Annotation of Amaya/amaya/styleparser.c, revision 1.436
1.1 cvs 1: /*
2: *
1.420 vatton 3: * (c) COPYRIGHT INRIA and W3C, 1996-2009
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
79:
1.1 cvs 80:
81: /*----------------------------------------------------------------------
1.327 vatton 82: SkipWord:
1.1 cvs 83: ----------------------------------------------------------------------*/
1.79 cvs 84: static char *SkipWord (char *ptr)
1.1 cvs 85: {
1.402 vatton 86: while (isalnum((int)*ptr) || *ptr == '-' || *ptr == '#' || *ptr == '%' || *ptr == '.')
1.168 vatton 87: ptr++;
1.1 cvs 88: return (ptr);
89: }
90:
91: /*----------------------------------------------------------------------
1.327 vatton 92: SkipBlanksAndComments:
1.13 cvs 93: ----------------------------------------------------------------------*/
1.82 cvs 94: char *SkipBlanksAndComments (char *ptr)
1.13 cvs 95: {
1.93 vatton 96: /* skip spaces */
1.155 cheyroul 97: while (*ptr == SPACE ||
1.327 vatton 98: *ptr == BSPACE ||
99: *ptr == EOL ||
100: *ptr == TAB ||
101: *ptr == __CR__)
1.93 vatton 102: {
103: if (*ptr == EOL)
1.327 vatton 104: /* increment the number of newline skipped */
105: NewLineSkipped++;
1.93 vatton 106: ptr++;
107: }
1.399 vatton 108: while (ptr[0] == '/' && ptr[1] == '*')
1.13 cvs 109: {
110: /* look for the end of the comment */
111: ptr = &ptr[2];
112: while (ptr[0] != EOS && (ptr[0] != '*' || ptr[1] != '/'))
1.327 vatton 113: ptr++;
1.13 cvs 114: if (ptr[0] != EOS)
1.327 vatton 115: ptr = &ptr[2];
1.93 vatton 116: /* skip spaces */
117: while (*ptr == SPACE || *ptr == BSPACE || *ptr == EOL ||
1.327 vatton 118: *ptr == TAB || *ptr == __CR__)
119: {
120: if (*ptr == EOL)
121: /* increment the number of newline skipped */
122: NewLineSkipped++;
123: ptr++;
124: }
1.13 cvs 125: }
126: return (ptr);
127: }
128:
1.366 vatton 129:
130: /*----------------------------------------------------------------------
131: Number of values
132: ----------------------------------------------------------------------*/
133: static int NumberOfValues (char *ptr)
134: {
135: int n = 0;
1.402 vatton 136: while (*ptr != EOS && *ptr != ';' && *ptr != '}' && *ptr != ',')
1.366 vatton 137: {
138: ptr = SkipBlanksAndComments (ptr);
139: n++;
140: ptr = SkipWord (ptr);
141: }
142: return n;
143: }
144:
1.49 cvs 145: /*----------------------------------------------------------------------
1.327 vatton 146: SkipQuotedString
1.1 cvs 147: ----------------------------------------------------------------------*/
1.79 cvs 148: static char *SkipQuotedString (char *ptr, char quote)
1.1 cvs 149: {
1.14 cvs 150: ThotBool stop;
1.1 cvs 151:
152: stop = FALSE;
153: while (!stop)
154: {
1.327 vatton 155: if (*ptr == quote)
156: {
157: ptr++;
158: stop = TRUE;
159: }
160: else if (*ptr == EOS)
161: stop = TRUE;
162: else if (*ptr == '\\')
163: /* escape character */
164: {
165: ptr++;
1.82 cvs 166: if ((*ptr >= '0' && *ptr <= '9') || (*ptr >= 'A' && *ptr <= 'F') ||
1.327 vatton 167: (*ptr >= 'a' && *ptr <= 'f'))
168: {
169: ptr++;
170: if ((*ptr >= '0' && *ptr <= '9') || (*ptr >= 'A' && *ptr <= 'F') ||
171: (*ptr >= 'a' && *ptr <= 'f'))
172: ptr++;
173: }
174: else
175: ptr++;
176: }
177: else
178: ptr++;
1.1 cvs 179: }
180: return (ptr);
181: }
182:
183: /*----------------------------------------------------------------------
1.327 vatton 184: CSSPrintError
185: print the error message msg on stderr.
1.436 ! quint 186: When the line is 0 ask expat the current line number
1.86 cvs 187: ----------------------------------------------------------------------*/
1.389 vatton 188: static void CSSPrintError (const char *msg, const char *value)
1.86 cvs 189: {
1.419 vatton 190: if (!IgnoreErrors && !DoDialog && !TtaIsPrinting () && ParsedDoc > 0)
1.86 cvs 191: {
192: if (!ErrFile)
1.327 vatton 193: {
194: if (OpenParsingErrors (ParsedDoc) == FALSE)
195: return;
196: }
1.86 cvs 197:
1.308 vatton 198: /* check if a CSS error file shoulb be updated too */
199: if (ParsedCSS > 0 && !CSSErrFile)
1.327 vatton 200: OpenParsingErrors (ParsedCSS);
1.308 vatton 201:
1.348 vatton 202: if (Error_DocURL)
1.327 vatton 203: {
1.348 vatton 204: fprintf (ErrFile, "\n*** Errors/warnings in %s\n", Error_DocURL);
1.327 vatton 205: /* set to NULL as long as the CSS file doesn't change */
1.348 vatton 206: Error_DocURL = NULL;
1.327 vatton 207: }
1.89 cvs 208: CSSErrorsFound = TRUE;
1.86 cvs 209: if (LineNumber < 0)
1.347 quint 210: {
211: if (value)
212: fprintf (ErrFile, " In style attribute, %s \"%s\"\n", msg, value);
213: else
214: fprintf (ErrFile, " In style attribute, %s\n", msg);
215: }
1.86 cvs 216: else
1.327 vatton 217: {
1.347 quint 218: if (value)
219: fprintf (ErrFile, "@ line %d: %s \"%s\"\n",
220: LineNumber+NewLineSkipped, msg, value);
221: else
222: fprintf (ErrFile, "@ line %d: %s\n", LineNumber+NewLineSkipped,
223: msg);
1.327 vatton 224: if (CSSErrFile)
1.347 quint 225: {
226: if (value)
227: fprintf (CSSErrFile, "@ line %d: %s \"%s\"\n",
228: LineNumber+NewLineSkipped, msg, value);
229: else
230: fprintf (CSSErrFile, "@ line %d: %s\n",
231: LineNumber+NewLineSkipped, msg);
232: }
1.327 vatton 233: }
1.86 cvs 234: }
235: }
236:
1.168 vatton 237: /*----------------------------------------------------------------------
1.327 vatton 238: CSSParseError
239: print the error message msg on stderr.
1.168 vatton 240: ----------------------------------------------------------------------*/
1.389 vatton 241: static void CSSParseError (const char *msg, const char *value, char *endvalue)
1.168 vatton 242: {
1.230 quint 243: char c = EOS;
1.168 vatton 244:
245: if (endvalue)
246: {
247: /* close the string here */
248: c = *endvalue;
249: *endvalue = EOS;
250: }
251: CSSPrintError (msg, value);
252: if (endvalue)
253: *endvalue = c;
254: }
255:
1.288 vatton 256: /*----------------------------------------------------------------------
1.342 vatton 257: SkipString move to the end of the string
258: ----------------------------------------------------------------------*/
259: static char *SkipString (char *ptr)
260: {
261: char c = *ptr;
262:
263: ptr++;
264: while (*ptr != EOS &&
265: (*ptr != c || (*ptr == c && ptr[-1] == '\\')))
266: ptr++;
267: return ptr;
268: }
269:
270: /*----------------------------------------------------------------------
1.327 vatton 271: CSSCheckEndValue
272: print an error message if another character is found
1.288 vatton 273: ----------------------------------------------------------------------*/
1.405 kia 274: static char *CSSCheckEndValue (char *cssRule, char *endvalue, const char *msg)
1.288 vatton 275: {
276: char c = EOS;
277: if (*endvalue != EOS && *endvalue != SPACE && *endvalue != '/' &&
1.316 quint 278: *endvalue != ';' && *endvalue != '}' && *endvalue != EOL &&
279: *endvalue != TAB && *endvalue != __CR__)
1.288 vatton 280: {
281: while (*endvalue != EOS && *endvalue != SPACE && *endvalue != '/' &&
1.327 vatton 282: *endvalue != ';' && *endvalue != '}' && *endvalue != EOL &&
283: *endvalue != TAB && *endvalue != __CR__)
1.342 vatton 284: {
285: if (*endvalue == '"' || *endvalue == '\'')
286: endvalue = SkipString (endvalue);
287: if (*endvalue != EOS)
288: endvalue++;
289: }
1.288 vatton 290: /* close the string here */
291: c = *endvalue;
292: *endvalue = EOS;
293: CSSPrintError (msg, cssRule);
294: *endvalue = c;
295: }
296: return endvalue;
297: }
298:
1.89 cvs 299:
1.86 cvs 300: /*----------------------------------------------------------------------
1.327 vatton 301: SkipProperty skips a property and display and error message
1.86 cvs 302: ----------------------------------------------------------------------*/
1.234 vatton 303: static char *SkipProperty (char *ptr, ThotBool reportError)
1.86 cvs 304: {
305: char *deb;
306: char c;
1.404 vatton 307: ThotBool warn;
1.86 cvs 308:
1.404 vatton 309: // check if Amaya should report CSS warnings
310: TtaGetEnvBoolean ("CSS_WARN", &warn);
311: if (!warn)
312: reportError = FALSE;
1.86 cvs 313: deb = ptr;
1.431 quint 314: while (*ptr != EOS && *ptr != ';' && *ptr != '}')
1.133 vatton 315: {
1.342 vatton 316: if (*ptr == '"' || *ptr == '\'')
317: ptr = SkipString (ptr);
318: if (*ptr != EOS)
319: ptr++;
1.133 vatton 320: }
1.95 cvs 321: /* print the skipped property */
1.86 cvs 322: c = *ptr;
1.386 vatton 323: if (*ptr != EOS)
324: *ptr = EOS;
1.366 vatton 325: if (DoDialog)
326: DisplayStyleValue ("", deb, ptr);
327: else if (reportError && *deb != EOS &&
328: strncasecmp (deb, "azimuth", 7) &&
329: strncasecmp (deb, "border-collapse", 15) &&
330: strncasecmp (deb, "border-spacing", 14) &&
331: strncasecmp (deb, "caption-side", 12) &&
332: strncasecmp (deb, "clip", 4) &&
333: strncasecmp (deb, "cue-after", 9) &&
334: strncasecmp (deb, "cue-before", 10) &&
335: strncasecmp (deb, "cue", 3) &&
336: strncasecmp (deb, "cursor", 6) &&
337: strncasecmp (deb, "elevation", 9) &&
338: strncasecmp (deb, "empty-cells", 11) &&
339: strncasecmp (deb, "font-strech", 11) &&
340: strncasecmp (deb, "letter-spacing", 14) &&
341: strncasecmp (deb, "marker-offset", 12) &&
342: strncasecmp (deb, "orphans", 7) &&
343: strncasecmp (deb, "outline-color", 13) &&
344: strncasecmp (deb, "outline-style", 13) &&
345: strncasecmp (deb, "outline-width", 13) &&
346: strncasecmp (deb, "outline", 7) &&
347: strncasecmp (deb, "overflow", 8) &&
348: strncasecmp (deb, "pause-after", 11) &&
349: strncasecmp (deb, "pause-before", 12) &&
350: strncasecmp (deb, "pause", 5) &&
351: strncasecmp (deb, "quotes", 6) &&
352: strncasecmp (deb, "richness", 8) &&
353: strncasecmp (deb, "speech-rate", 11) &&
354: strncasecmp (deb, "speak-header", 12) &&
355: strncasecmp (deb, "speak-punctuation", 17) &&
356: strncasecmp (deb, "speak-numeral", 13) &&
357: strncasecmp (deb, "speak", 5) &&
358: strncasecmp (deb, "pitch-range", 11) &&
359: strncasecmp (deb, "pitch", 5) &&
360: strncasecmp (deb, "stress", 6) &&
361: strncasecmp (deb, "table-layout", 12) &&
362: strncasecmp (deb, "text-shadow", 11) &&
363: strncasecmp (deb, "voice-family", 12) &&
364: strncasecmp (deb, "volume", 6) &&
365: strncasecmp (deb, "widows", 6))
1.205 quint 366: CSSPrintError ("CSS property ignored:", deb);
1.386 vatton 367: if (c != EOS)
368: *ptr = c;
1.86 cvs 369: return (ptr);
370: }
371:
372: /*----------------------------------------------------------------------
1.327 vatton 373: SkipValue
374: skips the value and display an error message if msg is not NULL
1.1 cvs 375: ----------------------------------------------------------------------*/
1.405 kia 376: static char *SkipValue (const char *msg, char *ptr)
1.1 cvs 377: {
1.86 cvs 378: char *deb;
379: char c;
380:
381: deb = ptr;
1.387 quint 382: while (*ptr != EOS && *ptr != ';' && *ptr != '}' && *ptr != '\n')
1.133 vatton 383: {
1.342 vatton 384: if (*ptr == '"' || *ptr == '\'')
385: ptr = SkipString (ptr);
386: if (*ptr != EOS)
387: ptr++;
1.133 vatton 388: }
1.95 cvs 389: /* print the skipped property */
1.86 cvs 390: c = *ptr;
1.397 vatton 391: if (c != EOS)
392: *ptr = EOS;
1.168 vatton 393: if (msg && *deb != EOS && *deb != ',')
394: CSSPrintError (msg, deb);
1.397 vatton 395: if (c != EOS)
396: *ptr = c;
1.1 cvs 397: return (ptr);
398: }
399:
400: /*----------------------------------------------------------------------
1.327 vatton 401: ParseNumber:
402: parse a number and returns the corresponding value.
1.1 cvs 403: ----------------------------------------------------------------------*/
1.79 cvs 404: char *ParseNumber (char *cssRule, PresentationValue *pval)
1.1 cvs 405: {
406: int val = 0;
407: int minus = 0;
408: int valid = 0;
409: int f = 0;
1.14 cvs 410: ThotBool real = FALSE;
1.1 cvs 411:
1.184 vatton 412: pval->typed_data.unit = UNIT_REL;
1.1 cvs 413: pval->typed_data.real = FALSE;
1.82 cvs 414: cssRule = SkipBlanksAndComments (cssRule);
415: if (*cssRule == '-')
1.1 cvs 416: {
417: minus = 1;
418: cssRule++;
1.82 cvs 419: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 420: }
1.387 quint 421: else if (*cssRule == '+')
1.1 cvs 422: {
423: cssRule++;
1.82 cvs 424: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 425: }
426:
1.82 cvs 427: while ((*cssRule >= '0') && (*cssRule <= '9'))
1.1 cvs 428: {
429: val *= 10;
1.82 cvs 430: val += *cssRule - '0';
1.1 cvs 431: cssRule++;
432: valid = 1;
433: }
434:
1.82 cvs 435: if (*cssRule == '.')
1.1 cvs 436: {
437: real = TRUE;
438: f = val;
439: val = 0;
440: cssRule++;
441: /* keep only 3 digits */
1.82 cvs 442: if (*cssRule >= '0' && *cssRule <= '9')
1.327 vatton 443: {
444: val = (*cssRule - '0') * 100;
445: cssRule++;
446: if (*cssRule >= '0' && *cssRule <= '9')
447: {
448: val += (*cssRule - '0') * 10;
449: cssRule++;
450: if ((*cssRule >= '0') && (*cssRule <= '9'))
451: {
452: val += *cssRule - '0';
453: cssRule++;
454: }
455: }
456:
457: while (*cssRule >= '0' && *cssRule <= '9')
458: cssRule++;
459: valid = 1;
460: }
1.1 cvs 461: }
462:
463: if (!valid)
464: {
1.184 vatton 465: pval->typed_data.unit = UNIT_INVALID;
1.1 cvs 466: pval->typed_data.value = 0;
467: }
468: else
469: {
470: pval->typed_data.real = real;
471: if (real)
1.327 vatton 472: {
473: if (minus)
474: pval->typed_data.value = -(f * 1000 + val);
475: else
476: pval->typed_data.value = f * 1000 + val;
477: }
1.1 cvs 478: else
1.327 vatton 479: {
480: if (minus)
481: pval->typed_data.value = -val;
482: else
483: pval->typed_data.value = val;
484: }
1.64 cvs 485: }
486: return (cssRule);
487: }
1.195 vatton 488:
1.155 cheyroul 489: /*----------------------------------------------------------------------
1.407 vatton 490: ParseCSSUnit a number followed by a CSS Unit and returns the corresponding
1.327 vatton 491: value and its unit.
1.64 cvs 492: ----------------------------------------------------------------------*/
1.82 cvs 493: char *ParseCSSUnit (char *cssRule, PresentationValue *pval)
1.64 cvs 494: {
1.368 vatton 495: char *p;
1.64 cvs 496: unsigned int uni;
497:
1.184 vatton 498: pval->typed_data.unit = UNIT_REL;
1.64 cvs 499: cssRule = ParseNumber (cssRule, pval);
1.184 vatton 500: if (pval->typed_data.unit == UNIT_INVALID)
1.387 quint 501: /* it does not start with a valid number */
1.327 vatton 502: cssRule = SkipWord (cssRule);
1.64 cvs 503: else
504: {
1.369 quint 505: /* is there a space after the number? */
1.368 vatton 506: p = cssRule;
1.82 cvs 507: cssRule = SkipBlanksAndComments (cssRule);
1.368 vatton 508: if (p == cssRule)
1.369 quint 509: /* no space */
1.368 vatton 510: p = NULL;
1.369 quint 511: else
512: /* a space is here. restore the pointer */
513: cssRule = p;
1.231 vatton 514: uni = 0;
515: while (CSSUnitNames[uni].sign)
1.327 vatton 516: {
517: if (!strncasecmp (CSSUnitNames[uni].sign, cssRule,
518: strlen (CSSUnitNames[uni].sign)))
1.369 quint 519: /* this is a correct unit */
1.327 vatton 520: {
521: pval->typed_data.unit = CSSUnitNames[uni].unit;
1.368 vatton 522: if (p)
1.369 quint 523: /* there was a space before the unit. Syntax error */
1.368 vatton 524: pval->typed_data.unit = UNIT_INVALID;
1.327 vatton 525: return (cssRule + strlen (CSSUnitNames[uni].sign));
526: }
527: else
528: uni++;
529: }
1.369 quint 530: /* not in the list of accepted units */
1.184 vatton 531: pval->typed_data.unit = UNIT_BOX;
1.1 cvs 532: }
533: return (cssRule);
534: }
535:
1.43 cvs 536: /*----------------------------------------------------------------------
1.327 vatton 537: ParseClampedUnit:
538: parse a CSS Unit substring and returns the corresponding value and unit.
539: [0,1]
1.239 vatton 540: ----------------------------------------------------------------------*/
541: char *ParseClampedUnit (char *cssRule, PresentationValue *pval)
542: {
1.251 vatton 543: char *p;
544:
545: p = cssRule;
1.239 vatton 546: cssRule = ParseNumber (cssRule, pval);
1.301 vatton 547: if (*cssRule != EOS && *cssRule != SPACE && *cssRule != ';' && *cssRule != '}')
1.418 quint 548: /* the value contains something after the number. Invalid */
1.239 vatton 549: {
1.251 vatton 550: cssRule++;
1.239 vatton 551: pval->typed_data.unit = UNIT_REL;
552: if (pval->typed_data.value > 100)
1.327 vatton 553: pval->typed_data.value = 1000;
1.239 vatton 554: else
1.327 vatton 555: pval->typed_data.value *= 10;
1.251 vatton 556: CSSParseError ("Invalid value", p, cssRule);
1.239 vatton 557: }
558: else
1.418 quint 559: /* it's a number. Check its value */
1.239 vatton 560: {
561: pval->typed_data.unit = UNIT_REL;
562: if (pval->typed_data.real)
1.327 vatton 563: pval->typed_data.real = FALSE;
1.239 vatton 564: else if (pval->typed_data.value > 1)
1.327 vatton 565: {
566: pval->typed_data.value = 1000;
567: CSSParseError ("Invalid value", p, cssRule);
568: }
1.251 vatton 569: else if (pval->typed_data.value < 0)
1.327 vatton 570: {
571: pval->typed_data.value = 0;
572: CSSParseError ("Invalid value", p, cssRule);
573: }
1.239 vatton 574: else
1.327 vatton 575: pval->typed_data.value *= 1000;
1.239 vatton 576: }
577: pval->data = pval->typed_data.value;
578: return (cssRule);
579: }
580:
581:
582: /*----------------------------------------------------------------------
1.327 vatton 583: ParseABorderValue
1.43 cvs 584: ----------------------------------------------------------------------*/
1.288 vatton 585: static char *ParseABorderValue (char *cssRule, PresentationValue *border)
1.43 cvs 586: {
1.288 vatton 587: char *ptr = cssRule;
1.168 vatton 588:
1.43 cvs 589: /* first parse the attribute string */
1.319 quint 590: border->typed_data.value = 0;
591: border->typed_data.unit = UNIT_INVALID;
592: border->typed_data.real = FALSE;
593: if (!strncasecmp (cssRule, "thin", 4))
594: {
595: border->typed_data.unit = UNIT_PX;
596: border->typed_data.value = 1;
597: cssRule += 4;
598: }
599: else if (!strncasecmp (cssRule, "medium", 6))
600: {
601: border->typed_data.unit = UNIT_PX;
602: border->typed_data.value = 3;
603: cssRule += 6;
604: }
605: else if (!strncasecmp (cssRule, "thick", 5))
606: {
607: border->typed_data.unit = UNIT_PX;
608: border->typed_data.value = 5;
609: cssRule += 5;
610: }
611: else if (!strncasecmp (cssRule, "inherit", 7))
612: {
613: border->typed_data.unit = VALUE_INHERIT;
614: cssRule += 7;
615: }
616: else if (isdigit (*cssRule) || *cssRule == '.')
617: {
618: cssRule = ParseCSSUnit (cssRule, border);
1.387 quint 619: if (border->typed_data.value == 0 &&
620: border->typed_data.unit != UNIT_INVALID)
1.327 vatton 621: border->typed_data.unit = UNIT_PX;
1.319 quint 622: else if (border->typed_data.unit == UNIT_INVALID ||
1.327 vatton 623: border->typed_data.unit == UNIT_BOX ||
624: border->typed_data.unit == UNIT_PERCENT)
625: {
626: border->typed_data.unit = UNIT_INVALID;
627: border->typed_data.value = 0;
628: CSSParseError ("Invalid border-width value", ptr, cssRule);
629: }
1.319 quint 630: }
631: return (cssRule);
1.43 cvs 632: }
633:
1.288 vatton 634:
635: /*----------------------------------------------------------------------
1.327 vatton 636: ParseBorderStyle
1.43 cvs 637: ----------------------------------------------------------------------*/
1.79 cvs 638: static char *ParseBorderStyle (char *cssRule, PresentationValue *border)
1.43 cvs 639: {
1.431 quint 640: char *ptr = cssRule;
641:
1.43 cvs 642: /* first parse the attribute string */
1.327 vatton 643: border->typed_data.value = 0;
644: border->typed_data.unit = UNIT_PX;
645: border->typed_data.real = FALSE;
646: if (!strncasecmp (cssRule, "none", 4))
647: {
648: border->typed_data.value = BorderStyleNone;
649: cssRule += 4;
650: }
651: else if (!strncasecmp (cssRule, "hidden", 6))
652: {
653: border->typed_data.value = BorderStyleHidden;
654: cssRule += 6;
655: }
656: else if (!strncasecmp (cssRule, "dotted", 6))
657: {
1.288 vatton 658: cssRule += 6;
1.327 vatton 659: border->typed_data.value = BorderStyleDotted;
1.288 vatton 660: }
1.327 vatton 661: else if (!strncasecmp (cssRule, "dashed", 6))
662: {
663: border->typed_data.value = BorderStyleDashed;
664: cssRule += 6;
665: }
666: else if (!strncasecmp (cssRule, "solid", 5))
667: {
668: border->typed_data.value = BorderStyleSolid;
669: cssRule += 5;
670: }
671: else if (!strncasecmp (cssRule, "double", 6))
672: {
673: border->typed_data.value = BorderStyleDouble;
674: cssRule += 6;
675: }
676: else if (!strncasecmp (cssRule, "groove", 6))
677: {
678: border->typed_data.value = BorderStyleGroove;
679: cssRule += 6;
680: }
681: else if (!strncasecmp (cssRule, "ridge", 5))
682: {
683: border->typed_data.value = BorderStyleRidge;
684: cssRule += 5;
685: }
686: else if (!strncasecmp (cssRule, "inset", 5))
687: {
688: border->typed_data.value = BorderStyleInset;
689: cssRule += 5;
690: }
691: else if (!strncasecmp (cssRule, "outset", 6))
692: {
693: border->typed_data.value = BorderStyleOutset;
694: cssRule += 6;
695: }
696: else
697: {
698: /* invalid style */
699: border->typed_data.unit = UNIT_INVALID;
700: return (cssRule);
701: }
1.431 quint 702: if (border->typed_data.value != 0)
703: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid border-style value");
1.327 vatton 704: return (cssRule);
1.43 cvs 705: }
706:
707: /*----------------------------------------------------------------------
1.327 vatton 708: ParseCSSColor: parse a CSS color attribute string
709: we expect the input string describing the attribute to be
710: either a color name, a 3 tuple or an hexadecimal encoding.
711: The color used will be approximed from the current color
712: table
1.43 cvs 713: ----------------------------------------------------------------------*/
1.79 cvs 714: static char *ParseCSSColor (char *cssRule, PresentationValue * val)
1.43 cvs 715: {
1.79 cvs 716: char *ptr;
1.43 cvs 717: unsigned short redval = (unsigned short) -1;
718: unsigned short greenval = 0; /* composant of each RGB */
719: unsigned short blueval = 0; /* default to red if unknown ! */
720: int best = 0; /* best color in list found */
1.404 vatton 721: ThotBool warn;
1.43 cvs 722:
1.82 cvs 723: cssRule = SkipBlanksAndComments (cssRule);
1.184 vatton 724: val->typed_data.unit = UNIT_INVALID;
1.43 cvs 725: val->typed_data.real = FALSE;
726: val->typed_data.value = 0;
1.57 cvs 727: ptr = TtaGiveRGB (cssRule, &redval, &greenval, &blueval);
1.292 vatton 728: if (!strncasecmp (cssRule, "InactiveCaptionText", 19))
729: {
1.364 vatton 730: val->typed_data.unit = VALUE_INHERIT;
1.292 vatton 731: cssRule += 19;
732: }
733: else if (!strncasecmp (cssRule, "ThreeDLightShadow", 17))
734: {
1.364 vatton 735: val->typed_data.unit = VALUE_INHERIT;
1.292 vatton 736: cssRule += 17;
737: }
738: else if (!strncasecmp (cssRule, "ThreeDDarkShadow", 16))
739: {
1.364 vatton 740: val->typed_data.unit = VALUE_INHERIT;
1.292 vatton 741: cssRule += 16;
742: }
743: else if (!strncasecmp (cssRule, "ButtonHighlight", 15) ||
1.327 vatton 744: !strncasecmp (cssRule, "InactiveCaption", 15) ||
745: !strncasecmp (cssRule, "ThreeDHighlight", 15))
1.292 vatton 746: {
1.364 vatton 747: val->typed_data.unit = VALUE_INHERIT;
1.292 vatton 748: cssRule += 15;
749: }
750: else if (!strncasecmp (cssRule, "InactiveBorder", 14) ||
1.327 vatton 751: !strncasecmp (cssRule, "InfoBackground", 14))
1.292 vatton 752: {
1.364 vatton 753: val->typed_data.unit = VALUE_INHERIT;
1.292 vatton 754: cssRule += 14;
755: }
756: else if (!strncasecmp (cssRule, "ActiveCaption", 13) ||
1.327 vatton 757: !strncasecmp (cssRule, "HighlightText", 13))
1.292 vatton 758: {
1.364 vatton 759: val->typed_data.unit = VALUE_INHERIT;
1.292 vatton 760: cssRule += 13;
761: }
762: else if (!strncasecmp (cssRule, "ActiveBorder", 12) ||
1.327 vatton 763: !strncasecmp (cssRule, "AppWorkspace", 12) ||
764: !strncasecmp (cssRule, "ButtonShadow", 12) ||
765: !strncasecmp (cssRule, "ThreeDShadow", 12))
1.292 vatton 766: {
1.364 vatton 767: val->typed_data.unit = VALUE_INHERIT;
1.292 vatton 768: cssRule += 12;
769: }
770: else if (!strncasecmp (cssRule, "CaptionText", 11) ||
1.327 vatton 771: !strncasecmp (cssRule, "WindowFrame", 11))
1.292 vatton 772: {
1.364 vatton 773: val->typed_data.unit = VALUE_INHERIT;
1.292 vatton 774: cssRule += 11;
775: }
776: else if (!strncasecmp (cssRule, "Background", 10) ||
1.327 vatton 777: !strncasecmp (cssRule, "ButtonFace", 10) ||
778: !strncasecmp (cssRule, "ButtonText", 10) ||
779: !strncasecmp (cssRule, "ThreeDFace", 10) ||
780: !strncasecmp (cssRule, "WindowText", 10))
1.292 vatton 781: {
1.364 vatton 782: val->typed_data.unit = VALUE_INHERIT;
1.292 vatton 783: cssRule += 10;
784: }
785: else if (!strncasecmp (cssRule, "Highlight", 9) ||
1.327 vatton 786: !strncasecmp (cssRule, "Scrollbar", 9))
1.292 vatton 787: {
1.364 vatton 788: val->typed_data.unit = VALUE_INHERIT;
1.292 vatton 789: cssRule += 9;
790: }
791: else if (!strncasecmp (cssRule, "GrayText", 8) ||
1.327 vatton 792: !strncasecmp (cssRule, "InfoText", 8) ||
793: !strncasecmp (cssRule, "MenuText", 8))
1.292 vatton 794: {
1.364 vatton 795: val->typed_data.unit = VALUE_INHERIT;
1.292 vatton 796: cssRule += 8;
797: }
798: else if (!strncasecmp (cssRule, "Window", 6))
799: {
1.364 vatton 800: val->typed_data.unit = VALUE_INHERIT;
1.292 vatton 801: cssRule += 6;
802: }
803: else if (!strncasecmp (cssRule, "Menu", 5))
804: {
1.364 vatton 805: val->typed_data.unit = VALUE_INHERIT;
1.292 vatton 806: cssRule += 5;
807: }
1.293 quint 808: else if (!strncasecmp (cssRule, "inherit", 7))
809: {
810: val->typed_data.unit = VALUE_INHERIT;
811: cssRule += 7;
812: }
1.404 vatton 813: else if (!strncasecmp (cssRule, "hsl", 3))
814: {
815: val->typed_data.unit = VALUE_INHERIT;
816: // check if Amaya should report CSS warnings
817: TtaGetEnvBoolean ("CSS_WARN", &warn);
818: if (warn)
819: cssRule = SkipValue ("Warning: CSS3 value not supported", cssRule);
820: else
821: cssRule = SkipValue (NULL, cssRule);
822: }
823: else if (!strncasecmp (cssRule, "rgba", 4))
824: {
825: val->typed_data.unit = VALUE_INHERIT;
826: // check if Amaya should report CSS warnings
827: TtaGetEnvBoolean ("CSS_WARN", &warn);
828: if (warn)
829: cssRule = SkipValue ("Warning: CSS3 value not supported", cssRule);
830: else
831: cssRule = SkipValue (NULL, cssRule);
832: }
1.57 cvs 833: if (ptr == cssRule)
1.43 cvs 834: {
1.404 vatton 835: cssRule = SkipValue ("Invalid color value", cssRule);
1.43 cvs 836: val->typed_data.value = 0;
1.184 vatton 837: val->typed_data.unit = UNIT_INVALID;
1.43 cvs 838: }
1.293 quint 839: else if (val->typed_data.unit != VALUE_INHERIT)
1.43 cvs 840: {
841: best = TtaGetThotColor (redval, greenval, blueval);
842: val->typed_data.value = best;
1.184 vatton 843: val->typed_data.unit = UNIT_REL;
1.57 cvs 844: cssRule = ptr;
1.43 cvs 845: }
846: val->typed_data.real = FALSE;
1.262 vatton 847: cssRule = SkipBlanksAndComments (cssRule);
1.65 cvs 848: return (cssRule);
1.43 cvs 849: }
1.1 cvs 850:
851: /*----------------------------------------------------------------------
1.231 vatton 852: CheckImportantRule updates the field important of the context and
853: the line number.
1.117 vatton 854: ----------------------------------------------------------------------*/
1.360 vatton 855: static void CheckImportantRule (char *cssRule, PresentationContext context)
1.117 vatton 856: {
1.276 vatton 857: PresentationContextBlock dummyctxt;
858:
859: if (context == NULL)
860: /* no context provided */
861: context = &dummyctxt;
862:
1.117 vatton 863: cssRule = SkipBlanksAndComments (cssRule);
1.360 vatton 864: while (*cssRule != EOS && *cssRule != '!' && *cssRule != ';')
865: cssRule++;
1.120 vatton 866: if (*cssRule != '!')
867: context->important = FALSE;
868: else
1.117 vatton 869: {
1.120 vatton 870: cssRule++;
1.360 vatton 871: ImportantPos = cssRule;
1.120 vatton 872: cssRule = SkipBlanksAndComments (cssRule);
873: if (!strncasecmp (cssRule, "important", 9))
1.327 vatton 874: {
1.360 vatton 875: ImportantPos[-1] = EOS;
1.327 vatton 876: context->important = TRUE;
877: }
1.120 vatton 878: else
1.360 vatton 879: {
880: ImportantPos = NULL;
881: context->important = FALSE;
882: }
883: }
884: }
885:
886: /*----------------------------------------------------------------------
887: SkipImportantRule skips important markup
888: ----------------------------------------------------------------------*/
889: static char *SkipImportantRule (char *cssRule)
890: {
891: if (ImportantPos)
892: {
893: ImportantPos[-1] = '!';
1.361 vatton 894: cssRule = ImportantPos;
895: cssRule = SkipBlanksAndComments (cssRule);
896: cssRule += 9;
1.360 vatton 897: ImportantPos = NULL;
1.117 vatton 898: }
1.360 vatton 899: cssRule = SkipBlanksAndComments (cssRule);
1.117 vatton 900: return (cssRule);
901: }
902:
903: /*----------------------------------------------------------------------
1.327 vatton 904: ParseCSSBorderTopWidth: parse a CSS BorderTopWidth
905: attribute string.
1.1 cvs 906: ----------------------------------------------------------------------*/
1.79 cvs 907: static char *ParseCSSBorderTopWidth (Element element, PSchema tsch,
1.327 vatton 908: PresentationContext context,
909: char *cssRule, CSSInfoPtr css,
910: ThotBool isHTML)
1.1 cvs 911: {
1.41 cvs 912: PresentationValue border;
1.366 vatton 913: char *start_value = cssRule;
1.41 cvs 914:
1.82 cvs 915: cssRule = SkipBlanksAndComments (cssRule);
1.288 vatton 916: cssRule = ParseABorderValue (cssRule, &border);
1.366 vatton 917: if (border.typed_data.unit != UNIT_INVALID)
918: {
919: if (DoDialog)
920: {
921: if (All_sides)
922: DisplayStyleValue ("border-width", start_value, cssRule);
923: else
924: DisplayStyleValue ("border-top-width", start_value, cssRule);
925: }
926: else if (DoApply)
927: TtaSetStylePresentation (PRBorderTopWidth, element, tsch, context, border);
928: }
1.1 cvs 929: return (cssRule);
930: }
931:
932: /*----------------------------------------------------------------------
1.327 vatton 933: ParseCSSBorderBottomWidth: parse a CSS BorderBottomWidth
934: attribute string.
1.1 cvs 935: ----------------------------------------------------------------------*/
1.79 cvs 936: static char *ParseCSSBorderBottomWidth (Element element, PSchema tsch,
1.327 vatton 937: PresentationContext context,
938: char *cssRule, CSSInfoPtr css,
939: ThotBool isHTML)
1.1 cvs 940: {
1.41 cvs 941: PresentationValue border;
1.366 vatton 942: char *start_value = cssRule;
1.41 cvs 943:
1.82 cvs 944: cssRule = SkipBlanksAndComments (cssRule);
1.41 cvs 945: /* first parse the attribute string */
1.288 vatton 946: cssRule = ParseABorderValue (cssRule, &border);
1.366 vatton 947: if (border.typed_data.unit != UNIT_INVALID)
948: {
949: if (DoDialog)
950: DisplayStyleValue ("border-bottom-width", start_value, cssRule);
951: else if (DoApply)
952: TtaSetStylePresentation (PRBorderBottomWidth, element, tsch, context, border);
953: }
1.1 cvs 954: return (cssRule);
955: }
956:
957: /*----------------------------------------------------------------------
1.327 vatton 958: ParseCSSBorderLeftWidth: parse a CSS BorderLeftWidth
959: attribute string.
1.1 cvs 960: ----------------------------------------------------------------------*/
1.79 cvs 961: static char *ParseCSSBorderLeftWidth (Element element, PSchema tsch,
1.327 vatton 962: PresentationContext context,
963: char *cssRule, CSSInfoPtr css,
964: ThotBool isHTML)
1.1 cvs 965: {
1.41 cvs 966: PresentationValue border;
1.366 vatton 967: char *start_value = cssRule;
1.41 cvs 968:
1.82 cvs 969: cssRule = SkipBlanksAndComments (cssRule);
1.41 cvs 970: /* first parse the attribute string */
1.288 vatton 971: cssRule = ParseABorderValue (cssRule, &border);
1.366 vatton 972: if (border.typed_data.unit != UNIT_INVALID)
973: {
974: if (DoDialog)
975: DisplayStyleValue ("border-left-width", start_value, cssRule);
976: else if (DoApply)
977: TtaSetStylePresentation (PRBorderLeftWidth, element, tsch, context, border);
978: }
1.1 cvs 979: return (cssRule);
980: }
981:
982: /*----------------------------------------------------------------------
1.327 vatton 983: ParseCSSBorderRightWidth: parse a CSS BorderRightWidth
984: attribute string.
1.1 cvs 985: ----------------------------------------------------------------------*/
1.79 cvs 986: static char *ParseCSSBorderRightWidth (Element element, PSchema tsch,
1.327 vatton 987: PresentationContext context,
988: char *cssRule, CSSInfoPtr css,
989: ThotBool isHTML)
1.1 cvs 990: {
1.41 cvs 991: PresentationValue border;
1.366 vatton 992: char *start_value = cssRule;
1.41 cvs 993:
1.82 cvs 994: cssRule = SkipBlanksAndComments (cssRule);
1.41 cvs 995: /* first parse the attribute string */
1.288 vatton 996: cssRule = ParseABorderValue (cssRule, &border);
1.184 vatton 997: if (border.typed_data.unit != UNIT_INVALID && DoApply)
1.366 vatton 998: {
999: if (DoDialog)
1000: DisplayStyleValue ("border-right-width", start_value, cssRule);
1001: else if (DoApply)
1002: TtaSetStylePresentation (PRBorderRightWidth, element, tsch, context, border);
1003: }
1.1 cvs 1004: return (cssRule);
1005: }
1006:
1007: /*----------------------------------------------------------------------
1.327 vatton 1008: ParseCSSBorderWidth: parse a CSS BorderWidth
1009: attribute string.
1.1 cvs 1010: ----------------------------------------------------------------------*/
1.79 cvs 1011: static char *ParseCSSBorderWidth (Element element, PSchema tsch,
1.327 vatton 1012: PresentationContext context,
1013: char *cssRule, CSSInfoPtr css,
1014: ThotBool isHTML)
1.1 cvs 1015: {
1.79 cvs 1016: char *ptrT, *ptrR, *ptrB, *ptrL;
1.366 vatton 1017: int skippedNL, n;
1.41 cvs 1018:
1.82 cvs 1019: ptrT = SkipBlanksAndComments (cssRule);
1.366 vatton 1020: if (DoDialog)
1021: n = NumberOfValues (ptrT);
1022: if (DoDialog && n < 2)
1.42 cvs 1023: {
1.366 vatton 1024: // check if the border dialog must be updated
1025: All_sides = TRUE;
1026: ptrR = ParseCSSBorderTopWidth (element, tsch, context, ptrT, css, isHTML);
1027: All_sides = FALSE;
1.42 cvs 1028: }
1029: else
1030: {
1.366 vatton 1031: /* First parse Border-Top */
1032: ptrR = ParseCSSBorderTopWidth (element, tsch, context, ptrT, css, isHTML);
1.415 vatton 1033: if (ptrR == ptrT)
1034: {
1035: // invalid value
1036: cssRule = SkipValue ("Invalid border-width value", ptrT);
1037: return (cssRule);
1038: }
1.366 vatton 1039: ptrR = SkipBlanksAndComments (ptrR);
1040: if (*ptrR == ';' || *ptrR == '}' || *ptrR == EOS || *ptrR == ',')
1.327 vatton 1041: {
1042: skippedNL = NewLineSkipped;
1.366 vatton 1043: cssRule = ptrR;
1044: /* apply the Border-Top to all */
1045: ptrR = ParseCSSBorderRightWidth (element, tsch, context, ptrT, css, isHTML);
1046: NewLineSkipped = skippedNL;
1047: ptrR = ParseCSSBorderBottomWidth (element, tsch, context, ptrT, css, isHTML);
1.327 vatton 1048: NewLineSkipped = skippedNL;
1.366 vatton 1049: ptrR = ParseCSSBorderLeftWidth (element, tsch, context, ptrT, css, isHTML);
1.327 vatton 1050: }
1.42 cvs 1051: else
1.327 vatton 1052: {
1.366 vatton 1053: /* parse Border-Right */
1054: ptrB = ParseCSSBorderRightWidth (element, tsch, context, ptrR, css, isHTML);
1055: ptrB = SkipBlanksAndComments (ptrB);
1056: if (*ptrB == ';' || *ptrB == '}' || *ptrB == EOS || *ptrB == ',')
1.327 vatton 1057: {
1.366 vatton 1058: skippedNL = NewLineSkipped;
1059: cssRule = ptrB;
1060: /* apply the Border-Top to Border-Bottom */
1061: ptrB = ParseCSSBorderBottomWidth (element, tsch, context, ptrT, css, isHTML);
1062: NewLineSkipped = skippedNL;
1.327 vatton 1063: /* apply the Border-Right to Border-Left */
1.366 vatton 1064: ptrB = ParseCSSBorderLeftWidth (element, tsch, context, ptrR, css, isHTML);
1.327 vatton 1065: }
1066: else
1.366 vatton 1067: {
1068: /* parse Border-Bottom */
1069: ptrL = ParseCSSBorderBottomWidth (element, tsch, context, ptrB, css, isHTML);
1070: ptrL = SkipBlanksAndComments (ptrL);
1071: if (*ptrL == ';' || *ptrL == '}' || *ptrL == EOS || *ptrL == ',')
1072: {
1073: cssRule = ptrL;
1074: /* apply the Border-Right to Border-Left */
1075: ptrL = ParseCSSBorderLeftWidth (element, tsch, context, ptrR, css, isHTML);
1076: }
1077: else
1078: /* parse Border-Left */
1079: cssRule = ParseCSSBorderLeftWidth (element, tsch, context, ptrL, css, isHTML);
1080: cssRule = SkipBlanksAndComments (cssRule);
1081: }
1.327 vatton 1082: }
1.42 cvs 1083: }
1.1 cvs 1084: return (cssRule);
1085: }
1086:
1087: /*----------------------------------------------------------------------
1.327 vatton 1088: ParseCSSBorderColorTop: parse a CSS BorderColorTop
1089: attribute string.
1.1 cvs 1090: ----------------------------------------------------------------------*/
1.79 cvs 1091: static char *ParseCSSBorderColorTop (Element element, PSchema tsch,
1.327 vatton 1092: PresentationContext context,
1093: char *cssRule, CSSInfoPtr css,
1094: ThotBool isHTML)
1.1 cvs 1095: {
1.117 vatton 1096: PresentationValue best;
1.366 vatton 1097: char *start_value = cssRule;
1.43 cvs 1098:
1.234 vatton 1099: if (!strncasecmp (cssRule, "transparent", 11))
1100: {
1101: best.typed_data.value = -2; /* -2 means transparent */
1102: best.typed_data.unit = UNIT_REL;
1103: cssRule = SkipWord (cssRule);
1104: }
1105: else
1106: cssRule = ParseCSSColor (cssRule, &best);
1.366 vatton 1107: if (best.typed_data.unit != UNIT_INVALID)
1108: {
1109: if (DoDialog)
1110: {
1111: if (All_sides)
1112: DisplayStyleValue ("border-color", start_value, cssRule);
1113: else
1114: DisplayStyleValue ("border-top-color", start_value, cssRule);
1115: }
1116: else if (DoApply)
1117: /* install the new presentation */
1118: TtaSetStylePresentation (PRBorderTopColor, element, tsch, context, best);
1119: }
1.117 vatton 1120: return (cssRule);
1.1 cvs 1121: }
1122:
1123: /*----------------------------------------------------------------------
1.327 vatton 1124: ParseCSSBorderColorLeft: parse a CSS BorderColorLeft
1125: attribute string.
1.42 cvs 1126: ----------------------------------------------------------------------*/
1.79 cvs 1127: static char *ParseCSSBorderColorLeft (Element element, PSchema tsch,
1.327 vatton 1128: PresentationContext context,
1129: char *cssRule, CSSInfoPtr css,
1130: ThotBool isHTML)
1.42 cvs 1131: {
1.117 vatton 1132: PresentationValue best;
1.366 vatton 1133: char *start_value = cssRule;
1.117 vatton 1134:
1.234 vatton 1135: if (!strncasecmp (cssRule, "transparent", 11))
1136: {
1137: best.typed_data.value = -2; /* -2 means transparent */
1138: best.typed_data.unit = UNIT_REL;
1139: cssRule = SkipWord (cssRule);
1140: }
1141: else
1142: cssRule = ParseCSSColor (cssRule, &best);
1.184 vatton 1143: if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.366 vatton 1144: {
1145: if (DoDialog)
1146: DisplayStyleValue ("border-left-color", start_value, cssRule);
1147: else if (DoApply)
1148: /* install the new presentation */
1149: TtaSetStylePresentation (PRBorderLeftColor, element, tsch, context, best);
1150: }
1.117 vatton 1151: return (cssRule);
1.42 cvs 1152: }
1153:
1154: /*----------------------------------------------------------------------
1.327 vatton 1155: ParseCSSBorderColorBottom: parse a CSS BorderColorBottom
1156: attribute string.
1.42 cvs 1157: ----------------------------------------------------------------------*/
1.79 cvs 1158: static char *ParseCSSBorderColorBottom (Element element, PSchema tsch,
1.327 vatton 1159: PresentationContext context,
1160: char *cssRule, CSSInfoPtr css,
1161: ThotBool isHTML)
1.42 cvs 1162: {
1.117 vatton 1163: PresentationValue best;
1.366 vatton 1164: char *start_value = cssRule;
1.43 cvs 1165:
1.234 vatton 1166: if (!strncasecmp (cssRule, "transparent", 11))
1167: {
1168: best.typed_data.value = -2; /* -2 means transparent */
1169: best.typed_data.unit = UNIT_REL;
1170: cssRule = SkipWord (cssRule);
1171: }
1172: else
1173: cssRule = ParseCSSColor (cssRule, &best);
1.184 vatton 1174: if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.366 vatton 1175: {
1176: if (DoDialog)
1177: DisplayStyleValue ("border-bottom-color", start_value, cssRule);
1178: else if (DoApply)
1179: /* install the new presentation */
1180: TtaSetStylePresentation (PRBorderBottomColor, element, tsch, context, best);
1181: }
1.327 vatton 1182: return (cssRule);
1.42 cvs 1183: }
1184:
1185: /*----------------------------------------------------------------------
1.327 vatton 1186: ParseCSSBorderColorRight: parse a CSS BorderColorRight
1187: attribute string.
1.1 cvs 1188: ----------------------------------------------------------------------*/
1.79 cvs 1189: static char *ParseCSSBorderColorRight (Element element, PSchema tsch,
1.327 vatton 1190: PresentationContext context,
1191: char *cssRule, CSSInfoPtr css,
1192: ThotBool isHTML)
1.1 cvs 1193: {
1.117 vatton 1194: PresentationValue best;
1.366 vatton 1195: char *start_value = cssRule;
1.43 cvs 1196:
1.234 vatton 1197: if (!strncasecmp (cssRule, "transparent", 11))
1198: {
1199: best.typed_data.value = -2; /* -2 means transparent */
1200: best.typed_data.unit = UNIT_REL;
1201: cssRule = SkipWord (cssRule);
1202: }
1203: else
1204: cssRule = ParseCSSColor (cssRule, &best);
1.184 vatton 1205: if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.366 vatton 1206: {
1207: if (DoDialog)
1208: DisplayStyleValue ("border-right-color", start_value, cssRule);
1209: else if (DoApply)
1210: TtaSetStylePresentation (PRBorderRightColor, element, tsch, context, best);
1211: }
1.117 vatton 1212: return (cssRule);
1.1 cvs 1213: }
1214:
1215: /*----------------------------------------------------------------------
1.327 vatton 1216: ParseCSSBorderColor: parse a CSS border-color
1217: attribute string.
1.42 cvs 1218: ----------------------------------------------------------------------*/
1.79 cvs 1219: static char *ParseCSSBorderColor (Element element, PSchema tsch,
1.327 vatton 1220: PresentationContext context,
1221: char *cssRule, CSSInfoPtr css,
1222: ThotBool isHTML)
1.42 cvs 1223: {
1.79 cvs 1224: char *ptrT, *ptrR, *ptrB, *ptrL;
1.366 vatton 1225: int skippedNL, n;
1.42 cvs 1226:
1.82 cvs 1227: ptrT = SkipBlanksAndComments (cssRule);
1.366 vatton 1228: if (DoDialog)
1229: n = NumberOfValues (ptrT);
1230: if (DoDialog && n < 2)
1.42 cvs 1231: {
1.366 vatton 1232: // check if the border dialog must be updated
1233: All_sides = TRUE;
1234: ptrR = ParseCSSBorderColorTop (element, tsch, context, ptrT, css, isHTML);
1235: All_sides = FALSE;
1.42 cvs 1236: }
1237: else
1238: {
1.366 vatton 1239: /* First parse Border-Top */
1240: ptrR = ParseCSSBorderColorTop (element, tsch, context, ptrT, css, isHTML);
1241: ptrR = SkipBlanksAndComments (ptrR);
1242: if (*ptrR == ';' || *ptrR == '}' || *ptrR == EOS || *ptrR == ',')
1.327 vatton 1243: {
1244: skippedNL = NewLineSkipped;
1.366 vatton 1245: cssRule = ptrR;
1246: /* apply the Border-Top to all */
1247: ptrR = ParseCSSBorderColorRight (element, tsch, context, ptrT, css, isHTML);
1248: NewLineSkipped = skippedNL;
1249: ptrR = ParseCSSBorderColorBottom (element, tsch, context, ptrT, css, isHTML);
1.327 vatton 1250: NewLineSkipped = skippedNL;
1.366 vatton 1251: ptrR = ParseCSSBorderColorLeft (element, tsch, context, ptrT, css, isHTML);
1.327 vatton 1252: }
1.42 cvs 1253: else
1.327 vatton 1254: {
1.366 vatton 1255: /* parse Border-Right */
1256: ptrB = ParseCSSBorderColorRight (element, tsch, context, ptrR, css, isHTML);
1257: ptrB = SkipBlanksAndComments (ptrB);
1258: if (*ptrB == ';' || *ptrB == '}' || *ptrB == EOS || *ptrB == ',')
1.327 vatton 1259: {
1.366 vatton 1260: skippedNL = NewLineSkipped;
1261: cssRule = ptrB;
1262: /* apply the Border-Top to Border-Bottom */
1263: ptrB = ParseCSSBorderColorBottom (element, tsch, context, ptrT, css, isHTML);
1264: NewLineSkipped = skippedNL;
1.327 vatton 1265: /* apply the Border-Right to Border-Left */
1.366 vatton 1266: ptrB = ParseCSSBorderColorLeft (element, tsch, context, ptrR, css, isHTML);
1.327 vatton 1267: }
1268: else
1.366 vatton 1269: {
1270: skippedNL = NewLineSkipped;
1271: /* parse Border-Bottom */
1272: ptrL = ParseCSSBorderColorBottom (element, tsch, context, ptrB, css, isHTML);
1273: NewLineSkipped = skippedNL;
1274: ptrL = SkipBlanksAndComments (ptrL);
1275: if (*ptrL == ';' || *ptrL == '}' || *ptrL == EOS || *ptrL == ',')
1276: {
1277: cssRule = ptrL;
1278: /* apply the Border-Right to Border-Left */
1279: ptrL = ParseCSSBorderColorLeft (element, tsch, context, ptrR, css, isHTML);
1280: }
1281: else
1282: /* parse Border-Left */
1283: cssRule = ParseCSSBorderColorLeft (element, tsch, context, ptrL, css, isHTML);
1284: cssRule = SkipBlanksAndComments (cssRule);
1285: }
1.327 vatton 1286: }
1.42 cvs 1287: }
1288: return (cssRule);
1289: }
1290:
1291: /*----------------------------------------------------------------------
1.327 vatton 1292: ParseCSSBorderStyleTop: parse a CSS BorderStyleTop
1293: attribute string.
1.42 cvs 1294: ----------------------------------------------------------------------*/
1.79 cvs 1295: static char *ParseCSSBorderStyleTop (Element element, PSchema tsch,
1.327 vatton 1296: PresentationContext context,
1297: char *cssRule, CSSInfoPtr css,
1298: ThotBool isHTML)
1.42 cvs 1299: {
1.43 cvs 1300: PresentationValue border;
1.366 vatton 1301: char *start_value;
1.43 cvs 1302:
1.82 cvs 1303: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 1304: start_value = cssRule;
1.43 cvs 1305: cssRule = ParseBorderStyle (cssRule, &border);
1.366 vatton 1306: if (border.typed_data.unit != UNIT_INVALID)
1307: {
1308: if (DoDialog)
1309: {
1310: if (All_sides)
1311: DisplayStyleValue ("border-style", start_value, cssRule);
1312: else
1313: DisplayStyleValue ("border-top-style", start_value, cssRule);
1314: }
1315: else if (DoApply)
1316: TtaSetStylePresentation (PRBorderTopStyle, element, tsch, context, border);
1317: }
1.42 cvs 1318: return (cssRule);
1319: }
1320:
1321: /*----------------------------------------------------------------------
1.327 vatton 1322: ParseCSSBorderStyleLeft: parse a CSS BorderStyleLeft
1323: attribute string.
1.42 cvs 1324: ----------------------------------------------------------------------*/
1.79 cvs 1325: static char *ParseCSSBorderStyleLeft (Element element, PSchema tsch,
1.327 vatton 1326: PresentationContext context,
1327: char *cssRule, CSSInfoPtr css,
1328: ThotBool isHTML)
1.42 cvs 1329: {
1.43 cvs 1330: PresentationValue border;
1.366 vatton 1331: char *start_value;
1.43 cvs 1332:
1.82 cvs 1333: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 1334: start_value = cssRule;
1.43 cvs 1335: cssRule = ParseBorderStyle (cssRule, &border);
1.366 vatton 1336: if (border.typed_data.unit != UNIT_INVALID)
1337: {
1338: if (DoDialog)
1339: DisplayStyleValue ("border-left-style", start_value, cssRule);
1340: else if (DoApply)
1341: TtaSetStylePresentation (PRBorderLeftStyle, element, tsch, context, border);
1342: }
1.42 cvs 1343: return (cssRule);
1344: }
1345:
1346: /*----------------------------------------------------------------------
1.327 vatton 1347: ParseCSSBorderStyleBottom: parse a CSS BorderStyleBottom
1348: attribute string.
1.1 cvs 1349: ----------------------------------------------------------------------*/
1.79 cvs 1350: static char *ParseCSSBorderStyleBottom (Element element, PSchema tsch,
1.327 vatton 1351: PresentationContext context,
1352: char *cssRule, CSSInfoPtr css,
1353: ThotBool isHTML)
1.1 cvs 1354: {
1.43 cvs 1355: PresentationValue border;
1.366 vatton 1356: char *start_value;
1.43 cvs 1357:
1.82 cvs 1358: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 1359: start_value = cssRule;
1.43 cvs 1360: cssRule = ParseBorderStyle (cssRule, &border);
1.366 vatton 1361: if (border.typed_data.unit != UNIT_INVALID)
1362: {
1363: if (DoDialog)
1364: DisplayStyleValue ("border-bottom-style", start_value, cssRule);
1365: else if (DoApply)
1366: TtaSetStylePresentation (PRBorderBottomStyle, element, tsch, context, border);
1367: }
1.1 cvs 1368: return (cssRule);
1369: }
1370:
1371: /*----------------------------------------------------------------------
1.327 vatton 1372: ParseCSSBorderStyleRight: parse a CSS BorderStyleRight
1373: attribute string.
1.1 cvs 1374: ----------------------------------------------------------------------*/
1.79 cvs 1375: static char *ParseCSSBorderStyleRight (Element element, PSchema tsch,
1.327 vatton 1376: PresentationContext context,
1377: char *cssRule, CSSInfoPtr css,
1378: ThotBool isHTML)
1.1 cvs 1379: {
1.43 cvs 1380: PresentationValue border;
1.366 vatton 1381: char *start_value;
1.43 cvs 1382:
1.82 cvs 1383: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 1384: start_value = cssRule;
1.43 cvs 1385: cssRule = ParseBorderStyle (cssRule, &border);
1.184 vatton 1386: if (border.typed_data.unit != UNIT_INVALID && DoApply)
1.366 vatton 1387: {
1388: if (DoDialog)
1389: DisplayStyleValue ("border-right-style", start_value, cssRule);
1390: else if (DoApply)
1391: TtaSetStylePresentation (PRBorderRightStyle, element, tsch, context, border);
1392: }
1.1 cvs 1393: return (cssRule);
1394: }
1395:
1396: /*----------------------------------------------------------------------
1.349 quint 1397: ParseCSSBorderStyle: parse a CSS border-style attribute string.
1.1 cvs 1398: ----------------------------------------------------------------------*/
1.79 cvs 1399: static char *ParseCSSBorderStyle (Element element, PSchema tsch,
1.327 vatton 1400: PresentationContext context,
1401: char *cssRule, CSSInfoPtr css,
1402: ThotBool isHTML)
1.1 cvs 1403: {
1.79 cvs 1404: char *ptrT, *ptrR, *ptrB, *ptrL;
1.366 vatton 1405: int skippedNL, n;
1.42 cvs 1406:
1.82 cvs 1407: ptrT = SkipBlanksAndComments (cssRule);
1.366 vatton 1408: if (DoDialog)
1409: n = NumberOfValues (ptrT);
1410: if (DoDialog && n < 2)
1.42 cvs 1411: {
1.366 vatton 1412: // check if the border dialog must be updated
1413: All_sides = TRUE;
1414: ptrR = ParseCSSBorderStyleTop(element, tsch, context, ptrT, css, isHTML);
1415: All_sides = FALSE;
1.42 cvs 1416: }
1417: else
1418: {
1.366 vatton 1419: /* First parse Border-Top */
1420: ptrR = ParseCSSBorderStyleTop (element, tsch, context, ptrT, css, isHTML);
1421: ptrR = SkipBlanksAndComments (ptrR);
1422: if (*ptrR == ';' || *ptrR == '}' || *ptrR == EOS || *ptrR == ',')
1.327 vatton 1423: {
1424: skippedNL = NewLineSkipped;
1.366 vatton 1425: cssRule = ptrR;
1426: /* apply the Border-Top to all */
1427: ptrR = ParseCSSBorderStyleRight (element, tsch, context, ptrT, css, isHTML);
1428: NewLineSkipped = skippedNL;
1429: ptrR = ParseCSSBorderStyleBottom (element, tsch, context, ptrT, css, isHTML);
1.327 vatton 1430: NewLineSkipped = skippedNL;
1.366 vatton 1431: ptrR = ParseCSSBorderStyleLeft (element, tsch, context, ptrT, css, isHTML);
1.327 vatton 1432: }
1.42 cvs 1433: else
1.327 vatton 1434: {
1.366 vatton 1435: /* parse Border-Right */
1436: ptrB = ParseCSSBorderStyleRight (element, tsch, context, ptrR, css, isHTML);
1437: ptrB = SkipBlanksAndComments (ptrB);
1438: if (*ptrB == ';' || *ptrR == '}' || *ptrB == EOS || *ptrB == ',')
1.327 vatton 1439: {
1.366 vatton 1440: skippedNL = NewLineSkipped;
1441: cssRule = ptrB;
1442: /* apply the Border-Top to Border-Bottom */
1443: ptrB = ParseCSSBorderStyleBottom (element, tsch, context, ptrT, css, isHTML);
1444: NewLineSkipped = skippedNL;
1.327 vatton 1445: /* apply the Border-Right to Border-Left */
1.366 vatton 1446: ptrB = ParseCSSBorderStyleLeft (element, tsch, context, ptrR, css, isHTML);
1.327 vatton 1447: }
1448: else
1.366 vatton 1449: {
1450: /* parse Border-Bottom */
1451: ptrL = ParseCSSBorderStyleBottom (element, tsch, context, ptrB, css, isHTML);
1452: ptrL = SkipBlanksAndComments (ptrL);
1453: if (*ptrL == ';' || *ptrR == '}' || *ptrL == EOS || *ptrL == ',')
1454: {
1455: cssRule = ptrL;
1456: /* apply the Border-Right to Border-Left */
1457: ptrL = ParseCSSBorderStyleLeft (element, tsch, context, ptrR, css, isHTML);
1458: }
1459: else
1460: /* parse Border-Left */
1461: cssRule = ParseCSSBorderStyleLeft (element, tsch, context, ptrL, css, isHTML);
1462: cssRule = SkipBlanksAndComments (cssRule);
1463: }
1.327 vatton 1464: }
1.42 cvs 1465: }
1466: return (cssRule);
1467: }
1468:
1469: /*----------------------------------------------------------------------
1.327 vatton 1470: ParseCSSBorderTop: parse a CSS BorderTop
1471: attribute string.
1.42 cvs 1472: ----------------------------------------------------------------------*/
1.79 cvs 1473: static char *ParseCSSBorderTop (Element element, PSchema tsch,
1.327 vatton 1474: PresentationContext context, char *cssRule,
1475: CSSInfoPtr css, ThotBool isHTML)
1.42 cvs 1476: {
1.370 vatton 1477: PresentationValue best;
1478: char *ptr;
1479: ThotBool style, width, color;
1.43 cvs 1480:
1.82 cvs 1481: cssRule = SkipBlanksAndComments (cssRule);
1.322 vatton 1482: /* register given values */
1.337 vatton 1483: if (!strncmp (cssRule, "none", 4))
1.370 vatton 1484: style = width = color = TRUE;
1.337 vatton 1485: else
1.370 vatton 1486: style = width = color = FALSE;
1.301 vatton 1487: while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.43 cvs 1488: {
1489: ptr = cssRule;
1490: cssRule = ParseCSSBorderStyleTop (element, tsch, context, cssRule, css, isHTML);
1491: if (ptr == cssRule)
1.327 vatton 1492: {
1493: cssRule = ParseCSSBorderTopWidth (element, tsch, context, cssRule, css, isHTML);
1494: if (ptr == cssRule)
1.370 vatton 1495: {
1496: cssRule = ParseCSSBorderColorTop (element, tsch, context, cssRule, css, isHTML);
1497: if (ptr != cssRule)
1498: color = TRUE;
1499: }
1.327 vatton 1500: else
1501: width = TRUE;
1502: if (ptr == cssRule)
1503: {
1504: /* rule not found */
1505: cssRule = SkipValue ("Invalid border value", cssRule);
1506: return (cssRule);
1507: }
1508: }
1.322 vatton 1509: else
1.327 vatton 1510: style = TRUE;
1.82 cvs 1511: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 1512: }
1.322 vatton 1513:
1514: if (!width)
1.405 kia 1515: ParseCSSBorderTopWidth (element, tsch, context, (char*)"medium", css, isHTML);
1.322 vatton 1516: if (!style)
1.405 kia 1517: ParseCSSBorderStyleTop (element, tsch, context, (char*)"none", css, isHTML);
1.370 vatton 1518: if (!color && DoApply)
1519: {
1520: /* get the box color */
1521: best.typed_data.value = -1;
1522: best.typed_data.unit = UNIT_REL;
1523: best.typed_data.real = FALSE;
1524: TtaSetStylePresentation (PRBorderTopColor, element, tsch, context, best);
1525: }
1.42 cvs 1526: return (cssRule);
1527: }
1528:
1529: /*----------------------------------------------------------------------
1.327 vatton 1530: ParseCSSBorderLeft: parse a CSS BorderLeft
1531: attribute string.
1.42 cvs 1532: ----------------------------------------------------------------------*/
1.79 cvs 1533: static char *ParseCSSBorderLeft (Element element, PSchema tsch,
1.327 vatton 1534: PresentationContext context, char *cssRule,
1535: CSSInfoPtr css, ThotBool isHTML)
1.42 cvs 1536: {
1.370 vatton 1537: PresentationValue best;
1538: char *ptr;
1539: ThotBool style, width, color;
1.43 cvs 1540:
1.82 cvs 1541: cssRule = SkipBlanksAndComments (cssRule);
1.322 vatton 1542: /* register given values */
1.337 vatton 1543: if (!strncmp (cssRule, "none", 4))
1.370 vatton 1544: style = width = color = TRUE;
1.337 vatton 1545: else
1.370 vatton 1546: style = width = color = FALSE;
1.301 vatton 1547: while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.43 cvs 1548: {
1549: ptr = cssRule;
1550: cssRule = ParseCSSBorderStyleLeft (element, tsch, context, cssRule, css, isHTML);
1551: if (ptr == cssRule)
1.327 vatton 1552: {
1553: cssRule = ParseCSSBorderLeftWidth (element, tsch, context, cssRule, css, isHTML);
1554: if (ptr == cssRule)
1.370 vatton 1555: {
1556: cssRule = ParseCSSBorderColorLeft (element, tsch, context, cssRule, css, isHTML);
1557: if (ptr != cssRule)
1558: color = TRUE;
1559: }
1.327 vatton 1560: else
1561: width = TRUE;
1562: if (ptr == cssRule)
1563: {
1564: /* rule not found */
1565: cssRule = SkipValue ("Invalid border value", cssRule);
1566: return (cssRule);
1567: }
1568: }
1.322 vatton 1569: else
1.327 vatton 1570: style = TRUE;
1571: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 1572: }
1.322 vatton 1573:
1574: if (!width)
1.405 kia 1575: ParseCSSBorderLeftWidth (element, tsch, context, (char*)"medium", css, isHTML);
1.322 vatton 1576: if (!style)
1.405 kia 1577: ParseCSSBorderStyleLeft (element, tsch, context, (char*)"none", css, isHTML);
1.370 vatton 1578: if (!color && DoApply)
1579: {
1580: /* get the box color */
1581: best.typed_data.value = -1;
1582: best.typed_data.unit = UNIT_REL;
1583: best.typed_data.real = FALSE;
1584: TtaSetStylePresentation (PRBorderLeftColor, element, tsch, context, best);
1585: }
1.1 cvs 1586: return (cssRule);
1587: }
1588:
1589: /*----------------------------------------------------------------------
1.327 vatton 1590: ParseCSSBorderBottom: parse a CSS BorderBottom
1591: attribute string.
1.1 cvs 1592: ----------------------------------------------------------------------*/
1.79 cvs 1593: static char *ParseCSSBorderBottom (Element element, PSchema tsch,
1.327 vatton 1594: PresentationContext context, char *cssRule,
1595: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1596: {
1.370 vatton 1597: PresentationValue best;
1598: char *ptr;
1599: ThotBool style, width, color;
1.43 cvs 1600:
1.82 cvs 1601: cssRule = SkipBlanksAndComments (cssRule);
1.322 vatton 1602: /* register given values */
1.337 vatton 1603: if (!strncmp (cssRule, "none", 4))
1.370 vatton 1604: style = width = color = TRUE;
1.337 vatton 1605: else
1.370 vatton 1606: style = width = color = FALSE;
1.301 vatton 1607: while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.43 cvs 1608: {
1609: ptr = cssRule;
1610: cssRule = ParseCSSBorderStyleBottom (element, tsch, context, cssRule, css, isHTML);
1611: if (ptr == cssRule)
1.327 vatton 1612: {
1613: cssRule = ParseCSSBorderBottomWidth (element, tsch, context, cssRule, css, isHTML);
1614: if (ptr == cssRule)
1.370 vatton 1615: {
1616: cssRule = ParseCSSBorderColorBottom (element, tsch, context, cssRule, css, isHTML);
1617: if (ptr != cssRule)
1618: color = TRUE;
1619: }
1.327 vatton 1620: else
1621: width = TRUE;
1622: if (ptr == cssRule)
1623: {
1624: /* rule not found */
1625: cssRule = SkipValue ("Invalid border value", cssRule);
1626: return (cssRule);
1627: }
1628: }
1.322 vatton 1629: else
1.327 vatton 1630: style = TRUE;
1.82 cvs 1631: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 1632: }
1.322 vatton 1633:
1634: if (!width)
1.405 kia 1635: ParseCSSBorderBottomWidth (element, tsch, context, (char*)"medium", css, isHTML);
1.322 vatton 1636: if (!style)
1.405 kia 1637: ParseCSSBorderStyleBottom (element, tsch, context, (char*)"none", css, isHTML);
1.370 vatton 1638: if (!color && DoApply)
1639: {
1640: /* get the box color */
1641: best.typed_data.value = -1;
1642: best.typed_data.unit = UNIT_REL;
1643: best.typed_data.real = FALSE;
1644: TtaSetStylePresentation (PRBorderBottomColor, element, tsch, context, best);
1645: }
1.1 cvs 1646: return (cssRule);
1647: }
1648:
1649: /*----------------------------------------------------------------------
1.327 vatton 1650: ParseCSSBorderRight: parse a CSS BorderRight
1651: attribute string.
1.1 cvs 1652: ----------------------------------------------------------------------*/
1.79 cvs 1653: static char *ParseCSSBorderRight (Element element, PSchema tsch,
1.327 vatton 1654: PresentationContext context, char *cssRule,
1655: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1656: {
1.370 vatton 1657: PresentationValue best;
1658: char *ptr;
1659: ThotBool style, width, color;
1.43 cvs 1660:
1.82 cvs 1661: cssRule = SkipBlanksAndComments (cssRule);
1.322 vatton 1662: /* register given values */
1.337 vatton 1663: if (!strncmp (cssRule, "none", 4))
1.370 vatton 1664: style = width = color = TRUE;
1.337 vatton 1665: else
1.370 vatton 1666: style = width = color = FALSE;
1.301 vatton 1667: while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.43 cvs 1668: {
1669: ptr = cssRule;
1670: cssRule = ParseCSSBorderStyleRight (element, tsch, context, cssRule, css, isHTML);
1671: if (ptr == cssRule)
1.327 vatton 1672: {
1673: cssRule = ParseCSSBorderRightWidth (element, tsch, context, cssRule, css, isHTML);
1674: if (ptr == cssRule)
1.370 vatton 1675: {
1676: cssRule = ParseCSSBorderColorRight (element, tsch, context, cssRule, css, isHTML);
1677: if (ptr != cssRule)
1678: color = TRUE;
1679: }
1.327 vatton 1680: else
1681: width = TRUE;
1682: if (ptr == cssRule)
1683: {
1684: /* rule not found */
1685: cssRule = SkipValue ("Invalid border value", cssRule);
1686: return (cssRule);
1687: }
1688: }
1.322 vatton 1689: else
1.327 vatton 1690: style = TRUE;
1.82 cvs 1691: cssRule = SkipBlanksAndComments (cssRule);
1.43 cvs 1692: }
1.322 vatton 1693:
1694: if (!width)
1.405 kia 1695: ParseCSSBorderRightWidth (element, tsch, context, (char*)"medium", css, isHTML);
1.322 vatton 1696: if (!style)
1.405 kia 1697: ParseCSSBorderStyleRight (element, tsch, context, (char*)"none", css, isHTML);
1.370 vatton 1698: if (!color && DoApply)
1699: {
1700: /* get the box color */
1701: best.typed_data.value = -1;
1702: best.typed_data.unit = UNIT_REL;
1.374 vatton 1703: best.typed_data.real = FALSE;
1.370 vatton 1704: TtaSetStylePresentation (PRBorderRightColor, element, tsch, context, best);
1705: }
1.1 cvs 1706: return (cssRule);
1707: }
1708:
1709: /*----------------------------------------------------------------------
1.327 vatton 1710: ParseCSSBorder: parse a CSS border
1711: attribute string.
1.42 cvs 1712: ----------------------------------------------------------------------*/
1.79 cvs 1713: static char *ParseCSSBorder (Element element, PSchema tsch,
1.327 vatton 1714: PresentationContext context, char *cssRule,
1715: CSSInfoPtr css, ThotBool isHTML)
1.42 cvs 1716: {
1.79 cvs 1717: char *ptrT, *ptrR;
1.366 vatton 1718: int skippedNL, n;
1.42 cvs 1719:
1.82 cvs 1720: ptrT = SkipBlanksAndComments (cssRule);
1.366 vatton 1721: if (DoDialog)
1722: n = NumberOfValues (ptrT);
1723: if (DoDialog && n < 4)
1.42 cvs 1724: {
1.366 vatton 1725: // check if the border dialog must be updated
1726: All_sides = TRUE;
1727: ptrR = ParseCSSBorderTop (element, tsch, context, ptrT, css, isHTML);
1728: All_sides = FALSE;
1729: }
1730: else
1731: {
1732: /* First parse Border-Top */
1733: ptrR = ParseCSSBorderTop (element, tsch, context, ptrT, css, isHTML);
1734: ptrR = SkipBlanksAndComments (ptrR);
1735: if (*ptrR == ';' || *ptrR == '}' || *ptrR == EOS || *ptrR == ',')
1736: {
1737: skippedNL = NewLineSkipped;
1738: cssRule = ptrR;
1739: /* apply the Border-Top to all */
1740: ptrR = ParseCSSBorderRight (element, tsch, context, ptrT, css, isHTML);
1741: NewLineSkipped = skippedNL;
1742: ptrR = ParseCSSBorderBottom (element, tsch, context, ptrT, css, isHTML);
1743: NewLineSkipped = skippedNL;
1744: ptrR = ParseCSSBorderLeft (element, tsch, context, ptrT, css, isHTML);
1745: }
1.42 cvs 1746: }
1747: return (cssRule);
1748: }
1749:
1.218 vatton 1750:
1.42 cvs 1751: /*----------------------------------------------------------------------
1.327 vatton 1752: ParseCSSFloat: parse a CSS float attribute string
1.184 vatton 1753: ----------------------------------------------------------------------*/
1754: static char *ParseCSSFloat (Element element, PSchema tsch,
1.327 vatton 1755: PresentationContext context, char *cssRule,
1756: CSSInfoPtr css, ThotBool isHTML)
1.184 vatton 1757: {
1.257 vatton 1758: DisplayMode dispMode;
1.184 vatton 1759: PresentationValue pval;
1.288 vatton 1760: char *ptr = cssRule;
1.404 vatton 1761: ThotBool warn;
1.184 vatton 1762:
1.404 vatton 1763: // check if Amaya should report CSS warnings
1764: TtaGetEnvBoolean ("CSS_WARN", &warn);
1.184 vatton 1765: pval.typed_data.value = 0;
1.187 vatton 1766: pval.typed_data.unit = UNIT_BOX;
1.192 cvs 1767: pval.typed_data.real = FALSE;
1.190 vatton 1768: if (!strncasecmp (cssRule, "inherit", 7))
1769: {
1.293 quint 1770: pval.typed_data.unit = VALUE_INHERIT;
1.288 vatton 1771: cssRule += 7;
1.190 vatton 1772: }
1.184 vatton 1773: if (!strncasecmp (cssRule, "none", 4))
1.288 vatton 1774: {
1775: pval.typed_data.value = FloatNone;
1.293 quint 1776: cssRule += 4;
1.288 vatton 1777: }
1.184 vatton 1778: else if (!strncasecmp (cssRule, "left", 4))
1.288 vatton 1779: {
1780: pval.typed_data.value = FloatLeft;
1.293 quint 1781: cssRule += 4;
1.288 vatton 1782: }
1.184 vatton 1783: else if (!strncasecmp (cssRule, "right", 5))
1.288 vatton 1784: {
1785: pval.typed_data.value = FloatRight;
1.293 quint 1786: cssRule += 5;
1.288 vatton 1787: }
1.184 vatton 1788:
1.293 quint 1789: if (pval.typed_data.value == 0 && pval.typed_data.unit != VALUE_INHERIT)
1.359 quint 1790: {
1791: if (!strncasecmp (cssRule, "top", 3) ||
1792: !strncasecmp (cssRule, "bottom", 6) ||
1793: !strncasecmp (cssRule, "inside", 6) ||
1794: !strncasecmp (cssRule, "outside", 7) ||
1795: !strncasecmp (cssRule, "start", 5) ||
1796: !strncasecmp (cssRule, "end", 3))
1.404 vatton 1797: {
1798: if (warn)
1799: cssRule = SkipValue ("Warning: CSS3 value not supported", cssRule);
1800: else
1801: cssRule = SkipValue (NULL, cssRule);
1802: }
1.359 quint 1803: else
1804: cssRule = SkipValue ("Invalid float value", cssRule);
1805: }
1.184 vatton 1806: else
1807: {
1.366 vatton 1808: if (DoDialog)
1809: DisplayStyleValue ("float", ptr, cssRule);
1810: else if (DoApply)
1.327 vatton 1811: {
1812: dispMode = TtaGetDisplayMode (context->doc);
1813: if (dispMode != NoComputedDisplay)
1814: {
1815: /* force a redisplay of the whole document */
1816: TtaSetDisplayMode (context->doc, NoComputedDisplay);
1.257 vatton 1817: #ifdef AMAYA_DEBUG
1.327 vatton 1818: /*printf ("Force NoComputedDisplay doc=%d\n", context->doc);*/
1.257 vatton 1819: #endif /* AMAYA_DEBUG */
1.327 vatton 1820: }
1821: TtaSetStylePresentation (PRFloat, element, tsch, context, pval);
1822: }
1.288 vatton 1823: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid float value");
1.184 vatton 1824: }
1825: return (cssRule);
1826: }
1827:
1828: /*----------------------------------------------------------------------
1.327 vatton 1829: ParseCSSClear: parse a CSS clear rule
1.1 cvs 1830: ----------------------------------------------------------------------*/
1.79 cvs 1831: static char *ParseCSSClear (Element element, PSchema tsch,
1.327 vatton 1832: PresentationContext context, char *cssRule,
1833: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1834: {
1.184 vatton 1835: PresentationValue pval;
1.366 vatton 1836: char *start_value = cssRule;
1.184 vatton 1837:
1838: pval.typed_data.value = 0;
1.187 vatton 1839: pval.typed_data.unit = UNIT_BOX;
1.193 vatton 1840: pval.typed_data.real = FALSE;
1.190 vatton 1841: if (!strncasecmp (cssRule, "inherit", 7))
1.293 quint 1842: pval.typed_data.unit = VALUE_INHERIT;
1.184 vatton 1843: if (!strncasecmp (cssRule, "none", 4))
1844: pval.typed_data.value = ClearNone;
1845: else if (!strncasecmp (cssRule, "left", 4))
1846: pval.typed_data.value = ClearLeft;
1847: else if (!strncasecmp (cssRule, "right", 5))
1848: pval.typed_data.value = ClearRight;
1849: else if (!strncasecmp (cssRule, "both", 4))
1850: pval.typed_data.value = ClearBoth;
1851:
1.293 quint 1852: if (pval.typed_data.value == 0 && pval.typed_data.unit != VALUE_INHERIT)
1.295 vatton 1853: {
1854: cssRule = SkipValue ("Invalid clear value", cssRule);
1855: cssRule = SkipValue (NULL, cssRule);
1856: }
1.184 vatton 1857: else
1858: {
1.295 vatton 1859: cssRule = SkipValue (NULL, cssRule);
1.366 vatton 1860: if (DoDialog)
1861: DisplayStyleValue ("clear", start_value, cssRule);
1862: else if (DoApply)
1.327 vatton 1863: TtaSetStylePresentation (PRClear, element, tsch, context, pval);
1.184 vatton 1864: }
1865: return (cssRule);
1866: }
1867:
1868: /*----------------------------------------------------------------------
1.333 vatton 1869: ParseCSSVisibility: parse a CSS visibility attribute string
1870: ----------------------------------------------------------------------*/
1871: static char *ParseCSSVisibility(Element element, PSchema tsch,
1872: PresentationContext context, char *cssRule,
1873: CSSInfoPtr css, ThotBool isHTML)
1874: {
1875: PresentationValue pval;
1.366 vatton 1876: char *ptr;
1.333 vatton 1877:
1878: pval.typed_data.unit = UNIT_REL;
1879: pval.typed_data.real = FALSE;
1880: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 1881: ptr = cssRule;
1.333 vatton 1882: if (!strncasecmp (cssRule, "hidden", 6))
1883: {
1884: cssRule += 6;
1885: pval.typed_data.value = VsHidden;
1886: }
1887: else if (!strncasecmp (cssRule, "visible", 7))
1888: {
1889: cssRule += 7;
1890: pval.typed_data.value = VsVisible;
1891: }
1892: else if (!strncasecmp (cssRule, "collapse", 8))
1893: {
1894: cssRule += 8;
1895: pval.typed_data.value = VsCollapse;
1896: }
1897: else if (!strncasecmp (cssRule, "inherit", 7))
1898: {
1899: cssRule += 7;
1900: pval.typed_data.value = VsInherit;
1901: }
1902: else
1903: {
1904: cssRule = SkipValue ("Invalid visibility value", cssRule);
1905: return (cssRule);
1906: }
1.366 vatton 1907: if (DoDialog)
1908: DisplayStyleValue ("visibility", ptr, cssRule);
1909: else if (DoApply)
1.333 vatton 1910: TtaSetStylePresentation (PRVis, element, tsch, context, pval);
1911: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid visibility value");
1912: return (cssRule);
1913: }
1914:
1915:
1916: /*----------------------------------------------------------------------
1.327 vatton 1917: ParseCSSDisplay: parse a CSS display attribute string
1.1 cvs 1918: ----------------------------------------------------------------------*/
1.79 cvs 1919: static char *ParseCSSDisplay (Element element, PSchema tsch,
1.327 vatton 1920: PresentationContext context, char *cssRule,
1921: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1922: {
1.184 vatton 1923: PresentationValue pval;
1.366 vatton 1924: char *ptr;
1.404 vatton 1925: ThotBool warn;
1.1 cvs 1926:
1.184 vatton 1927: pval.typed_data.unit = UNIT_REL;
1928: pval.typed_data.real = FALSE;
1929: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 1930: ptr = cssRule;
1.184 vatton 1931: if (!strncasecmp (cssRule, "none", 4))
1.288 vatton 1932: {
1933: cssRule += 4;
1934: pval.typed_data.value = DisplayNone;
1935: }
1.277 quint 1936: else if (!strncasecmp (cssRule, "block", 5))
1.288 vatton 1937: {
1938: cssRule += 5;
1939: pval.typed_data.value = Block;
1940: }
1.303 vatton 1941: else if (!strncasecmp (cssRule, "inline-block", 12))
1942: {
1943: cssRule += 12;
1944: pval.typed_data.value = InlineBlock;
1945: }
1.277 quint 1946: else if (!strncasecmp (cssRule, "inline", 6))
1.288 vatton 1947: {
1948: cssRule += 6;
1949: pval.typed_data.value = Inline;
1950: }
1.277 quint 1951: else if (!strncasecmp (cssRule, "list-item", 9))
1.288 vatton 1952: {
1953: cssRule += 9;
1954: pval.typed_data.value = ListItem;
1955: }
1.277 quint 1956: else if (!strncasecmp (cssRule, "run-in", 6))
1.288 vatton 1957: {
1958: cssRule += 6;
1959: pval.typed_data.value = RunIn;
1960: }
1.293 quint 1961: else if (!strncasecmp (cssRule, "inherit", 7))
1962: {
1963: cssRule += 7;
1964: pval.typed_data.unit = VALUE_INHERIT;
1965: }
1.277 quint 1966: else
1.184 vatton 1967: {
1.404 vatton 1968: TtaGetEnvBoolean ("CSS_WARN", &warn);
1969: if (warn &&
1970: strncasecmp (cssRule, "table-row-group", 15) &&
1.327 vatton 1971: strncasecmp (cssRule, "table-column-group", 18) &&
1972: strncasecmp (cssRule, "table-header-group", 5) &&
1973: strncasecmp (cssRule, "table-footer-group", 6) &&
1974: strncasecmp (cssRule, "table-row", 9) &&
1975: strncasecmp (cssRule, "table-column", 12) &&
1976: strncasecmp (cssRule, "table-cell", 10) &&
1977: strncasecmp (cssRule, "table-caption", 13) &&
1978: strncasecmp (cssRule, "inline-table", 12) &&
1979: strncasecmp (cssRule, "table", 5))
1980: cssRule = SkipValue ("Display value not supported", cssRule);
1.281 quint 1981: else
1.327 vatton 1982: cssRule = SkipWord (cssRule);
1.277 quint 1983: return (cssRule);
1.184 vatton 1984: }
1.277 quint 1985:
1.366 vatton 1986: if (DoDialog)
1987: DisplayStyleValue ("display", ptr, cssRule);
1988: else if (DoApply)
1.295 vatton 1989: TtaSetStylePresentation (PRDisplay, element, tsch, context, pval);
1.288 vatton 1990: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid display value");
1.1 cvs 1991: return (cssRule);
1992: }
1993:
1994: /*----------------------------------------------------------------------
1.327 vatton 1995: ParseCSSLetterSpacing: parse a CSS letter-spacing
1996: attribute string.
1.1 cvs 1997: ----------------------------------------------------------------------*/
1.79 cvs 1998: static char *ParseCSSLetterSpacing (Element element, PSchema tsch,
1.327 vatton 1999: PresentationContext context, char *cssRule,
2000: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2001: {
1.366 vatton 2002: char *start_value = cssRule;
2003:
1.168 vatton 2004: cssRule = SkipValue (NULL, cssRule);
1.366 vatton 2005: if (DoDialog)
2006: DisplayStyleValue ("letter-spacing", start_value, cssRule);
1.1 cvs 2007: return (cssRule);
2008: }
2009:
2010: /*----------------------------------------------------------------------
1.436 ! quint 2011: ParseCounterStyle: parse a CSS counter style.
1.1 cvs 2012: ----------------------------------------------------------------------*/
1.436 ! quint 2013: static char *ParseCounterStyle (char *cssRule, PresentationValue *pval,
! 2014: char *start_value)
1.1 cvs 2015: {
1.436 ! quint 2016: (*pval).typed_data.unit = UNIT_REL;
! 2017: (*pval).typed_data.real = FALSE;
1.281 quint 2018: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 2019: start_value = cssRule;
1.281 quint 2020: if (!strncasecmp (cssRule, "disc", 4))
1.288 vatton 2021: {
2022: cssRule += 4;
1.436 ! quint 2023: (*pval).typed_data.value = Disc;
1.288 vatton 2024: }
1.281 quint 2025: else if (!strncasecmp (cssRule, "circle", 6))
1.293 quint 2026: {
1.288 vatton 2027: cssRule += 6;
1.436 ! quint 2028: (*pval).typed_data.value = Circle;
1.293 quint 2029: }
1.281 quint 2030: else if (!strncasecmp (cssRule, "square", 6))
1.293 quint 2031: {
1.288 vatton 2032: cssRule += 6;
1.436 ! quint 2033: (*pval).typed_data.value = Square;
1.293 quint 2034: }
1.283 quint 2035: else if (!strncasecmp (cssRule, "decimal-leading-zero", 20))
1.293 quint 2036: {
1.288 vatton 2037: cssRule += 20;
1.436 ! quint 2038: (*pval).typed_data.value = DecimalLeadingZero;
1.293 quint 2039: }
1.281 quint 2040: else if (!strncasecmp (cssRule, "decimal", 7))
1.293 quint 2041: {
1.288 vatton 2042: cssRule += 7;
1.436 ! quint 2043: (*pval).typed_data.value = Decimal;
1.293 quint 2044: }
1.281 quint 2045: else if (!strncasecmp (cssRule, "lower-roman", 11))
1.293 quint 2046: {
1.288 vatton 2047: cssRule += 11;
1.436 ! quint 2048: (*pval).typed_data.value = LowerRoman;
1.293 quint 2049: }
1.281 quint 2050: else if (!strncasecmp (cssRule, "upper-roman", 11))
1.293 quint 2051: {
1.288 vatton 2052: cssRule += 11;
1.436 ! quint 2053: (*pval).typed_data.value = UpperRoman;
1.293 quint 2054: }
1.281 quint 2055: else if (!strncasecmp (cssRule, "lower-greek", 11))
1.293 quint 2056: {
1.288 vatton 2057: cssRule += 11;
1.436 ! quint 2058: (*pval).typed_data.value = LowerGreek;
1.293 quint 2059: }
1.281 quint 2060: else if (!strncasecmp (cssRule, "lower-latin", 11))
1.293 quint 2061: {
1.288 vatton 2062: cssRule += 11;
1.436 ! quint 2063: (*pval).typed_data.value = LowerLatin;
1.293 quint 2064: }
1.281 quint 2065: else if (!strncasecmp (cssRule, "lower-alpha", 11))
1.293 quint 2066: {
1.288 vatton 2067: cssRule += 11;
1.436 ! quint 2068: (*pval).typed_data.value = LowerLatin;
1.293 quint 2069: }
1.281 quint 2070: else if (!strncasecmp (cssRule, "upper-latin", 11))
1.293 quint 2071: {
1.288 vatton 2072: cssRule += 11;
1.436 ! quint 2073: (*pval).typed_data.value = UpperLatin;
1.293 quint 2074: }
1.281 quint 2075: else if (!strncasecmp (cssRule, "upper-alpha", 11))
1.293 quint 2076: {
1.288 vatton 2077: cssRule += 11;
1.436 ! quint 2078: (*pval).typed_data.value = UpperLatin;
1.293 quint 2079: }
1.281 quint 2080: else if (!strncasecmp (cssRule, "armenian", 8))
1.293 quint 2081: {
1.288 vatton 2082: cssRule += 8;
1.436 ! quint 2083: (*pval).typed_data.value = Decimal;
1.293 quint 2084: }
1.281 quint 2085: else if (!strncasecmp (cssRule, "georgian", 8))
1.293 quint 2086: {
1.288 vatton 2087: cssRule += 8;
1.436 ! quint 2088: (*pval).typed_data.value = Decimal;
1.293 quint 2089: }
1.281 quint 2090: else if (!strncasecmp (cssRule, "none", 4))
1.293 quint 2091: {
1.288 vatton 2092: cssRule += 4;
1.436 ! quint 2093: (*pval).typed_data.value = ListStyleTypeNone;
1.293 quint 2094: }
1.281 quint 2095: else if (!strncasecmp (cssRule, "inherit", 7))
2096: {
1.293 quint 2097: cssRule += 7;
1.436 ! quint 2098: (*pval).typed_data.unit = VALUE_INHERIT;
1.281 quint 2099: }
2100: else
1.436 ! quint 2101: cssRule = SkipValue ("Invalid list-style-type value", cssRule);
! 2102: return (cssRule);
! 2103: }
! 2104:
! 2105: /*----------------------------------------------------------------------
! 2106: ParseACSSListStyleType: parse a CSS list-style-type
! 2107: attribute string.
! 2108: ----------------------------------------------------------------------*/
! 2109: static char *ParseACSSListStyleType (Element element, PSchema tsch,
! 2110: PresentationContext context, char *cssRule,
! 2111: CSSInfoPtr css, ThotBool isHTML)
! 2112: {
! 2113: PresentationValue pval;
! 2114: char *start_value;
1.281 quint 2115:
1.436 ! quint 2116: cssRule = ParseCounterStyle (cssRule, &pval, start_value);
1.366 vatton 2117: if (DoDialog)
2118: DisplayStyleValue ("list-style-type", start_value, cssRule);
2119: else if (DoApply)
1.295 vatton 2120: TtaSetStylePresentation (PRListStyleType, element, tsch, context, pval);
1.318 vatton 2121: return (cssRule);
2122: }
2123:
2124: /*----------------------------------------------------------------------
1.327 vatton 2125: ParseCSSListStyleType: parse a CSS list-style-type
2126: attribute string.
1.318 vatton 2127: ----------------------------------------------------------------------*/
2128: static char *ParseCSSListStyleType (Element element, PSchema tsch,
1.327 vatton 2129: PresentationContext context, char *cssRule,
2130: CSSInfoPtr css, ThotBool isHTML)
1.318 vatton 2131: {
2132: char *ptr = cssRule;
2133: cssRule = ParseACSSListStyleType (element, tsch, context, cssRule, css,
1.327 vatton 2134: isHTML);
1.288 vatton 2135: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid list-style-type value");
1.318 vatton 2136: return cssRule;
1.1 cvs 2137: }
2138:
2139: /*----------------------------------------------------------------------
1.281 quint 2140: ParseCSSUrl: parse an URL
1.375 vatton 2141: Parse the url content (don't start with "url")
2142: Return the next pointer in the CSS string
2143: If a correct URL is found, it's returned in url (this string must
2144: be freed)
1.281 quint 2145: ----------------------------------------------------------------------*/
2146: static char *ParseCSSUrl (char *cssRule, char **url)
2147: {
2148: char saved;
2149: char *base, *ptr;
2150:
2151: cssRule = SkipBlanksAndComments (cssRule);
2152: saved = *cssRule;
2153: if (*cssRule == '(')
2154: {
2155: cssRule++;
2156: cssRule = SkipBlanksAndComments (cssRule);
2157: /*** Escaped quotes are not handled. See function SkipQuotedString */
2158: if (*cssRule == '"')
1.327 vatton 2159: {
2160: cssRule++;
2161: base = cssRule;
2162: while (*cssRule != EOS && *cssRule != '"')
2163: cssRule++;
2164: }
1.281 quint 2165: else if (*cssRule == '\'')
1.327 vatton 2166: {
2167: cssRule++;
2168: base = cssRule;
2169: while (*cssRule != EOS && *cssRule != '\'')
2170: cssRule++;
2171: }
1.281 quint 2172: else
1.327 vatton 2173: {
2174: base = cssRule;
2175: while (*cssRule != EOS && *cssRule != ')')
2176: cssRule++;
2177: }
1.281 quint 2178: /* keep the current position */
2179: ptr = cssRule;
1.402 vatton 2180: if (saved == '(')
1.327 vatton 2181: {
2182: /* remove extra spaces */
2183: if (cssRule[-1] == SPACE)
2184: {
2185: *cssRule = SPACE;
2186: cssRule--;
2187: while (cssRule[-1] == SPACE)
2188: cssRule--;
2189: }
2190: }
1.281 quint 2191: saved = *cssRule;
2192: *cssRule = EOS;
2193: *url = TtaStrdup (base);
2194: *cssRule = saved;
2195: if (saved == '"' || saved == '\'')
1.327 vatton 2196: /* we need to skip the quote character and possible spaces */
2197: {
2198: cssRule++;
2199: cssRule = SkipBlanksAndComments (cssRule);
2200: }
1.281 quint 2201: else
1.327 vatton 2202: cssRule = ptr;
1.281 quint 2203: }
2204: cssRule++;
2205: return cssRule;
2206: }
2207:
2208: /*----------------------------------------------------------------------
1.302 quint 2209: ParseCSSImageCallback: Callback called asynchronously by
2210: FetchImage when a CSS image (background-image or list-style-image)
2211: has been fetched.
2212: ----------------------------------------------------------------------*/
2213: void ParseCSSImageCallback (Document doc, Element element, char *file,
1.327 vatton 2214: void *extra, ThotBool isnew)
1.302 quint 2215: {
2216: DisplayMode dispMode = DisplayImmediately;
2217: CSSImageCallbackPtr callblock;
2218: Element el;
2219: PSchema tsch;
1.401 vatton 2220: Document redisplaydoc;
2221: PInfoPtr pInfo = NULL;
1.302 quint 2222: CSSInfoPtr css;
2223: PresentationContext ctxt;
2224: PresentationValue image;
2225: PresentationValue value;
1.400 vatton 2226: ThotBool found;
1.302 quint 2227:
2228: callblock = (CSSImageCallbackPtr) extra;
2229: if (callblock == NULL)
2230: return;
2231:
1.400 vatton 2232: css = callblock->css;
1.302 quint 2233: el = callblock->el;
2234: tsch = callblock->tsch;
2235: ctxt = callblock->ctxt;
1.401 vatton 2236: redisplaydoc = ctxt->doc;
1.302 quint 2237: if (doc == 0 && !isnew)
2238: /* apply to the current document only */
1.401 vatton 2239: doc = redisplaydoc;
1.302 quint 2240: if (doc)
1.401 vatton 2241: redisplaydoc = doc;
1.302 quint 2242: else
2243: {
2244: /* check if the CSS still exists */
2245: css = CSSList;
2246: while (css && css != callblock->css)
1.327 vatton 2247: css = css->NextCSS;
1.302 quint 2248: if (css == NULL)
1.400 vatton 2249: // the presentation schema doesn't exist anymore
1.327 vatton 2250: tsch = NULL;
1.302 quint 2251: }
1.400 vatton 2252:
1.401 vatton 2253: if (tsch && css && ctxt && redisplaydoc)
1.400 vatton 2254: {
2255: // check if the presentation schema is still there
1.401 vatton 2256: pInfo = css->infos[redisplaydoc];
2257: if (pInfo == NULL && DocumentURLs[redisplaydoc] == NULL)
2258: {
2259: // the redisplaydoc was probably an object
2260: while (redisplaydoc > 0 && pInfo == 0)
2261: pInfo = css->infos[--redisplaydoc];
2262: if (redisplaydoc)
2263: ctxt->doc = redisplaydoc;
2264: }
2265:
1.400 vatton 2266: found = FALSE;
2267: while (!found && pInfo)
2268: {
2269: found = (pInfo->PiSchemas && tsch == pInfo->PiSchemas->PiPSchema);
2270: pInfo = pInfo->PiNext;
2271: }
2272: if (!found)
2273: tsch = NULL;
2274: }
2275:
1.302 quint 2276: if (el || tsch)
2277: {
2278: /* Ok the image was fetched */
2279: image.typed_data.unit = UNIT_REL;
2280: image.typed_data.real = FALSE;
2281: image.pointer = file;
2282: TtaSetStylePresentation (callblock->ruleType, el, tsch, ctxt, image);
2283:
2284: if (callblock->ruleType == PRBackgroundPicture)
1.327 vatton 2285: /* enforce the showbox */
2286: {
2287: value.typed_data.value = 1;
2288: value.typed_data.unit = UNIT_REL;
2289: value.typed_data.real = FALSE;
2290: TtaSetStylePresentation (PRShowBox, el, tsch, ctxt, value);
2291: }
1.302 quint 2292: /* check if the context can be freed */
2293: ctxt->uses -= 1;
2294: if (ctxt->uses == 0)
1.327 vatton 2295: /* no other image loading */
2296: TtaFreeMemory (ctxt);
1.302 quint 2297: }
2298:
2299: TtaFreeMemory (callblock);
1.330 cvs 2300: if (css)
2301: RedisplayImages--;
1.401 vatton 2302: if (redisplaydoc &&
2303: /* check if all background images are now loaded */
2304: (css == NULL || (pInfo && Style_parsing == 0 && RedisplayImages == 0)))
2305: {
2306: /* don't manage a document used by make book */
2307: if (DocumentMeta[redisplaydoc] == NULL ||
2308: DocumentMeta[redisplaydoc]->method != CE_MAKEBOOK)
1.327 vatton 2309: {
2310: /* Change the Display Mode to take into account the new
2311: presentation */
1.401 vatton 2312: dispMode = TtaGetDisplayMode (redisplaydoc);
1.313 vatton 2313: /* force the redisplay of this box */
1.435 vatton 2314: if (dispMode == DisplayImmediately)
2315: TtaSetDisplayMode (redisplaydoc, NoComputedDisplay);
1.401 vatton 2316: TtaSetDisplayMode (redisplaydoc, dispMode);
1.327 vatton 2317: }
1.330 cvs 2318: RedisplayBGImage = FALSE;
1.302 quint 2319: }
1.310 vatton 2320: else
1.328 vatton 2321: RedisplayBGImage = TRUE;
1.302 quint 2322: }
2323:
2324: /*----------------------------------------------------------------------
2325: SetCSSImage fetch the image referred by a background-image or a
2326: list-style-image property.
2327: ----------------------------------------------------------------------*/
2328: static char *SetCSSImage (Element element, PSchema tsch,
1.327 vatton 2329: PresentationContext ctxt, char *cssRule,
2330: CSSInfoPtr css, unsigned int ruleType)
1.302 quint 2331: {
2332: CSSImageCallbackPtr callblock;
2333: Element el;
1.304 cvs 2334: PresentationValue image;
1.366 vatton 2335: char *url, *ptr;
1.302 quint 2336: char *bg_image;
2337: char tempname[MAX_LENGTH];
2338: char imgname[MAX_LENGTH];
2339:
2340: if (element)
2341: el = element;
2342: else
2343: /* default element for FetchImage */
2344: el = TtaGetMainRoot (ctxt->doc);
2345: url = NULL;
1.370 vatton 2346: image.typed_data.real = FALSE;
1.302 quint 2347: cssRule = ParseCSSUrl (cssRule, &url);
1.414 vatton 2348: if (strlen (url) > MAX_LENGTH / 4)
2349: url[MAX_LENGTH / 4] = EOS;
1.366 vatton 2350: ptr = cssRule;
1.302 quint 2351: if (ctxt->destroy)
2352: {
2353: /* remove the background image PRule */
2354: image.pointer = NULL;
1.366 vatton 2355: TtaSetStylePresentation (ruleType, element, tsch, ctxt, image);
1.302 quint 2356: }
1.366 vatton 2357: else if (url)
1.302 quint 2358: {
1.366 vatton 2359: if (css && css->url)
2360: /* the image concerns a CSS file */
2361: NormalizeURL (url, 0, tempname, imgname, css->url);
2362: else
2363: /* the image concerns a style element */
2364: NormalizeURL (url, ctxt->doc, tempname, imgname, NULL);
2365: if (DoDialog)
2366: {
2367: if (ruleType == PRBackgroundPicture)
2368: DisplayStyleValue ("background-image", tempname, &tempname[MAX_LENGTH-1]);
2369: else if (ruleType == PRListStyleImage)
2370: DisplayStyleValue ("list-style-image", tempname, &tempname[MAX_LENGTH-1]);
2371: else if (ruleType == PRContentURL)
2372: DisplayStyleValue ("", ptr, cssRule);
2373: }
2374: else if (DoApply)
2375: {
2376: bg_image = TtaGetEnvString ("ENABLE_BG_IMAGES");
2377: if (bg_image == NULL || !strcasecmp (bg_image, "yes"))
2378: /* background images are enabled */
2379: {
2380: callblock = (CSSImageCallbackPtr) TtaGetMemory (sizeof (CSSImageCallbackBlock));
2381: if (callblock)
2382: {
2383: callblock->el = element;
2384: callblock->tsch = tsch;
2385: callblock->css = css;
2386: callblock->ctxt = ctxt;
2387: callblock->ruleType = ruleType;
2388: /* new use of the context */
2389: ctxt->uses += 1;
2390: /* check if the image url is related to an external CSS */
2391: if (css)
2392: {
2393: /* fetch and display background image of element */
2394: if (FetchImage (0, el, tempname, AMAYA_LOAD_IMAGE,
2395: ParseCSSImageCallback, callblock))
2396: RedisplayImages++;
2397: }
1.327 vatton 2398: else
1.366 vatton 2399: FetchImage (ctxt->doc, el, url, AMAYA_LOAD_IMAGE,
2400: ParseCSSImageCallback, callblock);
1.327 vatton 2401: }
2402: }
2403: }
1.366 vatton 2404: TtaFreeMemory (url);
1.302 quint 2405: }
2406: return (cssRule);
2407: }
2408:
2409: /*----------------------------------------------------------------------
1.327 vatton 2410: ParseACSSListStyleImage: parse a CSS list-style-image
2411: attribute string.
1.1 cvs 2412: ----------------------------------------------------------------------*/
1.318 vatton 2413: static char *ParseACSSListStyleImage (Element element, PSchema tsch,
1.327 vatton 2414: PresentationContext ctxt,
2415: char *cssRule, CSSInfoPtr css,
2416: ThotBool isHTML)
1.1 cvs 2417: {
1.288 vatton 2418: char *url;
1.366 vatton 2419: char *start_value;
1.293 quint 2420: PresentationValue pval;
1.281 quint 2421:
1.293 quint 2422: pval.typed_data.unit = UNIT_REL;
2423: pval.typed_data.real = FALSE;
1.281 quint 2424: url = NULL;
2425: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 2426: start_value = cssRule;
1.281 quint 2427: if (!strncasecmp (cssRule, "none", 4))
2428: {
2429: cssRule += 4;
1.302 quint 2430: pval.typed_data.value = 0;
1.366 vatton 2431: if (DoDialog)
2432: DisplayStyleValue ("list-style-image", start_value, cssRule);
2433: else if (DoApply)
1.327 vatton 2434: TtaSetStylePresentation (PRListStyleImage, element, tsch, ctxt, pval);
1.281 quint 2435: }
2436: else if (!strncasecmp (cssRule, "url", 3))
2437: {
2438: cssRule += 3;
1.302 quint 2439: cssRule = SetCSSImage (element, tsch, ctxt, cssRule, css,
1.327 vatton 2440: PRListStyleImage);
1.281 quint 2441: }
2442: else if (!strncasecmp (cssRule, "inherit", 7))
1.288 vatton 2443: {
2444: cssRule += 7;
1.293 quint 2445: pval.typed_data.unit = VALUE_INHERIT;
1.366 vatton 2446: if (DoDialog)
2447: DisplayStyleValue ("list-style-image", start_value, cssRule);
2448: else if (DoApply)
1.327 vatton 2449: TtaSetStylePresentation (PRListStyleImage, element, tsch, ctxt, pval);
2450: }
1.281 quint 2451: else
1.295 vatton 2452: cssRule = SkipValue ("Invalid list-style-image value", cssRule);
1.1 cvs 2453: return (cssRule);
2454: }
2455:
2456: /*----------------------------------------------------------------------
1.327 vatton 2457: ParseCSSListStyleImage: parse a CSS list-style-image
2458: attribute string.
1.318 vatton 2459: ----------------------------------------------------------------------*/
2460: static char *ParseCSSListStyleImage (Element element, PSchema tsch,
1.327 vatton 2461: PresentationContext ctxt,
2462: char *cssRule, CSSInfoPtr css,
2463: ThotBool isHTML)
1.318 vatton 2464: {
2465: char *ptr = cssRule;
2466: cssRule = ParseACSSListStyleImage (element, tsch, ctxt, cssRule, css,
1.327 vatton 2467: isHTML);
1.318 vatton 2468: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid list-style-image value");
2469: return cssRule;
2470: }
2471:
2472: /*----------------------------------------------------------------------
1.327 vatton 2473: ParseACSSListStylePosition: parse a CSS list-style-position
2474: attribute string.
1.1 cvs 2475: ----------------------------------------------------------------------*/
1.318 vatton 2476: static char *ParseACSSListStylePosition (Element element, PSchema tsch,
1.327 vatton 2477: PresentationContext context,
2478: char *cssRule, CSSInfoPtr css,
2479: ThotBool isHTML)
1.1 cvs 2480: {
1.281 quint 2481: PresentationValue pval;
1.366 vatton 2482: char *start_value;
1.281 quint 2483:
2484: pval.typed_data.unit = UNIT_REL;
2485: pval.typed_data.real = FALSE;
2486: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 2487: start_value = cssRule;
1.281 quint 2488: if (!strncasecmp (cssRule, "inside", 6))
1.288 vatton 2489: {
2490: pval.typed_data.value = Inside;
2491: cssRule += 6;
2492: }
1.281 quint 2493: else if (!strncasecmp (cssRule, "outside", 7))
1.288 vatton 2494: {
2495: pval.typed_data.value = Outside;
2496: cssRule += 7;
2497: }
1.293 quint 2498: else if (!strncasecmp (cssRule, "inherit", 7))
2499: {
2500: pval.typed_data.unit = VALUE_INHERIT;
2501: cssRule += 7;
2502: }
1.281 quint 2503: else
2504: {
1.293 quint 2505: cssRule = SkipValue ("Invalid list-style-position value", cssRule);
1.281 quint 2506: return (cssRule);
2507: }
1.293 quint 2508:
1.366 vatton 2509: if (DoDialog)
2510: DisplayStyleValue ("list-style-position", start_value, cssRule);
2511: else if (DoApply)
1.295 vatton 2512: TtaSetStylePresentation (PRListStylePosition, element, tsch, context, pval);
1.327 vatton 2513: return (cssRule);
1.318 vatton 2514: }
2515:
2516: /*----------------------------------------------------------------------
1.327 vatton 2517: ParseCSSListStylePosition: parse a CSS list-style-position
2518: attribute string.
1.318 vatton 2519: ----------------------------------------------------------------------*/
2520: static char *ParseCSSListStylePosition (Element element, PSchema tsch,
1.327 vatton 2521: PresentationContext context,
2522: char *cssRule, CSSInfoPtr css,
2523: ThotBool isHTML)
1.318 vatton 2524: {
2525: char *ptr = cssRule;
2526: cssRule = ParseACSSListStylePosition (element, tsch, context, cssRule, css,
1.327 vatton 2527: isHTML);
1.288 vatton 2528: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid list-style-position value");
1.318 vatton 2529: return cssRule;
1.1 cvs 2530: }
2531:
2532: /*----------------------------------------------------------------------
1.327 vatton 2533: ParseCSSListStyle: parse a CSS list-style value string.
1.1 cvs 2534: ----------------------------------------------------------------------*/
1.79 cvs 2535: static char *ParseCSSListStyle (Element element, PSchema tsch,
1.327 vatton 2536: PresentationContext ctxt, char *cssRule,
2537: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2538: {
1.318 vatton 2539: char *ptr = cssRule;
2540: int skippedNL;
1.281 quint 2541:
2542: cssRule = SkipBlanksAndComments (cssRule);
1.301 vatton 2543: while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.281 quint 2544: {
1.316 quint 2545: skippedNL = NewLineSkipped;
1.281 quint 2546: /* perhaps a list-style-image */
2547: if (!strncasecmp (cssRule, "url", 3))
1.327 vatton 2548: cssRule = ParseACSSListStyleImage (element, tsch, ctxt, cssRule, css,
2549: isHTML);
1.281 quint 2550: /* perhaps a list-style-position */
2551: else if (!strncasecmp (cssRule, "inside", 6) ||
2552: !strncasecmp (cssRule, "outside", 7))
1.327 vatton 2553: cssRule = ParseACSSListStylePosition (element, tsch, ctxt, cssRule,
2554: css, isHTML);
1.281 quint 2555: /* perhaps a list-style-type */
2556: else if (!strncasecmp (cssRule, "disc", 4) ||
1.327 vatton 2557: !strncasecmp (cssRule, "circle", 6) ||
2558: !strncasecmp (cssRule, "square", 6) ||
2559: !strncasecmp (cssRule, "decimal", 7) ||
2560: !strncasecmp (cssRule, "decimal-leading-zero", 20) ||
2561: !strncasecmp (cssRule, "lower-roman", 11) ||
2562: !strncasecmp (cssRule, "upper-roman", 11) ||
2563: !strncasecmp (cssRule, "lower-greek", 11) ||
2564: !strncasecmp (cssRule, "lower-latin", 11) ||
2565: !strncasecmp (cssRule, "lower-alpha", 11) ||
2566: !strncasecmp (cssRule, "upper-latin", 11) ||
2567: !strncasecmp (cssRule, "upper-alpha", 11) ||
2568: !strncasecmp (cssRule, "armenian", 8) ||
2569: !strncasecmp (cssRule, "georgian", 8) ||
2570: !strncasecmp (cssRule, "none", 4) ||
2571: !strncasecmp (cssRule, "inherit", 7))
2572: cssRule = ParseACSSListStyleType (element, tsch, ctxt, cssRule, css,
2573: isHTML);
1.281 quint 2574: else
1.327 vatton 2575: {
2576: NewLineSkipped = skippedNL;
2577: /* rule not found */
2578: cssRule = SkipProperty (cssRule, FALSE);
2579: }
1.281 quint 2580: cssRule = SkipBlanksAndComments (cssRule);
2581: }
1.318 vatton 2582: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid list-style value");
1.1 cvs 2583: return (cssRule);
2584: }
2585:
2586: /*----------------------------------------------------------------------
1.327 vatton 2587: ParseCSSTextAlign: parse a CSS text-align
2588: attribute string.
1.1 cvs 2589: ----------------------------------------------------------------------*/
1.79 cvs 2590: static char *ParseCSSTextAlign (Element element, PSchema tsch,
1.327 vatton 2591: PresentationContext context, char *cssRule,
2592: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2593: {
1.366 vatton 2594: char *ptr;
1.327 vatton 2595: PresentationValue align;
2596:
2597: align.typed_data.value = 0;
2598: align.typed_data.unit = UNIT_REL;
2599: align.typed_data.real = FALSE;
2600:
2601: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 2602: ptr = cssRule;
1.327 vatton 2603: if (!strncasecmp (cssRule, "left", 4))
2604: {
2605: align.typed_data.value = AdjustLeft;
2606: cssRule += 4;
2607: }
2608: else if (!strncasecmp (cssRule, "right", 5))
2609: {
2610: align.typed_data.value = AdjustRight;
2611: cssRule += 5;
2612: }
2613: else if (!strncasecmp (cssRule, "center", 6))
2614: {
2615: align.typed_data.value = Centered;
2616: cssRule += 6;
2617: }
2618: else if (!strncasecmp (cssRule, "justify", 7))
2619: {
2620: align.typed_data.value = Justify;
2621: cssRule += 7;
2622: }
2623: else
2624: {
2625: cssRule = SkipValue ("Invalid text-align value", cssRule);
2626: return (cssRule);
2627: }
1.1 cvs 2628:
1.327 vatton 2629: /*
2630: * install the new presentation.
2631: */
1.366 vatton 2632: if (align.typed_data.value)
2633: {
2634: if (DoDialog)
2635: DisplayStyleValue ("text-align", ptr, cssRule);
2636: else if (DoApply)
2637: TtaSetStylePresentation (PRAdjust, element, tsch, context, align);
2638: }
1.327 vatton 2639: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid text-align value");
2640: return (cssRule);
1.1 cvs 2641: }
2642:
2643: /*----------------------------------------------------------------------
1.243 quint 2644: ParseCSSTextAnchor: parse a CSS text-anchor property (SVG property)
2645: We use the Thot Adjust PRule to represent the text-anchor property
2646: for CSS 1.0, as Adjust is not used otherwise in this context.
2647: ----------------------------------------------------------------------*/
2648: static char *ParseCSSTextAnchor (Element element, PSchema tsch,
1.327 vatton 2649: PresentationContext context, char *cssRule,
2650: CSSInfoPtr css, ThotBool isHTML)
1.243 quint 2651: {
1.327 vatton 2652: PresentationValue align;
1.366 vatton 2653: char *ptr;
1.327 vatton 2654:
2655: align.typed_data.value = 0;
2656: align.typed_data.unit = UNIT_REL;
2657: align.typed_data.real = FALSE;
1.243 quint 2658:
1.327 vatton 2659: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 2660: ptr = cssRule;
1.327 vatton 2661: if (!strncasecmp (cssRule, "start", 5))
2662: {
2663: align.typed_data.value = AdjustLeft;
2664: cssRule += 5;
2665: }
2666: else if (!strncasecmp (cssRule, "middle", 6))
2667: {
2668: align.typed_data.value = Centered;
2669: cssRule += 6;
2670: }
2671: else if (!strncasecmp (cssRule, "end", 3))
2672: {
2673: align.typed_data.value = AdjustRight;
2674: cssRule += 3;
2675: }
2676: else if (!strncasecmp (cssRule, "inherit", 7))
2677: {
2678: align.typed_data.unit = VALUE_INHERIT;
2679: cssRule += 7;
2680: }
2681: else
2682: {
2683: cssRule = SkipValue ("Invalid text-anchor value", cssRule);
1.295 vatton 2684: return (cssRule);
1.327 vatton 2685: }
1.243 quint 2686:
1.327 vatton 2687: /*
2688: * install the new presentation.
2689: */
1.366 vatton 2690: if (align.typed_data.value || align.typed_data.unit == VALUE_INHERIT)
2691: {
2692: if (DoDialog)
2693: DisplayStyleValue ("text-anchor", ptr, cssRule);
2694: else if (DoApply)
2695: TtaSetStylePresentation (PRAdjust, element, tsch, context, align);
2696: }
1.327 vatton 2697: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid text-anchor value");
2698: return (cssRule);
1.243 quint 2699: }
2700:
2701: /*----------------------------------------------------------------------
1.327 vatton 2702: ParseCSSDirection: parse a CSS direction property
1.112 quint 2703: ----------------------------------------------------------------------*/
2704: static char *ParseCSSDirection (Element element, PSchema tsch,
1.327 vatton 2705: PresentationContext context, char *cssRule,
2706: CSSInfoPtr css, ThotBool isHTML)
1.112 quint 2707: {
1.327 vatton 2708: PresentationValue direction;
1.366 vatton 2709: char *ptr;
1.327 vatton 2710:
2711: direction.typed_data.value = 0;
2712: direction.typed_data.unit = UNIT_REL;
2713: direction.typed_data.real = FALSE;
2714:
2715: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 2716: ptr = cssRule;
1.327 vatton 2717: if (!strncasecmp (cssRule, "ltr", 3))
2718: {
2719: direction.typed_data.value = LeftToRight;
2720: cssRule += 3;
2721: }
2722: else if (!strncasecmp (cssRule, "rtl", 3))
2723: {
2724: direction.typed_data.value = RightToLeft;
2725: cssRule += 3;
2726: }
2727: else if (!strncasecmp (cssRule, "inherit", 7))
2728: {
2729: direction.typed_data.unit = VALUE_INHERIT;
2730: cssRule += 7;
2731: }
2732: else
2733: {
2734: cssRule = SkipValue ("Invalid direction value", cssRule);
2735: return (cssRule);
2736: }
1.112 quint 2737:
1.327 vatton 2738: /*
2739: * install the new presentation.
2740: */
1.366 vatton 2741: if (direction.typed_data.value || direction.typed_data.unit == VALUE_INHERIT)
2742: {
2743: if (DoDialog)
2744: DisplayStyleValue ("direction", ptr, cssRule);
2745: else if (DoApply)
2746: TtaSetStylePresentation (PRDirection, element, tsch, context, direction);
2747: }
1.327 vatton 2748: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid direction value");
2749: return (cssRule);
1.112 quint 2750: }
2751:
2752: /*----------------------------------------------------------------------
1.327 vatton 2753: ParseCSSUnicodeBidi: parse a CSS unicode-bidi property
1.113 quint 2754: ----------------------------------------------------------------------*/
2755: static char *ParseCSSUnicodeBidi (Element element, PSchema tsch,
1.327 vatton 2756: PresentationContext context, char *cssRule,
2757: CSSInfoPtr css, ThotBool isHTML)
1.113 quint 2758: {
1.327 vatton 2759: PresentationValue bidi;
1.366 vatton 2760: char *ptr;
1.113 quint 2761:
1.327 vatton 2762: bidi.typed_data.value = 0;
2763: bidi.typed_data.unit = UNIT_REL;
2764: bidi.typed_data.real = FALSE;
2765:
2766: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 2767: ptr = cssRule;
1.327 vatton 2768: if (!strncasecmp (cssRule, "normal", 6))
2769: {
2770: bidi.typed_data.value = Normal;
2771: cssRule += 6;
2772: }
2773: else if (!strncasecmp (cssRule, "embed", 5))
2774: {
2775: bidi.typed_data.value = Embed;
2776: cssRule += 5;
2777: }
2778: else if (!strncasecmp (cssRule, "bidi-override", 13))
2779: {
2780: bidi.typed_data.value = Override;
2781: cssRule += 13;
2782: }
2783: else if (!strncasecmp (cssRule, "inherit", 7))
2784: {
2785: bidi.typed_data.unit = VALUE_INHERIT;
2786: cssRule += 7;
2787: }
2788: else
2789: {
2790: cssRule = SkipValue ("Invalid unicode-bidi value", cssRule);
1.295 vatton 2791: return (cssRule);
1.327 vatton 2792: }
1.113 quint 2793:
1.327 vatton 2794: /*
2795: * install the new presentation.
2796: */
1.366 vatton 2797: if (bidi.typed_data.value || bidi.typed_data.unit == VALUE_INHERIT)
2798: {
2799: if (DoDialog)
2800: DisplayStyleValue ("unicode-bidi", ptr, cssRule);
2801: else if (DoApply)
2802: TtaSetStylePresentation (PRUnicodeBidi, element, tsch, context, bidi);
2803: }
1.327 vatton 2804: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid unicode-bidi value");
2805: return (cssRule);
1.113 quint 2806: }
2807:
2808: /*----------------------------------------------------------------------
1.327 vatton 2809: ParseCSSTextIndent: parse a CSS text-indent
2810: attribute string.
1.1 cvs 2811: ----------------------------------------------------------------------*/
1.79 cvs 2812: static char *ParseCSSTextIndent (Element element, PSchema tsch,
1.327 vatton 2813: PresentationContext context, char *cssRule,
2814: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2815: {
1.327 vatton 2816: PresentationValue pval;
2817: char *ptr;
1.1 cvs 2818:
1.370 vatton 2819: pval.typed_data.real = FALSE;
1.327 vatton 2820: cssRule = SkipBlanksAndComments (cssRule);
2821: ptr = cssRule;
2822: cssRule = ParseCSSUnit (cssRule, &pval);
1.387 quint 2823: if (pval.typed_data.value == 0 &&
2824: pval.typed_data.unit != UNIT_INVALID)
1.327 vatton 2825: pval.typed_data.unit = UNIT_PX;
2826: else if (pval.typed_data.unit == UNIT_INVALID ||
2827: pval.typed_data.unit == UNIT_BOX)
2828: {
2829: CSSParseError ("Invalid text-indent value", ptr, cssRule);
2830: return (cssRule);
2831: }
2832: /* install the attribute */
1.366 vatton 2833: if (DoDialog)
2834: DisplayStyleValue ("text-indent", ptr, cssRule);
2835: else if (DoApply)
1.327 vatton 2836: TtaSetStylePresentation (PRIndent, element, tsch, context, pval);
2837: return (cssRule);
1.1 cvs 2838: }
2839:
2840: /*----------------------------------------------------------------------
1.327 vatton 2841: ParseCSSTextTransform: parse a CSS text-transform
2842: attribute string.
1.1 cvs 2843: ----------------------------------------------------------------------*/
1.79 cvs 2844: static char *ParseCSSTextTransform (Element element, PSchema tsch,
1.327 vatton 2845: PresentationContext context, char *cssRule,
2846: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2847: {
1.366 vatton 2848: char *ptr;
2849:
2850: cssRule = SkipBlanksAndComments (cssRule);
2851: ptr = cssRule;
1.168 vatton 2852: cssRule = SkipValue (NULL, cssRule);
1.366 vatton 2853: if (DoDialog)
2854: DisplayStyleValue ("text-transform", ptr, cssRule);
1.1 cvs 2855: return (cssRule);
2856: }
2857:
2858: /*----------------------------------------------------------------------
1.327 vatton 2859: ParseCSSVerticalAlign: parse a CSS vertical-align
2860: attribute string.
1.1 cvs 2861: ----------------------------------------------------------------------*/
1.79 cvs 2862: static char *ParseCSSVerticalAlign (Element element, PSchema tsch,
1.327 vatton 2863: PresentationContext context, char *cssRule,
2864: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2865: {
1.273 quint 2866: char *ptr;
2867: PresentationValue pval;
2868:
2869: pval.typed_data.unit = UNIT_REL;
2870: pval.typed_data.real = FALSE;
2871: cssRule = SkipBlanksAndComments (cssRule);
1.288 vatton 2872: ptr = cssRule;
1.273 quint 2873: if (!strncasecmp (cssRule, "baseline", 8))
2874: {
2875: pval.typed_data.value = 0;
1.288 vatton 2876: cssRule += 8;
1.273 quint 2877: }
2878: else if (!strncasecmp (cssRule, "sub", 3))
2879: {
2880: pval.typed_data.value = -3;
1.288 vatton 2881: cssRule += 3;
1.273 quint 2882: }
2883: else if (!strncasecmp (cssRule, "super", 5))
2884: {
2885: pval.typed_data.value = 4;
1.288 vatton 2886: cssRule += 5;
1.273 quint 2887: }
2888: else if (!strncasecmp (cssRule, "top", 3))
2889: {
1.275 quint 2890: pval.typed_data.unit = UNIT_INVALID; /* Not supported yet */
1.274 vatton 2891: pval.typed_data.value = 0;
1.288 vatton 2892: cssRule += 3;
1.273 quint 2893: }
2894: else if (!strncasecmp (cssRule, "text-top", 8))
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 += 8;
1.273 quint 2899: }
2900: else if (!strncasecmp (cssRule, "middle", 6))
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 += 6;
1.273 quint 2905: }
2906: else if (!strncasecmp (cssRule, "bottom", 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, "text-bottom", 11))
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 += 11;
1.273 quint 2917: }
2918: else if (!strncasecmp (cssRule, "inherit", 7))
2919: {
1.293 quint 2920: pval.typed_data.unit = VALUE_INHERIT;
1.274 vatton 2921: pval.typed_data.value = 0;
1.288 vatton 2922: cssRule +=7;
1.273 quint 2923: }
2924: else
2925: {
2926: /* parse <percentage> or <length> */
2927: cssRule = ParseCSSUnit (cssRule, &pval);
2928: if (pval.typed_data.unit == UNIT_INVALID)
1.327 vatton 2929: {
2930: pval.typed_data.value = 0;
2931: CSSParseError ("Invalid vertical-align value", ptr, cssRule);
2932: return (cssRule);
2933: }
1.273 quint 2934: else if (pval.typed_data.value == 0)
1.327 vatton 2935: pval.typed_data.unit = UNIT_PX;
1.273 quint 2936: else if (pval.typed_data.unit == UNIT_BOX)
1.327 vatton 2937: pval.typed_data.unit = UNIT_EM;
1.273 quint 2938: else if (pval.typed_data.unit == UNIT_PERCENT)
1.327 vatton 2939: /* it's a percentage */
2940: {
2941: /* convert it into a relative size */
2942: pval.typed_data.unit = UNIT_REL;
2943: pval.typed_data.value /= 10;
2944: }
1.273 quint 2945: }
1.295 vatton 2946:
1.366 vatton 2947: if (pval.typed_data.unit != UNIT_INVALID)
2948: {
2949: if (DoDialog)
2950: DisplayStyleValue ("vertical-align", ptr, cssRule);
2951: else if (DoApply)
2952: TtaSetStylePresentation (PRHorizRef, element, tsch, context, pval);
2953: }
1.288 vatton 2954: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid vertical-align value");
1.1 cvs 2955: return (cssRule);
2956: }
2957:
2958: /*----------------------------------------------------------------------
1.327 vatton 2959: ParseCSSWhiteSpace: parse a CSS white-space
2960: attribute string.
1.1 cvs 2961: ----------------------------------------------------------------------*/
1.79 cvs 2962: static char *ParseCSSWhiteSpace (Element element, PSchema tsch,
1.327 vatton 2963: PresentationContext context, char *cssRule,
2964: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2965: {
1.366 vatton 2966: char *ptr;
1.288 vatton 2967:
1.327 vatton 2968: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 2969: ptr = cssRule;
1.327 vatton 2970: if (!strncasecmp (cssRule, "normal", 6))
2971: cssRule += 6;
1.432 vatton 2972: else if (!strncasecmp (cssRule, "pre-wrap", 8))
2973: cssRule += 8;
2974: else if (!strncasecmp (cssRule, "pre-line", 8))
2975: cssRule += 8;
1.327 vatton 2976: else if (!strncasecmp (cssRule, "pre", 3))
2977: cssRule += 3;
2978: else if (!strncasecmp (cssRule, "nowrap", 6))
2979: cssRule += 6;
2980: else if (!strncasecmp (cssRule, "inherit", 7))
2981: cssRule += 7;
2982: else
2983: cssRule = SkipValue ("Invalid white-space value", cssRule);
2984:
1.387 quint 2985: if (ptr != cssRule && DoDialog)
1.366 vatton 2986: DisplayStyleValue ("white-space", ptr, cssRule);
1.327 vatton 2987: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid white-space value");
2988: return (cssRule);
1.1 cvs 2989: }
2990:
2991: /*----------------------------------------------------------------------
1.327 vatton 2992: ParseCSSWordSpacing: parse a CSS word-spacing
2993: attribute string.
1.1 cvs 2994: ----------------------------------------------------------------------*/
1.79 cvs 2995: static char *ParseCSSWordSpacing (Element element, PSchema tsch,
1.327 vatton 2996: PresentationContext context, char *cssRule,
2997: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2998: {
1.366 vatton 2999: char *ptr;
3000:
3001: cssRule = SkipBlanksAndComments (cssRule);
3002: ptr = cssRule;
1.168 vatton 3003: cssRule = SkipValue (NULL, cssRule);
1.366 vatton 3004: if (DoDialog)
3005: DisplayStyleValue ("word-spacing", ptr, cssRule);
1.1 cvs 3006: return (cssRule);
3007: }
3008:
3009: /*----------------------------------------------------------------------
1.327 vatton 3010: ParseCSSLineHeight: parse a CSS line-height property
1.25 cvs 3011: ----------------------------------------------------------------------*/
1.162 quint 3012: static char *ParseCSSLineHeight (Element element, PSchema tsch,
1.327 vatton 3013: PresentationContext context, char *cssRule,
3014: CSSInfoPtr css, ThotBool isHTML)
1.25 cvs 3015: {
1.162 quint 3016: PresentationValue pval;
1.288 vatton 3017: char *ptr;
1.162 quint 3018:
1.370 vatton 3019: pval.typed_data.real = FALSE;
1.366 vatton 3020: cssRule = SkipBlanksAndComments (cssRule);
1.162 quint 3021: ptr = cssRule;
3022: if (!strncasecmp (cssRule, "normal", 6))
3023: {
1.184 vatton 3024: pval.typed_data.unit = UNIT_REL;
1.162 quint 3025: pval.typed_data.real = TRUE;
3026: pval.typed_data.value = 1100;
1.288 vatton 3027: cssRule += 6;
1.162 quint 3028: }
3029: else if (!strncasecmp (cssRule, "inherit", 7))
3030: {
1.293 quint 3031: pval.typed_data.unit = VALUE_INHERIT;
1.354 quint 3032: cssRule += 7;
1.162 quint 3033: }
3034: else
3035: cssRule = ParseCSSUnit (cssRule, &pval);
1.25 cvs 3036:
1.184 vatton 3037: if (pval.typed_data.unit == UNIT_INVALID)
1.168 vatton 3038: CSSParseError ("Invalid line-height value", ptr, cssRule);
1.387 quint 3039: else if (DoDialog)
1.366 vatton 3040: DisplayStyleValue ("line-height", ptr, cssRule);
1.162 quint 3041: else if (DoApply)
3042: {
1.166 vatton 3043: /* install the new presentation */
1.184 vatton 3044: if (pval.typed_data.unit == UNIT_BOX)
1.327 vatton 3045: pval.typed_data.unit = UNIT_EM;
1.162 quint 3046: TtaSetStylePresentation (PRLineSpacing, element, tsch, context, pval);
3047: }
3048: return (cssRule);
1.25 cvs 3049: }
3050:
3051: /*----------------------------------------------------------------------
1.327 vatton 3052: ParseCSSFontSizeAdjust: parse a CSS fontsizeAdjust attr string
3053: we expect the input string describing the attribute to be
3054: xx-small, x-small, small, medium, large, x-large, xx-large
3055: or an absolute size, or an imcrement relative to the parent
1.1 cvs 3056: ----------------------------------------------------------------------*/
1.219 vatton 3057: static char *ParseCSSFontSizeAdjust (Element element, PSchema tsch,
1.327 vatton 3058: PresentationContext context, char *cssRule,
3059: CSSInfoPtr css, ThotBool isHTML)
1.219 vatton 3060: {
1.366 vatton 3061:
3062: cssRule = SkipBlanksAndComments (cssRule);
1.234 vatton 3063: cssRule = SkipProperty (cssRule, FALSE);
1.222 quint 3064: return (cssRule);
1.219 vatton 3065: }
3066:
3067: /*----------------------------------------------------------------------
1.327 vatton 3068: ParseACSSFontSize: parse a CSS font size attr string
3069: we expect the input string describing the attribute to be
3070: xx-small, x-small, small, medium, large, x-large, xx-large
3071: or an absolute size, or an imcrement relative to the parent.
3072: The parameter check is TRUE if the rule is just checked.
1.219 vatton 3073: ----------------------------------------------------------------------*/
1.270 vatton 3074: static char *ParseACSSFontSize (Element element, PSchema tsch,
1.327 vatton 3075: PresentationContext context, char *cssRule,
3076: CSSInfoPtr css, ThotBool isHTML, ThotBool check)
1.1 cvs 3077: {
1.327 vatton 3078: ElementType elType;
3079: PresentationValue pval;
1.369 quint 3080: char *ptr = NULL, *ptr1 = NULL, *ptr2 = NULL;
1.366 vatton 3081: char *start_value;
1.369 quint 3082: ThotBool real, error, linespace = FALSE;
1.327 vatton 3083:
1.369 quint 3084: error = FALSE;
1.327 vatton 3085: pval.typed_data.real = FALSE;
3086: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 3087: start_value = cssRule;
1.327 vatton 3088: /* look for a '/' within the current cssRule */
3089: ptr1 = strchr (cssRule, ';');
3090: ptr = strchr (cssRule, '/');
3091: if (ptr && (ptr1 == NULL || ptr < ptr1))
3092: {
3093: /* keep the line spacing rule */
3094: linespace = TRUE;
3095: ptr[0] = EOS;
3096: }
3097: else
3098: ptr = NULL;
3099: ptr1 = cssRule;
1.289 vatton 3100: /* relative size */
1.327 vatton 3101: if (!strncasecmp (cssRule, "larger", 6))
3102: {
3103: pval.typed_data.unit = UNIT_PERCENT;
3104: pval.typed_data.value = 130;
3105: cssRule += 6;
3106: }
3107: else if (!strncasecmp (cssRule, "smaller", 7))
3108: {
3109: pval.typed_data.unit = UNIT_PERCENT;
3110: pval.typed_data.value = 80;
3111: cssRule += 7;
3112: }
3113: /* absolute size */
3114: else if (!strncasecmp (cssRule, "xx-small", 8))
3115: {
3116: pval.typed_data.unit = UNIT_PT;
1.336 vatton 3117: pval.typed_data.value = 6;
1.327 vatton 3118: cssRule += 8;
3119: }
3120: else if (!strncasecmp (cssRule, "x-small", 7))
3121: {
3122: pval.typed_data.unit = UNIT_PT;
1.336 vatton 3123: pval.typed_data.value = 8;
1.327 vatton 3124: cssRule += 7;
3125: }
3126: else if (!strncasecmp (cssRule, "small", 5))
3127: {
3128: pval.typed_data.unit = UNIT_PT;
1.336 vatton 3129: pval.typed_data.value = 10;
1.327 vatton 3130: cssRule += 5;
3131: }
3132: else if (!strncasecmp (cssRule, "medium", 6))
3133: {
3134: pval.typed_data.unit = UNIT_PT;
3135: pval.typed_data.value = 12;
3136: cssRule += 6;
3137: }
3138: else if (!strncasecmp (cssRule, "large", 5))
3139: {
3140: pval.typed_data.unit = UNIT_PT;
3141: pval.typed_data.value = 13;
3142: cssRule += 5;
3143: }
3144: else if (!strncasecmp (cssRule, "x-large", 7))
3145: {
3146: pval.typed_data.unit = UNIT_PT;
3147: pval.typed_data.value = 14;
3148: cssRule += 7;
3149: }
3150: else if (!strncasecmp (cssRule, "xx-large", 8))
3151: {
3152: pval.typed_data.unit = UNIT_PT;
3153: pval.typed_data.value = 16;
3154: cssRule += 8;
3155: }
3156: else if (!strncasecmp (cssRule, "inherit", 7))
3157: {
3158: pval.typed_data.unit = VALUE_INHERIT;
3159: pval.typed_data.value = 0;
3160: cssRule += 7;
3161: }
3162: /* length or percentage */
3163: else if (!isdigit (*cssRule) && *cssRule != '.')
3164: {
3165: if (!check)
1.360 vatton 3166: cssRule = SkipValue ("Invalid font-size value", cssRule);
1.369 quint 3167: error = TRUE;
1.327 vatton 3168: }
3169: else
3170: {
3171: cssRule = ParseCSSUnit (cssRule, &pval);
3172: if (pval.typed_data.unit == UNIT_BOX)
3173: /* no unit specified */
3174: {
3175: elType = TtaGetElementType(element);
3176: if (!strcmp(TtaGetSSchemaName (elType.ElSSchema), "SVG"))
3177: /* we are working for an SVG element. No unit means pixels */
3178: pval.typed_data.unit = UNIT_PX;
3179: }
1.387 quint 3180: if (pval.typed_data.unit == UNIT_INVALID ||
3181: (pval.typed_data.value != 0 && pval.typed_data.unit == UNIT_BOX) ||
3182: pval.typed_data.value < 0)
1.327 vatton 3183: /* not a valid value */
1.369 quint 3184: {
3185: if (!check)
3186: {
3187: ptr2 = SkipWord (cssRule);
3188: CSSParseError ("Invalid font-size value", ptr1, ptr2);
3189: }
3190: error = TRUE;
3191: }
1.327 vatton 3192: else if (pval.typed_data.unit == UNIT_REL && pval.typed_data.value > 0)
3193: /* CSS relative sizes have to be higher than Thot ones */
3194: pval.typed_data.value += 1;
3195: else
3196: {
3197: real = pval.typed_data.real;
3198: if (pval.typed_data.unit == UNIT_EM)
3199: {
3200: if (real)
3201: {
3202: pval.typed_data.value /= 10;
3203: pval.typed_data.real = FALSE;
3204: real = FALSE;
3205: }
3206: else
3207: pval.typed_data.value *= 100;
3208: pval.typed_data.unit = UNIT_PERCENT;
3209: }
3210: else if (pval.typed_data.unit == UNIT_XHEIGHT)
3211: {
3212: /* a font size expressed in ex is converted into a percentage.
3213: For example, "3ex" is converted into "180%", supposing
3214: that 1ex is approximately 0.6 times the height of the
3215: current font */
3216: if (real)
3217: {
3218: pval.typed_data.value *= 6;
3219: pval.typed_data.value /= 100;
3220: pval.typed_data.real = FALSE;
3221: real = FALSE;
3222: }
3223: else
3224: pval.typed_data.value *= 60;
3225: pval.typed_data.unit = UNIT_PERCENT;
3226: }
3227: }
3228: }
3229:
3230: /* install the presentation style */
1.369 quint 3231: if (!check && !error)
1.366 vatton 3232: {
3233: if (DoDialog)
3234: DisplayStyleValue ("font-size", start_value, cssRule);
3235: else if (DoApply)
3236: TtaSetStylePresentation (PRSize, element, tsch, context, pval);
3237: }
1.327 vatton 3238: if (!check && ptr)
3239: cssRule = ParseCSSLineHeight (element, tsch, context, &ptr[1], css, isHTML);
3240: if (linespace)
3241: *ptr = '/';
3242:
3243: return (cssRule);
3244: }
3245:
3246: /*----------------------------------------------------------------------
3247: ParseCSSFontSize: parse a CSS font size attr string
3248: we expect the input string describing the attribute to be
3249: xx-small, x-small, small, medium, large, x-large, xx-large
3250: or an absolute size, or an imcrement relative to the parent
1.270 vatton 3251: ----------------------------------------------------------------------*/
3252: static char *ParseCSSFontSize (Element element, PSchema tsch,
1.327 vatton 3253: PresentationContext context, char *cssRule,
3254: CSSInfoPtr css, ThotBool isHTML)
1.270 vatton 3255: {
1.299 vatton 3256: char *ptr = cssRule;
1.295 vatton 3257: cssRule = ParseACSSFontSize (element, tsch, context, cssRule, css, isHTML, FALSE);
1.299 vatton 3258: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid font-size value");
1.295 vatton 3259: return cssRule;
1.270 vatton 3260: }
3261:
3262: /*----------------------------------------------------------------------
1.327 vatton 3263: ParseACSSFontFamily: parse a CSS font family string
3264: we expect the input string describing the attribute to be
3265: a common generic font style name
1.1 cvs 3266: ----------------------------------------------------------------------*/
1.268 vatton 3267: static char *ParseACSSFontFamily (Element element, PSchema tsch,
1.327 vatton 3268: PresentationContext context, char *cssRule,
3269: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 3270: {
3271: PresentationValue font;
1.252 vatton 3272: char quoteChar, *p;
1.1 cvs 3273:
3274: font.typed_data.value = 0;
1.184 vatton 3275: font.typed_data.unit = UNIT_REL;
1.1 cvs 3276: font.typed_data.real = FALSE;
1.82 cvs 3277: cssRule = SkipBlanksAndComments (cssRule);
3278: if (*cssRule == '"' || *cssRule == '\'')
1.327 vatton 3279: {
3280: quoteChar = *cssRule;
3281: cssRule++;
3282: }
1.1 cvs 3283: else
1.327 vatton 3284: quoteChar = EOS;
1.1 cvs 3285:
1.293 quint 3286: if (!strncasecmp (cssRule, "inherit", 7) && quoteChar == EOS)
3287: {
3288: font.typed_data.unit = VALUE_INHERIT;
3289: cssRule += 7;
3290: }
3291: else if (!strncasecmp (cssRule, "times", 5) &&
1.327 vatton 3292: (quoteChar == EOS || quoteChar == cssRule[5]))
1.86 cvs 3293: {
1.184 vatton 3294: font.typed_data.value = FontTimes;
1.86 cvs 3295: cssRule += 5;
3296: }
1.92 cvs 3297: else if (!strncasecmp (cssRule, "serif", 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;
1.92 cvs 3302: if (quoteChar != EOS)
1.327 vatton 3303: cssRule++;
1.86 cvs 3304: }
1.92 cvs 3305: else if (!strncasecmp (cssRule, "helvetica", 9) &&
1.327 vatton 3306: (quoteChar == EOS || quoteChar == cssRule[9]))
1.86 cvs 3307: {
1.327 vatton 3308: font.typed_data.value = FontHelvetica;
1.86 cvs 3309: cssRule += 9;
1.92 cvs 3310: if (quoteChar != EOS)
1.327 vatton 3311: cssRule++;
1.86 cvs 3312: }
1.92 cvs 3313: else if (!strncasecmp (cssRule, "verdana", 7) &&
1.327 vatton 3314: (quoteChar == EOS || quoteChar == cssRule[7]))
1.86 cvs 3315: {
1.184 vatton 3316: font.typed_data.value = FontHelvetica;
1.86 cvs 3317: cssRule += 7;
1.92 cvs 3318: if (quoteChar != EOS)
1.327 vatton 3319: cssRule++;
1.86 cvs 3320: }
1.92 cvs 3321: else if (!strncasecmp (cssRule, "sans-serif", 10) &&
1.327 vatton 3322: (quoteChar == EOS || quoteChar == cssRule[10]))
1.86 cvs 3323: {
1.184 vatton 3324: font.typed_data.value = FontHelvetica;
1.86 cvs 3325: cssRule += 10;
1.92 cvs 3326: if (quoteChar != EOS)
1.327 vatton 3327: cssRule++;
1.86 cvs 3328: }
1.268 vatton 3329: else if (!strncasecmp (cssRule, "courier new", 11) &&
1.327 vatton 3330: (quoteChar == EOS || quoteChar == cssRule[11]))
1.268 vatton 3331: {
3332: font.typed_data.value = FontCourier;
3333: cssRule += 11;
3334: if (quoteChar != EOS)
1.327 vatton 3335: cssRule++;
1.268 vatton 3336: }
1.92 cvs 3337: else if (!strncasecmp (cssRule, "courier", 7) &&
1.327 vatton 3338: (quoteChar == EOS || quoteChar == cssRule[7]))
1.86 cvs 3339: {
1.184 vatton 3340: font.typed_data.value = FontCourier;
1.86 cvs 3341: cssRule += 7;
1.92 cvs 3342: if (quoteChar != EOS)
1.327 vatton 3343: cssRule++;
1.86 cvs 3344: }
1.92 cvs 3345: else if (!strncasecmp (cssRule, "monospace", 9) &&
1.327 vatton 3346: (quoteChar == EOS || quoteChar == cssRule[9]))
1.86 cvs 3347: {
1.184 vatton 3348: font.typed_data.value = FontCourier;
1.86 cvs 3349: cssRule += 9;
1.92 cvs 3350: if (quoteChar != EOS)
1.327 vatton 3351: cssRule++;
1.86 cvs 3352: }
1.1 cvs 3353: else
3354: /* unknown font name. Skip it */
3355: {
1.252 vatton 3356: p = cssRule;
1.92 cvs 3357: if (quoteChar != EOS)
1.327 vatton 3358: cssRule = SkipQuotedString (cssRule, quoteChar);
1.86 cvs 3359: else
1.383 quint 3360: /* unquoted font name. The name may contain spaces */
3361: {
3362: cssRule = SkipWord (cssRule);
3363: while (*cssRule == SPACE || *cssRule == BSPACE || *cssRule == EOL ||
3364: *cssRule == TAB || *cssRule == __CR__)
3365: {
3366: cssRule = SkipBlanksAndComments (cssRule);
3367: if (*cssRule != ',' && *cssRule != ';' && *cssRule != '}' &&
3368: *cssRule != EOS)
3369: cssRule = SkipWord (cssRule);
3370: }
3371: }
1.252 vatton 3372: while (p == cssRule &&
1.327 vatton 3373: *cssRule != ',' && *cssRule != ';' && *cssRule != '}' && *cssRule != EOS)
3374: {
3375: cssRule++;
3376: p = cssRule;
3377: cssRule = SkipWord (cssRule);
3378: }
1.82 cvs 3379: cssRule = SkipBlanksAndComments (cssRule);
3380: if (*cssRule == ',')
1.327 vatton 3381: {
3382: /* recursive call to ParseCSSFontFamily */
3383: cssRule++;
3384: cssRule = ParseACSSFontFamily (element, tsch, context, cssRule, css, isHTML);
3385: return (cssRule);
3386: }
1.1 cvs 3387: }
3388:
1.239 vatton 3389: /* skip other values */
3390: cssRule = SkipBlanksAndComments (cssRule);
3391: while (*cssRule == ',')
3392: {
3393: cssRule++;
3394: cssRule = SkipValue (NULL, cssRule);
3395: cssRule = SkipBlanksAndComments (cssRule);
3396: }
3397:
1.366 vatton 3398: if (font.typed_data.value != 0 || font.typed_data.unit == VALUE_INHERIT)
3399: {
3400: if (!DoDialog && DoApply)
3401: /* install the new presentation */
3402: TtaSetStylePresentation (PRFont, element, tsch, context, font);
3403: }
1.1 cvs 3404: return (cssRule);
3405: }
3406:
3407: /*----------------------------------------------------------------------
1.327 vatton 3408: ParseCSSFontFamily: parse a CSS font family string
3409: we expect the input string describing the attribute to be
3410: a common generic font style name
1.268 vatton 3411: ----------------------------------------------------------------------*/
3412: static char *ParseCSSFontFamily (Element element, PSchema tsch,
1.327 vatton 3413: PresentationContext context, char *cssRule,
3414: CSSInfoPtr css, ThotBool isHTML)
1.268 vatton 3415: {
1.366 vatton 3416: char *start_value;
3417:
3418: cssRule = SkipBlanksAndComments (cssRule);
3419: start_value = cssRule;
1.268 vatton 3420: cssRule = ParseACSSFontFamily (element, tsch, context, cssRule, css, isHTML);
3421: /* skip extra values */
1.301 vatton 3422: while (cssRule && *cssRule != ';' && *cssRule != '}' && *cssRule != EOS)
1.268 vatton 3423: cssRule++;
1.366 vatton 3424: if (DoDialog)
3425: DisplayStyleValue ("font-family", start_value, cssRule);
1.268 vatton 3426: return (cssRule);
3427: }
3428:
3429: /*----------------------------------------------------------------------
1.327 vatton 3430: ParseACSSFontWeight: parse a CSS font weight string
3431: we expect the input string describing the attribute to be
3432: normal, bold, bolder, lighter, 100, 200, 300, ... 900, inherit.
1.1 cvs 3433: ----------------------------------------------------------------------*/
1.263 vatton 3434: static char *ParseACSSFontWeight (Element element, PSchema tsch,
1.327 vatton 3435: PresentationContext context, char *cssRule,
3436: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 3437: {
1.327 vatton 3438: PresentationValue weight;
1.366 vatton 3439: char *ptr;
1.1 cvs 3440:
1.327 vatton 3441: weight.typed_data.value = 0;
3442: weight.typed_data.unit = UNIT_REL;
3443: weight.typed_data.real = FALSE;
3444: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 3445: ptr = cssRule;
1.351 quint 3446: if (isdigit (*cssRule) && *cssRule != '0' &&
3447: cssRule[1] == '0' && cssRule[2] == '0' &&
3448: (cssRule[3] == EOS || cssRule[3] == SPACE || cssRule[3] == '/' ||
3449: cssRule[3] == ';' || cssRule[3] == '}' || cssRule[3] == EOL ||
3450: cssRule[3] == TAB || cssRule[3] == __CR__))
1.327 vatton 3451: {
1.351 quint 3452: if (!strncasecmp (cssRule, "100", 3))
3453: {
1.379 quint 3454: weight.typed_data.value = -4;
1.351 quint 3455: cssRule = SkipWord (cssRule);
3456: }
3457: else if (!strncasecmp (cssRule, "200", 3))
3458: {
1.379 quint 3459: weight.typed_data.value = -3;
1.351 quint 3460: cssRule = SkipWord (cssRule);
3461: }
3462: else if (!strncasecmp (cssRule, "300", 3))
3463: {
1.379 quint 3464: weight.typed_data.value = -2;
1.351 quint 3465: cssRule = SkipWord (cssRule);
3466: }
3467: else if (!strncasecmp (cssRule, "400", 3))
3468: {
1.379 quint 3469: weight.typed_data.value = -1;
1.351 quint 3470: cssRule = SkipWord (cssRule);
3471: }
3472: else if (!strncasecmp (cssRule, "500", 3))
3473: {
1.379 quint 3474: weight.typed_data.value = 0;
1.351 quint 3475: cssRule = SkipWord (cssRule);
3476: }
3477: else if (!strncasecmp (cssRule, "600", 3))
3478: {
1.379 quint 3479: weight.typed_data.value = +1;
1.351 quint 3480: cssRule = SkipWord (cssRule);
3481: }
3482: else if (!strncasecmp (cssRule, "700", 3))
3483: {
1.379 quint 3484: weight.typed_data.value = +2;
1.351 quint 3485: cssRule = SkipWord (cssRule);
3486: }
3487: else if (!strncasecmp (cssRule, "800", 3))
3488: {
1.379 quint 3489: weight.typed_data.value = +3;
1.351 quint 3490: cssRule = SkipWord (cssRule);
3491: }
3492: else if (!strncasecmp (cssRule, "900", 3))
3493: {
1.379 quint 3494: weight.typed_data.value = +4;
1.351 quint 3495: cssRule = SkipWord (cssRule);
3496: }
1.327 vatton 3497: }
1.351 quint 3498: else if (!strncasecmp (cssRule, "normal", 6))
1.327 vatton 3499: {
3500: weight.typed_data.value = 0;
3501: cssRule = SkipWord (cssRule);
3502: }
1.351 quint 3503: else if (!strncasecmp (cssRule, "bold", 4))
1.327 vatton 3504: {
3505: weight.typed_data.value = +3;
3506: cssRule = SkipWord (cssRule);
3507: }
3508: else if (!strncasecmp (cssRule, "inherit", 7))
3509: {
3510: weight.typed_data.unit = VALUE_INHERIT;
3511: cssRule += 7;
3512: }
1.379 quint 3513: else if (!strncasecmp (cssRule, "bolder", 6))
1.327 vatton 3514: {
1.379 quint 3515: weight.typed_data.value = +2;
3516: cssRule = SkipWord (cssRule);
3517: }
3518:
3519: else if (!strncasecmp (cssRule, "lighter", 7))
3520: {
3521: weight.typed_data.value = -1;
1.327 vatton 3522: cssRule = SkipWord (cssRule);
3523: }
3524: else
3525: return (cssRule);
3526:
3527: /*
3528: * Here we have to reduce since only two font weight values are supported
3529: * by the Thot presentation API.
3530: */
3531: if (weight.typed_data.unit != VALUE_INHERIT)
3532: {
3533: if (weight.typed_data.value > 0)
3534: weight.typed_data.value = WeightBold;
3535: else
3536: weight.typed_data.value = WeightNormal;
3537: }
3538:
3539: /* install the new presentation */
1.366 vatton 3540: if (cssRule != ptr && DoDialog)
3541: DisplayStyleValue ("font-weight", ptr, cssRule);
3542: else if (DoApply)
1.327 vatton 3543: TtaSetStylePresentation (PRWeight, element, tsch, context, weight);
3544: return (cssRule);
3545: }
3546:
3547: /*----------------------------------------------------------------------
3548: ParseCSSFontWeight: parse a CSS font weight string
3549: we expect the input string describing the attribute to be
3550: normal, bold, bolder, lighter, 100, 200, 300, ... 900, inherit.
1.263 vatton 3551: ----------------------------------------------------------------------*/
3552: static char *ParseCSSFontWeight (Element element, PSchema tsch,
1.327 vatton 3553: PresentationContext context, char *cssRule,
3554: CSSInfoPtr css, ThotBool isHTML)
1.263 vatton 3555: {
3556: char *ptr;
3557:
1.366 vatton 3558: cssRule = SkipBlanksAndComments (cssRule);
1.263 vatton 3559: ptr = cssRule;
3560: cssRule = ParseACSSFontWeight (element, tsch, context, cssRule, css, isHTML);
3561: if (ptr == cssRule)
3562: cssRule = SkipValue ("Invalid font-weight value", cssRule);
3563: return (cssRule);
3564: }
3565:
3566: /*----------------------------------------------------------------------
1.327 vatton 3567: ParseACSSFontVariant: parse a CSS font variant string
3568: we expect the input string describing the attribute to be
3569: normal or small-caps
1.1 cvs 3570: ----------------------------------------------------------------------*/
1.263 vatton 3571: static char *ParseACSSFontVariant (Element element, PSchema tsch,
1.327 vatton 3572: PresentationContext context, char *cssRule,
3573: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 3574: {
1.327 vatton 3575: PresentationValue style;
1.366 vatton 3576: char *ptr;
1.1 cvs 3577:
1.327 vatton 3578: style.typed_data.value = 0;
3579: style.typed_data.unit = UNIT_REL;
3580: style.typed_data.real = FALSE;
3581: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 3582: ptr = cssRule;
1.327 vatton 3583: if (!strncasecmp (cssRule, "small-caps", 10))
3584: {
1.381 quint 3585: style.typed_data.value = VariantSmallCaps;
1.327 vatton 3586: cssRule = SkipWord (cssRule);
3587: }
3588: else if (!strncasecmp (cssRule, "normal", 6))
3589: {
1.381 quint 3590: style.typed_data.value = VariantNormal;
1.327 vatton 3591: cssRule = SkipWord (cssRule);
3592: }
3593: else if (!strncasecmp (cssRule, "inherit", 7))
3594: {
1.381 quint 3595: style.typed_data.unit = VALUE_INHERIT;
1.327 vatton 3596: cssRule = SkipWord (cssRule);
3597: }
1.381 quint 3598: else
3599: /* invalid font-variant */
3600: return (cssRule);
3601:
3602: if (style.typed_data.value != 0 || style.typed_data.unit == VALUE_INHERIT)
3603: {
3604: if (DoDialog)
3605: DisplayStyleValue ("font-variant", ptr, cssRule);
3606: else if (DoApply)
3607: TtaSetStylePresentation (PRVariant, element, tsch, context, style);
3608: }
1.295 vatton 3609: return (cssRule);
1.263 vatton 3610: }
1.1 cvs 3611:
1.263 vatton 3612: /*----------------------------------------------------------------------
1.327 vatton 3613: ParseCSSFontVariant: parse a CSS font variant string
3614: we expect the input string describing the attribute to be
3615: normal or small-caps
1.263 vatton 3616: ----------------------------------------------------------------------*/
3617: static char *ParseCSSFontVariant (Element element, PSchema tsch,
1.327 vatton 3618: PresentationContext context, char *cssRule,
3619: CSSInfoPtr css, ThotBool isHTML)
1.263 vatton 3620: {
3621: char *ptr;
3622:
3623: ptr = cssRule;
3624: cssRule = ParseACSSFontVariant (element, tsch, context, cssRule, css, isHTML);
3625: if (ptr == cssRule)
3626: cssRule = SkipValue ("Invalid font-variant value", cssRule);
3627: return (cssRule);
1.1 cvs 3628: }
3629:
3630:
3631: /*----------------------------------------------------------------------
1.327 vatton 3632: ParseACSSFontStyle: parse a CSS font style string
3633: we expect the input string describing the attribute to be
3634: normal, italic, oblique or inherit
1.1 cvs 3635: ----------------------------------------------------------------------*/
1.263 vatton 3636: static char *ParseACSSFontStyle (Element element, PSchema tsch,
1.327 vatton 3637: PresentationContext context, char *cssRule,
3638: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 3639: {
1.327 vatton 3640: PresentationValue style;
3641: PresentationValue size;
1.366 vatton 3642: PresentationValue previous_size;
3643: char *ptr;
1.1 cvs 3644:
1.327 vatton 3645: style.typed_data.value = 0;
3646: style.typed_data.unit = UNIT_REL;
3647: style.typed_data.real = FALSE;
3648: size.typed_data.value = 0;
3649: size.typed_data.unit = UNIT_REL;
3650: size.typed_data.real = FALSE;
3651: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 3652: ptr = cssRule;
1.327 vatton 3653: if (!strncasecmp (cssRule, "italic", 6))
3654: {
3655: style.typed_data.value = StyleItalics;
3656: cssRule = SkipWord (cssRule);
3657: }
3658: else if (!strncasecmp (cssRule, "oblique", 7))
3659: {
3660: style.typed_data.value = StyleOblique;
3661: cssRule = SkipWord (cssRule);
3662: }
3663: else if (!strncasecmp (cssRule, "normal", 6))
3664: {
3665: style.typed_data.value = StyleRoman;
3666: cssRule = SkipWord (cssRule);
3667: }
3668: else if (!strncasecmp (cssRule, "inherit", 7))
3669: {
3670: style.typed_data.unit = VALUE_INHERIT;
3671: cssRule = SkipWord (cssRule);
3672: }
3673: else
3674: /* invalid font style */
3675: return (cssRule);
3676:
3677: /*
3678: * install the new presentation.
3679: */
1.366 vatton 3680: if (style.typed_data.value != 0 || style.typed_data.unit == VALUE_INHERIT)
1.327 vatton 3681: {
1.366 vatton 3682: if (DoDialog)
3683: DisplayStyleValue ("font-style", ptr, cssRule);
3684: else if (DoApply)
3685: TtaSetStylePresentation (PRStyle, element, tsch, context, style);
1.327 vatton 3686: }
1.366 vatton 3687: if (size.typed_data.value != 0)
1.327 vatton 3688: {
1.366 vatton 3689: if (DoDialog)
3690: DisplayStyleValue ("font-style", ptr, cssRule);
3691: else if (DoApply)
1.327 vatton 3692: {
1.366 vatton 3693: if (!TtaGetStylePresentation (PRSize, element, tsch, context, &previous_size))
3694: {
3695: /* !!!!!!!!!!!!!!!!!!!!!!!! Unit + relative !!!!!!!!!!!!!!!! */
3696: size.typed_data.value += previous_size.typed_data.value;
3697: TtaSetStylePresentation (PRSize, element, tsch, context, size);
3698: }
3699: else
3700: {
3701: size.typed_data.value = 10;
3702: TtaSetStylePresentation (PRSize, element, tsch, context, size);
3703: }
1.327 vatton 3704: }
3705: }
3706: return (cssRule);
3707: }
3708:
3709: /*----------------------------------------------------------------------
3710: ParseCSSFontStyle: parse a CSS font style string
3711: we expect the input string describing the attribute to be
3712: italic, oblique or normal
1.263 vatton 3713: ----------------------------------------------------------------------*/
3714: static char *ParseCSSFontStyle (Element element, PSchema tsch,
1.327 vatton 3715: PresentationContext context, char *cssRule,
3716: CSSInfoPtr css, ThotBool isHTML)
1.263 vatton 3717: {
3718: char *ptr;
3719:
3720: ptr = cssRule;
3721: cssRule = ParseACSSFontStyle (element, tsch, context, cssRule, css, isHTML);
3722: if (ptr == cssRule)
3723: cssRule = SkipValue ("Invalid font-style value", cssRule);
3724: return (cssRule);
3725: }
3726:
3727: /*----------------------------------------------------------------------
1.59 cvs 3728: ParseCSSFont: parse a CSS font attribute string
3729: we expect the input string describing the attribute to be
3730: !!!!!!
1.1 cvs 3731: ----------------------------------------------------------------------*/
1.79 cvs 3732: static char *ParseCSSFont (Element element, PSchema tsch,
1.327 vatton 3733: PresentationContext context, char *cssRule,
3734: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 3735: {
1.270 vatton 3736: char *ptr, *p;
1.366 vatton 3737: char *start_value;
1.93 vatton 3738: int skippedNL;
1.272 vatton 3739: ThotBool variant = FALSE, style = FALSE, weight = FALSE, found;
1.1 cvs 3740:
1.82 cvs 3741: cssRule = SkipBlanksAndComments (cssRule);
3742: if (!strncasecmp (cssRule, "caption", 7))
1.263 vatton 3743: cssRule += 7;
1.82 cvs 3744: else if (!strncasecmp (cssRule, "icon", 4))
1.263 vatton 3745: cssRule += 4;
1.82 cvs 3746: else if (!strncasecmp (cssRule, "menu", 4))
1.263 vatton 3747: cssRule += 4;
1.82 cvs 3748: else if (!strncasecmp (cssRule, "message-box", 11))
1.263 vatton 3749: cssRule += 11;
1.82 cvs 3750: else if (!strncasecmp (cssRule, "small-caption", 13))
1.263 vatton 3751: cssRule += 13;
1.82 cvs 3752: else if (!strncasecmp (cssRule, "status-bar", 10))
1.263 vatton 3753: cssRule += 10;
3754: else if (!strncasecmp (cssRule, "inherit", 7))
1.293 quint 3755: {
3756: ParseACSSFontStyle (element, tsch, context, cssRule, css, isHTML);
3757: ParseACSSFontVariant (element, tsch, context, cssRule, css, isHTML);
3758: ParseACSSFontWeight (element, tsch, context, cssRule, css, isHTML);
3759: ParseACSSFontSize (element, tsch, context, cssRule, css, isHTML, FALSE);
1.366 vatton 3760: cssRule = SkipBlanksAndComments (cssRule);
3761: start_value = cssRule;
1.293 quint 3762: ParseACSSFontFamily (element, tsch, context, cssRule, css, isHTML);
3763: cssRule += 7;
1.366 vatton 3764: if (DoDialog)
3765: DisplayStyleValue ("font-family", start_value, cssRule);
1.293 quint 3766: }
1.1 cvs 3767: else
1.43 cvs 3768: {
1.270 vatton 3769: ptr = NULL;
3770: p = cssRule;
1.301 vatton 3771: while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && p == cssRule)
1.327 vatton 3772: {
3773: found = FALSE;
3774: /* style, variant, weight can appear in any order */
3775: ptr = cssRule;
3776: skippedNL = NewLineSkipped;
3777: cssRule = ParseACSSFontStyle (element, tsch, context, cssRule, css, isHTML);
3778: if (ptr != cssRule)
3779: {
3780: skippedNL = NewLineSkipped;
3781: found = TRUE;
3782: style = TRUE;
3783: }
3784: else
3785: NewLineSkipped = skippedNL;
3786: ptr = cssRule;
3787: cssRule = ParseACSSFontVariant (element, tsch, context, cssRule, css, isHTML);
3788: if (ptr != cssRule)
3789: {
3790: skippedNL = NewLineSkipped;
3791: found = TRUE;
3792: variant = TRUE;
3793: }
3794: else
3795: NewLineSkipped = skippedNL;
3796: ptr = cssRule;
3797: cssRule = ParseACSSFontWeight (element, tsch, context, cssRule, css, isHTML);
3798: if (ptr != cssRule)
3799: {
3800: skippedNL = NewLineSkipped;
3801: found = TRUE;
3802: weight = TRUE;
3803: }
3804: else
3805: NewLineSkipped = skippedNL;
3806: cssRule = SkipBlanksAndComments (cssRule);
3807: p = ParseACSSFontSize (element, tsch, context, cssRule, css, isHTML, TRUE);
3808: NewLineSkipped = skippedNL;
3809: if (!found)
3810: /* break the loop when the current value was not parsed */
3811: p = cssRule + 1;
3812: }
1.263 vatton 3813: ptr = cssRule;
1.270 vatton 3814: /* set default variant, style, weight */
3815: if (!variant)
1.405 kia 3816: ParseACSSFontVariant (element, tsch, context, (char*)"normal", css, isHTML);
1.270 vatton 3817: if (!style)
1.405 kia 3818: ParseACSSFontStyle (element, tsch, context, (char*)"normal", css, isHTML);
1.270 vatton 3819: if (!weight)
1.405 kia 3820: ParseACSSFontWeight (element, tsch, context, (char*)"normal", css, isHTML);
1.270 vatton 3821: /* now parse the font size and the font family */
1.301 vatton 3822: if (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS)
1.327 vatton 3823: cssRule = ParseACSSFontSize (element, tsch, context, cssRule, css, isHTML, FALSE);
1.301 vatton 3824: if (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS)
1.366 vatton 3825: {
3826: cssRule = SkipBlanksAndComments (cssRule);
3827: start_value = cssRule;
3828: cssRule = ParseACSSFontFamily (element, tsch, context, cssRule, css, isHTML);
3829: if (DoDialog)
3830: DisplayStyleValue ("font-family", start_value, cssRule);
3831: }
1.263 vatton 3832: if (ptr == cssRule)
1.360 vatton 3833: cssRule = SkipValue ("Invalid font value", cssRule);
1.43 cvs 3834: }
1.263 vatton 3835: cssRule = SkipBlanksAndComments (cssRule);
1.301 vatton 3836: if (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS)
1.360 vatton 3837: cssRule = SkipValue ("Invalid font value", cssRule);
1.43 cvs 3838: return (cssRule);
1.1 cvs 3839: }
3840:
3841: /*----------------------------------------------------------------------
1.356 quint 3842: ParseCSSTextDecoration: parse a CSS text-decoration value.
3843: We expect the input string to be none, inherit or a combination of
3844: underline, overline, line-through, and blink.
1.1 cvs 3845: ----------------------------------------------------------------------*/
1.79 cvs 3846: static char *ParseCSSTextDecoration (Element element, PSchema tsch,
1.327 vatton 3847: PresentationContext context, char *cssRule,
3848: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 3849: {
1.327 vatton 3850: PresentationValue decor;
1.366 vatton 3851: char *ptr;
1.356 quint 3852: ThotBool ok;
1.327 vatton 3853:
3854: decor.typed_data.value = 0;
3855: decor.typed_data.unit = UNIT_REL;
3856: decor.typed_data.real = FALSE;
3857: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 3858: ptr = cssRule;
1.356 quint 3859: ok = TRUE;
1.327 vatton 3860: if (!strncasecmp (cssRule, "none", 4))
3861: {
3862: decor.typed_data.value = NoUnderline;
3863: cssRule += 4;
3864: }
3865: else if (!strncasecmp (cssRule, "inherit", 7))
3866: {
3867: decor.typed_data.unit = VALUE_INHERIT;
3868: cssRule += 7;
3869: }
3870: else
3871: {
1.356 quint 3872: do
3873: {
3874: if (!strncasecmp (cssRule, "underline", 9))
3875: {
3876: decor.typed_data.value = Underline;
3877: cssRule += 9;
3878: }
3879: else if (!strncasecmp (cssRule, "overline", 8))
3880: {
3881: decor.typed_data.value = Overline;
3882: cssRule += 8;
3883: }
3884: else if (!strncasecmp (cssRule, "line-through", 12))
3885: {
3886: decor.typed_data.value = CrossOut;
3887: cssRule += 12;
3888: }
3889: else if (!strncasecmp (cssRule, "blink", 5))
3890: {
3891: /* the blink text-decoration attribute is not supported */
3892: cssRule += 5;
3893: }
3894: else
3895: ok = FALSE;
3896: if (ok)
3897: {
3898: cssRule = SkipBlanksAndComments (cssRule);
3899: }
3900: }
3901: while (ok && (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS));
3902: }
3903: if (!ok)
3904: {
1.327 vatton 3905: cssRule = SkipValue ("Invalid text-decoration value", cssRule);
3906: return (cssRule);
3907: }
1.1 cvs 3908:
1.327 vatton 3909: /*
3910: * install the new presentation.
3911: */
1.366 vatton 3912: if (decor.typed_data.value || decor.typed_data.unit == VALUE_INHERIT)
3913: {
3914: if (DoDialog)
3915: DisplayStyleValue ("text-decoration", ptr, cssRule);
3916: else if (DoApply)
3917: TtaSetStylePresentation (PRUnderline, element, tsch, context, decor);
3918: }
1.327 vatton 3919: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid text-decoration value");
3920: return (cssRule);
1.1 cvs 3921: }
3922:
3923: /*----------------------------------------------------------------------
1.327 vatton 3924: ParseCSSHeight: parse a CSS height attribute
1.1 cvs 3925: ----------------------------------------------------------------------*/
1.79 cvs 3926: static char *ParseCSSHeight (Element element, PSchema tsch,
1.327 vatton 3927: PresentationContext context, char *cssRule,
3928: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 3929: {
1.117 vatton 3930: PresentationValue val;
1.168 vatton 3931: char *ptr;
1.93 vatton 3932:
1.370 vatton 3933: val.typed_data.real = FALSE;
1.117 vatton 3934: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 3935: ptr = cssRule;
1.117 vatton 3936: /* first parse the attribute string */
1.164 quint 3937: if (!strncasecmp (cssRule, "auto", 4))
3938: {
1.184 vatton 3939: val.typed_data.unit = VALUE_AUTO;
1.164 quint 3940: val.typed_data.value = 0;
1.288 vatton 3941: cssRule += 4;
3942: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid height value");
1.164 quint 3943: }
1.117 vatton 3944: else
1.168 vatton 3945: cssRule = ParseCSSUnit (cssRule, &val);
1.295 vatton 3946:
1.387 quint 3947: if (val.typed_data.unit == UNIT_INVALID ||
3948: (val.typed_data.value != 0 &&
1.184 vatton 3949: val.typed_data.unit == UNIT_BOX))
1.387 quint 3950: CSSParseError ("height value", ptr, cssRule);
3951: else if (DoDialog)
1.366 vatton 3952: DisplayStyleValue ("height", ptr, cssRule);
3953: else if (DoApply)
1.295 vatton 3954: /* install the new presentation */
3955: TtaSetStylePresentation (PRHeight, element, tsch, context, val);
1.117 vatton 3956: return (cssRule);
1.1 cvs 3957: }
3958:
3959: /*----------------------------------------------------------------------
1.382 vatton 3960: ParseCSSMaxHeight: parse a CSS height attribute
3961: ----------------------------------------------------------------------*/
3962: static char *ParseCSSMaxHeight (Element element, PSchema tsch,
3963: PresentationContext context, char *cssRule,
3964: CSSInfoPtr css, ThotBool isHTML)
3965: {
3966: PresentationValue val;
3967: char *ptr;
3968:
3969: val.typed_data.real = FALSE;
3970: cssRule = SkipBlanksAndComments (cssRule);
3971: ptr = cssRule;
3972: /* first parse the attribute string */
3973: if (!strncasecmp (cssRule, "auto", 4))
3974: {
3975: val.typed_data.unit = VALUE_AUTO;
3976: val.typed_data.value = 0;
3977: cssRule += 4;
3978: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid height value");
3979: }
3980: else
3981: cssRule = ParseCSSUnit (cssRule, &val);
3982:
1.387 quint 3983: if (val.typed_data.unit == UNIT_INVALID ||
3984: (val.typed_data.value != 0 &&
1.382 vatton 3985: val.typed_data.unit == UNIT_BOX))
1.387 quint 3986: CSSParseError ("height value", ptr, cssRule);
3987: else if (DoDialog)
1.382 vatton 3988: DisplayStyleValue ("max-height", ptr, cssRule);
1.390 vatton 3989: /*else if (DoApply)
3990: install the new presentation
3991: TtaSetStylePresentation (PRHeight, element, tsch, context, val)*/;
1.382 vatton 3992: return (cssRule);
3993: }
3994:
3995: /*----------------------------------------------------------------------
3996: ParseCSSMinHeight: parse a CSS height attribute
3997: ----------------------------------------------------------------------*/
3998: static char *ParseCSSMinHeight (Element element, PSchema tsch,
3999: PresentationContext context, char *cssRule,
4000: CSSInfoPtr css, ThotBool isHTML)
4001: {
4002: PresentationValue val;
4003: char *ptr;
4004:
4005: val.typed_data.real = FALSE;
4006: cssRule = SkipBlanksAndComments (cssRule);
4007: ptr = cssRule;
4008: /* first parse the attribute string */
4009: if (!strncasecmp (cssRule, "auto", 4))
4010: {
4011: val.typed_data.unit = VALUE_AUTO;
4012: val.typed_data.value = 0;
4013: cssRule += 4;
4014: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid height value");
4015: }
4016: else
4017: cssRule = ParseCSSUnit (cssRule, &val);
4018:
1.387 quint 4019: if (val.typed_data.unit == UNIT_INVALID ||
4020: (val.typed_data.value != 0 &&
1.382 vatton 4021: val.typed_data.unit == UNIT_BOX))
1.387 quint 4022: CSSParseError ("height value", ptr, cssRule);
4023: else if (DoDialog)
1.382 vatton 4024: DisplayStyleValue ("min-height", ptr, cssRule);
1.390 vatton 4025: /*else if (DoApply)*/
1.382 vatton 4026: /* install the new presentation */
1.384 vatton 4027: /*TtaSetStylePresentation (PRHeight, element, tsch, context, val)*/;
1.382 vatton 4028: return (cssRule);
4029: }
4030:
4031: /*----------------------------------------------------------------------
1.327 vatton 4032: ParseCSSWidth: parse a CSS width attribute
1.1 cvs 4033: ----------------------------------------------------------------------*/
1.79 cvs 4034: static char *ParseCSSWidth (Element element, PSchema tsch,
1.327 vatton 4035: PresentationContext context,
4036: char *cssRule, CSSInfoPtr css,
4037: ThotBool isHTML)
1.1 cvs 4038: {
1.117 vatton 4039: PresentationValue val;
1.168 vatton 4040: char *ptr;
1.93 vatton 4041:
1.370 vatton 4042: val.typed_data.real = FALSE;
1.117 vatton 4043: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 4044: ptr = cssRule;
1.117 vatton 4045: /* first parse the attribute string */
1.164 quint 4046: if (!strncasecmp (cssRule, "auto", 4))
4047: {
1.184 vatton 4048: val.typed_data.unit = VALUE_AUTO;
1.164 quint 4049: val.typed_data.value = 0;
1.288 vatton 4050: cssRule += 4;
4051: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid width value");
1.164 quint 4052: }
1.117 vatton 4053: else
1.327 vatton 4054: cssRule = ParseCSSUnit (cssRule, &val);
1.387 quint 4055: if (val.typed_data.unit == UNIT_INVALID ||
4056: (val.typed_data.value != 0 &&
1.184 vatton 4057: val.typed_data.unit == UNIT_BOX))
1.387 quint 4058: CSSParseError ("Invalid width value", ptr, cssRule);
4059: else if (DoDialog)
1.366 vatton 4060: DisplayStyleValue ("width", ptr, cssRule);
4061: else if (DoApply)
1.295 vatton 4062: /* install the new presentation */
4063: TtaSetStylePresentation (PRWidth, element, tsch, context, val);
1.117 vatton 4064: return (cssRule);
1.1 cvs 4065: }
4066:
4067: /*----------------------------------------------------------------------
1.382 vatton 4068: ParseCSSMaxWidth: parse a CSS width attribute
4069: ----------------------------------------------------------------------*/
4070: static char *ParseCSSMaxWidth (Element element, PSchema tsch,
4071: PresentationContext context,
4072: char *cssRule, CSSInfoPtr css,
4073: ThotBool isHTML)
4074: {
4075: PresentationValue val;
4076: char *ptr;
4077:
4078: val.typed_data.real = FALSE;
4079: cssRule = SkipBlanksAndComments (cssRule);
4080: ptr = cssRule;
4081: /* first parse the attribute string */
4082: if (!strncasecmp (cssRule, "auto", 4))
4083: {
4084: val.typed_data.unit = VALUE_AUTO;
4085: val.typed_data.value = 0;
4086: cssRule += 4;
4087: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid width value");
4088: }
4089: else
4090: cssRule = ParseCSSUnit (cssRule, &val);
1.387 quint 4091: if (val.typed_data.unit == UNIT_INVALID ||
4092: (val.typed_data.value != 0 &&
1.382 vatton 4093: val.typed_data.unit == UNIT_BOX))
4094: CSSParseError ("Invalid width value", ptr, cssRule);
1.387 quint 4095: else if (DoDialog)
1.382 vatton 4096: DisplayStyleValue ("max-width", ptr, cssRule);
1.408 vatton 4097: /*else if (DoApply)*/
1.382 vatton 4098: /* install the new presentation */
1.384 vatton 4099: /*TtaSetStylePresentation (PRWidth, element, tsch, context, val)*/;
1.382 vatton 4100: return (cssRule);
4101: }
4102:
4103: /*----------------------------------------------------------------------
4104: ParseCSSMinWidth: parse a CSS width attribute
4105: ----------------------------------------------------------------------*/
4106: static char *ParseCSSMinWidth (Element element, PSchema tsch,
4107: PresentationContext context,
4108: char *cssRule, CSSInfoPtr css,
4109: ThotBool isHTML)
4110: {
4111: PresentationValue val;
4112: char *ptr;
4113:
4114: val.typed_data.real = FALSE;
4115: cssRule = SkipBlanksAndComments (cssRule);
4116: ptr = cssRule;
4117: /* first parse the attribute string */
4118: if (!strncasecmp (cssRule, "auto", 4))
4119: {
4120: val.typed_data.unit = VALUE_AUTO;
4121: val.typed_data.value = 0;
4122: cssRule += 4;
4123: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid width value");
4124: }
4125: else
4126: cssRule = ParseCSSUnit (cssRule, &val);
1.387 quint 4127: if (val.typed_data.unit == UNIT_INVALID ||
4128: (val.typed_data.value != 0 &&
1.382 vatton 4129: val.typed_data.unit == UNIT_BOX))
1.387 quint 4130: CSSParseError ("Invalid width value", ptr, cssRule);
4131: else if (DoDialog)
1.382 vatton 4132: DisplayStyleValue ("min-width", ptr, cssRule);
1.408 vatton 4133: /*else if (DoApply)*/
1.382 vatton 4134: /* install the new presentation */
1.384 vatton 4135: /*TtaSetStylePresentation (PRWidth, element, tsch, context, val)*/;
1.382 vatton 4136: return (cssRule);
4137: }
4138:
4139: /*----------------------------------------------------------------------
1.391 vatton 4140: GetEmMarginValue returns the em value
4141: ----------------------------------------------------------------------*/
4142: int GetEmValue (char *data, Element el, Document doc)
4143: {
4144: PresentationValue val;
4145: char *ptr;
4146: int value;
4147:
4148: val.typed_data.real = FALSE;
4149: ptr = SkipBlanksAndComments (data);
4150: if (!strncasecmp (data, "auto", 4))
4151: value = TtaGetPixelValue (0, VALUE_AUTO, el, doc);
4152: else
4153: {
4154: ptr = ParseCSSUnit (data, &val);
4155: value = TtaGetPixelValue (val.typed_data.value, val.typed_data.unit,
4156: el, doc);
4157: }
4158: return TtaGetLogicalValue (value, UNIT_EM, el, doc);
4159: }
4160:
4161: /*----------------------------------------------------------------------
1.327 vatton 4162: ParseACSSMarginTop: parse a CSS margin-top attribute
1.1 cvs 4163: ----------------------------------------------------------------------*/
1.296 vatton 4164: static char *ParseACSSMarginTop (Element element, PSchema tsch,
1.327 vatton 4165: PresentationContext context,
4166: char *cssRule, CSSInfoPtr css,
4167: ThotBool isHTML)
1.1 cvs 4168: {
4169: PresentationValue margin;
1.168 vatton 4170: char *ptr;
1.1 cvs 4171:
1.370 vatton 4172: margin.typed_data.real = FALSE;
1.82 cvs 4173: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 4174: ptr = cssRule;
1.1 cvs 4175: /* first parse the attribute string */
1.164 quint 4176: if (!strncasecmp (cssRule, "auto", 4))
4177: {
1.184 vatton 4178: margin.typed_data.unit = VALUE_AUTO;
1.164 quint 4179: margin.typed_data.value = 0;
1.288 vatton 4180: cssRule += 4;
1.164 quint 4181: }
1.404 vatton 4182: else if (!strncasecmp (cssRule, "inherit", 7))
4183: {
4184: margin.typed_data.unit = VALUE_AUTO;
4185: margin.typed_data.value = 0;
4186: cssRule += 7;
4187: }
1.164 quint 4188: else
1.168 vatton 4189: cssRule = ParseCSSUnit (cssRule, &margin);
1.295 vatton 4190:
1.387 quint 4191: if (margin.typed_data.unit == UNIT_INVALID ||
4192: (margin.typed_data.value != 0 &&
1.184 vatton 4193: margin.typed_data.unit == UNIT_BOX))
1.169 vatton 4194: CSSParseError ("Invalid margin-top value", ptr, cssRule);
1.366 vatton 4195: else if (DoDialog)
4196: {
4197: if (All_sides)
4198: DisplayStyleValue ("margin", ptr, cssRule);
4199: else
4200: DisplayStyleValue ("margin-top", ptr, cssRule);
4201: }
1.168 vatton 4202: else if (DoApply)
1.295 vatton 4203: TtaSetStylePresentation (PRMarginTop, element, tsch, context, margin);
1.1 cvs 4204: return (cssRule);
4205: }
4206:
4207: /*----------------------------------------------------------------------
1.327 vatton 4208: ParseCSSMarginTop: parse a CSS margin-top attribute
1.296 vatton 4209: ----------------------------------------------------------------------*/
4210: static char *ParseCSSMarginTop (Element element, PSchema tsch,
1.327 vatton 4211: PresentationContext context,
4212: char *cssRule, CSSInfoPtr css,
4213: ThotBool isHTML)
1.296 vatton 4214: {
4215: char *ptr = cssRule;
4216:
4217: cssRule = ParseACSSMarginTop (element, tsch, context, ptr, css, isHTML);
4218: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid margin-top value");
4219: return (cssRule);
4220: }
4221:
4222: /*----------------------------------------------------------------------
4223: ParseACSSMarginBottom: parse a CSS margin-bottom attribute
1.1 cvs 4224: ----------------------------------------------------------------------*/
1.296 vatton 4225: static char *ParseACSSMarginBottom (Element element, PSchema tsch,
1.327 vatton 4226: PresentationContext context,
4227: char *cssRule, CSSInfoPtr css,
4228: ThotBool isHTML)
1.1 cvs 4229: {
4230: PresentationValue margin;
1.168 vatton 4231: char *ptr;
1.1 cvs 4232:
1.370 vatton 4233: margin.typed_data.real = FALSE;
1.82 cvs 4234: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 4235: ptr = cssRule;
1.1 cvs 4236: /* first parse the attribute string */
1.164 quint 4237: if (!strncasecmp (cssRule, "auto", 4))
4238: {
1.184 vatton 4239: margin.typed_data.unit = VALUE_AUTO;
1.164 quint 4240: margin.typed_data.value = 0;
1.288 vatton 4241: cssRule += 4;
1.164 quint 4242: }
1.404 vatton 4243: else if (!strncasecmp (cssRule, "inherit", 7))
4244: {
4245: margin.typed_data.unit = VALUE_AUTO;
4246: margin.typed_data.value = 0;
4247: cssRule += 7;
4248: }
1.164 quint 4249: else
1.168 vatton 4250: cssRule = ParseCSSUnit (cssRule, &margin);
1.295 vatton 4251:
1.387 quint 4252: if (margin.typed_data.unit == UNIT_INVALID ||
4253: (margin.typed_data.value != 0 &&
1.184 vatton 4254: margin.typed_data.unit == UNIT_BOX))
1.169 vatton 4255: CSSParseError ("Invalid margin-bottom value", ptr, cssRule);
1.366 vatton 4256: else if (DoDialog)
4257: DisplayStyleValue ("margin-bottom", ptr, cssRule);
1.168 vatton 4258: else if (DoApply)
1.295 vatton 4259: TtaSetStylePresentation (PRMarginBottom, element, tsch, context, margin);
1.1 cvs 4260: return (cssRule);
4261: }
4262:
4263: /*----------------------------------------------------------------------
1.296 vatton 4264: ParseCSSMarginBottom: parse a CSS margin-bottom attribute
4265: ----------------------------------------------------------------------*/
4266: static char *ParseCSSMarginBottom (Element element, PSchema tsch,
1.327 vatton 4267: PresentationContext context,
4268: char *cssRule, CSSInfoPtr css,
4269: ThotBool isHTML)
1.296 vatton 4270: {
4271: char *ptr = cssRule;
4272:
4273: cssRule = ParseACSSMarginBottom (element, tsch, context, ptr, css, isHTML);
4274: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid margin-bottom value");
4275: return (cssRule);
4276: }
4277:
4278: /*----------------------------------------------------------------------
4279: ParseACSSMarginLeft: parse a CSS margin-left attribute string
1.1 cvs 4280: ----------------------------------------------------------------------*/
1.296 vatton 4281: static char *ParseACSSMarginLeft (Element element, PSchema tsch,
1.327 vatton 4282: PresentationContext context,
4283: char *cssRule, CSSInfoPtr css,
4284: ThotBool isHTML)
1.1 cvs 4285: {
4286: PresentationValue margin;
1.168 vatton 4287: char *ptr;
1.1 cvs 4288:
1.370 vatton 4289: margin.typed_data.real = FALSE;
1.82 cvs 4290: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 4291: ptr = cssRule;
1.1 cvs 4292: /* first parse the attribute string */
1.164 quint 4293: if (!strncasecmp (cssRule, "auto", 4))
4294: {
1.184 vatton 4295: margin.typed_data.unit = VALUE_AUTO;
1.164 quint 4296: margin.typed_data.value = 0;
1.288 vatton 4297: cssRule += 4;
1.164 quint 4298: }
4299: else
1.168 vatton 4300: cssRule = ParseCSSUnit (cssRule, &margin);
1.295 vatton 4301:
1.387 quint 4302: if (margin.typed_data.unit == UNIT_INVALID ||
4303: (margin.typed_data.value != 0 &&
1.184 vatton 4304: margin.typed_data.unit == UNIT_BOX))
1.169 vatton 4305: CSSParseError ("Invalid margin-left value", ptr, cssRule);
1.366 vatton 4306: else if (DoDialog)
4307: DisplayStyleValue ("margin-left", ptr, cssRule);
1.295 vatton 4308: else if (DoApply && margin.typed_data.unit != UNIT_INVALID && DoApply)
1.327 vatton 4309: TtaSetStylePresentation (PRMarginLeft, element, tsch, context, margin);
1.1 cvs 4310: return (cssRule);
4311: }
4312:
4313: /*----------------------------------------------------------------------
1.296 vatton 4314: ParseCSSMarginBottom: parse a CSS margin-bottom attribute
4315: ----------------------------------------------------------------------*/
4316: static char *ParseCSSMarginLeft (Element element, PSchema tsch,
1.327 vatton 4317: PresentationContext context,
4318: char *cssRule, CSSInfoPtr css,
4319: ThotBool isHTML)
1.296 vatton 4320: {
4321: char *ptr = cssRule;
4322:
4323: cssRule = ParseACSSMarginLeft (element, tsch, context, ptr, css, isHTML);
4324: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid margin-left value");
4325: return (cssRule);
4326: }
4327:
4328:
4329: /*----------------------------------------------------------------------
4330: ParseACSSMarginRight: parse a CSS margin-right attribute string
1.1 cvs 4331: ----------------------------------------------------------------------*/
1.296 vatton 4332: static char *ParseACSSMarginRight (Element element, PSchema tsch,
1.327 vatton 4333: PresentationContext context,
4334: char *cssRule, CSSInfoPtr css,
4335: ThotBool isHTML)
1.1 cvs 4336: {
4337: PresentationValue margin;
1.168 vatton 4338: char *ptr;
1.1 cvs 4339:
1.370 vatton 4340: margin.typed_data.real = FALSE;
1.82 cvs 4341: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 4342: ptr = cssRule;
1.1 cvs 4343: /* first parse the attribute string */
1.164 quint 4344: if (!strncasecmp (cssRule, "auto", 4))
4345: {
1.184 vatton 4346: margin.typed_data.unit = VALUE_AUTO;
1.164 quint 4347: margin.typed_data.value = 0;
1.288 vatton 4348: cssRule += 4;
1.164 quint 4349: }
1.404 vatton 4350: else if (!strncasecmp (cssRule, "inherit", 7))
4351: {
4352: margin.typed_data.unit = VALUE_AUTO;
4353: margin.typed_data.value = 0;
4354: cssRule += 7;
4355: }
1.164 quint 4356: else
1.168 vatton 4357: cssRule = ParseCSSUnit (cssRule, &margin);
1.295 vatton 4358:
1.387 quint 4359: if (margin.typed_data.unit == UNIT_INVALID ||
4360: (margin.typed_data.value != 0 &&
1.184 vatton 4361: margin.typed_data.unit == UNIT_BOX))
1.169 vatton 4362: CSSParseError ("Invalid margin-right value", ptr, cssRule);
1.366 vatton 4363: else if (DoDialog)
4364: DisplayStyleValue ("margin-right", ptr, cssRule);
1.168 vatton 4365: else if (DoApply)
1.295 vatton 4366: TtaSetStylePresentation (PRMarginRight, element, tsch, context, margin);
1.1 cvs 4367: return (cssRule);
4368: }
4369:
4370: /*----------------------------------------------------------------------
1.296 vatton 4371: ParseCSSMarginRight: parse a CSS margin-right attribute string
4372: ----------------------------------------------------------------------*/
4373: static char *ParseCSSMarginRight (Element element, PSchema tsch,
1.327 vatton 4374: PresentationContext context,
4375: char *cssRule, CSSInfoPtr css,
4376: ThotBool isHTML)
1.296 vatton 4377: {
4378: char *ptr = cssRule;
4379:
1.297 vatton 4380: cssRule = ParseACSSMarginRight (element, tsch, context, ptr, css, isHTML);
1.296 vatton 4381: cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid margin-right value");
4382: return (cssRule);
4383: }
4384:
4385: /*----------------------------------------------------------------------
1.59 cvs 4386: ParseCSSMargin: parse a CSS margin attribute string
1.1 cvs 4387: ----------------------------------------------------------------------*/
1.79 cvs 4388: static char *ParseCSSMargin (Element element, PSchema tsch,
1.327 vatton 4389: PresentationContext context,
4390: char *cssRule, CSSInfoPtr css,
4391: ThotBool isHTML)
1.1 cvs 4392: {
1.79 cvs 4393: char *ptrT, *ptrR, *ptrB, *ptrL;
1.366 vatton 4394: int skippedNL, n;
1.1 cvs 4395:
1.82 cvs 4396: ptrT = SkipBlanksAndComments (cssRule);
1.366 vatton 4397: if (DoDialog)
4398: n = NumberOfValues (ptrT);
4399: if (DoDialog && n < 2)
1.1 cvs 4400: {
1.366 vatton 4401: // check if the margin dialog must be updated
4402: All_sides = TRUE;
4403: ptrR = ParseACSSMarginTop (element, tsch, context, ptrT, css, isHTML);
4404: All_sides = FALSE;
1.1 cvs 4405: }
4406: else
4407: {
1.366 vatton 4408: /* First parse Margin-Top */
4409: ptrR = ParseACSSMarginTop (element, tsch, context, ptrT, css, isHTML);
4410: ptrR = SkipBlanksAndComments (ptrR);
4411: if (*ptrR == ';' || *ptrR == '}' || *ptrR == EOS || *ptrR == ',')
1.327 vatton 4412: {
4413: skippedNL = NewLineSkipped;
1.366 vatton 4414: cssRule = ptrR;
4415: /* apply the Margin-Top to all */
4416: ptrR = ParseACSSMarginRight (element, tsch, context, ptrT, css, isHTML);
1.327 vatton 4417: NewLineSkipped = skippedNL;
1.366 vatton 4418: ptrR = ParseACSSMarginBottom (element, tsch, context, ptrT, css, isHTML);
4419: NewLineSkipped = skippedNL;
4420: ptrR = ParseACSSMarginLeft (element, tsch, context, ptrT, css, isHTML);
1.327 vatton 4421: }
1.1 cvs 4422: else
1.327 vatton 4423: {
1.366 vatton 4424: /* parse Margin-Right */
4425: ptrB = ParseACSSMarginRight (element, tsch, context, ptrR, css, isHTML);
4426: ptrB = SkipBlanksAndComments (ptrB);
4427: if (*ptrB == ';' || *ptrB == '}' || *ptrB == EOS || *ptrB == ',')
1.327 vatton 4428: {
1.366 vatton 4429: skippedNL = NewLineSkipped;
4430: cssRule = ptrB;
4431: /* apply the Margin-Top to Margin-Bottom */
4432: ptrB = ParseACSSMarginBottom (element, tsch, context, ptrT, css, isHTML);
4433: NewLineSkipped = skippedNL;
1.327 vatton 4434: /* apply the Margin-Right to Margin-Left */
1.366 vatton 4435: ptrB = ParseACSSMarginLeft (element, tsch, context, ptrR, css, isHTML);
1.327 vatton 4436: }
4437: else
1.366 vatton 4438: {
4439: /* parse Margin-Bottom */
4440: ptrL = ParseACSSMarginBottom (element, tsch, context, ptrB, css, isHTML);
4441: ptrL = SkipBlanksAndComments (ptrL);
4442: if (*ptrL == ';' || *ptrL == '}' || *ptrL == EOS || *ptrL == ',')
4443: {
4444: cssRule = ptrL;
4445: /* apply the Margin-Right to Margin-Left */
4446: ptrL = ParseACSSMarginLeft (element, tsch, context, ptrR, css, isHTML);
4447: }
4448: else
4449: /* parse Margin-Left */
4450: cssRule = ParseACSSMarginLeft (element, tsch, context, ptrL, css, isHTML);
4451: cssRule = SkipBlanksAndComments (cssRule);
4452: }
1.327 vatton 4453: }
1.1 cvs 4454: }
4455: return (cssRule);
4456: }
4457:
4458: /*----------------------------------------------------------------------
1.418 quint 4459: ParseCSSOpacity: parse a CSS opacity property
4460: ----------------------------------------------------------------------*/
4461: static char *ParseCSSOpacity (Element element, PSchema tsch,
4462: PresentationContext context, char *cssRule,
4463: CSSInfoPtr css, ThotBool isHTML)
4464: {
4465: PresentationValue opacity;
4466:
4467: opacity.typed_data.unit = UNIT_INVALID;
4468: opacity.typed_data.real = FALSE;
4469: if (!strncasecmp (cssRule, "inherit", 7))
4470: {
4471: opacity.typed_data.unit = VALUE_INHERIT;
4472: cssRule += 7;
4473: }
4474: else
4475: cssRule = ParseClampedUnit (cssRule, &opacity);
4476: if (DoApply)
4477: /* install the new presentation. */
4478: TtaSetStylePresentation (PROpacity, element, tsch, context, opacity);
4479: return (cssRule);
4480: }
4481:
4482: /*----------------------------------------------------------------------
1.327 vatton 4483: ParseCSSPaddingTop: parse a CSS PaddingTop attribute string
1.1 cvs 4484: ----------------------------------------------------------------------*/
1.79 cvs 4485: static char *ParseCSSPaddingTop (Element element, PSchema tsch,
1.327 vatton 4486: PresentationContext context,
4487: char *cssRule, CSSInfoPtr css,
4488: ThotBool isHTML)
1.1 cvs 4489: {
1.43 cvs 4490: PresentationValue padding;
1.168 vatton 4491: char *ptr;
1.370 vatton 4492:
4493: padding.typed_data.real = FALSE;
1.82 cvs 4494: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 4495: ptr = cssRule;
1.43 cvs 4496: /* first parse the attribute string */
4497: cssRule = ParseCSSUnit (cssRule, &padding);
1.295 vatton 4498:
1.387 quint 4499: if (padding.typed_data.unit == UNIT_INVALID ||
4500: (padding.typed_data.value != 0 &&
1.184 vatton 4501: padding.typed_data.unit == UNIT_BOX))
1.387 quint 4502: CSSParseError ("Invalid padding-top value", ptr, cssRule);
1.366 vatton 4503: else if (DoDialog)
4504: {
4505: if (All_sides)
4506: DisplayStyleValue ("padding", ptr, cssRule);
4507: else
4508: DisplayStyleValue ("padding-top", ptr, cssRule);
4509: }
1.168 vatton 4510: else if (DoApply)
1.295 vatton 4511: TtaSetStylePresentation (PRPaddingTop, element, tsch, context, padding);
1.1 cvs 4512: return (cssRule);
4513: }
4514:
4515: /*----------------------------------------------------------------------
1.59 cvs 4516: ParseCSSPaddingBottom: parse a CSS PaddingBottom attribute string
1.1 cvs 4517: ----------------------------------------------------------------------*/
1.79 cvs 4518: static char *ParseCSSPaddingBottom (Element element, PSchema tsch,
1.327 vatton 4519: PresentationContext context,
4520: char *cssRule, CSSInfoPtr css,
4521: ThotBool isHTML)
1.1 cvs 4522: {
1.43 cvs 4523: PresentationValue padding;
1.168 vatton 4524: char *ptr;
1.43 cvs 4525:
1.370 vatton 4526: padding.typed_data.real = FALSE;
1.82 cvs 4527: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 4528: ptr = cssRule;
1.43 cvs 4529: /* first parse the attribute string */
4530: cssRule = ParseCSSUnit (cssRule, &padding);
1.387 quint 4531: if (padding.typed_data.value == 0 && padding.typed_data.unit != UNIT_INVALID)
1.184 vatton 4532: padding.typed_data.unit = UNIT_EM;
1.295 vatton 4533:
1.387 quint 4534: if (padding.typed_data.unit == UNIT_INVALID ||
4535: (padding.typed_data.value != 0 &&
1.184 vatton 4536: padding.typed_data.unit == UNIT_BOX))
1.387 quint 4537: CSSParseError ("Invalid padding-bottom value", ptr, cssRule);
1.366 vatton 4538: else if (DoDialog)
4539: DisplayStyleValue ("padding-bottom", ptr, cssRule);
1.168 vatton 4540: else if (DoApply)
1.295 vatton 4541: TtaSetStylePresentation (PRPaddingBottom, element, tsch, context, padding);
1.1 cvs 4542: return (cssRule);
4543: }
4544:
4545: /*----------------------------------------------------------------------
1.59 cvs 4546: ParseCSSPaddingLeft: parse a CSS PaddingLeft attribute string.
1.1 cvs 4547: ----------------------------------------------------------------------*/
1.79 cvs 4548: static char *ParseCSSPaddingLeft (Element element, PSchema tsch,
1.327 vatton 4549: PresentationContext context,
4550: char *cssRule, CSSInfoPtr css,
4551: ThotBool isHTML)
1.1 cvs 4552: {
1.43 cvs 4553: PresentationValue padding;
1.168 vatton 4554: char *ptr;
1.43 cvs 4555:
1.370 vatton 4556: padding.typed_data.real = FALSE;
1.82 cvs 4557: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 4558: ptr = cssRule;
1.43 cvs 4559: /* first parse the attribute string */
4560: cssRule = ParseCSSUnit (cssRule, &padding);
1.387 quint 4561: if (padding.typed_data.value == 0 && padding.typed_data.unit != UNIT_INVALID)
1.184 vatton 4562: padding.typed_data.unit = UNIT_EM;
1.295 vatton 4563:
1.387 quint 4564: if (padding.typed_data.unit == UNIT_INVALID ||
4565: (padding.typed_data.value != 0 &&
1.184 vatton 4566: padding.typed_data.unit == UNIT_BOX))
1.168 vatton 4567: {
1.169 vatton 4568: CSSParseError ("Invalid padding-left value", ptr, cssRule);
1.168 vatton 4569: padding.typed_data.value = 0;
4570: }
1.366 vatton 4571: else if (DoDialog)
4572: DisplayStyleValue ("padding-left", ptr, cssRule);
1.168 vatton 4573: else if (DoApply)
1.295 vatton 4574: TtaSetStylePresentation (PRPaddingLeft, element, tsch, context, padding);
1.1 cvs 4575: return (cssRule);
4576: }
4577:
4578: /*----------------------------------------------------------------------
1.59 cvs 4579: ParseCSSPaddingRight: parse a CSS PaddingRight attribute string.
1.1 cvs 4580: ----------------------------------------------------------------------*/
1.79 cvs 4581: static char *ParseCSSPaddingRight (Element element, PSchema tsch,
1.327 vatton 4582: PresentationContext context,
4583: char *cssRule, CSSInfoPtr css,
4584: ThotBool isHTML)
1.1 cvs 4585: {
1.43 cvs 4586: PresentationValue padding;
1.168 vatton 4587: char *ptr;
1.43 cvs 4588:
1.370 vatton 4589: padding.typed_data.real = FALSE;
1.82 cvs 4590: cssRule = SkipBlanksAndComments (cssRule);
1.168 vatton 4591: ptr = cssRule;
1.43 cvs 4592: /* first parse the attribute string */
4593: cssRule = ParseCSSUnit (cssRule, &padding);
1.387 quint 4594: if (padding.typed_data.value == 0 && padding.typed_data.unit != UNIT_INVALID)
1.184 vatton 4595: padding.typed_data.unit = UNIT_EM;
1.295 vatton 4596:
1.387 quint 4597: if (padding.typed_data.unit == UNIT_INVALID ||
4598: (padding.typed_data.value != 0 &&
1.184 vatton 4599: padding.typed_data.unit == UNIT_BOX))
1.387 quint 4600: CSSParseError ("Invalid padding-right value", ptr, cssRule);
1.366 vatton 4601: else if (DoDialog)
4602: DisplayStyleValue ("padding-right", ptr, cssRule);
1.168 vatton 4603: else if (DoApply)
1.295 vatton 4604: TtaSetStylePresentation (PRPaddingRight, element, tsch, context, padding);
1.1 cvs 4605: return (cssRule);
4606: }
4607:
4608: /*----------------------------------------------------------------------
1.327 vatton 4609: ParseCSSPadding: parse a CSS padding attribute string.
1.1 cvs 4610: ----------------------------------------------------------------------*/
1.79 cvs 4611: static char *ParseCSSPadding (Element element, PSchema tsch,
1.327 vatton 4612: PresentationContext context,
4613: char *cssRule, CSSInfoPtr css,
4614: ThotBool isHTML)
1.1 cvs 4615: {
1.79 cvs 4616: char *ptrT, *ptrR, *ptrB, *ptrL;
1.366 vatton 4617: int skippedNL, n;
1.43 cvs 4618:
1.82 cvs 4619: ptrT = SkipBlanksAndComments (cssRule);
1.366 vatton 4620: if (DoDialog)
4621: n = NumberOfValues (ptrT);
4622: if (DoDialog && n < 2)
1.43 cvs 4623: {
1.366 vatton 4624: // check if the padding dialog must be updated
4625: All_sides = TRUE;
4626: ptrR = ParseCSSPaddingTop (element, tsch, context, ptrT, css, isHTML);
4627: All_sides = FALSE;
1.43 cvs 4628: }
4629: else
4630: {
1.366 vatton 4631: /* First parse Padding-Top */
4632: ptrR = ParseCSSPaddingTop (element, tsch, context, ptrT, css, isHTML);
4633: ptrR = SkipBlanksAndComments (ptrR);
4634: if (*ptrR == ';' || *ptrR == EOS || *ptrR == ',')
1.327 vatton 4635: {
4636: skippedNL = NewLineSkipped;
1.366 vatton 4637: cssRule = ptrR;
4638: /* apply the Padding-Top to all */
4639: ptrR = ParseCSSPaddingRight (element, tsch, context, ptrT, css, isHTML);
1.327 vatton 4640: NewLineSkipped = skippedNL;
1.366 vatton 4641: ptrR = ParseCSSPaddingBottom (element, tsch, context, ptrT, css, isHTML);
4642: NewLineSkipped = skippedNL;
4643: ptrR = ParseCSSPaddingLeft (element, tsch, context, ptrT, css, isHTML);
1.327 vatton 4644: }
1.43 cvs 4645: else
1.327 vatton 4646: {
1.366 vatton 4647: /* parse Padding-Right */
4648: ptrB = ParseCSSPaddingRight (element, tsch, context, ptrR, css, isHTML);
4649: ptrB = SkipBlanksAndComments (ptrB);
4650: if (*ptrB == ';' || *ptrB == EOS || *ptrB == ',')
1.327 vatton 4651: {
1.366 vatton 4652: skippedNL = NewLineSkipped;
4653: cssRule = ptrB;
4654: /* apply the Padding-Top to Padding-Bottom */
4655: ptrB = ParseCSSPaddingBottom (element, tsch, context, ptrT, css, isHTML);
4656: NewLineSkipped = skippedNL;
1.327 vatton 4657: /* apply the Padding-Right to Padding-Left */
1.366 vatton 4658: ptrB = ParseCSSPaddingLeft (element, tsch, context, ptrR, css, isHTML);
1.327 vatton 4659: }
4660: else
1.366 vatton 4661: {
4662: /* parse Padding-Bottom */
4663: ptrL = ParseCSSPaddingBottom (element, tsch, context, ptrB, css, isHTML);
4664: ptrL = SkipBlanksAndComments (ptrL);
4665: if (*ptrL == ';' || *ptrL == EOS || *ptrL == ',')
4666: {
4667: cssRule = ptrL;
4668: /* apply the Padding-Right to Padding-Left */
4669: ptrL = ParseCSSPaddingLeft (element, tsch, context, ptrR, css, isHTML);
4670: }
4671: else
4672: /* parse Padding-Left */
4673: cssRule = ParseCSSPaddingLeft (element, tsch, context, ptrL, css, isHTML);
4674: cssRule = SkipBlanksAndComments (cssRule);
4675: }
1.327 vatton 4676: }
1.43 cvs 4677: }
1.1 cvs 4678: return (cssRule);
4679: }
4680:
4681: /*----------------------------------------------------------------------
1.327 vatton 4682: ParseCSSForeground: parse a CSS foreground attribute
1.1 cvs 4683: ----------------------------------------------------------------------*/
1.79 cvs 4684: static char *ParseCSSForeground (Element element, PSchema tsch,
1.327 vatton 4685: PresentationContext context,
4686: char *cssRule,
4687: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 4688: {
1.425 quint 4689: ElementType elType;
1.117 vatton 4690: PresentationValue best;
1.262 vatton 4691: char *p;
1.1 cvs 4692:
1.370 vatton 4693: best.typed_data.real = FALSE;
1.366 vatton 4694: cssRule = SkipBlanksAndComments (cssRule);
1.262 vatton 4695: p = cssRule;
1.117 vatton 4696: cssRule = ParseCSSColor (cssRule, &best);
1.366 vatton 4697: if (best.typed_data.unit != UNIT_INVALID)
1.327 vatton 4698: {
4699: if (*cssRule != EOS && *cssRule !=';')
4700: {
4701: cssRule = SkipProperty (cssRule, FALSE);
1.366 vatton 4702: CSSParseError ("Invalid color value", p, cssRule);
1.327 vatton 4703: }
1.366 vatton 4704: else if (DoDialog)
4705: DisplayStyleValue ("color", p, cssRule);
4706: else if (DoApply)
1.327 vatton 4707: /* install the new presentation */
1.425 quint 4708: {
4709: elType = TtaGetElementType(element);
4710: if (!strcmp(TtaGetSSchemaName (elType.ElSSchema), "SVG"))
4711: /* we are working for an SVG element */
4712: TtaSetStylePresentation (PRColor, element, tsch, context, best);
4713: else
4714: TtaSetStylePresentation (PRForeground, element, tsch, context,best);
4715: }
1.327 vatton 4716: }
4717: return (cssRule);
1.1 cvs 4718: }
4719:
4720: /*----------------------------------------------------------------------
1.59 cvs 4721: ParseCSSBackgroundColor: parse a CSS background color attribute
1.1 cvs 4722: ----------------------------------------------------------------------*/
1.79 cvs 4723: static char *ParseCSSBackgroundColor (Element element, PSchema tsch,
1.327 vatton 4724: PresentationContext context,
4725: char *cssRule,
4726: CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 4727: {
4728: PresentationValue best;
1.366 vatton 4729: char *ptr;
1.1 cvs 4730:
1.370 vatton 4731: best.typed_data.real = FALSE;
1.366 vatton 4732: cssRule = SkipBlanksAndComments (cssRule);
4733: ptr = cssRule;
1.184 vatton 4734: best.typed_data.unit = UNIT_INVALID;
1.1 cvs 4735: best.typed_data.real = FALSE;
1.198 vatton 4736: if (!strncasecmp (cssRule, "transparent", 11))
1.1 cvs 4737: {
1.184 vatton 4738: best.typed_data.value = PATTERN_NONE;
4739: best.typed_data.unit = UNIT_REL;
1.295 vatton 4740: cssRule = SkipWord (cssRule);
1.116 vatton 4741: if (DoApply)
1.327 vatton 4742: TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
4743: }
1.1 cvs 4744: else
4745: {
4746: cssRule = ParseCSSColor (cssRule, &best);
1.366 vatton 4747: if (best.typed_data.unit != UNIT_INVALID)
1.327 vatton 4748: {
1.366 vatton 4749: if (DoDialog)
4750: DisplayStyleValue ("background-color", ptr, cssRule);
4751: else if (DoApply)
4752: {
4753: /* install the new presentation. */
4754: TtaSetStylePresentation (PRBackground, element, tsch, context, best);
4755: /* thot specificity: need to set fill pattern for background color */
4756: best.typed_data.value = PATTERN_BACKGROUND;
4757: best.typed_data.unit = UNIT_REL;
4758: TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
4759: best.typed_data.value = 1;
4760: best.typed_data.unit = UNIT_REL;
4761: TtaSetStylePresentation (PRShowBox, element, tsch, context, best);
4762: }
1.327 vatton 4763: }
1.1 cvs 4764: }
4765: return (cssRule);
4766: }
4767:
1.63 cvs 4768: /*----------------------------------------------------------------------
1.65 cvs 4769: ParseSVGStroke: parse a SVG stroke property
4770: ----------------------------------------------------------------------*/
1.79 cvs 4771: static char *ParseSVGStroke (Element element, PSchema tsch,
1.327 vatton 4772: PresentationContext context, char *cssRule,
4773: CSSInfoPtr css, ThotBool isHTML)
1.65 cvs 4774: {
1.428 quint 4775: PresentationValue best, color;
1.245 quint 4776: char *url;
1.65 cvs 4777:
1.184 vatton 4778: best.typed_data.unit = UNIT_INVALID;
1.65 cvs 4779: best.typed_data.real = FALSE;
1.82 cvs 4780: if (!strncasecmp (cssRule, "none", 4))
1.65 cvs 4781: {
4782: best.typed_data.value = -2; /* -2 means transparent */
1.184 vatton 4783: best.typed_data.unit = UNIT_REL;
1.65 cvs 4784: cssRule = SkipWord (cssRule);
4785: }
1.425 quint 4786: else if (!strncasecmp (cssRule, "inherit", 7))
1.245 quint 4787: {
1.293 quint 4788: best.typed_data.unit = VALUE_INHERIT;
4789: cssRule = SkipWord (cssRule);
1.245 quint 4790: }
1.425 quint 4791: else if (!strncasecmp (cssRule, "currentColor", 12))
4792: {
4793: best.typed_data.unit = VALUE_CURRENT;
4794: cssRule = SkipWord (cssRule);
4795: }
1.245 quint 4796: else if (!strncasecmp (cssRule, "url", 3))
4797: {
4798: cssRule += 3;
4799: cssRule = ParseCSSUrl (cssRule, &url);
4800: /* **** do something with the url ***** */;
4801: TtaFreeMemory (url);
1.428 quint 4802: /* a color property may follow the url */
4803: cssRule = SkipBlanksAndComments (cssRule);
4804: if (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS &&
4805: *cssRule != ',')
4806: /* we expect a color property here */
4807: {
4808: cssRule = ParseCSSColor (cssRule, &color);
4809: /* ***** do something with the color we have just parsed */
4810: }
1.245 quint 4811: }
1.65 cvs 4812: else
1.293 quint 4813: cssRule = ParseCSSColor (cssRule, &best);
4814:
4815: if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.295 vatton 4816: /* install the new presentation */
4817: TtaSetStylePresentation (PRForeground, element, tsch, context, best);
1.65 cvs 4818: return (cssRule);
4819: }
4820:
4821: /*----------------------------------------------------------------------
1.63 cvs 4822: ParseSVGFill: parse a SVG fill property
4823: ----------------------------------------------------------------------*/
1.79 cvs 4824: static char *ParseSVGFill (Element element, PSchema tsch,
1.327 vatton 4825: PresentationContext context, char *cssRule,
4826: CSSInfoPtr css, ThotBool isHTML)
1.63 cvs 4827: {
1.428 quint 4828: PresentationValue fill, color;
1.245 quint 4829: char *url;
1.429 quint 4830: int pattern;
1.63 cvs 4831:
1.426 quint 4832: url = NULL;
1.428 quint 4833: fill.typed_data.unit = UNIT_INVALID;
4834: fill.typed_data.real = FALSE;
1.429 quint 4835: pattern = PATTERN_BACKGROUND;
1.82 cvs 4836: if (!strncasecmp (cssRule, "none", 4))
1.63 cvs 4837: {
1.429 quint 4838: pattern = PATTERN_NONE;
4839: fill.typed_data.value = -2;
1.428 quint 4840: fill.typed_data.unit = UNIT_REL;
1.65 cvs 4841: cssRule = SkipWord (cssRule);
1.63 cvs 4842: }
1.425 quint 4843: else if (!strncasecmp (cssRule, "currentColor", 12))
4844: {
1.428 quint 4845: fill.typed_data.unit = VALUE_CURRENT;
1.425 quint 4846: cssRule = SkipWord (cssRule);
4847: }
1.245 quint 4848: else if (!strncasecmp (cssRule, "url", 3))
4849: {
4850: cssRule += 3;
4851: cssRule = ParseCSSUrl (cssRule, &url);
1.428 quint 4852: fill.typed_data.unit = VALUE_URL;
4853: fill.pointer = url;
4854: /* a color property may follow the url */
4855: cssRule = SkipBlanksAndComments (cssRule);
4856: if (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS &&
4857: *cssRule != ',')
4858: /* we expect a color property here */
4859: {
4860: cssRule = ParseCSSColor (cssRule, &color);
4861: /* @@@@@@ do something with the color we have just parsed */
4862: }
4863: }
4864: else if (!strncasecmp (cssRule, "inherit", 7))
4865: {
4866: fill.typed_data.unit = VALUE_INHERIT;
4867: cssRule = SkipWord (cssRule);
1.245 quint 4868: }
1.63 cvs 4869: else
1.428 quint 4870: cssRule = ParseCSSColor (cssRule, &fill);
1.293 quint 4871:
1.428 quint 4872: if (fill.typed_data.unit != UNIT_INVALID && DoApply)
1.63 cvs 4873: {
1.293 quint 4874: /* install the new presentation. */
1.428 quint 4875: TtaSetStylePresentation (PRBackground, element, tsch, context, fill);
1.426 quint 4876: if (url)
4877: TtaFreeMemory (url);
1.293 quint 4878: /* thot specificity: need to set fill pattern for background color */
1.429 quint 4879: fill.typed_data.value = pattern;
1.428 quint 4880: fill.typed_data.unit = UNIT_REL;
4881: TtaSetStylePresentation (PRFillPattern, element, tsch, context, fill);
1.63 cvs 4882: }
4883: return (cssRule);
4884: }
1.161 quint 4885:
1.155 cheyroul 4886: /*----------------------------------------------------------------------
1.424 quint 4887: ParseSVGStopColor: parse a SVG stop-color property
4888: ----------------------------------------------------------------------*/
4889: static char *ParseSVGStopColor (Element element, PSchema tsch,
4890: PresentationContext context, char *cssRule,
4891: CSSInfoPtr css, ThotBool isHTML)
4892: {
1.425 quint 4893: PresentationValue best;
4894:
4895: best.typed_data.unit = UNIT_INVALID;
4896: best.typed_data.real = FALSE;
4897: if (!strncasecmp (cssRule, "inherit", 7))
4898: {
4899: best.typed_data.unit = VALUE_INHERIT;
4900: cssRule = SkipWord (cssRule);
4901: }
4902: else if (!strncasecmp (cssRule, "currentColor", 12))
4903: {
4904: best.typed_data.unit = VALUE_CURRENT;
4905: cssRule = SkipWord (cssRule);
4906: }
4907: else
4908: cssRule = ParseCSSColor (cssRule, &best);
4909:
4910: if (best.typed_data.unit != UNIT_INVALID && DoApply)
4911: /* install the new presentation */
4912: TtaSetStylePresentation (PRStopColor, element, tsch, context, best);
4913: return (cssRule);
4914: }
4915:
4916: /*----------------------------------------------------------------------
1.427 quint 4917: ParseCSSColor: parse a CSS color attribute string
4918: we expect the input string describing the attribute to be
4919: either a color name, a 3 tuple or an hexadecimal encoding.
4920: The color used will be approximed from the current color
4921: table
4922: ----------------------------------------------------------------------*/
1.430 vatton 4923: static char *ParseSVGMarkerValue (char *cssRule, PresentationValue *val, char **url)
1.427 quint 4924: {
1.430 vatton 4925: *url = NULL;
1.427 quint 4926: val->typed_data.unit = UNIT_INVALID;
4927: val->typed_data.real = FALSE;
4928: if (!strncasecmp (cssRule, "none", 4))
4929: {
4930: val->typed_data.unit = UNIT_REL;
4931: val->typed_data.value = 0;
4932: cssRule += 4;
4933: }
4934: else if (!strncasecmp (cssRule, "inherit", 7))
4935: {
4936: val->typed_data.unit = VALUE_INHERIT;
4937: cssRule += 7;
4938: }
4939: else if (!strncasecmp (cssRule, "url", 3))
4940: {
4941: cssRule += 3;
1.430 vatton 4942: cssRule = ParseCSSUrl (cssRule, url);
1.427 quint 4943: val->typed_data.unit = VALUE_URL;
1.430 vatton 4944: val->pointer = *url;
1.427 quint 4945: }
4946: return cssRule;
4947: }
4948:
4949: /*----------------------------------------------------------------------
4950: ParseSVGMarker: parse a SVG marker property
4951: ----------------------------------------------------------------------*/
4952: static char *ParseSVGMarker (Element element, PSchema tsch,
4953: PresentationContext context, char *cssRule,
4954: CSSInfoPtr css, ThotBool isHTML)
4955: {
4956: PresentationValue marker;
4957: char *url;
4958:
4959: url = NULL;
1.430 vatton 4960: cssRule = ParseSVGMarkerValue (cssRule, &marker, &url);
1.427 quint 4961: if (marker.typed_data.unit != UNIT_INVALID && DoApply)
4962: /* install the new presentation. */
4963: TtaSetStylePresentation (PRMarker, element, tsch, context, marker);
4964: if (url)
4965: TtaFreeMemory (url);
4966: return (cssRule);
4967: }
4968:
4969: /*----------------------------------------------------------------------
4970: ParseSVGMarkerEnd: parse a SVG marker-end property
4971: ----------------------------------------------------------------------*/
4972: static char *ParseSVGMarkerEnd (Element element, PSchema tsch,
4973: PresentationContext context, char *cssRule,
4974: CSSInfoPtr css, ThotBool isHTML)
4975: {
4976: PresentationValue marker;
4977: char *url;
4978:
4979: url = NULL;
1.430 vatton 4980: cssRule = ParseSVGMarkerValue (cssRule, &marker, &url);
1.427 quint 4981: if (marker.typed_data.unit != UNIT_INVALID && DoApply)
4982: /* install the new presentation. */
4983: TtaSetStylePresentation (PRMarkerEnd, element, tsch, context, marker);
4984: if (url)
4985: TtaFreeMemory (url);
4986: return (cssRule);
4987: }
4988:
4989: /*----------------------------------------------------------------------
4990: ParseSVGMarkerMid: parse a SVG marker-mid property
4991: ----------------------------------------------------------------------*/
4992: static char *ParseSVGMarkerMid (Element element, PSchema tsch,
4993: PresentationContext context, char *cssRule,
4994: CSSInfoPtr css, ThotBool isHTML)
4995: {
4996: PresentationValue marker;
4997: char *url;
4998:
4999: url = NULL;
1.430 vatton 5000: cssRule = ParseSVGMarkerValue (cssRule, &marker, &url);
1.427 quint 5001: if (marker.typed_data.unit != UNIT_INVALID && DoApply)
5002: /* install the new presentation. */
5003: TtaSetStylePresentation (PRMarkerMid, element, tsch, context, marker);
5004: if (url)
5005: TtaFreeMemory (url);
5006: return (cssRule);
5007: }
5008:
5009: /*----------------------------------------------------------------------
5010: ParseSVGMarkerStart: parse a SVG marker-start property
5011: ----------------------------------------------------------------------*/
5012: static char *ParseSVGMarkerStart (Element element, PSchema tsch,
5013: PresentationContext context, char *cssRule,
5014: CSSInfoPtr css, ThotBool isHTML)
5015: {
5016: PresentationValue marker;
5017: char *url;
5018:
5019: url = NULL;
1.430 vatton 5020: cssRule = ParseSVGMarkerValue (cssRule, &marker, &url);
1.427 quint 5021: if (marker.typed_data.unit != UNIT_INVALID && DoApply)
5022: /* install the new presentation. */
5023: TtaSetStylePresentation (PRMarkerStart, element, tsch, context, marker);
5024: if (url)
5025: TtaFreeMemory (url);
5026: return (cssRule);
5027: }
5028:
5029: /*----------------------------------------------------------------------
1.425 quint 5030: ParseSVGStopOpacity: parse a SVG opacity property
5031: ----------------------------------------------------------------------*/
5032: static char *ParseSVGStopOpacity (Element element, PSchema tsch,
5033: PresentationContext context, char *cssRule,
5034: CSSInfoPtr css, ThotBool isHTML)
5035: {
5036: PresentationValue opacity;
5037:
5038: opacity.typed_data.unit = UNIT_INVALID;
5039: opacity.typed_data.real = FALSE;
5040: if (!strncasecmp (cssRule, "inherit", 7))
5041: {
5042: opacity.typed_data.unit = VALUE_INHERIT;
5043: cssRule += 7;
5044: }
5045: else
5046: cssRule = ParseClampedUnit (cssRule, &opacity);
5047: if (opacity.typed_data.unit != UNIT_INVALID && DoApply)
5048: /* install the new presentation. */
5049: TtaSetStylePresentation (PRStopOpacity, element, tsch, context, opacity);
1.424 quint 5050: return (cssRule);
5051: }
5052:
5053: /*----------------------------------------------------------------------
1.346 quint 5054: ParseSVGOpacity: parse a SVG opacity property
1.155 cheyroul 5055: ----------------------------------------------------------------------*/
5056: static char *ParseSVGOpacity (Element element, PSchema tsch,
1.327 vatton 5057: PresentationContext context, char *cssRule,
5058: CSSInfoPtr css, ThotBool isHTML)
1.155 cheyroul 5059: {
1.425 quint 5060: PresentationValue opacity;
1.63 cvs 5061:
1.425 quint 5062: opacity.typed_data.unit = UNIT_INVALID;
5063: opacity.typed_data.real = FALSE;
5064: if (!strncasecmp (cssRule, "inherit", 7))
5065: {
5066: opacity.typed_data.unit = VALUE_INHERIT;
5067: cssRule += 7;
5068: }
5069: else
5070: cssRule = ParseClampedUnit (cssRule, &opacity);
5071: if (opacity.typed_data.unit != UNIT_INVALID && DoApply)
1.295 vatton 5072: /* install the new presentation. */
1.425 quint 5073: TtaSetStylePresentation (PROpacity, element, tsch, context, opacity);
1.155 cheyroul 5074: return (cssRule);
5075: }
1.346 quint 5076:
1.170 cheyroul 5077: /*----------------------------------------------------------------------
1.346 quint 5078: ParseSVGStrokeOpacity: parse a SVG stroke-opacity property
1.170 cheyroul 5079: ----------------------------------------------------------------------*/
5080: static char *ParseSVGStrokeOpacity (Element element, PSchema tsch,
1.327 vatton 5081: PresentationContext context, char *cssRule,
5082: CSSInfoPtr css, ThotBool isHTML)
1.170 cheyroul 5083: {
1.425 quint 5084: PresentationValue opacity;
1.161 quint 5085:
1.425 quint 5086: opacity.typed_data.unit = UNIT_INVALID;
5087: opacity.typed_data.real = FALSE;
5088: if (!strncasecmp (cssRule, "inherit", 7))
5089: {
5090: opacity.typed_data.unit = VALUE_INHERIT;
5091: cssRule += 7;
5092: }
5093: else
5094: cssRule = ParseClampedUnit (cssRule, &opacity);
5095: if (opacity.typed_data.unit != UNIT_INVALID && DoApply)
1.295 vatton 5096: /* install the new presentation. */
1.425 quint 5097: TtaSetStylePresentation (PRStrokeOpacity, element, tsch, context, opacity);
1.170 cheyroul 5098: return (cssRule);
5099: }
1.346 quint 5100:
1.170 cheyroul 5101: /*----------------------------------------------------------------------
1.420 vatton 5102: ParseSVGFillOpacity: parse a SVG fill-opacityl property
1.170 cheyroul 5103: ----------------------------------------------------------------------*/
5104: static char *ParseSVGFillOpacity (Element element, PSchema tsch,
1.327 vatton 5105: PresentationContext context, char *cssRule,
5106: CSSInfoPtr css, ThotBool isHTML)
1.170 cheyroul 5107: {
1.425 quint 5108: PresentationValue opacity;
1.170 cheyroul 5109:
1.425 quint 5110: opacity.typed_data.unit = UNIT_INVALID;
5111: opacity.typed_data.real = FALSE;
5112: if (!strncasecmp (cssRule, "inherit", 7))
5113: {
5114: opacity.typed_data.unit = VALUE_INHERIT;
5115: cssRule += 7;
5116: }
5117: else
5118: cssRule = ParseClampedUnit (cssRule, &opacity);
5119: if (opacity.typed_data.unit != UNIT_INVALID && DoApply)
1.295 vatton 5120: /* install the new presentation. */
1.425 quint 5121: TtaSetStylePresentation (PRFillOpacity, element, tsch, context, opacity);
1.170 cheyroul 5122: return (cssRule);
5123: }
1.207 vatton 5124:
1.1 cvs 5125: /*----------------------------------------------------------------------
1.420 vatton 5126: ParseSVGFillRule: parse a SVG fill-rule property
5127: ----------------------------------------------------------------------*/
5128: static char *ParseSVGFillRule (Element element, PSchema tsch,
5129: PresentationContext context, char *cssRule,
5130: CSSInfoPtr css, ThotBool isHTML)
5131: {
5132: PresentationValue best;
5133:
5134: best.typed_data.unit = UNIT_INVALID;
5135: best.typed_data.real = FALSE;
5136: if (!strncasecmp (cssRule, "inherit", 7))
5137: {
5138: best.typed_data.unit = VALUE_INHERIT;
5139: best.typed_data.value = 0;
5140: cssRule = SkipWord (cssRule);
5141: }
5142: else if (!strncasecmp (cssRule, "nonzero", 7))
5143: {
5144: best.typed_data.unit = VALUE_AUTO;
1.421 quint 5145: best.typed_data.value = NonZero;
1.420 vatton 5146: cssRule = SkipWord (cssRule);
5147: }
5148: else if (!strncasecmp (cssRule, "evenodd", 7))
5149: {
5150: best.typed_data.unit = VALUE_AUTO;
1.421 quint 5151: best.typed_data.value = EvenOdd;
1.420 vatton 5152: cssRule = SkipWord (cssRule);
5153: }
5154:
5155: if (DoApply)
5156: /* install the new presentation. */
5157: TtaSetStylePresentation (PRFillRule, element, tsch, context, best);
5158: return (cssRule);
5159: }
5160:
5161: /*----------------------------------------------------------------------
1.327 vatton 5162: GetCSSBackgroundURL searches a CSS BackgroundImage url within
5163: the cssRule.
5164: Returns NULL or a new allocated url string.
1.217 vatton 5165: ----------------------------------------------------------------------*/
5166: char *GetCSSBackgroundURL (char *cssRule)
5167: {
5168: char *b, *url;
5169:
5170: url = NULL;
5171: b = strstr (cssRule, "url");
5172: if (b)
1.290 gully 5173: b = ParseCSSUrl (b, &url);
1.217 vatton 5174: return (url);
5175: }
5176:
5177: /*----------------------------------------------------------------------
1.327 vatton 5178: ParseCSSContent: parse the value of property "content"
1.217 vatton 5179: ----------------------------------------------------------------------*/
5180: static char *ParseCSSContent (Element element, PSchema tsch,
1.327 vatton 5181: PresentationContext ctxt, char *cssRule,
5182: CSSInfoPtr css, ThotBool isHTML)
1.217 vatton 5183: {
1.436 ! quint 5184: PresentationValue value, pval;
1.353 quint 5185: char *last, *start, quoteChar, savedChar;
5186: int length, val;
1.366 vatton 5187: char *buffer, *p;
5188: char *start_value;
1.434 quint 5189: wchar_t wc;
5190: ThotBool repeat, done;
1.312 quint 5191:
5192: value.typed_data.unit = UNIT_REL;
5193: value.typed_data.real = FALSE;
5194: value.typed_data.value = 0;
1.366 vatton 5195: if (!DoDialog && DoApply)
1.347 quint 5196: TtaSetStylePresentation (PRContent, element, tsch, ctxt, value);
1.217 vatton 5197: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 5198: start_value = cssRule;
1.312 quint 5199: repeat = TRUE;
5200: while (repeat)
5201: {
1.366 vatton 5202: p = cssRule;
1.312 quint 5203: if (!strncasecmp (cssRule, "normal", 6))
1.327 vatton 5204: /* The pseudo-element is not generated */
5205: {
5206: /* @@@@@@ */
5207: cssRule += 6;
5208: repeat = FALSE;
5209: }
1.331 quint 5210: else if (!strncasecmp (cssRule, "none", 4))
5211: /* The pseudo-element is not generated */
5212: {
5213: /* @@@@@@ */
5214: cssRule += 4;
5215: repeat = FALSE;
5216: }
1.312 quint 5217: else if (*cssRule == '"' || *cssRule == '\'')
1.327 vatton 5218: /* It's a string */
5219: {
5220: quoteChar = *cssRule;
1.353 quint 5221: /* how long is the string? */
5222: last = cssRule;
5223: last = SkipString (last);
5224: length = last - cssRule;
5225: /* get a buffer to store the string */
1.434 quint 5226: buffer = (char *)TtaGetMemory (3 * length);
1.353 quint 5227: p = buffer; /* beginning of the string */
1.327 vatton 5228: cssRule++;
5229: while (*cssRule != EOS && *cssRule != quoteChar)
1.353 quint 5230: {
1.434 quint 5231: done = FALSE;
1.353 quint 5232: if (*cssRule == '\\')
5233: {
5234: cssRule++; /* skip the backslash */
5235: if ((*cssRule >= '0' && *cssRule <= '9') ||
5236: (*cssRule >= 'A' && *cssRule <= 'F') ||
5237: (*cssRule >= 'a' && *cssRule <= 'f'))
5238: {
5239: start = cssRule; /* first hex digit after the backslash*/
5240: cssRule++;
5241: while ((*cssRule >= '0' && *cssRule <= '9') ||
5242: (*cssRule >= 'A' && *cssRule <= 'F') ||
5243: (*cssRule >= 'a' && *cssRule <= 'f'))
5244: cssRule++;
5245: savedChar = *cssRule;
5246: *cssRule = EOS;
5247: sscanf (start, "%x", &val);
1.366 vatton 5248: TtaWCToMBstring ((wchar_t) val, (unsigned char **) &p);
1.353 quint 5249: *cssRule = savedChar;
1.434 quint 5250: done = TRUE;
1.353 quint 5251: }
5252: }
1.434 quint 5253: if (!done)
1.353 quint 5254: {
1.434 quint 5255: /* The default encoding of CSS style sheets is ISO-8859-1,
5256: but we should use the real encoding fo the file instead
5257: of this default value @@@@@ */
5258: wc = TtaGetWCFromChar ((unsigned char) cssRule[0], ISO_8859_1);
5259: TtaWCToMBstring (wc, (unsigned char **) &p);
5260: cssRule++;
1.353 quint 5261: }
5262: }
5263: *p = EOS;
1.366 vatton 5264: if (DoDialog)
5265: {
5266: DisplayStyleValue ("", start_value, p);
5267: start_value = p;
5268: }
5269: else if (*cssRule != quoteChar)
1.327 vatton 5270: cssRule = SkipProperty (cssRule, FALSE);
5271: else
5272: {
5273: *cssRule = EOS;
5274: value.typed_data.unit = UNIT_REL;
5275: value.typed_data.real = FALSE;
1.353 quint 5276: value.pointer = buffer;
1.347 quint 5277: if (DoApply)
5278: TtaSetStylePresentation (PRContentString, element, tsch, ctxt,
5279: value);
1.327 vatton 5280: *cssRule = quoteChar;
5281: cssRule++;
5282: }
1.353 quint 5283: TtaFreeMemory (buffer);
1.327 vatton 5284: }
1.312 quint 5285: else if (!strncasecmp (cssRule, "url", 3))
1.327 vatton 5286: {
5287: cssRule += 3;
1.347 quint 5288: cssRule = SetCSSImage (element, tsch, ctxt, cssRule, css,
5289: PRContentURL);
1.366 vatton 5290: if (DoDialog)
5291: {
5292: DisplayStyleValue ("", start_value, p);
5293: start_value = p;
5294: }
1.327 vatton 5295: }
1.312 quint 5296: else if (!strncasecmp (cssRule, "counter", 7))
1.327 vatton 5297: {
1.436 ! quint 5298: value.pointer = NULL;
1.327 vatton 5299: cssRule += 7;
1.436 ! quint 5300: cssRule = SkipBlanksAndComments (cssRule);
! 5301: if (*cssRule == '(')
! 5302: {
! 5303: cssRule++;
! 5304: cssRule = SkipBlanksAndComments (cssRule);
! 5305: start = cssRule;
! 5306: while (*cssRule != EOS && *cssRule != ')' && *cssRule != ',')
! 5307: cssRule++;
! 5308: if (*cssRule != ')' && *cssRule != ',')
! 5309: cssRule = start;
! 5310: else
! 5311: {
! 5312: /* remove extra spaces */
! 5313: last = cssRule;
! 5314: while (last[-1] == SPACE || last[-1] == TAB)
! 5315: last--;
! 5316: savedChar = *last;
! 5317: *last = EOS;
! 5318: value.pointer = start;
! 5319: if (DoDialog)
! 5320: {
! 5321: DisplayStyleValue ("", start_value, p);
! 5322: start_value = p;
! 5323: }
! 5324: else if (DoApply)
! 5325: TtaSetStylePresentation (PRContentCounter, element, tsch,
! 5326: ctxt, value);
! 5327: *last = savedChar;
! 5328: if (*cssRule == ',')
! 5329: /* parse the counter style */
! 5330: {
! 5331: cssRule++;
! 5332: cssRule = ParseCounterStyle (cssRule, &pval, start_value);
! 5333: cssRule = SkipBlanksAndComments (cssRule);
! 5334: if (*cssRule == ')')
! 5335: {
! 5336: cssRule++;
! 5337: TtaSetStylePresentation (PRContentCounterStyle,
! 5338: element, tsch, ctxt, pval);
! 5339: }
! 5340: }
! 5341: }
! 5342: }
! 5343: if (value.pointer == NULL)
1.366 vatton 5344: {
1.436 ! quint 5345: CSSParseError ("Invalid content value", (char*) p, cssRule);
! 5346: if (DoDialog)
! 5347: {
! 5348: DisplayStyleValue ("", start_value, p);
! 5349: start_value = p;
! 5350: }
! 5351: else
! 5352: cssRule = SkipProperty (cssRule, FALSE);
1.366 vatton 5353: }
1.436 ! quint 5354: cssRule++;
1.327 vatton 5355: }
1.312 quint 5356: else if (!strncasecmp (cssRule, "counters", 8))
1.327 vatton 5357: {
5358: cssRule += 8;
5359: /* @@@@@@ */
1.366 vatton 5360: if (DoDialog)
5361: {
5362: DisplayStyleValue ("", start_value, p);
5363: start_value = p;
5364: }
5365: else
1.436 ! quint 5366: {
! 5367: cssRule = SkipProperty (cssRule, FALSE);
! 5368: }
1.327 vatton 5369: }
1.312 quint 5370: else if (!strncasecmp (cssRule, "attr", 4))
1.327 vatton 5371: {
1.347 quint 5372: value.pointer = NULL;
1.327 vatton 5373: cssRule += 4;
1.347 quint 5374: cssRule = SkipBlanksAndComments (cssRule);
5375: if (*cssRule == '(')
5376: {
5377: cssRule++;
5378: cssRule = SkipBlanksAndComments (cssRule);
5379: start = cssRule;
5380: while (*cssRule != EOS && *cssRule != ')')
5381: cssRule++;
5382: if (*cssRule != ')')
5383: cssRule = start;
5384: else
5385: {
5386: last = cssRule;
5387: /* remove extra spaces */
1.436 ! quint 5388: while (last[-1] == SPACE || last[-1] == TAB)
! 5389: last--;
1.347 quint 5390: savedChar = *last;
5391: *last = EOS;
5392: value.typed_data.unit = UNIT_REL;
5393: value.typed_data.real = FALSE;
5394: value.pointer = start;
1.366 vatton 5395: if (DoDialog)
5396: {
5397: DisplayStyleValue ("", start_value, p);
5398: start_value = p;
5399: }
5400: else if (DoApply)
1.347 quint 5401: TtaSetStylePresentation (PRContentAttr, element, tsch,
5402: ctxt, value);
5403: *last = savedChar;
5404: }
5405: }
5406: if (value.pointer == NULL)
5407: {
1.353 quint 5408: CSSParseError ("Invalid content value", (char*) p, cssRule);
1.366 vatton 5409: if (DoDialog)
5410: {
5411: DisplayStyleValue ("", start_value, p);
5412: start_value = p;
5413: }
5414: else
5415: cssRule = SkipProperty (cssRule, FALSE);
1.347 quint 5416: }
5417: cssRule++;
1.327 vatton 5418: }
1.312 quint 5419: else if (!strncasecmp (cssRule, "open-quote", 10))
1.327 vatton 5420: {
5421: cssRule += 10;
5422: /* @@@@@@ */
5423: }
1.312 quint 5424: else if (!strncasecmp (cssRule, "close-quote", 11))
1.327 vatton 5425: {
5426: cssRule += 11;
5427: /* @@@@@@ */
5428: }
1.312 quint 5429: else if (!strncasecmp (cssRule, "no-open-quote", 13))
1.327 vatton 5430: {
5431: cssRule += 13;
5432: /* @@@@@@ */
5433: }
1.312 quint 5434: else if (!strncasecmp (cssRule, "no-close-quote", 14))
1.327 vatton 5435: {
5436: cssRule += 14;
5437: /* @@@@@@ */
5438: }
1.312 quint 5439: else if (!strncasecmp (cssRule, "inherit", 7))
1.327 vatton 5440: {
5441: cssRule += 7;
5442: /* @@@@@@ */
5443: repeat = FALSE;
5444: }
1.312 quint 5445: else
1.327 vatton 5446: {
1.353 quint 5447: CSSParseError ("Invalid content value", (char*) p, cssRule);
1.366 vatton 5448: if (DoDialog)
5449: {
5450: DisplayStyleValue ("", start_value, p);
5451: start_value = p;
5452: }
5453: else
5454: cssRule = SkipProperty (cssRule, FALSE);
1.327 vatton 5455: }
1.312 quint 5456: cssRule = SkipBlanksAndComments (cssRule);
5457: if (repeat)
1.327 vatton 5458: if (*cssRule == ';' || *cssRule == '}' || *cssRule == EOS ||
5459: *cssRule == '!')
5460: repeat = FALSE;
1.217 vatton 5461: }
5462: return (cssRule);
5463: }
1.1 cvs 5464:
5465: /*----------------------------------------------------------------------
1.436 ! quint 5466: ParseCSSCounterOp: parse a CSS counter operation (increment or reset,
! 5467: depending on type).
! 5468: ----------------------------------------------------------------------*/
! 5469: static char *ParseCSSCounterOp (Element element, PSchema tsch,
! 5470: PresentationContext ctxt,
! 5471: char *cssRule, unsigned int type)
! 5472: {
! 5473: PresentationValue pval;
! 5474: char *start, *start_value, *p, *buff;
! 5475: char saved;
! 5476:
! 5477: cssRule = SkipBlanksAndComments (cssRule);
! 5478: if (!strncasecmp (cssRule, "inherit", 7))
! 5479: {
! 5480: pval.typed_data.unit = VALUE_INHERIT;
! 5481: cssRule += 7;
! 5482: /* @@@@ do something */
! 5483: }
! 5484: else if (!strncasecmp (cssRule, "none", 4))
! 5485: {
! 5486: pval.typed_data.value = 0;
! 5487: cssRule += 4;
! 5488: /* @@@@ do something */
! 5489: }
! 5490: else
! 5491: {
! 5492: start_value = cssRule;
! 5493: /* there may be multiple counter names (each possibly followed by an
! 5494: integer) */
! 5495: do
! 5496: {
! 5497: p = cssRule;
! 5498: /* name of a counter */
! 5499: start = cssRule;
! 5500: cssRule = SkipWord (cssRule);
! 5501: saved = *cssRule;
! 5502: *cssRule = EOS;
! 5503: buff = TtaStrdup (start);
! 5504: *cssRule = saved;
! 5505: pval.pointer = buff;
! 5506: /* set default value of parameter */
! 5507: if (type == PRCounterReset)
! 5508: pval.data = 0;
! 5509: else if (type == PRCounterIncrement)
! 5510: pval.data = 1;
! 5511: /* use the actual value of parameter (integer) if it is specified */
! 5512: cssRule = ParseNumber (cssRule, &pval);
! 5513: if (pval.typed_data.unit != UNIT_INVALID)
! 5514: /* there is an integer, the value of the parameter */
! 5515: {
! 5516: pval.data = pval.typed_data.value;
! 5517: cssRule = SkipBlanksAndComments (cssRule);
! 5518: }
! 5519: if (DoDialog)
! 5520: {
! 5521: DisplayStyleValue ("", start_value, p);
! 5522: start_value = p;
! 5523: }
! 5524: else if (DoApply)
! 5525: TtaSetStylePresentation (type, element, tsch, ctxt, pval);
! 5526: TtaFreeMemory (buff);
! 5527: }
! 5528: while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS &&
! 5529: *cssRule != ',');
! 5530: }
! 5531: cssRule = SkipBlanksAndComments (cssRule);
! 5532: return (cssRule);
! 5533: }
! 5534:
! 5535: /*----------------------------------------------------------------------
! 5536: ParseCSSCounterIncrement: parse a CSS counter-increment property
! 5537: ----------------------------------------------------------------------*/
! 5538: static char *ParseCSSCounterIncrement (Element element, PSchema tsch,
! 5539: PresentationContext ctxt,
! 5540: char *cssRule, CSSInfoPtr css,
! 5541: ThotBool isHTML)
! 5542: {
! 5543: return ParseCSSCounterOp (element, tsch, ctxt, cssRule, PRCounterIncrement);
! 5544: }
! 5545:
! 5546: /*----------------------------------------------------------------------
! 5547: ParseCSSCounterReset: parse a CSS counter-reset property
! 5548: ----------------------------------------------------------------------*/
! 5549: static char *ParseCSSCounterReset (Element element, PSchema tsch,
! 5550: PresentationContext ctxt,
! 5551: char *cssRule, CSSInfoPtr css,
! 5552: ThotBool isHTML)
! 5553: {
! 5554: return ParseCSSCounterOp (element, tsch, ctxt, cssRule, PRCounterReset);
! 5555: }
! 5556:
! 5557: /*----------------------------------------------------------------------
1.59 cvs 5558: ParseCSSBackgroundImage: parse a CSS BackgroundImage attribute string.
1.1 cvs 5559: ----------------------------------------------------------------------*/
1.79 cvs 5560: static char *ParseCSSBackgroundImage (Element element, PSchema tsch,
1.327 vatton 5561: PresentationContext ctxt,
5562: char *cssRule, CSSInfoPtr css,
5563: ThotBool isHTML)
1.1 cvs 5564: {
1.49 cvs 5565: PresentationValue image, value;
1.357 quint 5566: char *ptr;
1.148 vatton 5567:
1.370 vatton 5568: image.typed_data.real = FALSE;
5569: value.typed_data.real = FALSE;
1.82 cvs 5570: cssRule = SkipBlanksAndComments (cssRule);
1.357 quint 5571: ptr = cssRule;
1.161 quint 5572: if (!strncasecmp (cssRule, "none", 4))
5573: {
1.260 vatton 5574: cssRule += 4;
1.366 vatton 5575: if (DoDialog)
5576: DisplayStyleValue ("background-image", ptr, cssRule);
5577: else if (DoApply)
1.327 vatton 5578: {
5579: /* no background image */
5580: image.pointer = NULL;
5581: TtaSetStylePresentation (PRBackgroundPicture, element, tsch, ctxt,
5582: image);
5583: }
1.161 quint 5584: }
1.357 quint 5585: else if (!strncasecmp (cssRule, "inherit", 7))
5586: {
5587: value.typed_data.unit = VALUE_INHERIT;
5588: cssRule += 7;
1.366 vatton 5589: if (DoDialog)
5590: DisplayStyleValue ("background-image", ptr, cssRule);
1.357 quint 5591: }
1.161 quint 5592: else if (!strncasecmp (cssRule, "url", 3))
1.1 cvs 5593: {
5594: cssRule += 3;
1.302 quint 5595: cssRule = SetCSSImage (element, tsch, ctxt, cssRule, css,
1.327 vatton 5596: PRBackgroundPicture);
1.207 vatton 5597: if (ctxt->destroy)
1.327 vatton 5598: if (TtaGetStylePresentation (PRFillPattern, element, tsch, ctxt,
5599: &value) < 0)
5600: {
5601: /* there is no FillPattern rule -> remove ShowBox rule */
5602: value.typed_data.value = 1;
5603: value.typed_data.unit = UNIT_REL;
5604: value.typed_data.real = FALSE;
5605: TtaSetStylePresentation (PRShowBox, element, tsch, ctxt, value);
5606: }
1.18 cvs 5607: }
1.357 quint 5608: else
5609: {
5610: cssRule = SkipWord (cssRule);
5611: CSSParseError ("Invalid background-image value", ptr, cssRule);
5612: cssRule = SkipProperty (cssRule, FALSE);
5613: }
1.18 cvs 5614: return (cssRule);
5615: }
5616:
5617: /*----------------------------------------------------------------------
1.295 vatton 5618: ParseACSSBackgroundRepeat: parse a CSS BackgroundRepeat attribute string.
1.18 cvs 5619: ----------------------------------------------------------------------*/
1.295 vatton 5620: static char *ParseACSSBackgroundRepeat (Element element, PSchema tsch,
1.327 vatton 5621: PresentationContext ctxt,
5622: char *cssRule, CSSInfoPtr css, ThotBool isHTML)
1.18 cvs 5623: {
5624: PresentationValue repeat;
1.366 vatton 5625: char *start_value;
1.18 cvs 5626:
1.366 vatton 5627: cssRule = SkipBlanksAndComments (cssRule);
5628: start_value = cssRule;
1.184 vatton 5629: repeat.typed_data.value = REALSIZE;
1.191 vatton 5630: repeat.typed_data.unit = UNIT_BOX;
1.18 cvs 5631: repeat.typed_data.real = FALSE;
1.82 cvs 5632: cssRule = SkipBlanksAndComments (cssRule);
5633: if (!strncasecmp (cssRule, "no-repeat", 9))
1.184 vatton 5634: repeat.typed_data.value = REALSIZE;
1.82 cvs 5635: else if (!strncasecmp (cssRule, "repeat-y", 8))
1.265 vatton 5636: repeat.typed_data.value = YREPEAT;
1.82 cvs 5637: else if (!strncasecmp (cssRule, "repeat-x", 8))
1.265 vatton 5638: repeat.typed_data.value = XREPEAT;
1.82 cvs 5639: else if (!strncasecmp (cssRule, "repeat", 6))
1.184 vatton 5640: repeat.typed_data.value = REPEAT;
1.18 cvs 5641: else
5642: return (cssRule);
5643:
1.295 vatton 5644: cssRule = SkipWord (cssRule);
5645: /* check if it's an important rule */
1.366 vatton 5646: if (DoDialog)
5647: DisplayStyleValue ("background-repeat", start_value, cssRule);
5648: else if (DoApply)
1.295 vatton 5649: /* install the new presentation */
1.362 quint 5650: TtaSetStylePresentation (PRBackgroundRepeat, element, tsch, ctxt, repeat);
1.295 vatton 5651: return (cssRule);
5652: }
5653:
5654: /*----------------------------------------------------------------------
5655: ParseCSSBackgroundRepeat: parse a CSS BackgroundRepeat attribute string.
5656: ----------------------------------------------------------------------*/
5657: static char *ParseCSSBackgroundRepeat (Element element, PSchema tsch,
1.315 gully 5658: PresentationContext ctxt,
5659: char *cssRule, CSSInfoPtr css,
5660: ThotBool isHTML)
1.295 vatton 5661: {
1.388 carcone 5662:
5663: char *ptr;
5664:
5665: ptr = cssRule;
1.295 vatton 5666: cssRule = ParseACSSBackgroundRepeat (element, tsch, ctxt,
1.315 gully 5667: cssRule, css, isHTML);
1.388 carcone 5668:
5669: if (ptr == cssRule)
1.117 vatton 5670: {
1.295 vatton 5671: cssRule = SkipValue ("Invalid background-repeat value", cssRule);
1.117 vatton 5672: /* check if it's an important rule */
5673: }
1.295 vatton 5674: return cssRule;
1.18 cvs 5675: }
5676:
5677: /*----------------------------------------------------------------------
1.327 vatton 5678: ParseACSSBackgroundAttachment: parse a CSS BackgroundAttachment
5679: attribute string.
1.18 cvs 5680: ----------------------------------------------------------------------*/
1.295 vatton 5681: static char *ParseACSSBackgroundAttachment (Element element, PSchema tsch,
1.327 vatton 5682: PresentationContext ctxt,
5683: char *cssRule, CSSInfoPtr css,
5684: ThotBool isHTML)
1.18 cvs 5685: {
1.366 vatton 5686: char *start_value;
5687:
1.163 quint 5688: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 5689: start_value = cssRule;
1.163 quint 5690: if (!strncasecmp (cssRule, "scroll", 6))
1.199 vatton 5691: {
5692: cssRule = SkipWord (cssRule);
5693: }
1.163 quint 5694: else if (!strncasecmp (cssRule, "fixed", 5))
1.199 vatton 5695: {
5696: cssRule = SkipWord (cssRule);
5697: }
1.362 quint 5698: else if (!strncasecmp (cssRule, "inherit", 7))
5699: {
5700: cssRule = SkipWord (cssRule);
5701: }
1.366 vatton 5702: if (start_value != cssRule && DoDialog)
5703: DisplayStyleValue ("background-attachment", start_value, cssRule);
1.163 quint 5704: return (cssRule);
1.1 cvs 5705: }
5706:
5707: /*----------------------------------------------------------------------
1.327 vatton 5708: ParseCSSBackgroundAttachment: parse a CSS BackgroundAttachment
5709: attribute string.
1.295 vatton 5710: ----------------------------------------------------------------------*/
5711: static char *ParseCSSBackgroundAttachment (Element element, PSchema tsch,
1.327 vatton 5712: PresentationContext ctxt,
5713: char *cssRule, CSSInfoPtr css,
5714: ThotBool isHTML)
1.295 vatton 5715: {
5716: char *ptr;
5717:
5718: ptr = cssRule;
5719: cssRule = ParseACSSBackgroundAttachment (element, tsch, ctxt,
1.327 vatton 5720: cssRule, css, isHTML);
1.295 vatton 5721: if (ptr == cssRule)
1.366 vatton 5722: cssRule = SkipValue ("Invalid background-attachment value", cssRule);
1.295 vatton 5723: return cssRule;
5724: }
5725:
5726: /*----------------------------------------------------------------------
1.327 vatton 5727: ParseACSSBackgroundPosition: parse a CSS BackgroundPosition
5728: attribute string.
1.1 cvs 5729: ----------------------------------------------------------------------*/
1.279 vatton 5730: static char *ParseACSSBackgroundPosition (Element element, PSchema tsch,
1.327 vatton 5731: PresentationContext ctxt,
5732: char *cssRule, CSSInfoPtr css,
1.362 quint 5733: ThotBool isHTML, ThotBool *across)
1.1 cvs 5734: {
1.362 quint 5735: PresentationValue val;
5736: char *ptr;
1.1 cvs 5737:
1.163 quint 5738: cssRule = SkipBlanksAndComments (cssRule);
1.362 quint 5739: ptr = cssRule;
5740: val.typed_data.value = 0;
5741: val.typed_data.real = FALSE;
5742: val.typed_data.unit = UNIT_INVALID;
1.163 quint 5743: if (!strncasecmp (cssRule, "left", 4))
1.362 quint 5744: {
5745: val.typed_data.value = 0;
5746: val.typed_data.unit = UNIT_PERCENT;
5747: cssRule += 4;
5748: *across = TRUE;
5749: }
1.163 quint 5750: else if (!strncasecmp (cssRule, "right", 5))
1.362 quint 5751: {
5752: val.typed_data.value = 100;
5753: val.typed_data.unit = UNIT_PERCENT;
5754: cssRule += 5;
5755: *across = TRUE;
5756: }
1.163 quint 5757: else if (!strncasecmp (cssRule, "center", 6))
1.362 quint 5758: {
5759: val.typed_data.value = 50;
5760: val.typed_data.unit = UNIT_PERCENT;
5761: cssRule += 6;
5762: }
1.163 quint 5763: else if (!strncasecmp (cssRule, "top", 3))
1.362 quint 5764: {
5765: val.typed_data.value = 0;
5766: val.typed_data.unit = UNIT_PERCENT;
5767: cssRule += 3;
5768: *across = FALSE;
5769: }
1.163 quint 5770: else if (!strncasecmp (cssRule, "bottom", 6))
1.191 vatton 5771: {
1.362 quint 5772: val.typed_data.value = 100;
5773: val.typed_data.unit = UNIT_PERCENT;
5774: cssRule += 6;
5775: *across = FALSE;
5776: }
5777: else if (!strncasecmp (cssRule, "inherit", 7))
5778: {
5779: val.typed_data.unit = VALUE_INHERIT;
5780: cssRule += 7;
1.191 vatton 5781: }
1.163 quint 5782: else
1.362 quint 5783: /* <length> or <percentage> */
5784: {
5785: cssRule = ParseCSSUnit (cssRule, &val);
5786: if (val.typed_data.unit == UNIT_BOX && val.typed_data.value == 0)
5787: /* 0 with no unit. Accept */
5788: val.typed_data.unit = UNIT_PERCENT;
5789: }
1.163 quint 5790:
1.366 vatton 5791: if (val.typed_data.unit != UNIT_INVALID && val.typed_data.unit != UNIT_BOX)
1.362 quint 5792: {
1.366 vatton 5793: if (DoDialog)
5794: {
5795: if (val.typed_data.unit == VALUE_INHERIT)
5796: {
5797: DisplayStyleValue ("background-positionH", ptr, cssRule);
5798: DisplayStyleValue ("background-positionV", ptr, cssRule);
5799: }
5800: else if (*across)
5801: DisplayStyleValue ("background-positionH", ptr, cssRule);
5802: else
5803: DisplayStyleValue ("background-positionV", ptr, cssRule);
5804: }
5805: else if (DoApply)
1.362 quint 5806: /* install the new presentation */
5807: {
5808: if (val.typed_data.unit == VALUE_INHERIT)
5809: /* "inherit" applies to both dimensions */
5810: {
5811: TtaSetStylePresentation (PRBackgroundHorizPos, element, tsch,
5812: ctxt, val);
5813: TtaSetStylePresentation (PRBackgroundVertPos, element, tsch,
5814: ctxt, val);
5815: }
5816: else if (*across)
5817: TtaSetStylePresentation (PRBackgroundHorizPos, element, tsch,
5818: ctxt, val);
5819: else
5820: TtaSetStylePresentation (PRBackgroundVertPos, element, tsch,
5821: ctxt, val);
5822: }
5823: }
1.279 vatton 5824: return (cssRule);
5825: }
1.218 vatton 5826:
1.279 vatton 5827: /*----------------------------------------------------------------------
1.327 vatton 5828: ParseCSSBackgroundPosition: parse a CSS BackgroundPosition
5829: attribute string.
1.279 vatton 5830: ----------------------------------------------------------------------*/
5831: static char *ParseCSSBackgroundPosition (Element element, PSchema tsch,
1.327 vatton 5832: PresentationContext ctxt,
5833: char *cssRule, CSSInfoPtr css,
5834: ThotBool isHTML)
1.279 vatton 5835: {
1.295 vatton 5836: char *ptr;
1.362 quint 5837: ThotBool across;
1.295 vatton 5838:
5839: ptr = cssRule;
1.362 quint 5840: across = TRUE;
5841: cssRule = ParseACSSBackgroundPosition (element, tsch, ctxt, cssRule, css,
5842: isHTML, &across);
1.295 vatton 5843: if (ptr == cssRule)
1.360 vatton 5844: cssRule = SkipValue ("Invalid background-position value", cssRule);
1.362 quint 5845: else
1.298 vatton 5846: {
1.362 quint 5847: cssRule = SkipBlanksAndComments (cssRule);
5848: if (*cssRule != ';' && *cssRule != '!' && *cssRule != EOS)
5849: {
5850: /* possible second value */
5851: ptr = cssRule;
5852: across = !across;
5853: cssRule = ParseACSSBackgroundPosition (element, tsch, ctxt, cssRule,
5854: css, isHTML, &across);
5855: if (ptr == cssRule)
5856: cssRule = SkipValue ("Invalid background-position value", cssRule);
5857: }
1.298 vatton 5858: }
1.163 quint 5859: return (cssRule);
1.18 cvs 5860: }
5861:
5862: /*----------------------------------------------------------------------
1.327 vatton 5863: ParseCSSBackground: parse a CSS background attribute
1.18 cvs 5864: ----------------------------------------------------------------------*/
1.79 cvs 5865: static char *ParseCSSBackground (Element element, PSchema tsch,
1.327 vatton 5866: PresentationContext ctxt, char *cssRule,
5867: CSSInfoPtr css, ThotBool isHTML)
1.18 cvs 5868: {
1.323 vatton 5869: char *ptr;
5870: int skippedNL;
1.362 quint 5871: ThotBool img, repeat, position, attach, color, across;
1.18 cvs 5872:
1.82 cvs 5873: cssRule = SkipBlanksAndComments (cssRule);
1.323 vatton 5874: img = repeat = position = attach = color = FALSE;
1.362 quint 5875: across = TRUE;
1.301 vatton 5876: while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.18 cvs 5877: {
1.71 cvs 5878: /* perhaps a Background Image */
1.198 vatton 5879: if (!strncasecmp (cssRule, "url", 3) || !strncasecmp (cssRule, "none", 4))
1.327 vatton 5880: {
1.334 vatton 5881: if (!strncasecmp (cssRule, "none", 4))
1.423 vatton 5882: {
5883: repeat = TRUE;
5884: ParseCSSBackgroundColor (element, tsch, ctxt, "transparent",
5885: css, isHTML);
5886: }
1.327 vatton 5887: cssRule = ParseCSSBackgroundImage (element, tsch, ctxt, cssRule,
5888: css, isHTML);
5889: img = TRUE;
5890: }
1.18 cvs 5891: /* perhaps a Background Attachment */
1.82 cvs 5892: else if (!strncasecmp (cssRule, "scroll", 6) ||
5893: !strncasecmp (cssRule, "fixed", 5))
1.327 vatton 5894: {
5895: cssRule = ParseACSSBackgroundAttachment (element, tsch, ctxt,
5896: cssRule, css, isHTML);
1.328 vatton 5897: attach = repeat = TRUE;
1.327 vatton 5898: }
1.18 cvs 5899: /* perhaps a Background Repeat */
1.82 cvs 5900: else if (!strncasecmp (cssRule, "no-repeat", 9) ||
5901: !strncasecmp (cssRule, "repeat-y", 8) ||
5902: !strncasecmp (cssRule, "repeat-x", 8) ||
5903: !strncasecmp (cssRule, "repeat", 6))
1.327 vatton 5904: {
5905: cssRule = ParseACSSBackgroundRepeat (element, tsch, ctxt,
5906: cssRule, css, isHTML);
5907: repeat = TRUE;
5908: }
1.18 cvs 5909: /* perhaps a Background Position */
1.82 cvs 5910: else if (!strncasecmp (cssRule, "left", 4) ||
5911: !strncasecmp (cssRule, "right", 5) ||
5912: !strncasecmp (cssRule, "center", 6) ||
5913: !strncasecmp (cssRule, "top", 3) ||
5914: !strncasecmp (cssRule, "bottom", 6) ||
1.279 vatton 5915: isdigit (*cssRule) || *cssRule == '.' || *cssRule == '-')
1.327 vatton 5916: {
1.362 quint 5917: cssRule = ParseACSSBackgroundPosition (element, tsch, ctxt, cssRule,
5918: css, isHTML, &across);
5919: across = !across;
1.328 vatton 5920: position = repeat = TRUE;
1.327 vatton 5921: }
1.18 cvs 5922: /* perhaps a Background Color */
1.323 vatton 5923: else if (!color)
1.327 vatton 5924: {
5925: skippedNL = NewLineSkipped;
5926: /* check if the rule has been found */
5927: ptr = cssRule;
5928: cssRule = ParseCSSBackgroundColor (element, tsch, ctxt,
5929: cssRule, css, isHTML);
5930: if (ptr == cssRule)
5931: {
5932: NewLineSkipped = skippedNL;
5933: /* rule not found */
5934: cssRule = SkipProperty (cssRule, FALSE);
5935: }
5936: else
5937: color = TRUE;
5938: }
1.328 vatton 5939: else
1.327 vatton 5940: cssRule = SkipProperty (cssRule, FALSE);
1.328 vatton 5941:
1.82 cvs 5942: cssRule = SkipBlanksAndComments (cssRule);
1.18 cvs 5943: }
1.328 vatton 5944:
5945: if (color && !img)
1.405 kia 5946: ParseCSSBackgroundImage (element, tsch, ctxt, (char*)
5947: "none", css, isHTML);
1.328 vatton 5948:
5949: if (img && !repeat)
5950: ParseACSSBackgroundRepeat (element, tsch, ctxt,
1.405 kia 5951: (char*)"repeat", css, isHTML);
1.328 vatton 5952: if (img && !position)
5953: ParseACSSBackgroundPosition (element, tsch, ctxt,
1.405 kia 5954: (char*)"0% 0%", css, isHTML, &across);
1.328 vatton 5955: if (img && !attach)
5956: ParseACSSBackgroundAttachment (element, tsch, ctxt,
1.405 kia 5957: (char*)"scroll", css, isHTML);
1.327 vatton 5958: return (cssRule);
1.18 cvs 5959: }
5960:
1.59 cvs 5961: /*----------------------------------------------------------------------
1.327 vatton 5962: ParseCSSPageBreakBefore: parse a CSS page-break-before attribute
1.59 cvs 5963: ----------------------------------------------------------------------*/
1.79 cvs 5964: static char *ParseCSSPageBreakBefore (Element element, PSchema tsch,
1.327 vatton 5965: PresentationContext ctxt, char *cssRule,
5966: CSSInfoPtr css, ThotBool isHTML)
1.59 cvs 5967: {
5968: PresentationValue page;
1.366 vatton 5969: char *start_value;
1.59 cvs 5970:
1.184 vatton 5971: page.typed_data.unit = UNIT_INVALID;
1.59 cvs 5972: page.typed_data.real = FALSE;
1.82 cvs 5973: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 5974: start_value = cssRule;
1.82 cvs 5975: if (!strncasecmp (cssRule, "auto", 4))
1.184 vatton 5976: page.typed_data.value = PageAuto;
1.82 cvs 5977: else if (!strncasecmp (cssRule, "always", 6))
1.59 cvs 5978: {
1.184 vatton 5979: page.typed_data.unit = UNIT_REL;
5980: page.typed_data.value = PageAlways;
1.59 cvs 5981: }
1.82 cvs 5982: else if (!strncasecmp (cssRule, "avoid", 5))
1.59 cvs 5983: {
1.184 vatton 5984: page.typed_data.unit = UNIT_REL;
5985: page.typed_data.value = PageAvoid;
1.59 cvs 5986: }
1.82 cvs 5987: else if (!strncasecmp (cssRule, "left", 4))
1.59 cvs 5988: {
1.184 vatton 5989: page.typed_data.unit = UNIT_REL;
5990: page.typed_data.value = PageLeft;
1.59 cvs 5991: }
1.82 cvs 5992: else if (!strncasecmp (cssRule, "right", 5))
1.59 cvs 5993: {
1.184 vatton 5994: page.typed_data.unit = UNIT_REL;
5995: page.typed_data.value = PageRight;
1.59 cvs 5996: }
1.82 cvs 5997: else if (!strncasecmp (cssRule, "inherit", 7))
1.59 cvs 5998: {
1.293 quint 5999: page.typed_data.unit = VALUE_INHERIT;
1.184 vatton 6000: page.typed_data.value = PageInherit;
1.59 cvs 6001: }
6002: cssRule = SkipWord (cssRule);
6003: /* install the new presentation */
1.366 vatton 6004: if ((page.typed_data.unit == UNIT_REL && page.typed_data.value == PageAlways)
6005: || page.typed_data.unit == VALUE_INHERIT)
6006: {
6007: if (DoDialog)
6008: DisplayStyleValue ("page-break-before", start_value, cssRule);
6009: else if (DoApply)
6010: TtaSetStylePresentation (PRPageBefore, element, tsch, ctxt, page);
6011: }
1.59 cvs 6012: return (cssRule);
6013: }
6014:
6015: /*----------------------------------------------------------------------
1.327 vatton 6016: ParseCSSPageBreakAfter: parse a CSS page-break-after attribute
1.59 cvs 6017: ----------------------------------------------------------------------*/
1.79 cvs 6018: static char *ParseCSSPageBreakAfter (Element element, PSchema tsch,
1.327 vatton 6019: PresentationContext ctxt,
6020: char *cssRule, CSSInfoPtr css,
6021: ThotBool isHTML)
1.59 cvs 6022: {
6023: PresentationValue page;
1.366 vatton 6024: char *start_value;
1.59 cvs 6025:
1.184 vatton 6026: page.typed_data.unit = UNIT_INVALID;
1.59 cvs 6027: page.typed_data.real = FALSE;
1.82 cvs 6028: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 6029: start_value = cssRule;
1.82 cvs 6030: if (!strncasecmp (cssRule, "auto", 4))
1.184 vatton 6031: page.typed_data.value = PageAuto;
1.82 cvs 6032: else if (!strncasecmp (cssRule, "always", 6))
1.59 cvs 6033: {
1.184 vatton 6034: page.typed_data.unit = UNIT_REL;
6035: page.typed_data.value = PageAlways;
1.59 cvs 6036: }
1.82 cvs 6037: else if (!strncasecmp (cssRule, "avoid", 5))
1.59 cvs 6038: {
1.184 vatton 6039: page.typed_data.unit = UNIT_REL;
6040: page.typed_data.value = PageAvoid;
1.59 cvs 6041: }
1.82 cvs 6042: else if (!strncasecmp (cssRule, "left", 4))
1.59 cvs 6043: {
1.184 vatton 6044: page.typed_data.unit = UNIT_REL;
6045: page.typed_data.value = PageLeft;
1.59 cvs 6046: }
1.82 cvs 6047: else if (!strncasecmp (cssRule, "right", 5))
1.59 cvs 6048: {
1.184 vatton 6049: page.typed_data.unit = UNIT_REL;
6050: page.typed_data.value = PageRight;
1.59 cvs 6051: }
1.82 cvs 6052: else if (!strncasecmp (cssRule, "inherit", 7))
1.59 cvs 6053: {
1.293 quint 6054: page.typed_data.unit = VALUE_INHERIT;
1.184 vatton 6055: page.typed_data.value = PageInherit;
1.59 cvs 6056: }
6057: cssRule = SkipWord (cssRule);
6058: /* install the new presentation */
1.366 vatton 6059: if (page.typed_data.unit == UNIT_REL || page.typed_data.unit == VALUE_INHERIT)
6060: {
6061: if (DoDialog)
6062: DisplayStyleValue ("page-break-after", start_value, cssRule);
1.367 cvs 6063: //else if (DoApply)
6064: // TtaSetStylePresentation (PRPageAfter, element, tsch, ctxt, page);
1.366 vatton 6065: }
1.59 cvs 6066: return (cssRule);
6067: }
6068:
6069: /*----------------------------------------------------------------------
1.327 vatton 6070: ParseCSSPageBreakInside: parse a CSS page-break-inside attribute
1.59 cvs 6071: ----------------------------------------------------------------------*/
1.79 cvs 6072: static char *ParseCSSPageBreakInside (Element element, PSchema tsch,
1.327 vatton 6073: PresentationContext ctxt,
6074: char *cssRule, CSSInfoPtr css,
6075: ThotBool isHTML)
1.59 cvs 6076: {
6077: PresentationValue page;
1.366 vatton 6078: char *start_value;
1.59 cvs 6079:
1.184 vatton 6080: page.typed_data.unit = UNIT_INVALID;
1.59 cvs 6081: page.typed_data.real = FALSE;
1.82 cvs 6082: cssRule = SkipBlanksAndComments (cssRule);
1.366 vatton 6083: start_value = cssRule;
1.82 cvs 6084: if (!strncasecmp (cssRule, "auto", 4))
1.59 cvs 6085: {
1.184 vatton 6086: /*page.typed_data.unit = UNIT_REL;*/
6087: page.typed_data.value = PageAuto;
1.59 cvs 6088: }
1.82 cvs 6089: else if (!strncasecmp (cssRule, "avoid", 5))
1.59 cvs 6090: {
1.184 vatton 6091: page.typed_data.unit = UNIT_REL;
6092: page.typed_data.value = PageAvoid;
1.59 cvs 6093: }
1.82 cvs 6094: else if (!strncasecmp (cssRule, "inherit", 7))
1.59 cvs 6095: {
1.293 quint 6096: /* page.typed_data.unit = VALUE_INHERIT; */
1.184 vatton 6097: page.typed_data.value = PageInherit;
1.59 cvs 6098: }
6099: cssRule = SkipWord (cssRule);
6100: /* install the new presentation */
1.366 vatton 6101: if ((page.typed_data.unit == UNIT_REL || page.typed_data.unit == VALUE_INHERIT) &&
6102: page.typed_data.value == PageAvoid)
6103: {
6104: if (DoDialog)
6105: DisplayStyleValue ("page-break-inside", start_value, cssRule);
1.367 cvs 6106: //else if (DoApply)
6107: //TtaSetStylePresentation (PRPageInside, element, tsch, ctxt, page);
1.366 vatton 6108: }
1.59 cvs 6109: return (cssRule);
6110: }
1.18 cvs 6111:
1.60 cvs 6112: /*----------------------------------------------------------------------
1.327 vatton 6113: ParseSVGStrokeWidth: parse a SVG stroke-width property value.
1.60 cvs 6114: ----------------------------------------------------------------------*/
1.79 cvs 6115: static char *ParseSVGStrokeWidth (Element element, PSchema tsch,
1.327 vatton 6116: PresentationContext ctxt, char *cssRule,
6117: CSSInfoPtr css, ThotBool isHTML)
1.60 cvs 6118: {
6119: PresentationValue width;
6120:
1.82 cvs 6121: cssRule = SkipBlanksAndComments (cssRule);
1.60 cvs 6122: width.typed_data.value = 0;
1.184 vatton 6123: width.typed_data.unit = UNIT_INVALID;
1.60 cvs 6124: width.typed_data.real = FALSE;
1.110 vatton 6125: if (isdigit (*cssRule) || *cssRule == '.')
1.166 vatton 6126: {
1.327 vatton 6127: cssRule = ParseCSSUnit (cssRule, &width);
6128: if (width.typed_data.unit == UNIT_BOX)
6129: width.typed_data.unit = UNIT_PX;
1.166 vatton 6130: }
1.295 vatton 6131: else
6132: cssRule = SkipValue ("Invalid stroke-width value", cssRule);
6133:
1.184 vatton 6134: if (width.typed_data.unit != UNIT_INVALID && DoApply)
1.117 vatton 6135: {
1.207 vatton 6136: TtaSetStylePresentation (PRLineWeight, element, tsch, ctxt, width);
1.117 vatton 6137: width.typed_data.value = 1;
1.184 vatton 6138: width.typed_data.unit = UNIT_REL;
1.117 vatton 6139: }
1.60 cvs 6140: return (cssRule);
6141: }
6142:
1.217 vatton 6143: /*----------------------------------------------------------------------
1.327 vatton 6144: ParseCSSPosition: parse a CSS Position attribute string.
1.217 vatton 6145: ----------------------------------------------------------------------*/
6146: static char *ParseCSSPosition (Element element, PSchema tsch,
1.327 vatton 6147: PresentationContext ctxt, char *cssRule,
6148: CSSInfoPtr css, ThotBool isHTML)
1.217 vatton 6149: {
1.305 quint 6150: char *ptr;
6151: PresentationValue pval;
1.217 vatton 6152:
1.305 quint 6153: pval.typed_data.value = 0;
6154: pval.typed_data.unit = UNIT_BOX;
6155: pval.typed_data.real = FALSE;
1.217 vatton 6156: cssRule = SkipBlanksAndComments (cssRule);
6157: ptr = cssRule;
6158: if (!strncasecmp (cssRule, "static", 6))
1.337 vatton 6159: {
6160: pval.typed_data.value = PositionStatic;
6161: cssRule += 6;
6162: }
6163: else if (!strncasecmp (cssRule, "relative", 8))
6164: {
6165: pval.typed_data.value = PositionRelative;
6166: cssRule += 8;
6167: }
1.217 vatton 6168: else if (!strncasecmp (cssRule, "absolute", 8))
1.337 vatton 6169: {
6170: pval.typed_data.value = PositionAbsolute;
6171: cssRule += 8;
6172: }
1.217 vatton 6173: else if (!strncasecmp (cssRule, "fixed", 5))
1.337 vatton 6174: {
6175: pval.typed_data.value = PositionFixed;
6176: cssRule += 5;
6177: }
1.217 vatton 6178: else if (!strncasecmp (cssRule, "inherit", 7))
1.337 vatton 6179: {
6180: pval.typed_data.unit = VALUE_INHERIT;
6181: cssRule += 7;
6182: }
1.305 quint 6183:
6184: if (pval.typed_data.value == 0 && pval.typed_data.unit != VALUE_INHERIT)
6185: {
6186: cssRule = SkipValue ("Invalid position value", ptr);
6187: cssRule = SkipValue (NULL, cssRule);
6188: }
1.217 vatton 6189: else
1.305 quint 6190: {
1.337 vatton 6191: cssRule = SkipBlanksAndComments (cssRule);
6192: if (*cssRule != EOS && *cssRule != ';')
6193: SkipValue ("Invalid position value", ptr);
1.366 vatton 6194: else if (DoDialog)
6195: DisplayStyleValue ("position", ptr, cssRule);
1.337 vatton 6196: else if (DoApply)
1.327 vatton 6197: TtaSetStylePresentation (PRPosition, element, tsch, ctxt, pval);
1.305 quint 6198: }
1.217 vatton 6199: return (cssRule);
6200: }
6201:
6202: /*----------------------------------------------------------------------
1.327 vatton 6203: ParseCSSTop: parse a CSS Top attribute
1.217 vatton 6204: ----------------------------------------------------------------------*/
6205: static char *ParseCSSTop (Element element, PSchema tsch,
1.327 vatton 6206: PresentationContext context, char *cssRule,
6207: CSSInfoPtr css, ThotBool isHTML)
1.217 vatton 6208: {
6209: PresentationValue val;
6210: char *ptr;
6211:
1.370 vatton 6212: val.typed_data.real = FALSE;
1.217 vatton 6213: cssRule = SkipBlanksAndComments (cssRule);
6214: ptr = cssRule;
1.305 quint 6215: /* first parse the value */
6216: if (!strncasecmp (cssRule, "auto", 4))
1.217 vatton 6217: {
6218: val.typed_data.unit = VALUE_AUTO;
6219: val.typed_data.value = 0;
6220: cssRule = SkipWord (cssRule);
6221: }
1.305 quint 6222: else if (!strncasecmp (cssRule, "inherit", 7))
6223: {
6224: val.typed_data.unit = VALUE_INHERIT;
6225: cssRule = SkipWord (cssRule);
6226: }
1.217 vatton 6227: else
6228: cssRule = ParseCSSUnit (cssRule, &val);
1.387 quint 6229:
6230: if (val.typed_data.unit == UNIT_INVALID ||
6231: (val.typed_data.value != 0 &&
1.217 vatton 6232: val.typed_data.unit == UNIT_BOX))
6233: {
1.387 quint 6234: cssRule = SkipValue ("Invalid top value", ptr);
6235: if (val.typed_data.unit == UNIT_BOX)
6236: val.typed_data.unit = UNIT_PX;
6237: else
6238: return (cssRule);
1.217 vatton 6239: }
1.366 vatton 6240: if (DoDialog)
1.387 quint 6241: DisplayStyleValue ("top", ptr, cssRule);
1.366 vatton 6242: else if (DoApply)
1.305 quint 6243: TtaSetStylePresentation (PRTop, element, tsch, context, val);
1.217 vatton 6244: return (cssRule);
6245: }
6246:
6247: /*----------------------------------------------------------------------
1.327 vatton 6248: ParseCSSRight: parse a CSS Right attribute
1.217 vatton 6249: ----------------------------------------------------------------------*/
6250: static char *ParseCSSRight (Element element, PSchema tsch,
1.327 vatton 6251: PresentationContext context, char *cssRule,
6252: CSSInfoPtr css, ThotBool isHTML)
1.217 vatton 6253: {
6254: PresentationValue val;
6255: char *ptr;
6256:
1.370 vatton 6257: val.typed_data.real = FALSE;
1.217 vatton 6258: cssRule = SkipBlanksAndComments (cssRule);
6259: ptr = cssRule;
6260: /* first parse the attribute string */
1.305 quint 6261: if (!strncasecmp (cssRule, "auto", 4))
1.217 vatton 6262: {
6263: val.typed_data.unit = VALUE_AUTO;
6264: val.typed_data.value = 0;
6265: cssRule = SkipWord (cssRule);
6266: }
1.305 quint 6267: else if (!strncasecmp (cssRule, "inherit", 7))
6268: {
6269: val.typed_data.unit = VALUE_INHERIT;
6270: cssRule = SkipWord (cssRule);
6271: }
1.217 vatton 6272: else
6273: cssRule = ParseCSSUnit (cssRule, &val);
1.387 quint 6274:
6275: if (val.typed_data.unit == UNIT_INVALID ||
6276: (val.typed_data.value != 0 &&
1.217 vatton 6277: val.typed_data.unit == UNIT_BOX))
6278: {
1.387 quint 6279: cssRule = SkipValue ("Invalid right value", ptr);
6280: if (val.typed_data.unit == UNIT_BOX)
6281: val.typed_data.unit = UNIT_PX;
6282: else
6283: return (cssRule);
1.217 vatton 6284: }
1.366 vatton 6285: if (DoDialog)
6286: DisplayStyleValue ("right", ptr, cssRule);
6287: else if (DoApply)
1.305 quint 6288: TtaSetStylePresentation (PRRight, element, tsch, context, val);
1.217 vatton 6289: return (cssRule);
6290: }
6291:
6292: /*----------------------------------------------------------------------
1.327 vatton 6293: ParseCSSBottom: parse a CSS Bottom attribute
1.217 vatton 6294: ----------------------------------------------------------------------*/
6295: static char *ParseCSSBottom (Element element, PSchema tsch,
1.327 vatton 6296: PresentationContext context, char *cssRule,
6297: CSSInfoPtr css, ThotBool isHTML)
1.217 vatton 6298: {
6299: PresentationValue val;
6300: char *ptr;
6301:
1.370 vatton 6302: val.typed_data.real = FALSE;
1.217 vatton 6303: cssRule = SkipBlanksAndComments (cssRule);
6304: ptr = cssRule;
6305: /* first parse the attribute string */
1.305 quint 6306: if (!strncasecmp (cssRule, "auto", 4))
1.217 vatton 6307: {
6308: val.typed_data.unit = VALUE_AUTO;
6309: val.typed_data.value = 0;
6310: cssRule = SkipWord (cssRule);
6311: }
1.305 quint 6312: else if (!strncasecmp (cssRule, "inherit", 7))
6313: {
6314: val.typed_data.unit = VALUE_INHERIT;
6315: cssRule = SkipWord (cssRule);
6316: }
1.217 vatton 6317: else
6318: cssRule = ParseCSSUnit (cssRule, &val);
1.387 quint 6319:
6320: if (val.typed_data.unit == UNIT_INVALID ||
6321: (val.typed_data.value != 0 &&
1.217 vatton 6322: val.typed_data.unit == UNIT_BOX))
6323: {
1.387 quint 6324: cssRule = SkipValue ("Invalid bottom value", ptr);
6325: if (val.typed_data.unit == UNIT_BOX)
6326: val.typed_data.unit = UNIT_PX;
6327: else
6328: return (cssRule);
1.217 vatton 6329: }
1.366 vatton 6330: if (DoDialog)
6331: DisplayStyleValue ("bottom", ptr, cssRule);
6332: else if (DoApply)
1.305 quint 6333: TtaSetStylePresentation (PRBottom, element, tsch, context, val);
1.217 vatton 6334: return (cssRule);
6335: }
6336:
6337: /*----------------------------------------------------------------------
1.327 vatton 6338: ParseCSSLeft: parse a CSS Left attribute
1.217 vatton 6339: ----------------------------------------------------------------------*/
6340: static char *ParseCSSLeft (Element element, PSchema tsch,
1.327 vatton 6341: PresentationContext context, char *cssRule,
6342: CSSInfoPtr css, ThotBool isHTML)
1.217 vatton 6343: {
6344: PresentationValue val;
6345: char *ptr;
6346:
1.370 vatton 6347: val.typed_data.real = FALSE;
1.217 vatton 6348: cssRule = SkipBlanksAndComments (cssRule);
6349: ptr = cssRule;
6350: /* first parse the attribute string */
1.305 quint 6351: if (!strncasecmp (cssRule, "auto", 4))
1.217 vatton 6352: {
6353: val.typed_data.unit = VALUE_AUTO;
6354: val.typed_data.value = 0;
6355: cssRule = SkipWord (cssRule);
6356: }
1.305 quint 6357: else if (!strncasecmp (cssRule, "inherit", 7))
6358: {
6359: val.typed_data.unit = VALUE_INHERIT;
6360: cssRule = SkipWord (cssRule);
6361: }
1.217 vatton 6362: else
6363: cssRule = ParseCSSUnit (cssRule, &val);
1.387 quint 6364:
6365: if (val.typed_data.unit == UNIT_INVALID ||
6366: (val.typed_data.value != 0 &&
1.217 vatton 6367: val.typed_data.unit == UNIT_BOX))
6368: {
1.387 quint 6369: cssRule = SkipValue ("Invalid left value", ptr);
6370: if (val.typed_data.unit == UNIT_BOX)
6371: val.typed_data.unit = UNIT_PX;
6372: else
6373: return (cssRule);
1.217 vatton 6374: }
1.366 vatton 6375: if (DoDialog)
6376: DisplayStyleValue ("left", ptr, cssRule);
6377: else if (DoApply)
1.305 quint 6378: TtaSetStylePresentation (PRLeft, element, tsch, context, val);
1.217 vatton 6379: return (cssRule);
6380: }
6381:
6382: /*----------------------------------------------------------------------
1.327 vatton 6383: ParseCSSZIndex: parse a CSS z-index attribute
1.217 vatton 6384: ----------------------------------------------------------------------*/
6385: static char *ParseCSSZIndex (Element element, PSchema tsch,
1.327 vatton 6386: PresentationContext context, char *cssRule,
6387: CSSInfoPtr css, ThotBool isHTML)
1.217 vatton 6388: {
6389: PresentationValue val;
6390: char *ptr;
6391:
1.370 vatton 6392: val.typed_data.real = FALSE;
1.217 vatton 6393: cssRule = SkipBlanksAndComments (cssRule);
6394: ptr = cssRule;
6395: /* first parse the attribute string */
1.420 vatton 6396: if (!strncasecmp (cssRule, "auto", 4))
1.217 vatton 6397: {
6398: val.typed_data.unit = VALUE_AUTO;
6399: val.typed_data.value = 0;
6400: cssRule = SkipWord (cssRule);
6401: }
1.420 vatton 6402: else if (!strncasecmp (cssRule, "inherit", 7))
6403: {
6404: val.typed_data.unit = VALUE_INHERIT;
6405: val.typed_data.value = 0;
6406: cssRule = SkipWord (cssRule);
6407: }
1.217 vatton 6408: else
6409: {
6410: cssRule = ParseCSSUnit (cssRule, &val);
6411: if (val.typed_data.unit != UNIT_BOX)
1.327 vatton 6412: {
1.387 quint 6413: cssRule = SkipValue ("Invalid z-index value", ptr);
6414: return (cssRule);
1.327 vatton 6415: }
1.420 vatton 6416: val.typed_data.value = - val.typed_data.value;
1.217 vatton 6417: }
1.366 vatton 6418: if (DoDialog)
1.420 vatton 6419: DisplayStyleValue ("z-index", ptr, cssRule);
6420: else if (DoApply)
6421: TtaSetStylePresentation (PRDepth, element, tsch, context, val);
1.217 vatton 6422: return (cssRule);
6423: }
6424:
1.340 quint 6425: /*----------------------------------------------------------------------
6426: *
1.436 ! quint 6427: * STYLE PROPERTY DECLARATIONS
1.340 quint 6428: *
6429: *----------------------------------------------------------------------*/
1.18 cvs 6430: /*
1.436 ! quint 6431: * NOTE: Long property names MUST be placed before shortened ones !
! 6432: * e.g. "font-size" must be placed before "font"
1.18 cvs 6433: */
6434: static CSSProperty CSSProperties[] =
1.327 vatton 6435: {
6436: {"background-color", ParseCSSBackgroundColor},
6437: {"background-image", ParseCSSBackgroundImage},
6438: {"background-repeat", ParseCSSBackgroundRepeat},
6439: {"background-attachment", ParseCSSBackgroundAttachment},
6440: {"background-position", ParseCSSBackgroundPosition},
6441: {"background", ParseCSSBackground},
6442: {"border-top-width", ParseCSSBorderTopWidth},
6443: {"border-right-width", ParseCSSBorderRightWidth},
6444: {"border-bottom-width", ParseCSSBorderBottomWidth},
6445: {"border-left-width", ParseCSSBorderLeftWidth},
6446: {"border-width", ParseCSSBorderWidth},
6447: {"border-top-color", ParseCSSBorderColorTop},
6448: {"border-right-color", ParseCSSBorderColorRight},
6449: {"border-bottom-color", ParseCSSBorderColorBottom},
6450: {"border-left-color", ParseCSSBorderColorLeft},
6451: {"border-color", ParseCSSBorderColor},
6452: {"border-top-style", ParseCSSBorderStyleTop},
6453: {"border-right-style", ParseCSSBorderStyleRight},
6454: {"border-bottom-style", ParseCSSBorderStyleBottom},
6455: {"border-left-style", ParseCSSBorderStyleLeft},
6456: {"border-style", ParseCSSBorderStyle},
6457: {"border-top", ParseCSSBorderTop},
6458: {"border-right", ParseCSSBorderRight},
6459: {"border-bottom", ParseCSSBorderBottom},
6460: {"border-left", ParseCSSBorderLeft},
6461: {"border", ParseCSSBorder},
6462: {"bottom", ParseCSSBottom},
6463: {"clear", ParseCSSClear},
6464: {"color", ParseCSSForeground},
6465: {"content", ParseCSSContent},
1.436 ! quint 6466: {"counter-increment", ParseCSSCounterIncrement},
! 6467: {"counter-reset", ParseCSSCounterReset},
1.327 vatton 6468: {"direction", ParseCSSDirection},
6469: {"display", ParseCSSDisplay},
6470: {"float", ParseCSSFloat},
6471: {"font-family", ParseCSSFontFamily},
6472: {"font-style", ParseCSSFontStyle},
6473: {"font-variant", ParseCSSFontVariant},
6474: {"font-weight", ParseCSSFontWeight},
6475: {"font-size-adjust", ParseCSSFontSizeAdjust},
6476: {"font-size", ParseCSSFontSize},
6477: {"font", ParseCSSFont},
1.382 vatton 6478: {"max-height", ParseCSSMaxHeight},
6479: {"min-height", ParseCSSMinHeight},
1.327 vatton 6480: {"height", ParseCSSHeight},
6481: {"left", ParseCSSLeft},
6482: {"letter-spacing", ParseCSSLetterSpacing},
6483: {"line-height", ParseCSSLineHeight},
6484: {"list-style-type", ParseCSSListStyleType},
6485: {"list-style-image", ParseCSSListStyleImage},
6486: {"list-style-position", ParseCSSListStylePosition},
6487: {"list-style", ParseCSSListStyle},
6488: {"margin-bottom", ParseCSSMarginBottom},
6489: {"margin-top", ParseCSSMarginTop},
6490: {"margin-right", ParseCSSMarginRight},
6491: {"margin-left", ParseCSSMarginLeft},
6492: {"margin", ParseCSSMargin},
1.418 quint 6493: {"opacity", ParseCSSOpacity},
1.327 vatton 6494: {"padding-top", ParseCSSPaddingTop},
6495: {"padding-right", ParseCSSPaddingRight},
6496: {"padding-bottom", ParseCSSPaddingBottom},
6497: {"padding-left", ParseCSSPaddingLeft},
6498: {"padding", ParseCSSPadding},
6499: {"page-break-before", ParseCSSPageBreakBefore},
6500: {"page-break-after", ParseCSSPageBreakAfter},
6501: {"page-break-inside", ParseCSSPageBreakInside},
6502: {"position", ParseCSSPosition},
6503: {"right", ParseCSSRight},
6504: {"text-align", ParseCSSTextAlign},
6505: {"text-anchor", ParseCSSTextAnchor},
6506: {"text-indent", ParseCSSTextIndent},
6507: {"text-decoration", ParseCSSTextDecoration},
6508: {"text-transform", ParseCSSTextTransform},
6509: {"top", ParseCSSTop},
6510: {"unicode-bidi", ParseCSSUnicodeBidi},
6511: {"vertical-align", ParseCSSVerticalAlign},
6512: {"white-space", ParseCSSWhiteSpace},
1.382 vatton 6513: {"max-width", ParseCSSMaxWidth},
6514: {"min-width", ParseCSSMinWidth},
1.327 vatton 6515: {"width", ParseCSSWidth},
1.333 vatton 6516: {"visibility", ParseCSSVisibility},
1.327 vatton 6517: {"word-spacing", ParseCSSWordSpacing},
6518: {"z-index", ParseCSSZIndex},
6519:
6520: /* SVG extensions */
6521: {"fill-opacity", ParseSVGFillOpacity},
1.420 vatton 6522: {"fill-rule", ParseSVGFillRule},
1.327 vatton 6523: {"fill", ParseSVGFill},
1.427 quint 6524: {"marker-end", ParseSVGMarkerEnd},
6525: {"marker-mid", ParseSVGMarkerMid},
6526: {"marker-start", ParseSVGMarkerStart},
6527: {"marker", ParseSVGMarker},
1.327 vatton 6528: {"opacity", ParseSVGOpacity},
1.424 quint 6529: {"stop-color", ParseSVGStopColor},
1.425 quint 6530: {"stop-opacity", ParseSVGStopOpacity},
1.327 vatton 6531: {"stroke-opacity", ParseSVGStrokeOpacity},
6532: {"stroke-width", ParseSVGStrokeWidth},
6533: {"stroke", ParseSVGStroke}
6534: };
1.155 cheyroul 6535:
1.18 cvs 6536: #define NB_CSSSTYLEATTRIBUTE (sizeof(CSSProperties) / sizeof(CSSProperty))
6537:
6538: /*----------------------------------------------------------------------
1.327 vatton 6539: ParseCSSRule: parse a CSS Style string
6540: we expect the input string describing the style to be of the form
6541: property: value [ ; property: value ]*
6542: but tolerate incorrect or incomplete input
1.18 cvs 6543: ----------------------------------------------------------------------*/
1.366 vatton 6544: void ParseCSSRule (Element element, PSchema tsch, PresentationContext ctxt,
6545: char *cssRule, CSSInfoPtr css, ThotBool isHTML)
1.18 cvs 6546: {
1.366 vatton 6547: DisplayMode dispMode = DisplayImmediately;
1.312 quint 6548: char *p = NULL, *next, *end;
1.214 quint 6549: char *valueStart;
1.18 cvs 6550: int lg;
1.34 cvs 6551: unsigned int i;
1.76 cvs 6552: ThotBool found;
1.18 cvs 6553:
1.34 cvs 6554: /* avoid too many redisplay */
1.366 vatton 6555: if (!DoDialog && ctxt->doc)
6556: {
6557: dispMode = TtaGetDisplayMode (ctxt->doc);
6558: if (dispMode == DisplayImmediately)
6559: TtaSetDisplayMode (ctxt->doc, DeferredDisplay);
6560: }
1.34 cvs 6561:
1.82 cvs 6562: while (*cssRule != EOS)
1.18 cvs 6563: {
1.82 cvs 6564: cssRule = SkipBlanksAndComments (cssRule);
1.371 vatton 6565: if (*cssRule == ';' || *cssRule < 0x20 ||
1.372 vatton 6566: ((unsigned char)*cssRule) == 0xA0)
1.371 vatton 6567: cssRule++;
6568: else if (*cssRule < 0x41 || *cssRule > 0x7A ||
6569: (*cssRule > 0x5A && *cssRule < 0x61))
1.352 vatton 6570: {
6571: end = SkipProperty (cssRule, FALSE);
1.385 vatton 6572: if (cssRule[0] != '-')
6573: CSSParseError ("Invalid property", cssRule, end);
1.352 vatton 6574: cssRule = end;
6575: }
1.194 vatton 6576: else if (*cssRule != EOS)
1.327 vatton 6577: {
6578: found = FALSE;
6579: /* look for the type of property */
6580: for (i = 0; i < NB_CSSSTYLEATTRIBUTE && !found; i++)
6581: {
6582: lg = strlen (CSSProperties[i].name);
6583: if (!strncasecmp (cssRule, CSSProperties[i].name, lg))
6584: {
6585: p = cssRule + lg;
6586: found = TRUE;
6587: i--;
6588: }
6589: }
6590:
1.360 vatton 6591: // check if it's an important rule
6592: CheckImportantRule (cssRule, ctxt);
1.327 vatton 6593: if (i < NB_CSSSTYLEATTRIBUTE &&
6594: !strcasecmp (CSSProperties[i].name, "content") &&
6595: ((GenericContext)ctxt)->pseudo != PbBefore &&
6596: ((GenericContext)ctxt)->pseudo != PbAfter)
1.340 quint 6597: /* property content is allowed only for pseudo-elements :before and
6598: :after */
1.327 vatton 6599: {
1.352 vatton 6600: end = SkipProperty (cssRule, FALSE);
1.327 vatton 6601: CSSParseError ("content is allowed only for pseudo-elements",
6602: cssRule, end);
1.352 vatton 6603: cssRule = end;
1.327 vatton 6604: }
1.352 vatton 6605: else if (i == NB_CSSSTYLEATTRIBUTE)
1.376 vatton 6606: cssRule = SkipProperty (cssRule, !ctxt->destroy);
1.327 vatton 6607: else
6608: {
6609: /* update index and skip the ":" indicator if present */
6610: p = SkipBlanksAndComments (p);
6611: if (*p == ':')
6612: {
6613: p++;
6614: p = SkipBlanksAndComments (p);
6615: /* try to parse the value associated with this property */
6616: if (CSSProperties[i].parsing_function != NULL)
6617: {
6618: valueStart = p;
6619: p = CSSProperties[i].parsing_function (element, tsch,
6620: ctxt, p, css, isHTML);
6621: if (!element && isHTML)
6622: {
6623: if (ctxt->type == HTML_EL_Input)
6624: /* it's a generic rule for the HTML element input.
6625: Generate a Thot Pres rule for each kind of
6626: input element */
6627: {
6628: ctxt->type = HTML_EL_Text_Input;
6629: p = CSSProperties[i].parsing_function (element,
6630: tsch, ctxt, valueStart, css, isHTML);
6631: ctxt->type = HTML_EL_Password_Input;
6632: p = CSSProperties[i].parsing_function (element,
6633: tsch, ctxt, valueStart, css, isHTML);
6634: ctxt->type = HTML_EL_File_Input;
6635: p = CSSProperties[i].parsing_function (element,
6636: tsch, ctxt, valueStart, css, isHTML);
6637: ctxt->type = HTML_EL_Checkbox_Input;
6638: p = CSSProperties[i].parsing_function (element,
6639: tsch, ctxt, valueStart, css, isHTML);
6640: ctxt->type = HTML_EL_Radio_Input;
6641: p = CSSProperties[i].parsing_function (element,
6642: tsch, ctxt, valueStart, css, isHTML);
6643: ctxt->type = HTML_EL_Submit_Input;
6644: p = CSSProperties[i].parsing_function (element,
6645: tsch, ctxt, valueStart, css, isHTML);
6646: ctxt->type = HTML_EL_Reset_Input;
6647: p = CSSProperties[i].parsing_function (element,
6648: tsch, ctxt, valueStart, css, isHTML);
6649: ctxt->type = HTML_EL_Button_Input;
6650: p = CSSProperties[i].parsing_function (element,
6651: tsch, ctxt, valueStart, css, isHTML);
6652: ctxt->type = HTML_EL_Input;
6653: }
6654: else if (ctxt->type == HTML_EL_ruby)
6655: /* it's a generic rule for the HTML element ruby.
6656: Generate a Thot Pres rule for each kind of
6657: ruby element. */
6658: {
6659: ctxt->type = HTML_EL_simple_ruby;
6660: p = CSSProperties[i].parsing_function (element,
6661: tsch, ctxt, valueStart, css, isHTML);
6662: ctxt->type = HTML_EL_complex_ruby;
6663: p = CSSProperties[i].parsing_function (element,
6664: tsch, ctxt, valueStart, css, isHTML);
6665: ctxt->type = HTML_EL_ruby;
6666: }
6667: }
6668: /* update index and skip the ";" separator if present */
6669: next = SkipBlanksAndComments (p);
6670: if (*next != EOS && *next != ';')
1.431 quint 6671: CSSParseError ("Missing closing ';' after", cssRule, p);
1.327 vatton 6672: cssRule = next;
6673: }
6674: }
6675: else
6676: cssRule = SkipProperty (cssRule, TRUE);
6677: }
1.360 vatton 6678: // skip important markup
6679: cssRule = SkipImportantRule (cssRule);
6680:
1.327 vatton 6681: }
1.18 cvs 6682: /* next property */
1.82 cvs 6683: cssRule = SkipBlanksAndComments (cssRule);
1.89 cvs 6684: if (*cssRule == '}')
1.327 vatton 6685: {
6686: cssRule++;
6687: CSSPrintError ("Invalid character", "}");
6688: cssRule = SkipBlanksAndComments (cssRule);
6689: }
1.155 cheyroul 6690: if (*cssRule == ',' ||
1.327 vatton 6691: *cssRule == ';')
6692: {
6693: cssRule++;
6694: cssRule = SkipBlanksAndComments (cssRule);
6695: }
1.18 cvs 6696: }
1.34 cvs 6697:
6698: /* restore the display mode */
1.366 vatton 6699: if (!DoDialog && ctxt->doc && dispMode == DisplayImmediately)
1.207 vatton 6700: TtaSetDisplayMode (ctxt->doc, dispMode);
1.18 cvs 6701: }
1.1 cvs 6702:
1.111 cvs 6703: /*----------------------------------------------------------------------
1.327 vatton 6704: ParseHTMLSpecificStyle: parse and apply a CSS Style string.
6705: This function must be called when a specific style is applied to an
6706: element.
6707: The parameter specificity is the specificity of the style, 0 if it is
6708: not really a CSS rule.
1.1 cvs 6709: ----------------------------------------------------------------------*/
1.79 cvs 6710: void ParseHTMLSpecificStyle (Element el, char *cssRule, Document doc,
1.377 quint 6711: int specificity, ThotBool destroy)
1.1 cvs 6712: {
1.257 vatton 6713: DisplayMode dispMode;
1.207 vatton 6714: PresentationContext ctxt;
6715: ElementType elType;
1.413 vatton 6716: char *buff, *ptr, *end;
1.207 vatton 6717: ThotBool isHTML;
1.1 cvs 6718:
1.207 vatton 6719: /* A rule applying to BODY is really meant to address HTML */
6720: elType = TtaGetElementType (el);
1.286 quint 6721: NewLineSkipped = 0;
1.207 vatton 6722: /* store the current line for eventually reported errors */
6723: LineNumber = TtaGetElementLineNumber (el);
6724: if (destroy)
6725: /* no reported errors */
6726: ParsedDoc = 0;
6727: else if (ParsedDoc != doc)
6728: {
6729: /* update the context for reported errors */
6730: ParsedDoc = doc;
1.348 vatton 6731: Error_DocURL = DocumentURLs[doc];
1.207 vatton 6732: }
6733: isHTML = (strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML") == 0);
6734: /* create the context of the Specific presentation driver */
6735: ctxt = TtaGetSpecificStyleContext (doc);
6736: if (ctxt == NULL)
6737: return;
6738: ctxt->type = elType.ElTypeNum;
6739: ctxt->cssSpecificity = specificity;
1.236 quint 6740: ctxt->cssLine = LineNumber;
1.207 vatton 6741: ctxt->destroy = destroy;
6742: /* first use of the context */
6743: ctxt->uses = 1;
1.257 vatton 6744: /* save the current display mode */
6745: dispMode = TtaGetDisplayMode (doc);
1.207 vatton 6746: /* Call the parser */
1.366 vatton 6747: DoDialog = FALSE; // not parsing for CSS dialog
1.406 quint 6748: /* if it is a property applied to a COL or a COLGROUP element in a HTML table,
6749: associate the property to the corresponding Table_head or cell elements,
6750: depending on the property. */
1.413 vatton 6751: ptr = strstr (cssRule, "background-color");
6752: if (ptr && isHTML &&
1.406 quint 6753: (elType.ElTypeNum == HTML_EL_COL || elType.ElTypeNum == HTML_EL_COLGROUP))
1.413 vatton 6754: {
6755: end = strstr (ptr, ";");
6756: if (end)
6757: {
6758: buff = TtaStrdup (ptr);
6759: end = strstr (buff, ";");
6760: *end = EOS;
6761: ColApplyCSSRule (el, (PresentationContext) ctxt, buff, NULL);
6762: TtaFreeMemory (buff);
6763: }
6764: else
6765: ColApplyCSSRule (el, (PresentationContext) ctxt, ptr, NULL);
6766: }
1.406 quint 6767: else
6768: ParseCSSRule (el, NULL, ctxt, cssRule, NULL, isHTML);
6769:
1.257 vatton 6770: /* restore the display mode if necessary */
1.417 vatton 6771: if (dispMode != NoComputedDisplay)
6772: TtaSetDisplayMode (doc, dispMode);
1.207 vatton 6773: /* check if the context can be freed */
6774: ctxt->uses -= 1;
6775: if (ctxt->uses == 0)
6776: /* no image loading */
6777: TtaFreeMemory(ctxt);
1.1 cvs 6778: }
6779:
1.366 vatton 6780:
1.343 vatton 6781: /*----------------------------------------------------------------------
6782: AddClassName adds the class name into the class list of css if it's
6783: not already there.
6784: ----------------------------------------------------------------------*/
6785: static void AddClassName (char *name, CSSInfoPtr css)
6786: {
1.344 cvs 6787: int l, index, k, length, add;
1.343 vatton 6788: char *buf;
6789: ThotBool found, previous;
6790:
6791: l = strlen (name);
6792: if (l == 0 || css == NULL)
6793: return;
6794: if (css->class_list)
6795: {
6796: buf = css->class_list;
6797: length = strlen (css->class_list);
6798: }
6799: else
6800: {
6801: if (l > 200)
6802: length = l + 1;
6803: else
6804: length = 200;
6805: buf = (char *)TtaGetMemory (length * sizeof (char));
6806: memset (buf, 0, length);
6807: css->class_list = buf;
6808: css->lg_class_list = length;
6809: length = 0;
6810: }
6811:
6812: /* compare that name with all class names already known */
6813: index = 0;
6814: found = FALSE;
6815: previous = FALSE;
6816: while (index < length && !found && !previous)
6817: {
6818: k = 0;
6819: while (k < l && buf[index + k] != EOS && buf[index + k] != SPACE)
6820: {
6821: if (name[k] == buf[index+k])
6822: k++;
6823: else
6824: {
6825: previous = (name[k] < buf[index + k]);
6826: break;
6827: }
6828: }
6829: found = (k == l);
6830: if (!previous)
6831: {
6832: index += k;
6833: while (buf[index] != EOS && buf[index] != SPACE)
6834: index++;
6835: if (buf[index] == SPACE)
6836: index++;
6837: }
6838: }
6839:
6840: if (!found)
6841: /* this class name is not known, append it */
6842: {
6843: l++; /* add a space before */
6844: if (css->lg_class_list <= length + l)
6845: {
6846: // increase the list size
6847: if (l > 200)
6848: add = l + 1;
6849: else
6850: add = 200 ;
6851: buf = (char *)TtaRealloc (buf, css->lg_class_list + (add * sizeof (char)));
6852: if (buf == NULL)
6853: return;
6854: else
6855: {
6856: css->class_list = buf;
6857: memset (&buf[css->lg_class_list], 0, add);
6858: css->lg_class_list += add;
6859: }
6860: }
6861:
6862: if (previous)
6863: {
6864: // move the tail of the current list
6865: for (k = length; k >= index; k--)
6866: buf[k+l] = buf[k];
6867: /* add this new class name at the current position */
6868: strcpy (&buf[index], name);
6869: buf[index + l - 1] = SPACE;
6870: }
6871: else
6872: {
6873: /* add this new class name at the end */
6874: if (index != 0)
6875: buf[index++] = SPACE;
6876: strcpy (&buf[index], name);
6877: }
6878: }
6879: }
6880:
1.68 cvs 6881:
1.1 cvs 6882: /*----------------------------------------------------------------------
1.207 vatton 6883: ParseGenericSelector: Create a generic context for a given selector
6884: string.
6885: If the selector is made of multiple comma, it parses them one at a time
6886: and return the end of the selector string to be handled or NULL.
1.231 vatton 6887: The parameter ctxt gives the current style context which will be passed
6888: to Thotlib.
6889: The parameter css points to the current CSS context.
6890: The parameter link points to the link element.
6891: The parameter url gives the URL of the parsed style sheet.
1.1 cvs 6892: ----------------------------------------------------------------------*/
1.207 vatton 6893: static char *ParseGenericSelector (char *selector, char *cssRule,
1.327 vatton 6894: GenericContext ctxt, Document doc,
6895: CSSInfoPtr css, Element link, char *url)
1.79 cvs 6896: {
6897: ElementType elType;
6898: PSchema tsch;
1.119 vatton 6899: AttributeType attrType;
1.398 vatton 6900: char *deb, *cur, *sel, *next, *limit, c;
1.317 vatton 6901: char *schemaName, *mappedName, *saveURL;
1.79 cvs 6902: char *names[MAX_ANCESTORS];
1.355 quint 6903: ThotBool pseudoFirstChild[MAX_ANCESTORS];
1.340 quint 6904: ElemRel rel[MAX_ANCESTORS];
6905: char *attrnames[MAX_ANCESTORS];
6906: int attrnums[MAX_ANCESTORS];
6907: int attrlevels[MAX_ANCESTORS];
1.79 cvs 6908: char *attrvals[MAX_ANCESTORS];
1.133 vatton 6909: AttrMatch attrmatch[MAX_ANCESTORS];
1.340 quint 6910: int nbnames, nbattrs;
6911: int i, j;
1.256 vatton 6912: int att, kind;
1.118 vatton 6913: int specificity, xmlType;
1.217 vatton 6914: int skippedNL;
1.404 vatton 6915: ThotBool isHTML, noname, warn;
1.347 quint 6916: ThotBool level, quoted, doubleColon;
1.340 quint 6917: #define ATTR_ID 1
6918: #define ATTR_CLASS 2
6919: #define ATTR_PSEUDO 3
1.1 cvs 6920:
1.404 vatton 6921: // check if Amaya should report CSS warnings
6922: TtaGetEnvBoolean ("CSS_WARN", &warn);
1.207 vatton 6923: sel = ctxt->sel;
1.82 cvs 6924: sel[0] = EOS;
1.398 vatton 6925: // get the limit of the string
6926: limit = &sel[MAX_ANCESTORS * 50 -1];
6927: *limit = EOS;
1.117 vatton 6928: specificity = 0;
1.1 cvs 6929: for (i = 0; i < MAX_ANCESTORS; i++)
6930: {
1.25 cvs 6931: names[i] = NULL;
1.355 quint 6932: pseudoFirstChild[i] = FALSE;
1.340 quint 6933: rel[i] = RelAncestor;
6934: attrnames[i] = NULL;
6935: attrnums[i] = 0;
6936: attrlevels[i] = 0;
1.25 cvs 6937: attrvals[i] = NULL;
1.133 vatton 6938: attrmatch[i] = Txtmatch;
1.25 cvs 6939: ctxt->name[i] = 0;
1.355 quint 6940: ctxt->firstChild[i] = FALSE;
1.25 cvs 6941: ctxt->attrType[i] = 0;
1.129 vatton 6942: ctxt->attrLevel[i] = 0;
1.25 cvs 6943: ctxt->attrText[i] = NULL;
1.178 quint 6944: ctxt->attrMatch[i] = Txtmatch;
1.1 cvs 6945: }
1.25 cvs 6946: ctxt->box = 0;
1.312 quint 6947: ctxt->var = 0;
1.306 quint 6948: ctxt->pseudo = PbNone;
1.25 cvs 6949: ctxt->type = 0;
1.366 vatton 6950: DoDialog = FALSE; // not arsing for CSS dialog
1.114 quint 6951: /* the specificity of the rule depends on the selector */
6952: ctxt->cssSpecificity = 0;
1.231 vatton 6953: /* localisation of the CSS rule */
6954: ctxt->cssLine = LineNumber + NewLineSkipped;
6955: ctxt->cssURL = url;
1.240 quint 6956:
1.286 quint 6957: skippedNL = NewLineSkipped;
1.82 cvs 6958: selector = SkipBlanksAndComments (selector);
1.286 quint 6959: NewLineSkipped = skippedNL;
1.27 cvs 6960: cur = &sel[0];
1.340 quint 6961: nbnames = 0;
6962: nbattrs = 0;
1.1 cvs 6963: while (1)
6964: {
1.85 cvs 6965: /* point to the following word in sel[] */
1.27 cvs 6966: deb = cur;
1.25 cvs 6967: /* copy an item of the selector into sel[] */
1.1 cvs 6968: /* put one word in the sel buffer */
1.82 cvs 6969: while (*selector != EOS && *selector != ',' &&
6970: *selector != '.' && *selector != ':' &&
1.118 vatton 6971: *selector != '#' && *selector != '[' &&
1.250 vatton 6972: *selector != '>' && *selector != '+' &&
1.398 vatton 6973: !TtaIsBlank (selector) && cur < limit)
1.327 vatton 6974: *cur++ = *selector++;
1.82 cvs 6975: *cur++ = EOS; /* close the first string in sel[] */
1.380 vatton 6976: noname = TRUE;
1.82 cvs 6977: if (deb[0] != EOS)
1.340 quint 6978: /* the selector starts with an element name */
1.327 vatton 6979: {
6980: if (deb[0] <= 64 && deb[0] != '*')
6981: {
6982: CSSPrintError ("Invalid element", deb);
1.380 vatton 6983: names[0] = NULL; /* no element name */
6984: DoApply = FALSE;
1.327 vatton 6985: }
6986: else
6987: {
1.380 vatton 6988: noname = FALSE;
1.327 vatton 6989: names[0] = deb;
6990: if (!strcmp (names[0], "html"))
6991: /* give a greater priority to the backgoud color of html */
6992: specificity += 3;
6993: else
6994: /* selector "*" has specificity zero */
6995: if (strcmp (names[0], "*"))
6996: specificity += 1;
6997: }
6998: }
1.25 cvs 6999: else
1.340 quint 7000: names[0] = NULL; /* no element name */
1.226 quint 7001:
1.340 quint 7002: rel[0] = RelVoid;
1.27 cvs 7003: /* now names[0] points to the beginning of the parsed item
1.340 quint 7004: and cur to the next string to be parsed */
1.129 vatton 7005: while (*selector == '.' || *selector == ':' ||
1.327 vatton 7006: *selector == '#' || *selector == '[')
7007: {
7008: /* point to the following word in sel[] */
7009: deb = cur;
7010: if (*selector == '.')
1.340 quint 7011: /* class */
1.327 vatton 7012: {
7013: selector++;
1.340 quint 7014: while (*selector != '.' && *selector != ':' &&
7015: *selector != '#' && *selector != '[' &&
7016: *selector != EOS && *selector != ',' &&
7017: *selector != '+' && *selector != '>' &&
1.398 vatton 7018: !TtaIsBlank (selector) && cur < limit)
1.327 vatton 7019: {
7020: if (*selector == '\\')
7021: {
7022: selector++;
7023: if (*selector != EOS)
7024: *cur++ = *selector++;
7025: }
7026: else
7027: *cur++ = *selector++;
7028: }
7029: /* close the word */
7030: *cur++ = EOS;
1.340 quint 7031: /* point to the class in sel[] if it's a valid name */
1.327 vatton 7032: if (deb[0] <= 64)
7033: {
7034: CSSPrintError ("Invalid class", deb);
7035: DoApply = FALSE;
7036: }
7037: else
7038: {
1.340 quint 7039: /* simulate selector [class ~= "xxx"] */
7040: nbattrs++;
7041: if (nbattrs == MAX_ANCESTORS)
7042: /* abort parsing */
7043: {
7044: CSSPrintError ("Selector too long", deb);
7045: return (selector);
7046: }
7047: for (i = nbattrs; i > 0; i--)
7048: {
7049: attrnames[i] = attrnames[i - 1];
7050: attrnums[i] = attrnums[i - 1];
7051: attrlevels[i] = attrlevels[i - 1];
7052: attrvals[i] = attrvals[i - 1];
7053: attrmatch[i] = attrmatch[i - 1];
7054: }
7055: attrnames[0] = NULL;
7056: attrnums[0] = ATTR_CLASS;
7057: attrlevels[0] = 0;
7058: attrmatch[0] = Txtword;
7059: attrvals[0] = deb;
1.327 vatton 7060: specificity += 10;
1.343 vatton 7061: }
1.327 vatton 7062: }
7063: else if (*selector == ':')
1.340 quint 7064: /* pseudo-class or pseudo-element */
1.327 vatton 7065: {
7066: selector++;
1.347 quint 7067: doubleColon = FALSE;
7068: if (*selector == ':')
7069: /* it's a double "::". Probably CSS3 syntax */
7070: {
7071: selector++;
7072: doubleColon = TRUE;
7073: }
1.340 quint 7074: while (*selector != '.' && *selector != ':' &&
7075: *selector != '#' && *selector != '[' &&
7076: *selector != EOS && *selector != ',' &&
7077: *selector != '+' && *selector != '>' &&
1.398 vatton 7078: !TtaIsBlank (selector) && cur < limit)
1.327 vatton 7079: *cur++ = *selector++;
7080: /* close the word */
7081: *cur++ = EOS;
1.340 quint 7082: /* point to the pseudo-class or pseudo-element in sel[] if it's
7083: a valid name */
1.355 quint 7084: if (!strcmp (deb, "first-child"))
7085: /* first-child pseudo-class */
1.327 vatton 7086: {
1.355 quint 7087: pseudoFirstChild[0] = TRUE;
7088: specificity += 10;
1.327 vatton 7089: }
1.355 quint 7090: else if (!strcmp (deb, "link") || !strcmp (deb, "visited"))
7091: /* link or visited pseudo-classes */
1.327 vatton 7092: {
1.355 quint 7093: nbattrs++;
7094: if (nbattrs == MAX_ANCESTORS)
7095: /* abort parsing */
1.347 quint 7096: {
1.355 quint 7097: CSSPrintError ("Selector too long", deb);
7098: return (selector);
1.347 quint 7099: }
1.355 quint 7100: for (i = nbattrs; i > 0; i--)
1.347 quint 7101: {
1.355 quint 7102: attrnames[i] = attrnames[i - 1];
7103: attrnums[i] = attrnums[i - 1];
7104: attrlevels[i] = attrlevels[i - 1];
7105: attrvals[i] = attrvals[i - 1];
7106: attrmatch[i] = attrmatch[i - 1];
1.347 quint 7107: }
1.355 quint 7108: attrnames[0] = NULL;
7109: attrnums[0] = ATTR_PSEUDO;
7110: attrlevels[0] = 0;
7111: attrmatch[0] = Txtmatch;
7112: attrvals[0] = deb;
7113: specificity += 10;
7114: }
7115: else if (!strcmp (deb, "hover") || !strcmp (deb, "active") ||
7116: !strcmp (deb, "focus"))
7117: /* hover, active, focus pseudo-classes */
7118: {
1.403 vatton 7119: attrnames[0] = NULL;
7120: attrnums[0] = ATTR_PSEUDO;
7121: attrlevels[0] = 0;
7122: attrmatch[0] = Txtmatch;
7123: attrvals[0] = deb;
1.355 quint 7124: specificity += 10;
7125: /* not supported */
7126: DoApply = FALSE;
7127: }
7128: else if (!strncmp (deb, "lang", 4))
7129: /* it's the lang pseudo-class */
7130: {
7131: if (deb[4] != '(' || deb[strlen(deb)-1] != ')')
7132: /* at least one parenthesis is missing. Error */
1.327 vatton 7133: {
1.355 quint 7134: CSSPrintError ("Invalid :lang pseudo-class", deb);
7135: DoApply = FALSE;
1.327 vatton 7136: }
7137: else
1.355 quint 7138: /* simulate selector [lang|="xxx"] */
1.340 quint 7139: {
7140: nbattrs++;
7141: if (nbattrs == MAX_ANCESTORS)
7142: /* abort parsing */
7143: {
7144: CSSPrintError ("Selector too long", deb);
7145: return (selector);
7146: }
1.355 quint 7147: deb[strlen(deb)-1] = EOS;
7148: deb[4] = EOS;
1.340 quint 7149: for (i = nbattrs; i > 0; i--)
7150: {
7151: attrnames[i] = attrnames[i - 1];
7152: attrnums[i] = attrnums[i - 1];
7153: attrlevels[i] = attrlevels[i - 1];
7154: attrvals[i] = attrvals[i - 1];
7155: attrmatch[i] = attrmatch[i - 1];
7156: }
1.355 quint 7157: attrnames[0] = deb;
7158: attrnums[0] = 0;
1.340 quint 7159: attrlevels[0] = 0;
1.355 quint 7160: attrmatch[0] = Txtsubstring;
7161: attrvals[0] = &deb[5];
7162: specificity += 10;
1.340 quint 7163: }
1.327 vatton 7164: }
1.355 quint 7165: else if (!strcmp (deb, "first-line") ||
7166: !strcmp (deb, "first-letter"))
7167: /* pseudo-elements first-line or first-letter */
7168: {
1.404 vatton 7169: if (doubleColon && warn)
1.355 quint 7170: CSSPrintError ("Warning: \"::\" is CSS3 syntax", NULL);
7171: specificity += 1;
7172: /* not supported */
7173: DoApply = FALSE;
7174: }
7175: else if (!strncmp (deb, "before", 6))
7176: /* pseudo-element before */
7177: {
1.404 vatton 7178: if (doubleColon && warn)
1.355 quint 7179: CSSPrintError ("Warning: \"::before\" is CSS3 syntax",
7180: NULL);
7181: ctxt->pseudo = PbBefore;
7182: specificity += 1;
7183: }
7184: else if (!strncmp (deb, "after", 5))
7185: /* pseudo-element after */
7186: {
1.404 vatton 7187: if (doubleColon && warn)
1.355 quint 7188: CSSPrintError ("Warning: \"::after\" is CSS3 syntax",
7189: NULL);
7190: ctxt->pseudo = PbAfter;
7191: specificity += 1;
7192: }
1.433 vatton 7193: else if (!strncmp (deb, "target", 6))
1.404 vatton 7194: {
1.433 vatton 7195: if (warn)
1.404 vatton 7196: CSSPrintError ("Warning: \":target\" is CSS3 syntax",
7197: NULL);
7198: specificity += 1;
7199: DoApply = FALSE;
7200: }
1.433 vatton 7201: else if (!strncmp (deb, "not", 3) ||
7202: !strncmp (deb, "only", 4) ||
7203: !strncmp (deb, "last", 4))
7204: {
7205: if (warn)
7206: CSSPrintError ("Warning: Not supported CSS3 syntax",
7207: NULL);
7208: specificity += 1;
7209: DoApply = FALSE;
7210: }
7211: else
1.355 quint 7212: {
7213: CSSPrintError ("Invalid pseudo-element", deb);
7214: DoApply = FALSE;
7215: }
7216: if (names[0] && !strcmp (names[0], "*"))
7217: names[0] = NULL;
1.327 vatton 7218: }
7219: else if (*selector == '#')
1.340 quint 7220: /* unique identifier */
1.327 vatton 7221: {
7222: selector++;
1.340 quint 7223: while (*selector != '.' && *selector != ':' &&
7224: *selector != '#' && *selector != '[' &&
7225: *selector != '+' && *selector != '>' &&
7226: *selector != EOS && *selector != ',' &&
1.398 vatton 7227: !TtaIsBlank (selector) && cur < limit)
1.327 vatton 7228: *cur++ = *selector++;
7229: /* close the word */
7230: *cur++ = EOS;
7231: /* point to the attribute in sel[] if it's valid name */
7232: if (deb[0] <= 64)
7233: {
7234: CSSPrintError ("Invalid id", deb);
7235: DoApply = FALSE;
7236: }
7237: else
7238: {
1.340 quint 7239: nbattrs++;
7240: if (nbattrs == MAX_ANCESTORS)
7241: /* abort parsing */
7242: {
7243: CSSPrintError ("Selector too long", deb);
7244: return (selector);
7245: }
7246: for (i = nbattrs; i > 0; i--)
7247: {
7248: attrnames[i] = attrnames[i - 1];
7249: attrnums[i] = attrnums[i - 1];
7250: attrlevels[i] = attrlevels[i - 1];
7251: attrvals[i] = attrvals[i - 1];
7252: attrmatch[i] = attrmatch[i - 1];
7253: }
7254: attrnames[0] = NULL;
7255: attrnums[0] = ATTR_ID;
7256: attrlevels[0] = 0;
7257: attrmatch[0] = Txtmatch;
7258: attrvals[0] = deb;
7259: specificity += 100;
7260: if (names[0] && !strcmp (names[0], "*"))
7261: names[0] = NULL;
1.327 vatton 7262: }
7263: }
7264: else if (*selector == '[')
7265: {
7266: selector++;
1.341 quint 7267: selector = SkipBlanksAndComments (selector);
1.327 vatton 7268: while (*selector != EOS && *selector != ']' &&
7269: *selector != '=' && *selector != '~' &&
1.341 quint 7270: *selector != '|' && *selector != '^' &&
1.396 vatton 7271: *selector != '$' && *selector != '*' &&
1.398 vatton 7272: !TtaIsBlank (selector) && cur < limit)
1.327 vatton 7273: *cur++ = *selector++;
1.341 quint 7274: /* close the word (attribute name) */
1.327 vatton 7275: *cur++ = EOS;
7276: /* point to the attribute in sel[] if it's valid name */
7277: if (deb[0] <= 64)
7278: {
7279: CSSPrintError ("Invalid attribute", deb);
7280: DoApply = FALSE;
7281: }
7282: else
7283: {
1.340 quint 7284: nbattrs++;
7285: if (nbattrs == MAX_ANCESTORS)
7286: /* abort parsing */
7287: {
7288: CSSPrintError ("Selector too long", deb);
7289: return (selector);
7290: }
7291: for (i = nbattrs; i > 0; i--)
7292: {
7293: attrnames[i] = attrnames[i - 1];
7294: attrnums[i] = attrnums[i - 1];
7295: attrlevels[i] = attrlevels[i - 1];
7296: attrvals[i] = attrvals[i - 1];
7297: attrmatch[i] = attrmatch[i - 1];
7298: }
7299: attrnames[0] = deb;
7300: attrnums[0] = 0;
7301: attrlevels[0] = 0;
1.378 quint 7302: attrvals[0] = NULL;
7303: attrmatch[0] = Txtmatch;
1.327 vatton 7304: specificity += 10;
1.340 quint 7305: /* check matching */
1.341 quint 7306: selector = SkipBlanksAndComments (selector);
1.340 quint 7307: if (*selector == '~')
7308: {
7309: attrmatch[0] = Txtword;
7310: selector++;
7311: }
1.396 vatton 7312: else if (*selector == '|' || *selector == '$' || *selector == '*')
1.340 quint 7313: {
1.404 vatton 7314: if (*selector == '$' && warn)
1.396 vatton 7315: CSSPrintError ("Warning: \"$=\" is CSS3 syntax", NULL);
1.404 vatton 7316: if (*selector == '*' && warn)
1.396 vatton 7317: CSSPrintError ("Warning: \"*=\" is CSS3 syntax", NULL);
1.340 quint 7318: attrmatch[0] = Txtsubstring;
7319: selector++;
7320: }
1.341 quint 7321: else if (*selector == '^')
7322: {
7323: attrmatch[0] = Txtsubstring;
7324: selector++;
7325: }
1.340 quint 7326: else
7327: attrmatch[0] = Txtmatch;
1.327 vatton 7328: }
7329: if (*selector == '=')
7330: {
7331: /* look for a value "xxxx" */
7332: selector++;
1.341 quint 7333: selector = SkipBlanksAndComments (selector);
1.327 vatton 7334: if (*selector != '"')
7335: quoted = FALSE;
7336: else
7337: {
7338: quoted = TRUE;
7339: /* we are now parsing the attribute value */
7340: selector++;
7341: }
7342: deb = cur;
1.398 vatton 7343: while ((quoted && cur < limit &&
1.327 vatton 7344: (*selector != '"' ||
7345: (*selector == '"' && selector[-1] == '\\'))) ||
7346: (!quoted && *selector != ']'))
7347: {
7348: if (*selector == EOS)
7349: {
7350: CSSPrintError ("Invalid attribute value", deb);
7351: DoApply = FALSE;
7352: }
7353: else
7354: {
7355: if (attrmatch[0] == Txtword && TtaIsBlank (selector))
7356: {
7357: CSSPrintError ("No space allowed here: ", selector);
7358: DoApply = FALSE;
7359: }
7360: *cur++ = *selector;
7361: }
7362: selector++;
7363: }
7364: /* there is a value */
7365: if (quoted && *selector == '"')
7366: {
7367: selector++;
7368: quoted = FALSE;
7369: }
1.341 quint 7370: selector = SkipBlanksAndComments (selector);
1.327 vatton 7371: if (*selector != ']')
7372: {
7373: CSSPrintError ("Invalid attribute value", deb);
7374: DoApply = FALSE;
7375: }
7376: else
7377: {
7378: *cur++ = EOS;
7379: attrvals[0] = deb;
7380: selector++;
7381: }
7382: }
7383: /* end of the attribute */
7384: else if (*selector != ']')
7385: {
7386: selector[1] = EOS;
7387: CSSPrintError ("Invalid attribute", selector);
7388: selector += 2;
7389: DoApply = FALSE;
7390: }
7391: else
7392: {
7393: selector++;
7394: if (names[0] && !strcmp (names[0], "*"))
7395: names[0] = NULL;
7396: }
7397: }
7398: else
7399: {
7400: /* not supported selector */
1.340 quint 7401: while (*selector != '.' && *selector != ':' &&
7402: *selector != '#' && *selector != '[' &&
7403: *selector != EOS && *selector != ',' &&
7404: *selector != '+' && *selector != '>' &&
1.398 vatton 7405: !TtaIsBlank (selector) && cur < limit)
1.327 vatton 7406: *cur++ = *selector++;
7407: /* close the word */
7408: *cur++ = EOS;
7409: CSSPrintError ("Selector not supported:", deb);
7410: DoApply = FALSE;
7411: }
7412: }
1.1 cvs 7413:
1.286 quint 7414: skippedNL = NewLineSkipped;
1.82 cvs 7415: selector = SkipBlanksAndComments (selector);
1.286 quint 7416: NewLineSkipped = skippedNL;
7417:
1.380 vatton 7418: if (noname && !pseudoFirstChild[0] && attrnums[0] == 0 && attrnames[0] == NULL)
7419: {
7420: *cur++ = EOS;
7421: CSSPrintError ("Invalid Selector", deb);
7422: DoApply = FALSE;
7423: }
1.25 cvs 7424: /* is it a multi-level selector? */
1.82 cvs 7425: if (*selector == EOS)
1.327 vatton 7426: /* end of the selector */
7427: break;
1.82 cvs 7428: else if (*selector == ',')
1.327 vatton 7429: {
7430: /* end of the current selector */
7431: selector++;
7432: skippedNL = NewLineSkipped;
7433: next = SkipBlanksAndComments (selector);
7434: NewLineSkipped = skippedNL;
7435: if (*next == EOS)
7436: /* nothing after the comma. Invalid selector */
7437: {
1.380 vatton 7438: CSSPrintError ("Syntax error:", selector);
7439: selector = NULL;
1.327 vatton 7440: }
7441: break;
7442: }
1.25 cvs 7443: else
1.327 vatton 7444: {
7445: if (*selector == '>')
7446: {
1.340 quint 7447: /* handle parent */
1.327 vatton 7448: selector++;
7449: skippedNL = NewLineSkipped;
7450: selector = SkipBlanksAndComments (selector);
7451: NewLineSkipped = skippedNL;
1.340 quint 7452: rel[0] = RelParent;
1.327 vatton 7453: }
7454: else if (*selector == '+')
7455: {
1.340 quint 7456: /* handle immediate sibling */
1.327 vatton 7457: selector++;
7458: skippedNL = NewLineSkipped;
7459: selector = SkipBlanksAndComments (selector);
7460: NewLineSkipped = skippedNL;
7461: rel[0] = RelPrevious;
7462: }
1.340 quint 7463: else
7464: rel[0] = RelAncestor;
7465: nbnames++; /* a new level in ancestor tables */
7466: if (nbnames == MAX_ANCESTORS)
7467: /* abort parsing */
7468: {
7469: CSSPrintError ("Selector too long", deb);
7470: return (selector);
7471: }
7472: /* shift the list to make room for the next part of the selector */
7473: for (i = nbnames; i > 0; i--)
1.327 vatton 7474: {
7475: names[i] = names[i - 1];
1.355 quint 7476: pseudoFirstChild[i] = pseudoFirstChild[i - 1];
1.327 vatton 7477: rel[i] = rel[i - 1];
7478: }
1.340 quint 7479: /* increase the level of all attributes */
7480: for (i = 0; i < nbattrs; i++)
7481: attrlevels[i]++;
1.327 vatton 7482: }
1.1 cvs 7483: }
7484:
1.343 vatton 7485: /* Now update the list of classes defined by the CSS */
7486: for (i = 0; i < nbattrs; i++)
7487: if (attrvals[i] && attrnums[i] == ATTR_CLASS)
7488: AddClassName (attrvals[i], css);
7489:
1.1 cvs 7490: /* Now set up the context block */
1.25 cvs 7491: i = 0;
7492: j = 0;
1.91 cvs 7493: /* default schema name */
1.119 vatton 7494: ctxt->schema = NULL;
1.340 quint 7495: ctxt->nbElem = nbnames;
1.122 vatton 7496: elType.ElSSchema = NULL;
1.355 quint 7497: elType.ElTypeNum = 0;
1.122 vatton 7498: schemaName = TtaGetSSchemaName(TtaGetDocumentSSchema (doc));
1.119 vatton 7499: if (!strcmp (schemaName, "HTML"))
7500: xmlType = XHTML_TYPE;
7501: else if (!strcmp (schemaName, "MathML"))
7502: xmlType = MATH_TYPE;
7503: else if (!strcmp (schemaName, "SVG"))
7504: xmlType = SVG_TYPE;
7505: else if (!strcmp (schemaName, "XLink"))
7506: xmlType = XLINK_TYPE;
7507: else if (!strcmp (schemaName, "Annot"))
7508: xmlType = ANNOT_TYPE;
7509: else
7510: xmlType = XML_TYPE;
1.340 quint 7511: while (i <= nbnames)
1.25 cvs 7512: {
1.340 quint 7513: ctxt->rel[i] = rel[i];
1.355 quint 7514: ctxt->firstChild[i] = pseudoFirstChild[i];
7515: if (!names[i] && i > 0)
1.340 quint 7516: ctxt->name[i] = HTML_EL_ANY_TYPE;
7517: else
7518: /* store element information */
1.327 vatton 7519: {
7520: /* get the element type of this name in the current document */
7521: if (xmlType == XML_TYPE)
7522: /* it's a generic XML document. Check the main document schema */
7523: {
7524: elType.ElSSchema = TtaGetDocumentSSchema (doc);
1.355 quint 7525: elType.ElTypeNum = 0;
7526: if (names[i])
7527: TtaGetXmlElementType (names[i], &elType, &mappedName, doc);
1.327 vatton 7528: if (!elType.ElTypeNum)
7529: {
1.355 quint 7530: if (!names[i] || !strcmp (names[i], "*"))
1.327 vatton 7531: elType.ElTypeNum = HTML_EL_ANY_TYPE;
7532: else
7533: elType.ElSSchema = NULL;
7534: }
7535: }
7536: else
7537: {
1.355 quint 7538: if (!names[i] || !strcmp (names[i], "*"))
1.327 vatton 7539: {
7540: elType.ElSSchema = TtaGetDocumentSSchema (doc);
7541: elType.ElTypeNum = HTML_EL_ANY_TYPE;
7542: }
7543: else
7544: MapXMLElementType (xmlType, names[i], &elType, &mappedName, &c,
7545: &level, doc);
7546: }
7547: if (i == 0)
1.340 quint 7548: /* rightmost part of the selector */
1.327 vatton 7549: {
7550: if (elType.ElSSchema == NULL)
7551: {
1.340 quint 7552: /* element name not found. Search in all loaded schemas */
1.355 quint 7553: if (names[i])
7554: TtaGetXmlElementType (names[i], &elType, NULL, doc);
1.327 vatton 7555: if (elType.ElSSchema)
7556: {
7557: /* the element type concerns an imported nature */
7558: schemaName = TtaGetSSchemaName(elType.ElSSchema);
7559: if (!strcmp (schemaName, "HTML"))
7560: {
7561: if (xmlType == XHTML_TYPE &&
7562: DocumentMeta[doc] && DocumentMeta[doc]->xmlformat)
7563: /* the selector was found but the case is not correct */
7564: elType.ElSSchema = NULL;
7565: else
7566: xmlType = XHTML_TYPE;
7567: }
7568: else if (!strcmp (schemaName, "MathML"))
7569: xmlType = MATH_TYPE;
7570: else if (!strcmp (schemaName, "SVG"))
7571: xmlType = SVG_TYPE;
7572: else if (!strcmp (schemaName, "XLink"))
7573: xmlType = XLINK_TYPE;
7574: else if (!strcmp (schemaName, "Annot"))
7575: xmlType = ANNOT_TYPE;
7576: else
7577: xmlType = XML_TYPE;
7578: }
1.118 vatton 7579: #ifdef XML_GENERIC
1.327 vatton 7580: else if (xmlType == XML_TYPE)
7581: {
7582: /* Creation of a new element type in the main schema */
7583: elType.ElSSchema = TtaGetDocumentSSchema (doc);
1.355 quint 7584: if (names[i])
7585: TtaAppendXmlElement (names[i], &elType, &mappedName,
7586: doc);
1.327 vatton 7587: }
1.118 vatton 7588: #endif /* XML_GENERIC */
1.327 vatton 7589: else
7590: {
7591: if (xmlType != XHTML_TYPE)
7592: {
7593: MapXMLElementType (XHTML_TYPE, names[i], &elType,
7594: &mappedName, &c, &level, doc);
7595: if (elType.ElSSchema)
7596: elType.ElSSchema = GetXHTMLSSchema (doc);
7597: }
7598: if (elType.ElSSchema == NULL && xmlType != MATH_TYPE)
7599: {
7600: MapXMLElementType (MATH_TYPE, names[i], &elType,
7601: &mappedName, &c, &level, doc);
7602: if (elType.ElSSchema)
7603: elType.ElSSchema = GetMathMLSSchema (doc);
7604: }
7605: if (elType.ElSSchema == NULL && xmlType != SVG_TYPE)
7606: {
7607: MapXMLElementType (SVG_TYPE, names[i], &elType,
7608: &mappedName, &c, &level, doc);
7609: if (elType.ElSSchema)
7610: elType.ElSSchema = GetSVGSSchema (doc);
7611: }
7612: }
7613: }
7614:
7615: if (elType.ElSSchema == NULL)
7616: /* cannot apply these CSS rules */
7617: DoApply = FALSE;
7618: else
7619: {
1.340 quint 7620: /* Store the element type contained in the rightmost part of
7621: the selector */
7622: ctxt->schema = elType.ElSSchema;
1.327 vatton 7623: ctxt->type = elType.ElTypeNum;
7624: ctxt->name[0] = elType.ElTypeNum;
1.340 quint 7625: ctxt->rel[0] = RelVoid;
1.327 vatton 7626: }
7627: }
1.340 quint 7628: else
7629: /* not the rightmost part of the selector */
1.327 vatton 7630: {
1.340 quint 7631: if (elType.ElTypeNum != 0)
7632: ctxt->name[i] = elType.ElTypeNum;
7633: #ifdef XML_GENERIC
7634: else if (xmlType == XML_TYPE)
1.327 vatton 7635: {
1.340 quint 7636: TtaGetXmlElementType (names[i], &elType, NULL, doc);
7637: if (elType.ElTypeNum == 0)
1.327 vatton 7638: {
1.340 quint 7639: /* Creation of a new element type in the main schema */
7640: elType.ElSSchema = TtaGetDocumentSSchema (doc);
7641: TtaAppendXmlElement (names[i], &elType, &mappedName, doc);
1.327 vatton 7642: }
1.340 quint 7643: if (elType.ElTypeNum != 0)
7644: ctxt->name[i] = elType.ElTypeNum;
1.327 vatton 7645: }
1.340 quint 7646: #endif /* XML_GENERIC */
1.327 vatton 7647: }
1.340 quint 7648: }
7649:
7650: /* store attribute information for this element */
7651: while (j < nbattrs && attrlevels[j] <= i)
7652: {
7653: if (attrnames[j] || attrnums[j])
1.327 vatton 7654: {
1.340 quint 7655: if (attrnums[j] > 0)
1.327 vatton 7656: {
1.340 quint 7657: if (attrnums[j] == ATTR_CLASS)
1.327 vatton 7658: {
1.340 quint 7659: if (xmlType == SVG_TYPE)
7660: ctxt->attrType[j] = SVG_ATTR_class;
7661: else if (xmlType == MATH_TYPE)
7662: ctxt->attrType[j] = MathML_ATTR_class;
7663: else if (xmlType == XHTML_TYPE)
7664: ctxt->attrType[j] = HTML_ATTR_Class;
1.327 vatton 7665: else
1.119 vatton 7666: #ifdef XML_GENERIC
1.340 quint 7667: ctxt->attrType[j] = XML_ATTR_class;
1.107 cvs 7668: #else /* XML_GENERIC */
1.340 quint 7669: ctxt->attrType[j] = HTML_ATTR_Class;
1.107 cvs 7670: #endif /* XML_GENERIC */
1.340 quint 7671: }
7672: else if (attrnums[j] == ATTR_PSEUDO)
7673: {
7674: if (xmlType == SVG_TYPE)
7675: ctxt->attrType[j] = SVG_ATTR_PseudoClass;
7676: else if (xmlType == MATH_TYPE)
7677: ctxt->attrType[j] = MathML_ATTR_PseudoClass;
7678: else if (xmlType == XHTML_TYPE)
7679: ctxt->attrType[j] = HTML_ATTR_PseudoClass;
7680: else
1.119 vatton 7681: #ifdef XML_GENERIC
1.340 quint 7682: ctxt->attrType[j] = XML_ATTR_PseudoClass;
1.107 cvs 7683: #else /* XML_GENERIC */
1.340 quint 7684: ctxt->attrType[j] = HTML_ATTR_PseudoClass;
1.107 cvs 7685: #endif /* XML_GENERIC */
1.340 quint 7686: }
7687: else if (attrnums[j] == ATTR_ID)
7688: {
7689: if (xmlType == SVG_TYPE)
7690: ctxt->attrType[j] = SVG_ATTR_id;
7691: else if (xmlType == MATH_TYPE)
7692: ctxt->attrType[j] = MathML_ATTR_id;
7693: else if (xmlType == XHTML_TYPE)
7694: ctxt->attrType[j] = HTML_ATTR_ID;
7695: else
1.119 vatton 7696: #ifdef XML_GENERIC
1.340 quint 7697: ctxt->attrType[j] = XML_ATTR_xmlid;
1.107 cvs 7698: #else /* XML_GENERIC */
1.340 quint 7699: ctxt->attrType[j] = HTML_ATTR_ID;
1.107 cvs 7700: #endif /* XML_GENERIC */
1.340 quint 7701: }
7702: attrType.AttrTypeNum = ctxt->attrType[j];
7703: attrType.AttrSSchema = ctxt->schema;
7704: }
7705: else if (attrnames[j])
7706: {
7707: if (xmlType == XML_TYPE)
7708: {
7709: if (ctxt->schema)
7710: attrType.AttrSSchema = ctxt->schema;
7711: else
7712: attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
7713: TtaGetXmlAttributeType (attrnames[j], &attrType, doc);
7714: att = attrType.AttrTypeNum;
7715: if (ctxt->schema == NULL && att != 0)
7716: ctxt->schema = attrType.AttrSSchema;
7717: }
7718: else
7719: {
7720: MapXMLAttribute (xmlType, attrnames[j], names[i], &level,
7721: doc, &att);
7722: if (ctxt->schema == NULL && att != 0)
7723: ctxt->schema = TtaGetDocumentSSchema (doc);
7724: }
1.393 quint 7725: if (att == 0 && xmlType != XML_TYPE)
1.340 quint 7726: /* Attribute name not found: Search in the list of all
7727: schemas loaded for this document */
7728: {
7729: attrType.AttrSSchema = NULL;
7730: TtaGetXmlAttributeType (attrnames[j], &attrType, doc);
7731: att = attrType.AttrTypeNum;
7732: if (att != 0)
1.393 quint 7733: {
7734: ctxt->schema = attrType.AttrSSchema;
7735: schemaName = TtaGetSSchemaName(attrType.AttrSSchema);
7736: }
1.340 quint 7737: }
7738: attrType.AttrSSchema = ctxt->schema;
7739: attrType.AttrTypeNum = att;
1.412 vatton 7740: if ((i == 0 || xmlType == XML_TYPE) && att == 0)
1.340 quint 7741: {
1.119 vatton 7742: #ifdef XML_GENERIC
1.393 quint 7743: if (xmlType == XML_TYPE)
1.340 quint 7744: {
7745: /* The attribute is not yet present in the tree */
7746: /* Create a new global attribute */
7747: attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
7748: TtaAppendXmlAttribute (attrnames[j], &attrType, doc);
1.393 quint 7749: att = attrType.AttrTypeNum;
1.340 quint 7750: }
7751: #endif /* XML_GENERIC */
7752: if (attrType.AttrSSchema == NULL)
7753: /* cannot apply these CSS rules */
7754: DoApply = FALSE;
7755: else if (elType.ElSSchema)
7756: ctxt->schema = elType.ElSSchema;
7757: else
7758: ctxt->schema = attrType.AttrSSchema;
7759: }
7760: if (att == 0)
7761: {
7762: CSSPrintError ("Unknown attribute", attrnames[j]);
7763: DoApply = FALSE;
7764: }
7765: else
1.345 quint 7766: {
7767: ctxt->attrType[j] = att;
7768: if (att == DummyAttribute && !strcmp (schemaName,"HTML"))
7769: /* it's the "type" attribute for an "input" element.
7770: In the tree, it is represented by the element type,
7771: not by an attribute */
7772: {
7773: ctxt->attrType[j] = 0;
7774: if (attrvals[j] && attrmatch[i] == Txtmatch)
7775: /* a value is specified for attribute type. This
7776: value provides the Thot element type */
7777: {
7778: MapXMLAttributeValue (xmlType, attrvals[j],
7779: &attrType, &kind);
7780: /* attrType contains the element type */
7781: if (i == 0)
7782: ctxt->type = kind;
7783: ctxt->name[i] = kind;
7784: }
7785: }
7786: }
1.340 quint 7787: }
7788: if (ctxt->attrType[j])
1.327 vatton 7789: {
1.340 quint 7790: /* check the attribute type */
7791: if (!strcmp (schemaName, "HTML"))
7792: xmlType = XHTML_TYPE;
7793: else if (!strcmp (schemaName, "MathML"))
7794: xmlType = MATH_TYPE;
7795: else if (!strcmp (schemaName, "SVG"))
7796: xmlType = SVG_TYPE;
7797: else if (!strcmp (schemaName, "XLink"))
7798: xmlType = XLINK_TYPE;
7799: else if (!strcmp (schemaName, "Annot"))
7800: xmlType = ANNOT_TYPE;
7801: else
7802: xmlType = XML_TYPE;
7803: kind = TtaGetAttributeKind (attrType);
7804: if (kind == 0 && attrvals[j])
7805: {
7806: /* enumerated value */
7807: MapXMLAttributeValue (xmlType, attrvals[j], &attrType,
7808: &kind);
7809: /* store the attribute value */
7810: ctxt->attrText[j] = (char *) kind;
7811: }
7812: else
7813: ctxt->attrText[j] = attrvals[j];
7814: /* update attrLevel */
7815: ctxt->attrMatch[j] = attrmatch[j];
7816: ctxt->attrLevel[j] = attrlevels[j];
7817: }
7818: j++;
1.327 vatton 7819: }
7820: }
1.340 quint 7821: /* add a new entry */
1.25 cvs 7822: i++;
1.119 vatton 7823: if (i == 1 && ctxt->schema == NULL)
1.327 vatton 7824: /* use the document schema */
7825: ctxt->schema = TtaGetDocumentSSchema (doc);
1.1 cvs 7826: }
1.340 quint 7827:
1.312 quint 7828: ctxt->important = FALSE;
1.117 vatton 7829: /* set the selector specificity */
7830: ctxt->cssSpecificity = specificity;
1.25 cvs 7831: /* Get the schema name of the main element */
1.119 vatton 7832: schemaName = TtaGetSSchemaName (ctxt->schema);
7833: isHTML = (strcmp (schemaName, "HTML") == 0);
1.206 vatton 7834: tsch = GetPExtension (doc, ctxt->schema, css, link);
1.217 vatton 7835: skippedNL = NewLineSkipped;
1.380 vatton 7836: if (DoApply && tsch && cssRule)
1.317 vatton 7837: {
7838: if (css)
1.327 vatton 7839: {
7840: /* point the right URL for loaded images */
7841: saveURL = css->url;
7842: css->url = url;
7843: }
1.317 vatton 7844: else
1.327 vatton 7845: saveURL = NULL;
7846: ParseCSSRule (NULL, tsch, (PresentationContext) ctxt, cssRule, css, isHTML);
1.317 vatton 7847: if (css)
1.327 vatton 7848: /* restore previous url */
7849: css->url = saveURL;
1.317 vatton 7850: }
1.116 vatton 7851: /* future CSS rules should apply */
7852: DoApply = TRUE;
1.217 vatton 7853: if (selector)
7854: NewLineSkipped = skippedNL;
1.1 cvs 7855: return (selector);
7856: }
7857:
7858: /*----------------------------------------------------------------------
1.206 vatton 7859: ParseStyleDeclaration: parse a style declaration stored in the style
7860: element of a document
7861: We expect the style string to be of the form:
7862: .pinky, .awful { color: pink; font-family: helvetica }
1.231 vatton 7863: The parameter css points to the current CSS context.
7864: The parameter link points to the link element.
7865: The parameter url gives the URL of the parsed style sheet.
1.1 cvs 7866: ----------------------------------------------------------------------*/
1.206 vatton 7867: static void ParseStyleDeclaration (Element el, char *cssRule, Document doc,
1.327 vatton 7868: CSSInfoPtr css, Element link, char *url,
7869: ThotBool destroy)
1.1 cvs 7870: {
1.79 cvs 7871: GenericContext ctxt;
7872: char *decl_end;
7873: char *sel_end;
7874: char *selector;
1.1 cvs 7875:
7876: /* separate the selectors string */
1.82 cvs 7877: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 7878: decl_end = cssRule;
1.82 cvs 7879: while (*decl_end != EOS && *decl_end != '{')
1.286 quint 7880: {
7881: if (*decl_end == EOL)
1.327 vatton 7882: NewLineSkipped++;
1.286 quint 7883: decl_end++;
7884: }
1.82 cvs 7885: if (*decl_end == EOS)
1.86 cvs 7886: {
1.168 vatton 7887: CSSPrintError ("Invalid selector", cssRule);
1.86 cvs 7888: return;
7889: }
1.1 cvs 7890: /* verify and clean the selector string */
7891: sel_end = decl_end - 1;
1.82 cvs 7892: while (*sel_end == SPACE || *sel_end == BSPACE ||
1.411 vatton 7893: *sel_end == EOL || *sel_end == __CR__)
1.1 cvs 7894: sel_end--;
7895: sel_end++;
1.82 cvs 7896: *sel_end = EOS;
1.1 cvs 7897: selector = cssRule;
7898:
7899: /* now, deal with the content ... */
7900: decl_end++;
7901: cssRule = decl_end;
1.137 vatton 7902: decl_end = &cssRule[strlen (cssRule) - 1];
1.398 vatton 7903: if (*decl_end != '{' && *decl_end != EOS)
1.137 vatton 7904: *decl_end = EOS;
1.1 cvs 7905: /*
7906: * parse the style attribute string and install the corresponding
7907: * presentation attributes on the new element
7908: */
7909: ctxt = TtaGetGenericStyleContext (doc);
7910: if (ctxt == NULL)
7911: return;
7912: ctxt->destroy = destroy;
1.207 vatton 7913: /* first use of the context */
7914: ctxt->uses = 1;
1.197 vatton 7915: while (selector && *selector != EOS)
1.363 vatton 7916: {
7917: if (ctxt->uses > 1)
7918: {
7919: /* this context is waiting for a callback */
7920: ctxt = TtaGetGenericStyleContext (doc);
7921: if (ctxt == NULL)
7922: return;
7923: ctxt->destroy = destroy;
7924: /* first use of the context */
7925: ctxt->uses = 1;
7926: }
7927: selector = ParseGenericSelector (selector, cssRule, ctxt, doc, css,
7928: link, url);
7929: }
1.207 vatton 7930: /* check if the context can be freed */
7931: ctxt->uses -= 1;
7932: if (ctxt->uses == 0)
7933: /* no image loading */
7934: TtaFreeMemory (ctxt);
1.1 cvs 7935: }
7936:
7937: /************************************************************************
7938: * *
7939: * EVALUATION FUNCTIONS / CASCADING AND OVERLOADING *
7940: * *
7941: ************************************************************************/
7942:
7943: /*----------------------------------------------------------------------
1.327 vatton 7944: IsImplicitClassName: return wether the Class name is an
7945: implicit one, eg "H1" or "H2 EM" meaning it's a GI name
7946: or an HTML context name.
1.1 cvs 7947: ----------------------------------------------------------------------*/
1.248 gully 7948: int IsImplicitClassName (char *class_, Document doc)
1.1 cvs 7949: {
1.327 vatton 7950: char name[200];
7951: char *cur = name;
7952: char *first;
7953: char save;
7954: SSchema schema;
7955:
7956: /* make a local copy */
7957: strncpy (name, class_, 199);
7958: name[199] = 0;
7959:
7960: /* loop looking if each word is a GI */
7961: while (*cur != 0)
7962: {
7963: first = cur;
7964: cur = SkipWord (cur);
7965: save = *cur;
7966: *cur = 0;
7967: schema = NULL;
7968: if (MapGI (first, &schema, doc) == -1)
7969: {
7970: return (0);
7971: }
7972: *cur = save;
7973: cur = SkipBlanksAndComments (cur);
7974: }
7975: return (1);
1.1 cvs 7976: }
7977:
7978: /************************************************************************
1.114 quint 7979: * Functions needed for support of HTML: translate to CSS equivalent *
1.1 cvs 7980: ************************************************************************/
7981:
7982: /*----------------------------------------------------------------------
1.409 vatton 7983: SetBodyAbsolutePosition:
7984: ----------------------------------------------------------------------*/
7985: void SetBodyAbsolutePosition (Document doc)
7986: {
7987: Element root, body;
7988: ElementType elType;
7989:
7990: if (DocumentTypes[doc] != docHTML)
7991: return;
7992: root = TtaGetMainRoot (doc);
7993: elType = TtaGetElementType(root);
7994: elType.ElTypeNum = HTML_EL_BODY;
7995: body = TtaSearchTypedElement (elType, SearchInTree, root);
7996: if (body)
1.410 vatton 7997: ParseHTMLSpecificStyle (body, (char *)"position:absolute", doc, 200, FALSE);
1.409 vatton 7998: }
7999:
8000: /*----------------------------------------------------------------------
1.327 vatton 8001: HTMLSetBackgroundColor:
1.1 cvs 8002: ----------------------------------------------------------------------*/
1.264 vatton 8003: void HTMLSetBackgroundColor (Document doc, Element el, int specificity,
1.327 vatton 8004: char *color)
1.1 cvs 8005: {
1.350 vatton 8006: char css_command[1000];
1.1 cvs 8007:
1.416 vatton 8008: snprintf (css_command, 1000, "background-color: %50s", color);
1.327 vatton 8009: ParseHTMLSpecificStyle (el, css_command, doc, specificity, FALSE);
1.1 cvs 8010: }
8011:
8012: /*----------------------------------------------------------------------
1.327 vatton 8013: HTMLSetForegroundColor:
1.1 cvs 8014: ----------------------------------------------------------------------*/
1.264 vatton 8015: void HTMLSetForegroundColor (Document doc, Element el, int specificity,
1.327 vatton 8016: char *color)
1.1 cvs 8017: {
1.350 vatton 8018: char css_command[1000];
1.1 cvs 8019:
1.416 vatton 8020: snprintf (css_command, 1000, "color: %50s", color);
1.327 vatton 8021: ParseHTMLSpecificStyle (el, css_command, doc, specificity, FALSE);
1.1 cvs 8022: }
8023:
8024: /*----------------------------------------------------------------------
1.327 vatton 8025: HTMLResetBackgroundColor:
1.1 cvs 8026: ----------------------------------------------------------------------*/
1.97 vatton 8027: void HTMLResetBackgroundColor (Document doc, Element el)
1.1 cvs 8028: {
1.350 vatton 8029: char css_command[1000];
1.1 cvs 8030:
1.327 vatton 8031: sprintf (css_command, "background: red");
8032: ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1 cvs 8033: }
8034:
8035: /*----------------------------------------------------------------------
1.327 vatton 8036: HTMLResetBackgroundImage:
1.1 cvs 8037: ----------------------------------------------------------------------*/
1.97 vatton 8038: void HTMLResetBackgroundImage (Document doc, Element el)
1.1 cvs 8039: {
1.327 vatton 8040: char css_command[1000];
1.1 cvs 8041:
1.416 vatton 8042: snprintf (css_command, 1000, "background-image: url(xx); background-repeat: repeat");
1.327 vatton 8043: ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1 cvs 8044: }
8045:
8046: /*----------------------------------------------------------------------
1.327 vatton 8047: HTMLResetForegroundColor:
1.1 cvs 8048: ----------------------------------------------------------------------*/
1.97 vatton 8049: void HTMLResetForegroundColor (Document doc, Element el)
1.1 cvs 8050: {
1.350 vatton 8051: char css_command[1000];
1.1 cvs 8052:
1.327 vatton 8053: /* it's not necessary to well know the current color but it must be valid */
8054: sprintf (css_command, "color: red");
8055: ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1 cvs 8056: }
8057:
8058: /*----------------------------------------------------------------------
1.327 vatton 8059: HTMLSetAlinkColor:
1.1 cvs 8060: ----------------------------------------------------------------------*/
1.208 vatton 8061: void HTMLSetAlinkColor (Document doc, Element el, char *color)
1.1 cvs 8062: {
1.350 vatton 8063: char css_command[1000];
1.1 cvs 8064:
1.416 vatton 8065: snprintf (css_command, 1000, ":link { color: %50s }", color);
1.327 vatton 8066: ApplyCSSRules (el, css_command, doc, FALSE);
1.1 cvs 8067: }
8068:
8069: /*----------------------------------------------------------------------
1.327 vatton 8070: HTMLSetAactiveColor:
1.1 cvs 8071: ----------------------------------------------------------------------*/
1.208 vatton 8072: void HTMLSetAactiveColor (Document doc, Element el, char *color)
1.1 cvs 8073: {
1.350 vatton 8074: char css_command[1000];
1.1 cvs 8075:
1.416 vatton 8076: snprintf (css_command, 1000, ":active { color: %50s }", color);
1.327 vatton 8077: ApplyCSSRules (el, css_command, doc, FALSE);
1.1 cvs 8078: }
8079:
8080: /*----------------------------------------------------------------------
1.327 vatton 8081: HTMLSetAvisitedColor:
1.1 cvs 8082: ----------------------------------------------------------------------*/
1.208 vatton 8083: void HTMLSetAvisitedColor (Document doc, Element el, char *color)
1.1 cvs 8084: {
1.350 vatton 8085: char css_command[1000];
1.1 cvs 8086:
1.416 vatton 8087: snprintf (css_command, 1000, ":visited { color: %50s }", color);
1.327 vatton 8088: ApplyCSSRules (el, css_command, doc, FALSE);
1.1 cvs 8089: }
8090:
8091: /*----------------------------------------------------------------------
1.327 vatton 8092: HTMLResetAlinkColor:
1.1 cvs 8093: ----------------------------------------------------------------------*/
1.208 vatton 8094: void HTMLResetAlinkColor (Document doc, Element el)
1.1 cvs 8095: {
1.350 vatton 8096: char css_command[1000];
1.1 cvs 8097:
1.327 vatton 8098: sprintf (css_command, ":link { color: red }");
8099: ApplyCSSRules (el, css_command, doc, TRUE);
1.1 cvs 8100: }
8101:
8102: /*----------------------------------------------------------------------
1.327 vatton 8103: HTMLResetAactiveColor:
1.1 cvs 8104: ----------------------------------------------------------------------*/
1.208 vatton 8105: void HTMLResetAactiveColor (Document doc, Element el)
1.1 cvs 8106: {
1.350 vatton 8107: char css_command[1000];
1.1 cvs 8108:
1.327 vatton 8109: sprintf (css_command, ":active { color: red }");
8110: ApplyCSSRules (el, css_command, doc, TRUE);
1.1 cvs 8111: }
8112:
8113: /*----------------------------------------------------------------------
1.327 vatton 8114: HTMLResetAvisitedColor:
1.1 cvs 8115: ----------------------------------------------------------------------*/
1.208 vatton 8116: void HTMLResetAvisitedColor (Document doc, Element el)
1.1 cvs 8117: {
1.350 vatton 8118: char css_command[1000];
1.1 cvs 8119:
1.327 vatton 8120: sprintf (css_command, ":visited { color: red }");
8121: ApplyCSSRules (el, css_command, doc, TRUE);
1.1 cvs 8122: }
8123:
8124: /*----------------------------------------------------------------------
1.206 vatton 8125: ApplyCSSRules: parse a CSS Style description stored in the header of
8126: a HTML document.
1.1 cvs 8127: ----------------------------------------------------------------------*/
1.79 cvs 8128: void ApplyCSSRules (Element el, char *cssRule, Document doc, ThotBool destroy)
1.1 cvs 8129: {
1.206 vatton 8130: CSSInfoPtr css;
8131: PInfoPtr pInfo;
1.207 vatton 8132: ThotBool loadcss;
8133:
8134: /* check if we have to load CSS */
8135: TtaGetEnvBoolean ("LOAD_CSS", &loadcss);
8136: if (!loadcss)
8137: return;
1.376 vatton 8138: LineNumber = TtaGetElementLineNumber (el);
1.206 vatton 8139: css = SearchCSS (doc, NULL, el, &pInfo);
1.1 cvs 8140: if (css == NULL)
1.209 vatton 8141: {
8142: /* create the document css context */
8143: css = AddCSS (doc, doc, CSS_DOCUMENT_STYLE, CSS_ALL, NULL, NULL, el);
8144: pInfo = css->infos[doc];
8145: }
1.206 vatton 8146: else if (pInfo == NULL)
8147: /* create the entry into the css context */
8148: pInfo = AddInfoCSS (doc, css, CSS_DOCUMENT_STYLE, CSS_ALL, el);
1.209 vatton 8149: if (pInfo->PiEnabled)
1.376 vatton 8150: ParseStyleDeclaration (el, cssRule, doc, css, el, NULL, destroy);
8151: LineNumber = -1;
1.1 cvs 8152: }
8153:
8154: /*----------------------------------------------------------------------
1.327 vatton 8155: ReadCSSRules: is the front-end function called by the document parser
8156: when detecting a <style type="text/css"> indicating it's the
8157: beginning of a CSS fragment or when reading a file .css.
1.1 cvs 8158:
1.327 vatton 8159: The CSS parser has to handle <!-- ... --> constructs used to
8160: prevent prehistoric browser from displaying the CSS as a text
8161: content. It will stop on any sequence "<x" where x is different
8162: from ! and will return x as to the caller. Theorically x should
8163: be equal to / for the </style> end of style.
8164: The parameter doc gives the document tree that contains CSS information.
8165: The parameter docRef gives the document to which CSS are to be applied.
8166: This function uses the current css context or creates it. It's able
8167: to work on the given buffer or call GetNextChar to read the parsed
8168: file.
8169: The parameter url gives the URL of the parsed style sheet.
8170: The parameter numberOfLinesRead gives the number of lines already
8171: read in the file.
8172: The parameter withUndo indicates whether the changes made in the document
8173: structure and content have to be registered in the Undo queue or not.
1.1 cvs 8174: ----------------------------------------------------------------------*/
1.133 vatton 8175: char ReadCSSRules (Document docRef, CSSInfoPtr css, char *buffer, char *url,
1.343 vatton 8176: int numberOfLinesRead, ThotBool withUndo, Element link)
1.1 cvs 8177: {
1.6 cvs 8178: DisplayMode dispMode;
1.206 vatton 8179: CSSInfoPtr refcss = NULL;
1.321 vatton 8180: CSSmedia css_media = CSS_ALL;
1.206 vatton 8181: PInfoPtr pInfo;
1.321 vatton 8182: char c;
1.138 vatton 8183: char *cssRule, *base, *saveDocURL, *ptr;
1.19 cvs 8184: int index;
1.1 cvs 8185: int CSSindex;
1.327 vatton 8186: int CSScomment;
1.1 cvs 8187: int import;
1.358 quint 8188: int openBlock;
1.93 vatton 8189: int newlines;
1.358 quint 8190: int page;
1.14 cvs 8191: ThotBool HTMLcomment;
1.342 vatton 8192: ThotBool toParse, eof, quoted, s_quoted;
1.358 quint 8193: ThotBool ignore, media, lineComment;
1.234 vatton 8194: ThotBool noRule, ignoreImport, fontface;
1.1 cvs 8195:
1.327 vatton 8196: CSScomment = MAX_CSS_LENGTH;
1.1 cvs 8197: HTMLcomment = FALSE;
8198: CSSindex = 0;
8199: toParse = FALSE;
8200: noRule = FALSE;
1.234 vatton 8201: media = FALSE;
1.88 cvs 8202: ignoreImport = FALSE;
1.342 vatton 8203: ignore = lineComment = FALSE;
1.358 quint 8204: page = 0;
1.342 vatton 8205: quoted = s_quoted = FALSE;
1.234 vatton 8206: fontface = FALSE;
1.1 cvs 8207: eof = FALSE;
1.358 quint 8208: openBlock = 0;
1.234 vatton 8209: import = MAX_CSS_LENGTH;
1.82 cvs 8210: c = SPACE;
1.1 cvs 8211: index = 0;
1.134 vatton 8212: base = NULL;
1.310 vatton 8213: /* entering the CSS parsing */
1.311 vatton 8214: Style_parsing++;
1.93 vatton 8215: /* number of new lines parsed */
8216: newlines = 0;
1.6 cvs 8217: /* avoid too many redisplay */
8218: dispMode = TtaGetDisplayMode (docRef);
8219: if (dispMode == DisplayImmediately)
8220: TtaSetDisplayMode (docRef, DeferredDisplay);
1.18 cvs 8221:
8222: /* look for the CSS context */
8223: if (css == NULL)
1.206 vatton 8224: css = SearchCSS (docRef, NULL, link, &pInfo);
1.207 vatton 8225: else
8226: pInfo = css->infos[docRef];
1.18 cvs 8227: if (css == NULL)
1.206 vatton 8228: {
8229: css = AddCSS (docRef, docRef, CSS_DOCUMENT_STYLE, CSS_ALL, NULL, NULL, link);
8230: pInfo = css->infos[docRef];
8231: }
8232: else if (pInfo == NULL)
8233: pInfo = AddInfoCSS (docRef, css, CSS_DOCUMENT_STYLE, CSS_ALL, link);
1.174 vatton 8234: /* look for the CSS descriptor that points to the extension schema */
8235: refcss = css;
1.224 vatton 8236: if (pInfo && pInfo->PiCategory == CSS_IMPORT)
1.173 cvs 8237: {
1.206 vatton 8238: while (refcss &&
1.327 vatton 8239: refcss->infos[docRef] && refcss->infos[docRef]->PiCategory == CSS_IMPORT)
8240: refcss = refcss->NextCSS;
1.206 vatton 8241: if (refcss)
1.327 vatton 8242: pInfo = refcss->infos[docRef];
1.173 cvs 8243: }
8244:
1.343 vatton 8245: /* register parsed CSS file and the document to which CSS are to be applied */
1.395 vatton 8246: if (DocumentMeta[docRef] == NULL || DocumentMeta[docRef]->method != CE_MAKEBOOK)
8247: ParsedDoc = docRef;
8248: else
8249: ParsedDoc = 0;
1.343 vatton 8250: /* clean up the list of classes */
8251: TtaFreeMemory (refcss->class_list);
8252: refcss->class_list = NULL;
1.133 vatton 8253: if (url)
1.348 vatton 8254: Error_DocURL = url;
1.86 cvs 8255: else
8256: /* the CSS source in within the document itself */
1.348 vatton 8257: Error_DocURL = DocumentURLs[docRef];
1.86 cvs 8258: LineNumber = numberOfLinesRead + 1;
1.93 vatton 8259: NewLineSkipped = 0;
1.217 vatton 8260: newlines = 0;
1.392 carcone 8261:
8262: /* Search for an UTF-8 BOM character (EF BB BF) */
8263: if (index == 0 && strlen(buffer) > 2 &&
8264: (unsigned char) buffer[0] == 0xEF &&
8265: (unsigned char) buffer[1] == 0xBB &&
8266: (unsigned char) buffer[2] == 0xBF)
8267: {
8268: index = 3;
8269: }
8270:
8271: /* Search for an UTF-16 Big Endian BOM character (FE FF) */
8272: if (index == 0 && strlen(buffer) > 1 &&
8273: (unsigned char) buffer[0] == 0xFE &&
8274: (unsigned char) buffer[1] == 0xFF)
8275: {
8276: index = 2;
8277: }
8278:
8279: /* Search for an UTF-16 Little Endian BOM character (FF FE) */
8280: if (index == 0 && strlen(buffer) > 1 &&
8281: (unsigned char) buffer[0] == 0xFF &&
8282: (unsigned char) buffer[1] == 0xFE)
8283: {
8284: index = 2;
8285: }
8286:
1.82 cvs 8287: while (CSSindex < MAX_CSS_LENGTH && c != EOS && !eof)
8288: {
8289: c = buffer[index++];
8290: eof = (c == EOS);
8291: CSSbuffer[CSSindex] = c;
1.342 vatton 8292: if (!lineComment &&
8293: (CSScomment == MAX_CSS_LENGTH || c == '*' || c == '/' || c == '<' || c == EOL))
1.327 vatton 8294: {
8295: /* we're not within a comment or we're parsing * or / */
8296: switch (c)
8297: {
8298: case '@': /* perhaps an import primitive */
1.342 vatton 8299: if (!fontface && !page && !quoted && !s_quoted)
1.327 vatton 8300: import = CSSindex;
8301: break;
8302: case ';':
1.342 vatton 8303: if (!quoted && !s_quoted && !media && import != MAX_CSS_LENGTH)
1.327 vatton 8304: {
8305: if (strncasecmp (&CSSbuffer[import+1], "import", 6))
8306: /* it's not an import */
8307: import = MAX_CSS_LENGTH;
8308: /* save the text */
8309: noRule = TRUE;
8310: }
8311: break;
8312: case '*':
1.342 vatton 8313: if (!quoted && !s_quoted && CSScomment == MAX_CSS_LENGTH && CSSindex > 0 &&
1.327 vatton 8314: CSSbuffer[CSSindex - 1] == '/')
8315: /* start a comment */
8316: CSScomment = CSSindex - 1;
8317: break;
8318: case '/':
1.342 vatton 8319: if (!quoted && !s_quoted && CSSindex > 1 && CSScomment != MAX_CSS_LENGTH &&
1.399 vatton 8320: CSSbuffer[CSSindex - 1] == '*' && CSSindex != CSScomment + 2)
1.327 vatton 8321: {
8322: while (CSSindex > 0 && CSSindex >= CSScomment)
8323: {
8324: if ( CSSbuffer[CSSindex] == EOL)
8325: {
8326: LineNumber ++;
8327: newlines --;
8328: }
8329: CSSindex--;
8330: }
8331: CSSindex = CSScomment - 1; /* will be incremented later */
8332: CSScomment = MAX_CSS_LENGTH;
8333: /* clean up the buffer */
8334: if (newlines && CSSindex > 0)
8335: while (CSSindex > 0 &&
8336: (CSSbuffer[CSSindex] == SPACE ||
8337: CSSbuffer[CSSindex] == BSPACE ||
8338: CSSbuffer[CSSindex] == EOL ||
8339: CSSbuffer[CSSindex] == TAB ||
8340: CSSbuffer[CSSindex] == __CR__))
8341: {
8342: if ( CSSbuffer[CSSindex] == EOL)
8343: {
8344: LineNumber ++;
8345: newlines --;
8346: }
8347: CSSindex--;
8348: }
8349: }
1.342 vatton 8350: else if (!fontface && !page && !quoted && !s_quoted &&
1.327 vatton 8351: CSScomment == MAX_CSS_LENGTH && CSSindex > 0 &&
8352: CSSbuffer[CSSindex - 1] == '<')
8353: {
8354: /* this is the closing tag ! */
8355: CSSindex -= 2; /* remove </ from the CSS string */
8356: noRule = TRUE;
1.342 vatton 8357: }
8358: else if (!quoted && !s_quoted &&
8359: (CSSindex == 1 || (CSSindex > 1 && CSSbuffer[CSSindex - 2] == EOL)) &&
8360: CSScomment == MAX_CSS_LENGTH &&
8361: CSSbuffer[CSSindex - 1] == '/')
8362: {
8363: CSSindex--;
8364: lineComment = TRUE;
8365: }
8366:
1.327 vatton 8367: break;
8368: case '<':
1.342 vatton 8369: if (!fontface && !page && !quoted && !s_quoted &&
1.327 vatton 8370: CSScomment == MAX_CSS_LENGTH)
8371: {
8372: /* only if we're not parsing a comment */
8373: c = buffer[index++];
8374: eof = (c == EOS);
8375: if (c == '!')
8376: {
8377: /* CSS within an HTML comment */
8378: HTMLcomment = TRUE;
8379: CSSindex++;
8380: CSSbuffer[CSSindex] = c;
8381: }
8382: else if (c == EOS)
8383: CSSindex++;
8384: }
8385: break;
8386: case '-':
1.342 vatton 8387: if (!fontface && !page && !quoted && !s_quoted &&
1.327 vatton 8388: CSSindex > 0 && CSSbuffer[CSSindex - 1] == '-' &&
8389: HTMLcomment)
8390: /* CSS within an HTML comment */
8391: noRule = TRUE;
8392: break;
8393: case '>':
1.342 vatton 8394: if (!fontface && !page && !quoted && !s_quoted && HTMLcomment)
1.327 vatton 8395: noRule = TRUE;
8396: break;
8397: case ' ':
1.358 quint 8398: if (!quoted && !s_quoted && import != MAX_CSS_LENGTH && openBlock == 0)
1.327 vatton 8399: media = !strncasecmp (&CSSbuffer[import+1], "media", 5);
8400: break;
8401: case '{':
1.342 vatton 8402: if (!quoted && !s_quoted)
1.327 vatton 8403: {
1.358 quint 8404: openBlock++;
1.327 vatton 8405: if (import != MAX_CSS_LENGTH)
8406: {
1.358 quint 8407: if (openBlock == 1 && media)
1.327 vatton 8408: {
8409: /* is it the screen concerned? */
8410: CSSbuffer[CSSindex+1] = EOS;
8411: css_media = CheckMediaCSS (&CSSbuffer[import+7]);
8412: if (TtaIsPrinting ())
8413: ignore = (css_media != CSS_ALL && css_media != CSS_PRINT);
8414: else
8415: ignore = (css_media != CSS_ALL && css_media != CSS_SCREEN);
8416: noRule = TRUE;
8417: }
8418: else if (!strncasecmp (&CSSbuffer[import+1], "page", 4))
1.358 quint 8419: /* it is a @page block */
1.327 vatton 8420: {
1.358 quint 8421: page = openBlock;/*remember the level of this block*/
1.327 vatton 8422: noRule = TRUE;
8423: }
8424: else if (!strncasecmp (&CSSbuffer[import+1], "font-face", 9))
8425: {
8426: fontface = TRUE;
8427: noRule = TRUE;
8428: }
8429: }
8430: }
8431: break;
8432: case '}':
1.342 vatton 8433: if (!quoted && !s_quoted)
1.327 vatton 8434: {
1.358 quint 8435: if (page == openBlock)
8436: /* closing the @page block */
1.327 vatton 8437: {
8438: noRule = TRUE;
1.358 quint 8439: page = 0; /* close the page section */
1.327 vatton 8440: }
8441: else if (fontface)
8442: {
8443: noRule = TRUE;
8444: fontface = FALSE; /* close the fontface section */
8445: }
1.358 quint 8446: else if (openBlock == 1 && import != MAX_CSS_LENGTH)
1.327 vatton 8447: {
8448: import = MAX_CSS_LENGTH;
8449: noRule = TRUE;
8450: ignore = FALSE;
8451: media = FALSE;
8452: }
1.358 quint 8453: else if (!page)
1.327 vatton 8454: toParse = TRUE;
1.358 quint 8455: openBlock--;
1.327 vatton 8456: }
8457: break;
8458: case '"':
8459: if (quoted)
8460: {
1.342 vatton 8461: if (CSSindex > 0 && CSSbuffer[CSSindex - 1] != '\\')
1.327 vatton 8462: quoted = FALSE;
8463: }
1.342 vatton 8464: else if (!s_quoted)
1.327 vatton 8465: quoted = TRUE;
8466: break;
1.342 vatton 8467: case '\'':
8468: if (s_quoted)
8469: {
8470: if (CSSindex > 0 && CSSbuffer[CSSindex - 1] != '\\')
8471: s_quoted = FALSE;
8472: }
8473: else if (!quoted)
8474: s_quoted = TRUE;
8475: break;
8476: default:
1.327 vatton 8477: if (c == EOL)
8478: {
8479: newlines++;
8480: }
8481: break;
8482: }
1.82 cvs 8483: }
1.93 vatton 8484: else if (c == EOL)
1.327 vatton 8485: {
8486: LineNumber++;
1.342 vatton 8487: lineComment = FALSE;
1.411 vatton 8488: c = __CR__;
1.327 vatton 8489: }
1.234 vatton 8490:
1.411 vatton 8491: if (!lineComment && c != __CR__)
1.327 vatton 8492: CSSindex++;
1.82 cvs 8493:
8494: if (CSSindex >= MAX_CSS_LENGTH && CSScomment < MAX_CSS_LENGTH)
1.327 vatton 8495: /* we're still parsing a comment: remove the text comment */
8496: CSSindex = CSScomment;
1.82 cvs 8497:
8498: if (CSSindex >= MAX_CSS_LENGTH || toParse || noRule)
1.327 vatton 8499: {
8500: CSSbuffer[CSSindex] = EOS;
8501: /* parse a not empty string */
8502: if (CSSindex > 0)
8503: {
1.50 cvs 8504: /* apply CSS rule if it's not just a saving of text */
1.234 vatton 8505: if (!noRule && !ignore)
1.327 vatton 8506: {
8507: /* future import rules must be ignored */
8508: ignoreImport = TRUE;
8509: NewLineSkipped = 0;
8510: ParseStyleDeclaration (NULL, CSSbuffer, docRef, refcss,
8511: pInfo->PiLink, url, FALSE);
8512: LineNumber += newlines;
8513: newlines = 0;
8514: }
1.82 cvs 8515: else if (import != MAX_CSS_LENGTH &&
1.327 vatton 8516: !strncasecmp (&CSSbuffer[import+1], "import", 6))
8517: {
8518: /* import section */
8519: cssRule = &CSSbuffer[import+7];
1.405 kia 8520: cssRule = (char*)TtaSkipBlanks (cssRule);
1.327 vatton 8521: /* save the current line number */
8522: newlines += LineNumber;
8523: if (!strncasecmp (cssRule, "url", 3))
8524: {
1.50 cvs 8525: cssRule = &cssRule[3];
1.405 kia 8526: cssRule = (char*)TtaSkipBlanks (cssRule);
1.82 cvs 8527: if (*cssRule == '(')
1.327 vatton 8528: {
8529: cssRule++;
1.405 kia 8530: cssRule = (char*)TtaSkipBlanks (cssRule);
1.327 vatton 8531: quoted = (*cssRule == '"' || *cssRule == '\'');
8532: if (quoted)
8533: cssRule++;
8534: base = cssRule;
8535: while (*cssRule != EOS && *cssRule != ')')
8536: cssRule++;
8537: if (quoted)
8538: {
8539: /* isolate the file name */
8540: cssRule[-1] = EOS;
8541: quoted = FALSE;
8542: }
8543: else
8544: {
8545: /* remove extra spaces */
8546: if (cssRule[-1] == SPACE)
8547: {
8548: *cssRule = SPACE;
8549: cssRule--;
8550: while (cssRule[-1] == SPACE)
8551: cssRule--;
8552: }
8553: }
8554: *cssRule = EOS;
8555: }
8556: }
8557: else if (*cssRule == '"')
8558: {
8559: /*
8560: Do we have to accept single quotes?
8561: Double quotes are accepted here.
8562: Escaped quotes are not handled. See function SkipQuotedString
8563: */
8564: cssRule++;
1.405 kia 8565: cssRule = (char*)TtaSkipBlanks (cssRule);
1.327 vatton 8566: base = cssRule;
8567: while (*cssRule != EOS &&
8568: (*cssRule != '"' ||
8569: (*cssRule == '"' && cssRule[-1] == '\\')))
8570: cssRule++;
8571: /* isolate the file name */
8572: *cssRule = EOS;
8573: }
8574: /* check if a media is defined */
8575: cssRule++;
1.405 kia 8576: cssRule = (char*)TtaSkipBlanks (cssRule);
1.327 vatton 8577: if (*cssRule != ';')
8578: {
8579: css_media = CheckMediaCSS (cssRule);
8580: if (TtaIsPrinting ())
8581: ignoreImport = (css_media != CSS_ALL && css_media != CSS_PRINT);
8582: else
8583: ignoreImport = (css_media != CSS_ALL && css_media != CSS_SCREEN);
8584: }
8585: if (!ignoreImport)
8586: {
8587: /* save the displayed URL when an error is reported */
1.348 vatton 8588: saveDocURL = Error_DocURL;
1.327 vatton 8589: ptr = TtaStrdup (base);
8590: /* get the CSS URI in UTF-8 */
8591: /*ptr = ReallocUTF8String (ptr, docRef);*/
8592: LoadStyleSheet (base, docRef, (Element) css, css,
8593: url, pInfo->PiMedia,
8594: pInfo->PiCategory == CSS_USER_STYLE);
8595: /* restore the displayed URL when an error is reported */
1.348 vatton 8596: Error_DocURL = saveDocURL;
1.327 vatton 8597: TtaFreeMemory (ptr);
8598: }
8599: /* restore the number of lines */
8600: LineNumber = newlines;
8601: newlines = 0;
8602: NewLineSkipped = 0;
8603: import = MAX_CSS_LENGTH;
8604: }
8605: else
8606: {
8607: LineNumber += newlines;
8608: newlines = 0;
8609: }
8610: }
8611: toParse = FALSE;
8612: noRule = FALSE;
8613: CSSindex = 0;
1.50 cvs 8614: }
1.82 cvs 8615: }
1.310 vatton 8616: /* closing the CSS parsing */
1.311 vatton 8617: Style_parsing--;
1.330 cvs 8618: if (RedisplayImages == 0 && RedisplayBGImage && Style_parsing == 0)
1.310 vatton 8619: {
1.311 vatton 8620: /* CSS parsing finishes after a BG image was loaded */
1.310 vatton 8621: RedisplayBGImage = FALSE;
1.330 cvs 8622: if (dispMode != NoComputedDisplay)
8623: {
8624: //printf ("ReadCSS Show BGimages\n");
8625: TtaSetDisplayMode (docRef, NoComputedDisplay);
8626: TtaSetDisplayMode (docRef, dispMode);
8627: }
1.310 vatton 8628: }
1.330 cvs 8629: else if (dispMode != NoComputedDisplay)
1.311 vatton 8630: /* restore the display mode */
8631: TtaSetDisplayMode (docRef, dispMode);
1.86 cvs 8632:
8633: /* Prepare the context for style attributes */
1.348 vatton 8634: Error_DocURL = DocumentURLs[docRef];
1.86 cvs 8635: LineNumber = -1;
1.1 cvs 8636: return (c);
8637: }
Webmaster