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