Annotation of Amaya/amaya/styleparser.c, revision 1.206
1.1 cvs 1: /*
2: *
1.165 vatton 3: * (c) COPYRIGHT INRIA and W3C, 1996-2003
1.1 cvs 4: * Please first read the full copyright statement in file COPYRIGHT.
5: *
6: */
1.164 quint 7:
1.1 cvs 8: /*
1.164 quint 9: * Everything directly related to the CSS syntax should now hopefully
1.1 cvs 10: * be contained in this module.
11: *
12: * Author: I. Vatton
13: *
14: */
15:
16: /* Included headerfiles */
17: #define THOT_EXPORT extern
18: #include "amaya.h"
19: #include "css.h"
1.25 cvs 20: #include "fetchHTMLname.h"
1.100 vatton 21: #include "SVG.h"
1.107 cvs 22: #include "XML.h"
1.141 cvs 23: #include "document.h"
1.1 cvs 24:
25: typedef struct _BackgroundImageCallbackBlock
26: {
27: Element el;
28: PSchema tsch;
1.185 vatton 29: CSSInfoPtr css;
1.1 cvs 30: union
31: {
32: PresentationContextBlock specific;
33: GenericContextBlock generic;
34: } context;
35: }
36: BackgroundImageCallbackBlock, *BackgroundImageCallbackPtr;
37:
38: #include "AHTURLTools_f.h"
39: #include "HTMLpresentation_f.h"
40: #include "HTMLimage_f.h"
41: #include "UIcss_f.h"
42: #include "css_f.h"
1.24 cvs 43: #include "fetchHTMLname_f.h"
1.91 cvs 44: #include "fetchXMLname_f.h"
1.1 cvs 45: #include "html2thot_f.h"
1.91 cvs 46: #include "init_f.h"
1.1 cvs 47: #include "styleparser_f.h"
48:
49: #define MAX_BUFFER_LENGTH 200
50: /*
51: * A PropertyParser is a function used to parse the
52: * description substring associated to a given style attribute
1.59 cvs 53: * e.g.: "red" for a color attribute or "12pt bold helvetica"
1.1 cvs 54: * for a font attribute.
55: */
1.79 cvs 56: typedef char *(*PropertyParser) (Element element,
1.56 cvs 57: PSchema tsch,
58: PresentationContext context,
1.79 cvs 59: char *cssRule,
1.56 cvs 60: CSSInfoPtr css,
61: ThotBool isHTML);
1.1 cvs 62:
63: /* Description of the set of CSS properties supported */
64: typedef struct CSSProperty
65: {
1.79 cvs 66: char *name;
1.25 cvs 67: PropertyParser parsing_function;
1.1 cvs 68: }
69: CSSProperty;
70:
71: struct unit_def
72: {
1.79 cvs 73: char *sign;
1.1 cvs 74: unsigned int unit;
75: };
76:
77: static struct unit_def CSSUnitNames[] =
78: {
1.184 vatton 79: {"pt", UNIT_PT},
80: {"pc", UNIT_PC},
81: {"in", UNIT_IN},
82: {"cm", UNIT_CM},
83: {"mm", UNIT_MM},
84: {"em", UNIT_EM},
85: {"px", UNIT_PX},
86: {"ex", UNIT_XHEIGHT},
87: {"%", UNIT_PERCENT}
1.1 cvs 88: };
89:
90: #define NB_UNITS (sizeof(CSSUnitNames) / sizeof(struct unit_def))
1.86 cvs 91: static char *DocURL = NULL; /* The parsed CSS file */
92: static Document ParsedDoc; /* The document to which CSS are to be applied */
93: static int LineNumber = -1; /* The line where the error occurs */
1.93 vatton 94: static int NewLineSkipped = 0;
1.116 vatton 95: static ThotBool DoApply = TRUE;
1.1 cvs 96:
97: /*----------------------------------------------------------------------
98: SkipWord:
99: ----------------------------------------------------------------------*/
1.79 cvs 100: static char *SkipWord (char *ptr)
1.1 cvs 101: {
1.168 vatton 102: while (isalnum((int)*ptr) || *ptr == '-' || *ptr == '#' || *ptr == '%')
103: ptr++;
1.1 cvs 104: return (ptr);
105: }
106:
107: /*----------------------------------------------------------------------
1.13 cvs 108: SkipBlanksAndComments:
109: ----------------------------------------------------------------------*/
1.82 cvs 110: char *SkipBlanksAndComments (char *ptr)
1.13 cvs 111: {
1.93 vatton 112: /* skip spaces */
1.155 cheyroul 113: while (*ptr == SPACE ||
114: *ptr == BSPACE ||
115: *ptr == EOL ||
116: *ptr == TAB ||
117: *ptr == __CR__)
1.93 vatton 118: {
119: if (*ptr == EOL)
120: /* increment the number of newline skipped */
121: NewLineSkipped++;
122: ptr++;
123: }
1.155 cheyroul 124: while (ptr[0] == '/' &&
125: ptr[1] == '*')
1.13 cvs 126: {
127: /* look for the end of the comment */
128: ptr = &ptr[2];
129: while (ptr[0] != EOS && (ptr[0] != '*' || ptr[1] != '/'))
130: ptr++;
131: if (ptr[0] != EOS)
132: ptr = &ptr[2];
1.93 vatton 133: /* skip spaces */
134: while (*ptr == SPACE || *ptr == BSPACE || *ptr == EOL ||
135: *ptr == TAB || *ptr == __CR__)
136: {
137: if (*ptr == EOL)
138: /* increment the number of newline skipped */
139: NewLineSkipped++;
140: ptr++;
141: }
1.13 cvs 142: }
143: return (ptr);
144: }
145:
1.49 cvs 146: /*----------------------------------------------------------------------
1.161 quint 147: SkipQuotedString
1.1 cvs 148: ----------------------------------------------------------------------*/
1.79 cvs 149: static char *SkipQuotedString (char *ptr, char quote)
1.1 cvs 150: {
1.14 cvs 151: ThotBool stop;
1.1 cvs 152:
153: stop = FALSE;
154: while (!stop)
155: {
156: if (*ptr == quote)
157: {
158: ptr++;
159: stop = TRUE;
160: }
1.82 cvs 161: else if (*ptr == EOS)
1.1 cvs 162: stop = TRUE;
1.82 cvs 163: else if (*ptr == '\\')
1.1 cvs 164: /* escape character */
165: {
166: ptr++;
1.82 cvs 167: if ((*ptr >= '0' && *ptr <= '9') || (*ptr >= 'A' && *ptr <= 'F') ||
168: (*ptr >= 'a' && *ptr <= 'f'))
1.1 cvs 169: {
170: ptr++;
1.82 cvs 171: if ((*ptr >= '0' && *ptr <= '9') || (*ptr >= 'A' && *ptr <= 'F') ||
172: (*ptr >= 'a' && *ptr <= 'f'))
1.1 cvs 173: ptr++;
174: }
175: else
176: ptr++;
177: }
178: else
179: ptr++;
180: }
181: return (ptr);
182: }
183:
184: /*----------------------------------------------------------------------
1.168 vatton 185: CSSPrintError
1.86 cvs 186: print the error message msg on stderr.
187: When the line is 0 ask to expat the current line number
188: ----------------------------------------------------------------------*/
1.168 vatton 189: static void CSSPrintError (char *msg, char *value)
1.86 cvs 190: {
191: if (!TtaIsPrinting () && ParsedDoc > 0)
192: {
193: if (!ErrFile)
194: {
1.90 cvs 195: if (OpenParsingErrors (ParsedDoc) == FALSE)
1.86 cvs 196: return;
197: }
198:
1.133 vatton 199: if (DocURL)
1.86 cvs 200: {
1.94 cvs 201: fprintf (ErrFile, "*** Errors/warnings in %s\n", DocURL);
1.86 cvs 202: /* set to NULL as long as the CSS file doesn't change */
203: DocURL = NULL;
204: }
1.89 cvs 205: CSSErrorsFound = TRUE;
1.86 cvs 206: if (LineNumber < 0)
1.205 quint 207: fprintf (ErrFile, " In style attribute, %s \"%s\"\n", msg, value);
1.86 cvs 208: else
1.162 quint 209: fprintf (ErrFile, " line %d: %s \"%s\"\n", LineNumber+NewLineSkipped,
1.93 vatton 210: msg, value);
1.86 cvs 211: }
212: }
213:
1.168 vatton 214: /*----------------------------------------------------------------------
215: CSSParseError
216: print the error message msg on stderr.
217: When the line is 0 ask to expat the current line number
218: ----------------------------------------------------------------------*/
219: static void CSSParseError (char *msg, char *value, char *endvalue)
220: {
221: char c = EOS;
222:
223: if (endvalue)
224: {
225: /* close the string here */
226: c = *endvalue;
227: *endvalue = EOS;
228: }
229: CSSPrintError (msg, value);
230: if (endvalue)
231: *endvalue = c;
232: }
233:
1.89 cvs 234:
1.86 cvs 235: /*----------------------------------------------------------------------
1.168 vatton 236: SkipProperty skips a property and display and error message
1.86 cvs 237: ----------------------------------------------------------------------*/
238: static char *SkipProperty (char *ptr)
239: {
240: char *deb;
241: char c;
242:
243: deb = ptr;
1.135 vatton 244: while (*ptr != EOS && *ptr != ';' && *ptr != '}')
1.133 vatton 245: {
1.194 vatton 246: if (*ptr == '"' && (ptr == deb || ptr[-1] != '\\'))
1.133 vatton 247: {
248: /* skip to the end of the string "..." */
249: ptr++;
1.194 vatton 250: while (*ptr != EOS &&
251: (*ptr != '"' || (*ptr == '"' && ptr[-1] == '\\')))
1.133 vatton 252: ptr++;
253: }
254: ptr++;
255: }
1.95 cvs 256: /* print the skipped property */
1.86 cvs 257: c = *ptr;
258: *ptr = EOS;
1.95 cvs 259: #ifdef CSS_WARNING
1.86 cvs 260: if (*deb != EOS)
1.205 quint 261: CSSPrintError ("CSS property ignored:", deb);
1.95 cvs 262: #endif /* CSS_WARNING */
1.86 cvs 263: *ptr = c;
264: return (ptr);
265: }
266:
267: /*----------------------------------------------------------------------
1.168 vatton 268: SkipValue
269: skips the value and display an error message if msg is not NULL
1.1 cvs 270: ----------------------------------------------------------------------*/
1.168 vatton 271: static char *SkipValue (char *msg, char *ptr)
1.1 cvs 272: {
1.86 cvs 273: char *deb;
274: char c;
275:
276: deb = ptr;
1.135 vatton 277: while (*ptr != EOS && *ptr != ';' && *ptr != '}')
1.133 vatton 278: {
279: if (*ptr == '"' && (ptr == deb || ptr[-1] != '\\'))
280: {
281: /* skip to the end of the string "..." */
282: ptr++;
1.184 vatton 283: while (*ptr != '"' || (ptr[0] == '"' && ptr[-1] == '\\'))
1.133 vatton 284: ptr++;
285: }
286: ptr++;
287: }
1.95 cvs 288: /* print the skipped property */
1.86 cvs 289: c = *ptr;
290: *ptr = EOS;
1.168 vatton 291: if (msg && *deb != EOS && *deb != ',')
292: CSSPrintError (msg, deb);
1.86 cvs 293: *ptr = c;
1.1 cvs 294: return (ptr);
295: }
296:
297: /*----------------------------------------------------------------------
1.64 cvs 298: ParseNumber:
299: parse a number and returns the corresponding value.
1.1 cvs 300: ----------------------------------------------------------------------*/
1.79 cvs 301: char *ParseNumber (char *cssRule, PresentationValue *pval)
1.1 cvs 302: {
303: int val = 0;
304: int minus = 0;
305: int valid = 0;
306: int f = 0;
1.14 cvs 307: ThotBool real = FALSE;
1.1 cvs 308:
1.184 vatton 309: pval->typed_data.unit = UNIT_REL;
1.1 cvs 310: pval->typed_data.real = FALSE;
1.82 cvs 311: cssRule = SkipBlanksAndComments (cssRule);
312: if (*cssRule == '-')
1.1 cvs 313: {
314: minus = 1;
315: cssRule++;
1.82 cvs 316: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 317: }
318:
1.82 cvs 319: if (*cssRule == '+')
1.1 cvs 320: {
321: cssRule++;
1.82 cvs 322: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 323: }
324:
1.82 cvs 325: while ((*cssRule >= '0') && (*cssRule <= '9'))
1.1 cvs 326: {
327: val *= 10;
1.82 cvs 328: val += *cssRule - '0';
1.1 cvs 329: cssRule++;
330: valid = 1;
331: }
332:
1.82 cvs 333: if (*cssRule == '.')
1.1 cvs 334: {
335: real = TRUE;
336: f = val;
337: val = 0;
338: cssRule++;
339: /* keep only 3 digits */
1.82 cvs 340: if (*cssRule >= '0' && *cssRule <= '9')
1.1 cvs 341: {
1.82 cvs 342: val = (*cssRule - '0') * 100;
1.1 cvs 343: cssRule++;
1.82 cvs 344: if (*cssRule >= '0' && *cssRule <= '9')
1.1 cvs 345: {
1.82 cvs 346: val += (*cssRule - '0') * 10;
1.1 cvs 347: cssRule++;
1.82 cvs 348: if ((*cssRule >= '0') && (*cssRule <= '9'))
1.1 cvs 349: {
1.82 cvs 350: val += *cssRule - '0';
1.1 cvs 351: cssRule++;
352: }
353: }
354:
1.82 cvs 355: while (*cssRule >= '0' && *cssRule <= '9')
1.1 cvs 356: cssRule++;
357: valid = 1;
358: }
359: }
360:
361: if (!valid)
362: {
1.184 vatton 363: pval->typed_data.unit = UNIT_INVALID;
1.1 cvs 364: pval->typed_data.value = 0;
365: }
366: else
367: {
368: pval->typed_data.real = real;
369: if (real)
370: {
371: if (minus)
372: pval->typed_data.value = -(f * 1000 + val);
373: else
374: pval->typed_data.value = f * 1000 + val;
375: }
376: else
377: {
378: if (minus)
379: pval->typed_data.value = -val;
380: else
381: pval->typed_data.value = val;
382: }
1.64 cvs 383: }
384: return (cssRule);
385: }
1.195 vatton 386:
1.155 cheyroul 387: /*----------------------------------------------------------------------
388: ParseClampedUnit:
389: parse a CSS Unit substring and returns the corresponding
390: value and its unit.
391: [0,1]
392: or
393: [0,100] in %
394: ----------------------------------------------------------------------*/
1.195 vatton 395: char *ParseClampedUnit (char *text, PresentationValue *pval)
1.155 cheyroul 396: {
1.170 cheyroul 397: float clamped_value;
398: int int_clamped_value;
1.155 cheyroul 399:
400: if (*(text + strlen (text) -1) == '%')
1.195 vatton 401: {
402: int_clamped_value = atoi (text);
403: if (int_clamped_value < 0 || int_clamped_value > 100)
404: int_clamped_value = 1000;
1.155 cheyroul 405: else
1.195 vatton 406: int_clamped_value = int_clamped_value * 10;
407: }
408: else
409: {
410: clamped_value = (float) atof (text);
411: if (clamped_value < 0.0 || clamped_value > 1.0)
412: int_clamped_value = 1000;
413: else
414: int_clamped_value = (int) (clamped_value * 1000.);
415: }
416: pval->typed_data.unit = UNIT_REL;
417: pval->typed_data.value = int_clamped_value;
418: pval->typed_data.real = FALSE;
419: pval->data = int_clamped_value;
1.155 cheyroul 420: return (SkipWord (text));
421: }
1.64 cvs 422:
423: /*----------------------------------------------------------------------
424: ParseCSSUnit:
425: parse a CSS Unit substring and returns the corresponding
426: value and its unit.
427: ----------------------------------------------------------------------*/
1.82 cvs 428: char *ParseCSSUnit (char *cssRule, PresentationValue *pval)
1.64 cvs 429: {
430: unsigned int uni;
431:
1.184 vatton 432: pval->typed_data.unit = UNIT_REL;
1.64 cvs 433: cssRule = ParseNumber (cssRule, pval);
1.184 vatton 434: if (pval->typed_data.unit == UNIT_INVALID)
1.64 cvs 435: cssRule = SkipWord (cssRule);
436: else
437: {
1.82 cvs 438: cssRule = SkipBlanksAndComments (cssRule);
1.64 cvs 439: for (uni = 0; uni < NB_UNITS; uni++)
440: {
1.82 cvs 441: if (!strncasecmp (CSSUnitNames[uni].sign, cssRule,
442: strlen (CSSUnitNames[uni].sign)))
1.64 cvs 443: {
444: pval->typed_data.unit = CSSUnitNames[uni].unit;
1.82 cvs 445: return (cssRule + strlen (CSSUnitNames[uni].sign));
1.64 cvs 446: }
447: }
448: /* not in the list of predefined units */
1.184 vatton 449: pval->typed_data.unit = UNIT_BOX;
1.1 cvs 450: }
451: return (cssRule);
452: }
453:
1.43 cvs 454: /*----------------------------------------------------------------------
455: ParseBorderValue
456: ----------------------------------------------------------------------*/
1.79 cvs 457: static char *ParseBorderValue (char *cssRule, PresentationValue *border)
1.43 cvs 458: {
1.168 vatton 459: char *ptr;
460:
1.43 cvs 461: /* first parse the attribute string */
462: border->typed_data.value = 0;
1.184 vatton 463: border->typed_data.unit = UNIT_INVALID;
1.43 cvs 464: border->typed_data.real = FALSE;
1.82 cvs 465: if (!strncasecmp (cssRule, "thin", 4))
1.43 cvs 466: {
1.184 vatton 467: border->typed_data.unit = UNIT_PX;
1.43 cvs 468: border->typed_data.value = 1;
469: cssRule = SkipWord (cssRule);
470: }
1.82 cvs 471: else if (!strncasecmp (cssRule, "medium", 6))
1.43 cvs 472: {
1.184 vatton 473: border->typed_data.unit = UNIT_PX;
1.43 cvs 474: border->typed_data.value = 3;
475: cssRule = SkipWord (cssRule);
476: }
1.82 cvs 477: else if (!strncasecmp (cssRule, "thick", 5))
1.43 cvs 478: {
1.184 vatton 479: border->typed_data.unit = UNIT_PX;
1.43 cvs 480: border->typed_data.value = 5;
481: cssRule = SkipWord (cssRule);
482: }
1.110 vatton 483: else if (isdigit (*cssRule) || *cssRule == '.')
1.166 vatton 484: {
1.168 vatton 485: ptr = cssRule;
1.166 vatton 486: cssRule = ParseCSSUnit (cssRule, border);
1.168 vatton 487: if (border->typed_data.value == 0)
1.184 vatton 488: border->typed_data.unit = UNIT_PX;
489: else if (border->typed_data.unit == UNIT_INVALID ||
490: border->typed_data.unit == UNIT_BOX)
1.168 vatton 491: {
1.184 vatton 492: border->typed_data.unit = UNIT_INVALID;
1.168 vatton 493: border->typed_data.value = 0;
494: CSSParseError ("Invalid border-width value", ptr, cssRule);
495: }
1.166 vatton 496: }
1.43 cvs 497: return (cssRule);
498: }
499:
500: /*----------------------------------------------------------------------
501: ParseBorderStyle
502: ----------------------------------------------------------------------*/
1.79 cvs 503: static char *ParseBorderStyle (char *cssRule, PresentationValue *border)
1.43 cvs 504: {
505: /* first parse the attribute string */
506: border->typed_data.value = 0;
1.184 vatton 507: border->typed_data.unit = UNIT_PX;
1.43 cvs 508: border->typed_data.real = FALSE;
1.82 cvs 509: if (!strncasecmp (cssRule, "none", 4))
1.184 vatton 510: border->typed_data.value = BorderStyleNone;
1.82 cvs 511: else if (!strncasecmp (cssRule, "hidden", 6))
1.184 vatton 512: border->typed_data.value = BorderStyleHidden;
1.82 cvs 513: else if (!strncasecmp (cssRule, "dotted", 6))
1.184 vatton 514: border->typed_data.value = BorderStyleDotted;
1.82 cvs 515: else if (!strncasecmp (cssRule, "dashed", 6))
1.184 vatton 516: border->typed_data.value = BorderStyleDashed;
1.82 cvs 517: else if (!strncasecmp (cssRule, "solid", 5))
1.184 vatton 518: border->typed_data.value = BorderStyleSolid;
1.82 cvs 519: else if (!strncasecmp (cssRule, "double", 6))
1.184 vatton 520: border->typed_data.value = BorderStyleDouble;
1.82 cvs 521: else if (!strncasecmp (cssRule, "groove", 6))
1.184 vatton 522: border->typed_data.value = BorderStyleGroove;
1.82 cvs 523: else if (!strncasecmp (cssRule, "ridge", 5))
1.184 vatton 524: border->typed_data.value = BorderStyleRidge;
1.82 cvs 525: else if (!strncasecmp (cssRule, "inset", 5))
1.184 vatton 526: border->typed_data.value = BorderStyleInset;
1.82 cvs 527: else if (!strncasecmp (cssRule, "outset", 6))
1.184 vatton 528: border->typed_data.value = BorderStyleOutset;
1.43 cvs 529: else
1.44 cvs 530: {
531: /* invalid style */
1.184 vatton 532: border->typed_data.unit = UNIT_INVALID;
1.44 cvs 533: return (cssRule);
534: }
1.43 cvs 535: /* the value is parsed now */
536: cssRule = SkipWord (cssRule);
537: return (cssRule);
538: }
539:
540: /*----------------------------------------------------------------------
1.59 cvs 541: ParseCSSColor: parse a CSS color attribute string
1.43 cvs 542: we expect the input string describing the attribute to be
543: either a color name, a 3 tuple or an hexadecimal encoding.
544: The color used will be approximed from the current color
545: table
546: ----------------------------------------------------------------------*/
1.79 cvs 547: static char *ParseCSSColor (char *cssRule, PresentationValue * val)
1.43 cvs 548: {
1.79 cvs 549: char *ptr;
1.43 cvs 550: unsigned short redval = (unsigned short) -1;
551: unsigned short greenval = 0; /* composant of each RGB */
552: unsigned short blueval = 0; /* default to red if unknown ! */
553: int best = 0; /* best color in list found */
554:
1.82 cvs 555: cssRule = SkipBlanksAndComments (cssRule);
1.184 vatton 556: val->typed_data.unit = UNIT_INVALID;
1.43 cvs 557: val->typed_data.real = FALSE;
558: val->typed_data.value = 0;
1.57 cvs 559: ptr = TtaGiveRGB (cssRule, &redval, &greenval, &blueval);
1.135 vatton 560: if (!strncasecmp (cssRule, "inherit", 7))
561: {
562: cssRule = SkipWord (cssRule);
563: return (cssRule);
564: }
1.57 cvs 565: if (ptr == cssRule)
1.43 cvs 566: {
1.168 vatton 567: cssRule = SkipWord (cssRule);
568: CSSParseError ("Invalid color value", ptr, cssRule);
1.43 cvs 569: val->typed_data.value = 0;
1.184 vatton 570: val->typed_data.unit = UNIT_INVALID;
1.43 cvs 571: }
572: else
573: {
574: best = TtaGetThotColor (redval, greenval, blueval);
575: val->typed_data.value = best;
1.184 vatton 576: val->typed_data.unit = UNIT_REL;
1.57 cvs 577: cssRule = ptr;
1.43 cvs 578: }
579: val->typed_data.real = FALSE;
1.65 cvs 580: return (cssRule);
1.43 cvs 581: }
1.1 cvs 582:
583: /*----------------------------------------------------------------------
1.117 vatton 584: CheckImportantRule updates the field important of the context.
585: ----------------------------------------------------------------------*/
586: static char *CheckImportantRule (char *cssRule, PresentationContext context)
587: {
588: cssRule = SkipBlanksAndComments (cssRule);
1.120 vatton 589: if (*cssRule != '!')
590: context->important = FALSE;
591: else
1.117 vatton 592: {
1.120 vatton 593: cssRule++;
594: cssRule = SkipBlanksAndComments (cssRule);
595: if (!strncasecmp (cssRule, "important", 9))
596: {
597: context->important = TRUE;
598: cssRule += 9;
599: }
600: else
601: context->important = FALSE;
1.117 vatton 602: }
603: return (cssRule);
604: }
605:
606: /*----------------------------------------------------------------------
1.59 cvs 607: ParseCSSBorderTopWidth: parse a CSS BorderTopWidth
1.1 cvs 608: attribute string.
609: ----------------------------------------------------------------------*/
1.79 cvs 610: static char *ParseCSSBorderTopWidth (Element element, PSchema tsch,
611: PresentationContext context,
612: char *cssRule, CSSInfoPtr css,
613: ThotBool isHTML)
1.1 cvs 614: {
1.41 cvs 615: PresentationValue border;
616:
1.82 cvs 617: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 618: cssRule = ParseBorderValue (cssRule, &border);
1.184 vatton 619: if (border.typed_data.unit != UNIT_INVALID && DoApply)
1.44 cvs 620: {
1.117 vatton 621: /* check if it's an important rule */
622: if (tsch)
623: cssRule = CheckImportantRule (cssRule, context);
1.44 cvs 624: TtaSetStylePresentation (PRBorderTopWidth, element, tsch, context, border);
625: border.typed_data.value = 1;
1.184 vatton 626: border.typed_data.unit = UNIT_REL;
1.44 cvs 627: }
1.1 cvs 628: return (cssRule);
629: }
630:
631: /*----------------------------------------------------------------------
1.59 cvs 632: ParseCSSBorderBottomWidth: parse a CSS BorderBottomWidth
1.1 cvs 633: attribute string.
634: ----------------------------------------------------------------------*/
1.79 cvs 635: static char *ParseCSSBorderBottomWidth (Element element, PSchema tsch,
636: PresentationContext context,
637: char *cssRule, CSSInfoPtr css,
638: ThotBool isHTML)
1.1 cvs 639: {
1.41 cvs 640: PresentationValue border;
641:
1.82 cvs 642: cssRule = SkipBlanksAndComments (cssRule);
1.41 cvs 643: /* first parse the attribute string */
1.43 cvs 644: cssRule = ParseBorderValue (cssRule, &border);
1.184 vatton 645: if (border.typed_data.unit != UNIT_INVALID && DoApply)
1.44 cvs 646: {
1.117 vatton 647: /* check if it's an important rule */
648: if (tsch)
649: cssRule = CheckImportantRule (cssRule, context);
1.44 cvs 650: TtaSetStylePresentation (PRBorderBottomWidth, element, tsch, context, border);
651: border.typed_data.value = 1;
1.184 vatton 652: border.typed_data.unit = UNIT_REL;
1.44 cvs 653: }
1.1 cvs 654: return (cssRule);
655: }
656:
657: /*----------------------------------------------------------------------
1.59 cvs 658: ParseCSSBorderLeftWidth: parse a CSS BorderLeftWidth
1.1 cvs 659: attribute string.
660: ----------------------------------------------------------------------*/
1.79 cvs 661: static char *ParseCSSBorderLeftWidth (Element element, PSchema tsch,
662: PresentationContext context,
663: char *cssRule, CSSInfoPtr css,
664: ThotBool isHTML)
1.1 cvs 665: {
1.41 cvs 666: PresentationValue border;
667:
1.82 cvs 668: cssRule = SkipBlanksAndComments (cssRule);
1.41 cvs 669: /* first parse the attribute string */
1.43 cvs 670: cssRule = ParseBorderValue (cssRule, &border);
1.184 vatton 671: if (border.typed_data.unit != UNIT_INVALID && DoApply)
1.44 cvs 672: {
1.117 vatton 673: /* check if it's an important rule */
674: if (tsch)
675: cssRule = CheckImportantRule (cssRule, context);
1.44 cvs 676: TtaSetStylePresentation (PRBorderLeftWidth, element, tsch, context, border);
677: border.typed_data.value = 1;
1.184 vatton 678: border.typed_data.unit = UNIT_REL;
1.44 cvs 679: }
1.1 cvs 680: return (cssRule);
681: }
682:
683: /*----------------------------------------------------------------------
1.59 cvs 684: ParseCSSBorderRightWidth: parse a CSS BorderRightWidth
1.1 cvs 685: attribute string.
686: ----------------------------------------------------------------------*/
1.79 cvs 687: static char *ParseCSSBorderRightWidth (Element element, PSchema tsch,
688: PresentationContext context,
689: char *cssRule, CSSInfoPtr css,
690: ThotBool isHTML)
1.1 cvs 691: {
1.41 cvs 692: PresentationValue border;
693:
1.82 cvs 694: cssRule = SkipBlanksAndComments (cssRule);
1.41 cvs 695: /* first parse the attribute string */
1.43 cvs 696: cssRule = ParseBorderValue (cssRule, &border);
1.184 vatton 697: if (border.typed_data.unit != UNIT_INVALID && DoApply)
1.44 cvs 698: {
1.117 vatton 699: /* check if it's an important rule */
700: if (tsch)
701: cssRule = CheckImportantRule (cssRule, context);
1.44 cvs 702: TtaSetStylePresentation (PRBorderRightWidth, element, tsch, context, border);
703: border.typed_data.value = 1;
1.184 vatton 704: border.typed_data.unit = UNIT_REL;
1.44 cvs 705: }
1.1 cvs 706: return (cssRule);
707: }
708:
709: /*----------------------------------------------------------------------
1.59 cvs 710: ParseCSSBorderWidth: parse a CSS BorderWidth
1.1 cvs 711: attribute string.
712: ----------------------------------------------------------------------*/
1.79 cvs 713: static char *ParseCSSBorderWidth (Element element, PSchema tsch,
714: PresentationContext context,
715: char *cssRule, CSSInfoPtr css,
716: ThotBool isHTML)
1.1 cvs 717: {
1.79 cvs 718: char *ptrT, *ptrR, *ptrB, *ptrL;
1.93 vatton 719: int skippedNL;
1.41 cvs 720:
1.82 cvs 721: ptrT = SkipBlanksAndComments (cssRule);
1.42 cvs 722: /* First parse Border-Top */
723: ptrR = ParseCSSBorderTopWidth (element, tsch, context, ptrT, css, isHTML);
1.82 cvs 724: ptrR = SkipBlanksAndComments (ptrR);
725: if (*ptrR == ';' || *ptrR == EOS || *ptrR == ',')
1.42 cvs 726: {
1.93 vatton 727: skippedNL = NewLineSkipped;
1.42 cvs 728: cssRule = ptrR;
729: /* apply the Border-Top to all */
730: ptrR = ParseCSSBorderRightWidth (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 731: NewLineSkipped = skippedNL;
1.42 cvs 732: ptrR = ParseCSSBorderBottomWidth (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 733: NewLineSkipped = skippedNL;
1.42 cvs 734: ptrR = ParseCSSBorderLeftWidth (element, tsch, context, ptrT, css, isHTML);
735: }
736: else
737: {
738: /* parse Border-Right */
739: ptrB = ParseCSSBorderRightWidth (element, tsch, context, ptrR, css, isHTML);
1.82 cvs 740: ptrB = SkipBlanksAndComments (ptrB);
741: if (*ptrB == ';' || *ptrB == EOS || *ptrB == ',')
1.42 cvs 742: {
1.93 vatton 743: skippedNL = NewLineSkipped;
1.42 cvs 744: cssRule = ptrB;
745: /* apply the Border-Top to Border-Bottom */
746: ptrB = ParseCSSBorderBottomWidth (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 747: NewLineSkipped = skippedNL;
1.42 cvs 748: /* apply the Border-Right to Border-Left */
749: ptrB = ParseCSSBorderLeftWidth (element, tsch, context, ptrR, css, isHTML);
750: }
751: else
752: {
753: /* parse Border-Bottom */
754: ptrL = ParseCSSBorderBottomWidth (element, tsch, context, ptrB, css, isHTML);
1.82 cvs 755: ptrL = SkipBlanksAndComments (ptrL);
756: if (*ptrL == ';' || *ptrL == EOS || *ptrL == ',')
1.42 cvs 757: {
758: cssRule = ptrL;
759: /* apply the Border-Right to Border-Left */
760: ptrL = ParseCSSBorderLeftWidth (element, tsch, context, ptrR, css, isHTML);
761: }
762: else
763: /* parse Border-Left */
764: cssRule = ParseCSSBorderLeftWidth (element, tsch, context, ptrL, css, isHTML);
1.82 cvs 765: cssRule = SkipBlanksAndComments (cssRule);
1.42 cvs 766: }
767: }
1.1 cvs 768: return (cssRule);
769: }
770:
771: /*----------------------------------------------------------------------
1.59 cvs 772: ParseCSSBorderColorTop: parse a CSS BorderColorTop
1.1 cvs 773: attribute string.
774: ----------------------------------------------------------------------*/
1.79 cvs 775: static char *ParseCSSBorderColorTop (Element element, PSchema tsch,
776: PresentationContext context,
777: char *cssRule, CSSInfoPtr css,
778: ThotBool isHTML)
1.1 cvs 779: {
1.117 vatton 780: PresentationValue best;
1.43 cvs 781:
1.117 vatton 782: cssRule = ParseCSSColor (cssRule, &best);
1.184 vatton 783: if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.117 vatton 784: {
785: /* check if it's an important rule */
786: if (tsch)
787: cssRule = CheckImportantRule (cssRule, context);
788: /* install the new presentation */
789: TtaSetStylePresentation (PRBorderTopColor, element, tsch, context, best);
790: }
791: return (cssRule);
1.1 cvs 792: }
793:
794: /*----------------------------------------------------------------------
1.59 cvs 795: ParseCSSBorderColorLeft: parse a CSS BorderColorLeft
1.42 cvs 796: attribute string.
797: ----------------------------------------------------------------------*/
1.79 cvs 798: static char *ParseCSSBorderColorLeft (Element element, PSchema tsch,
799: PresentationContext context,
800: char *cssRule, CSSInfoPtr css,
801: ThotBool isHTML)
1.42 cvs 802: {
1.117 vatton 803: PresentationValue best;
804:
805: cssRule = ParseCSSColor (cssRule, &best);
1.184 vatton 806: if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.117 vatton 807: {
808: /* check if it's an important rule */
809: if (tsch)
810: cssRule = CheckImportantRule (cssRule, context);
811: /* install the new presentation */
812: TtaSetStylePresentation (PRBorderLeftColor, element, tsch, context, best);
813: }
814: return (cssRule);
1.42 cvs 815: }
816:
817: /*----------------------------------------------------------------------
1.59 cvs 818: ParseCSSBorderColorBottom: parse a CSS BorderColorBottom
1.42 cvs 819: attribute string.
820: ----------------------------------------------------------------------*/
1.79 cvs 821: static char *ParseCSSBorderColorBottom (Element element, PSchema tsch,
822: PresentationContext context,
823: char *cssRule, CSSInfoPtr css,
824: ThotBool isHTML)
1.42 cvs 825: {
1.117 vatton 826: PresentationValue best;
1.43 cvs 827:
1.117 vatton 828: cssRule = ParseCSSColor (cssRule, &best);
1.184 vatton 829: if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.117 vatton 830: {
831: /* check if it's an important rule */
832: if (tsch)
833: cssRule = CheckImportantRule (cssRule, context);
834: /* install the new presentation */
835: TtaSetStylePresentation (PRBorderBottomColor, element, tsch, context, best);
836: }
1.65 cvs 837: return (cssRule);
1.42 cvs 838: }
839:
840: /*----------------------------------------------------------------------
1.59 cvs 841: ParseCSSBorderColorRight: parse a CSS BorderColorRight
1.1 cvs 842: attribute string.
843: ----------------------------------------------------------------------*/
1.79 cvs 844: static char *ParseCSSBorderColorRight (Element element, PSchema tsch,
845: PresentationContext context,
846: char *cssRule, CSSInfoPtr css,
847: ThotBool isHTML)
1.1 cvs 848: {
1.117 vatton 849: PresentationValue best;
1.43 cvs 850:
1.117 vatton 851: cssRule = ParseCSSColor (cssRule, &best);
1.184 vatton 852: if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.117 vatton 853: {
854: /* check if it's an important rule */
855: if (tsch)
856: cssRule = CheckImportantRule (cssRule, context);
857: /* install the new presentation */
858: TtaSetStylePresentation (PRBorderRightColor, element, tsch, context, best);
859: }
860: return (cssRule);
1.1 cvs 861: }
862:
863: /*----------------------------------------------------------------------
1.59 cvs 864: ParseCSSBorderColor: parse a CSS border-color
1.42 cvs 865: attribute string.
866: ----------------------------------------------------------------------*/
1.79 cvs 867: static char *ParseCSSBorderColor (Element element, PSchema tsch,
868: PresentationContext context,
869: char *cssRule, CSSInfoPtr css,
870: ThotBool isHTML)
1.42 cvs 871: {
1.79 cvs 872: char *ptrT, *ptrR, *ptrB, *ptrL;
1.93 vatton 873: int skippedNL;
1.42 cvs 874:
1.82 cvs 875: ptrT = SkipBlanksAndComments (cssRule);
1.42 cvs 876: /* First parse Border-Top */
1.43 cvs 877: ptrR = ParseCSSBorderColorTop (element, tsch, context, ptrT, css, isHTML);
1.82 cvs 878: ptrR = SkipBlanksAndComments (ptrR);
879: if (*ptrR == ';' || *ptrR == EOS || *ptrR == ',')
1.42 cvs 880: {
1.93 vatton 881: skippedNL = NewLineSkipped;
1.42 cvs 882: cssRule = ptrR;
883: /* apply the Border-Top to all */
1.43 cvs 884: ptrR = ParseCSSBorderColorRight (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 885: NewLineSkipped = skippedNL;
1.43 cvs 886: ptrR = ParseCSSBorderColorBottom (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 887: NewLineSkipped = skippedNL;
1.43 cvs 888: ptrR = ParseCSSBorderColorLeft (element, tsch, context, ptrT, css, isHTML);
1.42 cvs 889: }
890: else
891: {
892: /* parse Border-Right */
1.43 cvs 893: ptrB = ParseCSSBorderColorRight (element, tsch, context, ptrR, css, isHTML);
1.82 cvs 894: ptrB = SkipBlanksAndComments (ptrB);
895: if (*ptrB == ';' || *ptrB == EOS || *ptrB == ',')
1.42 cvs 896: {
1.93 vatton 897: skippedNL = NewLineSkipped;
1.42 cvs 898: cssRule = ptrB;
899: /* apply the Border-Top to Border-Bottom */
1.43 cvs 900: ptrB = ParseCSSBorderColorBottom (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 901: NewLineSkipped = skippedNL;
1.42 cvs 902: /* apply the Border-Right to Border-Left */
1.43 cvs 903: ptrB = ParseCSSBorderColorLeft (element, tsch, context, ptrR, css, isHTML);
1.42 cvs 904: }
905: else
906: {
1.93 vatton 907: skippedNL = NewLineSkipped;
1.42 cvs 908: /* parse Border-Bottom */
1.43 cvs 909: ptrL = ParseCSSBorderColorBottom (element, tsch, context, ptrB, css, isHTML);
1.93 vatton 910: NewLineSkipped = skippedNL;
1.82 cvs 911: ptrL = SkipBlanksAndComments (ptrL);
912: if (*ptrL == ';' || *ptrL == EOS || *ptrL == ',')
1.42 cvs 913: {
914: cssRule = ptrL;
915: /* apply the Border-Right to Border-Left */
1.43 cvs 916: ptrL = ParseCSSBorderColorLeft (element, tsch, context, ptrR, css, isHTML);
1.42 cvs 917: }
918: else
919: /* parse Border-Left */
1.43 cvs 920: cssRule = ParseCSSBorderColorLeft (element, tsch, context, ptrL, css, isHTML);
1.82 cvs 921: cssRule = SkipBlanksAndComments (cssRule);
1.42 cvs 922: }
923: }
924: return (cssRule);
925: }
926:
927: /*----------------------------------------------------------------------
1.59 cvs 928: ParseCSSBorderStyleTop: parse a CSS BorderStyleTop
1.42 cvs 929: attribute string.
930: ----------------------------------------------------------------------*/
1.79 cvs 931: static char *ParseCSSBorderStyleTop (Element element, PSchema tsch,
932: PresentationContext context,
933: char *cssRule, CSSInfoPtr css,
934: ThotBool isHTML)
1.42 cvs 935: {
1.43 cvs 936: PresentationValue border;
937:
1.82 cvs 938: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 939: cssRule = ParseBorderStyle (cssRule, &border);
1.184 vatton 940: if (border.typed_data.unit != UNIT_INVALID && DoApply)
1.117 vatton 941: {
942: /* check if it's an important rule */
943: if (tsch)
944: cssRule = CheckImportantRule (cssRule, context);
945: TtaSetStylePresentation (PRBorderTopStyle, element, tsch, context, border);
946: }
1.42 cvs 947: return (cssRule);
948: }
949:
950: /*----------------------------------------------------------------------
1.59 cvs 951: ParseCSSBorderStyleLeft: parse a CSS BorderStyleLeft
1.42 cvs 952: attribute string.
953: ----------------------------------------------------------------------*/
1.79 cvs 954: static char *ParseCSSBorderStyleLeft (Element element, PSchema tsch,
955: PresentationContext context,
956: char *cssRule, CSSInfoPtr css,
957: ThotBool isHTML)
1.42 cvs 958: {
1.43 cvs 959: PresentationValue border;
960:
1.82 cvs 961: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 962: cssRule = ParseBorderStyle (cssRule, &border);
1.184 vatton 963: if (border.typed_data.unit != UNIT_INVALID && DoApply)
1.117 vatton 964: {
965: /* check if it's an important rule */
966: if (tsch)
967: cssRule = CheckImportantRule (cssRule, context);
968: TtaSetStylePresentation (PRBorderLeftStyle, element, tsch, context, border);
969: }
1.42 cvs 970: return (cssRule);
971: }
972:
973: /*----------------------------------------------------------------------
1.59 cvs 974: ParseCSSBorderStyleBottom: parse a CSS BorderStyleBottom
1.1 cvs 975: attribute string.
976: ----------------------------------------------------------------------*/
1.79 cvs 977: static char *ParseCSSBorderStyleBottom (Element element, PSchema tsch,
978: PresentationContext context,
979: char *cssRule, CSSInfoPtr css,
980: ThotBool isHTML)
1.1 cvs 981: {
1.43 cvs 982: PresentationValue border;
983:
1.82 cvs 984: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 985: cssRule = ParseBorderStyle (cssRule, &border);
1.184 vatton 986: if (border.typed_data.unit != UNIT_INVALID && DoApply)
1.117 vatton 987: {
988: /* check if it's an important rule */
989: if (tsch)
990: cssRule = CheckImportantRule (cssRule, context);
991: TtaSetStylePresentation (PRBorderBottomStyle, element, tsch, context, border);
992: }
1.1 cvs 993: return (cssRule);
994: }
995:
996: /*----------------------------------------------------------------------
1.59 cvs 997: ParseCSSBorderStyleRight: parse a CSS BorderStyleRight
1.1 cvs 998: attribute string.
999: ----------------------------------------------------------------------*/
1.79 cvs 1000: static char *ParseCSSBorderStyleRight (Element element, PSchema tsch,
1001: PresentationContext context,
1002: char *cssRule, CSSInfoPtr css,
1003: ThotBool isHTML)
1.1 cvs 1004: {
1.43 cvs 1005: PresentationValue border;
1006:
1.82 cvs 1007: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 1008: cssRule = ParseBorderStyle (cssRule, &border);
1.184 vatton 1009: if (border.typed_data.unit != UNIT_INVALID && DoApply)
1.117 vatton 1010: {
1011: /* check if it's an important rule */
1012: if (tsch)
1013: cssRule = CheckImportantRule (cssRule, context);
1014: TtaSetStylePresentation (PRBorderRightStyle, element, tsch, context, border);
1015: }
1.1 cvs 1016: return (cssRule);
1017: }
1018:
1019: /*----------------------------------------------------------------------
1.59 cvs 1020: ParseCSSBorderStyleStyle: parse a CSS border-style
1.1 cvs 1021: attribute string.
1022: ----------------------------------------------------------------------*/
1.79 cvs 1023: static char *ParseCSSBorderStyle (Element element, PSchema tsch,
1024: PresentationContext context,
1025: char *cssRule, CSSInfoPtr css,
1026: ThotBool isHTML)
1.1 cvs 1027: {
1.79 cvs 1028: char *ptrT, *ptrR, *ptrB, *ptrL;
1.93 vatton 1029: int skippedNL;
1.42 cvs 1030:
1.82 cvs 1031: ptrT = SkipBlanksAndComments (cssRule);
1.42 cvs 1032: /* First parse Border-Top */
1.43 cvs 1033: ptrR = ParseCSSBorderStyleTop (element, tsch, context, ptrT, css, isHTML);
1.82 cvs 1034: ptrR = SkipBlanksAndComments (ptrR);
1035: if (*ptrR == ';' || *ptrR == EOS || *ptrR == ',')
1.42 cvs 1036: {
1.93 vatton 1037: skippedNL = NewLineSkipped;
1.42 cvs 1038: cssRule = ptrR;
1039: /* apply the Border-Top to all */
1.43 cvs 1040: ptrR = ParseCSSBorderStyleRight (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 1041: NewLineSkipped = skippedNL;
1.43 cvs 1042: ptrR = ParseCSSBorderStyleBottom (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 1043: NewLineSkipped = skippedNL;
1.43 cvs 1044: ptrR = ParseCSSBorderStyleLeft (element, tsch, context, ptrT, css, isHTML);
1.42 cvs 1045: }
1046: else
1047: {
1048: /* parse Border-Right */
1.43 cvs 1049: ptrB = ParseCSSBorderStyleRight (element, tsch, context, ptrR, css, isHTML);
1.82 cvs 1050: ptrB = SkipBlanksAndComments (ptrB);
1051: if (*ptrB == ';' || *ptrB == EOS || *ptrB == ',')
1.42 cvs 1052: {
1.93 vatton 1053: skippedNL = NewLineSkipped;
1.42 cvs 1054: cssRule = ptrB;
1055: /* apply the Border-Top to Border-Bottom */
1.43 cvs 1056: ptrB = ParseCSSBorderStyleBottom (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 1057: NewLineSkipped = skippedNL;
1.42 cvs 1058: /* apply the Border-Right to Border-Left */
1.43 cvs 1059: ptrB = ParseCSSBorderStyleLeft (element, tsch, context, ptrR, css, isHTML);
1.42 cvs 1060: }
1061: else
1062: {
1063: /* parse Border-Bottom */
1.43 cvs 1064: ptrL = ParseCSSBorderStyleBottom (element, tsch, context, ptrB, css, isHTML);
1.82 cvs 1065: ptrL = SkipBlanksAndComments (ptrL);
1066: if (*ptrL == ';' || *ptrL == EOS || *ptrL == ',')
1.42 cvs 1067: {
1068: cssRule = ptrL;
1069: /* apply the Border-Right to Border-Left */
1.43 cvs 1070: ptrL = ParseCSSBorderStyleLeft (element, tsch, context, ptrR, css, isHTML);
1.42 cvs 1071: }
1072: else
1073: /* parse Border-Left */
1.43 cvs 1074: cssRule = ParseCSSBorderStyleLeft (element, tsch, context, ptrL, css, isHTML);
1.82 cvs 1075: cssRule = SkipBlanksAndComments (cssRule);
1.42 cvs 1076: }
1077: }
1078: return (cssRule);
1079: }
1080:
1081: /*----------------------------------------------------------------------
1.59 cvs 1082: ParseCSSBorderTop: parse a CSS BorderTop
1.42 cvs 1083: attribute string.
1084: ----------------------------------------------------------------------*/
1.79 cvs 1085: static char *ParseCSSBorderTop (Element element, PSchema tsch,
1086: PresentationContext context, char *cssRule,
1087: CSSInfoPtr css, ThotBool isHTML)
1.42 cvs 1088: {
1.79 cvs 1089: char *ptr;
1.43 cvs 1090:
1.82 cvs 1091: cssRule = SkipBlanksAndComments (cssRule);
1092: while (*cssRule != ';' && *cssRule != EOS && *cssRule != ',')
1.43 cvs 1093: {
1094: ptr = cssRule;
1095: cssRule = ParseCSSBorderStyleTop (element, tsch, context, cssRule, css, isHTML);
1096: if (ptr == cssRule)
1097: cssRule = ParseCSSBorderTopWidth (element, tsch, context, cssRule, css, isHTML);
1098: if (ptr == cssRule)
1099: cssRule = ParseCSSBorderColorTop (element, tsch, context, cssRule, css, isHTML);
1100: if (ptr == cssRule)
1101: /* rule not found */
1.168 vatton 1102: cssRule = SkipValue ("Invalid border value", cssRule);
1.82 cvs 1103: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 1104: }
1.42 cvs 1105: return (cssRule);
1106: }
1107:
1108: /*----------------------------------------------------------------------
1.59 cvs 1109: ParseCSSBorderLeft: parse a CSS BorderLeft
1.42 cvs 1110: attribute string.
1111: ----------------------------------------------------------------------*/
1.79 cvs 1112: static char *ParseCSSBorderLeft (Element element, PSchema tsch,
1113: PresentationContext context, char *cssRule,
1114: CSSInfoPtr css, ThotBool isHTML)
1.42 cvs 1115: {
1.79 cvs 1116: char *ptr;
1.43 cvs 1117:
1.82 cvs 1118: cssRule = SkipBlanksAndComments (cssRule);
1119: while (*cssRule != ';' && *cssRule != EOS && *cssRule != ',')
1.43 cvs 1120: {
1121: ptr = cssRule;
1122: cssRule = ParseCSSBorderStyleLeft (element, tsch, context, cssRule, css, isHTML);
1123: if (ptr == cssRule)
1124: cssRule = ParseCSSBorderLeftWidth (element, tsch, context, cssRule, css, isHTML);
1125: if (ptr == cssRule)
1126: cssRule = ParseCSSBorderColorLeft (element, tsch, context, cssRule, css, isHTML);
1127: if (ptr == cssRule)
1128: /* rule not found */
1.168 vatton 1129: cssRule = SkipValue ("Invalid border value", cssRule);
1.82 cvs 1130: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 1131: }
1.1 cvs 1132: return (cssRule);
1133: }
1134:
1135: /*----------------------------------------------------------------------
1.59 cvs 1136: ParseCSSBorderBottom: parse a CSS BorderBottom
1.1 cvs 1137: attribute string.
1138: ----------------------------------------------------------------------*/
1.79 cvs 1139: static char *ParseCSSBorderBottom (Element element, PSchema tsch,
1140: PresentationContext context, char *cssRule,
1141: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1142: {
1.79 cvs 1143: char *ptr;
1.43 cvs 1144:
1.82 cvs 1145: cssRule = SkipBlanksAndComments (cssRule);
1146: while (*cssRule != ';' && *cssRule != EOS && *cssRule != ',')
1.43 cvs 1147: {
1148: ptr = cssRule;
1149: cssRule = ParseCSSBorderStyleBottom (element, tsch, context, cssRule, css, isHTML);
1150: if (ptr == cssRule)
1151: cssRule = ParseCSSBorderBottomWidth (element, tsch, context, cssRule, css, isHTML);
1152: if (ptr == cssRule)
1153: cssRule = ParseCSSBorderColorBottom (element, tsch, context, cssRule, css, isHTML);
1154: if (ptr == cssRule)
1155: /* rule not found */
1.168 vatton 1156: cssRule = SkipValue ("Invalid border value", cssRule);
1.82 cvs 1157: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 1158: }
1.1 cvs 1159: return (cssRule);
1160: }
1161:
1162: /*----------------------------------------------------------------------
1.59 cvs 1163: ParseCSSBorderRight: parse a CSS BorderRight
1.1 cvs 1164: attribute string.
1165: ----------------------------------------------------------------------*/
1.79 cvs 1166: static char *ParseCSSBorderRight (Element element, PSchema tsch,
1167: PresentationContext context, char *cssRule,
1168: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1169: {
1.79 cvs 1170: char *ptr;
1.43 cvs 1171:
1.82 cvs 1172: cssRule = SkipBlanksAndComments (cssRule);
1173: while (*cssRule != ';' && *cssRule != EOS && *cssRule != ',')
1.43 cvs 1174: {
1175: ptr = cssRule;
1176: cssRule = ParseCSSBorderStyleRight (element, tsch, context, cssRule, css, isHTML);
1177: if (ptr == cssRule)
1178: cssRule = ParseCSSBorderRightWidth (element, tsch, context, cssRule, css, isHTML);
1179: if (ptr == cssRule)
1180: cssRule = ParseCSSBorderColorRight (element, tsch, context, cssRule, css, isHTML);
1181: if (ptr == cssRule)
1182: /* rule not found */
1.168 vatton 1183: cssRule = SkipValue ("Invalid border value", cssRule);
1.82 cvs 1184: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 1185: }
1.1 cvs 1186: return (cssRule);
1187: }
1188:
1189: /*----------------------------------------------------------------------
1.59 cvs 1190: ParseCSSBorder: parse a CSS border
1.42 cvs 1191: attribute string.
1192: ----------------------------------------------------------------------*/
1.79 cvs 1193: static char *ParseCSSBorder (Element element, PSchema tsch,
1194: PresentationContext context, char *cssRule,
1195: CSSInfoPtr css, ThotBool isHTML)
1.42 cvs 1196: {
1.79 cvs 1197: char *ptrT, *ptrR;
1.93 vatton 1198: int skippedNL;
1.42 cvs 1199:
1.82 cvs 1200: ptrT = SkipBlanksAndComments (cssRule);
1.42 cvs 1201: /* First parse Border-Top */
1202: ptrR = ParseCSSBorderTop (element, tsch, context, ptrT, css, isHTML);
1.82 cvs 1203: ptrR = SkipBlanksAndComments (ptrR);
1204: if (*ptrR == ';' || *ptrR == EOS || *ptrR == ',')
1.42 cvs 1205: {
1.93 vatton 1206: skippedNL = NewLineSkipped;
1.42 cvs 1207: cssRule = ptrR;
1208: /* apply the Border-Top to all */
1209: ptrR = ParseCSSBorderRight (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 1210: NewLineSkipped = skippedNL;
1.42 cvs 1211: ptrR = ParseCSSBorderBottom (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 1212: NewLineSkipped = skippedNL;
1.42 cvs 1213: ptrR = ParseCSSBorderLeft (element, tsch, context, ptrT, css, isHTML);
1214: }
1215: return (cssRule);
1216: }
1217:
1218: /*----------------------------------------------------------------------
1.184 vatton 1219: ParseCSSFloat: parse a CSS float attribute string
1220: ----------------------------------------------------------------------*/
1221: static char *ParseCSSFloat (Element element, PSchema tsch,
1222: PresentationContext context, char *cssRule,
1223: CSSInfoPtr css, ThotBool isHTML)
1224: {
1225: PresentationValue pval;
1226: char *ptr;
1227:
1228: pval.typed_data.value = 0;
1.187 vatton 1229: pval.typed_data.unit = UNIT_BOX;
1.192 cvs 1230: pval.typed_data.real = FALSE;
1.190 vatton 1231: if (!strncasecmp (cssRule, "inherit", 7))
1232: {
1233: cssRule = SkipWord (cssRule);
1234: return (cssRule);
1235: }
1.184 vatton 1236: if (!strncasecmp (cssRule, "none", 4))
1237: pval.typed_data.value = FloatNone;
1238: else if (!strncasecmp (cssRule, "left", 4))
1239: pval.typed_data.value = FloatLeft;
1240: else if (!strncasecmp (cssRule, "right", 5))
1241: pval.typed_data.value = FloatRight;
1242:
1243: ptr = cssRule;
1244: cssRule = SkipWord (cssRule);
1245: if (pval.typed_data.value == 0)
1246: CSSParseError ("Invalid float value", ptr, cssRule);
1247: else
1248: {
1249: if (DoApply)
1250: {
1251: if (tsch)
1252: cssRule = CheckImportantRule (cssRule, context);
1253: TtaSetStylePresentation (PRFloat, element, tsch, context, pval);
1254: }
1255: }
1256: cssRule = SkipValue (NULL, cssRule);
1257: return (cssRule);
1258: }
1259:
1260: /*----------------------------------------------------------------------
1261: ParseCSSClear: parse a CSS clear rule
1.1 cvs 1262: ----------------------------------------------------------------------*/
1.79 cvs 1263: static char *ParseCSSClear (Element element, PSchema tsch,
1264: PresentationContext context, char *cssRule,
1265: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1266: {
1.184 vatton 1267: PresentationValue pval;
1268: char *ptr;
1269:
1270: pval.typed_data.value = 0;
1.187 vatton 1271: pval.typed_data.unit = UNIT_BOX;
1.193 vatton 1272: pval.typed_data.real = FALSE;
1.190 vatton 1273: if (!strncasecmp (cssRule, "inherit", 7))
1274: {
1275: cssRule = SkipWord (cssRule);
1276: return (cssRule);
1277: }
1.184 vatton 1278: if (!strncasecmp (cssRule, "none", 4))
1279: pval.typed_data.value = ClearNone;
1280: else if (!strncasecmp (cssRule, "left", 4))
1281: pval.typed_data.value = ClearLeft;
1282: else if (!strncasecmp (cssRule, "right", 5))
1283: pval.typed_data.value = ClearRight;
1284: else if (!strncasecmp (cssRule, "both", 4))
1285: pval.typed_data.value = ClearBoth;
1286:
1287: ptr = cssRule;
1288: cssRule = SkipWord (cssRule);
1289: if (pval.typed_data.value == 0)
1.196 vatton 1290: CSSParseError ("Invalid clear value", ptr, cssRule);
1.184 vatton 1291: else
1292: {
1293: if (DoApply)
1294: {
1295: if (tsch)
1296: cssRule = CheckImportantRule (cssRule, context);
1297: TtaSetStylePresentation (PRClear, element, tsch, context, pval);
1298: }
1299: }
1300: cssRule = SkipValue (NULL, cssRule);
1301: return (cssRule);
1302: }
1303:
1304: /*----------------------------------------------------------------------
1305: ParseCSSContent: parse a CSS content value
1306: ----------------------------------------------------------------------*/
1307: static char *ParseCSSContent (Element element, PSchema tsch,
1308: PresentationContext context, char *cssRule,
1309: CSSInfoPtr css, ThotBool isHTML)
1310: {
1.168 vatton 1311: cssRule = SkipValue (NULL, cssRule);
1.1 cvs 1312: return (cssRule);
1313: }
1314:
1315: /*----------------------------------------------------------------------
1.59 cvs 1316: ParseCSSDisplay: parse a CSS display attribute string
1.1 cvs 1317: ----------------------------------------------------------------------*/
1.79 cvs 1318: static char *ParseCSSDisplay (Element element, PSchema tsch,
1319: PresentationContext context, char *cssRule,
1320: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1321: {
1.184 vatton 1322: PresentationValue pval;
1323: char *ptr;
1.1 cvs 1324:
1.184 vatton 1325: pval.typed_data.unit = UNIT_REL;
1326: pval.typed_data.real = FALSE;
1327: cssRule = SkipBlanksAndComments (cssRule);
1328: if (!strncasecmp (cssRule, "none", 4))
1329: {
1330: pval.typed_data.value = 0;
1331: if (DoApply)
1.117 vatton 1332: {
1333: if (tsch)
1334: cssRule = CheckImportantRule (cssRule, context);
1.116 vatton 1335: TtaSetStylePresentation (PRVisibility, element, tsch, context, pval);
1.117 vatton 1336: }
1.184 vatton 1337: cssRule = SkipWord (cssRule);
1338: }
1339: else
1340: {
1341: if (!strncasecmp (cssRule, "block", 5))
1342: pval.typed_data.value = Block;
1343: else if (!strncasecmp (cssRule, "inline", 6))
1344: pval.typed_data.value = Inline;
1345: else if (!strncasecmp (cssRule, "list-item", 9))
1346: pval.typed_data.value = ListItem;
1347: else if (!strncasecmp (cssRule, "run-in", 6))
1348: pval.typed_data.value = RunIn;
1349: else if (!strncasecmp (cssRule, "compact", 7))
1350: pval.typed_data.value = Compact;
1351: else if (!strncasecmp (cssRule, "marker", 6))
1352: pval.typed_data.value = Marker;
1353: else
1354: {
1355: if (strncasecmp (cssRule, "table-row-group", 15) &&
1356: strncasecmp (cssRule, "table-column-group", 18) &&
1357: strncasecmp (cssRule, "table-header-group", 5) &&
1358: strncasecmp (cssRule, "table-footer-group", 6) &&
1359: strncasecmp (cssRule, "table-row", 9) &&
1360: strncasecmp (cssRule, "table-column", 12) &&
1361: strncasecmp (cssRule, "table-cell", 10) &&
1362: strncasecmp (cssRule, "table-caption", 13) &&
1363: strncasecmp (cssRule, "table", 5) &&
1364: strncasecmp (cssRule, "inherit", 7))
1365: {
1366: ptr = cssRule;
1367: cssRule = SkipWord (cssRule);
1368: CSSParseError ("Invalid display value", ptr, cssRule);
1369: }
1370: return (cssRule);
1371: }
1372:
1373: if (DoApply)
1374: {
1375: if (tsch)
1376: cssRule = CheckImportantRule (cssRule, context);
1377: TtaSetStylePresentation (PRDisplay, element, tsch, context, pval);
1378: }
1379: cssRule = SkipWord (cssRule);
1380: }
1.1 cvs 1381: return (cssRule);
1382: }
1383:
1384: /*----------------------------------------------------------------------
1.59 cvs 1385: ParseCSSLetterSpacing: parse a CSS letter-spacing
1.1 cvs 1386: attribute string.
1387: ----------------------------------------------------------------------*/
1.79 cvs 1388: static char *ParseCSSLetterSpacing (Element element, PSchema tsch,
1389: PresentationContext context, char *cssRule,
1390: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1391: {
1.168 vatton 1392: cssRule = SkipValue (NULL, cssRule);
1.1 cvs 1393: return (cssRule);
1394: }
1395:
1396: /*----------------------------------------------------------------------
1.59 cvs 1397: ParseCSSListStyleType: parse a CSS list-style-type
1.1 cvs 1398: attribute string.
1399: ----------------------------------------------------------------------*/
1.79 cvs 1400: static char *ParseCSSListStyleType (Element element, PSchema tsch,
1401: PresentationContext context, char *cssRule,
1402: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1403: {
1.168 vatton 1404: cssRule = SkipValue (NULL, cssRule);
1.1 cvs 1405: return (cssRule);
1406: }
1407:
1408: /*----------------------------------------------------------------------
1.59 cvs 1409: ParseCSSListStyleImage: parse a CSS list-style-image
1.1 cvs 1410: attribute string.
1411: ----------------------------------------------------------------------*/
1.79 cvs 1412: static char *ParseCSSListStyleImage (Element element, PSchema tsch,
1413: PresentationContext context, char *cssRule,
1414: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1415: {
1.168 vatton 1416: cssRule = SkipValue (NULL, cssRule);
1.1 cvs 1417: return (cssRule);
1418: }
1419:
1420: /*----------------------------------------------------------------------
1.59 cvs 1421: ParseCSSListStylePosition: parse a CSS list-style-position
1.1 cvs 1422: attribute string.
1423: ----------------------------------------------------------------------*/
1.79 cvs 1424: static char *ParseCSSListStylePosition (Element element, PSchema tsch,
1425: PresentationContext context,
1426: char *cssRule, CSSInfoPtr css,
1427: ThotBool isHTML)
1.1 cvs 1428: {
1.168 vatton 1429: cssRule = SkipValue (NULL, cssRule);
1.1 cvs 1430: return (cssRule);
1431: }
1432:
1433: /*----------------------------------------------------------------------
1.59 cvs 1434: ParseCSSListStyle: parse a CSS list-style
1.1 cvs 1435: attribute string.
1436: ----------------------------------------------------------------------*/
1.79 cvs 1437: static char *ParseCSSListStyle (Element element, PSchema tsch,
1438: PresentationContext context, char *cssRule,
1439: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1440: {
1.168 vatton 1441: cssRule = SkipValue (NULL, cssRule);
1.1 cvs 1442: return (cssRule);
1443: }
1444:
1445: /*----------------------------------------------------------------------
1.59 cvs 1446: ParseCSSTextAlign: parse a CSS text-align
1.1 cvs 1447: attribute string.
1448: ----------------------------------------------------------------------*/
1.79 cvs 1449: static char *ParseCSSTextAlign (Element element, PSchema tsch,
1450: PresentationContext context, char *cssRule,
1451: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1452: {
1453: PresentationValue align;
1.168 vatton 1454: char *ptr;
1.1 cvs 1455:
1456: align.typed_data.value = 0;
1.184 vatton 1457: align.typed_data.unit = UNIT_REL;
1.1 cvs 1458: align.typed_data.real = FALSE;
1459:
1.82 cvs 1460: cssRule = SkipBlanksAndComments (cssRule);
1461: if (!strncasecmp (cssRule, "left", 4))
1.1 cvs 1462: {
1463: align.typed_data.value = AdjustLeft;
1464: cssRule = SkipWord (cssRule);
1465: }
1.82 cvs 1466: else if (!strncasecmp (cssRule, "right", 5))
1.1 cvs 1467: {
1468: align.typed_data.value = AdjustRight;
1469: cssRule = SkipWord (cssRule);
1470: }
1.82 cvs 1471: else if (!strncasecmp (cssRule, "center", 6))
1.1 cvs 1472: {
1473: align.typed_data.value = Centered;
1474: cssRule = SkipWord (cssRule);
1475: }
1.82 cvs 1476: else if (!strncasecmp (cssRule, "justify", 7))
1.1 cvs 1477: {
1.81 cvs 1478: align.typed_data.value = Justify;
1.1 cvs 1479: cssRule = SkipWord (cssRule);
1480: }
1481: else
1482: {
1.168 vatton 1483: ptr = cssRule;
1484: cssRule = SkipWord (cssRule);
1485: CSSParseError ("Invalid text-align value", ptr, cssRule);
1.1 cvs 1486: return (cssRule);
1487: }
1488:
1489: /*
1490: * install the new presentation.
1491: */
1.116 vatton 1492: if (align.typed_data.value && DoApply)
1.117 vatton 1493: {
1494: if (tsch)
1495: cssRule = CheckImportantRule (cssRule, context);
1496: TtaSetStylePresentation (PRAdjust, element, tsch, context, align);
1497: }
1.1 cvs 1498: return (cssRule);
1499: }
1500:
1501: /*----------------------------------------------------------------------
1.112 quint 1502: ParseCSSDirection: parse a CSS direction property
1503: ----------------------------------------------------------------------*/
1504: static char *ParseCSSDirection (Element element, PSchema tsch,
1505: PresentationContext context, char *cssRule,
1506: CSSInfoPtr css, ThotBool isHTML)
1507: {
1508: PresentationValue direction;
1.168 vatton 1509: char *ptr;
1.112 quint 1510:
1511: direction.typed_data.value = 0;
1.184 vatton 1512: direction.typed_data.unit = UNIT_REL;
1.112 quint 1513: direction.typed_data.real = FALSE;
1514:
1515: cssRule = SkipBlanksAndComments (cssRule);
1516: if (!strncasecmp (cssRule, "ltr", 3))
1517: {
1.184 vatton 1518: direction.typed_data.value = LeftToRight;
1.112 quint 1519: cssRule = SkipWord (cssRule);
1520: }
1521: else if (!strncasecmp (cssRule, "rtl", 3))
1522: {
1.184 vatton 1523: direction.typed_data.value = RightToLeft;
1.112 quint 1524: cssRule = SkipWord (cssRule);
1525: }
1526: else if (!strncasecmp (cssRule, "inherit", 7))
1527: {
1528: /* not implemented */
1529: cssRule = SkipWord (cssRule);
1530: return (cssRule);
1531: }
1532: else
1533: {
1.168 vatton 1534: ptr = cssRule;
1535: cssRule = SkipWord (cssRule);
1536: CSSParseError ("Invalid direction value", ptr, cssRule);
1.112 quint 1537: return (cssRule);
1538: }
1539:
1540: /*
1541: * install the new presentation.
1542: */
1.116 vatton 1543: if (direction.typed_data.value && DoApply)
1.117 vatton 1544: {
1545: if (tsch)
1546: cssRule = CheckImportantRule (cssRule, context);
1547: TtaSetStylePresentation (PRDirection, element, tsch, context, direction);
1548: }
1.112 quint 1549: return (cssRule);
1550: }
1551:
1552: /*----------------------------------------------------------------------
1.113 quint 1553: ParseCSSUnicodeBidi: parse a CSS unicode-bidi property
1554: ----------------------------------------------------------------------*/
1555: static char *ParseCSSUnicodeBidi (Element element, PSchema tsch,
1556: PresentationContext context, char *cssRule,
1557: CSSInfoPtr css, ThotBool isHTML)
1558: {
1559: PresentationValue bidi;
1.168 vatton 1560: char *ptr;
1.113 quint 1561:
1562: bidi.typed_data.value = 0;
1.184 vatton 1563: bidi.typed_data.unit = UNIT_REL;
1.113 quint 1564: bidi.typed_data.real = FALSE;
1565:
1566: cssRule = SkipBlanksAndComments (cssRule);
1567: if (!strncasecmp (cssRule, "normal", 6))
1568: {
1.184 vatton 1569: bidi.typed_data.value = Normal;
1.113 quint 1570: cssRule = SkipWord (cssRule);
1571: }
1572: else if (!strncasecmp (cssRule, "embed", 5))
1573: {
1.184 vatton 1574: bidi.typed_data.value = Embed;
1.113 quint 1575: cssRule = SkipWord (cssRule);
1576: }
1577: else if (!strncasecmp (cssRule, "override", 8))
1578: {
1.184 vatton 1579: bidi.typed_data.value = Override;
1.113 quint 1580: cssRule = SkipWord (cssRule);
1581: }
1582: else if (!strncasecmp (cssRule, "inherit", 7))
1583: {
1584: /* not implemented */
1585: cssRule = SkipWord (cssRule);
1586: return (cssRule);
1587: }
1588: else
1589: {
1.168 vatton 1590: ptr = cssRule;
1591: cssRule = SkipWord (cssRule);
1592: CSSParseError ("Invalid unicode-bidi value", ptr, cssRule);
1.113 quint 1593: return (cssRule);
1594: }
1595:
1596: /*
1597: * install the new presentation.
1598: */
1.116 vatton 1599: if (bidi.typed_data.value && DoApply)
1.117 vatton 1600: {
1601: if (tsch)
1602: cssRule = CheckImportantRule (cssRule, context);
1603: TtaSetStylePresentation (PRUnicodeBidi, element, tsch, context, bidi);
1604: }
1.113 quint 1605: return (cssRule);
1606: }
1607:
1608: /*----------------------------------------------------------------------
1.168 vatton 1609: ParseCSSTextIndent: parse a CSS text-indent
1.1 cvs 1610: attribute string.
1611: ----------------------------------------------------------------------*/
1.79 cvs 1612: static char *ParseCSSTextIndent (Element element, PSchema tsch,
1613: PresentationContext context, char *cssRule,
1614: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1615: {
1616: PresentationValue pval;
1.168 vatton 1617: char *ptr;
1.1 cvs 1618:
1.82 cvs 1619: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 1620: ptr = cssRule;
1.1 cvs 1621: cssRule = ParseCSSUnit (cssRule, &pval);
1.168 vatton 1622: if (pval.typed_data.value == 0)
1.184 vatton 1623: pval.typed_data.unit = UNIT_PX;
1624: else if (pval.typed_data.unit == UNIT_INVALID ||
1625: pval.typed_data.unit == UNIT_BOX)
1.168 vatton 1626: {
1627: CSSParseError ("Invalid text-indent value", ptr, cssRule);
1628: return (cssRule);
1629: }
1.1 cvs 1630: /* install the attribute */
1.116 vatton 1631: if (DoApply)
1.117 vatton 1632: {
1633: if (tsch)
1634: cssRule = CheckImportantRule (cssRule, context);
1635: TtaSetStylePresentation (PRIndent, element, tsch, context, pval);
1636: }
1.1 cvs 1637: return (cssRule);
1638: }
1639:
1640: /*----------------------------------------------------------------------
1.59 cvs 1641: ParseCSSTextTransform: parse a CSS text-transform
1.1 cvs 1642: attribute string.
1643: ----------------------------------------------------------------------*/
1.79 cvs 1644: static char *ParseCSSTextTransform (Element element, PSchema tsch,
1645: PresentationContext context, char *cssRule,
1646: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1647: {
1.168 vatton 1648: cssRule = SkipValue (NULL, cssRule);
1.1 cvs 1649: return (cssRule);
1650: }
1651:
1652: /*----------------------------------------------------------------------
1.59 cvs 1653: ParseCSSVerticalAlign: parse a CSS vertical-align
1.1 cvs 1654: attribute string.
1655: ----------------------------------------------------------------------*/
1.79 cvs 1656: static char *ParseCSSVerticalAlign (Element element, PSchema tsch,
1657: PresentationContext context, char *cssRule,
1658: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1659: {
1.168 vatton 1660: cssRule = SkipValue (NULL, cssRule);
1.1 cvs 1661: return (cssRule);
1662: }
1663:
1664: /*----------------------------------------------------------------------
1.59 cvs 1665: ParseCSSWhiteSpace: parse a CSS white-space
1.1 cvs 1666: attribute string.
1667: ----------------------------------------------------------------------*/
1.79 cvs 1668: static char *ParseCSSWhiteSpace (Element element, PSchema tsch,
1669: PresentationContext context, char *cssRule,
1670: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1671: {
1.82 cvs 1672: cssRule = SkipBlanksAndComments (cssRule);
1673: if (!strncasecmp (cssRule, "normal", 6))
1.1 cvs 1674: cssRule = SkipWord (cssRule);
1.82 cvs 1675: else if (!strncasecmp (cssRule, "pre", 3))
1.1 cvs 1676: cssRule = SkipWord (cssRule);
1677: else
1678: return (cssRule);
1679: return (cssRule);
1680: }
1681:
1682: /*----------------------------------------------------------------------
1.59 cvs 1683: ParseCSSWordSpacing: parse a CSS word-spacing
1.1 cvs 1684: attribute string.
1685: ----------------------------------------------------------------------*/
1.79 cvs 1686: static char *ParseCSSWordSpacing (Element element, PSchema tsch,
1687: PresentationContext context, char *cssRule,
1688: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1689: {
1.168 vatton 1690: cssRule = SkipValue (NULL, cssRule);
1.1 cvs 1691: return (cssRule);
1692: }
1693:
1694: /*----------------------------------------------------------------------
1.162 quint 1695: ParseCSSLineHeight: parse a CSS line-height property
1.25 cvs 1696: ----------------------------------------------------------------------*/
1.162 quint 1697: static char *ParseCSSLineHeight (Element element, PSchema tsch,
1.166 vatton 1698: PresentationContext context, char *cssRule,
1699: CSSInfoPtr css, ThotBool isHTML)
1.25 cvs 1700: {
1.162 quint 1701: PresentationValue pval;
1702: char *ptr;
1703:
1704: ptr = cssRule;
1705: if (!strncasecmp (cssRule, "normal", 6))
1706: {
1.184 vatton 1707: pval.typed_data.unit = UNIT_REL;
1.162 quint 1708: pval.typed_data.real = TRUE;
1709: pval.typed_data.value = 1100;
1710: cssRule = SkipWord (cssRule);
1711: }
1712: else if (!strncasecmp (cssRule, "inherit", 7))
1713: {
1714: cssRule = SkipWord (cssRule);
1715: return (cssRule);
1716: }
1717: else
1718: cssRule = ParseCSSUnit (cssRule, &pval);
1.25 cvs 1719:
1.184 vatton 1720: if (pval.typed_data.unit == UNIT_INVALID)
1.168 vatton 1721: CSSParseError ("Invalid line-height value", ptr, cssRule);
1.162 quint 1722: else if (DoApply)
1723: {
1.166 vatton 1724: /* install the new presentation */
1.184 vatton 1725: if (pval.typed_data.unit == UNIT_BOX)
1726: pval.typed_data.unit = UNIT_EM;
1.162 quint 1727: if (tsch)
1728: cssRule = CheckImportantRule (cssRule, context);
1729: TtaSetStylePresentation (PRLineSpacing, element, tsch, context, pval);
1730: }
1731: return (cssRule);
1.25 cvs 1732: }
1733:
1734: /*----------------------------------------------------------------------
1.59 cvs 1735: ParseCSSFontSize: parse a CSS font size attr string
1.1 cvs 1736: we expect the input string describing the attribute to be
1737: xx-small, x-small, small, medium, large, x-large, xx-large
1738: or an absolute size, or an imcrement relative to the parent
1739: ----------------------------------------------------------------------*/
1.79 cvs 1740: static char *ParseCSSFontSize (Element element, PSchema tsch,
1741: PresentationContext context, char *cssRule,
1742: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1743: {
1.171 quint 1744: ElementType elType;
1.1 cvs 1745: PresentationValue pval;
1.137 vatton 1746: char *ptr = NULL, *ptr1 = NULL;
1.14 cvs 1747: ThotBool real;
1.1 cvs 1748:
1749: pval.typed_data.real = FALSE;
1.82 cvs 1750: cssRule = SkipBlanksAndComments (cssRule);
1751: if (!strncasecmp (cssRule, "larger", 6))
1.1 cvs 1752: {
1.184 vatton 1753: pval.typed_data.unit = UNIT_PERCENT;
1.1 cvs 1754: pval.typed_data.value = 130;
1755: cssRule = SkipWord (cssRule);
1756: }
1.82 cvs 1757: else if (!strncasecmp (cssRule, "smaller", 7))
1.1 cvs 1758: {
1.184 vatton 1759: pval.typed_data.unit = UNIT_PERCENT;
1.1 cvs 1760: pval.typed_data.value = 80;
1761: cssRule = SkipWord (cssRule);
1762: }
1.82 cvs 1763: else if (!strncasecmp (cssRule, "xx-small", 8))
1.1 cvs 1764: {
1.184 vatton 1765: pval.typed_data.unit = UNIT_REL;
1.1 cvs 1766: pval.typed_data.value = 1;
1767: cssRule = SkipWord (cssRule);
1768: }
1.82 cvs 1769: else if (!strncasecmp (cssRule, "x-small", 7))
1.1 cvs 1770: {
1.184 vatton 1771: pval.typed_data.unit = UNIT_REL;
1.1 cvs 1772: pval.typed_data.value = 2;
1773: cssRule = SkipWord (cssRule);
1774: }
1.82 cvs 1775: else if (!strncasecmp (cssRule, "small", 5))
1.1 cvs 1776: {
1.184 vatton 1777: pval.typed_data.unit = UNIT_REL;
1.1 cvs 1778: pval.typed_data.value = 3;
1779: cssRule = SkipWord (cssRule);
1780: }
1.82 cvs 1781: else if (!strncasecmp (cssRule, "medium", 6))
1.1 cvs 1782: {
1.184 vatton 1783: pval.typed_data.unit = UNIT_REL;
1.1 cvs 1784: pval.typed_data.value = 4;
1785: cssRule = SkipWord (cssRule);
1786: }
1.82 cvs 1787: else if (!strncasecmp (cssRule, "large", 5))
1.1 cvs 1788: {
1.184 vatton 1789: pval.typed_data.unit = UNIT_REL;
1.1 cvs 1790: pval.typed_data.value = 5;
1791: cssRule = SkipWord (cssRule);
1792: }
1.82 cvs 1793: else if (!strncasecmp (cssRule, "x-large", 7))
1.1 cvs 1794: {
1.184 vatton 1795: pval.typed_data.unit = UNIT_REL;
1.1 cvs 1796: pval.typed_data.value = 6;
1797: cssRule = SkipWord (cssRule);
1798: }
1.82 cvs 1799: else if (!strncasecmp (cssRule, "xx-large", 8))
1.1 cvs 1800: {
1.184 vatton 1801: pval.typed_data.unit = UNIT_REL;
1.1 cvs 1802: pval.typed_data.value = 7;
1803: cssRule = SkipWord (cssRule);
1804: }
1.171 quint 1805: else if (!isdigit (*cssRule) && *cssRule != '.')
1806: return (cssRule);
1.1 cvs 1807: else
1808: {
1.25 cvs 1809: /* look for a '/' within the current cssRule */
1.137 vatton 1810: ptr1 = strchr (cssRule, ';');
1.82 cvs 1811: ptr = strchr (cssRule, '/');
1.137 vatton 1812: if (ptr && (ptr1 == NULL || ptr < ptr1))
1.25 cvs 1813: {
1814: /* keep the line spacing rule */
1.82 cvs 1815: ptr[0] = EOS;
1.25 cvs 1816: ptr = &ptr[1];
1817: }
1.137 vatton 1818: else
1819: ptr = NULL;
1.171 quint 1820:
1.1 cvs 1821: cssRule = ParseCSSUnit (cssRule, &pval);
1.171 quint 1822:
1.184 vatton 1823: if (pval.typed_data.unit == UNIT_BOX)
1.171 quint 1824: /* no unit specified */
1825: {
1826: elType = TtaGetElementType(element);
1827: if (!strcmp(TtaGetSSchemaName (elType.ElSSchema), "SVG"))
1828: /* we are working for an SVG element. No unit means pixels */
1.184 vatton 1829: pval.typed_data.unit = UNIT_PX;
1.171 quint 1830: }
1.168 vatton 1831: if (pval.typed_data.value != 0 &&
1.184 vatton 1832: (pval.typed_data.unit == UNIT_INVALID ||
1833: pval.typed_data.unit == UNIT_BOX ||
1.168 vatton 1834: pval.typed_data.value < 0))
1835: /* not a valid value */
1.1 cvs 1836: return (cssRule);
1.184 vatton 1837: else if (pval.typed_data.unit == UNIT_REL && pval.typed_data.value > 0)
1.1 cvs 1838: /* CSS relative sizes have to be higher than Thot ones */
1839: pval.typed_data.value += 1;
1840: else
1841: {
1842: real = pval.typed_data.real;
1.184 vatton 1843: if (pval.typed_data.unit == UNIT_EM)
1.1 cvs 1844: {
1845: if (real)
1846: {
1847: pval.typed_data.value /= 10;
1.11 cvs 1848: pval.typed_data.real = FALSE;
1.1 cvs 1849: real = FALSE;
1850: }
1851: else
1852: pval.typed_data.value *= 100;
1.184 vatton 1853: pval.typed_data.unit = UNIT_PERCENT;
1.1 cvs 1854: }
1.184 vatton 1855: else if (pval.typed_data.unit == UNIT_XHEIGHT)
1.146 quint 1856: {
1857: /* a font size expressed in ex is converted into a percentage.
1858: For example, "3ex" is converted into "180%", supposing
1859: that 1ex is approximately 0.6 times the height of the
1860: current font */
1861: if (real)
1862: {
1863: pval.typed_data.value *= 6;
1864: pval.typed_data.value /= 100;
1865: pval.typed_data.real = FALSE;
1866: real = FALSE;
1867: }
1868: else
1869: pval.typed_data.value *= 60;
1.184 vatton 1870: pval.typed_data.unit = UNIT_PERCENT;
1.146 quint 1871: }
1.1 cvs 1872: }
1873: }
1874:
1.25 cvs 1875: /* install the presentation style */
1.116 vatton 1876: if (DoApply)
1.117 vatton 1877: {
1878: if (tsch)
1879: cssRule = CheckImportantRule (cssRule, context);
1880: TtaSetStylePresentation (PRSize, element, tsch, context, pval);
1881: }
1882: if (ptr)
1.162 quint 1883: cssRule = ParseCSSLineHeight (element, tsch, context, ptr, css, isHTML);
1.1 cvs 1884: return (cssRule);
1885: }
1886:
1887: /*----------------------------------------------------------------------
1.59 cvs 1888: ParseCSSFontFamily: parse a CSS font family string
1.1 cvs 1889: we expect the input string describing the attribute to be
1890: a common generic font style name
1891: ----------------------------------------------------------------------*/
1.79 cvs 1892: static char *ParseCSSFontFamily (Element element, PSchema tsch,
1893: PresentationContext context, char *cssRule,
1894: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1895: {
1896: PresentationValue font;
1.79 cvs 1897: char quoteChar;
1.1 cvs 1898:
1899: font.typed_data.value = 0;
1.184 vatton 1900: font.typed_data.unit = UNIT_REL;
1.1 cvs 1901: font.typed_data.real = FALSE;
1.82 cvs 1902: cssRule = SkipBlanksAndComments (cssRule);
1903: if (*cssRule == '"' || *cssRule == '\'')
1.1 cvs 1904: {
1905: quoteChar = *cssRule;
1906: cssRule++;
1907: }
1908: else
1.82 cvs 1909: quoteChar = EOS;
1.1 cvs 1910:
1.92 cvs 1911: if (!strncasecmp (cssRule, "times", 5) &&
1912: (quoteChar == EOS || quoteChar == cssRule[5]))
1.86 cvs 1913: {
1.184 vatton 1914: font.typed_data.value = FontTimes;
1.86 cvs 1915: cssRule += 5;
1916: }
1.92 cvs 1917: else if (!strncasecmp (cssRule, "serif", 5) &&
1918: (quoteChar == EOS || quoteChar == cssRule[5]))
1.86 cvs 1919: {
1.184 vatton 1920: font.typed_data.value = FontTimes;
1.86 cvs 1921: cssRule += 5;
1.92 cvs 1922: if (quoteChar != EOS)
1923: cssRule++;
1.86 cvs 1924: }
1.92 cvs 1925: else if (!strncasecmp (cssRule, "helvetica", 9) &&
1926: (quoteChar == EOS || quoteChar == cssRule[9]))
1.86 cvs 1927: {
1.184 vatton 1928: font.typed_data.value = FontHelvetica;
1.86 cvs 1929: cssRule += 9;
1.92 cvs 1930: if (quoteChar != EOS)
1931: cssRule++;
1.86 cvs 1932: }
1.92 cvs 1933: else if (!strncasecmp (cssRule, "verdana", 7) &&
1934: (quoteChar == EOS || quoteChar == cssRule[7]))
1.86 cvs 1935: {
1.184 vatton 1936: font.typed_data.value = FontHelvetica;
1.86 cvs 1937: cssRule += 7;
1.92 cvs 1938: if (quoteChar != EOS)
1939: cssRule++;
1.86 cvs 1940: }
1.92 cvs 1941: else if (!strncasecmp (cssRule, "sans-serif", 10) &&
1942: (quoteChar == EOS || quoteChar == cssRule[10]))
1.86 cvs 1943: {
1.184 vatton 1944: font.typed_data.value = FontHelvetica;
1.86 cvs 1945: cssRule += 10;
1.92 cvs 1946: if (quoteChar != EOS)
1947: cssRule++;
1.86 cvs 1948: }
1.92 cvs 1949: else if (!strncasecmp (cssRule, "courier", 7) &&
1950: (quoteChar == EOS || quoteChar == cssRule[7]))
1.86 cvs 1951: {
1.184 vatton 1952: font.typed_data.value = FontCourier;
1.86 cvs 1953: cssRule += 7;
1.92 cvs 1954: if (quoteChar != EOS)
1955: cssRule++;
1.86 cvs 1956: }
1.92 cvs 1957: else if (!strncasecmp (cssRule, "monospace", 9) &&
1958: (quoteChar == EOS || quoteChar == cssRule[9]))
1.86 cvs 1959: {
1.184 vatton 1960: font.typed_data.value = FontCourier;
1.86 cvs 1961: cssRule += 9;
1.92 cvs 1962: if (quoteChar != EOS)
1963: cssRule++;
1.86 cvs 1964: }
1.1 cvs 1965: else
1966: /* unknown font name. Skip it */
1967: {
1.92 cvs 1968: if (quoteChar != EOS)
1.54 cvs 1969: cssRule = SkipQuotedString (cssRule, quoteChar);
1.86 cvs 1970: else
1.1 cvs 1971: cssRule = SkipWord (cssRule);
1.82 cvs 1972: cssRule = SkipBlanksAndComments (cssRule);
1973: if (*cssRule == ',')
1.1 cvs 1974: {
1.86 cvs 1975: cssRule++;
1976: cssRule = ParseCSSFontFamily (element, tsch, context, cssRule, css, isHTML);
1977: return (cssRule);
1.1 cvs 1978: }
1979: }
1980:
1981: if (font.typed_data.value != 0)
1982: {
1.93 vatton 1983: cssRule = SkipBlanksAndComments (cssRule);
1.133 vatton 1984: if (*cssRule == ',')
1985: {
1986: cssRule++;
1.168 vatton 1987: cssRule = SkipValue (NULL, cssRule);
1.133 vatton 1988: }
1.93 vatton 1989: /* install the new presentation */
1.116 vatton 1990: if (DoApply)
1.117 vatton 1991: {
1992: if (tsch)
1993: cssRule = CheckImportantRule (cssRule, context);
1994: TtaSetStylePresentation (PRFont, element, tsch, context, font);
1995: }
1.1 cvs 1996: }
1997: return (cssRule);
1998: }
1999:
2000: /*----------------------------------------------------------------------
1.59 cvs 2001: ParseCSSFontWeight: parse a CSS font weight string
1.1 cvs 2002: we expect the input string describing the attribute to be
1.20 cvs 2003: normal, bold, bolder, lighter, 100, 200, 300, ... 900, inherit.
1.1 cvs 2004: ----------------------------------------------------------------------*/
1.79 cvs 2005: static char *ParseCSSFontWeight (Element element, PSchema tsch,
2006: PresentationContext context, char *cssRule,
2007: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2008: {
1.20 cvs 2009: PresentationValue weight;
1.1 cvs 2010:
2011: weight.typed_data.value = 0;
1.184 vatton 2012: weight.typed_data.unit = UNIT_REL;
1.1 cvs 2013: weight.typed_data.real = FALSE;
1.82 cvs 2014: cssRule = SkipBlanksAndComments (cssRule);
2015: if (!strncasecmp (cssRule, "100", 3) && !isalpha (cssRule[3]))
1.1 cvs 2016: {
2017: weight.typed_data.value = -3;
2018: cssRule = SkipWord (cssRule);
2019: }
1.82 cvs 2020: else if (!strncasecmp (cssRule, "200", 3) && !isalpha (cssRule[3]))
1.1 cvs 2021: {
2022: weight.typed_data.value = -2;
2023: cssRule = SkipWord (cssRule);
2024: }
1.82 cvs 2025: else if (!strncasecmp (cssRule, "300", 3) && ! isalpha(cssRule[3]))
1.1 cvs 2026: {
2027: weight.typed_data.value = -1;
2028: cssRule = SkipWord (cssRule);
2029: }
1.82 cvs 2030: else if (!strncasecmp (cssRule, "normal", 6) || (!strncasecmp (cssRule, "400", 3) && !isalpha (cssRule[3])))
1.1 cvs 2031: {
2032: weight.typed_data.value = 0;
2033: cssRule = SkipWord (cssRule);
2034: }
1.82 cvs 2035: else if (!strncasecmp (cssRule, "500", 3) && !isalpha (cssRule[3]))
1.1 cvs 2036: {
2037: weight.typed_data.value = +1;
2038: cssRule = SkipWord (cssRule);
2039: }
1.82 cvs 2040: else if (!strncasecmp (cssRule, "600", 3) && !isalpha (cssRule[3]))
1.1 cvs 2041: {
2042: weight.typed_data.value = +2;
2043: cssRule = SkipWord (cssRule);
2044: }
1.82 cvs 2045: else if (!strncasecmp (cssRule, "bold", 4) || (!strncasecmp (cssRule, "700", 3) && !isalpha (cssRule[3])))
1.1 cvs 2046: {
2047: weight.typed_data.value = +3;
2048: cssRule = SkipWord (cssRule);
2049: }
1.82 cvs 2050: else if (!strncasecmp (cssRule, "800", 3) && !isalpha (cssRule[3]))
1.1 cvs 2051: {
2052: weight.typed_data.value = +4;
2053: cssRule = SkipWord (cssRule);
2054: }
1.82 cvs 2055: else if (!strncasecmp (cssRule, "900", 3) && !isalpha (cssRule[3]))
1.1 cvs 2056: {
2057: weight.typed_data.value = +5;
2058: cssRule = SkipWord (cssRule);
2059: }
1.82 cvs 2060: else if (!strncasecmp (cssRule, "inherit", 7) || !strncasecmp (cssRule, "bolder", 6) || !strncasecmp (cssRule, "lighter", 7))
1.1 cvs 2061: {
2062: /* not implemented */
2063: cssRule = SkipWord (cssRule);
2064: return (cssRule);
2065: }
2066: else
2067: return (cssRule);
2068:
2069: /*
1.20 cvs 2070: * Here we have to reduce since only two font weight values are supported
1.1 cvs 2071: * by the Thot presentation API.
2072: */
1.20 cvs 2073: if (weight.typed_data.value > 0)
1.184 vatton 2074: weight.typed_data.value = WeightBold;
1.20 cvs 2075: else
1.184 vatton 2076: weight.typed_data.value = WeightNormal;
1.1 cvs 2077:
2078: /* install the new presentation */
1.116 vatton 2079: if (DoApply)
1.117 vatton 2080: {
2081: if (tsch)
2082: cssRule = CheckImportantRule (cssRule, context);
2083: TtaSetStylePresentation (PRWeight, element, tsch, context, weight);
2084: }
1.1 cvs 2085: return (cssRule);
2086: }
2087:
2088: /*----------------------------------------------------------------------
1.59 cvs 2089: ParseCSSFontVariant: parse a CSS font variant string
1.1 cvs 2090: we expect the input string describing the attribute to be
2091: normal or small-caps
2092: ----------------------------------------------------------------------*/
1.79 cvs 2093: static char *ParseCSSFontVariant (Element element, PSchema tsch,
2094: PresentationContext context, char *cssRule,
2095: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2096: {
2097: PresentationValue style;
2098:
2099: style.typed_data.value = 0;
1.184 vatton 2100: style.typed_data.unit = UNIT_REL;
1.1 cvs 2101: style.typed_data.real = FALSE;
1.82 cvs 2102: cssRule = SkipBlanksAndComments (cssRule);
2103: if (!strncasecmp (cssRule, "small-caps", 10))
1.1 cvs 2104: {
2105: /* Not supported yet */
2106: cssRule = SkipWord (cssRule);
2107: }
1.82 cvs 2108: else if (!strncasecmp (cssRule, "normal", 6))
1.1 cvs 2109: {
2110: /* Not supported yet */
2111: cssRule = SkipWord (cssRule);
2112: }
1.82 cvs 2113: else if (!strncasecmp (cssRule, "inherit", 7))
1.1 cvs 2114: {
2115: /* Not supported yet */
2116: cssRule = SkipWord (cssRule);
2117: }
2118: else
2119: return (cssRule);
2120:
2121: return (cssRule);
2122: }
2123:
2124:
2125: /*----------------------------------------------------------------------
1.59 cvs 2126: ParseCSSFontStyle: parse a CSS font style string
1.1 cvs 2127: we expect the input string describing the attribute to be
2128: italic, oblique or normal
2129: ----------------------------------------------------------------------*/
1.79 cvs 2130: static char *ParseCSSFontStyle (Element element, PSchema tsch,
2131: PresentationContext context, char *cssRule,
2132: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2133: {
2134: PresentationValue style;
2135: PresentationValue size;
2136:
2137: style.typed_data.value = 0;
1.184 vatton 2138: style.typed_data.unit = UNIT_REL;
1.1 cvs 2139: style.typed_data.real = FALSE;
2140: size.typed_data.value = 0;
1.184 vatton 2141: size.typed_data.unit = UNIT_REL;
1.1 cvs 2142: size.typed_data.real = FALSE;
1.82 cvs 2143: cssRule = SkipBlanksAndComments (cssRule);
2144: if (!strncasecmp (cssRule, "italic", 6))
1.1 cvs 2145: {
1.184 vatton 2146: style.typed_data.value = StyleItalics;
1.1 cvs 2147: cssRule = SkipWord (cssRule);
2148: }
1.82 cvs 2149: else if (!strncasecmp (cssRule, "oblique", 7))
1.1 cvs 2150: {
1.184 vatton 2151: style.typed_data.value = StyleOblique;
1.1 cvs 2152: cssRule = SkipWord (cssRule);
2153: }
1.82 cvs 2154: else if (!strncasecmp (cssRule, "normal", 6))
1.1 cvs 2155: {
1.184 vatton 2156: style.typed_data.value = StyleRoman;
1.1 cvs 2157: cssRule = SkipWord (cssRule);
2158: }
1.108 cvs 2159: else if (!strncasecmp (cssRule, "inherit", 7))
2160: {
2161: /* not implemented */
2162: cssRule = SkipWord (cssRule);
2163: return (cssRule);
2164: }
1.1 cvs 2165: else
2166: {
2167: /* invalid font style */
1.108 cvs 2168: return (cssRule);
1.1 cvs 2169: }
2170:
2171: /*
2172: * install the new presentation.
2173: */
1.116 vatton 2174: if (style.typed_data.value != 0 && DoApply)
1.117 vatton 2175: {
2176: if (tsch)
2177: cssRule = CheckImportantRule (cssRule, context);
1.20 cvs 2178: TtaSetStylePresentation (PRStyle, element, tsch, context, style);
1.117 vatton 2179: }
1.116 vatton 2180: if (size.typed_data.value != 0 && DoApply)
1.1 cvs 2181: {
2182: PresentationValue previous_size;
2183:
2184: if (!TtaGetStylePresentation (PRSize, element, tsch, context, &previous_size))
2185: {
2186: /* !!!!!!!!!!!!!!!!!!!!!!!! Unite + relatif !!!!!!!!!!!!!!!! */
2187: size.typed_data.value += previous_size.typed_data.value;
2188: TtaSetStylePresentation (PRSize, element, tsch, context, size);
2189: }
2190: else
2191: {
2192: size.typed_data.value = 10;
2193: TtaSetStylePresentation (PRSize, element, tsch, context, size);
2194: }
2195: }
2196: return (cssRule);
2197: }
2198:
2199: /*----------------------------------------------------------------------
1.59 cvs 2200: ParseCSSFont: parse a CSS font attribute string
2201: we expect the input string describing the attribute to be
2202: !!!!!!
1.1 cvs 2203: ----------------------------------------------------------------------*/
1.79 cvs 2204: static char *ParseCSSFont (Element element, PSchema tsch,
2205: PresentationContext context, char *cssRule,
2206: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2207: {
1.79 cvs 2208: char *ptr;
1.93 vatton 2209: int skippedNL;
1.1 cvs 2210:
1.82 cvs 2211: cssRule = SkipBlanksAndComments (cssRule);
2212: if (!strncasecmp (cssRule, "caption", 7))
1.1 cvs 2213: ;
1.82 cvs 2214: else if (!strncasecmp (cssRule, "icon", 4))
1.1 cvs 2215: ;
1.82 cvs 2216: else if (!strncasecmp (cssRule, "menu", 4))
1.1 cvs 2217: ;
1.82 cvs 2218: else if (!strncasecmp (cssRule, "message-box", 11))
1.1 cvs 2219: ;
1.82 cvs 2220: else if (!strncasecmp (cssRule, "small-caption", 13))
1.1 cvs 2221: ;
1.82 cvs 2222: else if (!strncasecmp (cssRule, "status-bar", 10))
1.1 cvs 2223: ;
2224: else
1.43 cvs 2225: {
1.133 vatton 2226: while (*cssRule != ';' && *cssRule != EOS)
1.43 cvs 2227: {
1.72 cvs 2228: ptr = cssRule;
1.93 vatton 2229: skippedNL = NewLineSkipped;
1.72 cvs 2230: cssRule = ParseCSSFontStyle (element, tsch, context, cssRule, css, isHTML);
2231: if (ptr == cssRule)
1.93 vatton 2232: {
2233: NewLineSkipped = skippedNL;
2234: cssRule = ParseCSSFontVariant (element, tsch, context, cssRule, css, isHTML);
2235: }
1.72 cvs 2236: if (ptr == cssRule)
1.93 vatton 2237: {
2238: NewLineSkipped = skippedNL;
2239: cssRule = ParseCSSFontWeight (element, tsch, context, cssRule, css, isHTML);
2240: }
1.72 cvs 2241: if (ptr == cssRule)
1.93 vatton 2242: {
2243: NewLineSkipped = skippedNL;
2244: cssRule = ParseCSSFontSize (element, tsch, context, cssRule, css, isHTML);
2245: }
1.72 cvs 2246: if (ptr == cssRule)
1.93 vatton 2247: {
2248: NewLineSkipped = skippedNL;
2249: cssRule = ParseCSSFontFamily (element, tsch, context, cssRule, css, isHTML);
2250: }
1.99 vatton 2251: if (ptr == cssRule)
1.168 vatton 2252: cssRule = SkipValue ("Invalid font value", cssRule);
1.82 cvs 2253: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 2254: }
2255: }
2256: return (cssRule);
1.1 cvs 2257: }
2258:
2259: /*----------------------------------------------------------------------
1.59 cvs 2260: ParseCSSTextDecoration: parse a CSS text decor string
2261: we expect the input string describing the attribute to be
1.109 cvs 2262: underline, overline, line-through, blink or none.
1.1 cvs 2263: ----------------------------------------------------------------------*/
1.79 cvs 2264: static char *ParseCSSTextDecoration (Element element, PSchema tsch,
2265: PresentationContext context, char *cssRule,
2266: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2267: {
2268: PresentationValue decor;
1.168 vatton 2269: char *ptr;
1.1 cvs 2270:
2271: decor.typed_data.value = 0;
1.184 vatton 2272: decor.typed_data.unit = UNIT_REL;
1.1 cvs 2273: decor.typed_data.real = FALSE;
1.82 cvs 2274: cssRule = SkipBlanksAndComments (cssRule);
1.142 quint 2275: if (!strncasecmp (cssRule, "none", strlen ("none")))
2276: {
2277: decor.typed_data.value = NoUnderline;
2278: cssRule = SkipWord (cssRule);
2279: }
2280: else if (!strncasecmp (cssRule, "underline", strlen ("underline")))
1.1 cvs 2281: {
2282: decor.typed_data.value = Underline;
2283: cssRule = SkipWord (cssRule);
2284: }
1.82 cvs 2285: else if (!strncasecmp (cssRule, "overline", strlen ("overline")))
1.1 cvs 2286: {
2287: decor.typed_data.value = Overline;
2288: cssRule = SkipWord (cssRule);
2289: }
1.82 cvs 2290: else if (!strncasecmp (cssRule, "line-through", strlen ("line-through")))
1.1 cvs 2291: {
2292: decor.typed_data.value = CrossOut;
2293: cssRule = SkipWord (cssRule);
2294: }
1.82 cvs 2295: else if (!strncasecmp (cssRule, "blink", strlen ("blink")))
1.1 cvs 2296: {
1.109 cvs 2297: /* the blink text-decoration attribute is not supported */
1.1 cvs 2298: cssRule = SkipWord (cssRule);
2299: }
1.142 quint 2300: else if (!strncasecmp (cssRule, "inherit", 7))
1.1 cvs 2301: {
1.142 quint 2302: cssRule = SkipWord (cssRule);
2303: return (cssRule);
1.1 cvs 2304: }
2305: else
2306: {
1.168 vatton 2307: ptr = cssRule;
2308: cssRule = SkipWord (cssRule);
2309: CSSParseError ("Invalid text-decoration value", ptr, cssRule);
1.1 cvs 2310: return (cssRule);
2311: }
2312:
2313: /*
2314: * install the new presentation.
2315: */
1.116 vatton 2316: if (decor.typed_data.value && DoApply)
1.1 cvs 2317: {
1.117 vatton 2318: if (tsch)
2319: cssRule = CheckImportantRule (cssRule, context);
1.1 cvs 2320: TtaSetStylePresentation (PRUnderline, element, tsch, context, decor);
2321: }
2322: return (cssRule);
2323: }
2324:
2325: /*----------------------------------------------------------------------
1.59 cvs 2326: ParseCSSHeight: parse a CSS height attribute
1.1 cvs 2327: ----------------------------------------------------------------------*/
1.79 cvs 2328: static char *ParseCSSHeight (Element element, PSchema tsch,
1.93 vatton 2329: PresentationContext context, char *cssRule,
2330: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2331: {
1.117 vatton 2332: PresentationValue val;
1.168 vatton 2333: char *ptr;
1.93 vatton 2334:
1.117 vatton 2335: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 2336: ptr = cssRule;
1.117 vatton 2337: /* first parse the attribute string */
1.164 quint 2338: if (!strncasecmp (cssRule, "auto", 4))
2339: {
1.184 vatton 2340: val.typed_data.unit = VALUE_AUTO;
1.164 quint 2341: val.typed_data.value = 0;
2342: val.typed_data.real = FALSE;
2343: cssRule = SkipWord (cssRule);
2344: }
1.117 vatton 2345: else
1.168 vatton 2346: cssRule = ParseCSSUnit (cssRule, &val);
2347: if (val.typed_data.value != 0 &&
1.184 vatton 2348: (val.typed_data.unit == UNIT_INVALID ||
2349: val.typed_data.unit == UNIT_BOX))
1.168 vatton 2350: CSSParseError ("height value", ptr, cssRule);
2351: else if (DoApply)
1.117 vatton 2352: {
1.164 quint 2353: if (tsch)
2354: cssRule = CheckImportantRule (cssRule, context);
2355: /* install the new presentation */
2356: TtaSetStylePresentation (PRHeight, element, tsch, context, val);
1.117 vatton 2357: }
2358: return (cssRule);
1.1 cvs 2359: }
2360:
2361: /*----------------------------------------------------------------------
1.59 cvs 2362: ParseCSSWidth: parse a CSS width attribute
1.1 cvs 2363: ----------------------------------------------------------------------*/
1.79 cvs 2364: static char *ParseCSSWidth (Element element, PSchema tsch,
1.78 cvs 2365: PresentationContext context,
1.79 cvs 2366: char *cssRule, CSSInfoPtr css,
1.78 cvs 2367: ThotBool isHTML)
1.1 cvs 2368: {
1.117 vatton 2369: PresentationValue val;
1.168 vatton 2370: char *ptr;
1.93 vatton 2371:
1.117 vatton 2372: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 2373: ptr = cssRule;
1.117 vatton 2374: /* first parse the attribute string */
1.164 quint 2375: if (!strncasecmp (cssRule, "auto", 4))
2376: {
1.184 vatton 2377: val.typed_data.unit = VALUE_AUTO;
1.164 quint 2378: val.typed_data.value = 0;
2379: val.typed_data.real = FALSE;
2380: cssRule = SkipWord (cssRule);
2381: }
1.117 vatton 2382: else
1.164 quint 2383: cssRule = ParseCSSUnit (cssRule, &val);
1.168 vatton 2384: if (val.typed_data.value != 0 &&
1.184 vatton 2385: (val.typed_data.unit == UNIT_INVALID ||
2386: val.typed_data.unit == UNIT_BOX))
1.168 vatton 2387: CSSParseError ("Invalid width value", ptr, cssRule);
2388: else if (DoApply)
1.117 vatton 2389: {
1.164 quint 2390: if (tsch)
2391: cssRule = CheckImportantRule (cssRule, context);
2392: /* install the new presentation */
2393: TtaSetStylePresentation (PRWidth, element, tsch, context, val);
1.117 vatton 2394: }
2395: return (cssRule);
1.1 cvs 2396: }
2397:
2398: /*----------------------------------------------------------------------
1.59 cvs 2399: ParseCSSMarginTop: parse a CSS margin-top attribute
1.1 cvs 2400: ----------------------------------------------------------------------*/
1.79 cvs 2401: static char *ParseCSSMarginTop (Element element, PSchema tsch,
1.78 cvs 2402: PresentationContext context,
1.79 cvs 2403: char *cssRule, CSSInfoPtr css,
1.78 cvs 2404: ThotBool isHTML)
1.1 cvs 2405: {
2406: PresentationValue margin;
1.168 vatton 2407: char *ptr;
1.1 cvs 2408:
1.82 cvs 2409: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 2410: ptr = cssRule;
1.1 cvs 2411: /* first parse the attribute string */
1.164 quint 2412: if (!strncasecmp (cssRule, "auto", 4))
2413: {
1.184 vatton 2414: margin.typed_data.unit = VALUE_AUTO;
1.164 quint 2415: margin.typed_data.value = 0;
2416: margin.typed_data.real = FALSE;
2417: cssRule = SkipWord (cssRule);
2418: }
2419: else
1.168 vatton 2420: cssRule = ParseCSSUnit (cssRule, &margin);
2421: if (margin.typed_data.value != 0 &&
1.184 vatton 2422: (margin.typed_data.unit == UNIT_INVALID ||
2423: margin.typed_data.unit == UNIT_BOX))
1.169 vatton 2424: CSSParseError ("Invalid margin-top value", ptr, cssRule);
1.168 vatton 2425: else if (DoApply)
1.117 vatton 2426: {
2427: if (tsch)
2428: cssRule = CheckImportantRule (cssRule, context);
2429: TtaSetStylePresentation (PRMarginTop, element, tsch, context, margin);
2430: }
1.1 cvs 2431: return (cssRule);
2432: }
2433:
2434: /*----------------------------------------------------------------------
1.59 cvs 2435: ParseCSSMarginBottom: parse a CSS margin-bottom attribute
1.1 cvs 2436: ----------------------------------------------------------------------*/
1.79 cvs 2437: static char *ParseCSSMarginBottom (Element element, PSchema tsch,
1.78 cvs 2438: PresentationContext context,
1.79 cvs 2439: char *cssRule, CSSInfoPtr css,
1.78 cvs 2440: ThotBool isHTML)
1.1 cvs 2441: {
2442: PresentationValue margin;
1.168 vatton 2443: char *ptr;
1.1 cvs 2444:
1.82 cvs 2445: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 2446: ptr = cssRule;
1.1 cvs 2447: /* first parse the attribute string */
1.164 quint 2448: if (!strncasecmp (cssRule, "auto", 4))
2449: {
1.184 vatton 2450: margin.typed_data.unit = VALUE_AUTO;
1.164 quint 2451: margin.typed_data.value = 0;
2452: margin.typed_data.real = FALSE;
2453: cssRule = SkipWord (cssRule);
2454: }
2455: else
1.168 vatton 2456: cssRule = ParseCSSUnit (cssRule, &margin);
2457: if (margin.typed_data.value != 0 &&
1.184 vatton 2458: (margin.typed_data.unit == UNIT_INVALID ||
2459: margin.typed_data.unit == UNIT_BOX))
1.169 vatton 2460: CSSParseError ("Invalid margin-bottom value", ptr, cssRule);
1.168 vatton 2461: else if (DoApply)
1.117 vatton 2462: {
2463: if (tsch)
2464: cssRule = CheckImportantRule (cssRule, context);
2465: TtaSetStylePresentation (PRMarginBottom, element, tsch, context, margin);
2466: }
1.1 cvs 2467: return (cssRule);
2468: }
2469:
2470: /*----------------------------------------------------------------------
1.59 cvs 2471: ParseCSSMarginLeft: parse a CSS margin-left attribute string
1.1 cvs 2472: ----------------------------------------------------------------------*/
1.79 cvs 2473: static char *ParseCSSMarginLeft (Element element, PSchema tsch,
1.78 cvs 2474: PresentationContext context,
1.79 cvs 2475: char *cssRule, CSSInfoPtr css,
1.78 cvs 2476: ThotBool isHTML)
1.1 cvs 2477: {
2478: PresentationValue margin;
1.168 vatton 2479: char *ptr;
1.1 cvs 2480:
1.82 cvs 2481: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 2482: ptr = cssRule;
1.1 cvs 2483: /* first parse the attribute string */
1.164 quint 2484: if (!strncasecmp (cssRule, "auto", 4))
2485: {
1.184 vatton 2486: margin.typed_data.unit = VALUE_AUTO;
1.164 quint 2487: margin.typed_data.value = 0;
2488: margin.typed_data.real = FALSE;
2489: cssRule = SkipWord (cssRule);
2490: }
2491: else
1.168 vatton 2492: cssRule = ParseCSSUnit (cssRule, &margin);
2493: if (margin.typed_data.value != 0 &&
1.184 vatton 2494: (margin.typed_data.unit == UNIT_INVALID ||
2495: margin.typed_data.unit == UNIT_BOX))
1.169 vatton 2496: CSSParseError ("Invalid margin-left value", ptr, cssRule);
1.168 vatton 2497: else if (DoApply)
1.184 vatton 2498: if (margin.typed_data.unit != UNIT_INVALID && DoApply)
1.117 vatton 2499: {
2500: if (tsch)
2501: cssRule = CheckImportantRule (cssRule, context);
2502: TtaSetStylePresentation (PRMarginLeft, element, tsch, context, margin);
2503: }
1.1 cvs 2504: return (cssRule);
2505: }
2506:
2507: /*----------------------------------------------------------------------
1.59 cvs 2508: ParseCSSMarginRight: parse a CSS margin-right attribute string
1.1 cvs 2509: ----------------------------------------------------------------------*/
1.79 cvs 2510: static char *ParseCSSMarginRight (Element element, PSchema tsch,
1.78 cvs 2511: PresentationContext context,
1.79 cvs 2512: char *cssRule, CSSInfoPtr css,
1.78 cvs 2513: ThotBool isHTML)
1.1 cvs 2514: {
2515: PresentationValue margin;
1.168 vatton 2516: char *ptr;
1.1 cvs 2517:
1.82 cvs 2518: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 2519: ptr = cssRule;
1.1 cvs 2520: /* first parse the attribute string */
1.164 quint 2521: if (!strncasecmp (cssRule, "auto", 4))
2522: {
1.184 vatton 2523: margin.typed_data.unit = VALUE_AUTO;
1.164 quint 2524: margin.typed_data.value = 0;
2525: margin.typed_data.real = FALSE;
2526: cssRule = SkipWord (cssRule);
2527: }
2528: else
1.168 vatton 2529: cssRule = ParseCSSUnit (cssRule, &margin);
2530: if (margin.typed_data.value != 0 &&
1.184 vatton 2531: (margin.typed_data.unit == UNIT_INVALID ||
2532: margin.typed_data.unit == UNIT_BOX))
1.169 vatton 2533: CSSParseError ("Invalid margin-right value", ptr, cssRule);
1.168 vatton 2534: else if (DoApply)
1.117 vatton 2535: {
2536: if (tsch)
2537: cssRule = CheckImportantRule (cssRule, context);
2538: TtaSetStylePresentation (PRMarginRight, element, tsch, context, margin);
2539: }
1.1 cvs 2540: return (cssRule);
2541: }
2542:
2543: /*----------------------------------------------------------------------
1.59 cvs 2544: ParseCSSMargin: parse a CSS margin attribute string
1.1 cvs 2545: ----------------------------------------------------------------------*/
1.79 cvs 2546: static char *ParseCSSMargin (Element element, PSchema tsch,
1.78 cvs 2547: PresentationContext context,
1.79 cvs 2548: char *cssRule, CSSInfoPtr css,
1.78 cvs 2549: ThotBool isHTML)
1.1 cvs 2550: {
1.79 cvs 2551: char *ptrT, *ptrR, *ptrB, *ptrL;
1.93 vatton 2552: int skippedNL;
1.1 cvs 2553:
1.82 cvs 2554: ptrT = SkipBlanksAndComments (cssRule);
1.1 cvs 2555: /* First parse Margin-Top */
2556: ptrR = ParseCSSMarginTop (element, tsch, context, ptrT, css, isHTML);
1.82 cvs 2557: ptrR = SkipBlanksAndComments (ptrR);
2558: if (*ptrR == ';' || *ptrR == EOS || *ptrR == ',')
1.1 cvs 2559: {
1.93 vatton 2560: skippedNL = NewLineSkipped;
1.1 cvs 2561: cssRule = ptrR;
2562: /* apply the Margin-Top to all */
2563: ptrR = ParseCSSMarginRight (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 2564: NewLineSkipped = skippedNL;
1.1 cvs 2565: ptrR = ParseCSSMarginBottom (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 2566: NewLineSkipped = skippedNL;
1.1 cvs 2567: ptrR = ParseCSSMarginLeft (element, tsch, context, ptrT, css, isHTML);
2568: }
2569: else
2570: {
2571: /* parse Margin-Right */
2572: ptrB = ParseCSSMarginRight (element, tsch, context, ptrR, css, isHTML);
1.82 cvs 2573: ptrB = SkipBlanksAndComments (ptrB);
2574: if (*ptrB == ';' || *ptrB == EOS || *ptrB == ',')
1.1 cvs 2575: {
1.93 vatton 2576: skippedNL = NewLineSkipped;
1.1 cvs 2577: cssRule = ptrB;
2578: /* apply the Margin-Top to Margin-Bottom */
2579: ptrB = ParseCSSMarginBottom (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 2580: NewLineSkipped = skippedNL;
1.1 cvs 2581: /* apply the Margin-Right to Margin-Left */
2582: ptrB = ParseCSSMarginLeft (element, tsch, context, ptrR, css, isHTML);
2583: }
2584: else
2585: {
2586: /* parse Margin-Bottom */
2587: ptrL = ParseCSSMarginBottom (element, tsch, context, ptrB, css, isHTML);
1.82 cvs 2588: ptrL = SkipBlanksAndComments (ptrL);
2589: if (*ptrL == ';' || *ptrL == EOS || *ptrL == ',')
1.1 cvs 2590: {
2591: cssRule = ptrL;
2592: /* apply the Margin-Right to Margin-Left */
2593: ptrL = ParseCSSMarginLeft (element, tsch, context, ptrR, css, isHTML);
2594: }
2595: else
2596: /* parse Margin-Left */
2597: cssRule = ParseCSSMarginLeft (element, tsch, context, ptrL, css, isHTML);
1.82 cvs 2598: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 2599: }
2600: }
2601: return (cssRule);
2602: }
2603:
2604: /*----------------------------------------------------------------------
1.59 cvs 2605: ParseCSSPaddingTop: parse a CSS PaddingTop attribute string
1.1 cvs 2606: ----------------------------------------------------------------------*/
1.79 cvs 2607: static char *ParseCSSPaddingTop (Element element, PSchema tsch,
1.78 cvs 2608: PresentationContext context,
1.79 cvs 2609: char *cssRule, CSSInfoPtr css,
1.78 cvs 2610: ThotBool isHTML)
1.1 cvs 2611: {
1.43 cvs 2612: PresentationValue padding;
1.168 vatton 2613: char *ptr;
1.43 cvs 2614:
1.82 cvs 2615: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 2616: ptr = cssRule;
1.43 cvs 2617: /* first parse the attribute string */
2618: cssRule = ParseCSSUnit (cssRule, &padding);
1.168 vatton 2619: if (padding.typed_data.value != 0 &&
1.184 vatton 2620: (padding.typed_data.unit == UNIT_INVALID ||
2621: padding.typed_data.unit == UNIT_BOX))
1.168 vatton 2622: {
1.169 vatton 2623: CSSParseError ("Invalid padding-top value", ptr, cssRule);
1.168 vatton 2624: padding.typed_data.value = 0;
2625: }
2626: else if (DoApply)
1.117 vatton 2627: {
2628: if (tsch)
2629: cssRule = CheckImportantRule (cssRule, context);
2630: TtaSetStylePresentation (PRPaddingTop, element, tsch, context, padding);
2631: }
1.1 cvs 2632: return (cssRule);
2633: }
2634:
2635: /*----------------------------------------------------------------------
1.59 cvs 2636: ParseCSSPaddingBottom: parse a CSS PaddingBottom attribute string
1.1 cvs 2637: ----------------------------------------------------------------------*/
1.79 cvs 2638: static char *ParseCSSPaddingBottom (Element element, PSchema tsch,
1.78 cvs 2639: PresentationContext context,
1.79 cvs 2640: char *cssRule, CSSInfoPtr css,
1.78 cvs 2641: ThotBool isHTML)
1.1 cvs 2642: {
1.43 cvs 2643: PresentationValue padding;
1.168 vatton 2644: char *ptr;
1.43 cvs 2645:
1.82 cvs 2646: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 2647: ptr = cssRule;
1.43 cvs 2648: /* first parse the attribute string */
2649: cssRule = ParseCSSUnit (cssRule, &padding);
1.168 vatton 2650: if (padding.typed_data.value == 0)
1.184 vatton 2651: padding.typed_data.unit = UNIT_EM;
1.168 vatton 2652: if (padding.typed_data.value != 0 &&
1.184 vatton 2653: (padding.typed_data.unit == UNIT_INVALID ||
2654: padding.typed_data.unit == UNIT_BOX))
1.168 vatton 2655: {
1.169 vatton 2656: CSSParseError ("Invalid padding-bottom value", ptr, cssRule);
1.168 vatton 2657: padding.typed_data.value = 0;
2658: }
2659: else if (DoApply)
1.117 vatton 2660: {
2661: if (tsch)
2662: cssRule = CheckImportantRule (cssRule, context);
2663: TtaSetStylePresentation (PRPaddingBottom, element, tsch, context, padding);
2664: }
1.1 cvs 2665: return (cssRule);
2666: }
2667:
2668: /*----------------------------------------------------------------------
1.59 cvs 2669: ParseCSSPaddingLeft: parse a CSS PaddingLeft attribute string.
1.1 cvs 2670: ----------------------------------------------------------------------*/
1.79 cvs 2671: static char *ParseCSSPaddingLeft (Element element, PSchema tsch,
1.78 cvs 2672: PresentationContext context,
1.79 cvs 2673: char *cssRule, CSSInfoPtr css,
1.78 cvs 2674: ThotBool isHTML)
1.1 cvs 2675: {
1.43 cvs 2676: PresentationValue padding;
1.168 vatton 2677: char *ptr;
1.43 cvs 2678:
1.82 cvs 2679: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 2680: ptr = cssRule;
1.43 cvs 2681: /* first parse the attribute string */
2682: cssRule = ParseCSSUnit (cssRule, &padding);
1.168 vatton 2683: if (padding.typed_data.value == 0)
1.184 vatton 2684: padding.typed_data.unit = UNIT_EM;
1.168 vatton 2685: if (padding.typed_data.value != 0 &&
1.184 vatton 2686: (padding.typed_data.unit == UNIT_INVALID ||
2687: padding.typed_data.unit == UNIT_BOX))
1.168 vatton 2688: {
1.169 vatton 2689: CSSParseError ("Invalid padding-left value", ptr, cssRule);
1.168 vatton 2690: padding.typed_data.value = 0;
2691: }
2692: else if (DoApply)
1.117 vatton 2693: {
2694: if (tsch)
2695: cssRule = CheckImportantRule (cssRule, context);
1.43 cvs 2696: TtaSetStylePresentation (PRPaddingLeft, element, tsch, context, padding);
1.117 vatton 2697: }
1.1 cvs 2698: return (cssRule);
2699: }
2700:
2701: /*----------------------------------------------------------------------
1.59 cvs 2702: ParseCSSPaddingRight: parse a CSS PaddingRight attribute string.
1.1 cvs 2703: ----------------------------------------------------------------------*/
1.79 cvs 2704: static char *ParseCSSPaddingRight (Element element, PSchema tsch,
1.78 cvs 2705: PresentationContext context,
1.79 cvs 2706: char *cssRule, CSSInfoPtr css,
1.78 cvs 2707: ThotBool isHTML)
1.1 cvs 2708: {
1.43 cvs 2709: PresentationValue padding;
1.168 vatton 2710: char *ptr;
1.43 cvs 2711:
1.82 cvs 2712: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 2713: ptr = cssRule;
1.43 cvs 2714: /* first parse the attribute string */
2715: cssRule = ParseCSSUnit (cssRule, &padding);
1.168 vatton 2716: if (padding.typed_data.value == 0)
1.184 vatton 2717: padding.typed_data.unit = UNIT_EM;
1.168 vatton 2718: if (padding.typed_data.value != 0 &&
1.184 vatton 2719: (padding.typed_data.unit == UNIT_INVALID ||
2720: padding.typed_data.unit == UNIT_BOX))
1.168 vatton 2721: {
1.169 vatton 2722: CSSParseError ("Invalid padding-right value", ptr, cssRule);
1.168 vatton 2723: padding.typed_data.value = 0;
2724: }
2725: else if (DoApply)
1.117 vatton 2726: {
2727: if (tsch)
2728: cssRule = CheckImportantRule (cssRule, context);
1.43 cvs 2729: TtaSetStylePresentation (PRPaddingRight, element, tsch, context, padding);
1.117 vatton 2730: }
1.1 cvs 2731: return (cssRule);
2732: }
2733:
2734: /*----------------------------------------------------------------------
1.59 cvs 2735: ParseCSSPadding: parse a CSS padding attribute string.
1.1 cvs 2736: ----------------------------------------------------------------------*/
1.79 cvs 2737: static char *ParseCSSPadding (Element element, PSchema tsch,
1.78 cvs 2738: PresentationContext context,
1.79 cvs 2739: char *cssRule, CSSInfoPtr css,
1.78 cvs 2740: ThotBool isHTML)
1.1 cvs 2741: {
1.79 cvs 2742: char *ptrT, *ptrR, *ptrB, *ptrL;
1.93 vatton 2743: int skippedNL;
1.43 cvs 2744:
1.82 cvs 2745: ptrT = SkipBlanksAndComments (cssRule);
1.43 cvs 2746: /* First parse Padding-Top */
2747: ptrR = ParseCSSPaddingTop (element, tsch, context, ptrT, css, isHTML);
1.82 cvs 2748: ptrR = SkipBlanksAndComments (ptrR);
2749: if (*ptrR == ';' || *ptrR == EOS || *ptrR == ',')
1.43 cvs 2750: {
1.93 vatton 2751: skippedNL = NewLineSkipped;
1.43 cvs 2752: cssRule = ptrR;
2753: /* apply the Padding-Top to all */
2754: ptrR = ParseCSSPaddingRight (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 2755: NewLineSkipped = skippedNL;
1.43 cvs 2756: ptrR = ParseCSSPaddingBottom (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 2757: NewLineSkipped = skippedNL;
1.43 cvs 2758: ptrR = ParseCSSPaddingLeft (element, tsch, context, ptrT, css, isHTML);
2759: }
2760: else
2761: {
2762: /* parse Padding-Right */
2763: ptrB = ParseCSSPaddingRight (element, tsch, context, ptrR, css, isHTML);
1.82 cvs 2764: ptrB = SkipBlanksAndComments (ptrB);
2765: if (*ptrB == ';' || *ptrB == EOS || *ptrB == ',')
1.43 cvs 2766: {
1.93 vatton 2767: skippedNL = NewLineSkipped;
1.43 cvs 2768: cssRule = ptrB;
2769: /* apply the Padding-Top to Padding-Bottom */
2770: ptrB = ParseCSSPaddingBottom (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 2771: NewLineSkipped = skippedNL;
1.43 cvs 2772: /* apply the Padding-Right to Padding-Left */
2773: ptrB = ParseCSSPaddingLeft (element, tsch, context, ptrR, css, isHTML);
2774: }
2775: else
2776: {
2777: /* parse Padding-Bottom */
2778: ptrL = ParseCSSPaddingBottom (element, tsch, context, ptrB, css, isHTML);
1.82 cvs 2779: ptrL = SkipBlanksAndComments (ptrL);
2780: if (*ptrL == ';' || *ptrL == EOS || *ptrL == ',')
1.43 cvs 2781: {
2782: cssRule = ptrL;
2783: /* apply the Padding-Right to Padding-Left */
2784: ptrL = ParseCSSPaddingLeft (element, tsch, context, ptrR, css, isHTML);
2785: }
2786: else
2787: /* parse Padding-Left */
2788: cssRule = ParseCSSPaddingLeft (element, tsch, context, ptrL, css, isHTML);
1.82 cvs 2789: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 2790: }
2791: }
1.1 cvs 2792: return (cssRule);
2793: }
2794:
2795: /*----------------------------------------------------------------------
1.59 cvs 2796: ParseCSSForeground: parse a CSS foreground attribute
1.1 cvs 2797: ----------------------------------------------------------------------*/
1.79 cvs 2798: static char *ParseCSSForeground (Element element, PSchema tsch,
1.78 cvs 2799: PresentationContext context,
1.79 cvs 2800: char *cssRule,
1.78 cvs 2801: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2802: {
1.117 vatton 2803: PresentationValue best;
1.1 cvs 2804:
1.117 vatton 2805: cssRule = ParseCSSColor (cssRule, &best);
1.184 vatton 2806: if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.117 vatton 2807: {
2808: if (tsch)
2809: cssRule = CheckImportantRule (cssRule, context);
2810: /* install the new presentation */
2811: TtaSetStylePresentation (PRForeground, element, tsch, context, best);
2812: }
1.1 cvs 2813: return (cssRule);
2814: }
2815:
2816: /*----------------------------------------------------------------------
1.59 cvs 2817: ParseCSSBackgroundColor: parse a CSS background color attribute
1.1 cvs 2818: ----------------------------------------------------------------------*/
1.79 cvs 2819: static char *ParseCSSBackgroundColor (Element element, PSchema tsch,
1.78 cvs 2820: PresentationContext context,
1.79 cvs 2821: char *cssRule,
1.78 cvs 2822: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2823: {
2824: PresentationValue best;
2825:
1.184 vatton 2826: best.typed_data.unit = UNIT_INVALID;
1.1 cvs 2827: best.typed_data.real = FALSE;
1.198 vatton 2828: if (!strncasecmp (cssRule, "transparent", 11))
1.1 cvs 2829: {
1.184 vatton 2830: best.typed_data.value = PATTERN_NONE;
2831: best.typed_data.unit = UNIT_REL;
1.116 vatton 2832: if (DoApply)
1.117 vatton 2833: {
2834: if (tsch)
2835: cssRule = CheckImportantRule (cssRule, context);
2836: TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
2837: }
1.65 cvs 2838: cssRule = SkipWord (cssRule);
1.1 cvs 2839: }
2840: else
2841: {
2842: cssRule = ParseCSSColor (cssRule, &best);
1.184 vatton 2843: if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.1 cvs 2844: {
1.117 vatton 2845: if (tsch)
2846: cssRule = CheckImportantRule (cssRule, context);
1.1 cvs 2847: /* install the new presentation. */
2848: TtaSetStylePresentation (PRBackground, element, tsch, context, best);
1.59 cvs 2849: /* thot specificity: need to set fill pattern for background color */
1.184 vatton 2850: best.typed_data.value = PATTERN_BACKGROUND;
2851: best.typed_data.unit = UNIT_REL;
1.1 cvs 2852: TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
2853: best.typed_data.value = 1;
1.184 vatton 2854: best.typed_data.unit = UNIT_REL;
1.1 cvs 2855: TtaSetStylePresentation (PRShowBox, element, tsch, context, best);
2856: }
2857: }
2858: return (cssRule);
2859: }
2860:
1.63 cvs 2861: /*----------------------------------------------------------------------
1.65 cvs 2862: ParseSVGStroke: parse a SVG stroke property
2863: ----------------------------------------------------------------------*/
1.79 cvs 2864: static char *ParseSVGStroke (Element element, PSchema tsch,
2865: PresentationContext context, char *cssRule,
2866: CSSInfoPtr css, ThotBool isHTML)
1.65 cvs 2867: {
2868: PresentationValue best;
2869:
1.184 vatton 2870: best.typed_data.unit = UNIT_INVALID;
1.65 cvs 2871: best.typed_data.real = FALSE;
1.82 cvs 2872: if (!strncasecmp (cssRule, "none", 4))
1.65 cvs 2873: {
2874: best.typed_data.value = -2; /* -2 means transparent */
1.184 vatton 2875: best.typed_data.unit = UNIT_REL;
1.116 vatton 2876: if (DoApply)
1.117 vatton 2877: {
2878: if (tsch)
2879: cssRule = CheckImportantRule (cssRule, context);
2880: TtaSetStylePresentation (PRForeground, element, tsch, context, best);
2881: }
1.65 cvs 2882: cssRule = SkipWord (cssRule);
2883: }
2884: else
2885: {
2886: cssRule = ParseCSSColor (cssRule, &best);
1.184 vatton 2887: if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.117 vatton 2888: {
2889: if (tsch)
2890: cssRule = CheckImportantRule (cssRule, context);
2891: /* install the new presentation */
2892: TtaSetStylePresentation (PRForeground, element, tsch, context, best);
2893: }
1.65 cvs 2894: }
2895: return (cssRule);
2896: }
2897:
2898: /*----------------------------------------------------------------------
1.63 cvs 2899: ParseSVGFill: parse a SVG fill property
2900: ----------------------------------------------------------------------*/
1.79 cvs 2901: static char *ParseSVGFill (Element element, PSchema tsch,
2902: PresentationContext context, char *cssRule,
2903: CSSInfoPtr css, ThotBool isHTML)
1.63 cvs 2904: {
2905: PresentationValue best;
2906:
1.184 vatton 2907: best.typed_data.unit = UNIT_INVALID;
1.63 cvs 2908: best.typed_data.real = FALSE;
1.82 cvs 2909: if (!strncasecmp (cssRule, "none", 4))
1.63 cvs 2910: {
1.184 vatton 2911: best.typed_data.value = PATTERN_NONE;
2912: best.typed_data.unit = UNIT_REL;
1.116 vatton 2913: if (DoApply)
1.117 vatton 2914: {
2915: if (tsch)
2916: cssRule = CheckImportantRule (cssRule, context);
2917: TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
2918: }
1.65 cvs 2919: cssRule = SkipWord (cssRule);
1.63 cvs 2920: }
2921: else
2922: {
2923: cssRule = ParseCSSColor (cssRule, &best);
1.184 vatton 2924: if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.63 cvs 2925: {
1.117 vatton 2926: if (tsch)
2927: cssRule = CheckImportantRule (cssRule, context);
1.63 cvs 2928: /* install the new presentation. */
2929: TtaSetStylePresentation (PRBackground, element, tsch, context, best);
2930: /* thot specificity: need to set fill pattern for background color */
1.184 vatton 2931: best.typed_data.value = PATTERN_BACKGROUND;
2932: best.typed_data.unit = UNIT_REL;
1.63 cvs 2933: TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
2934: }
2935: }
2936: return (cssRule);
2937: }
1.161 quint 2938:
1.155 cheyroul 2939: /*----------------------------------------------------------------------
2940: ParseSVGOpacity: parse a SVG fill property
2941: ----------------------------------------------------------------------*/
2942: static char *ParseSVGOpacity (Element element, PSchema tsch,
2943: PresentationContext context, char *cssRule,
2944: CSSInfoPtr css, ThotBool isHTML)
2945: {
2946: PresentationValue best;
1.63 cvs 2947:
1.184 vatton 2948: best.typed_data.unit = UNIT_INVALID;
1.155 cheyroul 2949: best.typed_data.real = FALSE;
2950: cssRule = ParseClampedUnit (cssRule, &best);
2951: if (DoApply)
2952: {
2953: if (tsch)
2954: cssRule = CheckImportantRule (cssRule, context);
2955: /* install the new presentation. */
2956: TtaSetStylePresentation (PROpacity, element,
2957: tsch, context, best);
2958: }
2959: return (cssRule);
2960: }
1.170 cheyroul 2961: /*----------------------------------------------------------------------
2962: ParseSVGOpacity: parse a SVG fill property
2963: ----------------------------------------------------------------------*/
2964: static char *ParseSVGStrokeOpacity (Element element, PSchema tsch,
2965: PresentationContext context, char *cssRule,
2966: CSSInfoPtr css, ThotBool isHTML)
2967: {
2968: PresentationValue best;
1.161 quint 2969:
1.184 vatton 2970: best.typed_data.unit = UNIT_INVALID;
1.170 cheyroul 2971: best.typed_data.real = FALSE;
2972: cssRule = ParseClampedUnit (cssRule, &best);
2973: if (DoApply)
2974: {
2975: if (tsch)
2976: cssRule = CheckImportantRule (cssRule, context);
2977: /* install the new presentation. */
2978: TtaSetStylePresentation (PRStrokeOpacity, element,
2979: tsch, context, best);
2980: }
2981: return (cssRule);
2982: }
2983: /*----------------------------------------------------------------------
2984: ParseSVGOpacity: parse a SVG fill property
2985: ----------------------------------------------------------------------*/
2986: static char *ParseSVGFillOpacity (Element element, PSchema tsch,
2987: PresentationContext context, char *cssRule,
2988: CSSInfoPtr css, ThotBool isHTML)
2989: {
2990: PresentationValue best;
2991:
1.184 vatton 2992: best.typed_data.unit = UNIT_INVALID;
1.170 cheyroul 2993: best.typed_data.real = FALSE;
2994: cssRule = ParseClampedUnit (cssRule, &best);
2995: if (DoApply)
2996: {
2997: if (tsch)
2998: cssRule = CheckImportantRule (cssRule, context);
2999: /* install the new presentation. */
3000: TtaSetStylePresentation (PRFillOpacity, element,
3001: tsch, context, best);
3002: }
3003: return (cssRule);
3004: }
1.1 cvs 3005: /*----------------------------------------------------------------------
1.59 cvs 3006: ParseCSSBackgroundImageCallback: Callback called asynchronously by
3007: FetchImage when a background image has been fetched.
1.1 cvs 3008: ----------------------------------------------------------------------*/
1.82 cvs 3009: void ParseCSSBackgroundImageCallback (Document doc, Element element,
1.203 vatton 3010: char *file, void *extra,
3011: ThotBool isnew)
1.1 cvs 3012: {
1.82 cvs 3013: DisplayMode dispMode;
3014: BackgroundImageCallbackPtr callblock;
3015: Element el;
3016: PSchema tsch;
1.185 vatton 3017: CSSInfoPtr css;
1.206 ! vatton 3018: PInfoPtr pInfo;
1.82 cvs 3019: PresentationContext context;
3020: PresentationValue image;
3021: PresentationValue value;
1.206 ! vatton 3022: ThotBool enabled;
1.82 cvs 3023: callblock = (BackgroundImageCallbackPtr) extra;
1.34 cvs 3024: if (callblock == NULL)
3025: return;
1.1 cvs 3026:
1.188 cheyroul 3027: css = NULL;
1.34 cvs 3028: el = callblock->el;
3029: tsch = callblock->tsch;
3030: context = &callblock->context.specific;
1.203 vatton 3031: if (doc == 0 && !isnew)
3032: /* apply to the current document only */
3033: doc = context->doc;
1.185 vatton 3034: if (doc)
3035: {
3036: /* avoid too many redisplay */
3037: dispMode = TtaGetDisplayMode (doc);
3038: if (dispMode == DisplayImmediately)
3039: TtaSetDisplayMode (doc, DeferredDisplay);
3040: }
3041: else
3042: {
3043: /* check if the CSS still exists */
3044: css = CSSList;
3045: while (css && css != callblock->css)
3046: css = css->NextCSS;
3047: if (css == NULL)
3048: tsch = NULL;
3049: }
1.34 cvs 3050:
1.185 vatton 3051: if (el || tsch)
3052: {
3053: /* Ok the image was fetched, finish the background-image handling */
1.193 vatton 3054: image.typed_data.unit = UNIT_REL;
3055: image.typed_data.real = FALSE;
1.185 vatton 3056: image.pointer = file;
3057: TtaSetStylePresentation (PRBackgroundPicture, el, tsch, context, image);
3058:
3059: /* enforce the showbox */
3060: value.typed_data.value = 1;
3061: value.typed_data.unit = UNIT_REL;
3062: value.typed_data.real = FALSE;
1.193 vatton 3063: TtaSetStylePresentation (PRShowBox, el, tsch, context, value);
1.185 vatton 3064: }
1.34 cvs 3065:
3066: TtaFreeMemory (callblock);
3067: /* restore the display mode */
1.185 vatton 3068: if (doc)
3069: {
3070: if (dispMode == DisplayImmediately)
3071: TtaSetDisplayMode (doc, dispMode);
3072: }
3073: else if (css)
3074: {
3075: for (doc = 1; doc < DocumentTableLength; doc++)
1.206 ! vatton 3076: if (css->infos[doc] &&
1.185 vatton 3077: /* don't manage a document used by make book */
3078: (DocumentMeta[doc] == NULL ||
3079: DocumentMeta[doc]->method != CE_MAKEBOOK))
3080: {
1.206 ! vatton 3081: pInfo = css->infos[doc];
! 3082: enabled = FALSE;
! 3083: while (pInfo && !enabled)
! 3084: {
! 3085: enabled = pInfo->PiEnabled;
! 3086: pInfo = pInfo->PiNext;
! 3087: }
1.185 vatton 3088: /* Change the Display Mode to take into account the new presentation */
3089: dispMode = TtaGetDisplayMode (doc);
3090: if (dispMode == DisplayImmediately)
1.194 vatton 3091: {
3092: TtaSetDisplayMode (doc, NoComputedDisplay);
3093: /* Restore the display mode */
3094: TtaSetDisplayMode (doc, dispMode);
3095: }
1.185 vatton 3096: }
3097: }
1.1 cvs 3098: }
3099:
3100: /*----------------------------------------------------------------------
3101: GetCSSBackgroundURL searches a CSS BackgroundImage url within
3102: the styleString.
3103: Returns NULL or a new allocated url string.
3104: ----------------------------------------------------------------------*/
1.79 cvs 3105: char *GetCSSBackgroundURL (char *styleString)
1.1 cvs 3106: {
1.79 cvs 3107: char *b, *e, *ptr;
3108: int len;
1.1 cvs 3109:
3110: ptr = NULL;
1.82 cvs 3111: b = strstr (styleString, "url");
1.1 cvs 3112: if (b != NULL)
3113: {
3114: b += 3;
1.82 cvs 3115: b = SkipBlanksAndComments (b);
3116: if (*b == '(')
1.1 cvs 3117: {
3118: b++;
1.82 cvs 3119: b = SkipBlanksAndComments (b);
1.161 quint 3120: /*** Escaped quotes are not handled. See function SkipQuotedString */
1.82 cvs 3121: if (*b == '"')
1.1 cvs 3122: {
3123: b++;
3124: /* search the url end */
3125: e = b;
1.82 cvs 3126: while (*e != EOS && *e != '"')
1.1 cvs 3127: e++;
3128: }
1.161 quint 3129: else if (*b == '\'')
3130: {
3131: b++;
3132: /* search the url end */
3133: e = b;
3134: while (*e != EOS && *e != '\'')
3135: e++;
3136: }
1.1 cvs 3137: else
3138: {
3139: /* search the url end */
3140: e = b;
1.82 cvs 3141: while (*e != EOS && *e != ')')
1.1 cvs 3142: e++;
3143: }
1.82 cvs 3144: if (*e != EOS)
1.1 cvs 3145: {
3146: len = (int)(e - b);
1.82 cvs 3147: ptr = (char*) TtaGetMemory (len+1);
3148: strncpy (ptr, b, len);
3149: ptr[len] = EOS;
1.1 cvs 3150: }
3151: }
3152: }
3153: return (ptr);
3154: }
3155:
3156:
3157: /*----------------------------------------------------------------------
1.59 cvs 3158: ParseCSSBackgroundImage: parse a CSS BackgroundImage attribute string.
1.1 cvs 3159: ----------------------------------------------------------------------*/
1.79 cvs 3160: static char *ParseCSSBackgroundImage (Element element, PSchema tsch,
3161: PresentationContext context,
3162: char *cssRule, CSSInfoPtr css,
3163: ThotBool isHTML)
1.1 cvs 3164: {
1.149 vatton 3165: GenericContext ctxt = (GenericContext) context;
1.49 cvs 3166: Element el;
1.1 cvs 3167: BackgroundImageCallbackPtr callblock;
1.49 cvs 3168: PresentationValue image, value;
1.79 cvs 3169: char *url;
1.82 cvs 3170: char *bg_image;
1.79 cvs 3171: char saved;
3172: char *base;
3173: char tempname[MAX_LENGTH];
3174: char imgname[MAX_LENGTH];
1.148 vatton 3175:
1.163 quint 3176: if (element)
1.148 vatton 3177: el = element;
1.163 quint 3178: else
3179: /* default element for FetchImage */
3180: el = TtaGetMainRoot (context->doc);
3181:
1.1 cvs 3182: url = NULL;
1.82 cvs 3183: cssRule = SkipBlanksAndComments (cssRule);
1.161 quint 3184: if (!strncasecmp (cssRule, "none", 4))
3185: {
3186: image.pointer = NULL;
3187: TtaSetStylePresentation (PRBackgroundPicture, element, tsch, context,
3188: image);
1.198 vatton 3189: cssRule += 4;
1.161 quint 3190: }
3191: else if (!strncasecmp (cssRule, "url", 3))
1.1 cvs 3192: {
3193: cssRule += 3;
1.82 cvs 3194: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 3195: if (*cssRule == '(')
3196: {
3197: cssRule++;
1.82 cvs 3198: cssRule = SkipBlanksAndComments (cssRule);
1.161 quint 3199: /*** Escaped quotes are not handled. See function SkipQuotedString */
1.1 cvs 3200: if (*cssRule == '"')
3201: {
3202: cssRule++;
3203: base = cssRule;
1.82 cvs 3204: while (*cssRule != EOS && *cssRule != '"')
1.1 cvs 3205: cssRule++;
3206: }
1.161 quint 3207: else if (*cssRule == '\'')
3208: {
3209: cssRule++;
3210: base = cssRule;
3211: while (*cssRule != EOS && *cssRule != '\'')
3212: cssRule++;
3213: }
1.1 cvs 3214: else
3215: {
3216: base = cssRule;
3217: while (*cssRule != EOS && *cssRule != ')')
3218: cssRule++;
3219: }
3220: saved = *cssRule;
1.82 cvs 3221: *cssRule = EOS;
3222: url = TtaStrdup (base);
1.1 cvs 3223: *cssRule = saved;
1.161 quint 3224: if (saved == '"' || saved == '\'')
3225: /* we need to skip the quote character and possinble spaces */
3226: {
3227: cssRule++;
3228: cssRule = SkipBlanksAndComments (cssRule);
3229: }
1.1 cvs 3230: }
3231: cssRule++;
3232:
3233: if (context->destroy)
3234: {
3235: /* remove the background image PRule */
3236: image.pointer = NULL;
3237: TtaSetStylePresentation (PRBackgroundPicture, element, tsch, context, image);
3238: if (TtaGetStylePresentation (PRFillPattern, element, tsch, context, &value) < 0)
3239: {
3240: /* there is no FillPattern rule -> remove ShowBox rule */
3241: value.typed_data.value = 1;
1.184 vatton 3242: value.typed_data.unit = UNIT_REL;
1.1 cvs 3243: value.typed_data.real = FALSE;
3244: TtaSetStylePresentation (PRShowBox, element, tsch, context, value);
3245: }
3246: }
3247: else if (url)
3248: {
1.30 cvs 3249: bg_image = TtaGetEnvString ("ENABLE_BG_IMAGES");
1.82 cvs 3250: if (bg_image == NULL || !strcasecmp (bg_image, "yes"))
1.161 quint 3251: /* background images are enabled */
1.1 cvs 3252: {
1.185 vatton 3253: callblock = (BackgroundImageCallbackPtr) TtaGetMemory (sizeof (BackgroundImageCallbackBlock));
1.191 vatton 3254: if (callblock)
1.1 cvs 3255: {
3256: callblock->el = element;
3257: callblock->tsch = tsch;
1.185 vatton 3258: callblock->css = css;
1.1 cvs 3259: if (element == NULL)
1.149 vatton 3260: memcpy (&callblock->context.generic, ctxt,
3261: sizeof (GenericContextBlock));
1.18 cvs 3262: else
1.149 vatton 3263: memcpy (&callblock->context.specific, context,
3264: sizeof(PresentationContextBlock));
1.18 cvs 3265:
3266: /* check if the image url is related to an external CSS */
1.182 vatton 3267: if (css)
1.18 cvs 3268: {
1.189 vatton 3269: if (css->url)
3270: /* the image concerns a CSS file */
3271: NormalizeURL (url, 0, tempname, imgname, css->url);
3272: else
3273: /* the image concerns a style element */
3274: NormalizeURL (url, context->doc, tempname, imgname, NULL);
1.18 cvs 3275: /* fetch and display background image of element */
1.181 vatton 3276: FetchImage (0, el, tempname, AMAYA_LOAD_IMAGE,
1.161 quint 3277: ParseCSSBackgroundImageCallback, callblock);
1.18 cvs 3278: }
3279: else
1.182 vatton 3280: FetchImage (context->doc, el, url, AMAYA_LOAD_IMAGE,
1.161 quint 3281: ParseCSSBackgroundImageCallback, callblock);
1.18 cvs 3282: }
3283: }
3284:
3285: if (url)
3286: TtaFreeMemory (url);
3287: }
3288: }
3289: return (cssRule);
3290: }
3291:
3292: /*----------------------------------------------------------------------
1.59 cvs 3293: ParseCSSBackgroundRepeat: parse a CSS BackgroundRepeat attribute string.
1.18 cvs 3294: ----------------------------------------------------------------------*/
1.79 cvs 3295: static char *ParseCSSBackgroundRepeat (Element element, PSchema tsch,
1.97 vatton 3296: PresentationContext context,
3297: char *cssRule, CSSInfoPtr css, ThotBool isHTML)
1.18 cvs 3298: {
3299: PresentationValue repeat;
3300:
1.184 vatton 3301: repeat.typed_data.value = REALSIZE;
1.191 vatton 3302: repeat.typed_data.unit = UNIT_BOX;
1.18 cvs 3303: repeat.typed_data.real = FALSE;
1.82 cvs 3304: cssRule = SkipBlanksAndComments (cssRule);
3305: if (!strncasecmp (cssRule, "no-repeat", 9))
1.184 vatton 3306: repeat.typed_data.value = REALSIZE;
1.82 cvs 3307: else if (!strncasecmp (cssRule, "repeat-y", 8))
1.184 vatton 3308: repeat.typed_data.value = VREPEAT;
1.82 cvs 3309: else if (!strncasecmp (cssRule, "repeat-x", 8))
1.184 vatton 3310: repeat.typed_data.value = HREPEAT;
1.82 cvs 3311: else if (!strncasecmp (cssRule, "repeat", 6))
1.184 vatton 3312: repeat.typed_data.value = REPEAT;
1.18 cvs 3313: else
3314: return (cssRule);
3315:
3316: /* install the new presentation */
1.116 vatton 3317: if (DoApply)
1.117 vatton 3318: {
3319: /* check if it's an important rule */
3320: if (tsch)
3321: cssRule = CheckImportantRule (cssRule, context);
3322: TtaSetStylePresentation (PRPictureMode, element, tsch, context, repeat);
3323: }
1.18 cvs 3324: cssRule = SkipWord (cssRule);
1.163 quint 3325: return (cssRule);
1.18 cvs 3326: }
3327:
3328: /*----------------------------------------------------------------------
1.59 cvs 3329: ParseCSSBackgroundAttachment: parse a CSS BackgroundAttachment
1.18 cvs 3330: attribute string.
3331: ----------------------------------------------------------------------*/
1.79 cvs 3332: static char *ParseCSSBackgroundAttachment (Element element, PSchema tsch,
3333: PresentationContext context,
3334: char *cssRule, CSSInfoPtr css,
3335: ThotBool isHTML)
1.18 cvs 3336: {
1.200 vatton 3337: char *ptr;
3338:
1.163 quint 3339: cssRule = SkipBlanksAndComments (cssRule);
3340: if (!strncasecmp (cssRule, "scroll", 6))
1.199 vatton 3341: {
3342: /* force no-repeat for that background image */
1.200 vatton 3343: ptr = "no-repeat";
3344: ParseCSSBackgroundRepeat (element, tsch, context,
3345: ptr, css, isHTML);
1.199 vatton 3346: cssRule = SkipWord (cssRule);
3347: }
1.163 quint 3348: else if (!strncasecmp (cssRule, "fixed", 5))
1.199 vatton 3349: {
3350: /* force no-repeat for that background image */
1.201 vatton 3351: ptr = "no-repeat";
3352: ParseCSSBackgroundRepeat (element, tsch, context,
3353: ptr, css, isHTML);
1.199 vatton 3354: cssRule = SkipWord (cssRule);
3355: }
1.163 quint 3356: return (cssRule);
1.1 cvs 3357: }
3358:
3359: /*----------------------------------------------------------------------
1.59 cvs 3360: ParseCSSBackgroundPosition: parse a CSS BackgroundPosition
1.1 cvs 3361: attribute string.
3362: ----------------------------------------------------------------------*/
1.79 cvs 3363: static char *ParseCSSBackgroundPosition (Element element, PSchema tsch,
3364: PresentationContext context,
3365: char *cssRule, CSSInfoPtr css,
3366: ThotBool isHTML)
1.1 cvs 3367: {
1.18 cvs 3368: PresentationValue repeat;
1.200 vatton 3369: char *ptr;
1.18 cvs 3370: ThotBool ok;
1.1 cvs 3371:
1.163 quint 3372: cssRule = SkipBlanksAndComments (cssRule);
3373: ok = TRUE;
3374: if (!strncasecmp (cssRule, "left", 4))
3375: cssRule = SkipWord (cssRule);
3376: else if (!strncasecmp (cssRule, "right", 5))
3377: cssRule = SkipWord (cssRule);
3378: else if (!strncasecmp (cssRule, "center", 6))
3379: cssRule = SkipWord (cssRule);
3380: else if (!strncasecmp (cssRule, "top", 3))
3381: cssRule = SkipWord (cssRule);
3382: else if (!strncasecmp (cssRule, "bottom", 6))
3383: cssRule = SkipWord (cssRule);
3384: else if (isdigit (*cssRule) || *cssRule == '.')
1.191 vatton 3385: {
1.206 ! vatton 3386: while (*cssRule != EOS && *cssRule != SPACE &&
! 3387: *cssRule != ',' && *cssRule != ';')
! 3388: cssRule++;
1.191 vatton 3389: }
1.163 quint 3390: else
3391: ok = FALSE;
3392:
3393: if (ok && DoApply)
1.148 vatton 3394: {
1.199 vatton 3395: /* force no-repeat for that background image */
1.200 vatton 3396: ptr = "no-repeat";
3397: ParseCSSBackgroundRepeat (element, tsch, context,
3398: ptr, css, isHTML);
1.163 quint 3399: /* force realsize for the background image */
1.184 vatton 3400: repeat.typed_data.value = REALSIZE;
3401: repeat.typed_data.unit = UNIT_REL;
1.163 quint 3402: repeat.typed_data.real = FALSE;
3403: /* check if it's an important rule */
3404: if (tsch)
3405: cssRule = CheckImportantRule (cssRule, context);
1.191 vatton 3406: /*TtaSetStylePresentation (PRPictureMode, element, tsch, context, repeat);*/
1.148 vatton 3407: }
1.163 quint 3408: return (cssRule);
1.18 cvs 3409: }
3410:
3411: /*----------------------------------------------------------------------
1.59 cvs 3412: ParseCSSBackground: parse a CSS background attribute
1.18 cvs 3413: ----------------------------------------------------------------------*/
1.79 cvs 3414: static char *ParseCSSBackground (Element element, PSchema tsch,
3415: PresentationContext context, char *cssRule,
3416: CSSInfoPtr css, ThotBool isHTML)
1.18 cvs 3417: {
1.79 cvs 3418: char *ptr;
1.93 vatton 3419: int skippedNL;
1.18 cvs 3420:
1.82 cvs 3421: cssRule = SkipBlanksAndComments (cssRule);
3422: while (*cssRule != ';' && *cssRule != EOS && *cssRule != ',')
1.18 cvs 3423: {
1.71 cvs 3424: /* perhaps a Background Image */
1.198 vatton 3425: if (!strncasecmp (cssRule, "url", 3) || !strncasecmp (cssRule, "none", 4))
1.63 cvs 3426: cssRule = ParseCSSBackgroundImage (element, tsch, context, cssRule,
3427: css, isHTML);
1.18 cvs 3428: /* perhaps a Background Attachment */
1.82 cvs 3429: else if (!strncasecmp (cssRule, "scroll", 6) ||
3430: !strncasecmp (cssRule, "fixed", 5))
1.63 cvs 3431: cssRule = ParseCSSBackgroundAttachment (element, tsch, context,
3432: cssRule, css, isHTML);
1.18 cvs 3433: /* perhaps a Background Repeat */
1.82 cvs 3434: else if (!strncasecmp (cssRule, "no-repeat", 9) ||
3435: !strncasecmp (cssRule, "repeat-y", 8) ||
3436: !strncasecmp (cssRule, "repeat-x", 8) ||
3437: !strncasecmp (cssRule, "repeat", 6))
3438: cssRule = ParseCSSBackgroundRepeat (element, tsch, context,
3439: cssRule, css, isHTML);
1.18 cvs 3440: /* perhaps a Background Position */
1.82 cvs 3441: else if (!strncasecmp (cssRule, "left", 4) ||
3442: !strncasecmp (cssRule, "right", 5) ||
3443: !strncasecmp (cssRule, "center", 6) ||
3444: !strncasecmp (cssRule, "top", 3) ||
3445: !strncasecmp (cssRule, "bottom", 6) ||
1.110 vatton 3446: isdigit (*cssRule) || *cssRule == '.')
1.63 cvs 3447: cssRule = ParseCSSBackgroundPosition (element, tsch, context,
3448: cssRule, css, isHTML);
1.18 cvs 3449: /* perhaps a Background Color */
3450: else
3451: {
1.93 vatton 3452: skippedNL = NewLineSkipped;
1.18 cvs 3453: /* check if the rule has been found */
3454: ptr = cssRule;
1.82 cvs 3455: cssRule = ParseCSSBackgroundColor (element, tsch, context,
3456: cssRule, css, isHTML);
1.43 cvs 3457: if (ptr == cssRule)
1.93 vatton 3458: {
3459: NewLineSkipped = skippedNL;
3460: /* rule not found */
3461: cssRule = SkipProperty (cssRule);
3462: }
1.18 cvs 3463: }
1.82 cvs 3464: cssRule = SkipBlanksAndComments (cssRule);
1.18 cvs 3465: }
3466: return (cssRule);
3467: }
3468:
1.59 cvs 3469: /*----------------------------------------------------------------------
1.60 cvs 3470: ParseCSSPageBreakBefore: parse a CSS page-break-before attribute
1.59 cvs 3471: ----------------------------------------------------------------------*/
1.79 cvs 3472: static char *ParseCSSPageBreakBefore (Element element, PSchema tsch,
3473: PresentationContext context, char *cssRule,
3474: CSSInfoPtr css, ThotBool isHTML)
1.59 cvs 3475: {
3476: PresentationValue page;
3477:
1.184 vatton 3478: page.typed_data.unit = UNIT_INVALID;
1.59 cvs 3479: page.typed_data.real = FALSE;
1.82 cvs 3480: cssRule = SkipBlanksAndComments (cssRule);
3481: if (!strncasecmp (cssRule, "auto", 4))
1.184 vatton 3482: page.typed_data.value = PageAuto;
1.82 cvs 3483: else if (!strncasecmp (cssRule, "always", 6))
1.59 cvs 3484: {
1.184 vatton 3485: page.typed_data.unit = UNIT_REL;
3486: page.typed_data.value = PageAlways;
1.59 cvs 3487: }
1.82 cvs 3488: else if (!strncasecmp (cssRule, "avoid", 5))
1.59 cvs 3489: {
1.184 vatton 3490: page.typed_data.unit = UNIT_REL;
3491: page.typed_data.value = PageAvoid;
1.59 cvs 3492: }
1.82 cvs 3493: else if (!strncasecmp (cssRule, "left", 4))
1.59 cvs 3494: {
1.184 vatton 3495: page.typed_data.unit = UNIT_REL;
3496: page.typed_data.value = PageLeft;
1.59 cvs 3497: }
1.82 cvs 3498: else if (!strncasecmp (cssRule, "right", 5))
1.59 cvs 3499: {
1.184 vatton 3500: page.typed_data.unit = UNIT_REL;
3501: page.typed_data.value = PageRight;
1.59 cvs 3502: }
1.82 cvs 3503: else if (!strncasecmp (cssRule, "inherit", 7))
1.59 cvs 3504: {
1.184 vatton 3505: /*page.typed_data.unit = UNIT_REL;*/
3506: page.typed_data.value = PageInherit;
1.59 cvs 3507: }
3508: cssRule = SkipWord (cssRule);
3509: /* install the new presentation */
1.184 vatton 3510: if (page.typed_data.unit == UNIT_REL &&
3511: page.typed_data.value == PageAlways && DoApply)
1.117 vatton 3512: {
3513: /* check if it's an important rule */
3514: if (tsch)
3515: cssRule = CheckImportantRule (cssRule, context);
3516: TtaSetStylePresentation (PRPageBefore, element, tsch, context, page);
3517: }
1.59 cvs 3518: return (cssRule);
3519: }
3520:
3521: /*----------------------------------------------------------------------
1.60 cvs 3522: ParseCSSPageBreakAfter: parse a CSS page-break-after attribute
1.59 cvs 3523: ----------------------------------------------------------------------*/
1.79 cvs 3524: static char *ParseCSSPageBreakAfter (Element element, PSchema tsch,
3525: PresentationContext context,
3526: char *cssRule, CSSInfoPtr css,
3527: ThotBool isHTML)
1.59 cvs 3528: {
3529: PresentationValue page;
3530:
1.184 vatton 3531: page.typed_data.unit = UNIT_INVALID;
1.59 cvs 3532: page.typed_data.real = FALSE;
1.82 cvs 3533: cssRule = SkipBlanksAndComments (cssRule);
3534: if (!strncasecmp (cssRule, "auto", 4))
1.184 vatton 3535: page.typed_data.value = PageAuto;
1.82 cvs 3536: else if (!strncasecmp (cssRule, "always", 6))
1.59 cvs 3537: {
1.184 vatton 3538: page.typed_data.unit = UNIT_REL;
3539: page.typed_data.value = PageAlways;
1.59 cvs 3540: }
1.82 cvs 3541: else if (!strncasecmp (cssRule, "avoid", 5))
1.59 cvs 3542: {
1.184 vatton 3543: page.typed_data.unit = UNIT_REL;
3544: page.typed_data.value = PageAvoid;
1.59 cvs 3545: }
1.82 cvs 3546: else if (!strncasecmp (cssRule, "left", 4))
1.59 cvs 3547: {
1.184 vatton 3548: page.typed_data.unit = UNIT_REL;
3549: page.typed_data.value = PageLeft;
1.59 cvs 3550: }
1.82 cvs 3551: else if (!strncasecmp (cssRule, "right", 5))
1.59 cvs 3552: {
1.184 vatton 3553: page.typed_data.unit = UNIT_REL;
3554: page.typed_data.value = PageRight;
1.59 cvs 3555: }
1.82 cvs 3556: else if (!strncasecmp (cssRule, "inherit", 7))
1.59 cvs 3557: {
1.184 vatton 3558: /*page.typed_data.unit = UNIT_REL;*/
3559: page.typed_data.value = PageInherit;
1.59 cvs 3560: }
3561: cssRule = SkipWord (cssRule);
3562: /* install the new presentation */
1.184 vatton 3563: /*if (page.typed_data.unit == UNIT_REL && DoApply)
1.117 vatton 3564: {
3565: if (tsch)
3566: cssRule = CheckImportantRule (cssRule, context);
3567: TtaSetStylePresentation (PRPageAfter, element, tsch, context, page);
3568: }*/
1.59 cvs 3569: return (cssRule);
3570: }
3571:
3572: /*----------------------------------------------------------------------
1.60 cvs 3573: ParseCSSPageBreakInside: parse a CSS page-break-inside attribute
1.59 cvs 3574: ----------------------------------------------------------------------*/
1.79 cvs 3575: static char *ParseCSSPageBreakInside (Element element, PSchema tsch,
3576: PresentationContext context,
3577: char *cssRule, CSSInfoPtr css,
3578: ThotBool isHTML)
1.59 cvs 3579: {
3580: PresentationValue page;
3581:
1.184 vatton 3582: page.typed_data.unit = UNIT_INVALID;
1.59 cvs 3583: page.typed_data.real = FALSE;
1.82 cvs 3584: cssRule = SkipBlanksAndComments (cssRule);
3585: if (!strncasecmp (cssRule, "auto", 4))
1.59 cvs 3586: {
1.184 vatton 3587: /*page.typed_data.unit = UNIT_REL;*/
3588: page.typed_data.value = PageAuto;
1.59 cvs 3589: }
1.82 cvs 3590: else if (!strncasecmp (cssRule, "avoid", 5))
1.59 cvs 3591: {
1.184 vatton 3592: page.typed_data.unit = UNIT_REL;
3593: page.typed_data.value = PageAvoid;
1.59 cvs 3594: }
1.82 cvs 3595: else if (!strncasecmp (cssRule, "inherit", 7))
1.59 cvs 3596: {
1.184 vatton 3597: /*page.typed_data.unit = UNIT_REL;*/
3598: page.typed_data.value = PageInherit;
1.59 cvs 3599: }
3600: cssRule = SkipWord (cssRule);
3601: /* install the new presentation */
1.184 vatton 3602: /*if (page.typed_data.unit == UNIT_REL &&
3603: page.typed_data.value == PageAvoid && DoApply)
1.117 vatton 3604: {
3605: if (tsch)
3606: cssRule = CheckImportantRule (cssRule, context);
3607: TtaSetStylePresentation (PRPageInside, element, tsch, context, page);
3608: }*/
1.59 cvs 3609: return (cssRule);
3610: }
1.18 cvs 3611:
3612:
1.60 cvs 3613: /*----------------------------------------------------------------------
1.117 vatton 3614: ParseSVGStrokeWidth: parse a SVG stroke-width property value.
1.60 cvs 3615: ----------------------------------------------------------------------*/
1.79 cvs 3616: static char *ParseSVGStrokeWidth (Element element, PSchema tsch,
3617: PresentationContext context, char *cssRule,
3618: CSSInfoPtr css, ThotBool isHTML)
1.60 cvs 3619: {
3620: PresentationValue width;
3621:
1.82 cvs 3622: cssRule = SkipBlanksAndComments (cssRule);
1.60 cvs 3623: width.typed_data.value = 0;
1.184 vatton 3624: width.typed_data.unit = UNIT_INVALID;
1.60 cvs 3625: width.typed_data.real = FALSE;
1.110 vatton 3626: if (isdigit (*cssRule) || *cssRule == '.')
1.166 vatton 3627: {
1.60 cvs 3628: cssRule = ParseCSSUnit (cssRule, &width);
1.184 vatton 3629: if (width.typed_data.unit == UNIT_BOX)
3630: width.typed_data.unit = UNIT_PX;
1.166 vatton 3631: }
1.184 vatton 3632: if (width.typed_data.unit != UNIT_INVALID && DoApply)
1.117 vatton 3633: {
3634: /* check if it's an important rule */
3635: if (tsch)
3636: cssRule = CheckImportantRule (cssRule, context);
3637: TtaSetStylePresentation (PRLineWeight, element, tsch, context, width);
3638: width.typed_data.value = 1;
1.184 vatton 3639: width.typed_data.unit = UNIT_REL;
1.117 vatton 3640: }
1.60 cvs 3641: return (cssRule);
3642: }
3643:
1.18 cvs 3644: /************************************************************************
3645: * *
3646: * FUNCTIONS STYLE DECLARATIONS *
3647: * *
3648: ************************************************************************/
3649: /*
1.59 cvs 3650: * NOTE: Long attribute name MUST be placed before shortened ones !
1.18 cvs 3651: * e.g. "FONT-SIZE" must be placed before "FONT"
3652: */
3653: static CSSProperty CSSProperties[] =
3654: {
1.82 cvs 3655: {"font-family", ParseCSSFontFamily},
3656: {"font-style", ParseCSSFontStyle},
3657: {"font-variant", ParseCSSFontVariant},
3658: {"font-weight", ParseCSSFontWeight},
3659: {"font-size", ParseCSSFontSize},
3660: {"font", ParseCSSFont},
3661:
3662: {"color", ParseCSSForeground},
3663: {"background-color", ParseCSSBackgroundColor},
3664: {"background-image", ParseCSSBackgroundImage},
3665: {"background-repeat", ParseCSSBackgroundRepeat},
3666: {"background-attachment", ParseCSSBackgroundAttachment},
3667: {"background-position", ParseCSSBackgroundPosition},
3668: {"background", ParseCSSBackground},
3669:
3670: {"word-spacing", ParseCSSWordSpacing},
3671: {"letter-spacing", ParseCSSLetterSpacing},
3672: {"text-decoration", ParseCSSTextDecoration},
3673: {"vertical-align", ParseCSSVerticalAlign},
3674: {"text-transform", ParseCSSTextTransform},
3675: {"text-align", ParseCSSTextAlign},
3676: {"text-indent", ParseCSSTextIndent},
1.162 quint 3677: {"line-height", ParseCSSLineHeight},
1.82 cvs 3678:
1.112 quint 3679: {"direction", ParseCSSDirection},
1.113 quint 3680: {"unicode-bidi", ParseCSSUnicodeBidi},
1.112 quint 3681:
1.82 cvs 3682: {"margin-top", ParseCSSMarginTop},
3683: {"margin-right", ParseCSSMarginRight},
3684: {"margin-bottom", ParseCSSMarginBottom},
3685: {"margin-left", ParseCSSMarginLeft},
3686: {"margin", ParseCSSMargin},
3687:
3688: {"padding-top", ParseCSSPaddingTop},
3689: {"padding-right", ParseCSSPaddingRight},
3690: {"padding-bottom", ParseCSSPaddingBottom},
3691: {"padding-left", ParseCSSPaddingLeft},
3692: {"padding", ParseCSSPadding},
3693:
3694: {"border-top-width", ParseCSSBorderTopWidth},
3695: {"border-right-width", ParseCSSBorderRightWidth},
3696: {"border-bottom-width", ParseCSSBorderBottomWidth},
3697: {"border-left-width", ParseCSSBorderLeftWidth},
3698: {"border-width", ParseCSSBorderWidth},
3699: {"border-top-color", ParseCSSBorderColorTop},
3700: {"border-right-color", ParseCSSBorderColorRight},
3701: {"border-bottom-color", ParseCSSBorderColorBottom},
3702: {"border-left-color", ParseCSSBorderColorLeft},
3703: {"border-color", ParseCSSBorderColor},
3704: {"border-top-style", ParseCSSBorderStyleTop},
3705: {"border-right-style", ParseCSSBorderStyleRight},
3706: {"border-bottom-style", ParseCSSBorderStyleBottom},
3707: {"border-left-style", ParseCSSBorderStyleLeft},
3708: {"border-style", ParseCSSBorderStyle},
3709: {"border-top", ParseCSSBorderTop},
3710: {"border-right", ParseCSSBorderRight},
3711: {"border-bottom", ParseCSSBorderBottom},
3712: {"border-left", ParseCSSBorderLeft},
3713: {"border", ParseCSSBorder},
3714:
3715: {"width", ParseCSSWidth},
3716: {"height", ParseCSSHeight},
3717: {"float", ParseCSSFloat},
3718: {"clear", ParseCSSClear},
1.184 vatton 3719: {"content", ParseCSSContent},
1.82 cvs 3720:
3721: {"display", ParseCSSDisplay},
3722: {"white-space", ParseCSSWhiteSpace},
3723:
3724: {"list-style-type", ParseCSSListStyleType},
3725: {"list-style-image", ParseCSSListStyleImage},
3726: {"list-style-position", ParseCSSListStylePosition},
3727: {"list-style", ParseCSSListStyle},
3728:
3729: {"page-break-before", ParseCSSPageBreakBefore},
3730: {"page-break-after", ParseCSSPageBreakAfter},
3731: {"page-break-inside", ParseCSSPageBreakInside},
1.60 cvs 3732:
3733: /* SVG extensions */
1.170 cheyroul 3734: {"stroke-opacity", ParseSVGStrokeOpacity},
1.82 cvs 3735: {"stroke-width", ParseSVGStrokeWidth},
3736: {"stroke", ParseSVGStroke},
1.170 cheyroul 3737:
3738: {"fill-opacity", ParseSVGFillOpacity},
1.155 cheyroul 3739: {"fill", ParseSVGFill},
1.170 cheyroul 3740:
1.155 cheyroul 3741: {"opacity", ParseSVGOpacity}
1.18 cvs 3742: };
1.155 cheyroul 3743:
1.18 cvs 3744: #define NB_CSSSTYLEATTRIBUTE (sizeof(CSSProperties) / sizeof(CSSProperty))
3745:
3746: /*----------------------------------------------------------------------
1.59 cvs 3747: ParseCSSRule: parse a CSS Style string
1.18 cvs 3748: we expect the input string describing the style to be of the
1.59 cvs 3749: form: PRORPERTY: DESCRIPTION [ ; PROPERTY: DESCRIPTION ] *
1.18 cvs 3750: but tolerate incorrect or incomplete input
3751: ----------------------------------------------------------------------*/
1.79 cvs 3752: static void ParseCSSRule (Element element, PSchema tsch,
3753: PresentationContext context, char *cssRule,
3754: CSSInfoPtr css, ThotBool isHTML)
1.18 cvs 3755: {
1.34 cvs 3756: DisplayMode dispMode;
1.79 cvs 3757: char *p = NULL;
1.18 cvs 3758: int lg;
1.34 cvs 3759: unsigned int i;
1.76 cvs 3760: ThotBool found;
1.18 cvs 3761:
1.34 cvs 3762: /* avoid too many redisplay */
3763: dispMode = TtaGetDisplayMode (context->doc);
3764: if (dispMode == DisplayImmediately)
3765: TtaSetDisplayMode (context->doc, DeferredDisplay);
3766:
1.82 cvs 3767: while (*cssRule != EOS)
1.18 cvs 3768: {
1.82 cvs 3769: cssRule = SkipBlanksAndComments (cssRule);
1.153 vatton 3770: if (*cssRule < 0x41 || *cssRule > 0x7A ||
1.133 vatton 3771: (*cssRule > 0x5A && *cssRule < 0x60))
1.153 vatton 3772: cssRule++;
1.194 vatton 3773: else if (*cssRule != EOS)
1.89 cvs 3774: {
1.153 vatton 3775: found = FALSE;
3776: /* look for the type of property */
3777: for (i = 0; i < NB_CSSSTYLEATTRIBUTE && !found; i++)
1.18 cvs 3778: {
1.153 vatton 3779: lg = strlen (CSSProperties[i].name);
3780: if (!strncasecmp (cssRule, CSSProperties[i].name, lg))
3781: {
3782: p = cssRule + lg;
3783: found = TRUE;
3784: i--;
3785: }
1.18 cvs 3786: }
1.153 vatton 3787: if (i == NB_CSSSTYLEATTRIBUTE)
3788: cssRule = SkipProperty (cssRule);
3789: else
1.18 cvs 3790: {
1.153 vatton 3791: /* update index and skip the ":" indicator if present */
1.86 cvs 3792: p = SkipBlanksAndComments (p);
1.153 vatton 3793: if (*p == ':')
1.61 cvs 3794: {
1.153 vatton 3795: p++;
3796: p = SkipBlanksAndComments (p);
3797: /* try to parse the value associated with this property */
3798: if (CSSProperties[i].parsing_function != NULL)
3799: {
3800: p = CSSProperties[i].parsing_function (element, tsch, context,
3801: p, css, isHTML);
3802: /* update index and skip the ";" separator if present */
3803: cssRule = p;
3804: }
1.61 cvs 3805: }
1.153 vatton 3806: else
3807: cssRule = SkipProperty (cssRule);
1.18 cvs 3808: }
3809: }
3810: /* next property */
1.82 cvs 3811: cssRule = SkipBlanksAndComments (cssRule);
1.89 cvs 3812: if (*cssRule == '}')
3813: {
3814: cssRule++;
1.168 vatton 3815: CSSPrintError ("Invalid character", "}");
1.89 cvs 3816: cssRule = SkipBlanksAndComments (cssRule);
3817: }
1.155 cheyroul 3818: if (*cssRule == ',' ||
3819: *cssRule == ';')
1.18 cvs 3820: {
3821: cssRule++;
1.82 cvs 3822: cssRule = SkipBlanksAndComments (cssRule);
1.18 cvs 3823: }
3824: }
1.34 cvs 3825:
3826: /* restore the display mode */
3827: if (dispMode == DisplayImmediately)
3828: TtaSetDisplayMode (context->doc, dispMode);
1.18 cvs 3829: }
1.1 cvs 3830:
1.111 cvs 3831: /*----------------------------------------------------------------------
3832: AddBorderStyleValue
3833: -----------------------------------------------------------------------*/
3834: static void AddBorderStyleValue (char *buffer, int value)
3835: {
3836: switch (value)
3837: {
1.184 vatton 3838: case BorderStyleNone:
1.111 cvs 3839: strcat (buffer, "none");
3840: break;
1.184 vatton 3841: case BorderStyleHidden:
1.111 cvs 3842: strcat (buffer, "hidden");
3843: break;
1.184 vatton 3844: case BorderStyleDotted:
1.111 cvs 3845: strcat (buffer, "dotted");
3846: break;
1.184 vatton 3847: case BorderStyleDashed:
1.111 cvs 3848: strcat (buffer, "dashed");
3849: break;
1.184 vatton 3850: case BorderStyleSolid:
1.111 cvs 3851: strcat (buffer, "solid");
3852: break;
1.184 vatton 3853: case BorderStyleDouble:
1.111 cvs 3854: strcat (buffer, "double");
3855: break;
1.184 vatton 3856: case BorderStyleGroove:
1.111 cvs 3857: strcat (buffer, "groove");
3858: break;
1.184 vatton 3859: case BorderStyleRidge:
1.111 cvs 3860: strcat (buffer, "ridge");
3861: break;
1.184 vatton 3862: case BorderStyleInset:
1.111 cvs 3863: strcat (buffer, "inset");
3864: break;
1.184 vatton 3865: case BorderStyleOutset:
1.111 cvs 3866: strcat (buffer, "outset");
3867: break;
3868: }
3869: }
1.1 cvs 3870:
3871: /*----------------------------------------------------------------------
1.59 cvs 3872: PToCss: translate a PresentationSetting to the
1.18 cvs 3873: equivalent CSS string, and add it to the buffer given as the
1.67 cvs 3874: argument. It is used when extracting the CSS string from actual
3875: presentation.
3876: el is the element for which the style rule is generated
1.18 cvs 3877:
3878: All the possible values returned by the presentation drivers are
3879: described in thotlib/include/presentation.h
3880: -----------------------------------------------------------------------*/
1.79 cvs 3881: void PToCss (PresentationSetting settings, char *buffer, int len, Element el)
1.1 cvs 3882: {
1.76 cvs 3883: ElementType elType;
1.18 cvs 3884: float fval = 0;
3885: unsigned short red, green, blue;
3886: int add_unit = 0;
3887: unsigned int unit, i;
3888: ThotBool real = FALSE;
3889:
1.82 cvs 3890: buffer[0] = EOS;
1.18 cvs 3891: if (len < 40)
3892: return;
3893:
3894: unit = settings->value.typed_data.unit;
3895: if (settings->value.typed_data.real)
3896: {
3897: real = TRUE;
3898: fval = (float) settings->value.typed_data.value;
1.195 vatton 3899: fval /= 1000.;
1.18 cvs 3900: }
1.1 cvs 3901:
1.18 cvs 3902: switch (settings->type)
1.1 cvs 3903: {
1.18 cvs 3904: case PRVisibility:
3905: break;
1.111 cvs 3906: case PRHeight:
3907: if (real)
3908: sprintf (buffer, "height: %g", fval);
3909: else
3910: sprintf (buffer, "height: %d", settings->value.typed_data.value);
3911: add_unit = 1;
3912: break;
3913: case PRWidth:
3914: if (real)
3915: sprintf (buffer, "width: %g", fval);
3916: else
3917: sprintf (buffer, "width: %d", settings->value.typed_data.value);
3918: add_unit = 1;
3919: break;
3920: case PRMarginTop:
3921: if (real)
3922: sprintf (buffer, "margin-top: %g", fval);
3923: else
3924: sprintf (buffer, "margin-top: %d",settings->value.typed_data.value);
3925: add_unit = 1;
3926: break;
3927: case PRMarginBottom:
3928: if (real)
3929: sprintf (buffer, "margin-bottom: %g", fval);
3930: else
3931: sprintf (buffer, "margin-bottom: %d",
3932: settings->value.typed_data.value);
3933: add_unit = 1;
3934: break;
3935: case PRMarginLeft:
3936: if (real)
3937: sprintf (buffer, "margin-left: %g", fval);
3938: else
1.164 quint 3939: sprintf (buffer, "margin-left: %d", settings->value.typed_data.value);
1.111 cvs 3940: add_unit = 1;
3941: break;
3942: case PRMarginRight:
3943: if (real)
3944: sprintf (buffer, "margin-right: %g", fval);
3945: else
1.164 quint 3946: sprintf (buffer, "margin-right: %d", settings->value.typed_data.value);
1.111 cvs 3947: add_unit = 1;
3948: break;
3949: case PRPaddingTop:
3950: if (real)
3951: sprintf (buffer, "padding-top: %g", fval);
3952: else
1.164 quint 3953: sprintf (buffer, "padding-top: %d", settings->value.typed_data.value);
1.111 cvs 3954: add_unit = 1;
3955: break;
3956: case PRPaddingBottom:
3957: if (real)
3958: sprintf (buffer, "padding-bottom: %g", fval);
3959: else
3960: sprintf (buffer, "padding-bottom: %d",
3961: settings->value.typed_data.value);
3962: add_unit = 1;
3963: break;
3964: case PRPaddingLeft:
3965: if (real)
3966: sprintf (buffer, "padding-left: %g", fval);
3967: else
1.164 quint 3968: sprintf (buffer, "padding-left: %d", settings->value.typed_data.value);
1.111 cvs 3969: add_unit = 1;
3970: break;
3971: case PRPaddingRight:
3972: if (real)
3973: sprintf (buffer, "padding-right: %g", fval);
3974: else
3975: sprintf (buffer, "padding-right: %d",
3976: settings->value.typed_data.value);
3977: add_unit = 1;
3978: break;
3979: case PRBorderTopWidth:
3980: if (real)
3981: sprintf (buffer, "border-top-width: %g", fval);
3982: else
3983: sprintf (buffer, "border-top-width: %d",
3984: settings->value.typed_data.value);
3985: add_unit = 1;
3986: break;
3987: case PRBorderBottomWidth:
3988: if (real)
3989: sprintf (buffer, "border-bottom-width: %g", fval);
3990: else
3991: sprintf (buffer, "border-bottom-width: %d",
3992: settings->value.typed_data.value);
3993: add_unit = 1;
3994: break;
3995: case PRBorderLeftWidth:
3996: if (real)
3997: sprintf (buffer, "border-left-width: %g", fval);
3998: else
3999: sprintf (buffer, "border-left-width: %d",
4000: settings->value.typed_data.value);
4001: add_unit = 1;
4002: break;
4003: case PRBorderRightWidth:
4004: if (real)
4005: sprintf (buffer, "border-right-width: %g", fval);
4006: else
4007: sprintf (buffer, "border-right-width: %d",
4008: settings->value.typed_data.value);
4009: add_unit = 1;
4010: break;
4011: case PRBorderTopColor:
4012: TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
4013: elType = TtaGetElementType(el);
4014: sprintf (buffer, "border-top-color: #%02X%02X%02X", red, green, blue);
4015: break;
4016: case PRBorderRightColor:
4017: TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
4018: elType = TtaGetElementType(el);
4019: sprintf (buffer, "border-right-color: #%02X%02X%02X", red, green, blue);
4020: break;
4021: case PRBorderBottomColor:
4022: TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
4023: elType = TtaGetElementType(el);
4024: sprintf (buffer, "border-bottom-color: #%02X%02X%02X", red, green, blue);
1.18 cvs 4025: break;
1.111 cvs 4026: case PRBorderLeftColor:
4027: TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
4028: elType = TtaGetElementType(el);
4029: sprintf (buffer, "border-left-color: #%02X%02X%02X", red, green, blue);
1.20 cvs 4030: break;
1.111 cvs 4031: case PRBorderTopStyle:
4032: strcpy (buffer, "border-top-style: ");
4033: AddBorderStyleValue (buffer, settings->value.typed_data.value);
4034: break;
4035: case PRBorderRightStyle:
4036: strcpy (buffer, "border-right-style: ");
4037: AddBorderStyleValue (buffer, settings->value.typed_data.value);
4038: break;
4039: case PRBorderBottomStyle:
4040: strcpy (buffer, "border-bottom-style: ");
4041: AddBorderStyleValue (buffer, settings->value.typed_data.value);
4042: break;
4043: case PRBorderLeftStyle:
4044: strcpy (buffer, "border-left-style: ");
4045: AddBorderStyleValue (buffer, settings->value.typed_data.value);
1.18 cvs 4046: break;
4047: case PRSize:
1.184 vatton 4048: if (unit == UNIT_REL)
1.18 cvs 4049: {
4050: if (real)
4051: {
1.82 cvs 4052: sprintf (buffer, "font-size: %g", fval);
1.18 cvs 4053: add_unit = 1;
4054: }
4055: else
4056: switch (settings->value.typed_data.value)
4057: {
4058: case 1:
1.82 cvs 4059: strcpy (buffer, "font-size: xx-small");
1.18 cvs 4060: break;
4061: case 2:
1.82 cvs 4062: strcpy (buffer, "font-size: x-small");
1.18 cvs 4063: break;
4064: case 3:
1.82 cvs 4065: strcpy (buffer, "font-size: small");
1.18 cvs 4066: break;
4067: case 4:
1.82 cvs 4068: strcpy (buffer, "font-size: medium");
1.18 cvs 4069: break;
4070: case 5:
1.82 cvs 4071: strcpy (buffer, "font-size: large");
1.18 cvs 4072: break;
4073: case 6:
1.82 cvs 4074: strcpy (buffer, "font-size: x-large");
1.18 cvs 4075: break;
4076: case 7:
4077: case 8:
4078: case 9:
4079: case 10:
4080: case 11:
4081: case 12:
1.82 cvs 4082: strcpy (buffer, "font-size: xx-large");
1.18 cvs 4083: break;
4084: }
4085: }
4086: else
4087: {
4088: if (real)
1.82 cvs 4089: sprintf (buffer, "font-size: %g", fval);
1.18 cvs 4090: else
1.82 cvs 4091: sprintf (buffer, "font-size: %d",
1.67 cvs 4092: settings->value.typed_data.value);
1.18 cvs 4093: add_unit = 1;
4094: }
4095: break;
1.111 cvs 4096: case PRStyle:
4097: switch (settings->value.typed_data.value)
4098: {
1.184 vatton 4099: case StyleRoman:
1.111 cvs 4100: strcpy (buffer, "font-style: normal");
4101: break;
1.184 vatton 4102: case StyleItalics:
1.111 cvs 4103: strcpy (buffer, "font-style: italic");
4104: break;
1.184 vatton 4105: case StyleOblique:
1.111 cvs 4106: strcpy (buffer, "font-style: oblique");
4107: break;
4108: }
4109: break;
4110: case PRWeight:
4111: switch (settings->value.typed_data.value)
4112: {
1.184 vatton 4113: case WeightBold:
1.111 cvs 4114: strcpy (buffer, "font-weight: bold");
4115: break;
1.184 vatton 4116: case WeightNormal:
1.111 cvs 4117: strcpy (buffer, "font-weight: normal");
4118: break;
4119: }
4120: break;
4121: case PRFont:
4122: switch (settings->value.typed_data.value)
4123: {
1.184 vatton 4124: case FontHelvetica:
1.111 cvs 4125: strcpy (buffer, "font-family: helvetica");
4126: break;
1.184 vatton 4127: case FontTimes:
1.111 cvs 4128: strcpy (buffer, "font-family: times");
4129: break;
1.184 vatton 4130: case FontCourier:
1.111 cvs 4131: strcpy (buffer, "font-family: courier");
4132: break;
4133: }
4134: break;
1.18 cvs 4135: case PRUnderline:
4136: switch (settings->value.typed_data.value)
4137: {
1.184 vatton 4138: case Underline:
1.82 cvs 4139: strcpy (buffer, "text-decoration: underline");
1.18 cvs 4140: break;
1.184 vatton 4141: case Overline:
1.82 cvs 4142: strcpy (buffer, "text-decoration: overline");
1.18 cvs 4143: break;
1.184 vatton 4144: case CrossOut:
1.82 cvs 4145: strcpy (buffer, "text-decoration: line-through");
1.18 cvs 4146: break;
4147: }
4148: break;
1.111 cvs 4149: case PRThickness:
4150: break;
1.18 cvs 4151: case PRIndent:
4152: if (real)
1.82 cvs 4153: sprintf (buffer, "text-indent: %g", fval);
1.18 cvs 4154: else
1.82 cvs 4155: sprintf (buffer, "text-indent: %d",
1.67 cvs 4156: settings->value.typed_data.value);
1.18 cvs 4157: add_unit = 1;
4158: break;
4159: case PRLineSpacing:
4160: if (real)
1.82 cvs 4161: sprintf (buffer, "line-height: %g", fval);
1.1 cvs 4162: else
1.82 cvs 4163: sprintf (buffer, "line-height: %d",
1.67 cvs 4164: settings->value.typed_data.value);
1.18 cvs 4165: add_unit = 1;
4166: break;
1.111 cvs 4167: case PRDepth:
4168: break;
1.18 cvs 4169: case PRAdjust:
4170: switch (settings->value.typed_data.value)
1.1 cvs 4171: {
1.184 vatton 4172: case AdjustLeft:
1.82 cvs 4173: strcpy (buffer, "text-align: left");
1.18 cvs 4174: break;
1.184 vatton 4175: case AdjustRight:
1.82 cvs 4176: strcpy (buffer, "text-align: right");
1.18 cvs 4177: break;
1.184 vatton 4178: case Centered:
1.82 cvs 4179: strcpy (buffer, "text-align: center");
1.18 cvs 4180: break;
1.184 vatton 4181: case LeftWithDots:
1.82 cvs 4182: strcpy (buffer, "text-align: left");
1.81 cvs 4183: break;
1.184 vatton 4184: case Justify:
1.82 cvs 4185: strcpy (buffer, "text-align: justify");
1.112 quint 4186: break;
4187: }
4188: break;
4189: case PRDirection:
4190: switch (settings->value.typed_data.value)
4191: {
1.184 vatton 4192: case LeftToRight:
1.112 quint 4193: strcpy (buffer, "direction: ltr");
4194: break;
1.184 vatton 4195: case RightToLeft:
1.112 quint 4196: strcpy (buffer, "direction: rtl");
1.113 quint 4197: break;
4198: }
4199: break;
4200: case PRUnicodeBidi:
4201: switch (settings->value.typed_data.value)
4202: {
1.184 vatton 4203: case Normal:
1.113 quint 4204: strcpy (buffer, "unicode-bidi: normal");
4205: break;
1.184 vatton 4206: case Embed:
1.113 quint 4207: strcpy (buffer, "unicode-bidi: embed");
4208: break;
1.184 vatton 4209: case Override:
1.113 quint 4210: strcpy (buffer, "unicode-bidi: bidi-override");
1.18 cvs 4211: break;
1.1 cvs 4212: }
1.18 cvs 4213: break;
1.111 cvs 4214: case PRLineStyle:
4215: break;
1.126 vatton 4216: case PRDisplay:
4217: switch (settings->value.typed_data.value)
4218: {
1.184 vatton 4219: case Inline:
1.126 vatton 4220: strcpy (buffer, "display: inline");
4221: break;
1.184 vatton 4222: case Block:
1.126 vatton 4223: strcpy (buffer, "display: block");
4224: break;
1.184 vatton 4225: case ListItem:
1.126 vatton 4226: strcpy (buffer, "display: list-item");
4227: break;
1.184 vatton 4228: case RunIn:
1.126 vatton 4229: strcpy (buffer, "display: runin");
4230: break;
1.184 vatton 4231: case Compact:
1.126 vatton 4232: strcpy (buffer, "display: compact");
4233: break;
1.184 vatton 4234: case Marker:
1.126 vatton 4235: strcpy (buffer, "display: marker");
1.196 vatton 4236: break;
4237: default:
4238: break;
4239: }
4240: break;
4241: case PRFloat:
4242: switch (settings->value.typed_data.value)
4243: {
4244: case FloatNone:
4245: strcpy (buffer, "float: none");
4246: break;
4247: case FloatLeft:
4248: strcpy (buffer, "float: left");
4249: break;
4250: case FloatRight:
4251: strcpy (buffer, "float: right");
4252: break;
4253: default:
4254: break;
4255: }
4256: break;
4257: case PRClear:
4258: switch (settings->value.typed_data.value)
4259: {
4260: case ClearNone:
4261: strcpy (buffer, "clear: none");
4262: break;
4263: case ClearLeft:
4264: strcpy (buffer, "clear: left");
4265: break;
4266: case ClearRight:
4267: strcpy (buffer, "clear: right");
4268: break;
4269: case ClearBoth:
4270: strcpy (buffer, "clear: both");
1.126 vatton 4271: break;
4272: default:
4273: break;
4274: }
4275: break;
1.111 cvs 4276: case PRLineWeight:
4277: elType = TtaGetElementType(el);
4278: #ifdef _SVG
4279: if (!strcmp(TtaGetSSchemaName (elType.ElSSchema), "SVG"))
4280: #endif /* _SVG */
4281: {
4282: if (real)
4283: sprintf (buffer, "stroke-width: %g", fval);
4284: else
4285: sprintf (buffer, "stroke-width: %d",
4286: settings->value.typed_data.value);
4287: }
4288: add_unit = 1;
1.18 cvs 4289: break;
4290: case PRFillPattern:
4291: break;
4292: case PRBackground:
4293: TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
1.76 cvs 4294: elType = TtaGetElementType(el);
1.100 vatton 4295: #ifdef _SVG
4296: if (strcmp(TtaGetSSchemaName (elType.ElSSchema), "SVG") == 0)
1.82 cvs 4297: sprintf (buffer, "fill: #%02X%02X%02X", red, green, blue);
1.67 cvs 4298: else
1.100 vatton 4299: #endif /* _SVG */
1.82 cvs 4300: sprintf (buffer, "background-color: #%02X%02X%02X", red, green,
1.67 cvs 4301: blue);
1.18 cvs 4302: break;
4303: case PRForeground:
4304: TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
1.76 cvs 4305: elType = TtaGetElementType(el);
1.100 vatton 4306: #ifdef _SVG
4307: if (strcmp(TtaGetSSchemaName (elType.ElSSchema), "SVG") == 0)
1.82 cvs 4308: sprintf (buffer, "stroke: #%02X%02X%02X", red, green, blue);
1.67 cvs 4309: else
1.100 vatton 4310: #endif /* _SVG */
1.82 cvs 4311: sprintf (buffer, "color: #%02X%02X%02X", red, green, blue);
1.67 cvs 4312: break;
1.111 cvs 4313: case PRHyphenate:
1.195 vatton 4314: case PRVertOverflow:
4315: case PRHorizOverflow:
4316: break;
4317: case PROpacity:
4318: sprintf (buffer, "opacity: %g", fval);
1.18 cvs 4319: break;
1.195 vatton 4320: case PRStrokeOpacity:
4321: sprintf (buffer, "stroke-opacity: %g", fval);
1.18 cvs 4322: break;
1.195 vatton 4323: case PRFillOpacity:
4324: sprintf (buffer, "fill-opacity: %g", fval);
1.18 cvs 4325: break;
4326: case PRBackgroundPicture:
4327: if (settings->value.pointer != NULL)
1.82 cvs 4328: sprintf (buffer, "background-image: url(%s)",
1.67 cvs 4329: (char*)(settings->value.pointer));
1.1 cvs 4330: else
1.82 cvs 4331: sprintf (buffer, "background-image: none");
1.18 cvs 4332: break;
4333: case PRPictureMode:
4334: switch (settings->value.typed_data.value)
1.1 cvs 4335: {
1.184 vatton 4336: case REALSIZE:
1.82 cvs 4337: sprintf (buffer, "background-repeat: no-repeat");
1.18 cvs 4338: break;
1.184 vatton 4339: case REPEAT:
1.82 cvs 4340: sprintf (buffer, "background-repeat: repeat");
1.18 cvs 4341: break;
1.184 vatton 4342: case VREPEAT:
1.82 cvs 4343: sprintf (buffer, "background-repeat: repeat-y");
1.18 cvs 4344: break;
1.184 vatton 4345: case HREPEAT:
1.82 cvs 4346: sprintf (buffer, "background-repeat: repeat-x");
1.18 cvs 4347: break;
1.1 cvs 4348: }
1.18 cvs 4349: break;
4350: default:
4351: break;
1.1 cvs 4352: }
4353:
1.18 cvs 4354: if (add_unit)
1.1 cvs 4355: {
1.18 cvs 4356: /* add the unit string to the CSS string */
4357: for (i = 0; i < NB_UNITS; i++)
1.1 cvs 4358: {
1.18 cvs 4359: if (CSSUnitNames[i].unit == unit)
1.1 cvs 4360: {
1.82 cvs 4361: strcat (buffer, CSSUnitNames[i].sign);
1.18 cvs 4362: break;
1.1 cvs 4363: }
4364: }
4365: }
4366: }
4367:
4368: /*----------------------------------------------------------------------
1.59 cvs 4369: ParseHTMLSpecificStyle: parse and apply a CSS Style string.
1.18 cvs 4370: This function must be called when a specific style is applied to an
4371: element.
1.114 quint 4372: The parameter specificity is the specificity of the style, 0 if it is
4373: not really a CSS rule.
1.1 cvs 4374: ----------------------------------------------------------------------*/
1.79 cvs 4375: void ParseHTMLSpecificStyle (Element el, char *cssRule, Document doc,
1.114 quint 4376: int specificity, ThotBool destroy)
1.1 cvs 4377: {
4378: PresentationContext context;
4379: ElementType elType;
1.14 cvs 4380: ThotBool isHTML;
1.1 cvs 4381:
4382: /* A rule applying to BODY is really meant to address HTML */
4383: elType = TtaGetElementType (el);
1.89 cvs 4384:
1.86 cvs 4385: /* store the current line for eventually reported errors */
4386: LineNumber = TtaGetElementLineNumber (el);
1.89 cvs 4387: if (destroy)
4388: /* no reported errors */
4389: ParsedDoc = 0;
4390: else if (ParsedDoc != doc)
4391: {
4392: /* update the context for reported errors */
4393: ParsedDoc = doc;
4394: DocURL = DocumentURLs[doc];
4395: }
1.82 cvs 4396: isHTML = (strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML") == 0);
1.1 cvs 4397: /* create the context of the Specific presentation driver */
4398: context = TtaGetSpecificStyleContext (doc);
4399: if (context == NULL)
4400: return;
4401: context->type = elType.ElTypeNum;
1.114 quint 4402: context->cssSpecificity = specificity;
1.1 cvs 4403: context->destroy = destroy;
4404: /* Call the parser */
1.155 cheyroul 4405: ParseCSSRule (el, NULL,
4406: (PresentationContext) context,
4407: cssRule, NULL, isHTML);
1.1 cvs 4408: /* free the context */
4409: TtaFreeMemory(context);
4410: }
4411:
1.68 cvs 4412:
1.1 cvs 4413: /*----------------------------------------------------------------------
1.59 cvs 4414: ParseGenericSelector: Create a generic context for a given
1.1 cvs 4415: selector string. If the selector is made of multiple comma-
4416: separated selector items, it parses them one at a time and
4417: return the end of the selector string to be handled or NULL
4418: ----------------------------------------------------------------------*/
1.197 vatton 4419: static char *ParseGenericSelector (char *selector, char *cssRule, char *sel,
1.79 cvs 4420: GenericContext ctxt, Document doc,
1.206 ! vatton 4421: CSSInfoPtr css, Element link)
1.79 cvs 4422: {
4423: ElementType elType;
4424: PSchema tsch;
1.119 vatton 4425: AttributeType attrType;
1.118 vatton 4426: char *deb, *cur, c;
4427: char *schemaName, *mappedName;
1.79 cvs 4428: char *names[MAX_ANCESTORS];
4429: char *ids[MAX_ANCESTORS];
4430: char *classes[MAX_ANCESTORS];
4431: char *pseudoclasses[MAX_ANCESTORS];
4432: char *attrs[MAX_ANCESTORS];
4433: char *attrvals[MAX_ANCESTORS];
1.133 vatton 4434: AttrMatch attrmatch[MAX_ANCESTORS];
1.91 cvs 4435: int i, j, k, max;
1.125 vatton 4436: int att, maxAttr, kind;
1.118 vatton 4437: int specificity, xmlType;
1.79 cvs 4438: ThotBool isHTML;
1.183 vatton 4439: ThotBool level, quoted;
1.1 cvs 4440:
1.82 cvs 4441: sel[0] = EOS;
1.117 vatton 4442: specificity = 0;
1.1 cvs 4443: for (i = 0; i < MAX_ANCESTORS; i++)
4444: {
1.25 cvs 4445: names[i] = NULL;
4446: ids[i] = NULL;
4447: classes[i] = NULL;
4448: pseudoclasses[i] = NULL;
4449: attrs[i] = NULL;
4450: attrvals[i] = NULL;
1.133 vatton 4451: attrmatch[i] = Txtmatch;
1.25 cvs 4452: ctxt->name[i] = 0;
4453: ctxt->names_nb[i] = 0;
4454: ctxt->attrType[i] = 0;
1.129 vatton 4455: ctxt->attrLevel[i] = 0;
1.25 cvs 4456: ctxt->attrText[i] = NULL;
1.178 quint 4457: ctxt->attrMatch[i] = Txtmatch;
1.1 cvs 4458: }
1.25 cvs 4459: ctxt->box = 0;
4460: ctxt->type = 0;
1.114 quint 4461: /* the specificity of the rule depends on the selector */
4462: ctxt->cssSpecificity = 0;
1.25 cvs 4463:
1.82 cvs 4464: selector = SkipBlanksAndComments (selector);
1.27 cvs 4465: cur = &sel[0];
1.25 cvs 4466: max = 0; /* number of loops */
1.1 cvs 4467: while (1)
4468: {
1.85 cvs 4469: /* point to the following word in sel[] */
1.27 cvs 4470: deb = cur;
1.25 cvs 4471: /* copy an item of the selector into sel[] */
1.1 cvs 4472: /* put one word in the sel buffer */
1.82 cvs 4473: while (*selector != EOS && *selector != ',' &&
4474: *selector != '.' && *selector != ':' &&
1.118 vatton 4475: *selector != '#' && *selector != '[' &&
1.130 vatton 4476: *selector != '*' && *selector != '>' &&
1.118 vatton 4477: !TtaIsBlank (selector))
1.50 cvs 4478: *cur++ = *selector++;
1.82 cvs 4479: *cur++ = EOS; /* close the first string in sel[] */
4480: if (deb[0] != EOS)
1.117 vatton 4481: {
4482: names[0] = deb;
1.150 vatton 4483: if (!strcmp (names[0], "html"))
1.149 vatton 4484: /* give a greater priority to the backgoud color of html */
4485: specificity += 3;
4486: else
4487: specificity += 1;
1.117 vatton 4488: }
1.25 cvs 4489: else
1.27 cvs 4490: names[0] = NULL;
4491: classes[0] = NULL;
4492: pseudoclasses[0] = NULL;
4493: ids[0] = NULL;
4494: attrs[0] = NULL;
4495: attrvals[0] = NULL;
1.25 cvs 4496:
1.27 cvs 4497: /* now names[0] points to the beginning of the parsed item
1.25 cvs 4498: and cur to the next chain to be parsed */
1.129 vatton 4499: while (*selector == '.' || *selector == ':' ||
1.130 vatton 4500: *selector == '#' || *selector == '[' ||
1.183 vatton 4501: *selector == '*')
1.129 vatton 4502: {
1.85 cvs 4503: /* point to the following word in sel[] */
4504: deb = cur;
1.202 vatton 4505: if (*selector == '*' &&
4506: (selector[1] == '.' || selector[1] == ':' ||
4507: selector[1] == '#' || selector[1] == '['))
4508: selector++;
1.129 vatton 4509: if (*selector == '.')
4510: {
4511: selector++;
4512: while (*selector != EOS && *selector != ',' &&
4513: *selector != '.' && *selector != ':' &&
4514: !TtaIsBlank (selector))
4515: *cur++ = *selector++;
4516: /* close the word */
4517: *cur++ = EOS;
4518: /* point to the class in sel[] if it's valid name */
4519: if (deb[0] <= 64)
4520: {
1.168 vatton 4521: CSSPrintError ("Invalid class", deb);
1.116 vatton 4522: DoApply = FALSE;
1.129 vatton 4523: }
4524: else
4525: {
4526: classes[0] = deb;
1.178 quint 4527: /* a "class" attribute on an element may contain several
4528: words, one for each class it matches */
4529: attrmatch[0] = Txtword;
1.117 vatton 4530: specificity += 10;
1.129 vatton 4531: }
4532: }
4533: else if (*selector == ':')
4534: {
4535: selector++;
4536: while (*selector != EOS && *selector != ',' &&
4537: *selector != '.' && *selector != ':' &&
4538: !TtaIsBlank (selector))
4539: *cur++ = *selector++;
4540: /* close the word */
4541: *cur++ = EOS;
4542: /* point to the pseudoclass in sel[] if it's valid name */
4543: if (deb[0] <= 64)
4544: {
1.168 vatton 4545: CSSPrintError ("Invalid pseudoclass", deb);
1.129 vatton 4546: DoApply = FALSE;
4547: }
4548: else
4549: {
4550: if (!strcmp (deb, "first-letter") ||
4551: !strcmp (deb, "first-line") ||
4552: !strcmp (deb, "before") ||
4553: !strcmp (deb, "after"))
4554: /* not supported */
1.116 vatton 4555: DoApply = FALSE;
1.129 vatton 4556: else
4557: specificity += 10;
4558: pseudoclasses[0]= deb;
4559: }
4560: }
4561: else if (*selector == '#')
4562: {
4563: selector++;
4564: while (*selector != EOS && *selector != ',' &&
4565: *selector != '.' && *selector != ':' &&
4566: !TtaIsBlank (selector))
4567: *cur++ = *selector++;
4568: /* close the word */
4569: *cur++ = EOS;
4570: /* point to the attribute in sel[] if it's valid name */
4571: if (deb[0] <= 64)
4572: {
1.168 vatton 4573: CSSPrintError ("Invalid id", deb);
1.129 vatton 4574: DoApply = FALSE;
4575: }
4576: else
4577: {
4578: ids[0] = deb;
4579: specificity += 100;
4580: }
4581: }
4582: else if (*selector == '[')
4583: {
1.118 vatton 4584: selector++;
1.129 vatton 4585: while (*selector != EOS && *selector != ']' &&
1.131 vatton 4586: *selector != '=' && *selector != '~' &&
1.133 vatton 4587: *selector != '|' && *selector != '^' &&
4588: *selector != '!')
1.129 vatton 4589: *cur++ = *selector++;
1.133 vatton 4590: /* check matching */
4591: if (*selector == '~')
4592: {
4593: attrmatch[0] = Txtword;
4594: selector++;
4595: }
4596: else if (*selector == '|')
4597: {
4598: attrmatch[0] = Txtsubstring;
4599: selector++;
4600: }
4601: else
4602: attrmatch[0] = Txtmatch;
1.129 vatton 4603: /* close the word */
4604: *cur++ = EOS;
4605: /* point to the attribute in sel[] if it's valid name */
4606: if (deb[0] <= 64)
4607: {
1.168 vatton 4608: CSSPrintError ("Invalid attribute", deb);
1.129 vatton 4609: DoApply = FALSE;
4610: }
4611: else
4612: {
4613: attrs[0] = deb;
4614: specificity += 10;
4615: }
4616: if (*selector == '=')
4617: {
4618: /* look for a value "xxxx" */
4619: selector++;
4620: if (*selector != '"')
1.183 vatton 4621: quoted = FALSE;
1.129 vatton 4622: else
4623: {
1.183 vatton 4624: quoted = TRUE;
1.129 vatton 4625: /* we are now parsing the attribute value */
4626: selector++;
1.183 vatton 4627: }
4628: deb = cur;
4629: while ((quoted &&
4630: (*selector != '"' ||
4631: (*selector == '"' && selector[-1] == '\\'))) ||
4632: (!quoted && *selector != ']'))
4633: {
4634: if (*selector == EOS)
1.129 vatton 4635: {
1.183 vatton 4636: CSSPrintError ("Invalid attribute value", deb);
4637: DoApply = FALSE;
1.129 vatton 4638: }
1.183 vatton 4639: else
1.129 vatton 4640: {
1.183 vatton 4641: *cur++ = tolower (*selector);
1.129 vatton 4642: selector++;
4643: }
4644: }
1.183 vatton 4645: /* there is a value */
1.204 quint 4646: if (quoted && *selector == '"')
1.183 vatton 4647: {
4648: selector++;
4649: quoted = FALSE;
4650: }
4651: if (*selector != ']')
4652: {
4653: CSSPrintError ("Invalid attribute value", deb);
4654: DoApply = FALSE;
4655: }
4656: else
4657: {
4658: *cur++ = EOS;
4659: attrvals[0] = deb;
4660: selector++;
4661: }
1.129 vatton 4662: }
4663: /* end of the attribute */
1.183 vatton 4664: else if (*selector != ']')
1.129 vatton 4665: {
1.133 vatton 4666: selector[1] = EOS;
1.183 vatton 4667: CSSPrintError ("Invalid attribute", selector);
1.133 vatton 4668: selector += 2;
1.129 vatton 4669: DoApply = FALSE;
4670: }
4671: else
4672: selector++;
1.130 vatton 4673: }
4674: else
4675: {
4676: /* not supported selector */
4677: while (*selector != EOS && *selector != ',' &&
4678: *selector != '.' && *selector != ':' &&
4679: !TtaIsBlank (selector))
4680: *cur++ = *selector++;
4681: /* close the word */
4682: *cur++ = EOS;
1.205 quint 4683: CSSPrintError ("Selector not supported:", deb);
1.130 vatton 4684: DoApply = FALSE;
1.129 vatton 4685: }
4686: }
1.1 cvs 4687:
1.82 cvs 4688: selector = SkipBlanksAndComments (selector);
1.25 cvs 4689: /* is it a multi-level selector? */
1.82 cvs 4690: if (*selector == EOS)
1.1 cvs 4691: /* end of the selector */
4692: break;
1.82 cvs 4693: else if (*selector == ',')
1.1 cvs 4694: {
4695: /* end of the current selector */
4696: selector++;
4697: break;
4698: }
1.25 cvs 4699: else
4700: {
1.143 vatton 4701: if (*selector == '>')
4702: {
4703: /* handle immediat parent as a simple parent */
4704: selector++;
4705: selector = SkipBlanksAndComments (selector);
4706: }
1.25 cvs 4707: /* shifts the list to make room for the new name */
4708: max++; /* a new level in ancestor tables */
4709: if (max == MAX_ANCESTORS)
4710: /* abort the CSS parsing */
4711: return (selector);
4712: for (i = max; i > 0; i--)
4713: {
4714: names[i] = names[i - 1];
4715: ids[i] = ids[i - 1];
4716: classes[i] = classes[i - 1];
1.133 vatton 4717: pseudoclasses[i] = pseudoclasses[i - 1];
1.25 cvs 4718: attrs[i] = attrs[i - 1];
4719: attrvals[i] = attrvals[i - 1];
1.133 vatton 4720: attrmatch[i] = attrmatch[i - 1];
1.25 cvs 4721: }
4722: }
1.1 cvs 4723: }
4724:
4725: /* Now set up the context block */
1.25 cvs 4726: i = 0;
4727: k = 0;
4728: j = 0;
1.35 cvs 4729: maxAttr = 0;
1.91 cvs 4730: /* default schema name */
1.119 vatton 4731: ctxt->schema = NULL;
1.122 vatton 4732: elType.ElSSchema = NULL;
4733: schemaName = TtaGetSSchemaName(TtaGetDocumentSSchema (doc));
1.119 vatton 4734: if (!strcmp (schemaName, "HTML"))
4735: xmlType = XHTML_TYPE;
4736: else if (!strcmp (schemaName, "MathML"))
4737: xmlType = MATH_TYPE;
4738: else if (!strcmp (schemaName, "SVG"))
4739: xmlType = SVG_TYPE;
4740: else if (!strcmp (schemaName, "XLink"))
4741: xmlType = XLINK_TYPE;
4742: else if (!strcmp (schemaName, "Annot"))
4743: xmlType = ANNOT_TYPE;
4744: else
4745: xmlType = XML_TYPE;
1.25 cvs 4746: while (i <= max)
4747: {
4748: if (names[i])
4749: {
1.118 vatton 4750: /* get the element type of this name in the current document */
4751: MapXMLElementType (xmlType, names[i], &elType, &mappedName, &c, &level, doc);
1.25 cvs 4752: if (i == 0)
4753: {
1.106 cvs 4754: if (elType.ElSSchema == NULL)
4755: {
1.119 vatton 4756: /* Search in the list of loaded schemas */
1.106 cvs 4757: TtaGetXmlElementType (names[i], &elType, NULL, doc);
1.119 vatton 4758: if (elType.ElSSchema)
4759: {
1.154 vatton 4760: /* the element type concerns an imported nature */
1.119 vatton 4761: schemaName = TtaGetSSchemaName(elType.ElSSchema);
4762: if (!strcmp (schemaName, "HTML"))
4763: xmlType = XHTML_TYPE;
4764: else if (!strcmp (schemaName, "MathML"))
4765: xmlType = MATH_TYPE;
4766: else if (!strcmp (schemaName, "SVG"))
4767: xmlType = SVG_TYPE;
4768: else if (!strcmp (schemaName, "XLink"))
4769: xmlType = XLINK_TYPE;
4770: else if (!strcmp (schemaName, "Annot"))
4771: xmlType = ANNOT_TYPE;
4772: else
4773: xmlType = XML_TYPE;
4774: }
1.118 vatton 4775: #ifdef XML_GENERIC
1.119 vatton 4776: else if (xmlType == XML_TYPE)
1.106 cvs 4777: {
4778: /* Creation of a new element type in the main schema */
4779: elType.ElSSchema = TtaGetDocumentSSchema (doc);
1.118 vatton 4780: TtaAppendXmlElement (names[i], &elType, &mappedName, doc);
1.106 cvs 4781: }
1.118 vatton 4782: #endif /* XML_GENERIC */
1.122 vatton 4783: else
4784: {
4785: if (xmlType != XHTML_TYPE)
4786: {
4787: MapXMLElementType (XHTML_TYPE, names[i], &elType,
4788: &mappedName, &c, &level, doc);
4789: if (elType.ElSSchema)
1.123 vatton 4790: elType.ElSSchema = GetXHTMLSSchema (doc);
1.122 vatton 4791: }
4792: if (elType.ElSSchema == NULL && xmlType != MATH_TYPE)
4793: {
4794: MapXMLElementType (MATH_TYPE, names[i], &elType,
4795: &mappedName, &c, &level, doc);
4796: if (elType.ElSSchema)
1.123 vatton 4797: elType.ElSSchema = GetMathMLSSchema (doc);
1.122 vatton 4798: }
4799: if (elType.ElSSchema == NULL && xmlType != SVG_TYPE)
4800: {
4801: MapXMLElementType (SVG_TYPE, names[i], &elType,
4802: &mappedName, &c, &level, doc);
4803: if (elType.ElSSchema)
1.123 vatton 4804: elType.ElSSchema = GetSVGSSchema (doc);
1.122 vatton 4805: }
4806: }
1.118 vatton 4807: }
1.119 vatton 4808:
1.118 vatton 4809: if (elType.ElSSchema == NULL)
4810: /* cannot apply these CSS rules */
4811: DoApply = FALSE;
4812: else
4813: {
4814: /* Store the element type */
4815: ctxt->type = elType.ElTypeNum;
4816: ctxt->name[0] = elType.ElTypeNum;
4817: ctxt->names_nb[0] = 0;
4818: ctxt->schema = elType.ElSSchema;
1.106 cvs 4819: }
1.25 cvs 4820: }
4821: else if (elType.ElTypeNum != 0)
4822: {
4823: /* look at the current context to see if the type is already
4824: stored */
1.121 vatton 4825: j = 1;
1.32 cvs 4826: while (j < k && ctxt->name[j] != elType.ElTypeNum)
1.25 cvs 4827: j++;
4828: if (j == k)
4829: {
4830: ctxt->name[j] = elType.ElTypeNum;
4831: if (j != 0)
1.121 vatton 4832: ctxt->names_nb[j] = 1;
1.25 cvs 4833: }
4834: else
4835: /* increment the number of ancestor levels */
4836: ctxt->names_nb[j]++;
4837: }
1.154 vatton 4838: #ifdef XML_GENERIC
4839: else if (xmlType == XML_TYPE)
4840: {
1.158 vatton 4841: TtaGetXmlElementType (names[i], &elType, NULL, doc);
4842: if (elType.ElTypeNum == 0)
4843: {
4844: /* Creation of a new element type in the main schema */
4845: elType.ElSSchema = TtaGetDocumentSSchema (doc);
4846: TtaAppendXmlElement (names[i], &elType, &mappedName, doc);
4847: }
1.154 vatton 4848: if (elType.ElTypeNum != 0)
4849: {
4850: /* look at the current context to see if the type is already
4851: stored */
4852: j = 1;
4853: while (j < k && ctxt->name[j] != elType.ElTypeNum)
4854: j++;
4855: if (j == k)
4856: {
4857: ctxt->name[j] = elType.ElTypeNum;
4858: if (j != 0)
4859: ctxt->names_nb[j] = 1;
4860: }
4861: else
4862: /* increment the number of ancestor levels */
4863: ctxt->names_nb[j]++;
4864: }
4865: }
4866: #endif /* XML_GENERIC */
1.25 cvs 4867: else
1.117 vatton 4868: j = k;
1.25 cvs 4869: }
1.117 vatton 4870: else
4871: j = k;
1.1 cvs 4872:
1.25 cvs 4873: /* store attributes information */
4874: if (classes[i])
4875: {
4876: ctxt->attrText[j] = classes[i];
1.119 vatton 4877: if (xmlType == SVG_TYPE)
1.100 vatton 4878: ctxt->attrType[j] = SVG_ATTR_class;
1.119 vatton 4879: else if (xmlType == MATH_TYPE)
1.91 cvs 4880: ctxt->attrType[j] = MathML_ATTR_class;
1.119 vatton 4881: else if (xmlType == XHTML_TYPE)
1.107 cvs 4882: ctxt->attrType[j] = HTML_ATTR_Class;
4883: else
1.119 vatton 4884: #ifdef XML_GENERIC
1.107 cvs 4885: ctxt->attrType[j] = XML_ATTR_class;
4886: #else /* XML_GENERIC */
1.91 cvs 4887: ctxt->attrType[j] = HTML_ATTR_Class;
1.107 cvs 4888: #endif /* XML_GENERIC */
1.157 vatton 4889: ctxt->attrMatch[j] = attrmatch[i];
1.79 cvs 4890: /* add a new entry */
1.80 cvs 4891: maxAttr = i + 1;
1.129 vatton 4892: /* update attrLevel */
4893: ctxt->attrLevel[j] = i;
4894: j++;
1.25 cvs 4895: }
1.79 cvs 4896: if (pseudoclasses[i])
1.25 cvs 4897: {
4898: ctxt->attrText[j] = pseudoclasses[i];
1.119 vatton 4899: if (xmlType == SVG_TYPE)
1.100 vatton 4900: ctxt->attrType[j] = SVG_ATTR_PseudoClass;
1.119 vatton 4901: else if (xmlType == MATH_TYPE)
1.91 cvs 4902: ctxt->attrType[j] = MathML_ATTR_PseudoClass;
1.119 vatton 4903: else if (xmlType == XHTML_TYPE)
1.107 cvs 4904: ctxt->attrType[j] = HTML_ATTR_PseudoClass;
4905: else
1.119 vatton 4906: #ifdef XML_GENERIC
1.107 cvs 4907: ctxt->attrType[j] = XML_ATTR_PseudoClass;
4908: #else /* XML_GENERIC */
1.91 cvs 4909: ctxt->attrType[j] = HTML_ATTR_PseudoClass;
1.107 cvs 4910: #endif /* XML_GENERIC */
1.157 vatton 4911: ctxt->attrMatch[j] = attrmatch[i];
1.79 cvs 4912: /* add a new entry */
1.80 cvs 4913: maxAttr = i + 1;
1.129 vatton 4914: /* update attrLevel */
4915: ctxt->attrLevel[j] = i;
4916: j++;
1.25 cvs 4917: }
1.79 cvs 4918: if (ids[i])
1.25 cvs 4919: {
4920: ctxt->attrText[j] = ids[i];
1.119 vatton 4921: if (xmlType == SVG_TYPE)
1.100 vatton 4922: ctxt->attrType[j] = SVG_ATTR_id;
1.119 vatton 4923: else if (xmlType == MATH_TYPE)
1.91 cvs 4924: ctxt->attrType[j] = MathML_ATTR_id;
1.119 vatton 4925: else if (xmlType == XHTML_TYPE)
1.107 cvs 4926: ctxt->attrType[j] = HTML_ATTR_ID;
4927: else
1.119 vatton 4928: #ifdef XML_GENERIC
1.107 cvs 4929: ctxt->attrType[j] = XML_ATTR_id;
4930: #else /* XML_GENERIC */
1.91 cvs 4931: ctxt->attrType[j] = HTML_ATTR_ID;
1.107 cvs 4932: #endif /* XML_GENERIC */
1.157 vatton 4933: ctxt->attrMatch[j] = attrmatch[i];
1.80 cvs 4934: /* add a new entry */
4935: maxAttr = i + 1;
1.129 vatton 4936: /* update attrLevel */
4937: ctxt->attrLevel[j] = i;
4938: j++;
1.25 cvs 4939: }
1.79 cvs 4940: if (attrs[i])
1.25 cvs 4941: {
1.125 vatton 4942: /* it's an attribute */
1.119 vatton 4943: MapXMLAttribute (xmlType, attrs[i], names[i], &level, doc, &att);
1.127 quint 4944: if (att == DummyAttribute && !strcmp (schemaName, "HTML"))
4945: /* it's the "type" attribute for an "input" element. In the tree
4946: it's represented by the element type, not by an attribute */
4947: att = 0;
1.119 vatton 4948: ctxt->attrType[j] = att;
1.133 vatton 4949: ctxt->attrMatch[j] = attrmatch[i];
1.125 vatton 4950: attrType.AttrSSchema = ctxt->schema;
4951: attrType.AttrTypeNum = att;
1.119 vatton 4952: if (i == 0 && att == 0 && ctxt->schema == NULL)
4953: {
1.125 vatton 4954: /* Not found -> search in the list of loaded schemas */
1.119 vatton 4955: attrType.AttrSSchema = NULL;
4956: TtaGetXmlAttributeType (attrs[i], &attrType, doc);
4957: ctxt->attrType[j] = attrType.AttrTypeNum;
4958: if (attrType.AttrSSchema)
1.125 vatton 4959: /* the element type concerns an imported nature */
4960: schemaName = TtaGetSSchemaName(attrType.AttrSSchema);
1.119 vatton 4961: #ifdef XML_GENERIC
4962: else if (xmlType == XML_TYPE)
4963: {
4964: /* The attribute is not yet present in the tree */
4965: /* Create a new global attribute */
4966: attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
4967: TtaAppendXmlAttribute (attrs[i], &attrType, doc);
4968: }
4969: #endif /* XML_GENERIC */
4970:
4971: if (attrType.AttrSSchema == NULL)
4972: /* cannot apply these CSS rules */
4973: DoApply = FALSE;
1.136 quint 4974: else if (elType.ElSSchema)
4975: ctxt->schema = elType.ElSSchema;
1.119 vatton 4976: else
1.136 quint 4977: ctxt->schema = attrType.AttrSSchema;
1.119 vatton 4978: }
1.125 vatton 4979: /* check the attribute type */
4980: if (!strcmp (schemaName, "HTML"))
4981: xmlType = XHTML_TYPE;
4982: else if (!strcmp (schemaName, "MathML"))
4983: xmlType = MATH_TYPE;
4984: else if (!strcmp (schemaName, "SVG"))
4985: xmlType = SVG_TYPE;
4986: else if (!strcmp (schemaName, "XLink"))
4987: xmlType = XLINK_TYPE;
4988: else if (!strcmp (schemaName, "Annot"))
4989: xmlType = ANNOT_TYPE;
4990: else
4991: xmlType = XML_TYPE;
4992: kind = TtaGetAttributeKind (attrType);
4993: if (kind == 0 && attrvals[i])
4994: {
4995: /* enumerated value */
4996: MapXMLAttributeValue (xmlType, attrvals[i], attrType, &kind);
4997: /* store the attribute value */
4998: ctxt->attrText[j] = (char *) kind;
4999: }
5000: else
5001: ctxt->attrText[j] = attrvals[i];
1.80 cvs 5002: maxAttr = i + 1;
1.129 vatton 5003: /* update attrLevel */
5004: ctxt->attrLevel[j] = i;
5005: j++;
1.25 cvs 5006: }
5007: i++;
1.117 vatton 5008: /* add a new entry */
5009: k++;
1.129 vatton 5010: if (k < j)
5011: k = j;
1.119 vatton 5012: if (i == 1 && ctxt->schema == NULL)
5013: /* use the document schema */
5014: ctxt->schema = TtaGetDocumentSSchema (doc);
1.1 cvs 5015: }
1.117 vatton 5016: /* set the selector specificity */
5017: ctxt->cssSpecificity = specificity;
1.25 cvs 5018: /* sort the list of ancestors by name order */
5019: max = k;
5020: i = 1;
5021: while (i < max)
1.28 cvs 5022: {
5023: for (k = i + 1; k < max; k++)
5024: if (ctxt->name[i] > ctxt->name[k])
5025: {
5026: j = ctxt->name[i];
5027: ctxt->name[i] = ctxt->name[k];
5028: ctxt->name[k] = j;
5029: j = ctxt->names_nb[i];
5030: ctxt->names_nb[i] = ctxt->names_nb[k];
5031: ctxt->names_nb[k] = j;
5032: j = ctxt->attrType[i];
5033: ctxt->attrType[i] = ctxt->attrType[k];
5034: ctxt->attrType[k] = j;
5035: cur = ctxt->attrText[i];
5036: ctxt->attrText[i] = ctxt->attrText[k];
5037: ctxt->attrText[k] = cur;
5038: }
5039: i++;
5040: }
1.84 cvs 5041:
1.25 cvs 5042: /* Get the schema name of the main element */
1.119 vatton 5043: schemaName = TtaGetSSchemaName (ctxt->schema);
5044: isHTML = (strcmp (schemaName, "HTML") == 0);
1.206 ! vatton 5045: tsch = GetPExtension (doc, ctxt->schema, css, link);
1.119 vatton 5046: if (tsch && cssRule)
5047: ParseCSSRule (NULL, tsch, (PresentationContext) ctxt, cssRule, css, isHTML);
1.116 vatton 5048: /* future CSS rules should apply */
5049: DoApply = TRUE;
1.1 cvs 5050: return (selector);
5051: }
5052:
5053: /*----------------------------------------------------------------------
1.206 ! vatton 5054: ParseStyleDeclaration: parse a style declaration stored in the style
! 5055: element of a document
! 5056: We expect the style string to be of the form:
! 5057: .pinky, .awful { color: pink; font-family: helvetica }
1.1 cvs 5058: ----------------------------------------------------------------------*/
1.206 ! vatton 5059: static void ParseStyleDeclaration (Element el, char *cssRule, Document doc,
! 5060: CSSInfoPtr css, Element link, ThotBool destroy)
1.1 cvs 5061: {
1.79 cvs 5062: GenericContext ctxt;
1.197 vatton 5063: char sel[MAX_ANCESTORS * 50];
1.79 cvs 5064: char *decl_end;
5065: char *sel_end;
5066: char *selector;
1.1 cvs 5067:
5068: /* separate the selectors string */
1.82 cvs 5069: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 5070: decl_end = cssRule;
1.82 cvs 5071: while (*decl_end != EOS && *decl_end != '{')
1.1 cvs 5072: decl_end++;
1.82 cvs 5073: if (*decl_end == EOS)
1.86 cvs 5074: {
1.168 vatton 5075: CSSPrintError ("Invalid selector", cssRule);
1.86 cvs 5076: return;
5077: }
1.1 cvs 5078: /* verify and clean the selector string */
5079: sel_end = decl_end - 1;
1.82 cvs 5080: while (*sel_end == SPACE || *sel_end == BSPACE ||
5081: *sel_end == EOL || *sel_end == CR)
1.1 cvs 5082: sel_end--;
5083: sel_end++;
1.82 cvs 5084: *sel_end = EOS;
1.1 cvs 5085: selector = cssRule;
5086:
5087: /* now, deal with the content ... */
5088: decl_end++;
5089: cssRule = decl_end;
1.137 vatton 5090: decl_end = &cssRule[strlen (cssRule) - 1];
5091: if (*decl_end != '{')
5092: *decl_end = EOS;
1.1 cvs 5093: /*
5094: * parse the style attribute string and install the corresponding
5095: * presentation attributes on the new element
5096: */
5097: ctxt = TtaGetGenericStyleContext (doc);
5098: if (ctxt == NULL)
5099: return;
5100: ctxt->destroy = destroy;
5101:
1.197 vatton 5102: while (selector && *selector != EOS)
1.206 ! vatton 5103: selector = ParseGenericSelector (selector, cssRule, sel, ctxt, doc,
! 5104: css, link);
1.1 cvs 5105: TtaFreeMemory (ctxt);
5106: }
5107:
5108: /************************************************************************
5109: * *
5110: * EVALUATION FUNCTIONS / CASCADING AND OVERLOADING *
5111: * *
5112: ************************************************************************/
5113:
5114: /*----------------------------------------------------------------------
1.59 cvs 5115: IsImplicitClassName: return wether the Class name is an
1.1 cvs 5116: implicit one, eg "H1" or "H2 EM" meaning it's a GI name
5117: or an HTML context name.
5118: ----------------------------------------------------------------------*/
1.206 ! vatton 5119: int IsImplicitClassName (char *class, Document doc)
1.1 cvs 5120: {
1.79 cvs 5121: char name[200];
5122: char *cur = name;
5123: char *first;
5124: char save;
5125: SSchema schema;
1.1 cvs 5126:
5127: /* make a local copy */
1.82 cvs 5128: strncpy (name, class, 199);
1.1 cvs 5129: name[199] = 0;
5130:
5131: /* loop looking if each word is a GI */
5132: while (*cur != 0)
5133: {
5134: first = cur;
5135: cur = SkipWord (cur);
5136: save = *cur;
5137: *cur = 0;
5138: schema = NULL;
5139: if (MapGI (first, &schema, doc) == -1)
5140: {
5141: return (0);
5142: }
5143: *cur = save;
1.82 cvs 5144: cur = SkipBlanksAndComments (cur);
1.1 cvs 5145: }
5146: return (1);
5147: }
5148:
5149: /************************************************************************
5150: * *
1.114 quint 5151: * Functions needed for support of HTML: translate to CSS equivalent *
1.1 cvs 5152: * *
5153: ************************************************************************/
5154:
5155: /*----------------------------------------------------------------------
1.59 cvs 5156: HTMLSetBackgroundColor:
1.1 cvs 5157: ----------------------------------------------------------------------*/
1.79 cvs 5158: void HTMLSetBackgroundColor (Document doc, Element el, char *color)
1.1 cvs 5159: {
1.79 cvs 5160: char css_command[100];
1.1 cvs 5161:
1.82 cvs 5162: sprintf (css_command, "background-color: %s", color);
1.114 quint 5163: ParseHTMLSpecificStyle (el, css_command, doc, 0, FALSE);
1.1 cvs 5164: }
5165:
5166: /*----------------------------------------------------------------------
1.59 cvs 5167: HTMLSetForegroundColor:
1.1 cvs 5168: ----------------------------------------------------------------------*/
1.97 vatton 5169: void HTMLSetForegroundColor (Document doc, Element el, char *color)
1.1 cvs 5170: {
1.79 cvs 5171: char css_command[100];
1.1 cvs 5172:
1.82 cvs 5173: sprintf (css_command, "color: %s", color);
1.114 quint 5174: ParseHTMLSpecificStyle (el, css_command, doc, 0, FALSE);
1.1 cvs 5175: }
5176:
5177: /*----------------------------------------------------------------------
1.59 cvs 5178: HTMLResetBackgroundColor:
1.1 cvs 5179: ----------------------------------------------------------------------*/
1.97 vatton 5180: void HTMLResetBackgroundColor (Document doc, Element el)
1.1 cvs 5181: {
1.79 cvs 5182: char css_command[100];
1.1 cvs 5183:
1.82 cvs 5184: sprintf (css_command, "background: red");
1.114 quint 5185: ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1 cvs 5186: }
5187:
5188: /*----------------------------------------------------------------------
1.59 cvs 5189: HTMLResetBackgroundImage:
1.1 cvs 5190: ----------------------------------------------------------------------*/
1.97 vatton 5191: void HTMLResetBackgroundImage (Document doc, Element el)
1.1 cvs 5192: {
1.79 cvs 5193: char css_command[1000];
1.1 cvs 5194:
1.82 cvs 5195: sprintf (css_command, "background-image: url(xx); background-repeat: repeat");
1.114 quint 5196: ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1 cvs 5197: }
5198:
5199: /*----------------------------------------------------------------------
1.59 cvs 5200: HTMLResetForegroundColor:
1.1 cvs 5201: ----------------------------------------------------------------------*/
1.97 vatton 5202: void HTMLResetForegroundColor (Document doc, Element el)
1.1 cvs 5203: {
1.79 cvs 5204: char css_command[100];
1.1 cvs 5205:
1.36 cvs 5206: /* it's not necessary to well know the current color but it must be valid */
1.82 cvs 5207: sprintf (css_command, "color: red");
1.114 quint 5208: ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1 cvs 5209: }
5210:
5211: /*----------------------------------------------------------------------
1.59 cvs 5212: HTMLSetAlinkColor:
1.1 cvs 5213: ----------------------------------------------------------------------*/
1.97 vatton 5214: void HTMLSetAlinkColor (Document doc, char *color)
1.1 cvs 5215: {
1.79 cvs 5216: char css_command[100];
1.1 cvs 5217:
1.82 cvs 5218: sprintf (css_command, "a:link { color: %s }", color);
1.1 cvs 5219: ApplyCSSRules (NULL, css_command, doc, FALSE);
5220: }
5221:
5222: /*----------------------------------------------------------------------
1.59 cvs 5223: HTMLSetAactiveColor:
1.1 cvs 5224: ----------------------------------------------------------------------*/
1.97 vatton 5225: void HTMLSetAactiveColor (Document doc, char *color)
1.1 cvs 5226: {
1.79 cvs 5227: char css_command[100];
1.1 cvs 5228:
1.82 cvs 5229: sprintf (css_command, "a:active { color: %s }", color);
1.1 cvs 5230: ApplyCSSRules (NULL, css_command, doc, FALSE);
5231: }
5232:
5233: /*----------------------------------------------------------------------
1.59 cvs 5234: HTMLSetAvisitedColor:
1.1 cvs 5235: ----------------------------------------------------------------------*/
1.206 ! vatton 5236: void HTMLSetAvisitedColor (Document doc, char *color)
1.1 cvs 5237: {
1.79 cvs 5238: char css_command[100];
1.1 cvs 5239:
1.82 cvs 5240: sprintf (css_command, "a:visited { color: %s }", color);
1.1 cvs 5241: ApplyCSSRules (NULL, css_command, doc, FALSE);
5242: }
5243:
5244: /*----------------------------------------------------------------------
1.59 cvs 5245: HTMLResetAlinkColor:
1.1 cvs 5246: ----------------------------------------------------------------------*/
1.206 ! vatton 5247: void HTMLResetAlinkColor (Document doc)
1.1 cvs 5248: {
1.79 cvs 5249: char css_command[100];
1.1 cvs 5250:
1.82 cvs 5251: sprintf (css_command, "a:link { color: red }");
1.1 cvs 5252: ApplyCSSRules (NULL, css_command, doc, TRUE);
5253: }
5254:
5255: /*----------------------------------------------------------------------
1.59 cvs 5256: HTMLResetAactiveColor:
1.1 cvs 5257: ----------------------------------------------------------------------*/
1.206 ! vatton 5258: void HTMLResetAactiveColor (Document doc)
1.1 cvs 5259: {
1.79 cvs 5260: char css_command[100];
1.1 cvs 5261:
1.82 cvs 5262: sprintf (css_command, "a:active { color: red }");
1.1 cvs 5263: ApplyCSSRules (NULL, css_command, doc, TRUE);
5264: }
5265:
5266: /*----------------------------------------------------------------------
1.59 cvs 5267: HTMLResetAvisitedColor:
1.1 cvs 5268: ----------------------------------------------------------------------*/
1.206 ! vatton 5269: void HTMLResetAvisitedColor (Document doc)
1.1 cvs 5270: {
1.79 cvs 5271: char css_command[100];
1.1 cvs 5272:
1.82 cvs 5273: sprintf (css_command, "a:visited { color: red }");
1.1 cvs 5274: ApplyCSSRules (NULL, css_command, doc, TRUE);
5275: }
5276:
5277: /*----------------------------------------------------------------------
1.206 ! vatton 5278: ApplyCSSRules: parse a CSS Style description stored in the header of
! 5279: a HTML document.
1.1 cvs 5280: ----------------------------------------------------------------------*/
1.79 cvs 5281: void ApplyCSSRules (Element el, char *cssRule, Document doc, ThotBool destroy)
1.1 cvs 5282: {
1.206 ! vatton 5283: CSSInfoPtr css;
! 5284: PInfoPtr pInfo;
1.1 cvs 5285:
1.206 ! vatton 5286: css = SearchCSS (doc, NULL, el, &pInfo);
1.1 cvs 5287: if (css == NULL)
1.206 ! vatton 5288: /* create the document css context */
! 5289: css = AddCSS (doc, doc, CSS_DOCUMENT_STYLE, CSS_ALL, NULL, NULL, el);
! 5290: else if (pInfo == NULL)
! 5291: /* create the entry into the css context */
! 5292: pInfo = AddInfoCSS (doc, css, CSS_DOCUMENT_STYLE, CSS_ALL, el);
! 5293: ParseStyleDeclaration (el, cssRule, doc, css, el, destroy);
1.1 cvs 5294: }
5295:
5296: /*----------------------------------------------------------------------
1.145 quint 5297: ReadCSSRules: is the front-end function called by the document parser
5298: when detecting a <style type="text/css"> indicating it's the
1.1 cvs 5299: beginning of a CSS fragment or when reading a file .css.
5300:
5301: The CSS parser has to handle <!-- ... --> constructs used to
5302: prevent prehistoric browser from displaying the CSS as a text
5303: content. It will stop on any sequence "<x" where x is different
5304: from ! and will return x as to the caller. Theorically x should
1.145 quint 5305: be equal to / for the </style> end of style.
1.1 cvs 5306: The parameter doc gives the document tree that contains CSS information.
5307: The parameter docRef gives the document to which CSS are to be applied.
5308: This function uses the current css context or creates it. It's able
1.23 cvs 5309: to work on the given buffer or call GetNextChar to read the parsed
1.1 cvs 5310: file.
1.133 vatton 5311: The parameter url gives the URL of the style shheet parsed.
1.86 cvs 5312: Parameter numberOfLinesRead indicates the number of lines already
5313: read in the file.
1.1 cvs 5314: Parameter withUndo indicates whether the changes made in the document
1.145 quint 5315: structure and content have to be registered in the Undo queue or not.
1.1 cvs 5316: ----------------------------------------------------------------------*/
1.133 vatton 5317: char ReadCSSRules (Document docRef, CSSInfoPtr css, char *buffer, char *url,
1.144 quint 5318: int numberOfLinesRead, ThotBool withUndo,
1.206 ! vatton 5319: Element link)
1.1 cvs 5320: {
1.6 cvs 5321: DisplayMode dispMode;
1.206 ! vatton 5322: CSSInfoPtr refcss = NULL;
! 5323: PInfoPtr pInfo;
1.82 cvs 5324: char c;
1.138 vatton 5325: char *cssRule, *base, *saveDocURL, *ptr;
1.19 cvs 5326: int index;
1.1 cvs 5327: int CSSindex;
5328: int CSScomment;
5329: int import;
5330: int openRule;
1.93 vatton 5331: int newlines;
1.14 cvs 5332: ThotBool HTMLcomment;
1.102 vatton 5333: ThotBool toParse, eof, quoted;
1.36 cvs 5334: ThotBool ignoreMedia, media;
1.186 vatton 5335: ThotBool noRule, ignoreImport, skip;
1.1 cvs 5336:
5337: CSScomment = MAX_CSS_LENGTH;
5338: HTMLcomment = FALSE;
5339: CSSindex = 0;
5340: toParse = FALSE;
5341: noRule = FALSE;
1.36 cvs 5342: media = FALSE;
1.88 cvs 5343: ignoreImport = FALSE;
1.1 cvs 5344: ignoreMedia = FALSE;
5345: import = MAX_CSS_LENGTH;
5346: eof = FALSE;
5347: openRule = 0;
1.82 cvs 5348: c = SPACE;
1.1 cvs 5349: index = 0;
1.134 vatton 5350: base = NULL;
1.135 vatton 5351: quoted = FALSE;
1.186 vatton 5352: skip = FALSE;
1.93 vatton 5353: /* number of new lines parsed */
5354: newlines = 0;
1.6 cvs 5355: /* avoid too many redisplay */
5356: dispMode = TtaGetDisplayMode (docRef);
5357: if (dispMode == DisplayImmediately)
5358: TtaSetDisplayMode (docRef, DeferredDisplay);
1.18 cvs 5359:
5360: /* look for the CSS context */
5361: if (css == NULL)
1.206 ! vatton 5362: css = SearchCSS (docRef, NULL, link, &pInfo);
1.18 cvs 5363: if (css == NULL)
1.206 ! vatton 5364: {
! 5365: css = AddCSS (docRef, docRef, CSS_DOCUMENT_STYLE, CSS_ALL, NULL, NULL, link);
! 5366: pInfo = css->infos[docRef];
! 5367: }
! 5368: else if (pInfo == NULL)
! 5369: pInfo = AddInfoCSS (docRef, css, CSS_DOCUMENT_STYLE, CSS_ALL, link);
! 5370: else
! 5371: pInfo = css->infos[docRef];
1.174 vatton 5372: /* look for the CSS descriptor that points to the extension schema */
5373: refcss = css;
5374: if (import)
1.173 cvs 5375: {
1.206 ! vatton 5376: while (refcss &&
! 5377: refcss->infos[docRef] && refcss->infos[docRef]->PiCategory == CSS_IMPORT)
1.174 vatton 5378: refcss = refcss->NextCSS;
1.206 ! vatton 5379: if (refcss)
! 5380: pInfo = refcss->infos[docRef];
1.173 cvs 5381: }
5382:
1.144 quint 5383: /* register parsed CSS file and the document to which CSS are to be applied*/
1.86 cvs 5384: ParsedDoc = docRef;
1.133 vatton 5385: if (url)
5386: DocURL = url;
1.86 cvs 5387: else
5388: /* the CSS source in within the document itself */
5389: DocURL = DocumentURLs[docRef];
5390: LineNumber = numberOfLinesRead + 1;
1.93 vatton 5391: NewLineSkipped = 0;
1.82 cvs 5392: while (CSSindex < MAX_CSS_LENGTH && c != EOS && !eof)
5393: {
5394: c = buffer[index++];
5395: eof = (c == EOS);
5396: CSSbuffer[CSSindex] = c;
1.186 vatton 5397: if (skip)
5398: {
5399: if (c == '}')
5400: {
5401: /* end of the @font-face */
5402: skip = FALSE;
5403: import = MAX_CSS_LENGTH;
5404: noRule = TRUE;
5405: CSSindex = 0;
5406: }
5407: if (c == EOL)
5408: LineNumber++;
5409: c = CR;
5410: }
5411: else if (CSScomment == MAX_CSS_LENGTH ||
1.82 cvs 5412: c == '*' || c == '/' || c == '<')
5413: {
5414: /* we're not within a comment or we're parsing * or / */
5415: switch (c)
5416: {
5417: case '@': /* perhaps an import primitive */
1.135 vatton 5418: if (!quoted)
5419: import = CSSindex;
1.82 cvs 5420: break;
5421: case ';':
1.135 vatton 5422: if (!quoted && !media && import != MAX_CSS_LENGTH)
1.82 cvs 5423: {
5424: if (strncasecmp (&CSSbuffer[import+1], "import", 6))
5425: /* it's not an import */
5426: import = MAX_CSS_LENGTH;
5427: /* save the text */
5428: noRule = TRUE;
5429: }
5430: break;
5431: case '*':
1.135 vatton 5432: if (!quoted && CSScomment == MAX_CSS_LENGTH && CSSindex > 0 &&
1.82 cvs 5433: CSSbuffer[CSSindex - 1] == '/')
5434: /* start a comment */
5435: CSScomment = CSSindex - 1;
5436: break;
5437: case '/':
1.135 vatton 5438: if (!quoted && CSSindex > 1 && CSScomment != MAX_CSS_LENGTH &&
1.82 cvs 5439: CSSbuffer[CSSindex - 1] == '*')
5440: {
5441: /* close a comment:and ignore its contents */
5442: CSSindex = CSScomment - 1; /* will be incremented later */
5443: CSScomment = MAX_CSS_LENGTH;
1.93 vatton 5444: /* clean up the buffer */
1.103 vatton 5445: if (newlines && CSSindex > 0)
5446: while (CSSindex > 0 &&
5447: (CSSbuffer[CSSindex] == SPACE ||
5448: CSSbuffer[CSSindex] == BSPACE ||
5449: CSSbuffer[CSSindex] == EOL ||
5450: CSSbuffer[CSSindex] == TAB ||
5451: CSSbuffer[CSSindex] == __CR__))
1.93 vatton 5452: {
5453: if ( CSSbuffer[CSSindex] == EOL)
5454: {
5455: LineNumber ++;
5456: newlines --;
5457: }
5458: CSSindex--;
5459: }
1.82 cvs 5460: }
1.135 vatton 5461: else if (!quoted && CSScomment == MAX_CSS_LENGTH && CSSindex > 0 &&
1.82 cvs 5462: CSSbuffer[CSSindex - 1] == '<')
5463: {
5464: /* this is the closing tag ! */
5465: CSSindex -= 2; /* remove </ from the CSS string */
5466: noRule = TRUE;
5467: }
5468: break;
5469: case '<':
1.135 vatton 5470: if (!quoted && CSScomment == MAX_CSS_LENGTH)
1.82 cvs 5471: {
5472: /* only if we're not parsing a comment */
5473: c = buffer[index++];
5474: eof = (c == EOS);
5475: if (c == '!')
5476: {
5477: /* CSS within an HTML comment */
5478: HTMLcomment = TRUE;
5479: CSSindex++;
5480: CSSbuffer[CSSindex] = c;
5481: }
5482: else if (c == EOS)
5483: CSSindex++;
5484: }
5485: break;
5486: case '-':
1.135 vatton 5487: if (!quoted && CSSindex > 0 && CSSbuffer[CSSindex - 1] == '-' &&
1.82 cvs 5488: HTMLcomment)
5489: /* CSS within an HTML comment */
5490: noRule = TRUE;
5491: break;
5492: case '>':
1.135 vatton 5493: if (!quoted && HTMLcomment)
1.82 cvs 5494: noRule = TRUE;
5495: break;
5496: case ' ':
1.135 vatton 5497: if (!quoted && import != MAX_CSS_LENGTH && openRule == 0)
1.162 quint 5498: media = !strncasecmp (&CSSbuffer[import+1], "media", 5);
1.82 cvs 5499: break;
5500: case '{':
1.135 vatton 5501: if (!quoted)
1.82 cvs 5502: {
1.135 vatton 5503: openRule++;
5504: if (import != MAX_CSS_LENGTH && openRule == 1 && media)
5505: {
5506: /* is it the screen concerned? */
5507: CSSbuffer[CSSindex+1] = EOS;
5508: if (TtaIsPrinting ())
5509: base = strstr (&CSSbuffer[import], "print");
5510: else
5511: base = strstr (&CSSbuffer[import], "screen");
5512: if (base == NULL)
5513: base = strstr (&CSSbuffer[import], "all");
5514: if (base == NULL)
5515: ignoreMedia = TRUE;
5516: noRule = TRUE;
5517: }
1.186 vatton 5518: else if (import != MAX_CSS_LENGTH &&
5519: !strncasecmp (&CSSbuffer[import], "@font-face", 10))
5520: skip = TRUE;
1.135 vatton 5521: }
5522: break;
5523: case '}':
5524: if (!quoted)
5525: {
5526: openRule--;
5527: if (import != MAX_CSS_LENGTH && openRule == 0)
5528: {
5529: import = MAX_CSS_LENGTH;
5530: noRule = TRUE;
5531: ignoreMedia = FALSE;
5532: media = FALSE;
5533: }
1.82 cvs 5534: else
1.135 vatton 5535: toParse = TRUE;
1.82 cvs 5536: }
5537: break;
1.135 vatton 5538: case '"':
5539: if (quoted)
1.82 cvs 5540: {
1.135 vatton 5541: if (CSSbuffer[CSSindex - 1] != '\\')
5542: quoted = FALSE;
1.82 cvs 5543: }
5544: else
1.135 vatton 5545: quoted = TRUE;
1.82 cvs 5546: break;
5547: default:
1.86 cvs 5548: if (c == EOL)
1.93 vatton 5549: newlines++;
1.82 cvs 5550: break;
5551: }
5552: }
1.93 vatton 5553: else if (c == EOL)
5554: LineNumber++;
1.82 cvs 5555: if (c != CR)
5556: CSSindex++;
5557:
5558: if (CSSindex >= MAX_CSS_LENGTH && CSScomment < MAX_CSS_LENGTH)
5559: /* we're still parsing a comment: remove the text comment */
5560: CSSindex = CSScomment;
5561:
5562: if (CSSindex >= MAX_CSS_LENGTH || toParse || noRule)
5563: {
5564: CSSbuffer[CSSindex] = EOS;
5565: /* parse a not empty string */
5566: if (CSSindex > 0)
5567: {
1.50 cvs 5568: /* apply CSS rule if it's not just a saving of text */
5569: if (!noRule && !ignoreMedia)
1.88 cvs 5570: {
5571: /* future import rules must be ignored */
5572: ignoreImport = TRUE;
1.206 ! vatton 5573: ParseStyleDeclaration (NULL, CSSbuffer, docRef, refcss, link, FALSE);
1.93 vatton 5574: LineNumber += newlines;
5575: newlines = 0;
5576: NewLineSkipped = 0;
1.88 cvs 5577: }
1.82 cvs 5578: else if (import != MAX_CSS_LENGTH &&
5579: !strncasecmp (&CSSbuffer[import+1], "import", 6))
5580: {
5581: /* import section */
5582: cssRule = &CSSbuffer[import+7];
5583: cssRule = TtaSkipBlanks (cssRule);
1.93 vatton 5584: /* save the current line number */
5585: newlines += LineNumber;
1.82 cvs 5586: if (!strncasecmp (cssRule, "url", 3))
5587: {
1.50 cvs 5588: cssRule = &cssRule[3];
1.82 cvs 5589: cssRule = TtaSkipBlanks (cssRule);
5590: if (*cssRule == '(')
5591: {
5592: cssRule++;
5593: cssRule = TtaSkipBlanks (cssRule);
1.102 vatton 5594: quoted = (*cssRule == '"' || *cssRule == '\'');
5595: if (quoted)
5596: cssRule++;
1.82 cvs 5597: base = cssRule;
5598: while (*cssRule != EOS && *cssRule != ')')
5599: cssRule++;
1.102 vatton 5600: if (quoted)
1.167 vatton 5601: {
5602: /* isolate the file name */
5603: cssRule[-1] = EOS;
5604: quoted = FALSE;
5605: }
1.160 vatton 5606: *cssRule = EOS;
1.82 cvs 5607: }
5608: }
1.87 cvs 5609: else if (*cssRule == '"')
5610: {
1.88 cvs 5611: /*
5612: Do we have to accept single quotes?
5613: Double quotes are acceted here.
5614: Escaped quotes are not handled. See function SkipQuotedString
5615: */
1.87 cvs 5616: cssRule++;
5617: cssRule = TtaSkipBlanks (cssRule);
5618: base = cssRule;
1.179 vatton 5619: while (*cssRule != EOS &&
5620: (*cssRule != '"' ||
1.180 vatton 5621: (*cssRule == '"' && cssRule[-1] == '\\')))
1.87 cvs 5622: cssRule++;
1.160 vatton 5623: /* isolate the file name */
5624: *cssRule = EOS;
1.133 vatton 5625: }
5626: /* check if a media is defined */
5627: cssRule++;
5628: cssRule = TtaSkipBlanks (cssRule);
5629: if (*cssRule != ';')
5630: {
5631: if (TtaIsPrinting ())
5632: ignoreImport = (strncasecmp (cssRule, "print", 5) &&
5633: strncasecmp (cssRule, "all", 3));
5634: else
5635: ignoreImport = (strncasecmp (cssRule, "screen", 6) &&
5636: strncasecmp (cssRule, "all", 3));
5637: }
5638: if (!ignoreImport)
5639: {
5640: /* save the displayed URL when an error is reported */
5641: saveDocURL = DocURL;
1.138 vatton 5642: ptr = TtaStrdup (base);
5643: /* get the CSS URI in UTF-8 */
5644: ptr = ReallocUTF8String (ptr, docRef);
1.206 ! vatton 5645: LoadStyleSheet (base, docRef, (Element) css, css,
! 5646: pInfo->PiMedia,
! 5647: pInfo->PiCategory == CSS_USER_STYLE);
1.133 vatton 5648: /* restore the displayed URL when an error is reported */
5649: DocURL = saveDocURL;
1.138 vatton 5650: TtaFreeMemory (ptr);
1.82 cvs 5651: }
1.93 vatton 5652: /* restore the number of lines */
5653: LineNumber = newlines;
5654: newlines = 0;
1.82 cvs 5655: import = MAX_CSS_LENGTH;
5656: }
1.93 vatton 5657:
1.82 cvs 5658: }
5659: toParse = FALSE;
5660: noRule = FALSE;
5661: CSSindex = 0;
1.50 cvs 5662: }
1.82 cvs 5663: }
1.6 cvs 5664: /* restore the display mode */
5665: if (dispMode == DisplayImmediately)
1.82 cvs 5666: TtaSetDisplayMode (docRef, dispMode);
1.86 cvs 5667:
5668: /* Prepare the context for style attributes */
5669: DocURL = DocumentURLs[docRef];
5670: LineNumber = -1;
1.1 cvs 5671: return (c);
5672: }
1.89 cvs 5673:
Webmaster