Annotation of Amaya/amaya/styleparser.c, revision 1.197
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.162 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.168 vatton 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.82 cvs 2828: if (!strncasecmp (cssRule, "transparent", strlen ("transparent")))
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,
3010: char *file, void *extra)
1.1 cvs 3011: {
1.82 cvs 3012: DisplayMode dispMode;
3013: BackgroundImageCallbackPtr callblock;
3014: Element el;
3015: PSchema tsch;
1.185 vatton 3016: CSSInfoPtr css;
1.82 cvs 3017: PresentationContext context;
3018: PresentationValue image;
3019: PresentationValue value;
1.1 cvs 3020:
1.82 cvs 3021: callblock = (BackgroundImageCallbackPtr) extra;
1.34 cvs 3022: if (callblock == NULL)
3023: return;
1.1 cvs 3024:
1.188 cheyroul 3025: css = NULL;
1.34 cvs 3026: el = callblock->el;
3027: tsch = callblock->tsch;
3028: context = &callblock->context.specific;
1.185 vatton 3029: if (doc)
3030: {
3031: /* avoid too many redisplay */
3032: dispMode = TtaGetDisplayMode (doc);
3033: if (dispMode == DisplayImmediately)
3034: TtaSetDisplayMode (doc, DeferredDisplay);
3035: }
3036: else
3037: {
3038: /* check if the CSS still exists */
3039: css = CSSList;
3040: while (css && css != callblock->css)
3041: css = css->NextCSS;
3042: if (css == NULL)
3043: tsch = NULL;
3044: }
1.34 cvs 3045:
1.185 vatton 3046: if (el || tsch)
3047: {
3048: /* Ok the image was fetched, finish the background-image handling */
1.193 vatton 3049: image.typed_data.unit = UNIT_REL;
3050: image.typed_data.real = FALSE;
1.185 vatton 3051: image.pointer = file;
3052: TtaSetStylePresentation (PRBackgroundPicture, el, tsch, context, image);
3053:
3054: /* enforce the showbox */
3055: value.typed_data.value = 1;
3056: value.typed_data.unit = UNIT_REL;
3057: value.typed_data.real = FALSE;
1.193 vatton 3058: TtaSetStylePresentation (PRShowBox, el, tsch, context, value);
1.185 vatton 3059: }
1.34 cvs 3060:
3061: TtaFreeMemory (callblock);
3062: /* restore the display mode */
1.185 vatton 3063: if (doc)
3064: {
3065: if (dispMode == DisplayImmediately)
3066: TtaSetDisplayMode (doc, dispMode);
3067: }
3068: else if (css)
3069: {
3070: for (doc = 1; doc < DocumentTableLength; doc++)
3071: if (css->documents[doc] && css->enabled[doc] &&
3072: /* don't manage a document used by make book */
3073: (DocumentMeta[doc] == NULL ||
3074: DocumentMeta[doc]->method != CE_MAKEBOOK))
3075: {
3076: /* Change the Display Mode to take into account the new presentation */
3077: dispMode = TtaGetDisplayMode (doc);
3078: if (dispMode == DisplayImmediately)
1.194 vatton 3079: {
3080: TtaSetDisplayMode (doc, NoComputedDisplay);
3081: /* Restore the display mode */
3082: TtaSetDisplayMode (doc, dispMode);
3083: }
1.185 vatton 3084: }
3085: }
1.1 cvs 3086: }
3087:
3088: /*----------------------------------------------------------------------
3089: GetCSSBackgroundURL searches a CSS BackgroundImage url within
3090: the styleString.
3091: Returns NULL or a new allocated url string.
3092: ----------------------------------------------------------------------*/
1.79 cvs 3093: char *GetCSSBackgroundURL (char *styleString)
1.1 cvs 3094: {
1.79 cvs 3095: char *b, *e, *ptr;
3096: int len;
1.1 cvs 3097:
3098: ptr = NULL;
1.82 cvs 3099: b = strstr (styleString, "url");
1.1 cvs 3100: if (b != NULL)
3101: {
3102: b += 3;
1.82 cvs 3103: b = SkipBlanksAndComments (b);
3104: if (*b == '(')
1.1 cvs 3105: {
3106: b++;
1.82 cvs 3107: b = SkipBlanksAndComments (b);
1.161 quint 3108: /*** Escaped quotes are not handled. See function SkipQuotedString */
1.82 cvs 3109: if (*b == '"')
1.1 cvs 3110: {
3111: b++;
3112: /* search the url end */
3113: e = b;
1.82 cvs 3114: while (*e != EOS && *e != '"')
1.1 cvs 3115: e++;
3116: }
1.161 quint 3117: else if (*b == '\'')
3118: {
3119: b++;
3120: /* search the url end */
3121: e = b;
3122: while (*e != EOS && *e != '\'')
3123: e++;
3124: }
1.1 cvs 3125: else
3126: {
3127: /* search the url end */
3128: e = b;
1.82 cvs 3129: while (*e != EOS && *e != ')')
1.1 cvs 3130: e++;
3131: }
1.82 cvs 3132: if (*e != EOS)
1.1 cvs 3133: {
3134: len = (int)(e - b);
1.82 cvs 3135: ptr = (char*) TtaGetMemory (len+1);
3136: strncpy (ptr, b, len);
3137: ptr[len] = EOS;
1.1 cvs 3138: }
3139: }
3140: }
3141: return (ptr);
3142: }
3143:
3144:
3145: /*----------------------------------------------------------------------
1.59 cvs 3146: ParseCSSBackgroundImage: parse a CSS BackgroundImage attribute string.
1.1 cvs 3147: ----------------------------------------------------------------------*/
1.79 cvs 3148: static char *ParseCSSBackgroundImage (Element element, PSchema tsch,
3149: PresentationContext context,
3150: char *cssRule, CSSInfoPtr css,
3151: ThotBool isHTML)
1.1 cvs 3152: {
1.149 vatton 3153: GenericContext ctxt = (GenericContext) context;
1.49 cvs 3154: Element el;
1.1 cvs 3155: BackgroundImageCallbackPtr callblock;
1.49 cvs 3156: PresentationValue image, value;
1.79 cvs 3157: char *url;
1.82 cvs 3158: char *bg_image;
1.79 cvs 3159: char saved;
3160: char *base;
3161: char tempname[MAX_LENGTH];
3162: char imgname[MAX_LENGTH];
1.148 vatton 3163:
1.163 quint 3164: if (element)
1.148 vatton 3165: el = element;
1.163 quint 3166: else
3167: /* default element for FetchImage */
3168: el = TtaGetMainRoot (context->doc);
3169:
1.1 cvs 3170: url = NULL;
1.82 cvs 3171: cssRule = SkipBlanksAndComments (cssRule);
1.161 quint 3172: if (!strncasecmp (cssRule, "none", 4))
3173: {
3174: image.pointer = NULL;
3175: TtaSetStylePresentation (PRBackgroundPicture, element, tsch, context,
3176: image);
3177: }
3178: else if (!strncasecmp (cssRule, "url", 3))
1.1 cvs 3179: {
3180: cssRule += 3;
1.82 cvs 3181: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 3182: if (*cssRule == '(')
3183: {
3184: cssRule++;
1.82 cvs 3185: cssRule = SkipBlanksAndComments (cssRule);
1.161 quint 3186: /*** Escaped quotes are not handled. See function SkipQuotedString */
1.1 cvs 3187: if (*cssRule == '"')
3188: {
3189: cssRule++;
3190: base = cssRule;
1.82 cvs 3191: while (*cssRule != EOS && *cssRule != '"')
1.1 cvs 3192: cssRule++;
3193: }
1.161 quint 3194: else if (*cssRule == '\'')
3195: {
3196: cssRule++;
3197: base = cssRule;
3198: while (*cssRule != EOS && *cssRule != '\'')
3199: cssRule++;
3200: }
1.1 cvs 3201: else
3202: {
3203: base = cssRule;
3204: while (*cssRule != EOS && *cssRule != ')')
3205: cssRule++;
3206: }
3207: saved = *cssRule;
1.82 cvs 3208: *cssRule = EOS;
3209: url = TtaStrdup (base);
1.1 cvs 3210: *cssRule = saved;
1.161 quint 3211: if (saved == '"' || saved == '\'')
3212: /* we need to skip the quote character and possinble spaces */
3213: {
3214: cssRule++;
3215: cssRule = SkipBlanksAndComments (cssRule);
3216: }
1.1 cvs 3217: }
3218: cssRule++;
3219:
3220: if (context->destroy)
3221: {
3222: /* remove the background image PRule */
3223: image.pointer = NULL;
3224: TtaSetStylePresentation (PRBackgroundPicture, element, tsch, context, image);
3225: if (TtaGetStylePresentation (PRFillPattern, element, tsch, context, &value) < 0)
3226: {
3227: /* there is no FillPattern rule -> remove ShowBox rule */
3228: value.typed_data.value = 1;
1.184 vatton 3229: value.typed_data.unit = UNIT_REL;
1.1 cvs 3230: value.typed_data.real = FALSE;
3231: TtaSetStylePresentation (PRShowBox, element, tsch, context, value);
3232: }
3233: }
3234: else if (url)
3235: {
1.30 cvs 3236: bg_image = TtaGetEnvString ("ENABLE_BG_IMAGES");
1.82 cvs 3237: if (bg_image == NULL || !strcasecmp (bg_image, "yes"))
1.161 quint 3238: /* background images are enabled */
1.1 cvs 3239: {
1.185 vatton 3240: callblock = (BackgroundImageCallbackPtr) TtaGetMemory (sizeof (BackgroundImageCallbackBlock));
1.191 vatton 3241: if (callblock)
1.1 cvs 3242: {
3243: callblock->el = element;
3244: callblock->tsch = tsch;
1.185 vatton 3245: callblock->css = css;
1.1 cvs 3246: if (element == NULL)
1.149 vatton 3247: memcpy (&callblock->context.generic, ctxt,
3248: sizeof (GenericContextBlock));
1.18 cvs 3249: else
1.149 vatton 3250: memcpy (&callblock->context.specific, context,
3251: sizeof(PresentationContextBlock));
1.18 cvs 3252:
3253: /* check if the image url is related to an external CSS */
1.182 vatton 3254: if (css)
1.18 cvs 3255: {
1.189 vatton 3256: if (css->url)
3257: /* the image concerns a CSS file */
3258: NormalizeURL (url, 0, tempname, imgname, css->url);
3259: else
3260: /* the image concerns a style element */
3261: NormalizeURL (url, context->doc, tempname, imgname, NULL);
1.18 cvs 3262: /* fetch and display background image of element */
1.181 vatton 3263: FetchImage (0, el, tempname, AMAYA_LOAD_IMAGE,
1.161 quint 3264: ParseCSSBackgroundImageCallback, callblock);
1.18 cvs 3265: }
3266: else
1.182 vatton 3267: FetchImage (context->doc, el, url, AMAYA_LOAD_IMAGE,
1.161 quint 3268: ParseCSSBackgroundImageCallback, callblock);
1.18 cvs 3269: }
3270: }
3271:
3272: if (url)
3273: TtaFreeMemory (url);
3274: }
3275: }
3276: return (cssRule);
3277: }
3278:
3279: /*----------------------------------------------------------------------
1.59 cvs 3280: ParseCSSBackgroundRepeat: parse a CSS BackgroundRepeat attribute string.
1.18 cvs 3281: ----------------------------------------------------------------------*/
1.79 cvs 3282: static char *ParseCSSBackgroundRepeat (Element element, PSchema tsch,
1.97 vatton 3283: PresentationContext context,
3284: char *cssRule, CSSInfoPtr css, ThotBool isHTML)
1.18 cvs 3285: {
3286: PresentationValue repeat;
3287:
1.184 vatton 3288: repeat.typed_data.value = REALSIZE;
1.191 vatton 3289: repeat.typed_data.unit = UNIT_BOX;
1.18 cvs 3290: repeat.typed_data.real = FALSE;
1.82 cvs 3291: cssRule = SkipBlanksAndComments (cssRule);
3292: if (!strncasecmp (cssRule, "no-repeat", 9))
1.184 vatton 3293: repeat.typed_data.value = REALSIZE;
1.82 cvs 3294: else if (!strncasecmp (cssRule, "repeat-y", 8))
1.184 vatton 3295: repeat.typed_data.value = VREPEAT;
1.82 cvs 3296: else if (!strncasecmp (cssRule, "repeat-x", 8))
1.184 vatton 3297: repeat.typed_data.value = HREPEAT;
1.82 cvs 3298: else if (!strncasecmp (cssRule, "repeat", 6))
1.184 vatton 3299: repeat.typed_data.value = REPEAT;
1.18 cvs 3300: else
3301: return (cssRule);
3302:
3303: /* install the new presentation */
1.116 vatton 3304: if (DoApply)
1.117 vatton 3305: {
3306: /* check if it's an important rule */
3307: if (tsch)
3308: cssRule = CheckImportantRule (cssRule, context);
3309: TtaSetStylePresentation (PRPictureMode, element, tsch, context, repeat);
3310: }
1.18 cvs 3311: cssRule = SkipWord (cssRule);
1.163 quint 3312: return (cssRule);
1.18 cvs 3313: }
3314:
3315: /*----------------------------------------------------------------------
1.59 cvs 3316: ParseCSSBackgroundAttachment: parse a CSS BackgroundAttachment
1.18 cvs 3317: attribute string.
3318: ----------------------------------------------------------------------*/
1.79 cvs 3319: static char *ParseCSSBackgroundAttachment (Element element, PSchema tsch,
3320: PresentationContext context,
3321: char *cssRule, CSSInfoPtr css,
3322: ThotBool isHTML)
1.18 cvs 3323: {
1.163 quint 3324: cssRule = SkipBlanksAndComments (cssRule);
3325: if (!strncasecmp (cssRule, "scroll", 6))
3326: cssRule = SkipWord (cssRule);
3327: else if (!strncasecmp (cssRule, "fixed", 5))
3328: cssRule = SkipWord (cssRule);
3329: return (cssRule);
1.1 cvs 3330: }
3331:
3332: /*----------------------------------------------------------------------
1.59 cvs 3333: ParseCSSBackgroundPosition: parse a CSS BackgroundPosition
1.1 cvs 3334: attribute string.
3335: ----------------------------------------------------------------------*/
1.79 cvs 3336: static char *ParseCSSBackgroundPosition (Element element, PSchema tsch,
3337: PresentationContext context,
3338: char *cssRule, CSSInfoPtr css,
3339: ThotBool isHTML)
1.1 cvs 3340: {
1.18 cvs 3341: PresentationValue repeat;
3342: ThotBool ok;
1.1 cvs 3343:
1.163 quint 3344: cssRule = SkipBlanksAndComments (cssRule);
3345: ok = TRUE;
3346: if (!strncasecmp (cssRule, "left", 4))
3347: cssRule = SkipWord (cssRule);
3348: else if (!strncasecmp (cssRule, "right", 5))
3349: cssRule = SkipWord (cssRule);
3350: else if (!strncasecmp (cssRule, "center", 6))
3351: cssRule = SkipWord (cssRule);
3352: else if (!strncasecmp (cssRule, "top", 3))
3353: cssRule = SkipWord (cssRule);
3354: else if (!strncasecmp (cssRule, "bottom", 6))
3355: cssRule = SkipWord (cssRule);
3356: else if (isdigit (*cssRule) || *cssRule == '.')
1.191 vatton 3357: {
3358: cssRule = SkipWord (cssRule);
3359: }
1.163 quint 3360: else
3361: ok = FALSE;
3362:
3363: if (ok && DoApply)
1.148 vatton 3364: {
1.163 quint 3365: /* force realsize for the background image */
1.184 vatton 3366: repeat.typed_data.value = REALSIZE;
3367: repeat.typed_data.unit = UNIT_REL;
1.163 quint 3368: repeat.typed_data.real = FALSE;
3369: /* check if it's an important rule */
3370: if (tsch)
3371: cssRule = CheckImportantRule (cssRule, context);
1.191 vatton 3372: /*TtaSetStylePresentation (PRPictureMode, element, tsch, context, repeat);*/
1.148 vatton 3373: }
1.163 quint 3374: return (cssRule);
1.18 cvs 3375: }
3376:
3377: /*----------------------------------------------------------------------
1.59 cvs 3378: ParseCSSBackground: parse a CSS background attribute
1.18 cvs 3379: ----------------------------------------------------------------------*/
1.79 cvs 3380: static char *ParseCSSBackground (Element element, PSchema tsch,
3381: PresentationContext context, char *cssRule,
3382: CSSInfoPtr css, ThotBool isHTML)
1.18 cvs 3383: {
1.79 cvs 3384: char *ptr;
1.93 vatton 3385: int skippedNL;
1.18 cvs 3386:
1.82 cvs 3387: cssRule = SkipBlanksAndComments (cssRule);
3388: while (*cssRule != ';' && *cssRule != EOS && *cssRule != ',')
1.18 cvs 3389: {
1.71 cvs 3390: /* perhaps a Background Image */
1.82 cvs 3391: if (!strncasecmp (cssRule, "url", 3))
1.63 cvs 3392: cssRule = ParseCSSBackgroundImage (element, tsch, context, cssRule,
3393: css, isHTML);
1.18 cvs 3394: /* perhaps a Background Attachment */
1.82 cvs 3395: else if (!strncasecmp (cssRule, "scroll", 6) ||
3396: !strncasecmp (cssRule, "fixed", 5))
1.63 cvs 3397: cssRule = ParseCSSBackgroundAttachment (element, tsch, context,
3398: cssRule, css, isHTML);
1.18 cvs 3399: /* perhaps a Background Repeat */
1.82 cvs 3400: else if (!strncasecmp (cssRule, "no-repeat", 9) ||
3401: !strncasecmp (cssRule, "repeat-y", 8) ||
3402: !strncasecmp (cssRule, "repeat-x", 8) ||
3403: !strncasecmp (cssRule, "repeat", 6))
3404: cssRule = ParseCSSBackgroundRepeat (element, tsch, context,
3405: cssRule, css, isHTML);
1.18 cvs 3406: /* perhaps a Background Position */
1.82 cvs 3407: else if (!strncasecmp (cssRule, "left", 4) ||
3408: !strncasecmp (cssRule, "right", 5) ||
3409: !strncasecmp (cssRule, "center", 6) ||
3410: !strncasecmp (cssRule, "top", 3) ||
3411: !strncasecmp (cssRule, "bottom", 6) ||
1.110 vatton 3412: isdigit (*cssRule) || *cssRule == '.')
1.63 cvs 3413: cssRule = ParseCSSBackgroundPosition (element, tsch, context,
3414: cssRule, css, isHTML);
1.18 cvs 3415: /* perhaps a Background Color */
3416: else
3417: {
1.93 vatton 3418: skippedNL = NewLineSkipped;
1.18 cvs 3419: /* check if the rule has been found */
3420: ptr = cssRule;
1.82 cvs 3421: cssRule = ParseCSSBackgroundColor (element, tsch, context,
3422: cssRule, css, isHTML);
1.43 cvs 3423: if (ptr == cssRule)
1.93 vatton 3424: {
3425: NewLineSkipped = skippedNL;
3426: /* rule not found */
3427: cssRule = SkipProperty (cssRule);
3428: }
1.18 cvs 3429: }
1.82 cvs 3430: cssRule = SkipBlanksAndComments (cssRule);
1.18 cvs 3431: }
3432: return (cssRule);
3433: }
3434:
1.59 cvs 3435: /*----------------------------------------------------------------------
1.60 cvs 3436: ParseCSSPageBreakBefore: parse a CSS page-break-before attribute
1.59 cvs 3437: ----------------------------------------------------------------------*/
1.79 cvs 3438: static char *ParseCSSPageBreakBefore (Element element, PSchema tsch,
3439: PresentationContext context, char *cssRule,
3440: CSSInfoPtr css, ThotBool isHTML)
1.59 cvs 3441: {
3442: PresentationValue page;
3443:
1.184 vatton 3444: page.typed_data.unit = UNIT_INVALID;
1.59 cvs 3445: page.typed_data.real = FALSE;
1.82 cvs 3446: cssRule = SkipBlanksAndComments (cssRule);
3447: if (!strncasecmp (cssRule, "auto", 4))
1.184 vatton 3448: page.typed_data.value = PageAuto;
1.82 cvs 3449: else if (!strncasecmp (cssRule, "always", 6))
1.59 cvs 3450: {
1.184 vatton 3451: page.typed_data.unit = UNIT_REL;
3452: page.typed_data.value = PageAlways;
1.59 cvs 3453: }
1.82 cvs 3454: else if (!strncasecmp (cssRule, "avoid", 5))
1.59 cvs 3455: {
1.184 vatton 3456: page.typed_data.unit = UNIT_REL;
3457: page.typed_data.value = PageAvoid;
1.59 cvs 3458: }
1.82 cvs 3459: else if (!strncasecmp (cssRule, "left", 4))
1.59 cvs 3460: {
1.184 vatton 3461: page.typed_data.unit = UNIT_REL;
3462: page.typed_data.value = PageLeft;
1.59 cvs 3463: }
1.82 cvs 3464: else if (!strncasecmp (cssRule, "right", 5))
1.59 cvs 3465: {
1.184 vatton 3466: page.typed_data.unit = UNIT_REL;
3467: page.typed_data.value = PageRight;
1.59 cvs 3468: }
1.82 cvs 3469: else if (!strncasecmp (cssRule, "inherit", 7))
1.59 cvs 3470: {
1.184 vatton 3471: /*page.typed_data.unit = UNIT_REL;*/
3472: page.typed_data.value = PageInherit;
1.59 cvs 3473: }
3474: cssRule = SkipWord (cssRule);
3475: /* install the new presentation */
1.184 vatton 3476: if (page.typed_data.unit == UNIT_REL &&
3477: page.typed_data.value == PageAlways && DoApply)
1.117 vatton 3478: {
3479: /* check if it's an important rule */
3480: if (tsch)
3481: cssRule = CheckImportantRule (cssRule, context);
3482: TtaSetStylePresentation (PRPageBefore, element, tsch, context, page);
3483: }
1.59 cvs 3484: return (cssRule);
3485: }
3486:
3487: /*----------------------------------------------------------------------
1.60 cvs 3488: ParseCSSPageBreakAfter: parse a CSS page-break-after attribute
1.59 cvs 3489: ----------------------------------------------------------------------*/
1.79 cvs 3490: static char *ParseCSSPageBreakAfter (Element element, PSchema tsch,
3491: PresentationContext context,
3492: char *cssRule, CSSInfoPtr css,
3493: ThotBool isHTML)
1.59 cvs 3494: {
3495: PresentationValue page;
3496:
1.184 vatton 3497: page.typed_data.unit = UNIT_INVALID;
1.59 cvs 3498: page.typed_data.real = FALSE;
1.82 cvs 3499: cssRule = SkipBlanksAndComments (cssRule);
3500: if (!strncasecmp (cssRule, "auto", 4))
1.184 vatton 3501: page.typed_data.value = PageAuto;
1.82 cvs 3502: else if (!strncasecmp (cssRule, "always", 6))
1.59 cvs 3503: {
1.184 vatton 3504: page.typed_data.unit = UNIT_REL;
3505: page.typed_data.value = PageAlways;
1.59 cvs 3506: }
1.82 cvs 3507: else if (!strncasecmp (cssRule, "avoid", 5))
1.59 cvs 3508: {
1.184 vatton 3509: page.typed_data.unit = UNIT_REL;
3510: page.typed_data.value = PageAvoid;
1.59 cvs 3511: }
1.82 cvs 3512: else if (!strncasecmp (cssRule, "left", 4))
1.59 cvs 3513: {
1.184 vatton 3514: page.typed_data.unit = UNIT_REL;
3515: page.typed_data.value = PageLeft;
1.59 cvs 3516: }
1.82 cvs 3517: else if (!strncasecmp (cssRule, "right", 5))
1.59 cvs 3518: {
1.184 vatton 3519: page.typed_data.unit = UNIT_REL;
3520: page.typed_data.value = PageRight;
1.59 cvs 3521: }
1.82 cvs 3522: else if (!strncasecmp (cssRule, "inherit", 7))
1.59 cvs 3523: {
1.184 vatton 3524: /*page.typed_data.unit = UNIT_REL;*/
3525: page.typed_data.value = PageInherit;
1.59 cvs 3526: }
3527: cssRule = SkipWord (cssRule);
3528: /* install the new presentation */
1.184 vatton 3529: /*if (page.typed_data.unit == UNIT_REL && DoApply)
1.117 vatton 3530: {
3531: if (tsch)
3532: cssRule = CheckImportantRule (cssRule, context);
3533: TtaSetStylePresentation (PRPageAfter, element, tsch, context, page);
3534: }*/
1.59 cvs 3535: return (cssRule);
3536: }
3537:
3538: /*----------------------------------------------------------------------
1.60 cvs 3539: ParseCSSPageBreakInside: parse a CSS page-break-inside attribute
1.59 cvs 3540: ----------------------------------------------------------------------*/
1.79 cvs 3541: static char *ParseCSSPageBreakInside (Element element, PSchema tsch,
3542: PresentationContext context,
3543: char *cssRule, CSSInfoPtr css,
3544: ThotBool isHTML)
1.59 cvs 3545: {
3546: PresentationValue page;
3547:
1.184 vatton 3548: page.typed_data.unit = UNIT_INVALID;
1.59 cvs 3549: page.typed_data.real = FALSE;
1.82 cvs 3550: cssRule = SkipBlanksAndComments (cssRule);
3551: if (!strncasecmp (cssRule, "auto", 4))
1.59 cvs 3552: {
1.184 vatton 3553: /*page.typed_data.unit = UNIT_REL;*/
3554: page.typed_data.value = PageAuto;
1.59 cvs 3555: }
1.82 cvs 3556: else if (!strncasecmp (cssRule, "avoid", 5))
1.59 cvs 3557: {
1.184 vatton 3558: page.typed_data.unit = UNIT_REL;
3559: page.typed_data.value = PageAvoid;
1.59 cvs 3560: }
1.82 cvs 3561: else if (!strncasecmp (cssRule, "inherit", 7))
1.59 cvs 3562: {
1.184 vatton 3563: /*page.typed_data.unit = UNIT_REL;*/
3564: page.typed_data.value = PageInherit;
1.59 cvs 3565: }
3566: cssRule = SkipWord (cssRule);
3567: /* install the new presentation */
1.184 vatton 3568: /*if (page.typed_data.unit == UNIT_REL &&
3569: page.typed_data.value == PageAvoid && DoApply)
1.117 vatton 3570: {
3571: if (tsch)
3572: cssRule = CheckImportantRule (cssRule, context);
3573: TtaSetStylePresentation (PRPageInside, element, tsch, context, page);
3574: }*/
1.59 cvs 3575: return (cssRule);
3576: }
1.18 cvs 3577:
3578:
1.60 cvs 3579: /*----------------------------------------------------------------------
1.117 vatton 3580: ParseSVGStrokeWidth: parse a SVG stroke-width property value.
1.60 cvs 3581: ----------------------------------------------------------------------*/
1.79 cvs 3582: static char *ParseSVGStrokeWidth (Element element, PSchema tsch,
3583: PresentationContext context, char *cssRule,
3584: CSSInfoPtr css, ThotBool isHTML)
1.60 cvs 3585: {
3586: PresentationValue width;
3587:
1.82 cvs 3588: cssRule = SkipBlanksAndComments (cssRule);
1.60 cvs 3589: width.typed_data.value = 0;
1.184 vatton 3590: width.typed_data.unit = UNIT_INVALID;
1.60 cvs 3591: width.typed_data.real = FALSE;
1.110 vatton 3592: if (isdigit (*cssRule) || *cssRule == '.')
1.166 vatton 3593: {
1.60 cvs 3594: cssRule = ParseCSSUnit (cssRule, &width);
1.184 vatton 3595: if (width.typed_data.unit == UNIT_BOX)
3596: width.typed_data.unit = UNIT_PX;
1.166 vatton 3597: }
1.184 vatton 3598: if (width.typed_data.unit != UNIT_INVALID && DoApply)
1.117 vatton 3599: {
3600: /* check if it's an important rule */
3601: if (tsch)
3602: cssRule = CheckImportantRule (cssRule, context);
3603: TtaSetStylePresentation (PRLineWeight, element, tsch, context, width);
3604: width.typed_data.value = 1;
1.184 vatton 3605: width.typed_data.unit = UNIT_REL;
1.117 vatton 3606: }
1.60 cvs 3607: return (cssRule);
3608: }
3609:
1.18 cvs 3610: /************************************************************************
3611: * *
3612: * FUNCTIONS STYLE DECLARATIONS *
3613: * *
3614: ************************************************************************/
3615: /*
1.59 cvs 3616: * NOTE: Long attribute name MUST be placed before shortened ones !
1.18 cvs 3617: * e.g. "FONT-SIZE" must be placed before "FONT"
3618: */
3619: static CSSProperty CSSProperties[] =
3620: {
1.82 cvs 3621: {"font-family", ParseCSSFontFamily},
3622: {"font-style", ParseCSSFontStyle},
3623: {"font-variant", ParseCSSFontVariant},
3624: {"font-weight", ParseCSSFontWeight},
3625: {"font-size", ParseCSSFontSize},
3626: {"font", ParseCSSFont},
3627:
3628: {"color", ParseCSSForeground},
3629: {"background-color", ParseCSSBackgroundColor},
3630: {"background-image", ParseCSSBackgroundImage},
3631: {"background-repeat", ParseCSSBackgroundRepeat},
3632: {"background-attachment", ParseCSSBackgroundAttachment},
3633: {"background-position", ParseCSSBackgroundPosition},
3634: {"background", ParseCSSBackground},
3635:
3636: {"word-spacing", ParseCSSWordSpacing},
3637: {"letter-spacing", ParseCSSLetterSpacing},
3638: {"text-decoration", ParseCSSTextDecoration},
3639: {"vertical-align", ParseCSSVerticalAlign},
3640: {"text-transform", ParseCSSTextTransform},
3641: {"text-align", ParseCSSTextAlign},
3642: {"text-indent", ParseCSSTextIndent},
1.162 quint 3643: {"line-height", ParseCSSLineHeight},
1.82 cvs 3644:
1.112 quint 3645: {"direction", ParseCSSDirection},
1.113 quint 3646: {"unicode-bidi", ParseCSSUnicodeBidi},
1.112 quint 3647:
1.82 cvs 3648: {"margin-top", ParseCSSMarginTop},
3649: {"margin-right", ParseCSSMarginRight},
3650: {"margin-bottom", ParseCSSMarginBottom},
3651: {"margin-left", ParseCSSMarginLeft},
3652: {"margin", ParseCSSMargin},
3653:
3654: {"padding-top", ParseCSSPaddingTop},
3655: {"padding-right", ParseCSSPaddingRight},
3656: {"padding-bottom", ParseCSSPaddingBottom},
3657: {"padding-left", ParseCSSPaddingLeft},
3658: {"padding", ParseCSSPadding},
3659:
3660: {"border-top-width", ParseCSSBorderTopWidth},
3661: {"border-right-width", ParseCSSBorderRightWidth},
3662: {"border-bottom-width", ParseCSSBorderBottomWidth},
3663: {"border-left-width", ParseCSSBorderLeftWidth},
3664: {"border-width", ParseCSSBorderWidth},
3665: {"border-top-color", ParseCSSBorderColorTop},
3666: {"border-right-color", ParseCSSBorderColorRight},
3667: {"border-bottom-color", ParseCSSBorderColorBottom},
3668: {"border-left-color", ParseCSSBorderColorLeft},
3669: {"border-color", ParseCSSBorderColor},
3670: {"border-top-style", ParseCSSBorderStyleTop},
3671: {"border-right-style", ParseCSSBorderStyleRight},
3672: {"border-bottom-style", ParseCSSBorderStyleBottom},
3673: {"border-left-style", ParseCSSBorderStyleLeft},
3674: {"border-style", ParseCSSBorderStyle},
3675: {"border-top", ParseCSSBorderTop},
3676: {"border-right", ParseCSSBorderRight},
3677: {"border-bottom", ParseCSSBorderBottom},
3678: {"border-left", ParseCSSBorderLeft},
3679: {"border", ParseCSSBorder},
3680:
3681: {"width", ParseCSSWidth},
3682: {"height", ParseCSSHeight},
3683: {"float", ParseCSSFloat},
3684: {"clear", ParseCSSClear},
1.184 vatton 3685: {"content", ParseCSSContent},
1.82 cvs 3686:
3687: {"display", ParseCSSDisplay},
3688: {"white-space", ParseCSSWhiteSpace},
3689:
3690: {"list-style-type", ParseCSSListStyleType},
3691: {"list-style-image", ParseCSSListStyleImage},
3692: {"list-style-position", ParseCSSListStylePosition},
3693: {"list-style", ParseCSSListStyle},
3694:
3695: {"page-break-before", ParseCSSPageBreakBefore},
3696: {"page-break-after", ParseCSSPageBreakAfter},
3697: {"page-break-inside", ParseCSSPageBreakInside},
1.60 cvs 3698:
3699: /* SVG extensions */
1.170 cheyroul 3700: {"stroke-opacity", ParseSVGStrokeOpacity},
1.82 cvs 3701: {"stroke-width", ParseSVGStrokeWidth},
3702: {"stroke", ParseSVGStroke},
1.170 cheyroul 3703:
3704: {"fill-opacity", ParseSVGFillOpacity},
1.155 cheyroul 3705: {"fill", ParseSVGFill},
1.170 cheyroul 3706:
1.155 cheyroul 3707: {"opacity", ParseSVGOpacity}
1.18 cvs 3708: };
1.155 cheyroul 3709:
1.18 cvs 3710: #define NB_CSSSTYLEATTRIBUTE (sizeof(CSSProperties) / sizeof(CSSProperty))
3711:
3712: /*----------------------------------------------------------------------
1.59 cvs 3713: ParseCSSRule: parse a CSS Style string
1.18 cvs 3714: we expect the input string describing the style to be of the
1.59 cvs 3715: form: PRORPERTY: DESCRIPTION [ ; PROPERTY: DESCRIPTION ] *
1.18 cvs 3716: but tolerate incorrect or incomplete input
3717: ----------------------------------------------------------------------*/
1.79 cvs 3718: static void ParseCSSRule (Element element, PSchema tsch,
3719: PresentationContext context, char *cssRule,
3720: CSSInfoPtr css, ThotBool isHTML)
1.18 cvs 3721: {
1.34 cvs 3722: DisplayMode dispMode;
1.79 cvs 3723: char *p = NULL;
1.18 cvs 3724: int lg;
1.34 cvs 3725: unsigned int i;
1.76 cvs 3726: ThotBool found;
1.18 cvs 3727:
1.34 cvs 3728: /* avoid too many redisplay */
3729: dispMode = TtaGetDisplayMode (context->doc);
3730: if (dispMode == DisplayImmediately)
3731: TtaSetDisplayMode (context->doc, DeferredDisplay);
3732:
1.82 cvs 3733: while (*cssRule != EOS)
1.18 cvs 3734: {
1.82 cvs 3735: cssRule = SkipBlanksAndComments (cssRule);
1.153 vatton 3736: if (*cssRule < 0x41 || *cssRule > 0x7A ||
1.133 vatton 3737: (*cssRule > 0x5A && *cssRule < 0x60))
1.153 vatton 3738: cssRule++;
1.194 vatton 3739: else if (*cssRule != EOS)
1.89 cvs 3740: {
1.153 vatton 3741: found = FALSE;
3742: /* look for the type of property */
3743: for (i = 0; i < NB_CSSSTYLEATTRIBUTE && !found; i++)
1.18 cvs 3744: {
1.153 vatton 3745: lg = strlen (CSSProperties[i].name);
3746: if (!strncasecmp (cssRule, CSSProperties[i].name, lg))
3747: {
3748: p = cssRule + lg;
3749: found = TRUE;
3750: i--;
3751: }
1.18 cvs 3752: }
1.153 vatton 3753: if (i == NB_CSSSTYLEATTRIBUTE)
3754: cssRule = SkipProperty (cssRule);
3755: else
1.18 cvs 3756: {
1.153 vatton 3757: /* update index and skip the ":" indicator if present */
1.86 cvs 3758: p = SkipBlanksAndComments (p);
1.153 vatton 3759: if (*p == ':')
1.61 cvs 3760: {
1.153 vatton 3761: p++;
3762: p = SkipBlanksAndComments (p);
3763: /* try to parse the value associated with this property */
3764: if (CSSProperties[i].parsing_function != NULL)
3765: {
3766: p = CSSProperties[i].parsing_function (element, tsch, context,
3767: p, css, isHTML);
3768: /* update index and skip the ";" separator if present */
3769: cssRule = p;
3770: }
1.61 cvs 3771: }
1.153 vatton 3772: else
3773: cssRule = SkipProperty (cssRule);
1.18 cvs 3774: }
3775: }
3776: /* next property */
1.82 cvs 3777: cssRule = SkipBlanksAndComments (cssRule);
1.89 cvs 3778: if (*cssRule == '}')
3779: {
3780: cssRule++;
1.168 vatton 3781: CSSPrintError ("Invalid character", "}");
1.89 cvs 3782: cssRule = SkipBlanksAndComments (cssRule);
3783: }
1.155 cheyroul 3784: if (*cssRule == ',' ||
3785: *cssRule == ';')
1.18 cvs 3786: {
3787: cssRule++;
1.82 cvs 3788: cssRule = SkipBlanksAndComments (cssRule);
1.18 cvs 3789: }
3790: }
1.34 cvs 3791:
3792: /* restore the display mode */
3793: if (dispMode == DisplayImmediately)
3794: TtaSetDisplayMode (context->doc, dispMode);
1.18 cvs 3795: }
1.1 cvs 3796:
1.111 cvs 3797: /*----------------------------------------------------------------------
3798: AddBorderStyleValue
3799: -----------------------------------------------------------------------*/
3800: static void AddBorderStyleValue (char *buffer, int value)
3801: {
3802: switch (value)
3803: {
1.184 vatton 3804: case BorderStyleNone:
1.111 cvs 3805: strcat (buffer, "none");
3806: break;
1.184 vatton 3807: case BorderStyleHidden:
1.111 cvs 3808: strcat (buffer, "hidden");
3809: break;
1.184 vatton 3810: case BorderStyleDotted:
1.111 cvs 3811: strcat (buffer, "dotted");
3812: break;
1.184 vatton 3813: case BorderStyleDashed:
1.111 cvs 3814: strcat (buffer, "dashed");
3815: break;
1.184 vatton 3816: case BorderStyleSolid:
1.111 cvs 3817: strcat (buffer, "solid");
3818: break;
1.184 vatton 3819: case BorderStyleDouble:
1.111 cvs 3820: strcat (buffer, "double");
3821: break;
1.184 vatton 3822: case BorderStyleGroove:
1.111 cvs 3823: strcat (buffer, "groove");
3824: break;
1.184 vatton 3825: case BorderStyleRidge:
1.111 cvs 3826: strcat (buffer, "ridge");
3827: break;
1.184 vatton 3828: case BorderStyleInset:
1.111 cvs 3829: strcat (buffer, "inset");
3830: break;
1.184 vatton 3831: case BorderStyleOutset:
1.111 cvs 3832: strcat (buffer, "outset");
3833: break;
3834: }
3835: }
1.1 cvs 3836:
3837: /*----------------------------------------------------------------------
1.59 cvs 3838: PToCss: translate a PresentationSetting to the
1.18 cvs 3839: equivalent CSS string, and add it to the buffer given as the
1.67 cvs 3840: argument. It is used when extracting the CSS string from actual
3841: presentation.
3842: el is the element for which the style rule is generated
1.18 cvs 3843:
3844: All the possible values returned by the presentation drivers are
3845: described in thotlib/include/presentation.h
3846: -----------------------------------------------------------------------*/
1.79 cvs 3847: void PToCss (PresentationSetting settings, char *buffer, int len, Element el)
1.1 cvs 3848: {
1.76 cvs 3849: ElementType elType;
1.18 cvs 3850: float fval = 0;
3851: unsigned short red, green, blue;
3852: int add_unit = 0;
3853: unsigned int unit, i;
3854: ThotBool real = FALSE;
3855:
1.82 cvs 3856: buffer[0] = EOS;
1.18 cvs 3857: if (len < 40)
3858: return;
3859:
3860: unit = settings->value.typed_data.unit;
3861: if (settings->value.typed_data.real)
3862: {
3863: real = TRUE;
3864: fval = (float) settings->value.typed_data.value;
1.195 vatton 3865: fval /= 1000.;
1.18 cvs 3866: }
1.1 cvs 3867:
1.18 cvs 3868: switch (settings->type)
1.1 cvs 3869: {
1.18 cvs 3870: case PRVisibility:
3871: break;
1.111 cvs 3872: case PRHeight:
3873: if (real)
3874: sprintf (buffer, "height: %g", fval);
3875: else
3876: sprintf (buffer, "height: %d", settings->value.typed_data.value);
3877: add_unit = 1;
3878: break;
3879: case PRWidth:
3880: if (real)
3881: sprintf (buffer, "width: %g", fval);
3882: else
3883: sprintf (buffer, "width: %d", settings->value.typed_data.value);
3884: add_unit = 1;
3885: break;
3886: case PRMarginTop:
3887: if (real)
3888: sprintf (buffer, "margin-top: %g", fval);
3889: else
3890: sprintf (buffer, "margin-top: %d",settings->value.typed_data.value);
3891: add_unit = 1;
3892: break;
3893: case PRMarginBottom:
3894: if (real)
3895: sprintf (buffer, "margin-bottom: %g", fval);
3896: else
3897: sprintf (buffer, "margin-bottom: %d",
3898: settings->value.typed_data.value);
3899: add_unit = 1;
3900: break;
3901: case PRMarginLeft:
3902: if (real)
3903: sprintf (buffer, "margin-left: %g", fval);
3904: else
1.164 quint 3905: sprintf (buffer, "margin-left: %d", settings->value.typed_data.value);
1.111 cvs 3906: add_unit = 1;
3907: break;
3908: case PRMarginRight:
3909: if (real)
3910: sprintf (buffer, "margin-right: %g", fval);
3911: else
1.164 quint 3912: sprintf (buffer, "margin-right: %d", settings->value.typed_data.value);
1.111 cvs 3913: add_unit = 1;
3914: break;
3915: case PRPaddingTop:
3916: if (real)
3917: sprintf (buffer, "padding-top: %g", fval);
3918: else
1.164 quint 3919: sprintf (buffer, "padding-top: %d", settings->value.typed_data.value);
1.111 cvs 3920: add_unit = 1;
3921: break;
3922: case PRPaddingBottom:
3923: if (real)
3924: sprintf (buffer, "padding-bottom: %g", fval);
3925: else
3926: sprintf (buffer, "padding-bottom: %d",
3927: settings->value.typed_data.value);
3928: add_unit = 1;
3929: break;
3930: case PRPaddingLeft:
3931: if (real)
3932: sprintf (buffer, "padding-left: %g", fval);
3933: else
1.164 quint 3934: sprintf (buffer, "padding-left: %d", settings->value.typed_data.value);
1.111 cvs 3935: add_unit = 1;
3936: break;
3937: case PRPaddingRight:
3938: if (real)
3939: sprintf (buffer, "padding-right: %g", fval);
3940: else
3941: sprintf (buffer, "padding-right: %d",
3942: settings->value.typed_data.value);
3943: add_unit = 1;
3944: break;
3945: case PRBorderTopWidth:
3946: if (real)
3947: sprintf (buffer, "border-top-width: %g", fval);
3948: else
3949: sprintf (buffer, "border-top-width: %d",
3950: settings->value.typed_data.value);
3951: add_unit = 1;
3952: break;
3953: case PRBorderBottomWidth:
3954: if (real)
3955: sprintf (buffer, "border-bottom-width: %g", fval);
3956: else
3957: sprintf (buffer, "border-bottom-width: %d",
3958: settings->value.typed_data.value);
3959: add_unit = 1;
3960: break;
3961: case PRBorderLeftWidth:
3962: if (real)
3963: sprintf (buffer, "border-left-width: %g", fval);
3964: else
3965: sprintf (buffer, "border-left-width: %d",
3966: settings->value.typed_data.value);
3967: add_unit = 1;
3968: break;
3969: case PRBorderRightWidth:
3970: if (real)
3971: sprintf (buffer, "border-right-width: %g", fval);
3972: else
3973: sprintf (buffer, "border-right-width: %d",
3974: settings->value.typed_data.value);
3975: add_unit = 1;
3976: break;
3977: case PRBorderTopColor:
3978: TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
3979: elType = TtaGetElementType(el);
3980: sprintf (buffer, "border-top-color: #%02X%02X%02X", red, green, blue);
3981: break;
3982: case PRBorderRightColor:
3983: TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
3984: elType = TtaGetElementType(el);
3985: sprintf (buffer, "border-right-color: #%02X%02X%02X", red, green, blue);
3986: break;
3987: case PRBorderBottomColor:
3988: TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
3989: elType = TtaGetElementType(el);
3990: sprintf (buffer, "border-bottom-color: #%02X%02X%02X", red, green, blue);
1.18 cvs 3991: break;
1.111 cvs 3992: case PRBorderLeftColor:
3993: TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
3994: elType = TtaGetElementType(el);
3995: sprintf (buffer, "border-left-color: #%02X%02X%02X", red, green, blue);
1.20 cvs 3996: break;
1.111 cvs 3997: case PRBorderTopStyle:
3998: strcpy (buffer, "border-top-style: ");
3999: AddBorderStyleValue (buffer, settings->value.typed_data.value);
4000: break;
4001: case PRBorderRightStyle:
4002: strcpy (buffer, "border-right-style: ");
4003: AddBorderStyleValue (buffer, settings->value.typed_data.value);
4004: break;
4005: case PRBorderBottomStyle:
4006: strcpy (buffer, "border-bottom-style: ");
4007: AddBorderStyleValue (buffer, settings->value.typed_data.value);
4008: break;
4009: case PRBorderLeftStyle:
4010: strcpy (buffer, "border-left-style: ");
4011: AddBorderStyleValue (buffer, settings->value.typed_data.value);
1.18 cvs 4012: break;
4013: case PRSize:
1.184 vatton 4014: if (unit == UNIT_REL)
1.18 cvs 4015: {
4016: if (real)
4017: {
1.82 cvs 4018: sprintf (buffer, "font-size: %g", fval);
1.18 cvs 4019: add_unit = 1;
4020: }
4021: else
4022: switch (settings->value.typed_data.value)
4023: {
4024: case 1:
1.82 cvs 4025: strcpy (buffer, "font-size: xx-small");
1.18 cvs 4026: break;
4027: case 2:
1.82 cvs 4028: strcpy (buffer, "font-size: x-small");
1.18 cvs 4029: break;
4030: case 3:
1.82 cvs 4031: strcpy (buffer, "font-size: small");
1.18 cvs 4032: break;
4033: case 4:
1.82 cvs 4034: strcpy (buffer, "font-size: medium");
1.18 cvs 4035: break;
4036: case 5:
1.82 cvs 4037: strcpy (buffer, "font-size: large");
1.18 cvs 4038: break;
4039: case 6:
1.82 cvs 4040: strcpy (buffer, "font-size: x-large");
1.18 cvs 4041: break;
4042: case 7:
4043: case 8:
4044: case 9:
4045: case 10:
4046: case 11:
4047: case 12:
1.82 cvs 4048: strcpy (buffer, "font-size: xx-large");
1.18 cvs 4049: break;
4050: }
4051: }
4052: else
4053: {
4054: if (real)
1.82 cvs 4055: sprintf (buffer, "font-size: %g", fval);
1.18 cvs 4056: else
1.82 cvs 4057: sprintf (buffer, "font-size: %d",
1.67 cvs 4058: settings->value.typed_data.value);
1.18 cvs 4059: add_unit = 1;
4060: }
4061: break;
1.111 cvs 4062: case PRStyle:
4063: switch (settings->value.typed_data.value)
4064: {
1.184 vatton 4065: case StyleRoman:
1.111 cvs 4066: strcpy (buffer, "font-style: normal");
4067: break;
1.184 vatton 4068: case StyleItalics:
1.111 cvs 4069: strcpy (buffer, "font-style: italic");
4070: break;
1.184 vatton 4071: case StyleOblique:
1.111 cvs 4072: strcpy (buffer, "font-style: oblique");
4073: break;
4074: }
4075: break;
4076: case PRWeight:
4077: switch (settings->value.typed_data.value)
4078: {
1.184 vatton 4079: case WeightBold:
1.111 cvs 4080: strcpy (buffer, "font-weight: bold");
4081: break;
1.184 vatton 4082: case WeightNormal:
1.111 cvs 4083: strcpy (buffer, "font-weight: normal");
4084: break;
4085: }
4086: break;
4087: case PRFont:
4088: switch (settings->value.typed_data.value)
4089: {
1.184 vatton 4090: case FontHelvetica:
1.111 cvs 4091: strcpy (buffer, "font-family: helvetica");
4092: break;
1.184 vatton 4093: case FontTimes:
1.111 cvs 4094: strcpy (buffer, "font-family: times");
4095: break;
1.184 vatton 4096: case FontCourier:
1.111 cvs 4097: strcpy (buffer, "font-family: courier");
4098: break;
4099: }
4100: break;
1.18 cvs 4101: case PRUnderline:
4102: switch (settings->value.typed_data.value)
4103: {
1.184 vatton 4104: case Underline:
1.82 cvs 4105: strcpy (buffer, "text-decoration: underline");
1.18 cvs 4106: break;
1.184 vatton 4107: case Overline:
1.82 cvs 4108: strcpy (buffer, "text-decoration: overline");
1.18 cvs 4109: break;
1.184 vatton 4110: case CrossOut:
1.82 cvs 4111: strcpy (buffer, "text-decoration: line-through");
1.18 cvs 4112: break;
4113: }
4114: break;
1.111 cvs 4115: case PRThickness:
4116: break;
1.18 cvs 4117: case PRIndent:
4118: if (real)
1.82 cvs 4119: sprintf (buffer, "text-indent: %g", fval);
1.18 cvs 4120: else
1.82 cvs 4121: sprintf (buffer, "text-indent: %d",
1.67 cvs 4122: settings->value.typed_data.value);
1.18 cvs 4123: add_unit = 1;
4124: break;
4125: case PRLineSpacing:
4126: if (real)
1.82 cvs 4127: sprintf (buffer, "line-height: %g", fval);
1.1 cvs 4128: else
1.82 cvs 4129: sprintf (buffer, "line-height: %d",
1.67 cvs 4130: settings->value.typed_data.value);
1.18 cvs 4131: add_unit = 1;
4132: break;
1.111 cvs 4133: case PRDepth:
4134: break;
1.18 cvs 4135: case PRAdjust:
4136: switch (settings->value.typed_data.value)
1.1 cvs 4137: {
1.184 vatton 4138: case AdjustLeft:
1.82 cvs 4139: strcpy (buffer, "text-align: left");
1.18 cvs 4140: break;
1.184 vatton 4141: case AdjustRight:
1.82 cvs 4142: strcpy (buffer, "text-align: right");
1.18 cvs 4143: break;
1.184 vatton 4144: case Centered:
1.82 cvs 4145: strcpy (buffer, "text-align: center");
1.18 cvs 4146: break;
1.184 vatton 4147: case LeftWithDots:
1.82 cvs 4148: strcpy (buffer, "text-align: left");
1.81 cvs 4149: break;
1.184 vatton 4150: case Justify:
1.82 cvs 4151: strcpy (buffer, "text-align: justify");
1.112 quint 4152: break;
4153: }
4154: break;
4155: case PRDirection:
4156: switch (settings->value.typed_data.value)
4157: {
1.184 vatton 4158: case LeftToRight:
1.112 quint 4159: strcpy (buffer, "direction: ltr");
4160: break;
1.184 vatton 4161: case RightToLeft:
1.112 quint 4162: strcpy (buffer, "direction: rtl");
1.113 quint 4163: break;
4164: }
4165: break;
4166: case PRUnicodeBidi:
4167: switch (settings->value.typed_data.value)
4168: {
1.184 vatton 4169: case Normal:
1.113 quint 4170: strcpy (buffer, "unicode-bidi: normal");
4171: break;
1.184 vatton 4172: case Embed:
1.113 quint 4173: strcpy (buffer, "unicode-bidi: embed");
4174: break;
1.184 vatton 4175: case Override:
1.113 quint 4176: strcpy (buffer, "unicode-bidi: bidi-override");
1.18 cvs 4177: break;
1.1 cvs 4178: }
1.18 cvs 4179: break;
1.111 cvs 4180: case PRLineStyle:
4181: break;
1.126 vatton 4182: case PRDisplay:
4183: switch (settings->value.typed_data.value)
4184: {
1.184 vatton 4185: case Inline:
1.126 vatton 4186: strcpy (buffer, "display: inline");
4187: break;
1.184 vatton 4188: case Block:
1.126 vatton 4189: strcpy (buffer, "display: block");
4190: break;
1.184 vatton 4191: case ListItem:
1.126 vatton 4192: strcpy (buffer, "display: list-item");
4193: break;
1.184 vatton 4194: case RunIn:
1.126 vatton 4195: strcpy (buffer, "display: runin");
4196: break;
1.184 vatton 4197: case Compact:
1.126 vatton 4198: strcpy (buffer, "display: compact");
4199: break;
1.184 vatton 4200: case Marker:
1.126 vatton 4201: strcpy (buffer, "display: marker");
1.196 vatton 4202: break;
4203: default:
4204: break;
4205: }
4206: break;
4207: case PRFloat:
4208: switch (settings->value.typed_data.value)
4209: {
4210: case FloatNone:
4211: strcpy (buffer, "float: none");
4212: break;
4213: case FloatLeft:
4214: strcpy (buffer, "float: left");
4215: break;
4216: case FloatRight:
4217: strcpy (buffer, "float: right");
4218: break;
4219: default:
4220: break;
4221: }
4222: break;
4223: case PRClear:
4224: switch (settings->value.typed_data.value)
4225: {
4226: case ClearNone:
4227: strcpy (buffer, "clear: none");
4228: break;
4229: case ClearLeft:
4230: strcpy (buffer, "clear: left");
4231: break;
4232: case ClearRight:
4233: strcpy (buffer, "clear: right");
4234: break;
4235: case ClearBoth:
4236: strcpy (buffer, "clear: both");
1.126 vatton 4237: break;
4238: default:
4239: break;
4240: }
4241: break;
1.111 cvs 4242: case PRLineWeight:
4243: elType = TtaGetElementType(el);
4244: #ifdef _SVG
4245: if (!strcmp(TtaGetSSchemaName (elType.ElSSchema), "SVG"))
4246: #endif /* _SVG */
4247: {
4248: if (real)
4249: sprintf (buffer, "stroke-width: %g", fval);
4250: else
4251: sprintf (buffer, "stroke-width: %d",
4252: settings->value.typed_data.value);
4253: }
4254: add_unit = 1;
1.18 cvs 4255: break;
4256: case PRFillPattern:
4257: break;
4258: case PRBackground:
4259: TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
1.76 cvs 4260: elType = TtaGetElementType(el);
1.100 vatton 4261: #ifdef _SVG
4262: if (strcmp(TtaGetSSchemaName (elType.ElSSchema), "SVG") == 0)
1.82 cvs 4263: sprintf (buffer, "fill: #%02X%02X%02X", red, green, blue);
1.67 cvs 4264: else
1.100 vatton 4265: #endif /* _SVG */
1.82 cvs 4266: sprintf (buffer, "background-color: #%02X%02X%02X", red, green,
1.67 cvs 4267: blue);
1.18 cvs 4268: break;
4269: case PRForeground:
4270: TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
1.76 cvs 4271: elType = TtaGetElementType(el);
1.100 vatton 4272: #ifdef _SVG
4273: if (strcmp(TtaGetSSchemaName (elType.ElSSchema), "SVG") == 0)
1.82 cvs 4274: sprintf (buffer, "stroke: #%02X%02X%02X", red, green, blue);
1.67 cvs 4275: else
1.100 vatton 4276: #endif /* _SVG */
1.82 cvs 4277: sprintf (buffer, "color: #%02X%02X%02X", red, green, blue);
1.67 cvs 4278: break;
1.111 cvs 4279: case PRHyphenate:
1.195 vatton 4280: case PRVertOverflow:
4281: case PRHorizOverflow:
4282: break;
4283: case PROpacity:
4284: sprintf (buffer, "opacity: %g", fval);
1.18 cvs 4285: break;
1.195 vatton 4286: case PRStrokeOpacity:
4287: sprintf (buffer, "stroke-opacity: %g", fval);
1.18 cvs 4288: break;
1.195 vatton 4289: case PRFillOpacity:
4290: sprintf (buffer, "fill-opacity: %g", fval);
1.18 cvs 4291: break;
4292: case PRBackgroundPicture:
4293: if (settings->value.pointer != NULL)
1.82 cvs 4294: sprintf (buffer, "background-image: url(%s)",
1.67 cvs 4295: (char*)(settings->value.pointer));
1.1 cvs 4296: else
1.82 cvs 4297: sprintf (buffer, "background-image: none");
1.18 cvs 4298: break;
4299: case PRPictureMode:
4300: switch (settings->value.typed_data.value)
1.1 cvs 4301: {
1.184 vatton 4302: case REALSIZE:
1.82 cvs 4303: sprintf (buffer, "background-repeat: no-repeat");
1.18 cvs 4304: break;
1.184 vatton 4305: case REPEAT:
1.82 cvs 4306: sprintf (buffer, "background-repeat: repeat");
1.18 cvs 4307: break;
1.184 vatton 4308: case VREPEAT:
1.82 cvs 4309: sprintf (buffer, "background-repeat: repeat-y");
1.18 cvs 4310: break;
1.184 vatton 4311: case HREPEAT:
1.82 cvs 4312: sprintf (buffer, "background-repeat: repeat-x");
1.18 cvs 4313: break;
1.1 cvs 4314: }
1.18 cvs 4315: break;
4316: default:
4317: break;
1.1 cvs 4318: }
4319:
1.18 cvs 4320: if (add_unit)
1.1 cvs 4321: {
1.18 cvs 4322: /* add the unit string to the CSS string */
4323: for (i = 0; i < NB_UNITS; i++)
1.1 cvs 4324: {
1.18 cvs 4325: if (CSSUnitNames[i].unit == unit)
1.1 cvs 4326: {
1.82 cvs 4327: strcat (buffer, CSSUnitNames[i].sign);
1.18 cvs 4328: break;
1.1 cvs 4329: }
4330: }
4331: }
4332: }
4333:
4334: /*----------------------------------------------------------------------
1.59 cvs 4335: ParseHTMLSpecificStyle: parse and apply a CSS Style string.
1.18 cvs 4336: This function must be called when a specific style is applied to an
4337: element.
1.114 quint 4338: The parameter specificity is the specificity of the style, 0 if it is
4339: not really a CSS rule.
1.1 cvs 4340: ----------------------------------------------------------------------*/
1.79 cvs 4341: void ParseHTMLSpecificStyle (Element el, char *cssRule, Document doc,
1.114 quint 4342: int specificity, ThotBool destroy)
1.1 cvs 4343: {
4344: PresentationContext context;
4345: ElementType elType;
1.14 cvs 4346: ThotBool isHTML;
1.1 cvs 4347:
4348: /* A rule applying to BODY is really meant to address HTML */
4349: elType = TtaGetElementType (el);
1.89 cvs 4350:
1.86 cvs 4351: /* store the current line for eventually reported errors */
4352: LineNumber = TtaGetElementLineNumber (el);
1.89 cvs 4353: if (destroy)
4354: /* no reported errors */
4355: ParsedDoc = 0;
4356: else if (ParsedDoc != doc)
4357: {
4358: /* update the context for reported errors */
4359: ParsedDoc = doc;
4360: DocURL = DocumentURLs[doc];
4361: }
1.82 cvs 4362: isHTML = (strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML") == 0);
1.1 cvs 4363: /* create the context of the Specific presentation driver */
4364: context = TtaGetSpecificStyleContext (doc);
4365: if (context == NULL)
4366: return;
4367: context->type = elType.ElTypeNum;
1.114 quint 4368: context->cssSpecificity = specificity;
1.1 cvs 4369: context->destroy = destroy;
4370: /* Call the parser */
1.155 cheyroul 4371: ParseCSSRule (el, NULL,
4372: (PresentationContext) context,
4373: cssRule, NULL, isHTML);
1.1 cvs 4374: /* free the context */
4375: TtaFreeMemory(context);
4376: }
4377:
1.68 cvs 4378:
1.1 cvs 4379: /*----------------------------------------------------------------------
1.59 cvs 4380: ParseGenericSelector: Create a generic context for a given
1.1 cvs 4381: selector string. If the selector is made of multiple comma-
4382: separated selector items, it parses them one at a time and
4383: return the end of the selector string to be handled or NULL
4384: ----------------------------------------------------------------------*/
1.197 ! vatton 4385: static char *ParseGenericSelector (char *selector, char *cssRule, char *sel,
1.79 cvs 4386: GenericContext ctxt, Document doc,
4387: CSSInfoPtr css)
4388: {
4389: ElementType elType;
4390: PSchema tsch;
1.119 vatton 4391: AttributeType attrType;
1.118 vatton 4392: char *deb, *cur, c;
4393: char *schemaName, *mappedName;
1.79 cvs 4394: char *names[MAX_ANCESTORS];
4395: char *ids[MAX_ANCESTORS];
4396: char *classes[MAX_ANCESTORS];
4397: char *pseudoclasses[MAX_ANCESTORS];
4398: char *attrs[MAX_ANCESTORS];
4399: char *attrvals[MAX_ANCESTORS];
1.133 vatton 4400: AttrMatch attrmatch[MAX_ANCESTORS];
1.91 cvs 4401: int i, j, k, max;
1.125 vatton 4402: int att, maxAttr, kind;
1.118 vatton 4403: int specificity, xmlType;
1.79 cvs 4404: ThotBool isHTML;
1.183 vatton 4405: ThotBool level, quoted;
1.1 cvs 4406:
1.82 cvs 4407: sel[0] = EOS;
1.117 vatton 4408: specificity = 0;
1.1 cvs 4409: for (i = 0; i < MAX_ANCESTORS; i++)
4410: {
1.25 cvs 4411: names[i] = NULL;
4412: ids[i] = NULL;
4413: classes[i] = NULL;
4414: pseudoclasses[i] = NULL;
4415: attrs[i] = NULL;
4416: attrvals[i] = NULL;
1.133 vatton 4417: attrmatch[i] = Txtmatch;
1.25 cvs 4418: ctxt->name[i] = 0;
4419: ctxt->names_nb[i] = 0;
4420: ctxt->attrType[i] = 0;
1.129 vatton 4421: ctxt->attrLevel[i] = 0;
1.25 cvs 4422: ctxt->attrText[i] = NULL;
1.178 quint 4423: ctxt->attrMatch[i] = Txtmatch;
1.1 cvs 4424: }
1.25 cvs 4425: ctxt->box = 0;
4426: ctxt->type = 0;
1.114 quint 4427: /* the specificity of the rule depends on the selector */
4428: ctxt->cssSpecificity = 0;
1.25 cvs 4429:
1.82 cvs 4430: selector = SkipBlanksAndComments (selector);
1.27 cvs 4431: cur = &sel[0];
1.25 cvs 4432: max = 0; /* number of loops */
1.1 cvs 4433: while (1)
4434: {
1.85 cvs 4435: /* point to the following word in sel[] */
1.27 cvs 4436: deb = cur;
1.25 cvs 4437: /* copy an item of the selector into sel[] */
1.1 cvs 4438: /* put one word in the sel buffer */
1.82 cvs 4439: while (*selector != EOS && *selector != ',' &&
4440: *selector != '.' && *selector != ':' &&
1.118 vatton 4441: *selector != '#' && *selector != '[' &&
1.130 vatton 4442: *selector != '*' && *selector != '>' &&
1.118 vatton 4443: !TtaIsBlank (selector))
1.50 cvs 4444: *cur++ = *selector++;
1.82 cvs 4445: *cur++ = EOS; /* close the first string in sel[] */
4446: if (deb[0] != EOS)
1.117 vatton 4447: {
4448: names[0] = deb;
1.150 vatton 4449: if (!strcmp (names[0], "html"))
1.149 vatton 4450: /* give a greater priority to the backgoud color of html */
4451: specificity += 3;
4452: else
4453: specificity += 1;
1.117 vatton 4454: }
1.25 cvs 4455: else
1.27 cvs 4456: names[0] = NULL;
4457: classes[0] = NULL;
4458: pseudoclasses[0] = NULL;
4459: ids[0] = NULL;
4460: attrs[0] = NULL;
4461: attrvals[0] = NULL;
1.25 cvs 4462:
1.27 cvs 4463: /* now names[0] points to the beginning of the parsed item
1.25 cvs 4464: and cur to the next chain to be parsed */
1.129 vatton 4465: while (*selector == '.' || *selector == ':' ||
1.130 vatton 4466: *selector == '#' || *selector == '[' ||
1.183 vatton 4467: *selector == '*')
1.129 vatton 4468: {
1.85 cvs 4469: /* point to the following word in sel[] */
4470: deb = cur;
1.129 vatton 4471: if (*selector == '.')
4472: {
4473: selector++;
4474: while (*selector != EOS && *selector != ',' &&
4475: *selector != '.' && *selector != ':' &&
4476: !TtaIsBlank (selector))
4477: *cur++ = *selector++;
4478: /* close the word */
4479: *cur++ = EOS;
4480: /* point to the class in sel[] if it's valid name */
4481: if (deb[0] <= 64)
4482: {
1.168 vatton 4483: CSSPrintError ("Invalid class", deb);
1.116 vatton 4484: DoApply = FALSE;
1.129 vatton 4485: }
4486: else
4487: {
4488: classes[0] = deb;
1.178 quint 4489: /* a "class" attribute on an element may contain several
4490: words, one for each class it matches */
4491: attrmatch[0] = Txtword;
1.117 vatton 4492: specificity += 10;
1.129 vatton 4493: }
4494: }
4495: else if (*selector == ':')
4496: {
4497: selector++;
4498: while (*selector != EOS && *selector != ',' &&
4499: *selector != '.' && *selector != ':' &&
4500: !TtaIsBlank (selector))
4501: *cur++ = *selector++;
4502: /* close the word */
4503: *cur++ = EOS;
4504: /* point to the pseudoclass in sel[] if it's valid name */
4505: if (deb[0] <= 64)
4506: {
1.168 vatton 4507: CSSPrintError ("Invalid pseudoclass", deb);
1.129 vatton 4508: DoApply = FALSE;
4509: }
4510: else
4511: {
4512: if (!strcmp (deb, "first-letter") ||
4513: !strcmp (deb, "first-line") ||
4514: !strcmp (deb, "before") ||
4515: !strcmp (deb, "after"))
4516: /* not supported */
1.116 vatton 4517: DoApply = FALSE;
1.129 vatton 4518: else
4519: specificity += 10;
4520: pseudoclasses[0]= deb;
4521: }
4522: }
4523: else if (*selector == '#')
4524: {
4525: selector++;
4526: while (*selector != EOS && *selector != ',' &&
4527: *selector != '.' && *selector != ':' &&
4528: !TtaIsBlank (selector))
4529: *cur++ = *selector++;
4530: /* close the word */
4531: *cur++ = EOS;
4532: /* point to the attribute in sel[] if it's valid name */
4533: if (deb[0] <= 64)
4534: {
1.168 vatton 4535: CSSPrintError ("Invalid id", deb);
1.129 vatton 4536: DoApply = FALSE;
4537: }
4538: else
4539: {
4540: ids[0] = deb;
4541: specificity += 100;
4542: }
4543: }
4544: else if (*selector == '[')
4545: {
1.118 vatton 4546: selector++;
1.129 vatton 4547: while (*selector != EOS && *selector != ']' &&
1.131 vatton 4548: *selector != '=' && *selector != '~' &&
1.133 vatton 4549: *selector != '|' && *selector != '^' &&
4550: *selector != '!')
1.129 vatton 4551: *cur++ = *selector++;
1.133 vatton 4552: /* check matching */
4553: if (*selector == '~')
4554: {
4555: attrmatch[0] = Txtword;
4556: selector++;
4557: }
4558: else if (*selector == '|')
4559: {
4560: attrmatch[0] = Txtsubstring;
4561: selector++;
4562: }
4563: else
4564: attrmatch[0] = Txtmatch;
1.129 vatton 4565: /* close the word */
4566: *cur++ = EOS;
4567: /* point to the attribute in sel[] if it's valid name */
4568: if (deb[0] <= 64)
4569: {
1.168 vatton 4570: CSSPrintError ("Invalid attribute", deb);
1.129 vatton 4571: DoApply = FALSE;
4572: }
4573: else
4574: {
4575: attrs[0] = deb;
4576: specificity += 10;
4577: }
4578: if (*selector == '=')
4579: {
4580: /* look for a value "xxxx" */
4581: selector++;
4582: if (*selector != '"')
1.183 vatton 4583: quoted = FALSE;
1.129 vatton 4584: else
4585: {
1.183 vatton 4586: quoted = TRUE;
1.129 vatton 4587: /* we are now parsing the attribute value */
4588: selector++;
1.183 vatton 4589: }
4590: deb = cur;
4591: while ((quoted &&
4592: (*selector != '"' ||
4593: (*selector == '"' && selector[-1] == '\\'))) ||
4594: (!quoted && *selector != ']'))
4595: {
4596: if (*selector == EOS)
1.129 vatton 4597: {
1.183 vatton 4598: CSSPrintError ("Invalid attribute value", deb);
4599: DoApply = FALSE;
1.129 vatton 4600: }
1.183 vatton 4601: else
1.129 vatton 4602: {
1.183 vatton 4603: *cur++ = tolower (*selector);
1.129 vatton 4604: selector++;
4605: }
4606: }
1.183 vatton 4607: /* there is a value */
4608: if (quoted && *selector != '"')
4609: {
4610: selector++;
4611: quoted = FALSE;
4612: }
4613: if (*selector != ']')
4614: {
4615: CSSPrintError ("Invalid attribute value", deb);
4616: DoApply = FALSE;
4617: }
4618: else
4619: {
4620: *cur++ = EOS;
4621: attrvals[0] = deb;
4622: selector++;
4623: }
1.129 vatton 4624: }
4625: /* end of the attribute */
1.183 vatton 4626: else if (*selector != ']')
1.129 vatton 4627: {
1.133 vatton 4628: selector[1] = EOS;
1.183 vatton 4629: CSSPrintError ("Invalid attribute", selector);
1.133 vatton 4630: selector += 2;
1.129 vatton 4631: DoApply = FALSE;
4632: }
4633: else
4634: selector++;
1.130 vatton 4635: }
4636: else
4637: {
4638: /* not supported selector */
4639: while (*selector != EOS && *selector != ',' &&
4640: *selector != '.' && *selector != ':' &&
4641: !TtaIsBlank (selector))
4642: *cur++ = *selector++;
4643: /* close the word */
4644: *cur++ = EOS;
1.168 vatton 4645: CSSPrintError ("Not supported selector", deb);
1.130 vatton 4646: DoApply = FALSE;
1.129 vatton 4647: }
4648: }
1.1 cvs 4649:
1.82 cvs 4650: selector = SkipBlanksAndComments (selector);
1.25 cvs 4651: /* is it a multi-level selector? */
1.82 cvs 4652: if (*selector == EOS)
1.1 cvs 4653: /* end of the selector */
4654: break;
1.82 cvs 4655: else if (*selector == ',')
1.1 cvs 4656: {
4657: /* end of the current selector */
4658: selector++;
4659: break;
4660: }
1.25 cvs 4661: else
4662: {
1.143 vatton 4663: if (*selector == '>')
4664: {
4665: /* handle immediat parent as a simple parent */
4666: selector++;
4667: selector = SkipBlanksAndComments (selector);
4668: }
1.25 cvs 4669: /* shifts the list to make room for the new name */
4670: max++; /* a new level in ancestor tables */
4671: if (max == MAX_ANCESTORS)
4672: /* abort the CSS parsing */
4673: return (selector);
4674: for (i = max; i > 0; i--)
4675: {
4676: names[i] = names[i - 1];
4677: ids[i] = ids[i - 1];
4678: classes[i] = classes[i - 1];
1.133 vatton 4679: pseudoclasses[i] = pseudoclasses[i - 1];
1.25 cvs 4680: attrs[i] = attrs[i - 1];
4681: attrvals[i] = attrvals[i - 1];
1.133 vatton 4682: attrmatch[i] = attrmatch[i - 1];
1.25 cvs 4683: }
4684: }
1.1 cvs 4685: }
4686:
4687: /* Now set up the context block */
1.25 cvs 4688: i = 0;
4689: k = 0;
4690: j = 0;
1.35 cvs 4691: maxAttr = 0;
1.91 cvs 4692: /* default schema name */
1.119 vatton 4693: ctxt->schema = NULL;
1.122 vatton 4694: elType.ElSSchema = NULL;
4695: schemaName = TtaGetSSchemaName(TtaGetDocumentSSchema (doc));
1.119 vatton 4696: if (!strcmp (schemaName, "HTML"))
4697: xmlType = XHTML_TYPE;
4698: else if (!strcmp (schemaName, "MathML"))
4699: xmlType = MATH_TYPE;
4700: else if (!strcmp (schemaName, "SVG"))
4701: xmlType = SVG_TYPE;
4702: else if (!strcmp (schemaName, "XLink"))
4703: xmlType = XLINK_TYPE;
4704: else if (!strcmp (schemaName, "Annot"))
4705: xmlType = ANNOT_TYPE;
4706: else
4707: xmlType = XML_TYPE;
1.25 cvs 4708: while (i <= max)
4709: {
4710: if (names[i])
4711: {
1.118 vatton 4712: /* get the element type of this name in the current document */
4713: MapXMLElementType (xmlType, names[i], &elType, &mappedName, &c, &level, doc);
1.25 cvs 4714: if (i == 0)
4715: {
1.106 cvs 4716: if (elType.ElSSchema == NULL)
4717: {
1.119 vatton 4718: /* Search in the list of loaded schemas */
1.106 cvs 4719: TtaGetXmlElementType (names[i], &elType, NULL, doc);
1.119 vatton 4720: if (elType.ElSSchema)
4721: {
1.154 vatton 4722: /* the element type concerns an imported nature */
1.119 vatton 4723: schemaName = TtaGetSSchemaName(elType.ElSSchema);
4724: if (!strcmp (schemaName, "HTML"))
4725: xmlType = XHTML_TYPE;
4726: else if (!strcmp (schemaName, "MathML"))
4727: xmlType = MATH_TYPE;
4728: else if (!strcmp (schemaName, "SVG"))
4729: xmlType = SVG_TYPE;
4730: else if (!strcmp (schemaName, "XLink"))
4731: xmlType = XLINK_TYPE;
4732: else if (!strcmp (schemaName, "Annot"))
4733: xmlType = ANNOT_TYPE;
4734: else
4735: xmlType = XML_TYPE;
4736: }
1.118 vatton 4737: #ifdef XML_GENERIC
1.119 vatton 4738: else if (xmlType == XML_TYPE)
1.106 cvs 4739: {
4740: /* Creation of a new element type in the main schema */
4741: elType.ElSSchema = TtaGetDocumentSSchema (doc);
1.118 vatton 4742: TtaAppendXmlElement (names[i], &elType, &mappedName, doc);
1.106 cvs 4743: }
1.118 vatton 4744: #endif /* XML_GENERIC */
1.122 vatton 4745: else
4746: {
4747: if (xmlType != XHTML_TYPE)
4748: {
4749: MapXMLElementType (XHTML_TYPE, names[i], &elType,
4750: &mappedName, &c, &level, doc);
4751: if (elType.ElSSchema)
1.123 vatton 4752: elType.ElSSchema = GetXHTMLSSchema (doc);
1.122 vatton 4753: }
4754: if (elType.ElSSchema == NULL && xmlType != MATH_TYPE)
4755: {
4756: MapXMLElementType (MATH_TYPE, names[i], &elType,
4757: &mappedName, &c, &level, doc);
4758: if (elType.ElSSchema)
1.123 vatton 4759: elType.ElSSchema = GetMathMLSSchema (doc);
1.122 vatton 4760: }
4761: if (elType.ElSSchema == NULL && xmlType != SVG_TYPE)
4762: {
4763: MapXMLElementType (SVG_TYPE, names[i], &elType,
4764: &mappedName, &c, &level, doc);
4765: if (elType.ElSSchema)
1.123 vatton 4766: elType.ElSSchema = GetSVGSSchema (doc);
1.122 vatton 4767: }
4768: }
1.118 vatton 4769: }
1.119 vatton 4770:
1.118 vatton 4771: if (elType.ElSSchema == NULL)
4772: /* cannot apply these CSS rules */
4773: DoApply = FALSE;
4774: else
4775: {
4776: /* Store the element type */
4777: ctxt->type = elType.ElTypeNum;
4778: ctxt->name[0] = elType.ElTypeNum;
4779: ctxt->names_nb[0] = 0;
4780: ctxt->schema = elType.ElSSchema;
1.106 cvs 4781: }
1.25 cvs 4782: }
4783: else if (elType.ElTypeNum != 0)
4784: {
4785: /* look at the current context to see if the type is already
4786: stored */
1.121 vatton 4787: j = 1;
1.32 cvs 4788: while (j < k && ctxt->name[j] != elType.ElTypeNum)
1.25 cvs 4789: j++;
4790: if (j == k)
4791: {
4792: ctxt->name[j] = elType.ElTypeNum;
4793: if (j != 0)
1.121 vatton 4794: ctxt->names_nb[j] = 1;
1.25 cvs 4795: }
4796: else
4797: /* increment the number of ancestor levels */
4798: ctxt->names_nb[j]++;
4799: }
1.154 vatton 4800: #ifdef XML_GENERIC
4801: else if (xmlType == XML_TYPE)
4802: {
1.158 vatton 4803: TtaGetXmlElementType (names[i], &elType, NULL, doc);
4804: if (elType.ElTypeNum == 0)
4805: {
4806: /* Creation of a new element type in the main schema */
4807: elType.ElSSchema = TtaGetDocumentSSchema (doc);
4808: TtaAppendXmlElement (names[i], &elType, &mappedName, doc);
4809: }
1.154 vatton 4810: if (elType.ElTypeNum != 0)
4811: {
4812: /* look at the current context to see if the type is already
4813: stored */
4814: j = 1;
4815: while (j < k && ctxt->name[j] != elType.ElTypeNum)
4816: j++;
4817: if (j == k)
4818: {
4819: ctxt->name[j] = elType.ElTypeNum;
4820: if (j != 0)
4821: ctxt->names_nb[j] = 1;
4822: }
4823: else
4824: /* increment the number of ancestor levels */
4825: ctxt->names_nb[j]++;
4826: }
4827: }
4828: #endif /* XML_GENERIC */
1.25 cvs 4829: else
1.117 vatton 4830: j = k;
1.25 cvs 4831: }
1.117 vatton 4832: else
4833: j = k;
1.1 cvs 4834:
1.25 cvs 4835: /* store attributes information */
4836: if (classes[i])
4837: {
4838: ctxt->attrText[j] = classes[i];
1.119 vatton 4839: if (xmlType == SVG_TYPE)
1.100 vatton 4840: ctxt->attrType[j] = SVG_ATTR_class;
1.119 vatton 4841: else if (xmlType == MATH_TYPE)
1.91 cvs 4842: ctxt->attrType[j] = MathML_ATTR_class;
1.119 vatton 4843: else if (xmlType == XHTML_TYPE)
1.107 cvs 4844: ctxt->attrType[j] = HTML_ATTR_Class;
4845: else
1.119 vatton 4846: #ifdef XML_GENERIC
1.107 cvs 4847: ctxt->attrType[j] = XML_ATTR_class;
4848: #else /* XML_GENERIC */
1.91 cvs 4849: ctxt->attrType[j] = HTML_ATTR_Class;
1.107 cvs 4850: #endif /* XML_GENERIC */
1.157 vatton 4851: ctxt->attrMatch[j] = attrmatch[i];
1.79 cvs 4852: /* add a new entry */
1.80 cvs 4853: maxAttr = i + 1;
1.129 vatton 4854: /* update attrLevel */
4855: ctxt->attrLevel[j] = i;
4856: j++;
1.25 cvs 4857: }
1.79 cvs 4858: if (pseudoclasses[i])
1.25 cvs 4859: {
4860: ctxt->attrText[j] = pseudoclasses[i];
1.119 vatton 4861: if (xmlType == SVG_TYPE)
1.100 vatton 4862: ctxt->attrType[j] = SVG_ATTR_PseudoClass;
1.119 vatton 4863: else if (xmlType == MATH_TYPE)
1.91 cvs 4864: ctxt->attrType[j] = MathML_ATTR_PseudoClass;
1.119 vatton 4865: else if (xmlType == XHTML_TYPE)
1.107 cvs 4866: ctxt->attrType[j] = HTML_ATTR_PseudoClass;
4867: else
1.119 vatton 4868: #ifdef XML_GENERIC
1.107 cvs 4869: ctxt->attrType[j] = XML_ATTR_PseudoClass;
4870: #else /* XML_GENERIC */
1.91 cvs 4871: ctxt->attrType[j] = HTML_ATTR_PseudoClass;
1.107 cvs 4872: #endif /* XML_GENERIC */
1.157 vatton 4873: ctxt->attrMatch[j] = attrmatch[i];
1.79 cvs 4874: /* add a new entry */
1.80 cvs 4875: maxAttr = i + 1;
1.129 vatton 4876: /* update attrLevel */
4877: ctxt->attrLevel[j] = i;
4878: j++;
1.25 cvs 4879: }
1.79 cvs 4880: if (ids[i])
1.25 cvs 4881: {
4882: ctxt->attrText[j] = ids[i];
1.119 vatton 4883: if (xmlType == SVG_TYPE)
1.100 vatton 4884: ctxt->attrType[j] = SVG_ATTR_id;
1.119 vatton 4885: else if (xmlType == MATH_TYPE)
1.91 cvs 4886: ctxt->attrType[j] = MathML_ATTR_id;
1.119 vatton 4887: else if (xmlType == XHTML_TYPE)
1.107 cvs 4888: ctxt->attrType[j] = HTML_ATTR_ID;
4889: else
1.119 vatton 4890: #ifdef XML_GENERIC
1.107 cvs 4891: ctxt->attrType[j] = XML_ATTR_id;
4892: #else /* XML_GENERIC */
1.91 cvs 4893: ctxt->attrType[j] = HTML_ATTR_ID;
1.107 cvs 4894: #endif /* XML_GENERIC */
1.157 vatton 4895: ctxt->attrMatch[j] = attrmatch[i];
1.80 cvs 4896: /* add a new entry */
4897: maxAttr = i + 1;
1.129 vatton 4898: /* update attrLevel */
4899: ctxt->attrLevel[j] = i;
4900: j++;
1.25 cvs 4901: }
1.79 cvs 4902: if (attrs[i])
1.25 cvs 4903: {
1.125 vatton 4904: /* it's an attribute */
1.119 vatton 4905: MapXMLAttribute (xmlType, attrs[i], names[i], &level, doc, &att);
1.127 quint 4906: if (att == DummyAttribute && !strcmp (schemaName, "HTML"))
4907: /* it's the "type" attribute for an "input" element. In the tree
4908: it's represented by the element type, not by an attribute */
4909: att = 0;
1.119 vatton 4910: ctxt->attrType[j] = att;
1.133 vatton 4911: ctxt->attrMatch[j] = attrmatch[i];
1.125 vatton 4912: attrType.AttrSSchema = ctxt->schema;
4913: attrType.AttrTypeNum = att;
1.119 vatton 4914: if (i == 0 && att == 0 && ctxt->schema == NULL)
4915: {
1.125 vatton 4916: /* Not found -> search in the list of loaded schemas */
1.119 vatton 4917: attrType.AttrSSchema = NULL;
4918: TtaGetXmlAttributeType (attrs[i], &attrType, doc);
4919: ctxt->attrType[j] = attrType.AttrTypeNum;
4920: if (attrType.AttrSSchema)
1.125 vatton 4921: /* the element type concerns an imported nature */
4922: schemaName = TtaGetSSchemaName(attrType.AttrSSchema);
1.119 vatton 4923: #ifdef XML_GENERIC
4924: else if (xmlType == XML_TYPE)
4925: {
4926: /* The attribute is not yet present in the tree */
4927: /* Create a new global attribute */
4928: attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
4929: TtaAppendXmlAttribute (attrs[i], &attrType, doc);
4930: }
4931: #endif /* XML_GENERIC */
4932:
4933: if (attrType.AttrSSchema == NULL)
4934: /* cannot apply these CSS rules */
4935: DoApply = FALSE;
1.136 quint 4936: else if (elType.ElSSchema)
4937: ctxt->schema = elType.ElSSchema;
1.119 vatton 4938: else
1.136 quint 4939: ctxt->schema = attrType.AttrSSchema;
1.119 vatton 4940: }
1.125 vatton 4941: /* check the attribute type */
4942: if (!strcmp (schemaName, "HTML"))
4943: xmlType = XHTML_TYPE;
4944: else if (!strcmp (schemaName, "MathML"))
4945: xmlType = MATH_TYPE;
4946: else if (!strcmp (schemaName, "SVG"))
4947: xmlType = SVG_TYPE;
4948: else if (!strcmp (schemaName, "XLink"))
4949: xmlType = XLINK_TYPE;
4950: else if (!strcmp (schemaName, "Annot"))
4951: xmlType = ANNOT_TYPE;
4952: else
4953: xmlType = XML_TYPE;
4954: kind = TtaGetAttributeKind (attrType);
4955: if (kind == 0 && attrvals[i])
4956: {
4957: /* enumerated value */
4958: MapXMLAttributeValue (xmlType, attrvals[i], attrType, &kind);
4959: /* store the attribute value */
4960: ctxt->attrText[j] = (char *) kind;
4961: }
4962: else
4963: ctxt->attrText[j] = attrvals[i];
1.80 cvs 4964: maxAttr = i + 1;
1.129 vatton 4965: /* update attrLevel */
4966: ctxt->attrLevel[j] = i;
4967: j++;
1.25 cvs 4968: }
4969: i++;
1.117 vatton 4970: /* add a new entry */
4971: k++;
1.129 vatton 4972: if (k < j)
4973: k = j;
1.119 vatton 4974: if (i == 1 && ctxt->schema == NULL)
4975: /* use the document schema */
4976: ctxt->schema = TtaGetDocumentSSchema (doc);
1.1 cvs 4977: }
1.117 vatton 4978: /* set the selector specificity */
4979: ctxt->cssSpecificity = specificity;
1.25 cvs 4980: /* sort the list of ancestors by name order */
4981: max = k;
4982: i = 1;
4983: while (i < max)
1.28 cvs 4984: {
4985: for (k = i + 1; k < max; k++)
4986: if (ctxt->name[i] > ctxt->name[k])
4987: {
4988: j = ctxt->name[i];
4989: ctxt->name[i] = ctxt->name[k];
4990: ctxt->name[k] = j;
4991: j = ctxt->names_nb[i];
4992: ctxt->names_nb[i] = ctxt->names_nb[k];
4993: ctxt->names_nb[k] = j;
4994: j = ctxt->attrType[i];
4995: ctxt->attrType[i] = ctxt->attrType[k];
4996: ctxt->attrType[k] = j;
4997: cur = ctxt->attrText[i];
4998: ctxt->attrText[i] = ctxt->attrText[k];
4999: ctxt->attrText[k] = cur;
5000: }
5001: i++;
5002: }
1.84 cvs 5003:
1.25 cvs 5004: /* Get the schema name of the main element */
1.119 vatton 5005: schemaName = TtaGetSSchemaName (ctxt->schema);
5006: isHTML = (strcmp (schemaName, "HTML") == 0);
5007: tsch = GetPExtension (doc, ctxt->schema, css);
5008: if (tsch && cssRule)
5009: ParseCSSRule (NULL, tsch, (PresentationContext) ctxt, cssRule, css, isHTML);
1.116 vatton 5010: /* future CSS rules should apply */
5011: DoApply = TRUE;
1.1 cvs 5012: return (selector);
5013: }
5014:
5015: /*----------------------------------------------------------------------
1.73 cvs 5016: ParseStyleDeclaration: parse a style declaration
5017: stored in the style element of a document
1.59 cvs 5018: We expect the style string to be of the form:
1.1 cvs 5019: [
5020: e.g: pinky, awful { color: pink, font-family: helvetica }
5021: ----------------------------------------------------------------------*/
1.79 cvs 5022: static void ParseStyleDeclaration (Element el, char *cssRule, Document doc,
5023: CSSInfoPtr css, ThotBool destroy)
1.1 cvs 5024: {
1.79 cvs 5025: GenericContext ctxt;
1.197 ! vatton 5026: char sel[MAX_ANCESTORS * 50];
1.79 cvs 5027: char *decl_end;
5028: char *sel_end;
5029: char *selector;
1.1 cvs 5030:
5031: /* separate the selectors string */
1.82 cvs 5032: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 5033: decl_end = cssRule;
1.82 cvs 5034: while (*decl_end != EOS && *decl_end != '{')
1.1 cvs 5035: decl_end++;
1.82 cvs 5036: if (*decl_end == EOS)
1.86 cvs 5037: {
1.168 vatton 5038: CSSPrintError ("Invalid selector", cssRule);
1.86 cvs 5039: return;
5040: }
1.1 cvs 5041: /* verify and clean the selector string */
5042: sel_end = decl_end - 1;
1.82 cvs 5043: while (*sel_end == SPACE || *sel_end == BSPACE ||
5044: *sel_end == EOL || *sel_end == CR)
1.1 cvs 5045: sel_end--;
5046: sel_end++;
1.82 cvs 5047: *sel_end = EOS;
1.1 cvs 5048: selector = cssRule;
5049:
5050: /* now, deal with the content ... */
5051: decl_end++;
5052: cssRule = decl_end;
1.137 vatton 5053: decl_end = &cssRule[strlen (cssRule) - 1];
5054: if (*decl_end != '{')
5055: *decl_end = EOS;
1.1 cvs 5056: /*
5057: * parse the style attribute string and install the corresponding
5058: * presentation attributes on the new element
5059: */
5060: ctxt = TtaGetGenericStyleContext (doc);
5061: if (ctxt == NULL)
5062: return;
5063: ctxt->destroy = destroy;
5064:
1.197 ! vatton 5065: while (selector && *selector != EOS)
! 5066: selector = ParseGenericSelector (selector, cssRule, sel, ctxt, doc, css);
1.1 cvs 5067: TtaFreeMemory (ctxt);
5068: }
5069:
5070: /************************************************************************
5071: * *
5072: * EVALUATION FUNCTIONS / CASCADING AND OVERLOADING *
5073: * *
5074: ************************************************************************/
5075:
5076: /*----------------------------------------------------------------------
1.59 cvs 5077: IsImplicitClassName: return wether the Class name is an
1.1 cvs 5078: implicit one, eg "H1" or "H2 EM" meaning it's a GI name
5079: or an HTML context name.
5080: ----------------------------------------------------------------------*/
1.79 cvs 5081: int IsImplicitClassName (char *class, Document doc)
1.1 cvs 5082: {
1.79 cvs 5083: char name[200];
5084: char *cur = name;
5085: char *first;
5086: char save;
5087: SSchema schema;
1.1 cvs 5088:
5089: /* make a local copy */
1.82 cvs 5090: strncpy (name, class, 199);
1.1 cvs 5091: name[199] = 0;
5092:
5093: /* loop looking if each word is a GI */
5094: while (*cur != 0)
5095: {
5096: first = cur;
5097: cur = SkipWord (cur);
5098: save = *cur;
5099: *cur = 0;
5100: schema = NULL;
5101: if (MapGI (first, &schema, doc) == -1)
5102: {
5103: return (0);
5104: }
5105: *cur = save;
1.82 cvs 5106: cur = SkipBlanksAndComments (cur);
1.1 cvs 5107: }
5108: return (1);
5109: }
5110:
5111: /************************************************************************
5112: * *
1.114 quint 5113: * Functions needed for support of HTML: translate to CSS equivalent *
1.1 cvs 5114: * *
5115: ************************************************************************/
5116:
5117: /*----------------------------------------------------------------------
1.59 cvs 5118: HTMLSetBackgroundColor:
1.1 cvs 5119: ----------------------------------------------------------------------*/
1.79 cvs 5120: void HTMLSetBackgroundColor (Document doc, Element el, char *color)
1.1 cvs 5121: {
1.79 cvs 5122: char css_command[100];
1.1 cvs 5123:
1.82 cvs 5124: sprintf (css_command, "background-color: %s", color);
1.114 quint 5125: ParseHTMLSpecificStyle (el, css_command, doc, 0, FALSE);
1.1 cvs 5126: }
5127:
5128: /*----------------------------------------------------------------------
1.59 cvs 5129: HTMLSetForegroundColor:
1.1 cvs 5130: ----------------------------------------------------------------------*/
1.97 vatton 5131: void HTMLSetForegroundColor (Document doc, Element el, char *color)
1.1 cvs 5132: {
1.79 cvs 5133: char css_command[100];
1.1 cvs 5134:
1.82 cvs 5135: sprintf (css_command, "color: %s", color);
1.114 quint 5136: ParseHTMLSpecificStyle (el, css_command, doc, 0, FALSE);
1.1 cvs 5137: }
5138:
5139: /*----------------------------------------------------------------------
1.59 cvs 5140: HTMLResetBackgroundColor:
1.1 cvs 5141: ----------------------------------------------------------------------*/
1.97 vatton 5142: void HTMLResetBackgroundColor (Document doc, Element el)
1.1 cvs 5143: {
1.79 cvs 5144: char css_command[100];
1.1 cvs 5145:
1.82 cvs 5146: sprintf (css_command, "background: red");
1.114 quint 5147: ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1 cvs 5148: }
5149:
5150: /*----------------------------------------------------------------------
1.59 cvs 5151: HTMLResetBackgroundImage:
1.1 cvs 5152: ----------------------------------------------------------------------*/
1.97 vatton 5153: void HTMLResetBackgroundImage (Document doc, Element el)
1.1 cvs 5154: {
1.79 cvs 5155: char css_command[1000];
1.1 cvs 5156:
1.82 cvs 5157: sprintf (css_command, "background-image: url(xx); background-repeat: repeat");
1.114 quint 5158: ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1 cvs 5159: }
5160:
5161: /*----------------------------------------------------------------------
1.59 cvs 5162: HTMLResetForegroundColor:
1.1 cvs 5163: ----------------------------------------------------------------------*/
1.97 vatton 5164: void HTMLResetForegroundColor (Document doc, Element el)
1.1 cvs 5165: {
1.79 cvs 5166: char css_command[100];
1.1 cvs 5167:
1.36 cvs 5168: /* it's not necessary to well know the current color but it must be valid */
1.82 cvs 5169: sprintf (css_command, "color: red");
1.114 quint 5170: ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1 cvs 5171: }
5172:
5173: /*----------------------------------------------------------------------
1.59 cvs 5174: HTMLSetAlinkColor:
1.1 cvs 5175: ----------------------------------------------------------------------*/
1.97 vatton 5176: void HTMLSetAlinkColor (Document doc, char *color)
1.1 cvs 5177: {
1.79 cvs 5178: char css_command[100];
1.1 cvs 5179:
1.82 cvs 5180: sprintf (css_command, "a:link { color: %s }", color);
1.1 cvs 5181: ApplyCSSRules (NULL, css_command, doc, FALSE);
5182: }
5183:
5184: /*----------------------------------------------------------------------
1.59 cvs 5185: HTMLSetAactiveColor:
1.1 cvs 5186: ----------------------------------------------------------------------*/
1.97 vatton 5187: void HTMLSetAactiveColor (Document doc, char *color)
1.1 cvs 5188: {
1.79 cvs 5189: char css_command[100];
1.1 cvs 5190:
1.82 cvs 5191: sprintf (css_command, "a:active { color: %s }", color);
1.1 cvs 5192: ApplyCSSRules (NULL, css_command, doc, FALSE);
5193: }
5194:
5195: /*----------------------------------------------------------------------
1.59 cvs 5196: HTMLSetAvisitedColor:
1.1 cvs 5197: ----------------------------------------------------------------------*/
1.79 cvs 5198: void HTMLSetAvisitedColor (Document doc, char *color)
1.1 cvs 5199: {
1.79 cvs 5200: char css_command[100];
1.1 cvs 5201:
1.82 cvs 5202: sprintf (css_command, "a:visited { color: %s }", color);
1.1 cvs 5203: ApplyCSSRules (NULL, css_command, doc, FALSE);
5204: }
5205:
5206: /*----------------------------------------------------------------------
1.59 cvs 5207: HTMLResetAlinkColor:
1.1 cvs 5208: ----------------------------------------------------------------------*/
5209: void HTMLResetAlinkColor (Document doc)
5210: {
1.79 cvs 5211: char css_command[100];
1.1 cvs 5212:
1.82 cvs 5213: sprintf (css_command, "a:link { color: red }");
1.1 cvs 5214: ApplyCSSRules (NULL, css_command, doc, TRUE);
5215: }
5216:
5217: /*----------------------------------------------------------------------
1.59 cvs 5218: HTMLResetAactiveColor:
1.1 cvs 5219: ----------------------------------------------------------------------*/
5220: void HTMLResetAactiveColor (Document doc)
5221: {
1.79 cvs 5222: char css_command[100];
1.1 cvs 5223:
1.82 cvs 5224: sprintf (css_command, "a:active { color: red }");
1.1 cvs 5225: ApplyCSSRules (NULL, css_command, doc, TRUE);
5226: }
5227:
5228: /*----------------------------------------------------------------------
1.59 cvs 5229: HTMLResetAvisitedColor:
1.1 cvs 5230: ----------------------------------------------------------------------*/
5231: void HTMLResetAvisitedColor (Document doc)
5232: {
1.79 cvs 5233: char css_command[100];
1.1 cvs 5234:
1.82 cvs 5235: sprintf (css_command, "a:visited { color: red }");
1.1 cvs 5236: ApplyCSSRules (NULL, css_command, doc, TRUE);
5237: }
5238:
5239: /*----------------------------------------------------------------------
1.73 cvs 5240: ApplyCSSRules: parse a CSS Style description stored in the
1.1 cvs 5241: header of a HTML document.
5242: ----------------------------------------------------------------------*/
1.79 cvs 5243: void ApplyCSSRules (Element el, char *cssRule, Document doc, ThotBool destroy)
1.1 cvs 5244: {
5245: CSSInfoPtr css;
5246:
1.144 quint 5247: css = SearchCSS (doc, NULL, el);
1.1 cvs 5248: if (css == NULL)
5249: /* create the document css */
1.144 quint 5250: css = AddCSS (doc, doc, CSS_DOCUMENT_STYLE, NULL, NULL, el);
1.1 cvs 5251: ParseStyleDeclaration (el, cssRule, doc, css, destroy);
5252: }
5253:
5254: /*----------------------------------------------------------------------
1.145 quint 5255: ReadCSSRules: is the front-end function called by the document parser
5256: when detecting a <style type="text/css"> indicating it's the
1.1 cvs 5257: beginning of a CSS fragment or when reading a file .css.
5258:
5259: The CSS parser has to handle <!-- ... --> constructs used to
5260: prevent prehistoric browser from displaying the CSS as a text
5261: content. It will stop on any sequence "<x" where x is different
5262: from ! and will return x as to the caller. Theorically x should
1.145 quint 5263: be equal to / for the </style> end of style.
1.1 cvs 5264: The parameter doc gives the document tree that contains CSS information.
5265: The parameter docRef gives the document to which CSS are to be applied.
5266: This function uses the current css context or creates it. It's able
1.23 cvs 5267: to work on the given buffer or call GetNextChar to read the parsed
1.1 cvs 5268: file.
1.133 vatton 5269: The parameter url gives the URL of the style shheet parsed.
1.86 cvs 5270: Parameter numberOfLinesRead indicates the number of lines already
5271: read in the file.
1.1 cvs 5272: Parameter withUndo indicates whether the changes made in the document
1.145 quint 5273: structure and content have to be registered in the Undo queue or not.
1.1 cvs 5274: ----------------------------------------------------------------------*/
1.133 vatton 5275: char ReadCSSRules (Document docRef, CSSInfoPtr css, char *buffer, char *url,
1.144 quint 5276: int numberOfLinesRead, ThotBool withUndo,
1.172 quint 5277: Element styleElement)
1.1 cvs 5278: {
1.6 cvs 5279: DisplayMode dispMode;
1.82 cvs 5280: char c;
1.138 vatton 5281: char *cssRule, *base, *saveDocURL, *ptr;
1.19 cvs 5282: int index;
1.1 cvs 5283: int CSSindex;
5284: int CSScomment;
5285: int import;
5286: int openRule;
1.93 vatton 5287: int newlines;
1.14 cvs 5288: ThotBool HTMLcomment;
1.102 vatton 5289: ThotBool toParse, eof, quoted;
1.36 cvs 5290: ThotBool ignoreMedia, media;
1.186 vatton 5291: ThotBool noRule, ignoreImport, skip;
1.175 vatton 5292: CSSInfoPtr refcss = NULL;
1.1 cvs 5293:
5294: CSScomment = MAX_CSS_LENGTH;
5295: HTMLcomment = FALSE;
5296: CSSindex = 0;
5297: toParse = FALSE;
5298: noRule = FALSE;
1.36 cvs 5299: media = FALSE;
1.88 cvs 5300: ignoreImport = FALSE;
1.1 cvs 5301: ignoreMedia = FALSE;
5302: import = MAX_CSS_LENGTH;
5303: eof = FALSE;
5304: openRule = 0;
1.82 cvs 5305: c = SPACE;
1.1 cvs 5306: index = 0;
1.134 vatton 5307: base = NULL;
1.135 vatton 5308: quoted = FALSE;
1.186 vatton 5309: skip = FALSE;
1.93 vatton 5310: /* number of new lines parsed */
5311: newlines = 0;
1.6 cvs 5312: /* avoid too many redisplay */
5313: dispMode = TtaGetDisplayMode (docRef);
5314: if (dispMode == DisplayImmediately)
5315: TtaSetDisplayMode (docRef, DeferredDisplay);
1.18 cvs 5316:
5317: /* look for the CSS context */
5318: if (css == NULL)
1.144 quint 5319: css = SearchCSS (docRef, NULL, styleElement);
1.18 cvs 5320: if (css == NULL)
1.144 quint 5321: css = AddCSS (docRef, docRef, CSS_DOCUMENT_STYLE, NULL, NULL,
5322: styleElement);
1.174 vatton 5323: /* look for the CSS descriptor that points to the extension schema */
5324: refcss = css;
5325: if (import)
1.173 cvs 5326: {
1.174 vatton 5327: while (refcss && refcss->category == CSS_IMPORT)
5328: refcss = refcss->NextCSS;
1.173 cvs 5329: }
5330:
1.144 quint 5331: /* register parsed CSS file and the document to which CSS are to be applied*/
1.86 cvs 5332: ParsedDoc = docRef;
1.133 vatton 5333: if (url)
5334: DocURL = url;
1.86 cvs 5335: else
5336: /* the CSS source in within the document itself */
5337: DocURL = DocumentURLs[docRef];
5338: LineNumber = numberOfLinesRead + 1;
1.93 vatton 5339: NewLineSkipped = 0;
1.82 cvs 5340: while (CSSindex < MAX_CSS_LENGTH && c != EOS && !eof)
5341: {
5342: c = buffer[index++];
5343: eof = (c == EOS);
5344: CSSbuffer[CSSindex] = c;
1.186 vatton 5345: if (skip)
5346: {
5347: if (c == '}')
5348: {
5349: /* end of the @font-face */
5350: skip = FALSE;
5351: import = MAX_CSS_LENGTH;
5352: noRule = TRUE;
5353: CSSindex = 0;
5354: }
5355: if (c == EOL)
5356: LineNumber++;
5357: c = CR;
5358: }
5359: else if (CSScomment == MAX_CSS_LENGTH ||
1.82 cvs 5360: c == '*' || c == '/' || c == '<')
5361: {
5362: /* we're not within a comment or we're parsing * or / */
5363: switch (c)
5364: {
5365: case '@': /* perhaps an import primitive */
1.135 vatton 5366: if (!quoted)
5367: import = CSSindex;
1.82 cvs 5368: break;
5369: case ';':
1.135 vatton 5370: if (!quoted && !media && import != MAX_CSS_LENGTH)
1.82 cvs 5371: {
5372: if (strncasecmp (&CSSbuffer[import+1], "import", 6))
5373: /* it's not an import */
5374: import = MAX_CSS_LENGTH;
5375: /* save the text */
5376: noRule = TRUE;
5377: }
5378: break;
5379: case '*':
1.135 vatton 5380: if (!quoted && CSScomment == MAX_CSS_LENGTH && CSSindex > 0 &&
1.82 cvs 5381: CSSbuffer[CSSindex - 1] == '/')
5382: /* start a comment */
5383: CSScomment = CSSindex - 1;
5384: break;
5385: case '/':
1.135 vatton 5386: if (!quoted && CSSindex > 1 && CSScomment != MAX_CSS_LENGTH &&
1.82 cvs 5387: CSSbuffer[CSSindex - 1] == '*')
5388: {
5389: /* close a comment:and ignore its contents */
5390: CSSindex = CSScomment - 1; /* will be incremented later */
5391: CSScomment = MAX_CSS_LENGTH;
1.93 vatton 5392: /* clean up the buffer */
1.103 vatton 5393: if (newlines && CSSindex > 0)
5394: while (CSSindex > 0 &&
5395: (CSSbuffer[CSSindex] == SPACE ||
5396: CSSbuffer[CSSindex] == BSPACE ||
5397: CSSbuffer[CSSindex] == EOL ||
5398: CSSbuffer[CSSindex] == TAB ||
5399: CSSbuffer[CSSindex] == __CR__))
1.93 vatton 5400: {
5401: if ( CSSbuffer[CSSindex] == EOL)
5402: {
5403: LineNumber ++;
5404: newlines --;
5405: }
5406: CSSindex--;
5407: }
1.82 cvs 5408: }
1.135 vatton 5409: else if (!quoted && CSScomment == MAX_CSS_LENGTH && CSSindex > 0 &&
1.82 cvs 5410: CSSbuffer[CSSindex - 1] == '<')
5411: {
5412: /* this is the closing tag ! */
5413: CSSindex -= 2; /* remove </ from the CSS string */
5414: noRule = TRUE;
5415: }
5416: break;
5417: case '<':
1.135 vatton 5418: if (!quoted && CSScomment == MAX_CSS_LENGTH)
1.82 cvs 5419: {
5420: /* only if we're not parsing a comment */
5421: c = buffer[index++];
5422: eof = (c == EOS);
5423: if (c == '!')
5424: {
5425: /* CSS within an HTML comment */
5426: HTMLcomment = TRUE;
5427: CSSindex++;
5428: CSSbuffer[CSSindex] = c;
5429: }
5430: else if (c == EOS)
5431: CSSindex++;
5432: }
5433: break;
5434: case '-':
1.135 vatton 5435: if (!quoted && CSSindex > 0 && CSSbuffer[CSSindex - 1] == '-' &&
1.82 cvs 5436: HTMLcomment)
5437: /* CSS within an HTML comment */
5438: noRule = TRUE;
5439: break;
5440: case '>':
1.135 vatton 5441: if (!quoted && HTMLcomment)
1.82 cvs 5442: noRule = TRUE;
5443: break;
5444: case ' ':
1.135 vatton 5445: if (!quoted && import != MAX_CSS_LENGTH && openRule == 0)
1.162 quint 5446: media = !strncasecmp (&CSSbuffer[import+1], "media", 5);
1.82 cvs 5447: break;
5448: case '{':
1.135 vatton 5449: if (!quoted)
1.82 cvs 5450: {
1.135 vatton 5451: openRule++;
5452: if (import != MAX_CSS_LENGTH && openRule == 1 && media)
5453: {
5454: /* is it the screen concerned? */
5455: CSSbuffer[CSSindex+1] = EOS;
5456: if (TtaIsPrinting ())
5457: base = strstr (&CSSbuffer[import], "print");
5458: else
5459: base = strstr (&CSSbuffer[import], "screen");
5460: if (base == NULL)
5461: base = strstr (&CSSbuffer[import], "all");
5462: if (base == NULL)
5463: ignoreMedia = TRUE;
5464: noRule = TRUE;
5465: }
1.186 vatton 5466: else if (import != MAX_CSS_LENGTH &&
5467: !strncasecmp (&CSSbuffer[import], "@font-face", 10))
5468: skip = TRUE;
1.135 vatton 5469: }
5470: break;
5471: case '}':
5472: if (!quoted)
5473: {
5474: openRule--;
5475: if (import != MAX_CSS_LENGTH && openRule == 0)
5476: {
5477: import = MAX_CSS_LENGTH;
5478: noRule = TRUE;
5479: ignoreMedia = FALSE;
5480: media = FALSE;
5481: }
1.82 cvs 5482: else
1.135 vatton 5483: toParse = TRUE;
1.82 cvs 5484: }
5485: break;
1.135 vatton 5486: case '"':
5487: if (quoted)
1.82 cvs 5488: {
1.135 vatton 5489: if (CSSbuffer[CSSindex - 1] != '\\')
5490: quoted = FALSE;
1.82 cvs 5491: }
5492: else
1.135 vatton 5493: quoted = TRUE;
1.82 cvs 5494: break;
5495: default:
1.86 cvs 5496: if (c == EOL)
1.93 vatton 5497: newlines++;
1.82 cvs 5498: break;
5499: }
5500: }
1.93 vatton 5501: else if (c == EOL)
5502: LineNumber++;
1.82 cvs 5503: if (c != CR)
5504: CSSindex++;
5505:
5506: if (CSSindex >= MAX_CSS_LENGTH && CSScomment < MAX_CSS_LENGTH)
5507: /* we're still parsing a comment: remove the text comment */
5508: CSSindex = CSScomment;
5509:
5510: if (CSSindex >= MAX_CSS_LENGTH || toParse || noRule)
5511: {
5512: CSSbuffer[CSSindex] = EOS;
5513: /* parse a not empty string */
5514: if (CSSindex > 0)
5515: {
1.50 cvs 5516: /* apply CSS rule if it's not just a saving of text */
5517: if (!noRule && !ignoreMedia)
1.88 cvs 5518: {
5519: /* future import rules must be ignored */
5520: ignoreImport = TRUE;
1.173 cvs 5521: ParseStyleDeclaration (NULL, CSSbuffer, docRef, refcss, FALSE);
1.93 vatton 5522: LineNumber += newlines;
5523: newlines = 0;
5524: NewLineSkipped = 0;
1.88 cvs 5525: }
1.82 cvs 5526: else if (import != MAX_CSS_LENGTH &&
5527: !strncasecmp (&CSSbuffer[import+1], "import", 6))
5528: {
5529: /* import section */
5530: cssRule = &CSSbuffer[import+7];
5531: cssRule = TtaSkipBlanks (cssRule);
1.93 vatton 5532: /* save the current line number */
5533: newlines += LineNumber;
1.82 cvs 5534: if (!strncasecmp (cssRule, "url", 3))
5535: {
1.50 cvs 5536: cssRule = &cssRule[3];
1.82 cvs 5537: cssRule = TtaSkipBlanks (cssRule);
5538: if (*cssRule == '(')
5539: {
5540: cssRule++;
5541: cssRule = TtaSkipBlanks (cssRule);
1.102 vatton 5542: quoted = (*cssRule == '"' || *cssRule == '\'');
5543: if (quoted)
5544: cssRule++;
1.82 cvs 5545: base = cssRule;
5546: while (*cssRule != EOS && *cssRule != ')')
5547: cssRule++;
1.102 vatton 5548: if (quoted)
1.167 vatton 5549: {
5550: /* isolate the file name */
5551: cssRule[-1] = EOS;
5552: quoted = FALSE;
5553: }
1.160 vatton 5554: *cssRule = EOS;
1.82 cvs 5555: }
5556: }
1.87 cvs 5557: else if (*cssRule == '"')
5558: {
1.88 cvs 5559: /*
5560: Do we have to accept single quotes?
5561: Double quotes are acceted here.
5562: Escaped quotes are not handled. See function SkipQuotedString
5563: */
1.87 cvs 5564: cssRule++;
5565: cssRule = TtaSkipBlanks (cssRule);
5566: base = cssRule;
1.179 vatton 5567: while (*cssRule != EOS &&
5568: (*cssRule != '"' ||
1.180 vatton 5569: (*cssRule == '"' && cssRule[-1] == '\\')))
1.87 cvs 5570: cssRule++;
1.160 vatton 5571: /* isolate the file name */
5572: *cssRule = EOS;
1.133 vatton 5573: }
5574: /* check if a media is defined */
5575: cssRule++;
5576: cssRule = TtaSkipBlanks (cssRule);
5577: if (*cssRule != ';')
5578: {
5579: if (TtaIsPrinting ())
5580: ignoreImport = (strncasecmp (cssRule, "print", 5) &&
5581: strncasecmp (cssRule, "all", 3));
5582: else
5583: ignoreImport = (strncasecmp (cssRule, "screen", 6) &&
5584: strncasecmp (cssRule, "all", 3));
5585: }
5586: if (!ignoreImport)
5587: {
5588: /* save the displayed URL when an error is reported */
5589: saveDocURL = DocURL;
1.138 vatton 5590: ptr = TtaStrdup (base);
5591: /* get the CSS URI in UTF-8 */
5592: ptr = ReallocUTF8String (ptr, docRef);
1.133 vatton 5593: LoadStyleSheet (base, docRef, NULL, css,
5594: css->media[docRef],
5595: css->category == CSS_USER_STYLE);
5596: /* restore the displayed URL when an error is reported */
5597: DocURL = saveDocURL;
1.138 vatton 5598: TtaFreeMemory (ptr);
1.82 cvs 5599: }
1.93 vatton 5600: /* restore the number of lines */
5601: LineNumber = newlines;
5602: newlines = 0;
1.82 cvs 5603: import = MAX_CSS_LENGTH;
5604: }
1.93 vatton 5605:
1.82 cvs 5606: }
5607: toParse = FALSE;
5608: noRule = FALSE;
5609: CSSindex = 0;
1.50 cvs 5610: }
1.82 cvs 5611: }
1.6 cvs 5612: /* restore the display mode */
5613: if (dispMode == DisplayImmediately)
1.82 cvs 5614: TtaSetDisplayMode (docRef, dispMode);
1.86 cvs 5615:
5616: /* Prepare the context for style attributes */
5617: DocURL = DocumentURLs[docRef];
5618: LineNumber = -1;
1.1 cvs 5619: return (c);
5620: }
1.89 cvs 5621:
Webmaster