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