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