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