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