Annotation of Amaya/amaya/styleparser.c, revision 1.346
1.1 cvs 1: /*
2: *
1.312 quint 3: * (c) COPYRIGHT INRIA and W3C, 1996-2005
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:
1.302 quint 25: typedef struct _CSSImageCallbackBlock
1.1 cvs 26: {
1.207 vatton 27: Element el;
28: PSchema tsch;
29: CSSInfoPtr css;
30: PresentationContext ctxt;
1.302 quint 31: unsigned int ruleType;
1.1 cvs 32: }
1.302 quint 33: CSSImageCallbackBlock, *CSSImageCallbackPtr;
1.1 cvs 34:
35: #include "AHTURLTools_f.h"
36: #include "HTMLpresentation_f.h"
37: #include "HTMLimage_f.h"
38: #include "UIcss_f.h"
39: #include "css_f.h"
1.24 cvs 40: #include "fetchHTMLname_f.h"
1.91 cvs 41: #include "fetchXMLname_f.h"
1.1 cvs 42: #include "html2thot_f.h"
1.91 cvs 43: #include "init_f.h"
1.1 cvs 44: #include "styleparser_f.h"
45:
46: #define MAX_BUFFER_LENGTH 200
47: /*
48: * A PropertyParser is a function used to parse the
49: * description substring associated to a given style attribute
1.59 cvs 50: * e.g.: "red" for a color attribute or "12pt bold helvetica"
1.1 cvs 51: * for a font attribute.
52: */
1.79 cvs 53: typedef char *(*PropertyParser) (Element element,
1.327 vatton 54: PSchema tsch,
55: PresentationContext context,
56: char *cssRule,
57: CSSInfoPtr css,
58: ThotBool isHTML);
1.1 cvs 59:
60: /* Description of the set of CSS properties supported */
61: typedef struct CSSProperty
1.327 vatton 62: {
63: char *name;
64: PropertyParser parsing_function;
65: }
1.1 cvs 66: CSSProperty;
67:
1.86 cvs 68: static char *DocURL = NULL; /* The parsed CSS file */
69: static int LineNumber = -1; /* The line where the error occurs */
1.93 vatton 70: static int NewLineSkipped = 0;
1.311 vatton 71: static int RedisplayImages = 0; /* number of BG images loading */
72: static int RedisplayDoc = 0; /* document to be redisplayed */
73: static int Style_parsing = 0; /* > 0 when parsing a set of CSS rules */
1.310 vatton 74: static ThotBool RedisplayBGImage = FALSE; /* TRUE when a BG image is inserted */
1.116 vatton 75: static ThotBool DoApply = TRUE;
1.1 cvs 76:
77: /*----------------------------------------------------------------------
1.327 vatton 78: SkipWord:
1.1 cvs 79: ----------------------------------------------------------------------*/
1.79 cvs 80: static char *SkipWord (char *ptr)
1.1 cvs 81: {
1.168 vatton 82: while (isalnum((int)*ptr) || *ptr == '-' || *ptr == '#' || *ptr == '%')
83: ptr++;
1.1 cvs 84: return (ptr);
85: }
86:
87: /*----------------------------------------------------------------------
1.327 vatton 88: SkipBlanksAndComments:
1.13 cvs 89: ----------------------------------------------------------------------*/
1.82 cvs 90: char *SkipBlanksAndComments (char *ptr)
1.13 cvs 91: {
1.93 vatton 92: /* skip spaces */
1.155 cheyroul 93: while (*ptr == SPACE ||
1.327 vatton 94: *ptr == BSPACE ||
95: *ptr == EOL ||
96: *ptr == TAB ||
97: *ptr == __CR__)
1.93 vatton 98: {
99: if (*ptr == EOL)
1.327 vatton 100: /* increment the number of newline skipped */
101: NewLineSkipped++;
1.93 vatton 102: ptr++;
103: }
1.155 cheyroul 104: while (ptr[0] == '/' &&
1.327 vatton 105: ptr[1] == '*')
1.13 cvs 106: {
107: /* look for the end of the comment */
108: ptr = &ptr[2];
109: while (ptr[0] != EOS && (ptr[0] != '*' || ptr[1] != '/'))
1.327 vatton 110: ptr++;
1.13 cvs 111: if (ptr[0] != EOS)
1.327 vatton 112: ptr = &ptr[2];
1.93 vatton 113: /* skip spaces */
114: while (*ptr == SPACE || *ptr == BSPACE || *ptr == EOL ||
1.327 vatton 115: *ptr == TAB || *ptr == __CR__)
116: {
117: if (*ptr == EOL)
118: /* increment the number of newline skipped */
119: NewLineSkipped++;
120: ptr++;
121: }
1.13 cvs 122: }
123: return (ptr);
124: }
125:
1.49 cvs 126: /*----------------------------------------------------------------------
1.327 vatton 127: SkipQuotedString
1.1 cvs 128: ----------------------------------------------------------------------*/
1.79 cvs 129: static char *SkipQuotedString (char *ptr, char quote)
1.1 cvs 130: {
1.14 cvs 131: ThotBool stop;
1.1 cvs 132:
133: stop = FALSE;
134: while (!stop)
135: {
1.327 vatton 136: if (*ptr == quote)
137: {
138: ptr++;
139: stop = TRUE;
140: }
141: else if (*ptr == EOS)
142: stop = TRUE;
143: else if (*ptr == '\\')
144: /* escape character */
145: {
146: ptr++;
1.82 cvs 147: if ((*ptr >= '0' && *ptr <= '9') || (*ptr >= 'A' && *ptr <= 'F') ||
1.327 vatton 148: (*ptr >= 'a' && *ptr <= 'f'))
149: {
150: ptr++;
151: if ((*ptr >= '0' && *ptr <= '9') || (*ptr >= 'A' && *ptr <= 'F') ||
152: (*ptr >= 'a' && *ptr <= 'f'))
153: ptr++;
154: }
155: else
156: ptr++;
157: }
158: else
159: ptr++;
1.1 cvs 160: }
161: return (ptr);
162: }
163:
164: /*----------------------------------------------------------------------
1.327 vatton 165: CSSPrintError
166: print the error message msg on stderr.
167: When the line is 0 ask to expat the current line number
1.86 cvs 168: ----------------------------------------------------------------------*/
1.168 vatton 169: static void CSSPrintError (char *msg, char *value)
1.86 cvs 170: {
171: if (!TtaIsPrinting () && ParsedDoc > 0)
172: {
173: if (!ErrFile)
1.327 vatton 174: {
175: if (OpenParsingErrors (ParsedDoc) == FALSE)
176: return;
177: }
1.86 cvs 178:
1.308 vatton 179: /* check if a CSS error file shoulb be updated too */
180: if (ParsedCSS > 0 && !CSSErrFile)
1.327 vatton 181: OpenParsingErrors (ParsedCSS);
1.308 vatton 182:
1.133 vatton 183: if (DocURL)
1.327 vatton 184: {
185: fprintf (ErrFile, "\n*** Errors/warnings in %s\n", DocURL);
186: /* set to NULL as long as the CSS file doesn't change */
187: DocURL = NULL;
188: }
1.89 cvs 189: CSSErrorsFound = TRUE;
1.86 cvs 190: if (LineNumber < 0)
1.327 vatton 191: fprintf (ErrFile, " In style attribute, %s \"%s\"\n", msg, value);
1.86 cvs 192: else
1.327 vatton 193: {
194: fprintf (ErrFile, "@ line %d: %s \"%s\"\n",
195: LineNumber+NewLineSkipped, msg, value);
196: if (CSSErrFile)
197: fprintf (CSSErrFile, "@ line %d: %s \"%s\"\n",
198: LineNumber+NewLineSkipped, msg, value);
199: }
1.86 cvs 200: }
201: }
202:
1.168 vatton 203: /*----------------------------------------------------------------------
1.327 vatton 204: CSSParseError
205: print the error message msg on stderr.
206: When the line is 0 ask expat about the current line number
1.168 vatton 207: ----------------------------------------------------------------------*/
208: static void CSSParseError (char *msg, char *value, char *endvalue)
209: {
1.230 quint 210: char c = EOS;
1.168 vatton 211:
212: if (endvalue)
213: {
214: /* close the string here */
215: c = *endvalue;
216: *endvalue = EOS;
217: }
218: CSSPrintError (msg, value);
219: if (endvalue)
220: *endvalue = c;
221: }
222:
1.288 vatton 223: /*----------------------------------------------------------------------
1.342 vatton 224: SkipString move to the end of the string
225: ----------------------------------------------------------------------*/
226: static char *SkipString (char *ptr)
227: {
228: char c = *ptr;
229:
230: ptr++;
231: while (*ptr != EOS &&
232: (*ptr != c || (*ptr == c && ptr[-1] == '\\')))
233: ptr++;
234: return ptr;
235: }
236:
237: /*----------------------------------------------------------------------
1.327 vatton 238: CSSCheckEndValue
239: print an error message if another character is found
1.288 vatton 240: ----------------------------------------------------------------------*/
241: static char *CSSCheckEndValue (char *cssRule, char *endvalue, char *msg)
242: {
243: char c = EOS;
244: if (*endvalue != EOS && *endvalue != SPACE && *endvalue != '/' &&
1.316 quint 245: *endvalue != ';' && *endvalue != '}' && *endvalue != EOL &&
246: *endvalue != TAB && *endvalue != __CR__)
1.288 vatton 247: {
248: while (*endvalue != EOS && *endvalue != SPACE && *endvalue != '/' &&
1.327 vatton 249: *endvalue != ';' && *endvalue != '}' && *endvalue != EOL &&
250: *endvalue != TAB && *endvalue != __CR__)
1.342 vatton 251: {
252: if (*endvalue == '"' || *endvalue == '\'')
253: endvalue = SkipString (endvalue);
254: if (*endvalue != EOS)
255: endvalue++;
256: }
1.288 vatton 257: /* close the string here */
258: c = *endvalue;
259: *endvalue = EOS;
260: CSSPrintError (msg, cssRule);
261: *endvalue = c;
262: }
263: return endvalue;
264: }
265:
1.89 cvs 266:
1.86 cvs 267: /*----------------------------------------------------------------------
1.327 vatton 268: SkipProperty skips a property and display and error message
1.86 cvs 269: ----------------------------------------------------------------------*/
1.234 vatton 270: static char *SkipProperty (char *ptr, ThotBool reportError)
1.86 cvs 271: {
272: char *deb;
273: char c;
274:
275: deb = ptr;
1.301 vatton 276: while (*ptr != EOS && *ptr != ';' && *ptr != '}' && *ptr != '}')
1.133 vatton 277: {
1.342 vatton 278: if (*ptr == '"' || *ptr == '\'')
279: ptr = SkipString (ptr);
280: if (*ptr != EOS)
281: ptr++;
1.133 vatton 282: }
1.95 cvs 283: /* print the skipped property */
1.86 cvs 284: c = *ptr;
285: *ptr = EOS;
1.234 vatton 286: if (reportError && *deb != EOS &&
1.342 vatton 287: strncasecmp (deb, "azimuth", 7) &&
1.259 vatton 288: strncasecmp (deb, "border-collapse", 15) &&
1.234 vatton 289: strncasecmp (deb, "border-spacing", 14) &&
290: strncasecmp (deb, "caption-side", 12) &&
291: strncasecmp (deb, "clip", 4) &&
292: strncasecmp (deb, "counter-increment", 16) &&
293: strncasecmp (deb, "counter-reset", 13) &&
1.342 vatton 294: strncasecmp (deb, "cue-after", 9) &&
295: strncasecmp (deb, "cue-before", 10) &&
296: strncasecmp (deb, "cue", 3) &&
1.234 vatton 297: strncasecmp (deb, "cursor", 6) &&
1.342 vatton 298: strncasecmp (deb, "elevation", 9) &&
1.234 vatton 299: strncasecmp (deb, "empty-cells", 11) &&
1.259 vatton 300: strncasecmp (deb, "font-strech", 11) &&
1.234 vatton 301: strncasecmp (deb, "letter-spacing", 14) &&
1.242 vatton 302: strncasecmp (deb, "marker-offset", 12) &&
1.234 vatton 303: strncasecmp (deb, "max-height", 10) &&
304: strncasecmp (deb, "max-width", 9) &&
305: strncasecmp (deb, "min-height", 10) &&
306: strncasecmp (deb, "min-width", 9) &&
307: strncasecmp (deb, "orphans", 7) &&
308: strncasecmp (deb, "outline-color", 13) &&
309: strncasecmp (deb, "outline-style", 13) &&
310: strncasecmp (deb, "outline-width", 13) &&
311: strncasecmp (deb, "outline", 7) &&
312: strncasecmp (deb, "overflow", 8) &&
1.342 vatton 313: strncasecmp (deb, "pause-after", 11) &&
314: strncasecmp (deb, "pause-before", 12) &&
315: strncasecmp (deb, "pause", 5) &&
1.234 vatton 316: strncasecmp (deb, "quotes", 6) &&
1.342 vatton 317: strncasecmp (deb, "richness", 8) &&
318: strncasecmp (deb, "speech-rate", 11) &&
319: strncasecmp (deb, "speak-header", 12) &&
320: strncasecmp (deb, "speak-punctuation", 17) &&
321: strncasecmp (deb, "speak-numeral", 13) &&
322: strncasecmp (deb, "speak", 5) &&
323: strncasecmp (deb, "pitch-range", 11) &&
324: strncasecmp (deb, "pitch", 5) &&
325: strncasecmp (deb, "stress", 6) &&
1.234 vatton 326: strncasecmp (deb, "table-layout", 12) &&
1.259 vatton 327: strncasecmp (deb, "text-shadow", 11) &&
1.342 vatton 328: strncasecmp (deb, "voice-family", 12) &&
329: strncasecmp (deb, "volume", 6) &&
1.258 vatton 330: strncasecmp (deb, "widows", 6))
1.205 quint 331: CSSPrintError ("CSS property ignored:", deb);
1.86 cvs 332: *ptr = c;
333: return (ptr);
334: }
335:
336: /*----------------------------------------------------------------------
1.327 vatton 337: SkipValue
338: skips the value and display an error message if msg is not NULL
1.1 cvs 339: ----------------------------------------------------------------------*/
1.168 vatton 340: static char *SkipValue (char *msg, char *ptr)
1.1 cvs 341: {
1.86 cvs 342: char *deb;
343: char c;
344:
345: deb = ptr;
1.338 vatton 346: while (*ptr != EOS && *ptr != ';' && *ptr != '}' && *ptr != '}' && *ptr != '\n')
1.133 vatton 347: {
1.342 vatton 348: if (*ptr == '"' || *ptr == '\'')
349: ptr = SkipString (ptr);
350: if (*ptr != EOS)
351: ptr++;
1.133 vatton 352: }
1.95 cvs 353: /* print the skipped property */
1.86 cvs 354: c = *ptr;
355: *ptr = EOS;
1.168 vatton 356: if (msg && *deb != EOS && *deb != ',')
357: CSSPrintError (msg, deb);
1.86 cvs 358: *ptr = c;
1.1 cvs 359: return (ptr);
360: }
361:
362: /*----------------------------------------------------------------------
1.327 vatton 363: ParseNumber:
364: parse a number and returns the corresponding value.
1.1 cvs 365: ----------------------------------------------------------------------*/
1.79 cvs 366: char *ParseNumber (char *cssRule, PresentationValue *pval)
1.1 cvs 367: {
368: int val = 0;
369: int minus = 0;
370: int valid = 0;
371: int f = 0;
1.14 cvs 372: ThotBool real = FALSE;
1.1 cvs 373:
1.184 vatton 374: pval->typed_data.unit = UNIT_REL;
1.1 cvs 375: pval->typed_data.real = FALSE;
1.82 cvs 376: cssRule = SkipBlanksAndComments (cssRule);
377: if (*cssRule == '-')
1.1 cvs 378: {
379: minus = 1;
380: cssRule++;
1.82 cvs 381: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 382: }
383:
1.82 cvs 384: if (*cssRule == '+')
1.1 cvs 385: {
386: cssRule++;
1.82 cvs 387: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 388: }
389:
1.82 cvs 390: while ((*cssRule >= '0') && (*cssRule <= '9'))
1.1 cvs 391: {
392: val *= 10;
1.82 cvs 393: val += *cssRule - '0';
1.1 cvs 394: cssRule++;
395: valid = 1;
396: }
397:
1.82 cvs 398: if (*cssRule == '.')
1.1 cvs 399: {
400: real = TRUE;
401: f = val;
402: val = 0;
403: cssRule++;
404: /* keep only 3 digits */
1.82 cvs 405: if (*cssRule >= '0' && *cssRule <= '9')
1.327 vatton 406: {
407: val = (*cssRule - '0') * 100;
408: cssRule++;
409: if (*cssRule >= '0' && *cssRule <= '9')
410: {
411: val += (*cssRule - '0') * 10;
412: cssRule++;
413: if ((*cssRule >= '0') && (*cssRule <= '9'))
414: {
415: val += *cssRule - '0';
416: cssRule++;
417: }
418: }
419:
420: while (*cssRule >= '0' && *cssRule <= '9')
421: cssRule++;
422: valid = 1;
423: }
1.1 cvs 424: }
425:
426: if (!valid)
427: {
1.184 vatton 428: pval->typed_data.unit = UNIT_INVALID;
1.1 cvs 429: pval->typed_data.value = 0;
430: }
431: else
432: {
433: pval->typed_data.real = real;
434: if (real)
1.327 vatton 435: {
436: if (minus)
437: pval->typed_data.value = -(f * 1000 + val);
438: else
439: pval->typed_data.value = f * 1000 + val;
440: }
1.1 cvs 441: else
1.327 vatton 442: {
443: if (minus)
444: pval->typed_data.value = -val;
445: else
446: pval->typed_data.value = val;
447: }
1.64 cvs 448: }
449: return (cssRule);
450: }
1.195 vatton 451:
1.155 cheyroul 452: /*----------------------------------------------------------------------
1.327 vatton 453: ParseCSSUnit:
454: parse a CSS Unit substring and returns the corresponding
455: value and its unit.
1.64 cvs 456: ----------------------------------------------------------------------*/
1.82 cvs 457: char *ParseCSSUnit (char *cssRule, PresentationValue *pval)
1.64 cvs 458: {
459: unsigned int uni;
460:
1.184 vatton 461: pval->typed_data.unit = UNIT_REL;
1.64 cvs 462: cssRule = ParseNumber (cssRule, pval);
1.184 vatton 463: if (pval->typed_data.unit == UNIT_INVALID)
1.327 vatton 464: cssRule = SkipWord (cssRule);
1.64 cvs 465: else
466: {
1.82 cvs 467: cssRule = SkipBlanksAndComments (cssRule);
1.231 vatton 468: uni = 0;
469: while (CSSUnitNames[uni].sign)
1.327 vatton 470: {
471: if (!strncasecmp (CSSUnitNames[uni].sign, cssRule,
472: strlen (CSSUnitNames[uni].sign)))
473: {
474: pval->typed_data.unit = CSSUnitNames[uni].unit;
475: return (cssRule + strlen (CSSUnitNames[uni].sign));
476: }
477: else
478: uni++;
479: }
1.64 cvs 480: /* not in the list of predefined units */
1.184 vatton 481: pval->typed_data.unit = UNIT_BOX;
1.1 cvs 482: }
483: return (cssRule);
484: }
485:
1.43 cvs 486: /*----------------------------------------------------------------------
1.327 vatton 487: ParseClampedUnit:
488: parse a CSS Unit substring and returns the corresponding value and unit.
489: [0,1]
1.239 vatton 490: ----------------------------------------------------------------------*/
491: char *ParseClampedUnit (char *cssRule, PresentationValue *pval)
492: {
1.251 vatton 493: char *p;
494:
495: p = cssRule;
1.239 vatton 496: cssRule = ParseNumber (cssRule, pval);
1.301 vatton 497: if (*cssRule != EOS && *cssRule != SPACE && *cssRule != ';' && *cssRule != '}')
1.239 vatton 498: {
1.251 vatton 499: cssRule++;
1.239 vatton 500: pval->typed_data.unit = UNIT_REL;
501: if (pval->typed_data.value > 100)
1.327 vatton 502: pval->typed_data.value = 1000;
1.239 vatton 503: else
1.327 vatton 504: pval->typed_data.value *= 10;
1.251 vatton 505: CSSParseError ("Invalid value", p, cssRule);
1.239 vatton 506: }
507: else
508: {
509: pval->typed_data.unit = UNIT_REL;
510: if (pval->typed_data.real)
1.327 vatton 511: pval->typed_data.real = FALSE;
1.239 vatton 512: else if (pval->typed_data.value > 1)
1.327 vatton 513: {
514: pval->typed_data.value = 1000;
515: CSSParseError ("Invalid value", p, cssRule);
516: }
1.251 vatton 517: else if (pval->typed_data.value < 0)
1.327 vatton 518: {
519: pval->typed_data.value = 0;
520: CSSParseError ("Invalid value", p, cssRule);
521: }
1.239 vatton 522: else
1.327 vatton 523: pval->typed_data.value *= 1000;
1.239 vatton 524: }
525: pval->data = pval->typed_data.value;
526: return (cssRule);
527: }
528:
529:
530: /*----------------------------------------------------------------------
1.327 vatton 531: ParseABorderValue
1.43 cvs 532: ----------------------------------------------------------------------*/
1.288 vatton 533: static char *ParseABorderValue (char *cssRule, PresentationValue *border)
1.43 cvs 534: {
1.288 vatton 535: char *ptr = cssRule;
1.168 vatton 536:
1.43 cvs 537: /* first parse the attribute string */
1.319 quint 538: border->typed_data.value = 0;
539: border->typed_data.unit = UNIT_INVALID;
540: border->typed_data.real = FALSE;
541: if (!strncasecmp (cssRule, "thin", 4))
542: {
543: border->typed_data.unit = UNIT_PX;
544: border->typed_data.value = 1;
545: cssRule += 4;
546: }
547: else if (!strncasecmp (cssRule, "medium", 6))
548: {
549: border->typed_data.unit = UNIT_PX;
550: border->typed_data.value = 3;
551: cssRule += 6;
552: }
553: else if (!strncasecmp (cssRule, "thick", 5))
554: {
555: border->typed_data.unit = UNIT_PX;
556: border->typed_data.value = 5;
557: cssRule += 5;
558: }
559: else if (!strncasecmp (cssRule, "inherit", 7))
560: {
561: border->typed_data.unit = VALUE_INHERIT;
562: cssRule += 7;
563: }
564: else if (isdigit (*cssRule) || *cssRule == '.')
565: {
566: cssRule = ParseCSSUnit (cssRule, border);
567: if (border->typed_data.value == 0)
1.327 vatton 568: border->typed_data.unit = UNIT_PX;
1.319 quint 569: else if (border->typed_data.unit == UNIT_INVALID ||
1.327 vatton 570: border->typed_data.unit == UNIT_BOX ||
571: border->typed_data.unit == UNIT_PERCENT)
572: {
573: border->typed_data.unit = UNIT_INVALID;
574: border->typed_data.value = 0;
575: CSSParseError ("Invalid border-width value", ptr, cssRule);
576: }
1.319 quint 577: }
578: return (cssRule);
1.43 cvs 579: }
580:
1.288 vatton 581:
582: /*----------------------------------------------------------------------
1.327 vatton 583: ParseBorderStyle
1.43 cvs 584: ----------------------------------------------------------------------*/
1.79 cvs 585: static char *ParseBorderStyle (char *cssRule, PresentationValue *border)
1.43 cvs 586: {
587: /* first parse the attribute string */
1.327 vatton 588: border->typed_data.value = 0;
589: border->typed_data.unit = UNIT_PX;
590: border->typed_data.real = FALSE;
591: if (!strncasecmp (cssRule, "none", 4))
592: {
593: border->typed_data.value = BorderStyleNone;
594: cssRule += 4;
595: }
596: else if (!strncasecmp (cssRule, "hidden", 6))
597: {
598: border->typed_data.value = BorderStyleHidden;
599: cssRule += 6;
600: }
601: else if (!strncasecmp (cssRule, "dotted", 6))
602: {
1.288 vatton 603: cssRule += 6;
1.327 vatton 604: border->typed_data.value = BorderStyleDotted;
1.288 vatton 605: }
1.327 vatton 606: else if (!strncasecmp (cssRule, "dashed", 6))
607: {
608: border->typed_data.value = BorderStyleDashed;
609: cssRule += 6;
610: }
611: else if (!strncasecmp (cssRule, "solid", 5))
612: {
613: border->typed_data.value = BorderStyleSolid;
614: cssRule += 5;
615: }
616: else if (!strncasecmp (cssRule, "double", 6))
617: {
618: border->typed_data.value = BorderStyleDouble;
619: cssRule += 6;
620: }
621: else if (!strncasecmp (cssRule, "groove", 6))
622: {
623: border->typed_data.value = BorderStyleGroove;
624: cssRule += 6;
625: }
626: else if (!strncasecmp (cssRule, "ridge", 5))
627: {
628: border->typed_data.value = BorderStyleRidge;
629: cssRule += 5;
630: }
631: else if (!strncasecmp (cssRule, "inset", 5))
632: {
633: border->typed_data.value = BorderStyleInset;
634: cssRule += 5;
635: }
636: else if (!strncasecmp (cssRule, "outset", 6))
637: {
638: border->typed_data.value = BorderStyleOutset;
639: cssRule += 6;
640: }
641: else
642: {
643: /* invalid style */
644: border->typed_data.unit = UNIT_INVALID;
645: return (cssRule);
646: }
647: return (cssRule);
1.43 cvs 648: }
649:
650: /*----------------------------------------------------------------------
1.327 vatton 651: ParseCSSColor: parse a CSS color attribute string
652: we expect the input string describing the attribute to be
653: either a color name, a 3 tuple or an hexadecimal encoding.
654: The color used will be approximed from the current color
655: table
1.43 cvs 656: ----------------------------------------------------------------------*/
1.79 cvs 657: static char *ParseCSSColor (char *cssRule, PresentationValue * val)
1.43 cvs 658: {
1.79 cvs 659: char *ptr;
1.43 cvs 660: unsigned short redval = (unsigned short) -1;
661: unsigned short greenval = 0; /* composant of each RGB */
662: unsigned short blueval = 0; /* default to red if unknown ! */
663: int best = 0; /* best color in list found */
664:
1.82 cvs 665: cssRule = SkipBlanksAndComments (cssRule);
1.184 vatton 666: val->typed_data.unit = UNIT_INVALID;
1.43 cvs 667: val->typed_data.real = FALSE;
668: val->typed_data.value = 0;
1.57 cvs 669: ptr = TtaGiveRGB (cssRule, &redval, &greenval, &blueval);
1.292 vatton 670: if (!strncasecmp (cssRule, "InactiveCaptionText", 19))
671: {
672: cssRule += 19;
673: }
674: else if (!strncasecmp (cssRule, "ThreeDLightShadow", 17))
675: {
676: cssRule += 17;
677: }
678: else if (!strncasecmp (cssRule, "ThreeDDarkShadow", 16))
679: {
680: cssRule += 16;
681: }
682: else if (!strncasecmp (cssRule, "ButtonHighlight", 15) ||
1.327 vatton 683: !strncasecmp (cssRule, "InactiveCaption", 15) ||
684: !strncasecmp (cssRule, "ThreeDHighlight", 15))
1.292 vatton 685: {
686: cssRule += 15;
687: }
688: else if (!strncasecmp (cssRule, "InactiveBorder", 14) ||
1.327 vatton 689: !strncasecmp (cssRule, "InfoBackground", 14))
1.292 vatton 690: {
691: cssRule += 14;
692: }
693: else if (!strncasecmp (cssRule, "ActiveCaption", 13) ||
1.327 vatton 694: !strncasecmp (cssRule, "HighlightText", 13))
1.292 vatton 695: {
696: cssRule += 13;
697: }
698: else if (!strncasecmp (cssRule, "ActiveBorder", 12) ||
1.327 vatton 699: !strncasecmp (cssRule, "AppWorkspace", 12) ||
700: !strncasecmp (cssRule, "ButtonShadow", 12) ||
701: !strncasecmp (cssRule, "ThreeDShadow", 12))
1.292 vatton 702: {
703: cssRule += 12;
704: }
705: else if (!strncasecmp (cssRule, "CaptionText", 11) ||
1.327 vatton 706: !strncasecmp (cssRule, "WindowFrame", 11))
1.292 vatton 707: {
708: cssRule += 11;
709: }
710: else if (!strncasecmp (cssRule, "Background", 10) ||
1.327 vatton 711: !strncasecmp (cssRule, "ButtonFace", 10) ||
712: !strncasecmp (cssRule, "ButtonText", 10) ||
713: !strncasecmp (cssRule, "ThreeDFace", 10) ||
714: !strncasecmp (cssRule, "WindowText", 10))
1.292 vatton 715: {
716: cssRule += 10;
717: }
718: else if (!strncasecmp (cssRule, "Highlight", 9) ||
1.327 vatton 719: !strncasecmp (cssRule, "Scrollbar", 9))
1.292 vatton 720: {
721: cssRule += 9;
722: }
723: else if (!strncasecmp (cssRule, "GrayText", 8) ||
1.327 vatton 724: !strncasecmp (cssRule, "InfoText", 8) ||
725: !strncasecmp (cssRule, "MenuText", 8))
1.292 vatton 726: {
727: cssRule += 8;
728: }
729: else if (!strncasecmp (cssRule, "Window", 6))
730: {
731: cssRule += 6;
732: }
733: else if (!strncasecmp (cssRule, "Menu", 5))
734: {
735: cssRule += 5;
736: }
1.293 quint 737: else if (!strncasecmp (cssRule, "inherit", 7))
738: {
739: val->typed_data.unit = VALUE_INHERIT;
740: cssRule += 7;
741: }
1.292 vatton 742:
1.57 cvs 743: if (ptr == cssRule)
1.43 cvs 744: {
1.168 vatton 745: cssRule = SkipWord (cssRule);
746: CSSParseError ("Invalid color value", ptr, cssRule);
1.43 cvs 747: val->typed_data.value = 0;
1.184 vatton 748: val->typed_data.unit = UNIT_INVALID;
1.43 cvs 749: }
1.293 quint 750: else if (val->typed_data.unit != VALUE_INHERIT)
1.43 cvs 751: {
752: best = TtaGetThotColor (redval, greenval, blueval);
753: val->typed_data.value = best;
1.184 vatton 754: val->typed_data.unit = UNIT_REL;
1.57 cvs 755: cssRule = ptr;
1.43 cvs 756: }
757: val->typed_data.real = FALSE;
1.262 vatton 758: cssRule = SkipBlanksAndComments (cssRule);
1.65 cvs 759: return (cssRule);
1.43 cvs 760: }
1.1 cvs 761:
762: /*----------------------------------------------------------------------
1.231 vatton 763: CheckImportantRule updates the field important of the context and
764: the line number.
1.117 vatton 765: ----------------------------------------------------------------------*/
766: static char *CheckImportantRule (char *cssRule, PresentationContext context)
767: {
1.276 vatton 768: PresentationContextBlock dummyctxt;
769:
770: if (context == NULL)
771: /* no context provided */
772: context = &dummyctxt;
773:
1.117 vatton 774: cssRule = SkipBlanksAndComments (cssRule);
1.231 vatton 775: /* update the line number */
776: context->cssLine = LineNumber + NewLineSkipped;
1.120 vatton 777: if (*cssRule != '!')
778: context->important = FALSE;
779: else
1.117 vatton 780: {
1.120 vatton 781: cssRule++;
782: cssRule = SkipBlanksAndComments (cssRule);
783: if (!strncasecmp (cssRule, "important", 9))
1.327 vatton 784: {
785: context->important = TRUE;
786: cssRule += 9;
787: }
1.120 vatton 788: else
1.327 vatton 789: context->important = FALSE;
1.117 vatton 790: }
791: return (cssRule);
792: }
793:
794: /*----------------------------------------------------------------------
1.327 vatton 795: ParseCSSBorderTopWidth: parse a CSS BorderTopWidth
796: attribute string.
1.1 cvs 797: ----------------------------------------------------------------------*/
1.79 cvs 798: static char *ParseCSSBorderTopWidth (Element element, PSchema tsch,
1.327 vatton 799: PresentationContext context,
800: char *cssRule, CSSInfoPtr css,
801: ThotBool isHTML)
1.1 cvs 802: {
1.41 cvs 803: PresentationValue border;
804:
1.82 cvs 805: cssRule = SkipBlanksAndComments (cssRule);
1.288 vatton 806: cssRule = ParseABorderValue (cssRule, &border);
1.295 vatton 807: /* check if it's an important rule */
808: cssRule = CheckImportantRule (cssRule, context);
1.184 vatton 809: if (border.typed_data.unit != UNIT_INVALID && DoApply)
1.44 cvs 810: {
811: TtaSetStylePresentation (PRBorderTopWidth, element, tsch, context, border);
812: border.typed_data.value = 1;
1.184 vatton 813: border.typed_data.unit = UNIT_REL;
1.44 cvs 814: }
1.1 cvs 815: return (cssRule);
816: }
817:
818: /*----------------------------------------------------------------------
1.327 vatton 819: ParseCSSBorderBottomWidth: parse a CSS BorderBottomWidth
820: attribute string.
1.1 cvs 821: ----------------------------------------------------------------------*/
1.79 cvs 822: static char *ParseCSSBorderBottomWidth (Element element, PSchema tsch,
1.327 vatton 823: PresentationContext context,
824: char *cssRule, CSSInfoPtr css,
825: ThotBool isHTML)
1.1 cvs 826: {
1.41 cvs 827: PresentationValue border;
828:
1.82 cvs 829: cssRule = SkipBlanksAndComments (cssRule);
1.41 cvs 830: /* first parse the attribute string */
1.288 vatton 831: cssRule = ParseABorderValue (cssRule, &border);
1.295 vatton 832: /* check if it's an important rule */
833: cssRule = CheckImportantRule (cssRule, context);
1.184 vatton 834: if (border.typed_data.unit != UNIT_INVALID && DoApply)
1.44 cvs 835: {
836: TtaSetStylePresentation (PRBorderBottomWidth, element, tsch, context, border);
837: border.typed_data.value = 1;
1.184 vatton 838: border.typed_data.unit = UNIT_REL;
1.44 cvs 839: }
1.1 cvs 840: return (cssRule);
841: }
842:
843: /*----------------------------------------------------------------------
1.327 vatton 844: ParseCSSBorderLeftWidth: parse a CSS BorderLeftWidth
845: attribute string.
1.1 cvs 846: ----------------------------------------------------------------------*/
1.79 cvs 847: static char *ParseCSSBorderLeftWidth (Element element, PSchema tsch,
1.327 vatton 848: PresentationContext context,
849: char *cssRule, CSSInfoPtr css,
850: ThotBool isHTML)
1.1 cvs 851: {
1.41 cvs 852: PresentationValue border;
853:
1.82 cvs 854: cssRule = SkipBlanksAndComments (cssRule);
1.41 cvs 855: /* first parse the attribute string */
1.288 vatton 856: cssRule = ParseABorderValue (cssRule, &border);
1.295 vatton 857: /* check if it's an important rule */
858: cssRule = CheckImportantRule (cssRule, context);
1.184 vatton 859: if (border.typed_data.unit != UNIT_INVALID && DoApply)
1.44 cvs 860: {
861: TtaSetStylePresentation (PRBorderLeftWidth, element, tsch, context, border);
862: border.typed_data.value = 1;
1.184 vatton 863: border.typed_data.unit = UNIT_REL;
1.44 cvs 864: }
1.1 cvs 865: return (cssRule);
866: }
867:
868: /*----------------------------------------------------------------------
1.327 vatton 869: ParseCSSBorderRightWidth: parse a CSS BorderRightWidth
870: attribute string.
1.1 cvs 871: ----------------------------------------------------------------------*/
1.79 cvs 872: static char *ParseCSSBorderRightWidth (Element element, PSchema tsch,
1.327 vatton 873: PresentationContext context,
874: char *cssRule, CSSInfoPtr css,
875: ThotBool isHTML)
1.1 cvs 876: {
1.41 cvs 877: PresentationValue border;
878:
1.82 cvs 879: cssRule = SkipBlanksAndComments (cssRule);
1.41 cvs 880: /* first parse the attribute string */
1.288 vatton 881: cssRule = ParseABorderValue (cssRule, &border);
1.295 vatton 882: /* check if it's an important rule */
883: cssRule = CheckImportantRule (cssRule, context);
1.184 vatton 884: if (border.typed_data.unit != UNIT_INVALID && DoApply)
1.44 cvs 885: {
886: TtaSetStylePresentation (PRBorderRightWidth, element, tsch, context, border);
887: border.typed_data.value = 1;
1.184 vatton 888: border.typed_data.unit = UNIT_REL;
1.44 cvs 889: }
1.1 cvs 890: return (cssRule);
891: }
892:
893: /*----------------------------------------------------------------------
1.327 vatton 894: ParseCSSBorderWidth: parse a CSS BorderWidth
895: attribute string.
1.1 cvs 896: ----------------------------------------------------------------------*/
1.79 cvs 897: static char *ParseCSSBorderWidth (Element element, PSchema tsch,
1.327 vatton 898: PresentationContext context,
899: char *cssRule, CSSInfoPtr css,
900: ThotBool isHTML)
1.1 cvs 901: {
1.79 cvs 902: char *ptrT, *ptrR, *ptrB, *ptrL;
1.93 vatton 903: int skippedNL;
1.41 cvs 904:
1.82 cvs 905: ptrT = SkipBlanksAndComments (cssRule);
1.42 cvs 906: /* First parse Border-Top */
907: ptrR = ParseCSSBorderTopWidth (element, tsch, context, ptrT, css, isHTML);
1.82 cvs 908: ptrR = SkipBlanksAndComments (ptrR);
1.301 vatton 909: if (*ptrR == ';' || *ptrR == '}' || *ptrR == EOS || *ptrR == ',')
1.42 cvs 910: {
1.93 vatton 911: skippedNL = NewLineSkipped;
1.42 cvs 912: cssRule = ptrR;
913: /* apply the Border-Top to all */
914: ptrR = ParseCSSBorderRightWidth (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 915: NewLineSkipped = skippedNL;
1.42 cvs 916: ptrR = ParseCSSBorderBottomWidth (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 917: NewLineSkipped = skippedNL;
1.42 cvs 918: ptrR = ParseCSSBorderLeftWidth (element, tsch, context, ptrT, css, isHTML);
919: }
920: else
921: {
922: /* parse Border-Right */
923: ptrB = ParseCSSBorderRightWidth (element, tsch, context, ptrR, css, isHTML);
1.82 cvs 924: ptrB = SkipBlanksAndComments (ptrB);
1.301 vatton 925: if (*ptrB == ';' || *ptrB == '}' || *ptrB == EOS || *ptrB == ',')
1.327 vatton 926: {
927: skippedNL = NewLineSkipped;
928: cssRule = ptrB;
929: /* apply the Border-Top to Border-Bottom */
930: ptrB = ParseCSSBorderBottomWidth (element, tsch, context, ptrT, css, isHTML);
931: NewLineSkipped = skippedNL;
932: /* apply the Border-Right to Border-Left */
933: ptrB = ParseCSSBorderLeftWidth (element, tsch, context, ptrR, css, isHTML);
934: }
1.42 cvs 935: else
1.327 vatton 936: {
937: /* parse Border-Bottom */
938: ptrL = ParseCSSBorderBottomWidth (element, tsch, context, ptrB, css, isHTML);
939: ptrL = SkipBlanksAndComments (ptrL);
940: if (*ptrL == ';' || *ptrL == '}' || *ptrL == EOS || *ptrL == ',')
941: {
942: cssRule = ptrL;
943: /* apply the Border-Right to Border-Left */
944: ptrL = ParseCSSBorderLeftWidth (element, tsch, context, ptrR, css, isHTML);
945: }
946: else
947: /* parse Border-Left */
948: cssRule = ParseCSSBorderLeftWidth (element, tsch, context, ptrL, css, isHTML);
949: cssRule = SkipBlanksAndComments (cssRule);
950: }
1.42 cvs 951: }
1.1 cvs 952: return (cssRule);
953: }
954:
955: /*----------------------------------------------------------------------
1.327 vatton 956: ParseCSSBorderColorTop: parse a CSS BorderColorTop
957: attribute string.
1.1 cvs 958: ----------------------------------------------------------------------*/
1.79 cvs 959: static char *ParseCSSBorderColorTop (Element element, PSchema tsch,
1.327 vatton 960: PresentationContext context,
961: char *cssRule, CSSInfoPtr css,
962: ThotBool isHTML)
1.1 cvs 963: {
1.117 vatton 964: PresentationValue best;
1.43 cvs 965:
1.234 vatton 966: if (!strncasecmp (cssRule, "transparent", 11))
967: {
968: best.typed_data.value = -2; /* -2 means transparent */
969: best.typed_data.unit = UNIT_REL;
970: cssRule = SkipWord (cssRule);
971: }
972: else
973: cssRule = ParseCSSColor (cssRule, &best);
1.295 vatton 974: /* check if it's an important rule */
975: cssRule = CheckImportantRule (cssRule, context);
1.184 vatton 976: if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.117 vatton 977: {
978: /* install the new presentation */
979: TtaSetStylePresentation (PRBorderTopColor, element, tsch, context, best);
980: }
981: return (cssRule);
1.1 cvs 982: }
983:
984: /*----------------------------------------------------------------------
1.327 vatton 985: ParseCSSBorderColorLeft: parse a CSS BorderColorLeft
986: attribute string.
1.42 cvs 987: ----------------------------------------------------------------------*/
1.79 cvs 988: static char *ParseCSSBorderColorLeft (Element element, PSchema tsch,
1.327 vatton 989: PresentationContext context,
990: char *cssRule, CSSInfoPtr css,
991: ThotBool isHTML)
1.42 cvs 992: {
1.117 vatton 993: PresentationValue best;
994:
1.234 vatton 995: if (!strncasecmp (cssRule, "transparent", 11))
996: {
997: best.typed_data.value = -2; /* -2 means transparent */
998: best.typed_data.unit = UNIT_REL;
999: cssRule = SkipWord (cssRule);
1000: }
1001: else
1002: cssRule = ParseCSSColor (cssRule, &best);
1.295 vatton 1003: /* check if it's an important rule */
1004: cssRule = CheckImportantRule (cssRule, context);
1.184 vatton 1005: if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.117 vatton 1006: {
1007: /* install the new presentation */
1008: TtaSetStylePresentation (PRBorderLeftColor, element, tsch, context, best);
1009: }
1010: return (cssRule);
1.42 cvs 1011: }
1012:
1013: /*----------------------------------------------------------------------
1.327 vatton 1014: ParseCSSBorderColorBottom: parse a CSS BorderColorBottom
1015: attribute string.
1.42 cvs 1016: ----------------------------------------------------------------------*/
1.79 cvs 1017: static char *ParseCSSBorderColorBottom (Element element, PSchema tsch,
1.327 vatton 1018: PresentationContext context,
1019: char *cssRule, CSSInfoPtr css,
1020: ThotBool isHTML)
1.42 cvs 1021: {
1.117 vatton 1022: PresentationValue best;
1.43 cvs 1023:
1.234 vatton 1024: if (!strncasecmp (cssRule, "transparent", 11))
1025: {
1026: best.typed_data.value = -2; /* -2 means transparent */
1027: best.typed_data.unit = UNIT_REL;
1028: cssRule = SkipWord (cssRule);
1029: }
1030: else
1031: cssRule = ParseCSSColor (cssRule, &best);
1.295 vatton 1032: /* check if it's an important rule */
1033: cssRule = CheckImportantRule (cssRule, context);
1.184 vatton 1034: if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.117 vatton 1035: {
1036: /* install the new presentation */
1037: TtaSetStylePresentation (PRBorderBottomColor, element, tsch, context, best);
1038: }
1.327 vatton 1039: return (cssRule);
1.42 cvs 1040: }
1041:
1042: /*----------------------------------------------------------------------
1.327 vatton 1043: ParseCSSBorderColorRight: parse a CSS BorderColorRight
1044: attribute string.
1.1 cvs 1045: ----------------------------------------------------------------------*/
1.79 cvs 1046: static char *ParseCSSBorderColorRight (Element element, PSchema tsch,
1.327 vatton 1047: PresentationContext context,
1048: char *cssRule, CSSInfoPtr css,
1049: ThotBool isHTML)
1.1 cvs 1050: {
1.117 vatton 1051: PresentationValue best;
1.43 cvs 1052:
1.234 vatton 1053: if (!strncasecmp (cssRule, "transparent", 11))
1054: {
1055: best.typed_data.value = -2; /* -2 means transparent */
1056: best.typed_data.unit = UNIT_REL;
1057: cssRule = SkipWord (cssRule);
1058: }
1059: else
1060: cssRule = ParseCSSColor (cssRule, &best);
1.295 vatton 1061: cssRule = CheckImportantRule (cssRule, context);
1.184 vatton 1062: if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.117 vatton 1063: {
1064: /* check if it's an important rule */
1065: /* install the new presentation */
1066: TtaSetStylePresentation (PRBorderRightColor, element, tsch, context, best);
1067: }
1068: return (cssRule);
1.1 cvs 1069: }
1070:
1071: /*----------------------------------------------------------------------
1.327 vatton 1072: ParseCSSBorderColor: parse a CSS border-color
1073: attribute string.
1.42 cvs 1074: ----------------------------------------------------------------------*/
1.79 cvs 1075: static char *ParseCSSBorderColor (Element element, PSchema tsch,
1.327 vatton 1076: PresentationContext context,
1077: char *cssRule, CSSInfoPtr css,
1078: ThotBool isHTML)
1.42 cvs 1079: {
1.79 cvs 1080: char *ptrT, *ptrR, *ptrB, *ptrL;
1.93 vatton 1081: int skippedNL;
1.42 cvs 1082:
1.82 cvs 1083: ptrT = SkipBlanksAndComments (cssRule);
1.42 cvs 1084: /* First parse Border-Top */
1.43 cvs 1085: ptrR = ParseCSSBorderColorTop (element, tsch, context, ptrT, css, isHTML);
1.82 cvs 1086: ptrR = SkipBlanksAndComments (ptrR);
1.301 vatton 1087: if (*ptrR == ';' || *ptrR == '}' || *ptrR == EOS || *ptrR == ',')
1.42 cvs 1088: {
1.93 vatton 1089: skippedNL = NewLineSkipped;
1.42 cvs 1090: cssRule = ptrR;
1091: /* apply the Border-Top to all */
1.43 cvs 1092: ptrR = ParseCSSBorderColorRight (element, tsch, context, ptrT, css, isHTML);
1.327 vatton 1093: NewLineSkipped = skippedNL;
1.43 cvs 1094: ptrR = ParseCSSBorderColorBottom (element, tsch, context, ptrT, css, isHTML);
1.327 vatton 1095: NewLineSkipped = skippedNL;
1.43 cvs 1096: ptrR = ParseCSSBorderColorLeft (element, tsch, context, ptrT, css, isHTML);
1.42 cvs 1097: }
1098: else
1099: {
1100: /* parse Border-Right */
1.43 cvs 1101: ptrB = ParseCSSBorderColorRight (element, tsch, context, ptrR, css, isHTML);
1.82 cvs 1102: ptrB = SkipBlanksAndComments (ptrB);
1.301 vatton 1103: if (*ptrB == ';' || *ptrB == '}' || *ptrB == EOS || *ptrB == ',')
1.327 vatton 1104: {
1105: skippedNL = NewLineSkipped;
1106: cssRule = ptrB;
1107: /* apply the Border-Top to Border-Bottom */
1108: ptrB = ParseCSSBorderColorBottom (element, tsch, context, ptrT, css, isHTML);
1109: NewLineSkipped = skippedNL;
1110: /* apply the Border-Right to Border-Left */
1111: ptrB = ParseCSSBorderColorLeft (element, tsch, context, ptrR, css, isHTML);
1112: }
1.42 cvs 1113: else
1.327 vatton 1114: {
1115: skippedNL = NewLineSkipped;
1116: /* parse Border-Bottom */
1117: ptrL = ParseCSSBorderColorBottom (element, tsch, context, ptrB, css, isHTML);
1118: NewLineSkipped = skippedNL;
1119: ptrL = SkipBlanksAndComments (ptrL);
1120: if (*ptrL == ';' || *ptrL == '}' || *ptrL == EOS || *ptrL == ',')
1121: {
1122: cssRule = ptrL;
1123: /* apply the Border-Right to Border-Left */
1124: ptrL = ParseCSSBorderColorLeft (element, tsch, context, ptrR, css, isHTML);
1125: }
1126: else
1127: /* parse Border-Left */
1128: cssRule = ParseCSSBorderColorLeft (element, tsch, context, ptrL, css, isHTML);
1129: cssRule = SkipBlanksAndComments (cssRule);
1130: }
1.42 cvs 1131: }
1132: return (cssRule);
1133: }
1134:
1135: /*----------------------------------------------------------------------
1.327 vatton 1136: ParseCSSBorderStyleTop: parse a CSS BorderStyleTop
1137: attribute string.
1.42 cvs 1138: ----------------------------------------------------------------------*/
1.79 cvs 1139: static char *ParseCSSBorderStyleTop (Element element, PSchema tsch,
1.327 vatton 1140: PresentationContext context,
1141: char *cssRule, CSSInfoPtr css,
1142: ThotBool isHTML)
1.42 cvs 1143: {
1.43 cvs 1144: PresentationValue border;
1145:
1.82 cvs 1146: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 1147: cssRule = ParseBorderStyle (cssRule, &border);
1.295 vatton 1148: cssRule = CheckImportantRule (cssRule, context);
1.184 vatton 1149: if (border.typed_data.unit != UNIT_INVALID && DoApply)
1.117 vatton 1150: {
1151: /* check if it's an important rule */
1152: TtaSetStylePresentation (PRBorderTopStyle, element, tsch, context, border);
1153: }
1.42 cvs 1154: return (cssRule);
1155: }
1156:
1157: /*----------------------------------------------------------------------
1.327 vatton 1158: ParseCSSBorderStyleLeft: parse a CSS BorderStyleLeft
1159: attribute string.
1.42 cvs 1160: ----------------------------------------------------------------------*/
1.79 cvs 1161: static char *ParseCSSBorderStyleLeft (Element element, PSchema tsch,
1.327 vatton 1162: PresentationContext context,
1163: char *cssRule, CSSInfoPtr css,
1164: ThotBool isHTML)
1.42 cvs 1165: {
1.43 cvs 1166: PresentationValue border;
1167:
1.82 cvs 1168: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 1169: cssRule = ParseBorderStyle (cssRule, &border);
1.295 vatton 1170: cssRule = CheckImportantRule (cssRule, context);
1.184 vatton 1171: if (border.typed_data.unit != UNIT_INVALID && DoApply)
1.117 vatton 1172: {
1173: /* check if it's an important rule */
1174: TtaSetStylePresentation (PRBorderLeftStyle, element, tsch, context, border);
1175: }
1.42 cvs 1176: return (cssRule);
1177: }
1178:
1179: /*----------------------------------------------------------------------
1.327 vatton 1180: ParseCSSBorderStyleBottom: parse a CSS BorderStyleBottom
1181: attribute string.
1.1 cvs 1182: ----------------------------------------------------------------------*/
1.79 cvs 1183: static char *ParseCSSBorderStyleBottom (Element element, PSchema tsch,
1.327 vatton 1184: PresentationContext context,
1185: char *cssRule, CSSInfoPtr css,
1186: ThotBool isHTML)
1.1 cvs 1187: {
1.43 cvs 1188: PresentationValue border;
1189:
1.82 cvs 1190: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 1191: cssRule = ParseBorderStyle (cssRule, &border);
1.295 vatton 1192: cssRule = CheckImportantRule (cssRule, context);
1.184 vatton 1193: if (border.typed_data.unit != UNIT_INVALID && DoApply)
1.117 vatton 1194: {
1195: /* check if it's an important rule */
1196: TtaSetStylePresentation (PRBorderBottomStyle, element, tsch, context, border);
1197: }
1.1 cvs 1198: return (cssRule);
1199: }
1200:
1201: /*----------------------------------------------------------------------
1.327 vatton 1202: ParseCSSBorderStyleRight: parse a CSS BorderStyleRight
1203: attribute string.
1.1 cvs 1204: ----------------------------------------------------------------------*/
1.79 cvs 1205: static char *ParseCSSBorderStyleRight (Element element, PSchema tsch,
1.327 vatton 1206: PresentationContext context,
1207: char *cssRule, CSSInfoPtr css,
1208: ThotBool isHTML)
1.1 cvs 1209: {
1.43 cvs 1210: PresentationValue border;
1211:
1.82 cvs 1212: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 1213: cssRule = ParseBorderStyle (cssRule, &border);
1.295 vatton 1214: cssRule = CheckImportantRule (cssRule, context);
1.184 vatton 1215: if (border.typed_data.unit != UNIT_INVALID && DoApply)
1.117 vatton 1216: {
1217: /* check if it's an important rule */
1218: TtaSetStylePresentation (PRBorderRightStyle, element, tsch, context, border);
1219: }
1.1 cvs 1220: return (cssRule);
1221: }
1222:
1223: /*----------------------------------------------------------------------
1.327 vatton 1224: ParseCSSBorderStyleStyle: parse a CSS border-style
1225: attribute string.
1.1 cvs 1226: ----------------------------------------------------------------------*/
1.79 cvs 1227: static char *ParseCSSBorderStyle (Element element, PSchema tsch,
1.327 vatton 1228: PresentationContext context,
1229: char *cssRule, CSSInfoPtr css,
1230: ThotBool isHTML)
1.1 cvs 1231: {
1.79 cvs 1232: char *ptrT, *ptrR, *ptrB, *ptrL;
1.93 vatton 1233: int skippedNL;
1.42 cvs 1234:
1.82 cvs 1235: ptrT = SkipBlanksAndComments (cssRule);
1.42 cvs 1236: /* First parse Border-Top */
1.43 cvs 1237: ptrR = ParseCSSBorderStyleTop (element, tsch, context, ptrT, css, isHTML);
1.82 cvs 1238: ptrR = SkipBlanksAndComments (ptrR);
1.301 vatton 1239: if (*ptrR == ';' || *ptrR == '}' || *ptrR == EOS || *ptrR == ',')
1.42 cvs 1240: {
1.93 vatton 1241: skippedNL = NewLineSkipped;
1.42 cvs 1242: cssRule = ptrR;
1243: /* apply the Border-Top to all */
1.43 cvs 1244: ptrR = ParseCSSBorderStyleRight (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 1245: NewLineSkipped = skippedNL;
1.43 cvs 1246: ptrR = ParseCSSBorderStyleBottom (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 1247: NewLineSkipped = skippedNL;
1.43 cvs 1248: ptrR = ParseCSSBorderStyleLeft (element, tsch, context, ptrT, css, isHTML);
1.42 cvs 1249: }
1250: else
1251: {
1252: /* parse Border-Right */
1.43 cvs 1253: ptrB = ParseCSSBorderStyleRight (element, tsch, context, ptrR, css, isHTML);
1.82 cvs 1254: ptrB = SkipBlanksAndComments (ptrB);
1.301 vatton 1255: if (*ptrB == ';' || *ptrR == '}' || *ptrB == EOS || *ptrB == ',')
1.327 vatton 1256: {
1257: skippedNL = NewLineSkipped;
1258: cssRule = ptrB;
1259: /* apply the Border-Top to Border-Bottom */
1260: ptrB = ParseCSSBorderStyleBottom (element, tsch, context, ptrT, css, isHTML);
1261: NewLineSkipped = skippedNL;
1262: /* apply the Border-Right to Border-Left */
1263: ptrB = ParseCSSBorderStyleLeft (element, tsch, context, ptrR, css, isHTML);
1264: }
1.42 cvs 1265: else
1.327 vatton 1266: {
1267: /* parse Border-Bottom */
1268: ptrL = ParseCSSBorderStyleBottom (element, tsch, context, ptrB, css, isHTML);
1269: ptrL = SkipBlanksAndComments (ptrL);
1270: if (*ptrL == ';' || *ptrR == '}' || *ptrL == EOS || *ptrL == ',')
1271: {
1272: cssRule = ptrL;
1273: /* apply the Border-Right to Border-Left */
1274: ptrL = ParseCSSBorderStyleLeft (element, tsch, context, ptrR, css, isHTML);
1275: }
1276: else
1277: /* parse Border-Left */
1278: cssRule = ParseCSSBorderStyleLeft (element, tsch, context, ptrL, css, isHTML);
1279: cssRule = SkipBlanksAndComments (cssRule);
1280: }
1.42 cvs 1281: }
1282: return (cssRule);
1283: }
1284:
1285: /*----------------------------------------------------------------------
1.327 vatton 1286: ParseCSSBorderTop: parse a CSS BorderTop
1287: attribute string.
1.42 cvs 1288: ----------------------------------------------------------------------*/
1.79 cvs 1289: static char *ParseCSSBorderTop (Element element, PSchema tsch,
1.327 vatton 1290: PresentationContext context, char *cssRule,
1291: CSSInfoPtr css, ThotBool isHTML)
1.42 cvs 1292: {
1.79 cvs 1293: char *ptr;
1.322 vatton 1294: ThotBool style, width;
1.43 cvs 1295:
1.82 cvs 1296: cssRule = SkipBlanksAndComments (cssRule);
1.322 vatton 1297: /* register given values */
1.337 vatton 1298: if (!strncmp (cssRule, "none", 4))
1299: style = width = TRUE;
1300: else
1301: style = width = FALSE;
1.301 vatton 1302: while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.43 cvs 1303: {
1304: ptr = cssRule;
1305: cssRule = ParseCSSBorderStyleTop (element, tsch, context, cssRule, css, isHTML);
1306: if (ptr == cssRule)
1.327 vatton 1307: {
1308: cssRule = ParseCSSBorderTopWidth (element, tsch, context, cssRule, css, isHTML);
1309: if (ptr == cssRule)
1310: cssRule = ParseCSSBorderColorTop (element, tsch, context, cssRule, css, isHTML);
1311: else
1312: width = TRUE;
1313: if (ptr == cssRule)
1314: {
1315: /* rule not found */
1316: cssRule = SkipValue ("Invalid border value", cssRule);
1317: cssRule = CheckImportantRule (cssRule, context);
1318: return (cssRule);
1319: }
1320: }
1.322 vatton 1321: else
1.327 vatton 1322: style = TRUE;
1.82 cvs 1323: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 1324: }
1.322 vatton 1325:
1326: if (!width)
1327: ParseCSSBorderTopWidth (element, tsch, context, "medium", css, isHTML);
1328: if (!style)
1329: ParseCSSBorderStyleTop (element, tsch, context, "none", css, isHTML);
1330: cssRule = CheckImportantRule (cssRule, context);
1.42 cvs 1331: return (cssRule);
1332: }
1333:
1334: /*----------------------------------------------------------------------
1.327 vatton 1335: ParseCSSBorderLeft: parse a CSS BorderLeft
1336: attribute string.
1.42 cvs 1337: ----------------------------------------------------------------------*/
1.79 cvs 1338: static char *ParseCSSBorderLeft (Element element, PSchema tsch,
1.327 vatton 1339: PresentationContext context, char *cssRule,
1340: CSSInfoPtr css, ThotBool isHTML)
1.42 cvs 1341: {
1.79 cvs 1342: char *ptr;
1.322 vatton 1343: ThotBool style, width;
1.43 cvs 1344:
1.82 cvs 1345: cssRule = SkipBlanksAndComments (cssRule);
1.322 vatton 1346: /* register given values */
1.337 vatton 1347: if (!strncmp (cssRule, "none", 4))
1348: style = width = TRUE;
1349: else
1350: style = width = FALSE;
1.301 vatton 1351: while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.43 cvs 1352: {
1353: ptr = cssRule;
1354: cssRule = ParseCSSBorderStyleLeft (element, tsch, context, cssRule, css, isHTML);
1355: if (ptr == cssRule)
1.327 vatton 1356: {
1357: cssRule = ParseCSSBorderLeftWidth (element, tsch, context, cssRule, css, isHTML);
1358: if (ptr == cssRule)
1359: cssRule = ParseCSSBorderColorLeft (element, tsch, context, cssRule, css, isHTML);
1360: else
1361: width = TRUE;
1362: if (ptr == cssRule)
1363: {
1364: /* rule not found */
1365: cssRule = SkipValue ("Invalid border value", cssRule);
1366: cssRule = CheckImportantRule (cssRule, context);
1367: return (cssRule);
1368: }
1369: }
1.322 vatton 1370: else
1.327 vatton 1371: style = TRUE;
1372: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 1373: }
1.322 vatton 1374:
1375: if (!width)
1376: ParseCSSBorderLeftWidth (element, tsch, context, "medium", css, isHTML);
1377: if (!style)
1378: ParseCSSBorderStyleLeft (element, tsch, context, "none", css, isHTML);
1379: cssRule = CheckImportantRule (cssRule, context);
1.1 cvs 1380: return (cssRule);
1381: }
1382:
1383: /*----------------------------------------------------------------------
1.327 vatton 1384: ParseCSSBorderBottom: parse a CSS BorderBottom
1385: attribute string.
1.1 cvs 1386: ----------------------------------------------------------------------*/
1.79 cvs 1387: static char *ParseCSSBorderBottom (Element element, PSchema tsch,
1.327 vatton 1388: PresentationContext context, char *cssRule,
1389: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1390: {
1.79 cvs 1391: char *ptr;
1.322 vatton 1392: ThotBool style, width;
1.43 cvs 1393:
1.82 cvs 1394: cssRule = SkipBlanksAndComments (cssRule);
1.322 vatton 1395: /* register given values */
1.337 vatton 1396: if (!strncmp (cssRule, "none", 4))
1397: style = width = TRUE;
1398: else
1399: style = width = FALSE;
1.301 vatton 1400: while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.43 cvs 1401: {
1402: ptr = cssRule;
1403: cssRule = ParseCSSBorderStyleBottom (element, tsch, context, cssRule, css, isHTML);
1404: if (ptr == cssRule)
1.327 vatton 1405: {
1406: cssRule = ParseCSSBorderBottomWidth (element, tsch, context, cssRule, css, isHTML);
1407: if (ptr == cssRule)
1408: cssRule = ParseCSSBorderColorBottom (element, tsch, context, cssRule, css, isHTML);
1409: else
1410: width = TRUE;
1411: if (ptr == cssRule)
1412: {
1413: /* rule not found */
1414: cssRule = SkipValue ("Invalid border value", cssRule);
1415: cssRule = CheckImportantRule (cssRule, context);
1416: return (cssRule);
1417: }
1418: }
1.322 vatton 1419: else
1.327 vatton 1420: style = TRUE;
1.82 cvs 1421: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 1422: }
1.322 vatton 1423:
1424: if (!width)
1425: ParseCSSBorderBottomWidth (element, tsch, context, "medium", css, isHTML);
1426: if (!style)
1427: ParseCSSBorderStyleBottom (element, tsch, context, "none", css, isHTML);
1428: cssRule = CheckImportantRule (cssRule, context);
1.1 cvs 1429: return (cssRule);
1430: }
1431:
1432: /*----------------------------------------------------------------------
1.327 vatton 1433: ParseCSSBorderRight: parse a CSS BorderRight
1434: attribute string.
1.1 cvs 1435: ----------------------------------------------------------------------*/
1.79 cvs 1436: static char *ParseCSSBorderRight (Element element, PSchema tsch,
1.327 vatton 1437: PresentationContext context, char *cssRule,
1438: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1439: {
1.79 cvs 1440: char *ptr;
1.322 vatton 1441: ThotBool style, width;
1.43 cvs 1442:
1.82 cvs 1443: cssRule = SkipBlanksAndComments (cssRule);
1.322 vatton 1444: /* register given values */
1.337 vatton 1445: if (!strncmp (cssRule, "none", 4))
1446: style = width = TRUE;
1447: else
1448: style = width = FALSE;
1.301 vatton 1449: while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.43 cvs 1450: {
1451: ptr = cssRule;
1452: cssRule = ParseCSSBorderStyleRight (element, tsch, context, cssRule, css, isHTML);
1453: if (ptr == cssRule)
1.327 vatton 1454: {
1455: cssRule = ParseCSSBorderRightWidth (element, tsch, context, cssRule, css, isHTML);
1456: if (ptr == cssRule)
1457: cssRule = ParseCSSBorderColorRight (element, tsch, context, cssRule, css, isHTML);
1458: else
1459: width = TRUE;
1460: if (ptr == cssRule)
1461: {
1462: /* rule not found */
1463: cssRule = SkipValue ("Invalid border value", cssRule);
1464: cssRule = CheckImportantRule (cssRule, context);
1465: return (cssRule);
1466: }
1467: }
1.322 vatton 1468: else
1.327 vatton 1469: style = TRUE;
1.82 cvs 1470: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 1471: }
1.322 vatton 1472:
1473: if (!width)
1474: ParseCSSBorderRightWidth (element, tsch, context, "medium", css, isHTML);
1475: if (!style)
1476: ParseCSSBorderStyleRight (element, tsch, context, "none", css, isHTML);
1477: cssRule = CheckImportantRule (cssRule, context);
1.1 cvs 1478: return (cssRule);
1479: }
1480:
1481: /*----------------------------------------------------------------------
1.327 vatton 1482: ParseCSSBorder: parse a CSS border
1483: attribute string.
1.42 cvs 1484: ----------------------------------------------------------------------*/
1.79 cvs 1485: static char *ParseCSSBorder (Element element, PSchema tsch,
1.327 vatton 1486: PresentationContext context, char *cssRule,
1487: CSSInfoPtr css, ThotBool isHTML)
1.42 cvs 1488: {
1.79 cvs 1489: char *ptrT, *ptrR;
1.93 vatton 1490: int skippedNL;
1.42 cvs 1491:
1.82 cvs 1492: ptrT = SkipBlanksAndComments (cssRule);
1.42 cvs 1493: /* First parse Border-Top */
1494: ptrR = ParseCSSBorderTop (element, tsch, context, ptrT, css, isHTML);
1.82 cvs 1495: ptrR = SkipBlanksAndComments (ptrR);
1.301 vatton 1496: if (*ptrR == ';' || *ptrR == '}' || *ptrR == EOS || *ptrR == ',')
1.42 cvs 1497: {
1.93 vatton 1498: skippedNL = NewLineSkipped;
1.42 cvs 1499: cssRule = ptrR;
1500: /* apply the Border-Top to all */
1501: ptrR = ParseCSSBorderRight (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 1502: NewLineSkipped = skippedNL;
1.42 cvs 1503: ptrR = ParseCSSBorderBottom (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 1504: NewLineSkipped = skippedNL;
1.42 cvs 1505: ptrR = ParseCSSBorderLeft (element, tsch, context, ptrT, css, isHTML);
1506: }
1507: return (cssRule);
1508: }
1509:
1.218 vatton 1510:
1.42 cvs 1511: /*----------------------------------------------------------------------
1.327 vatton 1512: ParseCSSFloat: parse a CSS float attribute string
1.184 vatton 1513: ----------------------------------------------------------------------*/
1514: static char *ParseCSSFloat (Element element, PSchema tsch,
1.327 vatton 1515: PresentationContext context, char *cssRule,
1516: CSSInfoPtr css, ThotBool isHTML)
1.184 vatton 1517: {
1.257 vatton 1518: DisplayMode dispMode;
1.184 vatton 1519: PresentationValue pval;
1.288 vatton 1520: char *ptr = cssRule;
1.184 vatton 1521:
1522: pval.typed_data.value = 0;
1.187 vatton 1523: pval.typed_data.unit = UNIT_BOX;
1.192 cvs 1524: pval.typed_data.real = FALSE;
1.190 vatton 1525: if (!strncasecmp (cssRule, "inherit", 7))
1526: {
1.293 quint 1527: pval.typed_data.unit = VALUE_INHERIT;
1.288 vatton 1528: cssRule += 7;
1.190 vatton 1529: }
1.184 vatton 1530: if (!strncasecmp (cssRule, "none", 4))
1.288 vatton 1531: {
1532: pval.typed_data.value = FloatNone;
1.293 quint 1533: cssRule += 4;
1.288 vatton 1534: }
1.184 vatton 1535: else if (!strncasecmp (cssRule, "left", 4))
1.288 vatton 1536: {
1537: pval.typed_data.value = FloatLeft;
1.293 quint 1538: cssRule += 4;
1.288 vatton 1539: }
1.184 vatton 1540: else if (!strncasecmp (cssRule, "right", 5))
1.288 vatton 1541: {
1542: pval.typed_data.value = FloatRight;
1.293 quint 1543: cssRule += 5;
1.288 vatton 1544: }
1.184 vatton 1545:
1.293 quint 1546: if (pval.typed_data.value == 0 && pval.typed_data.unit != VALUE_INHERIT)
1.211 vatton 1547: cssRule = SkipValue ("Invalid float value", cssRule);
1.184 vatton 1548: else
1549: {
1.295 vatton 1550: cssRule = CheckImportantRule (cssRule, context);
1.184 vatton 1551: if (DoApply)
1.327 vatton 1552: {
1553: dispMode = TtaGetDisplayMode (context->doc);
1554: if (dispMode != NoComputedDisplay)
1555: {
1556: /* force a redisplay of the whole document */
1557: TtaSetDisplayMode (context->doc, NoComputedDisplay);
1.257 vatton 1558: #ifdef AMAYA_DEBUG
1.327 vatton 1559: /*printf ("Force NoComputedDisplay doc=%d\n", context->doc);*/
1.257 vatton 1560: #endif /* AMAYA_DEBUG */
1.327 vatton 1561: }
1562: TtaSetStylePresentation (PRFloat, element, tsch, context, pval);
1563: }
1.288 vatton 1564: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid float value");
1.184 vatton 1565: }
1566: return (cssRule);
1567: }
1568:
1569: /*----------------------------------------------------------------------
1.327 vatton 1570: ParseCSSClear: parse a CSS clear rule
1.1 cvs 1571: ----------------------------------------------------------------------*/
1.79 cvs 1572: static char *ParseCSSClear (Element element, PSchema tsch,
1.327 vatton 1573: PresentationContext context, char *cssRule,
1574: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1575: {
1.184 vatton 1576: PresentationValue pval;
1577:
1578: pval.typed_data.value = 0;
1.187 vatton 1579: pval.typed_data.unit = UNIT_BOX;
1.193 vatton 1580: pval.typed_data.real = FALSE;
1.190 vatton 1581: if (!strncasecmp (cssRule, "inherit", 7))
1.293 quint 1582: pval.typed_data.unit = VALUE_INHERIT;
1.184 vatton 1583: if (!strncasecmp (cssRule, "none", 4))
1584: pval.typed_data.value = ClearNone;
1585: else if (!strncasecmp (cssRule, "left", 4))
1586: pval.typed_data.value = ClearLeft;
1587: else if (!strncasecmp (cssRule, "right", 5))
1588: pval.typed_data.value = ClearRight;
1589: else if (!strncasecmp (cssRule, "both", 4))
1590: pval.typed_data.value = ClearBoth;
1591:
1.293 quint 1592: if (pval.typed_data.value == 0 && pval.typed_data.unit != VALUE_INHERIT)
1.295 vatton 1593: {
1594: cssRule = SkipValue ("Invalid clear value", cssRule);
1595: cssRule = CheckImportantRule (cssRule, context);
1596: cssRule = SkipValue (NULL, cssRule);
1597: }
1.184 vatton 1598: else
1599: {
1.295 vatton 1600: cssRule = SkipValue (NULL, cssRule);
1601: cssRule = CheckImportantRule (cssRule, context);
1.184 vatton 1602: if (DoApply)
1.327 vatton 1603: TtaSetStylePresentation (PRClear, element, tsch, context, pval);
1.184 vatton 1604: }
1605: return (cssRule);
1606: }
1607:
1608: /*----------------------------------------------------------------------
1.333 vatton 1609: ParseCSSVisibility: parse a CSS visibility attribute string
1610: ----------------------------------------------------------------------*/
1611: static char *ParseCSSVisibility(Element element, PSchema tsch,
1612: PresentationContext context, char *cssRule,
1613: CSSInfoPtr css, ThotBool isHTML)
1614: {
1615: PresentationValue pval;
1616: char *ptr = cssRule;
1617:
1618: pval.typed_data.unit = UNIT_REL;
1619: pval.typed_data.real = FALSE;
1620: cssRule = SkipBlanksAndComments (cssRule);
1621: if (!strncasecmp (cssRule, "hidden", 6))
1622: {
1623: cssRule += 6;
1624: pval.typed_data.value = VsHidden;
1625: }
1626: else if (!strncasecmp (cssRule, "visible", 7))
1627: {
1628: cssRule += 7;
1629: pval.typed_data.value = VsVisible;
1630: }
1631: else if (!strncasecmp (cssRule, "collapse", 8))
1632: {
1633: cssRule += 8;
1634: pval.typed_data.value = VsCollapse;
1635: }
1636: else if (!strncasecmp (cssRule, "inherit", 7))
1637: {
1638: cssRule += 7;
1639: pval.typed_data.value = VsInherit;
1640: }
1641: else
1642: {
1643: cssRule = SkipValue ("Invalid visibility value", cssRule);
1644: return (cssRule);
1645: }
1646: cssRule = CheckImportantRule (cssRule, context);
1647: if (DoApply)
1648: TtaSetStylePresentation (PRVis, element, tsch, context, pval);
1649: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid visibility value");
1650: return (cssRule);
1651: }
1652:
1653:
1654: /*----------------------------------------------------------------------
1.327 vatton 1655: ParseCSSDisplay: parse a CSS display attribute string
1.1 cvs 1656: ----------------------------------------------------------------------*/
1.79 cvs 1657: static char *ParseCSSDisplay (Element element, PSchema tsch,
1.327 vatton 1658: PresentationContext context, char *cssRule,
1659: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1660: {
1.184 vatton 1661: PresentationValue pval;
1.288 vatton 1662: char *ptr = cssRule;
1.1 cvs 1663:
1.184 vatton 1664: pval.typed_data.unit = UNIT_REL;
1665: pval.typed_data.real = FALSE;
1666: cssRule = SkipBlanksAndComments (cssRule);
1667: if (!strncasecmp (cssRule, "none", 4))
1.288 vatton 1668: {
1669: cssRule += 4;
1670: pval.typed_data.value = DisplayNone;
1671: }
1.277 quint 1672: else if (!strncasecmp (cssRule, "block", 5))
1.288 vatton 1673: {
1674: cssRule += 5;
1675: pval.typed_data.value = Block;
1676: }
1.303 vatton 1677: else if (!strncasecmp (cssRule, "inline-block", 12))
1678: {
1679: cssRule += 12;
1680: pval.typed_data.value = InlineBlock;
1681: }
1.277 quint 1682: else if (!strncasecmp (cssRule, "inline", 6))
1.288 vatton 1683: {
1684: cssRule += 6;
1685: pval.typed_data.value = Inline;
1686: }
1.277 quint 1687: else if (!strncasecmp (cssRule, "list-item", 9))
1.288 vatton 1688: {
1689: cssRule += 9;
1690: pval.typed_data.value = ListItem;
1691: }
1.277 quint 1692: else if (!strncasecmp (cssRule, "run-in", 6))
1.288 vatton 1693: {
1694: cssRule += 6;
1695: pval.typed_data.value = RunIn;
1696: }
1.293 quint 1697: else if (!strncasecmp (cssRule, "inherit", 7))
1698: {
1699: cssRule += 7;
1700: pval.typed_data.unit = VALUE_INHERIT;
1701: }
1.277 quint 1702: else
1.184 vatton 1703: {
1.277 quint 1704: if (strncasecmp (cssRule, "table-row-group", 15) &&
1.327 vatton 1705: strncasecmp (cssRule, "table-column-group", 18) &&
1706: strncasecmp (cssRule, "table-header-group", 5) &&
1707: strncasecmp (cssRule, "table-footer-group", 6) &&
1708: strncasecmp (cssRule, "table-row", 9) &&
1709: strncasecmp (cssRule, "table-column", 12) &&
1710: strncasecmp (cssRule, "table-cell", 10) &&
1711: strncasecmp (cssRule, "table-caption", 13) &&
1712: strncasecmp (cssRule, "inline-table", 12) &&
1713: strncasecmp (cssRule, "table", 5))
1714: cssRule = SkipValue ("Display value not supported", cssRule);
1.281 quint 1715: else
1.327 vatton 1716: cssRule = SkipWord (cssRule);
1.277 quint 1717: return (cssRule);
1.184 vatton 1718: }
1.277 quint 1719:
1.295 vatton 1720: cssRule = CheckImportantRule (cssRule, context);
1.277 quint 1721: if (DoApply)
1.295 vatton 1722: TtaSetStylePresentation (PRDisplay, element, tsch, context, pval);
1.288 vatton 1723: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid display value");
1.1 cvs 1724: return (cssRule);
1725: }
1726:
1727: /*----------------------------------------------------------------------
1.327 vatton 1728: ParseCSSLetterSpacing: parse a CSS letter-spacing
1729: attribute string.
1.1 cvs 1730: ----------------------------------------------------------------------*/
1.79 cvs 1731: static char *ParseCSSLetterSpacing (Element element, PSchema tsch,
1.327 vatton 1732: PresentationContext context, char *cssRule,
1733: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1734: {
1.168 vatton 1735: cssRule = SkipValue (NULL, cssRule);
1.295 vatton 1736: cssRule = CheckImportantRule (cssRule, context);
1.1 cvs 1737: return (cssRule);
1738: }
1739:
1740: /*----------------------------------------------------------------------
1.327 vatton 1741: ParseACSSListStyleType: parse a CSS list-style-type
1742: attribute string.
1.1 cvs 1743: ----------------------------------------------------------------------*/
1.318 vatton 1744: static char *ParseACSSListStyleType (Element element, PSchema tsch,
1.327 vatton 1745: PresentationContext context, char *cssRule,
1746: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1747: {
1.281 quint 1748: PresentationValue pval;
1749:
1750: pval.typed_data.unit = UNIT_REL;
1751: pval.typed_data.real = FALSE;
1752: cssRule = SkipBlanksAndComments (cssRule);
1753: if (!strncasecmp (cssRule, "disc", 4))
1.288 vatton 1754: {
1755: cssRule += 4;
1756: pval.typed_data.value = Disc;
1757: }
1.281 quint 1758: else if (!strncasecmp (cssRule, "circle", 6))
1.293 quint 1759: {
1.288 vatton 1760: cssRule += 6;
1761: pval.typed_data.value = Circle;
1.293 quint 1762: }
1.281 quint 1763: else if (!strncasecmp (cssRule, "square", 6))
1.293 quint 1764: {
1.288 vatton 1765: cssRule += 6;
1.293 quint 1766: pval.typed_data.value = Square;
1767: }
1.283 quint 1768: else if (!strncasecmp (cssRule, "decimal-leading-zero", 20))
1.293 quint 1769: {
1.288 vatton 1770: cssRule += 20;
1.293 quint 1771: pval.typed_data.value = DecimalLeadingZero;
1772: }
1.281 quint 1773: else if (!strncasecmp (cssRule, "decimal", 7))
1.293 quint 1774: {
1.288 vatton 1775: cssRule += 7;
1.293 quint 1776: pval.typed_data.value = Decimal;
1777: }
1.281 quint 1778: else if (!strncasecmp (cssRule, "lower-roman", 11))
1.293 quint 1779: {
1.288 vatton 1780: cssRule += 11;
1.293 quint 1781: pval.typed_data.value = LowerRoman;
1782: }
1.281 quint 1783: else if (!strncasecmp (cssRule, "upper-roman", 11))
1.293 quint 1784: {
1.288 vatton 1785: cssRule += 11;
1.293 quint 1786: pval.typed_data.value = UpperRoman;
1787: }
1.281 quint 1788: else if (!strncasecmp (cssRule, "lower-greek", 11))
1.293 quint 1789: {
1.288 vatton 1790: cssRule += 11;
1.293 quint 1791: pval.typed_data.value = LowerGreek;
1792: }
1.281 quint 1793: else if (!strncasecmp (cssRule, "lower-latin", 11))
1.293 quint 1794: {
1.288 vatton 1795: cssRule += 11;
1.293 quint 1796: pval.typed_data.value = LowerLatin;
1797: }
1.281 quint 1798: else if (!strncasecmp (cssRule, "lower-alpha", 11))
1.293 quint 1799: {
1.288 vatton 1800: cssRule += 11;
1.293 quint 1801: pval.typed_data.value = LowerLatin;
1802: }
1.281 quint 1803: else if (!strncasecmp (cssRule, "upper-latin", 11))
1.293 quint 1804: {
1.288 vatton 1805: cssRule += 11;
1.293 quint 1806: pval.typed_data.value = UpperLatin;
1807: }
1.281 quint 1808: else if (!strncasecmp (cssRule, "upper-alpha", 11))
1.293 quint 1809: {
1.288 vatton 1810: cssRule += 11;
1.293 quint 1811: pval.typed_data.value = UpperLatin;
1812: }
1.281 quint 1813: else if (!strncasecmp (cssRule, "armenian", 8))
1.293 quint 1814: {
1.288 vatton 1815: cssRule += 8;
1.293 quint 1816: pval.typed_data.value = Decimal;
1817: }
1.281 quint 1818: else if (!strncasecmp (cssRule, "georgian", 8))
1.293 quint 1819: {
1.288 vatton 1820: cssRule += 8;
1.293 quint 1821: pval.typed_data.value = Decimal;
1822: }
1.281 quint 1823: else if (!strncasecmp (cssRule, "none", 4))
1.293 quint 1824: {
1.288 vatton 1825: cssRule += 4;
1.293 quint 1826: pval.typed_data.value = ListStyleTypeNone;
1827: }
1.281 quint 1828: else if (!strncasecmp (cssRule, "inherit", 7))
1829: {
1.293 quint 1830: cssRule += 7;
1831: pval.typed_data.unit = VALUE_INHERIT;
1.281 quint 1832: }
1833: else
1834: {
1835: cssRule = SkipValue ("Invalid list-style-type value", cssRule);
1836: return (cssRule);
1837: }
1838:
1.295 vatton 1839: cssRule = CheckImportantRule (cssRule, context);
1.281 quint 1840: if (DoApply)
1.295 vatton 1841: TtaSetStylePresentation (PRListStyleType, element, tsch, context, pval);
1.318 vatton 1842: return (cssRule);
1843: }
1844:
1845: /*----------------------------------------------------------------------
1.327 vatton 1846: ParseCSSListStyleType: parse a CSS list-style-type
1847: attribute string.
1.318 vatton 1848: ----------------------------------------------------------------------*/
1849: static char *ParseCSSListStyleType (Element element, PSchema tsch,
1.327 vatton 1850: PresentationContext context, char *cssRule,
1851: CSSInfoPtr css, ThotBool isHTML)
1.318 vatton 1852: {
1853: char *ptr = cssRule;
1854: cssRule = ParseACSSListStyleType (element, tsch, context, cssRule, css,
1.327 vatton 1855: isHTML);
1.288 vatton 1856: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid list-style-type value");
1.318 vatton 1857: return cssRule;
1.1 cvs 1858: }
1859:
1860: /*----------------------------------------------------------------------
1.281 quint 1861: ParseCSSUrl: parse an URL
1862: ----------------------------------------------------------------------*/
1863: static char *ParseCSSUrl (char *cssRule, char **url)
1864: {
1865: char saved;
1866: char *base, *ptr;
1867:
1868: cssRule = SkipBlanksAndComments (cssRule);
1869: saved = *cssRule;
1870: if (*cssRule == '(')
1871: {
1872: cssRule++;
1873: cssRule = SkipBlanksAndComments (cssRule);
1874: /*** Escaped quotes are not handled. See function SkipQuotedString */
1875: if (*cssRule == '"')
1.327 vatton 1876: {
1877: cssRule++;
1878: base = cssRule;
1879: while (*cssRule != EOS && *cssRule != '"')
1880: cssRule++;
1881: }
1.281 quint 1882: else if (*cssRule == '\'')
1.327 vatton 1883: {
1884: cssRule++;
1885: base = cssRule;
1886: while (*cssRule != EOS && *cssRule != '\'')
1887: cssRule++;
1888: }
1.281 quint 1889: else
1.327 vatton 1890: {
1891: base = cssRule;
1892: while (*cssRule != EOS && *cssRule != ')')
1893: cssRule++;
1894: }
1.281 quint 1895: /* keep the current position */
1896: ptr = cssRule;
1897: if (saved == ')')
1.327 vatton 1898: {
1899: /* remove extra spaces */
1900: if (cssRule[-1] == SPACE)
1901: {
1902: *cssRule = SPACE;
1903: cssRule--;
1904: while (cssRule[-1] == SPACE)
1905: cssRule--;
1906: }
1907: }
1.281 quint 1908: saved = *cssRule;
1909: *cssRule = EOS;
1910: *url = TtaStrdup (base);
1911: *cssRule = saved;
1912: if (saved == '"' || saved == '\'')
1.327 vatton 1913: /* we need to skip the quote character and possible spaces */
1914: {
1915: cssRule++;
1916: cssRule = SkipBlanksAndComments (cssRule);
1917: }
1.281 quint 1918: else
1.327 vatton 1919: cssRule = ptr;
1.281 quint 1920: }
1921: cssRule++;
1922: return cssRule;
1923: }
1924:
1925: /*----------------------------------------------------------------------
1.302 quint 1926: ParseCSSImageCallback: Callback called asynchronously by
1927: FetchImage when a CSS image (background-image or list-style-image)
1928: has been fetched.
1929: ----------------------------------------------------------------------*/
1930: void ParseCSSImageCallback (Document doc, Element element, char *file,
1.327 vatton 1931: void *extra, ThotBool isnew)
1.302 quint 1932: {
1933: DisplayMode dispMode = DisplayImmediately;
1934: CSSImageCallbackPtr callblock;
1935: Element el;
1936: PSchema tsch;
1937: CSSInfoPtr css;
1938: PresentationContext ctxt;
1939: PresentationValue image;
1940: PresentationValue value;
1941:
1942: callblock = (CSSImageCallbackPtr) extra;
1943: if (callblock == NULL)
1944: return;
1945:
1946: css = NULL;
1947: el = callblock->el;
1948: tsch = callblock->tsch;
1949: ctxt = callblock->ctxt;
1950: if (doc == 0 && !isnew)
1951: /* apply to the current document only */
1952: doc = ctxt->doc;
1953: if (doc)
1954: {
1955: /* avoid too many redisplay */
1956: dispMode = TtaGetDisplayMode (doc);
1957: if (dispMode == DisplayImmediately)
1.327 vatton 1958: TtaSetDisplayMode (doc, DeferredDisplay);
1.302 quint 1959: }
1960: else
1961: {
1.330 cvs 1962: dispMode = TtaGetDisplayMode (RedisplayDoc);
1.302 quint 1963: /* check if the CSS still exists */
1964: css = CSSList;
1965: while (css && css != callblock->css)
1.327 vatton 1966: css = css->NextCSS;
1.302 quint 1967: if (css == NULL)
1.327 vatton 1968: tsch = NULL;
1.302 quint 1969: }
1970:
1971: if (el || tsch)
1972: {
1973: /* Ok the image was fetched */
1974: image.typed_data.unit = UNIT_REL;
1975: image.typed_data.real = FALSE;
1976: image.pointer = file;
1977: TtaSetStylePresentation (callblock->ruleType, el, tsch, ctxt, image);
1978:
1979: if (callblock->ruleType == PRBackgroundPicture)
1.327 vatton 1980: /* enforce the showbox */
1981: {
1982: value.typed_data.value = 1;
1983: value.typed_data.unit = UNIT_REL;
1984: value.typed_data.real = FALSE;
1985: TtaSetStylePresentation (PRShowBox, el, tsch, ctxt, value);
1986: }
1.302 quint 1987: /* check if the context can be freed */
1988: ctxt->uses -= 1;
1989: if (ctxt->uses == 0)
1.327 vatton 1990: /* no other image loading */
1991: TtaFreeMemory (ctxt);
1.302 quint 1992: }
1993:
1994: TtaFreeMemory (callblock);
1.330 cvs 1995: if (css)
1996: RedisplayImages--;
1.302 quint 1997: if (doc)
1998: {
1999: if (dispMode == DisplayImmediately)
1.327 vatton 2000: /* restore the display mode */
2001: TtaSetDisplayMode (doc, dispMode);
1.302 quint 2002: }
1.311 vatton 2003: else if (css && Style_parsing == 0 && RedisplayImages == 0 && RedisplayDoc)
1.302 quint 2004: {
1.310 vatton 2005: /* all background images are now loaded */
1.330 cvs 2006: if (css->infos[RedisplayDoc] &&
1.327 vatton 2007: /* don't manage a document used by make book */
1.330 cvs 2008: (DocumentMeta[RedisplayDoc] == NULL ||
2009: DocumentMeta[RedisplayDoc]->method != CE_MAKEBOOK))
1.327 vatton 2010: {
2011: /* Change the Display Mode to take into account the new
2012: presentation */
1.330 cvs 2013: dispMode = TtaGetDisplayMode (RedisplayDoc);
1.329 vatton 2014: #ifdef AMAYA_DEBUG
2015: //printf ("ParseCSSImageCallback Show BGimages\n");
2016: #endif /* AMAYA_DEBUG */
1.313 vatton 2017: /* force the redisplay of this box */
1.330 cvs 2018: TtaSetDisplayMode (RedisplayDoc, NoComputedDisplay);
2019: TtaSetDisplayMode (RedisplayDoc, dispMode);
1.327 vatton 2020: }
1.330 cvs 2021: RedisplayBGImage = FALSE;
1.302 quint 2022: }
1.310 vatton 2023: else
1.328 vatton 2024: RedisplayBGImage = TRUE;
1.302 quint 2025: }
2026:
2027: /*----------------------------------------------------------------------
2028: SetCSSImage fetch the image referred by a background-image or a
2029: list-style-image property.
2030: ----------------------------------------------------------------------*/
2031: static char *SetCSSImage (Element element, PSchema tsch,
1.327 vatton 2032: PresentationContext ctxt, char *cssRule,
2033: CSSInfoPtr css, unsigned int ruleType)
1.302 quint 2034: {
2035: CSSImageCallbackPtr callblock;
2036: Element el;
2037: char *url;
1.304 cvs 2038: PresentationValue image;
1.302 quint 2039: char *bg_image;
2040: char tempname[MAX_LENGTH];
2041: char imgname[MAX_LENGTH];
2042:
2043: if (element)
2044: el = element;
2045: else
2046: /* default element for FetchImage */
2047: el = TtaGetMainRoot (ctxt->doc);
2048: url = NULL;
2049: cssRule = ParseCSSUrl (cssRule, &url);
2050: cssRule = CheckImportantRule (cssRule, ctxt);
2051: if (ctxt->destroy)
2052: {
2053: /* remove the background image PRule */
2054: image.pointer = NULL;
2055: TtaSetStylePresentation (ruleType, element, tsch, ctxt,image);
2056: }
1.341 quint 2057: else if (url && DoApply)
1.302 quint 2058: {
2059: bg_image = TtaGetEnvString ("ENABLE_BG_IMAGES");
2060: if (bg_image == NULL || !strcasecmp (bg_image, "yes"))
1.327 vatton 2061: /* background images are enabled */
2062: {
2063: callblock = (CSSImageCallbackPtr) TtaGetMemory (sizeof (CSSImageCallbackBlock));
2064: if (callblock)
2065: {
2066: callblock->el = element;
2067: callblock->tsch = tsch;
2068: callblock->css = css;
2069: callblock->ctxt = ctxt;
2070: callblock->ruleType = ruleType;
2071: /* new use of the context */
2072: ctxt->uses += 1;
2073: /* check if the image url is related to an external CSS */
2074: if (css)
2075: {
2076: RedisplayDoc = ctxt->doc;
2077: if (css->url)
2078: /* the image concerns a CSS file */
2079: NormalizeURL (url, 0, tempname, imgname, css->url);
2080: else
2081: /* the image concerns a style element */
2082: NormalizeURL (url, ctxt->doc, tempname, imgname, NULL);
2083: /* fetch and display background image of element */
1.330 cvs 2084: if (FetchImage (0, el, tempname, AMAYA_LOAD_IMAGE,
2085: ParseCSSImageCallback, callblock))
2086: RedisplayImages++;
1.327 vatton 2087: }
2088: else
2089: FetchImage (ctxt->doc, el, url, AMAYA_LOAD_IMAGE,
2090: ParseCSSImageCallback, callblock);
2091: }
2092: }
1.302 quint 2093: }
2094: if (url)
2095: TtaFreeMemory (url);
2096: return (cssRule);
2097: }
2098:
2099: /*----------------------------------------------------------------------
1.327 vatton 2100: ParseACSSListStyleImage: parse a CSS list-style-image
2101: attribute string.
1.1 cvs 2102: ----------------------------------------------------------------------*/
1.318 vatton 2103: static char *ParseACSSListStyleImage (Element element, PSchema tsch,
1.327 vatton 2104: PresentationContext ctxt,
2105: char *cssRule, CSSInfoPtr css,
2106: ThotBool isHTML)
1.1 cvs 2107: {
1.288 vatton 2108: char *url;
1.293 quint 2109: PresentationValue pval;
1.281 quint 2110:
1.293 quint 2111: pval.typed_data.unit = UNIT_REL;
2112: pval.typed_data.real = FALSE;
1.281 quint 2113: url = NULL;
2114: cssRule = SkipBlanksAndComments (cssRule);
2115: if (!strncasecmp (cssRule, "none", 4))
2116: {
2117: cssRule += 4;
2118: cssRule = CheckImportantRule (cssRule, ctxt);
1.302 quint 2119: pval.typed_data.value = 0;
2120: if (DoApply)
1.327 vatton 2121: TtaSetStylePresentation (PRListStyleImage, element, tsch, ctxt, pval);
1.281 quint 2122: }
2123: else if (!strncasecmp (cssRule, "url", 3))
2124: {
2125: cssRule += 3;
1.302 quint 2126: cssRule = SetCSSImage (element, tsch, ctxt, cssRule, css,
1.327 vatton 2127: PRListStyleImage);
1.281 quint 2128: }
2129: else if (!strncasecmp (cssRule, "inherit", 7))
1.288 vatton 2130: {
2131: cssRule += 7;
1.293 quint 2132: pval.typed_data.unit = VALUE_INHERIT;
1.295 vatton 2133: cssRule = CheckImportantRule (cssRule, ctxt);
1.293 quint 2134: if (DoApply)
1.327 vatton 2135: TtaSetStylePresentation (PRListStyleImage, element, tsch, ctxt, pval);
2136: }
1.281 quint 2137: else
1.295 vatton 2138: {
2139: cssRule = SkipValue ("Invalid list-style-image value", cssRule);
2140: cssRule = CheckImportantRule (cssRule, ctxt);
2141: }
1.1 cvs 2142: return (cssRule);
2143: }
2144:
2145: /*----------------------------------------------------------------------
1.327 vatton 2146: ParseCSSListStyleImage: parse a CSS list-style-image
2147: attribute string.
1.318 vatton 2148: ----------------------------------------------------------------------*/
2149: static char *ParseCSSListStyleImage (Element element, PSchema tsch,
1.327 vatton 2150: PresentationContext ctxt,
2151: char *cssRule, CSSInfoPtr css,
2152: ThotBool isHTML)
1.318 vatton 2153: {
2154: char *ptr = cssRule;
2155: cssRule = ParseACSSListStyleImage (element, tsch, ctxt, cssRule, css,
1.327 vatton 2156: isHTML);
1.318 vatton 2157: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid list-style-image value");
2158: return cssRule;
2159: }
2160:
2161: /*----------------------------------------------------------------------
1.327 vatton 2162: ParseACSSListStylePosition: parse a CSS list-style-position
2163: attribute string.
1.1 cvs 2164: ----------------------------------------------------------------------*/
1.318 vatton 2165: static char *ParseACSSListStylePosition (Element element, PSchema tsch,
1.327 vatton 2166: PresentationContext context,
2167: char *cssRule, CSSInfoPtr css,
2168: ThotBool isHTML)
1.1 cvs 2169: {
1.281 quint 2170: PresentationValue pval;
2171:
2172: pval.typed_data.unit = UNIT_REL;
2173: pval.typed_data.real = FALSE;
2174: cssRule = SkipBlanksAndComments (cssRule);
2175: if (!strncasecmp (cssRule, "inside", 6))
1.288 vatton 2176: {
2177: pval.typed_data.value = Inside;
2178: cssRule += 6;
2179: }
1.281 quint 2180: else if (!strncasecmp (cssRule, "outside", 7))
1.288 vatton 2181: {
2182: pval.typed_data.value = Outside;
2183: cssRule += 7;
2184: }
1.293 quint 2185: else if (!strncasecmp (cssRule, "inherit", 7))
2186: {
2187: pval.typed_data.unit = VALUE_INHERIT;
2188: cssRule += 7;
2189: }
1.281 quint 2190: else
2191: {
1.293 quint 2192: cssRule = SkipValue ("Invalid list-style-position value", cssRule);
1.295 vatton 2193: cssRule = CheckImportantRule (cssRule, context);
1.281 quint 2194: return (cssRule);
2195: }
1.293 quint 2196:
1.295 vatton 2197: cssRule = CheckImportantRule (cssRule, context);
1.281 quint 2198: if (DoApply)
1.295 vatton 2199: TtaSetStylePresentation (PRListStylePosition, element, tsch, context, pval);
1.327 vatton 2200: return (cssRule);
1.318 vatton 2201: }
2202:
2203: /*----------------------------------------------------------------------
1.327 vatton 2204: ParseCSSListStylePosition: parse a CSS list-style-position
2205: attribute string.
1.318 vatton 2206: ----------------------------------------------------------------------*/
2207: static char *ParseCSSListStylePosition (Element element, PSchema tsch,
1.327 vatton 2208: PresentationContext context,
2209: char *cssRule, CSSInfoPtr css,
2210: ThotBool isHTML)
1.318 vatton 2211: {
2212: char *ptr = cssRule;
2213: cssRule = ParseACSSListStylePosition (element, tsch, context, cssRule, css,
1.327 vatton 2214: isHTML);
1.288 vatton 2215: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid list-style-position value");
1.318 vatton 2216: return cssRule;
1.1 cvs 2217: }
2218:
2219: /*----------------------------------------------------------------------
1.327 vatton 2220: ParseCSSListStyle: parse a CSS list-style value string.
1.1 cvs 2221: ----------------------------------------------------------------------*/
1.79 cvs 2222: static char *ParseCSSListStyle (Element element, PSchema tsch,
1.327 vatton 2223: PresentationContext ctxt, char *cssRule,
2224: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2225: {
1.318 vatton 2226: char *ptr = cssRule;
2227: int skippedNL;
1.281 quint 2228:
2229: cssRule = SkipBlanksAndComments (cssRule);
1.301 vatton 2230: while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.281 quint 2231: {
1.316 quint 2232: skippedNL = NewLineSkipped;
1.281 quint 2233: /* perhaps a list-style-image */
2234: if (!strncasecmp (cssRule, "url", 3))
1.327 vatton 2235: cssRule = ParseACSSListStyleImage (element, tsch, ctxt, cssRule, css,
2236: isHTML);
1.281 quint 2237: /* perhaps a list-style-position */
2238: else if (!strncasecmp (cssRule, "inside", 6) ||
2239: !strncasecmp (cssRule, "outside", 7))
1.327 vatton 2240: cssRule = ParseACSSListStylePosition (element, tsch, ctxt, cssRule,
2241: css, isHTML);
1.281 quint 2242: /* perhaps a list-style-type */
2243: else if (!strncasecmp (cssRule, "disc", 4) ||
1.327 vatton 2244: !strncasecmp (cssRule, "circle", 6) ||
2245: !strncasecmp (cssRule, "square", 6) ||
2246: !strncasecmp (cssRule, "decimal", 7) ||
2247: !strncasecmp (cssRule, "decimal-leading-zero", 20) ||
2248: !strncasecmp (cssRule, "lower-roman", 11) ||
2249: !strncasecmp (cssRule, "upper-roman", 11) ||
2250: !strncasecmp (cssRule, "lower-greek", 11) ||
2251: !strncasecmp (cssRule, "lower-latin", 11) ||
2252: !strncasecmp (cssRule, "lower-alpha", 11) ||
2253: !strncasecmp (cssRule, "upper-latin", 11) ||
2254: !strncasecmp (cssRule, "upper-alpha", 11) ||
2255: !strncasecmp (cssRule, "armenian", 8) ||
2256: !strncasecmp (cssRule, "georgian", 8) ||
2257: !strncasecmp (cssRule, "none", 4) ||
2258: !strncasecmp (cssRule, "inherit", 7))
2259: cssRule = ParseACSSListStyleType (element, tsch, ctxt, cssRule, css,
2260: isHTML);
1.281 quint 2261: else
1.327 vatton 2262: {
2263: NewLineSkipped = skippedNL;
2264: /* rule not found */
2265: cssRule = SkipProperty (cssRule, FALSE);
2266: }
1.281 quint 2267: cssRule = SkipBlanksAndComments (cssRule);
2268: }
1.318 vatton 2269: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid list-style value");
1.1 cvs 2270: return (cssRule);
2271: }
2272:
2273: /*----------------------------------------------------------------------
1.327 vatton 2274: ParseCSSTextAlign: parse a CSS text-align
2275: attribute string.
1.1 cvs 2276: ----------------------------------------------------------------------*/
1.79 cvs 2277: static char *ParseCSSTextAlign (Element element, PSchema tsch,
1.327 vatton 2278: PresentationContext context, char *cssRule,
2279: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2280: {
1.327 vatton 2281: char *ptr = cssRule;
2282: PresentationValue align;
2283:
2284: align.typed_data.value = 0;
2285: align.typed_data.unit = UNIT_REL;
2286: align.typed_data.real = FALSE;
2287:
2288: cssRule = SkipBlanksAndComments (cssRule);
2289: if (!strncasecmp (cssRule, "left", 4))
2290: {
2291: align.typed_data.value = AdjustLeft;
2292: cssRule += 4;
2293: }
2294: else if (!strncasecmp (cssRule, "right", 5))
2295: {
2296: align.typed_data.value = AdjustRight;
2297: cssRule += 5;
2298: }
2299: else if (!strncasecmp (cssRule, "center", 6))
2300: {
2301: align.typed_data.value = Centered;
2302: cssRule += 6;
2303: }
2304: else if (!strncasecmp (cssRule, "justify", 7))
2305: {
2306: align.typed_data.value = Justify;
2307: cssRule += 7;
2308: }
2309: else
2310: {
2311: cssRule = SkipValue ("Invalid text-align value", cssRule);
2312: cssRule = CheckImportantRule (cssRule, context);
2313: return (cssRule);
2314: }
1.1 cvs 2315:
1.327 vatton 2316: /*
2317: * install the new presentation.
2318: */
2319: cssRule = CheckImportantRule (cssRule, context);
2320: if (align.typed_data.value && DoApply)
2321: TtaSetStylePresentation (PRAdjust, element, tsch, context, align);
2322: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid text-align value");
2323: return (cssRule);
1.1 cvs 2324: }
2325:
2326: /*----------------------------------------------------------------------
1.243 quint 2327: ParseCSSTextAnchor: parse a CSS text-anchor property (SVG property)
2328: We use the Thot Adjust PRule to represent the text-anchor property
2329: for CSS 1.0, as Adjust is not used otherwise in this context.
2330: ----------------------------------------------------------------------*/
2331: static char *ParseCSSTextAnchor (Element element, PSchema tsch,
1.327 vatton 2332: PresentationContext context, char *cssRule,
2333: CSSInfoPtr css, ThotBool isHTML)
1.243 quint 2334: {
1.327 vatton 2335: PresentationValue align;
2336: char *ptr = cssRule;
2337:
2338: align.typed_data.value = 0;
2339: align.typed_data.unit = UNIT_REL;
2340: align.typed_data.real = FALSE;
1.243 quint 2341:
1.327 vatton 2342: cssRule = SkipBlanksAndComments (cssRule);
2343: if (!strncasecmp (cssRule, "start", 5))
2344: {
2345: align.typed_data.value = AdjustLeft;
2346: cssRule += 5;
2347: }
2348: else if (!strncasecmp (cssRule, "middle", 6))
2349: {
2350: align.typed_data.value = Centered;
2351: cssRule += 6;
2352: }
2353: else if (!strncasecmp (cssRule, "end", 3))
2354: {
2355: align.typed_data.value = AdjustRight;
2356: cssRule += 3;
2357: }
2358: else if (!strncasecmp (cssRule, "inherit", 7))
2359: {
2360: align.typed_data.unit = VALUE_INHERIT;
2361: cssRule += 7;
2362: }
2363: else
2364: {
2365: cssRule = SkipValue ("Invalid text-anchor value", cssRule);
2366: cssRule = CheckImportantRule (cssRule, context);
1.295 vatton 2367: return (cssRule);
1.327 vatton 2368: }
1.243 quint 2369:
1.327 vatton 2370: /*
2371: * install the new presentation.
2372: */
2373: cssRule = CheckImportantRule (cssRule, context);
2374: if (DoApply &&
2375: (align.typed_data.value || align.typed_data.unit == VALUE_INHERIT))
2376: TtaSetStylePresentation (PRAdjust, element, tsch, context, align);
2377: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid text-anchor value");
2378: return (cssRule);
1.243 quint 2379: }
2380:
2381: /*----------------------------------------------------------------------
1.327 vatton 2382: ParseCSSDirection: parse a CSS direction property
1.112 quint 2383: ----------------------------------------------------------------------*/
2384: static char *ParseCSSDirection (Element element, PSchema tsch,
1.327 vatton 2385: PresentationContext context, char *cssRule,
2386: CSSInfoPtr css, ThotBool isHTML)
1.112 quint 2387: {
1.327 vatton 2388: PresentationValue direction;
2389: char *ptr = cssRule;
2390:
2391: direction.typed_data.value = 0;
2392: direction.typed_data.unit = UNIT_REL;
2393: direction.typed_data.real = FALSE;
2394:
2395: cssRule = SkipBlanksAndComments (cssRule);
2396: if (!strncasecmp (cssRule, "ltr", 3))
2397: {
2398: direction.typed_data.value = LeftToRight;
2399: cssRule += 3;
2400: }
2401: else if (!strncasecmp (cssRule, "rtl", 3))
2402: {
2403: direction.typed_data.value = RightToLeft;
2404: cssRule += 3;
2405: }
2406: else if (!strncasecmp (cssRule, "inherit", 7))
2407: {
2408: direction.typed_data.unit = VALUE_INHERIT;
2409: cssRule += 7;
2410: }
2411: else
2412: {
2413: cssRule = SkipValue ("Invalid direction value", cssRule);
2414: cssRule = CheckImportantRule (cssRule, context);
2415: return (cssRule);
2416: }
1.112 quint 2417:
1.327 vatton 2418: /*
2419: * install the new presentation.
2420: */
2421: cssRule = CheckImportantRule (cssRule, context);
2422: if (DoApply &&
2423: (direction.typed_data.value || direction.typed_data.unit == VALUE_INHERIT))
2424: TtaSetStylePresentation (PRDirection, element, tsch, context, direction);
2425: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid direction value");
2426: return (cssRule);
1.112 quint 2427: }
2428:
2429: /*----------------------------------------------------------------------
1.327 vatton 2430: ParseCSSUnicodeBidi: parse a CSS unicode-bidi property
1.113 quint 2431: ----------------------------------------------------------------------*/
2432: static char *ParseCSSUnicodeBidi (Element element, PSchema tsch,
1.327 vatton 2433: PresentationContext context, char *cssRule,
2434: CSSInfoPtr css, ThotBool isHTML)
1.113 quint 2435: {
1.327 vatton 2436: PresentationValue bidi;
2437: char *ptr = cssRule;
1.113 quint 2438:
1.327 vatton 2439: bidi.typed_data.value = 0;
2440: bidi.typed_data.unit = UNIT_REL;
2441: bidi.typed_data.real = FALSE;
2442:
2443: cssRule = SkipBlanksAndComments (cssRule);
2444: if (!strncasecmp (cssRule, "normal", 6))
2445: {
2446: bidi.typed_data.value = Normal;
2447: cssRule += 6;
2448: }
2449: else if (!strncasecmp (cssRule, "embed", 5))
2450: {
2451: bidi.typed_data.value = Embed;
2452: cssRule += 5;
2453: }
2454: else if (!strncasecmp (cssRule, "bidi-override", 13))
2455: {
2456: bidi.typed_data.value = Override;
2457: cssRule += 13;
2458: }
2459: else if (!strncasecmp (cssRule, "inherit", 7))
2460: {
2461: bidi.typed_data.unit = VALUE_INHERIT;
2462: cssRule += 7;
2463: }
2464: else
2465: {
2466: cssRule = SkipValue ("Invalid unicode-bidi value", cssRule);
2467: cssRule = CheckImportantRule (cssRule, context);
1.295 vatton 2468: return (cssRule);
1.327 vatton 2469: }
1.113 quint 2470:
1.327 vatton 2471: /*
2472: * install the new presentation.
2473: */
2474: cssRule = CheckImportantRule (cssRule, context);
2475: if (DoApply &&
2476: (bidi.typed_data.value || bidi.typed_data.unit == VALUE_INHERIT))
2477: TtaSetStylePresentation (PRUnicodeBidi, element, tsch, context, bidi);
2478: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid unicode-bidi value");
2479: return (cssRule);
1.113 quint 2480: }
2481:
2482: /*----------------------------------------------------------------------
1.327 vatton 2483: ParseCSSTextIndent: parse a CSS text-indent
2484: attribute string.
1.1 cvs 2485: ----------------------------------------------------------------------*/
1.79 cvs 2486: static char *ParseCSSTextIndent (Element element, PSchema tsch,
1.327 vatton 2487: PresentationContext context, char *cssRule,
2488: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2489: {
1.327 vatton 2490: PresentationValue pval;
2491: char *ptr;
1.1 cvs 2492:
1.327 vatton 2493: cssRule = SkipBlanksAndComments (cssRule);
2494: ptr = cssRule;
2495: cssRule = ParseCSSUnit (cssRule, &pval);
2496: if (pval.typed_data.value == 0)
2497: pval.typed_data.unit = UNIT_PX;
2498: else if (pval.typed_data.unit == UNIT_INVALID ||
2499: pval.typed_data.unit == UNIT_BOX)
2500: {
2501: CSSParseError ("Invalid text-indent value", ptr, cssRule);
2502: cssRule = CheckImportantRule (cssRule, context);
2503: return (cssRule);
2504: }
2505: /* install the attribute */
2506: cssRule = CheckImportantRule (cssRule, context);
2507: if (DoApply)
2508: TtaSetStylePresentation (PRIndent, element, tsch, context, pval);
2509: return (cssRule);
1.1 cvs 2510: }
2511:
2512: /*----------------------------------------------------------------------
1.327 vatton 2513: ParseCSSTextTransform: parse a CSS text-transform
2514: attribute string.
1.1 cvs 2515: ----------------------------------------------------------------------*/
1.79 cvs 2516: static char *ParseCSSTextTransform (Element element, PSchema tsch,
1.327 vatton 2517: PresentationContext context, char *cssRule,
2518: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2519: {
1.168 vatton 2520: cssRule = SkipValue (NULL, cssRule);
1.295 vatton 2521: cssRule = CheckImportantRule (cssRule, context);
1.1 cvs 2522: return (cssRule);
2523: }
2524:
2525: /*----------------------------------------------------------------------
1.327 vatton 2526: ParseCSSVerticalAlign: parse a CSS vertical-align
2527: attribute string.
1.1 cvs 2528: ----------------------------------------------------------------------*/
1.79 cvs 2529: static char *ParseCSSVerticalAlign (Element element, PSchema tsch,
1.327 vatton 2530: PresentationContext context, char *cssRule,
2531: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2532: {
1.273 quint 2533: char *ptr;
2534: PresentationValue pval;
2535:
2536: pval.typed_data.unit = UNIT_REL;
2537: pval.typed_data.real = FALSE;
2538: cssRule = SkipBlanksAndComments (cssRule);
1.288 vatton 2539: ptr = cssRule;
1.273 quint 2540: if (!strncasecmp (cssRule, "baseline", 8))
2541: {
2542: pval.typed_data.value = 0;
1.288 vatton 2543: cssRule += 8;
1.273 quint 2544: }
2545: else if (!strncasecmp (cssRule, "sub", 3))
2546: {
2547: pval.typed_data.value = -3;
1.288 vatton 2548: cssRule += 3;
1.273 quint 2549: }
2550: else if (!strncasecmp (cssRule, "super", 5))
2551: {
2552: pval.typed_data.value = 4;
1.288 vatton 2553: cssRule += 5;
1.273 quint 2554: }
2555: else if (!strncasecmp (cssRule, "top", 3))
2556: {
1.275 quint 2557: pval.typed_data.unit = UNIT_INVALID; /* Not supported yet */
1.274 vatton 2558: pval.typed_data.value = 0;
1.288 vatton 2559: cssRule += 3;
1.273 quint 2560: }
2561: else if (!strncasecmp (cssRule, "text-top", 8))
2562: {
1.275 quint 2563: pval.typed_data.unit = UNIT_INVALID; /* Not supported yet */
1.274 vatton 2564: pval.typed_data.value = 0;
1.288 vatton 2565: cssRule += 8;
1.273 quint 2566: }
2567: else if (!strncasecmp (cssRule, "middle", 6))
2568: {
1.275 quint 2569: pval.typed_data.unit = UNIT_INVALID; /* Not supported yet */
1.274 vatton 2570: pval.typed_data.value = 0;
1.288 vatton 2571: cssRule += 6;
1.273 quint 2572: }
2573: else if (!strncasecmp (cssRule, "bottom", 6))
2574: {
1.275 quint 2575: pval.typed_data.unit = UNIT_INVALID; /* Not supported yet */
1.274 vatton 2576: pval.typed_data.value = 0;
1.288 vatton 2577: cssRule += 6;
1.273 quint 2578: }
2579: else if (!strncasecmp (cssRule, "text-bottom", 11))
2580: {
1.275 quint 2581: pval.typed_data.unit = UNIT_INVALID; /* Not supported yet */
1.274 vatton 2582: pval.typed_data.value = 0;
1.288 vatton 2583: cssRule += 11;
1.273 quint 2584: }
2585: else if (!strncasecmp (cssRule, "inherit", 7))
2586: {
1.293 quint 2587: pval.typed_data.unit = VALUE_INHERIT;
1.274 vatton 2588: pval.typed_data.value = 0;
1.288 vatton 2589: cssRule +=7;
1.273 quint 2590: }
2591: else
2592: {
2593: /* parse <percentage> or <length> */
2594: cssRule = ParseCSSUnit (cssRule, &pval);
2595: if (pval.typed_data.unit == UNIT_INVALID)
1.327 vatton 2596: {
2597: pval.typed_data.value = 0;
2598: CSSParseError ("Invalid vertical-align value", ptr, cssRule);
2599: cssRule = CheckImportantRule (cssRule, context);
2600: return (cssRule);
2601: }
1.273 quint 2602: else if (pval.typed_data.value == 0)
1.327 vatton 2603: pval.typed_data.unit = UNIT_PX;
1.273 quint 2604: else if (pval.typed_data.unit == UNIT_BOX)
1.327 vatton 2605: pval.typed_data.unit = UNIT_EM;
1.273 quint 2606: else if (pval.typed_data.unit == UNIT_PERCENT)
1.327 vatton 2607: /* it's a percentage */
2608: {
2609: /* convert it into a relative size */
2610: pval.typed_data.unit = UNIT_REL;
2611: pval.typed_data.value /= 10;
2612: }
1.273 quint 2613: }
1.295 vatton 2614:
2615: cssRule = CheckImportantRule (cssRule, context);
1.273 quint 2616: if (pval.typed_data.unit != UNIT_INVALID && DoApply)
2617: TtaSetStylePresentation (PRHorizRef, element, tsch, context, pval);
1.288 vatton 2618: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid vertical-align value");
1.1 cvs 2619: return (cssRule);
2620: }
2621:
2622: /*----------------------------------------------------------------------
1.327 vatton 2623: ParseCSSWhiteSpace: parse a CSS white-space
2624: attribute string.
1.1 cvs 2625: ----------------------------------------------------------------------*/
1.79 cvs 2626: static char *ParseCSSWhiteSpace (Element element, PSchema tsch,
1.327 vatton 2627: PresentationContext context, char *cssRule,
2628: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2629: {
1.288 vatton 2630: char *ptr = cssRule;
2631:
1.327 vatton 2632: cssRule = SkipBlanksAndComments (cssRule);
2633: if (!strncasecmp (cssRule, "normal", 6))
2634: cssRule += 6;
2635: else if (!strncasecmp (cssRule, "pre", 3))
2636: cssRule += 3;
2637: else if (!strncasecmp (cssRule, "nowrap", 6))
2638: cssRule += 6;
2639: else if (!strncasecmp (cssRule, "pre-wrap", 8))
2640: cssRule += 8;
2641: else if (!strncasecmp (cssRule, "pre-line", 8))
2642: cssRule += 8;
2643: else if (!strncasecmp (cssRule, "inherit", 7))
2644: cssRule += 7;
2645: else
2646: cssRule = SkipValue ("Invalid white-space value", cssRule);
2647:
2648: cssRule = CheckImportantRule (cssRule, context);
2649: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid white-space value");
2650: return (cssRule);
1.1 cvs 2651: }
2652:
2653: /*----------------------------------------------------------------------
1.327 vatton 2654: ParseCSSWordSpacing: parse a CSS word-spacing
2655: attribute string.
1.1 cvs 2656: ----------------------------------------------------------------------*/
1.79 cvs 2657: static char *ParseCSSWordSpacing (Element element, PSchema tsch,
1.327 vatton 2658: PresentationContext context, char *cssRule,
2659: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2660: {
1.168 vatton 2661: cssRule = SkipValue (NULL, cssRule);
1.295 vatton 2662: cssRule = CheckImportantRule (cssRule, context);
1.1 cvs 2663: return (cssRule);
2664: }
2665:
2666: /*----------------------------------------------------------------------
1.327 vatton 2667: ParseCSSLineHeight: parse a CSS line-height property
1.25 cvs 2668: ----------------------------------------------------------------------*/
1.162 quint 2669: static char *ParseCSSLineHeight (Element element, PSchema tsch,
1.327 vatton 2670: PresentationContext context, char *cssRule,
2671: CSSInfoPtr css, ThotBool isHTML)
1.25 cvs 2672: {
1.162 quint 2673: PresentationValue pval;
1.288 vatton 2674: char *ptr;
1.162 quint 2675:
2676: ptr = cssRule;
2677: if (!strncasecmp (cssRule, "normal", 6))
2678: {
1.184 vatton 2679: pval.typed_data.unit = UNIT_REL;
1.162 quint 2680: pval.typed_data.real = TRUE;
2681: pval.typed_data.value = 1100;
1.288 vatton 2682: cssRule += 6;
1.162 quint 2683: }
2684: else if (!strncasecmp (cssRule, "inherit", 7))
2685: {
1.293 quint 2686: pval.typed_data.unit = VALUE_INHERIT;
1.288 vatton 2687: cssRule += 6;
1.162 quint 2688: }
2689: else
2690: cssRule = ParseCSSUnit (cssRule, &pval);
1.25 cvs 2691:
1.295 vatton 2692: cssRule = CheckImportantRule (cssRule, context);
1.184 vatton 2693: if (pval.typed_data.unit == UNIT_INVALID)
1.168 vatton 2694: CSSParseError ("Invalid line-height value", ptr, cssRule);
1.162 quint 2695: else if (DoApply)
2696: {
1.166 vatton 2697: /* install the new presentation */
1.184 vatton 2698: if (pval.typed_data.unit == UNIT_BOX)
1.327 vatton 2699: pval.typed_data.unit = UNIT_EM;
1.162 quint 2700: TtaSetStylePresentation (PRLineSpacing, element, tsch, context, pval);
2701: }
2702: return (cssRule);
1.25 cvs 2703: }
2704:
2705: /*----------------------------------------------------------------------
1.327 vatton 2706: ParseCSSFontSizeAdjust: parse a CSS fontsizeAdjust attr string
2707: we expect the input string describing the attribute to be
2708: xx-small, x-small, small, medium, large, x-large, xx-large
2709: or an absolute size, or an imcrement relative to the parent
1.1 cvs 2710: ----------------------------------------------------------------------*/
1.219 vatton 2711: static char *ParseCSSFontSizeAdjust (Element element, PSchema tsch,
1.327 vatton 2712: PresentationContext context, char *cssRule,
2713: CSSInfoPtr css, ThotBool isHTML)
1.219 vatton 2714: {
1.234 vatton 2715: cssRule = SkipProperty (cssRule, FALSE);
1.222 quint 2716: return (cssRule);
1.219 vatton 2717: }
2718:
2719: /*----------------------------------------------------------------------
1.327 vatton 2720: ParseACSSFontSize: parse a CSS font size attr string
2721: we expect the input string describing the attribute to be
2722: xx-small, x-small, small, medium, large, x-large, xx-large
2723: or an absolute size, or an imcrement relative to the parent.
2724: The parameter check is TRUE if the rule is just checked.
1.219 vatton 2725: ----------------------------------------------------------------------*/
1.270 vatton 2726: static char *ParseACSSFontSize (Element element, PSchema tsch,
1.327 vatton 2727: PresentationContext context, char *cssRule,
2728: CSSInfoPtr css, ThotBool isHTML, ThotBool check)
1.1 cvs 2729: {
1.327 vatton 2730: ElementType elType;
2731: PresentationValue pval;
2732: char *ptr = NULL, *ptr1 = NULL;
2733: ThotBool real, linespace = FALSE;
2734:
2735: pval.typed_data.real = FALSE;
2736: cssRule = SkipBlanksAndComments (cssRule);
2737: /* look for a '/' within the current cssRule */
2738: ptr1 = strchr (cssRule, ';');
2739: ptr = strchr (cssRule, '/');
2740: if (ptr && (ptr1 == NULL || ptr < ptr1))
2741: {
2742: /* keep the line spacing rule */
2743: linespace = TRUE;
2744: ptr[0] = EOS;
2745: }
2746: else
2747: ptr = NULL;
2748: ptr1 = cssRule;
1.289 vatton 2749: /* relative size */
1.327 vatton 2750: if (!strncasecmp (cssRule, "larger", 6))
2751: {
2752: pval.typed_data.unit = UNIT_PERCENT;
2753: pval.typed_data.value = 130;
2754: cssRule += 6;
2755: }
2756: else if (!strncasecmp (cssRule, "smaller", 7))
2757: {
2758: pval.typed_data.unit = UNIT_PERCENT;
2759: pval.typed_data.value = 80;
2760: cssRule += 7;
2761: }
2762: /* absolute size */
2763: else if (!strncasecmp (cssRule, "xx-small", 8))
2764: {
2765: pval.typed_data.unit = UNIT_PT;
1.336 vatton 2766: pval.typed_data.value = 6;
1.327 vatton 2767: cssRule += 8;
2768: }
2769: else if (!strncasecmp (cssRule, "x-small", 7))
2770: {
2771: pval.typed_data.unit = UNIT_PT;
1.336 vatton 2772: pval.typed_data.value = 8;
1.327 vatton 2773: cssRule += 7;
2774: }
2775: else if (!strncasecmp (cssRule, "small", 5))
2776: {
2777: pval.typed_data.unit = UNIT_PT;
1.336 vatton 2778: pval.typed_data.value = 10;
1.327 vatton 2779: cssRule += 5;
2780: }
2781: else if (!strncasecmp (cssRule, "medium", 6))
2782: {
2783: pval.typed_data.unit = UNIT_PT;
2784: pval.typed_data.value = 12;
2785: cssRule += 6;
2786: }
2787: else if (!strncasecmp (cssRule, "large", 5))
2788: {
2789: pval.typed_data.unit = UNIT_PT;
2790: pval.typed_data.value = 13;
2791: cssRule += 5;
2792: }
2793: else if (!strncasecmp (cssRule, "x-large", 7))
2794: {
2795: pval.typed_data.unit = UNIT_PT;
2796: pval.typed_data.value = 14;
2797: cssRule += 7;
2798: }
2799: else if (!strncasecmp (cssRule, "xx-large", 8))
2800: {
2801: pval.typed_data.unit = UNIT_PT;
2802: pval.typed_data.value = 16;
2803: cssRule += 8;
2804: }
2805: else if (!strncasecmp (cssRule, "inherit", 7))
2806: {
2807: pval.typed_data.unit = VALUE_INHERIT;
2808: pval.typed_data.value = 0;
2809: cssRule += 7;
2810: }
2811: /* length or percentage */
2812: else if (!isdigit (*cssRule) && *cssRule != '.')
2813: {
2814: if (!check)
2815: {
2816: cssRule = SkipValue ("Invalid font-size value", cssRule);
2817: cssRule = CheckImportantRule (cssRule, context);
2818: }
2819: return (cssRule);
2820: }
2821: else
2822: {
2823: cssRule = ParseCSSUnit (cssRule, &pval);
2824: if (pval.typed_data.unit == UNIT_BOX)
2825: /* no unit specified */
2826: {
2827: elType = TtaGetElementType(element);
2828: if (!strcmp(TtaGetSSchemaName (elType.ElSSchema), "SVG"))
2829: /* we are working for an SVG element. No unit means pixels */
2830: pval.typed_data.unit = UNIT_PX;
2831: }
2832: if (pval.typed_data.value != 0 &&
2833: (pval.typed_data.unit == UNIT_INVALID ||
2834: pval.typed_data.unit == UNIT_BOX ||
2835: pval.typed_data.value < 0))
2836: /* not a valid value */
2837: return (cssRule);
2838: else if (pval.typed_data.unit == UNIT_REL && pval.typed_data.value > 0)
2839: /* CSS relative sizes have to be higher than Thot ones */
2840: pval.typed_data.value += 1;
2841: else
2842: {
2843: real = pval.typed_data.real;
2844: if (pval.typed_data.unit == UNIT_EM)
2845: {
2846: if (real)
2847: {
2848: pval.typed_data.value /= 10;
2849: pval.typed_data.real = FALSE;
2850: real = FALSE;
2851: }
2852: else
2853: pval.typed_data.value *= 100;
2854: pval.typed_data.unit = UNIT_PERCENT;
2855: }
2856: else if (pval.typed_data.unit == UNIT_XHEIGHT)
2857: {
2858: /* a font size expressed in ex is converted into a percentage.
2859: For example, "3ex" is converted into "180%", supposing
2860: that 1ex is approximately 0.6 times the height of the
2861: current font */
2862: if (real)
2863: {
2864: pval.typed_data.value *= 6;
2865: pval.typed_data.value /= 100;
2866: pval.typed_data.real = FALSE;
2867: real = FALSE;
2868: }
2869: else
2870: pval.typed_data.value *= 60;
2871: pval.typed_data.unit = UNIT_PERCENT;
2872: }
2873: }
2874: }
2875:
2876: /* install the presentation style */
2877: cssRule = CheckImportantRule (cssRule, context);
2878: if (!check && DoApply)
2879: TtaSetStylePresentation (PRSize, element, tsch, context, pval);
2880: if (!check && ptr)
2881: cssRule = ParseCSSLineHeight (element, tsch, context, &ptr[1], css, isHTML);
2882: if (linespace)
2883: *ptr = '/';
2884:
2885: return (cssRule);
2886: }
2887:
2888: /*----------------------------------------------------------------------
2889: ParseCSSFontSize: parse a CSS font size attr string
2890: we expect the input string describing the attribute to be
2891: xx-small, x-small, small, medium, large, x-large, xx-large
2892: or an absolute size, or an imcrement relative to the parent
1.270 vatton 2893: ----------------------------------------------------------------------*/
2894: static char *ParseCSSFontSize (Element element, PSchema tsch,
1.327 vatton 2895: PresentationContext context, char *cssRule,
2896: CSSInfoPtr css, ThotBool isHTML)
1.270 vatton 2897: {
1.299 vatton 2898: char *ptr = cssRule;
1.295 vatton 2899: cssRule = ParseACSSFontSize (element, tsch, context, cssRule, css, isHTML, FALSE);
2900: cssRule = CheckImportantRule (cssRule, context);
1.299 vatton 2901: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid font-size value");
1.295 vatton 2902: return cssRule;
1.270 vatton 2903: }
2904:
2905: /*----------------------------------------------------------------------
1.327 vatton 2906: ParseACSSFontFamily: parse a CSS font family string
2907: we expect the input string describing the attribute to be
2908: a common generic font style name
1.1 cvs 2909: ----------------------------------------------------------------------*/
1.268 vatton 2910: static char *ParseACSSFontFamily (Element element, PSchema tsch,
1.327 vatton 2911: PresentationContext context, char *cssRule,
2912: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2913: {
2914: PresentationValue font;
1.252 vatton 2915: char quoteChar, *p;
1.1 cvs 2916:
2917: font.typed_data.value = 0;
1.184 vatton 2918: font.typed_data.unit = UNIT_REL;
1.1 cvs 2919: font.typed_data.real = FALSE;
1.82 cvs 2920: cssRule = SkipBlanksAndComments (cssRule);
2921: if (*cssRule == '"' || *cssRule == '\'')
1.327 vatton 2922: {
2923: quoteChar = *cssRule;
2924: cssRule++;
2925: }
1.1 cvs 2926: else
1.327 vatton 2927: quoteChar = EOS;
1.1 cvs 2928:
1.293 quint 2929: if (!strncasecmp (cssRule, "inherit", 7) && quoteChar == EOS)
2930: {
2931: font.typed_data.unit = VALUE_INHERIT;
2932: cssRule += 7;
2933: }
2934: else if (!strncasecmp (cssRule, "times", 5) &&
1.327 vatton 2935: (quoteChar == EOS || quoteChar == cssRule[5]))
1.86 cvs 2936: {
1.184 vatton 2937: font.typed_data.value = FontTimes;
1.86 cvs 2938: cssRule += 5;
2939: }
1.92 cvs 2940: else if (!strncasecmp (cssRule, "serif", 5) &&
1.327 vatton 2941: (quoteChar == EOS || quoteChar == cssRule[5]))
1.86 cvs 2942: {
1.184 vatton 2943: font.typed_data.value = FontTimes;
1.86 cvs 2944: cssRule += 5;
1.92 cvs 2945: if (quoteChar != EOS)
1.327 vatton 2946: cssRule++;
1.86 cvs 2947: }
1.92 cvs 2948: else if (!strncasecmp (cssRule, "helvetica", 9) &&
1.327 vatton 2949: (quoteChar == EOS || quoteChar == cssRule[9]))
1.86 cvs 2950: {
1.327 vatton 2951: font.typed_data.value = FontHelvetica;
1.86 cvs 2952: cssRule += 9;
1.92 cvs 2953: if (quoteChar != EOS)
1.327 vatton 2954: cssRule++;
1.86 cvs 2955: }
1.92 cvs 2956: else if (!strncasecmp (cssRule, "verdana", 7) &&
1.327 vatton 2957: (quoteChar == EOS || quoteChar == cssRule[7]))
1.86 cvs 2958: {
1.184 vatton 2959: font.typed_data.value = FontHelvetica;
1.86 cvs 2960: cssRule += 7;
1.92 cvs 2961: if (quoteChar != EOS)
1.327 vatton 2962: cssRule++;
1.86 cvs 2963: }
1.92 cvs 2964: else if (!strncasecmp (cssRule, "sans-serif", 10) &&
1.327 vatton 2965: (quoteChar == EOS || quoteChar == cssRule[10]))
1.86 cvs 2966: {
1.184 vatton 2967: font.typed_data.value = FontHelvetica;
1.86 cvs 2968: cssRule += 10;
1.92 cvs 2969: if (quoteChar != EOS)
1.327 vatton 2970: cssRule++;
1.86 cvs 2971: }
1.268 vatton 2972: else if (!strncasecmp (cssRule, "courier new", 11) &&
1.327 vatton 2973: (quoteChar == EOS || quoteChar == cssRule[11]))
1.268 vatton 2974: {
2975: font.typed_data.value = FontCourier;
2976: cssRule += 11;
2977: if (quoteChar != EOS)
1.327 vatton 2978: cssRule++;
1.268 vatton 2979: }
1.92 cvs 2980: else if (!strncasecmp (cssRule, "courier", 7) &&
1.327 vatton 2981: (quoteChar == EOS || quoteChar == cssRule[7]))
1.86 cvs 2982: {
1.184 vatton 2983: font.typed_data.value = FontCourier;
1.86 cvs 2984: cssRule += 7;
1.92 cvs 2985: if (quoteChar != EOS)
1.327 vatton 2986: cssRule++;
1.86 cvs 2987: }
1.92 cvs 2988: else if (!strncasecmp (cssRule, "monospace", 9) &&
1.327 vatton 2989: (quoteChar == EOS || quoteChar == cssRule[9]))
1.86 cvs 2990: {
1.184 vatton 2991: font.typed_data.value = FontCourier;
1.86 cvs 2992: cssRule += 9;
1.92 cvs 2993: if (quoteChar != EOS)
1.327 vatton 2994: cssRule++;
1.86 cvs 2995: }
1.1 cvs 2996: else
2997: /* unknown font name. Skip it */
2998: {
1.252 vatton 2999: p = cssRule;
1.92 cvs 3000: if (quoteChar != EOS)
1.327 vatton 3001: cssRule = SkipQuotedString (cssRule, quoteChar);
1.86 cvs 3002: else
1.327 vatton 3003: cssRule = SkipWord (cssRule);
1.252 vatton 3004: while (p == cssRule &&
1.327 vatton 3005: *cssRule != ',' && *cssRule != ';' && *cssRule != '}' && *cssRule != EOS)
3006: {
3007: cssRule++;
3008: p = cssRule;
3009: cssRule = SkipWord (cssRule);
3010: }
1.82 cvs 3011: cssRule = SkipBlanksAndComments (cssRule);
3012: if (*cssRule == ',')
1.327 vatton 3013: {
3014: /* recursive call to ParseCSSFontFamily */
3015: cssRule++;
3016: cssRule = ParseACSSFontFamily (element, tsch, context, cssRule, css, isHTML);
3017: return (cssRule);
3018: }
1.1 cvs 3019: }
3020:
1.239 vatton 3021: /* skip other values */
3022: cssRule = SkipBlanksAndComments (cssRule);
3023: while (*cssRule == ',')
3024: {
3025: cssRule++;
3026: cssRule = SkipValue (NULL, cssRule);
3027: cssRule = SkipBlanksAndComments (cssRule);
3028: }
3029:
1.295 vatton 3030: cssRule = CheckImportantRule (cssRule, context);
3031: if ((font.typed_data.value != 0 || font.typed_data.unit == VALUE_INHERIT) &&
3032: DoApply)
3033: /* install the new presentation */
3034: TtaSetStylePresentation (PRFont, element, tsch, context, font);
1.1 cvs 3035: return (cssRule);
3036: }
3037:
3038: /*----------------------------------------------------------------------
1.327 vatton 3039: ParseCSSFontFamily: parse a CSS font family string
3040: we expect the input string describing the attribute to be
3041: a common generic font style name
1.268 vatton 3042: ----------------------------------------------------------------------*/
3043: static char *ParseCSSFontFamily (Element element, PSchema tsch,
1.327 vatton 3044: PresentationContext context, char *cssRule,
3045: CSSInfoPtr css, ThotBool isHTML)
1.268 vatton 3046: {
3047: cssRule = ParseACSSFontFamily (element, tsch, context, cssRule, css, isHTML);
3048: /* skip extra values */
1.301 vatton 3049: while (cssRule && *cssRule != ';' && *cssRule != '}' && *cssRule != EOS)
1.268 vatton 3050: cssRule++;
3051: return (cssRule);
3052: }
3053:
3054: /*----------------------------------------------------------------------
1.327 vatton 3055: ParseACSSFontWeight: parse a CSS font weight string
3056: we expect the input string describing the attribute to be
3057: normal, bold, bolder, lighter, 100, 200, 300, ... 900, inherit.
1.1 cvs 3058: ----------------------------------------------------------------------*/
1.263 vatton 3059: static char *ParseACSSFontWeight (Element element, PSchema tsch,
1.327 vatton 3060: PresentationContext context, char *cssRule,
3061: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 3062: {
1.327 vatton 3063: PresentationValue weight;
1.1 cvs 3064:
1.327 vatton 3065: weight.typed_data.value = 0;
3066: weight.typed_data.unit = UNIT_REL;
3067: weight.typed_data.real = FALSE;
3068: cssRule = SkipBlanksAndComments (cssRule);
3069: if (!strncasecmp (cssRule, "100", 3) && cssRule[3] != '%' &&
3070: !isalpha (cssRule[3]))
3071: {
3072: weight.typed_data.value = -3;
3073: cssRule = SkipWord (cssRule);
3074: }
3075: else if (!strncasecmp (cssRule, "200", 3) && !isalpha (cssRule[3]))
3076: {
3077: weight.typed_data.value = -2;
3078: cssRule = SkipWord (cssRule);
3079: }
3080: else if (!strncasecmp (cssRule, "300", 3) && ! isalpha(cssRule[3]))
3081: {
3082: weight.typed_data.value = -1;
3083: cssRule = SkipWord (cssRule);
3084: }
3085: else if (!strncasecmp (cssRule, "normal", 6) ||
3086: (!strncasecmp (cssRule, "400", 3) && !isalpha (cssRule[3])))
3087: {
3088: weight.typed_data.value = 0;
3089: cssRule = SkipWord (cssRule);
3090: }
3091: else if (!strncasecmp (cssRule, "500", 3) && !isalpha (cssRule[3]))
3092: {
3093: weight.typed_data.value = +1;
3094: cssRule = SkipWord (cssRule);
3095: }
3096: else if (!strncasecmp (cssRule, "600", 3) && !isalpha (cssRule[3]))
3097: {
3098: weight.typed_data.value = +2;
3099: cssRule = SkipWord (cssRule);
3100: }
3101: else if (!strncasecmp (cssRule, "bold", 4) ||
3102: (!strncasecmp (cssRule, "700", 3) && !isalpha (cssRule[3])))
3103: {
3104: weight.typed_data.value = +3;
3105: cssRule = SkipWord (cssRule);
3106: }
3107: else if (!strncasecmp (cssRule, "800", 3) && !isalpha (cssRule[3]))
3108: {
3109: weight.typed_data.value = +4;
3110: cssRule = SkipWord (cssRule);
3111: }
3112: else if (!strncasecmp (cssRule, "900", 3) && !isalpha (cssRule[3]))
3113: {
3114: weight.typed_data.value = +5;
3115: cssRule = SkipWord (cssRule);
3116: }
3117: else if (!strncasecmp (cssRule, "inherit", 7))
3118: {
3119: weight.typed_data.unit = VALUE_INHERIT;
3120: cssRule += 7;
3121: }
3122: else if (!strncasecmp (cssRule, "bolder", 6) ||
3123: !strncasecmp (cssRule, "lighter", 7))
3124: {
3125: /* not implemented */
3126: cssRule = SkipWord (cssRule);
3127: return (cssRule);
3128: }
3129: else
3130: return (cssRule);
3131:
3132: /*
3133: * Here we have to reduce since only two font weight values are supported
3134: * by the Thot presentation API.
3135: */
3136: if (weight.typed_data.unit != VALUE_INHERIT)
3137: {
3138: if (weight.typed_data.value > 0)
3139: weight.typed_data.value = WeightBold;
3140: else
3141: weight.typed_data.value = WeightNormal;
3142: }
3143:
3144: /* install the new presentation */
3145: cssRule = CheckImportantRule (cssRule, context);
3146: if (DoApply)
3147: TtaSetStylePresentation (PRWeight, element, tsch, context, weight);
3148: return (cssRule);
3149: }
3150:
3151: /*----------------------------------------------------------------------
3152: ParseCSSFontWeight: parse a CSS font weight string
3153: we expect the input string describing the attribute to be
3154: normal, bold, bolder, lighter, 100, 200, 300, ... 900, inherit.
1.263 vatton 3155: ----------------------------------------------------------------------*/
3156: static char *ParseCSSFontWeight (Element element, PSchema tsch,
1.327 vatton 3157: PresentationContext context, char *cssRule,
3158: CSSInfoPtr css, ThotBool isHTML)
1.263 vatton 3159: {
3160: char *ptr;
3161:
3162: ptr = cssRule;
3163: cssRule = ParseACSSFontWeight (element, tsch, context, cssRule, css, isHTML);
3164: if (ptr == cssRule)
3165: cssRule = SkipValue ("Invalid font-weight value", cssRule);
1.295 vatton 3166: cssRule = CheckImportantRule (cssRule, context);
1.263 vatton 3167: return (cssRule);
3168: }
3169:
3170: /*----------------------------------------------------------------------
1.327 vatton 3171: ParseACSSFontVariant: parse a CSS font variant string
3172: we expect the input string describing the attribute to be
3173: normal or small-caps
1.1 cvs 3174: ----------------------------------------------------------------------*/
1.263 vatton 3175: static char *ParseACSSFontVariant (Element element, PSchema tsch,
1.327 vatton 3176: PresentationContext context, char *cssRule,
3177: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 3178: {
1.327 vatton 3179: PresentationValue style;
1.1 cvs 3180:
1.327 vatton 3181: style.typed_data.value = 0;
3182: style.typed_data.unit = UNIT_REL;
3183: style.typed_data.real = FALSE;
3184: cssRule = SkipBlanksAndComments (cssRule);
3185: if (!strncasecmp (cssRule, "small-caps", 10))
3186: {
3187: /* Not supported yet */
3188: cssRule = SkipWord (cssRule);
3189: }
3190: else if (!strncasecmp (cssRule, "normal", 6))
3191: {
3192: /* Not supported yet */
3193: cssRule = SkipWord (cssRule);
3194: }
3195: else if (!strncasecmp (cssRule, "inherit", 7))
3196: {
3197: /* Not supported yet */
3198: cssRule = SkipWord (cssRule);
3199: }
1.295 vatton 3200: return (cssRule);
1.263 vatton 3201: }
1.1 cvs 3202:
1.263 vatton 3203: /*----------------------------------------------------------------------
1.327 vatton 3204: ParseCSSFontVariant: parse a CSS font variant string
3205: we expect the input string describing the attribute to be
3206: normal or small-caps
1.263 vatton 3207: ----------------------------------------------------------------------*/
3208: static char *ParseCSSFontVariant (Element element, PSchema tsch,
1.327 vatton 3209: PresentationContext context, char *cssRule,
3210: CSSInfoPtr css, ThotBool isHTML)
1.263 vatton 3211: {
3212: char *ptr;
3213:
3214: ptr = cssRule;
3215: cssRule = ParseACSSFontVariant (element, tsch, context, cssRule, css, isHTML);
3216: if (ptr == cssRule)
3217: cssRule = SkipValue ("Invalid font-variant value", cssRule);
1.295 vatton 3218: cssRule = CheckImportantRule (cssRule, context);
1.263 vatton 3219: return (cssRule);
1.1 cvs 3220: }
3221:
3222:
3223: /*----------------------------------------------------------------------
1.327 vatton 3224: ParseACSSFontStyle: parse a CSS font style string
3225: we expect the input string describing the attribute to be
3226: normal, italic, oblique or inherit
1.1 cvs 3227: ----------------------------------------------------------------------*/
1.263 vatton 3228: static char *ParseACSSFontStyle (Element element, PSchema tsch,
1.327 vatton 3229: PresentationContext context, char *cssRule,
3230: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 3231: {
1.327 vatton 3232: PresentationValue style;
3233: PresentationValue size;
1.1 cvs 3234:
1.327 vatton 3235: style.typed_data.value = 0;
3236: style.typed_data.unit = UNIT_REL;
3237: style.typed_data.real = FALSE;
3238: size.typed_data.value = 0;
3239: size.typed_data.unit = UNIT_REL;
3240: size.typed_data.real = FALSE;
3241: cssRule = SkipBlanksAndComments (cssRule);
3242: if (!strncasecmp (cssRule, "italic", 6))
3243: {
3244: style.typed_data.value = StyleItalics;
3245: cssRule = SkipWord (cssRule);
3246: }
3247: else if (!strncasecmp (cssRule, "oblique", 7))
3248: {
3249: style.typed_data.value = StyleOblique;
3250: cssRule = SkipWord (cssRule);
3251: }
3252: else if (!strncasecmp (cssRule, "normal", 6))
3253: {
3254: style.typed_data.value = StyleRoman;
3255: cssRule = SkipWord (cssRule);
3256: }
3257: else if (!strncasecmp (cssRule, "inherit", 7))
3258: {
3259: style.typed_data.unit = VALUE_INHERIT;
3260: cssRule = SkipWord (cssRule);
3261: }
3262: else
3263: /* invalid font style */
3264: return (cssRule);
3265:
3266: /*
3267: * install the new presentation.
3268: */
3269: cssRule = CheckImportantRule (cssRule, context);
3270: if (DoApply &&
3271: (style.typed_data.value != 0 || style.typed_data.unit == VALUE_INHERIT))
3272: {
3273: TtaSetStylePresentation (PRStyle, element, tsch, context, style);
3274: }
3275: if (size.typed_data.value != 0 && DoApply)
3276: {
3277: PresentationValue previous_size;
3278:
3279: if (!TtaGetStylePresentation (PRSize, element, tsch, context, &previous_size))
3280: {
3281: /* !!!!!!!!!!!!!!!!!!!!!!!! Unit + relative !!!!!!!!!!!!!!!! */
3282: size.typed_data.value += previous_size.typed_data.value;
3283: TtaSetStylePresentation (PRSize, element, tsch, context, size);
3284: }
3285: else
3286: {
3287: size.typed_data.value = 10;
3288: TtaSetStylePresentation (PRSize, element, tsch, context, size);
3289: }
3290: }
3291: return (cssRule);
3292: }
3293:
3294: /*----------------------------------------------------------------------
3295: ParseCSSFontStyle: parse a CSS font style string
3296: we expect the input string describing the attribute to be
3297: italic, oblique or normal
1.263 vatton 3298: ----------------------------------------------------------------------*/
3299: static char *ParseCSSFontStyle (Element element, PSchema tsch,
1.327 vatton 3300: PresentationContext context, char *cssRule,
3301: CSSInfoPtr css, ThotBool isHTML)
1.263 vatton 3302: {
3303: char *ptr;
3304:
3305: ptr = cssRule;
3306: cssRule = ParseACSSFontStyle (element, tsch, context, cssRule, css, isHTML);
3307: if (ptr == cssRule)
3308: cssRule = SkipValue ("Invalid font-style value", cssRule);
1.295 vatton 3309: cssRule = CheckImportantRule (cssRule, context);
1.263 vatton 3310: return (cssRule);
3311: }
3312:
3313: /*----------------------------------------------------------------------
1.59 cvs 3314: ParseCSSFont: parse a CSS font attribute string
3315: we expect the input string describing the attribute to be
3316: !!!!!!
1.1 cvs 3317: ----------------------------------------------------------------------*/
1.79 cvs 3318: static char *ParseCSSFont (Element element, PSchema tsch,
1.327 vatton 3319: PresentationContext context, char *cssRule,
3320: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 3321: {
1.270 vatton 3322: char *ptr, *p;
1.93 vatton 3323: int skippedNL;
1.272 vatton 3324: ThotBool variant = FALSE, style = FALSE, weight = FALSE, found;
1.1 cvs 3325:
1.82 cvs 3326: cssRule = SkipBlanksAndComments (cssRule);
3327: if (!strncasecmp (cssRule, "caption", 7))
1.263 vatton 3328: cssRule += 7;
1.82 cvs 3329: else if (!strncasecmp (cssRule, "icon", 4))
1.263 vatton 3330: cssRule += 4;
1.82 cvs 3331: else if (!strncasecmp (cssRule, "menu", 4))
1.263 vatton 3332: cssRule += 4;
1.82 cvs 3333: else if (!strncasecmp (cssRule, "message-box", 11))
1.263 vatton 3334: cssRule += 11;
1.82 cvs 3335: else if (!strncasecmp (cssRule, "small-caption", 13))
1.263 vatton 3336: cssRule += 13;
1.82 cvs 3337: else if (!strncasecmp (cssRule, "status-bar", 10))
1.263 vatton 3338: cssRule += 10;
3339: else if (!strncasecmp (cssRule, "inherit", 7))
1.293 quint 3340: {
3341: ParseACSSFontStyle (element, tsch, context, cssRule, css, isHTML);
3342: ParseACSSFontVariant (element, tsch, context, cssRule, css, isHTML);
3343: ParseACSSFontWeight (element, tsch, context, cssRule, css, isHTML);
3344: ParseACSSFontSize (element, tsch, context, cssRule, css, isHTML, FALSE);
3345: ParseACSSFontFamily (element, tsch, context, cssRule, css, isHTML);
3346: cssRule += 7;
3347: }
1.1 cvs 3348: else
1.43 cvs 3349: {
1.270 vatton 3350: ptr = NULL;
3351: p = cssRule;
1.301 vatton 3352: while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && p == cssRule)
1.327 vatton 3353: {
3354: found = FALSE;
3355: /* style, variant, weight can appear in any order */
3356: ptr = cssRule;
3357: skippedNL = NewLineSkipped;
3358: cssRule = ParseACSSFontStyle (element, tsch, context, cssRule, css, isHTML);
3359: if (ptr != cssRule)
3360: {
3361: skippedNL = NewLineSkipped;
3362: found = TRUE;
3363: style = TRUE;
3364: }
3365: else
3366: NewLineSkipped = skippedNL;
3367: ptr = cssRule;
3368: cssRule = ParseACSSFontVariant (element, tsch, context, cssRule, css, isHTML);
3369: if (ptr != cssRule)
3370: {
3371: skippedNL = NewLineSkipped;
3372: found = TRUE;
3373: variant = TRUE;
3374: }
3375: else
3376: NewLineSkipped = skippedNL;
3377: ptr = cssRule;
3378: cssRule = ParseACSSFontWeight (element, tsch, context, cssRule, css, isHTML);
3379: if (ptr != cssRule)
3380: {
3381: skippedNL = NewLineSkipped;
3382: found = TRUE;
3383: weight = TRUE;
3384: }
3385: else
3386: NewLineSkipped = skippedNL;
3387: cssRule = SkipBlanksAndComments (cssRule);
3388: p = ParseACSSFontSize (element, tsch, context, cssRule, css, isHTML, TRUE);
3389: NewLineSkipped = skippedNL;
3390: if (!found)
3391: /* break the loop when the current value was not parsed */
3392: p = cssRule + 1;
3393: }
1.263 vatton 3394: ptr = cssRule;
1.270 vatton 3395: /* set default variant, style, weight */
3396: if (!variant)
1.327 vatton 3397: ParseACSSFontVariant (element, tsch, context, "normal", css, isHTML);
1.270 vatton 3398: if (!style)
1.327 vatton 3399: ParseACSSFontStyle (element, tsch, context, "normal", css, isHTML);
1.270 vatton 3400: if (!weight)
1.327 vatton 3401: ParseACSSFontWeight (element, tsch, context, "normal", css, isHTML);
1.270 vatton 3402: /* now parse the font size and the font family */
1.301 vatton 3403: if (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS)
1.327 vatton 3404: cssRule = ParseACSSFontSize (element, tsch, context, cssRule, css, isHTML, FALSE);
1.301 vatton 3405: if (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS)
1.327 vatton 3406: cssRule = ParseACSSFontFamily (element, tsch, context, cssRule, css, isHTML);
1.263 vatton 3407: if (ptr == cssRule)
1.327 vatton 3408: {
3409: cssRule = SkipValue ("Invalid font value", cssRule);
3410: cssRule = CheckImportantRule (cssRule, context);
3411: }
1.43 cvs 3412: }
1.263 vatton 3413: cssRule = SkipBlanksAndComments (cssRule);
1.301 vatton 3414: if (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS)
1.295 vatton 3415: {
3416: cssRule = SkipValue ("Invalid font value", cssRule);
3417: cssRule = CheckImportantRule (cssRule, context);
3418: }
1.43 cvs 3419: return (cssRule);
1.1 cvs 3420: }
3421:
3422: /*----------------------------------------------------------------------
1.59 cvs 3423: ParseCSSTextDecoration: parse a CSS text decor string
3424: we expect the input string describing the attribute to be
1.109 cvs 3425: underline, overline, line-through, blink or none.
1.1 cvs 3426: ----------------------------------------------------------------------*/
1.79 cvs 3427: static char *ParseCSSTextDecoration (Element element, PSchema tsch,
1.327 vatton 3428: PresentationContext context, char *cssRule,
3429: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 3430: {
1.327 vatton 3431: PresentationValue decor;
3432: char *ptr = cssRule;
3433:
3434: decor.typed_data.value = 0;
3435: decor.typed_data.unit = UNIT_REL;
3436: decor.typed_data.real = FALSE;
3437: cssRule = SkipBlanksAndComments (cssRule);
3438: if (!strncasecmp (cssRule, "none", 4))
3439: {
3440: decor.typed_data.value = NoUnderline;
3441: cssRule += 4;
3442: }
3443: else if (!strncasecmp (cssRule, "underline", 9))
3444: {
3445: decor.typed_data.value = Underline;
3446: cssRule += 9;
3447: }
3448: else if (!strncasecmp (cssRule, "overline", 8))
3449: {
3450: decor.typed_data.value = Overline;
3451: cssRule += 8;
3452: }
3453: else if (!strncasecmp (cssRule, "line-through", 12))
3454: {
3455: decor.typed_data.value = CrossOut;
3456: cssRule += 12;
3457: }
3458: else if (!strncasecmp (cssRule, "blink", 5))
3459: {
3460: /* the blink text-decoration attribute is not supported */
3461: cssRule += 5;
3462: }
3463: else if (!strncasecmp (cssRule, "inherit", 7))
3464: {
3465: decor.typed_data.unit = VALUE_INHERIT;
3466: cssRule += 7;
3467: }
3468: else
3469: {
3470: cssRule = SkipValue ("Invalid text-decoration value", cssRule);
3471: cssRule = CheckImportantRule (cssRule, context);
3472: return (cssRule);
3473: }
1.1 cvs 3474:
1.327 vatton 3475: /*
3476: * install the new presentation.
3477: */
3478: cssRule = CheckImportantRule (cssRule, context);
3479: if (DoApply &&
3480: (decor.typed_data.value || decor.typed_data.unit == VALUE_INHERIT))
3481: TtaSetStylePresentation (PRUnderline, element, tsch, context, decor);
3482: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid text-decoration value");
3483: return (cssRule);
1.1 cvs 3484: }
3485:
3486: /*----------------------------------------------------------------------
1.327 vatton 3487: ParseCSSHeight: parse a CSS height attribute
1.1 cvs 3488: ----------------------------------------------------------------------*/
1.79 cvs 3489: static char *ParseCSSHeight (Element element, PSchema tsch,
1.327 vatton 3490: PresentationContext context, char *cssRule,
3491: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 3492: {
1.117 vatton 3493: PresentationValue val;
1.168 vatton 3494: char *ptr;
1.93 vatton 3495:
1.117 vatton 3496: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 3497: ptr = cssRule;
1.117 vatton 3498: /* first parse the attribute string */
1.164 quint 3499: if (!strncasecmp (cssRule, "auto", 4))
3500: {
1.184 vatton 3501: val.typed_data.unit = VALUE_AUTO;
1.164 quint 3502: val.typed_data.value = 0;
3503: val.typed_data.real = FALSE;
1.288 vatton 3504: cssRule += 4;
1.295 vatton 3505: cssRule = CheckImportantRule (cssRule, context);
3506: cssRule = CheckImportantRule (cssRule, context);
1.288 vatton 3507: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid height value");
1.164 quint 3508: }
1.117 vatton 3509: else
1.168 vatton 3510: cssRule = ParseCSSUnit (cssRule, &val);
1.295 vatton 3511:
1.168 vatton 3512: if (val.typed_data.value != 0 &&
1.184 vatton 3513: (val.typed_data.unit == UNIT_INVALID ||
3514: val.typed_data.unit == UNIT_BOX))
1.211 vatton 3515: {
3516: CSSParseError ("height value", ptr, cssRule);
1.212 cvs 3517: val.typed_data.unit = UNIT_PX;
1.211 vatton 3518: }
1.295 vatton 3519: cssRule = CheckImportantRule (cssRule, context);
1.211 vatton 3520: if (DoApply)
1.295 vatton 3521: /* install the new presentation */
3522: TtaSetStylePresentation (PRHeight, element, tsch, context, val);
1.117 vatton 3523: return (cssRule);
1.1 cvs 3524: }
3525:
3526: /*----------------------------------------------------------------------
1.327 vatton 3527: ParseCSSWidth: parse a CSS width attribute
1.1 cvs 3528: ----------------------------------------------------------------------*/
1.79 cvs 3529: static char *ParseCSSWidth (Element element, PSchema tsch,
1.327 vatton 3530: PresentationContext context,
3531: char *cssRule, CSSInfoPtr css,
3532: ThotBool isHTML)
1.1 cvs 3533: {
1.117 vatton 3534: PresentationValue val;
1.168 vatton 3535: char *ptr;
1.93 vatton 3536:
1.117 vatton 3537: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 3538: ptr = cssRule;
1.117 vatton 3539: /* first parse the attribute string */
1.164 quint 3540: if (!strncasecmp (cssRule, "auto", 4))
3541: {
1.184 vatton 3542: val.typed_data.unit = VALUE_AUTO;
1.164 quint 3543: val.typed_data.value = 0;
3544: val.typed_data.real = FALSE;
1.288 vatton 3545: cssRule += 4;
1.295 vatton 3546: cssRule = CheckImportantRule (cssRule, context);
1.288 vatton 3547: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid width value");
1.164 quint 3548: }
1.117 vatton 3549: else
1.327 vatton 3550: cssRule = ParseCSSUnit (cssRule, &val);
1.168 vatton 3551: if (val.typed_data.value != 0 &&
1.184 vatton 3552: (val.typed_data.unit == UNIT_INVALID ||
3553: val.typed_data.unit == UNIT_BOX))
1.211 vatton 3554: {
3555: CSSParseError ("Invalid width value", ptr, cssRule);
1.295 vatton 3556: cssRule = CheckImportantRule (cssRule, context);
1.212 cvs 3557: val.typed_data.unit = UNIT_PX;
1.211 vatton 3558: }
1.295 vatton 3559:
3560: cssRule = CheckImportantRule (cssRule, context);
1.211 vatton 3561: if (DoApply)
1.295 vatton 3562: /* install the new presentation */
3563: TtaSetStylePresentation (PRWidth, element, tsch, context, val);
1.117 vatton 3564: return (cssRule);
1.1 cvs 3565: }
3566:
3567: /*----------------------------------------------------------------------
1.327 vatton 3568: ParseACSSMarginTop: parse a CSS margin-top attribute
1.1 cvs 3569: ----------------------------------------------------------------------*/
1.296 vatton 3570: static char *ParseACSSMarginTop (Element element, PSchema tsch,
1.327 vatton 3571: PresentationContext context,
3572: char *cssRule, CSSInfoPtr css,
3573: ThotBool isHTML)
1.1 cvs 3574: {
3575: PresentationValue margin;
1.168 vatton 3576: char *ptr;
1.1 cvs 3577:
1.82 cvs 3578: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 3579: ptr = cssRule;
1.1 cvs 3580: /* first parse the attribute string */
1.164 quint 3581: if (!strncasecmp (cssRule, "auto", 4))
3582: {
1.184 vatton 3583: margin.typed_data.unit = VALUE_AUTO;
1.164 quint 3584: margin.typed_data.value = 0;
3585: margin.typed_data.real = FALSE;
1.288 vatton 3586: cssRule += 4;
1.295 vatton 3587: cssRule = CheckImportantRule (cssRule, context);
1.164 quint 3588: }
3589: else
1.168 vatton 3590: cssRule = ParseCSSUnit (cssRule, &margin);
1.295 vatton 3591:
3592: cssRule = CheckImportantRule (cssRule, context);
1.168 vatton 3593: if (margin.typed_data.value != 0 &&
1.184 vatton 3594: (margin.typed_data.unit == UNIT_INVALID ||
3595: margin.typed_data.unit == UNIT_BOX))
1.169 vatton 3596: CSSParseError ("Invalid margin-top value", ptr, cssRule);
1.168 vatton 3597: else if (DoApply)
1.295 vatton 3598: TtaSetStylePresentation (PRMarginTop, element, tsch, context, margin);
1.1 cvs 3599: return (cssRule);
3600: }
3601:
3602: /*----------------------------------------------------------------------
1.327 vatton 3603: ParseCSSMarginTop: parse a CSS margin-top attribute
1.296 vatton 3604: ----------------------------------------------------------------------*/
3605: static char *ParseCSSMarginTop (Element element, PSchema tsch,
1.327 vatton 3606: PresentationContext context,
3607: char *cssRule, CSSInfoPtr css,
3608: ThotBool isHTML)
1.296 vatton 3609: {
3610: char *ptr = cssRule;
3611:
3612: cssRule = ParseACSSMarginTop (element, tsch, context, ptr, css, isHTML);
3613: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid margin-top value");
3614: return (cssRule);
3615: }
3616:
3617: /*----------------------------------------------------------------------
3618: ParseACSSMarginBottom: parse a CSS margin-bottom attribute
1.1 cvs 3619: ----------------------------------------------------------------------*/
1.296 vatton 3620: static char *ParseACSSMarginBottom (Element element, PSchema tsch,
1.327 vatton 3621: PresentationContext context,
3622: char *cssRule, CSSInfoPtr css,
3623: ThotBool isHTML)
1.1 cvs 3624: {
3625: PresentationValue margin;
1.168 vatton 3626: char *ptr;
1.1 cvs 3627:
1.82 cvs 3628: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 3629: ptr = cssRule;
1.1 cvs 3630: /* first parse the attribute string */
1.164 quint 3631: if (!strncasecmp (cssRule, "auto", 4))
3632: {
1.184 vatton 3633: margin.typed_data.unit = VALUE_AUTO;
1.164 quint 3634: margin.typed_data.value = 0;
3635: margin.typed_data.real = FALSE;
1.288 vatton 3636: cssRule += 4;
1.295 vatton 3637: cssRule = CheckImportantRule (cssRule, context);
1.164 quint 3638: }
3639: else
1.168 vatton 3640: cssRule = ParseCSSUnit (cssRule, &margin);
1.295 vatton 3641:
3642: cssRule = CheckImportantRule (cssRule, context);
1.168 vatton 3643: if (margin.typed_data.value != 0 &&
1.184 vatton 3644: (margin.typed_data.unit == UNIT_INVALID ||
3645: margin.typed_data.unit == UNIT_BOX))
1.169 vatton 3646: CSSParseError ("Invalid margin-bottom value", ptr, cssRule);
1.168 vatton 3647: else if (DoApply)
1.295 vatton 3648: TtaSetStylePresentation (PRMarginBottom, element, tsch, context, margin);
1.1 cvs 3649: return (cssRule);
3650: }
3651:
3652: /*----------------------------------------------------------------------
1.296 vatton 3653: ParseCSSMarginBottom: parse a CSS margin-bottom attribute
3654: ----------------------------------------------------------------------*/
3655: static char *ParseCSSMarginBottom (Element element, PSchema tsch,
1.327 vatton 3656: PresentationContext context,
3657: char *cssRule, CSSInfoPtr css,
3658: ThotBool isHTML)
1.296 vatton 3659: {
3660: char *ptr = cssRule;
3661:
3662: cssRule = ParseACSSMarginBottom (element, tsch, context, ptr, css, isHTML);
3663: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid margin-bottom value");
3664: return (cssRule);
3665: }
3666:
3667: /*----------------------------------------------------------------------
3668: ParseACSSMarginLeft: parse a CSS margin-left attribute string
1.1 cvs 3669: ----------------------------------------------------------------------*/
1.296 vatton 3670: static char *ParseACSSMarginLeft (Element element, PSchema tsch,
1.327 vatton 3671: PresentationContext context,
3672: char *cssRule, CSSInfoPtr css,
3673: ThotBool isHTML)
1.1 cvs 3674: {
3675: PresentationValue margin;
1.168 vatton 3676: char *ptr;
1.1 cvs 3677:
1.82 cvs 3678: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 3679: ptr = cssRule;
1.1 cvs 3680: /* first parse the attribute string */
1.164 quint 3681: if (!strncasecmp (cssRule, "auto", 4))
3682: {
1.184 vatton 3683: margin.typed_data.unit = VALUE_AUTO;
1.164 quint 3684: margin.typed_data.value = 0;
3685: margin.typed_data.real = FALSE;
1.288 vatton 3686: cssRule += 4;
1.295 vatton 3687: cssRule = CheckImportantRule (cssRule, context);
1.164 quint 3688: }
3689: else
1.168 vatton 3690: cssRule = ParseCSSUnit (cssRule, &margin);
1.295 vatton 3691:
3692: cssRule = CheckImportantRule (cssRule, context);
1.168 vatton 3693: if (margin.typed_data.value != 0 &&
1.184 vatton 3694: (margin.typed_data.unit == UNIT_INVALID ||
3695: margin.typed_data.unit == UNIT_BOX))
1.169 vatton 3696: CSSParseError ("Invalid margin-left value", ptr, cssRule);
1.295 vatton 3697: else if (DoApply && margin.typed_data.unit != UNIT_INVALID && DoApply)
1.327 vatton 3698: TtaSetStylePresentation (PRMarginLeft, element, tsch, context, margin);
1.1 cvs 3699: return (cssRule);
3700: }
3701:
3702: /*----------------------------------------------------------------------
1.296 vatton 3703: ParseCSSMarginBottom: parse a CSS margin-bottom attribute
3704: ----------------------------------------------------------------------*/
3705: static char *ParseCSSMarginLeft (Element element, PSchema tsch,
1.327 vatton 3706: PresentationContext context,
3707: char *cssRule, CSSInfoPtr css,
3708: ThotBool isHTML)
1.296 vatton 3709: {
3710: char *ptr = cssRule;
3711:
3712: cssRule = ParseACSSMarginLeft (element, tsch, context, ptr, css, isHTML);
3713: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid margin-left value");
3714: return (cssRule);
3715: }
3716:
3717:
3718: /*----------------------------------------------------------------------
3719: ParseACSSMarginRight: parse a CSS margin-right attribute string
1.1 cvs 3720: ----------------------------------------------------------------------*/
1.296 vatton 3721: static char *ParseACSSMarginRight (Element element, PSchema tsch,
1.327 vatton 3722: PresentationContext context,
3723: char *cssRule, CSSInfoPtr css,
3724: ThotBool isHTML)
1.1 cvs 3725: {
3726: PresentationValue margin;
1.168 vatton 3727: char *ptr;
1.1 cvs 3728:
1.82 cvs 3729: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 3730: ptr = cssRule;
1.1 cvs 3731: /* first parse the attribute string */
1.164 quint 3732: if (!strncasecmp (cssRule, "auto", 4))
3733: {
1.184 vatton 3734: margin.typed_data.unit = VALUE_AUTO;
1.164 quint 3735: margin.typed_data.value = 0;
3736: margin.typed_data.real = FALSE;
1.288 vatton 3737: cssRule += 4;
1.295 vatton 3738: cssRule = CheckImportantRule (cssRule, context);
1.164 quint 3739: }
3740: else
1.168 vatton 3741: cssRule = ParseCSSUnit (cssRule, &margin);
1.295 vatton 3742:
3743: cssRule = CheckImportantRule (cssRule, context);
1.168 vatton 3744: if (margin.typed_data.value != 0 &&
1.184 vatton 3745: (margin.typed_data.unit == UNIT_INVALID ||
3746: margin.typed_data.unit == UNIT_BOX))
1.169 vatton 3747: CSSParseError ("Invalid margin-right value", ptr, cssRule);
1.168 vatton 3748: else if (DoApply)
1.295 vatton 3749: TtaSetStylePresentation (PRMarginRight, element, tsch, context, margin);
1.1 cvs 3750: return (cssRule);
3751: }
3752:
3753: /*----------------------------------------------------------------------
1.296 vatton 3754: ParseCSSMarginRight: parse a CSS margin-right attribute string
3755: ----------------------------------------------------------------------*/
3756: static char *ParseCSSMarginRight (Element element, PSchema tsch,
1.327 vatton 3757: PresentationContext context,
3758: char *cssRule, CSSInfoPtr css,
3759: ThotBool isHTML)
1.296 vatton 3760: {
3761: char *ptr = cssRule;
3762:
1.297 vatton 3763: cssRule = ParseACSSMarginRight (element, tsch, context, ptr, css, isHTML);
1.296 vatton 3764: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid margin-right value");
3765: return (cssRule);
3766: }
3767:
3768: /*----------------------------------------------------------------------
1.59 cvs 3769: ParseCSSMargin: parse a CSS margin attribute string
1.1 cvs 3770: ----------------------------------------------------------------------*/
1.79 cvs 3771: static char *ParseCSSMargin (Element element, PSchema tsch,
1.327 vatton 3772: PresentationContext context,
3773: char *cssRule, CSSInfoPtr css,
3774: ThotBool isHTML)
1.1 cvs 3775: {
1.79 cvs 3776: char *ptrT, *ptrR, *ptrB, *ptrL;
1.93 vatton 3777: int skippedNL;
1.1 cvs 3778:
1.82 cvs 3779: ptrT = SkipBlanksAndComments (cssRule);
1.1 cvs 3780: /* First parse Margin-Top */
1.296 vatton 3781: ptrR = ParseACSSMarginTop (element, tsch, context, ptrT, css, isHTML);
1.82 cvs 3782: ptrR = SkipBlanksAndComments (ptrR);
1.301 vatton 3783: if (*ptrR == ';' || *ptrR == '}' || *ptrR == EOS || *ptrR == ',')
1.1 cvs 3784: {
1.93 vatton 3785: skippedNL = NewLineSkipped;
1.1 cvs 3786: cssRule = ptrR;
3787: /* apply the Margin-Top to all */
1.296 vatton 3788: ptrR = ParseACSSMarginRight (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 3789: NewLineSkipped = skippedNL;
1.296 vatton 3790: ptrR = ParseACSSMarginBottom (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 3791: NewLineSkipped = skippedNL;
1.296 vatton 3792: ptrR = ParseACSSMarginLeft (element, tsch, context, ptrT, css, isHTML);
1.1 cvs 3793: }
3794: else
3795: {
3796: /* parse Margin-Right */
1.296 vatton 3797: ptrB = ParseACSSMarginRight (element, tsch, context, ptrR, css, isHTML);
1.82 cvs 3798: ptrB = SkipBlanksAndComments (ptrB);
1.301 vatton 3799: if (*ptrB == ';' || *ptrB == '}' || *ptrB == EOS || *ptrB == ',')
1.327 vatton 3800: {
3801: skippedNL = NewLineSkipped;
3802: cssRule = ptrB;
3803: /* apply the Margin-Top to Margin-Bottom */
3804: ptrB = ParseACSSMarginBottom (element, tsch, context, ptrT, css, isHTML);
3805: NewLineSkipped = skippedNL;
3806: /* apply the Margin-Right to Margin-Left */
3807: ptrB = ParseACSSMarginLeft (element, tsch, context, ptrR, css, isHTML);
3808: }
1.1 cvs 3809: else
1.327 vatton 3810: {
3811: /* parse Margin-Bottom */
3812: ptrL = ParseACSSMarginBottom (element, tsch, context, ptrB, css, isHTML);
3813: ptrL = SkipBlanksAndComments (ptrL);
3814: if (*ptrL == ';' || *ptrL == '}' || *ptrL == EOS || *ptrL == ',')
3815: {
3816: cssRule = ptrL;
3817: /* apply the Margin-Right to Margin-Left */
3818: ptrL = ParseACSSMarginLeft (element, tsch, context, ptrR, css, isHTML);
3819: }
3820: else
3821: /* parse Margin-Left */
3822: cssRule = ParseACSSMarginLeft (element, tsch, context, ptrL, css, isHTML);
3823: cssRule = SkipBlanksAndComments (cssRule);
3824: }
1.1 cvs 3825: }
3826: return (cssRule);
3827: }
3828:
3829: /*----------------------------------------------------------------------
1.327 vatton 3830: ParseCSSPaddingTop: parse a CSS PaddingTop attribute string
1.1 cvs 3831: ----------------------------------------------------------------------*/
1.79 cvs 3832: static char *ParseCSSPaddingTop (Element element, PSchema tsch,
1.327 vatton 3833: PresentationContext context,
3834: char *cssRule, CSSInfoPtr css,
3835: ThotBool isHTML)
1.1 cvs 3836: {
1.43 cvs 3837: PresentationValue padding;
1.168 vatton 3838: char *ptr;
1.43 cvs 3839:
1.82 cvs 3840: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 3841: ptr = cssRule;
1.43 cvs 3842: /* first parse the attribute string */
3843: cssRule = ParseCSSUnit (cssRule, &padding);
1.295 vatton 3844:
3845: cssRule = CheckImportantRule (cssRule, context);
1.168 vatton 3846: if (padding.typed_data.value != 0 &&
1.184 vatton 3847: (padding.typed_data.unit == UNIT_INVALID ||
3848: padding.typed_data.unit == UNIT_BOX))
1.168 vatton 3849: {
1.169 vatton 3850: CSSParseError ("Invalid padding-top value", ptr, cssRule);
1.168 vatton 3851: padding.typed_data.value = 0;
3852: }
3853: else if (DoApply)
1.295 vatton 3854: TtaSetStylePresentation (PRPaddingTop, element, tsch, context, padding);
1.1 cvs 3855: return (cssRule);
3856: }
3857:
3858: /*----------------------------------------------------------------------
1.59 cvs 3859: ParseCSSPaddingBottom: parse a CSS PaddingBottom attribute string
1.1 cvs 3860: ----------------------------------------------------------------------*/
1.79 cvs 3861: static char *ParseCSSPaddingBottom (Element element, PSchema tsch,
1.327 vatton 3862: PresentationContext context,
3863: char *cssRule, CSSInfoPtr css,
3864: ThotBool isHTML)
1.1 cvs 3865: {
1.43 cvs 3866: PresentationValue padding;
1.168 vatton 3867: char *ptr;
1.43 cvs 3868:
1.82 cvs 3869: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 3870: ptr = cssRule;
1.43 cvs 3871: /* first parse the attribute string */
3872: cssRule = ParseCSSUnit (cssRule, &padding);
1.168 vatton 3873: if (padding.typed_data.value == 0)
1.184 vatton 3874: padding.typed_data.unit = UNIT_EM;
1.295 vatton 3875:
3876: cssRule = CheckImportantRule (cssRule, context);
1.168 vatton 3877: if (padding.typed_data.value != 0 &&
1.184 vatton 3878: (padding.typed_data.unit == UNIT_INVALID ||
3879: padding.typed_data.unit == UNIT_BOX))
1.168 vatton 3880: {
1.169 vatton 3881: CSSParseError ("Invalid padding-bottom value", ptr, cssRule);
1.168 vatton 3882: padding.typed_data.value = 0;
3883: }
3884: else if (DoApply)
1.295 vatton 3885: TtaSetStylePresentation (PRPaddingBottom, element, tsch, context, padding);
1.1 cvs 3886: return (cssRule);
3887: }
3888:
3889: /*----------------------------------------------------------------------
1.59 cvs 3890: ParseCSSPaddingLeft: parse a CSS PaddingLeft attribute string.
1.1 cvs 3891: ----------------------------------------------------------------------*/
1.79 cvs 3892: static char *ParseCSSPaddingLeft (Element element, PSchema tsch,
1.327 vatton 3893: PresentationContext context,
3894: char *cssRule, CSSInfoPtr css,
3895: ThotBool isHTML)
1.1 cvs 3896: {
1.43 cvs 3897: PresentationValue padding;
1.168 vatton 3898: char *ptr;
1.43 cvs 3899:
1.82 cvs 3900: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 3901: ptr = cssRule;
1.43 cvs 3902: /* first parse the attribute string */
3903: cssRule = ParseCSSUnit (cssRule, &padding);
1.168 vatton 3904: if (padding.typed_data.value == 0)
1.184 vatton 3905: padding.typed_data.unit = UNIT_EM;
1.295 vatton 3906:
3907: cssRule = CheckImportantRule (cssRule, context);
1.168 vatton 3908: if (padding.typed_data.value != 0 &&
1.184 vatton 3909: (padding.typed_data.unit == UNIT_INVALID ||
3910: padding.typed_data.unit == UNIT_BOX))
1.168 vatton 3911: {
1.169 vatton 3912: CSSParseError ("Invalid padding-left value", ptr, cssRule);
1.168 vatton 3913: padding.typed_data.value = 0;
3914: }
3915: else if (DoApply)
1.295 vatton 3916: TtaSetStylePresentation (PRPaddingLeft, element, tsch, context, padding);
1.1 cvs 3917: return (cssRule);
3918: }
3919:
3920: /*----------------------------------------------------------------------
1.59 cvs 3921: ParseCSSPaddingRight: parse a CSS PaddingRight attribute string.
1.1 cvs 3922: ----------------------------------------------------------------------*/
1.79 cvs 3923: static char *ParseCSSPaddingRight (Element element, PSchema tsch,
1.327 vatton 3924: PresentationContext context,
3925: char *cssRule, CSSInfoPtr css,
3926: ThotBool isHTML)
1.1 cvs 3927: {
1.43 cvs 3928: PresentationValue padding;
1.168 vatton 3929: char *ptr;
1.43 cvs 3930:
1.82 cvs 3931: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 3932: ptr = cssRule;
1.43 cvs 3933: /* first parse the attribute string */
3934: cssRule = ParseCSSUnit (cssRule, &padding);
1.168 vatton 3935: if (padding.typed_data.value == 0)
1.184 vatton 3936: padding.typed_data.unit = UNIT_EM;
1.295 vatton 3937:
3938: cssRule = CheckImportantRule (cssRule, context);
1.168 vatton 3939: if (padding.typed_data.value != 0 &&
1.184 vatton 3940: (padding.typed_data.unit == UNIT_INVALID ||
3941: padding.typed_data.unit == UNIT_BOX))
1.168 vatton 3942: {
1.169 vatton 3943: CSSParseError ("Invalid padding-right value", ptr, cssRule);
1.168 vatton 3944: padding.typed_data.value = 0;
3945: }
3946: else if (DoApply)
1.295 vatton 3947: TtaSetStylePresentation (PRPaddingRight, element, tsch, context, padding);
1.1 cvs 3948: return (cssRule);
3949: }
3950:
3951: /*----------------------------------------------------------------------
1.327 vatton 3952: ParseCSSPadding: parse a CSS padding attribute string.
1.1 cvs 3953: ----------------------------------------------------------------------*/
1.79 cvs 3954: static char *ParseCSSPadding (Element element, PSchema tsch,
1.327 vatton 3955: PresentationContext context,
3956: char *cssRule, CSSInfoPtr css,
3957: ThotBool isHTML)
1.1 cvs 3958: {
1.79 cvs 3959: char *ptrT, *ptrR, *ptrB, *ptrL;
1.93 vatton 3960: int skippedNL;
1.43 cvs 3961:
1.82 cvs 3962: ptrT = SkipBlanksAndComments (cssRule);
1.43 cvs 3963: /* First parse Padding-Top */
3964: ptrR = ParseCSSPaddingTop (element, tsch, context, ptrT, css, isHTML);
1.82 cvs 3965: ptrR = SkipBlanksAndComments (ptrR);
3966: if (*ptrR == ';' || *ptrR == EOS || *ptrR == ',')
1.43 cvs 3967: {
1.93 vatton 3968: skippedNL = NewLineSkipped;
1.43 cvs 3969: cssRule = ptrR;
3970: /* apply the Padding-Top to all */
3971: ptrR = ParseCSSPaddingRight (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 3972: NewLineSkipped = skippedNL;
1.43 cvs 3973: ptrR = ParseCSSPaddingBottom (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 3974: NewLineSkipped = skippedNL;
1.43 cvs 3975: ptrR = ParseCSSPaddingLeft (element, tsch, context, ptrT, css, isHTML);
3976: }
3977: else
3978: {
3979: /* parse Padding-Right */
3980: ptrB = ParseCSSPaddingRight (element, tsch, context, ptrR, css, isHTML);
1.82 cvs 3981: ptrB = SkipBlanksAndComments (ptrB);
3982: if (*ptrB == ';' || *ptrB == EOS || *ptrB == ',')
1.327 vatton 3983: {
3984: skippedNL = NewLineSkipped;
3985: cssRule = ptrB;
3986: /* apply the Padding-Top to Padding-Bottom */
3987: ptrB = ParseCSSPaddingBottom (element, tsch, context, ptrT, css, isHTML);
3988: NewLineSkipped = skippedNL;
3989: /* apply the Padding-Right to Padding-Left */
3990: ptrB = ParseCSSPaddingLeft (element, tsch, context, ptrR, css, isHTML);
3991: }
1.43 cvs 3992: else
1.327 vatton 3993: {
3994: /* parse Padding-Bottom */
3995: ptrL = ParseCSSPaddingBottom (element, tsch, context, ptrB, css, isHTML);
3996: ptrL = SkipBlanksAndComments (ptrL);
3997: if (*ptrL == ';' || *ptrL == EOS || *ptrL == ',')
3998: {
3999: cssRule = ptrL;
4000: /* apply the Padding-Right to Padding-Left */
4001: ptrL = ParseCSSPaddingLeft (element, tsch, context, ptrR, css, isHTML);
4002: }
4003: else
4004: /* parse Padding-Left */
4005: cssRule = ParseCSSPaddingLeft (element, tsch, context, ptrL, css, isHTML);
4006: cssRule = SkipBlanksAndComments (cssRule);
4007: }
1.43 cvs 4008: }
1.1 cvs 4009: return (cssRule);
4010: }
4011:
4012: /*----------------------------------------------------------------------
1.327 vatton 4013: ParseCSSForeground: parse a CSS foreground attribute
1.1 cvs 4014: ----------------------------------------------------------------------*/
1.79 cvs 4015: static char *ParseCSSForeground (Element element, PSchema tsch,
1.327 vatton 4016: PresentationContext context,
4017: char *cssRule,
4018: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 4019: {
1.117 vatton 4020: PresentationValue best;
1.262 vatton 4021: char *p;
1.1 cvs 4022:
1.262 vatton 4023: p = cssRule;
1.117 vatton 4024: cssRule = ParseCSSColor (cssRule, &best);
1.295 vatton 4025: cssRule = CheckImportantRule (cssRule, context);
1.184 vatton 4026: if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.327 vatton 4027: {
4028: if (*cssRule != EOS && *cssRule !=';')
4029: {
4030: cssRule = SkipProperty (cssRule, FALSE);
4031: CSSParseError ("Invalid value", p, cssRule);
4032: }
4033: else
4034: /* install the new presentation */
4035: TtaSetStylePresentation (PRForeground, element, tsch, context, best);
4036: }
4037: return (cssRule);
1.1 cvs 4038: }
4039:
4040: /*----------------------------------------------------------------------
1.59 cvs 4041: ParseCSSBackgroundColor: parse a CSS background color attribute
1.1 cvs 4042: ----------------------------------------------------------------------*/
1.79 cvs 4043: static char *ParseCSSBackgroundColor (Element element, PSchema tsch,
1.327 vatton 4044: PresentationContext context,
4045: char *cssRule,
4046: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 4047: {
4048: PresentationValue best;
4049:
1.184 vatton 4050: best.typed_data.unit = UNIT_INVALID;
1.1 cvs 4051: best.typed_data.real = FALSE;
1.198 vatton 4052: if (!strncasecmp (cssRule, "transparent", 11))
1.1 cvs 4053: {
1.184 vatton 4054: best.typed_data.value = PATTERN_NONE;
4055: best.typed_data.unit = UNIT_REL;
1.295 vatton 4056: cssRule = SkipWord (cssRule);
4057: cssRule = CheckImportantRule (cssRule, context);
1.116 vatton 4058: if (DoApply)
1.327 vatton 4059: TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
4060: }
1.1 cvs 4061: else
4062: {
4063: cssRule = ParseCSSColor (cssRule, &best);
1.295 vatton 4064: cssRule = CheckImportantRule (cssRule, context);
1.184 vatton 4065: if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.327 vatton 4066: {
4067: /* install the new presentation. */
4068: TtaSetStylePresentation (PRBackground, element, tsch, context, best);
4069: /* thot specificity: need to set fill pattern for background color */
4070: best.typed_data.value = PATTERN_BACKGROUND;
4071: best.typed_data.unit = UNIT_REL;
4072: TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
4073: best.typed_data.value = 1;
4074: best.typed_data.unit = UNIT_REL;
4075: TtaSetStylePresentation (PRShowBox, element, tsch, context, best);
4076: }
1.1 cvs 4077: }
4078: return (cssRule);
4079: }
4080:
1.63 cvs 4081: /*----------------------------------------------------------------------
1.65 cvs 4082: ParseSVGStroke: parse a SVG stroke property
4083: ----------------------------------------------------------------------*/
1.79 cvs 4084: static char *ParseSVGStroke (Element element, PSchema tsch,
1.327 vatton 4085: PresentationContext context, char *cssRule,
4086: CSSInfoPtr css, ThotBool isHTML)
1.65 cvs 4087: {
4088: PresentationValue best;
1.245 quint 4089: char *url;
1.65 cvs 4090:
1.184 vatton 4091: best.typed_data.unit = UNIT_INVALID;
1.65 cvs 4092: best.typed_data.real = FALSE;
1.82 cvs 4093: if (!strncasecmp (cssRule, "none", 4))
1.65 cvs 4094: {
4095: best.typed_data.value = -2; /* -2 means transparent */
1.184 vatton 4096: best.typed_data.unit = UNIT_REL;
1.65 cvs 4097: cssRule = SkipWord (cssRule);
4098: }
1.245 quint 4099: else if (!strncasecmp (cssRule, "currentColor", 12))
4100: {
1.293 quint 4101: best.typed_data.unit = VALUE_INHERIT;
4102: cssRule = SkipWord (cssRule);
1.245 quint 4103: }
4104: else if (!strncasecmp (cssRule, "url", 3))
4105: {
4106: cssRule += 3;
4107: cssRule = ParseCSSUrl (cssRule, &url);
4108: /* **** do something with the url ***** */;
4109: TtaFreeMemory (url);
4110: /* **** caution: another color value may follow the uri (in case
1.327 vatton 4111: the uri could ne be dereferenced) *** */
1.245 quint 4112: }
1.65 cvs 4113: else
1.293 quint 4114: cssRule = ParseCSSColor (cssRule, &best);
4115:
1.295 vatton 4116: cssRule = CheckImportantRule (cssRule, context);
1.293 quint 4117: if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.295 vatton 4118: /* install the new presentation */
4119: TtaSetStylePresentation (PRForeground, element, tsch, context, best);
1.65 cvs 4120: return (cssRule);
4121: }
4122:
4123: /*----------------------------------------------------------------------
1.63 cvs 4124: ParseSVGFill: parse a SVG fill property
4125: ----------------------------------------------------------------------*/
1.79 cvs 4126: static char *ParseSVGFill (Element element, PSchema tsch,
1.327 vatton 4127: PresentationContext context, char *cssRule,
4128: CSSInfoPtr css, ThotBool isHTML)
1.63 cvs 4129: {
4130: PresentationValue best;
1.245 quint 4131: char *url;
1.63 cvs 4132:
1.184 vatton 4133: best.typed_data.unit = UNIT_INVALID;
1.63 cvs 4134: best.typed_data.real = FALSE;
1.82 cvs 4135: if (!strncasecmp (cssRule, "none", 4))
1.63 cvs 4136: {
1.184 vatton 4137: best.typed_data.value = PATTERN_NONE;
4138: best.typed_data.unit = UNIT_REL;
1.295 vatton 4139: cssRule = CheckImportantRule (cssRule, context);
1.116 vatton 4140: if (DoApply)
1.327 vatton 4141: TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
1.65 cvs 4142: cssRule = SkipWord (cssRule);
1.294 vatton 4143: return (cssRule);
1.63 cvs 4144: }
1.245 quint 4145: else if (!strncasecmp (cssRule, "currentColor", 12))
4146: {
1.293 quint 4147: best.typed_data.unit = VALUE_INHERIT;
4148: cssRule = SkipWord (cssRule);
1.245 quint 4149: }
4150: else if (!strncasecmp (cssRule, "url", 3))
4151: {
4152: cssRule += 3;
4153: cssRule = ParseCSSUrl (cssRule, &url);
4154: /* **** do something with the url ***** */;
4155: TtaFreeMemory (url);
4156: /* **** caution: another color value may follow the uri (in case
1.327 vatton 4157: the uri could ne be dereferenced) *** */
1.245 quint 4158: }
1.63 cvs 4159: else
1.327 vatton 4160: cssRule = ParseCSSColor (cssRule, &best);
1.293 quint 4161:
1.295 vatton 4162: cssRule = CheckImportantRule (cssRule, context);
1.293 quint 4163: if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.63 cvs 4164: {
1.293 quint 4165: /* install the new presentation. */
4166: TtaSetStylePresentation (PRBackground, element, tsch, context, best);
4167: /* thot specificity: need to set fill pattern for background color */
4168: best.typed_data.value = PATTERN_BACKGROUND;
4169: best.typed_data.unit = UNIT_REL;
4170: TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
1.63 cvs 4171: }
4172: return (cssRule);
4173: }
1.161 quint 4174:
1.155 cheyroul 4175: /*----------------------------------------------------------------------
1.346 ! quint 4176: ParseSVGOpacity: parse a SVG opacity property
1.155 cheyroul 4177: ----------------------------------------------------------------------*/
4178: static char *ParseSVGOpacity (Element element, PSchema tsch,
1.327 vatton 4179: PresentationContext context, char *cssRule,
4180: CSSInfoPtr css, ThotBool isHTML)
1.155 cheyroul 4181: {
4182: PresentationValue best;
1.63 cvs 4183:
1.184 vatton 4184: best.typed_data.unit = UNIT_INVALID;
1.155 cheyroul 4185: best.typed_data.real = FALSE;
4186: cssRule = ParseClampedUnit (cssRule, &best);
1.295 vatton 4187: cssRule = CheckImportantRule (cssRule, context);
1.155 cheyroul 4188: if (DoApply)
1.295 vatton 4189: /* install the new presentation. */
4190: TtaSetStylePresentation (PROpacity, element, tsch, context, best);
1.155 cheyroul 4191: return (cssRule);
4192: }
1.346 ! quint 4193:
1.170 cheyroul 4194: /*----------------------------------------------------------------------
1.346 ! quint 4195: ParseSVGStrokeOpacity: parse a SVG stroke-opacity property
1.170 cheyroul 4196: ----------------------------------------------------------------------*/
4197: static char *ParseSVGStrokeOpacity (Element element, PSchema tsch,
1.327 vatton 4198: PresentationContext context, char *cssRule,
4199: CSSInfoPtr css, ThotBool isHTML)
1.170 cheyroul 4200: {
4201: PresentationValue best;
1.161 quint 4202:
1.184 vatton 4203: best.typed_data.unit = UNIT_INVALID;
1.170 cheyroul 4204: best.typed_data.real = FALSE;
4205: cssRule = ParseClampedUnit (cssRule, &best);
1.295 vatton 4206: cssRule = CheckImportantRule (cssRule, context);
1.170 cheyroul 4207: if (DoApply)
1.295 vatton 4208: /* install the new presentation. */
4209: TtaSetStylePresentation (PRStrokeOpacity, element, tsch, context, best);
1.170 cheyroul 4210: return (cssRule);
4211: }
1.346 ! quint 4212:
1.170 cheyroul 4213: /*----------------------------------------------------------------------
1.346 ! quint 4214: ParseSVGFillOpacity: parse a SVG fil-opacityl property
1.170 cheyroul 4215: ----------------------------------------------------------------------*/
4216: static char *ParseSVGFillOpacity (Element element, PSchema tsch,
1.327 vatton 4217: PresentationContext context, char *cssRule,
4218: CSSInfoPtr css, ThotBool isHTML)
1.170 cheyroul 4219: {
4220: PresentationValue best;
4221:
1.184 vatton 4222: best.typed_data.unit = UNIT_INVALID;
1.170 cheyroul 4223: best.typed_data.real = FALSE;
4224: cssRule = ParseClampedUnit (cssRule, &best);
1.295 vatton 4225: cssRule = CheckImportantRule (cssRule, context);
1.170 cheyroul 4226: if (DoApply)
1.295 vatton 4227: /* install the new presentation. */
4228: TtaSetStylePresentation (PRFillOpacity, element, tsch, context, best);
1.170 cheyroul 4229: return (cssRule);
4230: }
1.207 vatton 4231:
1.1 cvs 4232: /*----------------------------------------------------------------------
1.327 vatton 4233: GetCSSBackgroundURL searches a CSS BackgroundImage url within
4234: the cssRule.
4235: Returns NULL or a new allocated url string.
1.217 vatton 4236: ----------------------------------------------------------------------*/
4237: char *GetCSSBackgroundURL (char *cssRule)
4238: {
4239: char *b, *url;
4240:
4241: url = NULL;
4242: b = strstr (cssRule, "url");
4243: if (b)
1.290 gully 4244: b = ParseCSSUrl (b, &url);
1.217 vatton 4245: return (url);
4246: }
4247:
4248: /*----------------------------------------------------------------------
1.327 vatton 4249: ParseCSSContent: parse the value of property "content"
1.217 vatton 4250: ----------------------------------------------------------------------*/
4251: static char *ParseCSSContent (Element element, PSchema tsch,
1.327 vatton 4252: PresentationContext ctxt, char *cssRule,
4253: CSSInfoPtr css, ThotBool isHTML)
1.217 vatton 4254: {
1.312 quint 4255: PresentationValue value;
1.332 quint 4256: char *p, *last, *start, quoteChar, savedChar;
1.312 quint 4257: ThotBool repeat;
4258:
4259: value.typed_data.unit = UNIT_REL;
4260: value.typed_data.real = FALSE;
4261: value.typed_data.value = 0;
4262: TtaSetStylePresentation (PRContent, element, tsch, ctxt, value);
1.217 vatton 4263: cssRule = SkipBlanksAndComments (cssRule);
1.312 quint 4264: repeat = TRUE;
4265: while (repeat)
4266: {
4267: p = cssRule;
4268: if (!strncasecmp (cssRule, "normal", 6))
1.327 vatton 4269: /* The pseudo-element is not generated */
4270: {
4271: /* @@@@@@ */
4272: cssRule += 6;
4273: repeat = FALSE;
4274: }
1.331 quint 4275: else if (!strncasecmp (cssRule, "none", 4))
4276: /* The pseudo-element is not generated */
4277: {
4278: /* @@@@@@ */
4279: cssRule += 4;
4280: repeat = FALSE;
4281: }
1.312 quint 4282: else if (*cssRule == '"' || *cssRule == '\'')
1.327 vatton 4283: /* It's a string */
4284: {
4285: quoteChar = *cssRule;
4286: cssRule++;
4287: p = cssRule;
4288: /**** escape characters are not handled.
4289: See function SkipQuotedString ******/
4290: while (*cssRule != EOS && *cssRule != quoteChar)
4291: cssRule++;
4292: if (*cssRule != quoteChar)
4293: cssRule = SkipProperty (cssRule, FALSE);
4294: else
4295: {
4296: *cssRule = EOS;
4297: value.typed_data.unit = UNIT_REL;
4298: value.typed_data.real = FALSE;
4299: value.pointer = p;
4300: TtaSetStylePresentation (PRContentString, element, tsch, ctxt,
4301: value);
4302: *cssRule = quoteChar;
4303: cssRule++;
4304: }
4305: }
1.312 quint 4306: else if (!strncasecmp (cssRule, "url", 3))
1.327 vatton 4307: {
4308: cssRule += 3;
4309: cssRule = SetCSSImage (element, tsch, ctxt, cssRule, css, PRContentURL);
4310: }
1.312 quint 4311: else if (!strncasecmp (cssRule, "counter", 7))
1.327 vatton 4312: {
4313: cssRule += 7;
4314: /* @@@@@@ */
4315: cssRule = SkipProperty (cssRule, FALSE);
4316: }
1.312 quint 4317: else if (!strncasecmp (cssRule, "counters", 8))
1.327 vatton 4318: {
4319: cssRule += 8;
4320: /* @@@@@@ */
4321: cssRule = SkipProperty (cssRule, FALSE);
4322: }
1.312 quint 4323: else if (!strncasecmp (cssRule, "attr", 4))
1.327 vatton 4324: {
1.331 quint 4325: value.pointer = NULL;
1.327 vatton 4326: cssRule += 4;
1.331 quint 4327: cssRule = SkipBlanksAndComments (cssRule);
4328: if (*cssRule == '(')
4329: {
4330: cssRule++;
4331: cssRule = SkipBlanksAndComments (cssRule);
4332: start = cssRule;
4333: while (*cssRule != EOS && *cssRule != ')')
4334: cssRule++;
4335: if (*cssRule != ')')
4336: cssRule = start;
4337: else
4338: {
4339: last = cssRule;
4340: /* remove extra spaces */
4341: if (last[-1] == SPACE)
4342: {
4343: *last = SPACE;
4344: last--;
4345: while (last[-1] == SPACE)
4346: last--;
4347: }
1.332 quint 4348: savedChar = *last;
1.331 quint 4349: *last = EOS;
4350: value.typed_data.unit = UNIT_REL;
4351: value.typed_data.real = FALSE;
4352: value.pointer = start;
4353: TtaSetStylePresentation (PRContentAttr, element, tsch, ctxt,
4354: value);
1.332 quint 4355: *last = savedChar;
1.331 quint 4356: }
4357: }
4358: if (value.pointer == NULL)
4359: {
4360: CSSParseError ("Invalid content value", p, cssRule);
4361: cssRule = SkipProperty (cssRule, FALSE);
4362: }
4363: cssRule++;
1.327 vatton 4364: }
1.312 quint 4365: else if (!strncasecmp (cssRule, "open-quote", 10))
1.327 vatton 4366: {
4367: cssRule += 10;
4368: /* @@@@@@ */
4369: }
1.312 quint 4370: else if (!strncasecmp (cssRule, "close-quote", 11))
1.327 vatton 4371: {
4372: cssRule += 11;
4373: /* @@@@@@ */
4374: }
1.312 quint 4375: else if (!strncasecmp (cssRule, "no-open-quote", 13))
1.327 vatton 4376: {
4377: cssRule += 13;
4378: /* @@@@@@ */
4379: }
1.312 quint 4380: else if (!strncasecmp (cssRule, "no-close-quote", 14))
1.327 vatton 4381: {
4382: cssRule += 14;
4383: /* @@@@@@ */
4384: }
1.312 quint 4385: else if (!strncasecmp (cssRule, "inherit", 7))
1.327 vatton 4386: {
4387: cssRule += 7;
4388: /* @@@@@@ */
4389: repeat = FALSE;
4390: }
1.312 quint 4391: else
1.327 vatton 4392: {
4393: CSSParseError ("Invalid content value", p, cssRule);
4394: cssRule = SkipProperty (cssRule, FALSE);
4395: }
1.312 quint 4396: cssRule = SkipBlanksAndComments (cssRule);
4397: if (repeat)
1.327 vatton 4398: if (*cssRule == ';' || *cssRule == '}' || *cssRule == EOS ||
4399: *cssRule == '!')
4400: repeat = FALSE;
1.217 vatton 4401: }
1.312 quint 4402: cssRule = CheckImportantRule (cssRule, ctxt);
1.217 vatton 4403: return (cssRule);
4404: }
1.1 cvs 4405:
4406: /*----------------------------------------------------------------------
1.59 cvs 4407: ParseCSSBackgroundImage: parse a CSS BackgroundImage attribute string.
1.1 cvs 4408: ----------------------------------------------------------------------*/
1.79 cvs 4409: static char *ParseCSSBackgroundImage (Element element, PSchema tsch,
1.327 vatton 4410: PresentationContext ctxt,
4411: char *cssRule, CSSInfoPtr css,
4412: ThotBool isHTML)
1.1 cvs 4413: {
1.49 cvs 4414: PresentationValue image, value;
1.148 vatton 4415:
1.82 cvs 4416: cssRule = SkipBlanksAndComments (cssRule);
1.161 quint 4417: if (!strncasecmp (cssRule, "none", 4))
4418: {
1.260 vatton 4419: cssRule += 4;
1.276 vatton 4420: cssRule = CheckImportantRule (cssRule, ctxt);
1.247 quint 4421: if (DoApply)
1.327 vatton 4422: {
4423: /* no background image */
4424: image.pointer = NULL;
4425: TtaSetStylePresentation (PRBackgroundPicture, element, tsch, ctxt,
4426: image);
4427: }
1.161 quint 4428: }
4429: else if (!strncasecmp (cssRule, "url", 3))
1.1 cvs 4430: {
4431: cssRule += 3;
1.302 quint 4432: cssRule = SetCSSImage (element, tsch, ctxt, cssRule, css,
1.327 vatton 4433: PRBackgroundPicture);
1.207 vatton 4434: if (ctxt->destroy)
1.327 vatton 4435: if (TtaGetStylePresentation (PRFillPattern, element, tsch, ctxt,
4436: &value) < 0)
4437: {
4438: /* there is no FillPattern rule -> remove ShowBox rule */
4439: value.typed_data.value = 1;
4440: value.typed_data.unit = UNIT_REL;
4441: value.typed_data.real = FALSE;
4442: TtaSetStylePresentation (PRShowBox, element, tsch, ctxt, value);
4443: }
1.18 cvs 4444: }
4445: return (cssRule);
4446: }
4447:
4448: /*----------------------------------------------------------------------
1.295 vatton 4449: ParseACSSBackgroundRepeat: parse a CSS BackgroundRepeat attribute string.
1.18 cvs 4450: ----------------------------------------------------------------------*/
1.295 vatton 4451: static char *ParseACSSBackgroundRepeat (Element element, PSchema tsch,
1.327 vatton 4452: PresentationContext ctxt,
4453: char *cssRule, CSSInfoPtr css, ThotBool isHTML)
1.18 cvs 4454: {
4455: PresentationValue repeat;
4456:
1.184 vatton 4457: repeat.typed_data.value = REALSIZE;
1.191 vatton 4458: repeat.typed_data.unit = UNIT_BOX;
1.18 cvs 4459: repeat.typed_data.real = FALSE;
1.82 cvs 4460: cssRule = SkipBlanksAndComments (cssRule);
4461: if (!strncasecmp (cssRule, "no-repeat", 9))
1.184 vatton 4462: repeat.typed_data.value = REALSIZE;
1.82 cvs 4463: else if (!strncasecmp (cssRule, "repeat-y", 8))
1.265 vatton 4464: repeat.typed_data.value = YREPEAT;
1.82 cvs 4465: else if (!strncasecmp (cssRule, "repeat-x", 8))
1.265 vatton 4466: repeat.typed_data.value = XREPEAT;
1.82 cvs 4467: else if (!strncasecmp (cssRule, "repeat", 6))
1.184 vatton 4468: repeat.typed_data.value = REPEAT;
1.18 cvs 4469: else
4470: return (cssRule);
4471:
1.295 vatton 4472: cssRule = SkipWord (cssRule);
4473: /* check if it's an important rule */
4474: cssRule = CheckImportantRule (cssRule, ctxt);
1.116 vatton 4475: if (DoApply)
1.295 vatton 4476: /* install the new presentation */
4477: TtaSetStylePresentation (PRPictureMode, element, tsch, ctxt, repeat);
4478: return (cssRule);
4479: }
4480:
4481: /*----------------------------------------------------------------------
4482: ParseCSSBackgroundRepeat: parse a CSS BackgroundRepeat attribute string.
4483: ----------------------------------------------------------------------*/
4484: static char *ParseCSSBackgroundRepeat (Element element, PSchema tsch,
1.315 gully 4485: PresentationContext ctxt,
4486: char *cssRule, CSSInfoPtr css,
4487: ThotBool isHTML)
1.295 vatton 4488: {
4489: cssRule = ParseACSSBackgroundRepeat (element, tsch, ctxt,
1.315 gully 4490: cssRule, css, isHTML);
4491: if (cssRule)
1.117 vatton 4492: {
1.295 vatton 4493: cssRule = SkipValue ("Invalid background-repeat value", cssRule);
1.117 vatton 4494: /* check if it's an important rule */
1.276 vatton 4495: cssRule = CheckImportantRule (cssRule, ctxt);
1.117 vatton 4496: }
1.295 vatton 4497: return cssRule;
1.18 cvs 4498: }
4499:
4500: /*----------------------------------------------------------------------
1.327 vatton 4501: ParseACSSBackgroundAttachment: parse a CSS BackgroundAttachment
4502: attribute string.
1.18 cvs 4503: ----------------------------------------------------------------------*/
1.295 vatton 4504: static char *ParseACSSBackgroundAttachment (Element element, PSchema tsch,
1.327 vatton 4505: PresentationContext ctxt,
4506: char *cssRule, CSSInfoPtr css,
4507: ThotBool isHTML)
1.18 cvs 4508: {
1.163 quint 4509: cssRule = SkipBlanksAndComments (cssRule);
4510: if (!strncasecmp (cssRule, "scroll", 6))
1.199 vatton 4511: {
4512: cssRule = SkipWord (cssRule);
4513: }
1.163 quint 4514: else if (!strncasecmp (cssRule, "fixed", 5))
1.199 vatton 4515: {
4516: cssRule = SkipWord (cssRule);
4517: }
1.163 quint 4518: return (cssRule);
1.1 cvs 4519: }
4520:
4521: /*----------------------------------------------------------------------
1.327 vatton 4522: ParseCSSBackgroundAttachment: parse a CSS BackgroundAttachment
4523: attribute string.
1.295 vatton 4524: ----------------------------------------------------------------------*/
4525: static char *ParseCSSBackgroundAttachment (Element element, PSchema tsch,
1.327 vatton 4526: PresentationContext ctxt,
4527: char *cssRule, CSSInfoPtr css,
4528: ThotBool isHTML)
1.295 vatton 4529: {
4530: char *ptr;
4531:
4532: ptr = cssRule;
4533: cssRule = ParseACSSBackgroundAttachment (element, tsch, ctxt,
1.327 vatton 4534: cssRule, css, isHTML);
1.295 vatton 4535: if (ptr == cssRule)
4536: {
4537: cssRule = SkipValue ("Invalid background-attachement value", cssRule);
4538: /* check if it's an important rule */
4539: cssRule = CheckImportantRule (cssRule, ctxt);
4540: }
4541: return cssRule;
4542: }
4543:
4544: /*----------------------------------------------------------------------
1.327 vatton 4545: ParseACSSBackgroundPosition: parse a CSS BackgroundPosition
4546: attribute string.
1.1 cvs 4547: ----------------------------------------------------------------------*/
1.279 vatton 4548: static char *ParseACSSBackgroundPosition (Element element, PSchema tsch,
1.327 vatton 4549: PresentationContext ctxt,
4550: char *cssRule, CSSInfoPtr css,
4551: ThotBool isHTML)
1.1 cvs 4552: {
1.18 cvs 4553: ThotBool ok;
1.1 cvs 4554:
1.163 quint 4555: cssRule = SkipBlanksAndComments (cssRule);
4556: ok = TRUE;
4557: if (!strncasecmp (cssRule, "left", 4))
4558: cssRule = SkipWord (cssRule);
4559: else if (!strncasecmp (cssRule, "right", 5))
4560: cssRule = SkipWord (cssRule);
4561: else if (!strncasecmp (cssRule, "center", 6))
4562: cssRule = SkipWord (cssRule);
4563: else if (!strncasecmp (cssRule, "top", 3))
4564: cssRule = SkipWord (cssRule);
4565: else if (!strncasecmp (cssRule, "bottom", 6))
4566: cssRule = SkipWord (cssRule);
1.279 vatton 4567: else if (isdigit (*cssRule) || *cssRule == '.' || *cssRule == '-')
1.191 vatton 4568: {
1.206 vatton 4569: while (*cssRule != EOS && *cssRule != SPACE &&
1.327 vatton 4570: *cssRule != ',' && *cssRule != ';')
4571: cssRule++;
1.191 vatton 4572: }
1.163 quint 4573: else
4574: ok = FALSE;
4575:
1.335 quint 4576: if (ok)
1.148 vatton 4577: {
1.163 quint 4578: /* check if it's an important rule */
1.276 vatton 4579: cssRule = CheckImportantRule (cssRule, ctxt);
1.279 vatton 4580: }
4581: cssRule = SkipBlanksAndComments (cssRule);
4582: return (cssRule);
4583: }
1.218 vatton 4584:
1.279 vatton 4585: /*----------------------------------------------------------------------
1.327 vatton 4586: ParseCSSBackgroundPosition: parse a CSS BackgroundPosition
4587: attribute string.
1.279 vatton 4588: ----------------------------------------------------------------------*/
4589: static char *ParseCSSBackgroundPosition (Element element, PSchema tsch,
1.327 vatton 4590: PresentationContext ctxt,
4591: char *cssRule, CSSInfoPtr css,
4592: ThotBool isHTML)
1.279 vatton 4593: {
1.295 vatton 4594: char *ptr;
4595:
4596: ptr = cssRule;
1.279 vatton 4597: cssRule = ParseACSSBackgroundPosition (element, tsch, ctxt,
1.327 vatton 4598: cssRule, css, isHTML);
1.295 vatton 4599: if (ptr == cssRule)
4600: {
4601: cssRule = SkipValue ("Invalid background-position value", cssRule);
4602: /* check if it's an important rule */
4603: cssRule = CheckImportantRule (cssRule, ctxt);
4604: }
1.298 vatton 4605: else if (*cssRule != ';' && *cssRule != EOS)
4606: {
4607: /* possible second value */
4608: ptr = cssRule;
4609: cssRule = ParseACSSBackgroundPosition (element, tsch, ctxt,
1.327 vatton 4610: cssRule, css, isHTML);
1.298 vatton 4611: if (ptr == cssRule)
1.327 vatton 4612: {
4613: cssRule = SkipValue ("Invalid background-position value", cssRule);
4614: /* check if it's an important rule */
4615: cssRule = CheckImportantRule (cssRule, ctxt);
4616: }
1.298 vatton 4617: }
1.163 quint 4618: return (cssRule);
1.18 cvs 4619: }
4620:
4621: /*----------------------------------------------------------------------
1.327 vatton 4622: ParseCSSBackground: parse a CSS background attribute
1.18 cvs 4623: ----------------------------------------------------------------------*/
1.79 cvs 4624: static char *ParseCSSBackground (Element element, PSchema tsch,
1.327 vatton 4625: PresentationContext ctxt, char *cssRule,
4626: CSSInfoPtr css, ThotBool isHTML)
1.18 cvs 4627: {
1.323 vatton 4628: char *ptr;
4629: int skippedNL;
4630: ThotBool img, repeat, position, attach, color;
1.18 cvs 4631:
1.82 cvs 4632: cssRule = SkipBlanksAndComments (cssRule);
1.323 vatton 4633: img = repeat = position = attach = color = FALSE;
1.301 vatton 4634: while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.18 cvs 4635: {
1.71 cvs 4636: /* perhaps a Background Image */
1.198 vatton 4637: if (!strncasecmp (cssRule, "url", 3) || !strncasecmp (cssRule, "none", 4))
1.327 vatton 4638: {
1.334 vatton 4639: if (!strncasecmp (cssRule, "none", 4))
4640: repeat = TRUE;
1.327 vatton 4641: cssRule = ParseCSSBackgroundImage (element, tsch, ctxt, cssRule,
4642: css, isHTML);
4643: img = TRUE;
4644: }
1.18 cvs 4645: /* perhaps a Background Attachment */
1.82 cvs 4646: else if (!strncasecmp (cssRule, "scroll", 6) ||
4647: !strncasecmp (cssRule, "fixed", 5))
1.327 vatton 4648: {
4649: cssRule = ParseACSSBackgroundAttachment (element, tsch, ctxt,
4650: cssRule, css, isHTML);
1.328 vatton 4651: attach = repeat = TRUE;
1.327 vatton 4652: }
1.18 cvs 4653: /* perhaps a Background Repeat */
1.82 cvs 4654: else if (!strncasecmp (cssRule, "no-repeat", 9) ||
4655: !strncasecmp (cssRule, "repeat-y", 8) ||
4656: !strncasecmp (cssRule, "repeat-x", 8) ||
4657: !strncasecmp (cssRule, "repeat", 6))
1.327 vatton 4658: {
4659: cssRule = ParseACSSBackgroundRepeat (element, tsch, ctxt,
4660: cssRule, css, isHTML);
4661: repeat = TRUE;
4662: }
1.18 cvs 4663: /* perhaps a Background Position */
1.82 cvs 4664: else if (!strncasecmp (cssRule, "left", 4) ||
4665: !strncasecmp (cssRule, "right", 5) ||
4666: !strncasecmp (cssRule, "center", 6) ||
4667: !strncasecmp (cssRule, "top", 3) ||
4668: !strncasecmp (cssRule, "bottom", 6) ||
1.279 vatton 4669: isdigit (*cssRule) || *cssRule == '.' || *cssRule == '-')
1.327 vatton 4670: {
4671: cssRule = ParseACSSBackgroundPosition (element, tsch, ctxt,
4672: cssRule, css, isHTML);
1.328 vatton 4673: position = repeat = TRUE;
1.327 vatton 4674: }
1.18 cvs 4675: /* perhaps a Background Color */
1.323 vatton 4676: else if (!color)
1.327 vatton 4677: {
4678: skippedNL = NewLineSkipped;
4679: /* check if the rule has been found */
4680: ptr = cssRule;
4681: cssRule = ParseCSSBackgroundColor (element, tsch, ctxt,
4682: cssRule, css, isHTML);
4683: if (ptr == cssRule)
4684: {
4685: NewLineSkipped = skippedNL;
4686: /* rule not found */
4687: cssRule = SkipProperty (cssRule, FALSE);
4688: }
4689: else
4690: color = TRUE;
4691: }
1.328 vatton 4692: else
1.327 vatton 4693: cssRule = SkipProperty (cssRule, FALSE);
1.328 vatton 4694:
1.82 cvs 4695: cssRule = SkipBlanksAndComments (cssRule);
1.18 cvs 4696: }
1.328 vatton 4697:
4698: if (color && !img)
4699: ParseCSSBackgroundImage (element, tsch, ctxt, "none", css, isHTML);
4700:
4701: if (img && !repeat)
4702: ParseACSSBackgroundRepeat (element, tsch, ctxt,
4703: "repeat", css, isHTML);
4704: if (img && !position)
4705: ParseACSSBackgroundPosition (element, tsch, ctxt,
4706: "0% 0%", css, isHTML);
4707: if (img && !attach)
4708: ParseACSSBackgroundAttachment (element, tsch, ctxt,
4709: "scroll", css, isHTML);
1.327 vatton 4710: return (cssRule);
1.18 cvs 4711: }
4712:
1.59 cvs 4713: /*----------------------------------------------------------------------
1.327 vatton 4714: ParseCSSPageBreakBefore: parse a CSS page-break-before attribute
1.59 cvs 4715: ----------------------------------------------------------------------*/
1.79 cvs 4716: static char *ParseCSSPageBreakBefore (Element element, PSchema tsch,
1.327 vatton 4717: PresentationContext ctxt, char *cssRule,
4718: CSSInfoPtr css, ThotBool isHTML)
1.59 cvs 4719: {
4720: PresentationValue page;
4721:
1.184 vatton 4722: page.typed_data.unit = UNIT_INVALID;
1.59 cvs 4723: page.typed_data.real = FALSE;
1.82 cvs 4724: cssRule = SkipBlanksAndComments (cssRule);
4725: if (!strncasecmp (cssRule, "auto", 4))
1.184 vatton 4726: page.typed_data.value = PageAuto;
1.82 cvs 4727: else if (!strncasecmp (cssRule, "always", 6))
1.59 cvs 4728: {
1.184 vatton 4729: page.typed_data.unit = UNIT_REL;
4730: page.typed_data.value = PageAlways;
1.59 cvs 4731: }
1.82 cvs 4732: else if (!strncasecmp (cssRule, "avoid", 5))
1.59 cvs 4733: {
1.184 vatton 4734: page.typed_data.unit = UNIT_REL;
4735: page.typed_data.value = PageAvoid;
1.59 cvs 4736: }
1.82 cvs 4737: else if (!strncasecmp (cssRule, "left", 4))
1.59 cvs 4738: {
1.184 vatton 4739: page.typed_data.unit = UNIT_REL;
4740: page.typed_data.value = PageLeft;
1.59 cvs 4741: }
1.82 cvs 4742: else if (!strncasecmp (cssRule, "right", 5))
1.59 cvs 4743: {
1.184 vatton 4744: page.typed_data.unit = UNIT_REL;
4745: page.typed_data.value = PageRight;
1.59 cvs 4746: }
1.82 cvs 4747: else if (!strncasecmp (cssRule, "inherit", 7))
1.59 cvs 4748: {
1.293 quint 4749: page.typed_data.unit = VALUE_INHERIT;
1.184 vatton 4750: page.typed_data.value = PageInherit;
1.59 cvs 4751: }
4752: cssRule = SkipWord (cssRule);
1.295 vatton 4753: /* check if it's an important rule */
4754: cssRule = CheckImportantRule (cssRule, ctxt);
1.59 cvs 4755: /* install the new presentation */
1.295 vatton 4756: if (DoApply &&
4757: ((page.typed_data.unit == UNIT_REL && page.typed_data.value == PageAlways)
4758: || page.typed_data.unit == VALUE_INHERIT))
4759: TtaSetStylePresentation (PRPageBefore, element, tsch, ctxt, page);
1.59 cvs 4760: return (cssRule);
4761: }
4762:
4763: /*----------------------------------------------------------------------
1.327 vatton 4764: ParseCSSPageBreakAfter: parse a CSS page-break-after attribute
1.59 cvs 4765: ----------------------------------------------------------------------*/
1.79 cvs 4766: static char *ParseCSSPageBreakAfter (Element element, PSchema tsch,
1.327 vatton 4767: PresentationContext ctxt,
4768: char *cssRule, CSSInfoPtr css,
4769: ThotBool isHTML)
1.59 cvs 4770: {
4771: PresentationValue page;
4772:
1.184 vatton 4773: page.typed_data.unit = UNIT_INVALID;
1.59 cvs 4774: page.typed_data.real = FALSE;
1.82 cvs 4775: cssRule = SkipBlanksAndComments (cssRule);
4776: if (!strncasecmp (cssRule, "auto", 4))
1.184 vatton 4777: page.typed_data.value = PageAuto;
1.82 cvs 4778: else if (!strncasecmp (cssRule, "always", 6))
1.59 cvs 4779: {
1.184 vatton 4780: page.typed_data.unit = UNIT_REL;
4781: page.typed_data.value = PageAlways;
1.59 cvs 4782: }
1.82 cvs 4783: else if (!strncasecmp (cssRule, "avoid", 5))
1.59 cvs 4784: {
1.184 vatton 4785: page.typed_data.unit = UNIT_REL;
4786: page.typed_data.value = PageAvoid;
1.59 cvs 4787: }
1.82 cvs 4788: else if (!strncasecmp (cssRule, "left", 4))
1.59 cvs 4789: {
1.184 vatton 4790: page.typed_data.unit = UNIT_REL;
4791: page.typed_data.value = PageLeft;
1.59 cvs 4792: }
1.82 cvs 4793: else if (!strncasecmp (cssRule, "right", 5))
1.59 cvs 4794: {
1.184 vatton 4795: page.typed_data.unit = UNIT_REL;
4796: page.typed_data.value = PageRight;
1.59 cvs 4797: }
1.82 cvs 4798: else if (!strncasecmp (cssRule, "inherit", 7))
1.59 cvs 4799: {
1.293 quint 4800: page.typed_data.unit = VALUE_INHERIT;
1.184 vatton 4801: page.typed_data.value = PageInherit;
1.59 cvs 4802: }
4803: cssRule = SkipWord (cssRule);
1.295 vatton 4804: /* check if it's an important rule */
4805: cssRule = CheckImportantRule (cssRule, ctxt);
1.314 gully 4806: #if 0
1.59 cvs 4807: /* install the new presentation */
1.295 vatton 4808: if (DoApply &&
4809: (page.typed_data.unit == UNIT_REL ||
4810: page.typed_data.unit == VALUE_INHERIT))
4811: /* TtaSetStylePresentation (PRPageAfter, element, tsch, ctxt, page) */;
1.314 gully 4812: #endif /* 0 */
1.59 cvs 4813: return (cssRule);
4814: }
4815:
4816: /*----------------------------------------------------------------------
1.327 vatton 4817: ParseCSSPageBreakInside: parse a CSS page-break-inside attribute
1.59 cvs 4818: ----------------------------------------------------------------------*/
1.79 cvs 4819: static char *ParseCSSPageBreakInside (Element element, PSchema tsch,
1.327 vatton 4820: PresentationContext ctxt,
4821: char *cssRule, CSSInfoPtr css,
4822: ThotBool isHTML)
1.59 cvs 4823: {
4824: PresentationValue page;
4825:
1.184 vatton 4826: page.typed_data.unit = UNIT_INVALID;
1.59 cvs 4827: page.typed_data.real = FALSE;
1.82 cvs 4828: cssRule = SkipBlanksAndComments (cssRule);
4829: if (!strncasecmp (cssRule, "auto", 4))
1.59 cvs 4830: {
1.184 vatton 4831: /*page.typed_data.unit = UNIT_REL;*/
4832: page.typed_data.value = PageAuto;
1.59 cvs 4833: }
1.82 cvs 4834: else if (!strncasecmp (cssRule, "avoid", 5))
1.59 cvs 4835: {
1.184 vatton 4836: page.typed_data.unit = UNIT_REL;
4837: page.typed_data.value = PageAvoid;
1.59 cvs 4838: }
1.82 cvs 4839: else if (!strncasecmp (cssRule, "inherit", 7))
1.59 cvs 4840: {
1.293 quint 4841: /* page.typed_data.unit = VALUE_INHERIT; */
1.184 vatton 4842: page.typed_data.value = PageInherit;
1.59 cvs 4843: }
4844: cssRule = SkipWord (cssRule);
1.295 vatton 4845: cssRule = CheckImportantRule (cssRule, ctxt);
1.59 cvs 4846: /* install the new presentation */
1.293 quint 4847: /*if ((page.typed_data.unit == UNIT_REL ||
4848: page.typed_data.unit == VALUE_INHERIT) &&
1.184 vatton 4849: page.typed_data.value == PageAvoid && DoApply)
1.295 vatton 4850: TtaSetStylePresentation (PRPageInside, element, tsch, ctxt, page);*/
1.59 cvs 4851: return (cssRule);
4852: }
1.18 cvs 4853:
1.60 cvs 4854: /*----------------------------------------------------------------------
1.327 vatton 4855: ParseSVGStrokeWidth: parse a SVG stroke-width property value.
1.60 cvs 4856: ----------------------------------------------------------------------*/
1.79 cvs 4857: static char *ParseSVGStrokeWidth (Element element, PSchema tsch,
1.327 vatton 4858: PresentationContext ctxt, char *cssRule,
4859: CSSInfoPtr css, ThotBool isHTML)
1.60 cvs 4860: {
4861: PresentationValue width;
4862:
1.82 cvs 4863: cssRule = SkipBlanksAndComments (cssRule);
1.60 cvs 4864: width.typed_data.value = 0;
1.184 vatton 4865: width.typed_data.unit = UNIT_INVALID;
1.60 cvs 4866: width.typed_data.real = FALSE;
1.110 vatton 4867: if (isdigit (*cssRule) || *cssRule == '.')
1.166 vatton 4868: {
1.327 vatton 4869: cssRule = ParseCSSUnit (cssRule, &width);
4870: if (width.typed_data.unit == UNIT_BOX)
4871: width.typed_data.unit = UNIT_PX;
1.166 vatton 4872: }
1.295 vatton 4873: else
4874: cssRule = SkipValue ("Invalid stroke-width value", cssRule);
4875:
4876: /* check if it's an important rule */
4877: cssRule = CheckImportantRule (cssRule, ctxt);
1.184 vatton 4878: if (width.typed_data.unit != UNIT_INVALID && DoApply)
1.117 vatton 4879: {
1.207 vatton 4880: TtaSetStylePresentation (PRLineWeight, element, tsch, ctxt, width);
1.117 vatton 4881: width.typed_data.value = 1;
1.184 vatton 4882: width.typed_data.unit = UNIT_REL;
1.117 vatton 4883: }
1.60 cvs 4884: return (cssRule);
4885: }
4886:
1.217 vatton 4887: /*----------------------------------------------------------------------
1.327 vatton 4888: ParseCSSPosition: parse a CSS Position attribute string.
1.217 vatton 4889: ----------------------------------------------------------------------*/
4890: static char *ParseCSSPosition (Element element, PSchema tsch,
1.327 vatton 4891: PresentationContext ctxt, char *cssRule,
4892: CSSInfoPtr css, ThotBool isHTML)
1.217 vatton 4893: {
1.305 quint 4894: char *ptr;
4895: PresentationValue pval;
1.217 vatton 4896:
1.305 quint 4897: pval.typed_data.value = 0;
4898: pval.typed_data.unit = UNIT_BOX;
4899: pval.typed_data.real = FALSE;
1.217 vatton 4900: cssRule = SkipBlanksAndComments (cssRule);
4901: ptr = cssRule;
4902: if (!strncasecmp (cssRule, "static", 6))
1.337 vatton 4903: {
4904: pval.typed_data.value = PositionStatic;
4905: cssRule += 6;
4906: }
4907: else if (!strncasecmp (cssRule, "relative", 8))
4908: {
4909: pval.typed_data.value = PositionRelative;
4910: cssRule += 8;
4911: }
1.217 vatton 4912: else if (!strncasecmp (cssRule, "absolute", 8))
1.337 vatton 4913: {
4914: pval.typed_data.value = PositionAbsolute;
4915: cssRule += 8;
4916: }
1.217 vatton 4917: else if (!strncasecmp (cssRule, "fixed", 5))
1.337 vatton 4918: {
4919: pval.typed_data.value = PositionFixed;
4920: cssRule += 5;
4921: }
1.217 vatton 4922: else if (!strncasecmp (cssRule, "inherit", 7))
1.337 vatton 4923: {
4924: pval.typed_data.unit = VALUE_INHERIT;
4925: cssRule += 7;
4926: }
1.305 quint 4927:
4928: if (pval.typed_data.value == 0 && pval.typed_data.unit != VALUE_INHERIT)
4929: {
4930: cssRule = SkipValue ("Invalid position value", ptr);
4931: cssRule = CheckImportantRule (cssRule, ctxt);
4932: cssRule = SkipValue (NULL, cssRule);
4933: }
1.217 vatton 4934: else
1.305 quint 4935: {
4936: cssRule = CheckImportantRule (cssRule, ctxt);
1.337 vatton 4937: cssRule = SkipBlanksAndComments (cssRule);
4938: if (*cssRule != EOS && *cssRule != ';')
4939: SkipValue ("Invalid position value", ptr);
4940: else if (DoApply)
1.327 vatton 4941: TtaSetStylePresentation (PRPosition, element, tsch, ctxt, pval);
1.305 quint 4942: }
1.217 vatton 4943: return (cssRule);
4944: }
4945:
4946: /*----------------------------------------------------------------------
1.327 vatton 4947: ParseCSSTop: parse a CSS Top attribute
1.217 vatton 4948: ----------------------------------------------------------------------*/
4949: static char *ParseCSSTop (Element element, PSchema tsch,
1.327 vatton 4950: PresentationContext context, char *cssRule,
4951: CSSInfoPtr css, ThotBool isHTML)
1.217 vatton 4952: {
4953: PresentationValue val;
4954: char *ptr;
4955:
4956: cssRule = SkipBlanksAndComments (cssRule);
4957: ptr = cssRule;
1.305 quint 4958: /* first parse the value */
4959: if (!strncasecmp (cssRule, "auto", 4))
1.217 vatton 4960: {
4961: val.typed_data.unit = VALUE_AUTO;
4962: val.typed_data.value = 0;
4963: val.typed_data.real = FALSE;
4964: cssRule = SkipWord (cssRule);
4965: }
1.305 quint 4966: else if (!strncasecmp (cssRule, "inherit", 7))
4967: {
4968: val.typed_data.unit = VALUE_INHERIT;
4969: cssRule = SkipWord (cssRule);
4970: }
1.217 vatton 4971: else
4972: cssRule = ParseCSSUnit (cssRule, &val);
4973: if (val.typed_data.value != 0 &&
4974: (val.typed_data.unit == UNIT_INVALID ||
4975: val.typed_data.unit == UNIT_BOX))
4976: {
1.218 vatton 4977: cssRule = SkipValue ("top value", ptr);
1.217 vatton 4978: val.typed_data.unit = UNIT_PX;
4979: }
1.295 vatton 4980: cssRule = CheckImportantRule (cssRule, context);
1.217 vatton 4981: if (DoApply)
1.305 quint 4982: TtaSetStylePresentation (PRTop, element, tsch, context, val);
1.217 vatton 4983: return (cssRule);
4984: }
4985:
4986: /*----------------------------------------------------------------------
1.327 vatton 4987: ParseCSSRight: parse a CSS Right attribute
1.217 vatton 4988: ----------------------------------------------------------------------*/
4989: static char *ParseCSSRight (Element element, PSchema tsch,
1.327 vatton 4990: PresentationContext context, char *cssRule,
4991: CSSInfoPtr css, ThotBool isHTML)
1.217 vatton 4992: {
4993: PresentationValue val;
4994: char *ptr;
4995:
4996: cssRule = SkipBlanksAndComments (cssRule);
4997: ptr = cssRule;
4998: /* first parse the attribute string */
1.305 quint 4999: if (!strncasecmp (cssRule, "auto", 4))
1.217 vatton 5000: {
5001: val.typed_data.unit = VALUE_AUTO;
5002: val.typed_data.value = 0;
5003: val.typed_data.real = FALSE;
5004: cssRule = SkipWord (cssRule);
5005: }
1.305 quint 5006: else if (!strncasecmp (cssRule, "inherit", 7))
5007: {
5008: val.typed_data.unit = VALUE_INHERIT;
5009: cssRule = SkipWord (cssRule);
5010: }
1.217 vatton 5011: else
5012: cssRule = ParseCSSUnit (cssRule, &val);
5013: if (val.typed_data.value != 0 &&
5014: (val.typed_data.unit == UNIT_INVALID ||
5015: val.typed_data.unit == UNIT_BOX))
5016: {
1.218 vatton 5017: cssRule = SkipValue ("right value", ptr);
1.217 vatton 5018: val.typed_data.unit = UNIT_PX;
5019: }
1.295 vatton 5020: cssRule = CheckImportantRule (cssRule, context);
1.217 vatton 5021: if (DoApply)
1.305 quint 5022: TtaSetStylePresentation (PRRight, element, tsch, context, val);
1.217 vatton 5023: return (cssRule);
5024: }
5025:
5026: /*----------------------------------------------------------------------
1.327 vatton 5027: ParseCSSBottom: parse a CSS Bottom attribute
1.217 vatton 5028: ----------------------------------------------------------------------*/
5029: static char *ParseCSSBottom (Element element, PSchema tsch,
1.327 vatton 5030: PresentationContext context, char *cssRule,
5031: CSSInfoPtr css, ThotBool isHTML)
1.217 vatton 5032: {
5033: PresentationValue val;
5034: char *ptr;
5035:
5036: cssRule = SkipBlanksAndComments (cssRule);
5037: ptr = cssRule;
5038: /* first parse the attribute string */
1.305 quint 5039: if (!strncasecmp (cssRule, "auto", 4))
1.217 vatton 5040: {
5041: val.typed_data.unit = VALUE_AUTO;
5042: val.typed_data.value = 0;
5043: val.typed_data.real = FALSE;
5044: cssRule = SkipWord (cssRule);
5045: }
1.305 quint 5046: else if (!strncasecmp (cssRule, "inherit", 7))
5047: {
5048: val.typed_data.unit = VALUE_INHERIT;
5049: cssRule = SkipWord (cssRule);
5050: }
1.217 vatton 5051: else
5052: cssRule = ParseCSSUnit (cssRule, &val);
5053: if (val.typed_data.value != 0 &&
5054: (val.typed_data.unit == UNIT_INVALID ||
5055: val.typed_data.unit == UNIT_BOX))
5056: {
1.218 vatton 5057: cssRule = SkipValue ("bottom value", ptr);
1.217 vatton 5058: val.typed_data.unit = UNIT_PX;
5059: }
1.295 vatton 5060: cssRule = CheckImportantRule (cssRule, context);
1.217 vatton 5061: if (DoApply)
1.305 quint 5062: TtaSetStylePresentation (PRBottom, element, tsch, context, val);
1.217 vatton 5063: return (cssRule);
5064: }
5065:
5066: /*----------------------------------------------------------------------
1.327 vatton 5067: ParseCSSLeft: parse a CSS Left attribute
1.217 vatton 5068: ----------------------------------------------------------------------*/
5069: static char *ParseCSSLeft (Element element, PSchema tsch,
1.327 vatton 5070: PresentationContext context, char *cssRule,
5071: CSSInfoPtr css, ThotBool isHTML)
1.217 vatton 5072: {
5073: PresentationValue val;
5074: char *ptr;
5075:
5076: cssRule = SkipBlanksAndComments (cssRule);
5077: ptr = cssRule;
5078: /* first parse the attribute string */
1.305 quint 5079: if (!strncasecmp (cssRule, "auto", 4))
1.217 vatton 5080: {
5081: val.typed_data.unit = VALUE_AUTO;
5082: val.typed_data.value = 0;
5083: val.typed_data.real = FALSE;
5084: cssRule = SkipWord (cssRule);
5085: }
1.305 quint 5086: else if (!strncasecmp (cssRule, "inherit", 7))
5087: {
5088: val.typed_data.unit = VALUE_INHERIT;
5089: cssRule = SkipWord (cssRule);
5090: }
1.217 vatton 5091: else
5092: cssRule = ParseCSSUnit (cssRule, &val);
5093: if (val.typed_data.value != 0 &&
5094: (val.typed_data.unit == UNIT_INVALID ||
5095: val.typed_data.unit == UNIT_BOX))
5096: {
1.218 vatton 5097: cssRule = SkipValue ("left value", ptr);
1.217 vatton 5098: val.typed_data.unit = UNIT_PX;
5099: }
1.295 vatton 5100: cssRule = CheckImportantRule (cssRule, context);
1.217 vatton 5101: if (DoApply)
1.305 quint 5102: TtaSetStylePresentation (PRLeft, element, tsch, context, val);
1.217 vatton 5103: return (cssRule);
5104: }
5105:
5106: /*----------------------------------------------------------------------
1.327 vatton 5107: ParseCSSZIndex: parse a CSS z-index attribute
1.217 vatton 5108: ----------------------------------------------------------------------*/
5109: static char *ParseCSSZIndex (Element element, PSchema tsch,
1.327 vatton 5110: PresentationContext context, char *cssRule,
5111: CSSInfoPtr css, ThotBool isHTML)
1.217 vatton 5112: {
5113: PresentationValue val;
5114: char *ptr;
5115:
5116: cssRule = SkipBlanksAndComments (cssRule);
5117: ptr = cssRule;
5118: /* first parse the attribute string */
5119: if (!strncasecmp (cssRule, "auto", 4) ||
5120: !strncasecmp (cssRule, "inherit", 7))
5121: {
5122: val.typed_data.unit = VALUE_AUTO;
5123: val.typed_data.value = 0;
5124: val.typed_data.real = FALSE;
5125: cssRule = SkipWord (cssRule);
5126: }
5127: else
5128: {
5129: cssRule = ParseCSSUnit (cssRule, &val);
5130: if (val.typed_data.unit != UNIT_BOX)
1.327 vatton 5131: {
5132: cssRule = SkipValue ("z-index value", ptr);
5133: val.typed_data.unit = UNIT_BOX;
5134: }
1.217 vatton 5135: }
1.295 vatton 5136: cssRule = CheckImportantRule (cssRule, context);
1.217 vatton 5137: /***
1.327 vatton 5138: if (DoApply)
5139: TtaSetStylePresentation (PR, element, tsch, context, val);
1.217 vatton 5140: ***/
5141: return (cssRule);
5142: }
5143:
1.340 quint 5144: /*----------------------------------------------------------------------
5145: *
5146: * FUNCTIONS STYLE DECLARATIONS
5147: *
5148: *----------------------------------------------------------------------*/
1.18 cvs 5149: /*
1.59 cvs 5150: * NOTE: Long attribute name MUST be placed before shortened ones !
1.18 cvs 5151: * e.g. "FONT-SIZE" must be placed before "FONT"
5152: */
5153: static CSSProperty CSSProperties[] =
1.327 vatton 5154: {
5155: {"background-color", ParseCSSBackgroundColor},
5156: {"background-image", ParseCSSBackgroundImage},
5157: {"background-repeat", ParseCSSBackgroundRepeat},
5158: {"background-attachment", ParseCSSBackgroundAttachment},
5159: {"background-position", ParseCSSBackgroundPosition},
5160: {"background", ParseCSSBackground},
5161: {"border-top-width", ParseCSSBorderTopWidth},
5162: {"border-right-width", ParseCSSBorderRightWidth},
5163: {"border-bottom-width", ParseCSSBorderBottomWidth},
5164: {"border-left-width", ParseCSSBorderLeftWidth},
5165: {"border-width", ParseCSSBorderWidth},
5166: {"border-top-color", ParseCSSBorderColorTop},
5167: {"border-right-color", ParseCSSBorderColorRight},
5168: {"border-bottom-color", ParseCSSBorderColorBottom},
5169: {"border-left-color", ParseCSSBorderColorLeft},
5170: {"border-color", ParseCSSBorderColor},
5171: {"border-top-style", ParseCSSBorderStyleTop},
5172: {"border-right-style", ParseCSSBorderStyleRight},
5173: {"border-bottom-style", ParseCSSBorderStyleBottom},
5174: {"border-left-style", ParseCSSBorderStyleLeft},
5175: {"border-style", ParseCSSBorderStyle},
5176: {"border-top", ParseCSSBorderTop},
5177: {"border-right", ParseCSSBorderRight},
5178: {"border-bottom", ParseCSSBorderBottom},
5179: {"border-left", ParseCSSBorderLeft},
5180: {"border", ParseCSSBorder},
5181: {"bottom", ParseCSSBottom},
5182: {"clear", ParseCSSClear},
5183: {"color", ParseCSSForeground},
5184: {"content", ParseCSSContent},
5185: {"direction", ParseCSSDirection},
5186: {"display", ParseCSSDisplay},
5187: {"float", ParseCSSFloat},
5188: {"font-family", ParseCSSFontFamily},
5189: {"font-style", ParseCSSFontStyle},
5190: {"font-variant", ParseCSSFontVariant},
5191: {"font-weight", ParseCSSFontWeight},
5192: {"font-size-adjust", ParseCSSFontSizeAdjust},
5193: {"font-size", ParseCSSFontSize},
5194: {"font", ParseCSSFont},
5195: {"height", ParseCSSHeight},
5196: {"left", ParseCSSLeft},
5197: {"letter-spacing", ParseCSSLetterSpacing},
5198: {"line-height", ParseCSSLineHeight},
5199: {"list-style-type", ParseCSSListStyleType},
5200: {"list-style-image", ParseCSSListStyleImage},
5201: {"list-style-position", ParseCSSListStylePosition},
5202: {"list-style", ParseCSSListStyle},
5203: {"margin-bottom", ParseCSSMarginBottom},
5204: {"margin-top", ParseCSSMarginTop},
5205: {"margin-right", ParseCSSMarginRight},
5206: {"margin-left", ParseCSSMarginLeft},
5207: {"margin", ParseCSSMargin},
5208: {"padding-top", ParseCSSPaddingTop},
5209: {"padding-right", ParseCSSPaddingRight},
5210: {"padding-bottom", ParseCSSPaddingBottom},
5211: {"padding-left", ParseCSSPaddingLeft},
5212: {"padding", ParseCSSPadding},
5213: {"page-break-before", ParseCSSPageBreakBefore},
5214: {"page-break-after", ParseCSSPageBreakAfter},
5215: {"page-break-inside", ParseCSSPageBreakInside},
5216: {"position", ParseCSSPosition},
5217: {"right", ParseCSSRight},
5218: {"text-align", ParseCSSTextAlign},
5219: {"text-anchor", ParseCSSTextAnchor},
5220: {"text-indent", ParseCSSTextIndent},
5221: {"text-decoration", ParseCSSTextDecoration},
5222: {"text-transform", ParseCSSTextTransform},
5223: {"top", ParseCSSTop},
5224: {"unicode-bidi", ParseCSSUnicodeBidi},
5225: {"vertical-align", ParseCSSVerticalAlign},
5226: {"white-space", ParseCSSWhiteSpace},
5227: {"width", ParseCSSWidth},
1.333 vatton 5228: {"visibility", ParseCSSVisibility},
1.327 vatton 5229: {"word-spacing", ParseCSSWordSpacing},
5230: {"z-index", ParseCSSZIndex},
5231:
5232: /* SVG extensions */
5233: {"fill-opacity", ParseSVGFillOpacity},
5234: {"fill", ParseSVGFill},
5235: {"opacity", ParseSVGOpacity},
5236: {"stroke-opacity", ParseSVGStrokeOpacity},
5237: {"stroke-width", ParseSVGStrokeWidth},
5238: {"stroke", ParseSVGStroke}
5239: };
1.155 cheyroul 5240:
1.18 cvs 5241: #define NB_CSSSTYLEATTRIBUTE (sizeof(CSSProperties) / sizeof(CSSProperty))
5242:
5243: /*----------------------------------------------------------------------
1.327 vatton 5244: ParseCSSRule: parse a CSS Style string
5245: we expect the input string describing the style to be of the form
5246: property: value [ ; property: value ]*
5247: but tolerate incorrect or incomplete input
1.18 cvs 5248: ----------------------------------------------------------------------*/
1.79 cvs 5249: static void ParseCSSRule (Element element, PSchema tsch,
1.327 vatton 5250: PresentationContext ctxt, char *cssRule,
5251: CSSInfoPtr css, ThotBool isHTML)
1.18 cvs 5252: {
1.34 cvs 5253: DisplayMode dispMode;
1.312 quint 5254: char *p = NULL, *next, *end;
1.214 quint 5255: char *valueStart;
1.18 cvs 5256: int lg;
1.34 cvs 5257: unsigned int i;
1.76 cvs 5258: ThotBool found;
1.18 cvs 5259:
1.34 cvs 5260: /* avoid too many redisplay */
1.207 vatton 5261: dispMode = TtaGetDisplayMode (ctxt->doc);
1.34 cvs 5262: if (dispMode == DisplayImmediately)
1.207 vatton 5263: TtaSetDisplayMode (ctxt->doc, DeferredDisplay);
1.34 cvs 5264:
1.82 cvs 5265: while (*cssRule != EOS)
1.18 cvs 5266: {
1.82 cvs 5267: cssRule = SkipBlanksAndComments (cssRule);
1.153 vatton 5268: if (*cssRule < 0x41 || *cssRule > 0x7A ||
1.327 vatton 5269: (*cssRule > 0x5A && *cssRule < 0x60))
5270: cssRule++;
1.194 vatton 5271: else if (*cssRule != EOS)
1.327 vatton 5272: {
5273: found = FALSE;
5274: /* look for the type of property */
5275: for (i = 0; i < NB_CSSSTYLEATTRIBUTE && !found; i++)
5276: {
5277: lg = strlen (CSSProperties[i].name);
5278: if (!strncasecmp (cssRule, CSSProperties[i].name, lg))
5279: {
5280: p = cssRule + lg;
5281: found = TRUE;
5282: i--;
5283: }
5284: }
5285:
5286: if (i < NB_CSSSTYLEATTRIBUTE &&
5287: !strcasecmp (CSSProperties[i].name, "content") &&
5288: ((GenericContext)ctxt)->pseudo != PbBefore &&
5289: ((GenericContext)ctxt)->pseudo != PbAfter)
1.340 quint 5290: /* property content is allowed only for pseudo-elements :before and
5291: :after */
1.327 vatton 5292: {
5293: end = cssRule;
1.345 quint 5294: end = SkipProperty (end, FALSE);
1.327 vatton 5295: CSSParseError ("content is allowed only for pseudo-elements",
5296: cssRule, end);
5297: i = NB_CSSSTYLEATTRIBUTE;
5298: }
5299: if (i == NB_CSSSTYLEATTRIBUTE)
5300: cssRule = SkipProperty (cssRule, TRUE);
5301: else
5302: {
5303: /* update index and skip the ":" indicator if present */
5304: p = SkipBlanksAndComments (p);
5305: if (*p == ':')
5306: {
5307: p++;
5308: p = SkipBlanksAndComments (p);
5309: /* try to parse the value associated with this property */
5310: if (CSSProperties[i].parsing_function != NULL)
5311: {
5312: valueStart = p;
5313: p = CSSProperties[i].parsing_function (element, tsch,
5314: ctxt, p, css, isHTML);
5315: if (!element && isHTML)
5316: {
5317: if (ctxt->type == HTML_EL_Input)
5318: /* it's a generic rule for the HTML element input.
5319: Generate a Thot Pres rule for each kind of
5320: input element */
5321: {
5322: ctxt->type = HTML_EL_Text_Input;
5323: p = CSSProperties[i].parsing_function (element,
5324: tsch, ctxt, valueStart, css, isHTML);
5325: ctxt->type = HTML_EL_Password_Input;
5326: p = CSSProperties[i].parsing_function (element,
5327: tsch, ctxt, valueStart, css, isHTML);
5328: ctxt->type = HTML_EL_File_Input;
5329: p = CSSProperties[i].parsing_function (element,
5330: tsch, ctxt, valueStart, css, isHTML);
5331: ctxt->type = HTML_EL_Checkbox_Input;
5332: p = CSSProperties[i].parsing_function (element,
5333: tsch, ctxt, valueStart, css, isHTML);
5334: ctxt->type = HTML_EL_Radio_Input;
5335: p = CSSProperties[i].parsing_function (element,
5336: tsch, ctxt, valueStart, css, isHTML);
5337: ctxt->type = HTML_EL_Submit_Input;
5338: p = CSSProperties[i].parsing_function (element,
5339: tsch, ctxt, valueStart, css, isHTML);
5340: ctxt->type = HTML_EL_Reset_Input;
5341: p = CSSProperties[i].parsing_function (element,
5342: tsch, ctxt, valueStart, css, isHTML);
5343: ctxt->type = HTML_EL_Button_Input;
5344: p = CSSProperties[i].parsing_function (element,
5345: tsch, ctxt, valueStart, css, isHTML);
5346: ctxt->type = HTML_EL_Input;
5347: }
5348: else if (ctxt->type == HTML_EL_ruby)
5349: /* it's a generic rule for the HTML element ruby.
5350: Generate a Thot Pres rule for each kind of
5351: ruby element. */
5352: {
5353: ctxt->type = HTML_EL_simple_ruby;
5354: p = CSSProperties[i].parsing_function (element,
5355: tsch, ctxt, valueStart, css, isHTML);
5356: ctxt->type = HTML_EL_complex_ruby;
5357: p = CSSProperties[i].parsing_function (element,
5358: tsch, ctxt, valueStart, css, isHTML);
5359: ctxt->type = HTML_EL_ruby;
5360: }
5361: }
5362: /* update index and skip the ";" separator if present */
5363: next = SkipBlanksAndComments (p);
5364: if (*next != EOS && *next != ';')
5365: CSSParseError ("Missing closing ';'", cssRule, p);
5366: cssRule = next;
5367: }
5368: }
5369: else
5370: cssRule = SkipProperty (cssRule, TRUE);
5371: }
5372: }
1.18 cvs 5373: /* next property */
1.82 cvs 5374: cssRule = SkipBlanksAndComments (cssRule);
1.89 cvs 5375: if (*cssRule == '}')
1.327 vatton 5376: {
5377: cssRule++;
5378: CSSPrintError ("Invalid character", "}");
5379: cssRule = SkipBlanksAndComments (cssRule);
5380: }
1.155 cheyroul 5381: if (*cssRule == ',' ||
1.327 vatton 5382: *cssRule == ';')
5383: {
5384: cssRule++;
5385: cssRule = SkipBlanksAndComments (cssRule);
5386: }
1.18 cvs 5387: }
1.34 cvs 5388:
5389: /* restore the display mode */
5390: if (dispMode == DisplayImmediately)
1.207 vatton 5391: TtaSetDisplayMode (ctxt->doc, dispMode);
1.18 cvs 5392: }
1.1 cvs 5393:
1.111 cvs 5394: /*----------------------------------------------------------------------
1.327 vatton 5395: ParseHTMLSpecificStyle: parse and apply a CSS Style string.
5396: This function must be called when a specific style is applied to an
5397: element.
5398: The parameter specificity is the specificity of the style, 0 if it is
5399: not really a CSS rule.
1.1 cvs 5400: ----------------------------------------------------------------------*/
1.79 cvs 5401: void ParseHTMLSpecificStyle (Element el, char *cssRule, Document doc,
1.327 vatton 5402: int specificity, ThotBool destroy)
1.1 cvs 5403: {
1.257 vatton 5404: DisplayMode dispMode;
1.207 vatton 5405: PresentationContext ctxt;
5406: ElementType elType;
5407: ThotBool isHTML;
1.1 cvs 5408:
1.207 vatton 5409: /* A rule applying to BODY is really meant to address HTML */
5410: elType = TtaGetElementType (el);
1.286 quint 5411: NewLineSkipped = 0;
1.207 vatton 5412: /* store the current line for eventually reported errors */
5413: LineNumber = TtaGetElementLineNumber (el);
5414: if (destroy)
5415: /* no reported errors */
5416: ParsedDoc = 0;
5417: else if (ParsedDoc != doc)
5418: {
5419: /* update the context for reported errors */
5420: ParsedDoc = doc;
5421: DocURL = DocumentURLs[doc];
5422: }
5423: isHTML = (strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML") == 0);
5424: /* create the context of the Specific presentation driver */
5425: ctxt = TtaGetSpecificStyleContext (doc);
5426: if (ctxt == NULL)
5427: return;
5428: ctxt->type = elType.ElTypeNum;
5429: ctxt->cssSpecificity = specificity;
1.236 quint 5430: ctxt->cssLine = LineNumber;
1.207 vatton 5431: ctxt->destroy = destroy;
5432: /* first use of the context */
5433: ctxt->uses = 1;
1.257 vatton 5434: /* save the current display mode */
5435: dispMode = TtaGetDisplayMode (doc);
1.207 vatton 5436: /* Call the parser */
5437: ParseCSSRule (el, NULL, (PresentationContext) ctxt, cssRule, NULL, isHTML);
1.257 vatton 5438: /* restore the display mode if necessary */
5439: TtaSetDisplayMode (doc, dispMode);
1.207 vatton 5440: /* check if the context can be freed */
5441: ctxt->uses -= 1;
5442: if (ctxt->uses == 0)
5443: /* no image loading */
5444: TtaFreeMemory(ctxt);
1.1 cvs 5445: }
5446:
1.343 vatton 5447: /*----------------------------------------------------------------------
5448: AddClassName adds the class name into the class list of css if it's
5449: not already there.
5450: ----------------------------------------------------------------------*/
5451: static void AddClassName (char *name, CSSInfoPtr css)
5452: {
1.344 cvs 5453: int l, index, k, length, add;
1.343 vatton 5454: char *buf;
5455: ThotBool found, previous;
5456:
5457: l = strlen (name);
5458: if (l == 0 || css == NULL)
5459: return;
5460: if (css->class_list)
5461: {
5462: buf = css->class_list;
5463: length = strlen (css->class_list);
5464: }
5465: else
5466: {
5467: if (l > 200)
5468: length = l + 1;
5469: else
5470: length = 200;
5471: buf = (char *)TtaGetMemory (length * sizeof (char));
5472: memset (buf, 0, length);
5473: css->class_list = buf;
5474: css->lg_class_list = length;
5475: length = 0;
5476: }
5477:
5478: /* compare that name with all class names already known */
5479: index = 0;
5480: found = FALSE;
5481: previous = FALSE;
5482: while (index < length && !found && !previous)
5483: {
5484: k = 0;
5485: while (k < l && buf[index + k] != EOS && buf[index + k] != SPACE)
5486: {
5487: if (name[k] == buf[index+k])
5488: k++;
5489: else
5490: {
5491: previous = (name[k] < buf[index + k]);
5492: break;
5493: }
5494: }
5495: found = (k == l);
5496: if (!previous)
5497: {
5498: index += k;
5499: while (buf[index] != EOS && buf[index] != SPACE)
5500: index++;
5501: if (buf[index] == SPACE)
5502: index++;
5503: }
5504: }
5505:
5506: if (!found)
5507: /* this class name is not known, append it */
5508: {
5509: l++; /* add a space before */
5510: if (css->lg_class_list <= length + l)
5511: {
5512: // increase the list size
5513: if (l > 200)
5514: add = l + 1;
5515: else
5516: add = 200 ;
5517: buf = (char *)TtaRealloc (buf, css->lg_class_list + (add * sizeof (char)));
5518: if (buf == NULL)
5519: return;
5520: else
5521: {
5522: css->class_list = buf;
5523: memset (&buf[css->lg_class_list], 0, add);
5524: css->lg_class_list += add;
5525: }
5526: }
5527:
5528: if (previous)
5529: {
5530: // move the tail of the current list
5531: for (k = length; k >= index; k--)
5532: buf[k+l] = buf[k];
5533: /* add this new class name at the current position */
5534: strcpy (&buf[index], name);
5535: buf[index + l - 1] = SPACE;
5536: }
5537: else
5538: {
5539: /* add this new class name at the end */
5540: if (index != 0)
5541: buf[index++] = SPACE;
5542: strcpy (&buf[index], name);
5543: }
5544: }
5545: }
5546:
1.68 cvs 5547:
1.1 cvs 5548: /*----------------------------------------------------------------------
1.207 vatton 5549: ParseGenericSelector: Create a generic context for a given selector
5550: string.
5551: If the selector is made of multiple comma, it parses them one at a time
5552: and return the end of the selector string to be handled or NULL.
1.231 vatton 5553: The parameter ctxt gives the current style context which will be passed
5554: to Thotlib.
5555: The parameter css points to the current CSS context.
5556: The parameter link points to the link element.
5557: The parameter url gives the URL of the parsed style sheet.
1.1 cvs 5558: ----------------------------------------------------------------------*/
1.207 vatton 5559: static char *ParseGenericSelector (char *selector, char *cssRule,
1.327 vatton 5560: GenericContext ctxt, Document doc,
5561: CSSInfoPtr css, Element link, char *url)
1.79 cvs 5562: {
5563: ElementType elType;
5564: PSchema tsch;
1.119 vatton 5565: AttributeType attrType;
1.240 quint 5566: char *deb, *cur, *sel, *next, c;
1.317 vatton 5567: char *schemaName, *mappedName, *saveURL;
1.79 cvs 5568: char *names[MAX_ANCESTORS];
1.340 quint 5569: ElemRel rel[MAX_ANCESTORS];
5570: char *attrnames[MAX_ANCESTORS];
5571: int attrnums[MAX_ANCESTORS];
5572: int attrlevels[MAX_ANCESTORS];
1.79 cvs 5573: char *attrvals[MAX_ANCESTORS];
1.133 vatton 5574: AttrMatch attrmatch[MAX_ANCESTORS];
1.340 quint 5575: int nbnames, nbattrs;
5576: int i, j;
1.256 vatton 5577: int att, kind;
1.118 vatton 5578: int specificity, xmlType;
1.217 vatton 5579: int skippedNL;
1.79 cvs 5580: ThotBool isHTML;
1.183 vatton 5581: ThotBool level, quoted;
1.340 quint 5582: #define ATTR_ID 1
5583: #define ATTR_CLASS 2
5584: #define ATTR_PSEUDO 3
1.1 cvs 5585:
1.207 vatton 5586: sel = ctxt->sel;
1.82 cvs 5587: sel[0] = EOS;
1.117 vatton 5588: specificity = 0;
1.1 cvs 5589: for (i = 0; i < MAX_ANCESTORS; i++)
5590: {
1.25 cvs 5591: names[i] = NULL;
1.340 quint 5592: rel[i] = RelAncestor;
5593: attrnames[i] = NULL;
5594: attrnums[i] = 0;
5595: attrlevels[i] = 0;
1.25 cvs 5596: attrvals[i] = NULL;
1.133 vatton 5597: attrmatch[i] = Txtmatch;
1.25 cvs 5598: ctxt->name[i] = 0;
5599: ctxt->attrType[i] = 0;
1.129 vatton 5600: ctxt->attrLevel[i] = 0;
1.25 cvs 5601: ctxt->attrText[i] = NULL;
1.178 quint 5602: ctxt->attrMatch[i] = Txtmatch;
1.1 cvs 5603: }
1.25 cvs 5604: ctxt->box = 0;
1.312 quint 5605: ctxt->var = 0;
1.306 quint 5606: ctxt->pseudo = PbNone;
1.25 cvs 5607: ctxt->type = 0;
1.114 quint 5608: /* the specificity of the rule depends on the selector */
5609: ctxt->cssSpecificity = 0;
1.231 vatton 5610: /* localisation of the CSS rule */
5611: ctxt->cssLine = LineNumber + NewLineSkipped;
5612: ctxt->cssURL = url;
1.240 quint 5613:
1.286 quint 5614: skippedNL = NewLineSkipped;
1.82 cvs 5615: selector = SkipBlanksAndComments (selector);
1.286 quint 5616: NewLineSkipped = skippedNL;
1.27 cvs 5617: cur = &sel[0];
1.340 quint 5618: nbnames = 0;
5619: nbattrs = 0;
1.1 cvs 5620: while (1)
5621: {
1.85 cvs 5622: /* point to the following word in sel[] */
1.27 cvs 5623: deb = cur;
1.25 cvs 5624: /* copy an item of the selector into sel[] */
1.1 cvs 5625: /* put one word in the sel buffer */
1.82 cvs 5626: while (*selector != EOS && *selector != ',' &&
5627: *selector != '.' && *selector != ':' &&
1.118 vatton 5628: *selector != '#' && *selector != '[' &&
1.250 vatton 5629: *selector != '>' && *selector != '+' &&
1.327 vatton 5630: !TtaIsBlank (selector))
5631: *cur++ = *selector++;
1.82 cvs 5632: *cur++ = EOS; /* close the first string in sel[] */
5633: if (deb[0] != EOS)
1.340 quint 5634: /* the selector starts with an element name */
1.327 vatton 5635: {
5636: if (deb[0] <= 64 && deb[0] != '*')
5637: {
5638: CSSPrintError ("Invalid element", deb);
5639: return NULL;
5640: }
5641: else
5642: {
5643: names[0] = deb;
5644: if (!strcmp (names[0], "html"))
5645: /* give a greater priority to the backgoud color of html */
5646: specificity += 3;
5647: else
5648: /* selector "*" has specificity zero */
5649: if (strcmp (names[0], "*"))
5650: specificity += 1;
5651: }
5652: }
1.25 cvs 5653: else
1.340 quint 5654: names[0] = NULL; /* no element name */
1.226 quint 5655:
1.340 quint 5656: rel[0] = RelVoid;
1.25 cvs 5657:
1.27 cvs 5658: /* now names[0] points to the beginning of the parsed item
1.340 quint 5659: and cur to the next string to be parsed */
1.129 vatton 5660: while (*selector == '.' || *selector == ':' ||
1.327 vatton 5661: *selector == '#' || *selector == '[')
5662: {
5663: /* point to the following word in sel[] */
5664: deb = cur;
5665: if (*selector == '.')
1.340 quint 5666: /* class */
1.327 vatton 5667: {
5668: selector++;
1.340 quint 5669: while (*selector != '.' && *selector != ':' &&
5670: *selector != '#' && *selector != '[' &&
5671: *selector != EOS && *selector != ',' &&
5672: *selector != '+' && *selector != '>' &&
1.327 vatton 5673: !TtaIsBlank (selector))
5674: {
5675: if (*selector == '\\')
5676: {
5677: selector++;
5678: if (*selector != EOS)
5679: *cur++ = *selector++;
5680: }
5681: else
5682: *cur++ = *selector++;
5683: }
5684: /* close the word */
5685: *cur++ = EOS;
1.340 quint 5686: /* point to the class in sel[] if it's a valid name */
1.327 vatton 5687: if (deb[0] <= 64)
5688: {
5689: CSSPrintError ("Invalid class", deb);
5690: DoApply = FALSE;
5691: }
5692: else
5693: {
1.340 quint 5694: /* simulate selector [class ~= "xxx"] */
5695: nbattrs++;
5696: if (nbattrs == MAX_ANCESTORS)
5697: /* abort parsing */
5698: {
5699: CSSPrintError ("Selector too long", deb);
5700: return (selector);
5701: }
5702: for (i = nbattrs; i > 0; i--)
5703: {
5704: attrnames[i] = attrnames[i - 1];
5705: attrnums[i] = attrnums[i - 1];
5706: attrlevels[i] = attrlevels[i - 1];
5707: attrvals[i] = attrvals[i - 1];
5708: attrmatch[i] = attrmatch[i - 1];
5709: }
5710: attrnames[0] = NULL;
5711: attrnums[0] = ATTR_CLASS;
5712: attrlevels[0] = 0;
5713: attrmatch[0] = Txtword;
5714: attrvals[0] = deb;
1.327 vatton 5715: specificity += 10;
1.343 vatton 5716: }
1.327 vatton 5717: }
5718: else if (*selector == ':')
1.340 quint 5719: /* pseudo-class or pseudo-element */
1.327 vatton 5720: {
5721: selector++;
1.340 quint 5722: while (*selector != '.' && *selector != ':' &&
5723: *selector != '#' && *selector != '[' &&
5724: *selector != EOS && *selector != ',' &&
5725: *selector != '+' && *selector != '>' &&
1.327 vatton 5726: !TtaIsBlank (selector))
5727: *cur++ = *selector++;
5728: /* close the word */
5729: *cur++ = EOS;
1.340 quint 5730: /* point to the pseudo-class or pseudo-element in sel[] if it's
5731: a valid name */
1.327 vatton 5732: if (deb[0] <= 64)
5733: {
1.340 quint 5734: CSSPrintError ("Invalid pseudo-element", deb);
1.327 vatton 5735: DoApply = FALSE;
5736: }
5737: else
5738: {
5739: if (!strcmp (deb, "first-letter") ||
5740: !strcmp (deb, "first-line") ||
5741: !strcmp (deb, "hover") ||
5742: !strcmp (deb, "focus"))
5743: /* not supported */
5744: DoApply = FALSE;
5745: else
5746: specificity += 10;
1.340 quint 5747: if (!strncmp (deb, "before", 6))
5748: ctxt->pseudo = PbBefore;
5749: else if (!strncmp (deb, "after", 5))
5750: ctxt->pseudo = PbAfter;
1.327 vatton 5751: else if (!strncmp (deb, "lang", 4))
5752: /* it's the lang pseudo-class */
5753: {
5754: if (deb[4] != '(' || deb[strlen(deb)-1] != ')')
1.340 quint 5755: /* at least one parenthesis is missing. Error */
1.327 vatton 5756: {
1.340 quint 5757: CSSPrintError ("Invalid :lang pseudo-class", deb);
1.327 vatton 5758: DoApply = FALSE;
5759: }
5760: else
1.340 quint 5761: /* simulate selector [lang|="xxx"] */
5762: {
5763: nbattrs++;
5764: if (nbattrs == MAX_ANCESTORS)
5765: /* abort parsing */
5766: {
5767: CSSPrintError ("Selector too long", deb);
5768: return (selector);
5769: }
5770: deb[strlen(deb)-1] = EOS;
5771: deb[4] = EOS;
5772: for (i = nbattrs; i > 0; i--)
5773: {
5774: attrnames[i] = attrnames[i - 1];
5775: attrnums[i] = attrnums[i - 1];
5776: attrlevels[i] = attrlevels[i - 1];
5777: attrvals[i] = attrvals[i - 1];
5778: attrmatch[i] = attrmatch[i - 1];
5779: }
5780: attrnames[0] = deb;
5781: attrnums[0] = 0;
5782: attrlevels[0] = 0;
5783: attrmatch[0] = Txtsubstring;
5784: attrvals[0] = &deb[5];
5785: }
1.327 vatton 5786: }
5787: else
1.340 quint 5788: {
5789: nbattrs++;
5790: if (nbattrs == MAX_ANCESTORS)
5791: /* abort parsing */
5792: {
5793: CSSPrintError ("Selector too long", deb);
5794: return (selector);
5795: }
5796: for (i = nbattrs; i > 0; i--)
5797: {
5798: attrnames[i] = attrnames[i - 1];
5799: attrnums[i] = attrnums[i - 1];
5800: attrlevels[i] = attrlevels[i - 1];
5801: attrvals[i] = attrvals[i - 1];
5802: attrmatch[i] = attrmatch[i - 1];
5803: }
5804: attrnames[0] = NULL;
5805: attrnums[0] = ATTR_PSEUDO;
5806: attrlevels[0] = 0;
5807: attrmatch[0] = Txtmatch;
5808: attrvals[0] = deb;
5809: }
1.327 vatton 5810: if (names[0] && !strcmp (names[0], "*"))
5811: names[0] = NULL;
5812: }
5813: }
5814: else if (*selector == '#')
1.340 quint 5815: /* unique identifier */
1.327 vatton 5816: {
5817: selector++;
1.340 quint 5818: while (*selector != '.' && *selector != ':' &&
5819: *selector != '#' && *selector != '[' &&
5820: *selector != '+' && *selector != '>' &&
5821: *selector != EOS && *selector != ',' &&
1.327 vatton 5822: !TtaIsBlank (selector))
5823: *cur++ = *selector++;
5824: /* close the word */
5825: *cur++ = EOS;
5826: /* point to the attribute in sel[] if it's valid name */
5827: if (deb[0] <= 64)
5828: {
5829: CSSPrintError ("Invalid id", deb);
5830: DoApply = FALSE;
5831: }
5832: else
5833: {
1.340 quint 5834: nbattrs++;
5835: if (nbattrs == MAX_ANCESTORS)
5836: /* abort parsing */
5837: {
5838: CSSPrintError ("Selector too long", deb);
5839: return (selector);
5840: }
5841: for (i = nbattrs; i > 0; i--)
5842: {
5843: attrnames[i] = attrnames[i - 1];
5844: attrnums[i] = attrnums[i - 1];
5845: attrlevels[i] = attrlevels[i - 1];
5846: attrvals[i] = attrvals[i - 1];
5847: attrmatch[i] = attrmatch[i - 1];
5848: }
5849: attrnames[0] = NULL;
5850: attrnums[0] = ATTR_ID;
5851: attrlevels[0] = 0;
5852: attrmatch[0] = Txtmatch;
5853: attrvals[0] = deb;
5854: specificity += 100;
5855: if (names[0] && !strcmp (names[0], "*"))
5856: names[0] = NULL;
1.327 vatton 5857: }
5858: }
5859: else if (*selector == '[')
5860: {
5861: selector++;
1.341 quint 5862: selector = SkipBlanksAndComments (selector);
1.327 vatton 5863: while (*selector != EOS && *selector != ']' &&
5864: *selector != '=' && *selector != '~' &&
1.341 quint 5865: *selector != '|' && *selector != '^' &&
5866: !TtaIsBlank (selector))
1.327 vatton 5867: *cur++ = *selector++;
1.341 quint 5868: /* close the word (attribute name) */
1.327 vatton 5869: *cur++ = EOS;
5870: /* point to the attribute in sel[] if it's valid name */
5871: if (deb[0] <= 64)
5872: {
5873: CSSPrintError ("Invalid attribute", deb);
5874: DoApply = FALSE;
5875: }
5876: else
5877: {
1.340 quint 5878: nbattrs++;
5879: if (nbattrs == MAX_ANCESTORS)
5880: /* abort parsing */
5881: {
5882: CSSPrintError ("Selector too long", deb);
5883: return (selector);
5884: }
5885: for (i = nbattrs; i > 0; i--)
5886: {
5887: attrnames[i] = attrnames[i - 1];
5888: attrnums[i] = attrnums[i - 1];
5889: attrlevels[i] = attrlevels[i - 1];
5890: attrvals[i] = attrvals[i - 1];
5891: attrmatch[i] = attrmatch[i - 1];
5892: }
5893: attrnames[0] = deb;
5894: attrnums[0] = 0;
5895: attrlevels[0] = 0;
1.327 vatton 5896: specificity += 10;
1.340 quint 5897: /* check matching */
1.341 quint 5898: selector = SkipBlanksAndComments (selector);
1.340 quint 5899: if (*selector == '~')
5900: {
5901: attrmatch[0] = Txtword;
5902: selector++;
5903: }
5904: else if (*selector == '|')
5905: {
5906: attrmatch[0] = Txtsubstring;
5907: selector++;
5908: }
1.341 quint 5909: else if (*selector == '^')
5910: {
5911: attrmatch[0] = Txtsubstring;
5912: selector++;
5913: }
1.340 quint 5914: else
5915: attrmatch[0] = Txtmatch;
1.327 vatton 5916: }
5917: if (*selector == '=')
5918: {
5919: /* look for a value "xxxx" */
5920: selector++;
1.341 quint 5921: selector = SkipBlanksAndComments (selector);
1.327 vatton 5922: if (*selector != '"')
5923: quoted = FALSE;
5924: else
5925: {
5926: quoted = TRUE;
5927: /* we are now parsing the attribute value */
5928: selector++;
5929: }
5930: deb = cur;
5931: while ((quoted &&
5932: (*selector != '"' ||
5933: (*selector == '"' && selector[-1] == '\\'))) ||
5934: (!quoted && *selector != ']'))
5935: {
5936: if (*selector == EOS)
5937: {
5938: CSSPrintError ("Invalid attribute value", deb);
5939: DoApply = FALSE;
5940: }
5941: else
5942: {
5943: if (attrmatch[0] == Txtword && TtaIsBlank (selector))
5944: {
5945: CSSPrintError ("No space allowed here: ", selector);
5946: DoApply = FALSE;
5947: }
5948: *cur++ = *selector;
5949: }
5950: selector++;
5951: }
5952: /* there is a value */
5953: if (quoted && *selector == '"')
5954: {
5955: selector++;
5956: quoted = FALSE;
5957: }
1.341 quint 5958: selector = SkipBlanksAndComments (selector);
1.327 vatton 5959: if (*selector != ']')
5960: {
5961: CSSPrintError ("Invalid attribute value", deb);
5962: DoApply = FALSE;
5963: }
5964: else
5965: {
5966: *cur++ = EOS;
5967: attrvals[0] = deb;
5968: selector++;
5969: }
5970: }
5971: /* end of the attribute */
5972: else if (*selector != ']')
5973: {
5974: selector[1] = EOS;
5975: CSSPrintError ("Invalid attribute", selector);
5976: selector += 2;
5977: DoApply = FALSE;
5978: }
5979: else
5980: {
5981: selector++;
5982: if (names[0] && !strcmp (names[0], "*"))
5983: names[0] = NULL;
5984: }
5985: }
5986: else
5987: {
5988: /* not supported selector */
1.340 quint 5989: while (*selector != '.' && *selector != ':' &&
5990: *selector != '#' && *selector != '[' &&
5991: *selector != EOS && *selector != ',' &&
5992: *selector != '+' && *selector != '>' &&
1.327 vatton 5993: !TtaIsBlank (selector))
5994: *cur++ = *selector++;
5995: /* close the word */
5996: *cur++ = EOS;
5997: CSSPrintError ("Selector not supported:", deb);
5998: DoApply = FALSE;
5999: }
6000: }
1.1 cvs 6001:
1.286 quint 6002: skippedNL = NewLineSkipped;
1.82 cvs 6003: selector = SkipBlanksAndComments (selector);
1.286 quint 6004: NewLineSkipped = skippedNL;
6005:
1.25 cvs 6006: /* is it a multi-level selector? */
1.82 cvs 6007: if (*selector == EOS)
1.327 vatton 6008: /* end of the selector */
6009: break;
1.82 cvs 6010: else if (*selector == ',')
1.327 vatton 6011: {
6012: /* end of the current selector */
6013: selector++;
6014: skippedNL = NewLineSkipped;
6015: next = SkipBlanksAndComments (selector);
6016: NewLineSkipped = skippedNL;
6017: if (*next == EOS)
6018: /* nothing after the comma. Invalid selector */
6019: {
6020: /*CSSPrintError ("Syntax error:", selector);*/
6021: return NULL;
6022: }
6023: break;
6024: }
1.25 cvs 6025: else
1.327 vatton 6026: {
6027: if (*selector == '>')
6028: {
1.340 quint 6029: /* handle parent */
1.327 vatton 6030: selector++;
6031: skippedNL = NewLineSkipped;
6032: selector = SkipBlanksAndComments (selector);
6033: NewLineSkipped = skippedNL;
1.340 quint 6034: rel[0] = RelParent;
1.327 vatton 6035: }
6036: else if (*selector == '+')
6037: {
1.340 quint 6038: /* handle immediate sibling */
1.327 vatton 6039: selector++;
6040: skippedNL = NewLineSkipped;
6041: selector = SkipBlanksAndComments (selector);
6042: NewLineSkipped = skippedNL;
6043: rel[0] = RelPrevious;
6044: }
1.340 quint 6045: else
6046: rel[0] = RelAncestor;
6047: nbnames++; /* a new level in ancestor tables */
6048: if (nbnames == MAX_ANCESTORS)
6049: /* abort parsing */
6050: {
6051: CSSPrintError ("Selector too long", deb);
6052: return (selector);
6053: }
6054: /* shift the list to make room for the next part of the selector */
6055: for (i = nbnames; i > 0; i--)
1.327 vatton 6056: {
6057: names[i] = names[i - 1];
6058: rel[i] = rel[i - 1];
6059: }
1.340 quint 6060: /* increase the level of all attributes */
6061: for (i = 0; i < nbattrs; i++)
6062: attrlevels[i]++;
1.327 vatton 6063: }
1.1 cvs 6064: }
6065:
1.343 vatton 6066: /* Now update the list of classes defined by the CSS */
6067: for (i = 0; i < nbattrs; i++)
6068: if (attrvals[i] && attrnums[i] == ATTR_CLASS)
6069: AddClassName (attrvals[i], css);
6070:
1.1 cvs 6071: /* Now set up the context block */
1.25 cvs 6072: i = 0;
6073: j = 0;
1.91 cvs 6074: /* default schema name */
1.119 vatton 6075: ctxt->schema = NULL;
1.340 quint 6076: ctxt->nbElem = nbnames;
1.122 vatton 6077: elType.ElSSchema = NULL;
6078: schemaName = TtaGetSSchemaName(TtaGetDocumentSSchema (doc));
1.119 vatton 6079: if (!strcmp (schemaName, "HTML"))
6080: xmlType = XHTML_TYPE;
6081: else if (!strcmp (schemaName, "MathML"))
6082: xmlType = MATH_TYPE;
6083: else if (!strcmp (schemaName, "SVG"))
6084: xmlType = SVG_TYPE;
6085: else if (!strcmp (schemaName, "XLink"))
6086: xmlType = XLINK_TYPE;
6087: else if (!strcmp (schemaName, "Annot"))
6088: xmlType = ANNOT_TYPE;
6089: else
6090: xmlType = XML_TYPE;
1.340 quint 6091: while (i <= nbnames)
1.25 cvs 6092: {
1.340 quint 6093: ctxt->rel[i] = rel[i];
6094: if (!names[i])
6095: ctxt->name[i] = HTML_EL_ANY_TYPE;
6096: else
6097: /* store element information */
1.327 vatton 6098: {
6099: /* get the element type of this name in the current document */
6100: if (xmlType == XML_TYPE)
6101: /* it's a generic XML document. Check the main document schema */
6102: {
6103: elType.ElSSchema = TtaGetDocumentSSchema (doc);
6104: TtaGetXmlElementType (names[i], &elType, &mappedName, doc);
6105: if (!elType.ElTypeNum)
6106: {
6107: if (!strcmp (names[i], "*"))
6108: elType.ElTypeNum = HTML_EL_ANY_TYPE;
6109: else
6110: elType.ElSSchema = NULL;
6111: }
6112: }
6113: else
6114: {
6115: if (!strcmp (names[i], "*"))
6116: {
6117: elType.ElSSchema = TtaGetDocumentSSchema (doc);
6118: elType.ElTypeNum = HTML_EL_ANY_TYPE;
6119: }
6120: else
6121: MapXMLElementType (xmlType, names[i], &elType, &mappedName, &c,
6122: &level, doc);
6123: }
6124: if (i == 0)
1.340 quint 6125: /* rightmost part of the selector */
1.327 vatton 6126: {
6127: if (elType.ElSSchema == NULL)
6128: {
1.340 quint 6129: /* element name not found. Search in all loaded schemas */
1.327 vatton 6130: TtaGetXmlElementType (names[i], &elType, NULL, doc);
6131: if (elType.ElSSchema)
6132: {
6133: /* the element type concerns an imported nature */
6134: schemaName = TtaGetSSchemaName(elType.ElSSchema);
6135: if (!strcmp (schemaName, "HTML"))
6136: {
6137: if (xmlType == XHTML_TYPE &&
6138: DocumentMeta[doc] && DocumentMeta[doc]->xmlformat)
6139: /* the selector was found but the case is not correct */
6140: elType.ElSSchema = NULL;
6141: else
6142: xmlType = XHTML_TYPE;
6143: }
6144: else if (!strcmp (schemaName, "MathML"))
6145: xmlType = MATH_TYPE;
6146: else if (!strcmp (schemaName, "SVG"))
6147: xmlType = SVG_TYPE;
6148: else if (!strcmp (schemaName, "XLink"))
6149: xmlType = XLINK_TYPE;
6150: else if (!strcmp (schemaName, "Annot"))
6151: xmlType = ANNOT_TYPE;
6152: else
6153: xmlType = XML_TYPE;
6154: }
1.118 vatton 6155: #ifdef XML_GENERIC
1.327 vatton 6156: else if (xmlType == XML_TYPE)
6157: {
6158: /* Creation of a new element type in the main schema */
6159: elType.ElSSchema = TtaGetDocumentSSchema (doc);
6160: TtaAppendXmlElement (names[i], &elType, &mappedName, doc);
6161: }
1.118 vatton 6162: #endif /* XML_GENERIC */
1.327 vatton 6163: else
6164: {
6165: if (xmlType != XHTML_TYPE)
6166: {
6167: MapXMLElementType (XHTML_TYPE, names[i], &elType,
6168: &mappedName, &c, &level, doc);
6169: if (elType.ElSSchema)
6170: elType.ElSSchema = GetXHTMLSSchema (doc);
6171: }
6172: if (elType.ElSSchema == NULL && xmlType != MATH_TYPE)
6173: {
6174: MapXMLElementType (MATH_TYPE, names[i], &elType,
6175: &mappedName, &c, &level, doc);
6176: if (elType.ElSSchema)
6177: elType.ElSSchema = GetMathMLSSchema (doc);
6178: }
6179: if (elType.ElSSchema == NULL && xmlType != SVG_TYPE)
6180: {
6181: MapXMLElementType (SVG_TYPE, names[i], &elType,
6182: &mappedName, &c, &level, doc);
6183: if (elType.ElSSchema)
6184: elType.ElSSchema = GetSVGSSchema (doc);
6185: }
6186: }
6187: }
6188:
6189: if (elType.ElSSchema == NULL)
6190: /* cannot apply these CSS rules */
6191: DoApply = FALSE;
6192: else
6193: {
1.340 quint 6194: /* Store the element type contained in the rightmost part of
6195: the selector */
6196: ctxt->schema = elType.ElSSchema;
1.327 vatton 6197: ctxt->type = elType.ElTypeNum;
6198: ctxt->name[0] = elType.ElTypeNum;
1.340 quint 6199: ctxt->rel[0] = RelVoid;
1.327 vatton 6200: }
6201: }
1.340 quint 6202: else
6203: /* not the rightmost part of the selector */
1.327 vatton 6204: {
1.340 quint 6205: if (elType.ElTypeNum != 0)
6206: ctxt->name[i] = elType.ElTypeNum;
6207: #ifdef XML_GENERIC
6208: else if (xmlType == XML_TYPE)
1.327 vatton 6209: {
1.340 quint 6210: TtaGetXmlElementType (names[i], &elType, NULL, doc);
6211: if (elType.ElTypeNum == 0)
1.327 vatton 6212: {
1.340 quint 6213: /* Creation of a new element type in the main schema */
6214: elType.ElSSchema = TtaGetDocumentSSchema (doc);
6215: TtaAppendXmlElement (names[i], &elType, &mappedName, doc);
1.327 vatton 6216: }
1.340 quint 6217: if (elType.ElTypeNum != 0)
6218: ctxt->name[i] = elType.ElTypeNum;
1.327 vatton 6219: }
1.340 quint 6220: #endif /* XML_GENERIC */
1.327 vatton 6221: }
1.340 quint 6222: }
6223:
6224: /* store attribute information for this element */
6225: while (j < nbattrs && attrlevels[j] <= i)
6226: {
6227: if (attrnames[j] || attrnums[j])
1.327 vatton 6228: {
1.340 quint 6229: if (attrnums[j] > 0)
1.327 vatton 6230: {
1.340 quint 6231: if (attrnums[j] == ATTR_CLASS)
1.327 vatton 6232: {
1.340 quint 6233: if (xmlType == SVG_TYPE)
6234: ctxt->attrType[j] = SVG_ATTR_class;
6235: else if (xmlType == MATH_TYPE)
6236: ctxt->attrType[j] = MathML_ATTR_class;
6237: else if (xmlType == XHTML_TYPE)
6238: ctxt->attrType[j] = HTML_ATTR_Class;
1.327 vatton 6239: else
1.119 vatton 6240: #ifdef XML_GENERIC
1.340 quint 6241: ctxt->attrType[j] = XML_ATTR_class;
1.107 cvs 6242: #else /* XML_GENERIC */
1.340 quint 6243: ctxt->attrType[j] = HTML_ATTR_Class;
1.107 cvs 6244: #endif /* XML_GENERIC */
1.340 quint 6245: }
6246: else if (attrnums[j] == ATTR_PSEUDO)
6247: {
6248: if (xmlType == SVG_TYPE)
6249: ctxt->attrType[j] = SVG_ATTR_PseudoClass;
6250: else if (xmlType == MATH_TYPE)
6251: ctxt->attrType[j] = MathML_ATTR_PseudoClass;
6252: else if (xmlType == XHTML_TYPE)
6253: ctxt->attrType[j] = HTML_ATTR_PseudoClass;
6254: else
1.119 vatton 6255: #ifdef XML_GENERIC
1.340 quint 6256: ctxt->attrType[j] = XML_ATTR_PseudoClass;
1.107 cvs 6257: #else /* XML_GENERIC */
1.340 quint 6258: ctxt->attrType[j] = HTML_ATTR_PseudoClass;
1.107 cvs 6259: #endif /* XML_GENERIC */
1.340 quint 6260: }
6261: else if (attrnums[j] == ATTR_ID)
6262: {
6263: if (xmlType == SVG_TYPE)
6264: ctxt->attrType[j] = SVG_ATTR_id;
6265: else if (xmlType == MATH_TYPE)
6266: ctxt->attrType[j] = MathML_ATTR_id;
6267: else if (xmlType == XHTML_TYPE)
6268: ctxt->attrType[j] = HTML_ATTR_ID;
6269: else
1.119 vatton 6270: #ifdef XML_GENERIC
1.340 quint 6271: ctxt->attrType[j] = XML_ATTR_xmlid;
1.107 cvs 6272: #else /* XML_GENERIC */
1.340 quint 6273: ctxt->attrType[j] = HTML_ATTR_ID;
1.107 cvs 6274: #endif /* XML_GENERIC */
1.340 quint 6275: }
6276: attrType.AttrTypeNum = ctxt->attrType[j];
6277: attrType.AttrSSchema = ctxt->schema;
6278: }
6279: else if (attrnames[j])
6280: {
6281: if (xmlType == XML_TYPE)
6282: {
6283: if (ctxt->schema)
6284: attrType.AttrSSchema = ctxt->schema;
6285: else
6286: attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
6287: TtaGetXmlAttributeType (attrnames[j], &attrType, doc);
6288: att = attrType.AttrTypeNum;
6289: if (ctxt->schema == NULL && att != 0)
6290: ctxt->schema = attrType.AttrSSchema;
6291: }
6292: else
6293: {
6294: MapXMLAttribute (xmlType, attrnames[j], names[i], &level,
6295: doc, &att);
6296: if (ctxt->schema == NULL && att != 0)
6297: ctxt->schema = TtaGetDocumentSSchema (doc);
6298: }
6299: if (att == 0 && ctxt->schema == NULL)
6300: /* Attribute name not found: Search in the list of all
6301: schemas loaded for this document */
6302: {
6303: attrType.AttrSSchema = NULL;
6304: TtaGetXmlAttributeType (attrnames[j], &attrType, doc);
6305: att = attrType.AttrTypeNum;
6306: if (att != 0)
6307: ctxt->schema = attrType.AttrSSchema;
6308: }
6309: attrType.AttrSSchema = ctxt->schema;
6310: attrType.AttrTypeNum = att;
6311: if (i == 0 && att == 0 && ctxt->schema == NULL)
6312: {
6313: /* Not found -> search in the list of loaded schemas */
6314: attrType.AttrSSchema = NULL;
6315: TtaGetXmlAttributeType (attrnames[j], &attrType, doc);
6316: att = attrType.AttrTypeNum;
6317: if (attrType.AttrSSchema)
6318: /* the element type concerns an imported nature */
6319: schemaName = TtaGetSSchemaName(attrType.AttrSSchema);
1.119 vatton 6320: #ifdef XML_GENERIC
1.340 quint 6321: else if (xmlType == XML_TYPE)
6322: {
6323: /* The attribute is not yet present in the tree */
6324: /* Create a new global attribute */
6325: attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
6326: TtaAppendXmlAttribute (attrnames[j], &attrType, doc);
6327: }
6328: #endif /* XML_GENERIC */
6329: if (attrType.AttrSSchema == NULL)
6330: /* cannot apply these CSS rules */
6331: DoApply = FALSE;
6332: else if (elType.ElSSchema)
6333: ctxt->schema = elType.ElSSchema;
6334: else
6335: ctxt->schema = attrType.AttrSSchema;
6336: }
6337: if (att == 0)
6338: {
6339: CSSPrintError ("Unknown attribute", attrnames[j]);
6340: DoApply = FALSE;
6341: }
6342: else
1.345 quint 6343: {
6344: ctxt->attrType[j] = att;
6345: if (att == DummyAttribute && !strcmp (schemaName,"HTML"))
6346: /* it's the "type" attribute for an "input" element.
6347: In the tree, it is represented by the element type,
6348: not by an attribute */
6349: {
6350: ctxt->attrType[j] = 0;
6351: if (attrvals[j] && attrmatch[i] == Txtmatch)
6352: /* a value is specified for attribute type. This
6353: value provides the Thot element type */
6354: {
6355: MapXMLAttributeValue (xmlType, attrvals[j],
6356: &attrType, &kind);
6357: /* attrType contains the element type */
6358: if (i == 0)
6359: ctxt->type = kind;
6360: ctxt->name[i] = kind;
6361: }
6362: }
6363: }
1.340 quint 6364: }
6365: if (ctxt->attrType[j])
1.327 vatton 6366: {
1.340 quint 6367: /* check the attribute type */
6368: if (!strcmp (schemaName, "HTML"))
6369: xmlType = XHTML_TYPE;
6370: else if (!strcmp (schemaName, "MathML"))
6371: xmlType = MATH_TYPE;
6372: else if (!strcmp (schemaName, "SVG"))
6373: xmlType = SVG_TYPE;
6374: else if (!strcmp (schemaName, "XLink"))
6375: xmlType = XLINK_TYPE;
6376: else if (!strcmp (schemaName, "Annot"))
6377: xmlType = ANNOT_TYPE;
6378: else
6379: xmlType = XML_TYPE;
6380: kind = TtaGetAttributeKind (attrType);
6381: if (kind == 0 && attrvals[j])
6382: {
6383: /* enumerated value */
6384: MapXMLAttributeValue (xmlType, attrvals[j], &attrType,
6385: &kind);
6386: /* store the attribute value */
6387: ctxt->attrText[j] = (char *) kind;
6388: }
6389: else
6390: ctxt->attrText[j] = attrvals[j];
6391: /* update attrLevel */
6392: ctxt->attrMatch[j] = attrmatch[j];
6393: ctxt->attrLevel[j] = attrlevels[j];
6394: }
6395: j++;
1.327 vatton 6396: }
6397: }
1.340 quint 6398: /* add a new entry */
1.25 cvs 6399: i++;
1.119 vatton 6400: if (i == 1 && ctxt->schema == NULL)
1.327 vatton 6401: /* use the document schema */
6402: ctxt->schema = TtaGetDocumentSSchema (doc);
1.1 cvs 6403: }
1.340 quint 6404:
1.312 quint 6405: ctxt->important = FALSE;
1.117 vatton 6406: /* set the selector specificity */
6407: ctxt->cssSpecificity = specificity;
1.25 cvs 6408: /* Get the schema name of the main element */
1.119 vatton 6409: schemaName = TtaGetSSchemaName (ctxt->schema);
6410: isHTML = (strcmp (schemaName, "HTML") == 0);
1.206 vatton 6411: tsch = GetPExtension (doc, ctxt->schema, css, link);
1.217 vatton 6412: skippedNL = NewLineSkipped;
1.119 vatton 6413: if (tsch && cssRule)
1.317 vatton 6414: {
6415: if (css)
1.327 vatton 6416: {
6417: /* point the right URL for loaded images */
6418: saveURL = css->url;
6419: css->url = url;
6420: }
1.317 vatton 6421: else
1.327 vatton 6422: saveURL = NULL;
6423: ParseCSSRule (NULL, tsch, (PresentationContext) ctxt, cssRule, css, isHTML);
1.317 vatton 6424: if (css)
1.327 vatton 6425: /* restore previous url */
6426: css->url = saveURL;
1.317 vatton 6427: }
1.116 vatton 6428: /* future CSS rules should apply */
6429: DoApply = TRUE;
1.217 vatton 6430: if (selector)
6431: NewLineSkipped = skippedNL;
1.1 cvs 6432: return (selector);
6433: }
6434:
6435: /*----------------------------------------------------------------------
1.206 vatton 6436: ParseStyleDeclaration: parse a style declaration stored in the style
6437: element of a document
6438: We expect the style string to be of the form:
6439: .pinky, .awful { color: pink; font-family: helvetica }
1.231 vatton 6440: The parameter css points to the current CSS context.
6441: The parameter link points to the link element.
6442: The parameter url gives the URL of the parsed style sheet.
1.1 cvs 6443: ----------------------------------------------------------------------*/
1.206 vatton 6444: static void ParseStyleDeclaration (Element el, char *cssRule, Document doc,
1.327 vatton 6445: CSSInfoPtr css, Element link, char *url,
6446: ThotBool destroy)
1.1 cvs 6447: {
1.79 cvs 6448: GenericContext ctxt;
6449: char *decl_end;
6450: char *sel_end;
6451: char *selector;
1.1 cvs 6452:
6453: /* separate the selectors string */
1.82 cvs 6454: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 6455: decl_end = cssRule;
1.82 cvs 6456: while (*decl_end != EOS && *decl_end != '{')
1.286 quint 6457: {
6458: if (*decl_end == EOL)
1.327 vatton 6459: NewLineSkipped++;
1.286 quint 6460: decl_end++;
6461: }
1.82 cvs 6462: if (*decl_end == EOS)
1.86 cvs 6463: {
1.168 vatton 6464: CSSPrintError ("Invalid selector", cssRule);
1.86 cvs 6465: return;
6466: }
1.1 cvs 6467: /* verify and clean the selector string */
6468: sel_end = decl_end - 1;
1.82 cvs 6469: while (*sel_end == SPACE || *sel_end == BSPACE ||
1.327 vatton 6470: *sel_end == EOL || *sel_end == CR)
1.1 cvs 6471: sel_end--;
6472: sel_end++;
1.82 cvs 6473: *sel_end = EOS;
1.1 cvs 6474: selector = cssRule;
6475:
6476: /* now, deal with the content ... */
6477: decl_end++;
6478: cssRule = decl_end;
1.137 vatton 6479: decl_end = &cssRule[strlen (cssRule) - 1];
6480: if (*decl_end != '{')
6481: *decl_end = EOS;
1.1 cvs 6482: /*
6483: * parse the style attribute string and install the corresponding
6484: * presentation attributes on the new element
6485: */
6486: ctxt = TtaGetGenericStyleContext (doc);
6487: if (ctxt == NULL)
6488: return;
6489: ctxt->destroy = destroy;
1.207 vatton 6490: /* first use of the context */
6491: ctxt->uses = 1;
1.197 vatton 6492: while (selector && *selector != EOS)
1.231 vatton 6493: selector = ParseGenericSelector (selector, cssRule, ctxt, doc, css,
1.327 vatton 6494: link, url);
1.207 vatton 6495: /* check if the context can be freed */
6496: ctxt->uses -= 1;
6497: if (ctxt->uses == 0)
6498: /* no image loading */
6499: TtaFreeMemory (ctxt);
1.1 cvs 6500: }
6501:
6502: /************************************************************************
6503: * *
6504: * EVALUATION FUNCTIONS / CASCADING AND OVERLOADING *
6505: * *
6506: ************************************************************************/
6507:
6508: /*----------------------------------------------------------------------
1.327 vatton 6509: IsImplicitClassName: return wether the Class name is an
6510: implicit one, eg "H1" or "H2 EM" meaning it's a GI name
6511: or an HTML context name.
1.1 cvs 6512: ----------------------------------------------------------------------*/
1.248 gully 6513: int IsImplicitClassName (char *class_, Document doc)
1.1 cvs 6514: {
1.327 vatton 6515: char name[200];
6516: char *cur = name;
6517: char *first;
6518: char save;
6519: SSchema schema;
6520:
6521: /* make a local copy */
6522: strncpy (name, class_, 199);
6523: name[199] = 0;
6524:
6525: /* loop looking if each word is a GI */
6526: while (*cur != 0)
6527: {
6528: first = cur;
6529: cur = SkipWord (cur);
6530: save = *cur;
6531: *cur = 0;
6532: schema = NULL;
6533: if (MapGI (first, &schema, doc) == -1)
6534: {
6535: return (0);
6536: }
6537: *cur = save;
6538: cur = SkipBlanksAndComments (cur);
6539: }
6540: return (1);
1.1 cvs 6541: }
6542:
6543: /************************************************************************
6544: * *
1.114 quint 6545: * Functions needed for support of HTML: translate to CSS equivalent *
1.1 cvs 6546: * *
6547: ************************************************************************/
6548:
6549: /*----------------------------------------------------------------------
1.327 vatton 6550: HTMLSetBackgroundColor:
1.1 cvs 6551: ----------------------------------------------------------------------*/
1.264 vatton 6552: void HTMLSetBackgroundColor (Document doc, Element el, int specificity,
1.327 vatton 6553: char *color)
1.1 cvs 6554: {
1.327 vatton 6555: char css_command[100];
1.1 cvs 6556:
1.327 vatton 6557: sprintf (css_command, "background-color: %s", color);
6558: ParseHTMLSpecificStyle (el, css_command, doc, specificity, FALSE);
1.1 cvs 6559: }
6560:
6561: /*----------------------------------------------------------------------
1.327 vatton 6562: HTMLSetForegroundColor:
1.1 cvs 6563: ----------------------------------------------------------------------*/
1.264 vatton 6564: void HTMLSetForegroundColor (Document doc, Element el, int specificity,
1.327 vatton 6565: char *color)
1.1 cvs 6566: {
1.327 vatton 6567: char css_command[100];
1.1 cvs 6568:
1.327 vatton 6569: sprintf (css_command, "color: %s", color);
6570: ParseHTMLSpecificStyle (el, css_command, doc, specificity, FALSE);
1.1 cvs 6571: }
6572:
6573: /*----------------------------------------------------------------------
1.327 vatton 6574: HTMLResetBackgroundColor:
1.1 cvs 6575: ----------------------------------------------------------------------*/
1.97 vatton 6576: void HTMLResetBackgroundColor (Document doc, Element el)
1.1 cvs 6577: {
1.327 vatton 6578: char css_command[100];
1.1 cvs 6579:
1.327 vatton 6580: sprintf (css_command, "background: red");
6581: ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1 cvs 6582: }
6583:
6584: /*----------------------------------------------------------------------
1.327 vatton 6585: HTMLResetBackgroundImage:
1.1 cvs 6586: ----------------------------------------------------------------------*/
1.97 vatton 6587: void HTMLResetBackgroundImage (Document doc, Element el)
1.1 cvs 6588: {
1.327 vatton 6589: char css_command[1000];
1.1 cvs 6590:
1.327 vatton 6591: sprintf (css_command, "background-image: url(xx); background-repeat: repeat");
6592: ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1 cvs 6593: }
6594:
6595: /*----------------------------------------------------------------------
1.327 vatton 6596: HTMLResetForegroundColor:
1.1 cvs 6597: ----------------------------------------------------------------------*/
1.97 vatton 6598: void HTMLResetForegroundColor (Document doc, Element el)
1.1 cvs 6599: {
1.327 vatton 6600: char css_command[100];
1.1 cvs 6601:
1.327 vatton 6602: /* it's not necessary to well know the current color but it must be valid */
6603: sprintf (css_command, "color: red");
6604: ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1 cvs 6605: }
6606:
6607: /*----------------------------------------------------------------------
1.327 vatton 6608: HTMLSetAlinkColor:
1.1 cvs 6609: ----------------------------------------------------------------------*/
1.208 vatton 6610: void HTMLSetAlinkColor (Document doc, Element el, char *color)
1.1 cvs 6611: {
1.327 vatton 6612: char css_command[100];
1.1 cvs 6613:
1.327 vatton 6614: sprintf (css_command, ":link { color: %s }", color);
6615: ApplyCSSRules (el, css_command, doc, FALSE);
1.1 cvs 6616: }
6617:
6618: /*----------------------------------------------------------------------
1.327 vatton 6619: HTMLSetAactiveColor:
1.1 cvs 6620: ----------------------------------------------------------------------*/
1.208 vatton 6621: void HTMLSetAactiveColor (Document doc, Element el, char *color)
1.1 cvs 6622: {
1.327 vatton 6623: char css_command[100];
1.1 cvs 6624:
1.327 vatton 6625: sprintf (css_command, ":active { color: %s }", color);
6626: ApplyCSSRules (el, css_command, doc, FALSE);
1.1 cvs 6627: }
6628:
6629: /*----------------------------------------------------------------------
1.327 vatton 6630: HTMLSetAvisitedColor:
1.1 cvs 6631: ----------------------------------------------------------------------*/
1.208 vatton 6632: void HTMLSetAvisitedColor (Document doc, Element el, char *color)
1.1 cvs 6633: {
1.327 vatton 6634: char css_command[100];
1.1 cvs 6635:
1.327 vatton 6636: sprintf (css_command, ":visited { color: %s }", color);
6637: ApplyCSSRules (el, css_command, doc, FALSE);
1.1 cvs 6638: }
6639:
6640: /*----------------------------------------------------------------------
1.327 vatton 6641: HTMLResetAlinkColor:
1.1 cvs 6642: ----------------------------------------------------------------------*/
1.208 vatton 6643: void HTMLResetAlinkColor (Document doc, Element el)
1.1 cvs 6644: {
1.327 vatton 6645: char css_command[100];
1.1 cvs 6646:
1.327 vatton 6647: sprintf (css_command, ":link { color: red }");
6648: ApplyCSSRules (el, css_command, doc, TRUE);
1.1 cvs 6649: }
6650:
6651: /*----------------------------------------------------------------------
1.327 vatton 6652: HTMLResetAactiveColor:
1.1 cvs 6653: ----------------------------------------------------------------------*/
1.208 vatton 6654: void HTMLResetAactiveColor (Document doc, Element el)
1.1 cvs 6655: {
1.327 vatton 6656: char css_command[100];
1.1 cvs 6657:
1.327 vatton 6658: sprintf (css_command, ":active { color: red }");
6659: ApplyCSSRules (el, css_command, doc, TRUE);
1.1 cvs 6660: }
6661:
6662: /*----------------------------------------------------------------------
1.327 vatton 6663: HTMLResetAvisitedColor:
1.1 cvs 6664: ----------------------------------------------------------------------*/
1.208 vatton 6665: void HTMLResetAvisitedColor (Document doc, Element el)
1.1 cvs 6666: {
1.327 vatton 6667: char css_command[100];
1.1 cvs 6668:
1.327 vatton 6669: sprintf (css_command, ":visited { color: red }");
6670: ApplyCSSRules (el, css_command, doc, TRUE);
1.1 cvs 6671: }
6672:
6673: /*----------------------------------------------------------------------
1.206 vatton 6674: ApplyCSSRules: parse a CSS Style description stored in the header of
6675: a HTML document.
1.1 cvs 6676: ----------------------------------------------------------------------*/
1.79 cvs 6677: void ApplyCSSRules (Element el, char *cssRule, Document doc, ThotBool destroy)
1.1 cvs 6678: {
1.206 vatton 6679: CSSInfoPtr css;
6680: PInfoPtr pInfo;
1.207 vatton 6681: ThotBool loadcss;
6682:
6683: /* check if we have to load CSS */
6684: TtaGetEnvBoolean ("LOAD_CSS", &loadcss);
6685: if (!loadcss)
6686: return;
1.1 cvs 6687:
1.206 vatton 6688: css = SearchCSS (doc, NULL, el, &pInfo);
1.1 cvs 6689: if (css == NULL)
1.209 vatton 6690: {
6691: /* create the document css context */
6692: css = AddCSS (doc, doc, CSS_DOCUMENT_STYLE, CSS_ALL, NULL, NULL, el);
6693: pInfo = css->infos[doc];
6694: }
1.206 vatton 6695: else if (pInfo == NULL)
6696: /* create the entry into the css context */
6697: pInfo = AddInfoCSS (doc, css, CSS_DOCUMENT_STYLE, CSS_ALL, el);
1.209 vatton 6698: if (pInfo->PiEnabled)
1.231 vatton 6699: ParseStyleDeclaration (el, cssRule, doc, css, el, NULL, destroy);
1.1 cvs 6700: }
6701:
6702: /*----------------------------------------------------------------------
1.327 vatton 6703: ReadCSSRules: is the front-end function called by the document parser
6704: when detecting a <style type="text/css"> indicating it's the
6705: beginning of a CSS fragment or when reading a file .css.
1.1 cvs 6706:
1.327 vatton 6707: The CSS parser has to handle <!-- ... --> constructs used to
6708: prevent prehistoric browser from displaying the CSS as a text
6709: content. It will stop on any sequence "<x" where x is different
6710: from ! and will return x as to the caller. Theorically x should
6711: be equal to / for the </style> end of style.
6712: The parameter doc gives the document tree that contains CSS information.
6713: The parameter docRef gives the document to which CSS are to be applied.
6714: This function uses the current css context or creates it. It's able
6715: to work on the given buffer or call GetNextChar to read the parsed
6716: file.
6717: The parameter url gives the URL of the parsed style sheet.
6718: The parameter numberOfLinesRead gives the number of lines already
6719: read in the file.
6720: The parameter withUndo indicates whether the changes made in the document
6721: structure and content have to be registered in the Undo queue or not.
1.1 cvs 6722: ----------------------------------------------------------------------*/
1.133 vatton 6723: char ReadCSSRules (Document docRef, CSSInfoPtr css, char *buffer, char *url,
1.343 vatton 6724: int numberOfLinesRead, ThotBool withUndo, Element link)
1.1 cvs 6725: {
1.6 cvs 6726: DisplayMode dispMode;
1.206 vatton 6727: CSSInfoPtr refcss = NULL;
1.321 vatton 6728: CSSmedia css_media = CSS_ALL;
1.206 vatton 6729: PInfoPtr pInfo;
1.321 vatton 6730: char c;
1.138 vatton 6731: char *cssRule, *base, *saveDocURL, *ptr;
1.19 cvs 6732: int index;
1.1 cvs 6733: int CSSindex;
1.327 vatton 6734: int CSScomment;
1.1 cvs 6735: int import;
6736: int openRule;
1.93 vatton 6737: int newlines;
1.14 cvs 6738: ThotBool HTMLcomment;
1.342 vatton 6739: ThotBool toParse, eof, quoted, s_quoted;
6740: ThotBool ignore, media, page, lineComment;
1.234 vatton 6741: ThotBool noRule, ignoreImport, fontface;
1.1 cvs 6742:
1.327 vatton 6743: CSScomment = MAX_CSS_LENGTH;
1.1 cvs 6744: HTMLcomment = FALSE;
6745: CSSindex = 0;
6746: toParse = FALSE;
6747: noRule = FALSE;
1.234 vatton 6748: media = FALSE;
1.88 cvs 6749: ignoreImport = FALSE;
1.342 vatton 6750: ignore = lineComment = FALSE;
1.234 vatton 6751: page = FALSE;
1.342 vatton 6752: quoted = s_quoted = FALSE;
1.234 vatton 6753: fontface = FALSE;
1.1 cvs 6754: eof = FALSE;
6755: openRule = 0;
1.234 vatton 6756: import = MAX_CSS_LENGTH;
1.82 cvs 6757: c = SPACE;
1.1 cvs 6758: index = 0;
1.134 vatton 6759: base = NULL;
1.310 vatton 6760: /* entering the CSS parsing */
1.311 vatton 6761: Style_parsing++;
1.93 vatton 6762: /* number of new lines parsed */
6763: newlines = 0;
1.6 cvs 6764: /* avoid too many redisplay */
6765: dispMode = TtaGetDisplayMode (docRef);
6766: if (dispMode == DisplayImmediately)
6767: TtaSetDisplayMode (docRef, DeferredDisplay);
1.18 cvs 6768:
6769: /* look for the CSS context */
6770: if (css == NULL)
1.206 vatton 6771: css = SearchCSS (docRef, NULL, link, &pInfo);
1.207 vatton 6772: else
6773: pInfo = css->infos[docRef];
1.18 cvs 6774: if (css == NULL)
1.206 vatton 6775: {
6776: css = AddCSS (docRef, docRef, CSS_DOCUMENT_STYLE, CSS_ALL, NULL, NULL, link);
6777: pInfo = css->infos[docRef];
6778: }
6779: else if (pInfo == NULL)
6780: pInfo = AddInfoCSS (docRef, css, CSS_DOCUMENT_STYLE, CSS_ALL, link);
1.174 vatton 6781: /* look for the CSS descriptor that points to the extension schema */
6782: refcss = css;
1.224 vatton 6783: if (pInfo && pInfo->PiCategory == CSS_IMPORT)
1.173 cvs 6784: {
1.206 vatton 6785: while (refcss &&
1.327 vatton 6786: refcss->infos[docRef] && refcss->infos[docRef]->PiCategory == CSS_IMPORT)
6787: refcss = refcss->NextCSS;
1.206 vatton 6788: if (refcss)
1.327 vatton 6789: pInfo = refcss->infos[docRef];
1.173 cvs 6790: }
6791:
1.343 vatton 6792: /* register parsed CSS file and the document to which CSS are to be applied */
1.86 cvs 6793: ParsedDoc = docRef;
1.343 vatton 6794: /* clean up the list of classes */
6795: TtaFreeMemory (refcss->class_list);
6796: refcss->class_list = NULL;
1.133 vatton 6797: if (url)
6798: DocURL = url;
1.86 cvs 6799: else
6800: /* the CSS source in within the document itself */
6801: DocURL = DocumentURLs[docRef];
6802: LineNumber = numberOfLinesRead + 1;
1.93 vatton 6803: NewLineSkipped = 0;
1.217 vatton 6804: newlines = 0;
1.82 cvs 6805: while (CSSindex < MAX_CSS_LENGTH && c != EOS && !eof)
6806: {
6807: c = buffer[index++];
6808: eof = (c == EOS);
6809: CSSbuffer[CSSindex] = c;
1.342 vatton 6810: if (!lineComment &&
6811: (CSScomment == MAX_CSS_LENGTH || c == '*' || c == '/' || c == '<' || c == EOL))
1.327 vatton 6812: {
6813: /* we're not within a comment or we're parsing * or / */
6814: switch (c)
6815: {
6816: case '@': /* perhaps an import primitive */
1.342 vatton 6817: if (!fontface && !page && !quoted && !s_quoted)
1.327 vatton 6818: import = CSSindex;
6819: break;
6820: case ';':
1.342 vatton 6821: if (!quoted && !s_quoted && !media && import != MAX_CSS_LENGTH)
1.327 vatton 6822: {
6823: if (strncasecmp (&CSSbuffer[import+1], "import", 6))
6824: /* it's not an import */
6825: import = MAX_CSS_LENGTH;
6826: /* save the text */
6827: noRule = TRUE;
6828: }
6829: break;
6830: case '*':
1.342 vatton 6831: if (!quoted && !s_quoted && CSScomment == MAX_CSS_LENGTH && CSSindex > 0 &&
1.327 vatton 6832: CSSbuffer[CSSindex - 1] == '/')
6833: /* start a comment */
6834: CSScomment = CSSindex - 1;
6835: break;
6836: case '/':
1.342 vatton 6837: if (!quoted && !s_quoted && CSSindex > 1 && CSScomment != MAX_CSS_LENGTH &&
1.327 vatton 6838: CSSbuffer[CSSindex - 1] == '*')
6839: {
6840: while (CSSindex > 0 && CSSindex >= CSScomment)
6841: {
6842: if ( CSSbuffer[CSSindex] == EOL)
6843: {
6844: LineNumber ++;
6845: newlines --;
6846: }
6847: CSSindex--;
6848: }
6849: CSSindex = CSScomment - 1; /* will be incremented later */
6850: CSScomment = MAX_CSS_LENGTH;
6851: /* clean up the buffer */
6852: if (newlines && CSSindex > 0)
6853: while (CSSindex > 0 &&
6854: (CSSbuffer[CSSindex] == SPACE ||
6855: CSSbuffer[CSSindex] == BSPACE ||
6856: CSSbuffer[CSSindex] == EOL ||
6857: CSSbuffer[CSSindex] == TAB ||
6858: CSSbuffer[CSSindex] == __CR__))
6859: {
6860: if ( CSSbuffer[CSSindex] == EOL)
6861: {
6862: LineNumber ++;
6863: newlines --;
6864: }
6865: CSSindex--;
6866: }
6867: }
1.342 vatton 6868: else if (!fontface && !page && !quoted && !s_quoted &&
1.327 vatton 6869: CSScomment == MAX_CSS_LENGTH && CSSindex > 0 &&
6870: CSSbuffer[CSSindex - 1] == '<')
6871: {
6872: /* this is the closing tag ! */
6873: CSSindex -= 2; /* remove </ from the CSS string */
6874: noRule = TRUE;
1.342 vatton 6875: }
6876: else if (!quoted && !s_quoted &&
6877: (CSSindex == 1 || (CSSindex > 1 && CSSbuffer[CSSindex - 2] == EOL)) &&
6878: CSScomment == MAX_CSS_LENGTH &&
6879: CSSbuffer[CSSindex - 1] == '/')
6880: {
6881: CSSindex--;
6882: lineComment = TRUE;
6883: }
6884:
1.327 vatton 6885: break;
6886: case '<':
1.342 vatton 6887: if (!fontface && !page && !quoted && !s_quoted &&
1.327 vatton 6888: CSScomment == MAX_CSS_LENGTH)
6889: {
6890: /* only if we're not parsing a comment */
6891: c = buffer[index++];
6892: eof = (c == EOS);
6893: if (c == '!')
6894: {
6895: /* CSS within an HTML comment */
6896: HTMLcomment = TRUE;
6897: CSSindex++;
6898: CSSbuffer[CSSindex] = c;
6899: }
6900: else if (c == EOS)
6901: CSSindex++;
6902: }
6903: break;
6904: case '-':
1.342 vatton 6905: if (!fontface && !page && !quoted && !s_quoted &&
1.327 vatton 6906: CSSindex > 0 && CSSbuffer[CSSindex - 1] == '-' &&
6907: HTMLcomment)
6908: /* CSS within an HTML comment */
6909: noRule = TRUE;
6910: break;
6911: case '>':
1.342 vatton 6912: if (!fontface && !page && !quoted && !s_quoted && HTMLcomment)
1.327 vatton 6913: noRule = TRUE;
6914: break;
6915: case ' ':
1.342 vatton 6916: if (!quoted && !s_quoted && import != MAX_CSS_LENGTH && openRule == 0)
1.327 vatton 6917: media = !strncasecmp (&CSSbuffer[import+1], "media", 5);
6918: break;
6919: case '{':
1.342 vatton 6920: if (!quoted && !s_quoted)
1.327 vatton 6921: {
6922: openRule++;
6923: if (import != MAX_CSS_LENGTH)
6924: {
6925: if (openRule == 1 && media)
6926: {
6927: /* is it the screen concerned? */
6928: CSSbuffer[CSSindex+1] = EOS;
6929: css_media = CheckMediaCSS (&CSSbuffer[import+7]);
6930: if (TtaIsPrinting ())
6931: ignore = (css_media != CSS_ALL && css_media != CSS_PRINT);
6932: else
6933: ignore = (css_media != CSS_ALL && css_media != CSS_SCREEN);
6934: noRule = TRUE;
6935: }
6936: else if (!strncasecmp (&CSSbuffer[import+1], "page", 4))
6937: {
6938: page = TRUE;
6939: noRule = TRUE;
6940: }
6941: else if (!strncasecmp (&CSSbuffer[import+1], "font-face", 9))
6942: {
6943: fontface = TRUE;
6944: noRule = TRUE;
6945: }
6946: }
6947: }
6948: break;
6949: case '}':
1.342 vatton 6950: if (!quoted && !s_quoted)
1.327 vatton 6951: {
6952: openRule--;
6953: if (page)
6954: {
6955: noRule = TRUE;
6956: page = FALSE; /* close the page section */
6957: }
6958: else if (fontface)
6959: {
6960: noRule = TRUE;
6961: fontface = FALSE; /* close the fontface section */
6962: }
6963: else if (openRule == 0 && import != MAX_CSS_LENGTH)
6964: {
6965: import = MAX_CSS_LENGTH;
6966: noRule = TRUE;
6967: ignore = FALSE;
6968: media = FALSE;
6969: }
6970: else
6971: toParse = TRUE;
6972: }
6973: break;
6974: case '"':
6975: if (quoted)
6976: {
1.342 vatton 6977: if (CSSindex > 0 && CSSbuffer[CSSindex - 1] != '\\')
1.327 vatton 6978: quoted = FALSE;
6979: }
1.342 vatton 6980: else if (!s_quoted)
1.327 vatton 6981: quoted = TRUE;
6982: break;
1.342 vatton 6983: case '\'':
6984: if (s_quoted)
6985: {
6986: if (CSSindex > 0 && CSSbuffer[CSSindex - 1] != '\\')
6987: s_quoted = FALSE;
6988: }
6989: else if (!quoted)
6990: s_quoted = TRUE;
6991: break;
6992: default:
1.327 vatton 6993: if (c == EOL)
6994: {
6995: newlines++;
6996: }
6997: break;
6998: }
1.82 cvs 6999: }
1.93 vatton 7000: else if (c == EOL)
1.327 vatton 7001: {
7002: LineNumber++;
1.342 vatton 7003: lineComment = FALSE;
1.327 vatton 7004: c = CR;
7005: }
1.234 vatton 7006:
1.342 vatton 7007: if (!lineComment && c != CR)
1.327 vatton 7008: CSSindex++;
1.82 cvs 7009:
7010: if (CSSindex >= MAX_CSS_LENGTH && CSScomment < MAX_CSS_LENGTH)
1.327 vatton 7011: /* we're still parsing a comment: remove the text comment */
7012: CSSindex = CSScomment;
1.82 cvs 7013:
7014: if (CSSindex >= MAX_CSS_LENGTH || toParse || noRule)
1.327 vatton 7015: {
7016: CSSbuffer[CSSindex] = EOS;
7017: /* parse a not empty string */
7018: if (CSSindex > 0)
7019: {
1.50 cvs 7020: /* apply CSS rule if it's not just a saving of text */
1.234 vatton 7021: if (!noRule && !ignore)
1.327 vatton 7022: {
7023: /* future import rules must be ignored */
7024: ignoreImport = TRUE;
7025: NewLineSkipped = 0;
7026: ParseStyleDeclaration (NULL, CSSbuffer, docRef, refcss,
7027: pInfo->PiLink, url, FALSE);
7028: LineNumber += newlines;
7029: newlines = 0;
7030: }
1.82 cvs 7031: else if (import != MAX_CSS_LENGTH &&
1.327 vatton 7032: !strncasecmp (&CSSbuffer[import+1], "import", 6))
7033: {
7034: /* import section */
7035: cssRule = &CSSbuffer[import+7];
7036: cssRule = TtaSkipBlanks (cssRule);
7037: /* save the current line number */
7038: newlines += LineNumber;
7039: if (!strncasecmp (cssRule, "url", 3))
7040: {
1.50 cvs 7041: cssRule = &cssRule[3];
1.82 cvs 7042: cssRule = TtaSkipBlanks (cssRule);
7043: if (*cssRule == '(')
1.327 vatton 7044: {
7045: cssRule++;
7046: cssRule = TtaSkipBlanks (cssRule);
7047: quoted = (*cssRule == '"' || *cssRule == '\'');
7048: if (quoted)
7049: cssRule++;
7050: base = cssRule;
7051: while (*cssRule != EOS && *cssRule != ')')
7052: cssRule++;
7053: if (quoted)
7054: {
7055: /* isolate the file name */
7056: cssRule[-1] = EOS;
7057: quoted = FALSE;
7058: }
7059: else
7060: {
7061: /* remove extra spaces */
7062: if (cssRule[-1] == SPACE)
7063: {
7064: *cssRule = SPACE;
7065: cssRule--;
7066: while (cssRule[-1] == SPACE)
7067: cssRule--;
7068: }
7069: }
7070: *cssRule = EOS;
7071: }
7072: }
7073: else if (*cssRule == '"')
7074: {
7075: /*
7076: Do we have to accept single quotes?
7077: Double quotes are accepted here.
7078: Escaped quotes are not handled. See function SkipQuotedString
7079: */
7080: cssRule++;
7081: cssRule = TtaSkipBlanks (cssRule);
7082: base = cssRule;
7083: while (*cssRule != EOS &&
7084: (*cssRule != '"' ||
7085: (*cssRule == '"' && cssRule[-1] == '\\')))
7086: cssRule++;
7087: /* isolate the file name */
7088: *cssRule = EOS;
7089: }
7090: /* check if a media is defined */
7091: cssRule++;
7092: cssRule = TtaSkipBlanks (cssRule);
7093: if (*cssRule != ';')
7094: {
7095: css_media = CheckMediaCSS (cssRule);
7096: if (TtaIsPrinting ())
7097: ignoreImport = (css_media != CSS_ALL && css_media != CSS_PRINT);
7098: else
7099: ignoreImport = (css_media != CSS_ALL && css_media != CSS_SCREEN);
7100: }
7101: if (!ignoreImport)
7102: {
7103: /* save the displayed URL when an error is reported */
7104: saveDocURL = DocURL;
7105: ptr = TtaStrdup (base);
7106: /* get the CSS URI in UTF-8 */
7107: /*ptr = ReallocUTF8String (ptr, docRef);*/
7108: LoadStyleSheet (base, docRef, (Element) css, css,
7109: url, pInfo->PiMedia,
7110: pInfo->PiCategory == CSS_USER_STYLE);
7111: /* restore the displayed URL when an error is reported */
7112: DocURL = saveDocURL;
7113: TtaFreeMemory (ptr);
7114: }
7115: /* restore the number of lines */
7116: LineNumber = newlines;
7117: newlines = 0;
7118: NewLineSkipped = 0;
7119: import = MAX_CSS_LENGTH;
7120: }
7121: else
7122: {
7123: LineNumber += newlines;
7124: newlines = 0;
7125: }
7126: }
7127: toParse = FALSE;
7128: noRule = FALSE;
7129: CSSindex = 0;
1.50 cvs 7130: }
1.82 cvs 7131: }
1.310 vatton 7132: /* closing the CSS parsing */
1.311 vatton 7133: Style_parsing--;
1.330 cvs 7134: if (RedisplayImages == 0 && RedisplayBGImage && Style_parsing == 0)
1.310 vatton 7135: {
1.311 vatton 7136: /* CSS parsing finishes after a BG image was loaded */
1.310 vatton 7137: RedisplayBGImage = FALSE;
1.330 cvs 7138: if (dispMode != NoComputedDisplay)
7139: {
7140: RedisplayDoc = 0;
7141: //printf ("ReadCSS Show BGimages\n");
7142: TtaSetDisplayMode (docRef, NoComputedDisplay);
7143: TtaSetDisplayMode (docRef, dispMode);
7144: }
1.310 vatton 7145: }
1.330 cvs 7146: else if (dispMode != NoComputedDisplay)
1.311 vatton 7147: /* restore the display mode */
7148: TtaSetDisplayMode (docRef, dispMode);
1.86 cvs 7149:
7150: /* Prepare the context for style attributes */
7151: DocURL = DocumentURLs[docRef];
7152: LineNumber = -1;
1.1 cvs 7153: return (c);
7154: }
Webmaster