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