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