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