Annotation of Amaya/amaya/styleparser.c, revision 1.148
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;
1.148 ! vatton 2512: unsigned int savedtype = 0;
! 2513: ThotBool moved;
! 2514:
! 2515: /* move the HTML rule to the root element */
! 2516: moved = ((context->type == HTML_EL_HTML || context->type == HTML_EL_BODY) && isHTML);
! 2517: if (moved)
! 2518: {
! 2519: if (element)
! 2520: element = TtaGetMainRoot (context->doc);
! 2521: else
! 2522: {
! 2523: savedtype = context->type;
! 2524: context->type = HTML_EL_Document;
! 2525: }
! 2526: }
1.1 cvs 2527:
2528: best.typed_data.unit = STYLE_UNIT_INVALID;
2529: best.typed_data.real = FALSE;
1.82 cvs 2530: if (!strncasecmp (cssRule, "transparent", strlen ("transparent")))
1.1 cvs 2531: {
2532: best.typed_data.value = STYLE_PATTERN_NONE;
2533: best.typed_data.unit = STYLE_UNIT_REL;
1.116 vatton 2534: if (DoApply)
1.117 vatton 2535: {
2536: if (tsch)
2537: cssRule = CheckImportantRule (cssRule, context);
2538: TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
2539: }
1.65 cvs 2540: cssRule = SkipWord (cssRule);
1.1 cvs 2541: }
2542: else
2543: {
2544: cssRule = ParseCSSColor (cssRule, &best);
1.116 vatton 2545: if (best.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.1 cvs 2546: {
1.117 vatton 2547: if (tsch)
2548: cssRule = CheckImportantRule (cssRule, context);
1.1 cvs 2549: /* install the new presentation. */
2550: TtaSetStylePresentation (PRBackground, element, tsch, context, best);
1.59 cvs 2551: /* thot specificity: need to set fill pattern for background color */
1.1 cvs 2552: best.typed_data.value = STYLE_PATTERN_BACKGROUND;
2553: best.typed_data.unit = STYLE_UNIT_REL;
2554: TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
2555: best.typed_data.value = 1;
2556: best.typed_data.unit = STYLE_UNIT_REL;
2557: TtaSetStylePresentation (PRShowBox, element, tsch, context, best);
2558: }
2559: }
2560:
2561: /* restore the refered element */
1.148 ! vatton 2562: if (moved && !element)
! 2563: context->type = savedtype;
1.1 cvs 2564: return (cssRule);
2565: }
2566:
1.63 cvs 2567:
2568: /*----------------------------------------------------------------------
1.65 cvs 2569: ParseSVGStroke: parse a SVG stroke property
2570: ----------------------------------------------------------------------*/
1.79 cvs 2571: static char *ParseSVGStroke (Element element, PSchema tsch,
2572: PresentationContext context, char *cssRule,
2573: CSSInfoPtr css, ThotBool isHTML)
1.65 cvs 2574: {
2575: PresentationValue best;
2576:
2577: best.typed_data.unit = STYLE_UNIT_INVALID;
2578: best.typed_data.real = FALSE;
1.82 cvs 2579: if (!strncasecmp (cssRule, "none", 4))
1.65 cvs 2580: {
2581: best.typed_data.value = -2; /* -2 means transparent */
2582: best.typed_data.unit = STYLE_UNIT_REL;
1.116 vatton 2583: if (DoApply)
1.117 vatton 2584: {
2585: if (tsch)
2586: cssRule = CheckImportantRule (cssRule, context);
2587: TtaSetStylePresentation (PRForeground, element, tsch, context, best);
2588: }
1.65 cvs 2589: cssRule = SkipWord (cssRule);
2590: }
2591: else
2592: {
2593: cssRule = ParseCSSColor (cssRule, &best);
1.116 vatton 2594: if (best.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.117 vatton 2595: {
2596: if (tsch)
2597: cssRule = CheckImportantRule (cssRule, context);
2598: /* install the new presentation */
2599: TtaSetStylePresentation (PRForeground, element, tsch, context, best);
2600: }
1.65 cvs 2601: }
2602: return (cssRule);
2603: }
2604:
2605: /*----------------------------------------------------------------------
1.63 cvs 2606: ParseSVGFill: parse a SVG fill property
2607: ----------------------------------------------------------------------*/
1.79 cvs 2608: static char *ParseSVGFill (Element element, PSchema tsch,
2609: PresentationContext context, char *cssRule,
2610: CSSInfoPtr css, ThotBool isHTML)
1.63 cvs 2611: {
2612: PresentationValue best;
2613:
2614: best.typed_data.unit = STYLE_UNIT_INVALID;
2615: best.typed_data.real = FALSE;
1.82 cvs 2616: if (!strncasecmp (cssRule, "none", 4))
1.63 cvs 2617: {
2618: best.typed_data.value = STYLE_PATTERN_NONE;
2619: best.typed_data.unit = STYLE_UNIT_REL;
1.116 vatton 2620: if (DoApply)
1.117 vatton 2621: {
2622: if (tsch)
2623: cssRule = CheckImportantRule (cssRule, context);
2624: TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
2625: }
1.65 cvs 2626: cssRule = SkipWord (cssRule);
1.63 cvs 2627: }
2628: else
2629: {
2630: cssRule = ParseCSSColor (cssRule, &best);
1.116 vatton 2631: if (best.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.63 cvs 2632: {
1.117 vatton 2633: if (tsch)
2634: cssRule = CheckImportantRule (cssRule, context);
1.63 cvs 2635: /* install the new presentation. */
2636: TtaSetStylePresentation (PRBackground, element, tsch, context, best);
2637: /* thot specificity: need to set fill pattern for background color */
2638: best.typed_data.value = STYLE_PATTERN_BACKGROUND;
2639: best.typed_data.unit = STYLE_UNIT_REL;
2640: TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
2641: }
2642: }
2643: return (cssRule);
2644: }
2645:
1.1 cvs 2646: /*----------------------------------------------------------------------
1.59 cvs 2647: ParseCSSBackgroundImageCallback: Callback called asynchronously by
2648: FetchImage when a background image has been fetched.
1.1 cvs 2649: ----------------------------------------------------------------------*/
1.82 cvs 2650: void ParseCSSBackgroundImageCallback (Document doc, Element element,
2651: char *file, void *extra)
1.1 cvs 2652: {
1.82 cvs 2653: DisplayMode dispMode;
2654: BackgroundImageCallbackPtr callblock;
2655: Element el;
2656: PSchema tsch;
2657: PresentationContext context;
2658: PresentationValue image;
2659: PresentationValue value;
1.1 cvs 2660:
1.82 cvs 2661: callblock = (BackgroundImageCallbackPtr) extra;
1.34 cvs 2662: if (callblock == NULL)
2663: return;
1.1 cvs 2664:
1.34 cvs 2665: /* avoid too many redisplay */
2666: dispMode = TtaGetDisplayMode (doc);
2667: if (dispMode == DisplayImmediately)
2668: TtaSetDisplayMode (doc, DeferredDisplay);
2669:
2670: el = callblock->el;
2671: tsch = callblock->tsch;
2672: context = &callblock->context.specific;
2673:
2674: /* Ok the image was fetched, finish the background-image handling */
2675: image.pointer = file;
2676: TtaSetStylePresentation (PRBackgroundPicture, el, tsch, context, image);
1.1 cvs 2677:
1.70 cvs 2678: /* enforce the showbox */
1.34 cvs 2679: value.typed_data.value = 1;
2680: value.typed_data.unit = STYLE_UNIT_REL;
2681: value.typed_data.real = FALSE;
2682: TtaSetStylePresentation (PRShowBox, el, tsch, context, value);
2683:
2684: TtaFreeMemory (callblock);
2685: /* restore the display mode */
2686: if (dispMode == DisplayImmediately)
2687: TtaSetDisplayMode (doc, dispMode);
1.1 cvs 2688: }
2689:
2690:
2691: /*----------------------------------------------------------------------
2692: GetCSSBackgroundURL searches a CSS BackgroundImage url within
2693: the styleString.
2694: Returns NULL or a new allocated url string.
2695: ----------------------------------------------------------------------*/
1.79 cvs 2696: char *GetCSSBackgroundURL (char *styleString)
1.1 cvs 2697: {
1.79 cvs 2698: char *b, *e, *ptr;
2699: int len;
1.1 cvs 2700:
2701: ptr = NULL;
1.82 cvs 2702: b = strstr (styleString, "url");
1.1 cvs 2703: if (b != NULL)
2704: {
2705: b += 3;
1.82 cvs 2706: b = SkipBlanksAndComments (b);
2707: if (*b == '(')
1.1 cvs 2708: {
2709: b++;
1.82 cvs 2710: b = SkipBlanksAndComments (b);
1.1 cvs 2711: /*** Caution: Strings can either be written with double quotes or
2712: with single quotes. Only double quotes are handled here.
2713: Escaped quotes are not handled. See function SkipQuotedString */
1.82 cvs 2714: if (*b == '"')
1.1 cvs 2715: {
2716: b++;
2717: /* search the url end */
2718: e = b;
1.82 cvs 2719: while (*e != EOS && *e != '"')
1.1 cvs 2720: e++;
2721: }
2722: else
2723: {
2724: /* search the url end */
2725: e = b;
1.82 cvs 2726: while (*e != EOS && *e != ')')
1.1 cvs 2727: e++;
2728: }
1.82 cvs 2729: if (*e != EOS)
1.1 cvs 2730: {
2731: len = (int)(e - b);
1.82 cvs 2732: ptr = (char*) TtaGetMemory (len+1);
2733: strncpy (ptr, b, len);
2734: ptr[len] = EOS;
1.1 cvs 2735: }
2736: }
2737: }
2738: return (ptr);
2739: }
2740:
2741:
2742: /*----------------------------------------------------------------------
1.59 cvs 2743: ParseCSSBackgroundImage: parse a CSS BackgroundImage attribute string.
1.1 cvs 2744: ----------------------------------------------------------------------*/
1.79 cvs 2745: static char *ParseCSSBackgroundImage (Element element, PSchema tsch,
2746: PresentationContext context,
2747: char *cssRule, CSSInfoPtr css,
2748: ThotBool isHTML)
1.1 cvs 2749: {
1.49 cvs 2750: Element el;
2751: GenericContext gblock;
1.71 cvs 2752: PresentationContext sblock;
1.1 cvs 2753: BackgroundImageCallbackPtr callblock;
1.49 cvs 2754: PresentationValue image, value;
1.79 cvs 2755: char *url;
1.82 cvs 2756: char *bg_image;
1.79 cvs 2757: char saved;
2758: char *base;
2759: char tempname[MAX_LENGTH];
2760: char imgname[MAX_LENGTH];
1.148 ! vatton 2761: unsigned int savedtype = 0;
! 2762: ThotBool moved;
! 2763:
! 2764: /* default element for FetchImage */
! 2765: el = TtaGetMainRoot (context->doc);
! 2766: /* move the HTML rule to the root element */
! 2767: moved = ((context->type == HTML_EL_HTML || context->type == HTML_EL_BODY) && isHTML);
! 2768: if (moved)
! 2769: {
! 2770: if (element)
! 2771: element = el;
! 2772: else
! 2773: {
! 2774: savedtype = context->type;
! 2775: context->type = HTML_EL_Document;
! 2776: }
! 2777: }
! 2778: else if (element)
! 2779: el = element;
1.1 cvs 2780:
2781: url = NULL;
1.82 cvs 2782: cssRule = SkipBlanksAndComments (cssRule);
2783: if (!strncasecmp (cssRule, "url", 3))
1.1 cvs 2784: {
2785: cssRule += 3;
1.82 cvs 2786: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 2787: if (*cssRule == '(')
2788: {
2789: cssRule++;
1.82 cvs 2790: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 2791: /*** Caution: Strings can either be written with double quotes or
2792: with single quotes. Only double quotes are handled here.
2793: Escaped quotes are not handled. See function SkipQuotedString */
2794: if (*cssRule == '"')
2795: {
2796: cssRule++;
2797: base = cssRule;
1.82 cvs 2798: while (*cssRule != EOS && *cssRule != '"')
1.1 cvs 2799: cssRule++;
2800: }
2801: else
2802: {
2803: base = cssRule;
2804: while (*cssRule != EOS && *cssRule != ')')
2805: cssRule++;
2806: }
2807: saved = *cssRule;
1.82 cvs 2808: *cssRule = EOS;
2809: url = TtaStrdup (base);
1.1 cvs 2810: *cssRule = saved;
2811: if (saved == '"')
2812: /* we need to skip two characters */
2813: cssRule++;
2814: }
2815: cssRule++;
2816:
2817: if (context->destroy)
2818: {
2819: /* remove the background image PRule */
2820: image.pointer = NULL;
2821: TtaSetStylePresentation (PRBackgroundPicture, element, tsch, context, image);
2822: if (TtaGetStylePresentation (PRFillPattern, element, tsch, context, &value) < 0)
2823: {
2824: /* there is no FillPattern rule -> remove ShowBox rule */
2825: value.typed_data.value = 1;
2826: value.typed_data.unit = STYLE_UNIT_REL;
2827: value.typed_data.real = FALSE;
2828: TtaSetStylePresentation (PRShowBox, element, tsch, context, value);
2829: }
2830: }
2831: else if (url)
2832: {
1.30 cvs 2833: bg_image = TtaGetEnvString ("ENABLE_BG_IMAGES");
1.82 cvs 2834: if (bg_image == NULL || !strcasecmp (bg_image, "yes"))
1.1 cvs 2835: {
2836: callblock = (BackgroundImageCallbackPtr) TtaGetMemory(sizeof(BackgroundImageCallbackBlock));
2837: if (callblock != NULL)
2838: {
2839: callblock->el = element;
2840: callblock->tsch = tsch;
2841: if (element == NULL)
1.18 cvs 2842: {
2843: gblock = (GenericContext) context;
2844: memcpy (&callblock->context.generic, gblock,
2845: sizeof (GenericContextBlock));
2846: }
2847: else
2848: {
2849: sblock = context;
2850: memcpy (&callblock->context.specific, sblock,
2851: sizeof(PresentationContextBlock));
2852: }
2853:
2854: /* check if the image url is related to an external CSS */
2855: if (css != NULL && css->category == CSS_EXTERNAL_STYLE)
2856: {
2857: NormalizeURL (url, 0, tempname, imgname, css->url);
2858: /* fetch and display background image of element */
1.49 cvs 2859: FetchImage (context->doc, el, tempname, AMAYA_LOAD_IMAGE, ParseCSSBackgroundImageCallback, callblock);
1.18 cvs 2860: }
2861: else
1.49 cvs 2862: FetchImage (context->doc, el, url, AMAYA_LOAD_IMAGE, ParseCSSBackgroundImageCallback, callblock);
1.18 cvs 2863: }
2864: }
2865:
2866: if (url)
2867: TtaFreeMemory (url);
2868: }
2869: }
1.148 ! vatton 2870:
! 2871: /* restore the refered element */
! 2872: if (moved && !element)
! 2873: context->type = savedtype;
1.18 cvs 2874: return (cssRule);
2875: }
2876:
2877: /*----------------------------------------------------------------------
1.59 cvs 2878: ParseCSSBackgroundRepeat: parse a CSS BackgroundRepeat attribute string.
1.18 cvs 2879: ----------------------------------------------------------------------*/
1.79 cvs 2880: static char *ParseCSSBackgroundRepeat (Element element, PSchema tsch,
1.97 vatton 2881: PresentationContext context,
2882: char *cssRule, CSSInfoPtr css, ThotBool isHTML)
1.18 cvs 2883: {
2884: PresentationValue repeat;
1.148 ! vatton 2885: unsigned int savedtype = 0;
! 2886: ThotBool moved;
! 2887:
! 2888: /* move the HTML rule to the root element */
! 2889: moved = ((context->type == HTML_EL_HTML || context->type == HTML_EL_BODY) && isHTML);
! 2890: if (moved)
! 2891: {
! 2892: if (element)
! 2893: element = TtaGetMainRoot (context->doc);
! 2894: else
! 2895: {
! 2896: savedtype = context->type;
! 2897: context->type = HTML_EL_Document;
! 2898: }
! 2899: }
1.18 cvs 2900:
2901: repeat.typed_data.value = STYLE_REALSIZE;
2902: repeat.typed_data.unit = STYLE_UNIT_REL;
2903: repeat.typed_data.real = FALSE;
1.82 cvs 2904: cssRule = SkipBlanksAndComments (cssRule);
2905: if (!strncasecmp (cssRule, "no-repeat", 9))
1.18 cvs 2906: repeat.typed_data.value = STYLE_REALSIZE;
1.82 cvs 2907: else if (!strncasecmp (cssRule, "repeat-y", 8))
1.18 cvs 2908: repeat.typed_data.value = STYLE_VREPEAT;
1.82 cvs 2909: else if (!strncasecmp (cssRule, "repeat-x", 8))
1.18 cvs 2910: repeat.typed_data.value = STYLE_HREPEAT;
1.82 cvs 2911: else if (!strncasecmp (cssRule, "repeat", 6))
1.18 cvs 2912: repeat.typed_data.value = STYLE_REPEAT;
2913: else
2914: return (cssRule);
2915:
2916: /* install the new presentation */
1.116 vatton 2917: if (DoApply)
1.117 vatton 2918: {
2919: /* check if it's an important rule */
2920: if (tsch)
2921: cssRule = CheckImportantRule (cssRule, context);
2922: TtaSetStylePresentation (PRPictureMode, element, tsch, context, repeat);
2923: }
1.18 cvs 2924: cssRule = SkipWord (cssRule);
1.148 ! vatton 2925:
! 2926: /* restore the refered element */
! 2927: if (moved && !element)
! 2928: context->type = savedtype;
! 2929: return (cssRule);
1.18 cvs 2930: }
2931:
2932: /*----------------------------------------------------------------------
1.59 cvs 2933: ParseCSSBackgroundAttachment: parse a CSS BackgroundAttachment
1.18 cvs 2934: attribute string.
2935: ----------------------------------------------------------------------*/
1.79 cvs 2936: static char *ParseCSSBackgroundAttachment (Element element, PSchema tsch,
2937: PresentationContext context,
2938: char *cssRule, CSSInfoPtr css,
2939: ThotBool isHTML)
1.18 cvs 2940: {
1.148 ! vatton 2941: unsigned int savedtype = 0;
! 2942: ThotBool moved;
! 2943:
! 2944: /* move the HTML rule to the root element */
! 2945: moved = ((context->type == HTML_EL_HTML || context->type == HTML_EL_BODY) && isHTML);
! 2946: if (moved)
! 2947: {
! 2948: if (element)
! 2949: element = TtaGetMainRoot (context->doc);
! 2950: else
! 2951: {
! 2952: savedtype = context->type;
! 2953: context->type = HTML_EL_Document;
! 2954: }
! 2955: }
! 2956:
1.82 cvs 2957: cssRule = SkipBlanksAndComments (cssRule);
2958: if (!strncasecmp (cssRule, "scroll", 6))
1.18 cvs 2959: cssRule = SkipWord (cssRule);
1.82 cvs 2960: else if (!strncasecmp (cssRule, "fixed", 5))
1.18 cvs 2961: cssRule = SkipWord (cssRule);
1.148 ! vatton 2962:
! 2963: /* restore the refered element */
! 2964: if (moved && !element)
! 2965: context->type = savedtype;
1.18 cvs 2966: return (cssRule);
1.1 cvs 2967: }
2968:
2969: /*----------------------------------------------------------------------
1.59 cvs 2970: ParseCSSBackgroundPosition: parse a CSS BackgroundPosition
1.1 cvs 2971: attribute string.
2972: ----------------------------------------------------------------------*/
1.79 cvs 2973: static char *ParseCSSBackgroundPosition (Element element, PSchema tsch,
2974: PresentationContext context,
2975: char *cssRule, CSSInfoPtr css,
2976: ThotBool isHTML)
1.1 cvs 2977: {
1.18 cvs 2978: PresentationValue repeat;
1.148 ! vatton 2979: unsigned int savedtype = 0;
! 2980: ThotBool moved;
1.18 cvs 2981: ThotBool ok;
1.1 cvs 2982:
1.148 ! vatton 2983: /* move the HTML rule to the root element */
! 2984: moved = ((context->type == HTML_EL_HTML || context->type == HTML_EL_BODY) && isHTML);
! 2985: if (moved)
! 2986: {
! 2987: if (element)
! 2988: element = TtaGetMainRoot (context->doc);
! 2989: else
! 2990: {
! 2991: savedtype = context->type;
! 2992: context->type = HTML_EL_Document;
! 2993: }
! 2994: }
! 2995:
1.82 cvs 2996: cssRule = SkipBlanksAndComments (cssRule);
1.18 cvs 2997: ok = TRUE;
1.82 cvs 2998: if (!strncasecmp (cssRule, "left", 4))
1.18 cvs 2999: cssRule = SkipWord (cssRule);
1.82 cvs 3000: else if (!strncasecmp (cssRule, "right", 5))
1.18 cvs 3001: cssRule = SkipWord (cssRule);
1.82 cvs 3002: else if (!strncasecmp (cssRule, "center", 6))
1.18 cvs 3003: cssRule = SkipWord (cssRule);
1.82 cvs 3004: else if (!strncasecmp (cssRule, "top", 3))
1.18 cvs 3005: cssRule = SkipWord (cssRule);
1.82 cvs 3006: else if (!strncasecmp (cssRule, "bottom", 6))
1.18 cvs 3007: cssRule = SkipWord (cssRule);
1.110 vatton 3008: else if (isdigit (*cssRule) || *cssRule == '.')
1.18 cvs 3009: cssRule = SkipWord (cssRule);
3010: else
3011: ok = FALSE;
3012:
1.116 vatton 3013: if (ok && DoApply)
1.18 cvs 3014: {
3015: /* force realsize for the background image */
3016: repeat.typed_data.value = STYLE_REALSIZE;
3017: repeat.typed_data.unit = STYLE_UNIT_REL;
3018: repeat.typed_data.real = FALSE;
1.117 vatton 3019: /* check if it's an important rule */
3020: if (tsch)
3021: cssRule = CheckImportantRule (cssRule, context);
1.18 cvs 3022: TtaSetStylePresentation (PRPictureMode, element, tsch, context, repeat);
3023: }
1.148 ! vatton 3024:
! 3025: /* restore the refered element */
! 3026: if (moved && !element)
! 3027: context->type = savedtype;
1.18 cvs 3028: return (cssRule);
3029: }
3030:
3031: /*----------------------------------------------------------------------
1.59 cvs 3032: ParseCSSBackground: parse a CSS background attribute
1.18 cvs 3033: ----------------------------------------------------------------------*/
1.79 cvs 3034: static char *ParseCSSBackground (Element element, PSchema tsch,
3035: PresentationContext context, char *cssRule,
3036: CSSInfoPtr css, ThotBool isHTML)
1.18 cvs 3037: {
1.79 cvs 3038: char *ptr;
1.93 vatton 3039: int skippedNL;
1.18 cvs 3040:
1.82 cvs 3041: cssRule = SkipBlanksAndComments (cssRule);
3042: while (*cssRule != ';' && *cssRule != EOS && *cssRule != ',')
1.18 cvs 3043: {
1.71 cvs 3044: /* perhaps a Background Image */
1.82 cvs 3045: if (!strncasecmp (cssRule, "url", 3))
1.63 cvs 3046: cssRule = ParseCSSBackgroundImage (element, tsch, context, cssRule,
3047: css, isHTML);
1.18 cvs 3048: /* perhaps a Background Attachment */
1.82 cvs 3049: else if (!strncasecmp (cssRule, "scroll", 6) ||
3050: !strncasecmp (cssRule, "fixed", 5))
1.63 cvs 3051: cssRule = ParseCSSBackgroundAttachment (element, tsch, context,
3052: cssRule, css, isHTML);
1.18 cvs 3053: /* perhaps a Background Repeat */
1.82 cvs 3054: else if (!strncasecmp (cssRule, "no-repeat", 9) ||
3055: !strncasecmp (cssRule, "repeat-y", 8) ||
3056: !strncasecmp (cssRule, "repeat-x", 8) ||
3057: !strncasecmp (cssRule, "repeat", 6))
3058: cssRule = ParseCSSBackgroundRepeat (element, tsch, context,
3059: cssRule, css, isHTML);
1.18 cvs 3060: /* perhaps a Background Position */
1.82 cvs 3061: else if (!strncasecmp (cssRule, "left", 4) ||
3062: !strncasecmp (cssRule, "right", 5) ||
3063: !strncasecmp (cssRule, "center", 6) ||
3064: !strncasecmp (cssRule, "top", 3) ||
3065: !strncasecmp (cssRule, "bottom", 6) ||
1.110 vatton 3066: isdigit (*cssRule) || *cssRule == '.')
1.63 cvs 3067: cssRule = ParseCSSBackgroundPosition (element, tsch, context,
3068: cssRule, css, isHTML);
1.18 cvs 3069: /* perhaps a Background Color */
3070: else
3071: {
1.93 vatton 3072: skippedNL = NewLineSkipped;
1.18 cvs 3073: /* check if the rule has been found */
3074: ptr = cssRule;
1.82 cvs 3075: cssRule = ParseCSSBackgroundColor (element, tsch, context,
3076: cssRule, css, isHTML);
1.43 cvs 3077: if (ptr == cssRule)
1.93 vatton 3078: {
3079: NewLineSkipped = skippedNL;
3080: /* rule not found */
3081: cssRule = SkipProperty (cssRule);
3082: }
1.18 cvs 3083: }
1.82 cvs 3084: cssRule = SkipBlanksAndComments (cssRule);
1.18 cvs 3085: }
3086: return (cssRule);
3087: }
3088:
1.59 cvs 3089: /*----------------------------------------------------------------------
1.60 cvs 3090: ParseCSSPageBreakBefore: parse a CSS page-break-before attribute
1.59 cvs 3091: ----------------------------------------------------------------------*/
1.79 cvs 3092: static char *ParseCSSPageBreakBefore (Element element, PSchema tsch,
3093: PresentationContext context, char *cssRule,
3094: CSSInfoPtr css, ThotBool isHTML)
1.59 cvs 3095: {
3096: PresentationValue page;
3097:
3098: page.typed_data.unit = STYLE_UNIT_INVALID;
3099: page.typed_data.real = FALSE;
1.82 cvs 3100: cssRule = SkipBlanksAndComments (cssRule);
3101: if (!strncasecmp (cssRule, "auto", 4))
1.59 cvs 3102: {
3103: /*page.typed_data.unit = STYLE_UNIT_REL;*/
3104: page.typed_data.value = STYLE_AUTO;
3105: }
1.82 cvs 3106: else if (!strncasecmp (cssRule, "always", 6))
1.59 cvs 3107: {
3108: page.typed_data.unit = STYLE_UNIT_REL;
3109: page.typed_data.value = STYLE_ALWAYS;
3110: }
1.82 cvs 3111: else if (!strncasecmp (cssRule, "avoid", 5))
1.59 cvs 3112: {
3113: page.typed_data.unit = STYLE_UNIT_REL;
3114: page.typed_data.value = STYLE_AVOID;
3115: }
1.82 cvs 3116: else if (!strncasecmp (cssRule, "left", 4))
1.59 cvs 3117: {
3118: page.typed_data.unit = STYLE_UNIT_REL;
3119: page.typed_data.value = STYLE_PAGELEFT;
3120: }
1.82 cvs 3121: else if (!strncasecmp (cssRule, "right", 5))
1.59 cvs 3122: {
3123: page.typed_data.unit = STYLE_UNIT_REL;
3124: page.typed_data.value = STYLE_PAGERIGHT;
3125: }
1.82 cvs 3126: else if (!strncasecmp (cssRule, "inherit", 7))
1.59 cvs 3127: {
3128: /*page.typed_data.unit = STYLE_UNIT_REL;*/
3129: page.typed_data.value = STYLE_INHERIT;
3130: }
3131: cssRule = SkipWord (cssRule);
3132: /* install the new presentation */
3133: if (page.typed_data.unit == STYLE_UNIT_REL &&
1.116 vatton 3134: page.typed_data.value == STYLE_ALWAYS && DoApply)
1.117 vatton 3135: {
3136: /* check if it's an important rule */
3137: if (tsch)
3138: cssRule = CheckImportantRule (cssRule, context);
3139: TtaSetStylePresentation (PRPageBefore, element, tsch, context, page);
3140: }
1.59 cvs 3141: return (cssRule);
3142: }
3143:
3144: /*----------------------------------------------------------------------
1.60 cvs 3145: ParseCSSPageBreakAfter: parse a CSS page-break-after attribute
1.59 cvs 3146: ----------------------------------------------------------------------*/
1.79 cvs 3147: static char *ParseCSSPageBreakAfter (Element element, PSchema tsch,
3148: PresentationContext context,
3149: char *cssRule, CSSInfoPtr css,
3150: ThotBool isHTML)
1.59 cvs 3151: {
3152: PresentationValue page;
3153:
3154: page.typed_data.unit = STYLE_UNIT_INVALID;
3155: page.typed_data.real = FALSE;
1.82 cvs 3156: cssRule = SkipBlanksAndComments (cssRule);
3157: if (!strncasecmp (cssRule, "auto", 4))
1.59 cvs 3158: {
3159: /*page.typed_data.unit = STYLE_UNIT_REL;*/
3160: page.typed_data.value = STYLE_AUTO;
3161: }
1.82 cvs 3162: else if (!strncasecmp (cssRule, "always", 6))
1.59 cvs 3163: {
3164: page.typed_data.unit = STYLE_UNIT_REL;
3165: page.typed_data.value = STYLE_ALWAYS;
3166: }
1.82 cvs 3167: else if (!strncasecmp (cssRule, "avoid", 5))
1.59 cvs 3168: {
3169: page.typed_data.unit = STYLE_UNIT_REL;
3170: page.typed_data.value = STYLE_AVOID;
3171: }
1.82 cvs 3172: else if (!strncasecmp (cssRule, "left", 4))
1.59 cvs 3173: {
3174: page.typed_data.unit = STYLE_UNIT_REL;
3175: page.typed_data.value = STYLE_PAGELEFT;
3176: }
1.82 cvs 3177: else if (!strncasecmp (cssRule, "right", 5))
1.59 cvs 3178: {
3179: page.typed_data.unit = STYLE_UNIT_REL;
3180: page.typed_data.value = STYLE_PAGERIGHT;
3181: }
1.82 cvs 3182: else if (!strncasecmp (cssRule, "inherit", 7))
1.59 cvs 3183: {
3184: /*page.typed_data.unit = STYLE_UNIT_REL;*/
3185: page.typed_data.value = STYLE_INHERIT;
3186: }
3187: cssRule = SkipWord (cssRule);
3188: /* install the new presentation */
1.116 vatton 3189: /*if (page.typed_data.unit == STYLE_UNIT_REL && DoApply)
1.117 vatton 3190: {
3191: if (tsch)
3192: cssRule = CheckImportantRule (cssRule, context);
3193: TtaSetStylePresentation (PRPageAfter, element, tsch, context, page);
3194: }*/
1.59 cvs 3195: return (cssRule);
3196: }
3197:
3198: /*----------------------------------------------------------------------
1.60 cvs 3199: ParseCSSPageBreakInside: parse a CSS page-break-inside attribute
1.59 cvs 3200: ----------------------------------------------------------------------*/
1.79 cvs 3201: static char *ParseCSSPageBreakInside (Element element, PSchema tsch,
3202: PresentationContext context,
3203: char *cssRule, CSSInfoPtr css,
3204: ThotBool isHTML)
1.59 cvs 3205: {
3206: PresentationValue page;
3207:
3208: page.typed_data.unit = STYLE_UNIT_INVALID;
3209: page.typed_data.real = FALSE;
1.82 cvs 3210: cssRule = SkipBlanksAndComments (cssRule);
3211: if (!strncasecmp (cssRule, "auto", 4))
1.59 cvs 3212: {
3213: /*page.typed_data.unit = STYLE_UNIT_REL;*/
3214: page.typed_data.value = STYLE_AUTO;
3215: }
1.82 cvs 3216: else if (!strncasecmp (cssRule, "avoid", 5))
1.59 cvs 3217: {
3218: page.typed_data.unit = STYLE_UNIT_REL;
3219: page.typed_data.value = STYLE_AVOID;
3220: }
1.82 cvs 3221: else if (!strncasecmp (cssRule, "inherit", 7))
1.59 cvs 3222: {
3223: /*page.typed_data.unit = STYLE_UNIT_REL;*/
3224: page.typed_data.value = STYLE_INHERIT;
3225: }
3226: cssRule = SkipWord (cssRule);
3227: /* install the new presentation */
1.96 vatton 3228: /*if (page.typed_data.unit == STYLE_UNIT_REL &&
1.117 vatton 3229: page.typed_data.value == STYLE_AVOID && DoApply)
3230: {
3231: if (tsch)
3232: cssRule = CheckImportantRule (cssRule, context);
3233: TtaSetStylePresentation (PRPageInside, element, tsch, context, page);
3234: }*/
1.59 cvs 3235: return (cssRule);
3236: }
1.18 cvs 3237:
3238:
1.60 cvs 3239: /*----------------------------------------------------------------------
1.117 vatton 3240: ParseSVGStrokeWidth: parse a SVG stroke-width property value.
1.60 cvs 3241: ----------------------------------------------------------------------*/
1.79 cvs 3242: static char *ParseSVGStrokeWidth (Element element, PSchema tsch,
3243: PresentationContext context, char *cssRule,
3244: CSSInfoPtr css, ThotBool isHTML)
1.60 cvs 3245: {
3246: PresentationValue width;
3247:
1.82 cvs 3248: cssRule = SkipBlanksAndComments (cssRule);
1.60 cvs 3249: width.typed_data.value = 0;
3250: width.typed_data.unit = STYLE_UNIT_INVALID;
3251: width.typed_data.real = FALSE;
1.110 vatton 3252: if (isdigit (*cssRule) || *cssRule == '.')
1.60 cvs 3253: cssRule = ParseCSSUnit (cssRule, &width);
1.116 vatton 3254: if (width.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.117 vatton 3255: {
3256: /* check if it's an important rule */
3257: if (tsch)
3258: cssRule = CheckImportantRule (cssRule, context);
3259: TtaSetStylePresentation (PRLineWeight, element, tsch, context, width);
3260: width.typed_data.value = 1;
3261: width.typed_data.unit = STYLE_UNIT_REL;
3262: }
1.60 cvs 3263: return (cssRule);
3264: }
3265:
1.18 cvs 3266: /************************************************************************
3267: * *
3268: * FUNCTIONS STYLE DECLARATIONS *
3269: * *
3270: ************************************************************************/
3271: /*
1.59 cvs 3272: * NOTE: Long attribute name MUST be placed before shortened ones !
1.18 cvs 3273: * e.g. "FONT-SIZE" must be placed before "FONT"
3274: */
3275: static CSSProperty CSSProperties[] =
3276: {
1.82 cvs 3277: {"font-family", ParseCSSFontFamily},
3278: {"font-style", ParseCSSFontStyle},
3279: {"font-variant", ParseCSSFontVariant},
3280: {"font-weight", ParseCSSFontWeight},
3281: {"font-size", ParseCSSFontSize},
3282: {"font", ParseCSSFont},
3283:
3284: {"color", ParseCSSForeground},
3285: {"background-color", ParseCSSBackgroundColor},
3286: {"background-image", ParseCSSBackgroundImage},
3287: {"background-repeat", ParseCSSBackgroundRepeat},
3288: {"background-attachment", ParseCSSBackgroundAttachment},
3289: {"background-position", ParseCSSBackgroundPosition},
3290: {"background", ParseCSSBackground},
3291:
3292: {"word-spacing", ParseCSSWordSpacing},
3293: {"letter-spacing", ParseCSSLetterSpacing},
3294: {"text-decoration", ParseCSSTextDecoration},
3295: {"vertical-align", ParseCSSVerticalAlign},
3296: {"text-transform", ParseCSSTextTransform},
3297: {"text-align", ParseCSSTextAlign},
3298: {"text-indent", ParseCSSTextIndent},
3299: {"line-height", ParseCSSLineSpacing},
3300:
1.112 quint 3301: {"direction", ParseCSSDirection},
1.113 quint 3302: {"unicode-bidi", ParseCSSUnicodeBidi},
1.112 quint 3303:
1.82 cvs 3304: {"margin-top", ParseCSSMarginTop},
3305: {"margin-right", ParseCSSMarginRight},
3306: {"margin-bottom", ParseCSSMarginBottom},
3307: {"margin-left", ParseCSSMarginLeft},
3308: {"margin", ParseCSSMargin},
3309:
3310: {"padding-top", ParseCSSPaddingTop},
3311: {"padding-right", ParseCSSPaddingRight},
3312: {"padding-bottom", ParseCSSPaddingBottom},
3313: {"padding-left", ParseCSSPaddingLeft},
3314: {"padding", ParseCSSPadding},
3315:
3316: {"border-top-width", ParseCSSBorderTopWidth},
3317: {"border-right-width", ParseCSSBorderRightWidth},
3318: {"border-bottom-width", ParseCSSBorderBottomWidth},
3319: {"border-left-width", ParseCSSBorderLeftWidth},
3320: {"border-width", ParseCSSBorderWidth},
3321: {"border-top-color", ParseCSSBorderColorTop},
3322: {"border-right-color", ParseCSSBorderColorRight},
3323: {"border-bottom-color", ParseCSSBorderColorBottom},
3324: {"border-left-color", ParseCSSBorderColorLeft},
3325: {"border-color", ParseCSSBorderColor},
3326: {"border-top-style", ParseCSSBorderStyleTop},
3327: {"border-right-style", ParseCSSBorderStyleRight},
3328: {"border-bottom-style", ParseCSSBorderStyleBottom},
3329: {"border-left-style", ParseCSSBorderStyleLeft},
3330: {"border-style", ParseCSSBorderStyle},
3331: {"border-top", ParseCSSBorderTop},
3332: {"border-right", ParseCSSBorderRight},
3333: {"border-bottom", ParseCSSBorderBottom},
3334: {"border-left", ParseCSSBorderLeft},
3335: {"border", ParseCSSBorder},
3336:
3337: {"width", ParseCSSWidth},
3338: {"height", ParseCSSHeight},
3339: {"float", ParseCSSFloat},
3340: {"clear", ParseCSSClear},
3341:
3342: {"display", ParseCSSDisplay},
3343: {"white-space", ParseCSSWhiteSpace},
3344:
3345: {"list-style-type", ParseCSSListStyleType},
3346: {"list-style-image", ParseCSSListStyleImage},
3347: {"list-style-position", ParseCSSListStylePosition},
3348: {"list-style", ParseCSSListStyle},
3349:
3350: {"page-break-before", ParseCSSPageBreakBefore},
3351: {"page-break-after", ParseCSSPageBreakAfter},
3352: {"page-break-inside", ParseCSSPageBreakInside},
1.60 cvs 3353:
3354: /* SVG extensions */
1.82 cvs 3355: {"stroke-width", ParseSVGStrokeWidth},
3356: {"stroke", ParseSVGStroke},
3357: {"fill", ParseSVGFill}
1.18 cvs 3358: };
3359: #define NB_CSSSTYLEATTRIBUTE (sizeof(CSSProperties) / sizeof(CSSProperty))
3360:
3361: /*----------------------------------------------------------------------
1.59 cvs 3362: ParseCSSRule: parse a CSS Style string
1.18 cvs 3363: we expect the input string describing the style to be of the
1.59 cvs 3364: form: PRORPERTY: DESCRIPTION [ ; PROPERTY: DESCRIPTION ] *
1.18 cvs 3365: but tolerate incorrect or incomplete input
3366: ----------------------------------------------------------------------*/
1.79 cvs 3367: static void ParseCSSRule (Element element, PSchema tsch,
3368: PresentationContext context, char *cssRule,
3369: CSSInfoPtr css, ThotBool isHTML)
1.18 cvs 3370: {
1.34 cvs 3371: DisplayMode dispMode;
1.79 cvs 3372: char *p = NULL;
1.18 cvs 3373: int lg;
1.34 cvs 3374: unsigned int i;
1.76 cvs 3375: ThotBool found;
1.18 cvs 3376:
1.34 cvs 3377: /* avoid too many redisplay */
3378: dispMode = TtaGetDisplayMode (context->doc);
3379: if (dispMode == DisplayImmediately)
3380: TtaSetDisplayMode (context->doc, DeferredDisplay);
3381:
1.82 cvs 3382: while (*cssRule != EOS)
1.18 cvs 3383: {
1.82 cvs 3384: cssRule = SkipBlanksAndComments (cssRule);
1.133 vatton 3385: if (*cssRule < 0x41 || *cssRule > 0x7A ||
3386: (*cssRule > 0x5A && *cssRule < 0x60))
1.89 cvs 3387: {
1.135 vatton 3388: CSSParseError ("Invalid character", cssRule);
1.89 cvs 3389: cssRule++;
3390: cssRule = SkipBlanksAndComments (cssRule);
3391: }
1.18 cvs 3392:
3393: found = FALSE;
3394: /* look for the type of property */
3395: for (i = 0; i < NB_CSSSTYLEATTRIBUTE && !found; i++)
3396: {
1.82 cvs 3397: lg = strlen (CSSProperties[i].name);
3398: if (!strncasecmp (cssRule, CSSProperties[i].name, lg))
1.18 cvs 3399: {
1.86 cvs 3400: p = cssRule + lg;
1.18 cvs 3401: found = TRUE;
3402: i--;
3403: }
3404: }
3405:
3406: if (i == NB_CSSSTYLEATTRIBUTE)
3407: cssRule = SkipProperty (cssRule);
3408: else
3409: {
3410: /* update index and skip the ":" indicator if present */
1.86 cvs 3411: p = SkipBlanksAndComments (p);
3412: if (*p == ':')
1.18 cvs 3413: {
1.86 cvs 3414: p++;
3415: p = SkipBlanksAndComments (p);
1.74 cvs 3416: /* try to parse the value associated with this property */
3417: if (CSSProperties[i].parsing_function != NULL)
1.61 cvs 3418: {
1.75 cvs 3419: p = CSSProperties[i].parsing_function (element, tsch, context,
1.86 cvs 3420: p, css, isHTML);
1.74 cvs 3421: /* update index and skip the ";" separator if present */
3422: cssRule = p;
1.61 cvs 3423: }
1.18 cvs 3424: }
1.74 cvs 3425: else
3426: cssRule = SkipProperty (cssRule);
1.18 cvs 3427: }
1.89 cvs 3428:
1.18 cvs 3429: /* next property */
1.82 cvs 3430: cssRule = SkipBlanksAndComments (cssRule);
1.89 cvs 3431: if (*cssRule == '}')
3432: {
3433: cssRule++;
3434: CSSParseError ("Invalid character", "}");
3435: cssRule = SkipBlanksAndComments (cssRule);
3436: }
1.82 cvs 3437: if (*cssRule == ',' || *cssRule == ';')
1.18 cvs 3438: {
3439: cssRule++;
1.82 cvs 3440: cssRule = SkipBlanksAndComments (cssRule);
1.18 cvs 3441: }
3442: }
1.34 cvs 3443:
3444: /* restore the display mode */
3445: if (dispMode == DisplayImmediately)
3446: TtaSetDisplayMode (context->doc, dispMode);
1.18 cvs 3447: }
1.1 cvs 3448:
1.111 cvs 3449: /*----------------------------------------------------------------------
3450: AddBorderStyleValue
3451: -----------------------------------------------------------------------*/
3452: static void AddBorderStyleValue (char *buffer, int value)
3453: {
3454: switch (value)
3455: {
3456: case STYLE_BORDERNONE:
3457: strcat (buffer, "none");
3458: break;
3459: case STYLE_BORDERHIDDEN:
3460: strcat (buffer, "hidden");
3461: break;
3462: case STYLE_BORDERDOTTED:
3463: strcat (buffer, "dotted");
3464: break;
3465: case STYLE_BORDERDASHED:
3466: strcat (buffer, "dashed");
3467: break;
3468: case STYLE_BORDERSOLID:
3469: strcat (buffer, "solid");
3470: break;
3471: case STYLE_BORDERDOUBLE:
3472: strcat (buffer, "double");
3473: break;
3474: case STYLE_BORDERGROOVE:
3475: strcat (buffer, "groove");
3476: break;
3477: case STYLE_BORDERRIDGE:
3478: strcat (buffer, "ridge");
3479: break;
3480: case STYLE_BORDERINSET:
3481: strcat (buffer, "inset");
3482: break;
3483: case STYLE_BORDEROUTSET:
3484: strcat (buffer, "outset");
3485: break;
3486: }
3487: }
1.1 cvs 3488:
3489: /*----------------------------------------------------------------------
1.59 cvs 3490: PToCss: translate a PresentationSetting to the
1.18 cvs 3491: equivalent CSS string, and add it to the buffer given as the
1.67 cvs 3492: argument. It is used when extracting the CSS string from actual
3493: presentation.
3494: el is the element for which the style rule is generated
1.18 cvs 3495:
3496: All the possible values returned by the presentation drivers are
3497: described in thotlib/include/presentation.h
3498: -----------------------------------------------------------------------*/
1.79 cvs 3499: void PToCss (PresentationSetting settings, char *buffer, int len, Element el)
1.1 cvs 3500: {
1.76 cvs 3501: ElementType elType;
1.18 cvs 3502: float fval = 0;
3503: unsigned short red, green, blue;
3504: int add_unit = 0;
3505: unsigned int unit, i;
3506: ThotBool real = FALSE;
3507:
1.82 cvs 3508: buffer[0] = EOS;
1.18 cvs 3509: if (len < 40)
3510: return;
3511:
3512: unit = settings->value.typed_data.unit;
3513: if (settings->value.typed_data.real)
3514: {
3515: real = TRUE;
3516: fval = (float) settings->value.typed_data.value;
3517: fval /= 1000;
3518: }
1.1 cvs 3519:
1.18 cvs 3520: switch (settings->type)
1.1 cvs 3521: {
1.18 cvs 3522: case PRVisibility:
3523: break;
1.111 cvs 3524: case PRHeight:
3525: if (real)
3526: sprintf (buffer, "height: %g", fval);
3527: else
3528: sprintf (buffer, "height: %d", settings->value.typed_data.value);
3529: add_unit = 1;
3530: break;
3531: case PRWidth:
3532: if (real)
3533: sprintf (buffer, "width: %g", fval);
3534: else
3535: sprintf (buffer, "width: %d", settings->value.typed_data.value);
3536: add_unit = 1;
3537: break;
3538: case PRMarginTop:
3539: if (real)
3540: sprintf (buffer, "margin-top: %g", fval);
3541: else
3542: sprintf (buffer, "margin-top: %d",settings->value.typed_data.value);
3543: add_unit = 1;
3544: break;
3545: case PRMarginBottom:
3546: if (real)
3547: sprintf (buffer, "margin-bottom: %g", fval);
3548: else
3549: sprintf (buffer, "margin-bottom: %d",
3550: settings->value.typed_data.value);
3551: add_unit = 1;
3552: break;
3553: case PRMarginLeft:
3554: if (real)
3555: sprintf (buffer, "margin-left: %g", fval);
3556: else
3557: sprintf (buffer, "margin-left: %d",
3558: settings->value.typed_data.value);
3559: add_unit = 1;
3560: break;
3561: case PRMarginRight:
3562: if (real)
3563: sprintf (buffer, "margin-right: %g", fval);
3564: else
3565: sprintf (buffer, "margin-right: %d",
3566: settings->value.typed_data.value);
3567: add_unit = 1;
3568: break;
3569: case PRPaddingTop:
3570: if (real)
3571: sprintf (buffer, "padding-top: %g", fval);
3572: else
3573: sprintf (buffer, "padding-top: %d",settings->value.typed_data.value);
3574: add_unit = 1;
3575: break;
3576: case PRPaddingBottom:
3577: if (real)
3578: sprintf (buffer, "padding-bottom: %g", fval);
3579: else
3580: sprintf (buffer, "padding-bottom: %d",
3581: settings->value.typed_data.value);
3582: add_unit = 1;
3583: break;
3584: case PRPaddingLeft:
3585: if (real)
3586: sprintf (buffer, "padding-left: %g", fval);
3587: else
3588: sprintf (buffer, "padding-left: %d",
3589: settings->value.typed_data.value);
3590: add_unit = 1;
3591: break;
3592: case PRPaddingRight:
3593: if (real)
3594: sprintf (buffer, "padding-right: %g", fval);
3595: else
3596: sprintf (buffer, "padding-right: %d",
3597: settings->value.typed_data.value);
3598: add_unit = 1;
3599: break;
3600: case PRBorderTopWidth:
3601: if (real)
3602: sprintf (buffer, "border-top-width: %g", fval);
3603: else
3604: sprintf (buffer, "border-top-width: %d",
3605: settings->value.typed_data.value);
3606: add_unit = 1;
3607: break;
3608: case PRBorderBottomWidth:
3609: if (real)
3610: sprintf (buffer, "border-bottom-width: %g", fval);
3611: else
3612: sprintf (buffer, "border-bottom-width: %d",
3613: settings->value.typed_data.value);
3614: add_unit = 1;
3615: break;
3616: case PRBorderLeftWidth:
3617: if (real)
3618: sprintf (buffer, "border-left-width: %g", fval);
3619: else
3620: sprintf (buffer, "border-left-width: %d",
3621: settings->value.typed_data.value);
3622: add_unit = 1;
3623: break;
3624: case PRBorderRightWidth:
3625: if (real)
3626: sprintf (buffer, "border-right-width: %g", fval);
3627: else
3628: sprintf (buffer, "border-right-width: %d",
3629: settings->value.typed_data.value);
3630: add_unit = 1;
3631: break;
3632: case PRBorderTopColor:
3633: TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
3634: elType = TtaGetElementType(el);
3635: sprintf (buffer, "border-top-color: #%02X%02X%02X", red, green, blue);
3636: break;
3637: case PRBorderRightColor:
3638: TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
3639: elType = TtaGetElementType(el);
3640: sprintf (buffer, "border-right-color: #%02X%02X%02X", red, green, blue);
3641: break;
3642: case PRBorderBottomColor:
3643: TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
3644: elType = TtaGetElementType(el);
3645: sprintf (buffer, "border-bottom-color: #%02X%02X%02X", red, green, blue);
1.18 cvs 3646: break;
1.111 cvs 3647: case PRBorderLeftColor:
3648: TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
3649: elType = TtaGetElementType(el);
3650: sprintf (buffer, "border-left-color: #%02X%02X%02X", red, green, blue);
1.20 cvs 3651: break;
1.111 cvs 3652: case PRBorderTopStyle:
3653: strcpy (buffer, "border-top-style: ");
3654: AddBorderStyleValue (buffer, settings->value.typed_data.value);
3655: break;
3656: case PRBorderRightStyle:
3657: strcpy (buffer, "border-right-style: ");
3658: AddBorderStyleValue (buffer, settings->value.typed_data.value);
3659: break;
3660: case PRBorderBottomStyle:
3661: strcpy (buffer, "border-bottom-style: ");
3662: AddBorderStyleValue (buffer, settings->value.typed_data.value);
3663: break;
3664: case PRBorderLeftStyle:
3665: strcpy (buffer, "border-left-style: ");
3666: AddBorderStyleValue (buffer, settings->value.typed_data.value);
1.18 cvs 3667: break;
3668: case PRSize:
3669: if (unit == STYLE_UNIT_REL)
3670: {
3671: if (real)
3672: {
1.82 cvs 3673: sprintf (buffer, "font-size: %g", fval);
1.18 cvs 3674: add_unit = 1;
3675: }
3676: else
3677: switch (settings->value.typed_data.value)
3678: {
3679: case 1:
1.82 cvs 3680: strcpy (buffer, "font-size: xx-small");
1.18 cvs 3681: break;
3682: case 2:
1.82 cvs 3683: strcpy (buffer, "font-size: x-small");
1.18 cvs 3684: break;
3685: case 3:
1.82 cvs 3686: strcpy (buffer, "font-size: small");
1.18 cvs 3687: break;
3688: case 4:
1.82 cvs 3689: strcpy (buffer, "font-size: medium");
1.18 cvs 3690: break;
3691: case 5:
1.82 cvs 3692: strcpy (buffer, "font-size: large");
1.18 cvs 3693: break;
3694: case 6:
1.82 cvs 3695: strcpy (buffer, "font-size: x-large");
1.18 cvs 3696: break;
3697: case 7:
3698: case 8:
3699: case 9:
3700: case 10:
3701: case 11:
3702: case 12:
1.82 cvs 3703: strcpy (buffer, "font-size: xx-large");
1.18 cvs 3704: break;
3705: }
3706: }
3707: else
3708: {
3709: if (real)
1.82 cvs 3710: sprintf (buffer, "font-size: %g", fval);
1.18 cvs 3711: else
1.82 cvs 3712: sprintf (buffer, "font-size: %d",
1.67 cvs 3713: settings->value.typed_data.value);
1.18 cvs 3714: add_unit = 1;
3715: }
3716: break;
1.111 cvs 3717: case PRStyle:
3718: switch (settings->value.typed_data.value)
3719: {
3720: case STYLE_FONT_ROMAN:
3721: strcpy (buffer, "font-style: normal");
3722: break;
3723: case STYLE_FONT_ITALICS:
3724: strcpy (buffer, "font-style: italic");
3725: break;
3726: case STYLE_FONT_OBLIQUE:
3727: strcpy (buffer, "font-style: oblique");
3728: break;
3729: }
3730: break;
3731: case PRWeight:
3732: switch (settings->value.typed_data.value)
3733: {
3734: case STYLE_WEIGHT_BOLD:
3735: strcpy (buffer, "font-weight: bold");
3736: break;
3737: case STYLE_WEIGHT_NORMAL:
3738: strcpy (buffer, "font-weight: normal");
3739: break;
3740: }
3741: break;
3742: case PRFont:
3743: switch (settings->value.typed_data.value)
3744: {
3745: case STYLE_FONT_HELVETICA:
3746: strcpy (buffer, "font-family: helvetica");
3747: break;
3748: case STYLE_FONT_TIMES:
3749: strcpy (buffer, "font-family: times");
3750: break;
3751: case STYLE_FONT_COURIER:
3752: strcpy (buffer, "font-family: courier");
3753: break;
3754: }
3755: break;
1.18 cvs 3756: case PRUnderline:
3757: switch (settings->value.typed_data.value)
3758: {
3759: case STYLE_UNDERLINE:
1.82 cvs 3760: strcpy (buffer, "text-decoration: underline");
1.18 cvs 3761: break;
3762: case STYLE_OVERLINE:
1.82 cvs 3763: strcpy (buffer, "text-decoration: overline");
1.18 cvs 3764: break;
3765: case STYLE_CROSSOUT:
1.82 cvs 3766: strcpy (buffer, "text-decoration: line-through");
1.18 cvs 3767: break;
3768: }
3769: break;
1.111 cvs 3770: case PRThickness:
3771: break;
1.18 cvs 3772: case PRIndent:
3773: if (real)
1.82 cvs 3774: sprintf (buffer, "text-indent: %g", fval);
1.18 cvs 3775: else
1.82 cvs 3776: sprintf (buffer, "text-indent: %d",
1.67 cvs 3777: settings->value.typed_data.value);
1.18 cvs 3778: add_unit = 1;
3779: break;
3780: case PRLineSpacing:
3781: if (real)
1.82 cvs 3782: sprintf (buffer, "line-height: %g", fval);
1.1 cvs 3783: else
1.82 cvs 3784: sprintf (buffer, "line-height: %d",
1.67 cvs 3785: settings->value.typed_data.value);
1.18 cvs 3786: add_unit = 1;
3787: break;
1.111 cvs 3788: case PRDepth:
3789: break;
1.18 cvs 3790: case PRAdjust:
3791: switch (settings->value.typed_data.value)
1.1 cvs 3792: {
1.18 cvs 3793: case STYLE_ADJUSTLEFT:
1.82 cvs 3794: strcpy (buffer, "text-align: left");
1.18 cvs 3795: break;
3796: case STYLE_ADJUSTRIGHT:
1.82 cvs 3797: strcpy (buffer, "text-align: right");
1.18 cvs 3798: break;
3799: case STYLE_ADJUSTCENTERED:
1.82 cvs 3800: strcpy (buffer, "text-align: center");
1.18 cvs 3801: break;
3802: case STYLE_ADJUSTLEFTWITHDOTS:
1.82 cvs 3803: strcpy (buffer, "text-align: left");
1.81 cvs 3804: break;
3805: case STYLE_ADJUSTJUSTIFY:
1.82 cvs 3806: strcpy (buffer, "text-align: justify");
1.112 quint 3807: break;
3808: }
3809: break;
3810: case PRDirection:
3811: switch (settings->value.typed_data.value)
3812: {
3813: case STYLE_LEFTTORIGHT:
3814: strcpy (buffer, "direction: ltr");
3815: break;
3816: case STYLE_RIGHTTOLEFT:
3817: strcpy (buffer, "direction: rtl");
1.113 quint 3818: break;
3819: }
3820: break;
3821: case PRUnicodeBidi:
3822: switch (settings->value.typed_data.value)
3823: {
3824: case STYLE_BIDINORMAL:
3825: strcpy (buffer, "unicode-bidi: normal");
3826: break;
3827: case STYLE_BIDIEMBED:
3828: strcpy (buffer, "unicode-bidi: embed");
3829: break;
3830: case STYLE_BIDIOVERRIDE:
3831: strcpy (buffer, "unicode-bidi: bidi-override");
1.18 cvs 3832: break;
1.1 cvs 3833: }
1.18 cvs 3834: break;
1.111 cvs 3835: case PRLineStyle:
3836: break;
1.126 vatton 3837: case PRDisplay:
3838: switch (settings->value.typed_data.value)
3839: {
3840: case STYLE_DISPLAYINLINE:
3841: strcpy (buffer, "display: inline");
3842: break;
3843: case STYLE_DISPLAYBLOCK:
3844: strcpy (buffer, "display: block");
3845: break;
3846: case STYLE_DISPLAYLISTITEM:
3847: strcpy (buffer, "display: list-item");
3848: break;
3849: case STYLE_DISPLAYRUNIN:
3850: strcpy (buffer, "display: runin");
3851: break;
3852: case STYLE_DISPLAYCOMPACT:
3853: strcpy (buffer, "display: compact");
3854: break;
3855: case STYLE_DISPLAYMARKER:
3856: strcpy (buffer, "display: marker");
3857: break;
3858: default:
3859: break;
3860: }
3861: break;
1.111 cvs 3862: case PRLineWeight:
3863: elType = TtaGetElementType(el);
3864: #ifdef _SVG
3865: if (!strcmp(TtaGetSSchemaName (elType.ElSSchema), "SVG"))
3866: #endif /* _SVG */
3867: {
3868: if (real)
3869: sprintf (buffer, "stroke-width: %g", fval);
3870: else
3871: sprintf (buffer, "stroke-width: %d",
3872: settings->value.typed_data.value);
3873: }
3874: add_unit = 1;
1.18 cvs 3875: break;
3876: case PRFillPattern:
3877: break;
3878: case PRBackground:
3879: TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
1.76 cvs 3880: elType = TtaGetElementType(el);
1.100 vatton 3881: #ifdef _SVG
3882: if (strcmp(TtaGetSSchemaName (elType.ElSSchema), "SVG") == 0)
1.82 cvs 3883: sprintf (buffer, "fill: #%02X%02X%02X", red, green, blue);
1.67 cvs 3884: else
1.100 vatton 3885: #endif /* _SVG */
1.82 cvs 3886: sprintf (buffer, "background-color: #%02X%02X%02X", red, green,
1.67 cvs 3887: blue);
1.18 cvs 3888: break;
3889: case PRForeground:
3890: TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
1.76 cvs 3891: elType = TtaGetElementType(el);
1.100 vatton 3892: #ifdef _SVG
3893: if (strcmp(TtaGetSSchemaName (elType.ElSSchema), "SVG") == 0)
1.82 cvs 3894: sprintf (buffer, "stroke: #%02X%02X%02X", red, green, blue);
1.67 cvs 3895: else
1.100 vatton 3896: #endif /* _SVG */
1.82 cvs 3897: sprintf (buffer, "color: #%02X%02X%02X", red, green, blue);
1.67 cvs 3898: break;
1.111 cvs 3899: case PRHyphenate:
1.18 cvs 3900: break;
1.111 cvs 3901: case PRVertOverflow:
1.18 cvs 3902: break;
1.111 cvs 3903: case PRHorizOverflow:
1.18 cvs 3904: break;
3905: case PRBackgroundPicture:
3906: if (settings->value.pointer != NULL)
1.82 cvs 3907: sprintf (buffer, "background-image: url(%s)",
1.67 cvs 3908: (char*)(settings->value.pointer));
1.1 cvs 3909: else
1.82 cvs 3910: sprintf (buffer, "background-image: none");
1.18 cvs 3911: break;
3912: case PRPictureMode:
3913: switch (settings->value.typed_data.value)
1.1 cvs 3914: {
1.18 cvs 3915: case STYLE_REALSIZE:
1.82 cvs 3916: sprintf (buffer, "background-repeat: no-repeat");
1.18 cvs 3917: break;
3918: case STYLE_REPEAT:
1.82 cvs 3919: sprintf (buffer, "background-repeat: repeat");
1.18 cvs 3920: break;
3921: case STYLE_VREPEAT:
1.82 cvs 3922: sprintf (buffer, "background-repeat: repeat-y");
1.18 cvs 3923: break;
3924: case STYLE_HREPEAT:
1.82 cvs 3925: sprintf (buffer, "background-repeat: repeat-x");
1.18 cvs 3926: break;
1.1 cvs 3927: }
1.18 cvs 3928: break;
3929: default:
3930: break;
1.1 cvs 3931: }
3932:
1.18 cvs 3933: if (add_unit)
1.1 cvs 3934: {
1.18 cvs 3935: /* add the unit string to the CSS string */
3936: for (i = 0; i < NB_UNITS; i++)
1.1 cvs 3937: {
1.18 cvs 3938: if (CSSUnitNames[i].unit == unit)
1.1 cvs 3939: {
1.82 cvs 3940: strcat (buffer, CSSUnitNames[i].sign);
1.18 cvs 3941: break;
1.1 cvs 3942: }
3943: }
3944: }
3945: }
3946:
3947: /*----------------------------------------------------------------------
1.59 cvs 3948: ParseHTMLSpecificStyle: parse and apply a CSS Style string.
1.18 cvs 3949: This function must be called when a specific style is applied to an
3950: element.
1.114 quint 3951: The parameter specificity is the specificity of the style, 0 if it is
3952: not really a CSS rule.
1.1 cvs 3953: ----------------------------------------------------------------------*/
1.79 cvs 3954: void ParseHTMLSpecificStyle (Element el, char *cssRule, Document doc,
1.114 quint 3955: int specificity, ThotBool destroy)
1.1 cvs 3956: {
3957: PresentationContext context;
3958: ElementType elType;
1.14 cvs 3959: ThotBool isHTML;
1.1 cvs 3960:
3961: /* A rule applying to BODY is really meant to address HTML */
3962: elType = TtaGetElementType (el);
1.89 cvs 3963:
1.86 cvs 3964: /* store the current line for eventually reported errors */
3965: LineNumber = TtaGetElementLineNumber (el);
1.89 cvs 3966: if (destroy)
3967: /* no reported errors */
3968: ParsedDoc = 0;
3969: else if (ParsedDoc != doc)
3970: {
3971: /* update the context for reported errors */
3972: ParsedDoc = doc;
3973: DocURL = DocumentURLs[doc];
3974: }
1.82 cvs 3975: isHTML = (strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML") == 0);
1.1 cvs 3976: /* create the context of the Specific presentation driver */
3977: context = TtaGetSpecificStyleContext (doc);
3978: if (context == NULL)
3979: return;
3980: context->type = elType.ElTypeNum;
1.114 quint 3981: context->cssSpecificity = specificity;
1.1 cvs 3982: context->destroy = destroy;
3983: /* Call the parser */
3984: ParseCSSRule (el, NULL, (PresentationContext) context, cssRule, NULL, isHTML);
3985: /* free the context */
3986: TtaFreeMemory(context);
3987: }
3988:
1.68 cvs 3989:
1.1 cvs 3990: /*----------------------------------------------------------------------
1.59 cvs 3991: ParseGenericSelector: Create a generic context for a given
1.1 cvs 3992: selector string. If the selector is made of multiple comma-
3993: separated selector items, it parses them one at a time and
3994: return the end of the selector string to be handled or NULL
3995: ----------------------------------------------------------------------*/
1.79 cvs 3996: static char *ParseGenericSelector (char *selector, char *cssRule,
3997: GenericContext ctxt, Document doc,
3998: CSSInfoPtr css)
3999: {
4000: ElementType elType;
4001: PSchema tsch;
1.119 vatton 4002: AttributeType attrType;
1.79 cvs 4003: char sel[MAX_ANCESTORS * 50];
1.118 vatton 4004: char *deb, *cur, c;
4005: char *schemaName, *mappedName;
1.79 cvs 4006: char *names[MAX_ANCESTORS];
4007: char *ids[MAX_ANCESTORS];
4008: char *classes[MAX_ANCESTORS];
4009: char *pseudoclasses[MAX_ANCESTORS];
4010: char *attrs[MAX_ANCESTORS];
4011: char *attrvals[MAX_ANCESTORS];
1.133 vatton 4012: AttrMatch attrmatch[MAX_ANCESTORS];
1.91 cvs 4013: int i, j, k, max;
1.125 vatton 4014: int att, maxAttr, kind;
1.118 vatton 4015: int specificity, xmlType;
1.79 cvs 4016: ThotBool isHTML;
4017: ThotBool level;
1.1 cvs 4018:
1.82 cvs 4019: sel[0] = EOS;
1.117 vatton 4020: specificity = 0;
1.1 cvs 4021: for (i = 0; i < MAX_ANCESTORS; i++)
4022: {
1.25 cvs 4023: names[i] = NULL;
4024: ids[i] = NULL;
4025: classes[i] = NULL;
4026: pseudoclasses[i] = NULL;
4027: attrs[i] = NULL;
4028: attrvals[i] = NULL;
1.133 vatton 4029: attrmatch[i] = Txtmatch;
1.25 cvs 4030: ctxt->name[i] = 0;
4031: ctxt->names_nb[i] = 0;
4032: ctxt->attrType[i] = 0;
1.129 vatton 4033: ctxt->attrLevel[i] = 0;
1.25 cvs 4034: ctxt->attrText[i] = NULL;
1.133 vatton 4035: ctxt->attrMatch[1] = Txtmatch;
1.1 cvs 4036: }
1.25 cvs 4037: ctxt->box = 0;
4038: ctxt->type = 0;
1.114 quint 4039: /* the specificity of the rule depends on the selector */
4040: ctxt->cssSpecificity = 0;
1.25 cvs 4041:
1.82 cvs 4042: selector = SkipBlanksAndComments (selector);
1.27 cvs 4043: cur = &sel[0];
1.25 cvs 4044: max = 0; /* number of loops */
1.1 cvs 4045: while (1)
4046: {
1.85 cvs 4047: /* point to the following word in sel[] */
1.27 cvs 4048: deb = cur;
1.25 cvs 4049: /* copy an item of the selector into sel[] */
1.1 cvs 4050: /* put one word in the sel buffer */
1.82 cvs 4051: while (*selector != EOS && *selector != ',' &&
4052: *selector != '.' && *selector != ':' &&
1.118 vatton 4053: *selector != '#' && *selector != '[' &&
1.130 vatton 4054: *selector != '*' && *selector != '>' &&
1.118 vatton 4055: !TtaIsBlank (selector))
1.50 cvs 4056: *cur++ = *selector++;
1.82 cvs 4057: *cur++ = EOS; /* close the first string in sel[] */
4058: if (deb[0] != EOS)
1.117 vatton 4059: {
4060: names[0] = deb;
4061: specificity += 1;
4062: }
1.25 cvs 4063: else
1.27 cvs 4064: names[0] = NULL;
4065: classes[0] = NULL;
4066: pseudoclasses[0] = NULL;
4067: ids[0] = NULL;
4068: attrs[0] = NULL;
4069: attrvals[0] = NULL;
1.25 cvs 4070:
1.27 cvs 4071: /* now names[0] points to the beginning of the parsed item
1.25 cvs 4072: and cur to the next chain to be parsed */
1.129 vatton 4073: while (*selector == '.' || *selector == ':' ||
1.130 vatton 4074: *selector == '#' || *selector == '[' ||
4075: *selector == '*' || *selector == '>')
1.129 vatton 4076: {
1.85 cvs 4077: /* point to the following word in sel[] */
4078: deb = cur;
1.129 vatton 4079: if (*selector == '.')
4080: {
4081: selector++;
4082: while (*selector != EOS && *selector != ',' &&
4083: *selector != '.' && *selector != ':' &&
4084: !TtaIsBlank (selector))
4085: *cur++ = *selector++;
4086: /* close the word */
4087: *cur++ = EOS;
4088: /* point to the class in sel[] if it's valid name */
4089: if (deb[0] <= 64)
4090: {
4091: CSSParseError ("Invalid class", deb);
1.116 vatton 4092: DoApply = FALSE;
1.129 vatton 4093: }
4094: else
4095: {
4096: classes[0] = deb;
1.117 vatton 4097: specificity += 10;
1.129 vatton 4098: }
4099: }
4100: else if (*selector == ':')
4101: {
4102: selector++;
4103: while (*selector != EOS && *selector != ',' &&
4104: *selector != '.' && *selector != ':' &&
4105: !TtaIsBlank (selector))
4106: *cur++ = *selector++;
4107: /* close the word */
4108: *cur++ = EOS;
4109: /* point to the pseudoclass in sel[] if it's valid name */
4110: if (deb[0] <= 64)
4111: {
4112: CSSParseError ("Invalid pseudoclass", deb);
4113: DoApply = FALSE;
4114: }
4115: else
4116: {
4117: if (!strcmp (deb, "first-letter") ||
4118: !strcmp (deb, "first-line") ||
4119: !strcmp (deb, "before") ||
4120: !strcmp (deb, "after"))
4121: /* not supported */
1.116 vatton 4122: DoApply = FALSE;
1.129 vatton 4123: else
4124: specificity += 10;
4125: pseudoclasses[0]= deb;
4126: }
4127: }
4128: else if (*selector == '#')
4129: {
4130: selector++;
4131: while (*selector != EOS && *selector != ',' &&
4132: *selector != '.' && *selector != ':' &&
4133: !TtaIsBlank (selector))
4134: *cur++ = *selector++;
4135: /* close the word */
4136: *cur++ = EOS;
4137: /* point to the attribute in sel[] if it's valid name */
4138: if (deb[0] <= 64)
4139: {
4140: CSSParseError ("Invalid id", deb);
4141: DoApply = FALSE;
4142: }
4143: else
4144: {
4145: ids[0] = deb;
4146: specificity += 100;
4147: }
4148: }
4149: else if (*selector == '[')
4150: {
1.118 vatton 4151: selector++;
1.129 vatton 4152: while (*selector != EOS && *selector != ']' &&
1.131 vatton 4153: *selector != '=' && *selector != '~' &&
1.133 vatton 4154: *selector != '|' && *selector != '^' &&
4155: *selector != '!')
1.129 vatton 4156: *cur++ = *selector++;
1.133 vatton 4157: /* check matching */
4158: if (*selector == '~')
4159: {
4160: attrmatch[0] = Txtword;
4161: selector++;
4162: }
4163: else if (*selector == '|')
4164: {
4165: attrmatch[0] = Txtsubstring;
4166: selector++;
4167: }
4168: else
4169: attrmatch[0] = Txtmatch;
1.129 vatton 4170: /* close the word */
4171: *cur++ = EOS;
4172: /* point to the attribute in sel[] if it's valid name */
4173: if (deb[0] <= 64)
4174: {
4175: CSSParseError ("Invalid attribute", deb);
4176: DoApply = FALSE;
4177: }
4178: else
4179: {
4180: attrs[0] = deb;
4181: specificity += 10;
4182: }
4183: if (*selector == '=')
4184: {
4185: /* look for a value "xxxx" */
4186: selector++;
4187: if (*selector != '"')
4188: {
4189: CSSParseError ("Invalid attribute value", deb);
4190: DoApply = FALSE;
4191: }
4192: else
4193: {
4194: /* we are now parsing the attribute value */
4195: selector++;
4196: deb = cur;
4197: while (*selector != '"')
4198: {
4199: if (*selector == EOS)
4200: {
4201: CSSParseError ("Invalid attribute value", deb);
4202: DoApply = FALSE;
4203: }
4204: else
1.133 vatton 4205: {
4206: *cur++ = tolower (*selector);
4207: selector++;
4208: }
1.129 vatton 4209: }
4210: /* there is a value */
4211: if (*selector == '"')
4212: {
4213: selector++;
4214: *cur++ = EOS;
4215: attrvals[0] = deb;
4216: }
4217: }
4218: }
4219: /* end of the attribute */
4220: if (*selector != ']')
4221: {
1.133 vatton 4222: selector[1] = EOS;
4223: CSSParseError ("Not supported selector", selector);
4224: selector += 2;
1.129 vatton 4225: DoApply = FALSE;
4226: }
4227: else
4228: selector++;
1.130 vatton 4229: }
4230: else
4231: {
4232: /* not supported selector */
4233: while (*selector != EOS && *selector != ',' &&
4234: *selector != '.' && *selector != ':' &&
4235: !TtaIsBlank (selector))
4236: *cur++ = *selector++;
4237: /* close the word */
4238: *cur++ = EOS;
4239: CSSParseError ("Not supported selector", deb);
4240: DoApply = FALSE;
1.129 vatton 4241: }
4242: }
1.1 cvs 4243:
1.82 cvs 4244: selector = SkipBlanksAndComments (selector);
1.25 cvs 4245: /* is it a multi-level selector? */
1.82 cvs 4246: if (*selector == EOS)
1.1 cvs 4247: /* end of the selector */
4248: break;
1.82 cvs 4249: else if (*selector == ',')
1.1 cvs 4250: {
4251: /* end of the current selector */
4252: selector++;
4253: break;
4254: }
1.25 cvs 4255: else
4256: {
1.143 vatton 4257: if (*selector == '>')
4258: {
4259: /* handle immediat parent as a simple parent */
4260: selector++;
4261: selector = SkipBlanksAndComments (selector);
4262: }
1.25 cvs 4263: /* shifts the list to make room for the new name */
4264: max++; /* a new level in ancestor tables */
4265: if (max == MAX_ANCESTORS)
4266: /* abort the CSS parsing */
4267: return (selector);
4268: for (i = max; i > 0; i--)
4269: {
4270: names[i] = names[i - 1];
4271: ids[i] = ids[i - 1];
4272: classes[i] = classes[i - 1];
1.133 vatton 4273: pseudoclasses[i] = pseudoclasses[i - 1];
1.25 cvs 4274: attrs[i] = attrs[i - 1];
4275: attrvals[i] = attrvals[i - 1];
1.133 vatton 4276: attrmatch[i] = attrmatch[i - 1];
1.25 cvs 4277: }
4278: }
1.1 cvs 4279: }
4280:
4281: /* Now set up the context block */
1.25 cvs 4282: i = 0;
4283: k = 0;
4284: j = 0;
1.35 cvs 4285: maxAttr = 0;
1.91 cvs 4286: /* default schema name */
1.119 vatton 4287: ctxt->schema = NULL;
1.122 vatton 4288: elType.ElSSchema = NULL;
4289: schemaName = TtaGetSSchemaName(TtaGetDocumentSSchema (doc));
1.119 vatton 4290: if (!strcmp (schemaName, "HTML"))
4291: xmlType = XHTML_TYPE;
4292: else if (!strcmp (schemaName, "MathML"))
4293: xmlType = MATH_TYPE;
4294: else if (!strcmp (schemaName, "SVG"))
4295: xmlType = SVG_TYPE;
4296: else if (!strcmp (schemaName, "XLink"))
4297: xmlType = XLINK_TYPE;
4298: else if (!strcmp (schemaName, "Annot"))
4299: xmlType = ANNOT_TYPE;
4300: else
4301: xmlType = XML_TYPE;
1.25 cvs 4302: while (i <= max)
4303: {
4304: if (names[i])
4305: {
1.118 vatton 4306: /* get the element type of this name in the current document */
4307: MapXMLElementType (xmlType, names[i], &elType, &mappedName, &c, &level, doc);
1.25 cvs 4308: if (i == 0)
4309: {
1.106 cvs 4310: if (elType.ElSSchema == NULL)
4311: {
1.119 vatton 4312: /* Search in the list of loaded schemas */
1.106 cvs 4313: TtaGetXmlElementType (names[i], &elType, NULL, doc);
1.119 vatton 4314: if (elType.ElSSchema)
4315: {
4316: /* the element type concerns an imprted nature */
4317: schemaName = TtaGetSSchemaName(elType.ElSSchema);
4318: if (!strcmp (schemaName, "HTML"))
4319: xmlType = XHTML_TYPE;
4320: else if (!strcmp (schemaName, "MathML"))
4321: xmlType = MATH_TYPE;
4322: else if (!strcmp (schemaName, "SVG"))
4323: xmlType = SVG_TYPE;
4324: else if (!strcmp (schemaName, "XLink"))
4325: xmlType = XLINK_TYPE;
4326: else if (!strcmp (schemaName, "Annot"))
4327: xmlType = ANNOT_TYPE;
4328: else
4329: xmlType = XML_TYPE;
4330: }
1.118 vatton 4331: #ifdef XML_GENERIC
1.119 vatton 4332: else if (xmlType == XML_TYPE)
1.106 cvs 4333: {
4334: /* Creation of a new element type in the main schema */
4335: elType.ElSSchema = TtaGetDocumentSSchema (doc);
1.118 vatton 4336: TtaAppendXmlElement (names[i], &elType, &mappedName, doc);
1.106 cvs 4337: }
1.118 vatton 4338: #endif /* XML_GENERIC */
1.122 vatton 4339: else
4340: {
4341: if (xmlType != XHTML_TYPE)
4342: {
4343: MapXMLElementType (XHTML_TYPE, names[i], &elType,
4344: &mappedName, &c, &level, doc);
4345: if (elType.ElSSchema)
1.123 vatton 4346: elType.ElSSchema = GetXHTMLSSchema (doc);
1.122 vatton 4347: }
4348: if (elType.ElSSchema == NULL && xmlType != MATH_TYPE)
4349: {
4350: MapXMLElementType (MATH_TYPE, names[i], &elType,
4351: &mappedName, &c, &level, doc);
4352: if (elType.ElSSchema)
1.123 vatton 4353: elType.ElSSchema = GetMathMLSSchema (doc);
1.122 vatton 4354: }
4355: if (elType.ElSSchema == NULL && xmlType != SVG_TYPE)
4356: {
4357: MapXMLElementType (SVG_TYPE, names[i], &elType,
4358: &mappedName, &c, &level, doc);
4359: if (elType.ElSSchema)
1.123 vatton 4360: elType.ElSSchema = GetSVGSSchema (doc);
1.122 vatton 4361: }
4362: }
1.118 vatton 4363: }
1.119 vatton 4364:
1.118 vatton 4365: if (elType.ElSSchema == NULL)
4366: /* cannot apply these CSS rules */
4367: DoApply = FALSE;
4368: else
4369: {
4370: /* Store the element type */
4371: ctxt->type = elType.ElTypeNum;
4372: ctxt->name[0] = elType.ElTypeNum;
4373: ctxt->names_nb[0] = 0;
4374: ctxt->schema = elType.ElSSchema;
1.106 cvs 4375: }
1.25 cvs 4376: }
4377: else if (elType.ElTypeNum != 0)
4378: {
4379: /* look at the current context to see if the type is already
4380: stored */
1.121 vatton 4381: j = 1;
1.32 cvs 4382: while (j < k && ctxt->name[j] != elType.ElTypeNum)
1.25 cvs 4383: j++;
4384: if (j == k)
4385: {
4386: ctxt->name[j] = elType.ElTypeNum;
4387: if (j != 0)
1.121 vatton 4388: ctxt->names_nb[j] = 1;
1.25 cvs 4389: }
4390: else
4391: /* increment the number of ancestor levels */
4392: ctxt->names_nb[j]++;
4393: }
4394: else
1.117 vatton 4395: j = k;
1.25 cvs 4396: }
1.117 vatton 4397: else
4398: j = k;
1.1 cvs 4399:
1.25 cvs 4400: /* store attributes information */
4401: if (classes[i])
4402: {
4403: ctxt->attrText[j] = classes[i];
1.119 vatton 4404: if (xmlType == SVG_TYPE)
1.100 vatton 4405: ctxt->attrType[j] = SVG_ATTR_class;
1.119 vatton 4406: else if (xmlType == MATH_TYPE)
1.91 cvs 4407: ctxt->attrType[j] = MathML_ATTR_class;
1.119 vatton 4408: else if (xmlType == XHTML_TYPE)
1.107 cvs 4409: ctxt->attrType[j] = HTML_ATTR_Class;
4410: else
1.119 vatton 4411: #ifdef XML_GENERIC
1.107 cvs 4412: ctxt->attrType[j] = XML_ATTR_class;
4413: #else /* XML_GENERIC */
1.91 cvs 4414: ctxt->attrType[j] = HTML_ATTR_Class;
1.107 cvs 4415: #endif /* XML_GENERIC */
1.79 cvs 4416: /* add a new entry */
1.80 cvs 4417: maxAttr = i + 1;
1.129 vatton 4418: /* update attrLevel */
4419: ctxt->attrLevel[j] = i;
4420: j++;
1.25 cvs 4421: }
1.79 cvs 4422: if (pseudoclasses[i])
1.25 cvs 4423: {
4424: ctxt->attrText[j] = pseudoclasses[i];
1.119 vatton 4425: if (xmlType == SVG_TYPE)
1.100 vatton 4426: ctxt->attrType[j] = SVG_ATTR_PseudoClass;
1.119 vatton 4427: else if (xmlType == MATH_TYPE)
1.91 cvs 4428: ctxt->attrType[j] = MathML_ATTR_PseudoClass;
1.119 vatton 4429: else if (xmlType == XHTML_TYPE)
1.107 cvs 4430: ctxt->attrType[j] = HTML_ATTR_PseudoClass;
4431: else
1.119 vatton 4432: #ifdef XML_GENERIC
1.107 cvs 4433: ctxt->attrType[j] = XML_ATTR_PseudoClass;
4434: #else /* XML_GENERIC */
1.91 cvs 4435: ctxt->attrType[j] = HTML_ATTR_PseudoClass;
1.107 cvs 4436: #endif /* XML_GENERIC */
1.79 cvs 4437: /* add a new entry */
1.80 cvs 4438: maxAttr = i + 1;
1.129 vatton 4439: /* update attrLevel */
4440: ctxt->attrLevel[j] = i;
4441: j++;
1.25 cvs 4442: }
1.79 cvs 4443: if (ids[i])
1.25 cvs 4444: {
4445: ctxt->attrText[j] = ids[i];
1.119 vatton 4446: if (xmlType == SVG_TYPE)
1.100 vatton 4447: ctxt->attrType[j] = SVG_ATTR_id;
1.119 vatton 4448: else if (xmlType == MATH_TYPE)
1.91 cvs 4449: ctxt->attrType[j] = MathML_ATTR_id;
1.119 vatton 4450: else if (xmlType == XHTML_TYPE)
1.107 cvs 4451: ctxt->attrType[j] = HTML_ATTR_ID;
4452: else
1.119 vatton 4453: #ifdef XML_GENERIC
1.107 cvs 4454: ctxt->attrType[j] = XML_ATTR_id;
4455: #else /* XML_GENERIC */
1.91 cvs 4456: ctxt->attrType[j] = HTML_ATTR_ID;
1.107 cvs 4457: #endif /* XML_GENERIC */
1.80 cvs 4458: /* add a new entry */
4459: maxAttr = i + 1;
1.129 vatton 4460: /* update attrLevel */
4461: ctxt->attrLevel[j] = i;
4462: j++;
1.25 cvs 4463: }
1.79 cvs 4464: if (attrs[i])
1.25 cvs 4465: {
1.125 vatton 4466: /* it's an attribute */
1.119 vatton 4467: MapXMLAttribute (xmlType, attrs[i], names[i], &level, doc, &att);
1.127 quint 4468: if (att == DummyAttribute && !strcmp (schemaName, "HTML"))
4469: /* it's the "type" attribute for an "input" element. In the tree
4470: it's represented by the element type, not by an attribute */
4471: att = 0;
1.119 vatton 4472: ctxt->attrType[j] = att;
1.133 vatton 4473: ctxt->attrMatch[j] = attrmatch[i];
1.125 vatton 4474: attrType.AttrSSchema = ctxt->schema;
4475: attrType.AttrTypeNum = att;
1.119 vatton 4476: if (i == 0 && att == 0 && ctxt->schema == NULL)
4477: {
1.125 vatton 4478: /* Not found -> search in the list of loaded schemas */
1.119 vatton 4479: attrType.AttrSSchema = NULL;
4480: TtaGetXmlAttributeType (attrs[i], &attrType, doc);
4481: ctxt->attrType[j] = attrType.AttrTypeNum;
4482: if (attrType.AttrSSchema)
1.125 vatton 4483: /* the element type concerns an imported nature */
4484: schemaName = TtaGetSSchemaName(attrType.AttrSSchema);
1.119 vatton 4485: #ifdef XML_GENERIC
4486: else if (xmlType == XML_TYPE)
4487: {
4488: /* The attribute is not yet present in the tree */
4489: /* Create a new global attribute */
4490: attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
4491: TtaAppendXmlAttribute (attrs[i], &attrType, doc);
4492: }
4493: #endif /* XML_GENERIC */
4494:
4495: if (attrType.AttrSSchema == NULL)
4496: /* cannot apply these CSS rules */
4497: DoApply = FALSE;
1.136 quint 4498: else if (elType.ElSSchema)
4499: ctxt->schema = elType.ElSSchema;
1.119 vatton 4500: else
1.136 quint 4501: ctxt->schema = attrType.AttrSSchema;
1.119 vatton 4502: }
1.125 vatton 4503: /* check the attribute type */
4504: if (!strcmp (schemaName, "HTML"))
4505: xmlType = XHTML_TYPE;
4506: else if (!strcmp (schemaName, "MathML"))
4507: xmlType = MATH_TYPE;
4508: else if (!strcmp (schemaName, "SVG"))
4509: xmlType = SVG_TYPE;
4510: else if (!strcmp (schemaName, "XLink"))
4511: xmlType = XLINK_TYPE;
4512: else if (!strcmp (schemaName, "Annot"))
4513: xmlType = ANNOT_TYPE;
4514: else
4515: xmlType = XML_TYPE;
4516: kind = TtaGetAttributeKind (attrType);
4517: if (kind == 0 && attrvals[i])
4518: {
4519: /* enumerated value */
4520: MapXMLAttributeValue (xmlType, attrvals[i], attrType, &kind);
4521: /* store the attribute value */
4522: ctxt->attrText[j] = (char *) kind;
4523: }
4524: else
4525: ctxt->attrText[j] = attrvals[i];
1.80 cvs 4526: maxAttr = i + 1;
1.129 vatton 4527: /* update attrLevel */
4528: ctxt->attrLevel[j] = i;
4529: j++;
1.25 cvs 4530: }
4531: i++;
1.117 vatton 4532: /* add a new entry */
4533: k++;
1.129 vatton 4534: if (k < j)
4535: k = j;
1.119 vatton 4536: if (i == 1 && ctxt->schema == NULL)
4537: /* use the document schema */
4538: ctxt->schema = TtaGetDocumentSSchema (doc);
1.1 cvs 4539: }
1.117 vatton 4540: /* set the selector specificity */
4541: ctxt->cssSpecificity = specificity;
1.25 cvs 4542: /* sort the list of ancestors by name order */
4543: max = k;
4544: i = 1;
4545: while (i < max)
1.28 cvs 4546: {
4547: for (k = i + 1; k < max; k++)
4548: if (ctxt->name[i] > ctxt->name[k])
4549: {
4550: j = ctxt->name[i];
4551: ctxt->name[i] = ctxt->name[k];
4552: ctxt->name[k] = j;
4553: j = ctxt->names_nb[i];
4554: ctxt->names_nb[i] = ctxt->names_nb[k];
4555: ctxt->names_nb[k] = j;
4556: j = ctxt->attrType[i];
4557: ctxt->attrType[i] = ctxt->attrType[k];
4558: ctxt->attrType[k] = j;
4559: cur = ctxt->attrText[i];
4560: ctxt->attrText[i] = ctxt->attrText[k];
4561: ctxt->attrText[k] = cur;
4562: }
4563: i++;
4564: }
1.84 cvs 4565:
1.25 cvs 4566: /* Get the schema name of the main element */
1.119 vatton 4567: schemaName = TtaGetSSchemaName (ctxt->schema);
4568: isHTML = (strcmp (schemaName, "HTML") == 0);
4569: tsch = GetPExtension (doc, ctxt->schema, css);
4570: if (tsch && cssRule)
4571: ParseCSSRule (NULL, tsch, (PresentationContext) ctxt, cssRule, css, isHTML);
1.116 vatton 4572: /* future CSS rules should apply */
4573: DoApply = TRUE;
1.1 cvs 4574: return (selector);
4575: }
4576:
4577: /*----------------------------------------------------------------------
1.73 cvs 4578: ParseStyleDeclaration: parse a style declaration
4579: stored in the style element of a document
1.59 cvs 4580: We expect the style string to be of the form:
1.1 cvs 4581: [
4582: e.g: pinky, awful { color: pink, font-family: helvetica }
4583: ----------------------------------------------------------------------*/
1.79 cvs 4584: static void ParseStyleDeclaration (Element el, char *cssRule, Document doc,
4585: CSSInfoPtr css, ThotBool destroy)
1.1 cvs 4586: {
1.79 cvs 4587: GenericContext ctxt;
4588: char *decl_end;
4589: char *sel_end;
4590: char *selector;
1.1 cvs 4591:
4592: /* separate the selectors string */
1.82 cvs 4593: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 4594: decl_end = cssRule;
1.82 cvs 4595: while (*decl_end != EOS && *decl_end != '{')
1.1 cvs 4596: decl_end++;
1.82 cvs 4597: if (*decl_end == EOS)
1.86 cvs 4598: {
4599: CSSParseError ("Invalid selector", cssRule);
4600: return;
4601: }
1.1 cvs 4602: /* verify and clean the selector string */
4603: sel_end = decl_end - 1;
1.82 cvs 4604: while (*sel_end == SPACE || *sel_end == BSPACE ||
4605: *sel_end == EOL || *sel_end == CR)
1.1 cvs 4606: sel_end--;
4607: sel_end++;
1.82 cvs 4608: *sel_end = EOS;
1.1 cvs 4609: selector = cssRule;
4610:
4611: /* now, deal with the content ... */
4612: decl_end++;
4613: cssRule = decl_end;
1.137 vatton 4614: decl_end = &cssRule[strlen (cssRule) - 1];
4615: if (*decl_end != '{')
4616: *decl_end = EOS;
1.1 cvs 4617: /*
4618: * parse the style attribute string and install the corresponding
4619: * presentation attributes on the new element
4620: */
4621: ctxt = TtaGetGenericStyleContext (doc);
4622: if (ctxt == NULL)
4623: return;
4624: ctxt->destroy = destroy;
4625:
1.82 cvs 4626: while ((selector != NULL) && (*selector != EOS))
1.25 cvs 4627: selector = ParseGenericSelector (selector, cssRule, ctxt, doc, css);
1.1 cvs 4628: TtaFreeMemory (ctxt);
4629: }
4630:
4631: /************************************************************************
4632: * *
4633: * EVALUATION FUNCTIONS / CASCADING AND OVERLOADING *
4634: * *
4635: ************************************************************************/
4636:
4637: /*----------------------------------------------------------------------
1.59 cvs 4638: IsImplicitClassName: return wether the Class name is an
1.1 cvs 4639: implicit one, eg "H1" or "H2 EM" meaning it's a GI name
4640: or an HTML context name.
4641: ----------------------------------------------------------------------*/
1.79 cvs 4642: int IsImplicitClassName (char *class, Document doc)
1.1 cvs 4643: {
1.79 cvs 4644: char name[200];
4645: char *cur = name;
4646: char *first;
4647: char save;
4648: SSchema schema;
1.1 cvs 4649:
4650: /* make a local copy */
1.82 cvs 4651: strncpy (name, class, 199);
1.1 cvs 4652: name[199] = 0;
4653:
4654: /* loop looking if each word is a GI */
4655: while (*cur != 0)
4656: {
4657: first = cur;
4658: cur = SkipWord (cur);
4659: save = *cur;
4660: *cur = 0;
4661: schema = NULL;
4662: if (MapGI (first, &schema, doc) == -1)
4663: {
4664: return (0);
4665: }
4666: *cur = save;
1.82 cvs 4667: cur = SkipBlanksAndComments (cur);
1.1 cvs 4668: }
4669: return (1);
4670: }
4671:
4672: /************************************************************************
4673: * *
1.114 quint 4674: * Functions needed for support of HTML: translate to CSS equivalent *
1.1 cvs 4675: * *
4676: ************************************************************************/
4677:
4678: /*----------------------------------------------------------------------
1.59 cvs 4679: HTMLSetBackgroundColor:
1.1 cvs 4680: ----------------------------------------------------------------------*/
1.79 cvs 4681: void HTMLSetBackgroundColor (Document doc, Element el, char *color)
1.1 cvs 4682: {
1.79 cvs 4683: char css_command[100];
1.1 cvs 4684:
1.82 cvs 4685: sprintf (css_command, "background-color: %s", color);
1.114 quint 4686: ParseHTMLSpecificStyle (el, css_command, doc, 0, FALSE);
1.1 cvs 4687: }
4688:
4689: /*----------------------------------------------------------------------
1.59 cvs 4690: HTMLSetBackgroundImage:
1.1 cvs 4691: repeat = repeat value
4692: image = url of background image
4693: ----------------------------------------------------------------------*/
1.79 cvs 4694: void HTMLSetBackgroundImage (Document doc, Element el, int repeat, char *image)
1.1 cvs 4695: {
1.79 cvs 4696: char css_command[400];
1.1 cvs 4697:
4698: /******* check buffer overflow ********/
1.82 cvs 4699: sprintf (css_command, "background-image: url(%s); background-repeat: ", image);
1.1 cvs 4700: if (repeat == STYLE_REPEAT)
1.82 cvs 4701: strcat (css_command, "repeat");
1.1 cvs 4702: else if (repeat == STYLE_HREPEAT)
1.82 cvs 4703: strcat (css_command, "repeat-x");
1.1 cvs 4704: else if (repeat == STYLE_VREPEAT)
1.82 cvs 4705: strcat (css_command, "repeat-y");
1.1 cvs 4706: else
1.82 cvs 4707: strcat (css_command, "no-repeat");
1.114 quint 4708: ParseHTMLSpecificStyle (el, css_command, doc, 0, FALSE);
1.1 cvs 4709: }
4710:
4711: /*----------------------------------------------------------------------
1.59 cvs 4712: HTMLSetForegroundColor:
1.1 cvs 4713: ----------------------------------------------------------------------*/
1.97 vatton 4714: void HTMLSetForegroundColor (Document doc, Element el, char *color)
1.1 cvs 4715: {
1.79 cvs 4716: char css_command[100];
1.1 cvs 4717:
1.82 cvs 4718: sprintf (css_command, "color: %s", color);
1.114 quint 4719: ParseHTMLSpecificStyle (el, css_command, doc, 0, FALSE);
1.1 cvs 4720: }
4721:
4722: /*----------------------------------------------------------------------
1.59 cvs 4723: HTMLResetBackgroundColor:
1.1 cvs 4724: ----------------------------------------------------------------------*/
1.97 vatton 4725: void HTMLResetBackgroundColor (Document doc, Element el)
1.1 cvs 4726: {
1.79 cvs 4727: char css_command[100];
1.1 cvs 4728:
1.82 cvs 4729: sprintf (css_command, "background: red");
1.114 quint 4730: ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1 cvs 4731: }
4732:
4733: /*----------------------------------------------------------------------
1.59 cvs 4734: HTMLResetBackgroundImage:
1.1 cvs 4735: ----------------------------------------------------------------------*/
1.97 vatton 4736: void HTMLResetBackgroundImage (Document doc, Element el)
1.1 cvs 4737: {
1.79 cvs 4738: char css_command[1000];
1.1 cvs 4739:
1.82 cvs 4740: sprintf (css_command, "background-image: url(xx); background-repeat: repeat");
1.114 quint 4741: ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1 cvs 4742: }
4743:
4744: /*----------------------------------------------------------------------
1.59 cvs 4745: HTMLResetForegroundColor:
1.1 cvs 4746: ----------------------------------------------------------------------*/
1.97 vatton 4747: void HTMLResetForegroundColor (Document doc, Element el)
1.1 cvs 4748: {
1.79 cvs 4749: char css_command[100];
1.1 cvs 4750:
1.36 cvs 4751: /* it's not necessary to well know the current color but it must be valid */
1.82 cvs 4752: sprintf (css_command, "color: red");
1.114 quint 4753: ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1 cvs 4754: }
4755:
4756: /*----------------------------------------------------------------------
1.59 cvs 4757: HTMLSetAlinkColor:
1.1 cvs 4758: ----------------------------------------------------------------------*/
1.97 vatton 4759: void HTMLSetAlinkColor (Document doc, char *color)
1.1 cvs 4760: {
1.79 cvs 4761: char css_command[100];
1.1 cvs 4762:
1.82 cvs 4763: sprintf (css_command, "a:link { color: %s }", color);
1.1 cvs 4764: ApplyCSSRules (NULL, css_command, doc, FALSE);
4765: }
4766:
4767: /*----------------------------------------------------------------------
1.59 cvs 4768: HTMLSetAactiveColor:
1.1 cvs 4769: ----------------------------------------------------------------------*/
1.97 vatton 4770: void HTMLSetAactiveColor (Document doc, char *color)
1.1 cvs 4771: {
1.79 cvs 4772: char css_command[100];
1.1 cvs 4773:
1.82 cvs 4774: sprintf (css_command, "a:active { color: %s }", color);
1.1 cvs 4775: ApplyCSSRules (NULL, css_command, doc, FALSE);
4776: }
4777:
4778: /*----------------------------------------------------------------------
1.59 cvs 4779: HTMLSetAvisitedColor:
1.1 cvs 4780: ----------------------------------------------------------------------*/
1.79 cvs 4781: void HTMLSetAvisitedColor (Document doc, char *color)
1.1 cvs 4782: {
1.79 cvs 4783: char css_command[100];
1.1 cvs 4784:
1.82 cvs 4785: sprintf (css_command, "a:visited { color: %s }", color);
1.1 cvs 4786: ApplyCSSRules (NULL, css_command, doc, FALSE);
4787: }
4788:
4789: /*----------------------------------------------------------------------
1.59 cvs 4790: HTMLResetAlinkColor:
1.1 cvs 4791: ----------------------------------------------------------------------*/
4792: void HTMLResetAlinkColor (Document doc)
4793: {
1.79 cvs 4794: char css_command[100];
1.1 cvs 4795:
1.82 cvs 4796: sprintf (css_command, "a:link { color: red }");
1.1 cvs 4797: ApplyCSSRules (NULL, css_command, doc, TRUE);
4798: }
4799:
4800: /*----------------------------------------------------------------------
1.59 cvs 4801: HTMLResetAactiveColor:
1.1 cvs 4802: ----------------------------------------------------------------------*/
4803: void HTMLResetAactiveColor (Document doc)
4804: {
1.79 cvs 4805: char css_command[100];
1.1 cvs 4806:
1.82 cvs 4807: sprintf (css_command, "a:active { color: red }");
1.1 cvs 4808: ApplyCSSRules (NULL, css_command, doc, TRUE);
4809: }
4810:
4811: /*----------------------------------------------------------------------
1.59 cvs 4812: HTMLResetAvisitedColor:
1.1 cvs 4813: ----------------------------------------------------------------------*/
4814: void HTMLResetAvisitedColor (Document doc)
4815: {
1.79 cvs 4816: char css_command[100];
1.1 cvs 4817:
1.82 cvs 4818: sprintf (css_command, "a:visited { color: red }");
1.1 cvs 4819: ApplyCSSRules (NULL, css_command, doc, TRUE);
4820: }
4821:
4822: /*----------------------------------------------------------------------
1.73 cvs 4823: ApplyCSSRules: parse a CSS Style description stored in the
1.1 cvs 4824: header of a HTML document.
4825: ----------------------------------------------------------------------*/
1.79 cvs 4826: void ApplyCSSRules (Element el, char *cssRule, Document doc, ThotBool destroy)
1.1 cvs 4827: {
4828: CSSInfoPtr css;
4829:
1.144 quint 4830: css = SearchCSS (doc, NULL, el);
1.1 cvs 4831: if (css == NULL)
4832: /* create the document css */
1.144 quint 4833: css = AddCSS (doc, doc, CSS_DOCUMENT_STYLE, NULL, NULL, el);
1.1 cvs 4834: ParseStyleDeclaration (el, cssRule, doc, css, destroy);
4835: }
4836:
4837: /*----------------------------------------------------------------------
1.145 quint 4838: ReadCSSRules: is the front-end function called by the document parser
4839: when detecting a <style type="text/css"> indicating it's the
1.1 cvs 4840: beginning of a CSS fragment or when reading a file .css.
4841:
4842: The CSS parser has to handle <!-- ... --> constructs used to
4843: prevent prehistoric browser from displaying the CSS as a text
4844: content. It will stop on any sequence "<x" where x is different
4845: from ! and will return x as to the caller. Theorically x should
1.145 quint 4846: be equal to / for the </style> end of style.
1.1 cvs 4847: The parameter doc gives the document tree that contains CSS information.
4848: The parameter docRef gives the document to which CSS are to be applied.
4849: This function uses the current css context or creates it. It's able
1.23 cvs 4850: to work on the given buffer or call GetNextChar to read the parsed
1.1 cvs 4851: file.
1.133 vatton 4852: The parameter url gives the URL of the style shheet parsed.
1.86 cvs 4853: Parameter numberOfLinesRead indicates the number of lines already
4854: read in the file.
1.1 cvs 4855: Parameter withUndo indicates whether the changes made in the document
1.145 quint 4856: structure and content have to be registered in the Undo queue or not.
4857: refElement is the element (image or use, for instance) that references
4858: the document containing the style element to be parsed.
1.1 cvs 4859: ----------------------------------------------------------------------*/
1.133 vatton 4860: char ReadCSSRules (Document docRef, CSSInfoPtr css, char *buffer, char *url,
1.144 quint 4861: int numberOfLinesRead, ThotBool withUndo,
1.145 quint 4862: Element styleElement, Element refElement)
1.1 cvs 4863: {
1.6 cvs 4864: DisplayMode dispMode;
1.82 cvs 4865: char c;
1.138 vatton 4866: char *cssRule, *base, *saveDocURL, *ptr;
1.19 cvs 4867: int index;
1.1 cvs 4868: int CSSindex;
4869: int CSScomment;
4870: int import;
4871: int openRule;
1.93 vatton 4872: int newlines;
1.14 cvs 4873: ThotBool HTMLcomment;
1.102 vatton 4874: ThotBool toParse, eof, quoted;
1.36 cvs 4875: ThotBool ignoreMedia, media;
1.88 cvs 4876: ThotBool noRule, ignoreImport;
1.1 cvs 4877:
4878: CSScomment = MAX_CSS_LENGTH;
4879: HTMLcomment = FALSE;
4880: CSSindex = 0;
4881: toParse = FALSE;
4882: noRule = FALSE;
1.36 cvs 4883: media = FALSE;
1.88 cvs 4884: ignoreImport = FALSE;
1.1 cvs 4885: ignoreMedia = FALSE;
4886: import = MAX_CSS_LENGTH;
4887: eof = FALSE;
4888: openRule = 0;
1.82 cvs 4889: c = SPACE;
1.1 cvs 4890: index = 0;
1.134 vatton 4891: base = NULL;
1.135 vatton 4892: quoted = FALSE;
1.93 vatton 4893: /* number of new lines parsed */
4894: newlines = 0;
1.6 cvs 4895: /* avoid too many redisplay */
4896: dispMode = TtaGetDisplayMode (docRef);
4897: if (dispMode == DisplayImmediately)
4898: TtaSetDisplayMode (docRef, DeferredDisplay);
1.18 cvs 4899:
4900: /* look for the CSS context */
4901: if (css == NULL)
1.144 quint 4902: css = SearchCSS (docRef, NULL, styleElement);
1.18 cvs 4903: if (css == NULL)
1.144 quint 4904: css = AddCSS (docRef, docRef, CSS_DOCUMENT_STYLE, NULL, NULL,
4905: styleElement);
1.145 quint 4906: if (css)
4907: css->refEl = refElement;
1.1 cvs 4908:
1.144 quint 4909: /* register parsed CSS file and the document to which CSS are to be applied*/
1.86 cvs 4910: ParsedDoc = docRef;
1.133 vatton 4911: if (url)
4912: DocURL = url;
1.86 cvs 4913: else
4914: /* the CSS source in within the document itself */
4915: DocURL = DocumentURLs[docRef];
4916: LineNumber = numberOfLinesRead + 1;
1.93 vatton 4917: NewLineSkipped = 0;
1.82 cvs 4918: while (CSSindex < MAX_CSS_LENGTH && c != EOS && !eof)
4919: {
4920: c = buffer[index++];
4921: eof = (c == EOS);
4922: CSSbuffer[CSSindex] = c;
4923: if (CSScomment == MAX_CSS_LENGTH ||
4924: c == '*' || c == '/' || c == '<')
4925: {
4926: /* we're not within a comment or we're parsing * or / */
4927: switch (c)
4928: {
4929: case '@': /* perhaps an import primitive */
1.135 vatton 4930: if (!quoted)
4931: import = CSSindex;
1.82 cvs 4932: break;
4933: case ';':
1.135 vatton 4934: if (!quoted && !media && import != MAX_CSS_LENGTH)
1.82 cvs 4935: {
4936: if (strncasecmp (&CSSbuffer[import+1], "import", 6))
4937: /* it's not an import */
4938: import = MAX_CSS_LENGTH;
4939: /* save the text */
4940: noRule = TRUE;
4941: }
4942: break;
4943: case '*':
1.135 vatton 4944: if (!quoted && CSScomment == MAX_CSS_LENGTH && CSSindex > 0 &&
1.82 cvs 4945: CSSbuffer[CSSindex - 1] == '/')
4946: /* start a comment */
4947: CSScomment = CSSindex - 1;
4948: break;
4949: case '/':
1.135 vatton 4950: if (!quoted && CSSindex > 1 && CSScomment != MAX_CSS_LENGTH &&
1.82 cvs 4951: CSSbuffer[CSSindex - 1] == '*')
4952: {
4953: /* close a comment:and ignore its contents */
4954: CSSindex = CSScomment - 1; /* will be incremented later */
4955: CSScomment = MAX_CSS_LENGTH;
1.93 vatton 4956: /* clean up the buffer */
1.103 vatton 4957: if (newlines && CSSindex > 0)
4958: while (CSSindex > 0 &&
4959: (CSSbuffer[CSSindex] == SPACE ||
4960: CSSbuffer[CSSindex] == BSPACE ||
4961: CSSbuffer[CSSindex] == EOL ||
4962: CSSbuffer[CSSindex] == TAB ||
4963: CSSbuffer[CSSindex] == __CR__))
1.93 vatton 4964: {
4965: if ( CSSbuffer[CSSindex] == EOL)
4966: {
4967: LineNumber ++;
4968: newlines --;
4969: }
4970: CSSindex--;
4971: }
1.82 cvs 4972: }
1.135 vatton 4973: else if (!quoted && CSScomment == MAX_CSS_LENGTH && CSSindex > 0 &&
1.82 cvs 4974: CSSbuffer[CSSindex - 1] == '<')
4975: {
4976: /* this is the closing tag ! */
4977: CSSindex -= 2; /* remove </ from the CSS string */
4978: noRule = TRUE;
4979: }
4980: break;
4981: case '<':
1.135 vatton 4982: if (!quoted && CSScomment == MAX_CSS_LENGTH)
1.82 cvs 4983: {
4984: /* only if we're not parsing a comment */
4985: c = buffer[index++];
4986: eof = (c == EOS);
4987: if (c == '!')
4988: {
4989: /* CSS within an HTML comment */
4990: HTMLcomment = TRUE;
4991: CSSindex++;
4992: CSSbuffer[CSSindex] = c;
4993: }
4994: else if (c == EOS)
4995: CSSindex++;
4996: }
4997: break;
4998: case '-':
1.135 vatton 4999: if (!quoted && CSSindex > 0 && CSSbuffer[CSSindex - 1] == '-' &&
1.82 cvs 5000: HTMLcomment)
5001: /* CSS within an HTML comment */
5002: noRule = TRUE;
5003: break;
5004: case '>':
1.135 vatton 5005: if (!quoted && HTMLcomment)
1.82 cvs 5006: noRule = TRUE;
5007: break;
5008: case ' ':
1.135 vatton 5009: if (!quoted && import != MAX_CSS_LENGTH && openRule == 0)
1.82 cvs 5010: media = !strncmp (&CSSbuffer[import+1], "media", 5);
5011: break;
5012: case '{':
1.135 vatton 5013: if (!quoted)
1.82 cvs 5014: {
1.135 vatton 5015: openRule++;
5016: if (import != MAX_CSS_LENGTH && openRule == 1 && media)
5017: {
5018: /* is it the screen concerned? */
5019: CSSbuffer[CSSindex+1] = EOS;
5020: if (TtaIsPrinting ())
5021: base = strstr (&CSSbuffer[import], "print");
5022: else
5023: base = strstr (&CSSbuffer[import], "screen");
5024: if (base == NULL)
5025: base = strstr (&CSSbuffer[import], "all");
5026: if (base == NULL)
5027: ignoreMedia = TRUE;
5028: noRule = TRUE;
5029: }
5030: }
5031: break;
5032: case '}':
5033: if (!quoted)
5034: {
5035: openRule--;
5036: if (import != MAX_CSS_LENGTH && openRule == 0)
5037: {
5038: import = MAX_CSS_LENGTH;
5039: noRule = TRUE;
5040: ignoreMedia = FALSE;
5041: media = FALSE;
5042: }
1.82 cvs 5043: else
1.135 vatton 5044: toParse = TRUE;
1.82 cvs 5045: }
5046: break;
1.135 vatton 5047: case '"':
5048: if (quoted)
1.82 cvs 5049: {
1.135 vatton 5050: if (CSSbuffer[CSSindex - 1] != '\\')
5051: quoted = FALSE;
1.82 cvs 5052: }
5053: else
1.135 vatton 5054: quoted = TRUE;
1.82 cvs 5055: break;
5056: default:
1.86 cvs 5057: if (c == EOL)
1.93 vatton 5058: newlines++;
1.82 cvs 5059: break;
5060: }
5061: }
1.93 vatton 5062: else if (c == EOL)
5063: LineNumber++;
1.82 cvs 5064: if (c != CR)
5065: CSSindex++;
5066:
5067: if (CSSindex >= MAX_CSS_LENGTH && CSScomment < MAX_CSS_LENGTH)
5068: /* we're still parsing a comment: remove the text comment */
5069: CSSindex = CSScomment;
5070:
5071: if (CSSindex >= MAX_CSS_LENGTH || toParse || noRule)
5072: {
5073: CSSbuffer[CSSindex] = EOS;
5074: /* parse a not empty string */
5075: if (CSSindex > 0)
5076: {
1.50 cvs 5077: /* apply CSS rule if it's not just a saving of text */
5078: if (!noRule && !ignoreMedia)
1.88 cvs 5079: {
5080: /* future import rules must be ignored */
5081: ignoreImport = TRUE;
5082: ParseStyleDeclaration (NULL, CSSbuffer, docRef, css, FALSE);
1.93 vatton 5083: LineNumber += newlines;
5084: newlines = 0;
5085: NewLineSkipped = 0;
1.88 cvs 5086: }
1.82 cvs 5087: else if (import != MAX_CSS_LENGTH &&
5088: !strncasecmp (&CSSbuffer[import+1], "import", 6))
5089: {
5090: /* import section */
5091: cssRule = &CSSbuffer[import+7];
5092: cssRule = TtaSkipBlanks (cssRule);
1.93 vatton 5093: /* save the current line number */
5094: newlines += LineNumber;
1.82 cvs 5095: if (!strncasecmp (cssRule, "url", 3))
5096: {
1.50 cvs 5097: cssRule = &cssRule[3];
1.82 cvs 5098: cssRule = TtaSkipBlanks (cssRule);
5099: if (*cssRule == '(')
5100: {
5101: cssRule++;
5102: cssRule = TtaSkipBlanks (cssRule);
1.102 vatton 5103: quoted = (*cssRule == '"' || *cssRule == '\'');
5104: if (quoted)
5105: cssRule++;
1.82 cvs 5106: base = cssRule;
5107: while (*cssRule != EOS && *cssRule != ')')
5108: cssRule++;
1.102 vatton 5109: if (quoted)
5110: cssRule--;
1.82 cvs 5111: }
5112: }
1.87 cvs 5113: else if (*cssRule == '"')
5114: {
1.88 cvs 5115: /*
5116: Do we have to accept single quotes?
5117: Double quotes are acceted here.
5118: Escaped quotes are not handled. See function SkipQuotedString
5119: */
1.87 cvs 5120: cssRule++;
5121: cssRule = TtaSkipBlanks (cssRule);
5122: base = cssRule;
5123: while (*cssRule != EOS && *cssRule != '"')
5124: cssRule++;
1.133 vatton 5125: }
5126: if (*cssRule != EOS)
5127: /* isolate the file name */
5128: *cssRule = EOS;
5129: /* check if a media is defined */
5130: cssRule++;
5131: cssRule = TtaSkipBlanks (cssRule);
5132: if (*cssRule != ';')
5133: {
5134: if (TtaIsPrinting ())
5135: ignoreImport = (strncasecmp (cssRule, "print", 5) &&
5136: strncasecmp (cssRule, "all", 3));
5137: else
5138: ignoreImport = (strncasecmp (cssRule, "screen", 6) &&
5139: strncasecmp (cssRule, "all", 3));
5140: }
5141: if (!ignoreImport)
5142: {
5143: /* save the displayed URL when an error is reported */
5144: saveDocURL = DocURL;
1.138 vatton 5145: ptr = TtaStrdup (base);
5146: /* get the CSS URI in UTF-8 */
5147: ptr = ReallocUTF8String (ptr, docRef);
1.133 vatton 5148: LoadStyleSheet (base, docRef, NULL, css,
5149: css->media[docRef],
5150: css->category == CSS_USER_STYLE);
5151: /* restore the displayed URL when an error is reported */
5152: DocURL = saveDocURL;
1.138 vatton 5153: TtaFreeMemory (ptr);
1.82 cvs 5154: }
1.93 vatton 5155: /* restore the number of lines */
5156: LineNumber = newlines;
5157: newlines = 0;
1.82 cvs 5158: import = MAX_CSS_LENGTH;
5159: }
1.93 vatton 5160:
1.82 cvs 5161: }
5162: toParse = FALSE;
5163: noRule = FALSE;
5164: CSSindex = 0;
1.50 cvs 5165: }
1.82 cvs 5166: }
1.6 cvs 5167: /* restore the display mode */
5168: if (dispMode == DisplayImmediately)
1.82 cvs 5169: TtaSetDisplayMode (docRef, dispMode);
1.86 cvs 5170:
5171: /* Prepare the context for style attributes */
5172: DocURL = DocumentURLs[docRef];
5173: LineNumber = -1;
1.1 cvs 5174: return (c);
5175: }
1.89 cvs 5176:
Webmaster