Annotation of Amaya/amaya/styleparser.c, revision 1.438
1.1 cvs 1: /*
2: *
1.437 quint 3: * (c) COPYRIGHT INRIA and W3C, 1996-2010
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"
1.406 quint 38: #include "HTMLtable_f.h"
1.1 cvs 39: #include "UIcss_f.h"
40: #include "css_f.h"
1.24 cvs 41: #include "fetchHTMLname_f.h"
1.91 cvs 42: #include "fetchXMLname_f.h"
1.1 cvs 43: #include "html2thot_f.h"
1.91 cvs 44: #include "init_f.h"
1.1 cvs 45: #include "styleparser_f.h"
1.424 quint 46: #include "SVGbuilder_f.h"
1.366 vatton 47: #include "wxdialogapi_f.h"
1.1 cvs 48:
49: #define MAX_BUFFER_LENGTH 200
50: /*
51: * A PropertyParser is a function used to parse the
52: * description substring associated to a given style attribute
1.59 cvs 53: * e.g.: "red" for a color attribute or "12pt bold helvetica"
1.1 cvs 54: * for a font attribute.
55: */
1.79 cvs 56: typedef char *(*PropertyParser) (Element element,
1.327 vatton 57: PSchema tsch,
58: PresentationContext context,
59: char *cssRule,
60: CSSInfoPtr css,
61: ThotBool isHTML);
1.1 cvs 62:
63: /* Description of the set of CSS properties supported */
64: typedef struct CSSProperty
1.327 vatton 65: {
1.405 kia 66: const char *name;
1.327 vatton 67: PropertyParser parsing_function;
68: }
1.1 cvs 69: CSSProperty;
70:
1.86 cvs 71: static int LineNumber = -1; /* The line where the error occurs */
1.93 vatton 72: static int NewLineSkipped = 0;
1.311 vatton 73: static int RedisplayImages = 0; /* number of BG images loading */
74: static int Style_parsing = 0; /* > 0 when parsing a set of CSS rules */
1.360 vatton 75: static char *ImportantPos = NULL;
1.310 vatton 76: static ThotBool RedisplayBGImage = FALSE; /* TRUE when a BG image is inserted */
1.116 vatton 77: static ThotBool DoApply = TRUE;
1.366 vatton 78: static ThotBool All_sides = FALSE; // TRUE when "boder valus must be displayed
1.437 quint 79: static char CSSbuffer[MAX_CSS_LENGTH + 1];
1.366 vatton 80:
1.1 cvs 81:
82: /*----------------------------------------------------------------------
1.327 vatton 83: SkipWord:
1.1 cvs 84: ----------------------------------------------------------------------*/
1.79 cvs 85: static char *SkipWord (char *ptr)
1.1 cvs 86: {
1.402 vatton 87: while (isalnum((int)*ptr) || *ptr == '-' || *ptr == '#' || *ptr == '%' || *ptr == '.')
1.168 vatton 88: ptr++;
1.1 cvs 89: return (ptr);
90: }
91:
92: /*----------------------------------------------------------------------
1.327 vatton 93: SkipBlanksAndComments:
1.13 cvs 94: ----------------------------------------------------------------------*/
1.82 cvs 95: char *SkipBlanksAndComments (char *ptr)
1.13 cvs 96: {
1.93 vatton 97: /* skip spaces */
1.155 cheyroul 98: while (*ptr == SPACE ||
1.327 vatton 99: *ptr == BSPACE ||
100: *ptr == EOL ||
101: *ptr == TAB ||
102: *ptr == __CR__)
1.93 vatton 103: {
104: if (*ptr == EOL)
1.327 vatton 105: /* increment the number of newline skipped */
106: NewLineSkipped++;
1.93 vatton 107: ptr++;
108: }
1.399 vatton 109: while (ptr[0] == '/' && ptr[1] == '*')
1.13 cvs 110: {
111: /* look for the end of the comment */
112: ptr = &ptr[2];
113: while (ptr[0] != EOS && (ptr[0] != '*' || ptr[1] != '/'))
1.327 vatton 114: ptr++;
1.13 cvs 115: if (ptr[0] != EOS)
1.327 vatton 116: ptr = &ptr[2];
1.93 vatton 117: /* skip spaces */
118: while (*ptr == SPACE || *ptr == BSPACE || *ptr == EOL ||
1.327 vatton 119: *ptr == TAB || *ptr == __CR__)
120: {
121: if (*ptr == EOL)
122: /* increment the number of newline skipped */
123: NewLineSkipped++;
124: ptr++;
125: }
1.13 cvs 126: }
127: return (ptr);
128: }
129:
1.366 vatton 130:
131: /*----------------------------------------------------------------------
132: Number of values
133: ----------------------------------------------------------------------*/
134: static int NumberOfValues (char *ptr)
135: {
136: int n = 0;
1.402 vatton 137: while (*ptr != EOS && *ptr != ';' && *ptr != '}' && *ptr != ',')
1.366 vatton 138: {
139: ptr = SkipBlanksAndComments (ptr);
140: n++;
141: ptr = SkipWord (ptr);
142: }
143: return n;
144: }
145:
1.49 cvs 146: /*----------------------------------------------------------------------
1.327 vatton 147: SkipQuotedString
1.1 cvs 148: ----------------------------------------------------------------------*/
1.79 cvs 149: static char *SkipQuotedString (char *ptr, char quote)
1.1 cvs 150: {
1.14 cvs 151: ThotBool stop;
1.1 cvs 152:
153: stop = FALSE;
154: while (!stop)
155: {
1.327 vatton 156: if (*ptr == quote)
157: {
158: ptr++;
159: stop = TRUE;
160: }
161: else if (*ptr == EOS)
162: stop = TRUE;
163: else if (*ptr == '\\')
164: /* escape character */
165: {
166: ptr++;
1.82 cvs 167: if ((*ptr >= '0' && *ptr <= '9') || (*ptr >= 'A' && *ptr <= 'F') ||
1.327 vatton 168: (*ptr >= 'a' && *ptr <= 'f'))
169: {
170: ptr++;
171: if ((*ptr >= '0' && *ptr <= '9') || (*ptr >= 'A' && *ptr <= 'F') ||
172: (*ptr >= 'a' && *ptr <= 'f'))
173: ptr++;
174: }
175: else
176: ptr++;
177: }
178: else
179: ptr++;
1.1 cvs 180: }
181: return (ptr);
182: }
183:
184: /*----------------------------------------------------------------------
1.327 vatton 185: CSSPrintError
186: print the error message msg on stderr.
1.436 quint 187: When the line is 0 ask expat the current line number
1.86 cvs 188: ----------------------------------------------------------------------*/
1.389 vatton 189: static void CSSPrintError (const char *msg, const char *value)
1.86 cvs 190: {
1.419 vatton 191: if (!IgnoreErrors && !DoDialog && !TtaIsPrinting () && ParsedDoc > 0)
1.86 cvs 192: {
193: if (!ErrFile)
1.327 vatton 194: {
195: if (OpenParsingErrors (ParsedDoc) == FALSE)
196: return;
197: }
1.86 cvs 198:
1.308 vatton 199: /* check if a CSS error file shoulb be updated too */
200: if (ParsedCSS > 0 && !CSSErrFile)
1.327 vatton 201: OpenParsingErrors (ParsedCSS);
1.308 vatton 202:
1.348 vatton 203: if (Error_DocURL)
1.327 vatton 204: {
1.348 vatton 205: fprintf (ErrFile, "\n*** Errors/warnings in %s\n", Error_DocURL);
1.327 vatton 206: /* set to NULL as long as the CSS file doesn't change */
1.348 vatton 207: Error_DocURL = NULL;
1.327 vatton 208: }
1.89 cvs 209: CSSErrorsFound = TRUE;
1.86 cvs 210: if (LineNumber < 0)
1.347 quint 211: {
212: if (value)
213: fprintf (ErrFile, " In style attribute, %s \"%s\"\n", msg, value);
214: else
215: fprintf (ErrFile, " In style attribute, %s\n", msg);
216: }
1.86 cvs 217: else
1.327 vatton 218: {
1.347 quint 219: if (value)
220: fprintf (ErrFile, "@ line %d: %s \"%s\"\n",
221: LineNumber+NewLineSkipped, msg, value);
222: else
223: fprintf (ErrFile, "@ line %d: %s\n", LineNumber+NewLineSkipped,
224: msg);
1.327 vatton 225: if (CSSErrFile)
1.347 quint 226: {
227: if (value)
228: fprintf (CSSErrFile, "@ line %d: %s \"%s\"\n",
229: LineNumber+NewLineSkipped, msg, value);
230: else
231: fprintf (CSSErrFile, "@ line %d: %s\n",
232: LineNumber+NewLineSkipped, msg);
233: }
1.327 vatton 234: }
1.86 cvs 235: }
236: }
237:
1.168 vatton 238: /*----------------------------------------------------------------------
1.327 vatton 239: CSSParseError
240: print the error message msg on stderr.
1.168 vatton 241: ----------------------------------------------------------------------*/
1.389 vatton 242: static void CSSParseError (const char *msg, const char *value, char *endvalue)
1.168 vatton 243: {
1.230 quint 244: char c = EOS;
1.168 vatton 245:
246: if (endvalue)
247: {
248: /* close the string here */
249: c = *endvalue;
250: *endvalue = EOS;
251: }
252: CSSPrintError (msg, value);
253: if (endvalue)
254: *endvalue = c;
255: }
256:
1.288 vatton 257: /*----------------------------------------------------------------------
1.342 vatton 258: SkipString move to the end of the string
259: ----------------------------------------------------------------------*/
260: static char *SkipString (char *ptr)
261: {
262: char c = *ptr;
263:
264: ptr++;
265: while (*ptr != EOS &&
266: (*ptr != c || (*ptr == c && ptr[-1] == '\\')))
267: ptr++;
268: return ptr;
269: }
270:
271: /*----------------------------------------------------------------------
1.327 vatton 272: CSSCheckEndValue
273: print an error message if another character is found
1.288 vatton 274: ----------------------------------------------------------------------*/
1.405 kia 275: static char *CSSCheckEndValue (char *cssRule, char *endvalue, const char *msg)
1.288 vatton 276: {
277: char c = EOS;
278: if (*endvalue != EOS && *endvalue != SPACE && *endvalue != '/' &&
1.316 quint 279: *endvalue != ';' && *endvalue != '}' && *endvalue != EOL &&
280: *endvalue != TAB && *endvalue != __CR__)
1.288 vatton 281: {
282: while (*endvalue != EOS && *endvalue != SPACE && *endvalue != '/' &&
1.327 vatton 283: *endvalue != ';' && *endvalue != '}' && *endvalue != EOL &&
284: *endvalue != TAB && *endvalue != __CR__)
1.342 vatton 285: {
286: if (*endvalue == '"' || *endvalue == '\'')
287: endvalue = SkipString (endvalue);
288: if (*endvalue != EOS)
289: endvalue++;
290: }
1.288 vatton 291: /* close the string here */
292: c = *endvalue;
293: *endvalue = EOS;
294: CSSPrintError (msg, cssRule);
295: *endvalue = c;
296: }
297: return endvalue;
298: }
299:
1.89 cvs 300:
1.86 cvs 301: /*----------------------------------------------------------------------
1.327 vatton 302: SkipProperty skips a property and display and error message
1.86 cvs 303: ----------------------------------------------------------------------*/
1.234 vatton 304: static char *SkipProperty (char *ptr, ThotBool reportError)
1.86 cvs 305: {
306: char *deb;
307: char c;
1.404 vatton 308: ThotBool warn;
1.86 cvs 309:
1.404 vatton 310: // check if Amaya should report CSS warnings
311: TtaGetEnvBoolean ("CSS_WARN", &warn);
312: if (!warn)
313: reportError = FALSE;
1.86 cvs 314: deb = ptr;
1.431 quint 315: while (*ptr != EOS && *ptr != ';' && *ptr != '}')
1.133 vatton 316: {
1.342 vatton 317: if (*ptr == '"' || *ptr == '\'')
318: ptr = SkipString (ptr);
319: if (*ptr != EOS)
320: ptr++;
1.133 vatton 321: }
1.95 cvs 322: /* print the skipped property */
1.86 cvs 323: c = *ptr;
1.386 vatton 324: if (*ptr != EOS)
325: *ptr = EOS;
1.366 vatton 326: if (DoDialog)
327: DisplayStyleValue ("", deb, ptr);
328: else if (reportError && *deb != EOS &&
329: strncasecmp (deb, "azimuth", 7) &&
330: strncasecmp (deb, "border-collapse", 15) &&
331: strncasecmp (deb, "border-spacing", 14) &&
332: strncasecmp (deb, "caption-side", 12) &&
333: strncasecmp (deb, "clip", 4) &&
334: strncasecmp (deb, "cue-after", 9) &&
335: strncasecmp (deb, "cue-before", 10) &&
336: strncasecmp (deb, "cue", 3) &&
337: strncasecmp (deb, "cursor", 6) &&
338: strncasecmp (deb, "elevation", 9) &&
339: strncasecmp (deb, "empty-cells", 11) &&
340: strncasecmp (deb, "font-strech", 11) &&
341: strncasecmp (deb, "letter-spacing", 14) &&
342: strncasecmp (deb, "marker-offset", 12) &&
343: strncasecmp (deb, "orphans", 7) &&
344: strncasecmp (deb, "outline-color", 13) &&
345: strncasecmp (deb, "outline-style", 13) &&
346: strncasecmp (deb, "outline-width", 13) &&
347: strncasecmp (deb, "outline", 7) &&
348: strncasecmp (deb, "overflow", 8) &&
349: strncasecmp (deb, "pause-after", 11) &&
350: strncasecmp (deb, "pause-before", 12) &&
351: strncasecmp (deb, "pause", 5) &&
352: strncasecmp (deb, "quotes", 6) &&
353: strncasecmp (deb, "richness", 8) &&
354: strncasecmp (deb, "speech-rate", 11) &&
355: strncasecmp (deb, "speak-header", 12) &&
356: strncasecmp (deb, "speak-punctuation", 17) &&
357: strncasecmp (deb, "speak-numeral", 13) &&
358: strncasecmp (deb, "speak", 5) &&
359: strncasecmp (deb, "pitch-range", 11) &&
360: strncasecmp (deb, "pitch", 5) &&
361: strncasecmp (deb, "stress", 6) &&
362: strncasecmp (deb, "table-layout", 12) &&
363: strncasecmp (deb, "text-shadow", 11) &&
364: strncasecmp (deb, "voice-family", 12) &&
365: strncasecmp (deb, "volume", 6) &&
366: strncasecmp (deb, "widows", 6))
1.205 quint 367: CSSPrintError ("CSS property ignored:", deb);
1.386 vatton 368: if (c != EOS)
369: *ptr = c;
1.86 cvs 370: return (ptr);
371: }
372:
373: /*----------------------------------------------------------------------
1.327 vatton 374: SkipValue
375: skips the value and display an error message if msg is not NULL
1.1 cvs 376: ----------------------------------------------------------------------*/
1.405 kia 377: static char *SkipValue (const char *msg, char *ptr)
1.1 cvs 378: {
1.86 cvs 379: char *deb;
380: char c;
381:
382: deb = ptr;
1.387 quint 383: while (*ptr != EOS && *ptr != ';' && *ptr != '}' && *ptr != '\n')
1.133 vatton 384: {
1.342 vatton 385: if (*ptr == '"' || *ptr == '\'')
386: ptr = SkipString (ptr);
387: if (*ptr != EOS)
388: ptr++;
1.133 vatton 389: }
1.95 cvs 390: /* print the skipped property */
1.86 cvs 391: c = *ptr;
1.397 vatton 392: if (c != EOS)
393: *ptr = EOS;
1.168 vatton 394: if (msg && *deb != EOS && *deb != ',')
395: CSSPrintError (msg, deb);
1.397 vatton 396: if (c != EOS)
397: *ptr = c;
1.1 cvs 398: return (ptr);
399: }
400:
401: /*----------------------------------------------------------------------
1.327 vatton 402: ParseNumber:
403: parse a number and returns the corresponding value.
1.1 cvs 404: ----------------------------------------------------------------------*/
1.79 cvs 405: char *ParseNumber (char *cssRule, PresentationValue *pval)
1.1 cvs 406: {
407: int val = 0;
408: int minus = 0;
409: int valid = 0;
410: int f = 0;
1.14 cvs 411: ThotBool real = FALSE;
1.1 cvs 412:
1.184 vatton 413: pval->typed_data.unit = UNIT_REL;
1.1 cvs 414: pval->typed_data.real = FALSE;
1.82 cvs 415: cssRule = SkipBlanksAndComments (cssRule);
416: if (*cssRule == '-')
1.1 cvs 417: {
418: minus = 1;
419: cssRule++;
1.82 cvs 420: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 421: }
1.387 quint 422: else if (*cssRule == '+')
1.1 cvs 423: {
424: cssRule++;
1.82 cvs 425: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 426: }
427:
1.82 cvs 428: while ((*cssRule >= '0') && (*cssRule <= '9'))
1.1 cvs 429: {
430: val *= 10;
1.82 cvs 431: val += *cssRule - '0';
1.1 cvs 432: cssRule++;
433: valid = 1;
434: }
435:
1.82 cvs 436: if (*cssRule == '.')
1.1 cvs 437: {
438: real = TRUE;
439: f = val;
440: val = 0;
441: cssRule++;
442: /* keep only 3 digits */
1.82 cvs 443: if (*cssRule >= '0' && *cssRule <= '9')
1.327 vatton 444: {
445: val = (*cssRule - '0') * 100;
446: cssRule++;
447: if (*cssRule >= '0' && *cssRule <= '9')
448: {
449: val += (*cssRule - '0') * 10;
450: cssRule++;
451: if ((*cssRule >= '0') && (*cssRule <= '9'))
452: {
453: val += *cssRule - '0';
454: cssRule++;
455: }
456: }
457:
458: while (*cssRule >= '0' && *cssRule <= '9')
459: cssRule++;
460: valid = 1;
461: }
1.1 cvs 462: }
463:
464: if (!valid)
465: {
1.184 vatton 466: pval->typed_data.unit = UNIT_INVALID;
1.1 cvs 467: pval->typed_data.value = 0;
468: }
469: else
470: {
471: pval->typed_data.real = real;
472: if (real)
1.327 vatton 473: {
474: if (minus)
475: pval->typed_data.value = -(f * 1000 + val);
476: else
477: pval->typed_data.value = f * 1000 + val;
478: }
1.1 cvs 479: else
1.327 vatton 480: {
481: if (minus)
482: pval->typed_data.value = -val;
483: else
484: pval->typed_data.value = val;
485: }
1.64 cvs 486: }
487: return (cssRule);
488: }
1.195 vatton 489:
1.155 cheyroul 490: /*----------------------------------------------------------------------
1.407 vatton 491: ParseCSSUnit a number followed by a CSS Unit and returns the corresponding
1.327 vatton 492: value and its unit.
1.64 cvs 493: ----------------------------------------------------------------------*/
1.82 cvs 494: char *ParseCSSUnit (char *cssRule, PresentationValue *pval)
1.64 cvs 495: {
1.368 vatton 496: char *p;
1.64 cvs 497: unsigned int uni;
498:
1.184 vatton 499: pval->typed_data.unit = UNIT_REL;
1.64 cvs 500: cssRule = ParseNumber (cssRule, pval);
1.184 vatton 501: if (pval->typed_data.unit == UNIT_INVALID)
1.387 quint 502: /* it does not start with a valid number */
1.327 vatton 503: cssRule = SkipWord (cssRule);
1.64 cvs 504: else
505: {
1.369 quint 506: /* is there a space after the number? */
1.368 vatton 507: p = cssRule;
1.82 cvs 508: cssRule = SkipBlanksAndComments (cssRule);
1.368 vatton 509: if (p == cssRule)
1.369 quint 510: /* no space */
1.368 vatton 511: p = NULL;
1.369 quint 512: else
513: /* a space is here. restore the pointer */
514: cssRule = p;
1.231 vatton 515: uni = 0;
516: while (CSSUnitNames[uni].sign)
1.327 vatton 517: {
518: if (!strncasecmp (CSSUnitNames[uni].sign, cssRule,
519: strlen (CSSUnitNames[uni].sign)))
1.369 quint 520: /* this is a correct unit */
1.327 vatton 521: {
522: pval->typed_data.unit = CSSUnitNames[uni].unit;
1.368 vatton 523: if (p)
1.369 quint 524: /* there was a space before the unit. Syntax error */
1.368 vatton 525: pval->typed_data.unit = UNIT_INVALID;
1.327 vatton 526: return (cssRule + strlen (CSSUnitNames[uni].sign));
527: }
528: else
529: uni++;
530: }
1.369 quint 531: /* not in the list of accepted units */
1.184 vatton 532: pval->typed_data.unit = UNIT_BOX;
1.1 cvs 533: }
534: return (cssRule);
535: }
536:
1.43 cvs 537: /*----------------------------------------------------------------------
1.327 vatton 538: ParseClampedUnit:
539: parse a CSS Unit substring and returns the corresponding value and unit.
540: [0,1]
1.239 vatton 541: ----------------------------------------------------------------------*/
542: char *ParseClampedUnit (char *cssRule, PresentationValue *pval)
543: {
1.251 vatton 544: char *p;
545:
546: p = cssRule;
1.239 vatton 547: cssRule = ParseNumber (cssRule, pval);
1.301 vatton 548: if (*cssRule != EOS && *cssRule != SPACE && *cssRule != ';' && *cssRule != '}')
1.418 quint 549: /* the value contains something after the number. Invalid */
1.239 vatton 550: {
1.251 vatton 551: cssRule++;
1.239 vatton 552: pval->typed_data.unit = UNIT_REL;
553: if (pval->typed_data.value > 100)
1.327 vatton 554: pval->typed_data.value = 1000;
1.239 vatton 555: else
1.327 vatton 556: pval->typed_data.value *= 10;
1.251 vatton 557: CSSParseError ("Invalid value", p, cssRule);
1.239 vatton 558: }
559: else
1.418 quint 560: /* it's a number. Check its value */
1.239 vatton 561: {
562: pval->typed_data.unit = UNIT_REL;
563: if (pval->typed_data.real)
1.327 vatton 564: pval->typed_data.real = FALSE;
1.239 vatton 565: else if (pval->typed_data.value > 1)
1.327 vatton 566: {
567: pval->typed_data.value = 1000;
568: CSSParseError ("Invalid value", p, cssRule);
569: }
1.251 vatton 570: else if (pval->typed_data.value < 0)
1.327 vatton 571: {
572: pval->typed_data.value = 0;
573: CSSParseError ("Invalid value", p, cssRule);
574: }
1.239 vatton 575: else
1.327 vatton 576: pval->typed_data.value *= 1000;
1.239 vatton 577: }
578: pval->data = pval->typed_data.value;
579: return (cssRule);
580: }
581:
582:
583: /*----------------------------------------------------------------------
1.327 vatton 584: ParseABorderValue
1.43 cvs 585: ----------------------------------------------------------------------*/
1.288 vatton 586: static char *ParseABorderValue (char *cssRule, PresentationValue *border)
1.43 cvs 587: {
1.288 vatton 588: char *ptr = cssRule;
1.168 vatton 589:
1.43 cvs 590: /* first parse the attribute string */
1.319 quint 591: border->typed_data.value = 0;
592: border->typed_data.unit = UNIT_INVALID;
593: border->typed_data.real = FALSE;
594: if (!strncasecmp (cssRule, "thin", 4))
595: {
596: border->typed_data.unit = UNIT_PX;
597: border->typed_data.value = 1;
598: cssRule += 4;
599: }
600: else if (!strncasecmp (cssRule, "medium", 6))
601: {
602: border->typed_data.unit = UNIT_PX;
603: border->typed_data.value = 3;
604: cssRule += 6;
605: }
606: else if (!strncasecmp (cssRule, "thick", 5))
607: {
608: border->typed_data.unit = UNIT_PX;
609: border->typed_data.value = 5;
610: cssRule += 5;
611: }
612: else if (!strncasecmp (cssRule, "inherit", 7))
613: {
614: border->typed_data.unit = VALUE_INHERIT;
615: cssRule += 7;
616: }
617: else if (isdigit (*cssRule) || *cssRule == '.')
618: {
619: cssRule = ParseCSSUnit (cssRule, border);
1.387 quint 620: if (border->typed_data.value == 0 &&
621: border->typed_data.unit != UNIT_INVALID)
1.327 vatton 622: border->typed_data.unit = UNIT_PX;
1.319 quint 623: else if (border->typed_data.unit == UNIT_INVALID ||
1.327 vatton 624: border->typed_data.unit == UNIT_BOX ||
625: border->typed_data.unit == UNIT_PERCENT)
626: {
627: border->typed_data.unit = UNIT_INVALID;
628: border->typed_data.value = 0;
629: CSSParseError ("Invalid border-width value", ptr, cssRule);
630: }
1.319 quint 631: }
632: return (cssRule);
1.43 cvs 633: }
634:
1.288 vatton 635:
636: /*----------------------------------------------------------------------
1.327 vatton 637: ParseBorderStyle
1.43 cvs 638: ----------------------------------------------------------------------*/
1.79 cvs 639: static char *ParseBorderStyle (char *cssRule, PresentationValue *border)
1.43 cvs 640: {
1.431 quint 641: char *ptr = cssRule;
642:
1.43 cvs 643: /* first parse the attribute string */
1.327 vatton 644: border->typed_data.value = 0;
645: border->typed_data.unit = UNIT_PX;
646: border->typed_data.real = FALSE;
647: if (!strncasecmp (cssRule, "none", 4))
648: {
649: border->typed_data.value = BorderStyleNone;
650: cssRule += 4;
651: }
652: else if (!strncasecmp (cssRule, "hidden", 6))
653: {
654: border->typed_data.value = BorderStyleHidden;
655: cssRule += 6;
656: }
657: else if (!strncasecmp (cssRule, "dotted", 6))
658: {
1.288 vatton 659: cssRule += 6;
1.327 vatton 660: border->typed_data.value = BorderStyleDotted;
1.288 vatton 661: }
1.327 vatton 662: else if (!strncasecmp (cssRule, "dashed", 6))
663: {
664: border->typed_data.value = BorderStyleDashed;
665: cssRule += 6;
666: }
667: else if (!strncasecmp (cssRule, "solid", 5))
668: {
669: border->typed_data.value = BorderStyleSolid;
670: cssRule += 5;
671: }
672: else if (!strncasecmp (cssRule, "double", 6))
673: {
674: border->typed_data.value = BorderStyleDouble;
675: cssRule += 6;
676: }
677: else if (!strncasecmp (cssRule, "groove", 6))
678: {
679: border->typed_data.value = BorderStyleGroove;
680: cssRule += 6;
681: }
682: else if (!strncasecmp (cssRule, "ridge", 5))
683: {
684: border->typed_data.value = BorderStyleRidge;
685: cssRule += 5;
686: }
687: else if (!strncasecmp (cssRule, "inset", 5))
688: {
689: border->typed_data.value = BorderStyleInset;
690: cssRule += 5;
691: }
692: else if (!strncasecmp (cssRule, "outset", 6))
693: {
694: border->typed_data.value = BorderStyleOutset;
695: cssRule += 6;
696: }
697: else
698: {
699: /* invalid style */
700: border->typed_data.unit = UNIT_INVALID;
701: return (cssRule);
702: }
1.431 quint 703: if (border->typed_data.value != 0)
704: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid border-style value");
1.327 vatton 705: return (cssRule);
1.43 cvs 706: }
707:
708: /*----------------------------------------------------------------------
1.327 vatton 709: ParseCSSColor: parse a CSS color attribute string
710: we expect the input string describing the attribute to be
711: either a color name, a 3 tuple or an hexadecimal encoding.
712: The color used will be approximed from the current color
713: table
1.43 cvs 714: ----------------------------------------------------------------------*/
1.79 cvs 715: static char *ParseCSSColor (char *cssRule, PresentationValue * val)
1.43 cvs 716: {
1.79 cvs 717: char *ptr;
1.43 cvs 718: unsigned short redval = (unsigned short) -1;
719: unsigned short greenval = 0; /* composant of each RGB */
720: unsigned short blueval = 0; /* default to red if unknown ! */
721: int best = 0; /* best color in list found */
1.404 vatton 722: ThotBool warn;
1.43 cvs 723:
1.82 cvs 724: cssRule = SkipBlanksAndComments (cssRule);
1.184 vatton 725: val->typed_data.unit = UNIT_INVALID;
1.43 cvs 726: val->typed_data.real = FALSE;
727: val->typed_data.value = 0;
1.57 cvs 728: ptr = TtaGiveRGB (cssRule, &redval, &greenval, &blueval);
1.292 vatton 729: if (!strncasecmp (cssRule, "InactiveCaptionText", 19))
730: {
1.364 vatton 731: val->typed_data.unit = VALUE_INHERIT;
1.292 vatton 732: cssRule += 19;
733: }
734: else if (!strncasecmp (cssRule, "ThreeDLightShadow", 17))
735: {
1.364 vatton 736: val->typed_data.unit = VALUE_INHERIT;
1.292 vatton 737: cssRule += 17;
738: }
739: else if (!strncasecmp (cssRule, "ThreeDDarkShadow", 16))
740: {
1.364 vatton 741: val->typed_data.unit = VALUE_INHERIT;
1.292 vatton 742: cssRule += 16;
743: }
744: else if (!strncasecmp (cssRule, "ButtonHighlight", 15) ||
1.327 vatton 745: !strncasecmp (cssRule, "InactiveCaption", 15) ||
746: !strncasecmp (cssRule, "ThreeDHighlight", 15))
1.292 vatton 747: {
1.364 vatton 748: val->typed_data.unit = VALUE_INHERIT;
1.292 vatton 749: cssRule += 15;
750: }
751: else if (!strncasecmp (cssRule, "InactiveBorder", 14) ||
1.327 vatton 752: !strncasecmp (cssRule, "InfoBackground", 14))
1.292 vatton 753: {
1.364 vatton 754: val->typed_data.unit = VALUE_INHERIT;
1.292 vatton 755: cssRule += 14;
756: }
757: else if (!strncasecmp (cssRule, "ActiveCaption", 13) ||
1.327 vatton 758: !strncasecmp (cssRule, "HighlightText", 13))
1.292 vatton 759: {
1.364 vatton 760: val->typed_data.unit = VALUE_INHERIT;
1.292 vatton 761: cssRule += 13;
762: }
763: else if (!strncasecmp (cssRule, "ActiveBorder", 12) ||
1.327 vatton 764: !strncasecmp (cssRule, "AppWorkspace", 12) ||
765: !strncasecmp (cssRule, "ButtonShadow", 12) ||
766: !strncasecmp (cssRule, "ThreeDShadow", 12))
1.292 vatton 767: {
1.364 vatton 768: val->typed_data.unit = VALUE_INHERIT;
1.292 vatton 769: cssRule += 12;
770: }
771: else if (!strncasecmp (cssRule, "CaptionText", 11) ||
1.327 vatton 772: !strncasecmp (cssRule, "WindowFrame", 11))
1.292 vatton 773: {
1.364 vatton 774: val->typed_data.unit = VALUE_INHERIT;
1.292 vatton 775: cssRule += 11;
776: }
777: else if (!strncasecmp (cssRule, "Background", 10) ||
1.327 vatton 778: !strncasecmp (cssRule, "ButtonFace", 10) ||
779: !strncasecmp (cssRule, "ButtonText", 10) ||
780: !strncasecmp (cssRule, "ThreeDFace", 10) ||
781: !strncasecmp (cssRule, "WindowText", 10))
1.292 vatton 782: {
1.364 vatton 783: val->typed_data.unit = VALUE_INHERIT;
1.292 vatton 784: cssRule += 10;
785: }
786: else if (!strncasecmp (cssRule, "Highlight", 9) ||
1.327 vatton 787: !strncasecmp (cssRule, "Scrollbar", 9))
1.292 vatton 788: {
1.364 vatton 789: val->typed_data.unit = VALUE_INHERIT;
1.292 vatton 790: cssRule += 9;
791: }
792: else if (!strncasecmp (cssRule, "GrayText", 8) ||
1.327 vatton 793: !strncasecmp (cssRule, "InfoText", 8) ||
794: !strncasecmp (cssRule, "MenuText", 8))
1.292 vatton 795: {
1.364 vatton 796: val->typed_data.unit = VALUE_INHERIT;
1.292 vatton 797: cssRule += 8;
798: }
799: else if (!strncasecmp (cssRule, "Window", 6))
800: {
1.364 vatton 801: val->typed_data.unit = VALUE_INHERIT;
1.292 vatton 802: cssRule += 6;
803: }
804: else if (!strncasecmp (cssRule, "Menu", 5))
805: {
1.364 vatton 806: val->typed_data.unit = VALUE_INHERIT;
1.292 vatton 807: cssRule += 5;
808: }
1.293 quint 809: else if (!strncasecmp (cssRule, "inherit", 7))
810: {
811: val->typed_data.unit = VALUE_INHERIT;
812: cssRule += 7;
813: }
1.404 vatton 814: else if (!strncasecmp (cssRule, "hsl", 3))
815: {
816: val->typed_data.unit = VALUE_INHERIT;
817: // check if Amaya should report CSS warnings
818: TtaGetEnvBoolean ("CSS_WARN", &warn);
819: if (warn)
820: cssRule = SkipValue ("Warning: CSS3 value not supported", cssRule);
821: else
822: cssRule = SkipValue (NULL, cssRule);
823: }
824: else if (!strncasecmp (cssRule, "rgba", 4))
825: {
826: val->typed_data.unit = VALUE_INHERIT;
827: // check if Amaya should report CSS warnings
828: TtaGetEnvBoolean ("CSS_WARN", &warn);
829: if (warn)
830: cssRule = SkipValue ("Warning: CSS3 value not supported", cssRule);
831: else
832: cssRule = SkipValue (NULL, cssRule);
833: }
1.57 cvs 834: if (ptr == cssRule)
1.43 cvs 835: {
1.404 vatton 836: cssRule = SkipValue ("Invalid color value", cssRule);
1.43 cvs 837: val->typed_data.value = 0;
1.184 vatton 838: val->typed_data.unit = UNIT_INVALID;
1.43 cvs 839: }
1.293 quint 840: else if (val->typed_data.unit != VALUE_INHERIT)
1.43 cvs 841: {
842: best = TtaGetThotColor (redval, greenval, blueval);
843: val->typed_data.value = best;
1.184 vatton 844: val->typed_data.unit = UNIT_REL;
1.57 cvs 845: cssRule = ptr;
1.43 cvs 846: }
847: val->typed_data.real = FALSE;
1.262 vatton 848: cssRule = SkipBlanksAndComments (cssRule);
1.65 cvs 849: return (cssRule);
1.43 cvs 850: }
1.1 cvs 851:
852: /*----------------------------------------------------------------------
1.231 vatton 853: CheckImportantRule updates the field important of the context and
854: the line number.
1.117 vatton 855: ----------------------------------------------------------------------*/
1.360 vatton 856: static void CheckImportantRule (char *cssRule, PresentationContext context)
1.117 vatton 857: {
1.276 vatton 858: PresentationContextBlock dummyctxt;
859:
860: if (context == NULL)
861: /* no context provided */
862: context = &dummyctxt;
863:
1.117 vatton 864: cssRule = SkipBlanksAndComments (cssRule);
1.360 vatton 865: while (*cssRule != EOS && *cssRule != '!' && *cssRule != ';')
866: cssRule++;
1.120 vatton 867: if (*cssRule != '!')
868: context->important = FALSE;
869: else
1.117 vatton 870: {
1.120 vatton 871: cssRule++;
1.360 vatton 872: ImportantPos = cssRule;
1.120 vatton 873: cssRule = SkipBlanksAndComments (cssRule);
874: if (!strncasecmp (cssRule, "important", 9))
1.327 vatton 875: {
1.360 vatton 876: ImportantPos[-1] = EOS;
1.327 vatton 877: context->important = TRUE;
878: }
1.120 vatton 879: else
1.360 vatton 880: {
881: ImportantPos = NULL;
882: context->important = FALSE;
883: }
884: }
885: }
886:
887: /*----------------------------------------------------------------------
888: SkipImportantRule skips important markup
889: ----------------------------------------------------------------------*/
890: static char *SkipImportantRule (char *cssRule)
891: {
892: if (ImportantPos)
893: {
894: ImportantPos[-1] = '!';
1.361 vatton 895: cssRule = ImportantPos;
896: cssRule = SkipBlanksAndComments (cssRule);
897: cssRule += 9;
1.360 vatton 898: ImportantPos = NULL;
1.117 vatton 899: }
1.360 vatton 900: cssRule = SkipBlanksAndComments (cssRule);
1.117 vatton 901: return (cssRule);
902: }
903:
904: /*----------------------------------------------------------------------
1.327 vatton 905: ParseCSSBorderTopWidth: parse a CSS BorderTopWidth
906: attribute string.
1.1 cvs 907: ----------------------------------------------------------------------*/
1.79 cvs 908: static char *ParseCSSBorderTopWidth (Element element, PSchema tsch,
1.327 vatton 909: PresentationContext context,
910: char *cssRule, CSSInfoPtr css,
911: ThotBool isHTML)
1.1 cvs 912: {
1.41 cvs 913: PresentationValue border;
1.366 vatton 914: char *start_value = cssRule;
1.41 cvs 915:
1.82 cvs 916: cssRule = SkipBlanksAndComments (cssRule);
1.288 vatton 917: cssRule = ParseABorderValue (cssRule, &border);
1.366 vatton 918: if (border.typed_data.unit != UNIT_INVALID)
919: {
920: if (DoDialog)
921: {
922: if (All_sides)
923: DisplayStyleValue ("border-width", start_value, cssRule);
924: else
925: DisplayStyleValue ("border-top-width", start_value, cssRule);
926: }
927: else if (DoApply)
928: TtaSetStylePresentation (PRBorderTopWidth, element, tsch, context, border);
929: }
1.1 cvs 930: return (cssRule);
931: }
932:
933: /*----------------------------------------------------------------------
1.327 vatton 934: ParseCSSBorderBottomWidth: parse a CSS BorderBottomWidth
935: attribute string.
1.1 cvs 936: ----------------------------------------------------------------------*/
1.79 cvs 937: static char *ParseCSSBorderBottomWidth (Element element, PSchema tsch,
1.327 vatton 938: PresentationContext context,
939: char *cssRule, CSSInfoPtr css,
940: ThotBool isHTML)
1.1 cvs 941: {
1.41 cvs 942: PresentationValue border;
1.366 vatton 943: char *start_value = cssRule;
1.41 cvs 944:
1.82 cvs 945: cssRule = SkipBlanksAndComments (cssRule);
1.41 cvs 946: /* first parse the attribute string */
1.288 vatton 947: cssRule = ParseABorderValue (cssRule, &border);
1.366 vatton 948: if (border.typed_data.unit != UNIT_INVALID)
949: {
950: if (DoDialog)
951: DisplayStyleValue ("border-bottom-width", start_value, cssRule);
952: else if (DoApply)
953: TtaSetStylePresentation (PRBorderBottomWidth, element, tsch, context, border);
954: }
1.1 cvs 955: return (cssRule);
956: }
957:
958: /*----------------------------------------------------------------------
1.327 vatton 959: ParseCSSBorderLeftWidth: parse a CSS BorderLeftWidth
960: attribute string.
1.1 cvs 961: ----------------------------------------------------------------------*/
1.79 cvs 962: static char *ParseCSSBorderLeftWidth (Element element, PSchema tsch,
1.327 vatton 963: PresentationContext context,
964: char *cssRule, CSSInfoPtr css,
965: ThotBool isHTML)
1.1 cvs 966: {
1.41 cvs 967: PresentationValue border;
1.366 vatton 968: char *start_value = cssRule;
1.41 cvs 969:
1.82 cvs 970: cssRule = SkipBlanksAndComments (cssRule);
1.41 cvs 971: /* first parse the attribute string */
1.288 vatton 972: cssRule = ParseABorderValue (cssRule, &border);
1.366 vatton 973: if (border.typed_data.unit != UNIT_INVALID)
974: {
975: if (DoDialog)
976: DisplayStyleValue ("border-left-width", start_value, cssRule);
977: else if (DoApply)
978: TtaSetStylePresentation (PRBorderLeftWidth, element, tsch, context, border);
979: }
1.1 cvs 980: return (cssRule);
981: }
982:
983: /*----------------------------------------------------------------------
1.327 vatton 984: ParseCSSBorderRightWidth: parse a CSS BorderRightWidth
985: attribute string.
1.1 cvs 986: ----------------------------------------------------------------------*/
1.79 cvs 987: static char *ParseCSSBorderRightWidth (Element element, PSchema tsch,
1.327 vatton 988: PresentationContext context,
989: char *cssRule, CSSInfoPtr css,
990: ThotBool isHTML)
1.1 cvs 991: {
1.41 cvs 992: PresentationValue border;
1.366 vatton 993: char *start_value = cssRule;
1.41 cvs 994:
1.82 cvs 995: cssRule = SkipBlanksAndComments (cssRule);
1.41 cvs 996: /* first parse the attribute string */
1.288 vatton 997: cssRule = ParseABorderValue (cssRule, &border);
1.184 vatton 998: if (border.typed_data.unit != UNIT_INVALID && DoApply)
1.366 vatton 999: {
1000: if (DoDialog)
1001: DisplayStyleValue ("border-right-width", start_value, cssRule);
1002: else if (DoApply)
1003: TtaSetStylePresentation (PRBorderRightWidth, element, tsch, context, border);
1004: }
1.1 cvs 1005: return (cssRule);
1006: }
1007:
1008: /*----------------------------------------------------------------------
1.327 vatton 1009: ParseCSSBorderWidth: parse a CSS BorderWidth
1010: attribute string.
1.1 cvs 1011: ----------------------------------------------------------------------*/
1.79 cvs 1012: static char *ParseCSSBorderWidth (Element element, PSchema tsch,
1.327 vatton 1013: PresentationContext context,
1014: char *cssRule, CSSInfoPtr css,
1015: ThotBool isHTML)
1.1 cvs 1016: {
1.79 cvs 1017: char *ptrT, *ptrR, *ptrB, *ptrL;
1.366 vatton 1018: int skippedNL, n;
1.41 cvs 1019:
1.82 cvs 1020: ptrT = SkipBlanksAndComments (cssRule);
1.366 vatton 1021: if (DoDialog)
1022: n = NumberOfValues (ptrT);
1023: if (DoDialog && n < 2)
1.42 cvs 1024: {
1.366 vatton 1025: // check if the border dialog must be updated
1026: All_sides = TRUE;
1027: ptrR = ParseCSSBorderTopWidth (element, tsch, context, ptrT, css, isHTML);
1028: All_sides = FALSE;
1.42 cvs 1029: }
1030: else
1031: {
1.366 vatton 1032: /* First parse Border-Top */
1033: ptrR = ParseCSSBorderTopWidth (element, tsch, context, ptrT, css, isHTML);
1.415 vatton 1034: if (ptrR == ptrT)
1035: {
1036: // invalid value
1037: cssRule = SkipValue ("Invalid border-width value", ptrT);
1038: return (cssRule);
1039: }
1.366 vatton 1040: ptrR = SkipBlanksAndComments (ptrR);
1041: if (*ptrR == ';' || *ptrR == '}' || *ptrR == EOS || *ptrR == ',')
1.327 vatton 1042: {
1043: skippedNL = NewLineSkipped;
1.366 vatton 1044: cssRule = ptrR;
1045: /* apply the Border-Top to all */
1046: ptrR = ParseCSSBorderRightWidth (element, tsch, context, ptrT, css, isHTML);
1047: NewLineSkipped = skippedNL;
1048: ptrR = ParseCSSBorderBottomWidth (element, tsch, context, ptrT, css, isHTML);
1.327 vatton 1049: NewLineSkipped = skippedNL;
1.366 vatton 1050: ptrR = ParseCSSBorderLeftWidth (element, tsch, context, ptrT, css, isHTML);
1.327 vatton 1051: }
1.42 cvs 1052: else
1.327 vatton 1053: {
1.366 vatton 1054: /* parse Border-Right */
1055: ptrB = ParseCSSBorderRightWidth (element, tsch, context, ptrR, css, isHTML);
1056: ptrB = SkipBlanksAndComments (ptrB);
1057: if (*ptrB == ';' || *ptrB == '}' || *ptrB == EOS || *ptrB == ',')
1.327 vatton 1058: {
1.366 vatton 1059: skippedNL = NewLineSkipped;
1060: cssRule = ptrB;
1061: /* apply the Border-Top to Border-Bottom */
1062: ptrB = ParseCSSBorderBottomWidth (element, tsch, context, ptrT, css, isHTML);
1063: NewLineSkipped = skippedNL;
1.327 vatton 1064: /* apply the Border-Right to Border-Left */
1.366 vatton 1065: ptrB = ParseCSSBorderLeftWidth (element, tsch, context, ptrR, css, isHTML);
1.327 vatton 1066: }
1067: else
1.366 vatton 1068: {
1069: /* parse Border-Bottom */
1070: ptrL = ParseCSSBorderBottomWidth (element, tsch, context, ptrB, css, isHTML);
1071: ptrL = SkipBlanksAndComments (ptrL);
1072: if (*ptrL == ';' || *ptrL == '}' || *ptrL == EOS || *ptrL == ',')
1073: {
1074: cssRule = ptrL;
1075: /* apply the Border-Right to Border-Left */
1076: ptrL = ParseCSSBorderLeftWidth (element, tsch, context, ptrR, css, isHTML);
1077: }
1078: else
1079: /* parse Border-Left */
1080: cssRule = ParseCSSBorderLeftWidth (element, tsch, context, ptrL, css, isHTML);
1081: cssRule = SkipBlanksAndComments (cssRule);
1082: }
1.327 vatton 1083: }
1.42 cvs 1084: }
1.1 cvs 1085: return (cssRule);
1086: }
1087:
1088: /*----------------------------------------------------------------------
1.327 vatton 1089: ParseCSSBorderColorTop: parse a CSS BorderColorTop
1090: attribute string.
1.1 cvs 1091: ----------------------------------------------------------------------*/
1.79 cvs 1092: static char *ParseCSSBorderColorTop (Element element, PSchema tsch,
1.327 vatton 1093: PresentationContext context,
1094: char *cssRule, CSSInfoPtr css,
1095: ThotBool isHTML)
1.1 cvs 1096: {
1.117 vatton 1097: PresentationValue best;
1.366 vatton 1098: char *start_value = cssRule;
1.43 cvs 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.366 vatton 1108: if (best.typed_data.unit != UNIT_INVALID)
1109: {
1110: if (DoDialog)
1111: {
1112: if (All_sides)
1113: DisplayStyleValue ("border-color", start_value, cssRule);
1114: else
1115: DisplayStyleValue ("border-top-color", start_value, cssRule);
1116: }
1117: else if (DoApply)
1118: /* install the new presentation */
1119: TtaSetStylePresentation (PRBorderTopColor, element, tsch, context, best);
1120: }
1.117 vatton 1121: return (cssRule);
1.1 cvs 1122: }
1123:
1124: /*----------------------------------------------------------------------
1.327 vatton 1125: ParseCSSBorderColorLeft: parse a CSS BorderColorLeft
1126: attribute string.
1.42 cvs 1127: ----------------------------------------------------------------------*/
1.79 cvs 1128: static char *ParseCSSBorderColorLeft (Element element, PSchema tsch,
1.327 vatton 1129: PresentationContext context,
1130: char *cssRule, CSSInfoPtr css,
1131: ThotBool isHTML)
1.42 cvs 1132: {
1.117 vatton 1133: PresentationValue best;
1.366 vatton 1134: char *start_value = cssRule;
1.117 vatton 1135:
1.234 vatton 1136: if (!strncasecmp (cssRule, "transparent", 11))
1137: {
1138: best.typed_data.value = -2; /* -2 means transparent */
1139: best.typed_data.unit = UNIT_REL;
1140: cssRule = SkipWord (cssRule);
1141: }
1142: else
1143: cssRule = ParseCSSColor (cssRule, &best);
1.184 vatton 1144: if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.366 vatton 1145: {
1146: if (DoDialog)
1147: DisplayStyleValue ("border-left-color", start_value, cssRule);
1148: else if (DoApply)
1149: /* install the new presentation */
1150: TtaSetStylePresentation (PRBorderLeftColor, element, tsch, context, best);
1151: }
1.117 vatton 1152: return (cssRule);
1.42 cvs 1153: }
1154:
1155: /*----------------------------------------------------------------------
1.327 vatton 1156: ParseCSSBorderColorBottom: parse a CSS BorderColorBottom
1157: attribute string.
1.42 cvs 1158: ----------------------------------------------------------------------*/
1.79 cvs 1159: static char *ParseCSSBorderColorBottom (Element element, PSchema tsch,
1.327 vatton 1160: PresentationContext context,
1161: char *cssRule, CSSInfoPtr css,
1162: ThotBool isHTML)
1.42 cvs 1163: {
1.117 vatton 1164: PresentationValue best;
1.366 vatton 1165: char *start_value = cssRule;
1.43 cvs 1166:
1.234 vatton 1167: if (!strncasecmp (cssRule, "transparent", 11))
1168: {
1169: best.typed_data.value = -2; /* -2 means transparent */
1170: best.typed_data.unit = UNIT_REL;
1171: cssRule = SkipWord (cssRule);
1172: }
1173: else
1174: cssRule = ParseCSSColor (cssRule, &best);
1.184 vatton 1175: if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.366 vatton 1176: {
1177: if (DoDialog)
1178: DisplayStyleValue ("border-bottom-color", start_value, cssRule);
1179: else if (DoApply)
1180: /* install the new presentation */
1181: TtaSetStylePresentation (PRBorderBottomColor, element, tsch, context, best);
1182: }
1.327 vatton 1183: return (cssRule);
1.42 cvs 1184: }
1185:
1186: /*----------------------------------------------------------------------
1.327 vatton 1187: ParseCSSBorderColorRight: parse a CSS BorderColorRight
1188: attribute string.
1.1 cvs 1189: ----------------------------------------------------------------------*/
1.79 cvs 1190: static char *ParseCSSBorderColorRight (Element element, PSchema tsch,
1.327 vatton 1191: PresentationContext context,
1192: char *cssRule, CSSInfoPtr css,
1193: ThotBool isHTML)
1.1 cvs 1194: {
1.117 vatton 1195: PresentationValue best;
1.366 vatton 1196: char *start_value = cssRule;
1.43 cvs 1197:
1.234 vatton 1198: if (!strncasecmp (cssRule, "transparent", 11))
1199: {
1200: best.typed_data.value = -2; /* -2 means transparent */
1201: best.typed_data.unit = UNIT_REL;
1202: cssRule = SkipWord (cssRule);
1203: }
1204: else
1205: cssRule = ParseCSSColor (cssRule, &best);
1.184 vatton 1206: if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.366 vatton 1207: {
1208: if (DoDialog)
1209: DisplayStyleValue ("border-right-color", start_value, cssRule);
1210: else if (DoApply)
1211: TtaSetStylePresentation (PRBorderRightColor, element, tsch, context, best);
1212: }
1.117 vatton 1213: return (cssRule);
1.1 cvs 1214: }
1215:
1216: /*----------------------------------------------------------------------
1.327 vatton 1217: ParseCSSBorderColor: parse a CSS border-color
1218: attribute string.
1.42 cvs 1219: ----------------------------------------------------------------------*/
1.79 cvs 1220: static char *ParseCSSBorderColor (Element element, PSchema tsch,
1.327 vatton 1221: PresentationContext context,
1222: char *cssRule, CSSInfoPtr css,
1223: ThotBool isHTML)
1.42 cvs 1224: {
1.79 cvs 1225: char *ptrT, *ptrR, *ptrB, *ptrL;
1.366 vatton 1226: int skippedNL, n;
1.42 cvs 1227:
1.82 cvs 1228: ptrT = SkipBlanksAndComments (cssRule);
1.366 vatton 1229: if (DoDialog)
1230: n = NumberOfValues (ptrT);
1231: if (DoDialog && n < 2)
1.42 cvs 1232: {
1.366 vatton 1233: // check if the border dialog must be updated
1234: All_sides = TRUE;
1235: ptrR = ParseCSSBorderColorTop (element, tsch, context, ptrT, css, isHTML);
1236: All_sides = FALSE;
1.42 cvs 1237: }
1238: else
1239: {
1.366 vatton 1240: /* First parse Border-Top */
1241: ptrR = ParseCSSBorderColorTop (element, tsch, context, ptrT, css, isHTML);
1242: ptrR = SkipBlanksAndComments (ptrR);
1243: if (*ptrR == ';' || *ptrR == '}' || *ptrR == EOS || *ptrR == ',')
1.327 vatton 1244: {
1245: skippedNL = NewLineSkipped;
1.366 vatton 1246: cssRule = ptrR;
1247: /* apply the Border-Top to all */
1248: ptrR = ParseCSSBorderColorRight (element, tsch, context, ptrT, css, isHTML);
1249: NewLineSkipped = skippedNL;
1250: ptrR = ParseCSSBorderColorBottom (element, tsch, context, ptrT, css, isHTML);
1.327 vatton 1251: NewLineSkipped = skippedNL;
1.366 vatton 1252: ptrR = ParseCSSBorderColorLeft (element, tsch, context, ptrT, css, isHTML);
1.327 vatton 1253: }
1.42 cvs 1254: else
1.327 vatton 1255: {
1.366 vatton 1256: /* parse Border-Right */
1257: ptrB = ParseCSSBorderColorRight (element, tsch, context, ptrR, css, isHTML);
1258: ptrB = SkipBlanksAndComments (ptrB);
1259: if (*ptrB == ';' || *ptrB == '}' || *ptrB == EOS || *ptrB == ',')
1.327 vatton 1260: {
1.366 vatton 1261: skippedNL = NewLineSkipped;
1262: cssRule = ptrB;
1263: /* apply the Border-Top to Border-Bottom */
1264: ptrB = ParseCSSBorderColorBottom (element, tsch, context, ptrT, css, isHTML);
1265: NewLineSkipped = skippedNL;
1.327 vatton 1266: /* apply the Border-Right to Border-Left */
1.366 vatton 1267: ptrB = ParseCSSBorderColorLeft (element, tsch, context, ptrR, css, isHTML);
1.327 vatton 1268: }
1269: else
1.366 vatton 1270: {
1271: skippedNL = NewLineSkipped;
1272: /* parse Border-Bottom */
1273: ptrL = ParseCSSBorderColorBottom (element, tsch, context, ptrB, css, isHTML);
1274: NewLineSkipped = skippedNL;
1275: ptrL = SkipBlanksAndComments (ptrL);
1276: if (*ptrL == ';' || *ptrL == '}' || *ptrL == EOS || *ptrL == ',')
1277: {
1278: cssRule = ptrL;
1279: /* apply the Border-Right to Border-Left */
1280: ptrL = ParseCSSBorderColorLeft (element, tsch, context, ptrR, css, isHTML);
1281: }
1282: else
1283: /* parse Border-Left */
1284: cssRule = ParseCSSBorderColorLeft (element, tsch, context, ptrL, css, isHTML);
1285: cssRule = SkipBlanksAndComments (cssRule);
1286: }
1.327 vatton 1287: }
1.42 cvs 1288: }
1289: return (cssRule);
1290: }
1291:
1292: /*----------------------------------------------------------------------
1.327 vatton 1293: ParseCSSBorderStyleTop: parse a CSS BorderStyleTop
1294: attribute string.
1.42 cvs 1295: ----------------------------------------------------------------------*/
1.79 cvs 1296: static char *ParseCSSBorderStyleTop (Element element, PSchema tsch,
1.327 vatton 1297: PresentationContext context,
1298: char *cssRule, CSSInfoPtr css,
1299: ThotBool isHTML)
1.42 cvs 1300: {
1.43 cvs 1301: PresentationValue border;
1.366 vatton 1302: char *start_value;
1.43 cvs 1303:
1.82 cvs 1304: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 1305: start_value = cssRule;
1.43 cvs 1306: cssRule = ParseBorderStyle (cssRule, &border);
1.366 vatton 1307: if (border.typed_data.unit != UNIT_INVALID)
1308: {
1309: if (DoDialog)
1310: {
1311: if (All_sides)
1312: DisplayStyleValue ("border-style", start_value, cssRule);
1313: else
1314: DisplayStyleValue ("border-top-style", start_value, cssRule);
1315: }
1316: else if (DoApply)
1317: TtaSetStylePresentation (PRBorderTopStyle, element, tsch, context, border);
1318: }
1.42 cvs 1319: return (cssRule);
1320: }
1321:
1322: /*----------------------------------------------------------------------
1.327 vatton 1323: ParseCSSBorderStyleLeft: parse a CSS BorderStyleLeft
1324: attribute string.
1.42 cvs 1325: ----------------------------------------------------------------------*/
1.79 cvs 1326: static char *ParseCSSBorderStyleLeft (Element element, PSchema tsch,
1.327 vatton 1327: PresentationContext context,
1328: char *cssRule, CSSInfoPtr css,
1329: ThotBool isHTML)
1.42 cvs 1330: {
1.43 cvs 1331: PresentationValue border;
1.366 vatton 1332: char *start_value;
1.43 cvs 1333:
1.82 cvs 1334: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 1335: start_value = cssRule;
1.43 cvs 1336: cssRule = ParseBorderStyle (cssRule, &border);
1.366 vatton 1337: if (border.typed_data.unit != UNIT_INVALID)
1338: {
1339: if (DoDialog)
1340: DisplayStyleValue ("border-left-style", start_value, cssRule);
1341: else if (DoApply)
1342: TtaSetStylePresentation (PRBorderLeftStyle, element, tsch, context, border);
1343: }
1.42 cvs 1344: return (cssRule);
1345: }
1346:
1347: /*----------------------------------------------------------------------
1.327 vatton 1348: ParseCSSBorderStyleBottom: parse a CSS BorderStyleBottom
1349: attribute string.
1.1 cvs 1350: ----------------------------------------------------------------------*/
1.79 cvs 1351: static char *ParseCSSBorderStyleBottom (Element element, PSchema tsch,
1.327 vatton 1352: PresentationContext context,
1353: char *cssRule, CSSInfoPtr css,
1354: ThotBool isHTML)
1.1 cvs 1355: {
1.43 cvs 1356: PresentationValue border;
1.366 vatton 1357: char *start_value;
1.43 cvs 1358:
1.82 cvs 1359: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 1360: start_value = cssRule;
1.43 cvs 1361: cssRule = ParseBorderStyle (cssRule, &border);
1.366 vatton 1362: if (border.typed_data.unit != UNIT_INVALID)
1363: {
1364: if (DoDialog)
1365: DisplayStyleValue ("border-bottom-style", start_value, cssRule);
1366: else if (DoApply)
1367: TtaSetStylePresentation (PRBorderBottomStyle, element, tsch, context, border);
1368: }
1.1 cvs 1369: return (cssRule);
1370: }
1371:
1372: /*----------------------------------------------------------------------
1.327 vatton 1373: ParseCSSBorderStyleRight: parse a CSS BorderStyleRight
1374: attribute string.
1.1 cvs 1375: ----------------------------------------------------------------------*/
1.79 cvs 1376: static char *ParseCSSBorderStyleRight (Element element, PSchema tsch,
1.327 vatton 1377: PresentationContext context,
1378: char *cssRule, CSSInfoPtr css,
1379: ThotBool isHTML)
1.1 cvs 1380: {
1.43 cvs 1381: PresentationValue border;
1.366 vatton 1382: char *start_value;
1.43 cvs 1383:
1.82 cvs 1384: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 1385: start_value = cssRule;
1.43 cvs 1386: cssRule = ParseBorderStyle (cssRule, &border);
1.184 vatton 1387: if (border.typed_data.unit != UNIT_INVALID && DoApply)
1.366 vatton 1388: {
1389: if (DoDialog)
1390: DisplayStyleValue ("border-right-style", start_value, cssRule);
1391: else if (DoApply)
1392: TtaSetStylePresentation (PRBorderRightStyle, element, tsch, context, border);
1393: }
1.1 cvs 1394: return (cssRule);
1395: }
1396:
1397: /*----------------------------------------------------------------------
1.349 quint 1398: ParseCSSBorderStyle: parse a CSS border-style attribute string.
1.1 cvs 1399: ----------------------------------------------------------------------*/
1.79 cvs 1400: static char *ParseCSSBorderStyle (Element element, PSchema tsch,
1.327 vatton 1401: PresentationContext context,
1402: char *cssRule, CSSInfoPtr css,
1403: ThotBool isHTML)
1.1 cvs 1404: {
1.79 cvs 1405: char *ptrT, *ptrR, *ptrB, *ptrL;
1.366 vatton 1406: int skippedNL, n;
1.42 cvs 1407:
1.82 cvs 1408: ptrT = SkipBlanksAndComments (cssRule);
1.366 vatton 1409: if (DoDialog)
1410: n = NumberOfValues (ptrT);
1411: if (DoDialog && n < 2)
1.42 cvs 1412: {
1.366 vatton 1413: // check if the border dialog must be updated
1414: All_sides = TRUE;
1415: ptrR = ParseCSSBorderStyleTop(element, tsch, context, ptrT, css, isHTML);
1416: All_sides = FALSE;
1.42 cvs 1417: }
1418: else
1419: {
1.366 vatton 1420: /* First parse Border-Top */
1421: ptrR = ParseCSSBorderStyleTop (element, tsch, context, ptrT, css, isHTML);
1422: ptrR = SkipBlanksAndComments (ptrR);
1423: if (*ptrR == ';' || *ptrR == '}' || *ptrR == EOS || *ptrR == ',')
1.327 vatton 1424: {
1425: skippedNL = NewLineSkipped;
1.366 vatton 1426: cssRule = ptrR;
1427: /* apply the Border-Top to all */
1428: ptrR = ParseCSSBorderStyleRight (element, tsch, context, ptrT, css, isHTML);
1429: NewLineSkipped = skippedNL;
1430: ptrR = ParseCSSBorderStyleBottom (element, tsch, context, ptrT, css, isHTML);
1.327 vatton 1431: NewLineSkipped = skippedNL;
1.366 vatton 1432: ptrR = ParseCSSBorderStyleLeft (element, tsch, context, ptrT, css, isHTML);
1.327 vatton 1433: }
1.42 cvs 1434: else
1.327 vatton 1435: {
1.366 vatton 1436: /* parse Border-Right */
1437: ptrB = ParseCSSBorderStyleRight (element, tsch, context, ptrR, css, isHTML);
1438: ptrB = SkipBlanksAndComments (ptrB);
1439: if (*ptrB == ';' || *ptrR == '}' || *ptrB == EOS || *ptrB == ',')
1.327 vatton 1440: {
1.366 vatton 1441: skippedNL = NewLineSkipped;
1442: cssRule = ptrB;
1443: /* apply the Border-Top to Border-Bottom */
1444: ptrB = ParseCSSBorderStyleBottom (element, tsch, context, ptrT, css, isHTML);
1445: NewLineSkipped = skippedNL;
1.327 vatton 1446: /* apply the Border-Right to Border-Left */
1.366 vatton 1447: ptrB = ParseCSSBorderStyleLeft (element, tsch, context, ptrR, css, isHTML);
1.327 vatton 1448: }
1449: else
1.366 vatton 1450: {
1451: /* parse Border-Bottom */
1452: ptrL = ParseCSSBorderStyleBottom (element, tsch, context, ptrB, css, isHTML);
1453: ptrL = SkipBlanksAndComments (ptrL);
1454: if (*ptrL == ';' || *ptrR == '}' || *ptrL == EOS || *ptrL == ',')
1455: {
1456: cssRule = ptrL;
1457: /* apply the Border-Right to Border-Left */
1458: ptrL = ParseCSSBorderStyleLeft (element, tsch, context, ptrR, css, isHTML);
1459: }
1460: else
1461: /* parse Border-Left */
1462: cssRule = ParseCSSBorderStyleLeft (element, tsch, context, ptrL, css, isHTML);
1463: cssRule = SkipBlanksAndComments (cssRule);
1464: }
1.327 vatton 1465: }
1.42 cvs 1466: }
1467: return (cssRule);
1468: }
1469:
1470: /*----------------------------------------------------------------------
1.327 vatton 1471: ParseCSSBorderTop: parse a CSS BorderTop
1472: attribute string.
1.42 cvs 1473: ----------------------------------------------------------------------*/
1.79 cvs 1474: static char *ParseCSSBorderTop (Element element, PSchema tsch,
1.327 vatton 1475: PresentationContext context, char *cssRule,
1476: CSSInfoPtr css, ThotBool isHTML)
1.42 cvs 1477: {
1.370 vatton 1478: PresentationValue best;
1479: char *ptr;
1480: ThotBool style, width, color;
1.43 cvs 1481:
1.82 cvs 1482: cssRule = SkipBlanksAndComments (cssRule);
1.322 vatton 1483: /* register given values */
1.337 vatton 1484: if (!strncmp (cssRule, "none", 4))
1.370 vatton 1485: style = width = color = TRUE;
1.337 vatton 1486: else
1.370 vatton 1487: style = width = color = FALSE;
1.301 vatton 1488: while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.43 cvs 1489: {
1490: ptr = cssRule;
1491: cssRule = ParseCSSBorderStyleTop (element, tsch, context, cssRule, css, isHTML);
1492: if (ptr == cssRule)
1.327 vatton 1493: {
1494: cssRule = ParseCSSBorderTopWidth (element, tsch, context, cssRule, css, isHTML);
1495: if (ptr == cssRule)
1.370 vatton 1496: {
1497: cssRule = ParseCSSBorderColorTop (element, tsch, context, cssRule, css, isHTML);
1498: if (ptr != cssRule)
1499: color = TRUE;
1500: }
1.327 vatton 1501: else
1502: width = TRUE;
1503: if (ptr == cssRule)
1504: {
1505: /* rule not found */
1506: cssRule = SkipValue ("Invalid border value", cssRule);
1507: return (cssRule);
1508: }
1509: }
1.322 vatton 1510: else
1.327 vatton 1511: style = TRUE;
1.82 cvs 1512: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 1513: }
1.322 vatton 1514:
1515: if (!width)
1.405 kia 1516: ParseCSSBorderTopWidth (element, tsch, context, (char*)"medium", css, isHTML);
1.322 vatton 1517: if (!style)
1.405 kia 1518: ParseCSSBorderStyleTop (element, tsch, context, (char*)"none", css, isHTML);
1.370 vatton 1519: if (!color && DoApply)
1520: {
1521: /* get the box color */
1522: best.typed_data.value = -1;
1523: best.typed_data.unit = UNIT_REL;
1524: best.typed_data.real = FALSE;
1525: TtaSetStylePresentation (PRBorderTopColor, element, tsch, context, best);
1526: }
1.42 cvs 1527: return (cssRule);
1528: }
1529:
1530: /*----------------------------------------------------------------------
1.327 vatton 1531: ParseCSSBorderLeft: parse a CSS BorderLeft
1532: attribute string.
1.42 cvs 1533: ----------------------------------------------------------------------*/
1.79 cvs 1534: static char *ParseCSSBorderLeft (Element element, PSchema tsch,
1.327 vatton 1535: PresentationContext context, char *cssRule,
1536: CSSInfoPtr css, ThotBool isHTML)
1.42 cvs 1537: {
1.370 vatton 1538: PresentationValue best;
1539: char *ptr;
1540: ThotBool style, width, color;
1.43 cvs 1541:
1.82 cvs 1542: cssRule = SkipBlanksAndComments (cssRule);
1.322 vatton 1543: /* register given values */
1.337 vatton 1544: if (!strncmp (cssRule, "none", 4))
1.370 vatton 1545: style = width = color = TRUE;
1.337 vatton 1546: else
1.370 vatton 1547: style = width = color = FALSE;
1.301 vatton 1548: while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.43 cvs 1549: {
1550: ptr = cssRule;
1551: cssRule = ParseCSSBorderStyleLeft (element, tsch, context, cssRule, css, isHTML);
1552: if (ptr == cssRule)
1.327 vatton 1553: {
1554: cssRule = ParseCSSBorderLeftWidth (element, tsch, context, cssRule, css, isHTML);
1555: if (ptr == cssRule)
1.370 vatton 1556: {
1557: cssRule = ParseCSSBorderColorLeft (element, tsch, context, cssRule, css, isHTML);
1558: if (ptr != cssRule)
1559: color = TRUE;
1560: }
1.327 vatton 1561: else
1562: width = TRUE;
1563: if (ptr == cssRule)
1564: {
1565: /* rule not found */
1566: cssRule = SkipValue ("Invalid border value", cssRule);
1567: return (cssRule);
1568: }
1569: }
1.322 vatton 1570: else
1.327 vatton 1571: style = TRUE;
1572: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 1573: }
1.322 vatton 1574:
1575: if (!width)
1.405 kia 1576: ParseCSSBorderLeftWidth (element, tsch, context, (char*)"medium", css, isHTML);
1.322 vatton 1577: if (!style)
1.405 kia 1578: ParseCSSBorderStyleLeft (element, tsch, context, (char*)"none", css, isHTML);
1.370 vatton 1579: if (!color && DoApply)
1580: {
1581: /* get the box color */
1582: best.typed_data.value = -1;
1583: best.typed_data.unit = UNIT_REL;
1584: best.typed_data.real = FALSE;
1585: TtaSetStylePresentation (PRBorderLeftColor, element, tsch, context, best);
1586: }
1.1 cvs 1587: return (cssRule);
1588: }
1589:
1590: /*----------------------------------------------------------------------
1.327 vatton 1591: ParseCSSBorderBottom: parse a CSS BorderBottom
1592: attribute string.
1.1 cvs 1593: ----------------------------------------------------------------------*/
1.79 cvs 1594: static char *ParseCSSBorderBottom (Element element, PSchema tsch,
1.327 vatton 1595: PresentationContext context, char *cssRule,
1596: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1597: {
1.370 vatton 1598: PresentationValue best;
1599: char *ptr;
1600: ThotBool style, width, color;
1.43 cvs 1601:
1.82 cvs 1602: cssRule = SkipBlanksAndComments (cssRule);
1.322 vatton 1603: /* register given values */
1.337 vatton 1604: if (!strncmp (cssRule, "none", 4))
1.370 vatton 1605: style = width = color = TRUE;
1.337 vatton 1606: else
1.370 vatton 1607: style = width = color = FALSE;
1.301 vatton 1608: while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.43 cvs 1609: {
1610: ptr = cssRule;
1611: cssRule = ParseCSSBorderStyleBottom (element, tsch, context, cssRule, css, isHTML);
1612: if (ptr == cssRule)
1.327 vatton 1613: {
1614: cssRule = ParseCSSBorderBottomWidth (element, tsch, context, cssRule, css, isHTML);
1615: if (ptr == cssRule)
1.370 vatton 1616: {
1617: cssRule = ParseCSSBorderColorBottom (element, tsch, context, cssRule, css, isHTML);
1618: if (ptr != cssRule)
1619: color = TRUE;
1620: }
1.327 vatton 1621: else
1622: width = TRUE;
1623: if (ptr == cssRule)
1624: {
1625: /* rule not found */
1626: cssRule = SkipValue ("Invalid border value", cssRule);
1627: return (cssRule);
1628: }
1629: }
1.322 vatton 1630: else
1.327 vatton 1631: style = TRUE;
1.82 cvs 1632: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 1633: }
1.322 vatton 1634:
1635: if (!width)
1.405 kia 1636: ParseCSSBorderBottomWidth (element, tsch, context, (char*)"medium", css, isHTML);
1.322 vatton 1637: if (!style)
1.405 kia 1638: ParseCSSBorderStyleBottom (element, tsch, context, (char*)"none", css, isHTML);
1.370 vatton 1639: if (!color && DoApply)
1640: {
1641: /* get the box color */
1642: best.typed_data.value = -1;
1643: best.typed_data.unit = UNIT_REL;
1644: best.typed_data.real = FALSE;
1645: TtaSetStylePresentation (PRBorderBottomColor, element, tsch, context, best);
1646: }
1.1 cvs 1647: return (cssRule);
1648: }
1649:
1650: /*----------------------------------------------------------------------
1.327 vatton 1651: ParseCSSBorderRight: parse a CSS BorderRight
1652: attribute string.
1.1 cvs 1653: ----------------------------------------------------------------------*/
1.79 cvs 1654: static char *ParseCSSBorderRight (Element element, PSchema tsch,
1.327 vatton 1655: PresentationContext context, char *cssRule,
1656: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1657: {
1.370 vatton 1658: PresentationValue best;
1659: char *ptr;
1660: ThotBool style, width, color;
1.43 cvs 1661:
1.82 cvs 1662: cssRule = SkipBlanksAndComments (cssRule);
1.322 vatton 1663: /* register given values */
1.337 vatton 1664: if (!strncmp (cssRule, "none", 4))
1.370 vatton 1665: style = width = color = TRUE;
1.337 vatton 1666: else
1.370 vatton 1667: style = width = color = FALSE;
1.301 vatton 1668: while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.43 cvs 1669: {
1670: ptr = cssRule;
1671: cssRule = ParseCSSBorderStyleRight (element, tsch, context, cssRule, css, isHTML);
1672: if (ptr == cssRule)
1.327 vatton 1673: {
1674: cssRule = ParseCSSBorderRightWidth (element, tsch, context, cssRule, css, isHTML);
1675: if (ptr == cssRule)
1.370 vatton 1676: {
1677: cssRule = ParseCSSBorderColorRight (element, tsch, context, cssRule, css, isHTML);
1678: if (ptr != cssRule)
1679: color = TRUE;
1680: }
1.327 vatton 1681: else
1682: width = TRUE;
1683: if (ptr == cssRule)
1684: {
1685: /* rule not found */
1686: cssRule = SkipValue ("Invalid border value", cssRule);
1687: return (cssRule);
1688: }
1689: }
1.322 vatton 1690: else
1.327 vatton 1691: style = TRUE;
1.82 cvs 1692: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 1693: }
1.322 vatton 1694:
1695: if (!width)
1.405 kia 1696: ParseCSSBorderRightWidth (element, tsch, context, (char*)"medium", css, isHTML);
1.322 vatton 1697: if (!style)
1.405 kia 1698: ParseCSSBorderStyleRight (element, tsch, context, (char*)"none", css, isHTML);
1.370 vatton 1699: if (!color && DoApply)
1700: {
1701: /* get the box color */
1702: best.typed_data.value = -1;
1703: best.typed_data.unit = UNIT_REL;
1.374 vatton 1704: best.typed_data.real = FALSE;
1.370 vatton 1705: TtaSetStylePresentation (PRBorderRightColor, element, tsch, context, best);
1706: }
1.1 cvs 1707: return (cssRule);
1708: }
1709:
1710: /*----------------------------------------------------------------------
1.327 vatton 1711: ParseCSSBorder: parse a CSS border
1712: attribute string.
1.42 cvs 1713: ----------------------------------------------------------------------*/
1.79 cvs 1714: static char *ParseCSSBorder (Element element, PSchema tsch,
1.327 vatton 1715: PresentationContext context, char *cssRule,
1716: CSSInfoPtr css, ThotBool isHTML)
1.42 cvs 1717: {
1.79 cvs 1718: char *ptrT, *ptrR;
1.366 vatton 1719: int skippedNL, n;
1.42 cvs 1720:
1.82 cvs 1721: ptrT = SkipBlanksAndComments (cssRule);
1.366 vatton 1722: if (DoDialog)
1723: n = NumberOfValues (ptrT);
1724: if (DoDialog && n < 4)
1.42 cvs 1725: {
1.366 vatton 1726: // check if the border dialog must be updated
1727: All_sides = TRUE;
1728: ptrR = ParseCSSBorderTop (element, tsch, context, ptrT, css, isHTML);
1729: All_sides = FALSE;
1730: }
1731: else
1732: {
1733: /* First parse Border-Top */
1734: ptrR = ParseCSSBorderTop (element, tsch, context, ptrT, css, isHTML);
1735: ptrR = SkipBlanksAndComments (ptrR);
1736: if (*ptrR == ';' || *ptrR == '}' || *ptrR == EOS || *ptrR == ',')
1737: {
1738: skippedNL = NewLineSkipped;
1739: cssRule = ptrR;
1740: /* apply the Border-Top to all */
1741: ptrR = ParseCSSBorderRight (element, tsch, context, ptrT, css, isHTML);
1742: NewLineSkipped = skippedNL;
1743: ptrR = ParseCSSBorderBottom (element, tsch, context, ptrT, css, isHTML);
1744: NewLineSkipped = skippedNL;
1745: ptrR = ParseCSSBorderLeft (element, tsch, context, ptrT, css, isHTML);
1746: }
1.42 cvs 1747: }
1748: return (cssRule);
1749: }
1750:
1.218 vatton 1751:
1.42 cvs 1752: /*----------------------------------------------------------------------
1.327 vatton 1753: ParseCSSFloat: parse a CSS float attribute string
1.184 vatton 1754: ----------------------------------------------------------------------*/
1755: static char *ParseCSSFloat (Element element, PSchema tsch,
1.327 vatton 1756: PresentationContext context, char *cssRule,
1757: CSSInfoPtr css, ThotBool isHTML)
1.184 vatton 1758: {
1.257 vatton 1759: DisplayMode dispMode;
1.184 vatton 1760: PresentationValue pval;
1.288 vatton 1761: char *ptr = cssRule;
1.404 vatton 1762: ThotBool warn;
1.184 vatton 1763:
1.404 vatton 1764: // check if Amaya should report CSS warnings
1765: TtaGetEnvBoolean ("CSS_WARN", &warn);
1.184 vatton 1766: pval.typed_data.value = 0;
1.187 vatton 1767: pval.typed_data.unit = UNIT_BOX;
1.192 cvs 1768: pval.typed_data.real = FALSE;
1.190 vatton 1769: if (!strncasecmp (cssRule, "inherit", 7))
1770: {
1.293 quint 1771: pval.typed_data.unit = VALUE_INHERIT;
1.288 vatton 1772: cssRule += 7;
1.190 vatton 1773: }
1.184 vatton 1774: if (!strncasecmp (cssRule, "none", 4))
1.288 vatton 1775: {
1776: pval.typed_data.value = FloatNone;
1.293 quint 1777: cssRule += 4;
1.288 vatton 1778: }
1.184 vatton 1779: else if (!strncasecmp (cssRule, "left", 4))
1.288 vatton 1780: {
1781: pval.typed_data.value = FloatLeft;
1.293 quint 1782: cssRule += 4;
1.288 vatton 1783: }
1.184 vatton 1784: else if (!strncasecmp (cssRule, "right", 5))
1.288 vatton 1785: {
1786: pval.typed_data.value = FloatRight;
1.293 quint 1787: cssRule += 5;
1.288 vatton 1788: }
1.184 vatton 1789:
1.293 quint 1790: if (pval.typed_data.value == 0 && pval.typed_data.unit != VALUE_INHERIT)
1.359 quint 1791: {
1792: if (!strncasecmp (cssRule, "top", 3) ||
1793: !strncasecmp (cssRule, "bottom", 6) ||
1794: !strncasecmp (cssRule, "inside", 6) ||
1795: !strncasecmp (cssRule, "outside", 7) ||
1796: !strncasecmp (cssRule, "start", 5) ||
1797: !strncasecmp (cssRule, "end", 3))
1.404 vatton 1798: {
1799: if (warn)
1800: cssRule = SkipValue ("Warning: CSS3 value not supported", cssRule);
1801: else
1802: cssRule = SkipValue (NULL, cssRule);
1803: }
1.359 quint 1804: else
1805: cssRule = SkipValue ("Invalid float value", cssRule);
1806: }
1.184 vatton 1807: else
1808: {
1.366 vatton 1809: if (DoDialog)
1810: DisplayStyleValue ("float", ptr, cssRule);
1811: else if (DoApply)
1.327 vatton 1812: {
1813: dispMode = TtaGetDisplayMode (context->doc);
1814: if (dispMode != NoComputedDisplay)
1815: {
1816: /* force a redisplay of the whole document */
1817: TtaSetDisplayMode (context->doc, NoComputedDisplay);
1.257 vatton 1818: #ifdef AMAYA_DEBUG
1.327 vatton 1819: /*printf ("Force NoComputedDisplay doc=%d\n", context->doc);*/
1.257 vatton 1820: #endif /* AMAYA_DEBUG */
1.327 vatton 1821: }
1822: TtaSetStylePresentation (PRFloat, element, tsch, context, pval);
1823: }
1.288 vatton 1824: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid float value");
1.184 vatton 1825: }
1826: return (cssRule);
1827: }
1828:
1829: /*----------------------------------------------------------------------
1.327 vatton 1830: ParseCSSClear: parse a CSS clear rule
1.1 cvs 1831: ----------------------------------------------------------------------*/
1.79 cvs 1832: static char *ParseCSSClear (Element element, PSchema tsch,
1.327 vatton 1833: PresentationContext context, char *cssRule,
1834: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1835: {
1.184 vatton 1836: PresentationValue pval;
1.366 vatton 1837: char *start_value = cssRule;
1.184 vatton 1838:
1839: pval.typed_data.value = 0;
1.187 vatton 1840: pval.typed_data.unit = UNIT_BOX;
1.193 vatton 1841: pval.typed_data.real = FALSE;
1.190 vatton 1842: if (!strncasecmp (cssRule, "inherit", 7))
1.293 quint 1843: pval.typed_data.unit = VALUE_INHERIT;
1.184 vatton 1844: if (!strncasecmp (cssRule, "none", 4))
1845: pval.typed_data.value = ClearNone;
1846: else if (!strncasecmp (cssRule, "left", 4))
1847: pval.typed_data.value = ClearLeft;
1848: else if (!strncasecmp (cssRule, "right", 5))
1849: pval.typed_data.value = ClearRight;
1850: else if (!strncasecmp (cssRule, "both", 4))
1851: pval.typed_data.value = ClearBoth;
1852:
1.293 quint 1853: if (pval.typed_data.value == 0 && pval.typed_data.unit != VALUE_INHERIT)
1.295 vatton 1854: {
1855: cssRule = SkipValue ("Invalid clear value", cssRule);
1856: cssRule = SkipValue (NULL, cssRule);
1857: }
1.184 vatton 1858: else
1859: {
1.295 vatton 1860: cssRule = SkipValue (NULL, cssRule);
1.366 vatton 1861: if (DoDialog)
1862: DisplayStyleValue ("clear", start_value, cssRule);
1863: else if (DoApply)
1.327 vatton 1864: TtaSetStylePresentation (PRClear, element, tsch, context, pval);
1.184 vatton 1865: }
1866: return (cssRule);
1867: }
1868:
1869: /*----------------------------------------------------------------------
1.333 vatton 1870: ParseCSSVisibility: parse a CSS visibility attribute string
1871: ----------------------------------------------------------------------*/
1872: static char *ParseCSSVisibility(Element element, PSchema tsch,
1873: PresentationContext context, char *cssRule,
1874: CSSInfoPtr css, ThotBool isHTML)
1875: {
1876: PresentationValue pval;
1.366 vatton 1877: char *ptr;
1.333 vatton 1878:
1879: pval.typed_data.unit = UNIT_REL;
1880: pval.typed_data.real = FALSE;
1881: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 1882: ptr = cssRule;
1.333 vatton 1883: if (!strncasecmp (cssRule, "hidden", 6))
1884: {
1885: cssRule += 6;
1886: pval.typed_data.value = VsHidden;
1887: }
1888: else if (!strncasecmp (cssRule, "visible", 7))
1889: {
1890: cssRule += 7;
1891: pval.typed_data.value = VsVisible;
1892: }
1893: else if (!strncasecmp (cssRule, "collapse", 8))
1894: {
1895: cssRule += 8;
1896: pval.typed_data.value = VsCollapse;
1897: }
1898: else if (!strncasecmp (cssRule, "inherit", 7))
1899: {
1900: cssRule += 7;
1901: pval.typed_data.value = VsInherit;
1902: }
1903: else
1904: {
1905: cssRule = SkipValue ("Invalid visibility value", cssRule);
1906: return (cssRule);
1907: }
1.366 vatton 1908: if (DoDialog)
1909: DisplayStyleValue ("visibility", ptr, cssRule);
1910: else if (DoApply)
1.333 vatton 1911: TtaSetStylePresentation (PRVis, element, tsch, context, pval);
1912: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid visibility value");
1913: return (cssRule);
1914: }
1915:
1916:
1917: /*----------------------------------------------------------------------
1.327 vatton 1918: ParseCSSDisplay: parse a CSS display attribute string
1.1 cvs 1919: ----------------------------------------------------------------------*/
1.79 cvs 1920: static char *ParseCSSDisplay (Element element, PSchema tsch,
1.327 vatton 1921: PresentationContext context, char *cssRule,
1922: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1923: {
1.184 vatton 1924: PresentationValue pval;
1.366 vatton 1925: char *ptr;
1.404 vatton 1926: ThotBool warn;
1.1 cvs 1927:
1.184 vatton 1928: pval.typed_data.unit = UNIT_REL;
1929: pval.typed_data.real = FALSE;
1930: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 1931: ptr = cssRule;
1.184 vatton 1932: if (!strncasecmp (cssRule, "none", 4))
1.288 vatton 1933: {
1934: cssRule += 4;
1935: pval.typed_data.value = DisplayNone;
1936: }
1.277 quint 1937: else if (!strncasecmp (cssRule, "block", 5))
1.288 vatton 1938: {
1939: cssRule += 5;
1940: pval.typed_data.value = Block;
1941: }
1.303 vatton 1942: else if (!strncasecmp (cssRule, "inline-block", 12))
1943: {
1944: cssRule += 12;
1945: pval.typed_data.value = InlineBlock;
1946: }
1.277 quint 1947: else if (!strncasecmp (cssRule, "inline", 6))
1.288 vatton 1948: {
1949: cssRule += 6;
1950: pval.typed_data.value = Inline;
1951: }
1.277 quint 1952: else if (!strncasecmp (cssRule, "list-item", 9))
1.288 vatton 1953: {
1954: cssRule += 9;
1955: pval.typed_data.value = ListItem;
1956: }
1.277 quint 1957: else if (!strncasecmp (cssRule, "run-in", 6))
1.288 vatton 1958: {
1959: cssRule += 6;
1960: pval.typed_data.value = RunIn;
1961: }
1.293 quint 1962: else if (!strncasecmp (cssRule, "inherit", 7))
1963: {
1964: cssRule += 7;
1965: pval.typed_data.unit = VALUE_INHERIT;
1966: }
1.277 quint 1967: else
1.184 vatton 1968: {
1.404 vatton 1969: TtaGetEnvBoolean ("CSS_WARN", &warn);
1970: if (warn &&
1971: strncasecmp (cssRule, "table-row-group", 15) &&
1.327 vatton 1972: strncasecmp (cssRule, "table-column-group", 18) &&
1973: strncasecmp (cssRule, "table-header-group", 5) &&
1974: strncasecmp (cssRule, "table-footer-group", 6) &&
1975: strncasecmp (cssRule, "table-row", 9) &&
1976: strncasecmp (cssRule, "table-column", 12) &&
1977: strncasecmp (cssRule, "table-cell", 10) &&
1978: strncasecmp (cssRule, "table-caption", 13) &&
1979: strncasecmp (cssRule, "inline-table", 12) &&
1980: strncasecmp (cssRule, "table", 5))
1981: cssRule = SkipValue ("Display value not supported", cssRule);
1.281 quint 1982: else
1.327 vatton 1983: cssRule = SkipWord (cssRule);
1.277 quint 1984: return (cssRule);
1.184 vatton 1985: }
1.277 quint 1986:
1.366 vatton 1987: if (DoDialog)
1988: DisplayStyleValue ("display", ptr, cssRule);
1989: else if (DoApply)
1.295 vatton 1990: TtaSetStylePresentation (PRDisplay, element, tsch, context, pval);
1.288 vatton 1991: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid display value");
1.1 cvs 1992: return (cssRule);
1993: }
1994:
1995: /*----------------------------------------------------------------------
1.327 vatton 1996: ParseCSSLetterSpacing: parse a CSS letter-spacing
1997: attribute string.
1.1 cvs 1998: ----------------------------------------------------------------------*/
1.79 cvs 1999: static char *ParseCSSLetterSpacing (Element element, PSchema tsch,
1.327 vatton 2000: PresentationContext context, char *cssRule,
2001: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2002: {
1.366 vatton 2003: char *start_value = cssRule;
2004:
1.168 vatton 2005: cssRule = SkipValue (NULL, cssRule);
1.366 vatton 2006: if (DoDialog)
2007: DisplayStyleValue ("letter-spacing", start_value, cssRule);
1.1 cvs 2008: return (cssRule);
2009: }
2010:
2011: /*----------------------------------------------------------------------
1.436 quint 2012: ParseCounterStyle: parse a CSS counter style.
1.1 cvs 2013: ----------------------------------------------------------------------*/
1.436 quint 2014: static char *ParseCounterStyle (char *cssRule, PresentationValue *pval,
2015: char *start_value)
1.1 cvs 2016: {
1.436 quint 2017: (*pval).typed_data.unit = UNIT_REL;
2018: (*pval).typed_data.real = FALSE;
1.281 quint 2019: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 2020: start_value = cssRule;
1.281 quint 2021: if (!strncasecmp (cssRule, "disc", 4))
1.288 vatton 2022: {
2023: cssRule += 4;
1.436 quint 2024: (*pval).typed_data.value = Disc;
1.288 vatton 2025: }
1.281 quint 2026: else if (!strncasecmp (cssRule, "circle", 6))
1.293 quint 2027: {
1.288 vatton 2028: cssRule += 6;
1.436 quint 2029: (*pval).typed_data.value = Circle;
1.293 quint 2030: }
1.281 quint 2031: else if (!strncasecmp (cssRule, "square", 6))
1.293 quint 2032: {
1.288 vatton 2033: cssRule += 6;
1.436 quint 2034: (*pval).typed_data.value = Square;
1.293 quint 2035: }
1.438 ! quint 2036: else if (!strncasecmp (cssRule, "decimal", 7))
! 2037: {
! 2038: cssRule += 7;
! 2039: (*pval).typed_data.value = Decimal;
! 2040: }
1.283 quint 2041: else if (!strncasecmp (cssRule, "decimal-leading-zero", 20))
1.293 quint 2042: {
1.288 vatton 2043: cssRule += 20;
1.436 quint 2044: (*pval).typed_data.value = DecimalLeadingZero;
1.293 quint 2045: }
1.281 quint 2046: else if (!strncasecmp (cssRule, "lower-roman", 11))
1.293 quint 2047: {
1.288 vatton 2048: cssRule += 11;
1.436 quint 2049: (*pval).typed_data.value = LowerRoman;
1.293 quint 2050: }
1.281 quint 2051: else if (!strncasecmp (cssRule, "upper-roman", 11))
1.293 quint 2052: {
1.288 vatton 2053: cssRule += 11;
1.436 quint 2054: (*pval).typed_data.value = UpperRoman;
1.293 quint 2055: }
1.281 quint 2056: else if (!strncasecmp (cssRule, "lower-greek", 11))
1.293 quint 2057: {
1.288 vatton 2058: cssRule += 11;
1.436 quint 2059: (*pval).typed_data.value = LowerGreek;
1.293 quint 2060: }
1.438 ! quint 2061: else if (!strncasecmp (cssRule, "upper-greek", 11))
1.293 quint 2062: {
1.288 vatton 2063: cssRule += 11;
1.438 ! quint 2064: (*pval).typed_data.value = UpperGreek;
1.293 quint 2065: }
1.438 ! quint 2066: else if (!strncasecmp (cssRule, "lower-latin", 11))
1.293 quint 2067: {
1.288 vatton 2068: cssRule += 11;
1.436 quint 2069: (*pval).typed_data.value = LowerLatin;
1.293 quint 2070: }
1.281 quint 2071: else if (!strncasecmp (cssRule, "upper-latin", 11))
1.293 quint 2072: {
1.288 vatton 2073: cssRule += 11;
1.436 quint 2074: (*pval).typed_data.value = UpperLatin;
1.293 quint 2075: }
1.281 quint 2076: else if (!strncasecmp (cssRule, "armenian", 8))
1.293 quint 2077: {
1.288 vatton 2078: cssRule += 8;
1.436 quint 2079: (*pval).typed_data.value = Decimal;
1.293 quint 2080: }
1.281 quint 2081: else if (!strncasecmp (cssRule, "georgian", 8))
1.293 quint 2082: {
1.288 vatton 2083: cssRule += 8;
1.436 quint 2084: (*pval).typed_data.value = Decimal;
1.293 quint 2085: }
1.438 ! quint 2086: else if (!strncasecmp (cssRule, "lower-alpha", 11))
! 2087: {
! 2088: cssRule += 11;
! 2089: (*pval).typed_data.value = LowerLatin;
! 2090: }
! 2091: else if (!strncasecmp (cssRule, "upper-alpha", 11))
! 2092: {
! 2093: cssRule += 11;
! 2094: (*pval).typed_data.value = UpperLatin;
! 2095: }
1.281 quint 2096: else if (!strncasecmp (cssRule, "none", 4))
1.293 quint 2097: {
1.288 vatton 2098: cssRule += 4;
1.436 quint 2099: (*pval).typed_data.value = ListStyleTypeNone;
1.293 quint 2100: }
1.281 quint 2101: else if (!strncasecmp (cssRule, "inherit", 7))
2102: {
1.293 quint 2103: cssRule += 7;
1.436 quint 2104: (*pval).typed_data.unit = VALUE_INHERIT;
1.281 quint 2105: }
2106: else
1.436 quint 2107: cssRule = SkipValue ("Invalid list-style-type value", cssRule);
2108: return (cssRule);
2109: }
2110:
2111: /*----------------------------------------------------------------------
2112: ParseACSSListStyleType: parse a CSS list-style-type
2113: attribute string.
2114: ----------------------------------------------------------------------*/
2115: static char *ParseACSSListStyleType (Element element, PSchema tsch,
2116: PresentationContext context, char *cssRule,
2117: CSSInfoPtr css, ThotBool isHTML)
2118: {
2119: PresentationValue pval;
2120: char *start_value;
1.281 quint 2121:
1.436 quint 2122: cssRule = ParseCounterStyle (cssRule, &pval, start_value);
1.366 vatton 2123: if (DoDialog)
2124: DisplayStyleValue ("list-style-type", start_value, cssRule);
2125: else if (DoApply)
1.295 vatton 2126: TtaSetStylePresentation (PRListStyleType, element, tsch, context, pval);
1.318 vatton 2127: return (cssRule);
2128: }
2129:
2130: /*----------------------------------------------------------------------
1.327 vatton 2131: ParseCSSListStyleType: parse a CSS list-style-type
2132: attribute string.
1.318 vatton 2133: ----------------------------------------------------------------------*/
2134: static char *ParseCSSListStyleType (Element element, PSchema tsch,
1.327 vatton 2135: PresentationContext context, char *cssRule,
2136: CSSInfoPtr css, ThotBool isHTML)
1.318 vatton 2137: {
2138: char *ptr = cssRule;
2139: cssRule = ParseACSSListStyleType (element, tsch, context, cssRule, css,
1.327 vatton 2140: isHTML);
1.288 vatton 2141: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid list-style-type value");
1.318 vatton 2142: return cssRule;
1.1 cvs 2143: }
2144:
2145: /*----------------------------------------------------------------------
1.281 quint 2146: ParseCSSUrl: parse an URL
1.375 vatton 2147: Parse the url content (don't start with "url")
2148: Return the next pointer in the CSS string
2149: If a correct URL is found, it's returned in url (this string must
2150: be freed)
1.281 quint 2151: ----------------------------------------------------------------------*/
2152: static char *ParseCSSUrl (char *cssRule, char **url)
2153: {
2154: char saved;
2155: char *base, *ptr;
2156:
2157: cssRule = SkipBlanksAndComments (cssRule);
2158: saved = *cssRule;
2159: if (*cssRule == '(')
2160: {
2161: cssRule++;
2162: cssRule = SkipBlanksAndComments (cssRule);
2163: /*** Escaped quotes are not handled. See function SkipQuotedString */
2164: if (*cssRule == '"')
1.327 vatton 2165: {
2166: cssRule++;
2167: base = cssRule;
2168: while (*cssRule != EOS && *cssRule != '"')
2169: cssRule++;
2170: }
1.281 quint 2171: else if (*cssRule == '\'')
1.327 vatton 2172: {
2173: cssRule++;
2174: base = cssRule;
2175: while (*cssRule != EOS && *cssRule != '\'')
2176: cssRule++;
2177: }
1.281 quint 2178: else
1.327 vatton 2179: {
2180: base = cssRule;
2181: while (*cssRule != EOS && *cssRule != ')')
2182: cssRule++;
2183: }
1.281 quint 2184: /* keep the current position */
2185: ptr = cssRule;
1.402 vatton 2186: if (saved == '(')
1.327 vatton 2187: {
2188: /* remove extra spaces */
2189: if (cssRule[-1] == SPACE)
2190: {
2191: *cssRule = SPACE;
2192: cssRule--;
2193: while (cssRule[-1] == SPACE)
2194: cssRule--;
2195: }
2196: }
1.281 quint 2197: saved = *cssRule;
2198: *cssRule = EOS;
2199: *url = TtaStrdup (base);
2200: *cssRule = saved;
2201: if (saved == '"' || saved == '\'')
1.327 vatton 2202: /* we need to skip the quote character and possible spaces */
2203: {
2204: cssRule++;
2205: cssRule = SkipBlanksAndComments (cssRule);
2206: }
1.281 quint 2207: else
1.327 vatton 2208: cssRule = ptr;
1.281 quint 2209: }
2210: cssRule++;
2211: return cssRule;
2212: }
2213:
2214: /*----------------------------------------------------------------------
1.302 quint 2215: ParseCSSImageCallback: Callback called asynchronously by
2216: FetchImage when a CSS image (background-image or list-style-image)
2217: has been fetched.
2218: ----------------------------------------------------------------------*/
2219: void ParseCSSImageCallback (Document doc, Element element, char *file,
1.327 vatton 2220: void *extra, ThotBool isnew)
1.302 quint 2221: {
2222: DisplayMode dispMode = DisplayImmediately;
2223: CSSImageCallbackPtr callblock;
2224: Element el;
2225: PSchema tsch;
1.401 vatton 2226: Document redisplaydoc;
2227: PInfoPtr pInfo = NULL;
1.302 quint 2228: CSSInfoPtr css;
2229: PresentationContext ctxt;
2230: PresentationValue image;
2231: PresentationValue value;
1.400 vatton 2232: ThotBool found;
1.302 quint 2233:
2234: callblock = (CSSImageCallbackPtr) extra;
2235: if (callblock == NULL)
2236: return;
2237:
1.400 vatton 2238: css = callblock->css;
1.302 quint 2239: el = callblock->el;
2240: tsch = callblock->tsch;
2241: ctxt = callblock->ctxt;
1.401 vatton 2242: redisplaydoc = ctxt->doc;
1.302 quint 2243: if (doc == 0 && !isnew)
2244: /* apply to the current document only */
1.401 vatton 2245: doc = redisplaydoc;
1.302 quint 2246: if (doc)
1.401 vatton 2247: redisplaydoc = doc;
1.302 quint 2248: else
2249: {
2250: /* check if the CSS still exists */
2251: css = CSSList;
2252: while (css && css != callblock->css)
1.327 vatton 2253: css = css->NextCSS;
1.302 quint 2254: if (css == NULL)
1.400 vatton 2255: // the presentation schema doesn't exist anymore
1.327 vatton 2256: tsch = NULL;
1.302 quint 2257: }
1.400 vatton 2258:
1.401 vatton 2259: if (tsch && css && ctxt && redisplaydoc)
1.400 vatton 2260: {
2261: // check if the presentation schema is still there
1.401 vatton 2262: pInfo = css->infos[redisplaydoc];
2263: if (pInfo == NULL && DocumentURLs[redisplaydoc] == NULL)
2264: {
2265: // the redisplaydoc was probably an object
2266: while (redisplaydoc > 0 && pInfo == 0)
2267: pInfo = css->infos[--redisplaydoc];
2268: if (redisplaydoc)
2269: ctxt->doc = redisplaydoc;
2270: }
2271:
1.400 vatton 2272: found = FALSE;
2273: while (!found && pInfo)
2274: {
2275: found = (pInfo->PiSchemas && tsch == pInfo->PiSchemas->PiPSchema);
2276: pInfo = pInfo->PiNext;
2277: }
2278: if (!found)
2279: tsch = NULL;
2280: }
2281:
1.302 quint 2282: if (el || tsch)
2283: {
2284: /* Ok the image was fetched */
2285: image.typed_data.unit = UNIT_REL;
2286: image.typed_data.real = FALSE;
2287: image.pointer = file;
2288: TtaSetStylePresentation (callblock->ruleType, el, tsch, ctxt, image);
2289:
2290: if (callblock->ruleType == PRBackgroundPicture)
1.327 vatton 2291: /* enforce the showbox */
2292: {
2293: value.typed_data.value = 1;
2294: value.typed_data.unit = UNIT_REL;
2295: value.typed_data.real = FALSE;
2296: TtaSetStylePresentation (PRShowBox, el, tsch, ctxt, value);
2297: }
1.302 quint 2298: /* check if the context can be freed */
2299: ctxt->uses -= 1;
2300: if (ctxt->uses == 0)
1.327 vatton 2301: /* no other image loading */
2302: TtaFreeMemory (ctxt);
1.302 quint 2303: }
2304:
2305: TtaFreeMemory (callblock);
1.330 cvs 2306: if (css)
2307: RedisplayImages--;
1.401 vatton 2308: if (redisplaydoc &&
2309: /* check if all background images are now loaded */
2310: (css == NULL || (pInfo && Style_parsing == 0 && RedisplayImages == 0)))
2311: {
2312: /* don't manage a document used by make book */
2313: if (DocumentMeta[redisplaydoc] == NULL ||
2314: DocumentMeta[redisplaydoc]->method != CE_MAKEBOOK)
1.327 vatton 2315: {
2316: /* Change the Display Mode to take into account the new
2317: presentation */
1.401 vatton 2318: dispMode = TtaGetDisplayMode (redisplaydoc);
1.313 vatton 2319: /* force the redisplay of this box */
1.435 vatton 2320: if (dispMode == DisplayImmediately)
2321: TtaSetDisplayMode (redisplaydoc, NoComputedDisplay);
1.401 vatton 2322: TtaSetDisplayMode (redisplaydoc, dispMode);
1.327 vatton 2323: }
1.330 cvs 2324: RedisplayBGImage = FALSE;
1.302 quint 2325: }
1.310 vatton 2326: else
1.328 vatton 2327: RedisplayBGImage = TRUE;
1.302 quint 2328: }
2329:
2330: /*----------------------------------------------------------------------
2331: SetCSSImage fetch the image referred by a background-image or a
2332: list-style-image property.
2333: ----------------------------------------------------------------------*/
2334: static char *SetCSSImage (Element element, PSchema tsch,
1.327 vatton 2335: PresentationContext ctxt, char *cssRule,
2336: CSSInfoPtr css, unsigned int ruleType)
1.302 quint 2337: {
2338: CSSImageCallbackPtr callblock;
2339: Element el;
1.304 cvs 2340: PresentationValue image;
1.366 vatton 2341: char *url, *ptr;
1.302 quint 2342: char *bg_image;
2343: char tempname[MAX_LENGTH];
2344: char imgname[MAX_LENGTH];
2345:
2346: if (element)
2347: el = element;
2348: else
2349: /* default element for FetchImage */
2350: el = TtaGetMainRoot (ctxt->doc);
2351: url = NULL;
1.370 vatton 2352: image.typed_data.real = FALSE;
1.302 quint 2353: cssRule = ParseCSSUrl (cssRule, &url);
1.414 vatton 2354: if (strlen (url) > MAX_LENGTH / 4)
2355: url[MAX_LENGTH / 4] = EOS;
1.366 vatton 2356: ptr = cssRule;
1.302 quint 2357: if (ctxt->destroy)
2358: {
2359: /* remove the background image PRule */
2360: image.pointer = NULL;
1.366 vatton 2361: TtaSetStylePresentation (ruleType, element, tsch, ctxt, image);
1.302 quint 2362: }
1.366 vatton 2363: else if (url)
1.302 quint 2364: {
1.366 vatton 2365: if (css && css->url)
2366: /* the image concerns a CSS file */
2367: NormalizeURL (url, 0, tempname, imgname, css->url);
2368: else
2369: /* the image concerns a style element */
2370: NormalizeURL (url, ctxt->doc, tempname, imgname, NULL);
2371: if (DoDialog)
2372: {
2373: if (ruleType == PRBackgroundPicture)
2374: DisplayStyleValue ("background-image", tempname, &tempname[MAX_LENGTH-1]);
2375: else if (ruleType == PRListStyleImage)
2376: DisplayStyleValue ("list-style-image", tempname, &tempname[MAX_LENGTH-1]);
2377: else if (ruleType == PRContentURL)
2378: DisplayStyleValue ("", ptr, cssRule);
2379: }
2380: else if (DoApply)
2381: {
2382: bg_image = TtaGetEnvString ("ENABLE_BG_IMAGES");
2383: if (bg_image == NULL || !strcasecmp (bg_image, "yes"))
2384: /* background images are enabled */
2385: {
2386: callblock = (CSSImageCallbackPtr) TtaGetMemory (sizeof (CSSImageCallbackBlock));
2387: if (callblock)
2388: {
2389: callblock->el = element;
2390: callblock->tsch = tsch;
2391: callblock->css = css;
2392: callblock->ctxt = ctxt;
2393: callblock->ruleType = ruleType;
2394: /* new use of the context */
2395: ctxt->uses += 1;
2396: /* check if the image url is related to an external CSS */
2397: if (css)
2398: {
2399: /* fetch and display background image of element */
2400: if (FetchImage (0, el, tempname, AMAYA_LOAD_IMAGE,
2401: ParseCSSImageCallback, callblock))
2402: RedisplayImages++;
2403: }
1.327 vatton 2404: else
1.366 vatton 2405: FetchImage (ctxt->doc, el, url, AMAYA_LOAD_IMAGE,
2406: ParseCSSImageCallback, callblock);
1.327 vatton 2407: }
2408: }
2409: }
1.366 vatton 2410: TtaFreeMemory (url);
1.302 quint 2411: }
2412: return (cssRule);
2413: }
2414:
2415: /*----------------------------------------------------------------------
1.327 vatton 2416: ParseACSSListStyleImage: parse a CSS list-style-image
2417: attribute string.
1.1 cvs 2418: ----------------------------------------------------------------------*/
1.318 vatton 2419: static char *ParseACSSListStyleImage (Element element, PSchema tsch,
1.327 vatton 2420: PresentationContext ctxt,
2421: char *cssRule, CSSInfoPtr css,
2422: ThotBool isHTML)
1.1 cvs 2423: {
1.288 vatton 2424: char *url;
1.366 vatton 2425: char *start_value;
1.293 quint 2426: PresentationValue pval;
1.281 quint 2427:
1.293 quint 2428: pval.typed_data.unit = UNIT_REL;
2429: pval.typed_data.real = FALSE;
1.281 quint 2430: url = NULL;
2431: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 2432: start_value = cssRule;
1.281 quint 2433: if (!strncasecmp (cssRule, "none", 4))
2434: {
2435: cssRule += 4;
1.302 quint 2436: pval.typed_data.value = 0;
1.366 vatton 2437: if (DoDialog)
2438: DisplayStyleValue ("list-style-image", start_value, cssRule);
2439: else if (DoApply)
1.327 vatton 2440: TtaSetStylePresentation (PRListStyleImage, element, tsch, ctxt, pval);
1.281 quint 2441: }
2442: else if (!strncasecmp (cssRule, "url", 3))
2443: {
2444: cssRule += 3;
1.302 quint 2445: cssRule = SetCSSImage (element, tsch, ctxt, cssRule, css,
1.327 vatton 2446: PRListStyleImage);
1.281 quint 2447: }
2448: else if (!strncasecmp (cssRule, "inherit", 7))
1.288 vatton 2449: {
2450: cssRule += 7;
1.293 quint 2451: pval.typed_data.unit = VALUE_INHERIT;
1.366 vatton 2452: if (DoDialog)
2453: DisplayStyleValue ("list-style-image", start_value, cssRule);
2454: else if (DoApply)
1.327 vatton 2455: TtaSetStylePresentation (PRListStyleImage, element, tsch, ctxt, pval);
2456: }
1.281 quint 2457: else
1.295 vatton 2458: cssRule = SkipValue ("Invalid list-style-image value", cssRule);
1.1 cvs 2459: return (cssRule);
2460: }
2461:
2462: /*----------------------------------------------------------------------
1.327 vatton 2463: ParseCSSListStyleImage: parse a CSS list-style-image
2464: attribute string.
1.318 vatton 2465: ----------------------------------------------------------------------*/
2466: static char *ParseCSSListStyleImage (Element element, PSchema tsch,
1.327 vatton 2467: PresentationContext ctxt,
2468: char *cssRule, CSSInfoPtr css,
2469: ThotBool isHTML)
1.318 vatton 2470: {
2471: char *ptr = cssRule;
2472: cssRule = ParseACSSListStyleImage (element, tsch, ctxt, cssRule, css,
1.327 vatton 2473: isHTML);
1.318 vatton 2474: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid list-style-image value");
2475: return cssRule;
2476: }
2477:
2478: /*----------------------------------------------------------------------
1.327 vatton 2479: ParseACSSListStylePosition: parse a CSS list-style-position
2480: attribute string.
1.1 cvs 2481: ----------------------------------------------------------------------*/
1.318 vatton 2482: static char *ParseACSSListStylePosition (Element element, PSchema tsch,
1.327 vatton 2483: PresentationContext context,
2484: char *cssRule, CSSInfoPtr css,
2485: ThotBool isHTML)
1.1 cvs 2486: {
1.281 quint 2487: PresentationValue pval;
1.366 vatton 2488: char *start_value;
1.281 quint 2489:
2490: pval.typed_data.unit = UNIT_REL;
2491: pval.typed_data.real = FALSE;
2492: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 2493: start_value = cssRule;
1.281 quint 2494: if (!strncasecmp (cssRule, "inside", 6))
1.288 vatton 2495: {
2496: pval.typed_data.value = Inside;
2497: cssRule += 6;
2498: }
1.281 quint 2499: else if (!strncasecmp (cssRule, "outside", 7))
1.288 vatton 2500: {
2501: pval.typed_data.value = Outside;
2502: cssRule += 7;
2503: }
1.293 quint 2504: else if (!strncasecmp (cssRule, "inherit", 7))
2505: {
2506: pval.typed_data.unit = VALUE_INHERIT;
2507: cssRule += 7;
2508: }
1.281 quint 2509: else
2510: {
1.293 quint 2511: cssRule = SkipValue ("Invalid list-style-position value", cssRule);
1.281 quint 2512: return (cssRule);
2513: }
1.293 quint 2514:
1.366 vatton 2515: if (DoDialog)
2516: DisplayStyleValue ("list-style-position", start_value, cssRule);
2517: else if (DoApply)
1.295 vatton 2518: TtaSetStylePresentation (PRListStylePosition, element, tsch, context, pval);
1.327 vatton 2519: return (cssRule);
1.318 vatton 2520: }
2521:
2522: /*----------------------------------------------------------------------
1.327 vatton 2523: ParseCSSListStylePosition: parse a CSS list-style-position
2524: attribute string.
1.318 vatton 2525: ----------------------------------------------------------------------*/
2526: static char *ParseCSSListStylePosition (Element element, PSchema tsch,
1.327 vatton 2527: PresentationContext context,
2528: char *cssRule, CSSInfoPtr css,
2529: ThotBool isHTML)
1.318 vatton 2530: {
2531: char *ptr = cssRule;
2532: cssRule = ParseACSSListStylePosition (element, tsch, context, cssRule, css,
1.327 vatton 2533: isHTML);
1.288 vatton 2534: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid list-style-position value");
1.318 vatton 2535: return cssRule;
1.1 cvs 2536: }
2537:
2538: /*----------------------------------------------------------------------
1.327 vatton 2539: ParseCSSListStyle: parse a CSS list-style value string.
1.1 cvs 2540: ----------------------------------------------------------------------*/
1.79 cvs 2541: static char *ParseCSSListStyle (Element element, PSchema tsch,
1.327 vatton 2542: PresentationContext ctxt, char *cssRule,
2543: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2544: {
1.318 vatton 2545: char *ptr = cssRule;
2546: int skippedNL;
1.281 quint 2547:
2548: cssRule = SkipBlanksAndComments (cssRule);
1.301 vatton 2549: while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.281 quint 2550: {
1.316 quint 2551: skippedNL = NewLineSkipped;
1.281 quint 2552: /* perhaps a list-style-image */
2553: if (!strncasecmp (cssRule, "url", 3))
1.327 vatton 2554: cssRule = ParseACSSListStyleImage (element, tsch, ctxt, cssRule, css,
2555: isHTML);
1.281 quint 2556: /* perhaps a list-style-position */
2557: else if (!strncasecmp (cssRule, "inside", 6) ||
2558: !strncasecmp (cssRule, "outside", 7))
1.327 vatton 2559: cssRule = ParseACSSListStylePosition (element, tsch, ctxt, cssRule,
2560: css, isHTML);
1.281 quint 2561: /* perhaps a list-style-type */
2562: else if (!strncasecmp (cssRule, "disc", 4) ||
1.327 vatton 2563: !strncasecmp (cssRule, "circle", 6) ||
2564: !strncasecmp (cssRule, "square", 6) ||
2565: !strncasecmp (cssRule, "decimal", 7) ||
2566: !strncasecmp (cssRule, "decimal-leading-zero", 20) ||
2567: !strncasecmp (cssRule, "lower-roman", 11) ||
2568: !strncasecmp (cssRule, "upper-roman", 11) ||
2569: !strncasecmp (cssRule, "lower-greek", 11) ||
2570: !strncasecmp (cssRule, "lower-latin", 11) ||
2571: !strncasecmp (cssRule, "lower-alpha", 11) ||
2572: !strncasecmp (cssRule, "upper-latin", 11) ||
2573: !strncasecmp (cssRule, "upper-alpha", 11) ||
2574: !strncasecmp (cssRule, "armenian", 8) ||
2575: !strncasecmp (cssRule, "georgian", 8) ||
2576: !strncasecmp (cssRule, "none", 4) ||
2577: !strncasecmp (cssRule, "inherit", 7))
2578: cssRule = ParseACSSListStyleType (element, tsch, ctxt, cssRule, css,
2579: isHTML);
1.281 quint 2580: else
1.327 vatton 2581: {
2582: NewLineSkipped = skippedNL;
2583: /* rule not found */
2584: cssRule = SkipProperty (cssRule, FALSE);
2585: }
1.281 quint 2586: cssRule = SkipBlanksAndComments (cssRule);
2587: }
1.318 vatton 2588: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid list-style value");
1.1 cvs 2589: return (cssRule);
2590: }
2591:
2592: /*----------------------------------------------------------------------
1.327 vatton 2593: ParseCSSTextAlign: parse a CSS text-align
2594: attribute string.
1.1 cvs 2595: ----------------------------------------------------------------------*/
1.79 cvs 2596: static char *ParseCSSTextAlign (Element element, PSchema tsch,
1.327 vatton 2597: PresentationContext context, char *cssRule,
2598: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2599: {
1.366 vatton 2600: char *ptr;
1.327 vatton 2601: PresentationValue align;
2602:
2603: align.typed_data.value = 0;
2604: align.typed_data.unit = UNIT_REL;
2605: align.typed_data.real = FALSE;
2606:
2607: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 2608: ptr = cssRule;
1.327 vatton 2609: if (!strncasecmp (cssRule, "left", 4))
2610: {
2611: align.typed_data.value = AdjustLeft;
2612: cssRule += 4;
2613: }
2614: else if (!strncasecmp (cssRule, "right", 5))
2615: {
2616: align.typed_data.value = AdjustRight;
2617: cssRule += 5;
2618: }
2619: else if (!strncasecmp (cssRule, "center", 6))
2620: {
2621: align.typed_data.value = Centered;
2622: cssRule += 6;
2623: }
2624: else if (!strncasecmp (cssRule, "justify", 7))
2625: {
2626: align.typed_data.value = Justify;
2627: cssRule += 7;
2628: }
2629: else
2630: {
2631: cssRule = SkipValue ("Invalid text-align value", cssRule);
2632: return (cssRule);
2633: }
1.1 cvs 2634:
1.327 vatton 2635: /*
2636: * install the new presentation.
2637: */
1.366 vatton 2638: if (align.typed_data.value)
2639: {
2640: if (DoDialog)
2641: DisplayStyleValue ("text-align", ptr, cssRule);
2642: else if (DoApply)
2643: TtaSetStylePresentation (PRAdjust, element, tsch, context, align);
2644: }
1.327 vatton 2645: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid text-align value");
2646: return (cssRule);
1.1 cvs 2647: }
2648:
2649: /*----------------------------------------------------------------------
1.243 quint 2650: ParseCSSTextAnchor: parse a CSS text-anchor property (SVG property)
2651: We use the Thot Adjust PRule to represent the text-anchor property
2652: for CSS 1.0, as Adjust is not used otherwise in this context.
2653: ----------------------------------------------------------------------*/
2654: static char *ParseCSSTextAnchor (Element element, PSchema tsch,
1.327 vatton 2655: PresentationContext context, char *cssRule,
2656: CSSInfoPtr css, ThotBool isHTML)
1.243 quint 2657: {
1.327 vatton 2658: PresentationValue align;
1.366 vatton 2659: char *ptr;
1.327 vatton 2660:
2661: align.typed_data.value = 0;
2662: align.typed_data.unit = UNIT_REL;
2663: align.typed_data.real = FALSE;
1.243 quint 2664:
1.327 vatton 2665: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 2666: ptr = cssRule;
1.327 vatton 2667: if (!strncasecmp (cssRule, "start", 5))
2668: {
2669: align.typed_data.value = AdjustLeft;
2670: cssRule += 5;
2671: }
2672: else if (!strncasecmp (cssRule, "middle", 6))
2673: {
2674: align.typed_data.value = Centered;
2675: cssRule += 6;
2676: }
2677: else if (!strncasecmp (cssRule, "end", 3))
2678: {
2679: align.typed_data.value = AdjustRight;
2680: cssRule += 3;
2681: }
2682: else if (!strncasecmp (cssRule, "inherit", 7))
2683: {
2684: align.typed_data.unit = VALUE_INHERIT;
2685: cssRule += 7;
2686: }
2687: else
2688: {
2689: cssRule = SkipValue ("Invalid text-anchor value", cssRule);
1.295 vatton 2690: return (cssRule);
1.327 vatton 2691: }
1.243 quint 2692:
1.327 vatton 2693: /*
2694: * install the new presentation.
2695: */
1.366 vatton 2696: if (align.typed_data.value || align.typed_data.unit == VALUE_INHERIT)
2697: {
2698: if (DoDialog)
2699: DisplayStyleValue ("text-anchor", ptr, cssRule);
2700: else if (DoApply)
2701: TtaSetStylePresentation (PRAdjust, element, tsch, context, align);
2702: }
1.327 vatton 2703: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid text-anchor value");
2704: return (cssRule);
1.243 quint 2705: }
2706:
2707: /*----------------------------------------------------------------------
1.327 vatton 2708: ParseCSSDirection: parse a CSS direction property
1.112 quint 2709: ----------------------------------------------------------------------*/
2710: static char *ParseCSSDirection (Element element, PSchema tsch,
1.327 vatton 2711: PresentationContext context, char *cssRule,
2712: CSSInfoPtr css, ThotBool isHTML)
1.112 quint 2713: {
1.327 vatton 2714: PresentationValue direction;
1.366 vatton 2715: char *ptr;
1.327 vatton 2716:
2717: direction.typed_data.value = 0;
2718: direction.typed_data.unit = UNIT_REL;
2719: direction.typed_data.real = FALSE;
2720:
2721: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 2722: ptr = cssRule;
1.327 vatton 2723: if (!strncasecmp (cssRule, "ltr", 3))
2724: {
2725: direction.typed_data.value = LeftToRight;
2726: cssRule += 3;
2727: }
2728: else if (!strncasecmp (cssRule, "rtl", 3))
2729: {
2730: direction.typed_data.value = RightToLeft;
2731: cssRule += 3;
2732: }
2733: else if (!strncasecmp (cssRule, "inherit", 7))
2734: {
2735: direction.typed_data.unit = VALUE_INHERIT;
2736: cssRule += 7;
2737: }
2738: else
2739: {
2740: cssRule = SkipValue ("Invalid direction value", cssRule);
2741: return (cssRule);
2742: }
1.112 quint 2743:
1.327 vatton 2744: /*
2745: * install the new presentation.
2746: */
1.366 vatton 2747: if (direction.typed_data.value || direction.typed_data.unit == VALUE_INHERIT)
2748: {
2749: if (DoDialog)
2750: DisplayStyleValue ("direction", ptr, cssRule);
2751: else if (DoApply)
2752: TtaSetStylePresentation (PRDirection, element, tsch, context, direction);
2753: }
1.327 vatton 2754: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid direction value");
2755: return (cssRule);
1.112 quint 2756: }
2757:
2758: /*----------------------------------------------------------------------
1.327 vatton 2759: ParseCSSUnicodeBidi: parse a CSS unicode-bidi property
1.113 quint 2760: ----------------------------------------------------------------------*/
2761: static char *ParseCSSUnicodeBidi (Element element, PSchema tsch,
1.327 vatton 2762: PresentationContext context, char *cssRule,
2763: CSSInfoPtr css, ThotBool isHTML)
1.113 quint 2764: {
1.327 vatton 2765: PresentationValue bidi;
1.366 vatton 2766: char *ptr;
1.113 quint 2767:
1.327 vatton 2768: bidi.typed_data.value = 0;
2769: bidi.typed_data.unit = UNIT_REL;
2770: bidi.typed_data.real = FALSE;
2771:
2772: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 2773: ptr = cssRule;
1.327 vatton 2774: if (!strncasecmp (cssRule, "normal", 6))
2775: {
2776: bidi.typed_data.value = Normal;
2777: cssRule += 6;
2778: }
2779: else if (!strncasecmp (cssRule, "embed", 5))
2780: {
2781: bidi.typed_data.value = Embed;
2782: cssRule += 5;
2783: }
2784: else if (!strncasecmp (cssRule, "bidi-override", 13))
2785: {
2786: bidi.typed_data.value = Override;
2787: cssRule += 13;
2788: }
2789: else if (!strncasecmp (cssRule, "inherit", 7))
2790: {
2791: bidi.typed_data.unit = VALUE_INHERIT;
2792: cssRule += 7;
2793: }
2794: else
2795: {
2796: cssRule = SkipValue ("Invalid unicode-bidi value", cssRule);
1.295 vatton 2797: return (cssRule);
1.327 vatton 2798: }
1.113 quint 2799:
1.327 vatton 2800: /*
2801: * install the new presentation.
2802: */
1.366 vatton 2803: if (bidi.typed_data.value || bidi.typed_data.unit == VALUE_INHERIT)
2804: {
2805: if (DoDialog)
2806: DisplayStyleValue ("unicode-bidi", ptr, cssRule);
2807: else if (DoApply)
2808: TtaSetStylePresentation (PRUnicodeBidi, element, tsch, context, bidi);
2809: }
1.327 vatton 2810: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid unicode-bidi value");
2811: return (cssRule);
1.113 quint 2812: }
2813:
2814: /*----------------------------------------------------------------------
1.327 vatton 2815: ParseCSSTextIndent: parse a CSS text-indent
2816: attribute string.
1.1 cvs 2817: ----------------------------------------------------------------------*/
1.79 cvs 2818: static char *ParseCSSTextIndent (Element element, PSchema tsch,
1.327 vatton 2819: PresentationContext context, char *cssRule,
2820: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2821: {
1.327 vatton 2822: PresentationValue pval;
2823: char *ptr;
1.1 cvs 2824:
1.370 vatton 2825: pval.typed_data.real = FALSE;
1.327 vatton 2826: cssRule = SkipBlanksAndComments (cssRule);
2827: ptr = cssRule;
2828: cssRule = ParseCSSUnit (cssRule, &pval);
1.387 quint 2829: if (pval.typed_data.value == 0 &&
2830: pval.typed_data.unit != UNIT_INVALID)
1.327 vatton 2831: pval.typed_data.unit = UNIT_PX;
2832: else if (pval.typed_data.unit == UNIT_INVALID ||
2833: pval.typed_data.unit == UNIT_BOX)
2834: {
2835: CSSParseError ("Invalid text-indent value", ptr, cssRule);
2836: return (cssRule);
2837: }
2838: /* install the attribute */
1.366 vatton 2839: if (DoDialog)
2840: DisplayStyleValue ("text-indent", ptr, cssRule);
2841: else if (DoApply)
1.327 vatton 2842: TtaSetStylePresentation (PRIndent, element, tsch, context, pval);
2843: return (cssRule);
1.1 cvs 2844: }
2845:
2846: /*----------------------------------------------------------------------
1.327 vatton 2847: ParseCSSTextTransform: parse a CSS text-transform
2848: attribute string.
1.1 cvs 2849: ----------------------------------------------------------------------*/
1.79 cvs 2850: static char *ParseCSSTextTransform (Element element, PSchema tsch,
1.327 vatton 2851: PresentationContext context, char *cssRule,
2852: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2853: {
1.366 vatton 2854: char *ptr;
2855:
2856: cssRule = SkipBlanksAndComments (cssRule);
2857: ptr = cssRule;
1.168 vatton 2858: cssRule = SkipValue (NULL, cssRule);
1.366 vatton 2859: if (DoDialog)
2860: DisplayStyleValue ("text-transform", ptr, cssRule);
1.1 cvs 2861: return (cssRule);
2862: }
2863:
2864: /*----------------------------------------------------------------------
1.327 vatton 2865: ParseCSSVerticalAlign: parse a CSS vertical-align
2866: attribute string.
1.1 cvs 2867: ----------------------------------------------------------------------*/
1.79 cvs 2868: static char *ParseCSSVerticalAlign (Element element, PSchema tsch,
1.327 vatton 2869: PresentationContext context, char *cssRule,
2870: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2871: {
1.273 quint 2872: char *ptr;
2873: PresentationValue pval;
2874:
2875: pval.typed_data.unit = UNIT_REL;
2876: pval.typed_data.real = FALSE;
2877: cssRule = SkipBlanksAndComments (cssRule);
1.288 vatton 2878: ptr = cssRule;
1.273 quint 2879: if (!strncasecmp (cssRule, "baseline", 8))
2880: {
2881: pval.typed_data.value = 0;
1.288 vatton 2882: cssRule += 8;
1.273 quint 2883: }
2884: else if (!strncasecmp (cssRule, "sub", 3))
2885: {
2886: pval.typed_data.value = -3;
1.288 vatton 2887: cssRule += 3;
1.273 quint 2888: }
2889: else if (!strncasecmp (cssRule, "super", 5))
2890: {
2891: pval.typed_data.value = 4;
1.288 vatton 2892: cssRule += 5;
1.273 quint 2893: }
2894: else if (!strncasecmp (cssRule, "top", 3))
2895: {
1.275 quint 2896: pval.typed_data.unit = UNIT_INVALID; /* Not supported yet */
1.274 vatton 2897: pval.typed_data.value = 0;
1.288 vatton 2898: cssRule += 3;
1.273 quint 2899: }
2900: else if (!strncasecmp (cssRule, "text-top", 8))
2901: {
1.275 quint 2902: pval.typed_data.unit = UNIT_INVALID; /* Not supported yet */
1.274 vatton 2903: pval.typed_data.value = 0;
1.288 vatton 2904: cssRule += 8;
1.273 quint 2905: }
2906: else if (!strncasecmp (cssRule, "middle", 6))
2907: {
1.275 quint 2908: pval.typed_data.unit = UNIT_INVALID; /* Not supported yet */
1.274 vatton 2909: pval.typed_data.value = 0;
1.288 vatton 2910: cssRule += 6;
1.273 quint 2911: }
2912: else if (!strncasecmp (cssRule, "bottom", 6))
2913: {
1.275 quint 2914: pval.typed_data.unit = UNIT_INVALID; /* Not supported yet */
1.274 vatton 2915: pval.typed_data.value = 0;
1.288 vatton 2916: cssRule += 6;
1.273 quint 2917: }
2918: else if (!strncasecmp (cssRule, "text-bottom", 11))
2919: {
1.275 quint 2920: pval.typed_data.unit = UNIT_INVALID; /* Not supported yet */
1.274 vatton 2921: pval.typed_data.value = 0;
1.288 vatton 2922: cssRule += 11;
1.273 quint 2923: }
2924: else if (!strncasecmp (cssRule, "inherit", 7))
2925: {
1.293 quint 2926: pval.typed_data.unit = VALUE_INHERIT;
1.274 vatton 2927: pval.typed_data.value = 0;
1.288 vatton 2928: cssRule +=7;
1.273 quint 2929: }
2930: else
2931: {
2932: /* parse <percentage> or <length> */
2933: cssRule = ParseCSSUnit (cssRule, &pval);
2934: if (pval.typed_data.unit == UNIT_INVALID)
1.327 vatton 2935: {
2936: pval.typed_data.value = 0;
2937: CSSParseError ("Invalid vertical-align value", ptr, cssRule);
2938: return (cssRule);
2939: }
1.273 quint 2940: else if (pval.typed_data.value == 0)
1.327 vatton 2941: pval.typed_data.unit = UNIT_PX;
1.273 quint 2942: else if (pval.typed_data.unit == UNIT_BOX)
1.327 vatton 2943: pval.typed_data.unit = UNIT_EM;
1.273 quint 2944: else if (pval.typed_data.unit == UNIT_PERCENT)
1.327 vatton 2945: /* it's a percentage */
2946: {
2947: /* convert it into a relative size */
2948: pval.typed_data.unit = UNIT_REL;
2949: pval.typed_data.value /= 10;
2950: }
1.273 quint 2951: }
1.295 vatton 2952:
1.366 vatton 2953: if (pval.typed_data.unit != UNIT_INVALID)
2954: {
2955: if (DoDialog)
2956: DisplayStyleValue ("vertical-align", ptr, cssRule);
2957: else if (DoApply)
2958: TtaSetStylePresentation (PRHorizRef, element, tsch, context, pval);
2959: }
1.288 vatton 2960: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid vertical-align value");
1.1 cvs 2961: return (cssRule);
2962: }
2963:
2964: /*----------------------------------------------------------------------
1.327 vatton 2965: ParseCSSWhiteSpace: parse a CSS white-space
2966: attribute string.
1.1 cvs 2967: ----------------------------------------------------------------------*/
1.79 cvs 2968: static char *ParseCSSWhiteSpace (Element element, PSchema tsch,
1.327 vatton 2969: PresentationContext context, char *cssRule,
2970: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2971: {
1.366 vatton 2972: char *ptr;
1.288 vatton 2973:
1.327 vatton 2974: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 2975: ptr = cssRule;
1.327 vatton 2976: if (!strncasecmp (cssRule, "normal", 6))
2977: cssRule += 6;
1.432 vatton 2978: else if (!strncasecmp (cssRule, "pre-wrap", 8))
2979: cssRule += 8;
2980: else if (!strncasecmp (cssRule, "pre-line", 8))
2981: cssRule += 8;
1.327 vatton 2982: else if (!strncasecmp (cssRule, "pre", 3))
2983: cssRule += 3;
2984: else if (!strncasecmp (cssRule, "nowrap", 6))
2985: cssRule += 6;
2986: else if (!strncasecmp (cssRule, "inherit", 7))
2987: cssRule += 7;
2988: else
2989: cssRule = SkipValue ("Invalid white-space value", cssRule);
2990:
1.387 quint 2991: if (ptr != cssRule && DoDialog)
1.366 vatton 2992: DisplayStyleValue ("white-space", ptr, cssRule);
1.327 vatton 2993: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid white-space value");
2994: return (cssRule);
1.1 cvs 2995: }
2996:
2997: /*----------------------------------------------------------------------
1.327 vatton 2998: ParseCSSWordSpacing: parse a CSS word-spacing
2999: attribute string.
1.1 cvs 3000: ----------------------------------------------------------------------*/
1.79 cvs 3001: static char *ParseCSSWordSpacing (Element element, PSchema tsch,
1.327 vatton 3002: PresentationContext context, char *cssRule,
3003: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 3004: {
1.366 vatton 3005: char *ptr;
3006:
3007: cssRule = SkipBlanksAndComments (cssRule);
3008: ptr = cssRule;
1.168 vatton 3009: cssRule = SkipValue (NULL, cssRule);
1.366 vatton 3010: if (DoDialog)
3011: DisplayStyleValue ("word-spacing", ptr, cssRule);
1.1 cvs 3012: return (cssRule);
3013: }
3014:
3015: /*----------------------------------------------------------------------
1.327 vatton 3016: ParseCSSLineHeight: parse a CSS line-height property
1.25 cvs 3017: ----------------------------------------------------------------------*/
1.162 quint 3018: static char *ParseCSSLineHeight (Element element, PSchema tsch,
1.327 vatton 3019: PresentationContext context, char *cssRule,
3020: CSSInfoPtr css, ThotBool isHTML)
1.25 cvs 3021: {
1.162 quint 3022: PresentationValue pval;
1.288 vatton 3023: char *ptr;
1.162 quint 3024:
1.370 vatton 3025: pval.typed_data.real = FALSE;
1.366 vatton 3026: cssRule = SkipBlanksAndComments (cssRule);
1.162 quint 3027: ptr = cssRule;
3028: if (!strncasecmp (cssRule, "normal", 6))
3029: {
1.184 vatton 3030: pval.typed_data.unit = UNIT_REL;
1.162 quint 3031: pval.typed_data.real = TRUE;
3032: pval.typed_data.value = 1100;
1.288 vatton 3033: cssRule += 6;
1.162 quint 3034: }
3035: else if (!strncasecmp (cssRule, "inherit", 7))
3036: {
1.293 quint 3037: pval.typed_data.unit = VALUE_INHERIT;
1.354 quint 3038: cssRule += 7;
1.162 quint 3039: }
3040: else
3041: cssRule = ParseCSSUnit (cssRule, &pval);
1.25 cvs 3042:
1.184 vatton 3043: if (pval.typed_data.unit == UNIT_INVALID)
1.168 vatton 3044: CSSParseError ("Invalid line-height value", ptr, cssRule);
1.387 quint 3045: else if (DoDialog)
1.366 vatton 3046: DisplayStyleValue ("line-height", ptr, cssRule);
1.162 quint 3047: else if (DoApply)
3048: {
1.166 vatton 3049: /* install the new presentation */
1.184 vatton 3050: if (pval.typed_data.unit == UNIT_BOX)
1.327 vatton 3051: pval.typed_data.unit = UNIT_EM;
1.162 quint 3052: TtaSetStylePresentation (PRLineSpacing, element, tsch, context, pval);
3053: }
3054: return (cssRule);
1.25 cvs 3055: }
3056:
3057: /*----------------------------------------------------------------------
1.327 vatton 3058: ParseCSSFontSizeAdjust: parse a CSS fontsizeAdjust attr string
3059: we expect the input string describing the attribute to be
3060: xx-small, x-small, small, medium, large, x-large, xx-large
3061: or an absolute size, or an imcrement relative to the parent
1.1 cvs 3062: ----------------------------------------------------------------------*/
1.219 vatton 3063: static char *ParseCSSFontSizeAdjust (Element element, PSchema tsch,
1.327 vatton 3064: PresentationContext context, char *cssRule,
3065: CSSInfoPtr css, ThotBool isHTML)
1.219 vatton 3066: {
1.366 vatton 3067:
3068: cssRule = SkipBlanksAndComments (cssRule);
1.234 vatton 3069: cssRule = SkipProperty (cssRule, FALSE);
1.222 quint 3070: return (cssRule);
1.219 vatton 3071: }
3072:
3073: /*----------------------------------------------------------------------
1.327 vatton 3074: ParseACSSFontSize: parse a CSS font size attr string
3075: we expect the input string describing the attribute to be
3076: xx-small, x-small, small, medium, large, x-large, xx-large
3077: or an absolute size, or an imcrement relative to the parent.
3078: The parameter check is TRUE if the rule is just checked.
1.219 vatton 3079: ----------------------------------------------------------------------*/
1.270 vatton 3080: static char *ParseACSSFontSize (Element element, PSchema tsch,
1.327 vatton 3081: PresentationContext context, char *cssRule,
3082: CSSInfoPtr css, ThotBool isHTML, ThotBool check)
1.1 cvs 3083: {
1.327 vatton 3084: ElementType elType;
3085: PresentationValue pval;
1.369 quint 3086: char *ptr = NULL, *ptr1 = NULL, *ptr2 = NULL;
1.366 vatton 3087: char *start_value;
1.369 quint 3088: ThotBool real, error, linespace = FALSE;
1.327 vatton 3089:
1.369 quint 3090: error = FALSE;
1.327 vatton 3091: pval.typed_data.real = FALSE;
3092: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 3093: start_value = cssRule;
1.327 vatton 3094: /* look for a '/' within the current cssRule */
3095: ptr1 = strchr (cssRule, ';');
3096: ptr = strchr (cssRule, '/');
3097: if (ptr && (ptr1 == NULL || ptr < ptr1))
3098: {
3099: /* keep the line spacing rule */
3100: linespace = TRUE;
3101: ptr[0] = EOS;
3102: }
3103: else
3104: ptr = NULL;
3105: ptr1 = cssRule;
1.289 vatton 3106: /* relative size */
1.327 vatton 3107: if (!strncasecmp (cssRule, "larger", 6))
3108: {
3109: pval.typed_data.unit = UNIT_PERCENT;
3110: pval.typed_data.value = 130;
3111: cssRule += 6;
3112: }
3113: else if (!strncasecmp (cssRule, "smaller", 7))
3114: {
3115: pval.typed_data.unit = UNIT_PERCENT;
3116: pval.typed_data.value = 80;
3117: cssRule += 7;
3118: }
3119: /* absolute size */
3120: else if (!strncasecmp (cssRule, "xx-small", 8))
3121: {
3122: pval.typed_data.unit = UNIT_PT;
1.336 vatton 3123: pval.typed_data.value = 6;
1.327 vatton 3124: cssRule += 8;
3125: }
3126: else if (!strncasecmp (cssRule, "x-small", 7))
3127: {
3128: pval.typed_data.unit = UNIT_PT;
1.336 vatton 3129: pval.typed_data.value = 8;
1.327 vatton 3130: cssRule += 7;
3131: }
3132: else if (!strncasecmp (cssRule, "small", 5))
3133: {
3134: pval.typed_data.unit = UNIT_PT;
1.336 vatton 3135: pval.typed_data.value = 10;
1.327 vatton 3136: cssRule += 5;
3137: }
3138: else if (!strncasecmp (cssRule, "medium", 6))
3139: {
3140: pval.typed_data.unit = UNIT_PT;
3141: pval.typed_data.value = 12;
3142: cssRule += 6;
3143: }
3144: else if (!strncasecmp (cssRule, "large", 5))
3145: {
3146: pval.typed_data.unit = UNIT_PT;
3147: pval.typed_data.value = 13;
3148: cssRule += 5;
3149: }
3150: else if (!strncasecmp (cssRule, "x-large", 7))
3151: {
3152: pval.typed_data.unit = UNIT_PT;
3153: pval.typed_data.value = 14;
3154: cssRule += 7;
3155: }
3156: else if (!strncasecmp (cssRule, "xx-large", 8))
3157: {
3158: pval.typed_data.unit = UNIT_PT;
3159: pval.typed_data.value = 16;
3160: cssRule += 8;
3161: }
3162: else if (!strncasecmp (cssRule, "inherit", 7))
3163: {
3164: pval.typed_data.unit = VALUE_INHERIT;
3165: pval.typed_data.value = 0;
3166: cssRule += 7;
3167: }
3168: /* length or percentage */
3169: else if (!isdigit (*cssRule) && *cssRule != '.')
3170: {
3171: if (!check)
1.360 vatton 3172: cssRule = SkipValue ("Invalid font-size value", cssRule);
1.369 quint 3173: error = TRUE;
1.327 vatton 3174: }
3175: else
3176: {
3177: cssRule = ParseCSSUnit (cssRule, &pval);
3178: if (pval.typed_data.unit == UNIT_BOX)
3179: /* no unit specified */
3180: {
3181: elType = TtaGetElementType(element);
3182: if (!strcmp(TtaGetSSchemaName (elType.ElSSchema), "SVG"))
3183: /* we are working for an SVG element. No unit means pixels */
3184: pval.typed_data.unit = UNIT_PX;
3185: }
1.387 quint 3186: if (pval.typed_data.unit == UNIT_INVALID ||
3187: (pval.typed_data.value != 0 && pval.typed_data.unit == UNIT_BOX) ||
3188: pval.typed_data.value < 0)
1.327 vatton 3189: /* not a valid value */
1.369 quint 3190: {
3191: if (!check)
3192: {
3193: ptr2 = SkipWord (cssRule);
3194: CSSParseError ("Invalid font-size value", ptr1, ptr2);
3195: }
3196: error = TRUE;
3197: }
1.327 vatton 3198: else if (pval.typed_data.unit == UNIT_REL && pval.typed_data.value > 0)
3199: /* CSS relative sizes have to be higher than Thot ones */
3200: pval.typed_data.value += 1;
3201: else
3202: {
3203: real = pval.typed_data.real;
3204: if (pval.typed_data.unit == UNIT_EM)
3205: {
3206: if (real)
3207: {
3208: pval.typed_data.value /= 10;
3209: pval.typed_data.real = FALSE;
3210: real = FALSE;
3211: }
3212: else
3213: pval.typed_data.value *= 100;
3214: pval.typed_data.unit = UNIT_PERCENT;
3215: }
3216: else if (pval.typed_data.unit == UNIT_XHEIGHT)
3217: {
3218: /* a font size expressed in ex is converted into a percentage.
3219: For example, "3ex" is converted into "180%", supposing
3220: that 1ex is approximately 0.6 times the height of the
3221: current font */
3222: if (real)
3223: {
3224: pval.typed_data.value *= 6;
3225: pval.typed_data.value /= 100;
3226: pval.typed_data.real = FALSE;
3227: real = FALSE;
3228: }
3229: else
3230: pval.typed_data.value *= 60;
3231: pval.typed_data.unit = UNIT_PERCENT;
3232: }
3233: }
3234: }
3235:
3236: /* install the presentation style */
1.369 quint 3237: if (!check && !error)
1.366 vatton 3238: {
3239: if (DoDialog)
3240: DisplayStyleValue ("font-size", start_value, cssRule);
3241: else if (DoApply)
3242: TtaSetStylePresentation (PRSize, element, tsch, context, pval);
3243: }
1.327 vatton 3244: if (!check && ptr)
3245: cssRule = ParseCSSLineHeight (element, tsch, context, &ptr[1], css, isHTML);
3246: if (linespace)
3247: *ptr = '/';
3248:
3249: return (cssRule);
3250: }
3251:
3252: /*----------------------------------------------------------------------
3253: ParseCSSFontSize: parse a CSS font size attr string
3254: we expect the input string describing the attribute to be
3255: xx-small, x-small, small, medium, large, x-large, xx-large
3256: or an absolute size, or an imcrement relative to the parent
1.270 vatton 3257: ----------------------------------------------------------------------*/
3258: static char *ParseCSSFontSize (Element element, PSchema tsch,
1.327 vatton 3259: PresentationContext context, char *cssRule,
3260: CSSInfoPtr css, ThotBool isHTML)
1.270 vatton 3261: {
1.299 vatton 3262: char *ptr = cssRule;
1.295 vatton 3263: cssRule = ParseACSSFontSize (element, tsch, context, cssRule, css, isHTML, FALSE);
1.299 vatton 3264: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid font-size value");
1.295 vatton 3265: return cssRule;
1.270 vatton 3266: }
3267:
3268: /*----------------------------------------------------------------------
1.327 vatton 3269: ParseACSSFontFamily: parse a CSS font family string
3270: we expect the input string describing the attribute to be
3271: a common generic font style name
1.1 cvs 3272: ----------------------------------------------------------------------*/
1.268 vatton 3273: static char *ParseACSSFontFamily (Element element, PSchema tsch,
1.327 vatton 3274: PresentationContext context, char *cssRule,
3275: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 3276: {
3277: PresentationValue font;
1.252 vatton 3278: char quoteChar, *p;
1.1 cvs 3279:
3280: font.typed_data.value = 0;
1.184 vatton 3281: font.typed_data.unit = UNIT_REL;
1.1 cvs 3282: font.typed_data.real = FALSE;
1.82 cvs 3283: cssRule = SkipBlanksAndComments (cssRule);
3284: if (*cssRule == '"' || *cssRule == '\'')
1.327 vatton 3285: {
3286: quoteChar = *cssRule;
3287: cssRule++;
3288: }
1.1 cvs 3289: else
1.327 vatton 3290: quoteChar = EOS;
1.1 cvs 3291:
1.293 quint 3292: if (!strncasecmp (cssRule, "inherit", 7) && quoteChar == EOS)
3293: {
3294: font.typed_data.unit = VALUE_INHERIT;
3295: cssRule += 7;
3296: }
3297: else if (!strncasecmp (cssRule, "times", 5) &&
1.327 vatton 3298: (quoteChar == EOS || quoteChar == cssRule[5]))
1.86 cvs 3299: {
1.184 vatton 3300: font.typed_data.value = FontTimes;
1.86 cvs 3301: cssRule += 5;
3302: }
1.92 cvs 3303: else if (!strncasecmp (cssRule, "serif", 5) &&
1.327 vatton 3304: (quoteChar == EOS || quoteChar == cssRule[5]))
1.86 cvs 3305: {
1.184 vatton 3306: font.typed_data.value = FontTimes;
1.86 cvs 3307: cssRule += 5;
1.92 cvs 3308: if (quoteChar != EOS)
1.327 vatton 3309: cssRule++;
1.86 cvs 3310: }
1.92 cvs 3311: else if (!strncasecmp (cssRule, "helvetica", 9) &&
1.327 vatton 3312: (quoteChar == EOS || quoteChar == cssRule[9]))
1.86 cvs 3313: {
1.327 vatton 3314: font.typed_data.value = FontHelvetica;
1.86 cvs 3315: cssRule += 9;
1.92 cvs 3316: if (quoteChar != EOS)
1.327 vatton 3317: cssRule++;
1.86 cvs 3318: }
1.92 cvs 3319: else if (!strncasecmp (cssRule, "verdana", 7) &&
1.327 vatton 3320: (quoteChar == EOS || quoteChar == cssRule[7]))
1.86 cvs 3321: {
1.184 vatton 3322: font.typed_data.value = FontHelvetica;
1.86 cvs 3323: cssRule += 7;
1.92 cvs 3324: if (quoteChar != EOS)
1.327 vatton 3325: cssRule++;
1.86 cvs 3326: }
1.92 cvs 3327: else if (!strncasecmp (cssRule, "sans-serif", 10) &&
1.327 vatton 3328: (quoteChar == EOS || quoteChar == cssRule[10]))
1.86 cvs 3329: {
1.184 vatton 3330: font.typed_data.value = FontHelvetica;
1.86 cvs 3331: cssRule += 10;
1.92 cvs 3332: if (quoteChar != EOS)
1.327 vatton 3333: cssRule++;
1.86 cvs 3334: }
1.268 vatton 3335: else if (!strncasecmp (cssRule, "courier new", 11) &&
1.327 vatton 3336: (quoteChar == EOS || quoteChar == cssRule[11]))
1.268 vatton 3337: {
3338: font.typed_data.value = FontCourier;
3339: cssRule += 11;
3340: if (quoteChar != EOS)
1.327 vatton 3341: cssRule++;
1.268 vatton 3342: }
1.92 cvs 3343: else if (!strncasecmp (cssRule, "courier", 7) &&
1.327 vatton 3344: (quoteChar == EOS || quoteChar == cssRule[7]))
1.86 cvs 3345: {
1.184 vatton 3346: font.typed_data.value = FontCourier;
1.86 cvs 3347: cssRule += 7;
1.92 cvs 3348: if (quoteChar != EOS)
1.327 vatton 3349: cssRule++;
1.86 cvs 3350: }
1.92 cvs 3351: else if (!strncasecmp (cssRule, "monospace", 9) &&
1.327 vatton 3352: (quoteChar == EOS || quoteChar == cssRule[9]))
1.86 cvs 3353: {
1.184 vatton 3354: font.typed_data.value = FontCourier;
1.86 cvs 3355: cssRule += 9;
1.92 cvs 3356: if (quoteChar != EOS)
1.327 vatton 3357: cssRule++;
1.86 cvs 3358: }
1.1 cvs 3359: else
3360: /* unknown font name. Skip it */
3361: {
1.252 vatton 3362: p = cssRule;
1.92 cvs 3363: if (quoteChar != EOS)
1.327 vatton 3364: cssRule = SkipQuotedString (cssRule, quoteChar);
1.86 cvs 3365: else
1.383 quint 3366: /* unquoted font name. The name may contain spaces */
3367: {
3368: cssRule = SkipWord (cssRule);
3369: while (*cssRule == SPACE || *cssRule == BSPACE || *cssRule == EOL ||
3370: *cssRule == TAB || *cssRule == __CR__)
3371: {
3372: cssRule = SkipBlanksAndComments (cssRule);
3373: if (*cssRule != ',' && *cssRule != ';' && *cssRule != '}' &&
3374: *cssRule != EOS)
3375: cssRule = SkipWord (cssRule);
3376: }
3377: }
1.252 vatton 3378: while (p == cssRule &&
1.327 vatton 3379: *cssRule != ',' && *cssRule != ';' && *cssRule != '}' && *cssRule != EOS)
3380: {
3381: cssRule++;
3382: p = cssRule;
3383: cssRule = SkipWord (cssRule);
3384: }
1.82 cvs 3385: cssRule = SkipBlanksAndComments (cssRule);
3386: if (*cssRule == ',')
1.327 vatton 3387: {
3388: /* recursive call to ParseCSSFontFamily */
3389: cssRule++;
3390: cssRule = ParseACSSFontFamily (element, tsch, context, cssRule, css, isHTML);
3391: return (cssRule);
3392: }
1.1 cvs 3393: }
3394:
1.239 vatton 3395: /* skip other values */
3396: cssRule = SkipBlanksAndComments (cssRule);
3397: while (*cssRule == ',')
3398: {
3399: cssRule++;
3400: cssRule = SkipValue (NULL, cssRule);
3401: cssRule = SkipBlanksAndComments (cssRule);
3402: }
3403:
1.366 vatton 3404: if (font.typed_data.value != 0 || font.typed_data.unit == VALUE_INHERIT)
3405: {
3406: if (!DoDialog && DoApply)
3407: /* install the new presentation */
3408: TtaSetStylePresentation (PRFont, element, tsch, context, font);
3409: }
1.1 cvs 3410: return (cssRule);
3411: }
3412:
3413: /*----------------------------------------------------------------------
1.327 vatton 3414: ParseCSSFontFamily: parse a CSS font family string
3415: we expect the input string describing the attribute to be
3416: a common generic font style name
1.268 vatton 3417: ----------------------------------------------------------------------*/
3418: static char *ParseCSSFontFamily (Element element, PSchema tsch,
1.327 vatton 3419: PresentationContext context, char *cssRule,
3420: CSSInfoPtr css, ThotBool isHTML)
1.268 vatton 3421: {
1.366 vatton 3422: char *start_value;
3423:
3424: cssRule = SkipBlanksAndComments (cssRule);
3425: start_value = cssRule;
1.268 vatton 3426: cssRule = ParseACSSFontFamily (element, tsch, context, cssRule, css, isHTML);
3427: /* skip extra values */
1.301 vatton 3428: while (cssRule && *cssRule != ';' && *cssRule != '}' && *cssRule != EOS)
1.268 vatton 3429: cssRule++;
1.366 vatton 3430: if (DoDialog)
3431: DisplayStyleValue ("font-family", start_value, cssRule);
1.268 vatton 3432: return (cssRule);
3433: }
3434:
3435: /*----------------------------------------------------------------------
1.327 vatton 3436: ParseACSSFontWeight: parse a CSS font weight string
3437: we expect the input string describing the attribute to be
3438: normal, bold, bolder, lighter, 100, 200, 300, ... 900, inherit.
1.1 cvs 3439: ----------------------------------------------------------------------*/
1.263 vatton 3440: static char *ParseACSSFontWeight (Element element, PSchema tsch,
1.327 vatton 3441: PresentationContext context, char *cssRule,
3442: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 3443: {
1.327 vatton 3444: PresentationValue weight;
1.366 vatton 3445: char *ptr;
1.1 cvs 3446:
1.327 vatton 3447: weight.typed_data.value = 0;
3448: weight.typed_data.unit = UNIT_REL;
3449: weight.typed_data.real = FALSE;
3450: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 3451: ptr = cssRule;
1.351 quint 3452: if (isdigit (*cssRule) && *cssRule != '0' &&
3453: cssRule[1] == '0' && cssRule[2] == '0' &&
3454: (cssRule[3] == EOS || cssRule[3] == SPACE || cssRule[3] == '/' ||
3455: cssRule[3] == ';' || cssRule[3] == '}' || cssRule[3] == EOL ||
3456: cssRule[3] == TAB || cssRule[3] == __CR__))
1.327 vatton 3457: {
1.351 quint 3458: if (!strncasecmp (cssRule, "100", 3))
3459: {
1.379 quint 3460: weight.typed_data.value = -4;
1.351 quint 3461: cssRule = SkipWord (cssRule);
3462: }
3463: else if (!strncasecmp (cssRule, "200", 3))
3464: {
1.379 quint 3465: weight.typed_data.value = -3;
1.351 quint 3466: cssRule = SkipWord (cssRule);
3467: }
3468: else if (!strncasecmp (cssRule, "300", 3))
3469: {
1.379 quint 3470: weight.typed_data.value = -2;
1.351 quint 3471: cssRule = SkipWord (cssRule);
3472: }
3473: else if (!strncasecmp (cssRule, "400", 3))
3474: {
1.379 quint 3475: weight.typed_data.value = -1;
1.351 quint 3476: cssRule = SkipWord (cssRule);
3477: }
3478: else if (!strncasecmp (cssRule, "500", 3))
3479: {
1.379 quint 3480: weight.typed_data.value = 0;
1.351 quint 3481: cssRule = SkipWord (cssRule);
3482: }
3483: else if (!strncasecmp (cssRule, "600", 3))
3484: {
1.379 quint 3485: weight.typed_data.value = +1;
1.351 quint 3486: cssRule = SkipWord (cssRule);
3487: }
3488: else if (!strncasecmp (cssRule, "700", 3))
3489: {
1.379 quint 3490: weight.typed_data.value = +2;
1.351 quint 3491: cssRule = SkipWord (cssRule);
3492: }
3493: else if (!strncasecmp (cssRule, "800", 3))
3494: {
1.379 quint 3495: weight.typed_data.value = +3;
1.351 quint 3496: cssRule = SkipWord (cssRule);
3497: }
3498: else if (!strncasecmp (cssRule, "900", 3))
3499: {
1.379 quint 3500: weight.typed_data.value = +4;
1.351 quint 3501: cssRule = SkipWord (cssRule);
3502: }
1.327 vatton 3503: }
1.351 quint 3504: else if (!strncasecmp (cssRule, "normal", 6))
1.327 vatton 3505: {
3506: weight.typed_data.value = 0;
3507: cssRule = SkipWord (cssRule);
3508: }
1.351 quint 3509: else if (!strncasecmp (cssRule, "bold", 4))
1.327 vatton 3510: {
3511: weight.typed_data.value = +3;
3512: cssRule = SkipWord (cssRule);
3513: }
3514: else if (!strncasecmp (cssRule, "inherit", 7))
3515: {
3516: weight.typed_data.unit = VALUE_INHERIT;
3517: cssRule += 7;
3518: }
1.379 quint 3519: else if (!strncasecmp (cssRule, "bolder", 6))
1.327 vatton 3520: {
1.379 quint 3521: weight.typed_data.value = +2;
3522: cssRule = SkipWord (cssRule);
3523: }
3524:
3525: else if (!strncasecmp (cssRule, "lighter", 7))
3526: {
3527: weight.typed_data.value = -1;
1.327 vatton 3528: cssRule = SkipWord (cssRule);
3529: }
3530: else
3531: return (cssRule);
3532:
3533: /*
3534: * Here we have to reduce since only two font weight values are supported
3535: * by the Thot presentation API.
3536: */
3537: if (weight.typed_data.unit != VALUE_INHERIT)
3538: {
3539: if (weight.typed_data.value > 0)
3540: weight.typed_data.value = WeightBold;
3541: else
3542: weight.typed_data.value = WeightNormal;
3543: }
3544:
3545: /* install the new presentation */
1.366 vatton 3546: if (cssRule != ptr && DoDialog)
3547: DisplayStyleValue ("font-weight", ptr, cssRule);
3548: else if (DoApply)
1.327 vatton 3549: TtaSetStylePresentation (PRWeight, element, tsch, context, weight);
3550: return (cssRule);
3551: }
3552:
3553: /*----------------------------------------------------------------------
3554: ParseCSSFontWeight: parse a CSS font weight string
3555: we expect the input string describing the attribute to be
3556: normal, bold, bolder, lighter, 100, 200, 300, ... 900, inherit.
1.263 vatton 3557: ----------------------------------------------------------------------*/
3558: static char *ParseCSSFontWeight (Element element, PSchema tsch,
1.327 vatton 3559: PresentationContext context, char *cssRule,
3560: CSSInfoPtr css, ThotBool isHTML)
1.263 vatton 3561: {
3562: char *ptr;
3563:
1.366 vatton 3564: cssRule = SkipBlanksAndComments (cssRule);
1.263 vatton 3565: ptr = cssRule;
3566: cssRule = ParseACSSFontWeight (element, tsch, context, cssRule, css, isHTML);
3567: if (ptr == cssRule)
3568: cssRule = SkipValue ("Invalid font-weight value", cssRule);
3569: return (cssRule);
3570: }
3571:
3572: /*----------------------------------------------------------------------
1.327 vatton 3573: ParseACSSFontVariant: parse a CSS font variant string
3574: we expect the input string describing the attribute to be
3575: normal or small-caps
1.1 cvs 3576: ----------------------------------------------------------------------*/
1.263 vatton 3577: static char *ParseACSSFontVariant (Element element, PSchema tsch,
1.327 vatton 3578: PresentationContext context, char *cssRule,
3579: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 3580: {
1.327 vatton 3581: PresentationValue style;
1.366 vatton 3582: char *ptr;
1.1 cvs 3583:
1.327 vatton 3584: style.typed_data.value = 0;
3585: style.typed_data.unit = UNIT_REL;
3586: style.typed_data.real = FALSE;
3587: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 3588: ptr = cssRule;
1.327 vatton 3589: if (!strncasecmp (cssRule, "small-caps", 10))
3590: {
1.381 quint 3591: style.typed_data.value = VariantSmallCaps;
1.327 vatton 3592: cssRule = SkipWord (cssRule);
3593: }
3594: else if (!strncasecmp (cssRule, "normal", 6))
3595: {
1.381 quint 3596: style.typed_data.value = VariantNormal;
1.327 vatton 3597: cssRule = SkipWord (cssRule);
3598: }
3599: else if (!strncasecmp (cssRule, "inherit", 7))
3600: {
1.381 quint 3601: style.typed_data.unit = VALUE_INHERIT;
1.327 vatton 3602: cssRule = SkipWord (cssRule);
3603: }
1.381 quint 3604: else
3605: /* invalid font-variant */
3606: return (cssRule);
3607:
3608: if (style.typed_data.value != 0 || style.typed_data.unit == VALUE_INHERIT)
3609: {
3610: if (DoDialog)
3611: DisplayStyleValue ("font-variant", ptr, cssRule);
3612: else if (DoApply)
3613: TtaSetStylePresentation (PRVariant, element, tsch, context, style);
3614: }
1.295 vatton 3615: return (cssRule);
1.263 vatton 3616: }
1.1 cvs 3617:
1.263 vatton 3618: /*----------------------------------------------------------------------
1.327 vatton 3619: ParseCSSFontVariant: parse a CSS font variant string
3620: we expect the input string describing the attribute to be
3621: normal or small-caps
1.263 vatton 3622: ----------------------------------------------------------------------*/
3623: static char *ParseCSSFontVariant (Element element, PSchema tsch,
1.327 vatton 3624: PresentationContext context, char *cssRule,
3625: CSSInfoPtr css, ThotBool isHTML)
1.263 vatton 3626: {
3627: char *ptr;
3628:
3629: ptr = cssRule;
3630: cssRule = ParseACSSFontVariant (element, tsch, context, cssRule, css, isHTML);
3631: if (ptr == cssRule)
3632: cssRule = SkipValue ("Invalid font-variant value", cssRule);
3633: return (cssRule);
1.1 cvs 3634: }
3635:
3636:
3637: /*----------------------------------------------------------------------
1.327 vatton 3638: ParseACSSFontStyle: parse a CSS font style string
3639: we expect the input string describing the attribute to be
3640: normal, italic, oblique or inherit
1.1 cvs 3641: ----------------------------------------------------------------------*/
1.263 vatton 3642: static char *ParseACSSFontStyle (Element element, PSchema tsch,
1.327 vatton 3643: PresentationContext context, char *cssRule,
3644: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 3645: {
1.327 vatton 3646: PresentationValue style;
3647: PresentationValue size;
1.366 vatton 3648: PresentationValue previous_size;
3649: char *ptr;
1.1 cvs 3650:
1.327 vatton 3651: style.typed_data.value = 0;
3652: style.typed_data.unit = UNIT_REL;
3653: style.typed_data.real = FALSE;
3654: size.typed_data.value = 0;
3655: size.typed_data.unit = UNIT_REL;
3656: size.typed_data.real = FALSE;
3657: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 3658: ptr = cssRule;
1.327 vatton 3659: if (!strncasecmp (cssRule, "italic", 6))
3660: {
3661: style.typed_data.value = StyleItalics;
3662: cssRule = SkipWord (cssRule);
3663: }
3664: else if (!strncasecmp (cssRule, "oblique", 7))
3665: {
3666: style.typed_data.value = StyleOblique;
3667: cssRule = SkipWord (cssRule);
3668: }
3669: else if (!strncasecmp (cssRule, "normal", 6))
3670: {
3671: style.typed_data.value = StyleRoman;
3672: cssRule = SkipWord (cssRule);
3673: }
3674: else if (!strncasecmp (cssRule, "inherit", 7))
3675: {
3676: style.typed_data.unit = VALUE_INHERIT;
3677: cssRule = SkipWord (cssRule);
3678: }
3679: else
3680: /* invalid font style */
3681: return (cssRule);
3682:
3683: /*
3684: * install the new presentation.
3685: */
1.366 vatton 3686: if (style.typed_data.value != 0 || style.typed_data.unit == VALUE_INHERIT)
1.327 vatton 3687: {
1.366 vatton 3688: if (DoDialog)
3689: DisplayStyleValue ("font-style", ptr, cssRule);
3690: else if (DoApply)
3691: TtaSetStylePresentation (PRStyle, element, tsch, context, style);
1.327 vatton 3692: }
1.366 vatton 3693: if (size.typed_data.value != 0)
1.327 vatton 3694: {
1.366 vatton 3695: if (DoDialog)
3696: DisplayStyleValue ("font-style", ptr, cssRule);
3697: else if (DoApply)
1.327 vatton 3698: {
1.366 vatton 3699: if (!TtaGetStylePresentation (PRSize, element, tsch, context, &previous_size))
3700: {
3701: /* !!!!!!!!!!!!!!!!!!!!!!!! Unit + relative !!!!!!!!!!!!!!!! */
3702: size.typed_data.value += previous_size.typed_data.value;
3703: TtaSetStylePresentation (PRSize, element, tsch, context, size);
3704: }
3705: else
3706: {
3707: size.typed_data.value = 10;
3708: TtaSetStylePresentation (PRSize, element, tsch, context, size);
3709: }
1.327 vatton 3710: }
3711: }
3712: return (cssRule);
3713: }
3714:
3715: /*----------------------------------------------------------------------
3716: ParseCSSFontStyle: parse a CSS font style string
3717: we expect the input string describing the attribute to be
3718: italic, oblique or normal
1.263 vatton 3719: ----------------------------------------------------------------------*/
3720: static char *ParseCSSFontStyle (Element element, PSchema tsch,
1.327 vatton 3721: PresentationContext context, char *cssRule,
3722: CSSInfoPtr css, ThotBool isHTML)
1.263 vatton 3723: {
3724: char *ptr;
3725:
3726: ptr = cssRule;
3727: cssRule = ParseACSSFontStyle (element, tsch, context, cssRule, css, isHTML);
3728: if (ptr == cssRule)
3729: cssRule = SkipValue ("Invalid font-style value", cssRule);
3730: return (cssRule);
3731: }
3732:
3733: /*----------------------------------------------------------------------
1.59 cvs 3734: ParseCSSFont: parse a CSS font attribute string
3735: we expect the input string describing the attribute to be
3736: !!!!!!
1.1 cvs 3737: ----------------------------------------------------------------------*/
1.79 cvs 3738: static char *ParseCSSFont (Element element, PSchema tsch,
1.327 vatton 3739: PresentationContext context, char *cssRule,
3740: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 3741: {
1.270 vatton 3742: char *ptr, *p;
1.366 vatton 3743: char *start_value;
1.93 vatton 3744: int skippedNL;
1.272 vatton 3745: ThotBool variant = FALSE, style = FALSE, weight = FALSE, found;
1.1 cvs 3746:
1.82 cvs 3747: cssRule = SkipBlanksAndComments (cssRule);
3748: if (!strncasecmp (cssRule, "caption", 7))
1.263 vatton 3749: cssRule += 7;
1.82 cvs 3750: else if (!strncasecmp (cssRule, "icon", 4))
1.263 vatton 3751: cssRule += 4;
1.82 cvs 3752: else if (!strncasecmp (cssRule, "menu", 4))
1.263 vatton 3753: cssRule += 4;
1.82 cvs 3754: else if (!strncasecmp (cssRule, "message-box", 11))
1.263 vatton 3755: cssRule += 11;
1.82 cvs 3756: else if (!strncasecmp (cssRule, "small-caption", 13))
1.263 vatton 3757: cssRule += 13;
1.82 cvs 3758: else if (!strncasecmp (cssRule, "status-bar", 10))
1.263 vatton 3759: cssRule += 10;
3760: else if (!strncasecmp (cssRule, "inherit", 7))
1.293 quint 3761: {
3762: ParseACSSFontStyle (element, tsch, context, cssRule, css, isHTML);
3763: ParseACSSFontVariant (element, tsch, context, cssRule, css, isHTML);
3764: ParseACSSFontWeight (element, tsch, context, cssRule, css, isHTML);
3765: ParseACSSFontSize (element, tsch, context, cssRule, css, isHTML, FALSE);
1.366 vatton 3766: cssRule = SkipBlanksAndComments (cssRule);
3767: start_value = cssRule;
1.293 quint 3768: ParseACSSFontFamily (element, tsch, context, cssRule, css, isHTML);
3769: cssRule += 7;
1.366 vatton 3770: if (DoDialog)
3771: DisplayStyleValue ("font-family", start_value, cssRule);
1.293 quint 3772: }
1.1 cvs 3773: else
1.43 cvs 3774: {
1.270 vatton 3775: ptr = NULL;
3776: p = cssRule;
1.301 vatton 3777: while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && p == cssRule)
1.327 vatton 3778: {
3779: found = FALSE;
3780: /* style, variant, weight can appear in any order */
3781: ptr = cssRule;
3782: skippedNL = NewLineSkipped;
3783: cssRule = ParseACSSFontStyle (element, tsch, context, cssRule, css, isHTML);
3784: if (ptr != cssRule)
3785: {
3786: skippedNL = NewLineSkipped;
3787: found = TRUE;
3788: style = TRUE;
3789: }
3790: else
3791: NewLineSkipped = skippedNL;
3792: ptr = cssRule;
3793: cssRule = ParseACSSFontVariant (element, tsch, context, cssRule, css, isHTML);
3794: if (ptr != cssRule)
3795: {
3796: skippedNL = NewLineSkipped;
3797: found = TRUE;
3798: variant = TRUE;
3799: }
3800: else
3801: NewLineSkipped = skippedNL;
3802: ptr = cssRule;
3803: cssRule = ParseACSSFontWeight (element, tsch, context, cssRule, css, isHTML);
3804: if (ptr != cssRule)
3805: {
3806: skippedNL = NewLineSkipped;
3807: found = TRUE;
3808: weight = TRUE;
3809: }
3810: else
3811: NewLineSkipped = skippedNL;
3812: cssRule = SkipBlanksAndComments (cssRule);
3813: p = ParseACSSFontSize (element, tsch, context, cssRule, css, isHTML, TRUE);
3814: NewLineSkipped = skippedNL;
3815: if (!found)
3816: /* break the loop when the current value was not parsed */
3817: p = cssRule + 1;
3818: }
1.263 vatton 3819: ptr = cssRule;
1.270 vatton 3820: /* set default variant, style, weight */
3821: if (!variant)
1.405 kia 3822: ParseACSSFontVariant (element, tsch, context, (char*)"normal", css, isHTML);
1.270 vatton 3823: if (!style)
1.405 kia 3824: ParseACSSFontStyle (element, tsch, context, (char*)"normal", css, isHTML);
1.270 vatton 3825: if (!weight)
1.405 kia 3826: ParseACSSFontWeight (element, tsch, context, (char*)"normal", css, isHTML);
1.270 vatton 3827: /* now parse the font size and the font family */
1.301 vatton 3828: if (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS)
1.327 vatton 3829: cssRule = ParseACSSFontSize (element, tsch, context, cssRule, css, isHTML, FALSE);
1.301 vatton 3830: if (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS)
1.366 vatton 3831: {
3832: cssRule = SkipBlanksAndComments (cssRule);
3833: start_value = cssRule;
3834: cssRule = ParseACSSFontFamily (element, tsch, context, cssRule, css, isHTML);
3835: if (DoDialog)
3836: DisplayStyleValue ("font-family", start_value, cssRule);
3837: }
1.263 vatton 3838: if (ptr == cssRule)
1.360 vatton 3839: cssRule = SkipValue ("Invalid font value", cssRule);
1.43 cvs 3840: }
1.263 vatton 3841: cssRule = SkipBlanksAndComments (cssRule);
1.301 vatton 3842: if (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS)
1.360 vatton 3843: cssRule = SkipValue ("Invalid font value", cssRule);
1.43 cvs 3844: return (cssRule);
1.1 cvs 3845: }
3846:
3847: /*----------------------------------------------------------------------
1.356 quint 3848: ParseCSSTextDecoration: parse a CSS text-decoration value.
3849: We expect the input string to be none, inherit or a combination of
3850: underline, overline, line-through, and blink.
1.1 cvs 3851: ----------------------------------------------------------------------*/
1.79 cvs 3852: static char *ParseCSSTextDecoration (Element element, PSchema tsch,
1.327 vatton 3853: PresentationContext context, char *cssRule,
3854: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 3855: {
1.327 vatton 3856: PresentationValue decor;
1.366 vatton 3857: char *ptr;
1.356 quint 3858: ThotBool ok;
1.327 vatton 3859:
3860: decor.typed_data.value = 0;
3861: decor.typed_data.unit = UNIT_REL;
3862: decor.typed_data.real = FALSE;
3863: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 3864: ptr = cssRule;
1.356 quint 3865: ok = TRUE;
1.327 vatton 3866: if (!strncasecmp (cssRule, "none", 4))
3867: {
3868: decor.typed_data.value = NoUnderline;
3869: cssRule += 4;
3870: }
3871: else if (!strncasecmp (cssRule, "inherit", 7))
3872: {
3873: decor.typed_data.unit = VALUE_INHERIT;
3874: cssRule += 7;
3875: }
3876: else
3877: {
1.356 quint 3878: do
3879: {
3880: if (!strncasecmp (cssRule, "underline", 9))
3881: {
3882: decor.typed_data.value = Underline;
3883: cssRule += 9;
3884: }
3885: else if (!strncasecmp (cssRule, "overline", 8))
3886: {
3887: decor.typed_data.value = Overline;
3888: cssRule += 8;
3889: }
3890: else if (!strncasecmp (cssRule, "line-through", 12))
3891: {
3892: decor.typed_data.value = CrossOut;
3893: cssRule += 12;
3894: }
3895: else if (!strncasecmp (cssRule, "blink", 5))
3896: {
3897: /* the blink text-decoration attribute is not supported */
3898: cssRule += 5;
3899: }
3900: else
3901: ok = FALSE;
3902: if (ok)
3903: {
3904: cssRule = SkipBlanksAndComments (cssRule);
3905: }
3906: }
3907: while (ok && (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS));
3908: }
3909: if (!ok)
3910: {
1.327 vatton 3911: cssRule = SkipValue ("Invalid text-decoration value", cssRule);
3912: return (cssRule);
3913: }
1.1 cvs 3914:
1.327 vatton 3915: /*
3916: * install the new presentation.
3917: */
1.366 vatton 3918: if (decor.typed_data.value || decor.typed_data.unit == VALUE_INHERIT)
3919: {
3920: if (DoDialog)
3921: DisplayStyleValue ("text-decoration", ptr, cssRule);
3922: else if (DoApply)
3923: TtaSetStylePresentation (PRUnderline, element, tsch, context, decor);
3924: }
1.327 vatton 3925: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid text-decoration value");
3926: return (cssRule);
1.1 cvs 3927: }
3928:
3929: /*----------------------------------------------------------------------
1.327 vatton 3930: ParseCSSHeight: parse a CSS height attribute
1.1 cvs 3931: ----------------------------------------------------------------------*/
1.79 cvs 3932: static char *ParseCSSHeight (Element element, PSchema tsch,
1.327 vatton 3933: PresentationContext context, char *cssRule,
3934: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 3935: {
1.117 vatton 3936: PresentationValue val;
1.168 vatton 3937: char *ptr;
1.93 vatton 3938:
1.370 vatton 3939: val.typed_data.real = FALSE;
1.117 vatton 3940: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 3941: ptr = cssRule;
1.117 vatton 3942: /* first parse the attribute string */
1.164 quint 3943: if (!strncasecmp (cssRule, "auto", 4))
3944: {
1.184 vatton 3945: val.typed_data.unit = VALUE_AUTO;
1.164 quint 3946: val.typed_data.value = 0;
1.288 vatton 3947: cssRule += 4;
3948: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid height value");
1.164 quint 3949: }
1.117 vatton 3950: else
1.168 vatton 3951: cssRule = ParseCSSUnit (cssRule, &val);
1.295 vatton 3952:
1.387 quint 3953: if (val.typed_data.unit == UNIT_INVALID ||
3954: (val.typed_data.value != 0 &&
1.184 vatton 3955: val.typed_data.unit == UNIT_BOX))
1.387 quint 3956: CSSParseError ("height value", ptr, cssRule);
3957: else if (DoDialog)
1.366 vatton 3958: DisplayStyleValue ("height", ptr, cssRule);
3959: else if (DoApply)
1.295 vatton 3960: /* install the new presentation */
3961: TtaSetStylePresentation (PRHeight, element, tsch, context, val);
1.117 vatton 3962: return (cssRule);
1.1 cvs 3963: }
3964:
3965: /*----------------------------------------------------------------------
1.382 vatton 3966: ParseCSSMaxHeight: parse a CSS height attribute
3967: ----------------------------------------------------------------------*/
3968: static char *ParseCSSMaxHeight (Element element, PSchema tsch,
3969: PresentationContext context, char *cssRule,
3970: CSSInfoPtr css, ThotBool isHTML)
3971: {
3972: PresentationValue val;
3973: char *ptr;
3974:
3975: val.typed_data.real = FALSE;
3976: cssRule = SkipBlanksAndComments (cssRule);
3977: ptr = cssRule;
3978: /* first parse the attribute string */
3979: if (!strncasecmp (cssRule, "auto", 4))
3980: {
3981: val.typed_data.unit = VALUE_AUTO;
3982: val.typed_data.value = 0;
3983: cssRule += 4;
3984: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid height value");
3985: }
3986: else
3987: cssRule = ParseCSSUnit (cssRule, &val);
3988:
1.387 quint 3989: if (val.typed_data.unit == UNIT_INVALID ||
3990: (val.typed_data.value != 0 &&
1.382 vatton 3991: val.typed_data.unit == UNIT_BOX))
1.387 quint 3992: CSSParseError ("height value", ptr, cssRule);
3993: else if (DoDialog)
1.382 vatton 3994: DisplayStyleValue ("max-height", ptr, cssRule);
1.390 vatton 3995: /*else if (DoApply)
3996: install the new presentation
3997: TtaSetStylePresentation (PRHeight, element, tsch, context, val)*/;
1.382 vatton 3998: return (cssRule);
3999: }
4000:
4001: /*----------------------------------------------------------------------
4002: ParseCSSMinHeight: parse a CSS height attribute
4003: ----------------------------------------------------------------------*/
4004: static char *ParseCSSMinHeight (Element element, PSchema tsch,
4005: PresentationContext context, char *cssRule,
4006: CSSInfoPtr css, ThotBool isHTML)
4007: {
4008: PresentationValue val;
4009: char *ptr;
4010:
4011: val.typed_data.real = FALSE;
4012: cssRule = SkipBlanksAndComments (cssRule);
4013: ptr = cssRule;
4014: /* first parse the attribute string */
4015: if (!strncasecmp (cssRule, "auto", 4))
4016: {
4017: val.typed_data.unit = VALUE_AUTO;
4018: val.typed_data.value = 0;
4019: cssRule += 4;
4020: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid height value");
4021: }
4022: else
4023: cssRule = ParseCSSUnit (cssRule, &val);
4024:
1.387 quint 4025: if (val.typed_data.unit == UNIT_INVALID ||
4026: (val.typed_data.value != 0 &&
1.382 vatton 4027: val.typed_data.unit == UNIT_BOX))
1.387 quint 4028: CSSParseError ("height value", ptr, cssRule);
4029: else if (DoDialog)
1.382 vatton 4030: DisplayStyleValue ("min-height", ptr, cssRule);
1.390 vatton 4031: /*else if (DoApply)*/
1.382 vatton 4032: /* install the new presentation */
1.384 vatton 4033: /*TtaSetStylePresentation (PRHeight, element, tsch, context, val)*/;
1.382 vatton 4034: return (cssRule);
4035: }
4036:
4037: /*----------------------------------------------------------------------
1.327 vatton 4038: ParseCSSWidth: parse a CSS width attribute
1.1 cvs 4039: ----------------------------------------------------------------------*/
1.79 cvs 4040: static char *ParseCSSWidth (Element element, PSchema tsch,
1.327 vatton 4041: PresentationContext context,
4042: char *cssRule, CSSInfoPtr css,
4043: ThotBool isHTML)
1.1 cvs 4044: {
1.117 vatton 4045: PresentationValue val;
1.168 vatton 4046: char *ptr;
1.93 vatton 4047:
1.370 vatton 4048: val.typed_data.real = FALSE;
1.117 vatton 4049: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 4050: ptr = cssRule;
1.117 vatton 4051: /* first parse the attribute string */
1.164 quint 4052: if (!strncasecmp (cssRule, "auto", 4))
4053: {
1.184 vatton 4054: val.typed_data.unit = VALUE_AUTO;
1.164 quint 4055: val.typed_data.value = 0;
1.288 vatton 4056: cssRule += 4;
4057: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid width value");
1.164 quint 4058: }
1.117 vatton 4059: else
1.327 vatton 4060: cssRule = ParseCSSUnit (cssRule, &val);
1.387 quint 4061: if (val.typed_data.unit == UNIT_INVALID ||
4062: (val.typed_data.value != 0 &&
1.184 vatton 4063: val.typed_data.unit == UNIT_BOX))
1.387 quint 4064: CSSParseError ("Invalid width value", ptr, cssRule);
4065: else if (DoDialog)
1.366 vatton 4066: DisplayStyleValue ("width", ptr, cssRule);
4067: else if (DoApply)
1.295 vatton 4068: /* install the new presentation */
4069: TtaSetStylePresentation (PRWidth, element, tsch, context, val);
1.117 vatton 4070: return (cssRule);
1.1 cvs 4071: }
4072:
4073: /*----------------------------------------------------------------------
1.382 vatton 4074: ParseCSSMaxWidth: parse a CSS width attribute
4075: ----------------------------------------------------------------------*/
4076: static char *ParseCSSMaxWidth (Element element, PSchema tsch,
4077: PresentationContext context,
4078: char *cssRule, CSSInfoPtr css,
4079: ThotBool isHTML)
4080: {
4081: PresentationValue val;
4082: char *ptr;
4083:
4084: val.typed_data.real = FALSE;
4085: cssRule = SkipBlanksAndComments (cssRule);
4086: ptr = cssRule;
4087: /* first parse the attribute string */
4088: if (!strncasecmp (cssRule, "auto", 4))
4089: {
4090: val.typed_data.unit = VALUE_AUTO;
4091: val.typed_data.value = 0;
4092: cssRule += 4;
4093: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid width value");
4094: }
4095: else
4096: cssRule = ParseCSSUnit (cssRule, &val);
1.387 quint 4097: if (val.typed_data.unit == UNIT_INVALID ||
4098: (val.typed_data.value != 0 &&
1.382 vatton 4099: val.typed_data.unit == UNIT_BOX))
4100: CSSParseError ("Invalid width value", ptr, cssRule);
1.387 quint 4101: else if (DoDialog)
1.382 vatton 4102: DisplayStyleValue ("max-width", ptr, cssRule);
1.408 vatton 4103: /*else if (DoApply)*/
1.382 vatton 4104: /* install the new presentation */
1.384 vatton 4105: /*TtaSetStylePresentation (PRWidth, element, tsch, context, val)*/;
1.382 vatton 4106: return (cssRule);
4107: }
4108:
4109: /*----------------------------------------------------------------------
4110: ParseCSSMinWidth: parse a CSS width attribute
4111: ----------------------------------------------------------------------*/
4112: static char *ParseCSSMinWidth (Element element, PSchema tsch,
4113: PresentationContext context,
4114: char *cssRule, CSSInfoPtr css,
4115: ThotBool isHTML)
4116: {
4117: PresentationValue val;
4118: char *ptr;
4119:
4120: val.typed_data.real = FALSE;
4121: cssRule = SkipBlanksAndComments (cssRule);
4122: ptr = cssRule;
4123: /* first parse the attribute string */
4124: if (!strncasecmp (cssRule, "auto", 4))
4125: {
4126: val.typed_data.unit = VALUE_AUTO;
4127: val.typed_data.value = 0;
4128: cssRule += 4;
4129: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid width value");
4130: }
4131: else
4132: cssRule = ParseCSSUnit (cssRule, &val);
1.387 quint 4133: if (val.typed_data.unit == UNIT_INVALID ||
4134: (val.typed_data.value != 0 &&
1.382 vatton 4135: val.typed_data.unit == UNIT_BOX))
1.387 quint 4136: CSSParseError ("Invalid width value", ptr, cssRule);
4137: else if (DoDialog)
1.382 vatton 4138: DisplayStyleValue ("min-width", ptr, cssRule);
1.408 vatton 4139: /*else if (DoApply)*/
1.382 vatton 4140: /* install the new presentation */
1.384 vatton 4141: /*TtaSetStylePresentation (PRWidth, element, tsch, context, val)*/;
1.382 vatton 4142: return (cssRule);
4143: }
4144:
4145: /*----------------------------------------------------------------------
1.391 vatton 4146: GetEmMarginValue returns the em value
4147: ----------------------------------------------------------------------*/
4148: int GetEmValue (char *data, Element el, Document doc)
4149: {
4150: PresentationValue val;
4151: char *ptr;
4152: int value;
4153:
4154: val.typed_data.real = FALSE;
4155: ptr = SkipBlanksAndComments (data);
4156: if (!strncasecmp (data, "auto", 4))
4157: value = TtaGetPixelValue (0, VALUE_AUTO, el, doc);
4158: else
4159: {
4160: ptr = ParseCSSUnit (data, &val);
4161: value = TtaGetPixelValue (val.typed_data.value, val.typed_data.unit,
4162: el, doc);
4163: }
4164: return TtaGetLogicalValue (value, UNIT_EM, el, doc);
4165: }
4166:
4167: /*----------------------------------------------------------------------
1.327 vatton 4168: ParseACSSMarginTop: parse a CSS margin-top attribute
1.1 cvs 4169: ----------------------------------------------------------------------*/
1.296 vatton 4170: static char *ParseACSSMarginTop (Element element, PSchema tsch,
1.327 vatton 4171: PresentationContext context,
4172: char *cssRule, CSSInfoPtr css,
4173: ThotBool isHTML)
1.1 cvs 4174: {
4175: PresentationValue margin;
1.168 vatton 4176: char *ptr;
1.1 cvs 4177:
1.370 vatton 4178: margin.typed_data.real = FALSE;
1.82 cvs 4179: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 4180: ptr = cssRule;
1.1 cvs 4181: /* first parse the attribute string */
1.164 quint 4182: if (!strncasecmp (cssRule, "auto", 4))
4183: {
1.184 vatton 4184: margin.typed_data.unit = VALUE_AUTO;
1.164 quint 4185: margin.typed_data.value = 0;
1.288 vatton 4186: cssRule += 4;
1.164 quint 4187: }
1.404 vatton 4188: else if (!strncasecmp (cssRule, "inherit", 7))
4189: {
4190: margin.typed_data.unit = VALUE_AUTO;
4191: margin.typed_data.value = 0;
4192: cssRule += 7;
4193: }
1.164 quint 4194: else
1.168 vatton 4195: cssRule = ParseCSSUnit (cssRule, &margin);
1.295 vatton 4196:
1.387 quint 4197: if (margin.typed_data.unit == UNIT_INVALID ||
4198: (margin.typed_data.value != 0 &&
1.184 vatton 4199: margin.typed_data.unit == UNIT_BOX))
1.169 vatton 4200: CSSParseError ("Invalid margin-top value", ptr, cssRule);
1.366 vatton 4201: else if (DoDialog)
4202: {
4203: if (All_sides)
4204: DisplayStyleValue ("margin", ptr, cssRule);
4205: else
4206: DisplayStyleValue ("margin-top", ptr, cssRule);
4207: }
1.168 vatton 4208: else if (DoApply)
1.295 vatton 4209: TtaSetStylePresentation (PRMarginTop, element, tsch, context, margin);
1.1 cvs 4210: return (cssRule);
4211: }
4212:
4213: /*----------------------------------------------------------------------
1.327 vatton 4214: ParseCSSMarginTop: parse a CSS margin-top attribute
1.296 vatton 4215: ----------------------------------------------------------------------*/
4216: static char *ParseCSSMarginTop (Element element, PSchema tsch,
1.327 vatton 4217: PresentationContext context,
4218: char *cssRule, CSSInfoPtr css,
4219: ThotBool isHTML)
1.296 vatton 4220: {
4221: char *ptr = cssRule;
4222:
4223: cssRule = ParseACSSMarginTop (element, tsch, context, ptr, css, isHTML);
4224: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid margin-top value");
4225: return (cssRule);
4226: }
4227:
4228: /*----------------------------------------------------------------------
4229: ParseACSSMarginBottom: parse a CSS margin-bottom attribute
1.1 cvs 4230: ----------------------------------------------------------------------*/
1.296 vatton 4231: static char *ParseACSSMarginBottom (Element element, PSchema tsch,
1.327 vatton 4232: PresentationContext context,
4233: char *cssRule, CSSInfoPtr css,
4234: ThotBool isHTML)
1.1 cvs 4235: {
4236: PresentationValue margin;
1.168 vatton 4237: char *ptr;
1.1 cvs 4238:
1.370 vatton 4239: margin.typed_data.real = FALSE;
1.82 cvs 4240: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 4241: ptr = cssRule;
1.1 cvs 4242: /* first parse the attribute string */
1.164 quint 4243: if (!strncasecmp (cssRule, "auto", 4))
4244: {
1.184 vatton 4245: margin.typed_data.unit = VALUE_AUTO;
1.164 quint 4246: margin.typed_data.value = 0;
1.288 vatton 4247: cssRule += 4;
1.164 quint 4248: }
1.404 vatton 4249: else if (!strncasecmp (cssRule, "inherit", 7))
4250: {
4251: margin.typed_data.unit = VALUE_AUTO;
4252: margin.typed_data.value = 0;
4253: cssRule += 7;
4254: }
1.164 quint 4255: else
1.168 vatton 4256: cssRule = ParseCSSUnit (cssRule, &margin);
1.295 vatton 4257:
1.387 quint 4258: if (margin.typed_data.unit == UNIT_INVALID ||
4259: (margin.typed_data.value != 0 &&
1.184 vatton 4260: margin.typed_data.unit == UNIT_BOX))
1.169 vatton 4261: CSSParseError ("Invalid margin-bottom value", ptr, cssRule);
1.366 vatton 4262: else if (DoDialog)
4263: DisplayStyleValue ("margin-bottom", ptr, cssRule);
1.168 vatton 4264: else if (DoApply)
1.295 vatton 4265: TtaSetStylePresentation (PRMarginBottom, element, tsch, context, margin);
1.1 cvs 4266: return (cssRule);
4267: }
4268:
4269: /*----------------------------------------------------------------------
1.296 vatton 4270: ParseCSSMarginBottom: parse a CSS margin-bottom attribute
4271: ----------------------------------------------------------------------*/
4272: static char *ParseCSSMarginBottom (Element element, PSchema tsch,
1.327 vatton 4273: PresentationContext context,
4274: char *cssRule, CSSInfoPtr css,
4275: ThotBool isHTML)
1.296 vatton 4276: {
4277: char *ptr = cssRule;
4278:
4279: cssRule = ParseACSSMarginBottom (element, tsch, context, ptr, css, isHTML);
4280: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid margin-bottom value");
4281: return (cssRule);
4282: }
4283:
4284: /*----------------------------------------------------------------------
4285: ParseACSSMarginLeft: parse a CSS margin-left attribute string
1.1 cvs 4286: ----------------------------------------------------------------------*/
1.296 vatton 4287: static char *ParseACSSMarginLeft (Element element, PSchema tsch,
1.327 vatton 4288: PresentationContext context,
4289: char *cssRule, CSSInfoPtr css,
4290: ThotBool isHTML)
1.1 cvs 4291: {
4292: PresentationValue margin;
1.168 vatton 4293: char *ptr;
1.1 cvs 4294:
1.370 vatton 4295: margin.typed_data.real = FALSE;
1.82 cvs 4296: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 4297: ptr = cssRule;
1.1 cvs 4298: /* first parse the attribute string */
1.164 quint 4299: if (!strncasecmp (cssRule, "auto", 4))
4300: {
1.184 vatton 4301: margin.typed_data.unit = VALUE_AUTO;
1.164 quint 4302: margin.typed_data.value = 0;
1.288 vatton 4303: cssRule += 4;
1.164 quint 4304: }
4305: else
1.168 vatton 4306: cssRule = ParseCSSUnit (cssRule, &margin);
1.295 vatton 4307:
1.387 quint 4308: if (margin.typed_data.unit == UNIT_INVALID ||
4309: (margin.typed_data.value != 0 &&
1.184 vatton 4310: margin.typed_data.unit == UNIT_BOX))
1.169 vatton 4311: CSSParseError ("Invalid margin-left value", ptr, cssRule);
1.366 vatton 4312: else if (DoDialog)
4313: DisplayStyleValue ("margin-left", ptr, cssRule);
1.295 vatton 4314: else if (DoApply && margin.typed_data.unit != UNIT_INVALID && DoApply)
1.327 vatton 4315: TtaSetStylePresentation (PRMarginLeft, element, tsch, context, margin);
1.1 cvs 4316: return (cssRule);
4317: }
4318:
4319: /*----------------------------------------------------------------------
1.296 vatton 4320: ParseCSSMarginBottom: parse a CSS margin-bottom attribute
4321: ----------------------------------------------------------------------*/
4322: static char *ParseCSSMarginLeft (Element element, PSchema tsch,
1.327 vatton 4323: PresentationContext context,
4324: char *cssRule, CSSInfoPtr css,
4325: ThotBool isHTML)
1.296 vatton 4326: {
4327: char *ptr = cssRule;
4328:
4329: cssRule = ParseACSSMarginLeft (element, tsch, context, ptr, css, isHTML);
4330: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid margin-left value");
4331: return (cssRule);
4332: }
4333:
4334:
4335: /*----------------------------------------------------------------------
4336: ParseACSSMarginRight: parse a CSS margin-right attribute string
1.1 cvs 4337: ----------------------------------------------------------------------*/
1.296 vatton 4338: static char *ParseACSSMarginRight (Element element, PSchema tsch,
1.327 vatton 4339: PresentationContext context,
4340: char *cssRule, CSSInfoPtr css,
4341: ThotBool isHTML)
1.1 cvs 4342: {
4343: PresentationValue margin;
1.168 vatton 4344: char *ptr;
1.1 cvs 4345:
1.370 vatton 4346: margin.typed_data.real = FALSE;
1.82 cvs 4347: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 4348: ptr = cssRule;
1.1 cvs 4349: /* first parse the attribute string */
1.164 quint 4350: if (!strncasecmp (cssRule, "auto", 4))
4351: {
1.184 vatton 4352: margin.typed_data.unit = VALUE_AUTO;
1.164 quint 4353: margin.typed_data.value = 0;
1.288 vatton 4354: cssRule += 4;
1.164 quint 4355: }
1.404 vatton 4356: else if (!strncasecmp (cssRule, "inherit", 7))
4357: {
4358: margin.typed_data.unit = VALUE_AUTO;
4359: margin.typed_data.value = 0;
4360: cssRule += 7;
4361: }
1.164 quint 4362: else
1.168 vatton 4363: cssRule = ParseCSSUnit (cssRule, &margin);
1.295 vatton 4364:
1.387 quint 4365: if (margin.typed_data.unit == UNIT_INVALID ||
4366: (margin.typed_data.value != 0 &&
1.184 vatton 4367: margin.typed_data.unit == UNIT_BOX))
1.169 vatton 4368: CSSParseError ("Invalid margin-right value", ptr, cssRule);
1.366 vatton 4369: else if (DoDialog)
4370: DisplayStyleValue ("margin-right", ptr, cssRule);
1.168 vatton 4371: else if (DoApply)
1.295 vatton 4372: TtaSetStylePresentation (PRMarginRight, element, tsch, context, margin);
1.1 cvs 4373: return (cssRule);
4374: }
4375:
4376: /*----------------------------------------------------------------------
1.296 vatton 4377: ParseCSSMarginRight: parse a CSS margin-right attribute string
4378: ----------------------------------------------------------------------*/
4379: static char *ParseCSSMarginRight (Element element, PSchema tsch,
1.327 vatton 4380: PresentationContext context,
4381: char *cssRule, CSSInfoPtr css,
4382: ThotBool isHTML)
1.296 vatton 4383: {
4384: char *ptr = cssRule;
4385:
1.297 vatton 4386: cssRule = ParseACSSMarginRight (element, tsch, context, ptr, css, isHTML);
1.296 vatton 4387: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid margin-right value");
4388: return (cssRule);
4389: }
4390:
4391: /*----------------------------------------------------------------------
1.59 cvs 4392: ParseCSSMargin: parse a CSS margin attribute string
1.1 cvs 4393: ----------------------------------------------------------------------*/
1.79 cvs 4394: static char *ParseCSSMargin (Element element, PSchema tsch,
1.327 vatton 4395: PresentationContext context,
4396: char *cssRule, CSSInfoPtr css,
4397: ThotBool isHTML)
1.1 cvs 4398: {
1.79 cvs 4399: char *ptrT, *ptrR, *ptrB, *ptrL;
1.366 vatton 4400: int skippedNL, n;
1.1 cvs 4401:
1.82 cvs 4402: ptrT = SkipBlanksAndComments (cssRule);
1.366 vatton 4403: if (DoDialog)
4404: n = NumberOfValues (ptrT);
4405: if (DoDialog && n < 2)
1.1 cvs 4406: {
1.366 vatton 4407: // check if the margin dialog must be updated
4408: All_sides = TRUE;
4409: ptrR = ParseACSSMarginTop (element, tsch, context, ptrT, css, isHTML);
4410: All_sides = FALSE;
1.1 cvs 4411: }
4412: else
4413: {
1.366 vatton 4414: /* First parse Margin-Top */
4415: ptrR = ParseACSSMarginTop (element, tsch, context, ptrT, css, isHTML);
4416: ptrR = SkipBlanksAndComments (ptrR);
4417: if (*ptrR == ';' || *ptrR == '}' || *ptrR == EOS || *ptrR == ',')
1.327 vatton 4418: {
4419: skippedNL = NewLineSkipped;
1.366 vatton 4420: cssRule = ptrR;
4421: /* apply the Margin-Top to all */
4422: ptrR = ParseACSSMarginRight (element, tsch, context, ptrT, css, isHTML);
1.327 vatton 4423: NewLineSkipped = skippedNL;
1.366 vatton 4424: ptrR = ParseACSSMarginBottom (element, tsch, context, ptrT, css, isHTML);
4425: NewLineSkipped = skippedNL;
4426: ptrR = ParseACSSMarginLeft (element, tsch, context, ptrT, css, isHTML);
1.327 vatton 4427: }
1.1 cvs 4428: else
1.327 vatton 4429: {
1.366 vatton 4430: /* parse Margin-Right */
4431: ptrB = ParseACSSMarginRight (element, tsch, context, ptrR, css, isHTML);
4432: ptrB = SkipBlanksAndComments (ptrB);
4433: if (*ptrB == ';' || *ptrB == '}' || *ptrB == EOS || *ptrB == ',')
1.327 vatton 4434: {
1.366 vatton 4435: skippedNL = NewLineSkipped;
4436: cssRule = ptrB;
4437: /* apply the Margin-Top to Margin-Bottom */
4438: ptrB = ParseACSSMarginBottom (element, tsch, context, ptrT, css, isHTML);
4439: NewLineSkipped = skippedNL;
1.327 vatton 4440: /* apply the Margin-Right to Margin-Left */
1.366 vatton 4441: ptrB = ParseACSSMarginLeft (element, tsch, context, ptrR, css, isHTML);
1.327 vatton 4442: }
4443: else
1.366 vatton 4444: {
4445: /* parse Margin-Bottom */
4446: ptrL = ParseACSSMarginBottom (element, tsch, context, ptrB, css, isHTML);
4447: ptrL = SkipBlanksAndComments (ptrL);
4448: if (*ptrL == ';' || *ptrL == '}' || *ptrL == EOS || *ptrL == ',')
4449: {
4450: cssRule = ptrL;
4451: /* apply the Margin-Right to Margin-Left */
4452: ptrL = ParseACSSMarginLeft (element, tsch, context, ptrR, css, isHTML);
4453: }
4454: else
4455: /* parse Margin-Left */
4456: cssRule = ParseACSSMarginLeft (element, tsch, context, ptrL, css, isHTML);
4457: cssRule = SkipBlanksAndComments (cssRule);
4458: }
1.327 vatton 4459: }
1.1 cvs 4460: }
4461: return (cssRule);
4462: }
4463:
4464: /*----------------------------------------------------------------------
1.418 quint 4465: ParseCSSOpacity: parse a CSS opacity property
4466: ----------------------------------------------------------------------*/
4467: static char *ParseCSSOpacity (Element element, PSchema tsch,
4468: PresentationContext context, char *cssRule,
4469: CSSInfoPtr css, ThotBool isHTML)
4470: {
4471: PresentationValue opacity;
4472:
4473: opacity.typed_data.unit = UNIT_INVALID;
4474: opacity.typed_data.real = FALSE;
4475: if (!strncasecmp (cssRule, "inherit", 7))
4476: {
4477: opacity.typed_data.unit = VALUE_INHERIT;
4478: cssRule += 7;
4479: }
4480: else
4481: cssRule = ParseClampedUnit (cssRule, &opacity);
4482: if (DoApply)
4483: /* install the new presentation. */
4484: TtaSetStylePresentation (PROpacity, element, tsch, context, opacity);
4485: return (cssRule);
4486: }
4487:
4488: /*----------------------------------------------------------------------
1.327 vatton 4489: ParseCSSPaddingTop: parse a CSS PaddingTop attribute string
1.1 cvs 4490: ----------------------------------------------------------------------*/
1.79 cvs 4491: static char *ParseCSSPaddingTop (Element element, PSchema tsch,
1.327 vatton 4492: PresentationContext context,
4493: char *cssRule, CSSInfoPtr css,
4494: ThotBool isHTML)
1.1 cvs 4495: {
1.43 cvs 4496: PresentationValue padding;
1.168 vatton 4497: char *ptr;
1.370 vatton 4498:
4499: padding.typed_data.real = FALSE;
1.82 cvs 4500: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 4501: ptr = cssRule;
1.43 cvs 4502: /* first parse the attribute string */
4503: cssRule = ParseCSSUnit (cssRule, &padding);
1.295 vatton 4504:
1.387 quint 4505: if (padding.typed_data.unit == UNIT_INVALID ||
4506: (padding.typed_data.value != 0 &&
1.184 vatton 4507: padding.typed_data.unit == UNIT_BOX))
1.387 quint 4508: CSSParseError ("Invalid padding-top value", ptr, cssRule);
1.366 vatton 4509: else if (DoDialog)
4510: {
4511: if (All_sides)
4512: DisplayStyleValue ("padding", ptr, cssRule);
4513: else
4514: DisplayStyleValue ("padding-top", ptr, cssRule);
4515: }
1.168 vatton 4516: else if (DoApply)
1.295 vatton 4517: TtaSetStylePresentation (PRPaddingTop, element, tsch, context, padding);
1.1 cvs 4518: return (cssRule);
4519: }
4520:
4521: /*----------------------------------------------------------------------
1.59 cvs 4522: ParseCSSPaddingBottom: parse a CSS PaddingBottom attribute string
1.1 cvs 4523: ----------------------------------------------------------------------*/
1.79 cvs 4524: static char *ParseCSSPaddingBottom (Element element, PSchema tsch,
1.327 vatton 4525: PresentationContext context,
4526: char *cssRule, CSSInfoPtr css,
4527: ThotBool isHTML)
1.1 cvs 4528: {
1.43 cvs 4529: PresentationValue padding;
1.168 vatton 4530: char *ptr;
1.43 cvs 4531:
1.370 vatton 4532: padding.typed_data.real = FALSE;
1.82 cvs 4533: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 4534: ptr = cssRule;
1.43 cvs 4535: /* first parse the attribute string */
4536: cssRule = ParseCSSUnit (cssRule, &padding);
1.387 quint 4537: if (padding.typed_data.value == 0 && padding.typed_data.unit != UNIT_INVALID)
1.184 vatton 4538: padding.typed_data.unit = UNIT_EM;
1.295 vatton 4539:
1.387 quint 4540: if (padding.typed_data.unit == UNIT_INVALID ||
4541: (padding.typed_data.value != 0 &&
1.184 vatton 4542: padding.typed_data.unit == UNIT_BOX))
1.387 quint 4543: CSSParseError ("Invalid padding-bottom value", ptr, cssRule);
1.366 vatton 4544: else if (DoDialog)
4545: DisplayStyleValue ("padding-bottom", ptr, cssRule);
1.168 vatton 4546: else if (DoApply)
1.295 vatton 4547: TtaSetStylePresentation (PRPaddingBottom, element, tsch, context, padding);
1.1 cvs 4548: return (cssRule);
4549: }
4550:
4551: /*----------------------------------------------------------------------
1.59 cvs 4552: ParseCSSPaddingLeft: parse a CSS PaddingLeft attribute string.
1.1 cvs 4553: ----------------------------------------------------------------------*/
1.79 cvs 4554: static char *ParseCSSPaddingLeft (Element element, PSchema tsch,
1.327 vatton 4555: PresentationContext context,
4556: char *cssRule, CSSInfoPtr css,
4557: ThotBool isHTML)
1.1 cvs 4558: {
1.43 cvs 4559: PresentationValue padding;
1.168 vatton 4560: char *ptr;
1.43 cvs 4561:
1.370 vatton 4562: padding.typed_data.real = FALSE;
1.82 cvs 4563: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 4564: ptr = cssRule;
1.43 cvs 4565: /* first parse the attribute string */
4566: cssRule = ParseCSSUnit (cssRule, &padding);
1.387 quint 4567: if (padding.typed_data.value == 0 && padding.typed_data.unit != UNIT_INVALID)
1.184 vatton 4568: padding.typed_data.unit = UNIT_EM;
1.295 vatton 4569:
1.387 quint 4570: if (padding.typed_data.unit == UNIT_INVALID ||
4571: (padding.typed_data.value != 0 &&
1.184 vatton 4572: padding.typed_data.unit == UNIT_BOX))
1.168 vatton 4573: {
1.169 vatton 4574: CSSParseError ("Invalid padding-left value", ptr, cssRule);
1.168 vatton 4575: padding.typed_data.value = 0;
4576: }
1.366 vatton 4577: else if (DoDialog)
4578: DisplayStyleValue ("padding-left", ptr, cssRule);
1.168 vatton 4579: else if (DoApply)
1.295 vatton 4580: TtaSetStylePresentation (PRPaddingLeft, element, tsch, context, padding);
1.1 cvs 4581: return (cssRule);
4582: }
4583:
4584: /*----------------------------------------------------------------------
1.59 cvs 4585: ParseCSSPaddingRight: parse a CSS PaddingRight attribute string.
1.1 cvs 4586: ----------------------------------------------------------------------*/
1.79 cvs 4587: static char *ParseCSSPaddingRight (Element element, PSchema tsch,
1.327 vatton 4588: PresentationContext context,
4589: char *cssRule, CSSInfoPtr css,
4590: ThotBool isHTML)
1.1 cvs 4591: {
1.43 cvs 4592: PresentationValue padding;
1.168 vatton 4593: char *ptr;
1.43 cvs 4594:
1.370 vatton 4595: padding.typed_data.real = FALSE;
1.82 cvs 4596: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 4597: ptr = cssRule;
1.43 cvs 4598: /* first parse the attribute string */
4599: cssRule = ParseCSSUnit (cssRule, &padding);
1.387 quint 4600: if (padding.typed_data.value == 0 && padding.typed_data.unit != UNIT_INVALID)
1.184 vatton 4601: padding.typed_data.unit = UNIT_EM;
1.295 vatton 4602:
1.387 quint 4603: if (padding.typed_data.unit == UNIT_INVALID ||
4604: (padding.typed_data.value != 0 &&
1.184 vatton 4605: padding.typed_data.unit == UNIT_BOX))
1.387 quint 4606: CSSParseError ("Invalid padding-right value", ptr, cssRule);
1.366 vatton 4607: else if (DoDialog)
4608: DisplayStyleValue ("padding-right", ptr, cssRule);
1.168 vatton 4609: else if (DoApply)
1.295 vatton 4610: TtaSetStylePresentation (PRPaddingRight, element, tsch, context, padding);
1.1 cvs 4611: return (cssRule);
4612: }
4613:
4614: /*----------------------------------------------------------------------
1.327 vatton 4615: ParseCSSPadding: parse a CSS padding attribute string.
1.1 cvs 4616: ----------------------------------------------------------------------*/
1.79 cvs 4617: static char *ParseCSSPadding (Element element, PSchema tsch,
1.327 vatton 4618: PresentationContext context,
4619: char *cssRule, CSSInfoPtr css,
4620: ThotBool isHTML)
1.1 cvs 4621: {
1.79 cvs 4622: char *ptrT, *ptrR, *ptrB, *ptrL;
1.366 vatton 4623: int skippedNL, n;
1.43 cvs 4624:
1.82 cvs 4625: ptrT = SkipBlanksAndComments (cssRule);
1.366 vatton 4626: if (DoDialog)
4627: n = NumberOfValues (ptrT);
4628: if (DoDialog && n < 2)
1.43 cvs 4629: {
1.366 vatton 4630: // check if the padding dialog must be updated
4631: All_sides = TRUE;
4632: ptrR = ParseCSSPaddingTop (element, tsch, context, ptrT, css, isHTML);
4633: All_sides = FALSE;
1.43 cvs 4634: }
4635: else
4636: {
1.366 vatton 4637: /* First parse Padding-Top */
4638: ptrR = ParseCSSPaddingTop (element, tsch, context, ptrT, css, isHTML);
4639: ptrR = SkipBlanksAndComments (ptrR);
4640: if (*ptrR == ';' || *ptrR == EOS || *ptrR == ',')
1.327 vatton 4641: {
4642: skippedNL = NewLineSkipped;
1.366 vatton 4643: cssRule = ptrR;
4644: /* apply the Padding-Top to all */
4645: ptrR = ParseCSSPaddingRight (element, tsch, context, ptrT, css, isHTML);
1.327 vatton 4646: NewLineSkipped = skippedNL;
1.366 vatton 4647: ptrR = ParseCSSPaddingBottom (element, tsch, context, ptrT, css, isHTML);
4648: NewLineSkipped = skippedNL;
4649: ptrR = ParseCSSPaddingLeft (element, tsch, context, ptrT, css, isHTML);
1.327 vatton 4650: }
1.43 cvs 4651: else
1.327 vatton 4652: {
1.366 vatton 4653: /* parse Padding-Right */
4654: ptrB = ParseCSSPaddingRight (element, tsch, context, ptrR, css, isHTML);
4655: ptrB = SkipBlanksAndComments (ptrB);
4656: if (*ptrB == ';' || *ptrB == EOS || *ptrB == ',')
1.327 vatton 4657: {
1.366 vatton 4658: skippedNL = NewLineSkipped;
4659: cssRule = ptrB;
4660: /* apply the Padding-Top to Padding-Bottom */
4661: ptrB = ParseCSSPaddingBottom (element, tsch, context, ptrT, css, isHTML);
4662: NewLineSkipped = skippedNL;
1.327 vatton 4663: /* apply the Padding-Right to Padding-Left */
1.366 vatton 4664: ptrB = ParseCSSPaddingLeft (element, tsch, context, ptrR, css, isHTML);
1.327 vatton 4665: }
4666: else
1.366 vatton 4667: {
4668: /* parse Padding-Bottom */
4669: ptrL = ParseCSSPaddingBottom (element, tsch, context, ptrB, css, isHTML);
4670: ptrL = SkipBlanksAndComments (ptrL);
4671: if (*ptrL == ';' || *ptrL == EOS || *ptrL == ',')
4672: {
4673: cssRule = ptrL;
4674: /* apply the Padding-Right to Padding-Left */
4675: ptrL = ParseCSSPaddingLeft (element, tsch, context, ptrR, css, isHTML);
4676: }
4677: else
4678: /* parse Padding-Left */
4679: cssRule = ParseCSSPaddingLeft (element, tsch, context, ptrL, css, isHTML);
4680: cssRule = SkipBlanksAndComments (cssRule);
4681: }
1.327 vatton 4682: }
1.43 cvs 4683: }
1.1 cvs 4684: return (cssRule);
4685: }
4686:
4687: /*----------------------------------------------------------------------
1.327 vatton 4688: ParseCSSForeground: parse a CSS foreground attribute
1.1 cvs 4689: ----------------------------------------------------------------------*/
1.79 cvs 4690: static char *ParseCSSForeground (Element element, PSchema tsch,
1.327 vatton 4691: PresentationContext context,
4692: char *cssRule,
4693: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 4694: {
1.425 quint 4695: ElementType elType;
1.117 vatton 4696: PresentationValue best;
1.262 vatton 4697: char *p;
1.1 cvs 4698:
1.370 vatton 4699: best.typed_data.real = FALSE;
1.366 vatton 4700: cssRule = SkipBlanksAndComments (cssRule);
1.262 vatton 4701: p = cssRule;
1.117 vatton 4702: cssRule = ParseCSSColor (cssRule, &best);
1.366 vatton 4703: if (best.typed_data.unit != UNIT_INVALID)
1.327 vatton 4704: {
4705: if (*cssRule != EOS && *cssRule !=';')
4706: {
4707: cssRule = SkipProperty (cssRule, FALSE);
1.366 vatton 4708: CSSParseError ("Invalid color value", p, cssRule);
1.327 vatton 4709: }
1.366 vatton 4710: else if (DoDialog)
4711: DisplayStyleValue ("color", p, cssRule);
4712: else if (DoApply)
1.327 vatton 4713: /* install the new presentation */
1.425 quint 4714: {
4715: elType = TtaGetElementType(element);
4716: if (!strcmp(TtaGetSSchemaName (elType.ElSSchema), "SVG"))
4717: /* we are working for an SVG element */
4718: TtaSetStylePresentation (PRColor, element, tsch, context, best);
4719: else
4720: TtaSetStylePresentation (PRForeground, element, tsch, context,best);
4721: }
1.327 vatton 4722: }
4723: return (cssRule);
1.1 cvs 4724: }
4725:
4726: /*----------------------------------------------------------------------
1.59 cvs 4727: ParseCSSBackgroundColor: parse a CSS background color attribute
1.1 cvs 4728: ----------------------------------------------------------------------*/
1.79 cvs 4729: static char *ParseCSSBackgroundColor (Element element, PSchema tsch,
1.327 vatton 4730: PresentationContext context,
4731: char *cssRule,
4732: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 4733: {
4734: PresentationValue best;
1.366 vatton 4735: char *ptr;
1.1 cvs 4736:
1.370 vatton 4737: best.typed_data.real = FALSE;
1.366 vatton 4738: cssRule = SkipBlanksAndComments (cssRule);
4739: ptr = cssRule;
1.184 vatton 4740: best.typed_data.unit = UNIT_INVALID;
1.1 cvs 4741: best.typed_data.real = FALSE;
1.198 vatton 4742: if (!strncasecmp (cssRule, "transparent", 11))
1.1 cvs 4743: {
1.184 vatton 4744: best.typed_data.value = PATTERN_NONE;
4745: best.typed_data.unit = UNIT_REL;
1.295 vatton 4746: cssRule = SkipWord (cssRule);
1.116 vatton 4747: if (DoApply)
1.327 vatton 4748: TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
4749: }
1.1 cvs 4750: else
4751: {
4752: cssRule = ParseCSSColor (cssRule, &best);
1.366 vatton 4753: if (best.typed_data.unit != UNIT_INVALID)
1.327 vatton 4754: {
1.366 vatton 4755: if (DoDialog)
4756: DisplayStyleValue ("background-color", ptr, cssRule);
4757: else if (DoApply)
4758: {
4759: /* install the new presentation. */
4760: TtaSetStylePresentation (PRBackground, element, tsch, context, best);
4761: /* thot specificity: need to set fill pattern for background color */
4762: best.typed_data.value = PATTERN_BACKGROUND;
4763: best.typed_data.unit = UNIT_REL;
4764: TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
4765: best.typed_data.value = 1;
4766: best.typed_data.unit = UNIT_REL;
4767: TtaSetStylePresentation (PRShowBox, element, tsch, context, best);
4768: }
1.327 vatton 4769: }
1.1 cvs 4770: }
4771: return (cssRule);
4772: }
4773:
1.63 cvs 4774: /*----------------------------------------------------------------------
1.65 cvs 4775: ParseSVGStroke: parse a SVG stroke property
4776: ----------------------------------------------------------------------*/
1.79 cvs 4777: static char *ParseSVGStroke (Element element, PSchema tsch,
1.327 vatton 4778: PresentationContext context, char *cssRule,
4779: CSSInfoPtr css, ThotBool isHTML)
1.65 cvs 4780: {
1.428 quint 4781: PresentationValue best, color;
1.245 quint 4782: char *url;
1.65 cvs 4783:
1.184 vatton 4784: best.typed_data.unit = UNIT_INVALID;
1.65 cvs 4785: best.typed_data.real = FALSE;
1.82 cvs 4786: if (!strncasecmp (cssRule, "none", 4))
1.65 cvs 4787: {
4788: best.typed_data.value = -2; /* -2 means transparent */
1.184 vatton 4789: best.typed_data.unit = UNIT_REL;
1.65 cvs 4790: cssRule = SkipWord (cssRule);
4791: }
1.425 quint 4792: else if (!strncasecmp (cssRule, "inherit", 7))
1.245 quint 4793: {
1.293 quint 4794: best.typed_data.unit = VALUE_INHERIT;
4795: cssRule = SkipWord (cssRule);
1.245 quint 4796: }
1.425 quint 4797: else if (!strncasecmp (cssRule, "currentColor", 12))
4798: {
4799: best.typed_data.unit = VALUE_CURRENT;
4800: cssRule = SkipWord (cssRule);
4801: }
1.245 quint 4802: else if (!strncasecmp (cssRule, "url", 3))
4803: {
4804: cssRule += 3;
4805: cssRule = ParseCSSUrl (cssRule, &url);
4806: /* **** do something with the url ***** */;
4807: TtaFreeMemory (url);
1.428 quint 4808: /* a color property may follow the url */
4809: cssRule = SkipBlanksAndComments (cssRule);
4810: if (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS &&
4811: *cssRule != ',')
4812: /* we expect a color property here */
4813: {
4814: cssRule = ParseCSSColor (cssRule, &color);
4815: /* ***** do something with the color we have just parsed */
4816: }
1.245 quint 4817: }
1.65 cvs 4818: else
1.293 quint 4819: cssRule = ParseCSSColor (cssRule, &best);
4820:
4821: if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.295 vatton 4822: /* install the new presentation */
4823: TtaSetStylePresentation (PRForeground, element, tsch, context, best);
1.65 cvs 4824: return (cssRule);
4825: }
4826:
4827: /*----------------------------------------------------------------------
1.63 cvs 4828: ParseSVGFill: parse a SVG fill property
4829: ----------------------------------------------------------------------*/
1.79 cvs 4830: static char *ParseSVGFill (Element element, PSchema tsch,
1.327 vatton 4831: PresentationContext context, char *cssRule,
4832: CSSInfoPtr css, ThotBool isHTML)
1.63 cvs 4833: {
1.428 quint 4834: PresentationValue fill, color;
1.245 quint 4835: char *url;
1.429 quint 4836: int pattern;
1.63 cvs 4837:
1.426 quint 4838: url = NULL;
1.428 quint 4839: fill.typed_data.unit = UNIT_INVALID;
4840: fill.typed_data.real = FALSE;
1.429 quint 4841: pattern = PATTERN_BACKGROUND;
1.82 cvs 4842: if (!strncasecmp (cssRule, "none", 4))
1.63 cvs 4843: {
1.429 quint 4844: pattern = PATTERN_NONE;
4845: fill.typed_data.value = -2;
1.428 quint 4846: fill.typed_data.unit = UNIT_REL;
1.65 cvs 4847: cssRule = SkipWord (cssRule);
1.63 cvs 4848: }
1.425 quint 4849: else if (!strncasecmp (cssRule, "currentColor", 12))
4850: {
1.428 quint 4851: fill.typed_data.unit = VALUE_CURRENT;
1.425 quint 4852: cssRule = SkipWord (cssRule);
4853: }
1.245 quint 4854: else if (!strncasecmp (cssRule, "url", 3))
4855: {
4856: cssRule += 3;
4857: cssRule = ParseCSSUrl (cssRule, &url);
1.428 quint 4858: fill.typed_data.unit = VALUE_URL;
4859: fill.pointer = url;
4860: /* a color property may follow the url */
4861: cssRule = SkipBlanksAndComments (cssRule);
4862: if (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS &&
4863: *cssRule != ',')
4864: /* we expect a color property here */
4865: {
4866: cssRule = ParseCSSColor (cssRule, &color);
4867: /* @@@@@@ do something with the color we have just parsed */
4868: }
4869: }
4870: else if (!strncasecmp (cssRule, "inherit", 7))
4871: {
4872: fill.typed_data.unit = VALUE_INHERIT;
4873: cssRule = SkipWord (cssRule);
1.245 quint 4874: }
1.63 cvs 4875: else
1.428 quint 4876: cssRule = ParseCSSColor (cssRule, &fill);
1.293 quint 4877:
1.428 quint 4878: if (fill.typed_data.unit != UNIT_INVALID && DoApply)
1.63 cvs 4879: {
1.293 quint 4880: /* install the new presentation. */
1.428 quint 4881: TtaSetStylePresentation (PRBackground, element, tsch, context, fill);
1.426 quint 4882: if (url)
4883: TtaFreeMemory (url);
1.293 quint 4884: /* thot specificity: need to set fill pattern for background color */
1.429 quint 4885: fill.typed_data.value = pattern;
1.428 quint 4886: fill.typed_data.unit = UNIT_REL;
4887: TtaSetStylePresentation (PRFillPattern, element, tsch, context, fill);
1.63 cvs 4888: }
4889: return (cssRule);
4890: }
1.161 quint 4891:
1.155 cheyroul 4892: /*----------------------------------------------------------------------
1.424 quint 4893: ParseSVGStopColor: parse a SVG stop-color property
4894: ----------------------------------------------------------------------*/
4895: static char *ParseSVGStopColor (Element element, PSchema tsch,
4896: PresentationContext context, char *cssRule,
4897: CSSInfoPtr css, ThotBool isHTML)
4898: {
1.425 quint 4899: PresentationValue best;
4900:
4901: best.typed_data.unit = UNIT_INVALID;
4902: best.typed_data.real = FALSE;
4903: if (!strncasecmp (cssRule, "inherit", 7))
4904: {
4905: best.typed_data.unit = VALUE_INHERIT;
4906: cssRule = SkipWord (cssRule);
4907: }
4908: else if (!strncasecmp (cssRule, "currentColor", 12))
4909: {
4910: best.typed_data.unit = VALUE_CURRENT;
4911: cssRule = SkipWord (cssRule);
4912: }
4913: else
4914: cssRule = ParseCSSColor (cssRule, &best);
4915:
4916: if (best.typed_data.unit != UNIT_INVALID && DoApply)
4917: /* install the new presentation */
4918: TtaSetStylePresentation (PRStopColor, element, tsch, context, best);
4919: return (cssRule);
4920: }
4921:
4922: /*----------------------------------------------------------------------
1.427 quint 4923: ParseCSSColor: parse a CSS color attribute string
4924: we expect the input string describing the attribute to be
4925: either a color name, a 3 tuple or an hexadecimal encoding.
4926: The color used will be approximed from the current color
4927: table
4928: ----------------------------------------------------------------------*/
1.430 vatton 4929: static char *ParseSVGMarkerValue (char *cssRule, PresentationValue *val, char **url)
1.427 quint 4930: {
1.430 vatton 4931: *url = NULL;
1.427 quint 4932: val->typed_data.unit = UNIT_INVALID;
4933: val->typed_data.real = FALSE;
4934: if (!strncasecmp (cssRule, "none", 4))
4935: {
4936: val->typed_data.unit = UNIT_REL;
4937: val->typed_data.value = 0;
4938: cssRule += 4;
4939: }
4940: else if (!strncasecmp (cssRule, "inherit", 7))
4941: {
4942: val->typed_data.unit = VALUE_INHERIT;
4943: cssRule += 7;
4944: }
4945: else if (!strncasecmp (cssRule, "url", 3))
4946: {
4947: cssRule += 3;
1.430 vatton 4948: cssRule = ParseCSSUrl (cssRule, url);
1.427 quint 4949: val->typed_data.unit = VALUE_URL;
1.430 vatton 4950: val->pointer = *url;
1.427 quint 4951: }
4952: return cssRule;
4953: }
4954:
4955: /*----------------------------------------------------------------------
4956: ParseSVGMarker: parse a SVG marker property
4957: ----------------------------------------------------------------------*/
4958: static char *ParseSVGMarker (Element element, PSchema tsch,
4959: PresentationContext context, char *cssRule,
4960: CSSInfoPtr css, ThotBool isHTML)
4961: {
4962: PresentationValue marker;
4963: char *url;
4964:
4965: url = NULL;
1.430 vatton 4966: cssRule = ParseSVGMarkerValue (cssRule, &marker, &url);
1.427 quint 4967: if (marker.typed_data.unit != UNIT_INVALID && DoApply)
4968: /* install the new presentation. */
4969: TtaSetStylePresentation (PRMarker, element, tsch, context, marker);
4970: if (url)
4971: TtaFreeMemory (url);
4972: return (cssRule);
4973: }
4974:
4975: /*----------------------------------------------------------------------
4976: ParseSVGMarkerEnd: parse a SVG marker-end property
4977: ----------------------------------------------------------------------*/
4978: static char *ParseSVGMarkerEnd (Element element, PSchema tsch,
4979: PresentationContext context, char *cssRule,
4980: CSSInfoPtr css, ThotBool isHTML)
4981: {
4982: PresentationValue marker;
4983: char *url;
4984:
4985: url = NULL;
1.430 vatton 4986: cssRule = ParseSVGMarkerValue (cssRule, &marker, &url);
1.427 quint 4987: if (marker.typed_data.unit != UNIT_INVALID && DoApply)
4988: /* install the new presentation. */
4989: TtaSetStylePresentation (PRMarkerEnd, element, tsch, context, marker);
4990: if (url)
4991: TtaFreeMemory (url);
4992: return (cssRule);
4993: }
4994:
4995: /*----------------------------------------------------------------------
4996: ParseSVGMarkerMid: parse a SVG marker-mid property
4997: ----------------------------------------------------------------------*/
4998: static char *ParseSVGMarkerMid (Element element, PSchema tsch,
4999: PresentationContext context, char *cssRule,
5000: CSSInfoPtr css, ThotBool isHTML)
5001: {
5002: PresentationValue marker;
5003: char *url;
5004:
5005: url = NULL;
1.430 vatton 5006: cssRule = ParseSVGMarkerValue (cssRule, &marker, &url);
1.427 quint 5007: if (marker.typed_data.unit != UNIT_INVALID && DoApply)
5008: /* install the new presentation. */
5009: TtaSetStylePresentation (PRMarkerMid, element, tsch, context, marker);
5010: if (url)
5011: TtaFreeMemory (url);
5012: return (cssRule);
5013: }
5014:
5015: /*----------------------------------------------------------------------
5016: ParseSVGMarkerStart: parse a SVG marker-start property
5017: ----------------------------------------------------------------------*/
5018: static char *ParseSVGMarkerStart (Element element, PSchema tsch,
5019: PresentationContext context, char *cssRule,
5020: CSSInfoPtr css, ThotBool isHTML)
5021: {
5022: PresentationValue marker;
5023: char *url;
5024:
5025: url = NULL;
1.430 vatton 5026: cssRule = ParseSVGMarkerValue (cssRule, &marker, &url);
1.427 quint 5027: if (marker.typed_data.unit != UNIT_INVALID && DoApply)
5028: /* install the new presentation. */
5029: TtaSetStylePresentation (PRMarkerStart, element, tsch, context, marker);
5030: if (url)
5031: TtaFreeMemory (url);
5032: return (cssRule);
5033: }
5034:
5035: /*----------------------------------------------------------------------
1.425 quint 5036: ParseSVGStopOpacity: parse a SVG opacity property
5037: ----------------------------------------------------------------------*/
5038: static char *ParseSVGStopOpacity (Element element, PSchema tsch,
5039: PresentationContext context, char *cssRule,
5040: CSSInfoPtr css, ThotBool isHTML)
5041: {
5042: PresentationValue opacity;
5043:
5044: opacity.typed_data.unit = UNIT_INVALID;
5045: opacity.typed_data.real = FALSE;
5046: if (!strncasecmp (cssRule, "inherit", 7))
5047: {
5048: opacity.typed_data.unit = VALUE_INHERIT;
5049: cssRule += 7;
5050: }
5051: else
5052: cssRule = ParseClampedUnit (cssRule, &opacity);
5053: if (opacity.typed_data.unit != UNIT_INVALID && DoApply)
5054: /* install the new presentation. */
5055: TtaSetStylePresentation (PRStopOpacity, element, tsch, context, opacity);
1.424 quint 5056: return (cssRule);
5057: }
5058:
5059: /*----------------------------------------------------------------------
1.346 quint 5060: ParseSVGOpacity: parse a SVG opacity property
1.155 cheyroul 5061: ----------------------------------------------------------------------*/
5062: static char *ParseSVGOpacity (Element element, PSchema tsch,
1.327 vatton 5063: PresentationContext context, char *cssRule,
5064: CSSInfoPtr css, ThotBool isHTML)
1.155 cheyroul 5065: {
1.425 quint 5066: PresentationValue opacity;
1.63 cvs 5067:
1.425 quint 5068: opacity.typed_data.unit = UNIT_INVALID;
5069: opacity.typed_data.real = FALSE;
5070: if (!strncasecmp (cssRule, "inherit", 7))
5071: {
5072: opacity.typed_data.unit = VALUE_INHERIT;
5073: cssRule += 7;
5074: }
5075: else
5076: cssRule = ParseClampedUnit (cssRule, &opacity);
5077: if (opacity.typed_data.unit != UNIT_INVALID && DoApply)
1.295 vatton 5078: /* install the new presentation. */
1.425 quint 5079: TtaSetStylePresentation (PROpacity, element, tsch, context, opacity);
1.155 cheyroul 5080: return (cssRule);
5081: }
1.346 quint 5082:
1.170 cheyroul 5083: /*----------------------------------------------------------------------
1.346 quint 5084: ParseSVGStrokeOpacity: parse a SVG stroke-opacity property
1.170 cheyroul 5085: ----------------------------------------------------------------------*/
5086: static char *ParseSVGStrokeOpacity (Element element, PSchema tsch,
1.327 vatton 5087: PresentationContext context, char *cssRule,
5088: CSSInfoPtr css, ThotBool isHTML)
1.170 cheyroul 5089: {
1.425 quint 5090: PresentationValue opacity;
1.161 quint 5091:
1.425 quint 5092: opacity.typed_data.unit = UNIT_INVALID;
5093: opacity.typed_data.real = FALSE;
5094: if (!strncasecmp (cssRule, "inherit", 7))
5095: {
5096: opacity.typed_data.unit = VALUE_INHERIT;
5097: cssRule += 7;
5098: }
5099: else
5100: cssRule = ParseClampedUnit (cssRule, &opacity);
5101: if (opacity.typed_data.unit != UNIT_INVALID && DoApply)
1.295 vatton 5102: /* install the new presentation. */
1.425 quint 5103: TtaSetStylePresentation (PRStrokeOpacity, element, tsch, context, opacity);
1.170 cheyroul 5104: return (cssRule);
5105: }
1.346 quint 5106:
1.170 cheyroul 5107: /*----------------------------------------------------------------------
1.420 vatton 5108: ParseSVGFillOpacity: parse a SVG fill-opacityl property
1.170 cheyroul 5109: ----------------------------------------------------------------------*/
5110: static char *ParseSVGFillOpacity (Element element, PSchema tsch,
1.327 vatton 5111: PresentationContext context, char *cssRule,
5112: CSSInfoPtr css, ThotBool isHTML)
1.170 cheyroul 5113: {
1.425 quint 5114: PresentationValue opacity;
1.170 cheyroul 5115:
1.425 quint 5116: opacity.typed_data.unit = UNIT_INVALID;
5117: opacity.typed_data.real = FALSE;
5118: if (!strncasecmp (cssRule, "inherit", 7))
5119: {
5120: opacity.typed_data.unit = VALUE_INHERIT;
5121: cssRule += 7;
5122: }
5123: else
5124: cssRule = ParseClampedUnit (cssRule, &opacity);
5125: if (opacity.typed_data.unit != UNIT_INVALID && DoApply)
1.295 vatton 5126: /* install the new presentation. */
1.425 quint 5127: TtaSetStylePresentation (PRFillOpacity, element, tsch, context, opacity);
1.170 cheyroul 5128: return (cssRule);
5129: }
1.207 vatton 5130:
1.1 cvs 5131: /*----------------------------------------------------------------------
1.420 vatton 5132: ParseSVGFillRule: parse a SVG fill-rule property
5133: ----------------------------------------------------------------------*/
5134: static char *ParseSVGFillRule (Element element, PSchema tsch,
5135: PresentationContext context, char *cssRule,
5136: CSSInfoPtr css, ThotBool isHTML)
5137: {
5138: PresentationValue best;
5139:
5140: best.typed_data.unit = UNIT_INVALID;
5141: best.typed_data.real = FALSE;
5142: if (!strncasecmp (cssRule, "inherit", 7))
5143: {
5144: best.typed_data.unit = VALUE_INHERIT;
5145: best.typed_data.value = 0;
5146: cssRule = SkipWord (cssRule);
5147: }
5148: else if (!strncasecmp (cssRule, "nonzero", 7))
5149: {
5150: best.typed_data.unit = VALUE_AUTO;
1.421 quint 5151: best.typed_data.value = NonZero;
1.420 vatton 5152: cssRule = SkipWord (cssRule);
5153: }
5154: else if (!strncasecmp (cssRule, "evenodd", 7))
5155: {
5156: best.typed_data.unit = VALUE_AUTO;
1.421 quint 5157: best.typed_data.value = EvenOdd;
1.420 vatton 5158: cssRule = SkipWord (cssRule);
5159: }
5160:
5161: if (DoApply)
5162: /* install the new presentation. */
5163: TtaSetStylePresentation (PRFillRule, element, tsch, context, best);
5164: return (cssRule);
5165: }
5166:
5167: /*----------------------------------------------------------------------
1.327 vatton 5168: GetCSSBackgroundURL searches a CSS BackgroundImage url within
5169: the cssRule.
5170: Returns NULL or a new allocated url string.
1.217 vatton 5171: ----------------------------------------------------------------------*/
5172: char *GetCSSBackgroundURL (char *cssRule)
5173: {
5174: char *b, *url;
5175:
5176: url = NULL;
5177: b = strstr (cssRule, "url");
5178: if (b)
1.290 gully 5179: b = ParseCSSUrl (b, &url);
1.217 vatton 5180: return (url);
5181: }
5182:
5183: /*----------------------------------------------------------------------
1.327 vatton 5184: ParseCSSContent: parse the value of property "content"
1.217 vatton 5185: ----------------------------------------------------------------------*/
5186: static char *ParseCSSContent (Element element, PSchema tsch,
1.327 vatton 5187: PresentationContext ctxt, char *cssRule,
5188: CSSInfoPtr css, ThotBool isHTML)
1.217 vatton 5189: {
1.436 quint 5190: PresentationValue value, pval;
1.353 quint 5191: char *last, *start, quoteChar, savedChar;
1.437 quint 5192: int length, val, l;
1.366 vatton 5193: char *buffer, *p;
5194: char *start_value;
1.434 quint 5195: wchar_t wc;
5196: ThotBool repeat, done;
1.312 quint 5197:
5198: value.typed_data.unit = UNIT_REL;
5199: value.typed_data.real = FALSE;
5200: value.typed_data.value = 0;
1.366 vatton 5201: if (!DoDialog && DoApply)
1.347 quint 5202: TtaSetStylePresentation (PRContent, element, tsch, ctxt, value);
1.217 vatton 5203: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 5204: start_value = cssRule;
1.312 quint 5205: repeat = TRUE;
5206: while (repeat)
5207: {
1.366 vatton 5208: p = cssRule;
1.312 quint 5209: if (!strncasecmp (cssRule, "normal", 6))
1.327 vatton 5210: /* The pseudo-element is not generated */
5211: {
5212: /* @@@@@@ */
5213: cssRule += 6;
5214: repeat = FALSE;
5215: }
1.331 quint 5216: else if (!strncasecmp (cssRule, "none", 4))
5217: /* The pseudo-element is not generated */
5218: {
5219: /* @@@@@@ */
5220: cssRule += 4;
5221: repeat = FALSE;
5222: }
1.312 quint 5223: else if (*cssRule == '"' || *cssRule == '\'')
1.327 vatton 5224: /* It's a string */
5225: {
5226: quoteChar = *cssRule;
1.353 quint 5227: /* how long is the string? */
1.437 quint 5228: last = SkipString (cssRule);
1.353 quint 5229: length = last - cssRule;
5230: /* get a buffer to store the string */
1.434 quint 5231: buffer = (char *)TtaGetMemory (3 * length);
1.353 quint 5232: p = buffer; /* beginning of the string */
1.327 vatton 5233: cssRule++;
1.437 quint 5234:
1.438 ! quint 5235: if (ctxt->cssURL)
! 5236: /* it's an external style sheet. Assume it is encoded in the
! 5237: default encoding (iso-latin-1), but we should use the actual
! 5238: encoding of the file @@@@ */
! 5239: l = TtaGetNextWCFromString (&wc, (unsigned char **) &cssRule,
! 5240: ISO_8859_1);
! 5241: else
! 5242: /* it's the content of a <style> element. It is encoded in UTF-8 */
! 5243: l = TtaGetNextWCFromString (&wc, (unsigned char **) &cssRule,
! 5244: UTF_8);
1.437 quint 5245: while (wc != EOS && wc != quoteChar && l > 0)
1.353 quint 5246: {
1.434 quint 5247: done = FALSE;
1.437 quint 5248: if (wc == '\\')
1.353 quint 5249: {
5250: cssRule++; /* skip the backslash */
5251: if ((*cssRule >= '0' && *cssRule <= '9') ||
5252: (*cssRule >= 'A' && *cssRule <= 'F') ||
5253: (*cssRule >= 'a' && *cssRule <= 'f'))
5254: {
5255: start = cssRule; /* first hex digit after the backslash*/
5256: cssRule++;
5257: while ((*cssRule >= '0' && *cssRule <= '9') ||
5258: (*cssRule >= 'A' && *cssRule <= 'F') ||
5259: (*cssRule >= 'a' && *cssRule <= 'f'))
5260: cssRule++;
5261: savedChar = *cssRule;
5262: *cssRule = EOS;
5263: sscanf (start, "%x", &val);
1.366 vatton 5264: TtaWCToMBstring ((wchar_t) val, (unsigned char **) &p);
1.353 quint 5265: *cssRule = savedChar;
1.437 quint 5266: wc = savedChar;
1.434 quint 5267: done = TRUE;
1.353 quint 5268: }
5269: }
1.434 quint 5270: if (!done)
1.353 quint 5271: {
1.434 quint 5272: TtaWCToMBstring (wc, (unsigned char **) &p);
1.437 quint 5273: cssRule+= l;
1.438 ! quint 5274: if (ctxt->cssURL)
! 5275: /* it's an external style sheet. Assume it is encoded in
! 5276: the default encoding (iso-latin-1), but we should use
! 5277: the actual encoding of the file @@@@ */
! 5278: l = TtaGetNextWCFromString (&wc, (unsigned char **)&cssRule,
! 5279: ISO_8859_1);
! 5280: else
! 5281: /* it's the content of a <style> element. It is encoded
! 5282: in UTF-8 */
! 5283: l = TtaGetNextWCFromString (&wc, (unsigned char **)&cssRule,
! 5284: UTF_8);
1.353 quint 5285: }
5286: }
5287: *p = EOS;
1.366 vatton 5288: if (DoDialog)
5289: {
5290: DisplayStyleValue ("", start_value, p);
5291: start_value = p;
5292: }
5293: else if (*cssRule != quoteChar)
1.327 vatton 5294: cssRule = SkipProperty (cssRule, FALSE);
5295: else
5296: {
5297: *cssRule = EOS;
5298: value.typed_data.unit = UNIT_REL;
5299: value.typed_data.real = FALSE;
1.353 quint 5300: value.pointer = buffer;
1.347 quint 5301: if (DoApply)
5302: TtaSetStylePresentation (PRContentString, element, tsch, ctxt,
5303: value);
1.327 vatton 5304: *cssRule = quoteChar;
5305: cssRule++;
5306: }
1.353 quint 5307: TtaFreeMemory (buffer);
1.327 vatton 5308: }
1.312 quint 5309: else if (!strncasecmp (cssRule, "url", 3))
1.327 vatton 5310: {
5311: cssRule += 3;
1.347 quint 5312: cssRule = SetCSSImage (element, tsch, ctxt, cssRule, css,
5313: PRContentURL);
1.366 vatton 5314: if (DoDialog)
5315: {
5316: DisplayStyleValue ("", start_value, p);
5317: start_value = p;
5318: }
1.327 vatton 5319: }
1.312 quint 5320: else if (!strncasecmp (cssRule, "counter", 7))
1.327 vatton 5321: {
1.436 quint 5322: value.pointer = NULL;
1.327 vatton 5323: cssRule += 7;
1.436 quint 5324: cssRule = SkipBlanksAndComments (cssRule);
5325: if (*cssRule == '(')
5326: {
5327: cssRule++;
5328: cssRule = SkipBlanksAndComments (cssRule);
5329: start = cssRule;
5330: while (*cssRule != EOS && *cssRule != ')' && *cssRule != ',')
5331: cssRule++;
5332: if (*cssRule != ')' && *cssRule != ',')
5333: cssRule = start;
5334: else
5335: {
5336: /* remove extra spaces */
5337: last = cssRule;
5338: while (last[-1] == SPACE || last[-1] == TAB)
5339: last--;
5340: savedChar = *last;
5341: *last = EOS;
5342: value.pointer = start;
5343: if (DoDialog)
5344: {
5345: DisplayStyleValue ("", start_value, p);
5346: start_value = p;
5347: }
5348: else if (DoApply)
5349: TtaSetStylePresentation (PRContentCounter, element, tsch,
5350: ctxt, value);
5351: *last = savedChar;
5352: if (*cssRule == ',')
5353: /* parse the counter style */
5354: {
5355: cssRule++;
5356: cssRule = ParseCounterStyle (cssRule, &pval, start_value);
5357: cssRule = SkipBlanksAndComments (cssRule);
5358: if (*cssRule == ')')
5359: {
5360: cssRule++;
5361: TtaSetStylePresentation (PRContentCounterStyle,
5362: element, tsch, ctxt, pval);
5363: }
5364: }
5365: }
5366: }
5367: if (value.pointer == NULL)
1.366 vatton 5368: {
1.436 quint 5369: CSSParseError ("Invalid content value", (char*) p, cssRule);
5370: if (DoDialog)
5371: {
5372: DisplayStyleValue ("", start_value, p);
5373: start_value = p;
5374: }
5375: else
5376: cssRule = SkipProperty (cssRule, FALSE);
1.366 vatton 5377: }
1.436 quint 5378: cssRule++;
1.327 vatton 5379: }
1.312 quint 5380: else if (!strncasecmp (cssRule, "counters", 8))
1.327 vatton 5381: {
5382: cssRule += 8;
5383: /* @@@@@@ */
1.366 vatton 5384: if (DoDialog)
5385: {
5386: DisplayStyleValue ("", start_value, p);
5387: start_value = p;
5388: }
5389: else
1.436 quint 5390: {
5391: cssRule = SkipProperty (cssRule, FALSE);
5392: }
1.327 vatton 5393: }
1.312 quint 5394: else if (!strncasecmp (cssRule, "attr", 4))
1.327 vatton 5395: {
1.347 quint 5396: value.pointer = NULL;
1.327 vatton 5397: cssRule += 4;
1.347 quint 5398: cssRule = SkipBlanksAndComments (cssRule);
5399: if (*cssRule == '(')
5400: {
5401: cssRule++;
5402: cssRule = SkipBlanksAndComments (cssRule);
5403: start = cssRule;
5404: while (*cssRule != EOS && *cssRule != ')')
5405: cssRule++;
5406: if (*cssRule != ')')
5407: cssRule = start;
5408: else
5409: {
5410: last = cssRule;
5411: /* remove extra spaces */
1.436 quint 5412: while (last[-1] == SPACE || last[-1] == TAB)
5413: last--;
1.347 quint 5414: savedChar = *last;
5415: *last = EOS;
5416: value.typed_data.unit = UNIT_REL;
5417: value.typed_data.real = FALSE;
5418: value.pointer = start;
1.366 vatton 5419: if (DoDialog)
5420: {
5421: DisplayStyleValue ("", start_value, p);
5422: start_value = p;
5423: }
5424: else if (DoApply)
1.347 quint 5425: TtaSetStylePresentation (PRContentAttr, element, tsch,
5426: ctxt, value);
5427: *last = savedChar;
5428: }
5429: }
5430: if (value.pointer == NULL)
5431: {
1.353 quint 5432: CSSParseError ("Invalid content value", (char*) p, cssRule);
1.366 vatton 5433: if (DoDialog)
5434: {
5435: DisplayStyleValue ("", start_value, p);
5436: start_value = p;
5437: }
5438: else
5439: cssRule = SkipProperty (cssRule, FALSE);
1.347 quint 5440: }
5441: cssRule++;
1.327 vatton 5442: }
1.312 quint 5443: else if (!strncasecmp (cssRule, "open-quote", 10))
1.327 vatton 5444: {
5445: cssRule += 10;
5446: /* @@@@@@ */
5447: }
1.312 quint 5448: else if (!strncasecmp (cssRule, "close-quote", 11))
1.327 vatton 5449: {
5450: cssRule += 11;
5451: /* @@@@@@ */
5452: }
1.312 quint 5453: else if (!strncasecmp (cssRule, "no-open-quote", 13))
1.327 vatton 5454: {
5455: cssRule += 13;
5456: /* @@@@@@ */
5457: }
1.312 quint 5458: else if (!strncasecmp (cssRule, "no-close-quote", 14))
1.327 vatton 5459: {
5460: cssRule += 14;
5461: /* @@@@@@ */
5462: }
1.312 quint 5463: else if (!strncasecmp (cssRule, "inherit", 7))
1.327 vatton 5464: {
5465: cssRule += 7;
5466: /* @@@@@@ */
5467: repeat = FALSE;
5468: }
1.312 quint 5469: else
1.327 vatton 5470: {
1.353 quint 5471: CSSParseError ("Invalid content value", (char*) p, cssRule);
1.366 vatton 5472: if (DoDialog)
5473: {
5474: DisplayStyleValue ("", start_value, p);
5475: start_value = p;
5476: }
5477: else
5478: cssRule = SkipProperty (cssRule, FALSE);
1.327 vatton 5479: }
1.312 quint 5480: cssRule = SkipBlanksAndComments (cssRule);
5481: if (repeat)
1.327 vatton 5482: if (*cssRule == ';' || *cssRule == '}' || *cssRule == EOS ||
5483: *cssRule == '!')
5484: repeat = FALSE;
1.217 vatton 5485: }
5486: return (cssRule);
5487: }
1.1 cvs 5488:
5489: /*----------------------------------------------------------------------
1.436 quint 5490: ParseCSSCounterOp: parse a CSS counter operation (increment or reset,
5491: depending on type).
5492: ----------------------------------------------------------------------*/
5493: static char *ParseCSSCounterOp (Element element, PSchema tsch,
5494: PresentationContext ctxt,
5495: char *cssRule, unsigned int type)
5496: {
5497: PresentationValue pval;
5498: char *start, *start_value, *p, *buff;
5499: char saved;
5500:
5501: cssRule = SkipBlanksAndComments (cssRule);
5502: if (!strncasecmp (cssRule, "inherit", 7))
5503: {
5504: pval.typed_data.unit = VALUE_INHERIT;
5505: cssRule += 7;
5506: /* @@@@ do something */
5507: }
5508: else if (!strncasecmp (cssRule, "none", 4))
5509: {
5510: pval.typed_data.value = 0;
5511: cssRule += 4;
5512: /* @@@@ do something */
5513: }
5514: else
5515: {
5516: start_value = cssRule;
5517: /* there may be multiple counter names (each possibly followed by an
5518: integer) */
5519: do
5520: {
5521: p = cssRule;
5522: /* name of a counter */
5523: start = cssRule;
5524: cssRule = SkipWord (cssRule);
5525: saved = *cssRule;
5526: *cssRule = EOS;
5527: buff = TtaStrdup (start);
5528: *cssRule = saved;
5529: pval.pointer = buff;
5530: /* set default value of parameter */
5531: if (type == PRCounterReset)
5532: pval.data = 0;
5533: else if (type == PRCounterIncrement)
5534: pval.data = 1;
5535: /* use the actual value of parameter (integer) if it is specified */
5536: cssRule = ParseNumber (cssRule, &pval);
5537: if (pval.typed_data.unit != UNIT_INVALID)
5538: /* there is an integer, the value of the parameter */
5539: {
5540: pval.data = pval.typed_data.value;
5541: cssRule = SkipBlanksAndComments (cssRule);
5542: }
5543: if (DoDialog)
5544: {
5545: DisplayStyleValue ("", start_value, p);
5546: start_value = p;
5547: }
5548: else if (DoApply)
5549: TtaSetStylePresentation (type, element, tsch, ctxt, pval);
5550: TtaFreeMemory (buff);
5551: }
5552: while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS &&
5553: *cssRule != ',');
5554: }
5555: cssRule = SkipBlanksAndComments (cssRule);
5556: return (cssRule);
5557: }
5558:
5559: /*----------------------------------------------------------------------
5560: ParseCSSCounterIncrement: parse a CSS counter-increment property
5561: ----------------------------------------------------------------------*/
5562: static char *ParseCSSCounterIncrement (Element element, PSchema tsch,
5563: PresentationContext ctxt,
5564: char *cssRule, CSSInfoPtr css,
5565: ThotBool isHTML)
5566: {
5567: return ParseCSSCounterOp (element, tsch, ctxt, cssRule, PRCounterIncrement);
5568: }
5569:
5570: /*----------------------------------------------------------------------
5571: ParseCSSCounterReset: parse a CSS counter-reset property
5572: ----------------------------------------------------------------------*/
5573: static char *ParseCSSCounterReset (Element element, PSchema tsch,
5574: PresentationContext ctxt,
5575: char *cssRule, CSSInfoPtr css,
5576: ThotBool isHTML)
5577: {
5578: return ParseCSSCounterOp (element, tsch, ctxt, cssRule, PRCounterReset);
5579: }
5580:
5581: /*----------------------------------------------------------------------
1.59 cvs 5582: ParseCSSBackgroundImage: parse a CSS BackgroundImage attribute string.
1.1 cvs 5583: ----------------------------------------------------------------------*/
1.79 cvs 5584: static char *ParseCSSBackgroundImage (Element element, PSchema tsch,
1.327 vatton 5585: PresentationContext ctxt,
5586: char *cssRule, CSSInfoPtr css,
5587: ThotBool isHTML)
1.1 cvs 5588: {
1.49 cvs 5589: PresentationValue image, value;
1.357 quint 5590: char *ptr;
1.148 vatton 5591:
1.370 vatton 5592: image.typed_data.real = FALSE;
5593: value.typed_data.real = FALSE;
1.82 cvs 5594: cssRule = SkipBlanksAndComments (cssRule);
1.357 quint 5595: ptr = cssRule;
1.161 quint 5596: if (!strncasecmp (cssRule, "none", 4))
5597: {
1.260 vatton 5598: cssRule += 4;
1.366 vatton 5599: if (DoDialog)
5600: DisplayStyleValue ("background-image", ptr, cssRule);
5601: else if (DoApply)
1.327 vatton 5602: {
5603: /* no background image */
5604: image.pointer = NULL;
5605: TtaSetStylePresentation (PRBackgroundPicture, element, tsch, ctxt,
5606: image);
5607: }
1.161 quint 5608: }
1.357 quint 5609: else if (!strncasecmp (cssRule, "inherit", 7))
5610: {
5611: value.typed_data.unit = VALUE_INHERIT;
5612: cssRule += 7;
1.366 vatton 5613: if (DoDialog)
5614: DisplayStyleValue ("background-image", ptr, cssRule);
1.357 quint 5615: }
1.161 quint 5616: else if (!strncasecmp (cssRule, "url", 3))
1.1 cvs 5617: {
5618: cssRule += 3;
1.302 quint 5619: cssRule = SetCSSImage (element, tsch, ctxt, cssRule, css,
1.327 vatton 5620: PRBackgroundPicture);
1.207 vatton 5621: if (ctxt->destroy)
1.327 vatton 5622: if (TtaGetStylePresentation (PRFillPattern, element, tsch, ctxt,
5623: &value) < 0)
5624: {
5625: /* there is no FillPattern rule -> remove ShowBox rule */
5626: value.typed_data.value = 1;
5627: value.typed_data.unit = UNIT_REL;
5628: value.typed_data.real = FALSE;
5629: TtaSetStylePresentation (PRShowBox, element, tsch, ctxt, value);
5630: }
1.18 cvs 5631: }
1.357 quint 5632: else
5633: {
5634: cssRule = SkipWord (cssRule);
5635: CSSParseError ("Invalid background-image value", ptr, cssRule);
5636: cssRule = SkipProperty (cssRule, FALSE);
5637: }
1.18 cvs 5638: return (cssRule);
5639: }
5640:
5641: /*----------------------------------------------------------------------
1.295 vatton 5642: ParseACSSBackgroundRepeat: parse a CSS BackgroundRepeat attribute string.
1.18 cvs 5643: ----------------------------------------------------------------------*/
1.295 vatton 5644: static char *ParseACSSBackgroundRepeat (Element element, PSchema tsch,
1.327 vatton 5645: PresentationContext ctxt,
5646: char *cssRule, CSSInfoPtr css, ThotBool isHTML)
1.18 cvs 5647: {
5648: PresentationValue repeat;
1.366 vatton 5649: char *start_value;
1.18 cvs 5650:
1.366 vatton 5651: cssRule = SkipBlanksAndComments (cssRule);
5652: start_value = cssRule;
1.184 vatton 5653: repeat.typed_data.value = REALSIZE;
1.191 vatton 5654: repeat.typed_data.unit = UNIT_BOX;
1.18 cvs 5655: repeat.typed_data.real = FALSE;
1.82 cvs 5656: cssRule = SkipBlanksAndComments (cssRule);
5657: if (!strncasecmp (cssRule, "no-repeat", 9))
1.184 vatton 5658: repeat.typed_data.value = REALSIZE;
1.82 cvs 5659: else if (!strncasecmp (cssRule, "repeat-y", 8))
1.265 vatton 5660: repeat.typed_data.value = YREPEAT;
1.82 cvs 5661: else if (!strncasecmp (cssRule, "repeat-x", 8))
1.265 vatton 5662: repeat.typed_data.value = XREPEAT;
1.82 cvs 5663: else if (!strncasecmp (cssRule, "repeat", 6))
1.184 vatton 5664: repeat.typed_data.value = REPEAT;
1.18 cvs 5665: else
5666: return (cssRule);
5667:
1.295 vatton 5668: cssRule = SkipWord (cssRule);
5669: /* check if it's an important rule */
1.366 vatton 5670: if (DoDialog)
5671: DisplayStyleValue ("background-repeat", start_value, cssRule);
5672: else if (DoApply)
1.295 vatton 5673: /* install the new presentation */
1.362 quint 5674: TtaSetStylePresentation (PRBackgroundRepeat, element, tsch, ctxt, repeat);
1.295 vatton 5675: return (cssRule);
5676: }
5677:
5678: /*----------------------------------------------------------------------
5679: ParseCSSBackgroundRepeat: parse a CSS BackgroundRepeat attribute string.
5680: ----------------------------------------------------------------------*/
5681: static char *ParseCSSBackgroundRepeat (Element element, PSchema tsch,
1.315 gully 5682: PresentationContext ctxt,
5683: char *cssRule, CSSInfoPtr css,
5684: ThotBool isHTML)
1.295 vatton 5685: {
1.388 carcone 5686:
5687: char *ptr;
5688:
5689: ptr = cssRule;
1.295 vatton 5690: cssRule = ParseACSSBackgroundRepeat (element, tsch, ctxt,
1.315 gully 5691: cssRule, css, isHTML);
1.388 carcone 5692:
5693: if (ptr == cssRule)
1.117 vatton 5694: {
1.295 vatton 5695: cssRule = SkipValue ("Invalid background-repeat value", cssRule);
1.117 vatton 5696: /* check if it's an important rule */
5697: }
1.295 vatton 5698: return cssRule;
1.18 cvs 5699: }
5700:
5701: /*----------------------------------------------------------------------
1.327 vatton 5702: ParseACSSBackgroundAttachment: parse a CSS BackgroundAttachment
5703: attribute string.
1.18 cvs 5704: ----------------------------------------------------------------------*/
1.295 vatton 5705: static char *ParseACSSBackgroundAttachment (Element element, PSchema tsch,
1.327 vatton 5706: PresentationContext ctxt,
5707: char *cssRule, CSSInfoPtr css,
5708: ThotBool isHTML)
1.18 cvs 5709: {
1.366 vatton 5710: char *start_value;
5711:
1.163 quint 5712: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 5713: start_value = cssRule;
1.163 quint 5714: if (!strncasecmp (cssRule, "scroll", 6))
1.199 vatton 5715: {
5716: cssRule = SkipWord (cssRule);
5717: }
1.163 quint 5718: else if (!strncasecmp (cssRule, "fixed", 5))
1.199 vatton 5719: {
5720: cssRule = SkipWord (cssRule);
5721: }
1.362 quint 5722: else if (!strncasecmp (cssRule, "inherit", 7))
5723: {
5724: cssRule = SkipWord (cssRule);
5725: }
1.366 vatton 5726: if (start_value != cssRule && DoDialog)
5727: DisplayStyleValue ("background-attachment", start_value, cssRule);
1.163 quint 5728: return (cssRule);
1.1 cvs 5729: }
5730:
5731: /*----------------------------------------------------------------------
1.327 vatton 5732: ParseCSSBackgroundAttachment: parse a CSS BackgroundAttachment
5733: attribute string.
1.295 vatton 5734: ----------------------------------------------------------------------*/
5735: static char *ParseCSSBackgroundAttachment (Element element, PSchema tsch,
1.327 vatton 5736: PresentationContext ctxt,
5737: char *cssRule, CSSInfoPtr css,
5738: ThotBool isHTML)
1.295 vatton 5739: {
5740: char *ptr;
5741:
5742: ptr = cssRule;
5743: cssRule = ParseACSSBackgroundAttachment (element, tsch, ctxt,
1.327 vatton 5744: cssRule, css, isHTML);
1.295 vatton 5745: if (ptr == cssRule)
1.366 vatton 5746: cssRule = SkipValue ("Invalid background-attachment value", cssRule);
1.295 vatton 5747: return cssRule;
5748: }
5749:
5750: /*----------------------------------------------------------------------
1.327 vatton 5751: ParseACSSBackgroundPosition: parse a CSS BackgroundPosition
5752: attribute string.
1.1 cvs 5753: ----------------------------------------------------------------------*/
1.279 vatton 5754: static char *ParseACSSBackgroundPosition (Element element, PSchema tsch,
1.327 vatton 5755: PresentationContext ctxt,
5756: char *cssRule, CSSInfoPtr css,
1.362 quint 5757: ThotBool isHTML, ThotBool *across)
1.1 cvs 5758: {
1.362 quint 5759: PresentationValue val;
5760: char *ptr;
1.1 cvs 5761:
1.163 quint 5762: cssRule = SkipBlanksAndComments (cssRule);
1.362 quint 5763: ptr = cssRule;
5764: val.typed_data.value = 0;
5765: val.typed_data.real = FALSE;
5766: val.typed_data.unit = UNIT_INVALID;
1.163 quint 5767: if (!strncasecmp (cssRule, "left", 4))
1.362 quint 5768: {
5769: val.typed_data.value = 0;
5770: val.typed_data.unit = UNIT_PERCENT;
5771: cssRule += 4;
5772: *across = TRUE;
5773: }
1.163 quint 5774: else if (!strncasecmp (cssRule, "right", 5))
1.362 quint 5775: {
5776: val.typed_data.value = 100;
5777: val.typed_data.unit = UNIT_PERCENT;
5778: cssRule += 5;
5779: *across = TRUE;
5780: }
1.163 quint 5781: else if (!strncasecmp (cssRule, "center", 6))
1.362 quint 5782: {
5783: val.typed_data.value = 50;
5784: val.typed_data.unit = UNIT_PERCENT;
5785: cssRule += 6;
5786: }
1.163 quint 5787: else if (!strncasecmp (cssRule, "top", 3))
1.362 quint 5788: {
5789: val.typed_data.value = 0;
5790: val.typed_data.unit = UNIT_PERCENT;
5791: cssRule += 3;
5792: *across = FALSE;
5793: }
1.163 quint 5794: else if (!strncasecmp (cssRule, "bottom", 6))
1.191 vatton 5795: {
1.362 quint 5796: val.typed_data.value = 100;
5797: val.typed_data.unit = UNIT_PERCENT;
5798: cssRule += 6;
5799: *across = FALSE;
5800: }
5801: else if (!strncasecmp (cssRule, "inherit", 7))
5802: {
5803: val.typed_data.unit = VALUE_INHERIT;
5804: cssRule += 7;
1.191 vatton 5805: }
1.163 quint 5806: else
1.362 quint 5807: /* <length> or <percentage> */
5808: {
5809: cssRule = ParseCSSUnit (cssRule, &val);
5810: if (val.typed_data.unit == UNIT_BOX && val.typed_data.value == 0)
5811: /* 0 with no unit. Accept */
5812: val.typed_data.unit = UNIT_PERCENT;
5813: }
1.163 quint 5814:
1.366 vatton 5815: if (val.typed_data.unit != UNIT_INVALID && val.typed_data.unit != UNIT_BOX)
1.362 quint 5816: {
1.366 vatton 5817: if (DoDialog)
5818: {
5819: if (val.typed_data.unit == VALUE_INHERIT)
5820: {
5821: DisplayStyleValue ("background-positionH", ptr, cssRule);
5822: DisplayStyleValue ("background-positionV", ptr, cssRule);
5823: }
5824: else if (*across)
5825: DisplayStyleValue ("background-positionH", ptr, cssRule);
5826: else
5827: DisplayStyleValue ("background-positionV", ptr, cssRule);
5828: }
5829: else if (DoApply)
1.362 quint 5830: /* install the new presentation */
5831: {
5832: if (val.typed_data.unit == VALUE_INHERIT)
5833: /* "inherit" applies to both dimensions */
5834: {
5835: TtaSetStylePresentation (PRBackgroundHorizPos, element, tsch,
5836: ctxt, val);
5837: TtaSetStylePresentation (PRBackgroundVertPos, element, tsch,
5838: ctxt, val);
5839: }
5840: else if (*across)
5841: TtaSetStylePresentation (PRBackgroundHorizPos, element, tsch,
5842: ctxt, val);
5843: else
5844: TtaSetStylePresentation (PRBackgroundVertPos, element, tsch,
5845: ctxt, val);
5846: }
5847: }
1.279 vatton 5848: return (cssRule);
5849: }
1.218 vatton 5850:
1.279 vatton 5851: /*----------------------------------------------------------------------
1.327 vatton 5852: ParseCSSBackgroundPosition: parse a CSS BackgroundPosition
5853: attribute string.
1.279 vatton 5854: ----------------------------------------------------------------------*/
5855: static char *ParseCSSBackgroundPosition (Element element, PSchema tsch,
1.327 vatton 5856: PresentationContext ctxt,
5857: char *cssRule, CSSInfoPtr css,
5858: ThotBool isHTML)
1.279 vatton 5859: {
1.295 vatton 5860: char *ptr;
1.362 quint 5861: ThotBool across;
1.295 vatton 5862:
5863: ptr = cssRule;
1.362 quint 5864: across = TRUE;
5865: cssRule = ParseACSSBackgroundPosition (element, tsch, ctxt, cssRule, css,
5866: isHTML, &across);
1.295 vatton 5867: if (ptr == cssRule)
1.360 vatton 5868: cssRule = SkipValue ("Invalid background-position value", cssRule);
1.362 quint 5869: else
1.298 vatton 5870: {
1.362 quint 5871: cssRule = SkipBlanksAndComments (cssRule);
5872: if (*cssRule != ';' && *cssRule != '!' && *cssRule != EOS)
5873: {
5874: /* possible second value */
5875: ptr = cssRule;
5876: across = !across;
5877: cssRule = ParseACSSBackgroundPosition (element, tsch, ctxt, cssRule,
5878: css, isHTML, &across);
5879: if (ptr == cssRule)
5880: cssRule = SkipValue ("Invalid background-position value", cssRule);
5881: }
1.298 vatton 5882: }
1.163 quint 5883: return (cssRule);
1.18 cvs 5884: }
5885:
5886: /*----------------------------------------------------------------------
1.327 vatton 5887: ParseCSSBackground: parse a CSS background attribute
1.18 cvs 5888: ----------------------------------------------------------------------*/
1.79 cvs 5889: static char *ParseCSSBackground (Element element, PSchema tsch,
1.327 vatton 5890: PresentationContext ctxt, char *cssRule,
5891: CSSInfoPtr css, ThotBool isHTML)
1.18 cvs 5892: {
1.323 vatton 5893: char *ptr;
5894: int skippedNL;
1.362 quint 5895: ThotBool img, repeat, position, attach, color, across;
1.18 cvs 5896:
1.82 cvs 5897: cssRule = SkipBlanksAndComments (cssRule);
1.323 vatton 5898: img = repeat = position = attach = color = FALSE;
1.362 quint 5899: across = TRUE;
1.301 vatton 5900: while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.18 cvs 5901: {
1.71 cvs 5902: /* perhaps a Background Image */
1.198 vatton 5903: if (!strncasecmp (cssRule, "url", 3) || !strncasecmp (cssRule, "none", 4))
1.327 vatton 5904: {
1.334 vatton 5905: if (!strncasecmp (cssRule, "none", 4))
1.423 vatton 5906: {
5907: repeat = TRUE;
5908: ParseCSSBackgroundColor (element, tsch, ctxt, "transparent",
5909: css, isHTML);
5910: }
1.327 vatton 5911: cssRule = ParseCSSBackgroundImage (element, tsch, ctxt, cssRule,
5912: css, isHTML);
5913: img = TRUE;
5914: }
1.18 cvs 5915: /* perhaps a Background Attachment */
1.82 cvs 5916: else if (!strncasecmp (cssRule, "scroll", 6) ||
5917: !strncasecmp (cssRule, "fixed", 5))
1.327 vatton 5918: {
5919: cssRule = ParseACSSBackgroundAttachment (element, tsch, ctxt,
5920: cssRule, css, isHTML);
1.328 vatton 5921: attach = repeat = TRUE;
1.327 vatton 5922: }
1.18 cvs 5923: /* perhaps a Background Repeat */
1.82 cvs 5924: else if (!strncasecmp (cssRule, "no-repeat", 9) ||
5925: !strncasecmp (cssRule, "repeat-y", 8) ||
5926: !strncasecmp (cssRule, "repeat-x", 8) ||
5927: !strncasecmp (cssRule, "repeat", 6))
1.327 vatton 5928: {
5929: cssRule = ParseACSSBackgroundRepeat (element, tsch, ctxt,
5930: cssRule, css, isHTML);
5931: repeat = TRUE;
5932: }
1.18 cvs 5933: /* perhaps a Background Position */
1.82 cvs 5934: else if (!strncasecmp (cssRule, "left", 4) ||
5935: !strncasecmp (cssRule, "right", 5) ||
5936: !strncasecmp (cssRule, "center", 6) ||
5937: !strncasecmp (cssRule, "top", 3) ||
5938: !strncasecmp (cssRule, "bottom", 6) ||
1.279 vatton 5939: isdigit (*cssRule) || *cssRule == '.' || *cssRule == '-')
1.327 vatton 5940: {
1.362 quint 5941: cssRule = ParseACSSBackgroundPosition (element, tsch, ctxt, cssRule,
5942: css, isHTML, &across);
5943: across = !across;
1.328 vatton 5944: position = repeat = TRUE;
1.327 vatton 5945: }
1.18 cvs 5946: /* perhaps a Background Color */
1.323 vatton 5947: else if (!color)
1.327 vatton 5948: {
5949: skippedNL = NewLineSkipped;
5950: /* check if the rule has been found */
5951: ptr = cssRule;
5952: cssRule = ParseCSSBackgroundColor (element, tsch, ctxt,
5953: cssRule, css, isHTML);
5954: if (ptr == cssRule)
5955: {
5956: NewLineSkipped = skippedNL;
5957: /* rule not found */
5958: cssRule = SkipProperty (cssRule, FALSE);
5959: }
5960: else
5961: color = TRUE;
5962: }
1.328 vatton 5963: else
1.327 vatton 5964: cssRule = SkipProperty (cssRule, FALSE);
1.328 vatton 5965:
1.82 cvs 5966: cssRule = SkipBlanksAndComments (cssRule);
1.18 cvs 5967: }
1.328 vatton 5968:
5969: if (color && !img)
1.405 kia 5970: ParseCSSBackgroundImage (element, tsch, ctxt, (char*)
5971: "none", css, isHTML);
1.328 vatton 5972:
5973: if (img && !repeat)
5974: ParseACSSBackgroundRepeat (element, tsch, ctxt,
1.405 kia 5975: (char*)"repeat", css, isHTML);
1.328 vatton 5976: if (img && !position)
5977: ParseACSSBackgroundPosition (element, tsch, ctxt,
1.405 kia 5978: (char*)"0% 0%", css, isHTML, &across);
1.328 vatton 5979: if (img && !attach)
5980: ParseACSSBackgroundAttachment (element, tsch, ctxt,
1.405 kia 5981: (char*)"scroll", css, isHTML);
1.327 vatton 5982: return (cssRule);
1.18 cvs 5983: }
5984:
1.59 cvs 5985: /*----------------------------------------------------------------------
1.327 vatton 5986: ParseCSSPageBreakBefore: parse a CSS page-break-before attribute
1.59 cvs 5987: ----------------------------------------------------------------------*/
1.79 cvs 5988: static char *ParseCSSPageBreakBefore (Element element, PSchema tsch,
1.327 vatton 5989: PresentationContext ctxt, char *cssRule,
5990: CSSInfoPtr css, ThotBool isHTML)
1.59 cvs 5991: {
5992: PresentationValue page;
1.366 vatton 5993: char *start_value;
1.59 cvs 5994:
1.184 vatton 5995: page.typed_data.unit = UNIT_INVALID;
1.59 cvs 5996: page.typed_data.real = FALSE;
1.82 cvs 5997: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 5998: start_value = cssRule;
1.82 cvs 5999: if (!strncasecmp (cssRule, "auto", 4))
1.184 vatton 6000: page.typed_data.value = PageAuto;
1.82 cvs 6001: else if (!strncasecmp (cssRule, "always", 6))
1.59 cvs 6002: {
1.184 vatton 6003: page.typed_data.unit = UNIT_REL;
6004: page.typed_data.value = PageAlways;
1.59 cvs 6005: }
1.82 cvs 6006: else if (!strncasecmp (cssRule, "avoid", 5))
1.59 cvs 6007: {
1.184 vatton 6008: page.typed_data.unit = UNIT_REL;
6009: page.typed_data.value = PageAvoid;
1.59 cvs 6010: }
1.82 cvs 6011: else if (!strncasecmp (cssRule, "left", 4))
1.59 cvs 6012: {
1.184 vatton 6013: page.typed_data.unit = UNIT_REL;
6014: page.typed_data.value = PageLeft;
1.59 cvs 6015: }
1.82 cvs 6016: else if (!strncasecmp (cssRule, "right", 5))
1.59 cvs 6017: {
1.184 vatton 6018: page.typed_data.unit = UNIT_REL;
6019: page.typed_data.value = PageRight;
1.59 cvs 6020: }
1.82 cvs 6021: else if (!strncasecmp (cssRule, "inherit", 7))
1.59 cvs 6022: {
1.293 quint 6023: page.typed_data.unit = VALUE_INHERIT;
1.184 vatton 6024: page.typed_data.value = PageInherit;
1.59 cvs 6025: }
6026: cssRule = SkipWord (cssRule);
6027: /* install the new presentation */
1.366 vatton 6028: if ((page.typed_data.unit == UNIT_REL && page.typed_data.value == PageAlways)
6029: || page.typed_data.unit == VALUE_INHERIT)
6030: {
6031: if (DoDialog)
6032: DisplayStyleValue ("page-break-before", start_value, cssRule);
6033: else if (DoApply)
6034: TtaSetStylePresentation (PRPageBefore, element, tsch, ctxt, page);
6035: }
1.59 cvs 6036: return (cssRule);
6037: }
6038:
6039: /*----------------------------------------------------------------------
1.327 vatton 6040: ParseCSSPageBreakAfter: parse a CSS page-break-after attribute
1.59 cvs 6041: ----------------------------------------------------------------------*/
1.79 cvs 6042: static char *ParseCSSPageBreakAfter (Element element, PSchema tsch,
1.327 vatton 6043: PresentationContext ctxt,
6044: char *cssRule, CSSInfoPtr css,
6045: ThotBool isHTML)
1.59 cvs 6046: {
6047: PresentationValue page;
1.366 vatton 6048: char *start_value;
1.59 cvs 6049:
1.184 vatton 6050: page.typed_data.unit = UNIT_INVALID;
1.59 cvs 6051: page.typed_data.real = FALSE;
1.82 cvs 6052: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 6053: start_value = cssRule;
1.82 cvs 6054: if (!strncasecmp (cssRule, "auto", 4))
1.184 vatton 6055: page.typed_data.value = PageAuto;
1.82 cvs 6056: else if (!strncasecmp (cssRule, "always", 6))
1.59 cvs 6057: {
1.184 vatton 6058: page.typed_data.unit = UNIT_REL;
6059: page.typed_data.value = PageAlways;
1.59 cvs 6060: }
1.82 cvs 6061: else if (!strncasecmp (cssRule, "avoid", 5))
1.59 cvs 6062: {
1.184 vatton 6063: page.typed_data.unit = UNIT_REL;
6064: page.typed_data.value = PageAvoid;
1.59 cvs 6065: }
1.82 cvs 6066: else if (!strncasecmp (cssRule, "left", 4))
1.59 cvs 6067: {
1.184 vatton 6068: page.typed_data.unit = UNIT_REL;
6069: page.typed_data.value = PageLeft;
1.59 cvs 6070: }
1.82 cvs 6071: else if (!strncasecmp (cssRule, "right", 5))
1.59 cvs 6072: {
1.184 vatton 6073: page.typed_data.unit = UNIT_REL;
6074: page.typed_data.value = PageRight;
1.59 cvs 6075: }
1.82 cvs 6076: else if (!strncasecmp (cssRule, "inherit", 7))
1.59 cvs 6077: {
1.293 quint 6078: page.typed_data.unit = VALUE_INHERIT;
1.184 vatton 6079: page.typed_data.value = PageInherit;
1.59 cvs 6080: }
6081: cssRule = SkipWord (cssRule);
6082: /* install the new presentation */
1.366 vatton 6083: if (page.typed_data.unit == UNIT_REL || page.typed_data.unit == VALUE_INHERIT)
6084: {
6085: if (DoDialog)
6086: DisplayStyleValue ("page-break-after", start_value, cssRule);
1.367 cvs 6087: //else if (DoApply)
6088: // TtaSetStylePresentation (PRPageAfter, element, tsch, ctxt, page);
1.366 vatton 6089: }
1.59 cvs 6090: return (cssRule);
6091: }
6092:
6093: /*----------------------------------------------------------------------
1.327 vatton 6094: ParseCSSPageBreakInside: parse a CSS page-break-inside attribute
1.59 cvs 6095: ----------------------------------------------------------------------*/
1.79 cvs 6096: static char *ParseCSSPageBreakInside (Element element, PSchema tsch,
1.327 vatton 6097: PresentationContext ctxt,
6098: char *cssRule, CSSInfoPtr css,
6099: ThotBool isHTML)
1.59 cvs 6100: {
6101: PresentationValue page;
1.366 vatton 6102: char *start_value;
1.59 cvs 6103:
1.184 vatton 6104: page.typed_data.unit = UNIT_INVALID;
1.59 cvs 6105: page.typed_data.real = FALSE;
1.82 cvs 6106: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 6107: start_value = cssRule;
1.82 cvs 6108: if (!strncasecmp (cssRule, "auto", 4))
1.59 cvs 6109: {
1.184 vatton 6110: /*page.typed_data.unit = UNIT_REL;*/
6111: page.typed_data.value = PageAuto;
1.59 cvs 6112: }
1.82 cvs 6113: else if (!strncasecmp (cssRule, "avoid", 5))
1.59 cvs 6114: {
1.184 vatton 6115: page.typed_data.unit = UNIT_REL;
6116: page.typed_data.value = PageAvoid;
1.59 cvs 6117: }
1.82 cvs 6118: else if (!strncasecmp (cssRule, "inherit", 7))
1.59 cvs 6119: {
1.293 quint 6120: /* page.typed_data.unit = VALUE_INHERIT; */
1.184 vatton 6121: page.typed_data.value = PageInherit;
1.59 cvs 6122: }
6123: cssRule = SkipWord (cssRule);
6124: /* install the new presentation */
1.366 vatton 6125: if ((page.typed_data.unit == UNIT_REL || page.typed_data.unit == VALUE_INHERIT) &&
6126: page.typed_data.value == PageAvoid)
6127: {
6128: if (DoDialog)
6129: DisplayStyleValue ("page-break-inside", start_value, cssRule);
1.367 cvs 6130: //else if (DoApply)
6131: //TtaSetStylePresentation (PRPageInside, element, tsch, ctxt, page);
1.366 vatton 6132: }
1.59 cvs 6133: return (cssRule);
6134: }
1.18 cvs 6135:
1.60 cvs 6136: /*----------------------------------------------------------------------
1.327 vatton 6137: ParseSVGStrokeWidth: parse a SVG stroke-width property value.
1.60 cvs 6138: ----------------------------------------------------------------------*/
1.79 cvs 6139: static char *ParseSVGStrokeWidth (Element element, PSchema tsch,
1.327 vatton 6140: PresentationContext ctxt, char *cssRule,
6141: CSSInfoPtr css, ThotBool isHTML)
1.60 cvs 6142: {
6143: PresentationValue width;
6144:
1.82 cvs 6145: cssRule = SkipBlanksAndComments (cssRule);
1.60 cvs 6146: width.typed_data.value = 0;
1.184 vatton 6147: width.typed_data.unit = UNIT_INVALID;
1.60 cvs 6148: width.typed_data.real = FALSE;
1.110 vatton 6149: if (isdigit (*cssRule) || *cssRule == '.')
1.166 vatton 6150: {
1.327 vatton 6151: cssRule = ParseCSSUnit (cssRule, &width);
6152: if (width.typed_data.unit == UNIT_BOX)
6153: width.typed_data.unit = UNIT_PX;
1.166 vatton 6154: }
1.295 vatton 6155: else
6156: cssRule = SkipValue ("Invalid stroke-width value", cssRule);
6157:
1.184 vatton 6158: if (width.typed_data.unit != UNIT_INVALID && DoApply)
1.117 vatton 6159: {
1.207 vatton 6160: TtaSetStylePresentation (PRLineWeight, element, tsch, ctxt, width);
1.117 vatton 6161: width.typed_data.value = 1;
1.184 vatton 6162: width.typed_data.unit = UNIT_REL;
1.117 vatton 6163: }
1.60 cvs 6164: return (cssRule);
6165: }
6166:
1.217 vatton 6167: /*----------------------------------------------------------------------
1.327 vatton 6168: ParseCSSPosition: parse a CSS Position attribute string.
1.217 vatton 6169: ----------------------------------------------------------------------*/
6170: static char *ParseCSSPosition (Element element, PSchema tsch,
1.327 vatton 6171: PresentationContext ctxt, char *cssRule,
6172: CSSInfoPtr css, ThotBool isHTML)
1.217 vatton 6173: {
1.305 quint 6174: char *ptr;
6175: PresentationValue pval;
1.217 vatton 6176:
1.305 quint 6177: pval.typed_data.value = 0;
6178: pval.typed_data.unit = UNIT_BOX;
6179: pval.typed_data.real = FALSE;
1.217 vatton 6180: cssRule = SkipBlanksAndComments (cssRule);
6181: ptr = cssRule;
6182: if (!strncasecmp (cssRule, "static", 6))
1.337 vatton 6183: {
6184: pval.typed_data.value = PositionStatic;
6185: cssRule += 6;
6186: }
6187: else if (!strncasecmp (cssRule, "relative", 8))
6188: {
6189: pval.typed_data.value = PositionRelative;
6190: cssRule += 8;
6191: }
1.217 vatton 6192: else if (!strncasecmp (cssRule, "absolute", 8))
1.337 vatton 6193: {
6194: pval.typed_data.value = PositionAbsolute;
6195: cssRule += 8;
6196: }
1.217 vatton 6197: else if (!strncasecmp (cssRule, "fixed", 5))
1.337 vatton 6198: {
6199: pval.typed_data.value = PositionFixed;
6200: cssRule += 5;
6201: }
1.217 vatton 6202: else if (!strncasecmp (cssRule, "inherit", 7))
1.337 vatton 6203: {
6204: pval.typed_data.unit = VALUE_INHERIT;
6205: cssRule += 7;
6206: }
1.305 quint 6207:
6208: if (pval.typed_data.value == 0 && pval.typed_data.unit != VALUE_INHERIT)
6209: {
6210: cssRule = SkipValue ("Invalid position value", ptr);
6211: cssRule = SkipValue (NULL, cssRule);
6212: }
1.217 vatton 6213: else
1.305 quint 6214: {
1.337 vatton 6215: cssRule = SkipBlanksAndComments (cssRule);
6216: if (*cssRule != EOS && *cssRule != ';')
6217: SkipValue ("Invalid position value", ptr);
1.366 vatton 6218: else if (DoDialog)
6219: DisplayStyleValue ("position", ptr, cssRule);
1.337 vatton 6220: else if (DoApply)
1.327 vatton 6221: TtaSetStylePresentation (PRPosition, element, tsch, ctxt, pval);
1.305 quint 6222: }
1.217 vatton 6223: return (cssRule);
6224: }
6225:
6226: /*----------------------------------------------------------------------
1.327 vatton 6227: ParseCSSTop: parse a CSS Top attribute
1.217 vatton 6228: ----------------------------------------------------------------------*/
6229: static char *ParseCSSTop (Element element, PSchema tsch,
1.327 vatton 6230: PresentationContext context, char *cssRule,
6231: CSSInfoPtr css, ThotBool isHTML)
1.217 vatton 6232: {
6233: PresentationValue val;
6234: char *ptr;
6235:
1.370 vatton 6236: val.typed_data.real = FALSE;
1.217 vatton 6237: cssRule = SkipBlanksAndComments (cssRule);
6238: ptr = cssRule;
1.305 quint 6239: /* first parse the value */
6240: if (!strncasecmp (cssRule, "auto", 4))
1.217 vatton 6241: {
6242: val.typed_data.unit = VALUE_AUTO;
6243: val.typed_data.value = 0;
6244: cssRule = SkipWord (cssRule);
6245: }
1.305 quint 6246: else if (!strncasecmp (cssRule, "inherit", 7))
6247: {
6248: val.typed_data.unit = VALUE_INHERIT;
6249: cssRule = SkipWord (cssRule);
6250: }
1.217 vatton 6251: else
6252: cssRule = ParseCSSUnit (cssRule, &val);
1.387 quint 6253:
6254: if (val.typed_data.unit == UNIT_INVALID ||
6255: (val.typed_data.value != 0 &&
1.217 vatton 6256: val.typed_data.unit == UNIT_BOX))
6257: {
1.387 quint 6258: cssRule = SkipValue ("Invalid top value", ptr);
6259: if (val.typed_data.unit == UNIT_BOX)
6260: val.typed_data.unit = UNIT_PX;
6261: else
6262: return (cssRule);
1.217 vatton 6263: }
1.366 vatton 6264: if (DoDialog)
1.387 quint 6265: DisplayStyleValue ("top", ptr, cssRule);
1.366 vatton 6266: else if (DoApply)
1.305 quint 6267: TtaSetStylePresentation (PRTop, element, tsch, context, val);
1.217 vatton 6268: return (cssRule);
6269: }
6270:
6271: /*----------------------------------------------------------------------
1.327 vatton 6272: ParseCSSRight: parse a CSS Right attribute
1.217 vatton 6273: ----------------------------------------------------------------------*/
6274: static char *ParseCSSRight (Element element, PSchema tsch,
1.327 vatton 6275: PresentationContext context, char *cssRule,
6276: CSSInfoPtr css, ThotBool isHTML)
1.217 vatton 6277: {
6278: PresentationValue val;
6279: char *ptr;
6280:
1.370 vatton 6281: val.typed_data.real = FALSE;
1.217 vatton 6282: cssRule = SkipBlanksAndComments (cssRule);
6283: ptr = cssRule;
6284: /* first parse the attribute string */
1.305 quint 6285: if (!strncasecmp (cssRule, "auto", 4))
1.217 vatton 6286: {
6287: val.typed_data.unit = VALUE_AUTO;
6288: val.typed_data.value = 0;
6289: cssRule = SkipWord (cssRule);
6290: }
1.305 quint 6291: else if (!strncasecmp (cssRule, "inherit", 7))
6292: {
6293: val.typed_data.unit = VALUE_INHERIT;
6294: cssRule = SkipWord (cssRule);
6295: }
1.217 vatton 6296: else
6297: cssRule = ParseCSSUnit (cssRule, &val);
1.387 quint 6298:
6299: if (val.typed_data.unit == UNIT_INVALID ||
6300: (val.typed_data.value != 0 &&
1.217 vatton 6301: val.typed_data.unit == UNIT_BOX))
6302: {
1.387 quint 6303: cssRule = SkipValue ("Invalid right value", ptr);
6304: if (val.typed_data.unit == UNIT_BOX)
6305: val.typed_data.unit = UNIT_PX;
6306: else
6307: return (cssRule);
1.217 vatton 6308: }
1.366 vatton 6309: if (DoDialog)
6310: DisplayStyleValue ("right", ptr, cssRule);
6311: else if (DoApply)
1.305 quint 6312: TtaSetStylePresentation (PRRight, element, tsch, context, val);
1.217 vatton 6313: return (cssRule);
6314: }
6315:
6316: /*----------------------------------------------------------------------
1.327 vatton 6317: ParseCSSBottom: parse a CSS Bottom attribute
1.217 vatton 6318: ----------------------------------------------------------------------*/
6319: static char *ParseCSSBottom (Element element, PSchema tsch,
1.327 vatton 6320: PresentationContext context, char *cssRule,
6321: CSSInfoPtr css, ThotBool isHTML)
1.217 vatton 6322: {
6323: PresentationValue val;
6324: char *ptr;
6325:
1.370 vatton 6326: val.typed_data.real = FALSE;
1.217 vatton 6327: cssRule = SkipBlanksAndComments (cssRule);
6328: ptr = cssRule;
6329: /* first parse the attribute string */
1.305 quint 6330: if (!strncasecmp (cssRule, "auto", 4))
1.217 vatton 6331: {
6332: val.typed_data.unit = VALUE_AUTO;
6333: val.typed_data.value = 0;
6334: cssRule = SkipWord (cssRule);
6335: }
1.305 quint 6336: else if (!strncasecmp (cssRule, "inherit", 7))
6337: {
6338: val.typed_data.unit = VALUE_INHERIT;
6339: cssRule = SkipWord (cssRule);
6340: }
1.217 vatton 6341: else
6342: cssRule = ParseCSSUnit (cssRule, &val);
1.387 quint 6343:
6344: if (val.typed_data.unit == UNIT_INVALID ||
6345: (val.typed_data.value != 0 &&
1.217 vatton 6346: val.typed_data.unit == UNIT_BOX))
6347: {
1.387 quint 6348: cssRule = SkipValue ("Invalid bottom value", ptr);
6349: if (val.typed_data.unit == UNIT_BOX)
6350: val.typed_data.unit = UNIT_PX;
6351: else
6352: return (cssRule);
1.217 vatton 6353: }
1.366 vatton 6354: if (DoDialog)
6355: DisplayStyleValue ("bottom", ptr, cssRule);
6356: else if (DoApply)
1.305 quint 6357: TtaSetStylePresentation (PRBottom, element, tsch, context, val);
1.217 vatton 6358: return (cssRule);
6359: }
6360:
6361: /*----------------------------------------------------------------------
1.327 vatton 6362: ParseCSSLeft: parse a CSS Left attribute
1.217 vatton 6363: ----------------------------------------------------------------------*/
6364: static char *ParseCSSLeft (Element element, PSchema tsch,
1.327 vatton 6365: PresentationContext context, char *cssRule,
6366: CSSInfoPtr css, ThotBool isHTML)
1.217 vatton 6367: {
6368: PresentationValue val;
6369: char *ptr;
6370:
1.370 vatton 6371: val.typed_data.real = FALSE;
1.217 vatton 6372: cssRule = SkipBlanksAndComments (cssRule);
6373: ptr = cssRule;
6374: /* first parse the attribute string */
1.305 quint 6375: if (!strncasecmp (cssRule, "auto", 4))
1.217 vatton 6376: {
6377: val.typed_data.unit = VALUE_AUTO;
6378: val.typed_data.value = 0;
6379: cssRule = SkipWord (cssRule);
6380: }
1.305 quint 6381: else if (!strncasecmp (cssRule, "inherit", 7))
6382: {
6383: val.typed_data.unit = VALUE_INHERIT;
6384: cssRule = SkipWord (cssRule);
6385: }
1.217 vatton 6386: else
6387: cssRule = ParseCSSUnit (cssRule, &val);
1.387 quint 6388:
6389: if (val.typed_data.unit == UNIT_INVALID ||
6390: (val.typed_data.value != 0 &&
1.217 vatton 6391: val.typed_data.unit == UNIT_BOX))
6392: {
1.387 quint 6393: cssRule = SkipValue ("Invalid left value", ptr);
6394: if (val.typed_data.unit == UNIT_BOX)
6395: val.typed_data.unit = UNIT_PX;
6396: else
6397: return (cssRule);
1.217 vatton 6398: }
1.366 vatton 6399: if (DoDialog)
6400: DisplayStyleValue ("left", ptr, cssRule);
6401: else if (DoApply)
1.305 quint 6402: TtaSetStylePresentation (PRLeft, element, tsch, context, val);
1.217 vatton 6403: return (cssRule);
6404: }
6405:
6406: /*----------------------------------------------------------------------
1.327 vatton 6407: ParseCSSZIndex: parse a CSS z-index attribute
1.217 vatton 6408: ----------------------------------------------------------------------*/
6409: static char *ParseCSSZIndex (Element element, PSchema tsch,
1.327 vatton 6410: PresentationContext context, char *cssRule,
6411: CSSInfoPtr css, ThotBool isHTML)
1.217 vatton 6412: {
6413: PresentationValue val;
6414: char *ptr;
6415:
1.370 vatton 6416: val.typed_data.real = FALSE;
1.217 vatton 6417: cssRule = SkipBlanksAndComments (cssRule);
6418: ptr = cssRule;
6419: /* first parse the attribute string */
1.420 vatton 6420: if (!strncasecmp (cssRule, "auto", 4))
1.217 vatton 6421: {
6422: val.typed_data.unit = VALUE_AUTO;
6423: val.typed_data.value = 0;
6424: cssRule = SkipWord (cssRule);
6425: }
1.420 vatton 6426: else if (!strncasecmp (cssRule, "inherit", 7))
6427: {
6428: val.typed_data.unit = VALUE_INHERIT;
6429: val.typed_data.value = 0;
6430: cssRule = SkipWord (cssRule);
6431: }
1.217 vatton 6432: else
6433: {
6434: cssRule = ParseCSSUnit (cssRule, &val);
6435: if (val.typed_data.unit != UNIT_BOX)
1.327 vatton 6436: {
1.387 quint 6437: cssRule = SkipValue ("Invalid z-index value", ptr);
6438: return (cssRule);
1.327 vatton 6439: }
1.420 vatton 6440: val.typed_data.value = - val.typed_data.value;
1.217 vatton 6441: }
1.366 vatton 6442: if (DoDialog)
1.420 vatton 6443: DisplayStyleValue ("z-index", ptr, cssRule);
6444: else if (DoApply)
6445: TtaSetStylePresentation (PRDepth, element, tsch, context, val);
1.217 vatton 6446: return (cssRule);
6447: }
6448:
1.340 quint 6449: /*----------------------------------------------------------------------
6450: *
1.436 quint 6451: * STYLE PROPERTY DECLARATIONS
1.340 quint 6452: *
6453: *----------------------------------------------------------------------*/
1.18 cvs 6454: /*
1.436 quint 6455: * NOTE: Long property names MUST be placed before shortened ones !
6456: * e.g. "font-size" must be placed before "font"
1.18 cvs 6457: */
6458: static CSSProperty CSSProperties[] =
1.327 vatton 6459: {
6460: {"background-color", ParseCSSBackgroundColor},
6461: {"background-image", ParseCSSBackgroundImage},
6462: {"background-repeat", ParseCSSBackgroundRepeat},
6463: {"background-attachment", ParseCSSBackgroundAttachment},
6464: {"background-position", ParseCSSBackgroundPosition},
6465: {"background", ParseCSSBackground},
6466: {"border-top-width", ParseCSSBorderTopWidth},
6467: {"border-right-width", ParseCSSBorderRightWidth},
6468: {"border-bottom-width", ParseCSSBorderBottomWidth},
6469: {"border-left-width", ParseCSSBorderLeftWidth},
6470: {"border-width", ParseCSSBorderWidth},
6471: {"border-top-color", ParseCSSBorderColorTop},
6472: {"border-right-color", ParseCSSBorderColorRight},
6473: {"border-bottom-color", ParseCSSBorderColorBottom},
6474: {"border-left-color", ParseCSSBorderColorLeft},
6475: {"border-color", ParseCSSBorderColor},
6476: {"border-top-style", ParseCSSBorderStyleTop},
6477: {"border-right-style", ParseCSSBorderStyleRight},
6478: {"border-bottom-style", ParseCSSBorderStyleBottom},
6479: {"border-left-style", ParseCSSBorderStyleLeft},
6480: {"border-style", ParseCSSBorderStyle},
6481: {"border-top", ParseCSSBorderTop},
6482: {"border-right", ParseCSSBorderRight},
6483: {"border-bottom", ParseCSSBorderBottom},
6484: {"border-left", ParseCSSBorderLeft},
6485: {"border", ParseCSSBorder},
6486: {"bottom", ParseCSSBottom},
6487: {"clear", ParseCSSClear},
6488: {"color", ParseCSSForeground},
6489: {"content", ParseCSSContent},
1.436 quint 6490: {"counter-increment", ParseCSSCounterIncrement},
6491: {"counter-reset", ParseCSSCounterReset},
1.327 vatton 6492: {"direction", ParseCSSDirection},
6493: {"display", ParseCSSDisplay},
6494: {"float", ParseCSSFloat},
6495: {"font-family", ParseCSSFontFamily},
6496: {"font-style", ParseCSSFontStyle},
6497: {"font-variant", ParseCSSFontVariant},
6498: {"font-weight", ParseCSSFontWeight},
6499: {"font-size-adjust", ParseCSSFontSizeAdjust},
6500: {"font-size", ParseCSSFontSize},
6501: {"font", ParseCSSFont},
1.382 vatton 6502: {"max-height", ParseCSSMaxHeight},
6503: {"min-height", ParseCSSMinHeight},
1.327 vatton 6504: {"height", ParseCSSHeight},
6505: {"left", ParseCSSLeft},
6506: {"letter-spacing", ParseCSSLetterSpacing},
6507: {"line-height", ParseCSSLineHeight},
6508: {"list-style-type", ParseCSSListStyleType},
6509: {"list-style-image", ParseCSSListStyleImage},
6510: {"list-style-position", ParseCSSListStylePosition},
6511: {"list-style", ParseCSSListStyle},
6512: {"margin-bottom", ParseCSSMarginBottom},
6513: {"margin-top", ParseCSSMarginTop},
6514: {"margin-right", ParseCSSMarginRight},
6515: {"margin-left", ParseCSSMarginLeft},
6516: {"margin", ParseCSSMargin},
1.418 quint 6517: {"opacity", ParseCSSOpacity},
1.327 vatton 6518: {"padding-top", ParseCSSPaddingTop},
6519: {"padding-right", ParseCSSPaddingRight},
6520: {"padding-bottom", ParseCSSPaddingBottom},
6521: {"padding-left", ParseCSSPaddingLeft},
6522: {"padding", ParseCSSPadding},
6523: {"page-break-before", ParseCSSPageBreakBefore},
6524: {"page-break-after", ParseCSSPageBreakAfter},
6525: {"page-break-inside", ParseCSSPageBreakInside},
6526: {"position", ParseCSSPosition},
6527: {"right", ParseCSSRight},
6528: {"text-align", ParseCSSTextAlign},
6529: {"text-anchor", ParseCSSTextAnchor},
6530: {"text-indent", ParseCSSTextIndent},
6531: {"text-decoration", ParseCSSTextDecoration},
6532: {"text-transform", ParseCSSTextTransform},
6533: {"top", ParseCSSTop},
6534: {"unicode-bidi", ParseCSSUnicodeBidi},
6535: {"vertical-align", ParseCSSVerticalAlign},
6536: {"white-space", ParseCSSWhiteSpace},
1.382 vatton 6537: {"max-width", ParseCSSMaxWidth},
6538: {"min-width", ParseCSSMinWidth},
1.327 vatton 6539: {"width", ParseCSSWidth},
1.333 vatton 6540: {"visibility", ParseCSSVisibility},
1.327 vatton 6541: {"word-spacing", ParseCSSWordSpacing},
6542: {"z-index", ParseCSSZIndex},
6543:
6544: /* SVG extensions */
6545: {"fill-opacity", ParseSVGFillOpacity},
1.420 vatton 6546: {"fill-rule", ParseSVGFillRule},
1.327 vatton 6547: {"fill", ParseSVGFill},
1.427 quint 6548: {"marker-end", ParseSVGMarkerEnd},
6549: {"marker-mid", ParseSVGMarkerMid},
6550: {"marker-start", ParseSVGMarkerStart},
6551: {"marker", ParseSVGMarker},
1.327 vatton 6552: {"opacity", ParseSVGOpacity},
1.424 quint 6553: {"stop-color", ParseSVGStopColor},
1.425 quint 6554: {"stop-opacity", ParseSVGStopOpacity},
1.327 vatton 6555: {"stroke-opacity", ParseSVGStrokeOpacity},
6556: {"stroke-width", ParseSVGStrokeWidth},
6557: {"stroke", ParseSVGStroke}
6558: };
1.155 cheyroul 6559:
1.18 cvs 6560: #define NB_CSSSTYLEATTRIBUTE (sizeof(CSSProperties) / sizeof(CSSProperty))
6561:
6562: /*----------------------------------------------------------------------
1.327 vatton 6563: ParseCSSRule: parse a CSS Style string
6564: we expect the input string describing the style to be of the form
6565: property: value [ ; property: value ]*
6566: but tolerate incorrect or incomplete input
1.18 cvs 6567: ----------------------------------------------------------------------*/
1.366 vatton 6568: void ParseCSSRule (Element element, PSchema tsch, PresentationContext ctxt,
6569: char *cssRule, CSSInfoPtr css, ThotBool isHTML)
1.18 cvs 6570: {
1.366 vatton 6571: DisplayMode dispMode = DisplayImmediately;
1.312 quint 6572: char *p = NULL, *next, *end;
1.214 quint 6573: char *valueStart;
1.18 cvs 6574: int lg;
1.34 cvs 6575: unsigned int i;
1.76 cvs 6576: ThotBool found;
1.18 cvs 6577:
1.34 cvs 6578: /* avoid too many redisplay */
1.366 vatton 6579: if (!DoDialog && ctxt->doc)
6580: {
6581: dispMode = TtaGetDisplayMode (ctxt->doc);
6582: if (dispMode == DisplayImmediately)
6583: TtaSetDisplayMode (ctxt->doc, DeferredDisplay);
6584: }
1.34 cvs 6585:
1.82 cvs 6586: while (*cssRule != EOS)
1.18 cvs 6587: {
1.82 cvs 6588: cssRule = SkipBlanksAndComments (cssRule);
1.371 vatton 6589: if (*cssRule == ';' || *cssRule < 0x20 ||
1.372 vatton 6590: ((unsigned char)*cssRule) == 0xA0)
1.371 vatton 6591: cssRule++;
6592: else if (*cssRule < 0x41 || *cssRule > 0x7A ||
6593: (*cssRule > 0x5A && *cssRule < 0x61))
1.352 vatton 6594: {
6595: end = SkipProperty (cssRule, FALSE);
1.385 vatton 6596: if (cssRule[0] != '-')
6597: CSSParseError ("Invalid property", cssRule, end);
1.352 vatton 6598: cssRule = end;
6599: }
1.194 vatton 6600: else if (*cssRule != EOS)
1.327 vatton 6601: {
6602: found = FALSE;
6603: /* look for the type of property */
6604: for (i = 0; i < NB_CSSSTYLEATTRIBUTE && !found; i++)
6605: {
6606: lg = strlen (CSSProperties[i].name);
6607: if (!strncasecmp (cssRule, CSSProperties[i].name, lg))
6608: {
6609: p = cssRule + lg;
6610: found = TRUE;
6611: i--;
6612: }
6613: }
6614:
1.360 vatton 6615: // check if it's an important rule
6616: CheckImportantRule (cssRule, ctxt);
1.327 vatton 6617: if (i < NB_CSSSTYLEATTRIBUTE &&
6618: !strcasecmp (CSSProperties[i].name, "content") &&
6619: ((GenericContext)ctxt)->pseudo != PbBefore &&
6620: ((GenericContext)ctxt)->pseudo != PbAfter)
1.340 quint 6621: /* property content is allowed only for pseudo-elements :before and
6622: :after */
1.327 vatton 6623: {
1.352 vatton 6624: end = SkipProperty (cssRule, FALSE);
1.327 vatton 6625: CSSParseError ("content is allowed only for pseudo-elements",
6626: cssRule, end);
1.352 vatton 6627: cssRule = end;
1.327 vatton 6628: }
1.352 vatton 6629: else if (i == NB_CSSSTYLEATTRIBUTE)
1.376 vatton 6630: cssRule = SkipProperty (cssRule, !ctxt->destroy);
1.327 vatton 6631: else
6632: {
6633: /* update index and skip the ":" indicator if present */
6634: p = SkipBlanksAndComments (p);
6635: if (*p == ':')
6636: {
6637: p++;
6638: p = SkipBlanksAndComments (p);
6639: /* try to parse the value associated with this property */
6640: if (CSSProperties[i].parsing_function != NULL)
6641: {
6642: valueStart = p;
6643: p = CSSProperties[i].parsing_function (element, tsch,
6644: ctxt, p, css, isHTML);
6645: if (!element && isHTML)
6646: {
6647: if (ctxt->type == HTML_EL_Input)
6648: /* it's a generic rule for the HTML element input.
6649: Generate a Thot Pres rule for each kind of
6650: input element */
6651: {
6652: ctxt->type = HTML_EL_Text_Input;
6653: p = CSSProperties[i].parsing_function (element,
6654: tsch, ctxt, valueStart, css, isHTML);
6655: ctxt->type = HTML_EL_Password_Input;
6656: p = CSSProperties[i].parsing_function (element,
6657: tsch, ctxt, valueStart, css, isHTML);
6658: ctxt->type = HTML_EL_File_Input;
6659: p = CSSProperties[i].parsing_function (element,
6660: tsch, ctxt, valueStart, css, isHTML);
6661: ctxt->type = HTML_EL_Checkbox_Input;
6662: p = CSSProperties[i].parsing_function (element,
6663: tsch, ctxt, valueStart, css, isHTML);
6664: ctxt->type = HTML_EL_Radio_Input;
6665: p = CSSProperties[i].parsing_function (element,
6666: tsch, ctxt, valueStart, css, isHTML);
6667: ctxt->type = HTML_EL_Submit_Input;
6668: p = CSSProperties[i].parsing_function (element,
6669: tsch, ctxt, valueStart, css, isHTML);
6670: ctxt->type = HTML_EL_Reset_Input;
6671: p = CSSProperties[i].parsing_function (element,
6672: tsch, ctxt, valueStart, css, isHTML);
6673: ctxt->type = HTML_EL_Button_Input;
6674: p = CSSProperties[i].parsing_function (element,
6675: tsch, ctxt, valueStart, css, isHTML);
6676: ctxt->type = HTML_EL_Input;
6677: }
6678: else if (ctxt->type == HTML_EL_ruby)
6679: /* it's a generic rule for the HTML element ruby.
6680: Generate a Thot Pres rule for each kind of
6681: ruby element. */
6682: {
6683: ctxt->type = HTML_EL_simple_ruby;
6684: p = CSSProperties[i].parsing_function (element,
6685: tsch, ctxt, valueStart, css, isHTML);
6686: ctxt->type = HTML_EL_complex_ruby;
6687: p = CSSProperties[i].parsing_function (element,
6688: tsch, ctxt, valueStart, css, isHTML);
6689: ctxt->type = HTML_EL_ruby;
6690: }
6691: }
6692: /* update index and skip the ";" separator if present */
6693: next = SkipBlanksAndComments (p);
6694: if (*next != EOS && *next != ';')
1.431 quint 6695: CSSParseError ("Missing closing ';' after", cssRule, p);
1.327 vatton 6696: cssRule = next;
6697: }
6698: }
6699: else
6700: cssRule = SkipProperty (cssRule, TRUE);
6701: }
1.360 vatton 6702: // skip important markup
6703: cssRule = SkipImportantRule (cssRule);
6704:
1.327 vatton 6705: }
1.18 cvs 6706: /* next property */
1.82 cvs 6707: cssRule = SkipBlanksAndComments (cssRule);
1.89 cvs 6708: if (*cssRule == '}')
1.327 vatton 6709: {
6710: cssRule++;
6711: CSSPrintError ("Invalid character", "}");
6712: cssRule = SkipBlanksAndComments (cssRule);
6713: }
1.155 cheyroul 6714: if (*cssRule == ',' ||
1.327 vatton 6715: *cssRule == ';')
6716: {
6717: cssRule++;
6718: cssRule = SkipBlanksAndComments (cssRule);
6719: }
1.18 cvs 6720: }
1.34 cvs 6721:
6722: /* restore the display mode */
1.366 vatton 6723: if (!DoDialog && ctxt->doc && dispMode == DisplayImmediately)
1.207 vatton 6724: TtaSetDisplayMode (ctxt->doc, dispMode);
1.18 cvs 6725: }
1.1 cvs 6726:
1.111 cvs 6727: /*----------------------------------------------------------------------
1.327 vatton 6728: ParseHTMLSpecificStyle: parse and apply a CSS Style string.
6729: This function must be called when a specific style is applied to an
6730: element.
6731: The parameter specificity is the specificity of the style, 0 if it is
6732: not really a CSS rule.
1.1 cvs 6733: ----------------------------------------------------------------------*/
1.79 cvs 6734: void ParseHTMLSpecificStyle (Element el, char *cssRule, Document doc,
1.377 quint 6735: int specificity, ThotBool destroy)
1.1 cvs 6736: {
1.257 vatton 6737: DisplayMode dispMode;
1.207 vatton 6738: PresentationContext ctxt;
6739: ElementType elType;
1.413 vatton 6740: char *buff, *ptr, *end;
1.207 vatton 6741: ThotBool isHTML;
1.1 cvs 6742:
1.207 vatton 6743: /* A rule applying to BODY is really meant to address HTML */
6744: elType = TtaGetElementType (el);
1.286 quint 6745: NewLineSkipped = 0;
1.207 vatton 6746: /* store the current line for eventually reported errors */
6747: LineNumber = TtaGetElementLineNumber (el);
6748: if (destroy)
6749: /* no reported errors */
6750: ParsedDoc = 0;
6751: else if (ParsedDoc != doc)
6752: {
6753: /* update the context for reported errors */
6754: ParsedDoc = doc;
1.348 vatton 6755: Error_DocURL = DocumentURLs[doc];
1.207 vatton 6756: }
6757: isHTML = (strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML") == 0);
6758: /* create the context of the Specific presentation driver */
6759: ctxt = TtaGetSpecificStyleContext (doc);
6760: if (ctxt == NULL)
6761: return;
6762: ctxt->type = elType.ElTypeNum;
6763: ctxt->cssSpecificity = specificity;
1.236 quint 6764: ctxt->cssLine = LineNumber;
1.207 vatton 6765: ctxt->destroy = destroy;
6766: /* first use of the context */
6767: ctxt->uses = 1;
1.257 vatton 6768: /* save the current display mode */
6769: dispMode = TtaGetDisplayMode (doc);
1.207 vatton 6770: /* Call the parser */
1.366 vatton 6771: DoDialog = FALSE; // not parsing for CSS dialog
1.406 quint 6772: /* if it is a property applied to a COL or a COLGROUP element in a HTML table,
6773: associate the property to the corresponding Table_head or cell elements,
6774: depending on the property. */
1.413 vatton 6775: ptr = strstr (cssRule, "background-color");
6776: if (ptr && isHTML &&
1.406 quint 6777: (elType.ElTypeNum == HTML_EL_COL || elType.ElTypeNum == HTML_EL_COLGROUP))
1.413 vatton 6778: {
6779: end = strstr (ptr, ";");
6780: if (end)
6781: {
6782: buff = TtaStrdup (ptr);
6783: end = strstr (buff, ";");
6784: *end = EOS;
6785: ColApplyCSSRule (el, (PresentationContext) ctxt, buff, NULL);
6786: TtaFreeMemory (buff);
6787: }
6788: else
6789: ColApplyCSSRule (el, (PresentationContext) ctxt, ptr, NULL);
6790: }
1.406 quint 6791: else
6792: ParseCSSRule (el, NULL, ctxt, cssRule, NULL, isHTML);
6793:
1.257 vatton 6794: /* restore the display mode if necessary */
1.417 vatton 6795: if (dispMode != NoComputedDisplay)
6796: TtaSetDisplayMode (doc, dispMode);
1.207 vatton 6797: /* check if the context can be freed */
6798: ctxt->uses -= 1;
6799: if (ctxt->uses == 0)
6800: /* no image loading */
6801: TtaFreeMemory(ctxt);
1.1 cvs 6802: }
6803:
1.366 vatton 6804:
1.343 vatton 6805: /*----------------------------------------------------------------------
6806: AddClassName adds the class name into the class list of css if it's
6807: not already there.
6808: ----------------------------------------------------------------------*/
6809: static void AddClassName (char *name, CSSInfoPtr css)
6810: {
1.344 cvs 6811: int l, index, k, length, add;
1.343 vatton 6812: char *buf;
6813: ThotBool found, previous;
6814:
6815: l = strlen (name);
6816: if (l == 0 || css == NULL)
6817: return;
6818: if (css->class_list)
6819: {
6820: buf = css->class_list;
6821: length = strlen (css->class_list);
6822: }
6823: else
6824: {
6825: if (l > 200)
6826: length = l + 1;
6827: else
6828: length = 200;
6829: buf = (char *)TtaGetMemory (length * sizeof (char));
6830: memset (buf, 0, length);
6831: css->class_list = buf;
6832: css->lg_class_list = length;
6833: length = 0;
6834: }
6835:
6836: /* compare that name with all class names already known */
6837: index = 0;
6838: found = FALSE;
6839: previous = FALSE;
6840: while (index < length && !found && !previous)
6841: {
6842: k = 0;
6843: while (k < l && buf[index + k] != EOS && buf[index + k] != SPACE)
6844: {
6845: if (name[k] == buf[index+k])
6846: k++;
6847: else
6848: {
6849: previous = (name[k] < buf[index + k]);
6850: break;
6851: }
6852: }
6853: found = (k == l);
6854: if (!previous)
6855: {
6856: index += k;
6857: while (buf[index] != EOS && buf[index] != SPACE)
6858: index++;
6859: if (buf[index] == SPACE)
6860: index++;
6861: }
6862: }
6863:
6864: if (!found)
6865: /* this class name is not known, append it */
6866: {
6867: l++; /* add a space before */
6868: if (css->lg_class_list <= length + l)
6869: {
6870: // increase the list size
6871: if (l > 200)
6872: add = l + 1;
6873: else
6874: add = 200 ;
6875: buf = (char *)TtaRealloc (buf, css->lg_class_list + (add * sizeof (char)));
6876: if (buf == NULL)
6877: return;
6878: else
6879: {
6880: css->class_list = buf;
6881: memset (&buf[css->lg_class_list], 0, add);
6882: css->lg_class_list += add;
6883: }
6884: }
6885:
6886: if (previous)
6887: {
6888: // move the tail of the current list
6889: for (k = length; k >= index; k--)
6890: buf[k+l] = buf[k];
6891: /* add this new class name at the current position */
6892: strcpy (&buf[index], name);
6893: buf[index + l - 1] = SPACE;
6894: }
6895: else
6896: {
6897: /* add this new class name at the end */
6898: if (index != 0)
6899: buf[index++] = SPACE;
6900: strcpy (&buf[index], name);
6901: }
6902: }
6903: }
6904:
1.68 cvs 6905:
1.1 cvs 6906: /*----------------------------------------------------------------------
1.207 vatton 6907: ParseGenericSelector: Create a generic context for a given selector
6908: string.
6909: If the selector is made of multiple comma, it parses them one at a time
6910: and return the end of the selector string to be handled or NULL.
1.231 vatton 6911: The parameter ctxt gives the current style context which will be passed
6912: to Thotlib.
6913: The parameter css points to the current CSS context.
6914: The parameter link points to the link element.
6915: The parameter url gives the URL of the parsed style sheet.
1.1 cvs 6916: ----------------------------------------------------------------------*/
1.207 vatton 6917: static char *ParseGenericSelector (char *selector, char *cssRule,
1.327 vatton 6918: GenericContext ctxt, Document doc,
6919: CSSInfoPtr css, Element link, char *url)
1.79 cvs 6920: {
6921: ElementType elType;
6922: PSchema tsch;
1.119 vatton 6923: AttributeType attrType;
1.398 vatton 6924: char *deb, *cur, *sel, *next, *limit, c;
1.317 vatton 6925: char *schemaName, *mappedName, *saveURL;
1.79 cvs 6926: char *names[MAX_ANCESTORS];
1.355 quint 6927: ThotBool pseudoFirstChild[MAX_ANCESTORS];
1.340 quint 6928: ElemRel rel[MAX_ANCESTORS];
6929: char *attrnames[MAX_ANCESTORS];
6930: int attrnums[MAX_ANCESTORS];
6931: int attrlevels[MAX_ANCESTORS];
1.79 cvs 6932: char *attrvals[MAX_ANCESTORS];
1.133 vatton 6933: AttrMatch attrmatch[MAX_ANCESTORS];
1.340 quint 6934: int nbnames, nbattrs;
6935: int i, j;
1.256 vatton 6936: int att, kind;
1.118 vatton 6937: int specificity, xmlType;
1.217 vatton 6938: int skippedNL;
1.404 vatton 6939: ThotBool isHTML, noname, warn;
1.347 quint 6940: ThotBool level, quoted, doubleColon;
1.340 quint 6941: #define ATTR_ID 1
6942: #define ATTR_CLASS 2
6943: #define ATTR_PSEUDO 3
1.1 cvs 6944:
1.404 vatton 6945: // check if Amaya should report CSS warnings
6946: TtaGetEnvBoolean ("CSS_WARN", &warn);
1.207 vatton 6947: sel = ctxt->sel;
1.82 cvs 6948: sel[0] = EOS;
1.398 vatton 6949: // get the limit of the string
6950: limit = &sel[MAX_ANCESTORS * 50 -1];
6951: *limit = EOS;
1.117 vatton 6952: specificity = 0;
1.1 cvs 6953: for (i = 0; i < MAX_ANCESTORS; i++)
6954: {
1.25 cvs 6955: names[i] = NULL;
1.355 quint 6956: pseudoFirstChild[i] = FALSE;
1.340 quint 6957: rel[i] = RelAncestor;
6958: attrnames[i] = NULL;
6959: attrnums[i] = 0;
6960: attrlevels[i] = 0;
1.25 cvs 6961: attrvals[i] = NULL;
1.133 vatton 6962: attrmatch[i] = Txtmatch;
1.25 cvs 6963: ctxt->name[i] = 0;
1.355 quint 6964: ctxt->firstChild[i] = FALSE;
1.25 cvs 6965: ctxt->attrType[i] = 0;
1.129 vatton 6966: ctxt->attrLevel[i] = 0;
1.25 cvs 6967: ctxt->attrText[i] = NULL;
1.178 quint 6968: ctxt->attrMatch[i] = Txtmatch;
1.1 cvs 6969: }
1.25 cvs 6970: ctxt->box = 0;
1.312 quint 6971: ctxt->var = 0;
1.306 quint 6972: ctxt->pseudo = PbNone;
1.25 cvs 6973: ctxt->type = 0;
1.366 vatton 6974: DoDialog = FALSE; // not arsing for CSS dialog
1.114 quint 6975: /* the specificity of the rule depends on the selector */
6976: ctxt->cssSpecificity = 0;
1.231 vatton 6977: /* localisation of the CSS rule */
6978: ctxt->cssLine = LineNumber + NewLineSkipped;
6979: ctxt->cssURL = url;
1.240 quint 6980:
1.286 quint 6981: skippedNL = NewLineSkipped;
1.82 cvs 6982: selector = SkipBlanksAndComments (selector);
1.286 quint 6983: NewLineSkipped = skippedNL;
1.27 cvs 6984: cur = &sel[0];
1.340 quint 6985: nbnames = 0;
6986: nbattrs = 0;
1.1 cvs 6987: while (1)
6988: {
1.85 cvs 6989: /* point to the following word in sel[] */
1.27 cvs 6990: deb = cur;
1.25 cvs 6991: /* copy an item of the selector into sel[] */
1.1 cvs 6992: /* put one word in the sel buffer */
1.82 cvs 6993: while (*selector != EOS && *selector != ',' &&
6994: *selector != '.' && *selector != ':' &&
1.118 vatton 6995: *selector != '#' && *selector != '[' &&
1.250 vatton 6996: *selector != '>' && *selector != '+' &&
1.398 vatton 6997: !TtaIsBlank (selector) && cur < limit)
1.327 vatton 6998: *cur++ = *selector++;
1.82 cvs 6999: *cur++ = EOS; /* close the first string in sel[] */
1.380 vatton 7000: noname = TRUE;
1.82 cvs 7001: if (deb[0] != EOS)
1.340 quint 7002: /* the selector starts with an element name */
1.327 vatton 7003: {
7004: if (deb[0] <= 64 && deb[0] != '*')
7005: {
7006: CSSPrintError ("Invalid element", deb);
1.380 vatton 7007: names[0] = NULL; /* no element name */
7008: DoApply = FALSE;
1.327 vatton 7009: }
7010: else
7011: {
1.380 vatton 7012: noname = FALSE;
1.327 vatton 7013: names[0] = deb;
7014: if (!strcmp (names[0], "html"))
7015: /* give a greater priority to the backgoud color of html */
7016: specificity += 3;
7017: else
7018: /* selector "*" has specificity zero */
7019: if (strcmp (names[0], "*"))
7020: specificity += 1;
7021: }
7022: }
1.25 cvs 7023: else
1.340 quint 7024: names[0] = NULL; /* no element name */
1.226 quint 7025:
1.340 quint 7026: rel[0] = RelVoid;
1.27 cvs 7027: /* now names[0] points to the beginning of the parsed item
1.340 quint 7028: and cur to the next string to be parsed */
1.129 vatton 7029: while (*selector == '.' || *selector == ':' ||
1.327 vatton 7030: *selector == '#' || *selector == '[')
7031: {
7032: /* point to the following word in sel[] */
7033: deb = cur;
7034: if (*selector == '.')
1.340 quint 7035: /* class */
1.327 vatton 7036: {
7037: selector++;
1.340 quint 7038: while (*selector != '.' && *selector != ':' &&
7039: *selector != '#' && *selector != '[' &&
7040: *selector != EOS && *selector != ',' &&
7041: *selector != '+' && *selector != '>' &&
1.398 vatton 7042: !TtaIsBlank (selector) && cur < limit)
1.327 vatton 7043: {
7044: if (*selector == '\\')
7045: {
7046: selector++;
7047: if (*selector != EOS)
7048: *cur++ = *selector++;
7049: }
7050: else
7051: *cur++ = *selector++;
7052: }
7053: /* close the word */
7054: *cur++ = EOS;
1.340 quint 7055: /* point to the class in sel[] if it's a valid name */
1.327 vatton 7056: if (deb[0] <= 64)
7057: {
7058: CSSPrintError ("Invalid class", deb);
7059: DoApply = FALSE;
7060: }
7061: else
7062: {
1.340 quint 7063: /* simulate selector [class ~= "xxx"] */
7064: nbattrs++;
7065: if (nbattrs == MAX_ANCESTORS)
7066: /* abort parsing */
7067: {
7068: CSSPrintError ("Selector too long", deb);
7069: return (selector);
7070: }
7071: for (i = nbattrs; i > 0; i--)
7072: {
7073: attrnames[i] = attrnames[i - 1];
7074: attrnums[i] = attrnums[i - 1];
7075: attrlevels[i] = attrlevels[i - 1];
7076: attrvals[i] = attrvals[i - 1];
7077: attrmatch[i] = attrmatch[i - 1];
7078: }
7079: attrnames[0] = NULL;
7080: attrnums[0] = ATTR_CLASS;
7081: attrlevels[0] = 0;
7082: attrmatch[0] = Txtword;
7083: attrvals[0] = deb;
1.327 vatton 7084: specificity += 10;
1.343 vatton 7085: }
1.327 vatton 7086: }
7087: else if (*selector == ':')
1.340 quint 7088: /* pseudo-class or pseudo-element */
1.327 vatton 7089: {
7090: selector++;
1.347 quint 7091: doubleColon = FALSE;
7092: if (*selector == ':')
7093: /* it's a double "::". Probably CSS3 syntax */
7094: {
7095: selector++;
7096: doubleColon = TRUE;
7097: }
1.340 quint 7098: while (*selector != '.' && *selector != ':' &&
7099: *selector != '#' && *selector != '[' &&
7100: *selector != EOS && *selector != ',' &&
7101: *selector != '+' && *selector != '>' &&
1.398 vatton 7102: !TtaIsBlank (selector) && cur < limit)
1.327 vatton 7103: *cur++ = *selector++;
7104: /* close the word */
7105: *cur++ = EOS;
1.340 quint 7106: /* point to the pseudo-class or pseudo-element in sel[] if it's
7107: a valid name */
1.355 quint 7108: if (!strcmp (deb, "first-child"))
7109: /* first-child pseudo-class */
1.327 vatton 7110: {
1.355 quint 7111: pseudoFirstChild[0] = TRUE;
7112: specificity += 10;
1.327 vatton 7113: }
1.355 quint 7114: else if (!strcmp (deb, "link") || !strcmp (deb, "visited"))
7115: /* link or visited pseudo-classes */
1.327 vatton 7116: {
1.355 quint 7117: nbattrs++;
7118: if (nbattrs == MAX_ANCESTORS)
7119: /* abort parsing */
1.347 quint 7120: {
1.355 quint 7121: CSSPrintError ("Selector too long", deb);
7122: return (selector);
1.347 quint 7123: }
1.355 quint 7124: for (i = nbattrs; i > 0; i--)
1.347 quint 7125: {
1.355 quint 7126: attrnames[i] = attrnames[i - 1];
7127: attrnums[i] = attrnums[i - 1];
7128: attrlevels[i] = attrlevels[i - 1];
7129: attrvals[i] = attrvals[i - 1];
7130: attrmatch[i] = attrmatch[i - 1];
1.347 quint 7131: }
1.355 quint 7132: attrnames[0] = NULL;
7133: attrnums[0] = ATTR_PSEUDO;
7134: attrlevels[0] = 0;
7135: attrmatch[0] = Txtmatch;
7136: attrvals[0] = deb;
7137: specificity += 10;
7138: }
7139: else if (!strcmp (deb, "hover") || !strcmp (deb, "active") ||
7140: !strcmp (deb, "focus"))
7141: /* hover, active, focus pseudo-classes */
7142: {
1.403 vatton 7143: attrnames[0] = NULL;
7144: attrnums[0] = ATTR_PSEUDO;
7145: attrlevels[0] = 0;
7146: attrmatch[0] = Txtmatch;
7147: attrvals[0] = deb;
1.355 quint 7148: specificity += 10;
7149: /* not supported */
7150: DoApply = FALSE;
7151: }
7152: else if (!strncmp (deb, "lang", 4))
7153: /* it's the lang pseudo-class */
7154: {
7155: if (deb[4] != '(' || deb[strlen(deb)-1] != ')')
7156: /* at least one parenthesis is missing. Error */
1.327 vatton 7157: {
1.355 quint 7158: CSSPrintError ("Invalid :lang pseudo-class", deb);
7159: DoApply = FALSE;
1.327 vatton 7160: }
7161: else
1.355 quint 7162: /* simulate selector [lang|="xxx"] */
1.340 quint 7163: {
7164: nbattrs++;
7165: if (nbattrs == MAX_ANCESTORS)
7166: /* abort parsing */
7167: {
7168: CSSPrintError ("Selector too long", deb);
7169: return (selector);
7170: }
1.355 quint 7171: deb[strlen(deb)-1] = EOS;
7172: deb[4] = EOS;
1.340 quint 7173: for (i = nbattrs; i > 0; i--)
7174: {
7175: attrnames[i] = attrnames[i - 1];
7176: attrnums[i] = attrnums[i - 1];
7177: attrlevels[i] = attrlevels[i - 1];
7178: attrvals[i] = attrvals[i - 1];
7179: attrmatch[i] = attrmatch[i - 1];
7180: }
1.355 quint 7181: attrnames[0] = deb;
7182: attrnums[0] = 0;
1.340 quint 7183: attrlevels[0] = 0;
1.355 quint 7184: attrmatch[0] = Txtsubstring;
7185: attrvals[0] = &deb[5];
7186: specificity += 10;
1.340 quint 7187: }
1.327 vatton 7188: }
1.355 quint 7189: else if (!strcmp (deb, "first-line") ||
7190: !strcmp (deb, "first-letter"))
7191: /* pseudo-elements first-line or first-letter */
7192: {
1.404 vatton 7193: if (doubleColon && warn)
1.355 quint 7194: CSSPrintError ("Warning: \"::\" is CSS3 syntax", NULL);
7195: specificity += 1;
7196: /* not supported */
7197: DoApply = FALSE;
7198: }
7199: else if (!strncmp (deb, "before", 6))
7200: /* pseudo-element before */
7201: {
1.404 vatton 7202: if (doubleColon && warn)
1.355 quint 7203: CSSPrintError ("Warning: \"::before\" is CSS3 syntax",
7204: NULL);
7205: ctxt->pseudo = PbBefore;
7206: specificity += 1;
7207: }
7208: else if (!strncmp (deb, "after", 5))
7209: /* pseudo-element after */
7210: {
1.404 vatton 7211: if (doubleColon && warn)
1.355 quint 7212: CSSPrintError ("Warning: \"::after\" is CSS3 syntax",
7213: NULL);
7214: ctxt->pseudo = PbAfter;
7215: specificity += 1;
7216: }
1.433 vatton 7217: else if (!strncmp (deb, "target", 6))
1.404 vatton 7218: {
1.433 vatton 7219: if (warn)
1.404 vatton 7220: CSSPrintError ("Warning: \":target\" is CSS3 syntax",
7221: NULL);
7222: specificity += 1;
7223: DoApply = FALSE;
7224: }
1.433 vatton 7225: else if (!strncmp (deb, "not", 3) ||
7226: !strncmp (deb, "only", 4) ||
7227: !strncmp (deb, "last", 4))
7228: {
7229: if (warn)
7230: CSSPrintError ("Warning: Not supported CSS3 syntax",
7231: NULL);
7232: specificity += 1;
7233: DoApply = FALSE;
7234: }
7235: else
1.355 quint 7236: {
7237: CSSPrintError ("Invalid pseudo-element", deb);
7238: DoApply = FALSE;
7239: }
7240: if (names[0] && !strcmp (names[0], "*"))
7241: names[0] = NULL;
1.327 vatton 7242: }
7243: else if (*selector == '#')
1.340 quint 7244: /* unique identifier */
1.327 vatton 7245: {
7246: selector++;
1.340 quint 7247: while (*selector != '.' && *selector != ':' &&
7248: *selector != '#' && *selector != '[' &&
7249: *selector != '+' && *selector != '>' &&
7250: *selector != EOS && *selector != ',' &&
1.398 vatton 7251: !TtaIsBlank (selector) && cur < limit)
1.327 vatton 7252: *cur++ = *selector++;
7253: /* close the word */
7254: *cur++ = EOS;
7255: /* point to the attribute in sel[] if it's valid name */
7256: if (deb[0] <= 64)
7257: {
7258: CSSPrintError ("Invalid id", deb);
7259: DoApply = FALSE;
7260: }
7261: else
7262: {
1.340 quint 7263: nbattrs++;
7264: if (nbattrs == MAX_ANCESTORS)
7265: /* abort parsing */
7266: {
7267: CSSPrintError ("Selector too long", deb);
7268: return (selector);
7269: }
7270: for (i = nbattrs; i > 0; i--)
7271: {
7272: attrnames[i] = attrnames[i - 1];
7273: attrnums[i] = attrnums[i - 1];
7274: attrlevels[i] = attrlevels[i - 1];
7275: attrvals[i] = attrvals[i - 1];
7276: attrmatch[i] = attrmatch[i - 1];
7277: }
7278: attrnames[0] = NULL;
7279: attrnums[0] = ATTR_ID;
7280: attrlevels[0] = 0;
7281: attrmatch[0] = Txtmatch;
7282: attrvals[0] = deb;
7283: specificity += 100;
7284: if (names[0] && !strcmp (names[0], "*"))
7285: names[0] = NULL;
1.327 vatton 7286: }
7287: }
7288: else if (*selector == '[')
7289: {
7290: selector++;
1.341 quint 7291: selector = SkipBlanksAndComments (selector);
1.327 vatton 7292: while (*selector != EOS && *selector != ']' &&
7293: *selector != '=' && *selector != '~' &&
1.341 quint 7294: *selector != '|' && *selector != '^' &&
1.396 vatton 7295: *selector != '$' && *selector != '*' &&
1.398 vatton 7296: !TtaIsBlank (selector) && cur < limit)
1.327 vatton 7297: *cur++ = *selector++;
1.341 quint 7298: /* close the word (attribute name) */
1.327 vatton 7299: *cur++ = EOS;
7300: /* point to the attribute in sel[] if it's valid name */
7301: if (deb[0] <= 64)
7302: {
7303: CSSPrintError ("Invalid attribute", deb);
7304: DoApply = FALSE;
7305: }
7306: else
7307: {
1.340 quint 7308: nbattrs++;
7309: if (nbattrs == MAX_ANCESTORS)
7310: /* abort parsing */
7311: {
7312: CSSPrintError ("Selector too long", deb);
7313: return (selector);
7314: }
7315: for (i = nbattrs; i > 0; i--)
7316: {
7317: attrnames[i] = attrnames[i - 1];
7318: attrnums[i] = attrnums[i - 1];
7319: attrlevels[i] = attrlevels[i - 1];
7320: attrvals[i] = attrvals[i - 1];
7321: attrmatch[i] = attrmatch[i - 1];
7322: }
7323: attrnames[0] = deb;
7324: attrnums[0] = 0;
7325: attrlevels[0] = 0;
1.378 quint 7326: attrvals[0] = NULL;
7327: attrmatch[0] = Txtmatch;
1.327 vatton 7328: specificity += 10;
1.340 quint 7329: /* check matching */
1.341 quint 7330: selector = SkipBlanksAndComments (selector);
1.340 quint 7331: if (*selector == '~')
7332: {
7333: attrmatch[0] = Txtword;
7334: selector++;
7335: }
1.396 vatton 7336: else if (*selector == '|' || *selector == '$' || *selector == '*')
1.340 quint 7337: {
1.404 vatton 7338: if (*selector == '$' && warn)
1.396 vatton 7339: CSSPrintError ("Warning: \"$=\" is CSS3 syntax", NULL);
1.404 vatton 7340: if (*selector == '*' && warn)
1.396 vatton 7341: CSSPrintError ("Warning: \"*=\" is CSS3 syntax", NULL);
1.340 quint 7342: attrmatch[0] = Txtsubstring;
7343: selector++;
7344: }
1.341 quint 7345: else if (*selector == '^')
7346: {
7347: attrmatch[0] = Txtsubstring;
7348: selector++;
7349: }
1.340 quint 7350: else
7351: attrmatch[0] = Txtmatch;
1.327 vatton 7352: }
7353: if (*selector == '=')
7354: {
7355: /* look for a value "xxxx" */
7356: selector++;
1.341 quint 7357: selector = SkipBlanksAndComments (selector);
1.327 vatton 7358: if (*selector != '"')
7359: quoted = FALSE;
7360: else
7361: {
7362: quoted = TRUE;
7363: /* we are now parsing the attribute value */
7364: selector++;
7365: }
7366: deb = cur;
1.398 vatton 7367: while ((quoted && cur < limit &&
1.327 vatton 7368: (*selector != '"' ||
7369: (*selector == '"' && selector[-1] == '\\'))) ||
7370: (!quoted && *selector != ']'))
7371: {
7372: if (*selector == EOS)
7373: {
7374: CSSPrintError ("Invalid attribute value", deb);
7375: DoApply = FALSE;
7376: }
7377: else
7378: {
7379: if (attrmatch[0] == Txtword && TtaIsBlank (selector))
7380: {
7381: CSSPrintError ("No space allowed here: ", selector);
7382: DoApply = FALSE;
7383: }
7384: *cur++ = *selector;
7385: }
7386: selector++;
7387: }
7388: /* there is a value */
7389: if (quoted && *selector == '"')
7390: {
7391: selector++;
7392: quoted = FALSE;
7393: }
1.341 quint 7394: selector = SkipBlanksAndComments (selector);
1.327 vatton 7395: if (*selector != ']')
7396: {
7397: CSSPrintError ("Invalid attribute value", deb);
7398: DoApply = FALSE;
7399: }
7400: else
7401: {
7402: *cur++ = EOS;
7403: attrvals[0] = deb;
7404: selector++;
7405: }
7406: }
7407: /* end of the attribute */
7408: else if (*selector != ']')
7409: {
7410: selector[1] = EOS;
7411: CSSPrintError ("Invalid attribute", selector);
7412: selector += 2;
7413: DoApply = FALSE;
7414: }
7415: else
7416: {
7417: selector++;
7418: if (names[0] && !strcmp (names[0], "*"))
7419: names[0] = NULL;
7420: }
7421: }
7422: else
7423: {
7424: /* not supported selector */
1.340 quint 7425: while (*selector != '.' && *selector != ':' &&
7426: *selector != '#' && *selector != '[' &&
7427: *selector != EOS && *selector != ',' &&
7428: *selector != '+' && *selector != '>' &&
1.398 vatton 7429: !TtaIsBlank (selector) && cur < limit)
1.327 vatton 7430: *cur++ = *selector++;
7431: /* close the word */
7432: *cur++ = EOS;
7433: CSSPrintError ("Selector not supported:", deb);
7434: DoApply = FALSE;
7435: }
7436: }
1.1 cvs 7437:
1.286 quint 7438: skippedNL = NewLineSkipped;
1.82 cvs 7439: selector = SkipBlanksAndComments (selector);
1.286 quint 7440: NewLineSkipped = skippedNL;
7441:
1.380 vatton 7442: if (noname && !pseudoFirstChild[0] && attrnums[0] == 0 && attrnames[0] == NULL)
7443: {
7444: *cur++ = EOS;
7445: CSSPrintError ("Invalid Selector", deb);
7446: DoApply = FALSE;
7447: }
1.25 cvs 7448: /* is it a multi-level selector? */
1.82 cvs 7449: if (*selector == EOS)
1.327 vatton 7450: /* end of the selector */
7451: break;
1.82 cvs 7452: else if (*selector == ',')
1.327 vatton 7453: {
7454: /* end of the current selector */
7455: selector++;
7456: skippedNL = NewLineSkipped;
7457: next = SkipBlanksAndComments (selector);
7458: NewLineSkipped = skippedNL;
7459: if (*next == EOS)
7460: /* nothing after the comma. Invalid selector */
7461: {
1.380 vatton 7462: CSSPrintError ("Syntax error:", selector);
7463: selector = NULL;
1.327 vatton 7464: }
7465: break;
7466: }
1.25 cvs 7467: else
1.327 vatton 7468: {
7469: if (*selector == '>')
7470: {
1.340 quint 7471: /* handle parent */
1.327 vatton 7472: selector++;
7473: skippedNL = NewLineSkipped;
7474: selector = SkipBlanksAndComments (selector);
7475: NewLineSkipped = skippedNL;
1.340 quint 7476: rel[0] = RelParent;
1.327 vatton 7477: }
7478: else if (*selector == '+')
7479: {
1.340 quint 7480: /* handle immediate sibling */
1.327 vatton 7481: selector++;
7482: skippedNL = NewLineSkipped;
7483: selector = SkipBlanksAndComments (selector);
7484: NewLineSkipped = skippedNL;
7485: rel[0] = RelPrevious;
7486: }
1.340 quint 7487: else
7488: rel[0] = RelAncestor;
7489: nbnames++; /* a new level in ancestor tables */
7490: if (nbnames == MAX_ANCESTORS)
7491: /* abort parsing */
7492: {
7493: CSSPrintError ("Selector too long", deb);
7494: return (selector);
7495: }
7496: /* shift the list to make room for the next part of the selector */
7497: for (i = nbnames; i > 0; i--)
1.327 vatton 7498: {
7499: names[i] = names[i - 1];
1.355 quint 7500: pseudoFirstChild[i] = pseudoFirstChild[i - 1];
1.327 vatton 7501: rel[i] = rel[i - 1];
7502: }
1.340 quint 7503: /* increase the level of all attributes */
7504: for (i = 0; i < nbattrs; i++)
7505: attrlevels[i]++;
1.327 vatton 7506: }
1.1 cvs 7507: }
7508:
1.343 vatton 7509: /* Now update the list of classes defined by the CSS */
7510: for (i = 0; i < nbattrs; i++)
7511: if (attrvals[i] && attrnums[i] == ATTR_CLASS)
7512: AddClassName (attrvals[i], css);
7513:
1.1 cvs 7514: /* Now set up the context block */
1.25 cvs 7515: i = 0;
7516: j = 0;
1.91 cvs 7517: /* default schema name */
1.119 vatton 7518: ctxt->schema = NULL;
1.340 quint 7519: ctxt->nbElem = nbnames;
1.122 vatton 7520: elType.ElSSchema = NULL;
1.355 quint 7521: elType.ElTypeNum = 0;
1.122 vatton 7522: schemaName = TtaGetSSchemaName(TtaGetDocumentSSchema (doc));
1.119 vatton 7523: if (!strcmp (schemaName, "HTML"))
7524: xmlType = XHTML_TYPE;
7525: else if (!strcmp (schemaName, "MathML"))
7526: xmlType = MATH_TYPE;
7527: else if (!strcmp (schemaName, "SVG"))
7528: xmlType = SVG_TYPE;
7529: else if (!strcmp (schemaName, "XLink"))
7530: xmlType = XLINK_TYPE;
7531: else if (!strcmp (schemaName, "Annot"))
7532: xmlType = ANNOT_TYPE;
7533: else
7534: xmlType = XML_TYPE;
1.340 quint 7535: while (i <= nbnames)
1.25 cvs 7536: {
1.340 quint 7537: ctxt->rel[i] = rel[i];
1.355 quint 7538: ctxt->firstChild[i] = pseudoFirstChild[i];
7539: if (!names[i] && i > 0)
1.340 quint 7540: ctxt->name[i] = HTML_EL_ANY_TYPE;
7541: else
7542: /* store element information */
1.327 vatton 7543: {
7544: /* get the element type of this name in the current document */
7545: if (xmlType == XML_TYPE)
7546: /* it's a generic XML document. Check the main document schema */
7547: {
7548: elType.ElSSchema = TtaGetDocumentSSchema (doc);
1.355 quint 7549: elType.ElTypeNum = 0;
7550: if (names[i])
7551: TtaGetXmlElementType (names[i], &elType, &mappedName, doc);
1.327 vatton 7552: if (!elType.ElTypeNum)
7553: {
1.355 quint 7554: if (!names[i] || !strcmp (names[i], "*"))
1.327 vatton 7555: elType.ElTypeNum = HTML_EL_ANY_TYPE;
7556: else
7557: elType.ElSSchema = NULL;
7558: }
7559: }
7560: else
7561: {
1.355 quint 7562: if (!names[i] || !strcmp (names[i], "*"))
1.327 vatton 7563: {
7564: elType.ElSSchema = TtaGetDocumentSSchema (doc);
7565: elType.ElTypeNum = HTML_EL_ANY_TYPE;
7566: }
7567: else
7568: MapXMLElementType (xmlType, names[i], &elType, &mappedName, &c,
7569: &level, doc);
7570: }
7571: if (i == 0)
1.340 quint 7572: /* rightmost part of the selector */
1.327 vatton 7573: {
7574: if (elType.ElSSchema == NULL)
7575: {
1.340 quint 7576: /* element name not found. Search in all loaded schemas */
1.355 quint 7577: if (names[i])
7578: TtaGetXmlElementType (names[i], &elType, NULL, doc);
1.327 vatton 7579: if (elType.ElSSchema)
7580: {
7581: /* the element type concerns an imported nature */
7582: schemaName = TtaGetSSchemaName(elType.ElSSchema);
7583: if (!strcmp (schemaName, "HTML"))
7584: {
7585: if (xmlType == XHTML_TYPE &&
7586: DocumentMeta[doc] && DocumentMeta[doc]->xmlformat)
7587: /* the selector was found but the case is not correct */
7588: elType.ElSSchema = NULL;
7589: else
7590: xmlType = XHTML_TYPE;
7591: }
7592: else if (!strcmp (schemaName, "MathML"))
7593: xmlType = MATH_TYPE;
7594: else if (!strcmp (schemaName, "SVG"))
7595: xmlType = SVG_TYPE;
7596: else if (!strcmp (schemaName, "XLink"))
7597: xmlType = XLINK_TYPE;
7598: else if (!strcmp (schemaName, "Annot"))
7599: xmlType = ANNOT_TYPE;
7600: else
7601: xmlType = XML_TYPE;
7602: }
1.118 vatton 7603: #ifdef XML_GENERIC
1.327 vatton 7604: else if (xmlType == XML_TYPE)
7605: {
7606: /* Creation of a new element type in the main schema */
7607: elType.ElSSchema = TtaGetDocumentSSchema (doc);
1.355 quint 7608: if (names[i])
7609: TtaAppendXmlElement (names[i], &elType, &mappedName,
7610: doc);
1.327 vatton 7611: }
1.118 vatton 7612: #endif /* XML_GENERIC */
1.327 vatton 7613: else
7614: {
7615: if (xmlType != XHTML_TYPE)
7616: {
7617: MapXMLElementType (XHTML_TYPE, names[i], &elType,
7618: &mappedName, &c, &level, doc);
7619: if (elType.ElSSchema)
7620: elType.ElSSchema = GetXHTMLSSchema (doc);
7621: }
7622: if (elType.ElSSchema == NULL && xmlType != MATH_TYPE)
7623: {
7624: MapXMLElementType (MATH_TYPE, names[i], &elType,
7625: &mappedName, &c, &level, doc);
7626: if (elType.ElSSchema)
7627: elType.ElSSchema = GetMathMLSSchema (doc);
7628: }
7629: if (elType.ElSSchema == NULL && xmlType != SVG_TYPE)
7630: {
7631: MapXMLElementType (SVG_TYPE, names[i], &elType,
7632: &mappedName, &c, &level, doc);
7633: if (elType.ElSSchema)
7634: elType.ElSSchema = GetSVGSSchema (doc);
7635: }
7636: }
7637: }
7638:
7639: if (elType.ElSSchema == NULL)
7640: /* cannot apply these CSS rules */
7641: DoApply = FALSE;
7642: else
7643: {
1.340 quint 7644: /* Store the element type contained in the rightmost part of
7645: the selector */
7646: ctxt->schema = elType.ElSSchema;
1.327 vatton 7647: ctxt->type = elType.ElTypeNum;
7648: ctxt->name[0] = elType.ElTypeNum;
1.340 quint 7649: ctxt->rel[0] = RelVoid;
1.327 vatton 7650: }
7651: }
1.340 quint 7652: else
7653: /* not the rightmost part of the selector */
1.327 vatton 7654: {
1.340 quint 7655: if (elType.ElTypeNum != 0)
7656: ctxt->name[i] = elType.ElTypeNum;
7657: #ifdef XML_GENERIC
7658: else if (xmlType == XML_TYPE)
1.327 vatton 7659: {
1.340 quint 7660: TtaGetXmlElementType (names[i], &elType, NULL, doc);
7661: if (elType.ElTypeNum == 0)
1.327 vatton 7662: {
1.340 quint 7663: /* Creation of a new element type in the main schema */
7664: elType.ElSSchema = TtaGetDocumentSSchema (doc);
7665: TtaAppendXmlElement (names[i], &elType, &mappedName, doc);
1.327 vatton 7666: }
1.340 quint 7667: if (elType.ElTypeNum != 0)
7668: ctxt->name[i] = elType.ElTypeNum;
1.327 vatton 7669: }
1.340 quint 7670: #endif /* XML_GENERIC */
1.327 vatton 7671: }
1.340 quint 7672: }
7673:
7674: /* store attribute information for this element */
7675: while (j < nbattrs && attrlevels[j] <= i)
7676: {
7677: if (attrnames[j] || attrnums[j])
1.327 vatton 7678: {
1.340 quint 7679: if (attrnums[j] > 0)
1.327 vatton 7680: {
1.340 quint 7681: if (attrnums[j] == ATTR_CLASS)
1.327 vatton 7682: {
1.340 quint 7683: if (xmlType == SVG_TYPE)
7684: ctxt->attrType[j] = SVG_ATTR_class;
7685: else if (xmlType == MATH_TYPE)
7686: ctxt->attrType[j] = MathML_ATTR_class;
7687: else if (xmlType == XHTML_TYPE)
7688: ctxt->attrType[j] = HTML_ATTR_Class;
1.327 vatton 7689: else
1.119 vatton 7690: #ifdef XML_GENERIC
1.340 quint 7691: ctxt->attrType[j] = XML_ATTR_class;
1.107 cvs 7692: #else /* XML_GENERIC */
1.340 quint 7693: ctxt->attrType[j] = HTML_ATTR_Class;
1.107 cvs 7694: #endif /* XML_GENERIC */
1.340 quint 7695: }
7696: else if (attrnums[j] == ATTR_PSEUDO)
7697: {
7698: if (xmlType == SVG_TYPE)
7699: ctxt->attrType[j] = SVG_ATTR_PseudoClass;
7700: else if (xmlType == MATH_TYPE)
7701: ctxt->attrType[j] = MathML_ATTR_PseudoClass;
7702: else if (xmlType == XHTML_TYPE)
7703: ctxt->attrType[j] = HTML_ATTR_PseudoClass;
7704: else
1.119 vatton 7705: #ifdef XML_GENERIC
1.340 quint 7706: ctxt->attrType[j] = XML_ATTR_PseudoClass;
1.107 cvs 7707: #else /* XML_GENERIC */
1.340 quint 7708: ctxt->attrType[j] = HTML_ATTR_PseudoClass;
1.107 cvs 7709: #endif /* XML_GENERIC */
1.340 quint 7710: }
7711: else if (attrnums[j] == ATTR_ID)
7712: {
7713: if (xmlType == SVG_TYPE)
7714: ctxt->attrType[j] = SVG_ATTR_id;
7715: else if (xmlType == MATH_TYPE)
7716: ctxt->attrType[j] = MathML_ATTR_id;
7717: else if (xmlType == XHTML_TYPE)
7718: ctxt->attrType[j] = HTML_ATTR_ID;
7719: else
1.119 vatton 7720: #ifdef XML_GENERIC
1.340 quint 7721: ctxt->attrType[j] = XML_ATTR_xmlid;
1.107 cvs 7722: #else /* XML_GENERIC */
1.340 quint 7723: ctxt->attrType[j] = HTML_ATTR_ID;
1.107 cvs 7724: #endif /* XML_GENERIC */
1.340 quint 7725: }
7726: attrType.AttrTypeNum = ctxt->attrType[j];
7727: attrType.AttrSSchema = ctxt->schema;
7728: }
7729: else if (attrnames[j])
7730: {
7731: if (xmlType == XML_TYPE)
7732: {
7733: if (ctxt->schema)
7734: attrType.AttrSSchema = ctxt->schema;
7735: else
7736: attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
7737: TtaGetXmlAttributeType (attrnames[j], &attrType, doc);
7738: att = attrType.AttrTypeNum;
7739: if (ctxt->schema == NULL && att != 0)
7740: ctxt->schema = attrType.AttrSSchema;
7741: }
7742: else
7743: {
7744: MapXMLAttribute (xmlType, attrnames[j], names[i], &level,
7745: doc, &att);
7746: if (ctxt->schema == NULL && att != 0)
7747: ctxt->schema = TtaGetDocumentSSchema (doc);
7748: }
1.393 quint 7749: if (att == 0 && xmlType != XML_TYPE)
1.340 quint 7750: /* Attribute name not found: Search in the list of all
7751: schemas loaded for this document */
7752: {
7753: attrType.AttrSSchema = NULL;
7754: TtaGetXmlAttributeType (attrnames[j], &attrType, doc);
7755: att = attrType.AttrTypeNum;
7756: if (att != 0)
1.393 quint 7757: {
7758: ctxt->schema = attrType.AttrSSchema;
7759: schemaName = TtaGetSSchemaName(attrType.AttrSSchema);
7760: }
1.340 quint 7761: }
7762: attrType.AttrSSchema = ctxt->schema;
7763: attrType.AttrTypeNum = att;
1.412 vatton 7764: if ((i == 0 || xmlType == XML_TYPE) && att == 0)
1.340 quint 7765: {
1.119 vatton 7766: #ifdef XML_GENERIC
1.393 quint 7767: if (xmlType == XML_TYPE)
1.340 quint 7768: {
7769: /* The attribute is not yet present in the tree */
7770: /* Create a new global attribute */
7771: attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
7772: TtaAppendXmlAttribute (attrnames[j], &attrType, doc);
1.393 quint 7773: att = attrType.AttrTypeNum;
1.340 quint 7774: }
7775: #endif /* XML_GENERIC */
7776: if (attrType.AttrSSchema == NULL)
7777: /* cannot apply these CSS rules */
7778: DoApply = FALSE;
7779: else if (elType.ElSSchema)
7780: ctxt->schema = elType.ElSSchema;
7781: else
7782: ctxt->schema = attrType.AttrSSchema;
7783: }
7784: if (att == 0)
7785: {
7786: CSSPrintError ("Unknown attribute", attrnames[j]);
7787: DoApply = FALSE;
7788: }
7789: else
1.345 quint 7790: {
7791: ctxt->attrType[j] = att;
7792: if (att == DummyAttribute && !strcmp (schemaName,"HTML"))
7793: /* it's the "type" attribute for an "input" element.
7794: In the tree, it is represented by the element type,
7795: not by an attribute */
7796: {
7797: ctxt->attrType[j] = 0;
7798: if (attrvals[j] && attrmatch[i] == Txtmatch)
7799: /* a value is specified for attribute type. This
7800: value provides the Thot element type */
7801: {
7802: MapXMLAttributeValue (xmlType, attrvals[j],
7803: &attrType, &kind);
7804: /* attrType contains the element type */
7805: if (i == 0)
7806: ctxt->type = kind;
7807: ctxt->name[i] = kind;
7808: }
7809: }
7810: }
1.340 quint 7811: }
7812: if (ctxt->attrType[j])
1.327 vatton 7813: {
1.340 quint 7814: /* check the attribute type */
7815: if (!strcmp (schemaName, "HTML"))
7816: xmlType = XHTML_TYPE;
7817: else if (!strcmp (schemaName, "MathML"))
7818: xmlType = MATH_TYPE;
7819: else if (!strcmp (schemaName, "SVG"))
7820: xmlType = SVG_TYPE;
7821: else if (!strcmp (schemaName, "XLink"))
7822: xmlType = XLINK_TYPE;
7823: else if (!strcmp (schemaName, "Annot"))
7824: xmlType = ANNOT_TYPE;
7825: else
7826: xmlType = XML_TYPE;
7827: kind = TtaGetAttributeKind (attrType);
7828: if (kind == 0 && attrvals[j])
7829: {
7830: /* enumerated value */
7831: MapXMLAttributeValue (xmlType, attrvals[j], &attrType,
7832: &kind);
7833: /* store the attribute value */
7834: ctxt->attrText[j] = (char *) kind;
7835: }
7836: else
7837: ctxt->attrText[j] = attrvals[j];
7838: /* update attrLevel */
7839: ctxt->attrMatch[j] = attrmatch[j];
7840: ctxt->attrLevel[j] = attrlevels[j];
7841: }
7842: j++;
1.327 vatton 7843: }
7844: }
1.340 quint 7845: /* add a new entry */
1.25 cvs 7846: i++;
1.119 vatton 7847: if (i == 1 && ctxt->schema == NULL)
1.327 vatton 7848: /* use the document schema */
7849: ctxt->schema = TtaGetDocumentSSchema (doc);
1.1 cvs 7850: }
1.340 quint 7851:
1.312 quint 7852: ctxt->important = FALSE;
1.117 vatton 7853: /* set the selector specificity */
7854: ctxt->cssSpecificity = specificity;
1.25 cvs 7855: /* Get the schema name of the main element */
1.119 vatton 7856: schemaName = TtaGetSSchemaName (ctxt->schema);
7857: isHTML = (strcmp (schemaName, "HTML") == 0);
1.206 vatton 7858: tsch = GetPExtension (doc, ctxt->schema, css, link);
1.217 vatton 7859: skippedNL = NewLineSkipped;
1.380 vatton 7860: if (DoApply && tsch && cssRule)
1.317 vatton 7861: {
7862: if (css)
1.327 vatton 7863: {
7864: /* point the right URL for loaded images */
7865: saveURL = css->url;
7866: css->url = url;
7867: }
1.317 vatton 7868: else
1.327 vatton 7869: saveURL = NULL;
7870: ParseCSSRule (NULL, tsch, (PresentationContext) ctxt, cssRule, css, isHTML);
1.317 vatton 7871: if (css)
1.327 vatton 7872: /* restore previous url */
7873: css->url = saveURL;
1.317 vatton 7874: }
1.116 vatton 7875: /* future CSS rules should apply */
7876: DoApply = TRUE;
1.217 vatton 7877: if (selector)
7878: NewLineSkipped = skippedNL;
1.1 cvs 7879: return (selector);
7880: }
7881:
7882: /*----------------------------------------------------------------------
1.206 vatton 7883: ParseStyleDeclaration: parse a style declaration stored in the style
7884: element of a document
7885: We expect the style string to be of the form:
7886: .pinky, .awful { color: pink; font-family: helvetica }
1.231 vatton 7887: The parameter css points to the current CSS context.
7888: The parameter link points to the link element.
7889: The parameter url gives the URL of the parsed style sheet.
1.1 cvs 7890: ----------------------------------------------------------------------*/
1.206 vatton 7891: static void ParseStyleDeclaration (Element el, char *cssRule, Document doc,
1.327 vatton 7892: CSSInfoPtr css, Element link, char *url,
7893: ThotBool destroy)
1.1 cvs 7894: {
1.79 cvs 7895: GenericContext ctxt;
7896: char *decl_end;
7897: char *sel_end;
7898: char *selector;
1.1 cvs 7899:
7900: /* separate the selectors string */
1.82 cvs 7901: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 7902: decl_end = cssRule;
1.82 cvs 7903: while (*decl_end != EOS && *decl_end != '{')
1.286 quint 7904: {
7905: if (*decl_end == EOL)
1.327 vatton 7906: NewLineSkipped++;
1.286 quint 7907: decl_end++;
7908: }
1.82 cvs 7909: if (*decl_end == EOS)
1.86 cvs 7910: {
1.168 vatton 7911: CSSPrintError ("Invalid selector", cssRule);
1.86 cvs 7912: return;
7913: }
1.1 cvs 7914: /* verify and clean the selector string */
7915: sel_end = decl_end - 1;
1.82 cvs 7916: while (*sel_end == SPACE || *sel_end == BSPACE ||
1.411 vatton 7917: *sel_end == EOL || *sel_end == __CR__)
1.1 cvs 7918: sel_end--;
7919: sel_end++;
1.82 cvs 7920: *sel_end = EOS;
1.1 cvs 7921: selector = cssRule;
7922:
7923: /* now, deal with the content ... */
7924: decl_end++;
7925: cssRule = decl_end;
1.137 vatton 7926: decl_end = &cssRule[strlen (cssRule) - 1];
1.398 vatton 7927: if (*decl_end != '{' && *decl_end != EOS)
1.137 vatton 7928: *decl_end = EOS;
1.1 cvs 7929: /*
7930: * parse the style attribute string and install the corresponding
7931: * presentation attributes on the new element
7932: */
7933: ctxt = TtaGetGenericStyleContext (doc);
7934: if (ctxt == NULL)
7935: return;
7936: ctxt->destroy = destroy;
1.207 vatton 7937: /* first use of the context */
7938: ctxt->uses = 1;
1.197 vatton 7939: while (selector && *selector != EOS)
1.363 vatton 7940: {
7941: if (ctxt->uses > 1)
7942: {
7943: /* this context is waiting for a callback */
7944: ctxt = TtaGetGenericStyleContext (doc);
7945: if (ctxt == NULL)
7946: return;
7947: ctxt->destroy = destroy;
7948: /* first use of the context */
7949: ctxt->uses = 1;
7950: }
7951: selector = ParseGenericSelector (selector, cssRule, ctxt, doc, css,
7952: link, url);
7953: }
1.207 vatton 7954: /* check if the context can be freed */
7955: ctxt->uses -= 1;
7956: if (ctxt->uses == 0)
7957: /* no image loading */
7958: TtaFreeMemory (ctxt);
1.1 cvs 7959: }
7960:
7961: /************************************************************************
7962: * *
7963: * EVALUATION FUNCTIONS / CASCADING AND OVERLOADING *
7964: * *
7965: ************************************************************************/
7966:
7967: /*----------------------------------------------------------------------
1.327 vatton 7968: IsImplicitClassName: return wether the Class name is an
7969: implicit one, eg "H1" or "H2 EM" meaning it's a GI name
7970: or an HTML context name.
1.1 cvs 7971: ----------------------------------------------------------------------*/
1.248 gully 7972: int IsImplicitClassName (char *class_, Document doc)
1.1 cvs 7973: {
1.327 vatton 7974: char name[200];
7975: char *cur = name;
7976: char *first;
7977: char save;
7978: SSchema schema;
7979:
7980: /* make a local copy */
7981: strncpy (name, class_, 199);
7982: name[199] = 0;
7983:
7984: /* loop looking if each word is a GI */
7985: while (*cur != 0)
7986: {
7987: first = cur;
7988: cur = SkipWord (cur);
7989: save = *cur;
7990: *cur = 0;
7991: schema = NULL;
7992: if (MapGI (first, &schema, doc) == -1)
7993: {
7994: return (0);
7995: }
7996: *cur = save;
7997: cur = SkipBlanksAndComments (cur);
7998: }
7999: return (1);
1.1 cvs 8000: }
8001:
8002: /************************************************************************
1.114 quint 8003: * Functions needed for support of HTML: translate to CSS equivalent *
1.1 cvs 8004: ************************************************************************/
8005:
8006: /*----------------------------------------------------------------------
1.409 vatton 8007: SetBodyAbsolutePosition:
8008: ----------------------------------------------------------------------*/
8009: void SetBodyAbsolutePosition (Document doc)
8010: {
8011: Element root, body;
8012: ElementType elType;
8013:
8014: if (DocumentTypes[doc] != docHTML)
8015: return;
8016: root = TtaGetMainRoot (doc);
8017: elType = TtaGetElementType(root);
8018: elType.ElTypeNum = HTML_EL_BODY;
8019: body = TtaSearchTypedElement (elType, SearchInTree, root);
8020: if (body)
1.410 vatton 8021: ParseHTMLSpecificStyle (body, (char *)"position:absolute", doc, 200, FALSE);
1.409 vatton 8022: }
8023:
8024: /*----------------------------------------------------------------------
1.327 vatton 8025: HTMLSetBackgroundColor:
1.1 cvs 8026: ----------------------------------------------------------------------*/
1.264 vatton 8027: void HTMLSetBackgroundColor (Document doc, Element el, int specificity,
1.327 vatton 8028: char *color)
1.1 cvs 8029: {
1.350 vatton 8030: char css_command[1000];
1.1 cvs 8031:
1.416 vatton 8032: snprintf (css_command, 1000, "background-color: %50s", color);
1.327 vatton 8033: ParseHTMLSpecificStyle (el, css_command, doc, specificity, FALSE);
1.1 cvs 8034: }
8035:
8036: /*----------------------------------------------------------------------
1.327 vatton 8037: HTMLSetForegroundColor:
1.1 cvs 8038: ----------------------------------------------------------------------*/
1.264 vatton 8039: void HTMLSetForegroundColor (Document doc, Element el, int specificity,
1.327 vatton 8040: char *color)
1.1 cvs 8041: {
1.350 vatton 8042: char css_command[1000];
1.1 cvs 8043:
1.416 vatton 8044: snprintf (css_command, 1000, "color: %50s", color);
1.327 vatton 8045: ParseHTMLSpecificStyle (el, css_command, doc, specificity, FALSE);
1.1 cvs 8046: }
8047:
8048: /*----------------------------------------------------------------------
1.327 vatton 8049: HTMLResetBackgroundColor:
1.1 cvs 8050: ----------------------------------------------------------------------*/
1.97 vatton 8051: void HTMLResetBackgroundColor (Document doc, Element el)
1.1 cvs 8052: {
1.350 vatton 8053: char css_command[1000];
1.1 cvs 8054:
1.327 vatton 8055: sprintf (css_command, "background: red");
8056: ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1 cvs 8057: }
8058:
8059: /*----------------------------------------------------------------------
1.327 vatton 8060: HTMLResetBackgroundImage:
1.1 cvs 8061: ----------------------------------------------------------------------*/
1.97 vatton 8062: void HTMLResetBackgroundImage (Document doc, Element el)
1.1 cvs 8063: {
1.327 vatton 8064: char css_command[1000];
1.1 cvs 8065:
1.416 vatton 8066: snprintf (css_command, 1000, "background-image: url(xx); background-repeat: repeat");
1.327 vatton 8067: ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1 cvs 8068: }
8069:
8070: /*----------------------------------------------------------------------
1.327 vatton 8071: HTMLResetForegroundColor:
1.1 cvs 8072: ----------------------------------------------------------------------*/
1.97 vatton 8073: void HTMLResetForegroundColor (Document doc, Element el)
1.1 cvs 8074: {
1.350 vatton 8075: char css_command[1000];
1.1 cvs 8076:
1.327 vatton 8077: /* it's not necessary to well know the current color but it must be valid */
8078: sprintf (css_command, "color: red");
8079: ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1 cvs 8080: }
8081:
8082: /*----------------------------------------------------------------------
1.327 vatton 8083: HTMLSetAlinkColor:
1.1 cvs 8084: ----------------------------------------------------------------------*/
1.208 vatton 8085: void HTMLSetAlinkColor (Document doc, Element el, char *color)
1.1 cvs 8086: {
1.350 vatton 8087: char css_command[1000];
1.1 cvs 8088:
1.416 vatton 8089: snprintf (css_command, 1000, ":link { color: %50s }", color);
1.327 vatton 8090: ApplyCSSRules (el, css_command, doc, FALSE);
1.1 cvs 8091: }
8092:
8093: /*----------------------------------------------------------------------
1.327 vatton 8094: HTMLSetAactiveColor:
1.1 cvs 8095: ----------------------------------------------------------------------*/
1.208 vatton 8096: void HTMLSetAactiveColor (Document doc, Element el, char *color)
1.1 cvs 8097: {
1.350 vatton 8098: char css_command[1000];
1.1 cvs 8099:
1.416 vatton 8100: snprintf (css_command, 1000, ":active { color: %50s }", color);
1.327 vatton 8101: ApplyCSSRules (el, css_command, doc, FALSE);
1.1 cvs 8102: }
8103:
8104: /*----------------------------------------------------------------------
1.327 vatton 8105: HTMLSetAvisitedColor:
1.1 cvs 8106: ----------------------------------------------------------------------*/
1.208 vatton 8107: void HTMLSetAvisitedColor (Document doc, Element el, char *color)
1.1 cvs 8108: {
1.350 vatton 8109: char css_command[1000];
1.1 cvs 8110:
1.416 vatton 8111: snprintf (css_command, 1000, ":visited { color: %50s }", color);
1.327 vatton 8112: ApplyCSSRules (el, css_command, doc, FALSE);
1.1 cvs 8113: }
8114:
8115: /*----------------------------------------------------------------------
1.327 vatton 8116: HTMLResetAlinkColor:
1.1 cvs 8117: ----------------------------------------------------------------------*/
1.208 vatton 8118: void HTMLResetAlinkColor (Document doc, Element el)
1.1 cvs 8119: {
1.350 vatton 8120: char css_command[1000];
1.1 cvs 8121:
1.327 vatton 8122: sprintf (css_command, ":link { color: red }");
8123: ApplyCSSRules (el, css_command, doc, TRUE);
1.1 cvs 8124: }
8125:
8126: /*----------------------------------------------------------------------
1.327 vatton 8127: HTMLResetAactiveColor:
1.1 cvs 8128: ----------------------------------------------------------------------*/
1.208 vatton 8129: void HTMLResetAactiveColor (Document doc, Element el)
1.1 cvs 8130: {
1.350 vatton 8131: char css_command[1000];
1.1 cvs 8132:
1.327 vatton 8133: sprintf (css_command, ":active { color: red }");
8134: ApplyCSSRules (el, css_command, doc, TRUE);
1.1 cvs 8135: }
8136:
8137: /*----------------------------------------------------------------------
1.327 vatton 8138: HTMLResetAvisitedColor:
1.1 cvs 8139: ----------------------------------------------------------------------*/
1.208 vatton 8140: void HTMLResetAvisitedColor (Document doc, Element el)
1.1 cvs 8141: {
1.350 vatton 8142: char css_command[1000];
1.1 cvs 8143:
1.327 vatton 8144: sprintf (css_command, ":visited { color: red }");
8145: ApplyCSSRules (el, css_command, doc, TRUE);
1.1 cvs 8146: }
8147:
8148: /*----------------------------------------------------------------------
1.206 vatton 8149: ApplyCSSRules: parse a CSS Style description stored in the header of
8150: a HTML document.
1.1 cvs 8151: ----------------------------------------------------------------------*/
1.79 cvs 8152: void ApplyCSSRules (Element el, char *cssRule, Document doc, ThotBool destroy)
1.1 cvs 8153: {
1.206 vatton 8154: CSSInfoPtr css;
8155: PInfoPtr pInfo;
1.207 vatton 8156: ThotBool loadcss;
8157:
8158: /* check if we have to load CSS */
8159: TtaGetEnvBoolean ("LOAD_CSS", &loadcss);
8160: if (!loadcss)
8161: return;
1.376 vatton 8162: LineNumber = TtaGetElementLineNumber (el);
1.206 vatton 8163: css = SearchCSS (doc, NULL, el, &pInfo);
1.1 cvs 8164: if (css == NULL)
1.209 vatton 8165: {
8166: /* create the document css context */
8167: css = AddCSS (doc, doc, CSS_DOCUMENT_STYLE, CSS_ALL, NULL, NULL, el);
8168: pInfo = css->infos[doc];
8169: }
1.206 vatton 8170: else if (pInfo == NULL)
8171: /* create the entry into the css context */
8172: pInfo = AddInfoCSS (doc, css, CSS_DOCUMENT_STYLE, CSS_ALL, el);
1.209 vatton 8173: if (pInfo->PiEnabled)
1.376 vatton 8174: ParseStyleDeclaration (el, cssRule, doc, css, el, NULL, destroy);
8175: LineNumber = -1;
1.1 cvs 8176: }
8177:
8178: /*----------------------------------------------------------------------
1.327 vatton 8179: ReadCSSRules: is the front-end function called by the document parser
8180: when detecting a <style type="text/css"> indicating it's the
8181: beginning of a CSS fragment or when reading a file .css.
1.1 cvs 8182:
1.327 vatton 8183: The CSS parser has to handle <!-- ... --> constructs used to
8184: prevent prehistoric browser from displaying the CSS as a text
8185: content. It will stop on any sequence "<x" where x is different
8186: from ! and will return x as to the caller. Theorically x should
8187: be equal to / for the </style> end of style.
8188: The parameter doc gives the document tree that contains CSS information.
8189: The parameter docRef gives the document to which CSS are to be applied.
8190: This function uses the current css context or creates it. It's able
8191: to work on the given buffer or call GetNextChar to read the parsed
8192: file.
8193: The parameter url gives the URL of the parsed style sheet.
8194: The parameter numberOfLinesRead gives the number of lines already
8195: read in the file.
8196: The parameter withUndo indicates whether the changes made in the document
8197: structure and content have to be registered in the Undo queue or not.
1.1 cvs 8198: ----------------------------------------------------------------------*/
1.133 vatton 8199: char ReadCSSRules (Document docRef, CSSInfoPtr css, char *buffer, char *url,
1.343 vatton 8200: int numberOfLinesRead, ThotBool withUndo, Element link)
1.1 cvs 8201: {
1.6 cvs 8202: DisplayMode dispMode;
1.206 vatton 8203: CSSInfoPtr refcss = NULL;
1.321 vatton 8204: CSSmedia css_media = CSS_ALL;
1.206 vatton 8205: PInfoPtr pInfo;
1.321 vatton 8206: char c;
1.138 vatton 8207: char *cssRule, *base, *saveDocURL, *ptr;
1.19 cvs 8208: int index;
1.1 cvs 8209: int CSSindex;
1.327 vatton 8210: int CSScomment;
1.1 cvs 8211: int import;
1.358 quint 8212: int openBlock;
1.93 vatton 8213: int newlines;
1.358 quint 8214: int page;
1.14 cvs 8215: ThotBool HTMLcomment;
1.342 vatton 8216: ThotBool toParse, eof, quoted, s_quoted;
1.358 quint 8217: ThotBool ignore, media, lineComment;
1.234 vatton 8218: ThotBool noRule, ignoreImport, fontface;
1.1 cvs 8219:
1.327 vatton 8220: CSScomment = MAX_CSS_LENGTH;
1.1 cvs 8221: HTMLcomment = FALSE;
8222: CSSindex = 0;
8223: toParse = FALSE;
8224: noRule = FALSE;
1.234 vatton 8225: media = FALSE;
1.88 cvs 8226: ignoreImport = FALSE;
1.342 vatton 8227: ignore = lineComment = FALSE;
1.358 quint 8228: page = 0;
1.342 vatton 8229: quoted = s_quoted = FALSE;
1.234 vatton 8230: fontface = FALSE;
1.1 cvs 8231: eof = FALSE;
1.358 quint 8232: openBlock = 0;
1.234 vatton 8233: import = MAX_CSS_LENGTH;
1.82 cvs 8234: c = SPACE;
1.1 cvs 8235: index = 0;
1.134 vatton 8236: base = NULL;
1.310 vatton 8237: /* entering the CSS parsing */
1.311 vatton 8238: Style_parsing++;
1.93 vatton 8239: /* number of new lines parsed */
8240: newlines = 0;
1.6 cvs 8241: /* avoid too many redisplay */
8242: dispMode = TtaGetDisplayMode (docRef);
8243: if (dispMode == DisplayImmediately)
8244: TtaSetDisplayMode (docRef, DeferredDisplay);
1.18 cvs 8245:
8246: /* look for the CSS context */
8247: if (css == NULL)
1.206 vatton 8248: css = SearchCSS (docRef, NULL, link, &pInfo);
1.207 vatton 8249: else
8250: pInfo = css->infos[docRef];
1.18 cvs 8251: if (css == NULL)
1.206 vatton 8252: {
8253: css = AddCSS (docRef, docRef, CSS_DOCUMENT_STYLE, CSS_ALL, NULL, NULL, link);
8254: pInfo = css->infos[docRef];
8255: }
8256: else if (pInfo == NULL)
8257: pInfo = AddInfoCSS (docRef, css, CSS_DOCUMENT_STYLE, CSS_ALL, link);
1.174 vatton 8258: /* look for the CSS descriptor that points to the extension schema */
8259: refcss = css;
1.224 vatton 8260: if (pInfo && pInfo->PiCategory == CSS_IMPORT)
1.173 cvs 8261: {
1.206 vatton 8262: while (refcss &&
1.327 vatton 8263: refcss->infos[docRef] && refcss->infos[docRef]->PiCategory == CSS_IMPORT)
8264: refcss = refcss->NextCSS;
1.206 vatton 8265: if (refcss)
1.327 vatton 8266: pInfo = refcss->infos[docRef];
1.173 cvs 8267: }
8268:
1.343 vatton 8269: /* register parsed CSS file and the document to which CSS are to be applied */
1.395 vatton 8270: if (DocumentMeta[docRef] == NULL || DocumentMeta[docRef]->method != CE_MAKEBOOK)
8271: ParsedDoc = docRef;
8272: else
8273: ParsedDoc = 0;
1.343 vatton 8274: /* clean up the list of classes */
8275: TtaFreeMemory (refcss->class_list);
8276: refcss->class_list = NULL;
1.133 vatton 8277: if (url)
1.348 vatton 8278: Error_DocURL = url;
1.86 cvs 8279: else
8280: /* the CSS source in within the document itself */
1.348 vatton 8281: Error_DocURL = DocumentURLs[docRef];
1.86 cvs 8282: LineNumber = numberOfLinesRead + 1;
1.93 vatton 8283: NewLineSkipped = 0;
1.217 vatton 8284: newlines = 0;
1.392 carcone 8285:
8286: /* Search for an UTF-8 BOM character (EF BB BF) */
8287: if (index == 0 && strlen(buffer) > 2 &&
8288: (unsigned char) buffer[0] == 0xEF &&
8289: (unsigned char) buffer[1] == 0xBB &&
8290: (unsigned char) buffer[2] == 0xBF)
8291: {
8292: index = 3;
8293: }
8294:
8295: /* Search for an UTF-16 Big Endian BOM character (FE FF) */
8296: if (index == 0 && strlen(buffer) > 1 &&
8297: (unsigned char) buffer[0] == 0xFE &&
8298: (unsigned char) buffer[1] == 0xFF)
8299: {
8300: index = 2;
8301: }
8302:
8303: /* Search for an UTF-16 Little Endian BOM character (FF FE) */
8304: if (index == 0 && strlen(buffer) > 1 &&
8305: (unsigned char) buffer[0] == 0xFF &&
8306: (unsigned char) buffer[1] == 0xFE)
8307: {
8308: index = 2;
8309: }
8310:
1.82 cvs 8311: while (CSSindex < MAX_CSS_LENGTH && c != EOS && !eof)
8312: {
8313: c = buffer[index++];
8314: eof = (c == EOS);
8315: CSSbuffer[CSSindex] = c;
1.342 vatton 8316: if (!lineComment &&
8317: (CSScomment == MAX_CSS_LENGTH || c == '*' || c == '/' || c == '<' || c == EOL))
1.327 vatton 8318: {
8319: /* we're not within a comment or we're parsing * or / */
8320: switch (c)
8321: {
8322: case '@': /* perhaps an import primitive */
1.342 vatton 8323: if (!fontface && !page && !quoted && !s_quoted)
1.327 vatton 8324: import = CSSindex;
8325: break;
8326: case ';':
1.342 vatton 8327: if (!quoted && !s_quoted && !media && import != MAX_CSS_LENGTH)
1.327 vatton 8328: {
8329: if (strncasecmp (&CSSbuffer[import+1], "import", 6))
8330: /* it's not an import */
8331: import = MAX_CSS_LENGTH;
8332: /* save the text */
8333: noRule = TRUE;
8334: }
8335: break;
8336: case '*':
1.342 vatton 8337: if (!quoted && !s_quoted && CSScomment == MAX_CSS_LENGTH && CSSindex > 0 &&
1.327 vatton 8338: CSSbuffer[CSSindex - 1] == '/')
8339: /* start a comment */
8340: CSScomment = CSSindex - 1;
8341: break;
8342: case '/':
1.342 vatton 8343: if (!quoted && !s_quoted && CSSindex > 1 && CSScomment != MAX_CSS_LENGTH &&
1.399 vatton 8344: CSSbuffer[CSSindex - 1] == '*' && CSSindex != CSScomment + 2)
1.327 vatton 8345: {
8346: while (CSSindex > 0 && CSSindex >= CSScomment)
8347: {
8348: if ( CSSbuffer[CSSindex] == EOL)
8349: {
8350: LineNumber ++;
8351: newlines --;
8352: }
8353: CSSindex--;
8354: }
8355: CSSindex = CSScomment - 1; /* will be incremented later */
8356: CSScomment = MAX_CSS_LENGTH;
8357: /* clean up the buffer */
8358: if (newlines && CSSindex > 0)
8359: while (CSSindex > 0 &&
8360: (CSSbuffer[CSSindex] == SPACE ||
8361: CSSbuffer[CSSindex] == BSPACE ||
8362: CSSbuffer[CSSindex] == EOL ||
8363: CSSbuffer[CSSindex] == TAB ||
8364: CSSbuffer[CSSindex] == __CR__))
8365: {
8366: if ( CSSbuffer[CSSindex] == EOL)
8367: {
8368: LineNumber ++;
8369: newlines --;
8370: }
8371: CSSindex--;
8372: }
8373: }
1.342 vatton 8374: else if (!fontface && !page && !quoted && !s_quoted &&
1.327 vatton 8375: CSScomment == MAX_CSS_LENGTH && CSSindex > 0 &&
8376: CSSbuffer[CSSindex - 1] == '<')
8377: {
8378: /* this is the closing tag ! */
8379: CSSindex -= 2; /* remove </ from the CSS string */
8380: noRule = TRUE;
1.342 vatton 8381: }
8382: else if (!quoted && !s_quoted &&
8383: (CSSindex == 1 || (CSSindex > 1 && CSSbuffer[CSSindex - 2] == EOL)) &&
8384: CSScomment == MAX_CSS_LENGTH &&
8385: CSSbuffer[CSSindex - 1] == '/')
8386: {
8387: CSSindex--;
8388: lineComment = TRUE;
8389: }
8390:
1.327 vatton 8391: break;
8392: case '<':
1.342 vatton 8393: if (!fontface && !page && !quoted && !s_quoted &&
1.327 vatton 8394: CSScomment == MAX_CSS_LENGTH)
8395: {
8396: /* only if we're not parsing a comment */
8397: c = buffer[index++];
8398: eof = (c == EOS);
8399: if (c == '!')
8400: {
8401: /* CSS within an HTML comment */
8402: HTMLcomment = TRUE;
8403: CSSindex++;
8404: CSSbuffer[CSSindex] = c;
8405: }
8406: else if (c == EOS)
8407: CSSindex++;
8408: }
8409: break;
8410: case '-':
1.342 vatton 8411: if (!fontface && !page && !quoted && !s_quoted &&
1.327 vatton 8412: CSSindex > 0 && CSSbuffer[CSSindex - 1] == '-' &&
8413: HTMLcomment)
8414: /* CSS within an HTML comment */
8415: noRule = TRUE;
8416: break;
8417: case '>':
1.342 vatton 8418: if (!fontface && !page && !quoted && !s_quoted && HTMLcomment)
1.327 vatton 8419: noRule = TRUE;
8420: break;
8421: case ' ':
1.358 quint 8422: if (!quoted && !s_quoted && import != MAX_CSS_LENGTH && openBlock == 0)
1.327 vatton 8423: media = !strncasecmp (&CSSbuffer[import+1], "media", 5);
8424: break;
8425: case '{':
1.342 vatton 8426: if (!quoted && !s_quoted)
1.327 vatton 8427: {
1.358 quint 8428: openBlock++;
1.327 vatton 8429: if (import != MAX_CSS_LENGTH)
8430: {
1.358 quint 8431: if (openBlock == 1 && media)
1.327 vatton 8432: {
8433: /* is it the screen concerned? */
8434: CSSbuffer[CSSindex+1] = EOS;
8435: css_media = CheckMediaCSS (&CSSbuffer[import+7]);
8436: if (TtaIsPrinting ())
8437: ignore = (css_media != CSS_ALL && css_media != CSS_PRINT);
8438: else
8439: ignore = (css_media != CSS_ALL && css_media != CSS_SCREEN);
8440: noRule = TRUE;
8441: }
8442: else if (!strncasecmp (&CSSbuffer[import+1], "page", 4))
1.358 quint 8443: /* it is a @page block */
1.327 vatton 8444: {
1.358 quint 8445: page = openBlock;/*remember the level of this block*/
1.327 vatton 8446: noRule = TRUE;
8447: }
8448: else if (!strncasecmp (&CSSbuffer[import+1], "font-face", 9))
8449: {
8450: fontface = TRUE;
8451: noRule = TRUE;
8452: }
8453: }
8454: }
8455: break;
8456: case '}':
1.342 vatton 8457: if (!quoted && !s_quoted)
1.327 vatton 8458: {
1.358 quint 8459: if (page == openBlock)
8460: /* closing the @page block */
1.327 vatton 8461: {
8462: noRule = TRUE;
1.358 quint 8463: page = 0; /* close the page section */
1.327 vatton 8464: }
8465: else if (fontface)
8466: {
8467: noRule = TRUE;
8468: fontface = FALSE; /* close the fontface section */
8469: }
1.358 quint 8470: else if (openBlock == 1 && import != MAX_CSS_LENGTH)
1.327 vatton 8471: {
8472: import = MAX_CSS_LENGTH;
8473: noRule = TRUE;
8474: ignore = FALSE;
8475: media = FALSE;
8476: }
1.358 quint 8477: else if (!page)
1.327 vatton 8478: toParse = TRUE;
1.358 quint 8479: openBlock--;
1.327 vatton 8480: }
8481: break;
8482: case '"':
8483: if (quoted)
8484: {
1.342 vatton 8485: if (CSSindex > 0 && CSSbuffer[CSSindex - 1] != '\\')
1.327 vatton 8486: quoted = FALSE;
8487: }
1.342 vatton 8488: else if (!s_quoted)
1.327 vatton 8489: quoted = TRUE;
8490: break;
1.342 vatton 8491: case '\'':
8492: if (s_quoted)
8493: {
8494: if (CSSindex > 0 && CSSbuffer[CSSindex - 1] != '\\')
8495: s_quoted = FALSE;
8496: }
8497: else if (!quoted)
8498: s_quoted = TRUE;
8499: break;
8500: default:
1.327 vatton 8501: if (c == EOL)
8502: {
8503: newlines++;
8504: }
8505: break;
8506: }
1.82 cvs 8507: }
1.93 vatton 8508: else if (c == EOL)
1.327 vatton 8509: {
8510: LineNumber++;
1.342 vatton 8511: lineComment = FALSE;
1.411 vatton 8512: c = __CR__;
1.327 vatton 8513: }
1.234 vatton 8514:
1.411 vatton 8515: if (!lineComment && c != __CR__)
1.327 vatton 8516: CSSindex++;
1.82 cvs 8517:
8518: if (CSSindex >= MAX_CSS_LENGTH && CSScomment < MAX_CSS_LENGTH)
1.327 vatton 8519: /* we're still parsing a comment: remove the text comment */
8520: CSSindex = CSScomment;
1.82 cvs 8521:
8522: if (CSSindex >= MAX_CSS_LENGTH || toParse || noRule)
1.327 vatton 8523: {
8524: CSSbuffer[CSSindex] = EOS;
8525: /* parse a not empty string */
8526: if (CSSindex > 0)
8527: {
1.50 cvs 8528: /* apply CSS rule if it's not just a saving of text */
1.234 vatton 8529: if (!noRule && !ignore)
1.327 vatton 8530: {
8531: /* future import rules must be ignored */
8532: ignoreImport = TRUE;
8533: NewLineSkipped = 0;
8534: ParseStyleDeclaration (NULL, CSSbuffer, docRef, refcss,
8535: pInfo->PiLink, url, FALSE);
8536: LineNumber += newlines;
8537: newlines = 0;
8538: }
1.82 cvs 8539: else if (import != MAX_CSS_LENGTH &&
1.327 vatton 8540: !strncasecmp (&CSSbuffer[import+1], "import", 6))
8541: {
8542: /* import section */
8543: cssRule = &CSSbuffer[import+7];
1.405 kia 8544: cssRule = (char*)TtaSkipBlanks (cssRule);
1.327 vatton 8545: /* save the current line number */
8546: newlines += LineNumber;
8547: if (!strncasecmp (cssRule, "url", 3))
8548: {
1.50 cvs 8549: cssRule = &cssRule[3];
1.405 kia 8550: cssRule = (char*)TtaSkipBlanks (cssRule);
1.82 cvs 8551: if (*cssRule == '(')
1.327 vatton 8552: {
8553: cssRule++;
1.405 kia 8554: cssRule = (char*)TtaSkipBlanks (cssRule);
1.327 vatton 8555: quoted = (*cssRule == '"' || *cssRule == '\'');
8556: if (quoted)
8557: cssRule++;
8558: base = cssRule;
8559: while (*cssRule != EOS && *cssRule != ')')
8560: cssRule++;
8561: if (quoted)
8562: {
8563: /* isolate the file name */
8564: cssRule[-1] = EOS;
8565: quoted = FALSE;
8566: }
8567: else
8568: {
8569: /* remove extra spaces */
8570: if (cssRule[-1] == SPACE)
8571: {
8572: *cssRule = SPACE;
8573: cssRule--;
8574: while (cssRule[-1] == SPACE)
8575: cssRule--;
8576: }
8577: }
8578: *cssRule = EOS;
8579: }
8580: }
8581: else if (*cssRule == '"')
8582: {
8583: /*
8584: Do we have to accept single quotes?
8585: Double quotes are accepted here.
8586: Escaped quotes are not handled. See function SkipQuotedString
8587: */
8588: cssRule++;
1.405 kia 8589: cssRule = (char*)TtaSkipBlanks (cssRule);
1.327 vatton 8590: base = cssRule;
8591: while (*cssRule != EOS &&
8592: (*cssRule != '"' ||
8593: (*cssRule == '"' && cssRule[-1] == '\\')))
8594: cssRule++;
8595: /* isolate the file name */
8596: *cssRule = EOS;
8597: }
8598: /* check if a media is defined */
8599: cssRule++;
1.405 kia 8600: cssRule = (char*)TtaSkipBlanks (cssRule);
1.327 vatton 8601: if (*cssRule != ';')
8602: {
8603: css_media = CheckMediaCSS (cssRule);
8604: if (TtaIsPrinting ())
8605: ignoreImport = (css_media != CSS_ALL && css_media != CSS_PRINT);
8606: else
8607: ignoreImport = (css_media != CSS_ALL && css_media != CSS_SCREEN);
8608: }
8609: if (!ignoreImport)
8610: {
8611: /* save the displayed URL when an error is reported */
1.348 vatton 8612: saveDocURL = Error_DocURL;
1.327 vatton 8613: ptr = TtaStrdup (base);
8614: /* get the CSS URI in UTF-8 */
8615: /*ptr = ReallocUTF8String (ptr, docRef);*/
8616: LoadStyleSheet (base, docRef, (Element) css, css,
8617: url, pInfo->PiMedia,
8618: pInfo->PiCategory == CSS_USER_STYLE);
8619: /* restore the displayed URL when an error is reported */
1.348 vatton 8620: Error_DocURL = saveDocURL;
1.327 vatton 8621: TtaFreeMemory (ptr);
8622: }
8623: /* restore the number of lines */
8624: LineNumber = newlines;
8625: newlines = 0;
8626: NewLineSkipped = 0;
8627: import = MAX_CSS_LENGTH;
8628: }
8629: else
8630: {
8631: LineNumber += newlines;
8632: newlines = 0;
8633: }
8634: }
8635: toParse = FALSE;
8636: noRule = FALSE;
8637: CSSindex = 0;
1.50 cvs 8638: }
1.82 cvs 8639: }
1.310 vatton 8640: /* closing the CSS parsing */
1.311 vatton 8641: Style_parsing--;
1.330 cvs 8642: if (RedisplayImages == 0 && RedisplayBGImage && Style_parsing == 0)
1.310 vatton 8643: {
1.311 vatton 8644: /* CSS parsing finishes after a BG image was loaded */
1.310 vatton 8645: RedisplayBGImage = FALSE;
1.330 cvs 8646: if (dispMode != NoComputedDisplay)
8647: {
8648: //printf ("ReadCSS Show BGimages\n");
8649: TtaSetDisplayMode (docRef, NoComputedDisplay);
8650: TtaSetDisplayMode (docRef, dispMode);
8651: }
1.310 vatton 8652: }
1.330 cvs 8653: else if (dispMode != NoComputedDisplay)
1.311 vatton 8654: /* restore the display mode */
8655: TtaSetDisplayMode (docRef, dispMode);
1.86 cvs 8656:
8657: /* Prepare the context for style attributes */
1.348 vatton 8658: Error_DocURL = DocumentURLs[docRef];
1.86 cvs 8659: LineNumber = -1;
1.1 cvs 8660: return (c);
8661: }
Webmaster