Annotation of Amaya/amaya/styleparser.c, revision 1.299
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.299 ! vatton 2497: TtaSetStylePresentation (PRSize, element, tsch, context, pval);
1.288 vatton 2498: if (!check && ptr)
2499: cssRule = ParseCSSLineHeight (element, tsch, context, &ptr[1], css, isHTML);
2500: if (linespace)
2501: *ptr = '/';
2502:
1.1 cvs 2503: return (cssRule);
2504: }
2505:
2506: /*----------------------------------------------------------------------
1.270 vatton 2507: ParseCSSFontSize: parse a CSS font size attr string
2508: we expect the input string describing the attribute to be
2509: xx-small, x-small, small, medium, large, x-large, xx-large
2510: or an absolute size, or an imcrement relative to the parent
2511: ----------------------------------------------------------------------*/
2512: static char *ParseCSSFontSize (Element element, PSchema tsch,
2513: PresentationContext context, char *cssRule,
2514: CSSInfoPtr css, ThotBool isHTML)
2515: {
1.299 ! vatton 2516: char *ptr = cssRule;
1.295 vatton 2517: cssRule = ParseACSSFontSize (element, tsch, context, cssRule, css, isHTML, FALSE);
2518: cssRule = CheckImportantRule (cssRule, context);
1.299 ! vatton 2519: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid font-size value");
1.295 vatton 2520: return cssRule;
1.270 vatton 2521: }
2522:
2523: /*----------------------------------------------------------------------
1.268 vatton 2524: ParseACSSFontFamily: parse a CSS font family string
1.1 cvs 2525: we expect the input string describing the attribute to be
2526: a common generic font style name
2527: ----------------------------------------------------------------------*/
1.268 vatton 2528: static char *ParseACSSFontFamily (Element element, PSchema tsch,
1.79 cvs 2529: PresentationContext context, char *cssRule,
2530: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2531: {
2532: PresentationValue font;
1.252 vatton 2533: char quoteChar, *p;
1.1 cvs 2534:
2535: font.typed_data.value = 0;
1.184 vatton 2536: font.typed_data.unit = UNIT_REL;
1.1 cvs 2537: font.typed_data.real = FALSE;
1.82 cvs 2538: cssRule = SkipBlanksAndComments (cssRule);
2539: if (*cssRule == '"' || *cssRule == '\'')
1.1 cvs 2540: {
2541: quoteChar = *cssRule;
2542: cssRule++;
2543: }
2544: else
1.82 cvs 2545: quoteChar = EOS;
1.1 cvs 2546:
1.293 quint 2547: if (!strncasecmp (cssRule, "inherit", 7) && quoteChar == EOS)
2548: {
2549: font.typed_data.unit = VALUE_INHERIT;
2550: cssRule += 7;
2551: }
2552: else if (!strncasecmp (cssRule, "times", 5) &&
1.92 cvs 2553: (quoteChar == EOS || quoteChar == cssRule[5]))
1.86 cvs 2554: {
1.184 vatton 2555: font.typed_data.value = FontTimes;
1.86 cvs 2556: cssRule += 5;
2557: }
1.92 cvs 2558: else if (!strncasecmp (cssRule, "serif", 5) &&
2559: (quoteChar == EOS || quoteChar == cssRule[5]))
1.86 cvs 2560: {
1.184 vatton 2561: font.typed_data.value = FontTimes;
1.86 cvs 2562: cssRule += 5;
1.92 cvs 2563: if (quoteChar != EOS)
2564: cssRule++;
1.86 cvs 2565: }
1.92 cvs 2566: else if (!strncasecmp (cssRule, "helvetica", 9) &&
2567: (quoteChar == EOS || quoteChar == cssRule[9]))
1.86 cvs 2568: {
1.184 vatton 2569: font.typed_data.value = FontHelvetica;
1.86 cvs 2570: cssRule += 9;
1.92 cvs 2571: if (quoteChar != EOS)
2572: cssRule++;
1.86 cvs 2573: }
1.92 cvs 2574: else if (!strncasecmp (cssRule, "verdana", 7) &&
2575: (quoteChar == EOS || quoteChar == cssRule[7]))
1.86 cvs 2576: {
1.184 vatton 2577: font.typed_data.value = FontHelvetica;
1.86 cvs 2578: cssRule += 7;
1.92 cvs 2579: if (quoteChar != EOS)
2580: cssRule++;
1.86 cvs 2581: }
1.92 cvs 2582: else if (!strncasecmp (cssRule, "sans-serif", 10) &&
2583: (quoteChar == EOS || quoteChar == cssRule[10]))
1.86 cvs 2584: {
1.184 vatton 2585: font.typed_data.value = FontHelvetica;
1.86 cvs 2586: cssRule += 10;
1.92 cvs 2587: if (quoteChar != EOS)
2588: cssRule++;
1.86 cvs 2589: }
1.268 vatton 2590: else if (!strncasecmp (cssRule, "courier new", 11) &&
2591: (quoteChar == EOS || quoteChar == cssRule[11]))
2592: {
2593: font.typed_data.value = FontCourier;
2594: cssRule += 11;
2595: if (quoteChar != EOS)
2596: cssRule++;
2597: }
1.92 cvs 2598: else if (!strncasecmp (cssRule, "courier", 7) &&
2599: (quoteChar == EOS || quoteChar == cssRule[7]))
1.86 cvs 2600: {
1.184 vatton 2601: font.typed_data.value = FontCourier;
1.86 cvs 2602: cssRule += 7;
1.92 cvs 2603: if (quoteChar != EOS)
2604: cssRule++;
1.86 cvs 2605: }
1.92 cvs 2606: else if (!strncasecmp (cssRule, "monospace", 9) &&
2607: (quoteChar == EOS || quoteChar == cssRule[9]))
1.86 cvs 2608: {
1.184 vatton 2609: font.typed_data.value = FontCourier;
1.86 cvs 2610: cssRule += 9;
1.92 cvs 2611: if (quoteChar != EOS)
2612: cssRule++;
1.86 cvs 2613: }
1.1 cvs 2614: else
2615: /* unknown font name. Skip it */
2616: {
1.252 vatton 2617: p = cssRule;
1.92 cvs 2618: if (quoteChar != EOS)
1.54 cvs 2619: cssRule = SkipQuotedString (cssRule, quoteChar);
1.86 cvs 2620: else
1.1 cvs 2621: cssRule = SkipWord (cssRule);
1.252 vatton 2622: while (p == cssRule &&
2623: *cssRule != ',' && *cssRule != ';' && *cssRule != EOS)
2624: {
2625: cssRule++;
2626: p = cssRule;
2627: cssRule = SkipWord (cssRule);
2628: }
1.82 cvs 2629: cssRule = SkipBlanksAndComments (cssRule);
2630: if (*cssRule == ',')
1.1 cvs 2631: {
1.239 vatton 2632: /* recursive call to ParseCSSFontFamily */
1.86 cvs 2633: cssRule++;
1.268 vatton 2634: cssRule = ParseACSSFontFamily (element, tsch, context, cssRule, css, isHTML);
1.86 cvs 2635: return (cssRule);
1.1 cvs 2636: }
2637: }
2638:
1.239 vatton 2639: /* skip other values */
2640: cssRule = SkipBlanksAndComments (cssRule);
2641: while (*cssRule == ',')
2642: {
2643: cssRule++;
2644: cssRule = SkipValue (NULL, cssRule);
2645: cssRule = SkipBlanksAndComments (cssRule);
2646: }
2647:
1.295 vatton 2648: cssRule = CheckImportantRule (cssRule, context);
2649: if ((font.typed_data.value != 0 || font.typed_data.unit == VALUE_INHERIT) &&
2650: DoApply)
2651: /* install the new presentation */
2652: TtaSetStylePresentation (PRFont, element, tsch, context, font);
1.1 cvs 2653: return (cssRule);
2654: }
2655:
2656: /*----------------------------------------------------------------------
1.268 vatton 2657: ParseCSSFontFamily: parse a CSS font family string
2658: we expect the input string describing the attribute to be
2659: a common generic font style name
2660: ----------------------------------------------------------------------*/
2661: static char *ParseCSSFontFamily (Element element, PSchema tsch,
2662: PresentationContext context, char *cssRule,
2663: CSSInfoPtr css, ThotBool isHTML)
2664: {
2665: cssRule = ParseACSSFontFamily (element, tsch, context, cssRule, css, isHTML);
2666: /* skip extra values */
2667: while (cssRule && *cssRule != ';' && *cssRule != EOS)
2668: cssRule++;
2669: return (cssRule);
2670: }
2671:
2672: /*----------------------------------------------------------------------
1.273 quint 2673: ParseACSSFontWeight: parse a CSS font weight string
1.1 cvs 2674: we expect the input string describing the attribute to be
1.20 cvs 2675: normal, bold, bolder, lighter, 100, 200, 300, ... 900, inherit.
1.1 cvs 2676: ----------------------------------------------------------------------*/
1.263 vatton 2677: static char *ParseACSSFontWeight (Element element, PSchema tsch,
1.79 cvs 2678: PresentationContext context, char *cssRule,
2679: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2680: {
1.20 cvs 2681: PresentationValue weight;
1.1 cvs 2682:
2683: weight.typed_data.value = 0;
1.184 vatton 2684: weight.typed_data.unit = UNIT_REL;
1.1 cvs 2685: weight.typed_data.real = FALSE;
1.82 cvs 2686: cssRule = SkipBlanksAndComments (cssRule);
1.270 vatton 2687: if (!strncasecmp (cssRule, "100", 3) && cssRule[3] != '%' &&
2688: !isalpha (cssRule[3]))
1.1 cvs 2689: {
2690: weight.typed_data.value = -3;
2691: cssRule = SkipWord (cssRule);
2692: }
1.82 cvs 2693: else if (!strncasecmp (cssRule, "200", 3) && !isalpha (cssRule[3]))
1.1 cvs 2694: {
2695: weight.typed_data.value = -2;
2696: cssRule = SkipWord (cssRule);
2697: }
1.82 cvs 2698: else if (!strncasecmp (cssRule, "300", 3) && ! isalpha(cssRule[3]))
1.1 cvs 2699: {
2700: weight.typed_data.value = -1;
2701: cssRule = SkipWord (cssRule);
2702: }
1.270 vatton 2703: else if (!strncasecmp (cssRule, "normal", 6) ||
2704: (!strncasecmp (cssRule, "400", 3) && !isalpha (cssRule[3])))
1.1 cvs 2705: {
2706: weight.typed_data.value = 0;
2707: cssRule = SkipWord (cssRule);
2708: }
1.82 cvs 2709: else if (!strncasecmp (cssRule, "500", 3) && !isalpha (cssRule[3]))
1.1 cvs 2710: {
2711: weight.typed_data.value = +1;
2712: cssRule = SkipWord (cssRule);
2713: }
1.82 cvs 2714: else if (!strncasecmp (cssRule, "600", 3) && !isalpha (cssRule[3]))
1.1 cvs 2715: {
2716: weight.typed_data.value = +2;
2717: cssRule = SkipWord (cssRule);
2718: }
1.270 vatton 2719: else if (!strncasecmp (cssRule, "bold", 4) ||
2720: (!strncasecmp (cssRule, "700", 3) && !isalpha (cssRule[3])))
1.1 cvs 2721: {
2722: weight.typed_data.value = +3;
2723: cssRule = SkipWord (cssRule);
2724: }
1.82 cvs 2725: else if (!strncasecmp (cssRule, "800", 3) && !isalpha (cssRule[3]))
1.1 cvs 2726: {
2727: weight.typed_data.value = +4;
2728: cssRule = SkipWord (cssRule);
2729: }
1.82 cvs 2730: else if (!strncasecmp (cssRule, "900", 3) && !isalpha (cssRule[3]))
1.1 cvs 2731: {
2732: weight.typed_data.value = +5;
2733: cssRule = SkipWord (cssRule);
2734: }
1.293 quint 2735: else if (!strncasecmp (cssRule, "inherit", 7))
2736: {
2737: weight.typed_data.unit = VALUE_INHERIT;
2738: cssRule += 7;
2739: }
2740: else if (!strncasecmp (cssRule, "bolder", 6) ||
1.287 quint 2741: !strncasecmp (cssRule, "lighter", 7))
1.1 cvs 2742: {
2743: /* not implemented */
2744: cssRule = SkipWord (cssRule);
2745: return (cssRule);
2746: }
2747: else
2748: return (cssRule);
2749:
2750: /*
1.20 cvs 2751: * Here we have to reduce since only two font weight values are supported
1.1 cvs 2752: * by the Thot presentation API.
2753: */
1.293 quint 2754: if (weight.typed_data.unit != VALUE_INHERIT)
2755: {
2756: if (weight.typed_data.value > 0)
2757: weight.typed_data.value = WeightBold;
2758: else
2759: weight.typed_data.value = WeightNormal;
2760: }
1.1 cvs 2761:
2762: /* install the new presentation */
1.295 vatton 2763: cssRule = CheckImportantRule (cssRule, context);
2764: if (DoApply)
2765: TtaSetStylePresentation (PRWeight, element, tsch, context, weight);
1.1 cvs 2766: return (cssRule);
2767: }
2768:
2769: /*----------------------------------------------------------------------
1.263 vatton 2770: ParseCSSFontWeight: parse a CSS font weight string
2771: we expect the input string describing the attribute to be
2772: normal, bold, bolder, lighter, 100, 200, 300, ... 900, inherit.
2773: ----------------------------------------------------------------------*/
2774: static char *ParseCSSFontWeight (Element element, PSchema tsch,
2775: PresentationContext context, char *cssRule,
2776: CSSInfoPtr css, ThotBool isHTML)
2777: {
2778: char *ptr;
2779:
2780: ptr = cssRule;
2781: cssRule = ParseACSSFontWeight (element, tsch, context, cssRule, css, isHTML);
2782: if (ptr == cssRule)
2783: cssRule = SkipValue ("Invalid font-weight value", cssRule);
1.295 vatton 2784: cssRule = CheckImportantRule (cssRule, context);
1.263 vatton 2785: return (cssRule);
2786: }
2787:
2788: /*----------------------------------------------------------------------
1.293 quint 2789: ParseACSSFontVariant: parse a CSS font variant string
1.1 cvs 2790: we expect the input string describing the attribute to be
2791: normal or small-caps
2792: ----------------------------------------------------------------------*/
1.263 vatton 2793: static char *ParseACSSFontVariant (Element element, PSchema tsch,
1.79 cvs 2794: PresentationContext context, char *cssRule,
2795: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2796: {
2797: PresentationValue style;
2798:
2799: style.typed_data.value = 0;
1.184 vatton 2800: style.typed_data.unit = UNIT_REL;
1.1 cvs 2801: style.typed_data.real = FALSE;
1.82 cvs 2802: cssRule = SkipBlanksAndComments (cssRule);
2803: if (!strncasecmp (cssRule, "small-caps", 10))
1.1 cvs 2804: {
2805: /* Not supported yet */
2806: cssRule = SkipWord (cssRule);
2807: }
1.82 cvs 2808: else if (!strncasecmp (cssRule, "normal", 6))
1.1 cvs 2809: {
2810: /* Not supported yet */
2811: cssRule = SkipWord (cssRule);
2812: }
1.82 cvs 2813: else if (!strncasecmp (cssRule, "inherit", 7))
1.1 cvs 2814: {
2815: /* Not supported yet */
2816: cssRule = SkipWord (cssRule);
2817: }
1.295 vatton 2818: return (cssRule);
1.263 vatton 2819: }
1.1 cvs 2820:
1.263 vatton 2821: /*----------------------------------------------------------------------
2822: ParseCSSFontVariant: parse a CSS font variant string
2823: we expect the input string describing the attribute to be
2824: normal or small-caps
2825: ----------------------------------------------------------------------*/
2826: static char *ParseCSSFontVariant (Element element, PSchema tsch,
2827: PresentationContext context, char *cssRule,
2828: CSSInfoPtr css, ThotBool isHTML)
2829: {
2830: char *ptr;
2831:
2832: ptr = cssRule;
2833: cssRule = ParseACSSFontVariant (element, tsch, context, cssRule, css, isHTML);
2834: if (ptr == cssRule)
2835: cssRule = SkipValue ("Invalid font-variant value", cssRule);
1.295 vatton 2836: cssRule = CheckImportantRule (cssRule, context);
1.263 vatton 2837: return (cssRule);
1.1 cvs 2838: }
2839:
2840:
2841: /*----------------------------------------------------------------------
1.293 quint 2842: ParseACSSFontStyle: parse a CSS font style string
1.1 cvs 2843: we expect the input string describing the attribute to be
1.287 quint 2844: normal, italic, oblique or inherit
1.1 cvs 2845: ----------------------------------------------------------------------*/
1.263 vatton 2846: static char *ParseACSSFontStyle (Element element, PSchema tsch,
1.79 cvs 2847: PresentationContext context, char *cssRule,
2848: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2849: {
2850: PresentationValue style;
2851: PresentationValue size;
2852:
2853: style.typed_data.value = 0;
1.184 vatton 2854: style.typed_data.unit = UNIT_REL;
1.1 cvs 2855: style.typed_data.real = FALSE;
2856: size.typed_data.value = 0;
1.184 vatton 2857: size.typed_data.unit = UNIT_REL;
1.1 cvs 2858: size.typed_data.real = FALSE;
1.82 cvs 2859: cssRule = SkipBlanksAndComments (cssRule);
2860: if (!strncasecmp (cssRule, "italic", 6))
1.1 cvs 2861: {
1.184 vatton 2862: style.typed_data.value = StyleItalics;
1.1 cvs 2863: cssRule = SkipWord (cssRule);
2864: }
1.82 cvs 2865: else if (!strncasecmp (cssRule, "oblique", 7))
1.1 cvs 2866: {
1.184 vatton 2867: style.typed_data.value = StyleOblique;
1.1 cvs 2868: cssRule = SkipWord (cssRule);
2869: }
1.82 cvs 2870: else if (!strncasecmp (cssRule, "normal", 6))
1.1 cvs 2871: {
1.184 vatton 2872: style.typed_data.value = StyleRoman;
1.1 cvs 2873: cssRule = SkipWord (cssRule);
2874: }
1.108 cvs 2875: else if (!strncasecmp (cssRule, "inherit", 7))
2876: {
1.293 quint 2877: style.typed_data.unit = VALUE_INHERIT;
1.108 cvs 2878: cssRule = SkipWord (cssRule);
2879: }
1.1 cvs 2880: else
1.263 vatton 2881: /* invalid font style */
2882: return (cssRule);
1.1 cvs 2883:
2884: /*
2885: * install the new presentation.
2886: */
1.295 vatton 2887: cssRule = CheckImportantRule (cssRule, context);
1.293 quint 2888: if (DoApply &&
2889: (style.typed_data.value != 0 || style.typed_data.unit == VALUE_INHERIT))
1.117 vatton 2890: {
1.276 vatton 2891: TtaSetStylePresentation (PRStyle, element, tsch, context, style);
1.117 vatton 2892: }
1.116 vatton 2893: if (size.typed_data.value != 0 && DoApply)
1.1 cvs 2894: {
2895: PresentationValue previous_size;
2896:
2897: if (!TtaGetStylePresentation (PRSize, element, tsch, context, &previous_size))
2898: {
1.293 quint 2899: /* !!!!!!!!!!!!!!!!!!!!!!!! Unit + relative !!!!!!!!!!!!!!!! */
1.1 cvs 2900: size.typed_data.value += previous_size.typed_data.value;
2901: TtaSetStylePresentation (PRSize, element, tsch, context, size);
2902: }
2903: else
2904: {
2905: size.typed_data.value = 10;
2906: TtaSetStylePresentation (PRSize, element, tsch, context, size);
2907: }
2908: }
2909: return (cssRule);
2910: }
2911:
2912: /*----------------------------------------------------------------------
1.263 vatton 2913: ParseCSSFontStyle: parse a CSS font style string
2914: we expect the input string describing the attribute to be
2915: italic, oblique or normal
2916: ----------------------------------------------------------------------*/
2917: static char *ParseCSSFontStyle (Element element, PSchema tsch,
2918: PresentationContext context, char *cssRule,
2919: CSSInfoPtr css, ThotBool isHTML)
2920: {
2921: char *ptr;
2922:
2923: ptr = cssRule;
2924: cssRule = ParseACSSFontStyle (element, tsch, context, cssRule, css, isHTML);
2925: if (ptr == cssRule)
2926: cssRule = SkipValue ("Invalid font-style value", cssRule);
1.295 vatton 2927: cssRule = CheckImportantRule (cssRule, context);
1.263 vatton 2928: return (cssRule);
2929: }
2930:
2931: /*----------------------------------------------------------------------
1.59 cvs 2932: ParseCSSFont: parse a CSS font attribute string
2933: we expect the input string describing the attribute to be
2934: !!!!!!
1.1 cvs 2935: ----------------------------------------------------------------------*/
1.79 cvs 2936: static char *ParseCSSFont (Element element, PSchema tsch,
2937: PresentationContext context, char *cssRule,
2938: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2939: {
1.270 vatton 2940: char *ptr, *p;
1.93 vatton 2941: int skippedNL;
1.272 vatton 2942: ThotBool variant = FALSE, style = FALSE, weight = FALSE, found;
1.1 cvs 2943:
1.82 cvs 2944: cssRule = SkipBlanksAndComments (cssRule);
2945: if (!strncasecmp (cssRule, "caption", 7))
1.263 vatton 2946: cssRule += 7;
1.82 cvs 2947: else if (!strncasecmp (cssRule, "icon", 4))
1.263 vatton 2948: cssRule += 4;
1.82 cvs 2949: else if (!strncasecmp (cssRule, "menu", 4))
1.263 vatton 2950: cssRule += 4;
1.82 cvs 2951: else if (!strncasecmp (cssRule, "message-box", 11))
1.263 vatton 2952: cssRule += 11;
1.82 cvs 2953: else if (!strncasecmp (cssRule, "small-caption", 13))
1.263 vatton 2954: cssRule += 13;
1.82 cvs 2955: else if (!strncasecmp (cssRule, "status-bar", 10))
1.263 vatton 2956: cssRule += 10;
2957: else if (!strncasecmp (cssRule, "inherit", 7))
1.293 quint 2958: {
2959: ParseACSSFontStyle (element, tsch, context, cssRule, css, isHTML);
2960: ParseACSSFontVariant (element, tsch, context, cssRule, css, isHTML);
2961: ParseACSSFontWeight (element, tsch, context, cssRule, css, isHTML);
2962: ParseACSSFontSize (element, tsch, context, cssRule, css, isHTML, FALSE);
2963: ParseACSSFontFamily (element, tsch, context, cssRule, css, isHTML);
2964: cssRule += 7;
2965: }
1.1 cvs 2966: else
1.43 cvs 2967: {
1.270 vatton 2968: ptr = NULL;
2969: p = cssRule;
2970: while (*cssRule != ';' && *cssRule != EOS && p == cssRule)
2971: {
1.272 vatton 2972: found = FALSE;
1.270 vatton 2973: /* style, variant, weight can appear in any order */
2974: ptr = cssRule;
2975: skippedNL = NewLineSkipped;
2976: cssRule = ParseACSSFontStyle (element, tsch, context, cssRule, css, isHTML);
2977: if (ptr != cssRule)
2978: {
2979: skippedNL = NewLineSkipped;
1.272 vatton 2980: found = TRUE;
1.270 vatton 2981: style = TRUE;
2982: }
2983: else
2984: NewLineSkipped = skippedNL;
2985: ptr = cssRule;
2986: cssRule = ParseACSSFontVariant (element, tsch, context, cssRule, css, isHTML);
2987: if (ptr != cssRule)
2988: {
2989: skippedNL = NewLineSkipped;
1.272 vatton 2990: found = TRUE;
1.270 vatton 2991: variant = TRUE;
2992: }
2993: else
2994: NewLineSkipped = skippedNL;
2995: ptr = cssRule;
2996: cssRule = ParseACSSFontWeight (element, tsch, context, cssRule, css, isHTML);
2997: if (ptr != cssRule)
2998: {
2999: skippedNL = NewLineSkipped;
1.272 vatton 3000: found = TRUE;
1.270 vatton 3001: weight = TRUE;
3002: }
3003: else
3004: NewLineSkipped = skippedNL;
3005: cssRule = SkipBlanksAndComments (cssRule);
3006: p = ParseACSSFontSize (element, tsch, context, cssRule, css, isHTML, TRUE);
3007: NewLineSkipped = skippedNL;
1.272 vatton 3008: if (!found)
3009: /* break the loop when the current value was not parsed */
3010: p = cssRule + 1;
1.270 vatton 3011: }
1.263 vatton 3012: ptr = cssRule;
1.270 vatton 3013: /* set default variant, style, weight */
3014: if (!variant)
3015: ParseACSSFontVariant (element, tsch, context, "normal", css, isHTML);
3016: if (!style)
3017: ParseACSSFontStyle (element, tsch, context, "normal", css, isHTML);
3018: if (!weight)
3019: ParseACSSFontWeight (element, tsch, context, "normal", css, isHTML);
3020: /* now parse the font size and the font family */
1.263 vatton 3021: if (*cssRule != ';' && *cssRule != EOS)
1.270 vatton 3022: cssRule = ParseACSSFontSize (element, tsch, context, cssRule, css, isHTML, FALSE);
1.263 vatton 3023: if (*cssRule != ';' && *cssRule != EOS)
1.270 vatton 3024: cssRule = ParseACSSFontFamily (element, tsch, context, cssRule, css, isHTML);
1.263 vatton 3025: if (ptr == cssRule)
1.295 vatton 3026: {
3027: cssRule = SkipValue ("Invalid font value", cssRule);
3028: cssRule = CheckImportantRule (cssRule, context);
3029: }
1.43 cvs 3030: }
1.263 vatton 3031: cssRule = SkipBlanksAndComments (cssRule);
3032: if (*cssRule != ';' && *cssRule != EOS)
1.295 vatton 3033: {
3034: cssRule = SkipValue ("Invalid font value", cssRule);
3035: cssRule = CheckImportantRule (cssRule, context);
3036: }
1.43 cvs 3037: return (cssRule);
1.1 cvs 3038: }
3039:
3040: /*----------------------------------------------------------------------
1.59 cvs 3041: ParseCSSTextDecoration: parse a CSS text decor string
3042: we expect the input string describing the attribute to be
1.109 cvs 3043: underline, overline, line-through, blink or none.
1.1 cvs 3044: ----------------------------------------------------------------------*/
1.79 cvs 3045: static char *ParseCSSTextDecoration (Element element, PSchema tsch,
3046: PresentationContext context, char *cssRule,
3047: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 3048: {
3049: PresentationValue decor;
1.288 vatton 3050: char *ptr = cssRule;
1.1 cvs 3051:
3052: decor.typed_data.value = 0;
1.184 vatton 3053: decor.typed_data.unit = UNIT_REL;
1.1 cvs 3054: decor.typed_data.real = FALSE;
1.82 cvs 3055: cssRule = SkipBlanksAndComments (cssRule);
1.211 vatton 3056: if (!strncasecmp (cssRule, "none", 4))
1.142 quint 3057: {
3058: decor.typed_data.value = NoUnderline;
1.288 vatton 3059: cssRule += 4;
1.142 quint 3060: }
1.211 vatton 3061: else if (!strncasecmp (cssRule, "underline", 9))
1.1 cvs 3062: {
3063: decor.typed_data.value = Underline;
1.288 vatton 3064: cssRule += 9;
1.1 cvs 3065: }
1.211 vatton 3066: else if (!strncasecmp (cssRule, "overline", 8))
1.1 cvs 3067: {
3068: decor.typed_data.value = Overline;
1.288 vatton 3069: cssRule += 8;
1.1 cvs 3070: }
1.211 vatton 3071: else if (!strncasecmp (cssRule, "line-through", 12))
1.1 cvs 3072: {
3073: decor.typed_data.value = CrossOut;
1.288 vatton 3074: cssRule += 12;
1.1 cvs 3075: }
1.211 vatton 3076: else if (!strncasecmp (cssRule, "blink", 5))
1.1 cvs 3077: {
1.293 quint 3078: /* the blink text-decoration attribute is not supported */
3079: cssRule += 5;
1.1 cvs 3080: }
1.142 quint 3081: else if (!strncasecmp (cssRule, "inherit", 7))
1.1 cvs 3082: {
1.293 quint 3083: decor.typed_data.unit = VALUE_INHERIT;
1.288 vatton 3084: cssRule += 7;
1.1 cvs 3085: }
3086: else
3087: {
1.211 vatton 3088: cssRule = SkipValue ("Invalid text-decoration value", cssRule);
1.295 vatton 3089: cssRule = CheckImportantRule (cssRule, context);
1.211 vatton 3090: return (cssRule);
1.1 cvs 3091: }
3092:
3093: /*
3094: * install the new presentation.
3095: */
1.295 vatton 3096: cssRule = CheckImportantRule (cssRule, context);
1.293 quint 3097: if (DoApply &&
3098: (decor.typed_data.value || decor.typed_data.unit == VALUE_INHERIT))
1.1 cvs 3099: TtaSetStylePresentation (PRUnderline, element, tsch, context, decor);
1.288 vatton 3100: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid text-decoration value");
1.1 cvs 3101: return (cssRule);
3102: }
3103:
3104: /*----------------------------------------------------------------------
1.59 cvs 3105: ParseCSSHeight: parse a CSS height attribute
1.1 cvs 3106: ----------------------------------------------------------------------*/
1.79 cvs 3107: static char *ParseCSSHeight (Element element, PSchema tsch,
1.93 vatton 3108: PresentationContext context, char *cssRule,
3109: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 3110: {
1.117 vatton 3111: PresentationValue val;
1.168 vatton 3112: char *ptr;
1.93 vatton 3113:
1.117 vatton 3114: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 3115: ptr = cssRule;
1.117 vatton 3116: /* first parse the attribute string */
1.164 quint 3117: if (!strncasecmp (cssRule, "auto", 4))
3118: {
1.184 vatton 3119: val.typed_data.unit = VALUE_AUTO;
1.164 quint 3120: val.typed_data.value = 0;
3121: val.typed_data.real = FALSE;
1.288 vatton 3122: cssRule += 4;
1.295 vatton 3123: cssRule = CheckImportantRule (cssRule, context);
3124: cssRule = CheckImportantRule (cssRule, context);
1.288 vatton 3125: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid height value");
1.164 quint 3126: }
1.117 vatton 3127: else
1.168 vatton 3128: cssRule = ParseCSSUnit (cssRule, &val);
1.295 vatton 3129:
1.168 vatton 3130: if (val.typed_data.value != 0 &&
1.184 vatton 3131: (val.typed_data.unit == UNIT_INVALID ||
3132: val.typed_data.unit == UNIT_BOX))
1.211 vatton 3133: {
3134: CSSParseError ("height value", ptr, cssRule);
1.212 cvs 3135: val.typed_data.unit = UNIT_PX;
1.211 vatton 3136: }
1.295 vatton 3137: cssRule = CheckImportantRule (cssRule, context);
1.211 vatton 3138: if (DoApply)
1.295 vatton 3139: /* install the new presentation */
3140: TtaSetStylePresentation (PRHeight, element, tsch, context, val);
1.117 vatton 3141: return (cssRule);
1.1 cvs 3142: }
3143:
3144: /*----------------------------------------------------------------------
1.59 cvs 3145: ParseCSSWidth: parse a CSS width attribute
1.1 cvs 3146: ----------------------------------------------------------------------*/
1.79 cvs 3147: static char *ParseCSSWidth (Element element, PSchema tsch,
1.78 cvs 3148: PresentationContext context,
1.79 cvs 3149: char *cssRule, CSSInfoPtr css,
1.78 cvs 3150: ThotBool isHTML)
1.1 cvs 3151: {
1.117 vatton 3152: PresentationValue val;
1.168 vatton 3153: char *ptr;
1.93 vatton 3154:
1.117 vatton 3155: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 3156: ptr = cssRule;
1.117 vatton 3157: /* first parse the attribute string */
1.164 quint 3158: if (!strncasecmp (cssRule, "auto", 4))
3159: {
1.184 vatton 3160: val.typed_data.unit = VALUE_AUTO;
1.164 quint 3161: val.typed_data.value = 0;
3162: val.typed_data.real = FALSE;
1.288 vatton 3163: cssRule += 4;
1.295 vatton 3164: cssRule = CheckImportantRule (cssRule, context);
1.288 vatton 3165: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid width value");
1.164 quint 3166: }
1.117 vatton 3167: else
1.164 quint 3168: cssRule = ParseCSSUnit (cssRule, &val);
1.168 vatton 3169: if (val.typed_data.value != 0 &&
1.184 vatton 3170: (val.typed_data.unit == UNIT_INVALID ||
3171: val.typed_data.unit == UNIT_BOX))
1.211 vatton 3172: {
3173: CSSParseError ("Invalid width value", ptr, cssRule);
1.295 vatton 3174: cssRule = CheckImportantRule (cssRule, context);
1.212 cvs 3175: val.typed_data.unit = UNIT_PX;
1.211 vatton 3176: }
1.295 vatton 3177:
3178: cssRule = CheckImportantRule (cssRule, context);
1.211 vatton 3179: if (DoApply)
1.295 vatton 3180: /* install the new presentation */
3181: TtaSetStylePresentation (PRWidth, element, tsch, context, val);
1.117 vatton 3182: return (cssRule);
1.1 cvs 3183: }
3184:
3185: /*----------------------------------------------------------------------
1.296 vatton 3186: ParseACSSMarginTop: parse a CSS margin-top attribute
1.1 cvs 3187: ----------------------------------------------------------------------*/
1.296 vatton 3188: static char *ParseACSSMarginTop (Element element, PSchema tsch,
1.78 cvs 3189: PresentationContext context,
1.79 cvs 3190: char *cssRule, CSSInfoPtr css,
1.78 cvs 3191: ThotBool isHTML)
1.1 cvs 3192: {
3193: PresentationValue margin;
1.168 vatton 3194: char *ptr;
1.1 cvs 3195:
1.82 cvs 3196: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 3197: ptr = cssRule;
1.1 cvs 3198: /* first parse the attribute string */
1.164 quint 3199: if (!strncasecmp (cssRule, "auto", 4))
3200: {
1.184 vatton 3201: margin.typed_data.unit = VALUE_AUTO;
1.164 quint 3202: margin.typed_data.value = 0;
3203: margin.typed_data.real = FALSE;
1.288 vatton 3204: cssRule += 4;
1.295 vatton 3205: cssRule = CheckImportantRule (cssRule, context);
1.164 quint 3206: }
3207: else
1.168 vatton 3208: cssRule = ParseCSSUnit (cssRule, &margin);
1.295 vatton 3209:
3210: cssRule = CheckImportantRule (cssRule, context);
1.168 vatton 3211: if (margin.typed_data.value != 0 &&
1.184 vatton 3212: (margin.typed_data.unit == UNIT_INVALID ||
3213: margin.typed_data.unit == UNIT_BOX))
1.169 vatton 3214: CSSParseError ("Invalid margin-top value", ptr, cssRule);
1.168 vatton 3215: else if (DoApply)
1.295 vatton 3216: TtaSetStylePresentation (PRMarginTop, element, tsch, context, margin);
1.1 cvs 3217: return (cssRule);
3218: }
3219:
3220: /*----------------------------------------------------------------------
1.296 vatton 3221: ParseCSSMarginTop: parse a CSS margin-top attribute
3222: ----------------------------------------------------------------------*/
3223: static char *ParseCSSMarginTop (Element element, PSchema tsch,
3224: PresentationContext context,
3225: char *cssRule, CSSInfoPtr css,
3226: ThotBool isHTML)
3227: {
3228: char *ptr = cssRule;
3229:
3230: cssRule = ParseACSSMarginTop (element, tsch, context, ptr, css, isHTML);
3231: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid margin-top value");
3232: return (cssRule);
3233: }
3234:
3235: /*----------------------------------------------------------------------
3236: ParseACSSMarginBottom: parse a CSS margin-bottom attribute
1.1 cvs 3237: ----------------------------------------------------------------------*/
1.296 vatton 3238: static char *ParseACSSMarginBottom (Element element, PSchema tsch,
1.78 cvs 3239: PresentationContext context,
1.79 cvs 3240: char *cssRule, CSSInfoPtr css,
1.78 cvs 3241: ThotBool isHTML)
1.1 cvs 3242: {
3243: PresentationValue margin;
1.168 vatton 3244: char *ptr;
1.1 cvs 3245:
1.82 cvs 3246: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 3247: ptr = cssRule;
1.1 cvs 3248: /* first parse the attribute string */
1.164 quint 3249: if (!strncasecmp (cssRule, "auto", 4))
3250: {
1.184 vatton 3251: margin.typed_data.unit = VALUE_AUTO;
1.164 quint 3252: margin.typed_data.value = 0;
3253: margin.typed_data.real = FALSE;
1.288 vatton 3254: cssRule += 4;
1.295 vatton 3255: cssRule = CheckImportantRule (cssRule, context);
1.164 quint 3256: }
3257: else
1.168 vatton 3258: cssRule = ParseCSSUnit (cssRule, &margin);
1.295 vatton 3259:
3260: cssRule = CheckImportantRule (cssRule, context);
1.168 vatton 3261: if (margin.typed_data.value != 0 &&
1.184 vatton 3262: (margin.typed_data.unit == UNIT_INVALID ||
3263: margin.typed_data.unit == UNIT_BOX))
1.169 vatton 3264: CSSParseError ("Invalid margin-bottom value", ptr, cssRule);
1.168 vatton 3265: else if (DoApply)
1.295 vatton 3266: TtaSetStylePresentation (PRMarginBottom, element, tsch, context, margin);
1.1 cvs 3267: return (cssRule);
3268: }
3269:
3270: /*----------------------------------------------------------------------
1.296 vatton 3271: ParseCSSMarginBottom: parse a CSS margin-bottom attribute
3272: ----------------------------------------------------------------------*/
3273: static char *ParseCSSMarginBottom (Element element, PSchema tsch,
3274: PresentationContext context,
3275: char *cssRule, CSSInfoPtr css,
3276: ThotBool isHTML)
3277: {
3278: char *ptr = cssRule;
3279:
3280: cssRule = ParseACSSMarginBottom (element, tsch, context, ptr, css, isHTML);
3281: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid margin-bottom value");
3282: return (cssRule);
3283: }
3284:
3285: /*----------------------------------------------------------------------
3286: ParseACSSMarginLeft: parse a CSS margin-left attribute string
1.1 cvs 3287: ----------------------------------------------------------------------*/
1.296 vatton 3288: static char *ParseACSSMarginLeft (Element element, PSchema tsch,
1.78 cvs 3289: PresentationContext context,
1.79 cvs 3290: char *cssRule, CSSInfoPtr css,
1.78 cvs 3291: ThotBool isHTML)
1.1 cvs 3292: {
3293: PresentationValue margin;
1.168 vatton 3294: char *ptr;
1.1 cvs 3295:
1.82 cvs 3296: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 3297: ptr = cssRule;
1.1 cvs 3298: /* first parse the attribute string */
1.164 quint 3299: if (!strncasecmp (cssRule, "auto", 4))
3300: {
1.184 vatton 3301: margin.typed_data.unit = VALUE_AUTO;
1.164 quint 3302: margin.typed_data.value = 0;
3303: margin.typed_data.real = FALSE;
1.288 vatton 3304: cssRule += 4;
1.295 vatton 3305: cssRule = CheckImportantRule (cssRule, context);
1.164 quint 3306: }
3307: else
1.168 vatton 3308: cssRule = ParseCSSUnit (cssRule, &margin);
1.295 vatton 3309:
3310: cssRule = CheckImportantRule (cssRule, context);
1.168 vatton 3311: if (margin.typed_data.value != 0 &&
1.184 vatton 3312: (margin.typed_data.unit == UNIT_INVALID ||
3313: margin.typed_data.unit == UNIT_BOX))
1.169 vatton 3314: CSSParseError ("Invalid margin-left value", ptr, cssRule);
1.295 vatton 3315: else if (DoApply && margin.typed_data.unit != UNIT_INVALID && DoApply)
1.117 vatton 3316: TtaSetStylePresentation (PRMarginLeft, element, tsch, context, margin);
1.1 cvs 3317: return (cssRule);
3318: }
3319:
3320: /*----------------------------------------------------------------------
1.296 vatton 3321: ParseCSSMarginBottom: parse a CSS margin-bottom attribute
3322: ----------------------------------------------------------------------*/
3323: static char *ParseCSSMarginLeft (Element element, PSchema tsch,
3324: PresentationContext context,
3325: char *cssRule, CSSInfoPtr css,
3326: ThotBool isHTML)
3327: {
3328: char *ptr = cssRule;
3329:
3330: cssRule = ParseACSSMarginLeft (element, tsch, context, ptr, css, isHTML);
3331: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid margin-left value");
3332: return (cssRule);
3333: }
3334:
3335:
3336: /*----------------------------------------------------------------------
3337: ParseACSSMarginRight: parse a CSS margin-right attribute string
1.1 cvs 3338: ----------------------------------------------------------------------*/
1.296 vatton 3339: static char *ParseACSSMarginRight (Element element, PSchema tsch,
1.78 cvs 3340: PresentationContext context,
1.79 cvs 3341: char *cssRule, CSSInfoPtr css,
1.78 cvs 3342: ThotBool isHTML)
1.1 cvs 3343: {
3344: PresentationValue margin;
1.168 vatton 3345: char *ptr;
1.1 cvs 3346:
1.82 cvs 3347: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 3348: ptr = cssRule;
1.1 cvs 3349: /* first parse the attribute string */
1.164 quint 3350: if (!strncasecmp (cssRule, "auto", 4))
3351: {
1.184 vatton 3352: margin.typed_data.unit = VALUE_AUTO;
1.164 quint 3353: margin.typed_data.value = 0;
3354: margin.typed_data.real = FALSE;
1.288 vatton 3355: cssRule += 4;
1.295 vatton 3356: cssRule = CheckImportantRule (cssRule, context);
1.164 quint 3357: }
3358: else
1.168 vatton 3359: cssRule = ParseCSSUnit (cssRule, &margin);
1.295 vatton 3360:
3361: cssRule = CheckImportantRule (cssRule, context);
1.168 vatton 3362: if (margin.typed_data.value != 0 &&
1.184 vatton 3363: (margin.typed_data.unit == UNIT_INVALID ||
3364: margin.typed_data.unit == UNIT_BOX))
1.169 vatton 3365: CSSParseError ("Invalid margin-right value", ptr, cssRule);
1.168 vatton 3366: else if (DoApply)
1.295 vatton 3367: TtaSetStylePresentation (PRMarginRight, element, tsch, context, margin);
1.1 cvs 3368: return (cssRule);
3369: }
3370:
3371: /*----------------------------------------------------------------------
1.296 vatton 3372: ParseCSSMarginRight: parse a CSS margin-right attribute string
3373: ----------------------------------------------------------------------*/
3374: static char *ParseCSSMarginRight (Element element, PSchema tsch,
3375: PresentationContext context,
3376: char *cssRule, CSSInfoPtr css,
3377: ThotBool isHTML)
3378: {
3379: char *ptr = cssRule;
3380:
1.297 vatton 3381: cssRule = ParseACSSMarginRight (element, tsch, context, ptr, css, isHTML);
1.296 vatton 3382: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid margin-right value");
3383: return (cssRule);
3384: }
3385:
3386: /*----------------------------------------------------------------------
1.59 cvs 3387: ParseCSSMargin: parse a CSS margin attribute string
1.1 cvs 3388: ----------------------------------------------------------------------*/
1.79 cvs 3389: static char *ParseCSSMargin (Element element, PSchema tsch,
1.78 cvs 3390: PresentationContext context,
1.79 cvs 3391: char *cssRule, CSSInfoPtr css,
1.78 cvs 3392: ThotBool isHTML)
1.1 cvs 3393: {
1.79 cvs 3394: char *ptrT, *ptrR, *ptrB, *ptrL;
1.93 vatton 3395: int skippedNL;
1.1 cvs 3396:
1.82 cvs 3397: ptrT = SkipBlanksAndComments (cssRule);
1.1 cvs 3398: /* First parse Margin-Top */
1.296 vatton 3399: ptrR = ParseACSSMarginTop (element, tsch, context, ptrT, css, isHTML);
1.82 cvs 3400: ptrR = SkipBlanksAndComments (ptrR);
3401: if (*ptrR == ';' || *ptrR == EOS || *ptrR == ',')
1.1 cvs 3402: {
1.93 vatton 3403: skippedNL = NewLineSkipped;
1.1 cvs 3404: cssRule = ptrR;
3405: /* apply the Margin-Top to all */
1.296 vatton 3406: ptrR = ParseACSSMarginRight (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 3407: NewLineSkipped = skippedNL;
1.296 vatton 3408: ptrR = ParseACSSMarginBottom (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 3409: NewLineSkipped = skippedNL;
1.296 vatton 3410: ptrR = ParseACSSMarginLeft (element, tsch, context, ptrT, css, isHTML);
1.1 cvs 3411: }
3412: else
3413: {
3414: /* parse Margin-Right */
1.296 vatton 3415: ptrB = ParseACSSMarginRight (element, tsch, context, ptrR, css, isHTML);
1.82 cvs 3416: ptrB = SkipBlanksAndComments (ptrB);
3417: if (*ptrB == ';' || *ptrB == EOS || *ptrB == ',')
1.1 cvs 3418: {
1.93 vatton 3419: skippedNL = NewLineSkipped;
1.1 cvs 3420: cssRule = ptrB;
3421: /* apply the Margin-Top to Margin-Bottom */
1.296 vatton 3422: ptrB = ParseACSSMarginBottom (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 3423: NewLineSkipped = skippedNL;
1.1 cvs 3424: /* apply the Margin-Right to Margin-Left */
1.296 vatton 3425: ptrB = ParseACSSMarginLeft (element, tsch, context, ptrR, css, isHTML);
1.1 cvs 3426: }
3427: else
3428: {
3429: /* parse Margin-Bottom */
1.296 vatton 3430: ptrL = ParseACSSMarginBottom (element, tsch, context, ptrB, css, isHTML);
1.82 cvs 3431: ptrL = SkipBlanksAndComments (ptrL);
3432: if (*ptrL == ';' || *ptrL == EOS || *ptrL == ',')
1.1 cvs 3433: {
3434: cssRule = ptrL;
3435: /* apply the Margin-Right to Margin-Left */
1.296 vatton 3436: ptrL = ParseACSSMarginLeft (element, tsch, context, ptrR, css, isHTML);
1.1 cvs 3437: }
3438: else
3439: /* parse Margin-Left */
1.296 vatton 3440: cssRule = ParseACSSMarginLeft (element, tsch, context, ptrL, css, isHTML);
1.82 cvs 3441: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 3442: }
3443: }
3444: return (cssRule);
3445: }
3446:
3447: /*----------------------------------------------------------------------
1.59 cvs 3448: ParseCSSPaddingTop: parse a CSS PaddingTop attribute string
1.1 cvs 3449: ----------------------------------------------------------------------*/
1.79 cvs 3450: static char *ParseCSSPaddingTop (Element element, PSchema tsch,
1.78 cvs 3451: PresentationContext context,
1.79 cvs 3452: char *cssRule, CSSInfoPtr css,
1.78 cvs 3453: ThotBool isHTML)
1.1 cvs 3454: {
1.43 cvs 3455: PresentationValue padding;
1.168 vatton 3456: char *ptr;
1.43 cvs 3457:
1.82 cvs 3458: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 3459: ptr = cssRule;
1.43 cvs 3460: /* first parse the attribute string */
3461: cssRule = ParseCSSUnit (cssRule, &padding);
1.295 vatton 3462:
3463: cssRule = CheckImportantRule (cssRule, context);
1.168 vatton 3464: if (padding.typed_data.value != 0 &&
1.184 vatton 3465: (padding.typed_data.unit == UNIT_INVALID ||
3466: padding.typed_data.unit == UNIT_BOX))
1.168 vatton 3467: {
1.169 vatton 3468: CSSParseError ("Invalid padding-top value", ptr, cssRule);
1.168 vatton 3469: padding.typed_data.value = 0;
3470: }
3471: else if (DoApply)
1.295 vatton 3472: TtaSetStylePresentation (PRPaddingTop, element, tsch, context, padding);
1.1 cvs 3473: return (cssRule);
3474: }
3475:
3476: /*----------------------------------------------------------------------
1.59 cvs 3477: ParseCSSPaddingBottom: parse a CSS PaddingBottom attribute string
1.1 cvs 3478: ----------------------------------------------------------------------*/
1.79 cvs 3479: static char *ParseCSSPaddingBottom (Element element, PSchema tsch,
1.78 cvs 3480: PresentationContext context,
1.79 cvs 3481: char *cssRule, CSSInfoPtr css,
1.78 cvs 3482: ThotBool isHTML)
1.1 cvs 3483: {
1.43 cvs 3484: PresentationValue padding;
1.168 vatton 3485: char *ptr;
1.43 cvs 3486:
1.82 cvs 3487: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 3488: ptr = cssRule;
1.43 cvs 3489: /* first parse the attribute string */
3490: cssRule = ParseCSSUnit (cssRule, &padding);
1.168 vatton 3491: if (padding.typed_data.value == 0)
1.184 vatton 3492: padding.typed_data.unit = UNIT_EM;
1.295 vatton 3493:
3494: cssRule = CheckImportantRule (cssRule, context);
1.168 vatton 3495: if (padding.typed_data.value != 0 &&
1.184 vatton 3496: (padding.typed_data.unit == UNIT_INVALID ||
3497: padding.typed_data.unit == UNIT_BOX))
1.168 vatton 3498: {
1.169 vatton 3499: CSSParseError ("Invalid padding-bottom value", ptr, cssRule);
1.168 vatton 3500: padding.typed_data.value = 0;
3501: }
3502: else if (DoApply)
1.295 vatton 3503: TtaSetStylePresentation (PRPaddingBottom, element, tsch, context, padding);
1.1 cvs 3504: return (cssRule);
3505: }
3506:
3507: /*----------------------------------------------------------------------
1.59 cvs 3508: ParseCSSPaddingLeft: parse a CSS PaddingLeft attribute string.
1.1 cvs 3509: ----------------------------------------------------------------------*/
1.79 cvs 3510: static char *ParseCSSPaddingLeft (Element element, PSchema tsch,
1.78 cvs 3511: PresentationContext context,
1.79 cvs 3512: char *cssRule, CSSInfoPtr css,
1.78 cvs 3513: ThotBool isHTML)
1.1 cvs 3514: {
1.43 cvs 3515: PresentationValue padding;
1.168 vatton 3516: char *ptr;
1.43 cvs 3517:
1.82 cvs 3518: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 3519: ptr = cssRule;
1.43 cvs 3520: /* first parse the attribute string */
3521: cssRule = ParseCSSUnit (cssRule, &padding);
1.168 vatton 3522: if (padding.typed_data.value == 0)
1.184 vatton 3523: padding.typed_data.unit = UNIT_EM;
1.295 vatton 3524:
3525: cssRule = CheckImportantRule (cssRule, context);
1.168 vatton 3526: if (padding.typed_data.value != 0 &&
1.184 vatton 3527: (padding.typed_data.unit == UNIT_INVALID ||
3528: padding.typed_data.unit == UNIT_BOX))
1.168 vatton 3529: {
1.169 vatton 3530: CSSParseError ("Invalid padding-left value", ptr, cssRule);
1.168 vatton 3531: padding.typed_data.value = 0;
3532: }
3533: else if (DoApply)
1.295 vatton 3534: TtaSetStylePresentation (PRPaddingLeft, element, tsch, context, padding);
1.1 cvs 3535: return (cssRule);
3536: }
3537:
3538: /*----------------------------------------------------------------------
1.59 cvs 3539: ParseCSSPaddingRight: parse a CSS PaddingRight attribute string.
1.1 cvs 3540: ----------------------------------------------------------------------*/
1.79 cvs 3541: static char *ParseCSSPaddingRight (Element element, PSchema tsch,
1.78 cvs 3542: PresentationContext context,
1.79 cvs 3543: char *cssRule, CSSInfoPtr css,
1.78 cvs 3544: ThotBool isHTML)
1.1 cvs 3545: {
1.43 cvs 3546: PresentationValue padding;
1.168 vatton 3547: char *ptr;
1.43 cvs 3548:
1.82 cvs 3549: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 3550: ptr = cssRule;
1.43 cvs 3551: /* first parse the attribute string */
3552: cssRule = ParseCSSUnit (cssRule, &padding);
1.168 vatton 3553: if (padding.typed_data.value == 0)
1.184 vatton 3554: padding.typed_data.unit = UNIT_EM;
1.295 vatton 3555:
3556: cssRule = CheckImportantRule (cssRule, context);
1.168 vatton 3557: if (padding.typed_data.value != 0 &&
1.184 vatton 3558: (padding.typed_data.unit == UNIT_INVALID ||
3559: padding.typed_data.unit == UNIT_BOX))
1.168 vatton 3560: {
1.169 vatton 3561: CSSParseError ("Invalid padding-right value", ptr, cssRule);
1.168 vatton 3562: padding.typed_data.value = 0;
3563: }
3564: else if (DoApply)
1.295 vatton 3565: TtaSetStylePresentation (PRPaddingRight, element, tsch, context, padding);
1.1 cvs 3566: return (cssRule);
3567: }
3568:
3569: /*----------------------------------------------------------------------
1.59 cvs 3570: ParseCSSPadding: parse a CSS padding attribute string.
1.1 cvs 3571: ----------------------------------------------------------------------*/
1.79 cvs 3572: static char *ParseCSSPadding (Element element, PSchema tsch,
1.78 cvs 3573: PresentationContext context,
1.79 cvs 3574: char *cssRule, CSSInfoPtr css,
1.78 cvs 3575: ThotBool isHTML)
1.1 cvs 3576: {
1.79 cvs 3577: char *ptrT, *ptrR, *ptrB, *ptrL;
1.93 vatton 3578: int skippedNL;
1.43 cvs 3579:
1.82 cvs 3580: ptrT = SkipBlanksAndComments (cssRule);
1.43 cvs 3581: /* First parse Padding-Top */
3582: ptrR = ParseCSSPaddingTop (element, tsch, context, ptrT, css, isHTML);
1.82 cvs 3583: ptrR = SkipBlanksAndComments (ptrR);
3584: if (*ptrR == ';' || *ptrR == EOS || *ptrR == ',')
1.43 cvs 3585: {
1.93 vatton 3586: skippedNL = NewLineSkipped;
1.43 cvs 3587: cssRule = ptrR;
3588: /* apply the Padding-Top to all */
3589: ptrR = ParseCSSPaddingRight (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 3590: NewLineSkipped = skippedNL;
1.43 cvs 3591: ptrR = ParseCSSPaddingBottom (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 3592: NewLineSkipped = skippedNL;
1.43 cvs 3593: ptrR = ParseCSSPaddingLeft (element, tsch, context, ptrT, css, isHTML);
3594: }
3595: else
3596: {
3597: /* parse Padding-Right */
3598: ptrB = ParseCSSPaddingRight (element, tsch, context, ptrR, css, isHTML);
1.82 cvs 3599: ptrB = SkipBlanksAndComments (ptrB);
3600: if (*ptrB == ';' || *ptrB == EOS || *ptrB == ',')
1.43 cvs 3601: {
1.93 vatton 3602: skippedNL = NewLineSkipped;
1.43 cvs 3603: cssRule = ptrB;
3604: /* apply the Padding-Top to Padding-Bottom */
3605: ptrB = ParseCSSPaddingBottom (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 3606: NewLineSkipped = skippedNL;
1.43 cvs 3607: /* apply the Padding-Right to Padding-Left */
3608: ptrB = ParseCSSPaddingLeft (element, tsch, context, ptrR, css, isHTML);
3609: }
3610: else
3611: {
3612: /* parse Padding-Bottom */
3613: ptrL = ParseCSSPaddingBottom (element, tsch, context, ptrB, css, isHTML);
1.82 cvs 3614: ptrL = SkipBlanksAndComments (ptrL);
3615: if (*ptrL == ';' || *ptrL == EOS || *ptrL == ',')
1.43 cvs 3616: {
3617: cssRule = ptrL;
3618: /* apply the Padding-Right to Padding-Left */
3619: ptrL = ParseCSSPaddingLeft (element, tsch, context, ptrR, css, isHTML);
3620: }
3621: else
3622: /* parse Padding-Left */
3623: cssRule = ParseCSSPaddingLeft (element, tsch, context, ptrL, css, isHTML);
1.82 cvs 3624: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 3625: }
3626: }
1.1 cvs 3627: return (cssRule);
3628: }
3629:
3630: /*----------------------------------------------------------------------
1.59 cvs 3631: ParseCSSForeground: parse a CSS foreground attribute
1.1 cvs 3632: ----------------------------------------------------------------------*/
1.79 cvs 3633: static char *ParseCSSForeground (Element element, PSchema tsch,
1.78 cvs 3634: PresentationContext context,
1.79 cvs 3635: char *cssRule,
1.78 cvs 3636: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 3637: {
1.117 vatton 3638: PresentationValue best;
1.262 vatton 3639: char *p;
1.1 cvs 3640:
1.262 vatton 3641: p = cssRule;
1.117 vatton 3642: cssRule = ParseCSSColor (cssRule, &best);
1.295 vatton 3643: cssRule = CheckImportantRule (cssRule, context);
1.184 vatton 3644: if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.117 vatton 3645: {
1.295 vatton 3646: if (*cssRule != EOS && *cssRule !=';')
1.262 vatton 3647: {
3648: cssRule = SkipProperty (cssRule, FALSE);
3649: CSSParseError ("Invalid value", p, cssRule);
3650: }
3651: else
3652: /* install the new presentation */
3653: TtaSetStylePresentation (PRForeground, element, tsch, context, best);
1.117 vatton 3654: }
1.1 cvs 3655: return (cssRule);
3656: }
3657:
3658: /*----------------------------------------------------------------------
1.59 cvs 3659: ParseCSSBackgroundColor: parse a CSS background color attribute
1.1 cvs 3660: ----------------------------------------------------------------------*/
1.79 cvs 3661: static char *ParseCSSBackgroundColor (Element element, PSchema tsch,
1.78 cvs 3662: PresentationContext context,
1.79 cvs 3663: char *cssRule,
1.78 cvs 3664: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 3665: {
3666: PresentationValue best;
3667:
1.184 vatton 3668: best.typed_data.unit = UNIT_INVALID;
1.1 cvs 3669: best.typed_data.real = FALSE;
1.198 vatton 3670: if (!strncasecmp (cssRule, "transparent", 11))
1.1 cvs 3671: {
1.184 vatton 3672: best.typed_data.value = PATTERN_NONE;
3673: best.typed_data.unit = UNIT_REL;
1.295 vatton 3674: cssRule = SkipWord (cssRule);
3675: cssRule = CheckImportantRule (cssRule, context);
1.116 vatton 3676: if (DoApply)
1.295 vatton 3677: TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
3678: }
1.1 cvs 3679: else
3680: {
3681: cssRule = ParseCSSColor (cssRule, &best);
1.295 vatton 3682: cssRule = CheckImportantRule (cssRule, context);
1.184 vatton 3683: if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.1 cvs 3684: {
3685: /* install the new presentation. */
3686: TtaSetStylePresentation (PRBackground, element, tsch, context, best);
1.59 cvs 3687: /* thot specificity: need to set fill pattern for background color */
1.184 vatton 3688: best.typed_data.value = PATTERN_BACKGROUND;
3689: best.typed_data.unit = UNIT_REL;
1.1 cvs 3690: TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
3691: best.typed_data.value = 1;
1.184 vatton 3692: best.typed_data.unit = UNIT_REL;
1.1 cvs 3693: TtaSetStylePresentation (PRShowBox, element, tsch, context, best);
3694: }
3695: }
3696: return (cssRule);
3697: }
3698:
1.63 cvs 3699: /*----------------------------------------------------------------------
1.65 cvs 3700: ParseSVGStroke: parse a SVG stroke property
3701: ----------------------------------------------------------------------*/
1.79 cvs 3702: static char *ParseSVGStroke (Element element, PSchema tsch,
3703: PresentationContext context, char *cssRule,
3704: CSSInfoPtr css, ThotBool isHTML)
1.65 cvs 3705: {
3706: PresentationValue best;
1.245 quint 3707: char *url;
1.65 cvs 3708:
1.184 vatton 3709: best.typed_data.unit = UNIT_INVALID;
1.65 cvs 3710: best.typed_data.real = FALSE;
1.82 cvs 3711: if (!strncasecmp (cssRule, "none", 4))
1.65 cvs 3712: {
3713: best.typed_data.value = -2; /* -2 means transparent */
1.184 vatton 3714: best.typed_data.unit = UNIT_REL;
1.65 cvs 3715: cssRule = SkipWord (cssRule);
3716: }
1.245 quint 3717: else if (!strncasecmp (cssRule, "currentColor", 12))
3718: {
1.293 quint 3719: best.typed_data.unit = VALUE_INHERIT;
3720: cssRule = SkipWord (cssRule);
1.245 quint 3721: }
3722: else if (!strncasecmp (cssRule, "url", 3))
3723: {
3724: cssRule += 3;
3725: cssRule = ParseCSSUrl (cssRule, &url);
3726: /* **** do something with the url ***** */;
3727: TtaFreeMemory (url);
3728: /* **** caution: another color value may follow the uri (in case
3729: the uri could ne be dereferenced) *** */
3730: }
1.65 cvs 3731: else
1.293 quint 3732: cssRule = ParseCSSColor (cssRule, &best);
3733:
1.295 vatton 3734: cssRule = CheckImportantRule (cssRule, context);
1.293 quint 3735: if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.295 vatton 3736: /* install the new presentation */
3737: TtaSetStylePresentation (PRForeground, element, tsch, context, best);
1.65 cvs 3738: return (cssRule);
3739: }
3740:
3741: /*----------------------------------------------------------------------
1.63 cvs 3742: ParseSVGFill: parse a SVG fill property
3743: ----------------------------------------------------------------------*/
1.79 cvs 3744: static char *ParseSVGFill (Element element, PSchema tsch,
3745: PresentationContext context, char *cssRule,
3746: CSSInfoPtr css, ThotBool isHTML)
1.63 cvs 3747: {
3748: PresentationValue best;
1.245 quint 3749: char *url;
1.63 cvs 3750:
1.184 vatton 3751: best.typed_data.unit = UNIT_INVALID;
1.63 cvs 3752: best.typed_data.real = FALSE;
1.82 cvs 3753: if (!strncasecmp (cssRule, "none", 4))
1.63 cvs 3754: {
1.184 vatton 3755: best.typed_data.value = PATTERN_NONE;
3756: best.typed_data.unit = UNIT_REL;
1.295 vatton 3757: cssRule = CheckImportantRule (cssRule, context);
1.116 vatton 3758: if (DoApply)
1.295 vatton 3759: TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
1.65 cvs 3760: cssRule = SkipWord (cssRule);
1.294 vatton 3761: return (cssRule);
1.63 cvs 3762: }
1.245 quint 3763: else if (!strncasecmp (cssRule, "currentColor", 12))
3764: {
1.293 quint 3765: best.typed_data.unit = VALUE_INHERIT;
3766: cssRule = SkipWord (cssRule);
1.245 quint 3767: }
3768: else if (!strncasecmp (cssRule, "url", 3))
3769: {
3770: cssRule += 3;
3771: cssRule = ParseCSSUrl (cssRule, &url);
3772: /* **** do something with the url ***** */;
3773: TtaFreeMemory (url);
3774: /* **** caution: another color value may follow the uri (in case
3775: the uri could ne be dereferenced) *** */
3776: }
1.63 cvs 3777: else
1.293 quint 3778: cssRule = ParseCSSColor (cssRule, &best);
3779:
1.295 vatton 3780: cssRule = CheckImportantRule (cssRule, context);
1.293 quint 3781: if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.63 cvs 3782: {
1.293 quint 3783: /* install the new presentation. */
3784: TtaSetStylePresentation (PRBackground, element, tsch, context, best);
3785: /* thot specificity: need to set fill pattern for background color */
3786: best.typed_data.value = PATTERN_BACKGROUND;
3787: best.typed_data.unit = UNIT_REL;
3788: TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
1.63 cvs 3789: }
3790: return (cssRule);
3791: }
1.161 quint 3792:
1.155 cheyroul 3793: /*----------------------------------------------------------------------
3794: ParseSVGOpacity: parse a SVG fill property
3795: ----------------------------------------------------------------------*/
3796: static char *ParseSVGOpacity (Element element, PSchema tsch,
3797: PresentationContext context, char *cssRule,
3798: CSSInfoPtr css, ThotBool isHTML)
3799: {
3800: PresentationValue best;
1.63 cvs 3801:
1.184 vatton 3802: best.typed_data.unit = UNIT_INVALID;
1.155 cheyroul 3803: best.typed_data.real = FALSE;
3804: cssRule = ParseClampedUnit (cssRule, &best);
1.295 vatton 3805: cssRule = CheckImportantRule (cssRule, context);
1.155 cheyroul 3806: if (DoApply)
1.295 vatton 3807: /* install the new presentation. */
3808: TtaSetStylePresentation (PROpacity, element, tsch, context, best);
1.155 cheyroul 3809: return (cssRule);
3810: }
1.170 cheyroul 3811: /*----------------------------------------------------------------------
3812: ParseSVGOpacity: parse a SVG fill property
3813: ----------------------------------------------------------------------*/
3814: static char *ParseSVGStrokeOpacity (Element element, PSchema tsch,
3815: PresentationContext context, char *cssRule,
3816: CSSInfoPtr css, ThotBool isHTML)
3817: {
3818: PresentationValue best;
1.161 quint 3819:
1.184 vatton 3820: best.typed_data.unit = UNIT_INVALID;
1.170 cheyroul 3821: best.typed_data.real = FALSE;
3822: cssRule = ParseClampedUnit (cssRule, &best);
1.295 vatton 3823: cssRule = CheckImportantRule (cssRule, context);
1.170 cheyroul 3824: if (DoApply)
1.295 vatton 3825: /* install the new presentation. */
3826: TtaSetStylePresentation (PRStrokeOpacity, element, tsch, context, best);
1.170 cheyroul 3827: return (cssRule);
3828: }
3829: /*----------------------------------------------------------------------
3830: ParseSVGOpacity: parse a SVG fill property
3831: ----------------------------------------------------------------------*/
3832: static char *ParseSVGFillOpacity (Element element, PSchema tsch,
3833: PresentationContext context, char *cssRule,
3834: CSSInfoPtr css, ThotBool isHTML)
3835: {
3836: PresentationValue best;
3837:
1.184 vatton 3838: best.typed_data.unit = UNIT_INVALID;
1.170 cheyroul 3839: best.typed_data.real = FALSE;
3840: cssRule = ParseClampedUnit (cssRule, &best);
1.295 vatton 3841: cssRule = CheckImportantRule (cssRule, context);
1.170 cheyroul 3842: if (DoApply)
1.295 vatton 3843: /* install the new presentation. */
3844: TtaSetStylePresentation (PRFillOpacity, element, tsch, context, best);
1.170 cheyroul 3845: return (cssRule);
3846: }
1.207 vatton 3847:
1.1 cvs 3848: /*----------------------------------------------------------------------
1.59 cvs 3849: ParseCSSBackgroundImageCallback: Callback called asynchronously by
3850: FetchImage when a background image has been fetched.
1.1 cvs 3851: ----------------------------------------------------------------------*/
1.82 cvs 3852: void ParseCSSBackgroundImageCallback (Document doc, Element element,
1.203 vatton 3853: char *file, void *extra,
3854: ThotBool isnew)
1.1 cvs 3855: {
1.233 vatton 3856: DisplayMode dispMode = DisplayImmediately;
1.82 cvs 3857: BackgroundImageCallbackPtr callblock;
3858: Element el;
3859: PSchema tsch;
1.185 vatton 3860: CSSInfoPtr css;
1.206 vatton 3861: PInfoPtr pInfo;
1.207 vatton 3862: PresentationContext ctxt;
1.82 cvs 3863: PresentationValue image;
3864: PresentationValue value;
1.206 vatton 3865: ThotBool enabled;
1.82 cvs 3866: callblock = (BackgroundImageCallbackPtr) extra;
1.34 cvs 3867: if (callblock == NULL)
3868: return;
1.1 cvs 3869:
1.188 cheyroul 3870: css = NULL;
1.34 cvs 3871: el = callblock->el;
3872: tsch = callblock->tsch;
1.207 vatton 3873: ctxt = callblock->ctxt;
1.203 vatton 3874: if (doc == 0 && !isnew)
3875: /* apply to the current document only */
1.207 vatton 3876: doc = ctxt->doc;
1.185 vatton 3877: if (doc)
3878: {
3879: /* avoid too many redisplay */
3880: dispMode = TtaGetDisplayMode (doc);
3881: if (dispMode == DisplayImmediately)
3882: TtaSetDisplayMode (doc, DeferredDisplay);
3883: }
3884: else
3885: {
3886: /* check if the CSS still exists */
3887: css = CSSList;
3888: while (css && css != callblock->css)
3889: css = css->NextCSS;
3890: if (css == NULL)
3891: tsch = NULL;
3892: }
1.34 cvs 3893:
1.185 vatton 3894: if (el || tsch)
3895: {
3896: /* Ok the image was fetched, finish the background-image handling */
1.193 vatton 3897: image.typed_data.unit = UNIT_REL;
3898: image.typed_data.real = FALSE;
1.185 vatton 3899: image.pointer = file;
1.207 vatton 3900: TtaSetStylePresentation (PRBackgroundPicture, el, tsch, ctxt, image);
1.185 vatton 3901:
3902: /* enforce the showbox */
3903: value.typed_data.value = 1;
3904: value.typed_data.unit = UNIT_REL;
3905: value.typed_data.real = FALSE;
1.207 vatton 3906: TtaSetStylePresentation (PRShowBox, el, tsch, ctxt, value);
3907: /* check if the context can be freed */
3908: ctxt->uses -= 1;
3909: if (ctxt->uses == 0)
3910: /* no other image loading */
3911: TtaFreeMemory (ctxt);
1.185 vatton 3912: }
1.34 cvs 3913:
3914: TtaFreeMemory (callblock);
3915: /* restore the display mode */
1.185 vatton 3916: if (doc)
3917: {
3918: if (dispMode == DisplayImmediately)
3919: TtaSetDisplayMode (doc, dispMode);
3920: }
3921: else if (css)
3922: {
3923: for (doc = 1; doc < DocumentTableLength; doc++)
1.206 vatton 3924: if (css->infos[doc] &&
1.185 vatton 3925: /* don't manage a document used by make book */
3926: (DocumentMeta[doc] == NULL ||
3927: DocumentMeta[doc]->method != CE_MAKEBOOK))
3928: {
1.206 vatton 3929: pInfo = css->infos[doc];
3930: enabled = FALSE;
3931: while (pInfo && !enabled)
3932: {
3933: enabled = pInfo->PiEnabled;
3934: pInfo = pInfo->PiNext;
3935: }
1.185 vatton 3936: /* Change the Display Mode to take into account the new presentation */
3937: dispMode = TtaGetDisplayMode (doc);
3938: if (dispMode == DisplayImmediately)
1.194 vatton 3939: {
3940: TtaSetDisplayMode (doc, NoComputedDisplay);
3941: /* Restore the display mode */
3942: TtaSetDisplayMode (doc, dispMode);
3943: }
1.185 vatton 3944: }
3945: }
1.1 cvs 3946: }
3947:
1.217 vatton 3948: /*----------------------------------------------------------------------
3949: GetCSSBackgroundURL searches a CSS BackgroundImage url within
3950: the cssRule.
3951: Returns NULL or a new allocated url string.
3952: ----------------------------------------------------------------------*/
3953: char *GetCSSBackgroundURL (char *cssRule)
3954: {
3955: char *b, *url;
3956:
3957: url = NULL;
3958: b = strstr (cssRule, "url");
3959: if (b)
1.290 gully 3960: b = ParseCSSUrl (b, &url);
1.217 vatton 3961: return (url);
3962: }
3963:
3964: /*----------------------------------------------------------------------
3965: ParseCSSContent: parse a CSS content value
3966: ----------------------------------------------------------------------*/
3967: static char *ParseCSSContent (Element element, PSchema tsch,
3968: PresentationContext context, char *cssRule,
3969: CSSInfoPtr css, ThotBool isHTML)
3970: {
3971: char *p, quoteChar, *url;
3972:
3973: cssRule = SkipBlanksAndComments (cssRule);
3974: p = cssRule;
3975: if (!strncasecmp (cssRule, "url", 3))
3976: {
3977: cssRule += 3;
3978: cssRule = ParseCSSUrl (cssRule, &url);
3979: TtaFreeMemory (url);
3980: }
3981: else if (*cssRule == '"' || *cssRule == '\'')
3982: {
3983: quoteChar = *cssRule;
3984: cssRule++;
3985: cssRule = SkipQuotedString (cssRule, quoteChar);
1.259 vatton 3986: cssRule = SkipBlanksAndComments (cssRule);
1.253 vatton 3987: if (*cssRule != EOS && *cssRule !=';')
1.260 vatton 3988: cssRule = SkipProperty (cssRule, FALSE);
1.217 vatton 3989: }
3990: else
1.260 vatton 3991: cssRule = SkipProperty (cssRule, FALSE);
1.295 vatton 3992: cssRule = CheckImportantRule (cssRule, context);
1.217 vatton 3993: return (cssRule);
3994: }
1.1 cvs 3995:
3996: /*----------------------------------------------------------------------
1.59 cvs 3997: ParseCSSBackgroundImage: parse a CSS BackgroundImage attribute string.
1.1 cvs 3998: ----------------------------------------------------------------------*/
1.79 cvs 3999: static char *ParseCSSBackgroundImage (Element element, PSchema tsch,
1.207 vatton 4000: PresentationContext ctxt,
1.79 cvs 4001: char *cssRule, CSSInfoPtr css,
4002: ThotBool isHTML)
1.1 cvs 4003: {
1.49 cvs 4004: Element el;
1.1 cvs 4005: BackgroundImageCallbackPtr callblock;
1.49 cvs 4006: PresentationValue image, value;
1.79 cvs 4007: char *url;
1.82 cvs 4008: char *bg_image;
1.79 cvs 4009: char tempname[MAX_LENGTH];
4010: char imgname[MAX_LENGTH];
1.148 vatton 4011:
1.163 quint 4012: if (element)
1.148 vatton 4013: el = element;
1.163 quint 4014: else
4015: /* default element for FetchImage */
1.207 vatton 4016: el = TtaGetMainRoot (ctxt->doc);
1.163 quint 4017:
1.1 cvs 4018: url = NULL;
1.82 cvs 4019: cssRule = SkipBlanksAndComments (cssRule);
1.161 quint 4020: if (!strncasecmp (cssRule, "none", 4))
4021: {
1.260 vatton 4022: cssRule += 4;
1.276 vatton 4023: cssRule = CheckImportantRule (cssRule, ctxt);
1.247 quint 4024: if (DoApply)
4025: {
4026: /* no background image */
4027: image.pointer = NULL;
4028: TtaSetStylePresentation (PRBackgroundPicture, element, tsch, ctxt, image);
4029: /* no background color */
4030: value.typed_data.unit = UNIT_INVALID;
4031: value.typed_data.real = FALSE;
4032: value.typed_data.value = PATTERN_NONE;
4033: value.typed_data.unit = UNIT_REL;
4034: TtaSetStylePresentation (PRFillPattern, element, tsch, ctxt, value);
4035: }
1.161 quint 4036: }
4037: else if (!strncasecmp (cssRule, "url", 3))
1.1 cvs 4038: {
4039: cssRule += 3;
1.217 vatton 4040: cssRule = ParseCSSUrl (cssRule, &url);
1.207 vatton 4041: if (ctxt->destroy)
1.1 cvs 4042: {
4043: /* remove the background image PRule */
4044: image.pointer = NULL;
1.295 vatton 4045: cssRule = CheckImportantRule (cssRule, ctxt);
1.207 vatton 4046: TtaSetStylePresentation (PRBackgroundPicture, element, tsch, ctxt, image);
4047: if (TtaGetStylePresentation (PRFillPattern, element, tsch, ctxt, &value) < 0)
1.1 cvs 4048: {
4049: /* there is no FillPattern rule -> remove ShowBox rule */
4050: value.typed_data.value = 1;
1.184 vatton 4051: value.typed_data.unit = UNIT_REL;
1.1 cvs 4052: value.typed_data.real = FALSE;
1.207 vatton 4053: TtaSetStylePresentation (PRShowBox, element, tsch, ctxt, value);
1.1 cvs 4054: }
4055: }
4056: else if (url)
4057: {
1.30 cvs 4058: bg_image = TtaGetEnvString ("ENABLE_BG_IMAGES");
1.82 cvs 4059: if (bg_image == NULL || !strcasecmp (bg_image, "yes"))
1.161 quint 4060: /* background images are enabled */
1.1 cvs 4061: {
1.276 vatton 4062: cssRule = CheckImportantRule (cssRule, ctxt);
1.185 vatton 4063: callblock = (BackgroundImageCallbackPtr) TtaGetMemory (sizeof (BackgroundImageCallbackBlock));
1.191 vatton 4064: if (callblock)
1.1 cvs 4065: {
4066: callblock->el = element;
4067: callblock->tsch = tsch;
1.185 vatton 4068: callblock->css = css;
1.207 vatton 4069: callblock->ctxt = ctxt;
4070: /* new use of the context */
4071: ctxt->uses += 1;
1.18 cvs 4072: /* check if the image url is related to an external CSS */
1.182 vatton 4073: if (css)
1.18 cvs 4074: {
1.189 vatton 4075: if (css->url)
4076: /* the image concerns a CSS file */
4077: NormalizeURL (url, 0, tempname, imgname, css->url);
4078: else
4079: /* the image concerns a style element */
1.207 vatton 4080: NormalizeURL (url, ctxt->doc, tempname, imgname, NULL);
1.18 cvs 4081: /* fetch and display background image of element */
1.181 vatton 4082: FetchImage (0, el, tempname, AMAYA_LOAD_IMAGE,
1.161 quint 4083: ParseCSSBackgroundImageCallback, callblock);
1.18 cvs 4084: }
4085: else
1.207 vatton 4086: FetchImage (ctxt->doc, el, url, AMAYA_LOAD_IMAGE,
1.161 quint 4087: ParseCSSBackgroundImageCallback, callblock);
1.18 cvs 4088: }
4089: }
4090: }
1.229 vatton 4091: if (url)
4092: TtaFreeMemory (url);
1.18 cvs 4093: }
4094: return (cssRule);
4095: }
4096:
4097: /*----------------------------------------------------------------------
1.295 vatton 4098: ParseACSSBackgroundRepeat: parse a CSS BackgroundRepeat attribute string.
1.18 cvs 4099: ----------------------------------------------------------------------*/
1.295 vatton 4100: static char *ParseACSSBackgroundRepeat (Element element, PSchema tsch,
4101: PresentationContext ctxt,
4102: char *cssRule, CSSInfoPtr css, ThotBool isHTML)
1.18 cvs 4103: {
4104: PresentationValue repeat;
4105:
1.184 vatton 4106: repeat.typed_data.value = REALSIZE;
1.191 vatton 4107: repeat.typed_data.unit = UNIT_BOX;
1.18 cvs 4108: repeat.typed_data.real = FALSE;
1.82 cvs 4109: cssRule = SkipBlanksAndComments (cssRule);
4110: if (!strncasecmp (cssRule, "no-repeat", 9))
1.184 vatton 4111: repeat.typed_data.value = REALSIZE;
1.82 cvs 4112: else if (!strncasecmp (cssRule, "repeat-y", 8))
1.265 vatton 4113: repeat.typed_data.value = YREPEAT;
1.82 cvs 4114: else if (!strncasecmp (cssRule, "repeat-x", 8))
1.265 vatton 4115: repeat.typed_data.value = XREPEAT;
1.82 cvs 4116: else if (!strncasecmp (cssRule, "repeat", 6))
1.184 vatton 4117: repeat.typed_data.value = REPEAT;
1.18 cvs 4118: else
4119: return (cssRule);
4120:
1.295 vatton 4121: cssRule = SkipWord (cssRule);
4122: /* check if it's an important rule */
4123: cssRule = CheckImportantRule (cssRule, ctxt);
1.116 vatton 4124: if (DoApply)
1.295 vatton 4125: /* install the new presentation */
4126: TtaSetStylePresentation (PRPictureMode, element, tsch, ctxt, repeat);
4127: return (cssRule);
4128: }
4129:
4130: /*----------------------------------------------------------------------
4131: ParseCSSBackgroundRepeat: parse a CSS BackgroundRepeat attribute string.
4132: ----------------------------------------------------------------------*/
4133: static char *ParseCSSBackgroundRepeat (Element element, PSchema tsch,
4134: PresentationContext ctxt,
4135: char *cssRule, CSSInfoPtr css,
4136: ThotBool isHTML)
4137: {
4138: char *ptr;
4139:
4140: ptr = cssRule;
4141: cssRule = ParseACSSBackgroundRepeat (element, tsch, ctxt,
4142: cssRule, css, isHTML);
4143: if (ptr = cssRule)
1.117 vatton 4144: {
1.295 vatton 4145: cssRule = SkipValue ("Invalid background-repeat value", cssRule);
1.117 vatton 4146: /* check if it's an important rule */
1.276 vatton 4147: cssRule = CheckImportantRule (cssRule, ctxt);
1.117 vatton 4148: }
1.295 vatton 4149: return cssRule;
1.18 cvs 4150: }
4151:
4152: /*----------------------------------------------------------------------
1.295 vatton 4153: ParseACSSBackgroundAttachment: parse a CSS BackgroundAttachment
1.18 cvs 4154: attribute string.
4155: ----------------------------------------------------------------------*/
1.295 vatton 4156: static char *ParseACSSBackgroundAttachment (Element element, PSchema tsch,
1.207 vatton 4157: PresentationContext ctxt,
1.79 cvs 4158: char *cssRule, CSSInfoPtr css,
4159: ThotBool isHTML)
1.18 cvs 4160: {
1.200 vatton 4161: char *ptr;
4162:
1.163 quint 4163: cssRule = SkipBlanksAndComments (cssRule);
4164: if (!strncasecmp (cssRule, "scroll", 6))
1.199 vatton 4165: {
4166: /* force no-repeat for that background image */
1.200 vatton 4167: ptr = "no-repeat";
1.295 vatton 4168: ParseACSSBackgroundRepeat (element, tsch, ctxt, ptr, css, isHTML);
1.199 vatton 4169: cssRule = SkipWord (cssRule);
4170: }
1.163 quint 4171: else if (!strncasecmp (cssRule, "fixed", 5))
1.199 vatton 4172: {
4173: /* force no-repeat for that background image */
1.201 vatton 4174: ptr = "no-repeat";
1.295 vatton 4175: ParseACSSBackgroundRepeat (element, tsch, ctxt, ptr, css, isHTML);
1.199 vatton 4176: cssRule = SkipWord (cssRule);
4177: }
1.163 quint 4178: return (cssRule);
1.1 cvs 4179: }
4180:
4181: /*----------------------------------------------------------------------
1.295 vatton 4182: ParseCSSBackgroundAttachment: parse a CSS BackgroundAttachment
4183: attribute string.
4184: ----------------------------------------------------------------------*/
4185: static char *ParseCSSBackgroundAttachment (Element element, PSchema tsch,
4186: PresentationContext ctxt,
4187: char *cssRule, CSSInfoPtr css,
4188: ThotBool isHTML)
4189: {
4190: char *ptr;
4191:
4192: ptr = cssRule;
4193: cssRule = ParseACSSBackgroundAttachment (element, tsch, ctxt,
4194: cssRule, css, isHTML);
4195: if (ptr == cssRule)
4196: {
4197: cssRule = SkipValue ("Invalid background-attachement value", cssRule);
4198: /* check if it's an important rule */
4199: cssRule = CheckImportantRule (cssRule, ctxt);
4200: }
4201: return cssRule;
4202: }
4203:
4204: /*----------------------------------------------------------------------
1.279 vatton 4205: ParseACSSBackgroundPosition: parse a CSS BackgroundPosition
1.1 cvs 4206: attribute string.
4207: ----------------------------------------------------------------------*/
1.279 vatton 4208: static char *ParseACSSBackgroundPosition (Element element, PSchema tsch,
4209: PresentationContext ctxt,
4210: char *cssRule, CSSInfoPtr css,
4211: ThotBool isHTML)
1.1 cvs 4212: {
1.18 cvs 4213: PresentationValue repeat;
1.200 vatton 4214: char *ptr;
1.18 cvs 4215: ThotBool ok;
1.1 cvs 4216:
1.163 quint 4217: cssRule = SkipBlanksAndComments (cssRule);
4218: ok = TRUE;
4219: if (!strncasecmp (cssRule, "left", 4))
4220: cssRule = SkipWord (cssRule);
4221: else if (!strncasecmp (cssRule, "right", 5))
4222: cssRule = SkipWord (cssRule);
4223: else if (!strncasecmp (cssRule, "center", 6))
4224: cssRule = SkipWord (cssRule);
4225: else if (!strncasecmp (cssRule, "top", 3))
4226: cssRule = SkipWord (cssRule);
4227: else if (!strncasecmp (cssRule, "bottom", 6))
4228: cssRule = SkipWord (cssRule);
1.279 vatton 4229: else if (isdigit (*cssRule) || *cssRule == '.' || *cssRule == '-')
1.191 vatton 4230: {
1.206 vatton 4231: while (*cssRule != EOS && *cssRule != SPACE &&
4232: *cssRule != ',' && *cssRule != ';')
4233: cssRule++;
1.191 vatton 4234: }
1.163 quint 4235: else
4236: ok = FALSE;
4237:
4238: if (ok && DoApply)
1.148 vatton 4239: {
1.199 vatton 4240: /* force no-repeat for that background image */
1.200 vatton 4241: ptr = "no-repeat";
1.295 vatton 4242: ParseACSSBackgroundRepeat (element, tsch, ctxt, ptr, css, isHTML);
1.163 quint 4243: /* force realsize for the background image */
1.184 vatton 4244: repeat.typed_data.value = REALSIZE;
4245: repeat.typed_data.unit = UNIT_REL;
1.163 quint 4246: repeat.typed_data.real = FALSE;
4247: /* check if it's an important rule */
1.276 vatton 4248: cssRule = CheckImportantRule (cssRule, ctxt);
1.207 vatton 4249: /*TtaSetStylePresentation (PRPictureMode, element, tsch, ctxt, repeat);*/
1.279 vatton 4250: }
4251: cssRule = SkipBlanksAndComments (cssRule);
4252: return (cssRule);
4253: }
1.218 vatton 4254:
1.279 vatton 4255: /*----------------------------------------------------------------------
4256: ParseCSSBackgroundPosition: parse a CSS BackgroundPosition
4257: attribute string.
4258: ----------------------------------------------------------------------*/
4259: static char *ParseCSSBackgroundPosition (Element element, PSchema tsch,
4260: PresentationContext ctxt,
4261: char *cssRule, CSSInfoPtr css,
4262: ThotBool isHTML)
4263: {
1.295 vatton 4264: char *ptr;
4265:
4266: ptr = cssRule;
1.279 vatton 4267: cssRule = ParseACSSBackgroundPosition (element, tsch, ctxt,
4268: cssRule, css, isHTML);
1.295 vatton 4269: if (ptr == cssRule)
1.279 vatton 4270: cssRule = ParseACSSBackgroundPosition (element, tsch, ctxt,
4271: cssRule, css, isHTML);
1.295 vatton 4272: if (ptr == cssRule)
4273: {
4274: cssRule = SkipValue ("Invalid background-position value", cssRule);
4275: /* check if it's an important rule */
4276: cssRule = CheckImportantRule (cssRule, ctxt);
4277: }
1.298 vatton 4278: else if (*cssRule != ';' && *cssRule != EOS)
4279: {
4280: /* possible second value */
4281: ptr = cssRule;
4282: cssRule = ParseACSSBackgroundPosition (element, tsch, ctxt,
4283: cssRule, css, isHTML);
4284: if (ptr == cssRule)
4285: cssRule = ParseACSSBackgroundPosition (element, tsch, ctxt,
4286: cssRule, css, isHTML);
4287: if (ptr == cssRule)
4288: {
4289: cssRule = SkipValue ("Invalid background-position value", cssRule);
4290: /* check if it's an important rule */
4291: cssRule = CheckImportantRule (cssRule, ctxt);
4292: }
4293: }
1.163 quint 4294: return (cssRule);
1.18 cvs 4295: }
4296:
4297: /*----------------------------------------------------------------------
1.59 cvs 4298: ParseCSSBackground: parse a CSS background attribute
1.18 cvs 4299: ----------------------------------------------------------------------*/
1.79 cvs 4300: static char *ParseCSSBackground (Element element, PSchema tsch,
1.207 vatton 4301: PresentationContext ctxt, char *cssRule,
1.79 cvs 4302: CSSInfoPtr css, ThotBool isHTML)
1.18 cvs 4303: {
1.79 cvs 4304: char *ptr;
1.93 vatton 4305: int skippedNL;
1.18 cvs 4306:
1.82 cvs 4307: cssRule = SkipBlanksAndComments (cssRule);
4308: while (*cssRule != ';' && *cssRule != EOS && *cssRule != ',')
1.18 cvs 4309: {
1.71 cvs 4310: /* perhaps a Background Image */
1.198 vatton 4311: if (!strncasecmp (cssRule, "url", 3) || !strncasecmp (cssRule, "none", 4))
1.207 vatton 4312: cssRule = ParseCSSBackgroundImage (element, tsch, ctxt, cssRule,
1.63 cvs 4313: css, isHTML);
1.18 cvs 4314: /* perhaps a Background Attachment */
1.82 cvs 4315: else if (!strncasecmp (cssRule, "scroll", 6) ||
4316: !strncasecmp (cssRule, "fixed", 5))
1.295 vatton 4317: cssRule = ParseACSSBackgroundAttachment (element, tsch, ctxt,
1.63 cvs 4318: cssRule, css, isHTML);
1.18 cvs 4319: /* perhaps a Background Repeat */
1.82 cvs 4320: else if (!strncasecmp (cssRule, "no-repeat", 9) ||
4321: !strncasecmp (cssRule, "repeat-y", 8) ||
4322: !strncasecmp (cssRule, "repeat-x", 8) ||
4323: !strncasecmp (cssRule, "repeat", 6))
1.295 vatton 4324: cssRule = ParseACSSBackgroundRepeat (element, tsch, ctxt,
4325: cssRule, css, isHTML);
1.18 cvs 4326: /* perhaps a Background Position */
1.82 cvs 4327: else if (!strncasecmp (cssRule, "left", 4) ||
4328: !strncasecmp (cssRule, "right", 5) ||
4329: !strncasecmp (cssRule, "center", 6) ||
4330: !strncasecmp (cssRule, "top", 3) ||
4331: !strncasecmp (cssRule, "bottom", 6) ||
1.279 vatton 4332: isdigit (*cssRule) || *cssRule == '.' || *cssRule == '-')
4333: cssRule = ParseACSSBackgroundPosition (element, tsch, ctxt,
1.63 cvs 4334: cssRule, css, isHTML);
1.18 cvs 4335: /* perhaps a Background Color */
4336: else
4337: {
1.93 vatton 4338: skippedNL = NewLineSkipped;
1.18 cvs 4339: /* check if the rule has been found */
4340: ptr = cssRule;
1.207 vatton 4341: cssRule = ParseCSSBackgroundColor (element, tsch, ctxt,
1.82 cvs 4342: cssRule, css, isHTML);
1.43 cvs 4343: if (ptr == cssRule)
1.93 vatton 4344: {
4345: NewLineSkipped = skippedNL;
4346: /* rule not found */
1.234 vatton 4347: cssRule = SkipProperty (cssRule, FALSE);
1.93 vatton 4348: }
1.18 cvs 4349: }
1.82 cvs 4350: cssRule = SkipBlanksAndComments (cssRule);
1.18 cvs 4351: }
4352: return (cssRule);
4353: }
4354:
1.59 cvs 4355: /*----------------------------------------------------------------------
1.60 cvs 4356: ParseCSSPageBreakBefore: parse a CSS page-break-before attribute
1.59 cvs 4357: ----------------------------------------------------------------------*/
1.79 cvs 4358: static char *ParseCSSPageBreakBefore (Element element, PSchema tsch,
1.207 vatton 4359: PresentationContext ctxt, char *cssRule,
1.79 cvs 4360: CSSInfoPtr css, ThotBool isHTML)
1.59 cvs 4361: {
4362: PresentationValue page;
4363:
1.184 vatton 4364: page.typed_data.unit = UNIT_INVALID;
1.59 cvs 4365: page.typed_data.real = FALSE;
1.82 cvs 4366: cssRule = SkipBlanksAndComments (cssRule);
4367: if (!strncasecmp (cssRule, "auto", 4))
1.184 vatton 4368: page.typed_data.value = PageAuto;
1.82 cvs 4369: else if (!strncasecmp (cssRule, "always", 6))
1.59 cvs 4370: {
1.184 vatton 4371: page.typed_data.unit = UNIT_REL;
4372: page.typed_data.value = PageAlways;
1.59 cvs 4373: }
1.82 cvs 4374: else if (!strncasecmp (cssRule, "avoid", 5))
1.59 cvs 4375: {
1.184 vatton 4376: page.typed_data.unit = UNIT_REL;
4377: page.typed_data.value = PageAvoid;
1.59 cvs 4378: }
1.82 cvs 4379: else if (!strncasecmp (cssRule, "left", 4))
1.59 cvs 4380: {
1.184 vatton 4381: page.typed_data.unit = UNIT_REL;
4382: page.typed_data.value = PageLeft;
1.59 cvs 4383: }
1.82 cvs 4384: else if (!strncasecmp (cssRule, "right", 5))
1.59 cvs 4385: {
1.184 vatton 4386: page.typed_data.unit = UNIT_REL;
4387: page.typed_data.value = PageRight;
1.59 cvs 4388: }
1.82 cvs 4389: else if (!strncasecmp (cssRule, "inherit", 7))
1.59 cvs 4390: {
1.293 quint 4391: page.typed_data.unit = VALUE_INHERIT;
1.184 vatton 4392: page.typed_data.value = PageInherit;
1.59 cvs 4393: }
4394: cssRule = SkipWord (cssRule);
1.295 vatton 4395: /* check if it's an important rule */
4396: cssRule = CheckImportantRule (cssRule, ctxt);
1.59 cvs 4397: /* install the new presentation */
1.295 vatton 4398: if (DoApply &&
4399: ((page.typed_data.unit == UNIT_REL && page.typed_data.value == PageAlways)
4400: || page.typed_data.unit == VALUE_INHERIT))
4401: TtaSetStylePresentation (PRPageBefore, element, tsch, ctxt, page);
1.59 cvs 4402: return (cssRule);
4403: }
4404:
4405: /*----------------------------------------------------------------------
1.60 cvs 4406: ParseCSSPageBreakAfter: parse a CSS page-break-after attribute
1.59 cvs 4407: ----------------------------------------------------------------------*/
1.79 cvs 4408: static char *ParseCSSPageBreakAfter (Element element, PSchema tsch,
1.207 vatton 4409: PresentationContext ctxt,
1.79 cvs 4410: char *cssRule, CSSInfoPtr css,
4411: ThotBool isHTML)
1.59 cvs 4412: {
4413: PresentationValue page;
4414:
1.184 vatton 4415: page.typed_data.unit = UNIT_INVALID;
1.59 cvs 4416: page.typed_data.real = FALSE;
1.82 cvs 4417: cssRule = SkipBlanksAndComments (cssRule);
4418: if (!strncasecmp (cssRule, "auto", 4))
1.184 vatton 4419: page.typed_data.value = PageAuto;
1.82 cvs 4420: else if (!strncasecmp (cssRule, "always", 6))
1.59 cvs 4421: {
1.184 vatton 4422: page.typed_data.unit = UNIT_REL;
4423: page.typed_data.value = PageAlways;
1.59 cvs 4424: }
1.82 cvs 4425: else if (!strncasecmp (cssRule, "avoid", 5))
1.59 cvs 4426: {
1.184 vatton 4427: page.typed_data.unit = UNIT_REL;
4428: page.typed_data.value = PageAvoid;
1.59 cvs 4429: }
1.82 cvs 4430: else if (!strncasecmp (cssRule, "left", 4))
1.59 cvs 4431: {
1.184 vatton 4432: page.typed_data.unit = UNIT_REL;
4433: page.typed_data.value = PageLeft;
1.59 cvs 4434: }
1.82 cvs 4435: else if (!strncasecmp (cssRule, "right", 5))
1.59 cvs 4436: {
1.184 vatton 4437: page.typed_data.unit = UNIT_REL;
4438: page.typed_data.value = PageRight;
1.59 cvs 4439: }
1.82 cvs 4440: else if (!strncasecmp (cssRule, "inherit", 7))
1.59 cvs 4441: {
1.293 quint 4442: page.typed_data.unit = VALUE_INHERIT;
1.184 vatton 4443: page.typed_data.value = PageInherit;
1.59 cvs 4444: }
4445: cssRule = SkipWord (cssRule);
1.295 vatton 4446: /* check if it's an important rule */
4447: cssRule = CheckImportantRule (cssRule, ctxt);
1.59 cvs 4448: /* install the new presentation */
1.295 vatton 4449: if (DoApply &&
4450: (page.typed_data.unit == UNIT_REL ||
4451: page.typed_data.unit == VALUE_INHERIT))
4452: /* TtaSetStylePresentation (PRPageAfter, element, tsch, ctxt, page) */;
1.59 cvs 4453: return (cssRule);
4454: }
4455:
4456: /*----------------------------------------------------------------------
1.60 cvs 4457: ParseCSSPageBreakInside: parse a CSS page-break-inside attribute
1.59 cvs 4458: ----------------------------------------------------------------------*/
1.79 cvs 4459: static char *ParseCSSPageBreakInside (Element element, PSchema tsch,
1.207 vatton 4460: PresentationContext ctxt,
1.79 cvs 4461: char *cssRule, CSSInfoPtr css,
4462: ThotBool isHTML)
1.59 cvs 4463: {
4464: PresentationValue page;
4465:
1.184 vatton 4466: page.typed_data.unit = UNIT_INVALID;
1.59 cvs 4467: page.typed_data.real = FALSE;
1.82 cvs 4468: cssRule = SkipBlanksAndComments (cssRule);
4469: if (!strncasecmp (cssRule, "auto", 4))
1.59 cvs 4470: {
1.184 vatton 4471: /*page.typed_data.unit = UNIT_REL;*/
4472: page.typed_data.value = PageAuto;
1.59 cvs 4473: }
1.82 cvs 4474: else if (!strncasecmp (cssRule, "avoid", 5))
1.59 cvs 4475: {
1.184 vatton 4476: page.typed_data.unit = UNIT_REL;
4477: page.typed_data.value = PageAvoid;
1.59 cvs 4478: }
1.82 cvs 4479: else if (!strncasecmp (cssRule, "inherit", 7))
1.59 cvs 4480: {
1.293 quint 4481: /* page.typed_data.unit = VALUE_INHERIT; */
1.184 vatton 4482: page.typed_data.value = PageInherit;
1.59 cvs 4483: }
4484: cssRule = SkipWord (cssRule);
1.295 vatton 4485: cssRule = CheckImportantRule (cssRule, ctxt);
1.59 cvs 4486: /* install the new presentation */
1.293 quint 4487: /*if ((page.typed_data.unit == UNIT_REL ||
4488: page.typed_data.unit == VALUE_INHERIT) &&
1.184 vatton 4489: page.typed_data.value == PageAvoid && DoApply)
1.295 vatton 4490: TtaSetStylePresentation (PRPageInside, element, tsch, ctxt, page);*/
1.59 cvs 4491: return (cssRule);
4492: }
1.18 cvs 4493:
1.60 cvs 4494: /*----------------------------------------------------------------------
1.217 vatton 4495: ParseSVGStrokeWidth: parse a SVG stroke-width property value.
1.60 cvs 4496: ----------------------------------------------------------------------*/
1.79 cvs 4497: static char *ParseSVGStrokeWidth (Element element, PSchema tsch,
1.207 vatton 4498: PresentationContext ctxt, char *cssRule,
1.79 cvs 4499: CSSInfoPtr css, ThotBool isHTML)
1.60 cvs 4500: {
4501: PresentationValue width;
4502:
1.82 cvs 4503: cssRule = SkipBlanksAndComments (cssRule);
1.60 cvs 4504: width.typed_data.value = 0;
1.184 vatton 4505: width.typed_data.unit = UNIT_INVALID;
1.60 cvs 4506: width.typed_data.real = FALSE;
1.110 vatton 4507: if (isdigit (*cssRule) || *cssRule == '.')
1.166 vatton 4508: {
1.60 cvs 4509: cssRule = ParseCSSUnit (cssRule, &width);
1.184 vatton 4510: if (width.typed_data.unit == UNIT_BOX)
4511: width.typed_data.unit = UNIT_PX;
1.166 vatton 4512: }
1.295 vatton 4513: else
4514: cssRule = SkipValue ("Invalid stroke-width value", cssRule);
4515:
4516: /* check if it's an important rule */
4517: cssRule = CheckImportantRule (cssRule, ctxt);
1.184 vatton 4518: if (width.typed_data.unit != UNIT_INVALID && DoApply)
1.117 vatton 4519: {
1.207 vatton 4520: TtaSetStylePresentation (PRLineWeight, element, tsch, ctxt, width);
1.117 vatton 4521: width.typed_data.value = 1;
1.184 vatton 4522: width.typed_data.unit = UNIT_REL;
1.117 vatton 4523: }
1.60 cvs 4524: return (cssRule);
4525: }
4526:
1.217 vatton 4527: /*----------------------------------------------------------------------
4528: ParseCSSPosition: parse a CSS Position attribute string.
4529: ----------------------------------------------------------------------*/
4530: static char *ParseCSSPosition (Element element, PSchema tsch,
4531: PresentationContext ctxt,
4532: char *cssRule, CSSInfoPtr css,
4533: ThotBool isHTML)
4534: {
4535: char *ptr;
4536:
4537: cssRule = SkipBlanksAndComments (cssRule);
4538: ptr = cssRule;
4539: if (!strncasecmp (cssRule, "static", 6))
4540: cssRule = SkipWord (cssRule);
4541: else if (!strncasecmp (cssRule, "relative", 7))
4542: cssRule = SkipWord (cssRule);
4543: else if (!strncasecmp (cssRule, "absolute", 8))
4544: cssRule = SkipWord (cssRule);
4545: else if (!strncasecmp (cssRule, "fixed", 5))
4546: cssRule = SkipWord (cssRule);
4547: else if (!strncasecmp (cssRule, "inherit", 7))
4548: cssRule = SkipWord (cssRule);
4549: else
4550: cssRule = SkipValue ("Invalid Position value", ptr);
1.295 vatton 4551: /* check if it's an important rule */
4552: cssRule = CheckImportantRule (cssRule, ctxt);
1.217 vatton 4553: return (cssRule);
4554: }
4555:
4556: /*----------------------------------------------------------------------
4557: ParseCSSTop: parse a CSS Top attribute
4558: ----------------------------------------------------------------------*/
4559: static char *ParseCSSTop (Element element, PSchema tsch,
4560: PresentationContext context, char *cssRule,
4561: CSSInfoPtr css, ThotBool isHTML)
4562: {
4563: PresentationValue val;
4564: char *ptr;
4565:
4566: cssRule = SkipBlanksAndComments (cssRule);
4567: ptr = cssRule;
4568: /* first parse the attribute string */
4569: if (!strncasecmp (cssRule, "auto", 4) ||
4570: !strncasecmp (cssRule, "inherit", 7))
4571: {
4572: val.typed_data.unit = VALUE_AUTO;
4573: val.typed_data.value = 0;
4574: val.typed_data.real = FALSE;
4575: cssRule = SkipWord (cssRule);
4576: }
4577: else
4578: cssRule = ParseCSSUnit (cssRule, &val);
4579: if (val.typed_data.value != 0 &&
4580: (val.typed_data.unit == UNIT_INVALID ||
4581: val.typed_data.unit == UNIT_BOX))
4582: {
1.218 vatton 4583: cssRule = SkipValue ("top value", ptr);
1.217 vatton 4584: val.typed_data.unit = UNIT_PX;
4585: }
1.295 vatton 4586: cssRule = CheckImportantRule (cssRule, context);
1.217 vatton 4587: /***
4588: if (DoApply)
1.295 vatton 4589: TtaSetStylePresentation (PR, element, tsch, context, val);
1.217 vatton 4590: ***/
4591: return (cssRule);
4592: }
4593:
4594: /*----------------------------------------------------------------------
4595: ParseCSSRight: parse a CSS Right attribute
4596: ----------------------------------------------------------------------*/
4597: static char *ParseCSSRight (Element element, PSchema tsch,
4598: PresentationContext context, char *cssRule,
4599: CSSInfoPtr css, ThotBool isHTML)
4600: {
4601: PresentationValue val;
4602: char *ptr;
4603:
4604: cssRule = SkipBlanksAndComments (cssRule);
4605: ptr = cssRule;
4606: /* first parse the attribute string */
4607: if (!strncasecmp (cssRule, "auto", 4) ||
4608: !strncasecmp (cssRule, "inherit", 7))
4609: {
4610: val.typed_data.unit = VALUE_AUTO;
4611: val.typed_data.value = 0;
4612: val.typed_data.real = FALSE;
4613: cssRule = SkipWord (cssRule);
4614: }
4615: else
4616: cssRule = ParseCSSUnit (cssRule, &val);
4617: if (val.typed_data.value != 0 &&
4618: (val.typed_data.unit == UNIT_INVALID ||
4619: val.typed_data.unit == UNIT_BOX))
4620: {
1.218 vatton 4621: cssRule = SkipValue ("right value", ptr);
1.217 vatton 4622: val.typed_data.unit = UNIT_PX;
4623: }
1.295 vatton 4624: cssRule = CheckImportantRule (cssRule, context);
1.217 vatton 4625: /***
4626: if (DoApply)
1.276 vatton 4627: TtaSetStylePresentation (PR, element, tsch, context, val);
1.217 vatton 4628: ***/
4629: return (cssRule);
4630: }
4631:
4632: /*----------------------------------------------------------------------
4633: ParseCSSBottom: parse a CSS Bottom attribute
4634: ----------------------------------------------------------------------*/
4635: static char *ParseCSSBottom (Element element, PSchema tsch,
4636: PresentationContext context, char *cssRule,
4637: CSSInfoPtr css, ThotBool isHTML)
4638: {
4639: PresentationValue val;
4640: char *ptr;
4641:
4642: cssRule = SkipBlanksAndComments (cssRule);
4643: ptr = cssRule;
4644: /* first parse the attribute string */
4645: if (!strncasecmp (cssRule, "auto", 4) ||
4646: !strncasecmp (cssRule, "inherit", 7))
4647: {
4648: val.typed_data.unit = VALUE_AUTO;
4649: val.typed_data.value = 0;
4650: val.typed_data.real = FALSE;
4651: cssRule = SkipWord (cssRule);
4652: }
4653: else
4654: cssRule = ParseCSSUnit (cssRule, &val);
4655: if (val.typed_data.value != 0 &&
4656: (val.typed_data.unit == UNIT_INVALID ||
4657: val.typed_data.unit == UNIT_BOX))
4658: {
1.218 vatton 4659: cssRule = SkipValue ("bottom value", ptr);
1.217 vatton 4660: val.typed_data.unit = UNIT_PX;
4661: }
1.295 vatton 4662: cssRule = CheckImportantRule (cssRule, context);
1.217 vatton 4663: /***
4664: if (DoApply)
1.295 vatton 4665: TtaSetStylePresentation (PR, element, tsch, context, val);
1.217 vatton 4666: ***/
4667: return (cssRule);
4668: }
4669:
4670: /*----------------------------------------------------------------------
4671: ParseCSSLeft: parse a CSS Left attribute
4672: ----------------------------------------------------------------------*/
4673: static char *ParseCSSLeft (Element element, PSchema tsch,
4674: PresentationContext context, char *cssRule,
4675: CSSInfoPtr css, ThotBool isHTML)
4676: {
4677: PresentationValue val;
4678: char *ptr;
4679:
4680: cssRule = SkipBlanksAndComments (cssRule);
4681: ptr = cssRule;
4682: /* first parse the attribute string */
4683: if (!strncasecmp (cssRule, "auto", 4) ||
4684: !strncasecmp (cssRule, "inherit", 7))
4685: {
4686: val.typed_data.unit = VALUE_AUTO;
4687: val.typed_data.value = 0;
4688: val.typed_data.real = FALSE;
4689: cssRule = SkipWord (cssRule);
4690: }
4691: else
4692: cssRule = ParseCSSUnit (cssRule, &val);
4693: if (val.typed_data.value != 0 &&
4694: (val.typed_data.unit == UNIT_INVALID ||
4695: val.typed_data.unit == UNIT_BOX))
4696: {
1.218 vatton 4697: cssRule = SkipValue ("left value", ptr);
1.217 vatton 4698: val.typed_data.unit = UNIT_PX;
4699: }
1.295 vatton 4700: cssRule = CheckImportantRule (cssRule, context);
1.217 vatton 4701: /***
4702: if (DoApply)
1.295 vatton 4703: TtaSetStylePresentation (PR, element, tsch, context, val);
1.217 vatton 4704: ***/
4705: return (cssRule);
4706: }
4707:
4708: /*----------------------------------------------------------------------
4709: ParseCSSZIndex: parse a CSS z-index attribute
4710: ----------------------------------------------------------------------*/
4711: static char *ParseCSSZIndex (Element element, PSchema tsch,
4712: PresentationContext context, char *cssRule,
4713: CSSInfoPtr css, ThotBool isHTML)
4714: {
4715: PresentationValue val;
4716: char *ptr;
4717:
4718: cssRule = SkipBlanksAndComments (cssRule);
4719: ptr = cssRule;
4720: /* first parse the attribute string */
4721: if (!strncasecmp (cssRule, "auto", 4) ||
4722: !strncasecmp (cssRule, "inherit", 7))
4723: {
4724: val.typed_data.unit = VALUE_AUTO;
4725: val.typed_data.value = 0;
4726: val.typed_data.real = FALSE;
4727: cssRule = SkipWord (cssRule);
4728: }
4729: else
4730: {
4731: cssRule = ParseCSSUnit (cssRule, &val);
4732: if (val.typed_data.unit != UNIT_BOX)
4733: {
1.218 vatton 4734: cssRule = SkipValue ("z-index value", ptr);
1.217 vatton 4735: val.typed_data.unit = UNIT_BOX;
4736: }
4737: }
1.295 vatton 4738: cssRule = CheckImportantRule (cssRule, context);
1.217 vatton 4739: /***
4740: if (DoApply)
1.295 vatton 4741: TtaSetStylePresentation (PR, element, tsch, context, val);
1.217 vatton 4742: ***/
4743: return (cssRule);
4744: }
4745:
1.18 cvs 4746: /************************************************************************
4747: * *
4748: * FUNCTIONS STYLE DECLARATIONS *
4749: * *
4750: ************************************************************************/
4751: /*
1.59 cvs 4752: * NOTE: Long attribute name MUST be placed before shortened ones !
1.18 cvs 4753: * e.g. "FONT-SIZE" must be placed before "FONT"
4754: */
4755: static CSSProperty CSSProperties[] =
4756: {
1.82 cvs 4757: {"background-color", ParseCSSBackgroundColor},
4758: {"background-image", ParseCSSBackgroundImage},
4759: {"background-repeat", ParseCSSBackgroundRepeat},
4760: {"background-attachment", ParseCSSBackgroundAttachment},
4761: {"background-position", ParseCSSBackgroundPosition},
4762: {"background", ParseCSSBackground},
4763: {"border-top-width", ParseCSSBorderTopWidth},
4764: {"border-right-width", ParseCSSBorderRightWidth},
4765: {"border-bottom-width", ParseCSSBorderBottomWidth},
4766: {"border-left-width", ParseCSSBorderLeftWidth},
4767: {"border-width", ParseCSSBorderWidth},
4768: {"border-top-color", ParseCSSBorderColorTop},
4769: {"border-right-color", ParseCSSBorderColorRight},
4770: {"border-bottom-color", ParseCSSBorderColorBottom},
4771: {"border-left-color", ParseCSSBorderColorLeft},
4772: {"border-color", ParseCSSBorderColor},
4773: {"border-top-style", ParseCSSBorderStyleTop},
4774: {"border-right-style", ParseCSSBorderStyleRight},
4775: {"border-bottom-style", ParseCSSBorderStyleBottom},
4776: {"border-left-style", ParseCSSBorderStyleLeft},
4777: {"border-style", ParseCSSBorderStyle},
4778: {"border-top", ParseCSSBorderTop},
4779: {"border-right", ParseCSSBorderRight},
4780: {"border-bottom", ParseCSSBorderBottom},
4781: {"border-left", ParseCSSBorderLeft},
4782: {"border", ParseCSSBorder},
1.234 vatton 4783: {"bottom", ParseCSSBottom},
1.82 cvs 4784: {"clear", ParseCSSClear},
1.234 vatton 4785: {"color", ParseCSSForeground},
1.184 vatton 4786: {"content", ParseCSSContent},
1.234 vatton 4787: {"direction", ParseCSSDirection},
1.82 cvs 4788: {"display", ParseCSSDisplay},
1.234 vatton 4789: {"float", ParseCSSFloat},
4790: {"font-family", ParseCSSFontFamily},
4791: {"font-style", ParseCSSFontStyle},
4792: {"font-variant", ParseCSSFontVariant},
4793: {"font-weight", ParseCSSFontWeight},
4794: {"font-size-adjust", ParseCSSFontSizeAdjust},
4795: {"font-size", ParseCSSFontSize},
4796: {"font", ParseCSSFont},
4797: {"height", ParseCSSHeight},
1.217 vatton 4798: {"left", ParseCSSLeft},
1.234 vatton 4799: {"letter-spacing", ParseCSSLetterSpacing},
4800: {"line-height", ParseCSSLineHeight},
1.82 cvs 4801: {"list-style-type", ParseCSSListStyleType},
4802: {"list-style-image", ParseCSSListStyleImage},
4803: {"list-style-position", ParseCSSListStylePosition},
4804: {"list-style", ParseCSSListStyle},
1.234 vatton 4805: {"margin-bottom", ParseCSSMarginBottom},
4806: {"margin-top", ParseCSSMarginTop},
4807: {"margin-right", ParseCSSMarginRight},
4808: {"margin-left", ParseCSSMarginLeft},
4809: {"margin", ParseCSSMargin},
4810: {"padding-top", ParseCSSPaddingTop},
4811: {"padding-right", ParseCSSPaddingRight},
4812: {"padding-bottom", ParseCSSPaddingBottom},
4813: {"padding-left", ParseCSSPaddingLeft},
4814: {"padding", ParseCSSPadding},
1.82 cvs 4815: {"page-break-before", ParseCSSPageBreakBefore},
4816: {"page-break-after", ParseCSSPageBreakAfter},
4817: {"page-break-inside", ParseCSSPageBreakInside},
1.234 vatton 4818: {"position", ParseCSSPosition},
4819: {"right", ParseCSSRight},
4820: {"text-align", ParseCSSTextAlign},
1.243 quint 4821: {"text-anchor", ParseCSSTextAnchor},
1.234 vatton 4822: {"text-indent", ParseCSSTextIndent},
4823: {"text-decoration", ParseCSSTextDecoration},
4824: {"text-transform", ParseCSSTextTransform},
4825: {"top", ParseCSSTop},
4826: {"unicode-bidi", ParseCSSUnicodeBidi},
4827: {"vertical-align", ParseCSSVerticalAlign},
4828: {"white-space", ParseCSSWhiteSpace},
4829: {"width", ParseCSSWidth},
4830: {"word-spacing", ParseCSSWordSpacing},
4831: {"z-index", ParseCSSZIndex},
1.60 cvs 4832:
4833: /* SVG extensions */
1.234 vatton 4834: {"fill-opacity", ParseSVGFillOpacity},
4835: {"fill", ParseSVGFill},
4836: {"opacity", ParseSVGOpacity},
1.170 cheyroul 4837: {"stroke-opacity", ParseSVGStrokeOpacity},
1.82 cvs 4838: {"stroke-width", ParseSVGStrokeWidth},
1.234 vatton 4839: {"stroke", ParseSVGStroke}
1.18 cvs 4840: };
1.155 cheyroul 4841:
1.18 cvs 4842: #define NB_CSSSTYLEATTRIBUTE (sizeof(CSSProperties) / sizeof(CSSProperty))
4843:
4844: /*----------------------------------------------------------------------
1.59 cvs 4845: ParseCSSRule: parse a CSS Style string
1.18 cvs 4846: we expect the input string describing the style to be of the
1.59 cvs 4847: form: PRORPERTY: DESCRIPTION [ ; PROPERTY: DESCRIPTION ] *
1.18 cvs 4848: but tolerate incorrect or incomplete input
4849: ----------------------------------------------------------------------*/
1.79 cvs 4850: static void ParseCSSRule (Element element, PSchema tsch,
1.207 vatton 4851: PresentationContext ctxt, char *cssRule,
1.79 cvs 4852: CSSInfoPtr css, ThotBool isHTML)
1.18 cvs 4853: {
1.34 cvs 4854: DisplayMode dispMode;
1.250 vatton 4855: char *p = NULL, *next;
1.214 quint 4856: char *valueStart;
1.18 cvs 4857: int lg;
1.34 cvs 4858: unsigned int i;
1.76 cvs 4859: ThotBool found;
1.18 cvs 4860:
1.34 cvs 4861: /* avoid too many redisplay */
1.207 vatton 4862: dispMode = TtaGetDisplayMode (ctxt->doc);
1.34 cvs 4863: if (dispMode == DisplayImmediately)
1.207 vatton 4864: TtaSetDisplayMode (ctxt->doc, DeferredDisplay);
1.34 cvs 4865:
1.82 cvs 4866: while (*cssRule != EOS)
1.18 cvs 4867: {
1.82 cvs 4868: cssRule = SkipBlanksAndComments (cssRule);
1.153 vatton 4869: if (*cssRule < 0x41 || *cssRule > 0x7A ||
1.133 vatton 4870: (*cssRule > 0x5A && *cssRule < 0x60))
1.153 vatton 4871: cssRule++;
1.194 vatton 4872: else if (*cssRule != EOS)
1.89 cvs 4873: {
1.153 vatton 4874: found = FALSE;
4875: /* look for the type of property */
4876: for (i = 0; i < NB_CSSSTYLEATTRIBUTE && !found; i++)
1.18 cvs 4877: {
1.153 vatton 4878: lg = strlen (CSSProperties[i].name);
4879: if (!strncasecmp (cssRule, CSSProperties[i].name, lg))
4880: {
4881: p = cssRule + lg;
4882: found = TRUE;
4883: i--;
4884: }
1.18 cvs 4885: }
1.153 vatton 4886: if (i == NB_CSSSTYLEATTRIBUTE)
1.234 vatton 4887: cssRule = SkipProperty (cssRule, TRUE);
1.153 vatton 4888: else
1.18 cvs 4889: {
1.153 vatton 4890: /* update index and skip the ":" indicator if present */
1.86 cvs 4891: p = SkipBlanksAndComments (p);
1.153 vatton 4892: if (*p == ':')
1.61 cvs 4893: {
1.153 vatton 4894: p++;
4895: p = SkipBlanksAndComments (p);
4896: /* try to parse the value associated with this property */
4897: if (CSSProperties[i].parsing_function != NULL)
4898: {
1.214 quint 4899: valueStart = p;
4900: p = CSSProperties[i].parsing_function (element, tsch,
4901: ctxt, p, css, isHTML);
4902: if (!element && isHTML)
4903: {
4904: if (ctxt->type == HTML_EL_Input)
4905: /* it's a generic rule for the HTML element input.
4906: Generate a Thot Pres rule for each kind of
4907: input element */
4908: {
4909: ctxt->type = HTML_EL_Text_Input;
4910: p = CSSProperties[i].parsing_function (element,
4911: tsch, ctxt, valueStart, css, isHTML);
4912: ctxt->type = HTML_EL_Password_Input;
4913: p = CSSProperties[i].parsing_function (element,
4914: tsch, ctxt, valueStart, css, isHTML);
4915: ctxt->type = HTML_EL_File_Input;
4916: p = CSSProperties[i].parsing_function (element,
4917: tsch, ctxt, valueStart, css, isHTML);
4918: ctxt->type = HTML_EL_Checkbox_Input;
4919: p = CSSProperties[i].parsing_function (element,
4920: tsch, ctxt, valueStart, css, isHTML);
4921: ctxt->type = HTML_EL_Radio_Input;
4922: p = CSSProperties[i].parsing_function (element,
4923: tsch, ctxt, valueStart, css, isHTML);
4924: ctxt->type = HTML_EL_Submit_Input;
4925: p = CSSProperties[i].parsing_function (element,
4926: tsch, ctxt, valueStart, css, isHTML);
4927: ctxt->type = HTML_EL_Reset_Input;
4928: p = CSSProperties[i].parsing_function (element,
4929: tsch, ctxt, valueStart, css, isHTML);
4930: ctxt->type = HTML_EL_Button_Input;
4931: p = CSSProperties[i].parsing_function (element,
4932: tsch, ctxt, valueStart, css, isHTML);
4933: ctxt->type = HTML_EL_Input;
4934: }
4935: else if (ctxt->type == HTML_EL_ruby)
4936: /* it's a generic rule for the HTML element ruby.
4937: Generate a Thot Pres rule for each kind of
4938: ruby element. */
4939: {
4940: ctxt->type = HTML_EL_simple_ruby;
4941: p = CSSProperties[i].parsing_function (element,
4942: tsch, ctxt, valueStart, css, isHTML);
4943: ctxt->type = HTML_EL_complex_ruby;
4944: p = CSSProperties[i].parsing_function (element,
4945: tsch, ctxt, valueStart, css, isHTML);
4946: ctxt->type = HTML_EL_ruby;
4947: }
4948: }
1.153 vatton 4949: /* update index and skip the ";" separator if present */
1.250 vatton 4950: next = SkipBlanksAndComments (p);
4951: if (*next != EOS && *next != ';')
1.251 vatton 4952: CSSParseError ("Missing closing ';'", cssRule, p);
1.250 vatton 4953: cssRule = next;
1.153 vatton 4954: }
1.61 cvs 4955: }
1.153 vatton 4956: else
1.234 vatton 4957: cssRule = SkipProperty (cssRule, TRUE);
1.18 cvs 4958: }
4959: }
4960: /* next property */
1.82 cvs 4961: cssRule = SkipBlanksAndComments (cssRule);
1.89 cvs 4962: if (*cssRule == '}')
4963: {
4964: cssRule++;
1.168 vatton 4965: CSSPrintError ("Invalid character", "}");
1.89 cvs 4966: cssRule = SkipBlanksAndComments (cssRule);
4967: }
1.155 cheyroul 4968: if (*cssRule == ',' ||
4969: *cssRule == ';')
1.18 cvs 4970: {
4971: cssRule++;
1.82 cvs 4972: cssRule = SkipBlanksAndComments (cssRule);
1.18 cvs 4973: }
4974: }
1.34 cvs 4975:
4976: /* restore the display mode */
4977: if (dispMode == DisplayImmediately)
1.207 vatton 4978: TtaSetDisplayMode (ctxt->doc, dispMode);
1.18 cvs 4979: }
1.1 cvs 4980:
1.111 cvs 4981: /*----------------------------------------------------------------------
1.59 cvs 4982: ParseHTMLSpecificStyle: parse and apply a CSS Style string.
1.18 cvs 4983: This function must be called when a specific style is applied to an
4984: element.
1.114 quint 4985: The parameter specificity is the specificity of the style, 0 if it is
4986: not really a CSS rule.
1.1 cvs 4987: ----------------------------------------------------------------------*/
1.79 cvs 4988: void ParseHTMLSpecificStyle (Element el, char *cssRule, Document doc,
1.114 quint 4989: int specificity, ThotBool destroy)
1.1 cvs 4990: {
1.257 vatton 4991: DisplayMode dispMode;
1.207 vatton 4992: PresentationContext ctxt;
4993: ElementType elType;
4994: ThotBool isHTML;
1.1 cvs 4995:
1.207 vatton 4996: /* A rule applying to BODY is really meant to address HTML */
4997: elType = TtaGetElementType (el);
1.286 quint 4998: NewLineSkipped = 0;
1.207 vatton 4999: /* store the current line for eventually reported errors */
5000: LineNumber = TtaGetElementLineNumber (el);
5001: if (destroy)
5002: /* no reported errors */
5003: ParsedDoc = 0;
5004: else if (ParsedDoc != doc)
5005: {
5006: /* update the context for reported errors */
5007: ParsedDoc = doc;
5008: DocURL = DocumentURLs[doc];
5009: }
5010: isHTML = (strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML") == 0);
5011: /* create the context of the Specific presentation driver */
5012: ctxt = TtaGetSpecificStyleContext (doc);
5013: if (ctxt == NULL)
5014: return;
5015: ctxt->type = elType.ElTypeNum;
5016: ctxt->cssSpecificity = specificity;
1.236 quint 5017: ctxt->cssLine = LineNumber;
1.207 vatton 5018: ctxt->destroy = destroy;
5019: /* first use of the context */
5020: ctxt->uses = 1;
1.257 vatton 5021: /* save the current display mode */
5022: dispMode = TtaGetDisplayMode (doc);
1.207 vatton 5023: /* Call the parser */
5024: ParseCSSRule (el, NULL, (PresentationContext) ctxt, cssRule, NULL, isHTML);
1.257 vatton 5025: /* restore the display mode if necessary */
5026: TtaSetDisplayMode (doc, dispMode);
1.207 vatton 5027: /* check if the context can be freed */
5028: ctxt->uses -= 1;
5029: if (ctxt->uses == 0)
5030: /* no image loading */
5031: TtaFreeMemory(ctxt);
1.1 cvs 5032: }
5033:
1.68 cvs 5034:
1.1 cvs 5035: /*----------------------------------------------------------------------
1.207 vatton 5036: ParseGenericSelector: Create a generic context for a given selector
5037: string.
5038: If the selector is made of multiple comma, it parses them one at a time
5039: and return the end of the selector string to be handled or NULL.
1.231 vatton 5040: The parameter ctxt gives the current style context which will be passed
5041: to Thotlib.
5042: The parameter css points to the current CSS context.
5043: The parameter link points to the link element.
5044: The parameter url gives the URL of the parsed style sheet.
1.1 cvs 5045: ----------------------------------------------------------------------*/
1.207 vatton 5046: static char *ParseGenericSelector (char *selector, char *cssRule,
1.79 cvs 5047: GenericContext ctxt, Document doc,
1.231 vatton 5048: CSSInfoPtr css, Element link, char *url)
1.79 cvs 5049: {
5050: ElementType elType;
5051: PSchema tsch;
1.119 vatton 5052: AttributeType attrType;
1.240 quint 5053: char *deb, *cur, *sel, *next, c;
1.118 vatton 5054: char *schemaName, *mappedName;
1.79 cvs 5055: char *names[MAX_ANCESTORS];
5056: char *ids[MAX_ANCESTORS];
5057: char *classes[MAX_ANCESTORS];
5058: char *pseudoclasses[MAX_ANCESTORS];
5059: char *attrs[MAX_ANCESTORS];
5060: char *attrvals[MAX_ANCESTORS];
1.133 vatton 5061: AttrMatch attrmatch[MAX_ANCESTORS];
1.255 vatton 5062: ElemRel rel[MAX_ANCESTORS];
1.91 cvs 5063: int i, j, k, max;
1.256 vatton 5064: int att, kind;
1.118 vatton 5065: int specificity, xmlType;
1.217 vatton 5066: int skippedNL;
1.79 cvs 5067: ThotBool isHTML;
1.183 vatton 5068: ThotBool level, quoted;
1.1 cvs 5069:
1.207 vatton 5070: sel = ctxt->sel;
1.82 cvs 5071: sel[0] = EOS;
1.117 vatton 5072: specificity = 0;
1.1 cvs 5073: for (i = 0; i < MAX_ANCESTORS; i++)
5074: {
1.25 cvs 5075: names[i] = NULL;
5076: ids[i] = NULL;
5077: classes[i] = NULL;
5078: pseudoclasses[i] = NULL;
5079: attrs[i] = NULL;
5080: attrvals[i] = NULL;
1.133 vatton 5081: attrmatch[i] = Txtmatch;
1.255 vatton 5082: rel[i] = RelAncestor;
1.25 cvs 5083: ctxt->name[i] = 0;
5084: ctxt->names_nb[i] = 0;
5085: ctxt->attrType[i] = 0;
1.129 vatton 5086: ctxt->attrLevel[i] = 0;
1.25 cvs 5087: ctxt->attrText[i] = NULL;
1.178 quint 5088: ctxt->attrMatch[i] = Txtmatch;
1.1 cvs 5089: }
1.25 cvs 5090: ctxt->box = 0;
5091: ctxt->type = 0;
1.114 quint 5092: /* the specificity of the rule depends on the selector */
5093: ctxt->cssSpecificity = 0;
1.231 vatton 5094: /* localisation of the CSS rule */
5095: ctxt->cssLine = LineNumber + NewLineSkipped;
5096: ctxt->cssURL = url;
1.240 quint 5097:
1.286 quint 5098: skippedNL = NewLineSkipped;
1.82 cvs 5099: selector = SkipBlanksAndComments (selector);
1.286 quint 5100: NewLineSkipped = skippedNL;
1.27 cvs 5101: cur = &sel[0];
1.25 cvs 5102: max = 0; /* number of loops */
1.1 cvs 5103: while (1)
5104: {
1.85 cvs 5105: /* point to the following word in sel[] */
1.27 cvs 5106: deb = cur;
1.25 cvs 5107: /* copy an item of the selector into sel[] */
1.1 cvs 5108: /* put one word in the sel buffer */
1.82 cvs 5109: while (*selector != EOS && *selector != ',' &&
5110: *selector != '.' && *selector != ':' &&
1.118 vatton 5111: *selector != '#' && *selector != '[' &&
1.250 vatton 5112: *selector != '>' && *selector != '+' &&
1.118 vatton 5113: !TtaIsBlank (selector))
1.50 cvs 5114: *cur++ = *selector++;
1.82 cvs 5115: *cur++ = EOS; /* close the first string in sel[] */
5116: if (deb[0] != EOS)
1.117 vatton 5117: {
1.240 quint 5118: if (deb[0] <= 64 && deb[0] != '*')
5119: {
5120: CSSPrintError ("Invalid element", deb);
5121: return NULL;
5122: }
1.149 vatton 5123: else
1.240 quint 5124: {
5125: names[0] = deb;
5126: if (!strcmp (names[0], "html"))
5127: /* give a greater priority to the backgoud color of html */
5128: specificity += 3;
5129: else
5130: /* selector "*" has specificity zero */
5131: if (strcmp (names[0], "*"))
5132: specificity += 1;
5133: }
1.117 vatton 5134: }
1.25 cvs 5135: else
1.27 cvs 5136: names[0] = NULL;
1.226 quint 5137:
1.27 cvs 5138: classes[0] = NULL;
5139: pseudoclasses[0] = NULL;
5140: ids[0] = NULL;
5141: attrs[0] = NULL;
5142: attrvals[0] = NULL;
1.267 vatton 5143: attrmatch[0] = Txtmatch;
1.25 cvs 5144:
1.27 cvs 5145: /* now names[0] points to the beginning of the parsed item
1.25 cvs 5146: and cur to the next chain to be parsed */
1.129 vatton 5147: while (*selector == '.' || *selector == ':' ||
1.234 vatton 5148: *selector == '#' || *selector == '[')
1.129 vatton 5149: {
1.85 cvs 5150: /* point to the following word in sel[] */
5151: deb = cur;
1.129 vatton 5152: if (*selector == '.')
5153: {
5154: selector++;
5155: while (*selector != EOS && *selector != ',' &&
5156: *selector != '.' && *selector != ':' &&
5157: !TtaIsBlank (selector))
1.240 quint 5158: {
5159: if (*selector == '\\')
5160: {
5161: selector++;
5162: if (*selector != EOS)
5163: *cur++ = *selector++;
5164: }
5165: else
5166: *cur++ = *selector++;
5167: }
1.129 vatton 5168: /* close the word */
5169: *cur++ = EOS;
5170: /* point to the class in sel[] if it's valid name */
5171: if (deb[0] <= 64)
5172: {
1.168 vatton 5173: CSSPrintError ("Invalid class", deb);
1.116 vatton 5174: DoApply = FALSE;
1.129 vatton 5175: }
5176: else
5177: {
5178: classes[0] = deb;
1.117 vatton 5179: specificity += 10;
1.227 quint 5180: if (names[0] && !strcmp (names[0], "*"))
1.226 quint 5181: names[0] = NULL;
1.129 vatton 5182: }
5183: }
5184: else if (*selector == ':')
5185: {
5186: selector++;
5187: while (*selector != EOS && *selector != ',' &&
5188: *selector != '.' && *selector != ':' &&
5189: !TtaIsBlank (selector))
5190: *cur++ = *selector++;
5191: /* close the word */
5192: *cur++ = EOS;
5193: /* point to the pseudoclass in sel[] if it's valid name */
5194: if (deb[0] <= 64)
5195: {
1.168 vatton 5196: CSSPrintError ("Invalid pseudoclass", deb);
1.129 vatton 5197: DoApply = FALSE;
5198: }
5199: else
5200: {
5201: if (!strcmp (deb, "first-letter") ||
5202: !strcmp (deb, "first-line") ||
5203: !strcmp (deb, "before") ||
1.266 quint 5204: !strcmp (deb, "after") ||
5205: !strcmp (deb, "hover") ||
5206: !strcmp (deb, "focus"))
1.129 vatton 5207: /* not supported */
1.116 vatton 5208: DoApply = FALSE;
1.129 vatton 5209: else
5210: specificity += 10;
1.238 quint 5211: if (!strncmp (deb, "lang", 4))
5212: /* it's the lang pseudo-class */
5213: {
5214: if (deb[4] != '(' || deb[strlen(deb)-1] != ')')
5215: /* at least one paranthesis is missing. Error */
5216: {
5217: CSSPrintError ("Invalid :lang pseudoclass", deb);
5218: DoApply = FALSE;
5219: }
5220: else
5221: /* simulate selector [lang|="xxx"] if there no
5222: attribute yet in the selector */
5223: if (!attrs[0])
5224: {
5225: deb[strlen(deb)-1] = EOS;
5226: deb[4] = EOS;
5227: attrmatch[0] = Txtsubstring;
5228: attrs[0] = deb;
5229: attrvals[0] = &deb[5];
5230: }
5231: }
5232: else
1.267 vatton 5233: pseudoclasses[0] = deb;
1.227 quint 5234: if (names[0] && !strcmp (names[0], "*"))
1.226 quint 5235: names[0] = NULL;
1.129 vatton 5236: }
5237: }
5238: else if (*selector == '#')
5239: {
5240: selector++;
5241: while (*selector != EOS && *selector != ',' &&
5242: *selector != '.' && *selector != ':' &&
1.237 quint 5243: *selector != '#' &&
1.129 vatton 5244: !TtaIsBlank (selector))
5245: *cur++ = *selector++;
5246: /* close the word */
5247: *cur++ = EOS;
5248: /* point to the attribute in sel[] if it's valid name */
5249: if (deb[0] <= 64)
5250: {
1.168 vatton 5251: CSSPrintError ("Invalid id", deb);
1.129 vatton 5252: DoApply = FALSE;
5253: }
5254: else
5255: {
1.237 quint 5256: if (ids[0] && strcmp(ids[0], deb))
5257: {
5258: CSSPrintError ("Too many ids", deb);
5259: DoApply = FALSE;
5260: }
5261: else
5262: {
5263: ids[0] = deb;
5264: specificity += 100;
5265: if (names[0] && !strcmp (names[0], "*"))
5266: names[0] = NULL;
5267: }
1.129 vatton 5268: }
5269: }
5270: else if (*selector == '[')
5271: {
1.118 vatton 5272: selector++;
1.129 vatton 5273: while (*selector != EOS && *selector != ']' &&
1.131 vatton 5274: *selector != '=' && *selector != '~' &&
1.133 vatton 5275: *selector != '|' && *selector != '^' &&
5276: *selector != '!')
1.129 vatton 5277: *cur++ = *selector++;
1.133 vatton 5278: /* check matching */
5279: if (*selector == '~')
5280: {
5281: attrmatch[0] = Txtword;
5282: selector++;
5283: }
5284: else if (*selector == '|')
5285: {
5286: attrmatch[0] = Txtsubstring;
5287: selector++;
5288: }
5289: else
5290: attrmatch[0] = Txtmatch;
1.129 vatton 5291: /* close the word */
5292: *cur++ = EOS;
5293: /* point to the attribute in sel[] if it's valid name */
5294: if (deb[0] <= 64)
5295: {
1.168 vatton 5296: CSSPrintError ("Invalid attribute", deb);
1.129 vatton 5297: DoApply = FALSE;
5298: }
5299: else
5300: {
5301: attrs[0] = deb;
5302: specificity += 10;
5303: }
5304: if (*selector == '=')
5305: {
5306: /* look for a value "xxxx" */
5307: selector++;
5308: if (*selector != '"')
1.183 vatton 5309: quoted = FALSE;
1.129 vatton 5310: else
5311: {
1.183 vatton 5312: quoted = TRUE;
1.129 vatton 5313: /* we are now parsing the attribute value */
5314: selector++;
1.183 vatton 5315: }
5316: deb = cur;
5317: while ((quoted &&
5318: (*selector != '"' ||
5319: (*selector == '"' && selector[-1] == '\\'))) ||
5320: (!quoted && *selector != ']'))
5321: {
5322: if (*selector == EOS)
1.129 vatton 5323: {
1.183 vatton 5324: CSSPrintError ("Invalid attribute value", deb);
5325: DoApply = FALSE;
1.129 vatton 5326: }
1.183 vatton 5327: else
1.129 vatton 5328: {
1.228 quint 5329: if (attrmatch[0] == Txtword && TtaIsBlank (selector))
5330: {
5331: CSSPrintError ("No space allowed here: ", selector);
5332: DoApply = FALSE;
5333: }
1.238 quint 5334: *cur++ = *selector;
1.129 vatton 5335: }
1.228 quint 5336: selector++;
1.129 vatton 5337: }
1.183 vatton 5338: /* there is a value */
1.204 quint 5339: if (quoted && *selector == '"')
1.183 vatton 5340: {
5341: selector++;
5342: quoted = FALSE;
5343: }
5344: if (*selector != ']')
5345: {
5346: CSSPrintError ("Invalid attribute value", deb);
5347: DoApply = FALSE;
5348: }
5349: else
5350: {
5351: *cur++ = EOS;
5352: attrvals[0] = deb;
5353: selector++;
5354: }
1.129 vatton 5355: }
5356: /* end of the attribute */
1.183 vatton 5357: else if (*selector != ']')
1.129 vatton 5358: {
1.133 vatton 5359: selector[1] = EOS;
1.183 vatton 5360: CSSPrintError ("Invalid attribute", selector);
1.133 vatton 5361: selector += 2;
1.129 vatton 5362: DoApply = FALSE;
5363: }
5364: else
1.226 quint 5365: {
1.129 vatton 5366: selector++;
1.227 quint 5367: if (names[0] && !strcmp (names[0], "*"))
1.226 quint 5368: names[0] = NULL;
5369: }
1.130 vatton 5370: }
5371: else
5372: {
5373: /* not supported selector */
5374: while (*selector != EOS && *selector != ',' &&
5375: *selector != '.' && *selector != ':' &&
5376: !TtaIsBlank (selector))
5377: *cur++ = *selector++;
5378: /* close the word */
5379: *cur++ = EOS;
1.205 quint 5380: CSSPrintError ("Selector not supported:", deb);
1.130 vatton 5381: DoApply = FALSE;
1.129 vatton 5382: }
5383: }
1.1 cvs 5384:
1.286 quint 5385: skippedNL = NewLineSkipped;
1.82 cvs 5386: selector = SkipBlanksAndComments (selector);
1.286 quint 5387: NewLineSkipped = skippedNL;
5388:
1.25 cvs 5389: /* is it a multi-level selector? */
1.82 cvs 5390: if (*selector == EOS)
1.1 cvs 5391: /* end of the selector */
5392: break;
1.82 cvs 5393: else if (*selector == ',')
1.1 cvs 5394: {
5395: /* end of the current selector */
5396: selector++;
1.286 quint 5397: skippedNL = NewLineSkipped;
1.240 quint 5398: next = SkipBlanksAndComments (selector);
1.286 quint 5399: NewLineSkipped = skippedNL;
1.240 quint 5400: if (*next == EOS)
5401: /* nothing after the comma. Invalid selector */
5402: {
5403: CSSPrintError ("Syntax error:", selector);
5404: return NULL;
5405: }
1.1 cvs 5406: break;
5407: }
1.25 cvs 5408: else
5409: {
1.143 vatton 5410: if (*selector == '>')
5411: {
5412: /* handle immediat parent as a simple parent */
5413: selector++;
1.286 quint 5414: skippedNL = NewLineSkipped;
1.143 vatton 5415: selector = SkipBlanksAndComments (selector);
1.286 quint 5416: NewLineSkipped = skippedNL;
1.255 vatton 5417: rel[0] = RelImmediat;
1.250 vatton 5418: }
5419: else if (*selector == '+')
5420: {
5421: /* handle immediat parent as a simple parent */
5422: selector++;
1.286 quint 5423: skippedNL = NewLineSkipped;
1.250 vatton 5424: selector = SkipBlanksAndComments (selector);
1.286 quint 5425: NewLineSkipped = skippedNL;
1.255 vatton 5426: rel[0] = RelPrevious;
1.143 vatton 5427: }
1.25 cvs 5428: /* shifts the list to make room for the new name */
5429: max++; /* a new level in ancestor tables */
5430: if (max == MAX_ANCESTORS)
5431: /* abort the CSS parsing */
5432: return (selector);
5433: for (i = max; i > 0; i--)
5434: {
5435: names[i] = names[i - 1];
5436: ids[i] = ids[i - 1];
5437: classes[i] = classes[i - 1];
1.133 vatton 5438: pseudoclasses[i] = pseudoclasses[i - 1];
1.25 cvs 5439: attrs[i] = attrs[i - 1];
5440: attrvals[i] = attrvals[i - 1];
1.133 vatton 5441: attrmatch[i] = attrmatch[i - 1];
1.250 vatton 5442: rel[i] = rel[i - 1];
1.25 cvs 5443: }
5444: }
1.1 cvs 5445: }
5446:
5447: /* Now set up the context block */
1.25 cvs 5448: i = 0;
5449: k = 0;
5450: j = 0;
1.91 cvs 5451: /* default schema name */
1.119 vatton 5452: ctxt->schema = NULL;
1.122 vatton 5453: elType.ElSSchema = NULL;
5454: schemaName = TtaGetSSchemaName(TtaGetDocumentSSchema (doc));
1.119 vatton 5455: if (!strcmp (schemaName, "HTML"))
5456: xmlType = XHTML_TYPE;
5457: else if (!strcmp (schemaName, "MathML"))
5458: xmlType = MATH_TYPE;
5459: else if (!strcmp (schemaName, "SVG"))
5460: xmlType = SVG_TYPE;
5461: else if (!strcmp (schemaName, "XLink"))
5462: xmlType = XLINK_TYPE;
5463: else if (!strcmp (schemaName, "Annot"))
5464: xmlType = ANNOT_TYPE;
5465: else
5466: xmlType = XML_TYPE;
1.256 vatton 5467: while (i <= max && j < MAX_ANCESTORS)
1.25 cvs 5468: {
5469: if (names[i])
5470: {
1.118 vatton 5471: /* get the element type of this name in the current document */
1.220 quint 5472: if (xmlType == XML_TYPE)
1.223 quint 5473: /* it's a generic XML document. Check the main document schema */
1.220 quint 5474: {
5475: elType.ElSSchema = TtaGetDocumentSSchema (doc);
5476: TtaGetXmlElementType (names[i], &elType, &mappedName, doc);
5477: if (!elType.ElTypeNum)
1.226 quint 5478: {
5479: if (!strcmp (names[i], "*"))
5480: elType.ElTypeNum = HTML_EL_ANY_TYPE;
5481: else
5482: elType.ElSSchema = NULL;
5483: }
1.220 quint 5484: }
5485: else
1.226 quint 5486: {
5487: if (!strcmp (names[i], "*"))
5488: {
5489: elType.ElSSchema = TtaGetDocumentSSchema (doc);
5490: elType.ElTypeNum = HTML_EL_ANY_TYPE;
5491: }
5492: else
5493: MapXMLElementType (xmlType, names[i], &elType, &mappedName, &c,
5494: &level, doc);
5495: }
1.25 cvs 5496: if (i == 0)
5497: {
1.106 cvs 5498: if (elType.ElSSchema == NULL)
5499: {
1.269 vatton 5500: /* Selector not found: Search in the list of loaded schemas */
1.106 cvs 5501: TtaGetXmlElementType (names[i], &elType, NULL, doc);
1.119 vatton 5502: if (elType.ElSSchema)
5503: {
1.154 vatton 5504: /* the element type concerns an imported nature */
1.119 vatton 5505: schemaName = TtaGetSSchemaName(elType.ElSSchema);
5506: if (!strcmp (schemaName, "HTML"))
1.269 vatton 5507: {
5508: if (xmlType == XHTML_TYPE &&
5509: DocumentMeta[doc] && DocumentMeta[doc]->xmlformat)
5510: /* the selector was found but the case is not correct */
5511: elType.ElSSchema = NULL;
5512: else
5513: xmlType = XHTML_TYPE;
5514: }
1.119 vatton 5515: else if (!strcmp (schemaName, "MathML"))
5516: xmlType = MATH_TYPE;
5517: else if (!strcmp (schemaName, "SVG"))
5518: xmlType = SVG_TYPE;
5519: else if (!strcmp (schemaName, "XLink"))
5520: xmlType = XLINK_TYPE;
5521: else if (!strcmp (schemaName, "Annot"))
5522: xmlType = ANNOT_TYPE;
5523: else
5524: xmlType = XML_TYPE;
5525: }
1.118 vatton 5526: #ifdef XML_GENERIC
1.119 vatton 5527: else if (xmlType == XML_TYPE)
1.106 cvs 5528: {
5529: /* Creation of a new element type in the main schema */
5530: elType.ElSSchema = TtaGetDocumentSSchema (doc);
1.118 vatton 5531: TtaAppendXmlElement (names[i], &elType, &mappedName, doc);
1.106 cvs 5532: }
1.118 vatton 5533: #endif /* XML_GENERIC */
1.122 vatton 5534: else
5535: {
5536: if (xmlType != XHTML_TYPE)
5537: {
5538: MapXMLElementType (XHTML_TYPE, names[i], &elType,
5539: &mappedName, &c, &level, doc);
5540: if (elType.ElSSchema)
1.123 vatton 5541: elType.ElSSchema = GetXHTMLSSchema (doc);
1.122 vatton 5542: }
5543: if (elType.ElSSchema == NULL && xmlType != MATH_TYPE)
5544: {
5545: MapXMLElementType (MATH_TYPE, names[i], &elType,
5546: &mappedName, &c, &level, doc);
5547: if (elType.ElSSchema)
1.123 vatton 5548: elType.ElSSchema = GetMathMLSSchema (doc);
1.122 vatton 5549: }
5550: if (elType.ElSSchema == NULL && xmlType != SVG_TYPE)
5551: {
5552: MapXMLElementType (SVG_TYPE, names[i], &elType,
5553: &mappedName, &c, &level, doc);
5554: if (elType.ElSSchema)
1.123 vatton 5555: elType.ElSSchema = GetSVGSSchema (doc);
1.122 vatton 5556: }
5557: }
1.118 vatton 5558: }
1.119 vatton 5559:
1.118 vatton 5560: if (elType.ElSSchema == NULL)
5561: /* cannot apply these CSS rules */
5562: DoApply = FALSE;
5563: else
5564: {
5565: /* Store the element type */
5566: ctxt->type = elType.ElTypeNum;
5567: ctxt->name[0] = elType.ElTypeNum;
5568: ctxt->names_nb[0] = 0;
1.255 vatton 5569: ctxt->rel[0] = RelAncestor;
1.118 vatton 5570: ctxt->schema = elType.ElSSchema;
1.106 cvs 5571: }
1.25 cvs 5572: }
5573: else if (elType.ElTypeNum != 0)
5574: {
5575: /* look at the current context to see if the type is already
5576: stored */
1.121 vatton 5577: j = 1;
1.250 vatton 5578: while (j < k &&
1.255 vatton 5579: (ctxt->name[j] != elType.ElTypeNum ||
5580: ctxt->rel[j] != RelAncestor))
1.25 cvs 5581: j++;
5582: if (j == k)
5583: {
5584: ctxt->name[j] = elType.ElTypeNum;
5585: if (j != 0)
1.255 vatton 5586: {
5587: ctxt->names_nb[j] = 1;
5588: ctxt->rel[j] = rel[i];
5589: }
1.25 cvs 5590: }
5591: else
5592: /* increment the number of ancestor levels */
5593: ctxt->names_nb[j]++;
5594: }
1.154 vatton 5595: #ifdef XML_GENERIC
5596: else if (xmlType == XML_TYPE)
5597: {
1.158 vatton 5598: TtaGetXmlElementType (names[i], &elType, NULL, doc);
5599: if (elType.ElTypeNum == 0)
5600: {
5601: /* Creation of a new element type in the main schema */
5602: elType.ElSSchema = TtaGetDocumentSSchema (doc);
5603: TtaAppendXmlElement (names[i], &elType, &mappedName, doc);
5604: }
1.154 vatton 5605: if (elType.ElTypeNum != 0)
5606: {
5607: /* look at the current context to see if the type is already
5608: stored */
5609: j = 1;
1.250 vatton 5610: while (j < k &&
1.255 vatton 5611: (ctxt->name[j] != elType.ElTypeNum ||
5612: ctxt->rel[j] != RelAncestor))
1.154 vatton 5613: j++;
5614: if (j == k)
5615: {
5616: ctxt->name[j] = elType.ElTypeNum;
5617: if (j != 0)
1.250 vatton 5618: {
5619: ctxt->names_nb[j] = 1;
5620: ctxt->rel[j] = rel[i];
5621: }
5622: else
1.255 vatton 5623: ctxt->rel[j] = RelAncestor;
1.154 vatton 5624: }
5625: else
5626: /* increment the number of ancestor levels */
5627: ctxt->names_nb[j]++;
5628: }
5629: }
5630: #endif /* XML_GENERIC */
1.25 cvs 5631: else
1.117 vatton 5632: j = k;
1.25 cvs 5633: }
1.117 vatton 5634: else
5635: j = k;
1.1 cvs 5636:
1.25 cvs 5637: /* store attributes information */
5638: if (classes[i])
5639: {
5640: ctxt->attrText[j] = classes[i];
1.119 vatton 5641: if (xmlType == SVG_TYPE)
1.100 vatton 5642: ctxt->attrType[j] = SVG_ATTR_class;
1.119 vatton 5643: else if (xmlType == MATH_TYPE)
1.91 cvs 5644: ctxt->attrType[j] = MathML_ATTR_class;
1.119 vatton 5645: else if (xmlType == XHTML_TYPE)
1.107 cvs 5646: ctxt->attrType[j] = HTML_ATTR_Class;
5647: else
1.119 vatton 5648: #ifdef XML_GENERIC
1.107 cvs 5649: ctxt->attrType[j] = XML_ATTR_class;
5650: #else /* XML_GENERIC */
1.91 cvs 5651: ctxt->attrType[j] = HTML_ATTR_Class;
1.107 cvs 5652: #endif /* XML_GENERIC */
1.267 vatton 5653: /* a "class" attribute on an element may contain several
5654: words, one for each class it matches */
5655: ctxt->attrMatch[j] = Txtword;
1.79 cvs 5656: /* add a new entry */
1.129 vatton 5657: /* update attrLevel */
5658: ctxt->attrLevel[j] = i;
5659: j++;
1.25 cvs 5660: }
1.79 cvs 5661: if (pseudoclasses[i])
1.25 cvs 5662: {
5663: ctxt->attrText[j] = pseudoclasses[i];
1.119 vatton 5664: if (xmlType == SVG_TYPE)
1.100 vatton 5665: ctxt->attrType[j] = SVG_ATTR_PseudoClass;
1.119 vatton 5666: else if (xmlType == MATH_TYPE)
1.91 cvs 5667: ctxt->attrType[j] = MathML_ATTR_PseudoClass;
1.119 vatton 5668: else if (xmlType == XHTML_TYPE)
1.107 cvs 5669: ctxt->attrType[j] = HTML_ATTR_PseudoClass;
5670: else
1.119 vatton 5671: #ifdef XML_GENERIC
1.107 cvs 5672: ctxt->attrType[j] = XML_ATTR_PseudoClass;
5673: #else /* XML_GENERIC */
1.91 cvs 5674: ctxt->attrType[j] = HTML_ATTR_PseudoClass;
1.107 cvs 5675: #endif /* XML_GENERIC */
1.267 vatton 5676: ctxt->attrMatch[j] = Txtmatch;
1.79 cvs 5677: /* add a new entry */
1.129 vatton 5678: /* update attrLevel */
5679: ctxt->attrLevel[j] = i;
5680: j++;
1.25 cvs 5681: }
1.79 cvs 5682: if (ids[i])
1.25 cvs 5683: {
5684: ctxt->attrText[j] = ids[i];
1.119 vatton 5685: if (xmlType == SVG_TYPE)
1.100 vatton 5686: ctxt->attrType[j] = SVG_ATTR_id;
1.119 vatton 5687: else if (xmlType == MATH_TYPE)
1.91 cvs 5688: ctxt->attrType[j] = MathML_ATTR_id;
1.119 vatton 5689: else if (xmlType == XHTML_TYPE)
1.107 cvs 5690: ctxt->attrType[j] = HTML_ATTR_ID;
5691: else
1.119 vatton 5692: #ifdef XML_GENERIC
1.107 cvs 5693: ctxt->attrType[j] = XML_ATTR_id;
5694: #else /* XML_GENERIC */
1.91 cvs 5695: ctxt->attrType[j] = HTML_ATTR_ID;
1.107 cvs 5696: #endif /* XML_GENERIC */
1.267 vatton 5697: ctxt->attrMatch[j] = Txtmatch;
1.80 cvs 5698: /* add a new entry */
1.129 vatton 5699: /* update attrLevel */
5700: ctxt->attrLevel[j] = i;
5701: j++;
1.25 cvs 5702: }
1.79 cvs 5703: if (attrs[i])
1.25 cvs 5704: {
1.125 vatton 5705: /* it's an attribute */
1.220 quint 5706: if (xmlType == XML_TYPE)
5707: {
5708: attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
5709: TtaGetXmlAttributeType (attrs[i], &attrType, doc);
5710: att = attrType.AttrTypeNum;
5711: }
5712: else
1.221 vatton 5713: {
5714: MapXMLAttribute (xmlType, attrs[i], names[i], &level, doc, &att);
5715: if (ctxt->schema == NULL && att != 0)
5716: ctxt->schema = TtaGetDocumentSSchema (doc);
5717: }
1.278 quint 5718: if (att == 0)
5719: /* Attribute name not found: Search in the list of all loaded
5720: schemas */
5721: {
5722: attrType.AttrSSchema = NULL;
5723: TtaGetXmlAttributeType (attrs[i], &attrType, doc);
5724: att = attrType.AttrTypeNum;
5725: }
1.127 quint 5726: if (att == DummyAttribute && !strcmp (schemaName, "HTML"))
5727: /* it's the "type" attribute for an "input" element. In the tree
5728: it's represented by the element type, not by an attribute */
5729: att = 0;
1.119 vatton 5730: ctxt->attrType[j] = att;
1.133 vatton 5731: ctxt->attrMatch[j] = attrmatch[i];
1.125 vatton 5732: attrType.AttrSSchema = ctxt->schema;
5733: attrType.AttrTypeNum = att;
1.119 vatton 5734: if (i == 0 && att == 0 && ctxt->schema == NULL)
5735: {
1.125 vatton 5736: /* Not found -> search in the list of loaded schemas */
1.119 vatton 5737: attrType.AttrSSchema = NULL;
5738: TtaGetXmlAttributeType (attrs[i], &attrType, doc);
5739: ctxt->attrType[j] = attrType.AttrTypeNum;
5740: if (attrType.AttrSSchema)
1.125 vatton 5741: /* the element type concerns an imported nature */
5742: schemaName = TtaGetSSchemaName(attrType.AttrSSchema);
1.119 vatton 5743: #ifdef XML_GENERIC
5744: else if (xmlType == XML_TYPE)
5745: {
5746: /* The attribute is not yet present in the tree */
5747: /* Create a new global attribute */
5748: attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
5749: TtaAppendXmlAttribute (attrs[i], &attrType, doc);
5750: }
5751: #endif /* XML_GENERIC */
5752:
5753: if (attrType.AttrSSchema == NULL)
5754: /* cannot apply these CSS rules */
5755: DoApply = FALSE;
1.136 quint 5756: else if (elType.ElSSchema)
5757: ctxt->schema = elType.ElSSchema;
1.119 vatton 5758: else
1.136 quint 5759: ctxt->schema = attrType.AttrSSchema;
1.119 vatton 5760: }
1.125 vatton 5761: /* check the attribute type */
5762: if (!strcmp (schemaName, "HTML"))
5763: xmlType = XHTML_TYPE;
5764: else if (!strcmp (schemaName, "MathML"))
5765: xmlType = MATH_TYPE;
5766: else if (!strcmp (schemaName, "SVG"))
5767: xmlType = SVG_TYPE;
5768: else if (!strcmp (schemaName, "XLink"))
5769: xmlType = XLINK_TYPE;
5770: else if (!strcmp (schemaName, "Annot"))
5771: xmlType = ANNOT_TYPE;
5772: else
5773: xmlType = XML_TYPE;
5774: kind = TtaGetAttributeKind (attrType);
1.220 quint 5775: if (kind == 0 && attrvals[i])
1.125 vatton 5776: {
5777: /* enumerated value */
1.248 gully 5778: MapXMLAttributeValue (xmlType, attrvals[i], &attrType, &kind);
1.125 vatton 5779: /* store the attribute value */
5780: ctxt->attrText[j] = (char *) kind;
5781: }
5782: else
5783: ctxt->attrText[j] = attrvals[i];
1.129 vatton 5784: /* update attrLevel */
5785: ctxt->attrLevel[j] = i;
5786: j++;
1.25 cvs 5787: }
5788: i++;
1.117 vatton 5789: /* add a new entry */
5790: k++;
1.129 vatton 5791: if (k < j)
5792: k = j;
1.119 vatton 5793: if (i == 1 && ctxt->schema == NULL)
5794: /* use the document schema */
5795: ctxt->schema = TtaGetDocumentSSchema (doc);
1.1 cvs 5796: }
1.117 vatton 5797: /* set the selector specificity */
5798: ctxt->cssSpecificity = specificity;
1.25 cvs 5799: /* Get the schema name of the main element */
1.119 vatton 5800: schemaName = TtaGetSSchemaName (ctxt->schema);
5801: isHTML = (strcmp (schemaName, "HTML") == 0);
1.206 vatton 5802: tsch = GetPExtension (doc, ctxt->schema, css, link);
1.217 vatton 5803: skippedNL = NewLineSkipped;
1.119 vatton 5804: if (tsch && cssRule)
5805: ParseCSSRule (NULL, tsch, (PresentationContext) ctxt, cssRule, css, isHTML);
1.116 vatton 5806: /* future CSS rules should apply */
5807: DoApply = TRUE;
1.217 vatton 5808: if (selector)
5809: NewLineSkipped = skippedNL;
1.1 cvs 5810: return (selector);
5811: }
5812:
5813: /*----------------------------------------------------------------------
1.206 vatton 5814: ParseStyleDeclaration: parse a style declaration stored in the style
5815: element of a document
5816: We expect the style string to be of the form:
5817: .pinky, .awful { color: pink; font-family: helvetica }
1.231 vatton 5818: The parameter css points to the current CSS context.
5819: The parameter link points to the link element.
5820: The parameter url gives the URL of the parsed style sheet.
1.1 cvs 5821: ----------------------------------------------------------------------*/
1.206 vatton 5822: static void ParseStyleDeclaration (Element el, char *cssRule, Document doc,
1.231 vatton 5823: CSSInfoPtr css, Element link, char *url,
5824: ThotBool destroy)
1.1 cvs 5825: {
1.79 cvs 5826: GenericContext ctxt;
5827: char *decl_end;
5828: char *sel_end;
5829: char *selector;
1.1 cvs 5830:
5831: /* separate the selectors string */
1.82 cvs 5832: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 5833: decl_end = cssRule;
1.82 cvs 5834: while (*decl_end != EOS && *decl_end != '{')
1.286 quint 5835: {
5836: if (*decl_end == EOL)
5837: NewLineSkipped++;
5838: decl_end++;
5839: }
1.82 cvs 5840: if (*decl_end == EOS)
1.86 cvs 5841: {
1.168 vatton 5842: CSSPrintError ("Invalid selector", cssRule);
1.86 cvs 5843: return;
5844: }
1.1 cvs 5845: /* verify and clean the selector string */
5846: sel_end = decl_end - 1;
1.82 cvs 5847: while (*sel_end == SPACE || *sel_end == BSPACE ||
5848: *sel_end == EOL || *sel_end == CR)
1.1 cvs 5849: sel_end--;
5850: sel_end++;
1.82 cvs 5851: *sel_end = EOS;
1.1 cvs 5852: selector = cssRule;
5853:
5854: /* now, deal with the content ... */
5855: decl_end++;
5856: cssRule = decl_end;
1.137 vatton 5857: decl_end = &cssRule[strlen (cssRule) - 1];
5858: if (*decl_end != '{')
5859: *decl_end = EOS;
1.1 cvs 5860: /*
5861: * parse the style attribute string and install the corresponding
5862: * presentation attributes on the new element
5863: */
5864: ctxt = TtaGetGenericStyleContext (doc);
5865: if (ctxt == NULL)
5866: return;
5867: ctxt->destroy = destroy;
1.207 vatton 5868: /* first use of the context */
5869: ctxt->uses = 1;
1.197 vatton 5870: while (selector && *selector != EOS)
1.231 vatton 5871: selector = ParseGenericSelector (selector, cssRule, ctxt, doc, css,
5872: link, url);
1.207 vatton 5873: /* check if the context can be freed */
5874: ctxt->uses -= 1;
5875: if (ctxt->uses == 0)
5876: /* no image loading */
5877: TtaFreeMemory (ctxt);
1.1 cvs 5878: }
5879:
5880: /************************************************************************
5881: * *
5882: * EVALUATION FUNCTIONS / CASCADING AND OVERLOADING *
5883: * *
5884: ************************************************************************/
5885:
5886: /*----------------------------------------------------------------------
1.59 cvs 5887: IsImplicitClassName: return wether the Class name is an
1.1 cvs 5888: implicit one, eg "H1" or "H2 EM" meaning it's a GI name
5889: or an HTML context name.
5890: ----------------------------------------------------------------------*/
1.248 gully 5891: int IsImplicitClassName (char *class_, Document doc)
1.1 cvs 5892: {
1.79 cvs 5893: char name[200];
5894: char *cur = name;
5895: char *first;
5896: char save;
5897: SSchema schema;
1.1 cvs 5898:
5899: /* make a local copy */
1.248 gully 5900: strncpy (name, class_, 199);
1.1 cvs 5901: name[199] = 0;
5902:
5903: /* loop looking if each word is a GI */
5904: while (*cur != 0)
5905: {
5906: first = cur;
5907: cur = SkipWord (cur);
5908: save = *cur;
5909: *cur = 0;
5910: schema = NULL;
5911: if (MapGI (first, &schema, doc) == -1)
5912: {
5913: return (0);
5914: }
5915: *cur = save;
1.82 cvs 5916: cur = SkipBlanksAndComments (cur);
1.1 cvs 5917: }
5918: return (1);
5919: }
5920:
5921: /************************************************************************
5922: * *
1.114 quint 5923: * Functions needed for support of HTML: translate to CSS equivalent *
1.1 cvs 5924: * *
5925: ************************************************************************/
5926:
5927: /*----------------------------------------------------------------------
1.59 cvs 5928: HTMLSetBackgroundColor:
1.1 cvs 5929: ----------------------------------------------------------------------*/
1.264 vatton 5930: void HTMLSetBackgroundColor (Document doc, Element el, int specificity,
5931: char *color)
1.1 cvs 5932: {
1.79 cvs 5933: char css_command[100];
1.1 cvs 5934:
1.82 cvs 5935: sprintf (css_command, "background-color: %s", color);
1.264 vatton 5936: ParseHTMLSpecificStyle (el, css_command, doc, specificity, FALSE);
1.1 cvs 5937: }
5938:
5939: /*----------------------------------------------------------------------
1.59 cvs 5940: HTMLSetForegroundColor:
1.1 cvs 5941: ----------------------------------------------------------------------*/
1.264 vatton 5942: void HTMLSetForegroundColor (Document doc, Element el, int specificity,
5943: char *color)
1.1 cvs 5944: {
1.79 cvs 5945: char css_command[100];
1.1 cvs 5946:
1.82 cvs 5947: sprintf (css_command, "color: %s", color);
1.264 vatton 5948: ParseHTMLSpecificStyle (el, css_command, doc, specificity, FALSE);
1.1 cvs 5949: }
5950:
5951: /*----------------------------------------------------------------------
1.59 cvs 5952: HTMLResetBackgroundColor:
1.1 cvs 5953: ----------------------------------------------------------------------*/
1.97 vatton 5954: void HTMLResetBackgroundColor (Document doc, Element el)
1.1 cvs 5955: {
1.79 cvs 5956: char css_command[100];
1.1 cvs 5957:
1.82 cvs 5958: sprintf (css_command, "background: red");
1.114 quint 5959: ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1 cvs 5960: }
5961:
5962: /*----------------------------------------------------------------------
1.59 cvs 5963: HTMLResetBackgroundImage:
1.1 cvs 5964: ----------------------------------------------------------------------*/
1.97 vatton 5965: void HTMLResetBackgroundImage (Document doc, Element el)
1.1 cvs 5966: {
1.79 cvs 5967: char css_command[1000];
1.1 cvs 5968:
1.82 cvs 5969: sprintf (css_command, "background-image: url(xx); background-repeat: repeat");
1.114 quint 5970: ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1 cvs 5971: }
5972:
5973: /*----------------------------------------------------------------------
1.59 cvs 5974: HTMLResetForegroundColor:
1.1 cvs 5975: ----------------------------------------------------------------------*/
1.97 vatton 5976: void HTMLResetForegroundColor (Document doc, Element el)
1.1 cvs 5977: {
1.79 cvs 5978: char css_command[100];
1.1 cvs 5979:
1.36 cvs 5980: /* it's not necessary to well know the current color but it must be valid */
1.82 cvs 5981: sprintf (css_command, "color: red");
1.114 quint 5982: ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1 cvs 5983: }
5984:
5985: /*----------------------------------------------------------------------
1.59 cvs 5986: HTMLSetAlinkColor:
1.1 cvs 5987: ----------------------------------------------------------------------*/
1.208 vatton 5988: void HTMLSetAlinkColor (Document doc, Element el, char *color)
1.1 cvs 5989: {
1.79 cvs 5990: char css_command[100];
1.1 cvs 5991:
1.215 quint 5992: sprintf (css_command, ":link { color: %s }", color);
1.208 vatton 5993: ApplyCSSRules (el, css_command, doc, FALSE);
1.1 cvs 5994: }
5995:
5996: /*----------------------------------------------------------------------
1.59 cvs 5997: HTMLSetAactiveColor:
1.1 cvs 5998: ----------------------------------------------------------------------*/
1.208 vatton 5999: void HTMLSetAactiveColor (Document doc, Element el, char *color)
1.1 cvs 6000: {
1.79 cvs 6001: char css_command[100];
1.1 cvs 6002:
1.215 quint 6003: sprintf (css_command, ":active { color: %s }", color);
1.208 vatton 6004: ApplyCSSRules (el, css_command, doc, FALSE);
1.1 cvs 6005: }
6006:
6007: /*----------------------------------------------------------------------
1.59 cvs 6008: HTMLSetAvisitedColor:
1.1 cvs 6009: ----------------------------------------------------------------------*/
1.208 vatton 6010: void HTMLSetAvisitedColor (Document doc, Element el, char *color)
1.1 cvs 6011: {
1.79 cvs 6012: char css_command[100];
1.1 cvs 6013:
1.215 quint 6014: sprintf (css_command, ":visited { color: %s }", color);
1.208 vatton 6015: ApplyCSSRules (el, css_command, doc, FALSE);
1.1 cvs 6016: }
6017:
6018: /*----------------------------------------------------------------------
1.59 cvs 6019: HTMLResetAlinkColor:
1.1 cvs 6020: ----------------------------------------------------------------------*/
1.208 vatton 6021: void HTMLResetAlinkColor (Document doc, Element el)
1.1 cvs 6022: {
1.79 cvs 6023: char css_command[100];
1.1 cvs 6024:
1.215 quint 6025: sprintf (css_command, ":link { color: red }");
1.208 vatton 6026: ApplyCSSRules (el, css_command, doc, TRUE);
1.1 cvs 6027: }
6028:
6029: /*----------------------------------------------------------------------
1.59 cvs 6030: HTMLResetAactiveColor:
1.1 cvs 6031: ----------------------------------------------------------------------*/
1.208 vatton 6032: void HTMLResetAactiveColor (Document doc, Element el)
1.1 cvs 6033: {
1.79 cvs 6034: char css_command[100];
1.1 cvs 6035:
1.215 quint 6036: sprintf (css_command, ":active { color: red }");
1.208 vatton 6037: ApplyCSSRules (el, css_command, doc, TRUE);
1.1 cvs 6038: }
6039:
6040: /*----------------------------------------------------------------------
1.59 cvs 6041: HTMLResetAvisitedColor:
1.1 cvs 6042: ----------------------------------------------------------------------*/
1.208 vatton 6043: void HTMLResetAvisitedColor (Document doc, Element el)
1.1 cvs 6044: {
1.79 cvs 6045: char css_command[100];
1.1 cvs 6046:
1.215 quint 6047: sprintf (css_command, ":visited { color: red }");
1.208 vatton 6048: ApplyCSSRules (el, css_command, doc, TRUE);
1.1 cvs 6049: }
6050:
6051: /*----------------------------------------------------------------------
1.206 vatton 6052: ApplyCSSRules: parse a CSS Style description stored in the header of
6053: a HTML document.
1.1 cvs 6054: ----------------------------------------------------------------------*/
1.79 cvs 6055: void ApplyCSSRules (Element el, char *cssRule, Document doc, ThotBool destroy)
1.1 cvs 6056: {
1.206 vatton 6057: CSSInfoPtr css;
6058: PInfoPtr pInfo;
1.207 vatton 6059: ThotBool loadcss;
6060:
6061: /* check if we have to load CSS */
6062: TtaGetEnvBoolean ("LOAD_CSS", &loadcss);
6063: if (!loadcss)
6064: return;
1.1 cvs 6065:
1.206 vatton 6066: css = SearchCSS (doc, NULL, el, &pInfo);
1.1 cvs 6067: if (css == NULL)
1.209 vatton 6068: {
6069: /* create the document css context */
6070: css = AddCSS (doc, doc, CSS_DOCUMENT_STYLE, CSS_ALL, NULL, NULL, el);
6071: pInfo = css->infos[doc];
6072: }
1.206 vatton 6073: else if (pInfo == NULL)
6074: /* create the entry into the css context */
6075: pInfo = AddInfoCSS (doc, css, CSS_DOCUMENT_STYLE, CSS_ALL, el);
1.209 vatton 6076: if (pInfo->PiEnabled)
1.231 vatton 6077: ParseStyleDeclaration (el, cssRule, doc, css, el, NULL, destroy);
1.1 cvs 6078: }
6079:
6080: /*----------------------------------------------------------------------
1.145 quint 6081: ReadCSSRules: is the front-end function called by the document parser
6082: when detecting a <style type="text/css"> indicating it's the
1.1 cvs 6083: beginning of a CSS fragment or when reading a file .css.
6084:
6085: The CSS parser has to handle <!-- ... --> constructs used to
6086: prevent prehistoric browser from displaying the CSS as a text
6087: content. It will stop on any sequence "<x" where x is different
6088: from ! and will return x as to the caller. Theorically x should
1.145 quint 6089: be equal to / for the </style> end of style.
1.1 cvs 6090: The parameter doc gives the document tree that contains CSS information.
6091: The parameter docRef gives the document to which CSS are to be applied.
6092: This function uses the current css context or creates it. It's able
1.23 cvs 6093: to work on the given buffer or call GetNextChar to read the parsed
1.1 cvs 6094: file.
1.231 vatton 6095: The parameter url gives the URL of the parsed style sheet.
6096: The parameter numberOfLinesRead gives the number of lines already
1.86 cvs 6097: read in the file.
1.231 vatton 6098: The parameter withUndo indicates whether the changes made in the document
1.145 quint 6099: structure and content have to be registered in the Undo queue or not.
1.1 cvs 6100: ----------------------------------------------------------------------*/
1.133 vatton 6101: char ReadCSSRules (Document docRef, CSSInfoPtr css, char *buffer, char *url,
1.144 quint 6102: int numberOfLinesRead, ThotBool withUndo,
1.206 vatton 6103: Element link)
1.1 cvs 6104: {
1.6 cvs 6105: DisplayMode dispMode;
1.206 vatton 6106: CSSInfoPtr refcss = NULL;
6107: PInfoPtr pInfo;
1.271 vatton 6108: char c, *screentype;
1.138 vatton 6109: char *cssRule, *base, *saveDocURL, *ptr;
1.19 cvs 6110: int index;
1.1 cvs 6111: int CSSindex;
6112: int CSScomment;
6113: int import;
6114: int openRule;
1.93 vatton 6115: int newlines;
1.14 cvs 6116: ThotBool HTMLcomment;
1.102 vatton 6117: ThotBool toParse, eof, quoted;
1.234 vatton 6118: ThotBool ignore, media, page;
6119: ThotBool noRule, ignoreImport, fontface;
1.1 cvs 6120:
6121: CSScomment = MAX_CSS_LENGTH;
6122: HTMLcomment = FALSE;
6123: CSSindex = 0;
6124: toParse = FALSE;
6125: noRule = FALSE;
1.234 vatton 6126: media = FALSE;
1.88 cvs 6127: ignoreImport = FALSE;
1.234 vatton 6128: ignore = FALSE;
6129: page = FALSE;
6130: quoted = FALSE;
6131: fontface = FALSE;
1.1 cvs 6132: eof = FALSE;
6133: openRule = 0;
1.234 vatton 6134: import = MAX_CSS_LENGTH;
1.82 cvs 6135: c = SPACE;
1.1 cvs 6136: index = 0;
1.134 vatton 6137: base = NULL;
1.271 vatton 6138: screentype = TtaGetEnvString ("SCREEN_TYPE");
1.93 vatton 6139: /* number of new lines parsed */
6140: newlines = 0;
1.6 cvs 6141: /* avoid too many redisplay */
6142: dispMode = TtaGetDisplayMode (docRef);
6143: if (dispMode == DisplayImmediately)
6144: TtaSetDisplayMode (docRef, DeferredDisplay);
1.18 cvs 6145:
6146: /* look for the CSS context */
6147: if (css == NULL)
1.206 vatton 6148: css = SearchCSS (docRef, NULL, link, &pInfo);
1.207 vatton 6149: else
6150: pInfo = css->infos[docRef];
1.18 cvs 6151: if (css == NULL)
1.206 vatton 6152: {
6153: css = AddCSS (docRef, docRef, CSS_DOCUMENT_STYLE, CSS_ALL, NULL, NULL, link);
6154: pInfo = css->infos[docRef];
6155: }
6156: else if (pInfo == NULL)
6157: pInfo = AddInfoCSS (docRef, css, CSS_DOCUMENT_STYLE, CSS_ALL, link);
1.174 vatton 6158: /* look for the CSS descriptor that points to the extension schema */
6159: refcss = css;
1.224 vatton 6160: if (pInfo && pInfo->PiCategory == CSS_IMPORT)
1.173 cvs 6161: {
1.206 vatton 6162: while (refcss &&
6163: refcss->infos[docRef] && refcss->infos[docRef]->PiCategory == CSS_IMPORT)
1.174 vatton 6164: refcss = refcss->NextCSS;
1.206 vatton 6165: if (refcss)
6166: pInfo = refcss->infos[docRef];
1.173 cvs 6167: }
6168:
1.144 quint 6169: /* register parsed CSS file and the document to which CSS are to be applied*/
1.86 cvs 6170: ParsedDoc = docRef;
1.133 vatton 6171: if (url)
6172: DocURL = url;
1.86 cvs 6173: else
6174: /* the CSS source in within the document itself */
6175: DocURL = DocumentURLs[docRef];
6176: LineNumber = numberOfLinesRead + 1;
1.93 vatton 6177: NewLineSkipped = 0;
1.217 vatton 6178: newlines = 0;
1.82 cvs 6179: while (CSSindex < MAX_CSS_LENGTH && c != EOS && !eof)
6180: {
6181: c = buffer[index++];
6182: eof = (c == EOS);
6183: CSSbuffer[CSSindex] = c;
1.234 vatton 6184: if (CSScomment == MAX_CSS_LENGTH ||
1.246 vatton 6185: c == '*' || c == '/' || c == '<' || c == EOL)
1.82 cvs 6186: {
6187: /* we're not within a comment or we're parsing * or / */
6188: switch (c)
6189: {
6190: case '@': /* perhaps an import primitive */
1.234 vatton 6191: if (!fontface && !page && !quoted)
1.135 vatton 6192: import = CSSindex;
1.82 cvs 6193: break;
6194: case ';':
1.135 vatton 6195: if (!quoted && !media && import != MAX_CSS_LENGTH)
1.82 cvs 6196: {
6197: if (strncasecmp (&CSSbuffer[import+1], "import", 6))
6198: /* it's not an import */
6199: import = MAX_CSS_LENGTH;
6200: /* save the text */
6201: noRule = TRUE;
6202: }
6203: break;
6204: case '*':
1.135 vatton 6205: if (!quoted && CSScomment == MAX_CSS_LENGTH && CSSindex > 0 &&
1.82 cvs 6206: CSSbuffer[CSSindex - 1] == '/')
6207: /* start a comment */
6208: CSScomment = CSSindex - 1;
6209: break;
6210: case '/':
1.135 vatton 6211: if (!quoted && CSSindex > 1 && CSScomment != MAX_CSS_LENGTH &&
1.82 cvs 6212: CSSbuffer[CSSindex - 1] == '*')
6213: {
1.234 vatton 6214: /* close a comment and ignore its contents */
1.82 cvs 6215: CSSindex = CSScomment - 1; /* will be incremented later */
6216: CSScomment = MAX_CSS_LENGTH;
1.93 vatton 6217: /* clean up the buffer */
1.103 vatton 6218: if (newlines && CSSindex > 0)
6219: while (CSSindex > 0 &&
6220: (CSSbuffer[CSSindex] == SPACE ||
6221: CSSbuffer[CSSindex] == BSPACE ||
6222: CSSbuffer[CSSindex] == EOL ||
6223: CSSbuffer[CSSindex] == TAB ||
6224: CSSbuffer[CSSindex] == __CR__))
1.93 vatton 6225: {
6226: if ( CSSbuffer[CSSindex] == EOL)
6227: {
6228: LineNumber ++;
1.217 vatton 6229: newlines --;
1.93 vatton 6230: }
6231: CSSindex--;
6232: }
1.82 cvs 6233: }
1.234 vatton 6234: else if (!fontface && !page && !quoted &&
6235: CSScomment == MAX_CSS_LENGTH && CSSindex > 0 &&
1.82 cvs 6236: CSSbuffer[CSSindex - 1] == '<')
6237: {
6238: /* this is the closing tag ! */
6239: CSSindex -= 2; /* remove </ from the CSS string */
6240: noRule = TRUE;
6241: }
6242: break;
6243: case '<':
1.234 vatton 6244: if (!fontface && !page && !quoted &&
6245: CSScomment == MAX_CSS_LENGTH)
1.82 cvs 6246: {
6247: /* only if we're not parsing a comment */
6248: c = buffer[index++];
6249: eof = (c == EOS);
6250: if (c == '!')
6251: {
6252: /* CSS within an HTML comment */
6253: HTMLcomment = TRUE;
6254: CSSindex++;
6255: CSSbuffer[CSSindex] = c;
6256: }
6257: else if (c == EOS)
6258: CSSindex++;
6259: }
6260: break;
6261: case '-':
1.234 vatton 6262: if (!fontface && !page && !quoted &&
6263: CSSindex > 0 && CSSbuffer[CSSindex - 1] == '-' &&
1.82 cvs 6264: HTMLcomment)
6265: /* CSS within an HTML comment */
6266: noRule = TRUE;
6267: break;
6268: case '>':
1.234 vatton 6269: if (!fontface && !page && !quoted && HTMLcomment)
1.82 cvs 6270: noRule = TRUE;
6271: break;
6272: case ' ':
1.135 vatton 6273: if (!quoted && import != MAX_CSS_LENGTH && openRule == 0)
1.234 vatton 6274: media = !strncasecmp (&CSSbuffer[import+1], "media", 5);
1.82 cvs 6275: break;
6276: case '{':
1.135 vatton 6277: if (!quoted)
1.82 cvs 6278: {
1.135 vatton 6279: openRule++;
1.234 vatton 6280: if (import != MAX_CSS_LENGTH)
1.135 vatton 6281: {
1.234 vatton 6282: if (openRule == 1 && media)
6283: {
6284: /* is it the screen concerned? */
6285: CSSbuffer[CSSindex+1] = EOS;
6286: if (TtaIsPrinting ())
6287: base = strstr (&CSSbuffer[import], "print");
6288: else
1.271 vatton 6289: base = strstr (&CSSbuffer[import], screentype);
1.234 vatton 6290: if (base == NULL)
6291: base = strstr (&CSSbuffer[import], "all");
6292: if (base == NULL)
6293: ignore = TRUE;
1.235 vatton 6294: noRule = TRUE;
1.234 vatton 6295: }
6296: else if (!strncasecmp (&CSSbuffer[import+1], "page", 4))
1.235 vatton 6297: {
6298: page = TRUE;
6299: noRule = TRUE;
6300: }
1.234 vatton 6301: else if (!strncasecmp (&CSSbuffer[import+1], "font-face", 9))
1.235 vatton 6302: {
6303: fontface = TRUE;
6304: noRule = TRUE;
6305: }
1.135 vatton 6306: }
6307: }
6308: break;
6309: case '}':
6310: if (!quoted)
6311: {
6312: openRule--;
1.234 vatton 6313: if (page)
6314: {
6315: noRule = TRUE;
6316: page = FALSE; /* close the page section */
6317: }
6318: else if (fontface)
6319: {
6320: noRule = TRUE;
6321: fontface = FALSE; /* close the fontface section */
6322: }
6323: else if (openRule == 0 && import != MAX_CSS_LENGTH)
1.135 vatton 6324: {
6325: import = MAX_CSS_LENGTH;
6326: noRule = TRUE;
1.234 vatton 6327: ignore = FALSE;
1.135 vatton 6328: media = FALSE;
6329: }
1.82 cvs 6330: else
1.135 vatton 6331: toParse = TRUE;
1.82 cvs 6332: }
6333: break;
1.135 vatton 6334: case '"':
6335: if (quoted)
1.82 cvs 6336: {
1.135 vatton 6337: if (CSSbuffer[CSSindex - 1] != '\\')
6338: quoted = FALSE;
1.82 cvs 6339: }
6340: else
1.135 vatton 6341: quoted = TRUE;
1.82 cvs 6342: break;
6343: default:
1.86 cvs 6344: if (c == EOL)
1.93 vatton 6345: newlines++;
1.82 cvs 6346: break;
6347: }
6348: }
1.93 vatton 6349: else if (c == EOL)
1.217 vatton 6350: {
6351: LineNumber++;
6352: c = CR;
6353: }
1.234 vatton 6354:
1.82 cvs 6355: if (c != CR)
6356: CSSindex++;
6357:
6358: if (CSSindex >= MAX_CSS_LENGTH && CSScomment < MAX_CSS_LENGTH)
6359: /* we're still parsing a comment: remove the text comment */
6360: CSSindex = CSScomment;
6361:
6362: if (CSSindex >= MAX_CSS_LENGTH || toParse || noRule)
6363: {
6364: CSSbuffer[CSSindex] = EOS;
6365: /* parse a not empty string */
6366: if (CSSindex > 0)
6367: {
1.50 cvs 6368: /* apply CSS rule if it's not just a saving of text */
1.234 vatton 6369: if (!noRule && !ignore)
1.88 cvs 6370: {
6371: /* future import rules must be ignored */
6372: ignoreImport = TRUE;
1.217 vatton 6373: NewLineSkipped = 0;
1.210 vatton 6374: ParseStyleDeclaration (NULL, CSSbuffer, docRef, refcss,
1.231 vatton 6375: pInfo->PiLink, url, FALSE);
1.93 vatton 6376: LineNumber += newlines;
6377: newlines = 0;
1.88 cvs 6378: }
1.82 cvs 6379: else if (import != MAX_CSS_LENGTH &&
6380: !strncasecmp (&CSSbuffer[import+1], "import", 6))
6381: {
6382: /* import section */
6383: cssRule = &CSSbuffer[import+7];
6384: cssRule = TtaSkipBlanks (cssRule);
1.93 vatton 6385: /* save the current line number */
6386: newlines += LineNumber;
1.82 cvs 6387: if (!strncasecmp (cssRule, "url", 3))
6388: {
1.50 cvs 6389: cssRule = &cssRule[3];
1.82 cvs 6390: cssRule = TtaSkipBlanks (cssRule);
6391: if (*cssRule == '(')
6392: {
6393: cssRule++;
6394: cssRule = TtaSkipBlanks (cssRule);
1.102 vatton 6395: quoted = (*cssRule == '"' || *cssRule == '\'');
6396: if (quoted)
6397: cssRule++;
1.82 cvs 6398: base = cssRule;
6399: while (*cssRule != EOS && *cssRule != ')')
6400: cssRule++;
1.102 vatton 6401: if (quoted)
1.167 vatton 6402: {
6403: /* isolate the file name */
6404: cssRule[-1] = EOS;
6405: quoted = FALSE;
6406: }
1.216 vatton 6407: else
6408: {
6409: /* remove extra spaces */
6410: if (cssRule[-1] == SPACE)
6411: {
6412: *cssRule = SPACE;
6413: cssRule--;
6414: while (cssRule[-1] == SPACE)
6415: cssRule--;
6416: }
6417: }
1.160 vatton 6418: *cssRule = EOS;
1.82 cvs 6419: }
6420: }
1.87 cvs 6421: else if (*cssRule == '"')
6422: {
1.88 cvs 6423: /*
6424: Do we have to accept single quotes?
6425: Double quotes are acceted here.
6426: Escaped quotes are not handled. See function SkipQuotedString
6427: */
1.87 cvs 6428: cssRule++;
6429: cssRule = TtaSkipBlanks (cssRule);
6430: base = cssRule;
1.179 vatton 6431: while (*cssRule != EOS &&
6432: (*cssRule != '"' ||
1.180 vatton 6433: (*cssRule == '"' && cssRule[-1] == '\\')))
1.87 cvs 6434: cssRule++;
1.160 vatton 6435: /* isolate the file name */
6436: *cssRule = EOS;
1.133 vatton 6437: }
6438: /* check if a media is defined */
6439: cssRule++;
6440: cssRule = TtaSkipBlanks (cssRule);
6441: if (*cssRule != ';')
6442: {
6443: if (TtaIsPrinting ())
6444: ignoreImport = (strncasecmp (cssRule, "print", 5) &&
6445: strncasecmp (cssRule, "all", 3));
6446: else
6447: ignoreImport = (strncasecmp (cssRule, "screen", 6) &&
6448: strncasecmp (cssRule, "all", 3));
6449: }
6450: if (!ignoreImport)
6451: {
6452: /* save the displayed URL when an error is reported */
6453: saveDocURL = DocURL;
1.138 vatton 6454: ptr = TtaStrdup (base);
6455: /* get the CSS URI in UTF-8 */
1.285 cvs 6456: /*ptr = ReallocUTF8String (ptr, docRef);*/
1.206 vatton 6457: LoadStyleSheet (base, docRef, (Element) css, css,
6458: pInfo->PiMedia,
6459: pInfo->PiCategory == CSS_USER_STYLE);
1.133 vatton 6460: /* restore the displayed URL when an error is reported */
6461: DocURL = saveDocURL;
1.138 vatton 6462: TtaFreeMemory (ptr);
1.82 cvs 6463: }
1.93 vatton 6464: /* restore the number of lines */
6465: LineNumber = newlines;
6466: newlines = 0;
1.217 vatton 6467: NewLineSkipped = 0;
1.82 cvs 6468: import = MAX_CSS_LENGTH;
6469: }
1.234 vatton 6470: else
6471: {
6472: LineNumber += newlines;
6473: newlines = 0;
6474: }
1.82 cvs 6475: }
6476: toParse = FALSE;
6477: noRule = FALSE;
6478: CSSindex = 0;
1.50 cvs 6479: }
1.82 cvs 6480: }
1.6 cvs 6481: /* restore the display mode */
6482: if (dispMode == DisplayImmediately)
1.82 cvs 6483: TtaSetDisplayMode (docRef, dispMode);
1.86 cvs 6484:
6485: /* Prepare the context for style attributes */
6486: DocURL = DocumentURLs[docRef];
6487: LineNumber = -1;
1.1 cvs 6488: return (c);
6489: }
Webmaster