Annotation of Amaya/amaya/styleparser.c, revision 1.147
1.1 cvs 1: /*
2: *
1.113 quint 3: * (c) COPYRIGHT MIT and INRIA, 1996-2002
1.1 cvs 4: * Please first read the full copyright statement in file COPYRIGHT.
5: *
6: */
1.53 cvs 7:
1.1 cvs 8: /*
9: * Everything directly linked to the CSS syntax should now hopefully
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: {
27: Element el;
28: PSchema tsch;
29: union
30: {
31: PresentationContextBlock specific;
32: GenericContextBlock generic;
33: } context;
34: }
35: BackgroundImageCallbackBlock, *BackgroundImageCallbackPtr;
36:
37: #include "AHTURLTools_f.h"
38: #include "HTMLpresentation_f.h"
39: #include "HTMLimage_f.h"
40: #include "UIcss_f.h"
41: #include "css_f.h"
1.24 cvs 42: #include "fetchHTMLname_f.h"
1.91 cvs 43: #include "fetchXMLname_f.h"
1.1 cvs 44: #include "html2thot_f.h"
1.91 cvs 45: #include "init_f.h"
1.1 cvs 46: #include "styleparser_f.h"
47:
48: #define MAX_BUFFER_LENGTH 200
49: /*
50: * A PropertyParser is a function used to parse the
51: * description substring associated to a given style attribute
1.59 cvs 52: * e.g.: "red" for a color attribute or "12pt bold helvetica"
1.1 cvs 53: * for a font attribute.
54: */
1.79 cvs 55: typedef char *(*PropertyParser) (Element element,
1.56 cvs 56: PSchema tsch,
57: PresentationContext context,
1.79 cvs 58: char *cssRule,
1.56 cvs 59: CSSInfoPtr css,
60: ThotBool isHTML);
1.1 cvs 61:
62: /* Description of the set of CSS properties supported */
63: typedef struct CSSProperty
64: {
1.79 cvs 65: char *name;
1.25 cvs 66: PropertyParser parsing_function;
1.1 cvs 67: }
68: CSSProperty;
69:
70: struct unit_def
71: {
1.79 cvs 72: char *sign;
1.1 cvs 73: unsigned int unit;
74: };
75:
76: static struct unit_def CSSUnitNames[] =
77: {
1.82 cvs 78: {"pt", STYLE_UNIT_PT},
79: {"pc", STYLE_UNIT_PC},
80: {"in", STYLE_UNIT_IN},
81: {"cm", STYLE_UNIT_CM},
82: {"mm", STYLE_UNIT_MM},
83: {"em", STYLE_UNIT_EM},
84: {"px", STYLE_UNIT_PX},
85: {"ex", STYLE_UNIT_XHEIGHT},
86: {"%", STYLE_UNIT_PERCENT}
1.1 cvs 87: };
88:
89: #define NB_UNITS (sizeof(CSSUnitNames) / sizeof(struct unit_def))
1.86 cvs 90: static char *DocURL = NULL; /* The parsed CSS file */
91: static Document ParsedDoc; /* The document to which CSS are to be applied */
92: static int LineNumber = -1; /* The line where the error occurs */
1.93 vatton 93: static int NewLineSkipped = 0;
1.116 vatton 94: static ThotBool DoApply = TRUE;
1.1 cvs 95:
96: /*----------------------------------------------------------------------
97: SkipWord:
98: ----------------------------------------------------------------------*/
1.79 cvs 99: static char *SkipWord (char *ptr)
1.1 cvs 100: {
1.50 cvs 101: # ifdef _WINDOWS
102: /* iswalnum is supposed to be supported by the i18n veriosn of libc
103: use it when available */
1.82 cvs 104: while (iswalnum (*ptr) || *ptr == '-' || *ptr == '%')
1.50 cvs 105: # else /* !_WINDOWS */
1.82 cvs 106: while (isalnum((int)*ptr) || *ptr == '-' || *ptr == '%')
1.50 cvs 107: # endif /* !_WINDOWS */
108: ptr++;
1.1 cvs 109: return (ptr);
110: }
111:
112: /*----------------------------------------------------------------------
1.13 cvs 113: SkipBlanksAndComments:
114: ----------------------------------------------------------------------*/
1.82 cvs 115: char *SkipBlanksAndComments (char *ptr)
1.13 cvs 116: {
1.93 vatton 117: /* skip spaces */
118: while (*ptr == SPACE || *ptr == BSPACE || *ptr == EOL ||
119: *ptr == TAB || *ptr == __CR__)
120: {
121: if (*ptr == EOL)
122: /* increment the number of newline skipped */
123: NewLineSkipped++;
124: ptr++;
125: }
1.13 cvs 126: while (ptr[0] == '/' && ptr[1] == '*')
127: {
128: /* look for the end of the comment */
129: ptr = &ptr[2];
130: while (ptr[0] != EOS && (ptr[0] != '*' || ptr[1] != '/'))
131: ptr++;
132: if (ptr[0] != EOS)
133: ptr = &ptr[2];
1.93 vatton 134: /* skip spaces */
135: while (*ptr == SPACE || *ptr == BSPACE || *ptr == EOL ||
136: *ptr == TAB || *ptr == __CR__)
137: {
138: if (*ptr == EOL)
139: /* increment the number of newline skipped */
140: NewLineSkipped++;
141: ptr++;
142: }
1.13 cvs 143: }
144: return (ptr);
145: }
146:
1.49 cvs 147:
148: /*----------------------------------------------------------------------
1.1 cvs 149: SkipQuotedString:
150: ----------------------------------------------------------------------*/
1.79 cvs 151: static char *SkipQuotedString (char *ptr, char quote)
1.1 cvs 152: {
1.14 cvs 153: ThotBool stop;
1.1 cvs 154:
155: stop = FALSE;
156: while (!stop)
157: {
158: if (*ptr == quote)
159: {
160: ptr++;
161: stop = TRUE;
162: }
1.82 cvs 163: else if (*ptr == EOS)
1.1 cvs 164: stop = TRUE;
1.82 cvs 165: else if (*ptr == '\\')
1.1 cvs 166: /* escape character */
167: {
168: ptr++;
1.82 cvs 169: if ((*ptr >= '0' && *ptr <= '9') || (*ptr >= 'A' && *ptr <= 'F') ||
170: (*ptr >= 'a' && *ptr <= 'f'))
1.1 cvs 171: {
172: ptr++;
1.82 cvs 173: if ((*ptr >= '0' && *ptr <= '9') || (*ptr >= 'A' && *ptr <= 'F') ||
174: (*ptr >= 'a' && *ptr <= 'f'))
1.1 cvs 175: ptr++;
176: }
177: else
178: ptr++;
179: }
180: else
181: ptr++;
182: }
183: return (ptr);
184: }
185:
186: /*----------------------------------------------------------------------
1.86 cvs 187: CSSParseError
188: print the error message msg on stderr.
189: When the line is 0 ask to expat the current line number
190: ----------------------------------------------------------------------*/
191: static void CSSParseError (char *msg, char *value)
192: {
193: if (!TtaIsPrinting () && ParsedDoc > 0)
194: {
195: if (!ErrFile)
196: {
1.90 cvs 197: if (OpenParsingErrors (ParsedDoc) == FALSE)
1.86 cvs 198: return;
199: }
200:
1.133 vatton 201: if (DocURL)
1.86 cvs 202: {
1.94 cvs 203: fprintf (ErrFile, "*** Errors/warnings in %s\n", DocURL);
1.86 cvs 204: /* set to NULL as long as the CSS file doesn't change */
205: DocURL = NULL;
206: }
1.89 cvs 207: CSSErrorsFound = TRUE;
1.86 cvs 208: if (LineNumber < 0)
1.99 vatton 209: fprintf (ErrFile, " In Style attribute %s %s\"\n", msg, value);
1.86 cvs 210: else
1.99 vatton 211: fprintf (ErrFile, " line %d: %s %s\"\n", LineNumber + NewLineSkipped,
1.93 vatton 212: msg, value);
1.86 cvs 213: }
214: }
215:
1.89 cvs 216:
1.86 cvs 217: /*----------------------------------------------------------------------
218: SkipProperty:
219: ----------------------------------------------------------------------*/
220: static char *SkipProperty (char *ptr)
221: {
222: char *deb;
223: char c;
224:
225: deb = ptr;
1.135 vatton 226: while (*ptr != EOS && *ptr != ';' && *ptr != '}')
1.133 vatton 227: {
228: if (*ptr == '"' && (ptr == deb || ptr[-1] != '\\'))
229: {
230: /* skip to the end of the string "..." */
231: ptr++;
232: while (*ptr != '"' && ptr[-1] != '\\')
233: ptr++;
234: }
235: ptr++;
236: }
1.95 cvs 237: /* print the skipped property */
1.86 cvs 238: c = *ptr;
239: *ptr = EOS;
1.95 cvs 240: #ifdef CSS_WARNING
1.86 cvs 241: if (*deb != EOS)
1.99 vatton 242: CSSParseError ("CSS property ignored \"", deb);
1.95 cvs 243: #endif /* CSS_WARNING */
1.86 cvs 244: *ptr = c;
245: return (ptr);
246: }
247:
248: /*----------------------------------------------------------------------
1.1 cvs 249: SkipProperty:
250: ----------------------------------------------------------------------*/
1.99 vatton 251: static char *SkipValue (char *ptr, ThotBool error)
1.1 cvs 252: {
1.86 cvs 253: char *deb;
254: char c;
255:
256: deb = ptr;
1.135 vatton 257: while (*ptr != EOS && *ptr != ';' && *ptr != '}')
1.133 vatton 258: {
259: if (*ptr == '"' && (ptr == deb || ptr[-1] != '\\'))
260: {
261: /* skip to the end of the string "..." */
262: ptr++;
263: while (*ptr != '"' && ptr[-1] != '\\')
264: ptr++;
265: }
266: ptr++;
267: }
1.95 cvs 268: /* print the skipped property */
1.86 cvs 269: c = *ptr;
270: *ptr = EOS;
1.99 vatton 271: if (*deb != EOS && *deb != ',')
272: {
273: if (error)
274: CSSParseError ("invalid CSS value \"", deb);
1.95 cvs 275: #ifdef CSS_WARNING
1.99 vatton 276: else
277: CSSParseError ("CSS value ignored \"", deb);
1.95 cvs 278: #endif /* CSS_WARNING */
1.99 vatton 279: }
1.86 cvs 280: *ptr = c;
1.1 cvs 281: return (ptr);
282: }
283:
284: /*----------------------------------------------------------------------
1.64 cvs 285: ParseNumber:
286: parse a number and returns the corresponding value.
1.1 cvs 287: ----------------------------------------------------------------------*/
1.79 cvs 288: char *ParseNumber (char *cssRule, PresentationValue *pval)
1.1 cvs 289: {
290: int val = 0;
291: int minus = 0;
292: int valid = 0;
293: int f = 0;
1.14 cvs 294: ThotBool real = FALSE;
1.1 cvs 295:
296: pval->typed_data.unit = STYLE_UNIT_REL;
297: pval->typed_data.real = FALSE;
1.82 cvs 298: cssRule = SkipBlanksAndComments (cssRule);
299: if (*cssRule == '-')
1.1 cvs 300: {
301: minus = 1;
302: cssRule++;
1.82 cvs 303: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 304: }
305:
1.82 cvs 306: if (*cssRule == '+')
1.1 cvs 307: {
308: cssRule++;
1.82 cvs 309: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 310: }
311:
1.82 cvs 312: while ((*cssRule >= '0') && (*cssRule <= '9'))
1.1 cvs 313: {
314: val *= 10;
1.82 cvs 315: val += *cssRule - '0';
1.1 cvs 316: cssRule++;
317: valid = 1;
318: }
319:
1.82 cvs 320: if (*cssRule == '.')
1.1 cvs 321: {
322: real = TRUE;
323: f = val;
324: val = 0;
325: cssRule++;
326: /* keep only 3 digits */
1.82 cvs 327: if (*cssRule >= '0' && *cssRule <= '9')
1.1 cvs 328: {
1.82 cvs 329: val = (*cssRule - '0') * 100;
1.1 cvs 330: cssRule++;
1.82 cvs 331: if (*cssRule >= '0' && *cssRule <= '9')
1.1 cvs 332: {
1.82 cvs 333: val += (*cssRule - '0') * 10;
1.1 cvs 334: cssRule++;
1.82 cvs 335: if ((*cssRule >= '0') && (*cssRule <= '9'))
1.1 cvs 336: {
1.82 cvs 337: val += *cssRule - '0';
1.1 cvs 338: cssRule++;
339: }
340: }
341:
1.82 cvs 342: while (*cssRule >= '0' && *cssRule <= '9')
1.1 cvs 343: cssRule++;
344: valid = 1;
345: }
346: }
347:
348: if (!valid)
349: {
350: pval->typed_data.unit = STYLE_UNIT_INVALID;
351: pval->typed_data.value = 0;
352: }
353: else
354: {
355: pval->typed_data.real = real;
356: if (real)
357: {
358: if (minus)
359: pval->typed_data.value = -(f * 1000 + val);
360: else
361: pval->typed_data.value = f * 1000 + val;
362: }
363: else
364: {
365: if (minus)
366: pval->typed_data.value = -val;
367: else
368: pval->typed_data.value = val;
369: }
1.64 cvs 370: }
371: return (cssRule);
372: }
373:
374: /*----------------------------------------------------------------------
375: ParseCSSUnit:
376: parse a CSS Unit substring and returns the corresponding
377: value and its unit.
378: ----------------------------------------------------------------------*/
1.82 cvs 379: char *ParseCSSUnit (char *cssRule, PresentationValue *pval)
1.64 cvs 380: {
381: unsigned int uni;
382:
383: pval->typed_data.unit = STYLE_UNIT_REL;
384: cssRule = ParseNumber (cssRule, pval);
385: if (pval->typed_data.unit == STYLE_UNIT_INVALID)
386: cssRule = SkipWord (cssRule);
387: else
388: {
1.82 cvs 389: cssRule = SkipBlanksAndComments (cssRule);
1.64 cvs 390: for (uni = 0; uni < NB_UNITS; uni++)
391: {
1.82 cvs 392: if (!strncasecmp (CSSUnitNames[uni].sign, cssRule,
393: strlen (CSSUnitNames[uni].sign)))
1.64 cvs 394: {
395: pval->typed_data.unit = CSSUnitNames[uni].unit;
1.82 cvs 396: return (cssRule + strlen (CSSUnitNames[uni].sign));
1.64 cvs 397: }
398: }
399: /* not in the list of predefined units */
400: pval->typed_data.unit = STYLE_UNIT_PX;
1.1 cvs 401: }
402: return (cssRule);
403: }
404:
1.43 cvs 405: /*----------------------------------------------------------------------
406: ParseBorderValue
407: ----------------------------------------------------------------------*/
1.79 cvs 408: static char *ParseBorderValue (char *cssRule, PresentationValue *border)
1.43 cvs 409: {
410: /* first parse the attribute string */
411: border->typed_data.value = 0;
1.44 cvs 412: border->typed_data.unit = STYLE_UNIT_INVALID;
1.43 cvs 413: border->typed_data.real = FALSE;
1.82 cvs 414: if (!strncasecmp (cssRule, "thin", 4))
1.43 cvs 415: {
1.44 cvs 416: border->typed_data.unit = STYLE_UNIT_PX;
1.43 cvs 417: border->typed_data.value = 1;
418: cssRule = SkipWord (cssRule);
419: }
1.82 cvs 420: else if (!strncasecmp (cssRule, "medium", 6))
1.43 cvs 421: {
1.44 cvs 422: border->typed_data.unit = STYLE_UNIT_PX;
1.43 cvs 423: border->typed_data.value = 3;
424: cssRule = SkipWord (cssRule);
425: }
1.82 cvs 426: else if (!strncasecmp (cssRule, "thick", 5))
1.43 cvs 427: {
1.44 cvs 428: border->typed_data.unit = STYLE_UNIT_PX;
1.43 cvs 429: border->typed_data.value = 5;
430: cssRule = SkipWord (cssRule);
431: }
1.110 vatton 432: else if (isdigit (*cssRule) || *cssRule == '.')
1.43 cvs 433: cssRule = ParseCSSUnit (cssRule, border);
434: return (cssRule);
435: }
436:
437: /*----------------------------------------------------------------------
438: ParseBorderStyle
439: ----------------------------------------------------------------------*/
1.79 cvs 440: static char *ParseBorderStyle (char *cssRule, PresentationValue *border)
1.43 cvs 441: {
442: /* first parse the attribute string */
443: border->typed_data.value = 0;
444: border->typed_data.unit = STYLE_UNIT_PX;
445: border->typed_data.real = FALSE;
1.82 cvs 446: if (!strncasecmp (cssRule, "none", 4))
1.43 cvs 447: border->typed_data.value = STYLE_BORDERNONE;
1.82 cvs 448: else if (!strncasecmp (cssRule, "hidden", 6))
1.43 cvs 449: border->typed_data.value = STYLE_BORDERHIDDEN;
1.82 cvs 450: else if (!strncasecmp (cssRule, "dotted", 6))
1.43 cvs 451: border->typed_data.value = STYLE_BORDERDOTTED;
1.82 cvs 452: else if (!strncasecmp (cssRule, "dashed", 6))
1.43 cvs 453: border->typed_data.value = STYLE_BORDERDASHED;
1.82 cvs 454: else if (!strncasecmp (cssRule, "solid", 5))
1.43 cvs 455: border->typed_data.value = STYLE_BORDERSOLID;
1.82 cvs 456: else if (!strncasecmp (cssRule, "double", 6))
1.43 cvs 457: border->typed_data.value = STYLE_BORDERDOUBLE;
1.82 cvs 458: else if (!strncasecmp (cssRule, "groove", 6))
1.43 cvs 459: border->typed_data.value = STYLE_BORDERGROOVE;
1.82 cvs 460: else if (!strncasecmp (cssRule, "ridge", 5))
1.43 cvs 461: border->typed_data.value = STYLE_BORDERRIDGE;
1.82 cvs 462: else if (!strncasecmp (cssRule, "inset", 5))
1.43 cvs 463: border->typed_data.value = STYLE_BORDERINSET;
1.82 cvs 464: else if (!strncasecmp (cssRule, "outset", 6))
1.43 cvs 465: border->typed_data.value = STYLE_BORDEROUTSET;
466: else
1.44 cvs 467: {
468: /* invalid style */
469: border->typed_data.unit = STYLE_UNIT_INVALID;
470: return (cssRule);
471: }
1.43 cvs 472: /* the value is parsed now */
473: cssRule = SkipWord (cssRule);
474: return (cssRule);
475: }
476:
477: /*----------------------------------------------------------------------
1.59 cvs 478: ParseCSSColor: parse a CSS color attribute string
1.43 cvs 479: we expect the input string describing the attribute to be
480: either a color name, a 3 tuple or an hexadecimal encoding.
481: The color used will be approximed from the current color
482: table
483: ----------------------------------------------------------------------*/
1.79 cvs 484: static char *ParseCSSColor (char *cssRule, PresentationValue * val)
1.43 cvs 485: {
1.79 cvs 486: char *ptr;
1.43 cvs 487: unsigned short redval = (unsigned short) -1;
488: unsigned short greenval = 0; /* composant of each RGB */
489: unsigned short blueval = 0; /* default to red if unknown ! */
490: int best = 0; /* best color in list found */
491:
1.82 cvs 492: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 493: val->typed_data.unit = STYLE_UNIT_INVALID;
494: val->typed_data.real = FALSE;
495: val->typed_data.value = 0;
1.57 cvs 496: ptr = TtaGiveRGB (cssRule, &redval, &greenval, &blueval);
1.135 vatton 497: if (!strncasecmp (cssRule, "inherit", 7))
498: {
499: cssRule = SkipWord (cssRule);
500: return (cssRule);
501: }
1.57 cvs 502: if (ptr == cssRule)
1.43 cvs 503: {
1.99 vatton 504: cssRule = SkipValue (cssRule, TRUE);
1.43 cvs 505: val->typed_data.value = 0;
506: val->typed_data.unit = STYLE_UNIT_INVALID;
507: }
508: else
509: {
510: best = TtaGetThotColor (redval, greenval, blueval);
511: val->typed_data.value = best;
512: val->typed_data.unit = STYLE_UNIT_REL;
1.57 cvs 513: cssRule = ptr;
1.43 cvs 514: }
515: val->typed_data.real = FALSE;
1.65 cvs 516: return (cssRule);
1.43 cvs 517: }
1.1 cvs 518:
519: /*----------------------------------------------------------------------
1.117 vatton 520: CheckImportantRule updates the field important of the context.
521: ----------------------------------------------------------------------*/
522: static char *CheckImportantRule (char *cssRule, PresentationContext context)
523: {
524: cssRule = SkipBlanksAndComments (cssRule);
1.120 vatton 525: if (*cssRule != '!')
526: context->important = FALSE;
527: else
1.117 vatton 528: {
1.120 vatton 529: cssRule++;
530: cssRule = SkipBlanksAndComments (cssRule);
531: if (!strncasecmp (cssRule, "important", 9))
532: {
533: context->important = TRUE;
534: cssRule += 9;
535: }
536: else
537: context->important = FALSE;
1.117 vatton 538: }
539: return (cssRule);
540: }
541:
542: /*----------------------------------------------------------------------
1.59 cvs 543: ParseCSSBorderTopWidth: parse a CSS BorderTopWidth
1.1 cvs 544: attribute string.
545: ----------------------------------------------------------------------*/
1.79 cvs 546: static char *ParseCSSBorderTopWidth (Element element, PSchema tsch,
547: PresentationContext context,
548: char *cssRule, CSSInfoPtr css,
549: ThotBool isHTML)
1.1 cvs 550: {
1.41 cvs 551: PresentationValue border;
552:
1.82 cvs 553: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 554: cssRule = ParseBorderValue (cssRule, &border);
1.116 vatton 555: if (border.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.44 cvs 556: {
1.117 vatton 557: /* check if it's an important rule */
558: if (tsch)
559: cssRule = CheckImportantRule (cssRule, context);
1.44 cvs 560: TtaSetStylePresentation (PRBorderTopWidth, element, tsch, context, border);
561: border.typed_data.value = 1;
562: border.typed_data.unit = STYLE_UNIT_REL;
563: }
1.1 cvs 564: return (cssRule);
565: }
566:
567: /*----------------------------------------------------------------------
1.59 cvs 568: ParseCSSBorderBottomWidth: parse a CSS BorderBottomWidth
1.1 cvs 569: attribute string.
570: ----------------------------------------------------------------------*/
1.79 cvs 571: static char *ParseCSSBorderBottomWidth (Element element, PSchema tsch,
572: PresentationContext context,
573: char *cssRule, CSSInfoPtr css,
574: ThotBool isHTML)
1.1 cvs 575: {
1.41 cvs 576: PresentationValue border;
577:
1.82 cvs 578: cssRule = SkipBlanksAndComments (cssRule);
1.41 cvs 579: /* first parse the attribute string */
1.43 cvs 580: cssRule = ParseBorderValue (cssRule, &border);
1.116 vatton 581: if (border.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.44 cvs 582: {
1.117 vatton 583: /* check if it's an important rule */
584: if (tsch)
585: cssRule = CheckImportantRule (cssRule, context);
1.44 cvs 586: TtaSetStylePresentation (PRBorderBottomWidth, element, tsch, context, border);
587: border.typed_data.value = 1;
588: border.typed_data.unit = STYLE_UNIT_REL;
589: }
1.1 cvs 590: return (cssRule);
591: }
592:
593: /*----------------------------------------------------------------------
1.59 cvs 594: ParseCSSBorderLeftWidth: parse a CSS BorderLeftWidth
1.1 cvs 595: attribute string.
596: ----------------------------------------------------------------------*/
1.79 cvs 597: static char *ParseCSSBorderLeftWidth (Element element, PSchema tsch,
598: PresentationContext context,
599: char *cssRule, CSSInfoPtr css,
600: ThotBool isHTML)
1.1 cvs 601: {
1.41 cvs 602: PresentationValue border;
603:
1.82 cvs 604: cssRule = SkipBlanksAndComments (cssRule);
1.41 cvs 605: /* first parse the attribute string */
1.43 cvs 606: cssRule = ParseBorderValue (cssRule, &border);
1.116 vatton 607: if (border.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.44 cvs 608: {
1.117 vatton 609: /* check if it's an important rule */
610: if (tsch)
611: cssRule = CheckImportantRule (cssRule, context);
1.44 cvs 612: TtaSetStylePresentation (PRBorderLeftWidth, element, tsch, context, border);
613: border.typed_data.value = 1;
614: border.typed_data.unit = STYLE_UNIT_REL;
615: }
1.1 cvs 616: return (cssRule);
617: }
618:
619: /*----------------------------------------------------------------------
1.59 cvs 620: ParseCSSBorderRightWidth: parse a CSS BorderRightWidth
1.1 cvs 621: attribute string.
622: ----------------------------------------------------------------------*/
1.79 cvs 623: static char *ParseCSSBorderRightWidth (Element element, PSchema tsch,
624: PresentationContext context,
625: char *cssRule, CSSInfoPtr css,
626: ThotBool isHTML)
1.1 cvs 627: {
1.41 cvs 628: PresentationValue border;
629:
1.82 cvs 630: cssRule = SkipBlanksAndComments (cssRule);
1.41 cvs 631: /* first parse the attribute string */
1.43 cvs 632: cssRule = ParseBorderValue (cssRule, &border);
1.116 vatton 633: if (border.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.44 cvs 634: {
1.117 vatton 635: /* check if it's an important rule */
636: if (tsch)
637: cssRule = CheckImportantRule (cssRule, context);
1.44 cvs 638: TtaSetStylePresentation (PRBorderRightWidth, element, tsch, context, border);
639: border.typed_data.value = 1;
640: border.typed_data.unit = STYLE_UNIT_REL;
641: }
1.1 cvs 642: return (cssRule);
643: }
644:
645: /*----------------------------------------------------------------------
1.59 cvs 646: ParseCSSBorderWidth: parse a CSS BorderWidth
1.1 cvs 647: attribute string.
648: ----------------------------------------------------------------------*/
1.79 cvs 649: static char *ParseCSSBorderWidth (Element element, PSchema tsch,
650: PresentationContext context,
651: char *cssRule, CSSInfoPtr css,
652: ThotBool isHTML)
1.1 cvs 653: {
1.79 cvs 654: char *ptrT, *ptrR, *ptrB, *ptrL;
1.93 vatton 655: int skippedNL;
1.41 cvs 656:
1.82 cvs 657: ptrT = SkipBlanksAndComments (cssRule);
1.42 cvs 658: /* First parse Border-Top */
659: ptrR = ParseCSSBorderTopWidth (element, tsch, context, ptrT, css, isHTML);
1.82 cvs 660: ptrR = SkipBlanksAndComments (ptrR);
661: if (*ptrR == ';' || *ptrR == EOS || *ptrR == ',')
1.42 cvs 662: {
1.93 vatton 663: skippedNL = NewLineSkipped;
1.42 cvs 664: cssRule = ptrR;
665: /* apply the Border-Top to all */
666: ptrR = ParseCSSBorderRightWidth (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 667: NewLineSkipped = skippedNL;
1.42 cvs 668: ptrR = ParseCSSBorderBottomWidth (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 669: NewLineSkipped = skippedNL;
1.42 cvs 670: ptrR = ParseCSSBorderLeftWidth (element, tsch, context, ptrT, css, isHTML);
671: }
672: else
673: {
674: /* parse Border-Right */
675: ptrB = ParseCSSBorderRightWidth (element, tsch, context, ptrR, css, isHTML);
1.82 cvs 676: ptrB = SkipBlanksAndComments (ptrB);
677: if (*ptrB == ';' || *ptrB == EOS || *ptrB == ',')
1.42 cvs 678: {
1.93 vatton 679: skippedNL = NewLineSkipped;
1.42 cvs 680: cssRule = ptrB;
681: /* apply the Border-Top to Border-Bottom */
682: ptrB = ParseCSSBorderBottomWidth (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 683: NewLineSkipped = skippedNL;
1.42 cvs 684: /* apply the Border-Right to Border-Left */
685: ptrB = ParseCSSBorderLeftWidth (element, tsch, context, ptrR, css, isHTML);
686: }
687: else
688: {
689: /* parse Border-Bottom */
690: ptrL = ParseCSSBorderBottomWidth (element, tsch, context, ptrB, css, isHTML);
1.82 cvs 691: ptrL = SkipBlanksAndComments (ptrL);
692: if (*ptrL == ';' || *ptrL == EOS || *ptrL == ',')
1.42 cvs 693: {
694: cssRule = ptrL;
695: /* apply the Border-Right to Border-Left */
696: ptrL = ParseCSSBorderLeftWidth (element, tsch, context, ptrR, css, isHTML);
697: }
698: else
699: /* parse Border-Left */
700: cssRule = ParseCSSBorderLeftWidth (element, tsch, context, ptrL, css, isHTML);
1.82 cvs 701: cssRule = SkipBlanksAndComments (cssRule);
1.42 cvs 702: }
703: }
1.1 cvs 704: return (cssRule);
705: }
706:
707: /*----------------------------------------------------------------------
1.59 cvs 708: ParseCSSBorderColorTop: parse a CSS BorderColorTop
1.1 cvs 709: attribute string.
710: ----------------------------------------------------------------------*/
1.79 cvs 711: static char *ParseCSSBorderColorTop (Element element, PSchema tsch,
712: PresentationContext context,
713: char *cssRule, CSSInfoPtr css,
714: ThotBool isHTML)
1.1 cvs 715: {
1.117 vatton 716: PresentationValue best;
1.43 cvs 717:
1.117 vatton 718: cssRule = ParseCSSColor (cssRule, &best);
719: if (best.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
720: {
721: /* check if it's an important rule */
722: if (tsch)
723: cssRule = CheckImportantRule (cssRule, context);
724: /* install the new presentation */
725: TtaSetStylePresentation (PRBorderTopColor, element, tsch, context, best);
726: }
727: return (cssRule);
1.1 cvs 728: }
729:
730: /*----------------------------------------------------------------------
1.59 cvs 731: ParseCSSBorderColorLeft: parse a CSS BorderColorLeft
1.42 cvs 732: attribute string.
733: ----------------------------------------------------------------------*/
1.79 cvs 734: static char *ParseCSSBorderColorLeft (Element element, PSchema tsch,
735: PresentationContext context,
736: char *cssRule, CSSInfoPtr css,
737: ThotBool isHTML)
1.42 cvs 738: {
1.117 vatton 739: PresentationValue best;
740:
741: cssRule = ParseCSSColor (cssRule, &best);
742: if (best.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
743: {
744: /* check if it's an important rule */
745: if (tsch)
746: cssRule = CheckImportantRule (cssRule, context);
747: /* install the new presentation */
748: TtaSetStylePresentation (PRBorderLeftColor, element, tsch, context, best);
749: }
750: return (cssRule);
1.42 cvs 751: }
752:
753: /*----------------------------------------------------------------------
1.59 cvs 754: ParseCSSBorderColorBottom: parse a CSS BorderColorBottom
1.42 cvs 755: attribute string.
756: ----------------------------------------------------------------------*/
1.79 cvs 757: static char *ParseCSSBorderColorBottom (Element element, PSchema tsch,
758: PresentationContext context,
759: char *cssRule, CSSInfoPtr css,
760: ThotBool isHTML)
1.42 cvs 761: {
1.117 vatton 762: PresentationValue best;
1.43 cvs 763:
1.117 vatton 764: cssRule = ParseCSSColor (cssRule, &best);
765: if (best.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
766: {
767: /* check if it's an important rule */
768: if (tsch)
769: cssRule = CheckImportantRule (cssRule, context);
770: /* install the new presentation */
771: TtaSetStylePresentation (PRBorderBottomColor, element, tsch, context, best);
772: }
1.65 cvs 773: return (cssRule);
1.42 cvs 774: }
775:
776: /*----------------------------------------------------------------------
1.59 cvs 777: ParseCSSBorderColorRight: parse a CSS BorderColorRight
1.1 cvs 778: attribute string.
779: ----------------------------------------------------------------------*/
1.79 cvs 780: static char *ParseCSSBorderColorRight (Element element, PSchema tsch,
781: PresentationContext context,
782: char *cssRule, CSSInfoPtr css,
783: ThotBool isHTML)
1.1 cvs 784: {
1.117 vatton 785: PresentationValue best;
1.43 cvs 786:
1.117 vatton 787: cssRule = ParseCSSColor (cssRule, &best);
788: if (best.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
789: {
790: /* check if it's an important rule */
791: if (tsch)
792: cssRule = CheckImportantRule (cssRule, context);
793: /* install the new presentation */
794: TtaSetStylePresentation (PRBorderRightColor, element, tsch, context, best);
795: }
796: return (cssRule);
1.1 cvs 797: }
798:
799: /*----------------------------------------------------------------------
1.59 cvs 800: ParseCSSBorderColor: parse a CSS border-color
1.42 cvs 801: attribute string.
802: ----------------------------------------------------------------------*/
1.79 cvs 803: static char *ParseCSSBorderColor (Element element, PSchema tsch,
804: PresentationContext context,
805: char *cssRule, CSSInfoPtr css,
806: ThotBool isHTML)
1.42 cvs 807: {
1.79 cvs 808: char *ptrT, *ptrR, *ptrB, *ptrL;
1.93 vatton 809: int skippedNL;
1.42 cvs 810:
1.82 cvs 811: ptrT = SkipBlanksAndComments (cssRule);
1.42 cvs 812: /* First parse Border-Top */
1.43 cvs 813: ptrR = ParseCSSBorderColorTop (element, tsch, context, ptrT, css, isHTML);
1.82 cvs 814: ptrR = SkipBlanksAndComments (ptrR);
815: if (*ptrR == ';' || *ptrR == EOS || *ptrR == ',')
1.42 cvs 816: {
1.93 vatton 817: skippedNL = NewLineSkipped;
1.42 cvs 818: cssRule = ptrR;
819: /* apply the Border-Top to all */
1.43 cvs 820: ptrR = ParseCSSBorderColorRight (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 821: NewLineSkipped = skippedNL;
1.43 cvs 822: ptrR = ParseCSSBorderColorBottom (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 823: NewLineSkipped = skippedNL;
1.43 cvs 824: ptrR = ParseCSSBorderColorLeft (element, tsch, context, ptrT, css, isHTML);
1.42 cvs 825: }
826: else
827: {
828: /* parse Border-Right */
1.43 cvs 829: ptrB = ParseCSSBorderColorRight (element, tsch, context, ptrR, css, isHTML);
1.82 cvs 830: ptrB = SkipBlanksAndComments (ptrB);
831: if (*ptrB == ';' || *ptrB == EOS || *ptrB == ',')
1.42 cvs 832: {
1.93 vatton 833: skippedNL = NewLineSkipped;
1.42 cvs 834: cssRule = ptrB;
835: /* apply the Border-Top to Border-Bottom */
1.43 cvs 836: ptrB = ParseCSSBorderColorBottom (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 837: NewLineSkipped = skippedNL;
1.42 cvs 838: /* apply the Border-Right to Border-Left */
1.43 cvs 839: ptrB = ParseCSSBorderColorLeft (element, tsch, context, ptrR, css, isHTML);
1.42 cvs 840: }
841: else
842: {
1.93 vatton 843: skippedNL = NewLineSkipped;
1.42 cvs 844: /* parse Border-Bottom */
1.43 cvs 845: ptrL = ParseCSSBorderColorBottom (element, tsch, context, ptrB, css, isHTML);
1.93 vatton 846: NewLineSkipped = skippedNL;
1.82 cvs 847: ptrL = SkipBlanksAndComments (ptrL);
848: if (*ptrL == ';' || *ptrL == EOS || *ptrL == ',')
1.42 cvs 849: {
850: cssRule = ptrL;
851: /* apply the Border-Right to Border-Left */
1.43 cvs 852: ptrL = ParseCSSBorderColorLeft (element, tsch, context, ptrR, css, isHTML);
1.42 cvs 853: }
854: else
855: /* parse Border-Left */
1.43 cvs 856: cssRule = ParseCSSBorderColorLeft (element, tsch, context, ptrL, css, isHTML);
1.82 cvs 857: cssRule = SkipBlanksAndComments (cssRule);
1.42 cvs 858: }
859: }
860: return (cssRule);
861: }
862:
863: /*----------------------------------------------------------------------
1.59 cvs 864: ParseCSSBorderStyleTop: parse a CSS BorderStyleTop
1.42 cvs 865: attribute string.
866: ----------------------------------------------------------------------*/
1.79 cvs 867: static char *ParseCSSBorderStyleTop (Element element, PSchema tsch,
868: PresentationContext context,
869: char *cssRule, CSSInfoPtr css,
870: ThotBool isHTML)
1.42 cvs 871: {
1.43 cvs 872: PresentationValue border;
873:
1.82 cvs 874: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 875: cssRule = ParseBorderStyle (cssRule, &border);
1.116 vatton 876: if (border.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.117 vatton 877: {
878: /* check if it's an important rule */
879: if (tsch)
880: cssRule = CheckImportantRule (cssRule, context);
881: TtaSetStylePresentation (PRBorderTopStyle, element, tsch, context, border);
882: }
1.42 cvs 883: return (cssRule);
884: }
885:
886: /*----------------------------------------------------------------------
1.59 cvs 887: ParseCSSBorderStyleLeft: parse a CSS BorderStyleLeft
1.42 cvs 888: attribute string.
889: ----------------------------------------------------------------------*/
1.79 cvs 890: static char *ParseCSSBorderStyleLeft (Element element, PSchema tsch,
891: PresentationContext context,
892: char *cssRule, CSSInfoPtr css,
893: ThotBool isHTML)
1.42 cvs 894: {
1.43 cvs 895: PresentationValue border;
896:
1.82 cvs 897: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 898: cssRule = ParseBorderStyle (cssRule, &border);
1.116 vatton 899: if (border.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.117 vatton 900: {
901: /* check if it's an important rule */
902: if (tsch)
903: cssRule = CheckImportantRule (cssRule, context);
904: TtaSetStylePresentation (PRBorderLeftStyle, element, tsch, context, border);
905: }
1.42 cvs 906: return (cssRule);
907: }
908:
909: /*----------------------------------------------------------------------
1.59 cvs 910: ParseCSSBorderStyleBottom: parse a CSS BorderStyleBottom
1.1 cvs 911: attribute string.
912: ----------------------------------------------------------------------*/
1.79 cvs 913: static char *ParseCSSBorderStyleBottom (Element element, PSchema tsch,
914: PresentationContext context,
915: char *cssRule, CSSInfoPtr css,
916: ThotBool isHTML)
1.1 cvs 917: {
1.43 cvs 918: PresentationValue border;
919:
1.82 cvs 920: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 921: cssRule = ParseBorderStyle (cssRule, &border);
1.116 vatton 922: if (border.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.117 vatton 923: {
924: /* check if it's an important rule */
925: if (tsch)
926: cssRule = CheckImportantRule (cssRule, context);
927: TtaSetStylePresentation (PRBorderBottomStyle, element, tsch, context, border);
928: }
1.1 cvs 929: return (cssRule);
930: }
931:
932: /*----------------------------------------------------------------------
1.59 cvs 933: ParseCSSBorderStyleRight: parse a CSS BorderStyleRight
1.1 cvs 934: attribute string.
935: ----------------------------------------------------------------------*/
1.79 cvs 936: static char *ParseCSSBorderStyleRight (Element element, PSchema tsch,
937: PresentationContext context,
938: char *cssRule, CSSInfoPtr css,
939: ThotBool isHTML)
1.1 cvs 940: {
1.43 cvs 941: PresentationValue border;
942:
1.82 cvs 943: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 944: cssRule = ParseBorderStyle (cssRule, &border);
1.116 vatton 945: if (border.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.117 vatton 946: {
947: /* check if it's an important rule */
948: if (tsch)
949: cssRule = CheckImportantRule (cssRule, context);
950: TtaSetStylePresentation (PRBorderRightStyle, element, tsch, context, border);
951: }
1.1 cvs 952: return (cssRule);
953: }
954:
955: /*----------------------------------------------------------------------
1.59 cvs 956: ParseCSSBorderStyleStyle: parse a CSS border-style
1.1 cvs 957: attribute string.
958: ----------------------------------------------------------------------*/
1.79 cvs 959: static char *ParseCSSBorderStyle (Element element, PSchema tsch,
960: PresentationContext context,
961: char *cssRule, CSSInfoPtr css,
962: ThotBool isHTML)
1.1 cvs 963: {
1.79 cvs 964: char *ptrT, *ptrR, *ptrB, *ptrL;
1.93 vatton 965: int skippedNL;
1.42 cvs 966:
1.82 cvs 967: ptrT = SkipBlanksAndComments (cssRule);
1.42 cvs 968: /* First parse Border-Top */
1.43 cvs 969: ptrR = ParseCSSBorderStyleTop (element, tsch, context, ptrT, css, isHTML);
1.82 cvs 970: ptrR = SkipBlanksAndComments (ptrR);
971: if (*ptrR == ';' || *ptrR == EOS || *ptrR == ',')
1.42 cvs 972: {
1.93 vatton 973: skippedNL = NewLineSkipped;
1.42 cvs 974: cssRule = ptrR;
975: /* apply the Border-Top to all */
1.43 cvs 976: ptrR = ParseCSSBorderStyleRight (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 977: NewLineSkipped = skippedNL;
1.43 cvs 978: ptrR = ParseCSSBorderStyleBottom (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 979: NewLineSkipped = skippedNL;
1.43 cvs 980: ptrR = ParseCSSBorderStyleLeft (element, tsch, context, ptrT, css, isHTML);
1.42 cvs 981: }
982: else
983: {
984: /* parse Border-Right */
1.43 cvs 985: ptrB = ParseCSSBorderStyleRight (element, tsch, context, ptrR, css, isHTML);
1.82 cvs 986: ptrB = SkipBlanksAndComments (ptrB);
987: if (*ptrB == ';' || *ptrB == EOS || *ptrB == ',')
1.42 cvs 988: {
1.93 vatton 989: skippedNL = NewLineSkipped;
1.42 cvs 990: cssRule = ptrB;
991: /* apply the Border-Top to Border-Bottom */
1.43 cvs 992: ptrB = ParseCSSBorderStyleBottom (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 993: NewLineSkipped = skippedNL;
1.42 cvs 994: /* apply the Border-Right to Border-Left */
1.43 cvs 995: ptrB = ParseCSSBorderStyleLeft (element, tsch, context, ptrR, css, isHTML);
1.42 cvs 996: }
997: else
998: {
999: /* parse Border-Bottom */
1.43 cvs 1000: ptrL = ParseCSSBorderStyleBottom (element, tsch, context, ptrB, css, isHTML);
1.82 cvs 1001: ptrL = SkipBlanksAndComments (ptrL);
1002: if (*ptrL == ';' || *ptrL == EOS || *ptrL == ',')
1.42 cvs 1003: {
1004: cssRule = ptrL;
1005: /* apply the Border-Right to Border-Left */
1.43 cvs 1006: ptrL = ParseCSSBorderStyleLeft (element, tsch, context, ptrR, css, isHTML);
1.42 cvs 1007: }
1008: else
1009: /* parse Border-Left */
1.43 cvs 1010: cssRule = ParseCSSBorderStyleLeft (element, tsch, context, ptrL, css, isHTML);
1.82 cvs 1011: cssRule = SkipBlanksAndComments (cssRule);
1.42 cvs 1012: }
1013: }
1014: return (cssRule);
1015: }
1016:
1017: /*----------------------------------------------------------------------
1.59 cvs 1018: ParseCSSBorderTop: parse a CSS BorderTop
1.42 cvs 1019: attribute string.
1020: ----------------------------------------------------------------------*/
1.79 cvs 1021: static char *ParseCSSBorderTop (Element element, PSchema tsch,
1022: PresentationContext context, char *cssRule,
1023: CSSInfoPtr css, ThotBool isHTML)
1.42 cvs 1024: {
1.79 cvs 1025: char *ptr;
1.43 cvs 1026:
1.82 cvs 1027: cssRule = SkipBlanksAndComments (cssRule);
1028: while (*cssRule != ';' && *cssRule != EOS && *cssRule != ',')
1.43 cvs 1029: {
1030: ptr = cssRule;
1031: cssRule = ParseCSSBorderStyleTop (element, tsch, context, cssRule, css, isHTML);
1032: if (ptr == cssRule)
1033: cssRule = ParseCSSBorderTopWidth (element, tsch, context, cssRule, css, isHTML);
1034: if (ptr == cssRule)
1035: cssRule = ParseCSSBorderColorTop (element, tsch, context, cssRule, css, isHTML);
1036: if (ptr == cssRule)
1037: /* rule not found */
1.99 vatton 1038: cssRule = SkipValue (cssRule, TRUE);
1.82 cvs 1039: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 1040: }
1.42 cvs 1041: return (cssRule);
1042: }
1043:
1044: /*----------------------------------------------------------------------
1.59 cvs 1045: ParseCSSBorderLeft: parse a CSS BorderLeft
1.42 cvs 1046: attribute string.
1047: ----------------------------------------------------------------------*/
1.79 cvs 1048: static char *ParseCSSBorderLeft (Element element, PSchema tsch,
1049: PresentationContext context, char *cssRule,
1050: CSSInfoPtr css, ThotBool isHTML)
1.42 cvs 1051: {
1.79 cvs 1052: char *ptr;
1.43 cvs 1053:
1.82 cvs 1054: cssRule = SkipBlanksAndComments (cssRule);
1055: while (*cssRule != ';' && *cssRule != EOS && *cssRule != ',')
1.43 cvs 1056: {
1057: ptr = cssRule;
1058: cssRule = ParseCSSBorderStyleLeft (element, tsch, context, cssRule, css, isHTML);
1059: if (ptr == cssRule)
1060: cssRule = ParseCSSBorderLeftWidth (element, tsch, context, cssRule, css, isHTML);
1061: if (ptr == cssRule)
1062: cssRule = ParseCSSBorderColorLeft (element, tsch, context, cssRule, css, isHTML);
1063: if (ptr == cssRule)
1064: /* rule not found */
1.99 vatton 1065: cssRule = SkipValue (cssRule, TRUE);
1.82 cvs 1066: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 1067: }
1.1 cvs 1068: return (cssRule);
1069: }
1070:
1071: /*----------------------------------------------------------------------
1.59 cvs 1072: ParseCSSBorderBottom: parse a CSS BorderBottom
1.1 cvs 1073: attribute string.
1074: ----------------------------------------------------------------------*/
1.79 cvs 1075: static char *ParseCSSBorderBottom (Element element, PSchema tsch,
1076: PresentationContext context, char *cssRule,
1077: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1078: {
1.79 cvs 1079: char *ptr;
1.43 cvs 1080:
1.82 cvs 1081: cssRule = SkipBlanksAndComments (cssRule);
1082: while (*cssRule != ';' && *cssRule != EOS && *cssRule != ',')
1.43 cvs 1083: {
1084: ptr = cssRule;
1085: cssRule = ParseCSSBorderStyleBottom (element, tsch, context, cssRule, css, isHTML);
1086: if (ptr == cssRule)
1087: cssRule = ParseCSSBorderBottomWidth (element, tsch, context, cssRule, css, isHTML);
1088: if (ptr == cssRule)
1089: cssRule = ParseCSSBorderColorBottom (element, tsch, context, cssRule, css, isHTML);
1090: if (ptr == cssRule)
1091: /* rule not found */
1.99 vatton 1092: cssRule = SkipValue (cssRule, TRUE);
1.82 cvs 1093: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 1094: }
1.1 cvs 1095: return (cssRule);
1096: }
1097:
1098: /*----------------------------------------------------------------------
1.59 cvs 1099: ParseCSSBorderRight: parse a CSS BorderRight
1.1 cvs 1100: attribute string.
1101: ----------------------------------------------------------------------*/
1.79 cvs 1102: static char *ParseCSSBorderRight (Element element, PSchema tsch,
1103: PresentationContext context, char *cssRule,
1104: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1105: {
1.79 cvs 1106: char *ptr;
1.43 cvs 1107:
1.82 cvs 1108: cssRule = SkipBlanksAndComments (cssRule);
1109: while (*cssRule != ';' && *cssRule != EOS && *cssRule != ',')
1.43 cvs 1110: {
1111: ptr = cssRule;
1112: cssRule = ParseCSSBorderStyleRight (element, tsch, context, cssRule, css, isHTML);
1113: if (ptr == cssRule)
1114: cssRule = ParseCSSBorderRightWidth (element, tsch, context, cssRule, css, isHTML);
1115: if (ptr == cssRule)
1116: cssRule = ParseCSSBorderColorRight (element, tsch, context, cssRule, css, isHTML);
1117: if (ptr == cssRule)
1118: /* rule not found */
1.99 vatton 1119: cssRule = SkipValue (cssRule, TRUE);
1.82 cvs 1120: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 1121: }
1.1 cvs 1122: return (cssRule);
1123: }
1124:
1125: /*----------------------------------------------------------------------
1.59 cvs 1126: ParseCSSBorder: parse a CSS border
1.42 cvs 1127: attribute string.
1128: ----------------------------------------------------------------------*/
1.79 cvs 1129: static char *ParseCSSBorder (Element element, PSchema tsch,
1130: PresentationContext context, char *cssRule,
1131: CSSInfoPtr css, ThotBool isHTML)
1.42 cvs 1132: {
1.79 cvs 1133: char *ptrT, *ptrR;
1.93 vatton 1134: int skippedNL;
1.42 cvs 1135:
1.82 cvs 1136: ptrT = SkipBlanksAndComments (cssRule);
1.42 cvs 1137: /* First parse Border-Top */
1138: ptrR = ParseCSSBorderTop (element, tsch, context, ptrT, css, isHTML);
1.82 cvs 1139: ptrR = SkipBlanksAndComments (ptrR);
1140: if (*ptrR == ';' || *ptrR == EOS || *ptrR == ',')
1.42 cvs 1141: {
1.93 vatton 1142: skippedNL = NewLineSkipped;
1.42 cvs 1143: cssRule = ptrR;
1144: /* apply the Border-Top to all */
1145: ptrR = ParseCSSBorderRight (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 1146: NewLineSkipped = skippedNL;
1.42 cvs 1147: ptrR = ParseCSSBorderBottom (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 1148: NewLineSkipped = skippedNL;
1.42 cvs 1149: ptrR = ParseCSSBorderLeft (element, tsch, context, ptrT, css, isHTML);
1150: }
1151: return (cssRule);
1152: }
1153:
1154: /*----------------------------------------------------------------------
1.59 cvs 1155: ParseCSSClear: parse a CSS clear attribute string
1.1 cvs 1156: ----------------------------------------------------------------------*/
1.79 cvs 1157: static char *ParseCSSClear (Element element, PSchema tsch,
1158: PresentationContext context, char *cssRule,
1159: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1160: {
1.99 vatton 1161: cssRule = SkipValue (cssRule, FALSE);
1.1 cvs 1162: return (cssRule);
1163: }
1164:
1165: /*----------------------------------------------------------------------
1.59 cvs 1166: ParseCSSDisplay: parse a CSS display attribute string
1.1 cvs 1167: ----------------------------------------------------------------------*/
1.79 cvs 1168: static char *ParseCSSDisplay (Element element, PSchema tsch,
1169: PresentationContext context, char *cssRule,
1170: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1171: {
1172: PresentationValue pval;
1173:
1174: pval.typed_data.unit = STYLE_UNIT_REL;
1175: pval.typed_data.real = FALSE;
1.82 cvs 1176: cssRule = SkipBlanksAndComments (cssRule);
1.126 vatton 1177: if (!strncasecmp (cssRule, "none", 4))
1.1 cvs 1178: {
1.124 quint 1179: pval.typed_data.value = 0;
1.116 vatton 1180: if (DoApply)
1.117 vatton 1181: {
1182: if (tsch)
1183: cssRule = CheckImportantRule (cssRule, context);
1.116 vatton 1184: TtaSetStylePresentation (PRVisibility, element, tsch, context, pval);
1.117 vatton 1185: }
1.1 cvs 1186: cssRule = SkipWord (cssRule);
1187: }
1188: else
1.126 vatton 1189: {
1190: if (!strncasecmp (cssRule, "block", 5))
1191: pval.typed_data.value = STYLE_DISPLAYBLOCK;
1192: else if (!strncasecmp (cssRule, "inline", 6))
1193: pval.typed_data.value = STYLE_DISPLAYINLINE;
1194: else if (!strncasecmp (cssRule, "list-item", 9))
1195: pval.typed_data.value = STYLE_DISPLAYLISTITEM;
1.128 vatton 1196: else if (!strncasecmp (cssRule, "run-in", 6))
1.126 vatton 1197: pval.typed_data.value = STYLE_DISPLAYRUNIN;
1198: else if (!strncasecmp (cssRule, "compact", 7))
1199: pval.typed_data.value = STYLE_DISPLAYCOMPACT;
1200: else if (!strncasecmp (cssRule, "marker", 6))
1201: pval.typed_data.value = STYLE_DISPLAYMARKER;
1202: else
1203: {
1.128 vatton 1204: if (strncasecmp (cssRule, "table-row-group", 15) &&
1205: strncasecmp (cssRule, "table-column-group", 18) &&
1206: strncasecmp (cssRule, "table-header-group", 5) &&
1207: strncasecmp (cssRule, "table-footer-group", 6) &&
1208: strncasecmp (cssRule, "table-row", 9) &&
1209: strncasecmp (cssRule, "table-column", 12) &&
1210: strncasecmp (cssRule, "table-cell", 10) &&
1211: strncasecmp (cssRule, "table-caption", 13) &&
1212: strncasecmp (cssRule, "table", 5) &&
1213: strncasecmp (cssRule, "inherit", 7))
1.126 vatton 1214: CSSParseError ("Invalid display value", cssRule);
1215: cssRule = SkipWord (cssRule);
1216: return (cssRule);
1217: }
1.34 cvs 1218:
1.126 vatton 1219: if (DoApply)
1220: {
1221: if (tsch)
1222: cssRule = CheckImportantRule (cssRule, context);
1223: TtaSetStylePresentation (PRDisplay, element, tsch, context, pval);
1224: }
1225: cssRule = SkipWord (cssRule);
1226: }
1.1 cvs 1227: return (cssRule);
1228: }
1229:
1230: /*----------------------------------------------------------------------
1.59 cvs 1231: ParseCSSFloat: parse a CSS float attribute string
1.1 cvs 1232: ----------------------------------------------------------------------*/
1.79 cvs 1233: static char *ParseCSSFloat (Element element, PSchema tsch,
1234: PresentationContext context, char *cssRule,
1235: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1236: {
1.99 vatton 1237: cssRule = SkipValue (cssRule, FALSE);
1.1 cvs 1238: return (cssRule);
1239: }
1240:
1241: /*----------------------------------------------------------------------
1.59 cvs 1242: ParseCSSLetterSpacing: parse a CSS letter-spacing
1.1 cvs 1243: attribute string.
1244: ----------------------------------------------------------------------*/
1.79 cvs 1245: static char *ParseCSSLetterSpacing (Element element, PSchema tsch,
1246: PresentationContext context, char *cssRule,
1247: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1248: {
1.99 vatton 1249: cssRule = SkipValue (cssRule, FALSE);
1.1 cvs 1250: return (cssRule);
1251: }
1252:
1253: /*----------------------------------------------------------------------
1.59 cvs 1254: ParseCSSListStyleType: parse a CSS list-style-type
1.1 cvs 1255: attribute string.
1256: ----------------------------------------------------------------------*/
1.79 cvs 1257: static char *ParseCSSListStyleType (Element element, PSchema tsch,
1258: PresentationContext context, char *cssRule,
1259: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1260: {
1.99 vatton 1261: cssRule = SkipValue (cssRule, FALSE);
1.1 cvs 1262: return (cssRule);
1263: }
1264:
1265: /*----------------------------------------------------------------------
1.59 cvs 1266: ParseCSSListStyleImage: parse a CSS list-style-image
1.1 cvs 1267: attribute string.
1268: ----------------------------------------------------------------------*/
1.79 cvs 1269: static char *ParseCSSListStyleImage (Element element, PSchema tsch,
1270: PresentationContext context, char *cssRule,
1271: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1272: {
1.99 vatton 1273: cssRule = SkipValue (cssRule, FALSE);
1.1 cvs 1274: return (cssRule);
1275: }
1276:
1277: /*----------------------------------------------------------------------
1.59 cvs 1278: ParseCSSListStylePosition: parse a CSS list-style-position
1.1 cvs 1279: attribute string.
1280: ----------------------------------------------------------------------*/
1.79 cvs 1281: static char *ParseCSSListStylePosition (Element element, PSchema tsch,
1282: PresentationContext context,
1283: char *cssRule, CSSInfoPtr css,
1284: ThotBool isHTML)
1.1 cvs 1285: {
1.99 vatton 1286: cssRule = SkipValue (cssRule, FALSE);
1.1 cvs 1287: return (cssRule);
1288: }
1289:
1290: /*----------------------------------------------------------------------
1.59 cvs 1291: ParseCSSListStyle: parse a CSS list-style
1.1 cvs 1292: attribute string.
1293: ----------------------------------------------------------------------*/
1.79 cvs 1294: static char *ParseCSSListStyle (Element element, PSchema tsch,
1295: PresentationContext context, char *cssRule,
1296: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1297: {
1.99 vatton 1298: cssRule = SkipValue (cssRule, FALSE);
1.1 cvs 1299: return (cssRule);
1300: }
1301:
1302: /*----------------------------------------------------------------------
1.59 cvs 1303: ParseCSSTextAlign: parse a CSS text-align
1.1 cvs 1304: attribute string.
1305: ----------------------------------------------------------------------*/
1.79 cvs 1306: static char *ParseCSSTextAlign (Element element, PSchema tsch,
1307: PresentationContext context, char *cssRule,
1308: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1309: {
1310: PresentationValue align;
1311:
1312: align.typed_data.value = 0;
1313: align.typed_data.unit = STYLE_UNIT_REL;
1314: align.typed_data.real = FALSE;
1315:
1.82 cvs 1316: cssRule = SkipBlanksAndComments (cssRule);
1317: if (!strncasecmp (cssRule, "left", 4))
1.1 cvs 1318: {
1319: align.typed_data.value = AdjustLeft;
1320: cssRule = SkipWord (cssRule);
1321: }
1.82 cvs 1322: else if (!strncasecmp (cssRule, "right", 5))
1.1 cvs 1323: {
1324: align.typed_data.value = AdjustRight;
1325: cssRule = SkipWord (cssRule);
1326: }
1.82 cvs 1327: else if (!strncasecmp (cssRule, "center", 6))
1.1 cvs 1328: {
1329: align.typed_data.value = Centered;
1330: cssRule = SkipWord (cssRule);
1331: }
1.82 cvs 1332: else if (!strncasecmp (cssRule, "justify", 7))
1.1 cvs 1333: {
1.81 cvs 1334: align.typed_data.value = Justify;
1.1 cvs 1335: cssRule = SkipWord (cssRule);
1336: }
1337: else
1338: {
1.86 cvs 1339: CSSParseError ("Invalid align value", cssRule);
1.1 cvs 1340: return (cssRule);
1341: }
1342:
1343: /*
1344: * install the new presentation.
1345: */
1.116 vatton 1346: if (align.typed_data.value && DoApply)
1.117 vatton 1347: {
1348: if (tsch)
1349: cssRule = CheckImportantRule (cssRule, context);
1350: TtaSetStylePresentation (PRAdjust, element, tsch, context, align);
1351: }
1.1 cvs 1352: return (cssRule);
1353: }
1354:
1355: /*----------------------------------------------------------------------
1.112 quint 1356: ParseCSSDirection: parse a CSS direction property
1357: ----------------------------------------------------------------------*/
1358: static char *ParseCSSDirection (Element element, PSchema tsch,
1359: PresentationContext context, char *cssRule,
1360: CSSInfoPtr css, ThotBool isHTML)
1361: {
1362: PresentationValue direction;
1363:
1364: direction.typed_data.value = 0;
1365: direction.typed_data.unit = STYLE_UNIT_REL;
1366: direction.typed_data.real = FALSE;
1367:
1368: cssRule = SkipBlanksAndComments (cssRule);
1369: if (!strncasecmp (cssRule, "ltr", 3))
1370: {
1371: direction.typed_data.value = STYLE_LEFTTORIGHT;
1372: cssRule = SkipWord (cssRule);
1373: }
1374: else if (!strncasecmp (cssRule, "rtl", 3))
1375: {
1376: direction.typed_data.value = STYLE_RIGHTTOLEFT;
1377: cssRule = SkipWord (cssRule);
1378: }
1379: else if (!strncasecmp (cssRule, "inherit", 7))
1380: {
1381: /* not implemented */
1382: cssRule = SkipWord (cssRule);
1383: return (cssRule);
1384: }
1385: else
1386: {
1387: CSSParseError ("Invalid direction value", cssRule);
1388: return (cssRule);
1389: }
1390:
1391: /*
1392: * install the new presentation.
1393: */
1.116 vatton 1394: if (direction.typed_data.value && DoApply)
1.117 vatton 1395: {
1396: if (tsch)
1397: cssRule = CheckImportantRule (cssRule, context);
1398: TtaSetStylePresentation (PRDirection, element, tsch, context, direction);
1399: }
1.112 quint 1400: return (cssRule);
1401: }
1402:
1403: /*----------------------------------------------------------------------
1.113 quint 1404: ParseCSSUnicodeBidi: parse a CSS unicode-bidi property
1405: ----------------------------------------------------------------------*/
1406: static char *ParseCSSUnicodeBidi (Element element, PSchema tsch,
1407: PresentationContext context, char *cssRule,
1408: CSSInfoPtr css, ThotBool isHTML)
1409: {
1410: PresentationValue bidi;
1411:
1412: bidi.typed_data.value = 0;
1413: bidi.typed_data.unit = STYLE_UNIT_REL;
1414: bidi.typed_data.real = FALSE;
1415:
1416: cssRule = SkipBlanksAndComments (cssRule);
1417: if (!strncasecmp (cssRule, "normal", 6))
1418: {
1419: bidi.typed_data.value = STYLE_BIDINORMAL;
1420: cssRule = SkipWord (cssRule);
1421: }
1422: else if (!strncasecmp (cssRule, "embed", 5))
1423: {
1424: bidi.typed_data.value = STYLE_BIDIEMBED;
1425: cssRule = SkipWord (cssRule);
1426: }
1427: else if (!strncasecmp (cssRule, "override", 8))
1428: {
1429: bidi.typed_data.value = STYLE_BIDIOVERRIDE;
1430: cssRule = SkipWord (cssRule);
1431: }
1432: else if (!strncasecmp (cssRule, "inherit", 7))
1433: {
1434: /* not implemented */
1435: cssRule = SkipWord (cssRule);
1436: return (cssRule);
1437: }
1438: else
1439: {
1440: CSSParseError ("Invalid unicode-bidi value", cssRule);
1441: return (cssRule);
1442: }
1443:
1444: /*
1445: * install the new presentation.
1446: */
1.116 vatton 1447: if (bidi.typed_data.value && DoApply)
1.117 vatton 1448: {
1449: if (tsch)
1450: cssRule = CheckImportantRule (cssRule, context);
1451: TtaSetStylePresentation (PRUnicodeBidi, element, tsch, context, bidi);
1452: }
1.113 quint 1453: return (cssRule);
1454: }
1455:
1456: /*----------------------------------------------------------------------
1.59 cvs 1457: ParseCSSTextIndent: parse a CSS text-indent
1.1 cvs 1458: attribute string.
1459: ----------------------------------------------------------------------*/
1.79 cvs 1460: static char *ParseCSSTextIndent (Element element, PSchema tsch,
1461: PresentationContext context, char *cssRule,
1462: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1463: {
1464: PresentationValue pval;
1465:
1.82 cvs 1466: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 1467: cssRule = ParseCSSUnit (cssRule, &pval);
1468: if (pval.typed_data.unit == STYLE_UNIT_INVALID)
1469: return (cssRule);
1470: /* install the attribute */
1.116 vatton 1471: if (DoApply)
1.117 vatton 1472: {
1473: if (tsch)
1474: cssRule = CheckImportantRule (cssRule, context);
1475: TtaSetStylePresentation (PRIndent, element, tsch, context, pval);
1476: }
1.1 cvs 1477: return (cssRule);
1478: }
1479:
1480: /*----------------------------------------------------------------------
1.59 cvs 1481: ParseCSSTextTransform: parse a CSS text-transform
1.1 cvs 1482: attribute string.
1483: ----------------------------------------------------------------------*/
1.79 cvs 1484: static char *ParseCSSTextTransform (Element element, PSchema tsch,
1485: PresentationContext context, char *cssRule,
1486: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1487: {
1.99 vatton 1488: cssRule = SkipValue (cssRule, FALSE);
1.1 cvs 1489: return (cssRule);
1490: }
1491:
1492: /*----------------------------------------------------------------------
1.59 cvs 1493: ParseCSSVerticalAlign: parse a CSS vertical-align
1.1 cvs 1494: attribute string.
1495: ----------------------------------------------------------------------*/
1.79 cvs 1496: static char *ParseCSSVerticalAlign (Element element, PSchema tsch,
1497: PresentationContext context, char *cssRule,
1498: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1499: {
1.99 vatton 1500: cssRule = SkipValue (cssRule, FALSE);
1.1 cvs 1501: return (cssRule);
1502: }
1503:
1504: /*----------------------------------------------------------------------
1.59 cvs 1505: ParseCSSWhiteSpace: parse a CSS white-space
1.1 cvs 1506: attribute string.
1507: ----------------------------------------------------------------------*/
1.79 cvs 1508: static char *ParseCSSWhiteSpace (Element element, PSchema tsch,
1509: PresentationContext context, char *cssRule,
1510: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1511: {
1.82 cvs 1512: cssRule = SkipBlanksAndComments (cssRule);
1513: if (!strncasecmp (cssRule, "normal", 6))
1.1 cvs 1514: cssRule = SkipWord (cssRule);
1.82 cvs 1515: else if (!strncasecmp (cssRule, "pre", 3))
1.1 cvs 1516: cssRule = SkipWord (cssRule);
1517: else
1518: return (cssRule);
1519: return (cssRule);
1520: }
1521:
1522: /*----------------------------------------------------------------------
1.59 cvs 1523: ParseCSSWordSpacing: parse a CSS word-spacing
1.1 cvs 1524: attribute string.
1525: ----------------------------------------------------------------------*/
1.79 cvs 1526: static char *ParseCSSWordSpacing (Element element, PSchema tsch,
1527: PresentationContext context, char *cssRule,
1528: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1529: {
1.99 vatton 1530: cssRule = SkipValue (cssRule, FALSE);
1.1 cvs 1531: return (cssRule);
1532: }
1533:
1534: /*----------------------------------------------------------------------
1.59 cvs 1535: ParseCSSLineSpacing: parse a CSS font leading string
1.25 cvs 1536: we expect the input string describing the attribute to be
1537: value% or value
1538: ----------------------------------------------------------------------*/
1.79 cvs 1539: static char *ParseCSSLineSpacing (Element element, PSchema tsch,
1540: PresentationContext context, char *cssRule,
1541: CSSInfoPtr css, ThotBool isHTML)
1.25 cvs 1542: {
1543: PresentationValue lead;
1544:
1545: cssRule = ParseCSSUnit (cssRule, &lead);
1.117 vatton 1546: if (lead.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.93 vatton 1547: /* install the new presentation */
1.117 vatton 1548: {
1549: if (tsch)
1550: cssRule = CheckImportantRule (cssRule, context);
1.116 vatton 1551: TtaSetStylePresentation (PRLineSpacing, element, tsch, context, lead);
1.117 vatton 1552: }
1.25 cvs 1553: return (cssRule);
1554: }
1555:
1556: /*----------------------------------------------------------------------
1.59 cvs 1557: ParseCSSFontSize: parse a CSS font size attr string
1.1 cvs 1558: we expect the input string describing the attribute to be
1559: xx-small, x-small, small, medium, large, x-large, xx-large
1560: or an absolute size, or an imcrement relative to the parent
1561: ----------------------------------------------------------------------*/
1.79 cvs 1562: static char *ParseCSSFontSize (Element element, PSchema tsch,
1563: PresentationContext context, char *cssRule,
1564: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1565: {
1566: PresentationValue pval;
1.137 vatton 1567: char *ptr = NULL, *ptr1 = NULL;
1.14 cvs 1568: ThotBool real;
1.1 cvs 1569:
1570: pval.typed_data.real = FALSE;
1.82 cvs 1571: cssRule = SkipBlanksAndComments (cssRule);
1572: if (!strncasecmp (cssRule, "larger", 6))
1.1 cvs 1573: {
1574: pval.typed_data.unit = STYLE_UNIT_PERCENT;
1575: pval.typed_data.value = 130;
1576: cssRule = SkipWord (cssRule);
1577: }
1.82 cvs 1578: else if (!strncasecmp (cssRule, "smaller", 7))
1.1 cvs 1579: {
1580: pval.typed_data.unit = STYLE_UNIT_PERCENT;
1581: pval.typed_data.value = 80;
1582: cssRule = SkipWord (cssRule);
1583: }
1.82 cvs 1584: else if (!strncasecmp (cssRule, "xx-small", 8))
1.1 cvs 1585: {
1586: pval.typed_data.unit = STYLE_UNIT_REL;
1587: pval.typed_data.value = 1;
1588: cssRule = SkipWord (cssRule);
1589: }
1.82 cvs 1590: else if (!strncasecmp (cssRule, "x-small", 7))
1.1 cvs 1591: {
1592: pval.typed_data.unit = STYLE_UNIT_REL;
1593: pval.typed_data.value = 2;
1594: cssRule = SkipWord (cssRule);
1595: }
1.82 cvs 1596: else if (!strncasecmp (cssRule, "small", 5))
1.1 cvs 1597: {
1598: pval.typed_data.unit = STYLE_UNIT_REL;
1599: pval.typed_data.value = 3;
1600: cssRule = SkipWord (cssRule);
1601: }
1.82 cvs 1602: else if (!strncasecmp (cssRule, "medium", 6))
1.1 cvs 1603: {
1604: pval.typed_data.unit = STYLE_UNIT_REL;
1605: pval.typed_data.value = 4;
1606: cssRule = SkipWord (cssRule);
1607: }
1.82 cvs 1608: else if (!strncasecmp (cssRule, "large", 5))
1.1 cvs 1609: {
1610: pval.typed_data.unit = STYLE_UNIT_REL;
1611: pval.typed_data.value = 5;
1612: cssRule = SkipWord (cssRule);
1613: }
1.82 cvs 1614: else if (!strncasecmp (cssRule, "x-large", 7))
1.1 cvs 1615: {
1616: pval.typed_data.unit = STYLE_UNIT_REL;
1617: pval.typed_data.value = 6;
1618: cssRule = SkipWord (cssRule);
1619: }
1.82 cvs 1620: else if (!strncasecmp (cssRule, "xx-large", 8))
1.1 cvs 1621: {
1622: pval.typed_data.unit = STYLE_UNIT_REL;
1623: pval.typed_data.value = 7;
1624: cssRule = SkipWord (cssRule);
1625: }
1626: else
1627: {
1.25 cvs 1628: /* look for a '/' within the current cssRule */
1.137 vatton 1629: ptr1 = strchr (cssRule, ';');
1.82 cvs 1630: ptr = strchr (cssRule, '/');
1.137 vatton 1631: if (ptr && (ptr1 == NULL || ptr < ptr1))
1.25 cvs 1632: {
1633: /* keep the line spacing rule */
1.82 cvs 1634: ptr[0] = EOS;
1.25 cvs 1635: ptr = &ptr[1];
1636: }
1.137 vatton 1637: else
1638: ptr = NULL;
1.1 cvs 1639: cssRule = ParseCSSUnit (cssRule, &pval);
1640: if (pval.typed_data.unit == STYLE_UNIT_INVALID ||
1641: pval.typed_data.value < 0)
1642: return (cssRule);
1643: if (pval.typed_data.unit == STYLE_UNIT_REL && pval.typed_data.value > 0)
1644: /* CSS relative sizes have to be higher than Thot ones */
1645: pval.typed_data.value += 1;
1646: else
1647: {
1648: real = pval.typed_data.real;
1649: if (pval.typed_data.unit == STYLE_UNIT_EM)
1650: {
1651: if (real)
1652: {
1653: pval.typed_data.value /= 10;
1.11 cvs 1654: pval.typed_data.real = FALSE;
1.1 cvs 1655: real = FALSE;
1656: }
1657: else
1658: pval.typed_data.value *= 100;
1659: pval.typed_data.unit = STYLE_UNIT_PERCENT;
1660: }
1.146 quint 1661: else if (pval.typed_data.unit == STYLE_UNIT_XHEIGHT)
1662: {
1663: /* a font size expressed in ex is converted into a percentage.
1664: For example, "3ex" is converted into "180%", supposing
1665: that 1ex is approximately 0.6 times the height of the
1666: current font */
1667: if (real)
1668: {
1669: pval.typed_data.value *= 6;
1670: pval.typed_data.value /= 100;
1671: pval.typed_data.real = FALSE;
1672: real = FALSE;
1673: }
1674: else
1675: pval.typed_data.value *= 60;
1676: pval.typed_data.unit = STYLE_UNIT_PERCENT;
1677: }
1.1 cvs 1678: }
1.25 cvs 1679:
1.1 cvs 1680: }
1681:
1.25 cvs 1682: /* install the presentation style */
1.116 vatton 1683: if (DoApply)
1.117 vatton 1684: {
1685: if (tsch)
1686: cssRule = CheckImportantRule (cssRule, context);
1687: TtaSetStylePresentation (PRSize, element, tsch, context, pval);
1688: }
1689: if (ptr)
1.25 cvs 1690: cssRule = ParseCSSLineSpacing (element, tsch, context, ptr, css, isHTML);
1.1 cvs 1691: return (cssRule);
1692: }
1693:
1694: /*----------------------------------------------------------------------
1.59 cvs 1695: ParseCSSFontFamily: parse a CSS font family string
1.1 cvs 1696: we expect the input string describing the attribute to be
1697: a common generic font style name
1698: ----------------------------------------------------------------------*/
1.79 cvs 1699: static char *ParseCSSFontFamily (Element element, PSchema tsch,
1700: PresentationContext context, char *cssRule,
1701: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1702: {
1703: PresentationValue font;
1.79 cvs 1704: char quoteChar;
1.1 cvs 1705:
1706: font.typed_data.value = 0;
1707: font.typed_data.unit = STYLE_UNIT_REL;
1708: font.typed_data.real = FALSE;
1.82 cvs 1709: cssRule = SkipBlanksAndComments (cssRule);
1710: if (*cssRule == '"' || *cssRule == '\'')
1.1 cvs 1711: {
1712: quoteChar = *cssRule;
1713: cssRule++;
1714: }
1715: else
1.82 cvs 1716: quoteChar = EOS;
1.1 cvs 1717:
1.92 cvs 1718: if (!strncasecmp (cssRule, "times", 5) &&
1719: (quoteChar == EOS || quoteChar == cssRule[5]))
1.86 cvs 1720: {
1.1 cvs 1721: font.typed_data.value = STYLE_FONT_TIMES;
1.86 cvs 1722: cssRule += 5;
1723: }
1.92 cvs 1724: else if (!strncasecmp (cssRule, "serif", 5) &&
1725: (quoteChar == EOS || quoteChar == cssRule[5]))
1.86 cvs 1726: {
1.1 cvs 1727: font.typed_data.value = STYLE_FONT_TIMES;
1.86 cvs 1728: cssRule += 5;
1.92 cvs 1729: if (quoteChar != EOS)
1730: cssRule++;
1.86 cvs 1731: }
1.92 cvs 1732: else if (!strncasecmp (cssRule, "helvetica", 9) &&
1733: (quoteChar == EOS || quoteChar == cssRule[9]))
1.86 cvs 1734: {
1735: font.typed_data.value = STYLE_FONT_HELVETICA;
1736: cssRule += 9;
1.92 cvs 1737: if (quoteChar != EOS)
1738: cssRule++;
1.86 cvs 1739: }
1.92 cvs 1740: else if (!strncasecmp (cssRule, "verdana", 7) &&
1741: (quoteChar == EOS || quoteChar == cssRule[7]))
1.86 cvs 1742: {
1.1 cvs 1743: font.typed_data.value = STYLE_FONT_HELVETICA;
1.86 cvs 1744: cssRule += 7;
1.92 cvs 1745: if (quoteChar != EOS)
1746: cssRule++;
1.86 cvs 1747: }
1.92 cvs 1748: else if (!strncasecmp (cssRule, "sans-serif", 10) &&
1749: (quoteChar == EOS || quoteChar == cssRule[10]))
1.86 cvs 1750: {
1.1 cvs 1751: font.typed_data.value = STYLE_FONT_HELVETICA;
1.86 cvs 1752: cssRule += 10;
1.92 cvs 1753: if (quoteChar != EOS)
1754: cssRule++;
1.86 cvs 1755: }
1.92 cvs 1756: else if (!strncasecmp (cssRule, "courier", 7) &&
1757: (quoteChar == EOS || quoteChar == cssRule[7]))
1.86 cvs 1758: {
1.1 cvs 1759: font.typed_data.value = STYLE_FONT_COURIER;
1.86 cvs 1760: cssRule += 7;
1.92 cvs 1761: if (quoteChar != EOS)
1762: cssRule++;
1.86 cvs 1763: }
1.92 cvs 1764: else if (!strncasecmp (cssRule, "monospace", 9) &&
1765: (quoteChar == EOS || quoteChar == cssRule[9]))
1.86 cvs 1766: {
1.1 cvs 1767: font.typed_data.value = STYLE_FONT_COURIER;
1.86 cvs 1768: cssRule += 9;
1.92 cvs 1769: if (quoteChar != EOS)
1770: cssRule++;
1.86 cvs 1771: }
1.1 cvs 1772: else
1773: /* unknown font name. Skip it */
1774: {
1.92 cvs 1775: if (quoteChar != EOS)
1.54 cvs 1776: cssRule = SkipQuotedString (cssRule, quoteChar);
1.86 cvs 1777: else
1.1 cvs 1778: cssRule = SkipWord (cssRule);
1.82 cvs 1779: cssRule = SkipBlanksAndComments (cssRule);
1780: if (*cssRule == ',')
1.1 cvs 1781: {
1.86 cvs 1782: cssRule++;
1783: cssRule = ParseCSSFontFamily (element, tsch, context, cssRule, css, isHTML);
1784: return (cssRule);
1.1 cvs 1785: }
1786: }
1787:
1788: if (font.typed_data.value != 0)
1789: {
1.93 vatton 1790: cssRule = SkipBlanksAndComments (cssRule);
1.133 vatton 1791: if (*cssRule == ',')
1792: {
1793: cssRule++;
1794: cssRule = SkipValue (cssRule, FALSE);
1795: }
1.93 vatton 1796: /* install the new presentation */
1.116 vatton 1797: if (DoApply)
1.117 vatton 1798: {
1799: if (tsch)
1800: cssRule = CheckImportantRule (cssRule, context);
1801: TtaSetStylePresentation (PRFont, element, tsch, context, font);
1802: }
1.1 cvs 1803: }
1804: return (cssRule);
1805: }
1806:
1807: /*----------------------------------------------------------------------
1.59 cvs 1808: ParseCSSFontWeight: parse a CSS font weight string
1.1 cvs 1809: we expect the input string describing the attribute to be
1.20 cvs 1810: normal, bold, bolder, lighter, 100, 200, 300, ... 900, inherit.
1.1 cvs 1811: ----------------------------------------------------------------------*/
1.79 cvs 1812: static char *ParseCSSFontWeight (Element element, PSchema tsch,
1813: PresentationContext context, char *cssRule,
1814: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1815: {
1.20 cvs 1816: PresentationValue weight;
1.1 cvs 1817:
1818: weight.typed_data.value = 0;
1819: weight.typed_data.unit = STYLE_UNIT_REL;
1820: weight.typed_data.real = FALSE;
1.82 cvs 1821: cssRule = SkipBlanksAndComments (cssRule);
1822: if (!strncasecmp (cssRule, "100", 3) && !isalpha (cssRule[3]))
1.1 cvs 1823: {
1824: weight.typed_data.value = -3;
1825: cssRule = SkipWord (cssRule);
1826: }
1.82 cvs 1827: else if (!strncasecmp (cssRule, "200", 3) && !isalpha (cssRule[3]))
1.1 cvs 1828: {
1829: weight.typed_data.value = -2;
1830: cssRule = SkipWord (cssRule);
1831: }
1.82 cvs 1832: else if (!strncasecmp (cssRule, "300", 3) && ! isalpha(cssRule[3]))
1.1 cvs 1833: {
1834: weight.typed_data.value = -1;
1835: cssRule = SkipWord (cssRule);
1836: }
1.82 cvs 1837: else if (!strncasecmp (cssRule, "normal", 6) || (!strncasecmp (cssRule, "400", 3) && !isalpha (cssRule[3])))
1.1 cvs 1838: {
1839: weight.typed_data.value = 0;
1840: cssRule = SkipWord (cssRule);
1841: }
1.82 cvs 1842: else if (!strncasecmp (cssRule, "500", 3) && !isalpha (cssRule[3]))
1.1 cvs 1843: {
1844: weight.typed_data.value = +1;
1845: cssRule = SkipWord (cssRule);
1846: }
1.82 cvs 1847: else if (!strncasecmp (cssRule, "600", 3) && !isalpha (cssRule[3]))
1.1 cvs 1848: {
1849: weight.typed_data.value = +2;
1850: cssRule = SkipWord (cssRule);
1851: }
1.82 cvs 1852: else if (!strncasecmp (cssRule, "bold", 4) || (!strncasecmp (cssRule, "700", 3) && !isalpha (cssRule[3])))
1.1 cvs 1853: {
1854: weight.typed_data.value = +3;
1855: cssRule = SkipWord (cssRule);
1856: }
1.82 cvs 1857: else if (!strncasecmp (cssRule, "800", 3) && !isalpha (cssRule[3]))
1.1 cvs 1858: {
1859: weight.typed_data.value = +4;
1860: cssRule = SkipWord (cssRule);
1861: }
1.82 cvs 1862: else if (!strncasecmp (cssRule, "900", 3) && !isalpha (cssRule[3]))
1.1 cvs 1863: {
1864: weight.typed_data.value = +5;
1865: cssRule = SkipWord (cssRule);
1866: }
1.82 cvs 1867: else if (!strncasecmp (cssRule, "inherit", 7) || !strncasecmp (cssRule, "bolder", 6) || !strncasecmp (cssRule, "lighter", 7))
1.1 cvs 1868: {
1869: /* not implemented */
1870: cssRule = SkipWord (cssRule);
1871: return (cssRule);
1872: }
1873: else
1874: return (cssRule);
1875:
1876: /*
1.20 cvs 1877: * Here we have to reduce since only two font weight values are supported
1.1 cvs 1878: * by the Thot presentation API.
1879: */
1.20 cvs 1880: if (weight.typed_data.value > 0)
1881: weight.typed_data.value = STYLE_WEIGHT_BOLD;
1882: else
1883: weight.typed_data.value = STYLE_WEIGHT_NORMAL;
1.1 cvs 1884:
1885: /* install the new presentation */
1.116 vatton 1886: if (DoApply)
1.117 vatton 1887: {
1888: if (tsch)
1889: cssRule = CheckImportantRule (cssRule, context);
1890: TtaSetStylePresentation (PRWeight, element, tsch, context, weight);
1891: }
1.1 cvs 1892: return (cssRule);
1893: }
1894:
1895: /*----------------------------------------------------------------------
1.59 cvs 1896: ParseCSSFontVariant: parse a CSS font variant string
1.1 cvs 1897: we expect the input string describing the attribute to be
1898: normal or small-caps
1899: ----------------------------------------------------------------------*/
1.79 cvs 1900: static char *ParseCSSFontVariant (Element element, PSchema tsch,
1901: PresentationContext context, char *cssRule,
1902: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1903: {
1904: PresentationValue style;
1905:
1906: style.typed_data.value = 0;
1907: style.typed_data.unit = STYLE_UNIT_REL;
1908: style.typed_data.real = FALSE;
1.82 cvs 1909: cssRule = SkipBlanksAndComments (cssRule);
1910: if (!strncasecmp (cssRule, "small-caps", 10))
1.1 cvs 1911: {
1912: /* Not supported yet */
1913: cssRule = SkipWord (cssRule);
1914: }
1.82 cvs 1915: else if (!strncasecmp (cssRule, "normal", 6))
1.1 cvs 1916: {
1917: /* Not supported yet */
1918: cssRule = SkipWord (cssRule);
1919: }
1.82 cvs 1920: else if (!strncasecmp (cssRule, "inherit", 7))
1.1 cvs 1921: {
1922: /* Not supported yet */
1923: cssRule = SkipWord (cssRule);
1924: }
1925: else
1926: return (cssRule);
1927:
1928: return (cssRule);
1929: }
1930:
1931:
1932: /*----------------------------------------------------------------------
1.59 cvs 1933: ParseCSSFontStyle: parse a CSS font style string
1.1 cvs 1934: we expect the input string describing the attribute to be
1935: italic, oblique or normal
1936: ----------------------------------------------------------------------*/
1.79 cvs 1937: static char *ParseCSSFontStyle (Element element, PSchema tsch,
1938: PresentationContext context, char *cssRule,
1939: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1940: {
1941: PresentationValue style;
1942: PresentationValue size;
1943:
1944: style.typed_data.value = 0;
1945: style.typed_data.unit = STYLE_UNIT_REL;
1946: style.typed_data.real = FALSE;
1947: size.typed_data.value = 0;
1948: size.typed_data.unit = STYLE_UNIT_REL;
1949: size.typed_data.real = FALSE;
1.82 cvs 1950: cssRule = SkipBlanksAndComments (cssRule);
1951: if (!strncasecmp (cssRule, "italic", 6))
1.1 cvs 1952: {
1953: style.typed_data.value = STYLE_FONT_ITALICS;
1954: cssRule = SkipWord (cssRule);
1955: }
1.82 cvs 1956: else if (!strncasecmp (cssRule, "oblique", 7))
1.1 cvs 1957: {
1958: style.typed_data.value = STYLE_FONT_OBLIQUE;
1959: cssRule = SkipWord (cssRule);
1960: }
1.82 cvs 1961: else if (!strncasecmp (cssRule, "normal", 6))
1.1 cvs 1962: {
1963: style.typed_data.value = STYLE_FONT_ROMAN;
1964: cssRule = SkipWord (cssRule);
1965: }
1.108 cvs 1966: else if (!strncasecmp (cssRule, "inherit", 7))
1967: {
1968: /* not implemented */
1969: cssRule = SkipWord (cssRule);
1970: return (cssRule);
1971: }
1.1 cvs 1972: else
1973: {
1974: /* invalid font style */
1.108 cvs 1975: return (cssRule);
1.1 cvs 1976: }
1977:
1978: /*
1979: * install the new presentation.
1980: */
1.116 vatton 1981: if (style.typed_data.value != 0 && DoApply)
1.117 vatton 1982: {
1983: if (tsch)
1984: cssRule = CheckImportantRule (cssRule, context);
1.20 cvs 1985: TtaSetStylePresentation (PRStyle, element, tsch, context, style);
1.117 vatton 1986: }
1.116 vatton 1987: if (size.typed_data.value != 0 && DoApply)
1.1 cvs 1988: {
1989: PresentationValue previous_size;
1990:
1991: if (!TtaGetStylePresentation (PRSize, element, tsch, context, &previous_size))
1992: {
1993: /* !!!!!!!!!!!!!!!!!!!!!!!! Unite + relatif !!!!!!!!!!!!!!!! */
1994: size.typed_data.value += previous_size.typed_data.value;
1995: TtaSetStylePresentation (PRSize, element, tsch, context, size);
1996: }
1997: else
1998: {
1999: size.typed_data.value = 10;
2000: TtaSetStylePresentation (PRSize, element, tsch, context, size);
2001: }
2002: }
2003: return (cssRule);
2004: }
2005:
2006: /*----------------------------------------------------------------------
1.59 cvs 2007: ParseCSSFont: parse a CSS font attribute string
2008: we expect the input string describing the attribute to be
2009: !!!!!!
1.1 cvs 2010: ----------------------------------------------------------------------*/
1.79 cvs 2011: static char *ParseCSSFont (Element element, PSchema tsch,
2012: PresentationContext context, char *cssRule,
2013: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2014: {
1.79 cvs 2015: char *ptr;
1.93 vatton 2016: int skippedNL;
1.1 cvs 2017:
1.82 cvs 2018: cssRule = SkipBlanksAndComments (cssRule);
2019: if (!strncasecmp (cssRule, "caption", 7))
1.1 cvs 2020: ;
1.82 cvs 2021: else if (!strncasecmp (cssRule, "icon", 4))
1.1 cvs 2022: ;
1.82 cvs 2023: else if (!strncasecmp (cssRule, "menu", 4))
1.1 cvs 2024: ;
1.82 cvs 2025: else if (!strncasecmp (cssRule, "message-box", 11))
1.1 cvs 2026: ;
1.82 cvs 2027: else if (!strncasecmp (cssRule, "small-caption", 13))
1.1 cvs 2028: ;
1.82 cvs 2029: else if (!strncasecmp (cssRule, "status-bar", 10))
1.1 cvs 2030: ;
2031: else
1.43 cvs 2032: {
1.133 vatton 2033: while (*cssRule != ';' && *cssRule != EOS)
1.43 cvs 2034: {
1.72 cvs 2035: ptr = cssRule;
1.93 vatton 2036: skippedNL = NewLineSkipped;
1.72 cvs 2037: cssRule = ParseCSSFontStyle (element, tsch, context, cssRule, css, isHTML);
2038: if (ptr == cssRule)
1.93 vatton 2039: {
2040: NewLineSkipped = skippedNL;
2041: cssRule = ParseCSSFontVariant (element, tsch, context, cssRule, css, isHTML);
2042: }
1.72 cvs 2043: if (ptr == cssRule)
1.93 vatton 2044: {
2045: NewLineSkipped = skippedNL;
2046: cssRule = ParseCSSFontWeight (element, tsch, context, cssRule, css, isHTML);
2047: }
1.72 cvs 2048: if (ptr == cssRule)
1.93 vatton 2049: {
2050: NewLineSkipped = skippedNL;
2051: cssRule = ParseCSSFontSize (element, tsch, context, cssRule, css, isHTML);
2052: }
1.72 cvs 2053: if (ptr == cssRule)
1.93 vatton 2054: {
2055: NewLineSkipped = skippedNL;
2056: cssRule = ParseCSSFontFamily (element, tsch, context, cssRule, css, isHTML);
2057: }
1.99 vatton 2058: if (ptr == cssRule)
2059: cssRule = SkipValue (cssRule, TRUE);
1.82 cvs 2060: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 2061: }
2062: }
2063: return (cssRule);
1.1 cvs 2064: }
2065:
2066: /*----------------------------------------------------------------------
1.59 cvs 2067: ParseCSSTextDecoration: parse a CSS text decor string
2068: we expect the input string describing the attribute to be
1.109 cvs 2069: underline, overline, line-through, blink or none.
1.1 cvs 2070: ----------------------------------------------------------------------*/
1.79 cvs 2071: static char *ParseCSSTextDecoration (Element element, PSchema tsch,
2072: PresentationContext context, char *cssRule,
2073: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2074: {
2075: PresentationValue decor;
2076:
2077: decor.typed_data.value = 0;
2078: decor.typed_data.unit = STYLE_UNIT_REL;
2079: decor.typed_data.real = FALSE;
1.82 cvs 2080: cssRule = SkipBlanksAndComments (cssRule);
1.142 quint 2081: if (!strncasecmp (cssRule, "none", strlen ("none")))
2082: {
2083: decor.typed_data.value = NoUnderline;
2084: cssRule = SkipWord (cssRule);
2085: }
2086: else if (!strncasecmp (cssRule, "underline", strlen ("underline")))
1.1 cvs 2087: {
2088: decor.typed_data.value = Underline;
2089: cssRule = SkipWord (cssRule);
2090: }
1.82 cvs 2091: else if (!strncasecmp (cssRule, "overline", strlen ("overline")))
1.1 cvs 2092: {
2093: decor.typed_data.value = Overline;
2094: cssRule = SkipWord (cssRule);
2095: }
1.82 cvs 2096: else if (!strncasecmp (cssRule, "line-through", strlen ("line-through")))
1.1 cvs 2097: {
2098: decor.typed_data.value = CrossOut;
2099: cssRule = SkipWord (cssRule);
2100: }
1.82 cvs 2101: else if (!strncasecmp (cssRule, "blink", strlen ("blink")))
1.1 cvs 2102: {
1.109 cvs 2103: /* the blink text-decoration attribute is not supported */
1.1 cvs 2104: cssRule = SkipWord (cssRule);
2105: }
1.142 quint 2106: else if (!strncasecmp (cssRule, "inherit", 7))
1.1 cvs 2107: {
1.142 quint 2108: cssRule = SkipWord (cssRule);
2109: return (cssRule);
1.1 cvs 2110: }
2111: else
2112: {
1.86 cvs 2113: CSSParseError ("Invalid text decoration", cssRule);
1.1 cvs 2114: return (cssRule);
2115: }
2116:
2117: /*
2118: * install the new presentation.
2119: */
1.116 vatton 2120: if (decor.typed_data.value && DoApply)
1.1 cvs 2121: {
1.117 vatton 2122: if (tsch)
2123: cssRule = CheckImportantRule (cssRule, context);
1.1 cvs 2124: TtaSetStylePresentation (PRUnderline, element, tsch, context, decor);
2125: }
2126: return (cssRule);
2127: }
2128:
2129: /*----------------------------------------------------------------------
1.59 cvs 2130: ParseCSSHeight: parse a CSS height attribute
1.1 cvs 2131: ----------------------------------------------------------------------*/
1.79 cvs 2132: static char *ParseCSSHeight (Element element, PSchema tsch,
1.93 vatton 2133: PresentationContext context, char *cssRule,
2134: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2135: {
1.117 vatton 2136: PresentationValue val;
1.93 vatton 2137:
1.117 vatton 2138: cssRule = SkipBlanksAndComments (cssRule);
2139: /* first parse the attribute string */
2140: if (!strcasecmp (cssRule, "auto"))
2141: cssRule = SkipWord (cssRule);
2142: else
2143: {
2144: cssRule = ParseCSSUnit (cssRule, &val);
2145: if (val.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
2146: {
2147: if (tsch)
2148: cssRule = CheckImportantRule (cssRule, context);
2149: /* install the new presentation */
2150: TtaSetStylePresentation (PRHeight, element, tsch, context, val);
2151: }
2152: }
2153: return (cssRule);
1.1 cvs 2154: }
2155:
2156: /*----------------------------------------------------------------------
1.59 cvs 2157: ParseCSSWidth: parse a CSS width attribute
1.1 cvs 2158: ----------------------------------------------------------------------*/
1.79 cvs 2159: static char *ParseCSSWidth (Element element, PSchema tsch,
1.78 cvs 2160: PresentationContext context,
1.79 cvs 2161: char *cssRule, CSSInfoPtr css,
1.78 cvs 2162: ThotBool isHTML)
1.1 cvs 2163: {
1.117 vatton 2164: PresentationValue val;
1.93 vatton 2165:
1.117 vatton 2166: cssRule = SkipBlanksAndComments (cssRule);
2167: /* first parse the attribute string */
2168: if (!strcasecmp (cssRule, "auto"))
2169: cssRule = SkipWord (cssRule);
2170: else
2171: {
2172: cssRule = ParseCSSUnit (cssRule, &val);
2173: if (val.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
2174: {
2175: if (tsch)
2176: cssRule = CheckImportantRule (cssRule, context);
2177: /* install the new presentation */
2178: TtaSetStylePresentation (PRWidth, element, tsch, context, val);
2179: }
2180: }
2181: return (cssRule);
1.1 cvs 2182: }
2183:
2184: /*----------------------------------------------------------------------
1.59 cvs 2185: ParseCSSMarginTop: parse a CSS margin-top attribute
1.1 cvs 2186: ----------------------------------------------------------------------*/
1.79 cvs 2187: static char *ParseCSSMarginTop (Element element, PSchema tsch,
1.78 cvs 2188: PresentationContext context,
1.79 cvs 2189: char *cssRule, CSSInfoPtr css,
1.78 cvs 2190: ThotBool isHTML)
1.1 cvs 2191: {
2192: PresentationValue margin;
2193:
1.82 cvs 2194: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 2195: /* first parse the attribute string */
2196: cssRule = ParseCSSUnit (cssRule, &margin);
1.116 vatton 2197: if (margin.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.117 vatton 2198: {
2199: if (tsch)
2200: cssRule = CheckImportantRule (cssRule, context);
2201: TtaSetStylePresentation (PRMarginTop, element, tsch, context, margin);
2202: }
1.1 cvs 2203: return (cssRule);
2204: }
2205:
2206: /*----------------------------------------------------------------------
1.59 cvs 2207: ParseCSSMarginBottom: parse a CSS margin-bottom attribute
1.1 cvs 2208: ----------------------------------------------------------------------*/
1.79 cvs 2209: static char *ParseCSSMarginBottom (Element element, PSchema tsch,
1.78 cvs 2210: PresentationContext context,
1.79 cvs 2211: char *cssRule, CSSInfoPtr css,
1.78 cvs 2212: ThotBool isHTML)
1.1 cvs 2213: {
2214: PresentationValue margin;
2215:
1.82 cvs 2216: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 2217: /* first parse the attribute string */
2218: cssRule = ParseCSSUnit (cssRule, &margin);
1.116 vatton 2219: if (margin.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.117 vatton 2220: {
2221: if (tsch)
2222: cssRule = CheckImportantRule (cssRule, context);
2223: TtaSetStylePresentation (PRMarginBottom, element, tsch, context, margin);
2224: }
1.1 cvs 2225: return (cssRule);
2226: }
2227:
2228: /*----------------------------------------------------------------------
1.59 cvs 2229: ParseCSSMarginLeft: parse a CSS margin-left attribute string
1.1 cvs 2230: ----------------------------------------------------------------------*/
1.79 cvs 2231: static char *ParseCSSMarginLeft (Element element, PSchema tsch,
1.78 cvs 2232: PresentationContext context,
1.79 cvs 2233: char *cssRule, CSSInfoPtr css,
1.78 cvs 2234: ThotBool isHTML)
1.1 cvs 2235: {
2236: PresentationValue margin;
2237:
1.82 cvs 2238: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 2239: /* first parse the attribute string */
2240: cssRule = ParseCSSUnit (cssRule, &margin);
1.116 vatton 2241: if (margin.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.117 vatton 2242: {
2243: if (tsch)
2244: cssRule = CheckImportantRule (cssRule, context);
2245: TtaSetStylePresentation (PRMarginLeft, element, tsch, context, margin);
2246: }
1.1 cvs 2247: return (cssRule);
2248: }
2249:
2250: /*----------------------------------------------------------------------
1.59 cvs 2251: ParseCSSMarginRight: parse a CSS margin-right attribute string
1.1 cvs 2252: ----------------------------------------------------------------------*/
1.79 cvs 2253: static char *ParseCSSMarginRight (Element element, PSchema tsch,
1.78 cvs 2254: PresentationContext context,
1.79 cvs 2255: char *cssRule, CSSInfoPtr css,
1.78 cvs 2256: ThotBool isHTML)
1.1 cvs 2257: {
2258: PresentationValue margin;
2259:
1.82 cvs 2260: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 2261: /* first parse the attribute string */
2262: cssRule = ParseCSSUnit (cssRule, &margin);
1.116 vatton 2263: if (margin.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.117 vatton 2264: {
2265: if (tsch)
2266: cssRule = CheckImportantRule (cssRule, context);
2267: TtaSetStylePresentation (PRMarginRight, element, tsch, context, margin);
2268: }
1.1 cvs 2269: return (cssRule);
2270: }
2271:
2272: /*----------------------------------------------------------------------
1.59 cvs 2273: ParseCSSMargin: parse a CSS margin attribute string
1.1 cvs 2274: ----------------------------------------------------------------------*/
1.79 cvs 2275: static char *ParseCSSMargin (Element element, PSchema tsch,
1.78 cvs 2276: PresentationContext context,
1.79 cvs 2277: char *cssRule, CSSInfoPtr css,
1.78 cvs 2278: ThotBool isHTML)
1.1 cvs 2279: {
1.79 cvs 2280: char *ptrT, *ptrR, *ptrB, *ptrL;
1.93 vatton 2281: int skippedNL;
1.1 cvs 2282:
1.82 cvs 2283: ptrT = SkipBlanksAndComments (cssRule);
1.1 cvs 2284: /* First parse Margin-Top */
2285: ptrR = ParseCSSMarginTop (element, tsch, context, ptrT, css, isHTML);
1.82 cvs 2286: ptrR = SkipBlanksAndComments (ptrR);
2287: if (*ptrR == ';' || *ptrR == EOS || *ptrR == ',')
1.1 cvs 2288: {
1.93 vatton 2289: skippedNL = NewLineSkipped;
1.1 cvs 2290: cssRule = ptrR;
2291: /* apply the Margin-Top to all */
2292: ptrR = ParseCSSMarginRight (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 2293: NewLineSkipped = skippedNL;
1.1 cvs 2294: ptrR = ParseCSSMarginBottom (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 2295: NewLineSkipped = skippedNL;
1.1 cvs 2296: ptrR = ParseCSSMarginLeft (element, tsch, context, ptrT, css, isHTML);
2297: }
2298: else
2299: {
2300: /* parse Margin-Right */
2301: ptrB = ParseCSSMarginRight (element, tsch, context, ptrR, css, isHTML);
1.82 cvs 2302: ptrB = SkipBlanksAndComments (ptrB);
2303: if (*ptrB == ';' || *ptrB == EOS || *ptrB == ',')
1.1 cvs 2304: {
1.93 vatton 2305: skippedNL = NewLineSkipped;
1.1 cvs 2306: cssRule = ptrB;
2307: /* apply the Margin-Top to Margin-Bottom */
2308: ptrB = ParseCSSMarginBottom (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 2309: NewLineSkipped = skippedNL;
1.1 cvs 2310: /* apply the Margin-Right to Margin-Left */
2311: ptrB = ParseCSSMarginLeft (element, tsch, context, ptrR, css, isHTML);
2312: }
2313: else
2314: {
2315: /* parse Margin-Bottom */
2316: ptrL = ParseCSSMarginBottom (element, tsch, context, ptrB, css, isHTML);
1.82 cvs 2317: ptrL = SkipBlanksAndComments (ptrL);
2318: if (*ptrL == ';' || *ptrL == EOS || *ptrL == ',')
1.1 cvs 2319: {
2320: cssRule = ptrL;
2321: /* apply the Margin-Right to Margin-Left */
2322: ptrL = ParseCSSMarginLeft (element, tsch, context, ptrR, css, isHTML);
2323: }
2324: else
2325: /* parse Margin-Left */
2326: cssRule = ParseCSSMarginLeft (element, tsch, context, ptrL, css, isHTML);
1.82 cvs 2327: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 2328: }
2329: }
2330: return (cssRule);
2331: }
2332:
2333: /*----------------------------------------------------------------------
1.59 cvs 2334: ParseCSSPaddingTop: parse a CSS PaddingTop attribute string
1.1 cvs 2335: ----------------------------------------------------------------------*/
1.79 cvs 2336: static char *ParseCSSPaddingTop (Element element, PSchema tsch,
1.78 cvs 2337: PresentationContext context,
1.79 cvs 2338: char *cssRule, CSSInfoPtr css,
1.78 cvs 2339: ThotBool isHTML)
1.1 cvs 2340: {
1.43 cvs 2341: PresentationValue padding;
2342:
1.82 cvs 2343: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 2344: /* first parse the attribute string */
2345: cssRule = ParseCSSUnit (cssRule, &padding);
1.116 vatton 2346: if (padding.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.117 vatton 2347: {
2348: if (tsch)
2349: cssRule = CheckImportantRule (cssRule, context);
2350: TtaSetStylePresentation (PRPaddingTop, element, tsch, context, padding);
2351: }
1.1 cvs 2352: return (cssRule);
2353: }
2354:
2355: /*----------------------------------------------------------------------
1.59 cvs 2356: ParseCSSPaddingBottom: parse a CSS PaddingBottom attribute string
1.1 cvs 2357: ----------------------------------------------------------------------*/
1.79 cvs 2358: static char *ParseCSSPaddingBottom (Element element, PSchema tsch,
1.78 cvs 2359: PresentationContext context,
1.79 cvs 2360: char *cssRule, CSSInfoPtr css,
1.78 cvs 2361: ThotBool isHTML)
1.1 cvs 2362: {
1.43 cvs 2363: PresentationValue padding;
2364:
1.82 cvs 2365: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 2366: /* first parse the attribute string */
2367: cssRule = ParseCSSUnit (cssRule, &padding);
1.116 vatton 2368: if (padding.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.117 vatton 2369: {
2370: if (tsch)
2371: cssRule = CheckImportantRule (cssRule, context);
2372: TtaSetStylePresentation (PRPaddingBottom, element, tsch, context, padding);
2373: }
1.1 cvs 2374: return (cssRule);
2375: }
2376:
2377: /*----------------------------------------------------------------------
1.59 cvs 2378: ParseCSSPaddingLeft: parse a CSS PaddingLeft attribute string.
1.1 cvs 2379: ----------------------------------------------------------------------*/
1.79 cvs 2380: static char *ParseCSSPaddingLeft (Element element, PSchema tsch,
1.78 cvs 2381: PresentationContext context,
1.79 cvs 2382: char *cssRule, CSSInfoPtr css,
1.78 cvs 2383: ThotBool isHTML)
1.1 cvs 2384: {
1.43 cvs 2385: PresentationValue padding;
2386:
1.82 cvs 2387: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 2388: /* first parse the attribute string */
2389: cssRule = ParseCSSUnit (cssRule, &padding);
1.116 vatton 2390: if (padding.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.117 vatton 2391: {
2392: if (tsch)
2393: cssRule = CheckImportantRule (cssRule, context);
1.43 cvs 2394: TtaSetStylePresentation (PRPaddingLeft, element, tsch, context, padding);
1.117 vatton 2395: }
1.1 cvs 2396: return (cssRule);
2397: }
2398:
2399: /*----------------------------------------------------------------------
1.59 cvs 2400: ParseCSSPaddingRight: parse a CSS PaddingRight attribute string.
1.1 cvs 2401: ----------------------------------------------------------------------*/
1.79 cvs 2402: static char *ParseCSSPaddingRight (Element element, PSchema tsch,
1.78 cvs 2403: PresentationContext context,
1.79 cvs 2404: char *cssRule, CSSInfoPtr css,
1.78 cvs 2405: ThotBool isHTML)
1.1 cvs 2406: {
1.43 cvs 2407: PresentationValue padding;
2408:
1.82 cvs 2409: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 2410: /* first parse the attribute string */
2411: cssRule = ParseCSSUnit (cssRule, &padding);
1.116 vatton 2412: if (padding.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.117 vatton 2413: {
2414: if (tsch)
2415: cssRule = CheckImportantRule (cssRule, context);
1.43 cvs 2416: TtaSetStylePresentation (PRPaddingRight, element, tsch, context, padding);
1.117 vatton 2417: }
1.1 cvs 2418: return (cssRule);
2419: }
2420:
2421: /*----------------------------------------------------------------------
1.59 cvs 2422: ParseCSSPadding: parse a CSS padding attribute string.
1.1 cvs 2423: ----------------------------------------------------------------------*/
1.79 cvs 2424: static char *ParseCSSPadding (Element element, PSchema tsch,
1.78 cvs 2425: PresentationContext context,
1.79 cvs 2426: char *cssRule, CSSInfoPtr css,
1.78 cvs 2427: ThotBool isHTML)
1.1 cvs 2428: {
1.79 cvs 2429: char *ptrT, *ptrR, *ptrB, *ptrL;
1.93 vatton 2430: int skippedNL;
1.43 cvs 2431:
1.82 cvs 2432: ptrT = SkipBlanksAndComments (cssRule);
1.43 cvs 2433: /* First parse Padding-Top */
2434: ptrR = ParseCSSPaddingTop (element, tsch, context, ptrT, css, isHTML);
1.82 cvs 2435: ptrR = SkipBlanksAndComments (ptrR);
2436: if (*ptrR == ';' || *ptrR == EOS || *ptrR == ',')
1.43 cvs 2437: {
1.93 vatton 2438: skippedNL = NewLineSkipped;
1.43 cvs 2439: cssRule = ptrR;
2440: /* apply the Padding-Top to all */
2441: ptrR = ParseCSSPaddingRight (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 2442: NewLineSkipped = skippedNL;
1.43 cvs 2443: ptrR = ParseCSSPaddingBottom (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 2444: NewLineSkipped = skippedNL;
1.43 cvs 2445: ptrR = ParseCSSPaddingLeft (element, tsch, context, ptrT, css, isHTML);
2446: }
2447: else
2448: {
2449: /* parse Padding-Right */
2450: ptrB = ParseCSSPaddingRight (element, tsch, context, ptrR, css, isHTML);
1.82 cvs 2451: ptrB = SkipBlanksAndComments (ptrB);
2452: if (*ptrB == ';' || *ptrB == EOS || *ptrB == ',')
1.43 cvs 2453: {
1.93 vatton 2454: skippedNL = NewLineSkipped;
1.43 cvs 2455: cssRule = ptrB;
2456: /* apply the Padding-Top to Padding-Bottom */
2457: ptrB = ParseCSSPaddingBottom (element, tsch, context, ptrT, css, isHTML);
1.93 vatton 2458: NewLineSkipped = skippedNL;
1.43 cvs 2459: /* apply the Padding-Right to Padding-Left */
2460: ptrB = ParseCSSPaddingLeft (element, tsch, context, ptrR, css, isHTML);
2461: }
2462: else
2463: {
2464: /* parse Padding-Bottom */
2465: ptrL = ParseCSSPaddingBottom (element, tsch, context, ptrB, css, isHTML);
1.82 cvs 2466: ptrL = SkipBlanksAndComments (ptrL);
2467: if (*ptrL == ';' || *ptrL == EOS || *ptrL == ',')
1.43 cvs 2468: {
2469: cssRule = ptrL;
2470: /* apply the Padding-Right to Padding-Left */
2471: ptrL = ParseCSSPaddingLeft (element, tsch, context, ptrR, css, isHTML);
2472: }
2473: else
2474: /* parse Padding-Left */
2475: cssRule = ParseCSSPaddingLeft (element, tsch, context, ptrL, css, isHTML);
1.82 cvs 2476: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 2477: }
2478: }
1.1 cvs 2479: return (cssRule);
2480: }
2481:
2482: /*----------------------------------------------------------------------
1.59 cvs 2483: ParseCSSForeground: parse a CSS foreground attribute
1.1 cvs 2484: ----------------------------------------------------------------------*/
1.79 cvs 2485: static char *ParseCSSForeground (Element element, PSchema tsch,
1.78 cvs 2486: PresentationContext context,
1.79 cvs 2487: char *cssRule,
1.78 cvs 2488: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2489: {
1.117 vatton 2490: PresentationValue best;
1.1 cvs 2491:
1.117 vatton 2492: cssRule = ParseCSSColor (cssRule, &best);
2493: if (best.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
2494: {
2495: if (tsch)
2496: cssRule = CheckImportantRule (cssRule, context);
2497: /* install the new presentation */
2498: TtaSetStylePresentation (PRForeground, element, tsch, context, best);
2499: }
1.1 cvs 2500: return (cssRule);
2501: }
2502:
2503: /*----------------------------------------------------------------------
1.59 cvs 2504: ParseCSSBackgroundColor: parse a CSS background color attribute
1.1 cvs 2505: ----------------------------------------------------------------------*/
1.79 cvs 2506: static char *ParseCSSBackgroundColor (Element element, PSchema tsch,
1.78 cvs 2507: PresentationContext context,
1.79 cvs 2508: char *cssRule,
1.78 cvs 2509: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2510: {
2511: PresentationValue best;
2512:
2513: best.typed_data.unit = STYLE_UNIT_INVALID;
2514: best.typed_data.real = FALSE;
1.82 cvs 2515: if (!strncasecmp (cssRule, "transparent", strlen ("transparent")))
1.1 cvs 2516: {
2517: best.typed_data.value = STYLE_PATTERN_NONE;
2518: best.typed_data.unit = STYLE_UNIT_REL;
1.116 vatton 2519: if (DoApply)
1.117 vatton 2520: {
2521: if (tsch)
2522: cssRule = CheckImportantRule (cssRule, context);
2523: TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
2524: }
1.65 cvs 2525: cssRule = SkipWord (cssRule);
1.1 cvs 2526: }
2527: else
2528: {
2529: cssRule = ParseCSSColor (cssRule, &best);
1.116 vatton 2530: if (best.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.1 cvs 2531: {
1.117 vatton 2532: if (tsch)
2533: cssRule = CheckImportantRule (cssRule, context);
1.1 cvs 2534: /* install the new presentation. */
2535: TtaSetStylePresentation (PRBackground, element, tsch, context, best);
1.59 cvs 2536: /* thot specificity: need to set fill pattern for background color */
1.1 cvs 2537: best.typed_data.value = STYLE_PATTERN_BACKGROUND;
2538: best.typed_data.unit = STYLE_UNIT_REL;
2539: TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
2540: best.typed_data.value = 1;
2541: best.typed_data.unit = STYLE_UNIT_REL;
2542: TtaSetStylePresentation (PRShowBox, element, tsch, context, best);
2543: }
2544: }
2545:
2546: /* restore the refered element */
2547: return (cssRule);
2548: }
2549:
1.63 cvs 2550:
2551: /*----------------------------------------------------------------------
1.65 cvs 2552: ParseSVGStroke: parse a SVG stroke property
2553: ----------------------------------------------------------------------*/
1.79 cvs 2554: static char *ParseSVGStroke (Element element, PSchema tsch,
2555: PresentationContext context, char *cssRule,
2556: CSSInfoPtr css, ThotBool isHTML)
1.65 cvs 2557: {
2558: PresentationValue best;
2559:
2560: best.typed_data.unit = STYLE_UNIT_INVALID;
2561: best.typed_data.real = FALSE;
1.82 cvs 2562: if (!strncasecmp (cssRule, "none", 4))
1.65 cvs 2563: {
2564: best.typed_data.value = -2; /* -2 means transparent */
2565: best.typed_data.unit = STYLE_UNIT_REL;
1.116 vatton 2566: if (DoApply)
1.117 vatton 2567: {
2568: if (tsch)
2569: cssRule = CheckImportantRule (cssRule, context);
2570: TtaSetStylePresentation (PRForeground, element, tsch, context, best);
2571: }
1.65 cvs 2572: cssRule = SkipWord (cssRule);
2573: }
2574: else
2575: {
2576: cssRule = ParseCSSColor (cssRule, &best);
1.116 vatton 2577: if (best.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.117 vatton 2578: {
2579: if (tsch)
2580: cssRule = CheckImportantRule (cssRule, context);
2581: /* install the new presentation */
2582: TtaSetStylePresentation (PRForeground, element, tsch, context, best);
2583: }
1.65 cvs 2584: }
2585: return (cssRule);
2586: }
2587:
2588: /*----------------------------------------------------------------------
1.63 cvs 2589: ParseSVGFill: parse a SVG fill property
2590: ----------------------------------------------------------------------*/
1.79 cvs 2591: static char *ParseSVGFill (Element element, PSchema tsch,
2592: PresentationContext context, char *cssRule,
2593: CSSInfoPtr css, ThotBool isHTML)
1.63 cvs 2594: {
2595: PresentationValue best;
2596:
2597: best.typed_data.unit = STYLE_UNIT_INVALID;
2598: best.typed_data.real = FALSE;
1.82 cvs 2599: if (!strncasecmp (cssRule, "none", 4))
1.63 cvs 2600: {
2601: best.typed_data.value = STYLE_PATTERN_NONE;
2602: best.typed_data.unit = STYLE_UNIT_REL;
1.116 vatton 2603: if (DoApply)
1.117 vatton 2604: {
2605: if (tsch)
2606: cssRule = CheckImportantRule (cssRule, context);
2607: TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
2608: }
1.65 cvs 2609: cssRule = SkipWord (cssRule);
1.63 cvs 2610: }
2611: else
2612: {
2613: cssRule = ParseCSSColor (cssRule, &best);
1.116 vatton 2614: if (best.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.63 cvs 2615: {
1.117 vatton 2616: if (tsch)
2617: cssRule = CheckImportantRule (cssRule, context);
1.63 cvs 2618: /* install the new presentation. */
2619: TtaSetStylePresentation (PRBackground, element, tsch, context, best);
2620: /* thot specificity: need to set fill pattern for background color */
2621: best.typed_data.value = STYLE_PATTERN_BACKGROUND;
2622: best.typed_data.unit = STYLE_UNIT_REL;
2623: TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
2624: }
2625: }
2626: return (cssRule);
2627: }
2628:
1.1 cvs 2629: /*----------------------------------------------------------------------
1.59 cvs 2630: ParseCSSBackgroundImageCallback: Callback called asynchronously by
2631: FetchImage when a background image has been fetched.
1.1 cvs 2632: ----------------------------------------------------------------------*/
1.82 cvs 2633: void ParseCSSBackgroundImageCallback (Document doc, Element element,
2634: char *file, void *extra)
1.1 cvs 2635: {
1.82 cvs 2636: DisplayMode dispMode;
2637: BackgroundImageCallbackPtr callblock;
2638: Element el;
2639: PSchema tsch;
2640: PresentationContext context;
2641: PresentationValue image;
2642: PresentationValue value;
1.1 cvs 2643:
1.82 cvs 2644: callblock = (BackgroundImageCallbackPtr) extra;
1.34 cvs 2645: if (callblock == NULL)
2646: return;
1.1 cvs 2647:
1.34 cvs 2648: /* avoid too many redisplay */
2649: dispMode = TtaGetDisplayMode (doc);
2650: if (dispMode == DisplayImmediately)
2651: TtaSetDisplayMode (doc, DeferredDisplay);
2652:
2653: el = callblock->el;
2654: tsch = callblock->tsch;
2655: context = &callblock->context.specific;
2656:
2657: /* Ok the image was fetched, finish the background-image handling */
2658: image.pointer = file;
2659: TtaSetStylePresentation (PRBackgroundPicture, el, tsch, context, image);
1.1 cvs 2660:
1.70 cvs 2661: /* enforce the showbox */
1.34 cvs 2662: value.typed_data.value = 1;
2663: value.typed_data.unit = STYLE_UNIT_REL;
2664: value.typed_data.real = FALSE;
2665: TtaSetStylePresentation (PRShowBox, el, tsch, context, value);
2666:
2667: TtaFreeMemory (callblock);
2668: /* restore the display mode */
2669: if (dispMode == DisplayImmediately)
2670: TtaSetDisplayMode (doc, dispMode);
1.1 cvs 2671: }
2672:
2673:
2674: /*----------------------------------------------------------------------
2675: GetCSSBackgroundURL searches a CSS BackgroundImage url within
2676: the styleString.
2677: Returns NULL or a new allocated url string.
2678: ----------------------------------------------------------------------*/
1.79 cvs 2679: char *GetCSSBackgroundURL (char *styleString)
1.1 cvs 2680: {
1.79 cvs 2681: char *b, *e, *ptr;
2682: int len;
1.1 cvs 2683:
2684: ptr = NULL;
1.82 cvs 2685: b = strstr (styleString, "url");
1.1 cvs 2686: if (b != NULL)
2687: {
2688: b += 3;
1.82 cvs 2689: b = SkipBlanksAndComments (b);
2690: if (*b == '(')
1.1 cvs 2691: {
2692: b++;
1.82 cvs 2693: b = SkipBlanksAndComments (b);
1.1 cvs 2694: /*** Caution: Strings can either be written with double quotes or
2695: with single quotes. Only double quotes are handled here.
2696: Escaped quotes are not handled. See function SkipQuotedString */
1.82 cvs 2697: if (*b == '"')
1.1 cvs 2698: {
2699: b++;
2700: /* search the url end */
2701: e = b;
1.82 cvs 2702: while (*e != EOS && *e != '"')
1.1 cvs 2703: e++;
2704: }
2705: else
2706: {
2707: /* search the url end */
2708: e = b;
1.82 cvs 2709: while (*e != EOS && *e != ')')
1.1 cvs 2710: e++;
2711: }
1.82 cvs 2712: if (*e != EOS)
1.1 cvs 2713: {
2714: len = (int)(e - b);
1.82 cvs 2715: ptr = (char*) TtaGetMemory (len+1);
2716: strncpy (ptr, b, len);
2717: ptr[len] = EOS;
1.1 cvs 2718: }
2719: }
2720: }
2721: return (ptr);
2722: }
2723:
2724:
2725: /*----------------------------------------------------------------------
1.59 cvs 2726: ParseCSSBackgroundImage: parse a CSS BackgroundImage attribute string.
1.1 cvs 2727: ----------------------------------------------------------------------*/
1.79 cvs 2728: static char *ParseCSSBackgroundImage (Element element, PSchema tsch,
2729: PresentationContext context,
2730: char *cssRule, CSSInfoPtr css,
2731: ThotBool isHTML)
1.1 cvs 2732: {
1.49 cvs 2733: Element el;
2734: GenericContext gblock;
1.71 cvs 2735: PresentationContext sblock;
1.1 cvs 2736: BackgroundImageCallbackPtr callblock;
1.49 cvs 2737: PresentationValue image, value;
1.79 cvs 2738: char *url;
1.82 cvs 2739: char *bg_image;
1.79 cvs 2740: char saved;
2741: char *base;
2742: char tempname[MAX_LENGTH];
2743: char imgname[MAX_LENGTH];
1.1 cvs 2744:
1.147 ! vatton 2745: el = element;
1.1 cvs 2746: url = NULL;
1.82 cvs 2747: cssRule = SkipBlanksAndComments (cssRule);
2748: if (!strncasecmp (cssRule, "url", 3))
1.1 cvs 2749: {
2750: cssRule += 3;
1.82 cvs 2751: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 2752: if (*cssRule == '(')
2753: {
2754: cssRule++;
1.82 cvs 2755: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 2756: /*** Caution: Strings can either be written with double quotes or
2757: with single quotes. Only double quotes are handled here.
2758: Escaped quotes are not handled. See function SkipQuotedString */
2759: if (*cssRule == '"')
2760: {
2761: cssRule++;
2762: base = cssRule;
1.82 cvs 2763: while (*cssRule != EOS && *cssRule != '"')
1.1 cvs 2764: cssRule++;
2765: }
2766: else
2767: {
2768: base = cssRule;
2769: while (*cssRule != EOS && *cssRule != ')')
2770: cssRule++;
2771: }
2772: saved = *cssRule;
1.82 cvs 2773: *cssRule = EOS;
2774: url = TtaStrdup (base);
1.1 cvs 2775: *cssRule = saved;
2776: if (saved == '"')
2777: /* we need to skip two characters */
2778: cssRule++;
2779: }
2780: cssRule++;
2781:
2782: if (context->destroy)
2783: {
2784: /* remove the background image PRule */
2785: image.pointer = NULL;
2786: TtaSetStylePresentation (PRBackgroundPicture, element, tsch, context, image);
2787: if (TtaGetStylePresentation (PRFillPattern, element, tsch, context, &value) < 0)
2788: {
2789: /* there is no FillPattern rule -> remove ShowBox rule */
2790: value.typed_data.value = 1;
2791: value.typed_data.unit = STYLE_UNIT_REL;
2792: value.typed_data.real = FALSE;
2793: TtaSetStylePresentation (PRShowBox, element, tsch, context, value);
2794: }
2795: }
2796: else if (url)
2797: {
1.30 cvs 2798: bg_image = TtaGetEnvString ("ENABLE_BG_IMAGES");
1.82 cvs 2799: if (bg_image == NULL || !strcasecmp (bg_image, "yes"))
1.1 cvs 2800: {
2801: callblock = (BackgroundImageCallbackPtr) TtaGetMemory(sizeof(BackgroundImageCallbackBlock));
2802: if (callblock != NULL)
2803: {
2804: callblock->el = element;
2805: callblock->tsch = tsch;
2806: if (element == NULL)
1.18 cvs 2807: {
2808: gblock = (GenericContext) context;
2809: memcpy (&callblock->context.generic, gblock,
2810: sizeof (GenericContextBlock));
2811: }
2812: else
2813: {
2814: sblock = context;
2815: memcpy (&callblock->context.specific, sblock,
2816: sizeof(PresentationContextBlock));
2817: }
2818:
2819: /* check if the image url is related to an external CSS */
2820: if (css != NULL && css->category == CSS_EXTERNAL_STYLE)
2821: {
2822: NormalizeURL (url, 0, tempname, imgname, css->url);
2823: /* fetch and display background image of element */
1.49 cvs 2824: FetchImage (context->doc, el, tempname, AMAYA_LOAD_IMAGE, ParseCSSBackgroundImageCallback, callblock);
1.18 cvs 2825: }
2826: else
1.49 cvs 2827: FetchImage (context->doc, el, url, AMAYA_LOAD_IMAGE, ParseCSSBackgroundImageCallback, callblock);
1.18 cvs 2828: }
2829: }
2830:
2831: if (url)
2832: TtaFreeMemory (url);
2833: }
2834: }
2835: return (cssRule);
2836: }
2837:
2838: /*----------------------------------------------------------------------
1.59 cvs 2839: ParseCSSBackgroundRepeat: parse a CSS BackgroundRepeat attribute string.
1.18 cvs 2840: ----------------------------------------------------------------------*/
1.79 cvs 2841: static char *ParseCSSBackgroundRepeat (Element element, PSchema tsch,
1.97 vatton 2842: PresentationContext context,
2843: char *cssRule, CSSInfoPtr css, ThotBool isHTML)
1.18 cvs 2844: {
2845: PresentationValue repeat;
2846:
2847: repeat.typed_data.value = STYLE_REALSIZE;
2848: repeat.typed_data.unit = STYLE_UNIT_REL;
2849: repeat.typed_data.real = FALSE;
1.82 cvs 2850: cssRule = SkipBlanksAndComments (cssRule);
2851: if (!strncasecmp (cssRule, "no-repeat", 9))
1.18 cvs 2852: repeat.typed_data.value = STYLE_REALSIZE;
1.82 cvs 2853: else if (!strncasecmp (cssRule, "repeat-y", 8))
1.18 cvs 2854: repeat.typed_data.value = STYLE_VREPEAT;
1.82 cvs 2855: else if (!strncasecmp (cssRule, "repeat-x", 8))
1.18 cvs 2856: repeat.typed_data.value = STYLE_HREPEAT;
1.82 cvs 2857: else if (!strncasecmp (cssRule, "repeat", 6))
1.18 cvs 2858: repeat.typed_data.value = STYLE_REPEAT;
2859: else
2860: return (cssRule);
2861:
2862: /* install the new presentation */
1.116 vatton 2863: if (DoApply)
1.117 vatton 2864: {
2865: /* check if it's an important rule */
2866: if (tsch)
2867: cssRule = CheckImportantRule (cssRule, context);
2868: TtaSetStylePresentation (PRPictureMode, element, tsch, context, repeat);
2869: }
1.18 cvs 2870: cssRule = SkipWord (cssRule);
1.147 ! vatton 2871: return (cssRule);
1.18 cvs 2872: }
2873:
2874: /*----------------------------------------------------------------------
1.59 cvs 2875: ParseCSSBackgroundAttachment: parse a CSS BackgroundAttachment
1.18 cvs 2876: attribute string.
2877: ----------------------------------------------------------------------*/
1.79 cvs 2878: static char *ParseCSSBackgroundAttachment (Element element, PSchema tsch,
2879: PresentationContext context,
2880: char *cssRule, CSSInfoPtr css,
2881: ThotBool isHTML)
1.18 cvs 2882: {
1.82 cvs 2883: cssRule = SkipBlanksAndComments (cssRule);
2884: if (!strncasecmp (cssRule, "scroll", 6))
1.18 cvs 2885: cssRule = SkipWord (cssRule);
1.82 cvs 2886: else if (!strncasecmp (cssRule, "fixed", 5))
1.18 cvs 2887: cssRule = SkipWord (cssRule);
2888: return (cssRule);
1.1 cvs 2889: }
2890:
2891: /*----------------------------------------------------------------------
1.59 cvs 2892: ParseCSSBackgroundPosition: parse a CSS BackgroundPosition
1.1 cvs 2893: attribute string.
2894: ----------------------------------------------------------------------*/
1.79 cvs 2895: static char *ParseCSSBackgroundPosition (Element element, PSchema tsch,
2896: PresentationContext context,
2897: char *cssRule, CSSInfoPtr css,
2898: ThotBool isHTML)
1.1 cvs 2899: {
1.18 cvs 2900: PresentationValue repeat;
2901: ThotBool ok;
1.1 cvs 2902:
1.82 cvs 2903: cssRule = SkipBlanksAndComments (cssRule);
1.18 cvs 2904: ok = TRUE;
1.82 cvs 2905: if (!strncasecmp (cssRule, "left", 4))
1.18 cvs 2906: cssRule = SkipWord (cssRule);
1.82 cvs 2907: else if (!strncasecmp (cssRule, "right", 5))
1.18 cvs 2908: cssRule = SkipWord (cssRule);
1.82 cvs 2909: else if (!strncasecmp (cssRule, "center", 6))
1.18 cvs 2910: cssRule = SkipWord (cssRule);
1.82 cvs 2911: else if (!strncasecmp (cssRule, "top", 3))
1.18 cvs 2912: cssRule = SkipWord (cssRule);
1.82 cvs 2913: else if (!strncasecmp (cssRule, "bottom", 6))
1.18 cvs 2914: cssRule = SkipWord (cssRule);
1.110 vatton 2915: else if (isdigit (*cssRule) || *cssRule == '.')
1.18 cvs 2916: cssRule = SkipWord (cssRule);
2917: else
2918: ok = FALSE;
2919:
1.116 vatton 2920: if (ok && DoApply)
1.18 cvs 2921: {
2922: /* force realsize for the background image */
2923: repeat.typed_data.value = STYLE_REALSIZE;
2924: repeat.typed_data.unit = STYLE_UNIT_REL;
2925: repeat.typed_data.real = FALSE;
1.117 vatton 2926: /* check if it's an important rule */
2927: if (tsch)
2928: cssRule = CheckImportantRule (cssRule, context);
1.18 cvs 2929: TtaSetStylePresentation (PRPictureMode, element, tsch, context, repeat);
2930: }
2931: return (cssRule);
2932: }
2933:
2934: /*----------------------------------------------------------------------
1.59 cvs 2935: ParseCSSBackground: parse a CSS background attribute
1.18 cvs 2936: ----------------------------------------------------------------------*/
1.79 cvs 2937: static char *ParseCSSBackground (Element element, PSchema tsch,
2938: PresentationContext context, char *cssRule,
2939: CSSInfoPtr css, ThotBool isHTML)
1.18 cvs 2940: {
1.79 cvs 2941: char *ptr;
1.93 vatton 2942: int skippedNL;
1.18 cvs 2943:
1.82 cvs 2944: cssRule = SkipBlanksAndComments (cssRule);
2945: while (*cssRule != ';' && *cssRule != EOS && *cssRule != ',')
1.18 cvs 2946: {
1.71 cvs 2947: /* perhaps a Background Image */
1.82 cvs 2948: if (!strncasecmp (cssRule, "url", 3))
1.63 cvs 2949: cssRule = ParseCSSBackgroundImage (element, tsch, context, cssRule,
2950: css, isHTML);
1.18 cvs 2951: /* perhaps a Background Attachment */
1.82 cvs 2952: else if (!strncasecmp (cssRule, "scroll", 6) ||
2953: !strncasecmp (cssRule, "fixed", 5))
1.63 cvs 2954: cssRule = ParseCSSBackgroundAttachment (element, tsch, context,
2955: cssRule, css, isHTML);
1.18 cvs 2956: /* perhaps a Background Repeat */
1.82 cvs 2957: else if (!strncasecmp (cssRule, "no-repeat", 9) ||
2958: !strncasecmp (cssRule, "repeat-y", 8) ||
2959: !strncasecmp (cssRule, "repeat-x", 8) ||
2960: !strncasecmp (cssRule, "repeat", 6))
2961: cssRule = ParseCSSBackgroundRepeat (element, tsch, context,
2962: cssRule, css, isHTML);
1.18 cvs 2963: /* perhaps a Background Position */
1.82 cvs 2964: else if (!strncasecmp (cssRule, "left", 4) ||
2965: !strncasecmp (cssRule, "right", 5) ||
2966: !strncasecmp (cssRule, "center", 6) ||
2967: !strncasecmp (cssRule, "top", 3) ||
2968: !strncasecmp (cssRule, "bottom", 6) ||
1.110 vatton 2969: isdigit (*cssRule) || *cssRule == '.')
1.63 cvs 2970: cssRule = ParseCSSBackgroundPosition (element, tsch, context,
2971: cssRule, css, isHTML);
1.18 cvs 2972: /* perhaps a Background Color */
2973: else
2974: {
1.93 vatton 2975: skippedNL = NewLineSkipped;
1.18 cvs 2976: /* check if the rule has been found */
2977: ptr = cssRule;
1.82 cvs 2978: cssRule = ParseCSSBackgroundColor (element, tsch, context,
2979: cssRule, css, isHTML);
1.43 cvs 2980: if (ptr == cssRule)
1.93 vatton 2981: {
2982: NewLineSkipped = skippedNL;
2983: /* rule not found */
2984: cssRule = SkipProperty (cssRule);
2985: }
1.18 cvs 2986: }
1.82 cvs 2987: cssRule = SkipBlanksAndComments (cssRule);
1.18 cvs 2988: }
2989: return (cssRule);
2990: }
2991:
1.59 cvs 2992: /*----------------------------------------------------------------------
1.60 cvs 2993: ParseCSSPageBreakBefore: parse a CSS page-break-before attribute
1.59 cvs 2994: ----------------------------------------------------------------------*/
1.79 cvs 2995: static char *ParseCSSPageBreakBefore (Element element, PSchema tsch,
2996: PresentationContext context, char *cssRule,
2997: CSSInfoPtr css, ThotBool isHTML)
1.59 cvs 2998: {
2999: PresentationValue page;
3000:
3001: page.typed_data.unit = STYLE_UNIT_INVALID;
3002: page.typed_data.real = FALSE;
1.82 cvs 3003: cssRule = SkipBlanksAndComments (cssRule);
3004: if (!strncasecmp (cssRule, "auto", 4))
1.59 cvs 3005: {
3006: /*page.typed_data.unit = STYLE_UNIT_REL;*/
3007: page.typed_data.value = STYLE_AUTO;
3008: }
1.82 cvs 3009: else if (!strncasecmp (cssRule, "always", 6))
1.59 cvs 3010: {
3011: page.typed_data.unit = STYLE_UNIT_REL;
3012: page.typed_data.value = STYLE_ALWAYS;
3013: }
1.82 cvs 3014: else if (!strncasecmp (cssRule, "avoid", 5))
1.59 cvs 3015: {
3016: page.typed_data.unit = STYLE_UNIT_REL;
3017: page.typed_data.value = STYLE_AVOID;
3018: }
1.82 cvs 3019: else if (!strncasecmp (cssRule, "left", 4))
1.59 cvs 3020: {
3021: page.typed_data.unit = STYLE_UNIT_REL;
3022: page.typed_data.value = STYLE_PAGELEFT;
3023: }
1.82 cvs 3024: else if (!strncasecmp (cssRule, "right", 5))
1.59 cvs 3025: {
3026: page.typed_data.unit = STYLE_UNIT_REL;
3027: page.typed_data.value = STYLE_PAGERIGHT;
3028: }
1.82 cvs 3029: else if (!strncasecmp (cssRule, "inherit", 7))
1.59 cvs 3030: {
3031: /*page.typed_data.unit = STYLE_UNIT_REL;*/
3032: page.typed_data.value = STYLE_INHERIT;
3033: }
3034: cssRule = SkipWord (cssRule);
3035: /* install the new presentation */
3036: if (page.typed_data.unit == STYLE_UNIT_REL &&
1.116 vatton 3037: page.typed_data.value == STYLE_ALWAYS && DoApply)
1.117 vatton 3038: {
3039: /* check if it's an important rule */
3040: if (tsch)
3041: cssRule = CheckImportantRule (cssRule, context);
3042: TtaSetStylePresentation (PRPageBefore, element, tsch, context, page);
3043: }
1.59 cvs 3044: return (cssRule);
3045: }
3046:
3047: /*----------------------------------------------------------------------
1.60 cvs 3048: ParseCSSPageBreakAfter: parse a CSS page-break-after attribute
1.59 cvs 3049: ----------------------------------------------------------------------*/
1.79 cvs 3050: static char *ParseCSSPageBreakAfter (Element element, PSchema tsch,
3051: PresentationContext context,
3052: char *cssRule, CSSInfoPtr css,
3053: ThotBool isHTML)
1.59 cvs 3054: {
3055: PresentationValue page;
3056:
3057: page.typed_data.unit = STYLE_UNIT_INVALID;
3058: page.typed_data.real = FALSE;
1.82 cvs 3059: cssRule = SkipBlanksAndComments (cssRule);
3060: if (!strncasecmp (cssRule, "auto", 4))
1.59 cvs 3061: {
3062: /*page.typed_data.unit = STYLE_UNIT_REL;*/
3063: page.typed_data.value = STYLE_AUTO;
3064: }
1.82 cvs 3065: else if (!strncasecmp (cssRule, "always", 6))
1.59 cvs 3066: {
3067: page.typed_data.unit = STYLE_UNIT_REL;
3068: page.typed_data.value = STYLE_ALWAYS;
3069: }
1.82 cvs 3070: else if (!strncasecmp (cssRule, "avoid", 5))
1.59 cvs 3071: {
3072: page.typed_data.unit = STYLE_UNIT_REL;
3073: page.typed_data.value = STYLE_AVOID;
3074: }
1.82 cvs 3075: else if (!strncasecmp (cssRule, "left", 4))
1.59 cvs 3076: {
3077: page.typed_data.unit = STYLE_UNIT_REL;
3078: page.typed_data.value = STYLE_PAGELEFT;
3079: }
1.82 cvs 3080: else if (!strncasecmp (cssRule, "right", 5))
1.59 cvs 3081: {
3082: page.typed_data.unit = STYLE_UNIT_REL;
3083: page.typed_data.value = STYLE_PAGERIGHT;
3084: }
1.82 cvs 3085: else if (!strncasecmp (cssRule, "inherit", 7))
1.59 cvs 3086: {
3087: /*page.typed_data.unit = STYLE_UNIT_REL;*/
3088: page.typed_data.value = STYLE_INHERIT;
3089: }
3090: cssRule = SkipWord (cssRule);
3091: /* install the new presentation */
1.116 vatton 3092: /*if (page.typed_data.unit == STYLE_UNIT_REL && DoApply)
1.117 vatton 3093: {
3094: if (tsch)
3095: cssRule = CheckImportantRule (cssRule, context);
3096: TtaSetStylePresentation (PRPageAfter, element, tsch, context, page);
3097: }*/
1.59 cvs 3098: return (cssRule);
3099: }
3100:
3101: /*----------------------------------------------------------------------
1.60 cvs 3102: ParseCSSPageBreakInside: parse a CSS page-break-inside attribute
1.59 cvs 3103: ----------------------------------------------------------------------*/
1.79 cvs 3104: static char *ParseCSSPageBreakInside (Element element, PSchema tsch,
3105: PresentationContext context,
3106: char *cssRule, CSSInfoPtr css,
3107: ThotBool isHTML)
1.59 cvs 3108: {
3109: PresentationValue page;
3110:
3111: page.typed_data.unit = STYLE_UNIT_INVALID;
3112: page.typed_data.real = FALSE;
1.82 cvs 3113: cssRule = SkipBlanksAndComments (cssRule);
3114: if (!strncasecmp (cssRule, "auto", 4))
1.59 cvs 3115: {
3116: /*page.typed_data.unit = STYLE_UNIT_REL;*/
3117: page.typed_data.value = STYLE_AUTO;
3118: }
1.82 cvs 3119: else if (!strncasecmp (cssRule, "avoid", 5))
1.59 cvs 3120: {
3121: page.typed_data.unit = STYLE_UNIT_REL;
3122: page.typed_data.value = STYLE_AVOID;
3123: }
1.82 cvs 3124: else if (!strncasecmp (cssRule, "inherit", 7))
1.59 cvs 3125: {
3126: /*page.typed_data.unit = STYLE_UNIT_REL;*/
3127: page.typed_data.value = STYLE_INHERIT;
3128: }
3129: cssRule = SkipWord (cssRule);
3130: /* install the new presentation */
1.96 vatton 3131: /*if (page.typed_data.unit == STYLE_UNIT_REL &&
1.117 vatton 3132: page.typed_data.value == STYLE_AVOID && DoApply)
3133: {
3134: if (tsch)
3135: cssRule = CheckImportantRule (cssRule, context);
3136: TtaSetStylePresentation (PRPageInside, element, tsch, context, page);
3137: }*/
1.59 cvs 3138: return (cssRule);
3139: }
1.18 cvs 3140:
3141:
1.60 cvs 3142: /*----------------------------------------------------------------------
1.117 vatton 3143: ParseSVGStrokeWidth: parse a SVG stroke-width property value.
1.60 cvs 3144: ----------------------------------------------------------------------*/
1.79 cvs 3145: static char *ParseSVGStrokeWidth (Element element, PSchema tsch,
3146: PresentationContext context, char *cssRule,
3147: CSSInfoPtr css, ThotBool isHTML)
1.60 cvs 3148: {
3149: PresentationValue width;
3150:
1.82 cvs 3151: cssRule = SkipBlanksAndComments (cssRule);
1.60 cvs 3152: width.typed_data.value = 0;
3153: width.typed_data.unit = STYLE_UNIT_INVALID;
3154: width.typed_data.real = FALSE;
1.110 vatton 3155: if (isdigit (*cssRule) || *cssRule == '.')
1.60 cvs 3156: cssRule = ParseCSSUnit (cssRule, &width);
1.116 vatton 3157: if (width.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.117 vatton 3158: {
3159: /* check if it's an important rule */
3160: if (tsch)
3161: cssRule = CheckImportantRule (cssRule, context);
3162: TtaSetStylePresentation (PRLineWeight, element, tsch, context, width);
3163: width.typed_data.value = 1;
3164: width.typed_data.unit = STYLE_UNIT_REL;
3165: }
1.60 cvs 3166: return (cssRule);
3167: }
3168:
1.18 cvs 3169: /************************************************************************
3170: * *
3171: * FUNCTIONS STYLE DECLARATIONS *
3172: * *
3173: ************************************************************************/
3174: /*
1.59 cvs 3175: * NOTE: Long attribute name MUST be placed before shortened ones !
1.18 cvs 3176: * e.g. "FONT-SIZE" must be placed before "FONT"
3177: */
3178: static CSSProperty CSSProperties[] =
3179: {
1.82 cvs 3180: {"font-family", ParseCSSFontFamily},
3181: {"font-style", ParseCSSFontStyle},
3182: {"font-variant", ParseCSSFontVariant},
3183: {"font-weight", ParseCSSFontWeight},
3184: {"font-size", ParseCSSFontSize},
3185: {"font", ParseCSSFont},
3186:
3187: {"color", ParseCSSForeground},
3188: {"background-color", ParseCSSBackgroundColor},
3189: {"background-image", ParseCSSBackgroundImage},
3190: {"background-repeat", ParseCSSBackgroundRepeat},
3191: {"background-attachment", ParseCSSBackgroundAttachment},
3192: {"background-position", ParseCSSBackgroundPosition},
3193: {"background", ParseCSSBackground},
3194:
3195: {"word-spacing", ParseCSSWordSpacing},
3196: {"letter-spacing", ParseCSSLetterSpacing},
3197: {"text-decoration", ParseCSSTextDecoration},
3198: {"vertical-align", ParseCSSVerticalAlign},
3199: {"text-transform", ParseCSSTextTransform},
3200: {"text-align", ParseCSSTextAlign},
3201: {"text-indent", ParseCSSTextIndent},
3202: {"line-height", ParseCSSLineSpacing},
3203:
1.112 quint 3204: {"direction", ParseCSSDirection},
1.113 quint 3205: {"unicode-bidi", ParseCSSUnicodeBidi},
1.112 quint 3206:
1.82 cvs 3207: {"margin-top", ParseCSSMarginTop},
3208: {"margin-right", ParseCSSMarginRight},
3209: {"margin-bottom", ParseCSSMarginBottom},
3210: {"margin-left", ParseCSSMarginLeft},
3211: {"margin", ParseCSSMargin},
3212:
3213: {"padding-top", ParseCSSPaddingTop},
3214: {"padding-right", ParseCSSPaddingRight},
3215: {"padding-bottom", ParseCSSPaddingBottom},
3216: {"padding-left", ParseCSSPaddingLeft},
3217: {"padding", ParseCSSPadding},
3218:
3219: {"border-top-width", ParseCSSBorderTopWidth},
3220: {"border-right-width", ParseCSSBorderRightWidth},
3221: {"border-bottom-width", ParseCSSBorderBottomWidth},
3222: {"border-left-width", ParseCSSBorderLeftWidth},
3223: {"border-width", ParseCSSBorderWidth},
3224: {"border-top-color", ParseCSSBorderColorTop},
3225: {"border-right-color", ParseCSSBorderColorRight},
3226: {"border-bottom-color", ParseCSSBorderColorBottom},
3227: {"border-left-color", ParseCSSBorderColorLeft},
3228: {"border-color", ParseCSSBorderColor},
3229: {"border-top-style", ParseCSSBorderStyleTop},
3230: {"border-right-style", ParseCSSBorderStyleRight},
3231: {"border-bottom-style", ParseCSSBorderStyleBottom},
3232: {"border-left-style", ParseCSSBorderStyleLeft},
3233: {"border-style", ParseCSSBorderStyle},
3234: {"border-top", ParseCSSBorderTop},
3235: {"border-right", ParseCSSBorderRight},
3236: {"border-bottom", ParseCSSBorderBottom},
3237: {"border-left", ParseCSSBorderLeft},
3238: {"border", ParseCSSBorder},
3239:
3240: {"width", ParseCSSWidth},
3241: {"height", ParseCSSHeight},
3242: {"float", ParseCSSFloat},
3243: {"clear", ParseCSSClear},
3244:
3245: {"display", ParseCSSDisplay},
3246: {"white-space", ParseCSSWhiteSpace},
3247:
3248: {"list-style-type", ParseCSSListStyleType},
3249: {"list-style-image", ParseCSSListStyleImage},
3250: {"list-style-position", ParseCSSListStylePosition},
3251: {"list-style", ParseCSSListStyle},
3252:
3253: {"page-break-before", ParseCSSPageBreakBefore},
3254: {"page-break-after", ParseCSSPageBreakAfter},
3255: {"page-break-inside", ParseCSSPageBreakInside},
1.60 cvs 3256:
3257: /* SVG extensions */
1.82 cvs 3258: {"stroke-width", ParseSVGStrokeWidth},
3259: {"stroke", ParseSVGStroke},
3260: {"fill", ParseSVGFill}
1.18 cvs 3261: };
3262: #define NB_CSSSTYLEATTRIBUTE (sizeof(CSSProperties) / sizeof(CSSProperty))
3263:
3264: /*----------------------------------------------------------------------
1.59 cvs 3265: ParseCSSRule: parse a CSS Style string
1.18 cvs 3266: we expect the input string describing the style to be of the
1.59 cvs 3267: form: PRORPERTY: DESCRIPTION [ ; PROPERTY: DESCRIPTION ] *
1.18 cvs 3268: but tolerate incorrect or incomplete input
3269: ----------------------------------------------------------------------*/
1.79 cvs 3270: static void ParseCSSRule (Element element, PSchema tsch,
3271: PresentationContext context, char *cssRule,
3272: CSSInfoPtr css, ThotBool isHTML)
1.18 cvs 3273: {
1.34 cvs 3274: DisplayMode dispMode;
1.79 cvs 3275: char *p = NULL;
1.18 cvs 3276: int lg;
1.34 cvs 3277: unsigned int i;
1.76 cvs 3278: ThotBool found;
1.18 cvs 3279:
1.34 cvs 3280: /* avoid too many redisplay */
3281: dispMode = TtaGetDisplayMode (context->doc);
3282: if (dispMode == DisplayImmediately)
3283: TtaSetDisplayMode (context->doc, DeferredDisplay);
3284:
1.82 cvs 3285: while (*cssRule != EOS)
1.18 cvs 3286: {
1.82 cvs 3287: cssRule = SkipBlanksAndComments (cssRule);
1.133 vatton 3288: if (*cssRule < 0x41 || *cssRule > 0x7A ||
3289: (*cssRule > 0x5A && *cssRule < 0x60))
1.89 cvs 3290: {
1.135 vatton 3291: CSSParseError ("Invalid character", cssRule);
1.89 cvs 3292: cssRule++;
3293: cssRule = SkipBlanksAndComments (cssRule);
3294: }
1.18 cvs 3295:
3296: found = FALSE;
3297: /* look for the type of property */
3298: for (i = 0; i < NB_CSSSTYLEATTRIBUTE && !found; i++)
3299: {
1.82 cvs 3300: lg = strlen (CSSProperties[i].name);
3301: if (!strncasecmp (cssRule, CSSProperties[i].name, lg))
1.18 cvs 3302: {
1.86 cvs 3303: p = cssRule + lg;
1.18 cvs 3304: found = TRUE;
3305: i--;
3306: }
3307: }
3308:
3309: if (i == NB_CSSSTYLEATTRIBUTE)
3310: cssRule = SkipProperty (cssRule);
3311: else
3312: {
3313: /* update index and skip the ":" indicator if present */
1.86 cvs 3314: p = SkipBlanksAndComments (p);
3315: if (*p == ':')
1.18 cvs 3316: {
1.86 cvs 3317: p++;
3318: p = SkipBlanksAndComments (p);
1.74 cvs 3319: /* try to parse the value associated with this property */
3320: if (CSSProperties[i].parsing_function != NULL)
1.61 cvs 3321: {
1.75 cvs 3322: p = CSSProperties[i].parsing_function (element, tsch, context,
1.86 cvs 3323: p, css, isHTML);
1.74 cvs 3324: /* update index and skip the ";" separator if present */
3325: cssRule = p;
1.61 cvs 3326: }
1.18 cvs 3327: }
1.74 cvs 3328: else
3329: cssRule = SkipProperty (cssRule);
1.18 cvs 3330: }
1.89 cvs 3331:
1.18 cvs 3332: /* next property */
1.82 cvs 3333: cssRule = SkipBlanksAndComments (cssRule);
1.89 cvs 3334: if (*cssRule == '}')
3335: {
3336: cssRule++;
3337: CSSParseError ("Invalid character", "}");
3338: cssRule = SkipBlanksAndComments (cssRule);
3339: }
1.82 cvs 3340: if (*cssRule == ',' || *cssRule == ';')
1.18 cvs 3341: {
3342: cssRule++;
1.82 cvs 3343: cssRule = SkipBlanksAndComments (cssRule);
1.18 cvs 3344: }
3345: }
1.34 cvs 3346:
3347: /* restore the display mode */
3348: if (dispMode == DisplayImmediately)
3349: TtaSetDisplayMode (context->doc, dispMode);
1.18 cvs 3350: }
1.1 cvs 3351:
1.111 cvs 3352: /*----------------------------------------------------------------------
3353: AddBorderStyleValue
3354: -----------------------------------------------------------------------*/
3355: static void AddBorderStyleValue (char *buffer, int value)
3356: {
3357: switch (value)
3358: {
3359: case STYLE_BORDERNONE:
3360: strcat (buffer, "none");
3361: break;
3362: case STYLE_BORDERHIDDEN:
3363: strcat (buffer, "hidden");
3364: break;
3365: case STYLE_BORDERDOTTED:
3366: strcat (buffer, "dotted");
3367: break;
3368: case STYLE_BORDERDASHED:
3369: strcat (buffer, "dashed");
3370: break;
3371: case STYLE_BORDERSOLID:
3372: strcat (buffer, "solid");
3373: break;
3374: case STYLE_BORDERDOUBLE:
3375: strcat (buffer, "double");
3376: break;
3377: case STYLE_BORDERGROOVE:
3378: strcat (buffer, "groove");
3379: break;
3380: case STYLE_BORDERRIDGE:
3381: strcat (buffer, "ridge");
3382: break;
3383: case STYLE_BORDERINSET:
3384: strcat (buffer, "inset");
3385: break;
3386: case STYLE_BORDEROUTSET:
3387: strcat (buffer, "outset");
3388: break;
3389: }
3390: }
1.1 cvs 3391:
3392: /*----------------------------------------------------------------------
1.59 cvs 3393: PToCss: translate a PresentationSetting to the
1.18 cvs 3394: equivalent CSS string, and add it to the buffer given as the
1.67 cvs 3395: argument. It is used when extracting the CSS string from actual
3396: presentation.
3397: el is the element for which the style rule is generated
1.18 cvs 3398:
3399: All the possible values returned by the presentation drivers are
3400: described in thotlib/include/presentation.h
3401: -----------------------------------------------------------------------*/
1.79 cvs 3402: void PToCss (PresentationSetting settings, char *buffer, int len, Element el)
1.1 cvs 3403: {
1.76 cvs 3404: ElementType elType;
1.18 cvs 3405: float fval = 0;
3406: unsigned short red, green, blue;
3407: int add_unit = 0;
3408: unsigned int unit, i;
3409: ThotBool real = FALSE;
3410:
1.82 cvs 3411: buffer[0] = EOS;
1.18 cvs 3412: if (len < 40)
3413: return;
3414:
3415: unit = settings->value.typed_data.unit;
3416: if (settings->value.typed_data.real)
3417: {
3418: real = TRUE;
3419: fval = (float) settings->value.typed_data.value;
3420: fval /= 1000;
3421: }
1.1 cvs 3422:
1.18 cvs 3423: switch (settings->type)
1.1 cvs 3424: {
1.18 cvs 3425: case PRVisibility:
3426: break;
1.111 cvs 3427: case PRHeight:
3428: if (real)
3429: sprintf (buffer, "height: %g", fval);
3430: else
3431: sprintf (buffer, "height: %d", settings->value.typed_data.value);
3432: add_unit = 1;
3433: break;
3434: case PRWidth:
3435: if (real)
3436: sprintf (buffer, "width: %g", fval);
3437: else
3438: sprintf (buffer, "width: %d", settings->value.typed_data.value);
3439: add_unit = 1;
3440: break;
3441: case PRMarginTop:
3442: if (real)
3443: sprintf (buffer, "margin-top: %g", fval);
3444: else
3445: sprintf (buffer, "margin-top: %d",settings->value.typed_data.value);
3446: add_unit = 1;
3447: break;
3448: case PRMarginBottom:
3449: if (real)
3450: sprintf (buffer, "margin-bottom: %g", fval);
3451: else
3452: sprintf (buffer, "margin-bottom: %d",
3453: settings->value.typed_data.value);
3454: add_unit = 1;
3455: break;
3456: case PRMarginLeft:
3457: if (real)
3458: sprintf (buffer, "margin-left: %g", fval);
3459: else
3460: sprintf (buffer, "margin-left: %d",
3461: settings->value.typed_data.value);
3462: add_unit = 1;
3463: break;
3464: case PRMarginRight:
3465: if (real)
3466: sprintf (buffer, "margin-right: %g", fval);
3467: else
3468: sprintf (buffer, "margin-right: %d",
3469: settings->value.typed_data.value);
3470: add_unit = 1;
3471: break;
3472: case PRPaddingTop:
3473: if (real)
3474: sprintf (buffer, "padding-top: %g", fval);
3475: else
3476: sprintf (buffer, "padding-top: %d",settings->value.typed_data.value);
3477: add_unit = 1;
3478: break;
3479: case PRPaddingBottom:
3480: if (real)
3481: sprintf (buffer, "padding-bottom: %g", fval);
3482: else
3483: sprintf (buffer, "padding-bottom: %d",
3484: settings->value.typed_data.value);
3485: add_unit = 1;
3486: break;
3487: case PRPaddingLeft:
3488: if (real)
3489: sprintf (buffer, "padding-left: %g", fval);
3490: else
3491: sprintf (buffer, "padding-left: %d",
3492: settings->value.typed_data.value);
3493: add_unit = 1;
3494: break;
3495: case PRPaddingRight:
3496: if (real)
3497: sprintf (buffer, "padding-right: %g", fval);
3498: else
3499: sprintf (buffer, "padding-right: %d",
3500: settings->value.typed_data.value);
3501: add_unit = 1;
3502: break;
3503: case PRBorderTopWidth:
3504: if (real)
3505: sprintf (buffer, "border-top-width: %g", fval);
3506: else
3507: sprintf (buffer, "border-top-width: %d",
3508: settings->value.typed_data.value);
3509: add_unit = 1;
3510: break;
3511: case PRBorderBottomWidth:
3512: if (real)
3513: sprintf (buffer, "border-bottom-width: %g", fval);
3514: else
3515: sprintf (buffer, "border-bottom-width: %d",
3516: settings->value.typed_data.value);
3517: add_unit = 1;
3518: break;
3519: case PRBorderLeftWidth:
3520: if (real)
3521: sprintf (buffer, "border-left-width: %g", fval);
3522: else
3523: sprintf (buffer, "border-left-width: %d",
3524: settings->value.typed_data.value);
3525: add_unit = 1;
3526: break;
3527: case PRBorderRightWidth:
3528: if (real)
3529: sprintf (buffer, "border-right-width: %g", fval);
3530: else
3531: sprintf (buffer, "border-right-width: %d",
3532: settings->value.typed_data.value);
3533: add_unit = 1;
3534: break;
3535: case PRBorderTopColor:
3536: TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
3537: elType = TtaGetElementType(el);
3538: sprintf (buffer, "border-top-color: #%02X%02X%02X", red, green, blue);
3539: break;
3540: case PRBorderRightColor:
3541: TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
3542: elType = TtaGetElementType(el);
3543: sprintf (buffer, "border-right-color: #%02X%02X%02X", red, green, blue);
3544: break;
3545: case PRBorderBottomColor:
3546: TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
3547: elType = TtaGetElementType(el);
3548: sprintf (buffer, "border-bottom-color: #%02X%02X%02X", red, green, blue);
1.18 cvs 3549: break;
1.111 cvs 3550: case PRBorderLeftColor:
3551: TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
3552: elType = TtaGetElementType(el);
3553: sprintf (buffer, "border-left-color: #%02X%02X%02X", red, green, blue);
1.20 cvs 3554: break;
1.111 cvs 3555: case PRBorderTopStyle:
3556: strcpy (buffer, "border-top-style: ");
3557: AddBorderStyleValue (buffer, settings->value.typed_data.value);
3558: break;
3559: case PRBorderRightStyle:
3560: strcpy (buffer, "border-right-style: ");
3561: AddBorderStyleValue (buffer, settings->value.typed_data.value);
3562: break;
3563: case PRBorderBottomStyle:
3564: strcpy (buffer, "border-bottom-style: ");
3565: AddBorderStyleValue (buffer, settings->value.typed_data.value);
3566: break;
3567: case PRBorderLeftStyle:
3568: strcpy (buffer, "border-left-style: ");
3569: AddBorderStyleValue (buffer, settings->value.typed_data.value);
1.18 cvs 3570: break;
3571: case PRSize:
3572: if (unit == STYLE_UNIT_REL)
3573: {
3574: if (real)
3575: {
1.82 cvs 3576: sprintf (buffer, "font-size: %g", fval);
1.18 cvs 3577: add_unit = 1;
3578: }
3579: else
3580: switch (settings->value.typed_data.value)
3581: {
3582: case 1:
1.82 cvs 3583: strcpy (buffer, "font-size: xx-small");
1.18 cvs 3584: break;
3585: case 2:
1.82 cvs 3586: strcpy (buffer, "font-size: x-small");
1.18 cvs 3587: break;
3588: case 3:
1.82 cvs 3589: strcpy (buffer, "font-size: small");
1.18 cvs 3590: break;
3591: case 4:
1.82 cvs 3592: strcpy (buffer, "font-size: medium");
1.18 cvs 3593: break;
3594: case 5:
1.82 cvs 3595: strcpy (buffer, "font-size: large");
1.18 cvs 3596: break;
3597: case 6:
1.82 cvs 3598: strcpy (buffer, "font-size: x-large");
1.18 cvs 3599: break;
3600: case 7:
3601: case 8:
3602: case 9:
3603: case 10:
3604: case 11:
3605: case 12:
1.82 cvs 3606: strcpy (buffer, "font-size: xx-large");
1.18 cvs 3607: break;
3608: }
3609: }
3610: else
3611: {
3612: if (real)
1.82 cvs 3613: sprintf (buffer, "font-size: %g", fval);
1.18 cvs 3614: else
1.82 cvs 3615: sprintf (buffer, "font-size: %d",
1.67 cvs 3616: settings->value.typed_data.value);
1.18 cvs 3617: add_unit = 1;
3618: }
3619: break;
1.111 cvs 3620: case PRStyle:
3621: switch (settings->value.typed_data.value)
3622: {
3623: case STYLE_FONT_ROMAN:
3624: strcpy (buffer, "font-style: normal");
3625: break;
3626: case STYLE_FONT_ITALICS:
3627: strcpy (buffer, "font-style: italic");
3628: break;
3629: case STYLE_FONT_OBLIQUE:
3630: strcpy (buffer, "font-style: oblique");
3631: break;
3632: }
3633: break;
3634: case PRWeight:
3635: switch (settings->value.typed_data.value)
3636: {
3637: case STYLE_WEIGHT_BOLD:
3638: strcpy (buffer, "font-weight: bold");
3639: break;
3640: case STYLE_WEIGHT_NORMAL:
3641: strcpy (buffer, "font-weight: normal");
3642: break;
3643: }
3644: break;
3645: case PRFont:
3646: switch (settings->value.typed_data.value)
3647: {
3648: case STYLE_FONT_HELVETICA:
3649: strcpy (buffer, "font-family: helvetica");
3650: break;
3651: case STYLE_FONT_TIMES:
3652: strcpy (buffer, "font-family: times");
3653: break;
3654: case STYLE_FONT_COURIER:
3655: strcpy (buffer, "font-family: courier");
3656: break;
3657: }
3658: break;
1.18 cvs 3659: case PRUnderline:
3660: switch (settings->value.typed_data.value)
3661: {
3662: case STYLE_UNDERLINE:
1.82 cvs 3663: strcpy (buffer, "text-decoration: underline");
1.18 cvs 3664: break;
3665: case STYLE_OVERLINE:
1.82 cvs 3666: strcpy (buffer, "text-decoration: overline");
1.18 cvs 3667: break;
3668: case STYLE_CROSSOUT:
1.82 cvs 3669: strcpy (buffer, "text-decoration: line-through");
1.18 cvs 3670: break;
3671: }
3672: break;
1.111 cvs 3673: case PRThickness:
3674: break;
1.18 cvs 3675: case PRIndent:
3676: if (real)
1.82 cvs 3677: sprintf (buffer, "text-indent: %g", fval);
1.18 cvs 3678: else
1.82 cvs 3679: sprintf (buffer, "text-indent: %d",
1.67 cvs 3680: settings->value.typed_data.value);
1.18 cvs 3681: add_unit = 1;
3682: break;
3683: case PRLineSpacing:
3684: if (real)
1.82 cvs 3685: sprintf (buffer, "line-height: %g", fval);
1.1 cvs 3686: else
1.82 cvs 3687: sprintf (buffer, "line-height: %d",
1.67 cvs 3688: settings->value.typed_data.value);
1.18 cvs 3689: add_unit = 1;
3690: break;
1.111 cvs 3691: case PRDepth:
3692: break;
1.18 cvs 3693: case PRAdjust:
3694: switch (settings->value.typed_data.value)
1.1 cvs 3695: {
1.18 cvs 3696: case STYLE_ADJUSTLEFT:
1.82 cvs 3697: strcpy (buffer, "text-align: left");
1.18 cvs 3698: break;
3699: case STYLE_ADJUSTRIGHT:
1.82 cvs 3700: strcpy (buffer, "text-align: right");
1.18 cvs 3701: break;
3702: case STYLE_ADJUSTCENTERED:
1.82 cvs 3703: strcpy (buffer, "text-align: center");
1.18 cvs 3704: break;
3705: case STYLE_ADJUSTLEFTWITHDOTS:
1.82 cvs 3706: strcpy (buffer, "text-align: left");
1.81 cvs 3707: break;
3708: case STYLE_ADJUSTJUSTIFY:
1.82 cvs 3709: strcpy (buffer, "text-align: justify");
1.112 quint 3710: break;
3711: }
3712: break;
3713: case PRDirection:
3714: switch (settings->value.typed_data.value)
3715: {
3716: case STYLE_LEFTTORIGHT:
3717: strcpy (buffer, "direction: ltr");
3718: break;
3719: case STYLE_RIGHTTOLEFT:
3720: strcpy (buffer, "direction: rtl");
1.113 quint 3721: break;
3722: }
3723: break;
3724: case PRUnicodeBidi:
3725: switch (settings->value.typed_data.value)
3726: {
3727: case STYLE_BIDINORMAL:
3728: strcpy (buffer, "unicode-bidi: normal");
3729: break;
3730: case STYLE_BIDIEMBED:
3731: strcpy (buffer, "unicode-bidi: embed");
3732: break;
3733: case STYLE_BIDIOVERRIDE:
3734: strcpy (buffer, "unicode-bidi: bidi-override");
1.18 cvs 3735: break;
1.1 cvs 3736: }
1.18 cvs 3737: break;
1.111 cvs 3738: case PRLineStyle:
3739: break;
1.126 vatton 3740: case PRDisplay:
3741: switch (settings->value.typed_data.value)
3742: {
3743: case STYLE_DISPLAYINLINE:
3744: strcpy (buffer, "display: inline");
3745: break;
3746: case STYLE_DISPLAYBLOCK:
3747: strcpy (buffer, "display: block");
3748: break;
3749: case STYLE_DISPLAYLISTITEM:
3750: strcpy (buffer, "display: list-item");
3751: break;
3752: case STYLE_DISPLAYRUNIN:
3753: strcpy (buffer, "display: runin");
3754: break;
3755: case STYLE_DISPLAYCOMPACT:
3756: strcpy (buffer, "display: compact");
3757: break;
3758: case STYLE_DISPLAYMARKER:
3759: strcpy (buffer, "display: marker");
3760: break;
3761: default:
3762: break;
3763: }
3764: break;
1.111 cvs 3765: case PRLineWeight:
3766: elType = TtaGetElementType(el);
3767: #ifdef _SVG
3768: if (!strcmp(TtaGetSSchemaName (elType.ElSSchema), "SVG"))
3769: #endif /* _SVG */
3770: {
3771: if (real)
3772: sprintf (buffer, "stroke-width: %g", fval);
3773: else
3774: sprintf (buffer, "stroke-width: %d",
3775: settings->value.typed_data.value);
3776: }
3777: add_unit = 1;
1.18 cvs 3778: break;
3779: case PRFillPattern:
3780: break;
3781: case PRBackground:
3782: TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
1.76 cvs 3783: elType = TtaGetElementType(el);
1.100 vatton 3784: #ifdef _SVG
3785: if (strcmp(TtaGetSSchemaName (elType.ElSSchema), "SVG") == 0)
1.82 cvs 3786: sprintf (buffer, "fill: #%02X%02X%02X", red, green, blue);
1.67 cvs 3787: else
1.100 vatton 3788: #endif /* _SVG */
1.82 cvs 3789: sprintf (buffer, "background-color: #%02X%02X%02X", red, green,
1.67 cvs 3790: blue);
1.18 cvs 3791: break;
3792: case PRForeground:
3793: TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
1.76 cvs 3794: elType = TtaGetElementType(el);
1.100 vatton 3795: #ifdef _SVG
3796: if (strcmp(TtaGetSSchemaName (elType.ElSSchema), "SVG") == 0)
1.82 cvs 3797: sprintf (buffer, "stroke: #%02X%02X%02X", red, green, blue);
1.67 cvs 3798: else
1.100 vatton 3799: #endif /* _SVG */
1.82 cvs 3800: sprintf (buffer, "color: #%02X%02X%02X", red, green, blue);
1.67 cvs 3801: break;
1.111 cvs 3802: case PRHyphenate:
1.18 cvs 3803: break;
1.111 cvs 3804: case PRVertOverflow:
1.18 cvs 3805: break;
1.111 cvs 3806: case PRHorizOverflow:
1.18 cvs 3807: break;
3808: case PRBackgroundPicture:
3809: if (settings->value.pointer != NULL)
1.82 cvs 3810: sprintf (buffer, "background-image: url(%s)",
1.67 cvs 3811: (char*)(settings->value.pointer));
1.1 cvs 3812: else
1.82 cvs 3813: sprintf (buffer, "background-image: none");
1.18 cvs 3814: break;
3815: case PRPictureMode:
3816: switch (settings->value.typed_data.value)
1.1 cvs 3817: {
1.18 cvs 3818: case STYLE_REALSIZE:
1.82 cvs 3819: sprintf (buffer, "background-repeat: no-repeat");
1.18 cvs 3820: break;
3821: case STYLE_REPEAT:
1.82 cvs 3822: sprintf (buffer, "background-repeat: repeat");
1.18 cvs 3823: break;
3824: case STYLE_VREPEAT:
1.82 cvs 3825: sprintf (buffer, "background-repeat: repeat-y");
1.18 cvs 3826: break;
3827: case STYLE_HREPEAT:
1.82 cvs 3828: sprintf (buffer, "background-repeat: repeat-x");
1.18 cvs 3829: break;
1.1 cvs 3830: }
1.18 cvs 3831: break;
3832: default:
3833: break;
1.1 cvs 3834: }
3835:
1.18 cvs 3836: if (add_unit)
1.1 cvs 3837: {
1.18 cvs 3838: /* add the unit string to the CSS string */
3839: for (i = 0; i < NB_UNITS; i++)
1.1 cvs 3840: {
1.18 cvs 3841: if (CSSUnitNames[i].unit == unit)
1.1 cvs 3842: {
1.82 cvs 3843: strcat (buffer, CSSUnitNames[i].sign);
1.18 cvs 3844: break;
1.1 cvs 3845: }
3846: }
3847: }
3848: }
3849:
3850: /*----------------------------------------------------------------------
1.59 cvs 3851: ParseHTMLSpecificStyle: parse and apply a CSS Style string.
1.18 cvs 3852: This function must be called when a specific style is applied to an
3853: element.
1.114 quint 3854: The parameter specificity is the specificity of the style, 0 if it is
3855: not really a CSS rule.
1.1 cvs 3856: ----------------------------------------------------------------------*/
1.79 cvs 3857: void ParseHTMLSpecificStyle (Element el, char *cssRule, Document doc,
1.114 quint 3858: int specificity, ThotBool destroy)
1.1 cvs 3859: {
3860: PresentationContext context;
3861: ElementType elType;
1.14 cvs 3862: ThotBool isHTML;
1.1 cvs 3863:
3864: /* A rule applying to BODY is really meant to address HTML */
3865: elType = TtaGetElementType (el);
1.89 cvs 3866:
1.86 cvs 3867: /* store the current line for eventually reported errors */
3868: LineNumber = TtaGetElementLineNumber (el);
1.89 cvs 3869: if (destroy)
3870: /* no reported errors */
3871: ParsedDoc = 0;
3872: else if (ParsedDoc != doc)
3873: {
3874: /* update the context for reported errors */
3875: ParsedDoc = doc;
3876: DocURL = DocumentURLs[doc];
3877: }
1.82 cvs 3878: isHTML = (strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML") == 0);
1.1 cvs 3879: /* create the context of the Specific presentation driver */
3880: context = TtaGetSpecificStyleContext (doc);
3881: if (context == NULL)
3882: return;
3883: context->type = elType.ElTypeNum;
1.114 quint 3884: context->cssSpecificity = specificity;
1.1 cvs 3885: context->destroy = destroy;
3886: /* Call the parser */
3887: ParseCSSRule (el, NULL, (PresentationContext) context, cssRule, NULL, isHTML);
3888: /* free the context */
3889: TtaFreeMemory(context);
3890: }
3891:
1.68 cvs 3892:
1.1 cvs 3893: /*----------------------------------------------------------------------
1.59 cvs 3894: ParseGenericSelector: Create a generic context for a given
1.1 cvs 3895: selector string. If the selector is made of multiple comma-
3896: separated selector items, it parses them one at a time and
3897: return the end of the selector string to be handled or NULL
3898: ----------------------------------------------------------------------*/
1.79 cvs 3899: static char *ParseGenericSelector (char *selector, char *cssRule,
3900: GenericContext ctxt, Document doc,
3901: CSSInfoPtr css)
3902: {
3903: ElementType elType;
3904: PSchema tsch;
1.119 vatton 3905: AttributeType attrType;
1.79 cvs 3906: char sel[MAX_ANCESTORS * 50];
1.118 vatton 3907: char *deb, *cur, c;
3908: char *schemaName, *mappedName;
1.79 cvs 3909: char *names[MAX_ANCESTORS];
3910: char *ids[MAX_ANCESTORS];
3911: char *classes[MAX_ANCESTORS];
3912: char *pseudoclasses[MAX_ANCESTORS];
3913: char *attrs[MAX_ANCESTORS];
3914: char *attrvals[MAX_ANCESTORS];
1.133 vatton 3915: AttrMatch attrmatch[MAX_ANCESTORS];
1.91 cvs 3916: int i, j, k, max;
1.125 vatton 3917: int att, maxAttr, kind;
1.118 vatton 3918: int specificity, xmlType;
1.79 cvs 3919: ThotBool isHTML;
3920: ThotBool level;
1.1 cvs 3921:
1.82 cvs 3922: sel[0] = EOS;
1.117 vatton 3923: specificity = 0;
1.1 cvs 3924: for (i = 0; i < MAX_ANCESTORS; i++)
3925: {
1.25 cvs 3926: names[i] = NULL;
3927: ids[i] = NULL;
3928: classes[i] = NULL;
3929: pseudoclasses[i] = NULL;
3930: attrs[i] = NULL;
3931: attrvals[i] = NULL;
1.133 vatton 3932: attrmatch[i] = Txtmatch;
1.25 cvs 3933: ctxt->name[i] = 0;
3934: ctxt->names_nb[i] = 0;
3935: ctxt->attrType[i] = 0;
1.129 vatton 3936: ctxt->attrLevel[i] = 0;
1.25 cvs 3937: ctxt->attrText[i] = NULL;
1.133 vatton 3938: ctxt->attrMatch[1] = Txtmatch;
1.1 cvs 3939: }
1.25 cvs 3940: ctxt->box = 0;
3941: ctxt->type = 0;
1.114 quint 3942: /* the specificity of the rule depends on the selector */
3943: ctxt->cssSpecificity = 0;
1.25 cvs 3944:
1.82 cvs 3945: selector = SkipBlanksAndComments (selector);
1.27 cvs 3946: cur = &sel[0];
1.25 cvs 3947: max = 0; /* number of loops */
1.1 cvs 3948: while (1)
3949: {
1.85 cvs 3950: /* point to the following word in sel[] */
1.27 cvs 3951: deb = cur;
1.25 cvs 3952: /* copy an item of the selector into sel[] */
1.1 cvs 3953: /* put one word in the sel buffer */
1.82 cvs 3954: while (*selector != EOS && *selector != ',' &&
3955: *selector != '.' && *selector != ':' &&
1.118 vatton 3956: *selector != '#' && *selector != '[' &&
1.130 vatton 3957: *selector != '*' && *selector != '>' &&
1.118 vatton 3958: !TtaIsBlank (selector))
1.50 cvs 3959: *cur++ = *selector++;
1.82 cvs 3960: *cur++ = EOS; /* close the first string in sel[] */
3961: if (deb[0] != EOS)
1.117 vatton 3962: {
3963: names[0] = deb;
3964: specificity += 1;
3965: }
1.25 cvs 3966: else
1.27 cvs 3967: names[0] = NULL;
3968: classes[0] = NULL;
3969: pseudoclasses[0] = NULL;
3970: ids[0] = NULL;
3971: attrs[0] = NULL;
3972: attrvals[0] = NULL;
1.25 cvs 3973:
1.27 cvs 3974: /* now names[0] points to the beginning of the parsed item
1.25 cvs 3975: and cur to the next chain to be parsed */
1.129 vatton 3976: while (*selector == '.' || *selector == ':' ||
1.130 vatton 3977: *selector == '#' || *selector == '[' ||
3978: *selector == '*' || *selector == '>')
1.129 vatton 3979: {
1.85 cvs 3980: /* point to the following word in sel[] */
3981: deb = cur;
1.129 vatton 3982: if (*selector == '.')
3983: {
3984: selector++;
3985: while (*selector != EOS && *selector != ',' &&
3986: *selector != '.' && *selector != ':' &&
3987: !TtaIsBlank (selector))
3988: *cur++ = *selector++;
3989: /* close the word */
3990: *cur++ = EOS;
3991: /* point to the class in sel[] if it's valid name */
3992: if (deb[0] <= 64)
3993: {
3994: CSSParseError ("Invalid class", deb);
1.116 vatton 3995: DoApply = FALSE;
1.129 vatton 3996: }
3997: else
3998: {
3999: classes[0] = deb;
1.117 vatton 4000: specificity += 10;
1.129 vatton 4001: }
4002: }
4003: else if (*selector == ':')
4004: {
4005: selector++;
4006: while (*selector != EOS && *selector != ',' &&
4007: *selector != '.' && *selector != ':' &&
4008: !TtaIsBlank (selector))
4009: *cur++ = *selector++;
4010: /* close the word */
4011: *cur++ = EOS;
4012: /* point to the pseudoclass in sel[] if it's valid name */
4013: if (deb[0] <= 64)
4014: {
4015: CSSParseError ("Invalid pseudoclass", deb);
4016: DoApply = FALSE;
4017: }
4018: else
4019: {
4020: if (!strcmp (deb, "first-letter") ||
4021: !strcmp (deb, "first-line") ||
4022: !strcmp (deb, "before") ||
4023: !strcmp (deb, "after"))
4024: /* not supported */
1.116 vatton 4025: DoApply = FALSE;
1.129 vatton 4026: else
4027: specificity += 10;
4028: pseudoclasses[0]= deb;
4029: }
4030: }
4031: else if (*selector == '#')
4032: {
4033: selector++;
4034: while (*selector != EOS && *selector != ',' &&
4035: *selector != '.' && *selector != ':' &&
4036: !TtaIsBlank (selector))
4037: *cur++ = *selector++;
4038: /* close the word */
4039: *cur++ = EOS;
4040: /* point to the attribute in sel[] if it's valid name */
4041: if (deb[0] <= 64)
4042: {
4043: CSSParseError ("Invalid id", deb);
4044: DoApply = FALSE;
4045: }
4046: else
4047: {
4048: ids[0] = deb;
4049: specificity += 100;
4050: }
4051: }
4052: else if (*selector == '[')
4053: {
1.118 vatton 4054: selector++;
1.129 vatton 4055: while (*selector != EOS && *selector != ']' &&
1.131 vatton 4056: *selector != '=' && *selector != '~' &&
1.133 vatton 4057: *selector != '|' && *selector != '^' &&
4058: *selector != '!')
1.129 vatton 4059: *cur++ = *selector++;
1.133 vatton 4060: /* check matching */
4061: if (*selector == '~')
4062: {
4063: attrmatch[0] = Txtword;
4064: selector++;
4065: }
4066: else if (*selector == '|')
4067: {
4068: attrmatch[0] = Txtsubstring;
4069: selector++;
4070: }
4071: else
4072: attrmatch[0] = Txtmatch;
1.129 vatton 4073: /* close the word */
4074: *cur++ = EOS;
4075: /* point to the attribute in sel[] if it's valid name */
4076: if (deb[0] <= 64)
4077: {
4078: CSSParseError ("Invalid attribute", deb);
4079: DoApply = FALSE;
4080: }
4081: else
4082: {
4083: attrs[0] = deb;
4084: specificity += 10;
4085: }
4086: if (*selector == '=')
4087: {
4088: /* look for a value "xxxx" */
4089: selector++;
4090: if (*selector != '"')
4091: {
4092: CSSParseError ("Invalid attribute value", deb);
4093: DoApply = FALSE;
4094: }
4095: else
4096: {
4097: /* we are now parsing the attribute value */
4098: selector++;
4099: deb = cur;
4100: while (*selector != '"')
4101: {
4102: if (*selector == EOS)
4103: {
4104: CSSParseError ("Invalid attribute value", deb);
4105: DoApply = FALSE;
4106: }
4107: else
1.133 vatton 4108: {
4109: *cur++ = tolower (*selector);
4110: selector++;
4111: }
1.129 vatton 4112: }
4113: /* there is a value */
4114: if (*selector == '"')
4115: {
4116: selector++;
4117: *cur++ = EOS;
4118: attrvals[0] = deb;
4119: }
4120: }
4121: }
4122: /* end of the attribute */
4123: if (*selector != ']')
4124: {
1.133 vatton 4125: selector[1] = EOS;
4126: CSSParseError ("Not supported selector", selector);
4127: selector += 2;
1.129 vatton 4128: DoApply = FALSE;
4129: }
4130: else
4131: selector++;
1.130 vatton 4132: }
4133: else
4134: {
4135: /* not supported selector */
4136: while (*selector != EOS && *selector != ',' &&
4137: *selector != '.' && *selector != ':' &&
4138: !TtaIsBlank (selector))
4139: *cur++ = *selector++;
4140: /* close the word */
4141: *cur++ = EOS;
4142: CSSParseError ("Not supported selector", deb);
4143: DoApply = FALSE;
1.129 vatton 4144: }
4145: }
1.1 cvs 4146:
1.82 cvs 4147: selector = SkipBlanksAndComments (selector);
1.25 cvs 4148: /* is it a multi-level selector? */
1.82 cvs 4149: if (*selector == EOS)
1.1 cvs 4150: /* end of the selector */
4151: break;
1.82 cvs 4152: else if (*selector == ',')
1.1 cvs 4153: {
4154: /* end of the current selector */
4155: selector++;
4156: break;
4157: }
1.25 cvs 4158: else
4159: {
1.143 vatton 4160: if (*selector == '>')
4161: {
4162: /* handle immediat parent as a simple parent */
4163: selector++;
4164: selector = SkipBlanksAndComments (selector);
4165: }
1.25 cvs 4166: /* shifts the list to make room for the new name */
4167: max++; /* a new level in ancestor tables */
4168: if (max == MAX_ANCESTORS)
4169: /* abort the CSS parsing */
4170: return (selector);
4171: for (i = max; i > 0; i--)
4172: {
4173: names[i] = names[i - 1];
4174: ids[i] = ids[i - 1];
4175: classes[i] = classes[i - 1];
1.133 vatton 4176: pseudoclasses[i] = pseudoclasses[i - 1];
1.25 cvs 4177: attrs[i] = attrs[i - 1];
4178: attrvals[i] = attrvals[i - 1];
1.133 vatton 4179: attrmatch[i] = attrmatch[i - 1];
1.25 cvs 4180: }
4181: }
1.1 cvs 4182: }
4183:
4184: /* Now set up the context block */
1.25 cvs 4185: i = 0;
4186: k = 0;
4187: j = 0;
1.35 cvs 4188: maxAttr = 0;
1.91 cvs 4189: /* default schema name */
1.119 vatton 4190: ctxt->schema = NULL;
1.122 vatton 4191: elType.ElSSchema = NULL;
4192: schemaName = TtaGetSSchemaName(TtaGetDocumentSSchema (doc));
1.119 vatton 4193: if (!strcmp (schemaName, "HTML"))
4194: xmlType = XHTML_TYPE;
4195: else if (!strcmp (schemaName, "MathML"))
4196: xmlType = MATH_TYPE;
4197: else if (!strcmp (schemaName, "SVG"))
4198: xmlType = SVG_TYPE;
4199: else if (!strcmp (schemaName, "XLink"))
4200: xmlType = XLINK_TYPE;
4201: else if (!strcmp (schemaName, "Annot"))
4202: xmlType = ANNOT_TYPE;
4203: else
4204: xmlType = XML_TYPE;
1.25 cvs 4205: while (i <= max)
4206: {
4207: if (names[i])
4208: {
1.118 vatton 4209: /* get the element type of this name in the current document */
4210: MapXMLElementType (xmlType, names[i], &elType, &mappedName, &c, &level, doc);
1.25 cvs 4211: if (i == 0)
4212: {
1.106 cvs 4213: if (elType.ElSSchema == NULL)
4214: {
1.119 vatton 4215: /* Search in the list of loaded schemas */
1.106 cvs 4216: TtaGetXmlElementType (names[i], &elType, NULL, doc);
1.119 vatton 4217: if (elType.ElSSchema)
4218: {
4219: /* the element type concerns an imprted nature */
4220: schemaName = TtaGetSSchemaName(elType.ElSSchema);
4221: if (!strcmp (schemaName, "HTML"))
4222: xmlType = XHTML_TYPE;
4223: else if (!strcmp (schemaName, "MathML"))
4224: xmlType = MATH_TYPE;
4225: else if (!strcmp (schemaName, "SVG"))
4226: xmlType = SVG_TYPE;
4227: else if (!strcmp (schemaName, "XLink"))
4228: xmlType = XLINK_TYPE;
4229: else if (!strcmp (schemaName, "Annot"))
4230: xmlType = ANNOT_TYPE;
4231: else
4232: xmlType = XML_TYPE;
4233: }
1.118 vatton 4234: #ifdef XML_GENERIC
1.119 vatton 4235: else if (xmlType == XML_TYPE)
1.106 cvs 4236: {
4237: /* Creation of a new element type in the main schema */
4238: elType.ElSSchema = TtaGetDocumentSSchema (doc);
1.118 vatton 4239: TtaAppendXmlElement (names[i], &elType, &mappedName, doc);
1.106 cvs 4240: }
1.118 vatton 4241: #endif /* XML_GENERIC */
1.122 vatton 4242: else
4243: {
4244: if (xmlType != XHTML_TYPE)
4245: {
4246: MapXMLElementType (XHTML_TYPE, names[i], &elType,
4247: &mappedName, &c, &level, doc);
4248: if (elType.ElSSchema)
1.123 vatton 4249: elType.ElSSchema = GetXHTMLSSchema (doc);
1.122 vatton 4250: }
4251: if (elType.ElSSchema == NULL && xmlType != MATH_TYPE)
4252: {
4253: MapXMLElementType (MATH_TYPE, names[i], &elType,
4254: &mappedName, &c, &level, doc);
4255: if (elType.ElSSchema)
1.123 vatton 4256: elType.ElSSchema = GetMathMLSSchema (doc);
1.122 vatton 4257: }
4258: if (elType.ElSSchema == NULL && xmlType != SVG_TYPE)
4259: {
4260: MapXMLElementType (SVG_TYPE, names[i], &elType,
4261: &mappedName, &c, &level, doc);
4262: if (elType.ElSSchema)
1.123 vatton 4263: elType.ElSSchema = GetSVGSSchema (doc);
1.122 vatton 4264: }
4265: }
1.118 vatton 4266: }
1.119 vatton 4267:
1.118 vatton 4268: if (elType.ElSSchema == NULL)
4269: /* cannot apply these CSS rules */
4270: DoApply = FALSE;
4271: else
4272: {
4273: /* Store the element type */
4274: ctxt->type = elType.ElTypeNum;
4275: ctxt->name[0] = elType.ElTypeNum;
4276: ctxt->names_nb[0] = 0;
4277: ctxt->schema = elType.ElSSchema;
1.106 cvs 4278: }
1.25 cvs 4279: }
4280: else if (elType.ElTypeNum != 0)
4281: {
4282: /* look at the current context to see if the type is already
4283: stored */
1.121 vatton 4284: j = 1;
1.32 cvs 4285: while (j < k && ctxt->name[j] != elType.ElTypeNum)
1.25 cvs 4286: j++;
4287: if (j == k)
4288: {
4289: ctxt->name[j] = elType.ElTypeNum;
4290: if (j != 0)
1.121 vatton 4291: ctxt->names_nb[j] = 1;
1.25 cvs 4292: }
4293: else
4294: /* increment the number of ancestor levels */
4295: ctxt->names_nb[j]++;
4296: }
4297: else
1.117 vatton 4298: j = k;
1.25 cvs 4299: }
1.117 vatton 4300: else
4301: j = k;
1.1 cvs 4302:
1.25 cvs 4303: /* store attributes information */
4304: if (classes[i])
4305: {
4306: ctxt->attrText[j] = classes[i];
1.119 vatton 4307: if (xmlType == SVG_TYPE)
1.100 vatton 4308: ctxt->attrType[j] = SVG_ATTR_class;
1.119 vatton 4309: else if (xmlType == MATH_TYPE)
1.91 cvs 4310: ctxt->attrType[j] = MathML_ATTR_class;
1.119 vatton 4311: else if (xmlType == XHTML_TYPE)
1.107 cvs 4312: ctxt->attrType[j] = HTML_ATTR_Class;
4313: else
1.119 vatton 4314: #ifdef XML_GENERIC
1.107 cvs 4315: ctxt->attrType[j] = XML_ATTR_class;
4316: #else /* XML_GENERIC */
1.91 cvs 4317: ctxt->attrType[j] = HTML_ATTR_Class;
1.107 cvs 4318: #endif /* XML_GENERIC */
1.79 cvs 4319: /* add a new entry */
1.80 cvs 4320: maxAttr = i + 1;
1.129 vatton 4321: /* update attrLevel */
4322: ctxt->attrLevel[j] = i;
4323: j++;
1.25 cvs 4324: }
1.79 cvs 4325: if (pseudoclasses[i])
1.25 cvs 4326: {
4327: ctxt->attrText[j] = pseudoclasses[i];
1.119 vatton 4328: if (xmlType == SVG_TYPE)
1.100 vatton 4329: ctxt->attrType[j] = SVG_ATTR_PseudoClass;
1.119 vatton 4330: else if (xmlType == MATH_TYPE)
1.91 cvs 4331: ctxt->attrType[j] = MathML_ATTR_PseudoClass;
1.119 vatton 4332: else if (xmlType == XHTML_TYPE)
1.107 cvs 4333: ctxt->attrType[j] = HTML_ATTR_PseudoClass;
4334: else
1.119 vatton 4335: #ifdef XML_GENERIC
1.107 cvs 4336: ctxt->attrType[j] = XML_ATTR_PseudoClass;
4337: #else /* XML_GENERIC */
1.91 cvs 4338: ctxt->attrType[j] = HTML_ATTR_PseudoClass;
1.107 cvs 4339: #endif /* XML_GENERIC */
1.79 cvs 4340: /* add a new entry */
1.80 cvs 4341: maxAttr = i + 1;
1.129 vatton 4342: /* update attrLevel */
4343: ctxt->attrLevel[j] = i;
4344: j++;
1.25 cvs 4345: }
1.79 cvs 4346: if (ids[i])
1.25 cvs 4347: {
4348: ctxt->attrText[j] = ids[i];
1.119 vatton 4349: if (xmlType == SVG_TYPE)
1.100 vatton 4350: ctxt->attrType[j] = SVG_ATTR_id;
1.119 vatton 4351: else if (xmlType == MATH_TYPE)
1.91 cvs 4352: ctxt->attrType[j] = MathML_ATTR_id;
1.119 vatton 4353: else if (xmlType == XHTML_TYPE)
1.107 cvs 4354: ctxt->attrType[j] = HTML_ATTR_ID;
4355: else
1.119 vatton 4356: #ifdef XML_GENERIC
1.107 cvs 4357: ctxt->attrType[j] = XML_ATTR_id;
4358: #else /* XML_GENERIC */
1.91 cvs 4359: ctxt->attrType[j] = HTML_ATTR_ID;
1.107 cvs 4360: #endif /* XML_GENERIC */
1.80 cvs 4361: /* add a new entry */
4362: maxAttr = i + 1;
1.129 vatton 4363: /* update attrLevel */
4364: ctxt->attrLevel[j] = i;
4365: j++;
1.25 cvs 4366: }
1.79 cvs 4367: if (attrs[i])
1.25 cvs 4368: {
1.125 vatton 4369: /* it's an attribute */
1.119 vatton 4370: MapXMLAttribute (xmlType, attrs[i], names[i], &level, doc, &att);
1.127 quint 4371: if (att == DummyAttribute && !strcmp (schemaName, "HTML"))
4372: /* it's the "type" attribute for an "input" element. In the tree
4373: it's represented by the element type, not by an attribute */
4374: att = 0;
1.119 vatton 4375: ctxt->attrType[j] = att;
1.133 vatton 4376: ctxt->attrMatch[j] = attrmatch[i];
1.125 vatton 4377: attrType.AttrSSchema = ctxt->schema;
4378: attrType.AttrTypeNum = att;
1.119 vatton 4379: if (i == 0 && att == 0 && ctxt->schema == NULL)
4380: {
1.125 vatton 4381: /* Not found -> search in the list of loaded schemas */
1.119 vatton 4382: attrType.AttrSSchema = NULL;
4383: TtaGetXmlAttributeType (attrs[i], &attrType, doc);
4384: ctxt->attrType[j] = attrType.AttrTypeNum;
4385: if (attrType.AttrSSchema)
1.125 vatton 4386: /* the element type concerns an imported nature */
4387: schemaName = TtaGetSSchemaName(attrType.AttrSSchema);
1.119 vatton 4388: #ifdef XML_GENERIC
4389: else if (xmlType == XML_TYPE)
4390: {
4391: /* The attribute is not yet present in the tree */
4392: /* Create a new global attribute */
4393: attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
4394: TtaAppendXmlAttribute (attrs[i], &attrType, doc);
4395: }
4396: #endif /* XML_GENERIC */
4397:
4398: if (attrType.AttrSSchema == NULL)
4399: /* cannot apply these CSS rules */
4400: DoApply = FALSE;
1.136 quint 4401: else if (elType.ElSSchema)
4402: ctxt->schema = elType.ElSSchema;
1.119 vatton 4403: else
1.136 quint 4404: ctxt->schema = attrType.AttrSSchema;
1.119 vatton 4405: }
1.125 vatton 4406: /* check the attribute type */
4407: if (!strcmp (schemaName, "HTML"))
4408: xmlType = XHTML_TYPE;
4409: else if (!strcmp (schemaName, "MathML"))
4410: xmlType = MATH_TYPE;
4411: else if (!strcmp (schemaName, "SVG"))
4412: xmlType = SVG_TYPE;
4413: else if (!strcmp (schemaName, "XLink"))
4414: xmlType = XLINK_TYPE;
4415: else if (!strcmp (schemaName, "Annot"))
4416: xmlType = ANNOT_TYPE;
4417: else
4418: xmlType = XML_TYPE;
4419: kind = TtaGetAttributeKind (attrType);
4420: if (kind == 0 && attrvals[i])
4421: {
4422: /* enumerated value */
4423: MapXMLAttributeValue (xmlType, attrvals[i], attrType, &kind);
4424: /* store the attribute value */
4425: ctxt->attrText[j] = (char *) kind;
4426: }
4427: else
4428: ctxt->attrText[j] = attrvals[i];
1.80 cvs 4429: maxAttr = i + 1;
1.129 vatton 4430: /* update attrLevel */
4431: ctxt->attrLevel[j] = i;
4432: j++;
1.25 cvs 4433: }
4434: i++;
1.117 vatton 4435: /* add a new entry */
4436: k++;
1.129 vatton 4437: if (k < j)
4438: k = j;
1.119 vatton 4439: if (i == 1 && ctxt->schema == NULL)
4440: /* use the document schema */
4441: ctxt->schema = TtaGetDocumentSSchema (doc);
1.1 cvs 4442: }
1.117 vatton 4443: /* set the selector specificity */
4444: ctxt->cssSpecificity = specificity;
1.25 cvs 4445: /* sort the list of ancestors by name order */
4446: max = k;
4447: i = 1;
4448: while (i < max)
1.28 cvs 4449: {
4450: for (k = i + 1; k < max; k++)
4451: if (ctxt->name[i] > ctxt->name[k])
4452: {
4453: j = ctxt->name[i];
4454: ctxt->name[i] = ctxt->name[k];
4455: ctxt->name[k] = j;
4456: j = ctxt->names_nb[i];
4457: ctxt->names_nb[i] = ctxt->names_nb[k];
4458: ctxt->names_nb[k] = j;
4459: j = ctxt->attrType[i];
4460: ctxt->attrType[i] = ctxt->attrType[k];
4461: ctxt->attrType[k] = j;
4462: cur = ctxt->attrText[i];
4463: ctxt->attrText[i] = ctxt->attrText[k];
4464: ctxt->attrText[k] = cur;
4465: }
4466: i++;
4467: }
1.84 cvs 4468:
1.25 cvs 4469: /* Get the schema name of the main element */
1.119 vatton 4470: schemaName = TtaGetSSchemaName (ctxt->schema);
4471: isHTML = (strcmp (schemaName, "HTML") == 0);
4472: tsch = GetPExtension (doc, ctxt->schema, css);
4473: if (tsch && cssRule)
4474: ParseCSSRule (NULL, tsch, (PresentationContext) ctxt, cssRule, css, isHTML);
1.116 vatton 4475: /* future CSS rules should apply */
4476: DoApply = TRUE;
1.1 cvs 4477: return (selector);
4478: }
4479:
4480: /*----------------------------------------------------------------------
1.73 cvs 4481: ParseStyleDeclaration: parse a style declaration
4482: stored in the style element of a document
1.59 cvs 4483: We expect the style string to be of the form:
1.1 cvs 4484: [
4485: e.g: pinky, awful { color: pink, font-family: helvetica }
4486: ----------------------------------------------------------------------*/
1.79 cvs 4487: static void ParseStyleDeclaration (Element el, char *cssRule, Document doc,
4488: CSSInfoPtr css, ThotBool destroy)
1.1 cvs 4489: {
1.79 cvs 4490: GenericContext ctxt;
4491: char *decl_end;
4492: char *sel_end;
4493: char *selector;
1.1 cvs 4494:
4495: /* separate the selectors string */
1.82 cvs 4496: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 4497: decl_end = cssRule;
1.82 cvs 4498: while (*decl_end != EOS && *decl_end != '{')
1.1 cvs 4499: decl_end++;
1.82 cvs 4500: if (*decl_end == EOS)
1.86 cvs 4501: {
4502: CSSParseError ("Invalid selector", cssRule);
4503: return;
4504: }
1.1 cvs 4505: /* verify and clean the selector string */
4506: sel_end = decl_end - 1;
1.82 cvs 4507: while (*sel_end == SPACE || *sel_end == BSPACE ||
4508: *sel_end == EOL || *sel_end == CR)
1.1 cvs 4509: sel_end--;
4510: sel_end++;
1.82 cvs 4511: *sel_end = EOS;
1.1 cvs 4512: selector = cssRule;
4513:
4514: /* now, deal with the content ... */
4515: decl_end++;
4516: cssRule = decl_end;
1.137 vatton 4517: decl_end = &cssRule[strlen (cssRule) - 1];
4518: if (*decl_end != '{')
4519: *decl_end = EOS;
1.1 cvs 4520: /*
4521: * parse the style attribute string and install the corresponding
4522: * presentation attributes on the new element
4523: */
4524: ctxt = TtaGetGenericStyleContext (doc);
4525: if (ctxt == NULL)
4526: return;
4527: ctxt->destroy = destroy;
4528:
1.82 cvs 4529: while ((selector != NULL) && (*selector != EOS))
1.25 cvs 4530: selector = ParseGenericSelector (selector, cssRule, ctxt, doc, css);
1.1 cvs 4531: TtaFreeMemory (ctxt);
4532: }
4533:
4534: /************************************************************************
4535: * *
4536: * EVALUATION FUNCTIONS / CASCADING AND OVERLOADING *
4537: * *
4538: ************************************************************************/
4539:
4540: /*----------------------------------------------------------------------
1.59 cvs 4541: IsImplicitClassName: return wether the Class name is an
1.1 cvs 4542: implicit one, eg "H1" or "H2 EM" meaning it's a GI name
4543: or an HTML context name.
4544: ----------------------------------------------------------------------*/
1.79 cvs 4545: int IsImplicitClassName (char *class, Document doc)
1.1 cvs 4546: {
1.79 cvs 4547: char name[200];
4548: char *cur = name;
4549: char *first;
4550: char save;
4551: SSchema schema;
1.1 cvs 4552:
4553: /* make a local copy */
1.82 cvs 4554: strncpy (name, class, 199);
1.1 cvs 4555: name[199] = 0;
4556:
4557: /* loop looking if each word is a GI */
4558: while (*cur != 0)
4559: {
4560: first = cur;
4561: cur = SkipWord (cur);
4562: save = *cur;
4563: *cur = 0;
4564: schema = NULL;
4565: if (MapGI (first, &schema, doc) == -1)
4566: {
4567: return (0);
4568: }
4569: *cur = save;
1.82 cvs 4570: cur = SkipBlanksAndComments (cur);
1.1 cvs 4571: }
4572: return (1);
4573: }
4574:
4575: /************************************************************************
4576: * *
1.114 quint 4577: * Functions needed for support of HTML: translate to CSS equivalent *
1.1 cvs 4578: * *
4579: ************************************************************************/
4580:
4581: /*----------------------------------------------------------------------
1.59 cvs 4582: HTMLSetBackgroundColor:
1.1 cvs 4583: ----------------------------------------------------------------------*/
1.79 cvs 4584: void HTMLSetBackgroundColor (Document doc, Element el, char *color)
1.1 cvs 4585: {
1.79 cvs 4586: char css_command[100];
1.1 cvs 4587:
1.82 cvs 4588: sprintf (css_command, "background-color: %s", color);
1.114 quint 4589: ParseHTMLSpecificStyle (el, css_command, doc, 0, FALSE);
1.1 cvs 4590: }
4591:
4592: /*----------------------------------------------------------------------
1.59 cvs 4593: HTMLSetBackgroundImage:
1.1 cvs 4594: repeat = repeat value
4595: image = url of background image
4596: ----------------------------------------------------------------------*/
1.79 cvs 4597: void HTMLSetBackgroundImage (Document doc, Element el, int repeat, char *image)
1.1 cvs 4598: {
1.79 cvs 4599: char css_command[400];
1.1 cvs 4600:
4601: /******* check buffer overflow ********/
1.82 cvs 4602: sprintf (css_command, "background-image: url(%s); background-repeat: ", image);
1.1 cvs 4603: if (repeat == STYLE_REPEAT)
1.82 cvs 4604: strcat (css_command, "repeat");
1.1 cvs 4605: else if (repeat == STYLE_HREPEAT)
1.82 cvs 4606: strcat (css_command, "repeat-x");
1.1 cvs 4607: else if (repeat == STYLE_VREPEAT)
1.82 cvs 4608: strcat (css_command, "repeat-y");
1.1 cvs 4609: else
1.82 cvs 4610: strcat (css_command, "no-repeat");
1.114 quint 4611: ParseHTMLSpecificStyle (el, css_command, doc, 0, FALSE);
1.1 cvs 4612: }
4613:
4614: /*----------------------------------------------------------------------
1.59 cvs 4615: HTMLSetForegroundColor:
1.1 cvs 4616: ----------------------------------------------------------------------*/
1.97 vatton 4617: void HTMLSetForegroundColor (Document doc, Element el, char *color)
1.1 cvs 4618: {
1.79 cvs 4619: char css_command[100];
1.1 cvs 4620:
1.82 cvs 4621: sprintf (css_command, "color: %s", color);
1.114 quint 4622: ParseHTMLSpecificStyle (el, css_command, doc, 0, FALSE);
1.1 cvs 4623: }
4624:
4625: /*----------------------------------------------------------------------
1.59 cvs 4626: HTMLResetBackgroundColor:
1.1 cvs 4627: ----------------------------------------------------------------------*/
1.97 vatton 4628: void HTMLResetBackgroundColor (Document doc, Element el)
1.1 cvs 4629: {
1.79 cvs 4630: char css_command[100];
1.1 cvs 4631:
1.82 cvs 4632: sprintf (css_command, "background: red");
1.114 quint 4633: ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1 cvs 4634: }
4635:
4636: /*----------------------------------------------------------------------
1.59 cvs 4637: HTMLResetBackgroundImage:
1.1 cvs 4638: ----------------------------------------------------------------------*/
1.97 vatton 4639: void HTMLResetBackgroundImage (Document doc, Element el)
1.1 cvs 4640: {
1.79 cvs 4641: char css_command[1000];
1.1 cvs 4642:
1.82 cvs 4643: sprintf (css_command, "background-image: url(xx); background-repeat: repeat");
1.114 quint 4644: ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1 cvs 4645: }
4646:
4647: /*----------------------------------------------------------------------
1.59 cvs 4648: HTMLResetForegroundColor:
1.1 cvs 4649: ----------------------------------------------------------------------*/
1.97 vatton 4650: void HTMLResetForegroundColor (Document doc, Element el)
1.1 cvs 4651: {
1.79 cvs 4652: char css_command[100];
1.1 cvs 4653:
1.36 cvs 4654: /* it's not necessary to well know the current color but it must be valid */
1.82 cvs 4655: sprintf (css_command, "color: red");
1.114 quint 4656: ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1 cvs 4657: }
4658:
4659: /*----------------------------------------------------------------------
1.59 cvs 4660: HTMLSetAlinkColor:
1.1 cvs 4661: ----------------------------------------------------------------------*/
1.97 vatton 4662: void HTMLSetAlinkColor (Document doc, char *color)
1.1 cvs 4663: {
1.79 cvs 4664: char css_command[100];
1.1 cvs 4665:
1.82 cvs 4666: sprintf (css_command, "a:link { color: %s }", color);
1.1 cvs 4667: ApplyCSSRules (NULL, css_command, doc, FALSE);
4668: }
4669:
4670: /*----------------------------------------------------------------------
1.59 cvs 4671: HTMLSetAactiveColor:
1.1 cvs 4672: ----------------------------------------------------------------------*/
1.97 vatton 4673: void HTMLSetAactiveColor (Document doc, char *color)
1.1 cvs 4674: {
1.79 cvs 4675: char css_command[100];
1.1 cvs 4676:
1.82 cvs 4677: sprintf (css_command, "a:active { color: %s }", color);
1.1 cvs 4678: ApplyCSSRules (NULL, css_command, doc, FALSE);
4679: }
4680:
4681: /*----------------------------------------------------------------------
1.59 cvs 4682: HTMLSetAvisitedColor:
1.1 cvs 4683: ----------------------------------------------------------------------*/
1.79 cvs 4684: void HTMLSetAvisitedColor (Document doc, char *color)
1.1 cvs 4685: {
1.79 cvs 4686: char css_command[100];
1.1 cvs 4687:
1.82 cvs 4688: sprintf (css_command, "a:visited { color: %s }", color);
1.1 cvs 4689: ApplyCSSRules (NULL, css_command, doc, FALSE);
4690: }
4691:
4692: /*----------------------------------------------------------------------
1.59 cvs 4693: HTMLResetAlinkColor:
1.1 cvs 4694: ----------------------------------------------------------------------*/
4695: void HTMLResetAlinkColor (Document doc)
4696: {
1.79 cvs 4697: char css_command[100];
1.1 cvs 4698:
1.82 cvs 4699: sprintf (css_command, "a:link { color: red }");
1.1 cvs 4700: ApplyCSSRules (NULL, css_command, doc, TRUE);
4701: }
4702:
4703: /*----------------------------------------------------------------------
1.59 cvs 4704: HTMLResetAactiveColor:
1.1 cvs 4705: ----------------------------------------------------------------------*/
4706: void HTMLResetAactiveColor (Document doc)
4707: {
1.79 cvs 4708: char css_command[100];
1.1 cvs 4709:
1.82 cvs 4710: sprintf (css_command, "a:active { color: red }");
1.1 cvs 4711: ApplyCSSRules (NULL, css_command, doc, TRUE);
4712: }
4713:
4714: /*----------------------------------------------------------------------
1.59 cvs 4715: HTMLResetAvisitedColor:
1.1 cvs 4716: ----------------------------------------------------------------------*/
4717: void HTMLResetAvisitedColor (Document doc)
4718: {
1.79 cvs 4719: char css_command[100];
1.1 cvs 4720:
1.82 cvs 4721: sprintf (css_command, "a:visited { color: red }");
1.1 cvs 4722: ApplyCSSRules (NULL, css_command, doc, TRUE);
4723: }
4724:
4725: /*----------------------------------------------------------------------
1.73 cvs 4726: ApplyCSSRules: parse a CSS Style description stored in the
1.1 cvs 4727: header of a HTML document.
4728: ----------------------------------------------------------------------*/
1.79 cvs 4729: void ApplyCSSRules (Element el, char *cssRule, Document doc, ThotBool destroy)
1.1 cvs 4730: {
4731: CSSInfoPtr css;
4732:
1.144 quint 4733: css = SearchCSS (doc, NULL, el);
1.1 cvs 4734: if (css == NULL)
4735: /* create the document css */
1.144 quint 4736: css = AddCSS (doc, doc, CSS_DOCUMENT_STYLE, NULL, NULL, el);
1.1 cvs 4737: ParseStyleDeclaration (el, cssRule, doc, css, destroy);
4738: }
4739:
4740: /*----------------------------------------------------------------------
1.145 quint 4741: ReadCSSRules: is the front-end function called by the document parser
4742: when detecting a <style type="text/css"> indicating it's the
1.1 cvs 4743: beginning of a CSS fragment or when reading a file .css.
4744:
4745: The CSS parser has to handle <!-- ... --> constructs used to
4746: prevent prehistoric browser from displaying the CSS as a text
4747: content. It will stop on any sequence "<x" where x is different
4748: from ! and will return x as to the caller. Theorically x should
1.145 quint 4749: be equal to / for the </style> end of style.
1.1 cvs 4750: The parameter doc gives the document tree that contains CSS information.
4751: The parameter docRef gives the document to which CSS are to be applied.
4752: This function uses the current css context or creates it. It's able
1.23 cvs 4753: to work on the given buffer or call GetNextChar to read the parsed
1.1 cvs 4754: file.
1.133 vatton 4755: The parameter url gives the URL of the style shheet parsed.
1.86 cvs 4756: Parameter numberOfLinesRead indicates the number of lines already
4757: read in the file.
1.1 cvs 4758: Parameter withUndo indicates whether the changes made in the document
1.145 quint 4759: structure and content have to be registered in the Undo queue or not.
4760: refElement is the element (image or use, for instance) that references
4761: the document containing the style element to be parsed.
1.1 cvs 4762: ----------------------------------------------------------------------*/
1.133 vatton 4763: char ReadCSSRules (Document docRef, CSSInfoPtr css, char *buffer, char *url,
1.144 quint 4764: int numberOfLinesRead, ThotBool withUndo,
1.145 quint 4765: Element styleElement, Element refElement)
1.1 cvs 4766: {
1.6 cvs 4767: DisplayMode dispMode;
1.82 cvs 4768: char c;
1.138 vatton 4769: char *cssRule, *base, *saveDocURL, *ptr;
1.19 cvs 4770: int index;
1.1 cvs 4771: int CSSindex;
4772: int CSScomment;
4773: int import;
4774: int openRule;
1.93 vatton 4775: int newlines;
1.14 cvs 4776: ThotBool HTMLcomment;
1.102 vatton 4777: ThotBool toParse, eof, quoted;
1.36 cvs 4778: ThotBool ignoreMedia, media;
1.88 cvs 4779: ThotBool noRule, ignoreImport;
1.1 cvs 4780:
4781: CSScomment = MAX_CSS_LENGTH;
4782: HTMLcomment = FALSE;
4783: CSSindex = 0;
4784: toParse = FALSE;
4785: noRule = FALSE;
1.36 cvs 4786: media = FALSE;
1.88 cvs 4787: ignoreImport = FALSE;
1.1 cvs 4788: ignoreMedia = FALSE;
4789: import = MAX_CSS_LENGTH;
4790: eof = FALSE;
4791: openRule = 0;
1.82 cvs 4792: c = SPACE;
1.1 cvs 4793: index = 0;
1.134 vatton 4794: base = NULL;
1.135 vatton 4795: quoted = FALSE;
1.93 vatton 4796: /* number of new lines parsed */
4797: newlines = 0;
1.6 cvs 4798: /* avoid too many redisplay */
4799: dispMode = TtaGetDisplayMode (docRef);
4800: if (dispMode == DisplayImmediately)
4801: TtaSetDisplayMode (docRef, DeferredDisplay);
1.18 cvs 4802:
4803: /* look for the CSS context */
4804: if (css == NULL)
1.144 quint 4805: css = SearchCSS (docRef, NULL, styleElement);
1.18 cvs 4806: if (css == NULL)
1.144 quint 4807: css = AddCSS (docRef, docRef, CSS_DOCUMENT_STYLE, NULL, NULL,
4808: styleElement);
1.145 quint 4809: if (css)
4810: css->refEl = refElement;
1.1 cvs 4811:
1.144 quint 4812: /* register parsed CSS file and the document to which CSS are to be applied*/
1.86 cvs 4813: ParsedDoc = docRef;
1.133 vatton 4814: if (url)
4815: DocURL = url;
1.86 cvs 4816: else
4817: /* the CSS source in within the document itself */
4818: DocURL = DocumentURLs[docRef];
4819: LineNumber = numberOfLinesRead + 1;
1.93 vatton 4820: NewLineSkipped = 0;
1.82 cvs 4821: while (CSSindex < MAX_CSS_LENGTH && c != EOS && !eof)
4822: {
4823: c = buffer[index++];
4824: eof = (c == EOS);
4825: CSSbuffer[CSSindex] = c;
4826: if (CSScomment == MAX_CSS_LENGTH ||
4827: c == '*' || c == '/' || c == '<')
4828: {
4829: /* we're not within a comment or we're parsing * or / */
4830: switch (c)
4831: {
4832: case '@': /* perhaps an import primitive */
1.135 vatton 4833: if (!quoted)
4834: import = CSSindex;
1.82 cvs 4835: break;
4836: case ';':
1.135 vatton 4837: if (!quoted && !media && import != MAX_CSS_LENGTH)
1.82 cvs 4838: {
4839: if (strncasecmp (&CSSbuffer[import+1], "import", 6))
4840: /* it's not an import */
4841: import = MAX_CSS_LENGTH;
4842: /* save the text */
4843: noRule = TRUE;
4844: }
4845: break;
4846: case '*':
1.135 vatton 4847: if (!quoted && CSScomment == MAX_CSS_LENGTH && CSSindex > 0 &&
1.82 cvs 4848: CSSbuffer[CSSindex - 1] == '/')
4849: /* start a comment */
4850: CSScomment = CSSindex - 1;
4851: break;
4852: case '/':
1.135 vatton 4853: if (!quoted && CSSindex > 1 && CSScomment != MAX_CSS_LENGTH &&
1.82 cvs 4854: CSSbuffer[CSSindex - 1] == '*')
4855: {
4856: /* close a comment:and ignore its contents */
4857: CSSindex = CSScomment - 1; /* will be incremented later */
4858: CSScomment = MAX_CSS_LENGTH;
1.93 vatton 4859: /* clean up the buffer */
1.103 vatton 4860: if (newlines && CSSindex > 0)
4861: while (CSSindex > 0 &&
4862: (CSSbuffer[CSSindex] == SPACE ||
4863: CSSbuffer[CSSindex] == BSPACE ||
4864: CSSbuffer[CSSindex] == EOL ||
4865: CSSbuffer[CSSindex] == TAB ||
4866: CSSbuffer[CSSindex] == __CR__))
1.93 vatton 4867: {
4868: if ( CSSbuffer[CSSindex] == EOL)
4869: {
4870: LineNumber ++;
4871: newlines --;
4872: }
4873: CSSindex--;
4874: }
1.82 cvs 4875: }
1.135 vatton 4876: else if (!quoted && CSScomment == MAX_CSS_LENGTH && CSSindex > 0 &&
1.82 cvs 4877: CSSbuffer[CSSindex - 1] == '<')
4878: {
4879: /* this is the closing tag ! */
4880: CSSindex -= 2; /* remove </ from the CSS string */
4881: noRule = TRUE;
4882: }
4883: break;
4884: case '<':
1.135 vatton 4885: if (!quoted && CSScomment == MAX_CSS_LENGTH)
1.82 cvs 4886: {
4887: /* only if we're not parsing a comment */
4888: c = buffer[index++];
4889: eof = (c == EOS);
4890: if (c == '!')
4891: {
4892: /* CSS within an HTML comment */
4893: HTMLcomment = TRUE;
4894: CSSindex++;
4895: CSSbuffer[CSSindex] = c;
4896: }
4897: else if (c == EOS)
4898: CSSindex++;
4899: }
4900: break;
4901: case '-':
1.135 vatton 4902: if (!quoted && CSSindex > 0 && CSSbuffer[CSSindex - 1] == '-' &&
1.82 cvs 4903: HTMLcomment)
4904: /* CSS within an HTML comment */
4905: noRule = TRUE;
4906: break;
4907: case '>':
1.135 vatton 4908: if (!quoted && HTMLcomment)
1.82 cvs 4909: noRule = TRUE;
4910: break;
4911: case ' ':
1.135 vatton 4912: if (!quoted && import != MAX_CSS_LENGTH && openRule == 0)
1.82 cvs 4913: media = !strncmp (&CSSbuffer[import+1], "media", 5);
4914: break;
4915: case '{':
1.135 vatton 4916: if (!quoted)
1.82 cvs 4917: {
1.135 vatton 4918: openRule++;
4919: if (import != MAX_CSS_LENGTH && openRule == 1 && media)
4920: {
4921: /* is it the screen concerned? */
4922: CSSbuffer[CSSindex+1] = EOS;
4923: if (TtaIsPrinting ())
4924: base = strstr (&CSSbuffer[import], "print");
4925: else
4926: base = strstr (&CSSbuffer[import], "screen");
4927: if (base == NULL)
4928: base = strstr (&CSSbuffer[import], "all");
4929: if (base == NULL)
4930: ignoreMedia = TRUE;
4931: noRule = TRUE;
4932: }
4933: }
4934: break;
4935: case '}':
4936: if (!quoted)
4937: {
4938: openRule--;
4939: if (import != MAX_CSS_LENGTH && openRule == 0)
4940: {
4941: import = MAX_CSS_LENGTH;
4942: noRule = TRUE;
4943: ignoreMedia = FALSE;
4944: media = FALSE;
4945: }
1.82 cvs 4946: else
1.135 vatton 4947: toParse = TRUE;
1.82 cvs 4948: }
4949: break;
1.135 vatton 4950: case '"':
4951: if (quoted)
1.82 cvs 4952: {
1.135 vatton 4953: if (CSSbuffer[CSSindex - 1] != '\\')
4954: quoted = FALSE;
1.82 cvs 4955: }
4956: else
1.135 vatton 4957: quoted = TRUE;
1.82 cvs 4958: break;
4959: default:
1.86 cvs 4960: if (c == EOL)
1.93 vatton 4961: newlines++;
1.82 cvs 4962: break;
4963: }
4964: }
1.93 vatton 4965: else if (c == EOL)
4966: LineNumber++;
1.82 cvs 4967: if (c != CR)
4968: CSSindex++;
4969:
4970: if (CSSindex >= MAX_CSS_LENGTH && CSScomment < MAX_CSS_LENGTH)
4971: /* we're still parsing a comment: remove the text comment */
4972: CSSindex = CSScomment;
4973:
4974: if (CSSindex >= MAX_CSS_LENGTH || toParse || noRule)
4975: {
4976: CSSbuffer[CSSindex] = EOS;
4977: /* parse a not empty string */
4978: if (CSSindex > 0)
4979: {
1.50 cvs 4980: /* apply CSS rule if it's not just a saving of text */
4981: if (!noRule && !ignoreMedia)
1.88 cvs 4982: {
4983: /* future import rules must be ignored */
4984: ignoreImport = TRUE;
4985: ParseStyleDeclaration (NULL, CSSbuffer, docRef, css, FALSE);
1.93 vatton 4986: LineNumber += newlines;
4987: newlines = 0;
4988: NewLineSkipped = 0;
1.88 cvs 4989: }
1.82 cvs 4990: else if (import != MAX_CSS_LENGTH &&
4991: !strncasecmp (&CSSbuffer[import+1], "import", 6))
4992: {
4993: /* import section */
4994: cssRule = &CSSbuffer[import+7];
4995: cssRule = TtaSkipBlanks (cssRule);
1.93 vatton 4996: /* save the current line number */
4997: newlines += LineNumber;
1.82 cvs 4998: if (!strncasecmp (cssRule, "url", 3))
4999: {
1.50 cvs 5000: cssRule = &cssRule[3];
1.82 cvs 5001: cssRule = TtaSkipBlanks (cssRule);
5002: if (*cssRule == '(')
5003: {
5004: cssRule++;
5005: cssRule = TtaSkipBlanks (cssRule);
1.102 vatton 5006: quoted = (*cssRule == '"' || *cssRule == '\'');
5007: if (quoted)
5008: cssRule++;
1.82 cvs 5009: base = cssRule;
5010: while (*cssRule != EOS && *cssRule != ')')
5011: cssRule++;
1.102 vatton 5012: if (quoted)
5013: cssRule--;
1.82 cvs 5014: }
5015: }
1.87 cvs 5016: else if (*cssRule == '"')
5017: {
1.88 cvs 5018: /*
5019: Do we have to accept single quotes?
5020: Double quotes are acceted here.
5021: Escaped quotes are not handled. See function SkipQuotedString
5022: */
1.87 cvs 5023: cssRule++;
5024: cssRule = TtaSkipBlanks (cssRule);
5025: base = cssRule;
5026: while (*cssRule != EOS && *cssRule != '"')
5027: cssRule++;
1.133 vatton 5028: }
5029: if (*cssRule != EOS)
5030: /* isolate the file name */
5031: *cssRule = EOS;
5032: /* check if a media is defined */
5033: cssRule++;
5034: cssRule = TtaSkipBlanks (cssRule);
5035: if (*cssRule != ';')
5036: {
5037: if (TtaIsPrinting ())
5038: ignoreImport = (strncasecmp (cssRule, "print", 5) &&
5039: strncasecmp (cssRule, "all", 3));
5040: else
5041: ignoreImport = (strncasecmp (cssRule, "screen", 6) &&
5042: strncasecmp (cssRule, "all", 3));
5043: }
5044: if (!ignoreImport)
5045: {
5046: /* save the displayed URL when an error is reported */
5047: saveDocURL = DocURL;
1.138 vatton 5048: ptr = TtaStrdup (base);
5049: /* get the CSS URI in UTF-8 */
5050: ptr = ReallocUTF8String (ptr, docRef);
1.133 vatton 5051: LoadStyleSheet (base, docRef, NULL, css,
5052: css->media[docRef],
5053: css->category == CSS_USER_STYLE);
5054: /* restore the displayed URL when an error is reported */
5055: DocURL = saveDocURL;
1.138 vatton 5056: TtaFreeMemory (ptr);
1.82 cvs 5057: }
1.93 vatton 5058: /* restore the number of lines */
5059: LineNumber = newlines;
5060: newlines = 0;
1.82 cvs 5061: import = MAX_CSS_LENGTH;
5062: }
1.93 vatton 5063:
1.82 cvs 5064: }
5065: toParse = FALSE;
5066: noRule = FALSE;
5067: CSSindex = 0;
1.50 cvs 5068: }
1.82 cvs 5069: }
1.6 cvs 5070: /* restore the display mode */
5071: if (dispMode == DisplayImmediately)
1.82 cvs 5072: TtaSetDisplayMode (docRef, dispMode);
1.86 cvs 5073:
5074: /* Prepare the context for style attributes */
5075: DocURL = DocumentURLs[docRef];
5076: LineNumber = -1;
1.1 cvs 5077: return (c);
5078: }
1.89 cvs 5079:
Webmaster