Annotation of Amaya/amaya/styleparser.c, revision 1.26
1.1 cvs 1: /*
2: *
3: * (c) COPYRIGHT MIT and INRIA, 1996.
4: * Please first read the full copyright statement in file COPYRIGHT.
5: *
6: */
7:
8: /*
9: * Everything directly linked to the CSS syntax should now hopefully
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"
20: #include "undo.h"
1.25 cvs 21: #include "fetchHTMLname.h"
1.1 cvs 22:
23: typedef struct _BackgroundImageCallbackBlock
24: {
25: Element el;
26: PSchema tsch;
27: union
28: {
29: PresentationContextBlock specific;
30: GenericContextBlock generic;
31: } context;
32: }
33: BackgroundImageCallbackBlock, *BackgroundImageCallbackPtr;
34:
35: #include "AHTURLTools_f.h"
36: #include "HTMLpresentation_f.h"
37: #include "HTMLimage_f.h"
38: #include "UIcss_f.h"
39: #include "css_f.h"
1.24 cvs 40: #include "fetchHTMLname_f.h"
1.1 cvs 41: #include "html2thot_f.h"
42: #include "styleparser_f.h"
43:
44: #define MAX_BUFFER_LENGTH 200
45: /*
46: * A PropertyParser is a function used to parse the
47: * description substring associated to a given style attribute
48: * e.g. : "red" for a color attribute or "12pt bold helvetica"
49: * for a font attribute.
50: */
51: #ifdef __STDC__
1.17 cvs 52: typedef STRING (*PropertyParser) (Element element,
1.1 cvs 53: PSchema tsch,
54: PresentationContext context,
55: STRING cssRule,
56: CSSInfoPtr css,
1.14 cvs 57: ThotBool isHTML);
1.1 cvs 58: #else
1.17 cvs 59: typedef STRING (*PropertyParser) ();
1.1 cvs 60: #endif
61:
62: /* Description of the set of CSS properties supported */
63: typedef struct CSSProperty
64: {
65: STRING name;
1.25 cvs 66: PropertyParser parsing_function;
1.1 cvs 67: }
68: CSSProperty;
69:
70: #include "HTMLstyleColor.h"
71:
72: struct unit_def
73: {
74: STRING sign;
75: unsigned int unit;
76: };
77:
78: static struct unit_def CSSUnitNames[] =
79: {
1.18 cvs 80: {TEXT ("pt"), STYLE_UNIT_PT},
81: {TEXT ("pc"), STYLE_UNIT_PC},
82: {TEXT ("in"), STYLE_UNIT_IN},
83: {TEXT ("cm"), STYLE_UNIT_CM},
84: {TEXT ("mm"), STYLE_UNIT_MM},
85: {TEXT ("em"), STYLE_UNIT_EM},
86: {TEXT ("px"), STYLE_UNIT_PX},
87: {TEXT ("ex"), STYLE_UNIT_XHEIGHT},
88: {TEXT ("%"), STYLE_UNIT_PERCENT}
1.1 cvs 89: };
90:
91: #define NB_UNITS (sizeof(CSSUnitNames) / sizeof(struct unit_def))
92:
93: /*----------------------------------------------------------------------
94: ----------------------------------------------------------------------*/
95: #ifdef __STDC__
1.7 cvs 96: static unsigned int hexa_val (CHAR_T c)
1.1 cvs 97: #else
98: static unsigned int hexa_val (c)
1.7 cvs 99: CHAR_T c;
1.1 cvs 100: #endif
101: {
102: if (c >= '0' && c <= '9')
103: return (c - '0');
104: if (c >= 'a' && c <= 'f')
105: return (c - 'a' + 10);
106: if (c >= 'A' && c <= 'F')
107: return (c - 'A' + 10);
108: return (0);
109: }
110:
111: /*----------------------------------------------------------------------
112: SkipWord:
113: ----------------------------------------------------------------------*/
114: #ifdef __STDC__
115: static STRING SkipWord (STRING ptr)
116: #else
117: static STRING SkipWord (ptr)
118: STRING ptr;
119: #endif
120: {
121: while (isalnum(*ptr) || *ptr == '-' || *ptr == '%')
122: ptr++;
123: return (ptr);
124: }
125:
126: /*----------------------------------------------------------------------
1.13 cvs 127: SkipBlanksAndComments:
128: ----------------------------------------------------------------------*/
129: #ifdef __STDC__
1.23 cvs 130: STRING SkipBlanksAndComments (STRING ptr)
1.13 cvs 131: #else
1.23 cvs 132: STRING SkipBlanksAndComments (ptr)
133: STRING ptr;
1.13 cvs 134: #endif
135: {
136: ptr = TtaSkipBlanks (ptr);
137: while (ptr[0] == '/' && ptr[1] == '*')
138: {
139: /* look for the end of the comment */
140: ptr = &ptr[2];
141: while (ptr[0] != EOS && (ptr[0] != '*' || ptr[1] != '/'))
142: ptr++;
143: if (ptr[0] != EOS)
144: ptr = &ptr[2];
145: ptr = TtaSkipBlanks (ptr);
146: }
147: return (ptr);
148: }
149:
150: /*----------------------------------------------------------------------
1.1 cvs 151: SkipQuotedString:
152: ----------------------------------------------------------------------*/
153: #ifdef __STDC__
1.7 cvs 154: static STRING SkipQuotedString (STRING ptr, CHAR_T quote)
1.1 cvs 155: #else
156: static STRING SkipQuotedString (ptr, quote)
157: STRING ptr;
1.7 cvs 158: CHAR_T quote;
1.1 cvs 159: #endif
160: {
1.14 cvs 161: ThotBool stop;
1.1 cvs 162:
163: stop = FALSE;
164: while (!stop)
165: {
166: if (*ptr == quote)
167: {
168: ptr++;
169: stop = TRUE;
170: }
171: else if (*ptr == EOS)
172: stop = TRUE;
173: else if (*ptr == '\\')
174: /* escape character */
175: {
176: ptr++;
177: if ((*ptr >= '0' && *ptr <= '9') || (*ptr >= 'A' && *ptr <= 'F') ||
178: (*ptr >= 'a' && *ptr <= 'f'))
179: {
180: ptr++;
181: if ((*ptr >= '0' && *ptr <= '9') || (*ptr >= 'A' && *ptr <= 'F') ||
182: (*ptr >= 'a' && *ptr <= 'f'))
183: ptr++;
184: }
185: else
186: ptr++;
187: }
188: else
189: ptr++;
190: }
191: return (ptr);
192: }
193:
194: /*----------------------------------------------------------------------
195: SkipProperty:
196: ----------------------------------------------------------------------*/
197: #ifdef __STDC__
198: STRING SkipProperty (STRING ptr)
199: #else
200: STRING SkipProperty (ptr)
201: STRING ptr;
202: #endif
203: {
204: while (*ptr != EOS && *ptr != ';' && *ptr != '}')
205: ptr++;
206: return (ptr);
207: }
208:
209: /*----------------------------------------------------------------------
210: ParseCSSUnit :
211: parse a CSS Unit substring and returns the corresponding
212: value and its unit.
213: ----------------------------------------------------------------------*/
214: #ifdef __STDC__
215: static STRING ParseCSSUnit (STRING cssRule, PresentationValue *pval)
216: #else
217: static STRING ParseCSSUnit (cssRule, pval)
218: STRING cssRule;
219: PresentationValue *pval;
220: #endif
221: {
222: int val = 0;
223: int minus = 0;
224: int valid = 0;
225: int f = 0;
226: unsigned int uni;
1.14 cvs 227: ThotBool real = FALSE;
1.1 cvs 228:
229: pval->typed_data.unit = STYLE_UNIT_REL;
230: pval->typed_data.real = FALSE;
1.13 cvs 231: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 232: if (*cssRule == '-')
233: {
234: minus = 1;
235: cssRule++;
1.13 cvs 236: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 237: }
238:
239: if (*cssRule == '+')
240: {
241: cssRule++;
1.13 cvs 242: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 243: }
244:
245: while ((*cssRule >= '0') && (*cssRule <= '9'))
246: {
247: val *= 10;
248: val += *cssRule - '0';
249: cssRule++;
250: valid = 1;
251: }
252:
253: if (*cssRule == '.')
254: {
255: real = TRUE;
256: f = val;
257: val = 0;
258: cssRule++;
259: /* keep only 3 digits */
260: if (*cssRule >= '0' && *cssRule <= '9')
261: {
262: val = (*cssRule - '0') * 100;
263: cssRule++;
264: if (*cssRule >= '0' && *cssRule <= '9')
265: {
266: val += (*cssRule - '0') * 10;
267: cssRule++;
268: if ((*cssRule >= '0') && (*cssRule <= '9'))
269: {
270: val += *cssRule - '0';
271: cssRule++;
272: }
273: }
274:
275: while (*cssRule >= '0' && *cssRule <= '9')
276: cssRule++;
277: valid = 1;
278: }
279: }
280:
281: if (!valid)
282: {
283: cssRule = SkipWord (cssRule);
284: pval->typed_data.unit = STYLE_UNIT_INVALID;
285: pval->typed_data.value = 0;
286: }
287: else
288: {
1.13 cvs 289: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 290: for (uni = 0; uni < NB_UNITS; uni++)
291: {
292: if (!ustrncasecmp (CSSUnitNames[uni].sign, cssRule,
293: ustrlen (CSSUnitNames[uni].sign)))
294: {
295: pval->typed_data.unit = CSSUnitNames[uni].unit;
296: pval->typed_data.real = real;
297: if (real)
298: {
299: if (minus)
300: pval->typed_data.value = -(f * 1000 + val);
301: else
302: pval->typed_data.value = f * 1000 + val;
303: }
304: else
305: {
306: if (minus)
307: pval->typed_data.value = -val;
308: else
309: pval->typed_data.value = val;
310: }
311: return (cssRule + ustrlen (CSSUnitNames[uni].sign));
312: }
313: }
314:
315: /* not in the list of predefined units */
316: pval->typed_data.unit = STYLE_UNIT_REL;
317: pval->typed_data.real = real;
318: if (real)
319: {
320: if (minus)
321: pval->typed_data.value = -(f * 1000 + val);
322: else
323: pval->typed_data.value = f * 1000 + val;
324: }
325: else
326: {
327: if (minus)
328: pval->typed_data.value = -val;
329: else
330: pval->typed_data.value = val;
331: }
332: }
333: return (cssRule);
334: }
335:
336: /************************************************************************
337: * *
338: * PARSING FUNCTIONS *
339: * *
340: ************************************************************************/
341:
342: /************************************************************************
343: * *
344: * CORE OF THE CSS PARSER : THESE TAKE THE CSS STRINGS *
345: * PRODUCE THE CORECT DRIVER CONTEXT, AND DO THE PARSING *
346: * *
347: ************************************************************************/
348:
349: /*----------------------------------------------------------------------
350: ParseCSSBorderTopWidth : parse a CSS BorderTopWidth
351: attribute string.
352: ----------------------------------------------------------------------*/
353: #ifdef __STDC__
354: static STRING ParseCSSBorderTopWidth (Element element, PSchema tsch,
1.14 cvs 355: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 356: #else
357: static STRING ParseCSSBorderTopWidth (element, tsch, context, cssRule, css, isHTML)
358: Element element;
359: PSchema tsch;
360: PresentationContext context;
361: STRING cssRule;
362: CSSInfoPtr css;
1.14 cvs 363: ThotBool isHTML;
1.1 cvs 364: #endif
365: {
366: cssRule = SkipProperty (cssRule);
367: return (cssRule);
368: }
369:
370: /*----------------------------------------------------------------------
371: ParseCSSBorderRightWidth : parse a CSS BorderRightWidth
372: attribute string.
373: ----------------------------------------------------------------------*/
374: #ifdef __STDC__
375: static STRING ParseCSSBorderRightWidth (Element element, PSchema tsch,
1.14 cvs 376: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 377: #else
378: static STRING ParseCSSBorderRightWidth (element, tsch, context, cssRule, css, isHTML)
379: Element element;
380: PSchema tsch;
381: PresentationContext context;
382: STRING cssRule;
383: CSSInfoPtr css;
1.14 cvs 384: ThotBool isHTML;
1.1 cvs 385: #endif
386: {
387: cssRule = SkipProperty (cssRule);
388: return (cssRule);
389: }
390:
391: /*----------------------------------------------------------------------
392: ParseCSSBorderBottomWidth : parse a CSS BorderBottomWidth
393: attribute string.
394: ----------------------------------------------------------------------*/
395: #ifdef __STDC__
396: static STRING ParseCSSBorderBottomWidth (Element element, PSchema tsch,
1.14 cvs 397: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 398: #else
399: static STRING ParseCSSBorderBottomWidth (element, tsch, context, cssRule, css, isHTML)
400: Element element;
401: PSchema tsch;
402: PresentationContext context;
403: STRING cssRule;
404: CSSInfoPtr css;
1.14 cvs 405: ThotBool isHTML;
1.1 cvs 406: #endif
407: {
408: cssRule = SkipProperty (cssRule);
409: return (cssRule);
410: }
411:
412: /*----------------------------------------------------------------------
413: ParseCSSBorderLeftWidth : parse a CSS BorderLeftWidth
414: attribute string.
415: ----------------------------------------------------------------------*/
416: #ifdef __STDC__
417: static STRING ParseCSSBorderLeftWidth (Element element, PSchema tsch,
1.14 cvs 418: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 419: #else
420: static STRING ParseCSSBorderLeftWidth (element, tsch, context, cssRule, css, isHTML)
421: Element element;
422: PSchema tsch;
423: PresentationContext context;
424: STRING cssRule;
425: CSSInfoPtr css;
1.14 cvs 426: ThotBool isHTML;
1.1 cvs 427: #endif
428: {
429: cssRule = SkipProperty (cssRule);
430: return (cssRule);
431: }
432:
433: /*----------------------------------------------------------------------
434: ParseCSSBorderWidth : parse a CSS BorderWidth
435: attribute string.
436: ----------------------------------------------------------------------*/
437: #ifdef __STDC__
438: static STRING ParseCSSBorderWidth (Element element, PSchema tsch,
1.14 cvs 439: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 440: #else
441: static STRING ParseCSSBorderWidth (element, tsch, context, cssRule, css, isHTML)
442: Element element;
443: PSchema tsch;
444: PresentationContext context;
445: STRING cssRule;
446: CSSInfoPtr css;
1.14 cvs 447: ThotBool isHTML;
1.1 cvs 448: #endif
449: {
450: cssRule = SkipProperty (cssRule);
451: return (cssRule);
452: }
453:
454: /*----------------------------------------------------------------------
455: ParseCSSBorderTop : parse a CSS BorderTop
456: attribute string.
457: ----------------------------------------------------------------------*/
458: #ifdef __STDC__
459: static STRING ParseCSSBorderTop (Element element, PSchema tsch,
1.14 cvs 460: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 461: #else
462: static STRING ParseCSSBorderTop (element, tsch, context, cssRule, css, isHTML)
463: Element element;
464: PSchema tsch;
465: PresentationContext context;
466: STRING cssRule;
467: CSSInfoPtr css;
1.14 cvs 468: ThotBool isHTML;
1.1 cvs 469: #endif
470: {
471: cssRule = SkipProperty (cssRule);
472: return (cssRule);
473: }
474:
475: /*----------------------------------------------------------------------
476: ParseCSSBorderRight : parse a CSS BorderRight
477: attribute string.
478: ----------------------------------------------------------------------*/
479: #ifdef __STDC__
480: static STRING ParseCSSBorderRight (Element element, PSchema tsch,
1.14 cvs 481: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 482: #else
483: static STRING ParseCSSBorderRight (element, tsch, context, cssRule, css, isHTML)
484: Element element;
485: PSchema tsch;
486: PresentationContext context;
487: STRING cssRule;
488: CSSInfoPtr css;
1.14 cvs 489: ThotBool isHTML;
1.1 cvs 490: #endif
491: {
492: cssRule = SkipProperty (cssRule);
493: return (cssRule);
494: }
495:
496: /*----------------------------------------------------------------------
497: ParseCSSBorderBottom : parse a CSS BorderBottom
498: attribute string.
499: ----------------------------------------------------------------------*/
500: #ifdef __STDC__
501: static STRING ParseCSSBorderBottom (Element element, PSchema tsch,
1.14 cvs 502: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 503: #else
504: static STRING ParseCSSBorderBottom (element, tsch, context, cssRule, css, isHTML)
505: Element element;
506: PSchema tsch;
507: PresentationContext context;
508: STRING cssRule;
509: CSSInfoPtr css;
1.14 cvs 510: ThotBool isHTML;
1.1 cvs 511: #endif
512: {
513: cssRule = SkipProperty (cssRule);
514: return (cssRule);
515: }
516:
517: /*----------------------------------------------------------------------
518: ParseCSSBorderLeft : parse a CSS BorderLeft
519: attribute string.
520: ----------------------------------------------------------------------*/
521: #ifdef __STDC__
522: static STRING ParseCSSBorderLeft (Element element, PSchema tsch,
1.14 cvs 523: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 524: #else
525: static STRING ParseCSSBorderLeft (element, tsch, context, cssRule, css, isHTML)
526: Element element;
527: PSchema tsch;
528: PresentationContext context;
529: STRING cssRule;
530: CSSInfoPtr css;
1.14 cvs 531: ThotBool isHTML;
1.1 cvs 532: #endif
533: {
534: cssRule = SkipProperty (cssRule);
535: return (cssRule);
536: }
537:
538: /*----------------------------------------------------------------------
539: ParseCSSBorderColor : parse a CSS border-color
540: attribute string.
541: ----------------------------------------------------------------------*/
542: #ifdef __STDC__
543: static STRING ParseCSSBorderColor (Element element, PSchema tsch,
1.14 cvs 544: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 545: #else
546: static STRING ParseCSSBorderColor (element, tsch, context, cssRule, css, isHTML)
547: Element element;
548: PSchema tsch;
549: PresentationContext context;
550: STRING cssRule;
551: CSSInfoPtr css;
1.14 cvs 552: ThotBool isHTML;
1.1 cvs 553: #endif
554: {
555: cssRule = SkipProperty (cssRule);
556: return (cssRule);
557: }
558:
559: /*----------------------------------------------------------------------
560: ParseCSSBorderStyle : parse a CSS border-style
561: attribute string.
562: ----------------------------------------------------------------------*/
563: #ifdef __STDC__
564: static STRING ParseCSSBorderStyle (Element element, PSchema tsch,
1.14 cvs 565: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 566: #else
567: static STRING ParseCSSBorderStyle (element, tsch, context, cssRule, css, isHTML)
568: Element element;
569: PSchema tsch;
570: PresentationContext context;
571: STRING cssRule;
572: CSSInfoPtr css;
1.14 cvs 573: ThotBool isHTML;
1.1 cvs 574: #endif
575: {
576: cssRule = SkipProperty (cssRule);
577: return (cssRule);
578: }
579:
580: /*----------------------------------------------------------------------
581: ParseCSSBorder : parse a CSS border
582: attribute string.
583: ----------------------------------------------------------------------*/
584: #ifdef __STDC__
585: static STRING ParseCSSBorder (Element element, PSchema tsch,
1.14 cvs 586: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 587: #else
588: static STRING ParseCSSBorder (element, tsch, context, cssRule, css, isHTML)
589: Element element;
590: PSchema tsch;
591: PresentationContext context;
592: STRING cssRule;
593: CSSInfoPtr css;
1.14 cvs 594: ThotBool isHTML;
1.1 cvs 595: #endif
596: {
597: cssRule = SkipProperty (cssRule);
598: return (cssRule);
599: }
600:
601: /*----------------------------------------------------------------------
602: ParseCSSClear : parse a CSS clear attribute string
603: ----------------------------------------------------------------------*/
604: #ifdef __STDC__
605: static STRING ParseCSSClear (Element element, PSchema tsch,
1.14 cvs 606: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 607: #else
608: static STRING ParseCSSClear (element, tsch, context, cssRule, css, isHTML)
609: Element element;
610: PSchema tsch;
611: PresentationContext context;
612: STRING cssRule;
613: CSSInfoPtr css;
1.14 cvs 614: ThotBool isHTML;
1.1 cvs 615: #endif
616: {
617: cssRule = SkipProperty (cssRule);
618: return (cssRule);
619: }
620:
621: /*----------------------------------------------------------------------
622: ParseCSSDisplay : parse a CSS display attribute string
623: ----------------------------------------------------------------------*/
624: #ifdef __STDC__
625: static STRING ParseCSSDisplay (Element element, PSchema tsch,
1.14 cvs 626: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 627: #else
628: static STRING ParseCSSDisplay (element, tsch, context, cssRule, css, isHTML)
629: Element element;
630: PSchema tsch;
631: PresentationContext context;
632: STRING cssRule;
633: CSSInfoPtr css;
1.14 cvs 634: ThotBool isHTML;
1.1 cvs 635: #endif
636: {
637: PresentationValue pval;
638:
639: pval.typed_data.unit = STYLE_UNIT_REL;
640: pval.typed_data.real = FALSE;
1.13 cvs 641: cssRule = SkipBlanksAndComments (cssRule);
1.17 cvs 642: if (!ustrncasecmp (cssRule, TEXT("block"), 5))
1.1 cvs 643: {
644: pval.typed_data.value = STYLE_NOTINLINE;
645: TtaSetStylePresentation (PRLine, element, tsch, context, pval);
646: cssRule = SkipWord (cssRule);
647: }
1.17 cvs 648: else if (!ustrncasecmp (cssRule, TEXT("inline"), 6))
1.1 cvs 649: {
650: pval.typed_data.value = STYLE_INLINE;
651: TtaSetStylePresentation (PRLine, element, tsch, context, pval);
652: cssRule = SkipWord (cssRule);
653: }
1.17 cvs 654: else if (!ustrncasecmp (cssRule, TEXT("none"), 4))
1.1 cvs 655: {
656: pval.typed_data.value = STYLE_HIDE;
657: TtaSetStylePresentation (PRVisibility, element, tsch, context, pval);
658: cssRule = SkipWord (cssRule);
659: }
1.17 cvs 660: else if (!ustrncasecmp (cssRule, TEXT("list-item"), 9))
1.1 cvs 661: cssRule = SkipProperty (cssRule);
662: else
663: fprintf (stderr, "invalid display value %s\n", cssRule);
664: return (cssRule);
665: }
666:
667: /*----------------------------------------------------------------------
668: ParseCSSFloat : parse a CSS float attribute string
669: ----------------------------------------------------------------------*/
670: #ifdef __STDC__
671: static STRING ParseCSSFloat (Element element, PSchema tsch,
1.14 cvs 672: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 673: #else
674: static STRING ParseCSSFloat (element, tsch, context, cssRule, css, isHTML)
675: Element element;
676: PSchema tsch;
677: PresentationContext context;
678: STRING cssRule;
679: CSSInfoPtr css;
1.14 cvs 680: ThotBool isHTML;
1.1 cvs 681: #endif
682: {
683: cssRule = SkipProperty (cssRule);
684: return (cssRule);
685: }
686:
687: /*----------------------------------------------------------------------
688: ParseCSSLetterSpacing : parse a CSS letter-spacing
689: attribute string.
690: ----------------------------------------------------------------------*/
691: #ifdef __STDC__
692: static STRING ParseCSSLetterSpacing (Element element, PSchema tsch,
1.14 cvs 693: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 694: #else
695: static STRING ParseCSSLetterSpacing (element, tsch, context, cssRule, css, isHTML)
696: Element element;
697: PSchema tsch;
698: PresentationContext context;
699: STRING cssRule;
700: CSSInfoPtr css;
1.14 cvs 701: ThotBool isHTML;
1.1 cvs 702: #endif
703: {
704: cssRule = SkipProperty (cssRule);
705: return (cssRule);
706: }
707:
708: /*----------------------------------------------------------------------
709: ParseCSSListStyleType : parse a CSS list-style-type
710: attribute string.
711: ----------------------------------------------------------------------*/
712: #ifdef __STDC__
713: static STRING ParseCSSListStyleType (Element element, PSchema tsch,
1.14 cvs 714: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 715: #else
716: static STRING ParseCSSListStyleType (element, tsch, context, cssRule, css, isHTML)
717: Element element;
718: PSchema tsch;
719: PresentationContext context;
720: STRING cssRule;
721: CSSInfoPtr css;
1.14 cvs 722: ThotBool isHTML;
1.1 cvs 723: #endif
724: {
725: cssRule = SkipProperty (cssRule);
726: return (cssRule);
727: }
728:
729: /*----------------------------------------------------------------------
730: ParseCSSListStyleImage : parse a CSS list-style-image
731: attribute string.
732: ----------------------------------------------------------------------*/
733: #ifdef __STDC__
734: static STRING ParseCSSListStyleImage (Element element, PSchema tsch,
1.14 cvs 735: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 736: #else
737: static STRING ParseCSSListStyleImage (element, tsch, context, cssRule, css, isHTML)
738: Element element;
739: PSchema tsch;
740: PresentationContext context;
741: STRING cssRule;
742: CSSInfoPtr css;
1.14 cvs 743: ThotBool isHTML;
1.1 cvs 744: #endif
745: {
746: cssRule = SkipProperty (cssRule);
747: return (cssRule);
748: }
749:
750: /*----------------------------------------------------------------------
751: ParseCSSListStylePosition : parse a CSS list-style-position
752: attribute string.
753: ----------------------------------------------------------------------*/
754: #ifdef __STDC__
755: static STRING ParseCSSListStylePosition (Element element, PSchema tsch,
1.14 cvs 756: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 757: #else
758: static STRING ParseCSSListStylePosition (element, tsch, context, cssRule, css, isHTML)
759: Element element;
760: PSchema tsch;
761: PresentationContext context;
762: STRING cssRule;
763: CSSInfoPtr css;
1.14 cvs 764: ThotBool isHTML;
1.1 cvs 765: #endif
766: {
767: cssRule = SkipProperty (cssRule);
768: return (cssRule);
769: }
770:
771: /*----------------------------------------------------------------------
772: ParseCSSListStyle : parse a CSS list-style
773: attribute string.
774: ----------------------------------------------------------------------*/
775: #ifdef __STDC__
776: static STRING ParseCSSListStyle (Element element, PSchema tsch,
1.14 cvs 777: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 778: #else
779: static STRING ParseCSSListStyle (element, tsch, context, cssRule, css, isHTML)
780: Element element;
781: PSchema tsch;
782: PresentationContext context;
783: STRING cssRule;
784: CSSInfoPtr css;
1.14 cvs 785: ThotBool isHTML;
1.1 cvs 786: #endif
787: {
788: cssRule = SkipProperty (cssRule);
789: return (cssRule);
790: }
791:
792: /*----------------------------------------------------------------------
793: ParseCSSTextAlign : parse a CSS text-align
794: attribute string.
795: ----------------------------------------------------------------------*/
796: #ifdef __STDC__
797: static STRING ParseCSSTextAlign (Element element, PSchema tsch,
1.14 cvs 798: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 799: #else
800: static STRING ParseCSSTextAlign (element, tsch, context, cssRule, css, isHTML)
801: Element element;
802: PSchema tsch;
803: PresentationContext context;
804: STRING cssRule;
805: CSSInfoPtr css;
1.14 cvs 806: ThotBool isHTML;
1.1 cvs 807: #endif
808: {
809: PresentationValue align;
810: PresentationValue justify;
811:
812: align.typed_data.value = 0;
813: align.typed_data.unit = STYLE_UNIT_REL;
814: align.typed_data.real = FALSE;
815: justify.typed_data.value = 0;
816: justify.typed_data.unit = STYLE_UNIT_REL;
817: justify.typed_data.real = FALSE;
818:
1.13 cvs 819: cssRule = SkipBlanksAndComments (cssRule);
1.17 cvs 820: if (!ustrncasecmp (cssRule, TEXT("left"), 4))
1.1 cvs 821: {
822: align.typed_data.value = AdjustLeft;
823: cssRule = SkipWord (cssRule);
824: }
1.17 cvs 825: else if (!ustrncasecmp (cssRule, TEXT("right"), 5))
1.1 cvs 826: {
827: align.typed_data.value = AdjustRight;
828: cssRule = SkipWord (cssRule);
829: }
1.17 cvs 830: else if (!ustrncasecmp (cssRule, TEXT("center"), 6))
1.1 cvs 831: {
832: align.typed_data.value = Centered;
833: cssRule = SkipWord (cssRule);
834: }
1.17 cvs 835: else if (!ustrncasecmp (cssRule, TEXT("justify"), 7))
1.1 cvs 836: {
837: justify.typed_data.value = Justified;
838: cssRule = SkipWord (cssRule);
839: }
840: else
841: {
842: fprintf (stderr, "invalid align value\n");
843: return (cssRule);
844: }
845:
846: /*
847: * install the new presentation.
848: */
849: if (align.typed_data.value)
850: {
851: TtaSetStylePresentation (PRAdjust, element, tsch, context, align);
852: }
853: if (justify.typed_data.value)
854: {
855: TtaSetStylePresentation (PRJustify, element, tsch, context, justify);
856: TtaSetStylePresentation (PRHyphenate, element, tsch, context, justify);
857: }
858: return (cssRule);
859: }
860:
861: /*----------------------------------------------------------------------
862: ParseCSSTextIndent : parse a CSS text-indent
863: attribute string.
864: ----------------------------------------------------------------------*/
865: #ifdef __STDC__
866: static STRING ParseCSSTextIndent (Element element, PSchema tsch,
1.14 cvs 867: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 868: #else
869: static STRING ParseCSSTextIndent (element, tsch, context, cssRule, css, isHTML)
870: Element element;
871: PSchema tsch;
872: PresentationContext context;
873: STRING cssRule;
874: CSSInfoPtr css;
1.14 cvs 875: ThotBool isHTML;
1.1 cvs 876: #endif
877: {
878: PresentationValue pval;
879:
1.13 cvs 880: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 881: cssRule = ParseCSSUnit (cssRule, &pval);
882: if (pval.typed_data.unit == STYLE_UNIT_INVALID)
883: return (cssRule);
884: /* install the attribute */
885: TtaSetStylePresentation (PRIndent, element, tsch, context, pval);
886: return (cssRule);
887: }
888:
889: /*----------------------------------------------------------------------
890: ParseCSSTextTransform : parse a CSS text-transform
891: attribute string.
892: ----------------------------------------------------------------------*/
893: #ifdef __STDC__
894: static STRING ParseCSSTextTransform (Element element, PSchema tsch,
1.14 cvs 895: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 896: #else
897: static STRING ParseCSSTextTransform (element, tsch, context, cssRule, css, isHTML)
898: Element element;
899: PSchema tsch;
900: PresentationContext context;
901: STRING cssRule;
902: CSSInfoPtr css;
1.14 cvs 903: ThotBool isHTML;
1.1 cvs 904: #endif
905: {
906: cssRule = SkipProperty (cssRule);
907: return (cssRule);
908: }
909:
910: /*----------------------------------------------------------------------
911: ParseCSSVerticalAlign : parse a CSS vertical-align
912: attribute string.
913: ----------------------------------------------------------------------*/
914: #ifdef __STDC__
915: static STRING ParseCSSVerticalAlign (Element element, PSchema tsch,
1.14 cvs 916: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 917: #else
918: static STRING ParseCSSVerticalAlign (element, tsch, context, cssRule, css, isHTML)
919: Element element;
920: PSchema tsch;
921: PresentationContext context;
922: STRING cssRule;
923: CSSInfoPtr css;
1.14 cvs 924: ThotBool isHTML;
1.1 cvs 925: #endif
926: {
927: cssRule = SkipProperty (cssRule);
928: return (cssRule);
929: }
930:
931: /*----------------------------------------------------------------------
932: ParseCSSWhiteSpace : parse a CSS white-space
933: attribute string.
934: ----------------------------------------------------------------------*/
935: #ifdef __STDC__
936: static STRING ParseCSSWhiteSpace (Element element, PSchema tsch,
1.14 cvs 937: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 938: #else
939: static STRING ParseCSSWhiteSpace (element, tsch, context, cssRule, css, isHTML)
940: Element element;
941: PSchema tsch;
942: PresentationContext context;
943: STRING cssRule;
944: CSSInfoPtr css;
1.14 cvs 945: ThotBool isHTML;
1.1 cvs 946: #endif
947: {
1.13 cvs 948: cssRule = SkipBlanksAndComments (cssRule);
1.17 cvs 949: if (!ustrncasecmp (cssRule, TEXT("normal"), 6))
1.1 cvs 950: cssRule = SkipWord (cssRule);
1.17 cvs 951: else if (!ustrncasecmp (cssRule, TEXT("pre"), 3))
1.1 cvs 952: cssRule = SkipWord (cssRule);
953: else
954: return (cssRule);
955: return (cssRule);
956: }
957:
958: /*----------------------------------------------------------------------
959: ParseCSSWordSpacing : parse a CSS word-spacing
960: attribute string.
961: ----------------------------------------------------------------------*/
962: #ifdef __STDC__
963: static STRING ParseCSSWordSpacing (Element element, PSchema tsch,
1.14 cvs 964: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 965: #else
966: static STRING ParseCSSWordSpacing (element, tsch, context, cssRule, css, isHTML)
967: Element element;
968: PSchema tsch;
969: PresentationContext context;
970: STRING cssRule;
971: CSSInfoPtr css;
1.14 cvs 972: ThotBool isHTML;
1.1 cvs 973: #endif
974: {
975: cssRule = SkipProperty (cssRule);
976: return (cssRule);
977: }
978:
979: /*----------------------------------------------------------------------
1.25 cvs 980: ParseCSSLineSpacing : parse a CSS font leading string
981: we expect the input string describing the attribute to be
982: value% or value
983: ----------------------------------------------------------------------*/
984: #ifdef __STDC__
985: static STRING ParseCSSLineSpacing (Element element, PSchema tsch,
986: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
987: #else
988: static STRING ParseCSSLineSpacing (element, tsch, context, cssRule, css, isHTML)
989: Element element;
990: PSchema tsch;
991: PresentationContext context;
992: STRING cssRule;
993: CSSInfoPtr css;
994: ThotBool isHTML;
995: #endif
996: {
997: PresentationValue lead;
998:
999: cssRule = ParseCSSUnit (cssRule, &lead);
1000: if (lead.typed_data.unit == STYLE_UNIT_INVALID)
1001: {
1002: /* invalid line spacing */
1003: return (cssRule);
1004: }
1005: /* install the new presentation */
1006: TtaSetStylePresentation (PRLineSpacing, element, tsch, context, lead);
1007: return (cssRule);
1008: }
1009:
1010: /*----------------------------------------------------------------------
1.1 cvs 1011: ParseCSSFontSize : parse a CSS font size attr string
1012: we expect the input string describing the attribute to be
1013: xx-small, x-small, small, medium, large, x-large, xx-large
1014: or an absolute size, or an imcrement relative to the parent
1015: ----------------------------------------------------------------------*/
1016: #ifdef __STDC__
1017: static STRING ParseCSSFontSize (Element element, PSchema tsch,
1.14 cvs 1018: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1019: #else
1020: static STRING ParseCSSFontSize (element, tsch, context, cssRule, css, isHTML)
1021: Element element;
1022: PSchema tsch;
1023: PresentationContext context;
1024: STRING cssRule;
1025: CSSInfoPtr css;
1.14 cvs 1026: ThotBool isHTML;
1.1 cvs 1027: #endif
1028: {
1029: PresentationValue pval;
1.25 cvs 1030: STRING ptr = NULL;
1.14 cvs 1031: ThotBool real;
1.1 cvs 1032:
1033: pval.typed_data.real = FALSE;
1.13 cvs 1034: cssRule = SkipBlanksAndComments (cssRule);
1.17 cvs 1035: if (!ustrncasecmp (cssRule, TEXT("larger"), 6))
1.1 cvs 1036: {
1037: pval.typed_data.unit = STYLE_UNIT_PERCENT;
1038: pval.typed_data.value = 130;
1039: cssRule = SkipWord (cssRule);
1040: }
1.17 cvs 1041: else if (!ustrncasecmp (cssRule, TEXT("smaller"), 7))
1.1 cvs 1042: {
1043: pval.typed_data.unit = STYLE_UNIT_PERCENT;
1044: pval.typed_data.value = 80;
1045: cssRule = SkipWord (cssRule);
1046: }
1.17 cvs 1047: else if (!ustrncasecmp (cssRule, TEXT("xx-small"), 8))
1.1 cvs 1048: {
1049: pval.typed_data.unit = STYLE_UNIT_REL;
1050: pval.typed_data.value = 1;
1051: cssRule = SkipWord (cssRule);
1052: }
1.17 cvs 1053: else if (!ustrncasecmp (cssRule, TEXT("x-small"), 7))
1.1 cvs 1054: {
1055: pval.typed_data.unit = STYLE_UNIT_REL;
1056: pval.typed_data.value = 2;
1057: cssRule = SkipWord (cssRule);
1058: }
1.17 cvs 1059: else if (!ustrncasecmp (cssRule, TEXT("small"), 5))
1.1 cvs 1060: {
1061: pval.typed_data.unit = STYLE_UNIT_REL;
1062: pval.typed_data.value = 3;
1063: cssRule = SkipWord (cssRule);
1064: }
1.17 cvs 1065: else if (!ustrncasecmp (cssRule, TEXT("medium"), 6))
1.1 cvs 1066: {
1067: pval.typed_data.unit = STYLE_UNIT_REL;
1068: pval.typed_data.value = 4;
1069: cssRule = SkipWord (cssRule);
1070: }
1.17 cvs 1071: else if (!ustrncasecmp (cssRule, TEXT("large"), 5))
1.1 cvs 1072: {
1073: pval.typed_data.unit = STYLE_UNIT_REL;
1074: pval.typed_data.value = 5;
1075: cssRule = SkipWord (cssRule);
1076: }
1.17 cvs 1077: else if (!ustrncasecmp (cssRule, TEXT("x-large"), 7))
1.1 cvs 1078: {
1079: pval.typed_data.unit = STYLE_UNIT_REL;
1080: pval.typed_data.value = 6;
1081: cssRule = SkipWord (cssRule);
1082: }
1.17 cvs 1083: else if (!ustrncasecmp (cssRule, TEXT("xx-large"), 8))
1.1 cvs 1084: {
1085: pval.typed_data.unit = STYLE_UNIT_REL;
1086: pval.typed_data.value = 7;
1087: cssRule = SkipWord (cssRule);
1088: }
1089: else
1090: {
1.25 cvs 1091: /* look for a '/' within the current cssRule */
1092: ptr = ustrchr (cssRule, TEXT('/'));
1093: if (ptr != NULL)
1094: {
1095: /* keep the line spacing rule */
1096: ptr[0] = EOS;
1097: ptr = &ptr[1];
1098: }
1.1 cvs 1099: cssRule = ParseCSSUnit (cssRule, &pval);
1100: if (pval.typed_data.unit == STYLE_UNIT_INVALID ||
1101: pval.typed_data.value < 0)
1102: return (cssRule);
1103: if (pval.typed_data.unit == STYLE_UNIT_REL && pval.typed_data.value > 0)
1104: /* CSS relative sizes have to be higher than Thot ones */
1105: pval.typed_data.value += 1;
1106: else
1107: {
1108: real = pval.typed_data.real;
1109: if (pval.typed_data.unit == STYLE_UNIT_EM)
1110: {
1111: if (real)
1112: {
1113: pval.typed_data.value /= 10;
1.11 cvs 1114: pval.typed_data.real = FALSE;
1.1 cvs 1115: real = FALSE;
1116: }
1117: else
1118: pval.typed_data.value *= 100;
1119: pval.typed_data.unit = STYLE_UNIT_PERCENT;
1120: }
1121: }
1.25 cvs 1122:
1.1 cvs 1123: }
1124:
1.25 cvs 1125: /* install the presentation style */
1.1 cvs 1126: TtaSetStylePresentation (PRSize, element, tsch, context, pval);
1.25 cvs 1127:
1128: if (ptr != NULL)
1129: cssRule = ParseCSSLineSpacing (element, tsch, context, ptr, css, isHTML);
1.1 cvs 1130: return (cssRule);
1131: }
1132:
1133: /*----------------------------------------------------------------------
1134: ParseCSSFontFamily : parse a CSS font family string
1135: we expect the input string describing the attribute to be
1136: a common generic font style name
1137: ----------------------------------------------------------------------*/
1138: #ifdef __STDC__
1139: static STRING ParseCSSFontFamily (Element element, PSchema tsch,
1.14 cvs 1140: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1141: #else
1142: static STRING ParseCSSFontFamily (element, tsch, context, cssRule, css, isHTML)
1143: Element element;
1144: PSchema tsch;
1145: PresentationContext context;
1146: STRING cssRule;
1147: CSSInfoPtr css;
1.14 cvs 1148: ThotBool isHTML;
1.1 cvs 1149: #endif
1150: {
1151: PresentationValue font;
1.7 cvs 1152: CHAR_T quoteChar;
1.1 cvs 1153:
1154: font.typed_data.value = 0;
1155: font.typed_data.unit = STYLE_UNIT_REL;
1156: font.typed_data.real = FALSE;
1.13 cvs 1157: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 1158: if (*cssRule == '"' || *cssRule == '\'')
1159: {
1160: quoteChar = *cssRule;
1161: cssRule++;
1162: }
1163: else
1164: quoteChar = '\0';
1165:
1.17 cvs 1166: if (!ustrncasecmp (cssRule, TEXT("times"), 5))
1.1 cvs 1167: font.typed_data.value = STYLE_FONT_TIMES;
1.17 cvs 1168: else if (!ustrncasecmp (cssRule, TEXT("serif"), 5))
1.1 cvs 1169: font.typed_data.value = STYLE_FONT_TIMES;
1.17 cvs 1170: else if (!ustrncasecmp (cssRule, TEXT("helvetica"), 9) ||
1171: !ustrncasecmp (cssRule, TEXT("verdana"), 7))
1.1 cvs 1172: font.typed_data.value = STYLE_FONT_HELVETICA;
1.17 cvs 1173: else if (!ustrncasecmp (cssRule, TEXT("sans-serif"), 10))
1.1 cvs 1174: font.typed_data.value = STYLE_FONT_HELVETICA;
1.17 cvs 1175: else if (!ustrncasecmp (cssRule, TEXT("courier"), 7))
1.1 cvs 1176: font.typed_data.value = STYLE_FONT_COURIER;
1.17 cvs 1177: else if (!ustrncasecmp (cssRule, TEXT("monospace"), 9))
1.1 cvs 1178: font.typed_data.value = STYLE_FONT_COURIER;
1179: else
1180: /* unknown font name. Skip it */
1181: {
1182: if (quoteChar)
1183: cssRule = SkipQuotedString (cssRule, quoteChar);
1184: else
1185: cssRule = SkipWord (cssRule);
1.13 cvs 1186: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 1187: if (*cssRule == ',')
1188: {
1189: cssRule++;
1190: cssRule = ParseCSSFontFamily (element, tsch, context, cssRule, css, isHTML);
1191: return (cssRule);
1192: }
1193: }
1194:
1195: if (font.typed_data.value != 0)
1196: {
1197: cssRule = SkipProperty (cssRule);
1198: /* install the new presentation */
1199: TtaSetStylePresentation (PRFont, element, tsch, context, font);
1200: }
1201: return (cssRule);
1202: }
1203:
1204: /*----------------------------------------------------------------------
1205: ParseCSSFontWeight : parse a CSS font weight string
1206: we expect the input string describing the attribute to be
1.20 cvs 1207: normal, bold, bolder, lighter, 100, 200, 300, ... 900, inherit.
1.1 cvs 1208: ----------------------------------------------------------------------*/
1209: #ifdef __STDC__
1210: static STRING ParseCSSFontWeight (Element element, PSchema tsch,
1.14 cvs 1211: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1212: #else
1213: static STRING ParseCSSFontWeight (element, tsch, context, cssRule, css, isHTML)
1214: Element element;
1215: PSchema tsch;
1216: PresentationContext context;
1217: STRING cssRule;
1218: CSSInfoPtr css;
1.14 cvs 1219: ThotBool isHTML;
1.1 cvs 1220: #endif
1221: {
1.20 cvs 1222: PresentationValue weight;
1.1 cvs 1223:
1224: weight.typed_data.value = 0;
1225: weight.typed_data.unit = STYLE_UNIT_REL;
1226: weight.typed_data.real = FALSE;
1.13 cvs 1227: cssRule = SkipBlanksAndComments (cssRule);
1.17 cvs 1228: if (!ustrncasecmp (cssRule, TEXT("100"), 3) && !isalpha (cssRule[3]))
1.1 cvs 1229: {
1230: weight.typed_data.value = -3;
1231: cssRule = SkipWord (cssRule);
1232: }
1.17 cvs 1233: else if (!ustrncasecmp (cssRule, TEXT("200"), 3) && !isalpha (cssRule[3]))
1.1 cvs 1234: {
1235: weight.typed_data.value = -2;
1236: cssRule = SkipWord (cssRule);
1237: }
1.17 cvs 1238: else if (!ustrncasecmp (cssRule, TEXT("300"), 3) && !isalpha (cssRule[3]))
1.1 cvs 1239: {
1240: weight.typed_data.value = -1;
1241: cssRule = SkipWord (cssRule);
1242: }
1.17 cvs 1243: else if (!ustrncasecmp (cssRule, TEXT("normal"), 6) ||
1244: (!ustrncasecmp (cssRule, TEXT("400"), 3) && !isalpha (cssRule[3])))
1.1 cvs 1245: {
1246: weight.typed_data.value = 0;
1247: cssRule = SkipWord (cssRule);
1248: }
1.17 cvs 1249: else if (!ustrncasecmp (cssRule, TEXT("500"), 3) && !isalpha (cssRule[3]))
1.1 cvs 1250: {
1251: weight.typed_data.value = +1;
1252: cssRule = SkipWord (cssRule);
1253: }
1.17 cvs 1254: else if (!ustrncasecmp (cssRule, TEXT("600"), 3) && !isalpha (cssRule[3]))
1.1 cvs 1255: {
1256: weight.typed_data.value = +2;
1257: cssRule = SkipWord (cssRule);
1258: }
1.17 cvs 1259: else if (!ustrncasecmp (cssRule, TEXT("bold"), 4) ||
1260: (!ustrncasecmp (cssRule, TEXT("700"), 3) && !isalpha (cssRule[3])))
1.1 cvs 1261: {
1262: weight.typed_data.value = +3;
1263: cssRule = SkipWord (cssRule);
1264: }
1.17 cvs 1265: else if (!ustrncasecmp (cssRule, TEXT("800"), 3) && !isalpha (cssRule[3]))
1.1 cvs 1266: {
1267: weight.typed_data.value = +4;
1268: cssRule = SkipWord (cssRule);
1269: }
1.17 cvs 1270: else if (!ustrncasecmp (cssRule, TEXT("900"), 3) && !isalpha (cssRule[3]))
1.1 cvs 1271: {
1272: weight.typed_data.value = +5;
1273: cssRule = SkipWord (cssRule);
1274: }
1.17 cvs 1275: else if (!ustrncasecmp (cssRule, TEXT("inherit"), 7) ||
1276: !ustrncasecmp (cssRule, TEXT("bolder"), 6) ||
1277: !ustrncasecmp (cssRule, TEXT("lighter"), 7))
1.1 cvs 1278: {
1279: /* not implemented */
1280: cssRule = SkipWord (cssRule);
1281: return (cssRule);
1282: }
1283: else
1284: return (cssRule);
1285:
1286: /*
1.20 cvs 1287: * Here we have to reduce since only two font weight values are supported
1.1 cvs 1288: * by the Thot presentation API.
1289: */
1.20 cvs 1290: if (weight.typed_data.value > 0)
1291: weight.typed_data.value = STYLE_WEIGHT_BOLD;
1292: else
1293: weight.typed_data.value = STYLE_WEIGHT_NORMAL;
1.1 cvs 1294:
1295: /* install the new presentation */
1.21 cvs 1296: TtaSetStylePresentation (PRWeight, element, tsch, context, weight);
1.1 cvs 1297: return (cssRule);
1298: }
1299:
1300: /*----------------------------------------------------------------------
1301: ParseCSSFontVariant : parse a CSS font variant string
1302: we expect the input string describing the attribute to be
1303: normal or small-caps
1304: ----------------------------------------------------------------------*/
1305: #ifdef __STDC__
1306: static STRING ParseCSSFontVariant (Element element, PSchema tsch,
1.14 cvs 1307: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1308: #else
1309: static STRING ParseCSSFontVariant (element, tsch, context, cssRule, css, isHTML)
1310: Element element;
1311: PSchema tsch;
1312: PresentationContext context;
1313: STRING cssRule;
1314: CSSInfoPtr css;
1.14 cvs 1315: ThotBool isHTML;
1.1 cvs 1316: #endif
1317: {
1318: PresentationValue style;
1319:
1320: style.typed_data.value = 0;
1321: style.typed_data.unit = STYLE_UNIT_REL;
1322: style.typed_data.real = FALSE;
1.13 cvs 1323: cssRule = SkipBlanksAndComments (cssRule);
1.17 cvs 1324: if (!ustrncasecmp (cssRule, TEXT("small-caps"), 10))
1.1 cvs 1325: {
1326: /* Not supported yet */
1327: cssRule = SkipWord (cssRule);
1328: }
1.17 cvs 1329: else if (!ustrncasecmp (cssRule, TEXT("normal"), 6))
1.1 cvs 1330: {
1331: /* Not supported yet */
1332: cssRule = SkipWord (cssRule);
1333: }
1.17 cvs 1334: else if (!ustrncasecmp (cssRule, TEXT("inherit"), 7))
1.1 cvs 1335: {
1336: /* Not supported yet */
1337: cssRule = SkipWord (cssRule);
1338: }
1339: else
1340: return (cssRule);
1341:
1342: return (cssRule);
1343: }
1344:
1345:
1346: /*----------------------------------------------------------------------
1347: ParseCSSFontStyle : parse a CSS font style string
1348: we expect the input string describing the attribute to be
1349: italic, oblique or normal
1350: ----------------------------------------------------------------------*/
1351: #ifdef __STDC__
1352: static STRING ParseCSSFontStyle (Element element, PSchema tsch,
1.14 cvs 1353: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1354: #else
1355: static STRING ParseCSSFontStyle (element, tsch, context, cssRule, css, isHTML)
1356: Element element;
1357: PSchema tsch;
1358: PresentationContext context;
1359: STRING cssRule;
1360: CSSInfoPtr css;
1.14 cvs 1361: ThotBool isHTML;
1.1 cvs 1362: #endif
1363: {
1364: PresentationValue style;
1365: PresentationValue size;
1366:
1367: style.typed_data.value = 0;
1368: style.typed_data.unit = STYLE_UNIT_REL;
1369: style.typed_data.real = FALSE;
1370: size.typed_data.value = 0;
1371: size.typed_data.unit = STYLE_UNIT_REL;
1372: size.typed_data.real = FALSE;
1.13 cvs 1373: cssRule = SkipBlanksAndComments (cssRule);
1.17 cvs 1374: if (!ustrncasecmp (cssRule, TEXT("italic"), 6))
1.1 cvs 1375: {
1376: style.typed_data.value = STYLE_FONT_ITALICS;
1377: cssRule = SkipWord (cssRule);
1378: }
1.17 cvs 1379: else if (!ustrncasecmp (cssRule, TEXT("oblique"), 7))
1.1 cvs 1380: {
1381: style.typed_data.value = STYLE_FONT_OBLIQUE;
1382: cssRule = SkipWord (cssRule);
1383: }
1.17 cvs 1384: else if (!ustrncasecmp (cssRule, TEXT("normal"), 6))
1.1 cvs 1385: {
1386: style.typed_data.value = STYLE_FONT_ROMAN;
1387: cssRule = SkipWord (cssRule);
1388: }
1389: else
1390: {
1391: /* invalid font style */
1392: return (cssRule);
1393: }
1394:
1395: /*
1396: * install the new presentation.
1397: */
1398: if (style.typed_data.value != 0)
1.20 cvs 1399: TtaSetStylePresentation (PRStyle, element, tsch, context, style);
1.1 cvs 1400: if (size.typed_data.value != 0)
1401: {
1402: PresentationValue previous_size;
1403:
1404: if (!TtaGetStylePresentation (PRSize, element, tsch, context, &previous_size))
1405: {
1406: /* !!!!!!!!!!!!!!!!!!!!!!!! Unite + relatif !!!!!!!!!!!!!!!! */
1407: size.typed_data.value += previous_size.typed_data.value;
1408: TtaSetStylePresentation (PRSize, element, tsch, context, size);
1409: }
1410: else
1411: {
1412: size.typed_data.value = 10;
1413: TtaSetStylePresentation (PRSize, element, tsch, context, size);
1414: }
1415: }
1416: return (cssRule);
1417: }
1418:
1419: /*----------------------------------------------------------------------
1420: ParseCSSFont : parse a CSS font attribute string
1421: we expect the input string describing the attribute to be
1422: !!!!!!
1423: ----------------------------------------------------------------------*/
1424: #ifdef __STDC__
1425: static STRING ParseCSSFont (Element element, PSchema tsch,
1.14 cvs 1426: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1427: #else
1428: static STRING ParseCSSFont (element, tsch, context, cssRule, css, isHTML)
1429: Element element;
1430: PSchema tsch;
1431: PresentationContext context;
1432: STRING cssRule;
1433: CSSInfoPtr css;
1.14 cvs 1434: ThotBool isHTML;
1.1 cvs 1435: #endif
1436: {
1437: STRING ptr;
1438:
1.13 cvs 1439: cssRule = SkipBlanksAndComments (cssRule);
1.17 cvs 1440: if (!ustrncasecmp (cssRule, TEXT("caption"), 7))
1.1 cvs 1441: ;
1.17 cvs 1442: else if (!ustrncasecmp (cssRule, TEXT("icon"), 4))
1.1 cvs 1443: ;
1.17 cvs 1444: else if (!ustrncasecmp (cssRule, TEXT("menu"), 4))
1.1 cvs 1445: ;
1.17 cvs 1446: else if (!ustrncasecmp (cssRule, TEXT("message-box"), 11))
1.1 cvs 1447: ;
1.17 cvs 1448: else if (!ustrncasecmp (cssRule, TEXT("small-caption"), 13))
1.1 cvs 1449: ;
1.17 cvs 1450: else if (!ustrncasecmp (cssRule, TEXT("status-bar"), 10))
1.1 cvs 1451: ;
1452: else
1453: {
1454: ptr = cssRule;
1455: cssRule = ParseCSSFontStyle (element, tsch, context, cssRule, css, isHTML);
1456: if (ptr == cssRule)
1457: cssRule = ParseCSSFontVariant (element, tsch, context, cssRule, css, isHTML);
1458: if (ptr == cssRule)
1459: cssRule = ParseCSSFontWeight (element, tsch, context, cssRule, css, isHTML);
1460: cssRule = ParseCSSFontSize (element, tsch, context, cssRule, css, isHTML);
1461: if (*cssRule == '/')
1462: {
1463: cssRule++;
1.13 cvs 1464: SkipBlanksAndComments (cssRule);
1.1 cvs 1465: cssRule = SkipWord (cssRule);
1466: }
1467: cssRule = ParseCSSFontFamily (element, tsch, context, cssRule, css, isHTML);
1.13 cvs 1468: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 1469: while (*cssRule != ';' && *cssRule != EOS)
1470: {
1471: /* now skip remainding info */
1472: cssRule++;
1473: }
1474: }
1475: return (cssRule);
1476: }
1477:
1478: /*----------------------------------------------------------------------
1479: ParseCSSTextDecoration : parse a CSS text decor string
1480: we expect the input string describing the attribute to be
1481: underline, overline, line-through, box, shadowbox, box3d,
1482: cartouche, blink or none
1483: ----------------------------------------------------------------------*/
1484: #ifdef __STDC__
1485: static STRING ParseCSSTextDecoration (Element element, PSchema tsch,
1.14 cvs 1486: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1487: #else
1488: static STRING ParseCSSTextDecoration (element, tsch, context, cssRule, css, isHTML)
1489: Element element;
1490: PSchema tsch;
1491: PresentationContext context;
1492: STRING cssRule;
1493: CSSInfoPtr css;
1.14 cvs 1494: ThotBool isHTML;
1.1 cvs 1495: #endif
1496: {
1497: PresentationValue decor;
1498:
1499: decor.typed_data.value = 0;
1500: decor.typed_data.unit = STYLE_UNIT_REL;
1501: decor.typed_data.real = FALSE;
1.13 cvs 1502: cssRule = SkipBlanksAndComments (cssRule);
1.17 cvs 1503: if (!ustrncasecmp (cssRule, TEXT("underline"), ustrlen (TEXT("underline"))))
1.1 cvs 1504: {
1505: decor.typed_data.value = Underline;
1506: cssRule = SkipWord (cssRule);
1507: }
1.17 cvs 1508: else if (!ustrncasecmp (cssRule, TEXT("overline"), ustrlen (TEXT("overline"))))
1.1 cvs 1509: {
1510: decor.typed_data.value = Overline;
1511: cssRule = SkipWord (cssRule);
1512: }
1.17 cvs 1513: else if (!ustrncasecmp (cssRule, TEXT("line-through"), ustrlen (TEXT("line-through"))))
1.1 cvs 1514: {
1515: decor.typed_data.value = CrossOut;
1516: cssRule = SkipWord (cssRule);
1517: }
1.17 cvs 1518: else if (!ustrncasecmp (cssRule, TEXT("box"), ustrlen (TEXT("box"))))
1.1 cvs 1519: {
1520: /* the box text-decoration attribute is not yet supported */
1521: cssRule = SkipWord (cssRule);
1522: }
1.17 cvs 1523: else if (!ustrncasecmp (cssRule, TEXT("boxshadow"), ustrlen (TEXT("boxshadow"))))
1.1 cvs 1524: {
1525: /* the boxshadow text-decoration attribute is not yet supported */
1526: cssRule = SkipWord (cssRule);
1527: }
1.17 cvs 1528: else if (!ustrncasecmp (cssRule, TEXT("box3d"), ustrlen (TEXT("box3d"))))
1.1 cvs 1529: {
1530: /* the box3d text-decoration attribute is not yet supported */
1531: cssRule = SkipWord (cssRule);
1532: }
1.17 cvs 1533: else if (!ustrncasecmp (cssRule, TEXT("cartouche"), ustrlen (TEXT("cartouche"))))
1.1 cvs 1534: {
1535: /*the cartouche text-decoration attribute is not yet supported */
1536: cssRule = SkipWord (cssRule);
1537: }
1.17 cvs 1538: else if (!ustrncasecmp (cssRule, TEXT("blink"), ustrlen (TEXT("blink"))))
1.1 cvs 1539: {
1540: /*the blink text-decoration attribute will not be supported */
1541: cssRule = SkipWord (cssRule);
1542: }
1.17 cvs 1543: else if (!ustrncasecmp (cssRule, TEXT("none"), ustrlen (TEXT("none"))))
1.1 cvs 1544: {
1545: decor.typed_data.value = NoUnderline;
1546: cssRule = SkipWord (cssRule);
1547: }
1548: else
1549: {
1550: fprintf (stderr, "invalid text decoration\n");
1551: return (cssRule);
1552: }
1553:
1554: /*
1555: * install the new presentation.
1556: */
1557: if (decor.typed_data.value)
1558: {
1559: TtaSetStylePresentation (PRUnderline, element, tsch, context, decor);
1560: }
1561: return (cssRule);
1562: }
1563:
1564: /*----------------------------------------------------------------------
1565: ParseCSSColor : parse a CSS color attribute string
1566: we expect the input string describing the attribute to be
1567: either a color name, a 3 tuple or an hexadecimal encoding.
1568: The color used will be approximed from the current color
1569: table
1570: ----------------------------------------------------------------------*/
1571: #ifdef __STDC__
1572: static STRING ParseCSSColor (STRING cssRule, PresentationValue * val)
1573: #else
1574: static STRING ParseCSSColor (cssRule, val)
1575: STRING cssRule;
1576: PresentationValue *val;
1577: #endif
1578: {
1.7 cvs 1579: CHAR_T colname[100];
1.1 cvs 1580: unsigned short redval = (unsigned short) -1;
1581: unsigned short greenval = 0; /* composant of each RGB */
1582: unsigned short blueval = 0; /* default to red if unknown ! */
1583: unsigned int i, len;
1584: int r, g, b;
1585: int best = 0; /* best color in list found */
1.14 cvs 1586: ThotBool failed;
1.1 cvs 1587:
1.13 cvs 1588: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 1589: val->typed_data.unit = STYLE_UNIT_INVALID;
1590: val->typed_data.real = FALSE;
1591: val->typed_data.value = 0;
1592: failed = TRUE;
1593: /*
1594: * first parse the attribute string
1595: * NOTE : this can't lookup for color name in
1596: * cause we try first to lokup color name from digits
1597: * [0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f]
1598: */
1599: if ((*cssRule == '#') ||
1600: (isxdigit (cssRule[0]) && isxdigit (cssRule[1]) &&
1601: isxdigit (cssRule[2])))
1602: {
1603: if (*cssRule == '#')
1604: cssRule++;
1605: failed = FALSE;
1606: /* we expect an hexa encoding like F00 or FF0000 */
1607: if ((!isxdigit (cssRule[0])) || (!isxdigit (cssRule[1])) ||
1608: (!isxdigit (cssRule[2])))
1609: {
1610: fprintf (stderr, "Invalid color encoding %s\n", cssRule - 1);
1611: failed = TRUE;
1612: }
1613: else if (!isxdigit (cssRule[3]))
1614: {
1615: /* encoded as on 3 digits #F0F */
1616: redval = hexa_val (cssRule[0]) * 16 + hexa_val (cssRule[0]);
1617: greenval = hexa_val (cssRule[1]) * 16 + hexa_val (cssRule[1]);
1618: blueval = hexa_val (cssRule[2]) * 16 + hexa_val (cssRule[2]);
1.13 cvs 1619: cssRule = &cssRule[3];
1.1 cvs 1620: }
1621: else if ((!isxdigit (cssRule[4])) || (!isxdigit (cssRule[5])))
1622: fprintf (stderr, "Invalid color encoding %s\n", cssRule - 1);
1623: else
1624: {
1625: /* encoded as on 3 digits #FF00FF */
1626: redval = hexa_val (cssRule[0]) * 16 + hexa_val (cssRule[1]);
1627: greenval = hexa_val (cssRule[2]) * 16 + hexa_val (cssRule[3]);
1628: blueval = hexa_val (cssRule[4]) * 16 + hexa_val (cssRule[5]);
1.13 cvs 1629: cssRule = &cssRule[6];
1.1 cvs 1630: }
1631: }
1.17 cvs 1632: else if (!ustrncasecmp (cssRule, TEXT("rgb"), 3))
1.1 cvs 1633: {
1.13 cvs 1634: cssRule = &cssRule[3];
1635: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 1636: if (*cssRule == '(')
1637: {
1638: cssRule++;
1.13 cvs 1639: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 1640: failed = FALSE;
1641: if (*cssRule == '%')
1642: {
1643: /* encoded as rgb(%red,%green,&blue) */
1.17 cvs 1644: usscanf (cssRule, TEXT("%%%d"), &r);
1645: while (*cssRule != EOS && *cssRule != TEXT(','))
1.1 cvs 1646: cssRule++;
1647: cssRule++;
1.17 cvs 1648: usscanf (cssRule, TEXT("%%%d"), &g);
1649: while (*cssRule != EOS && *cssRule != TEXT(','))
1.1 cvs 1650: cssRule++;
1651: cssRule++;
1.17 cvs 1652: usscanf (cssRule, TEXT("%%%d"), &b);
1.1 cvs 1653: redval = (unsigned short)(r * 255 / 100);
1654: greenval = (unsigned short)(g * 255 / 100);
1655: blueval = (unsigned short)(b * 255 / 100);
1656: }
1657: else
1658: {
1659: /* encoded as rgb(red,green,blue) */
1.17 cvs 1660: usscanf (cssRule, TEXT("%d"), &r);
1661: while (*cssRule != EOS && *cssRule != TEXT(','))
1.1 cvs 1662: cssRule++;
1663: cssRule++;
1.17 cvs 1664: usscanf (cssRule, TEXT("%d"), &g);
1665: while (*cssRule != EOS && *cssRule != TEXT(','))
1.1 cvs 1666: cssRule++;
1667: cssRule++;
1.17 cvs 1668: usscanf (cssRule, TEXT("%d"), &b);
1.1 cvs 1669: redval = (unsigned short)r;
1670: greenval = (unsigned short)g;
1671: blueval = (unsigned short)b;
1672: }
1673: /* search the rgb end */
1674: while (*cssRule != EOS && *cssRule != ')')
1675: cssRule++;
1676: cssRule++;
1677: }
1678: else
1679: cssRule = SkipProperty (cssRule);
1680: }
1681: else if (isalpha (*cssRule))
1682: {
1683: /* we expect a color name like "red", store it in colname */
1684: len = sizeof (colname) - 1;
1685: for (i = 0; i < len && cssRule[i] != EOS; i++)
1686: {
1687: if (!isalnum (cssRule[i]) && cssRule[i] != EOS)
1688: {
1689: cssRule += i;
1690: break;
1691: }
1692: colname[i] = cssRule[i];
1693: }
1694: colname[i] = EOS;
1695:
1696: /* Lookup the color name in our own color name database */
1697: for (i = 0; i < NBCOLORNAME; i++)
1698: if (!ustrcasecmp (ColornameTable[i].name, colname))
1699: {
1700: redval = ColornameTable[i].red;
1701: greenval = ColornameTable[i].green;
1702: blueval = ColornameTable[i].blue;
1703: failed = FALSE;
1704: i = NBCOLORNAME;
1705: }
1.23 cvs 1706: /******** Lookup the color name in Thot color name database
1.1 cvs 1707: if (failed)
1708: {
1709: TtaGiveRGB (colname, &redval, &greenval, &blueval);
1710: failed = FALSE;
1711: }
1.23 cvs 1712: **********/
1.1 cvs 1713: }
1714:
1715: if (failed)
1.25 cvs 1716: {
1717: val->typed_data.value = 0;
1718: val->typed_data.unit = STYLE_UNIT_INVALID;
1719: }
1.1 cvs 1720: else
1721: {
1722: best = TtaGetThotColor (redval, greenval, blueval);
1723: val->typed_data.value = best;
1.26 ! cvs 1724: val->typed_data.unit = STYLE_UNIT_REL;
1.1 cvs 1725: }
1726: val->typed_data.real = FALSE;
1727: return (cssRule);
1728: }
1729:
1730: /*----------------------------------------------------------------------
1731: ParseCSSHeight : parse a CSS height attribute
1732: ----------------------------------------------------------------------*/
1733: #ifdef __STDC__
1734: static STRING ParseCSSHeight (Element element, PSchema tsch,
1.14 cvs 1735: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1736: #else
1737: static STRING ParseCSSHeight (element, tsch, context, cssRule, css, isHTML)
1738: Element element;
1739: PSchema tsch;
1740: PresentationContext context;
1741: STRING cssRule;
1742: CSSInfoPtr css;
1.14 cvs 1743: ThotBool isHTML;
1.1 cvs 1744: #endif
1745: {
1.13 cvs 1746: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 1747:
1748: /* first parse the attribute string */
1.17 cvs 1749: if (!ustrcasecmp (cssRule, TEXT("auto")))
1.1 cvs 1750: {
1751: cssRule = SkipWord (cssRule);
1752: /* ParseCSSHeight : auto */
1753: return (cssRule);
1754: }
1755: else
1756: cssRule = SkipProperty (cssRule);
1757: return (cssRule);
1758: }
1759:
1760: /*----------------------------------------------------------------------
1761: ParseCSSWidth : parse a CSS width attribute
1762: ----------------------------------------------------------------------*/
1763: #ifdef __STDC__
1764: static STRING ParseCSSWidth (Element element, PSchema tsch,
1.14 cvs 1765: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1766: #else
1767: static STRING ParseCSSWidth (element, tsch, context, cssRule, css, isHTML)
1768: Element element;
1769: PSchema tsch;
1770: PresentationContext context;
1771: STRING cssRule;
1772: CSSInfoPtr css;
1.14 cvs 1773: ThotBool isHTML;
1.1 cvs 1774: #endif
1775: {
1.13 cvs 1776: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 1777:
1778: /* first parse the attribute string */
1.17 cvs 1779: if (!ustrcasecmp (cssRule, TEXT("auto")))
1.1 cvs 1780: {
1781: cssRule = SkipWord (cssRule);
1782: return (cssRule);
1783: }
1784: else
1785: cssRule = SkipProperty (cssRule);
1786: return (cssRule);
1787: }
1788:
1789: /*----------------------------------------------------------------------
1790: ParseCSSMarginTop : parse a CSS margin-top attribute
1791: ----------------------------------------------------------------------*/
1792: #ifdef __STDC__
1793: static STRING ParseCSSMarginTop (Element element, PSchema tsch,
1.14 cvs 1794: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1795: #else
1796: static STRING ParseCSSMarginTop (element, tsch, context, cssRule, css, isHTML)
1797: Element element;
1798: PSchema tsch;
1799: PresentationContext context;
1800: STRING cssRule;
1801: CSSInfoPtr css;
1.14 cvs 1802: ThotBool isHTML;
1.1 cvs 1803: #endif
1804: {
1805: PresentationValue margin;
1806:
1.13 cvs 1807: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 1808: /* first parse the attribute string */
1809: cssRule = ParseCSSUnit (cssRule, &margin);
1.3 cvs 1810: if (margin.typed_data.unit != STYLE_UNIT_INVALID && margin.typed_data.value != 0)
1.1 cvs 1811: {
1812: TtaSetStylePresentation (PRTMargin, element, tsch, context, margin);
1813: if (margin.typed_data.value < 0)
1814: TtaSetStylePresentation (PRVertOverflow, element, tsch, context, margin);
1815: }
1816: return (cssRule);
1817: }
1818:
1819: /*----------------------------------------------------------------------
1820: ParseCSSMarginBottom : parse a CSS margin-bottom
1821: attribute
1822: ----------------------------------------------------------------------*/
1823: #ifdef __STDC__
1824: static STRING ParseCSSMarginBottom (Element element, PSchema tsch,
1.14 cvs 1825: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1826: #else
1827: static STRING ParseCSSMarginBottom (element, tsch, context, cssRule, css, isHTML)
1828: Element element;
1829: PSchema tsch;
1830: PresentationContext context;
1831: STRING cssRule;
1832: CSSInfoPtr css;
1.14 cvs 1833: ThotBool isHTML;
1.1 cvs 1834: #endif
1835: {
1836: PresentationValue margin;
1837:
1.13 cvs 1838: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 1839: /* first parse the attribute string */
1840: cssRule = ParseCSSUnit (cssRule, &margin);
1841: margin.typed_data.value = - margin.typed_data.value;
1842: /*if (margin.typed_data.unit != STYLE_UNIT_INVALID)
1843: TtaSetStylePresentation (PRBMargin, element, tsch, context, margin)*/;
1844: return (cssRule);
1845: }
1846:
1847: /*----------------------------------------------------------------------
1848: ParseCSSMarginLeft : parse a CSS margin-left
1849: attribute string.
1850: ----------------------------------------------------------------------*/
1851: #ifdef __STDC__
1852: static STRING ParseCSSMarginLeft (Element element, PSchema tsch,
1.14 cvs 1853: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1854: #else
1855: static STRING ParseCSSMarginLeft (element, tsch, context, cssRule, css, isHTML)
1856: Element element;
1857: PSchema tsch;
1858: PresentationContext context;
1859: STRING cssRule;
1860: CSSInfoPtr css;
1.14 cvs 1861: ThotBool isHTML;
1.1 cvs 1862: #endif
1863: {
1864: PresentationValue margin;
1865:
1.13 cvs 1866: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 1867: /* first parse the attribute string */
1868: cssRule = ParseCSSUnit (cssRule, &margin);
1.3 cvs 1869: if (margin.typed_data.unit != STYLE_UNIT_INVALID && margin.typed_data.value != 0)
1.1 cvs 1870: {
1871: TtaSetStylePresentation (PRLMargin, element, tsch, context, margin);
1872: if (margin.typed_data.value < 0)
1873: TtaSetStylePresentation (PRHorizOverflow, element, tsch, context, margin);
1874: TtaSetStylePresentation (PRRMargin, element, tsch, context, margin);
1875: }
1876: return (cssRule);
1877: }
1878:
1879: /*----------------------------------------------------------------------
1880: ParseCSSMarginRight : parse a CSS margin-right
1881: attribute string.
1882: ----------------------------------------------------------------------*/
1883: #ifdef __STDC__
1884: static STRING ParseCSSMarginRight (Element element, PSchema tsch,
1.14 cvs 1885: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1886: #else
1887: static STRING ParseCSSMarginRight (element, tsch, context, cssRule, css, isHTML)
1888: Element element;
1889: PSchema tsch;
1890: PresentationContext context;
1891: STRING cssRule;
1892: CSSInfoPtr css;
1.14 cvs 1893: ThotBool isHTML;
1.1 cvs 1894: #endif
1895: {
1896: PresentationValue margin;
1897:
1.13 cvs 1898: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 1899: /* first parse the attribute string */
1900: cssRule = ParseCSSUnit (cssRule, &margin);
1901: /*if (margin.typed_data.unit != STYLE_UNIT_INVALID)
1902: TtaSetStylePresentation (PRRMargin, element, tsch, context, margin)*/;
1903: return (cssRule);
1904: }
1905:
1906: /*----------------------------------------------------------------------
1907: ParseCSSMargin : parse a CSS margin attribute string.
1908: ----------------------------------------------------------------------*/
1909: #ifdef __STDC__
1910: static STRING ParseCSSMargin (Element element, PSchema tsch,
1.14 cvs 1911: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1912: #else
1913: static STRING ParseCSSMargin (element, tsch, context, cssRule, css, isHTML)
1914: Element element;
1915: PSchema tsch;
1916: PresentationContext context;
1917: STRING cssRule;
1918: CSSInfoPtr css;
1.14 cvs 1919: ThotBool isHTML;
1.1 cvs 1920: #endif
1921: {
1922: STRING ptrT, ptrR, ptrB, ptrL;
1923:
1.13 cvs 1924: ptrT = SkipBlanksAndComments (cssRule);
1.1 cvs 1925: /* First parse Margin-Top */
1926: ptrR = ParseCSSMarginTop (element, tsch, context, ptrT, css, isHTML);
1.13 cvs 1927: ptrR = SkipBlanksAndComments (ptrR);
1.1 cvs 1928: if (*ptrR == ';' || *ptrR == EOS || *ptrR == ',')
1929: {
1930: cssRule = ptrR;
1931: /* apply the Margin-Top to all */
1932: ptrR = ParseCSSMarginRight (element, tsch, context, ptrT, css, isHTML);
1933: ptrR = ParseCSSMarginBottom (element, tsch, context, ptrT, css, isHTML);
1934: ptrR = ParseCSSMarginLeft (element, tsch, context, ptrT, css, isHTML);
1935: }
1936: else
1937: {
1938: /* parse Margin-Right */
1939: ptrB = ParseCSSMarginRight (element, tsch, context, ptrR, css, isHTML);
1.13 cvs 1940: ptrB = SkipBlanksAndComments (ptrB);
1.1 cvs 1941: if (*ptrB == ';' || *ptrB == EOS || *ptrB == ',')
1942: {
1943: cssRule = ptrB;
1944: /* apply the Margin-Top to Margin-Bottom */
1945: ptrB = ParseCSSMarginBottom (element, tsch, context, ptrT, css, isHTML);
1946: /* apply the Margin-Right to Margin-Left */
1947: ptrB = ParseCSSMarginLeft (element, tsch, context, ptrR, css, isHTML);
1948: }
1949: else
1950: {
1951: /* parse Margin-Bottom */
1952: ptrL = ParseCSSMarginBottom (element, tsch, context, ptrB, css, isHTML);
1.13 cvs 1953: ptrL = SkipBlanksAndComments (ptrL);
1.1 cvs 1954: if (*ptrL == ';' || *ptrL == EOS || *ptrL == ',')
1955: {
1956: cssRule = ptrL;
1957: /* apply the Margin-Right to Margin-Left */
1958: ptrL = ParseCSSMarginLeft (element, tsch, context, ptrR, css, isHTML);
1959: }
1960: else
1961: /* parse Margin-Left */
1962: cssRule = ParseCSSMarginLeft (element, tsch, context, ptrL, css, isHTML);
1.13 cvs 1963: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 1964: }
1965: }
1966: return (cssRule);
1967: }
1968:
1969: /*----------------------------------------------------------------------
1970: ParseCSSPaddingTop : parse a CSS PaddingTop
1971: attribute string.
1972: ----------------------------------------------------------------------*/
1973: #ifdef __STDC__
1974: static STRING ParseCSSPaddingTop (Element element, PSchema tsch,
1.14 cvs 1975: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1976: #else
1977: static STRING ParseCSSPaddingTop (element, tsch, context, cssRule, css, isHTML)
1978: Element element;
1979: PSchema tsch;
1980: PresentationContext context;
1981: STRING cssRule;
1982: CSSInfoPtr css;
1.14 cvs 1983: ThotBool isHTML;
1.1 cvs 1984: #endif
1985: {
1986: cssRule = SkipProperty (cssRule);
1987: return (cssRule);
1988: }
1989:
1990: /*----------------------------------------------------------------------
1991: ParseCSSPaddingRight : parse a CSS PaddingRight
1992: attribute string.
1993: ----------------------------------------------------------------------*/
1994: #ifdef __STDC__
1995: static STRING ParseCSSPaddingRight (Element element, PSchema tsch,
1.14 cvs 1996: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 1997: #else
1998: static STRING ParseCSSPaddingRight (element, tsch, context, cssRule, css, isHTML)
1999: Element element;
2000: PSchema tsch;
2001: PresentationContext context;
2002: STRING cssRule;
2003: CSSInfoPtr css;
1.14 cvs 2004: ThotBool isHTML;
1.1 cvs 2005: #endif
2006: {
2007: cssRule = SkipProperty (cssRule);
2008: return (cssRule);
2009: }
2010:
2011:
2012: /*----------------------------------------------------------------------
2013: ParseCSSPaddingBottom : parse a CSS PaddingBottom
2014: attribute string.
2015: ----------------------------------------------------------------------*/
2016: #ifdef __STDC__
2017: static STRING ParseCSSPaddingBottom (Element element, PSchema tsch,
1.14 cvs 2018: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2019: #else
2020: static STRING ParseCSSPaddingBottom (element, tsch, context, cssRule, css, isHTML)
2021: Element element;
2022: PSchema tsch;
2023: PresentationContext context;
2024: STRING cssRule;
2025: CSSInfoPtr css;
1.14 cvs 2026: ThotBool isHTML;
1.1 cvs 2027: #endif
2028: {
2029: cssRule = SkipProperty (cssRule);
2030: return (cssRule);
2031: }
2032:
2033: /*----------------------------------------------------------------------
2034: ParseCSSPaddingLeft : parse a CSS PaddingLeft
2035: attribute string.
2036: ----------------------------------------------------------------------*/
2037: #ifdef __STDC__
2038: static STRING ParseCSSPaddingLeft (Element element, PSchema tsch,
1.14 cvs 2039: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2040: #else
2041: static STRING ParseCSSPaddingLeft (element, tsch, context, cssRule, css, isHTML)
2042: Element element;
2043: PSchema tsch;
2044: PresentationContext context;
2045: STRING cssRule;
2046: CSSInfoPtr css;
1.14 cvs 2047: ThotBool isHTML;
1.1 cvs 2048: #endif
2049: {
2050: cssRule = SkipProperty (cssRule);
2051: return (cssRule);
2052: }
2053:
2054: /*----------------------------------------------------------------------
2055: ParseCSSPadding : parse a CSS padding attribute string.
2056: ----------------------------------------------------------------------*/
2057: #ifdef __STDC__
2058: static STRING ParseCSSPadding (Element element, PSchema tsch,
1.14 cvs 2059: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2060: #else
2061: static STRING ParseCSSPadding (element, tsch, context, cssRule, css, isHTML)
2062: Element element;
2063: PSchema tsch;
2064: PresentationContext context;
2065: STRING cssRule;
2066: CSSInfoPtr css;
1.14 cvs 2067: ThotBool isHTML;
1.1 cvs 2068: #endif
2069: {
2070: cssRule = SkipProperty (cssRule);
2071: return (cssRule);
2072: }
2073:
2074: /*----------------------------------------------------------------------
2075: ParseCSSForeground : parse a CSS foreground attribute
2076: ----------------------------------------------------------------------*/
2077: #ifdef __STDC__
2078: static STRING ParseCSSForeground (Element element, PSchema tsch,
1.14 cvs 2079: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2080: #else
2081: static STRING ParseCSSForeground (element, tsch, context, cssRule, css, isHTML)
2082: Element element;
2083: PSchema tsch;
2084: PresentationContext context;
2085: STRING cssRule;
2086: CSSInfoPtr css;
1.14 cvs 2087: ThotBool isHTML;
1.1 cvs 2088: #endif
2089: {
2090: PresentationValue best;
2091:
2092: cssRule = ParseCSSColor (cssRule, &best);
1.25 cvs 2093: if (best.typed_data.unit != STYLE_UNIT_INVALID)
2094: /* install the new presentation */
2095: TtaSetStylePresentation (PRForeground, element, tsch, context, best);
1.1 cvs 2096: return (cssRule);
2097: }
2098:
2099: /*----------------------------------------------------------------------
2100: ParseCSSBackgroundColor : parse a CSS background color attribute
2101: ----------------------------------------------------------------------*/
2102: #ifdef __STDC__
2103: static STRING ParseCSSBackgroundColor (Element element, PSchema tsch,
1.14 cvs 2104: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2105: #else
2106: static STRING ParseCSSBackgroundColor (element, tsch, context, cssRule, css, isHTML)
2107: Element element;
2108: PSchema tsch;
2109: PresentationContext context;
2110: STRING cssRule;
2111: CSSInfoPtr css;
1.14 cvs 2112: ThotBool isHTML;
1.1 cvs 2113: #endif
2114: {
2115: PresentationValue best;
2116: unsigned int savedtype = 0;
1.14 cvs 2117: ThotBool moved;
1.1 cvs 2118:
2119: /* move the BODY rule to the HTML element */
2120: moved = (context->type == HTML_EL_BODY && isHTML);
2121: if (moved)
2122: {
2123: if (element)
2124: element = TtaGetMainRoot (context->doc);
2125: else
2126: {
2127: savedtype = context->type;
2128: context->type = HTML_EL_HTML;
2129: }
2130: }
2131:
2132: best.typed_data.unit = STYLE_UNIT_INVALID;
2133: best.typed_data.real = FALSE;
1.17 cvs 2134: if (!ustrncasecmp (cssRule, TEXT("transparent"), ustrlen (TEXT("transparent"))))
1.1 cvs 2135: {
2136: best.typed_data.value = STYLE_PATTERN_NONE;
2137: best.typed_data.unit = STYLE_UNIT_REL;
2138: TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
2139: }
2140: else
2141: {
2142: cssRule = ParseCSSColor (cssRule, &best);
2143: if (best.typed_data.unit != STYLE_UNIT_INVALID)
2144: {
2145: /* install the new presentation. */
2146: TtaSetStylePresentation (PRBackground, element, tsch, context, best);
2147: /* thot specificity : need to set fill pattern for background color */
2148: best.typed_data.value = STYLE_PATTERN_BACKGROUND;
2149: best.typed_data.unit = STYLE_UNIT_REL;
2150: TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
2151: best.typed_data.value = 1;
2152: best.typed_data.unit = STYLE_UNIT_REL;
2153: TtaSetStylePresentation (PRShowBox, element, tsch, context, best);
2154: }
2155: }
2156: cssRule = SkipWord (cssRule);
2157:
2158: /* restore the refered element */
2159: if (moved && !element)
2160: context->type = savedtype;
2161: return (cssRule);
2162: }
2163:
2164: /*----------------------------------------------------------------------
2165: ParseCSSBackgroundImageCallback : Callback called asynchronously by
2166: FetchImage when a background image has been fetched.
2167: ----------------------------------------------------------------------*/
2168: #ifdef __STDC__
2169: void ParseCSSBackgroundImageCallback (Document doc, Element element, STRING file,
2170: void *extra)
2171: #else
2172: void ParseCSSBackgroundImageCallback (doc, element, file, extra)
2173: Document doc;
2174: Element element;
2175: STRING file;
2176: void *extra;
2177: #endif
2178: {
2179: BackgroundImageCallbackPtr callblock = (BackgroundImageCallbackPtr) extra;
2180: Element el;
2181: PSchema tsch;
2182: PresentationContext context;
2183: PresentationValue image;
2184: PresentationValue repeat;
2185: PresentationValue value;
2186:
2187: if (callblock == NULL)
2188: return;
2189: el = callblock->el;
2190: tsch = callblock->tsch;
2191: context = &callblock->context.specific;
2192:
2193: /* Ok the image was fetched, finish the background-image handling */
2194: image.pointer = file;
2195: TtaSetStylePresentation (PRBackgroundPicture, el, tsch, context, image);
2196:
2197: /* If there is no default repeat mode, enforce a V-Repeat */
2198: if (TtaGetStylePresentation (PRPictureMode, el, tsch, context, &repeat) < 0)
2199: {
2200: repeat.typed_data.value = STYLE_REPEAT;
2201: repeat.typed_data.unit = STYLE_UNIT_REL;
2202: repeat.typed_data.real = FALSE;
2203: TtaSetStylePresentation (PRPictureMode, el, tsch, context, repeat);
2204: }
2205:
2206: /* If there is no default repeat mode, enforce a V-Repeat */
2207: value.typed_data.value = 1;
2208: value.typed_data.unit = STYLE_UNIT_REL;
2209: value.typed_data.real = FALSE;
2210: TtaSetStylePresentation (PRShowBox, el, tsch, context, value);
2211:
2212: /* Update the rendering */
2213: TtaUpdateStylePresentation (el, tsch, context);
2214:
2215: TtaFreeMemory (callblock);
2216: }
2217:
2218:
2219: /*----------------------------------------------------------------------
2220: GetCSSBackgroundURL searches a CSS BackgroundImage url within
2221: the styleString.
2222: Returns NULL or a new allocated url string.
2223: ----------------------------------------------------------------------*/
2224: #ifdef __STDC__
2225: STRING GetCSSBackgroundURL (STRING styleString)
2226: #else
2227: STRING GetCSSBackgroundURL (styleString)
2228: STRING styleString;
2229: #endif
2230: {
2231: STRING b, e, ptr;
2232: int len;
2233:
2234: ptr = NULL;
1.17 cvs 2235: b = ustrstr (styleString, TEXT("url"));
1.1 cvs 2236: if (b != NULL)
2237: {
2238: b += 3;
1.13 cvs 2239: b = SkipBlanksAndComments (b);
1.1 cvs 2240: if (*b == '(')
2241: {
2242: b++;
1.13 cvs 2243: b = SkipBlanksAndComments (b);
1.1 cvs 2244: /*** Caution: Strings can either be written with double quotes or
2245: with single quotes. Only double quotes are handled here.
2246: Escaped quotes are not handled. See function SkipQuotedString */
2247: if (*b == '"')
2248: {
2249: b++;
2250: /* search the url end */
2251: e = b;
2252: while (*e != EOS && *e != '"')
2253: e++;
2254: }
2255: else
2256: {
2257: /* search the url end */
2258: e = b;
2259: while (*e != EOS && *e != ')')
2260: e++;
2261: }
2262: if (*e != EOS)
2263: {
2264: len = (int)(e - b);
2265: ptr = (STRING) TtaGetMemory (len+1);
2266: ustrncpy (ptr, b, len);
2267: ptr[len] = EOS;
2268: }
2269: }
2270: }
2271: return (ptr);
2272: }
2273:
2274:
2275: /*----------------------------------------------------------------------
2276: ParseCSSBackgroundImage : parse a CSS BackgroundImage
2277: attribute string.
2278: ----------------------------------------------------------------------*/
2279: #ifdef __STDC__
2280: static STRING ParseCSSBackgroundImage (Element element, PSchema tsch,
1.14 cvs 2281: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2282: #else
2283: static STRING ParseCSSBackgroundImage (element, tsch, context, cssRule, css, isHTML)
2284: Element element;
2285: PSchema tsch;
2286: PresentationContext context;
2287: STRING cssRule;
2288: CSSInfoPtr css;
1.14 cvs 2289: ThotBool isHTML;
1.1 cvs 2290: #endif
2291: {
2292: Element el;
2293: GenericContext gblock;
2294: PresentationContextBlock *sblock;
2295: BackgroundImageCallbackPtr callblock;
2296: PresentationValue image, value;
2297: STRING url;
2298: STRING bg_image;
1.25 cvs 2299: CHAR_T saved;
1.1 cvs 2300: STRING base;
1.25 cvs 2301: CHAR_T tempname[MAX_LENGTH];
2302: CHAR_T imgname[MAX_LENGTH];
1.1 cvs 2303: unsigned int savedtype = 0;
1.14 cvs 2304: ThotBool moved;
1.1 cvs 2305:
2306: /* default element for FetchImage */
2307: el = TtaGetMainRoot (context->doc);
2308: /* move the BODY rule to the HTML element */
2309: moved = (context->type == HTML_EL_BODY && isHTML);
2310: if (moved)
2311: {
2312: if (element)
2313: element = el;
2314: else
2315: {
2316: savedtype = context->type;
2317: context->type = HTML_EL_HTML;
2318: }
2319: }
2320: else if (element)
2321: el = element;
2322:
2323: url = NULL;
1.13 cvs 2324: cssRule = SkipBlanksAndComments (cssRule);
1.17 cvs 2325: if (!ustrncasecmp (cssRule, TEXT("url"), 3))
1.1 cvs 2326: {
2327: cssRule += 3;
1.13 cvs 2328: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 2329: if (*cssRule == '(')
2330: {
2331: cssRule++;
1.13 cvs 2332: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 2333: /*** Caution: Strings can either be written with double quotes or
2334: with single quotes. Only double quotes are handled here.
2335: Escaped quotes are not handled. See function SkipQuotedString */
2336: if (*cssRule == '"')
2337: {
2338: cssRule++;
2339: base = cssRule;
2340: while (*cssRule != EOS && *cssRule != '"')
2341: cssRule++;
2342: }
2343: else
2344: {
2345: base = cssRule;
2346: while (*cssRule != EOS && *cssRule != ')')
2347: cssRule++;
2348: }
2349: saved = *cssRule;
2350: *cssRule = EOS;
2351: url = TtaStrdup (base);
2352: *cssRule = saved;
2353: if (saved == '"')
2354: /* we need to skip two characters */
2355: cssRule++;
2356: }
2357: cssRule++;
2358:
2359: if (context->destroy)
2360: {
2361: /* remove the background image PRule */
2362: image.pointer = NULL;
2363: TtaSetStylePresentation (PRBackgroundPicture, element, tsch, context, image);
2364: if (TtaGetStylePresentation (PRFillPattern, element, tsch, context, &value) < 0)
2365: {
2366: /* there is no FillPattern rule -> remove ShowBox rule */
2367: value.typed_data.value = 1;
2368: value.typed_data.unit = STYLE_UNIT_REL;
2369: value.typed_data.real = FALSE;
2370: TtaSetStylePresentation (PRShowBox, element, tsch, context, value);
2371: }
2372: }
2373: else if (url)
2374: {
1.17 cvs 2375: bg_image = TtaGetEnvString (TEXT("ENABLE_BG_IMAGES"));
2376: if (bg_image == NULL || !ustrcasecmp (bg_image, TEXT("yes")))
1.1 cvs 2377: {
2378: callblock = (BackgroundImageCallbackPtr) TtaGetMemory(sizeof(BackgroundImageCallbackBlock));
2379: if (callblock != NULL)
2380: {
2381: callblock->el = element;
2382: callblock->tsch = tsch;
2383: if (element == NULL)
1.18 cvs 2384: {
2385: gblock = (GenericContext) context;
2386: memcpy (&callblock->context.generic, gblock,
2387: sizeof (GenericContextBlock));
2388: }
2389: else
2390: {
2391: sblock = context;
2392: memcpy (&callblock->context.specific, sblock,
2393: sizeof(PresentationContextBlock));
2394: }
2395:
2396: /* check if the image url is related to an external CSS */
2397: if (css != NULL && css->category == CSS_EXTERNAL_STYLE)
2398: {
2399: NormalizeURL (url, 0, tempname, imgname, css->url);
2400: /* fetch and display background image of element */
2401: FetchImage (context->doc, el, tempname, 0,
2402: ParseCSSBackgroundImageCallback, callblock);
2403: }
2404: else
2405: FetchImage (context->doc, el, url, 0,
2406: ParseCSSBackgroundImageCallback, callblock);
2407: }
2408: }
2409:
2410: if (url)
2411: TtaFreeMemory (url);
2412: }
2413: }
2414:
2415: /* restore the refered element */
2416: if (moved && !element)
2417: context->type = savedtype;
2418: return (cssRule);
2419: }
2420:
2421: /*----------------------------------------------------------------------
2422: ParseCSSBackgroundRepeat : parse a CSS BackgroundRepeat
2423: attribute string.
2424: ----------------------------------------------------------------------*/
2425: #ifdef __STDC__
2426: static STRING ParseCSSBackgroundRepeat (Element element, PSchema tsch,
2427: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
2428: #else
2429: static STRING ParseCSSBackgroundRepeat (element, tsch, context, cssRule, css, isHTML)
2430: Element element;
2431: PSchema tsch;
2432: PresentationContext context;
2433: STRING cssRule;
2434: CSSInfoPtr css;
2435: ThotBool isHTML;
2436: #endif
2437: {
2438: PresentationValue repeat;
2439: unsigned int savedtype = 0;
2440: ThotBool moved;
2441:
2442: /* move the BODY rule to the HTML element */
2443: moved = (context->type == HTML_EL_BODY && isHTML);
2444: if (moved)
2445: {
2446: if (element)
2447: element = TtaGetMainRoot (context->doc);
2448: else
2449: {
2450: savedtype = context->type;
2451: context->type = HTML_EL_HTML;
2452: }
2453: }
2454:
2455: repeat.typed_data.value = STYLE_REALSIZE;
2456: repeat.typed_data.unit = STYLE_UNIT_REL;
2457: repeat.typed_data.real = FALSE;
2458: cssRule = SkipBlanksAndComments (cssRule);
2459: if (!ustrncasecmp (cssRule, TEXT("no-repeat"), 9))
2460: repeat.typed_data.value = STYLE_REALSIZE;
2461: else if (!ustrncasecmp (cssRule, TEXT("repeat-y"), 8))
2462: repeat.typed_data.value = STYLE_VREPEAT;
2463: else if (!ustrncasecmp (cssRule, TEXT("repeat-x"), 8))
2464: repeat.typed_data.value = STYLE_HREPEAT;
2465: else if (!ustrncasecmp (cssRule, TEXT("repeat"), 6))
2466: repeat.typed_data.value = STYLE_REPEAT;
2467: else
2468: return (cssRule);
2469:
2470: /* install the new presentation */
2471: TtaSetStylePresentation (PRPictureMode, element, tsch, context, repeat);
2472: cssRule = SkipWord (cssRule);
2473:
2474: /* restore the refered element */
2475: if (moved && !element)
2476: context->type = savedtype;
2477: return (cssRule);
2478: }
2479:
2480: /*----------------------------------------------------------------------
2481: ParseCSSBackgroundAttachment : parse a CSS BackgroundAttachment
2482: attribute string.
2483: ----------------------------------------------------------------------*/
2484: #ifdef __STDC__
2485: static STRING ParseCSSBackgroundAttachment (Element element, PSchema tsch,
2486: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
2487: #else
2488: static STRING ParseCSSBackgroundAttachment (element, tsch, context, cssRule, css, isHTML)
2489: Element element;
2490: PSchema tsch;
2491: PresentationContext context;
2492: STRING cssRule;
2493: CSSInfoPtr css;
2494: ThotBool isHTML;
2495: #endif
2496: {
2497: unsigned int savedtype = 0;
2498: ThotBool moved;
1.1 cvs 2499:
1.18 cvs 2500: /* move the BODY rule to the HTML element */
2501: moved = (context->type == HTML_EL_BODY && isHTML);
2502: if (moved)
2503: {
2504: if (element)
2505: element = TtaGetMainRoot (context->doc);
2506: else
2507: {
2508: savedtype = context->type;
2509: context->type = HTML_EL_HTML;
1.1 cvs 2510: }
2511: }
2512:
1.18 cvs 2513: cssRule = SkipBlanksAndComments (cssRule);
2514: if (!ustrncasecmp (cssRule, TEXT("scroll"), 6))
2515: cssRule = SkipWord (cssRule);
2516: else if (!ustrncasecmp (cssRule, TEXT("fixed"), 5))
2517: cssRule = SkipWord (cssRule);
2518:
1.1 cvs 2519: /* restore the refered element */
2520: if (moved && !element)
2521: context->type = savedtype;
1.18 cvs 2522: return (cssRule);
1.1 cvs 2523: }
2524:
2525: /*----------------------------------------------------------------------
1.18 cvs 2526: ParseCSSBackgroundPosition : parse a CSS BackgroundPosition
1.1 cvs 2527: attribute string.
2528: ----------------------------------------------------------------------*/
2529: #ifdef __STDC__
1.18 cvs 2530: static STRING ParseCSSBackgroundPosition (Element element, PSchema tsch,
1.14 cvs 2531: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
1.1 cvs 2532: #else
1.18 cvs 2533: static STRING ParseCSSBackgroundPosition (element, tsch, context, cssRule, css, isHTML)
1.1 cvs 2534: Element element;
2535: PSchema tsch;
2536: PresentationContext context;
2537: STRING cssRule;
2538: CSSInfoPtr css;
1.14 cvs 2539: ThotBool isHTML;
1.1 cvs 2540: #endif
2541: {
1.18 cvs 2542: PresentationValue repeat;
2543: unsigned int savedtype = 0;
2544: ThotBool moved;
2545: ThotBool ok;
1.1 cvs 2546:
2547: /* move the BODY rule to the HTML element */
2548: moved = (context->type == HTML_EL_BODY && isHTML);
2549: if (moved)
2550: {
2551: if (element)
2552: element = TtaGetMainRoot (context->doc);
2553: else
2554: {
2555: savedtype = context->type;
2556: context->type = HTML_EL_HTML;
2557: }
2558: }
2559:
1.18 cvs 2560: cssRule = SkipBlanksAndComments (cssRule);
2561: ok = TRUE;
2562: if (!ustrncasecmp (cssRule, TEXT("left"), 4))
2563: cssRule = SkipWord (cssRule);
2564: else if (!ustrncasecmp (cssRule, TEXT("right"), 5))
2565: cssRule = SkipWord (cssRule);
2566: else if (!ustrncasecmp (cssRule, TEXT("center"), 6))
2567: cssRule = SkipWord (cssRule);
2568: else if (!ustrncasecmp (cssRule, TEXT("top"), 3))
2569: cssRule = SkipWord (cssRule);
2570: else if (!ustrncasecmp (cssRule, TEXT("bottom"), 6))
2571: cssRule = SkipWord (cssRule);
2572: else if (isdigit (*cssRule))
2573: cssRule = SkipWord (cssRule);
2574: else
2575: ok = FALSE;
2576:
2577: if (ok)
2578: {
2579: /* force realsize for the background image */
2580: repeat.typed_data.value = STYLE_REALSIZE;
2581: repeat.typed_data.unit = STYLE_UNIT_REL;
2582: repeat.typed_data.real = FALSE;
2583: TtaSetStylePresentation (PRPictureMode, element, tsch, context, repeat);
2584: }
2585:
2586: /* restore the refered element */
2587: if (moved && !element)
2588: context->type = savedtype;
2589: return (cssRule);
2590: }
2591:
2592: /*----------------------------------------------------------------------
2593: ParseCSSBackground : parse a CSS background attribute
2594: ----------------------------------------------------------------------*/
2595: #ifdef __STDC__
2596: static STRING ParseCSSBackground (Element element, PSchema tsch,
2597: PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
2598: #else
2599: static STRING ParseCSSBackground (element, tsch, context, cssRule, css, isHTML)
2600: Element element;
2601: PSchema tsch;
2602: PresentationContext context;
2603: STRING cssRule;
2604: CSSInfoPtr css;
2605: ThotBool isHTML;
2606: #endif
2607: {
2608: STRING ptr;
2609:
1.13 cvs 2610: cssRule = SkipBlanksAndComments (cssRule);
1.18 cvs 2611: while (*cssRule != ';' && *cssRule != EOS && *cssRule != ',')
2612: {
2613: /* perhaps a Backgroud Image */
2614: if (!ustrncasecmp (cssRule, TEXT("url"), 3))
2615: cssRule = ParseCSSBackgroundImage (element, tsch, context, cssRule, css, isHTML);
2616: /* perhaps a Background Attachment */
2617: else if (!ustrncasecmp (cssRule, TEXT("scroll"), 6) ||
2618: !ustrncasecmp (cssRule, TEXT("fixed"), 5))
2619: cssRule = ParseCSSBackgroundAttachment (element, tsch, context, cssRule, css, isHTML);
2620: /* perhaps a Background Repeat */
2621: else if (!ustrncasecmp (cssRule, TEXT("no-repeat"), 9) ||
2622: !ustrncasecmp (cssRule, TEXT("repeat-y"), 8) ||
2623: !ustrncasecmp (cssRule, TEXT("repeat-x"), 8) ||
2624: !ustrncasecmp (cssRule, TEXT("repeat"), 6))
2625: cssRule = ParseCSSBackgroundRepeat (element, tsch, context, cssRule, css, isHTML);
2626: /* perhaps a Background Position */
2627: else if (!ustrncasecmp (cssRule, TEXT("left"), 4) ||
2628: !ustrncasecmp (cssRule, TEXT("right"), 5) ||
2629: !ustrncasecmp (cssRule, TEXT("center"), 6) ||
2630: !ustrncasecmp (cssRule, TEXT("top"), 3) ||
2631: !ustrncasecmp (cssRule, TEXT("bottom"), 6) ||
2632: isdigit (*cssRule))
2633: cssRule = ParseCSSBackgroundPosition (element, tsch, context, cssRule, css, isHTML);
2634: /* perhaps a Background Color */
2635: else
2636: {
2637: /* check if the rule has been found */
2638: ptr = cssRule;
2639: cssRule = ParseCSSBackgroundColor (element, tsch, context, cssRule, css, isHTML);
2640: if (ptr== cssRule)
2641: /* rule not found */
2642: cssRule = SkipProperty (cssRule);
2643: }
2644: cssRule = SkipBlanksAndComments (cssRule);
2645: }
2646: return (cssRule);
2647: }
2648:
2649:
2650:
2651: /************************************************************************
2652: * *
2653: * FUNCTIONS STYLE DECLARATIONS *
2654: * *
2655: ************************************************************************/
2656: /*
2657: * NOTE : Long attribute name MUST be placed before shortened ones !
2658: * e.g. "FONT-SIZE" must be placed before "FONT"
2659: */
2660: static CSSProperty CSSProperties[] =
2661: {
2662: {TEXT ("font-family"), ParseCSSFontFamily},
2663: {TEXT ("font-style"), ParseCSSFontStyle},
2664: {TEXT ("font-variant"), ParseCSSFontVariant},
2665: {TEXT ("font-weight"), ParseCSSFontWeight},
2666: {TEXT ("font-size"), ParseCSSFontSize},
2667: {TEXT ("font"), ParseCSSFont},
2668:
2669: {TEXT ("color"), ParseCSSForeground},
2670: {TEXT ("background-color"), ParseCSSBackgroundColor},
2671: {TEXT ("background-image"), ParseCSSBackgroundImage},
2672: {TEXT ("background-repeat"), ParseCSSBackgroundRepeat},
2673: {TEXT ("background-attachment"), ParseCSSBackgroundAttachment},
2674: {TEXT ("background-position"), ParseCSSBackgroundPosition},
2675: {TEXT ("background"), ParseCSSBackground},
2676:
2677: {TEXT ("word-spacing"), ParseCSSWordSpacing},
2678: {TEXT ("letter-spacing"), ParseCSSLetterSpacing},
2679: {TEXT ("text-decoration"), ParseCSSTextDecoration},
2680: {TEXT ("vertical-align"), ParseCSSVerticalAlign},
2681: {TEXT ("text-transform"), ParseCSSTextTransform},
2682: {TEXT ("text-align"), ParseCSSTextAlign},
2683: {TEXT ("text-indent"), ParseCSSTextIndent},
2684: {TEXT ("line-height"), ParseCSSLineSpacing},
2685:
2686: {TEXT ("margin-top"), ParseCSSMarginTop},
2687: {TEXT ("margin-right"), ParseCSSMarginRight},
2688: {TEXT ("margin-bottom"), ParseCSSMarginBottom},
2689: {TEXT ("margin-left"), ParseCSSMarginLeft},
2690: {TEXT ("margin"), ParseCSSMargin},
2691:
2692: {TEXT ("padding-top"), ParseCSSPaddingTop},
2693: {TEXT ("padding-right"), ParseCSSPaddingRight},
2694: {TEXT ("padding-bottom"), ParseCSSPaddingBottom},
2695: {TEXT ("padding-left"), ParseCSSPaddingLeft},
2696: {TEXT ("padding"), ParseCSSPadding},
2697:
2698: {TEXT ("border-top-width"), ParseCSSBorderTopWidth},
2699: {TEXT ("border-right-width"), ParseCSSBorderRightWidth},
2700: {TEXT ("border-bottom-width"), ParseCSSBorderBottomWidth},
2701: {TEXT ("border-left-width"), ParseCSSBorderLeftWidth},
2702: {TEXT ("border-width"), ParseCSSBorderWidth},
2703: {TEXT ("border-color"), ParseCSSBorderColor},
2704: {TEXT ("border-style"), ParseCSSBorderStyle},
2705: {TEXT ("border-top"), ParseCSSBorderTop},
2706: {TEXT ("border-right"), ParseCSSBorderRight},
2707: {TEXT ("border-bottom"), ParseCSSBorderBottom},
2708: {TEXT ("border-left"), ParseCSSBorderLeft},
2709: {TEXT ("border"), ParseCSSBorder},
2710:
2711: {TEXT ("width"), ParseCSSWidth},
2712: {TEXT ("height"), ParseCSSHeight},
2713: {TEXT ("float"), ParseCSSFloat},
2714: {TEXT ("clear"), ParseCSSClear},
2715:
2716: {TEXT ("display"), ParseCSSDisplay},
2717: {TEXT ("white-space"), ParseCSSWhiteSpace},
2718:
2719: {TEXT ("list-style-type"), ParseCSSListStyleType},
2720: {TEXT ("list-style-image"), ParseCSSListStyleImage},
2721: {TEXT ("list-style-position"), ParseCSSListStylePosition},
2722: {TEXT ("list-style"), ParseCSSListStyle}
2723: };
2724: #define NB_CSSSTYLEATTRIBUTE (sizeof(CSSProperties) / sizeof(CSSProperty))
2725:
2726: /*----------------------------------------------------------------------
2727: ParseCSSRule : parse a CSS Style string
2728: we expect the input string describing the style to be of the
2729: form : PRORPERTY : DESCRIPTION [ ; PROPERTY : DESCRIPTION ] *
2730: but tolerate incorrect or incomplete input
2731: ----------------------------------------------------------------------*/
2732: #ifdef __STDC__
2733: static void ParseCSSRule (Element element, PSchema tsch, PresentationContext context, STRING cssRule, CSSInfoPtr css, ThotBool isHTML)
2734: #else
2735: static void ParseCSSRule (element, tsch, context, cssRule, css, isHTML)
2736: Element element;
2737: PSchema tsch;
2738: PresentationContext context;
2739: STRING cssRule;
2740: CSSInfoPtr css;
2741: ThotBool isHTML;
2742: #endif
2743: {
2744: STRING p = NULL;
2745: int lg;
2746: unsigned int i, savedtype;
2747: ThotBool found;
2748:
2749: while (*cssRule != EOS)
2750: {
2751: cssRule = SkipBlanksAndComments (cssRule);
2752:
2753: found = FALSE;
2754: /* look for the type of property */
2755: for (i = 0; i < NB_CSSSTYLEATTRIBUTE && !found; i++)
2756: {
2757: lg = ustrlen (CSSProperties[i].name);
2758: if (!ustrncasecmp (cssRule, CSSProperties[i].name, lg))
2759: {
2760: cssRule += lg;
2761: found = TRUE;
2762: i--;
2763: }
2764: }
2765:
2766: if (i == NB_CSSSTYLEATTRIBUTE)
2767: cssRule = SkipProperty (cssRule);
2768: else
2769: {
2770: /* update index and skip the ":" indicator if present */
2771: cssRule = SkipBlanksAndComments (cssRule);
2772: if (*cssRule == ':')
2773: {
2774: cssRule++;
2775: cssRule = SkipBlanksAndComments (cssRule);
2776: }
2777: /* try to parse the attribute associated to this attribute */
2778: if (CSSProperties[i].parsing_function != NULL)
2779: p = CSSProperties[i].parsing_function (element, tsch, context, cssRule, css, isHTML);
2780:
2781: /* Update the rendering */
2782: TtaUpdateStylePresentation (element, tsch, context);
2783: /* In case of specific rules on BODY element */
2784: if (context->type == HTML_EL_BODY && isHTML)
2785: {
2786: if (element)
2787: TtaUpdateStylePresentation (TtaGetMainRoot (context->doc), NULL, context);
2788: else
2789: {
2790: savedtype = context->type;
2791: context->type = HTML_EL_HTML;
2792: TtaUpdateStylePresentation (NULL, tsch, context);
2793: context->type = savedtype;
2794: }
2795: }
2796:
2797: /* update index and skip the ";" separator if present */
2798: cssRule = p;
2799: }
2800: /* next property */
2801: cssRule = SkipBlanksAndComments (cssRule);
2802: if (*cssRule == ',' || *cssRule == ';')
2803: {
2804: cssRule++;
2805: cssRule = SkipBlanksAndComments (cssRule);
2806: }
2807: }
2808: }
1.1 cvs 2809:
2810:
2811: /*----------------------------------------------------------------------
1.18 cvs 2812: PToCss : translate a PresentationSetting to the
2813: equivalent CSS string, and add it to the buffer given as the
2814: argument. It is used when extracting the CSS string from actual
2815: presentation.
2816:
2817: All the possible values returned by the presentation drivers are
2818: described in thotlib/include/presentation.h
2819: -----------------------------------------------------------------------*/
1.1 cvs 2820: #ifdef __STDC__
1.18 cvs 2821: void PToCss (PresentationSetting settings, STRING buffer, int len)
1.1 cvs 2822: #else
1.18 cvs 2823: void PToCss (settings, buffer, len)
2824: PresentationSetting settings;
2825: STRING param;
2826: int len
1.1 cvs 2827: #endif
2828: {
1.18 cvs 2829: float fval = 0;
2830: unsigned short red, green, blue;
2831: int add_unit = 0;
2832: unsigned int unit, i;
2833: ThotBool real = FALSE;
2834:
2835: buffer[0] = EOS;
2836: if (len < 40)
2837: return;
2838:
2839: unit = settings->value.typed_data.unit;
2840: if (settings->value.typed_data.real)
2841: {
2842: real = TRUE;
2843: fval = (float) settings->value.typed_data.value;
2844: fval /= 1000;
2845: }
1.1 cvs 2846:
1.18 cvs 2847: switch (settings->type)
1.1 cvs 2848: {
1.18 cvs 2849: case PRVisibility:
2850: break;
2851: case PRFont:
2852: switch (settings->value.typed_data.value)
2853: {
2854: case STYLE_FONT_HELVETICA:
2855: ustrcpy (buffer, TEXT("font-family: helvetica"));
2856: break;
2857: case STYLE_FONT_TIMES:
2858: ustrcpy (buffer, TEXT("font-family: times"));
2859: break;
2860: case STYLE_FONT_COURIER:
2861: ustrcpy (buffer, TEXT("font-family: courier"));
2862: break;
2863: }
2864: break;
2865: case PRStyle:
2866: switch (settings->value.typed_data.value)
2867: {
2868: case STYLE_FONT_ROMAN:
2869: ustrcpy (buffer, TEXT("font-style: normal"));
2870: break;
2871: case STYLE_FONT_ITALICS:
2872: ustrcpy (buffer, TEXT("font-style: italic"));
2873: break;
2874: case STYLE_FONT_OBLIQUE:
2875: ustrcpy (buffer, TEXT("font-style: oblique"));
2876: break;
1.20 cvs 2877: }
2878: break;
2879: case PRWeight:
2880: switch (settings->value.typed_data.value)
2881: {
2882: case STYLE_WEIGHT_BOLD:
2883: ustrcpy (buffer, TEXT("font-weight: bold"));
2884: break;
2885: case STYLE_WEIGHT_NORMAL:
2886: ustrcpy (buffer, TEXT("font-weight: normal"));
1.18 cvs 2887: break;
2888: }
2889: break;
2890: case PRSize:
2891: if (unit == STYLE_UNIT_REL)
2892: {
2893: if (real)
2894: {
2895: usprintf (buffer, TEXT("font-size: %g"), fval);
2896: add_unit = 1;
2897: }
2898: else
2899: switch (settings->value.typed_data.value)
2900: {
2901: case 1:
2902: ustrcpy (buffer, TEXT("font-size: xx-small"));
2903: break;
2904: case 2:
2905: ustrcpy (buffer, TEXT("font-size: x-small"));
2906: break;
2907: case 3:
2908: ustrcpy (buffer, TEXT("font-size: small"));
2909: break;
2910: case 4:
2911: ustrcpy (buffer, TEXT("font-size: medium"));
2912: break;
2913: case 5:
2914: ustrcpy (buffer, TEXT("font-size: large"));
2915: break;
2916: case 6:
2917: ustrcpy (buffer, TEXT("font-size: x-large"));
2918: break;
2919: case 7:
2920: case 8:
2921: case 9:
2922: case 10:
2923: case 11:
2924: case 12:
2925: ustrcpy (buffer, TEXT("font-size: xx-large"));
2926: break;
2927: }
2928: }
2929: else
2930: {
2931: if (real)
2932: usprintf (buffer, TEXT("font-size: %g"), fval);
2933: else
2934: usprintf (buffer, TEXT("font-size: %d"), settings->value.typed_data.value);
2935: add_unit = 1;
2936: }
2937: break;
2938: case PRUnderline:
2939: switch (settings->value.typed_data.value)
2940: {
2941: case STYLE_UNDERLINE:
2942: ustrcpy (buffer, TEXT("text-decoration: underline"));
2943: break;
2944: case STYLE_OVERLINE:
2945: ustrcpy (buffer, TEXT("text-decoration: overline"));
2946: break;
2947: case STYLE_CROSSOUT:
2948: ustrcpy (buffer, TEXT("text-decoration: line-through"));
2949: break;
2950: }
2951: break;
2952: case PRIndent:
2953: if (real)
2954: usprintf (buffer, TEXT("text-indent: %g"), fval);
2955: else
2956: usprintf (buffer, TEXT("text-indent: %d"), settings->value.typed_data.value);
2957: add_unit = 1;
2958: break;
2959: case PRLineSpacing:
2960: if (real)
2961: usprintf (buffer, TEXT("line-height: %g"), fval);
1.1 cvs 2962: else
1.18 cvs 2963: usprintf (buffer, TEXT("line-height: %d"), settings->value.typed_data.value);
2964: add_unit = 1;
2965: break;
2966: case PRJustify:
2967: if (settings->value.typed_data.value == STYLE_JUSTIFIED)
2968: usprintf (buffer, TEXT("text-align: justify"));
2969: break;
2970: case PRAdjust:
2971: switch (settings->value.typed_data.value)
1.1 cvs 2972: {
1.18 cvs 2973: case STYLE_ADJUSTLEFT:
2974: ustrcpy (buffer, TEXT("text-align: left"));
2975: break;
2976: case STYLE_ADJUSTRIGHT:
2977: ustrcpy (buffer, TEXT("text-align: right"));
2978: break;
2979: case STYLE_ADJUSTCENTERED:
2980: ustrcpy (buffer, TEXT("text-align: center"));
2981: break;
2982: case STYLE_ADJUSTLEFTWITHDOTS:
2983: ustrcpy (buffer, TEXT("text-align: left"));
2984: break;
1.1 cvs 2985: }
1.18 cvs 2986: break;
2987: case PRHyphenate:
2988: break;
2989: case PRFillPattern:
2990: break;
2991: case PRBackground:
2992: TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
2993: usprintf (buffer, TEXT("background-color: #%02X%02X%02X"), red, green, blue);
2994: break;
2995: case PRForeground:
2996: TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
2997: usprintf (buffer, TEXT("color: #%02X%02X%02X"), red, green, blue);
2998: break;
2999: case PRTMargin:
3000: if (real)
3001: usprintf (buffer, TEXT("marging-top: %g"), fval);
3002: else
3003: usprintf (buffer, TEXT("marging-top: %d"), settings->value.typed_data.value);
3004: add_unit = 1;
3005: break;
3006: case PRLMargin:
3007: if (real)
3008: usprintf (buffer, TEXT("margin-left: %g"), fval);
3009: else
3010: usprintf (buffer, TEXT("margin-left: %d"), settings->value.typed_data.value);
3011: add_unit = 1;
3012: break;
3013: case PRHeight:
3014: if (real)
3015: usprintf (buffer, TEXT("height: %g"), fval);
3016: else
3017: usprintf (buffer, TEXT("height: %d"), settings->value.typed_data.value);
3018: add_unit = 1;
3019: break;
3020: case PRWidth:
3021: if (real)
3022: usprintf (buffer, TEXT("width: %g"), fval);
1.1 cvs 3023: else
1.18 cvs 3024: usprintf (buffer, TEXT("width: %d"), settings->value.typed_data.value);
3025: add_unit = 1;
3026: break;
3027: case PRLine:
3028: if (settings->value.typed_data.value == STYLE_INLINE)
3029: ustrcpy (buffer, TEXT("display: inline"));
3030: else if (settings->value.typed_data.value == STYLE_NOTINLINE)
3031: ustrcpy (buffer, TEXT("display: block"));
3032: break;
3033: case PRBackgroundPicture:
3034: if (settings->value.pointer != NULL)
1.19 cvs 3035: usprintf (buffer, TEXT("background-image: url(%s)"), (STRING)(settings->value.pointer));
1.1 cvs 3036: else
1.18 cvs 3037: usprintf (buffer, TEXT("background-image: none"));
3038: break;
3039: case PRPictureMode:
3040: switch (settings->value.typed_data.value)
1.1 cvs 3041: {
1.18 cvs 3042: case STYLE_REALSIZE:
3043: usprintf (buffer, TEXT("background-repeat: no-repeat"));
3044: break;
3045: case STYLE_REPEAT:
3046: usprintf (buffer, TEXT("background-repeat: repeat"));
3047: break;
3048: case STYLE_VREPEAT:
3049: usprintf (buffer, TEXT("background-repeat: repeat-y"));
3050: break;
3051: case STYLE_HREPEAT:
3052: usprintf (buffer, TEXT("background-repeat: repeat-x"));
3053: break;
1.1 cvs 3054: }
1.18 cvs 3055: break;
3056: default:
3057: break;
1.1 cvs 3058: }
3059:
1.18 cvs 3060: if (add_unit)
1.1 cvs 3061: {
1.18 cvs 3062: /* add the unit string to the CSS string */
3063: for (i = 0; i < NB_UNITS; i++)
1.1 cvs 3064: {
1.18 cvs 3065: if (CSSUnitNames[i].unit == unit)
1.1 cvs 3066: {
1.18 cvs 3067: ustrcat (buffer, CSSUnitNames[i].sign);
3068: break;
1.1 cvs 3069: }
3070: }
3071: }
3072: }
3073:
3074: /*----------------------------------------------------------------------
1.18 cvs 3075: ParseHTMLSpecificStyle : parse and apply a CSS Style string.
3076: This function must be called when a specific style is applied to an
3077: element.
1.1 cvs 3078: ----------------------------------------------------------------------*/
3079: #ifdef __STDC__
1.14 cvs 3080: void ParseHTMLSpecificStyle (Element el, STRING cssRule, Document doc, ThotBool destroy)
1.1 cvs 3081: #else
3082: void ParseHTMLSpecificStyle (el, cssRule, doc, destroy)
3083: Element elem;
3084: STRING cssRule;
3085: Document doc;
1.14 cvs 3086: ThotBool destroy;
1.1 cvs 3087: #endif
3088: {
3089: PresentationContext context;
3090: ElementType elType;
1.14 cvs 3091: ThotBool isHTML;
1.1 cvs 3092:
3093: /* A rule applying to BODY is really meant to address HTML */
3094: elType = TtaGetElementType (el);
1.17 cvs 3095: isHTML = (ustrcmp(TtaGetSSchemaName (elType.ElSSchema), TEXT("HTML")) == 0);
1.1 cvs 3096: /* create the context of the Specific presentation driver */
3097: context = TtaGetSpecificStyleContext (doc);
3098: if (context == NULL)
3099: return;
3100: context->type = elType.ElTypeNum;
3101: context->destroy = destroy;
3102: /* Call the parser */
3103: ParseCSSRule (el, NULL, (PresentationContext) context, cssRule, NULL, isHTML);
3104: /* free the context */
3105: TtaFreeMemory(context);
3106: }
3107:
3108: /*----------------------------------------------------------------------
1.25 cvs 3109: ParseGenericSelector : Create a generic context for a given
1.1 cvs 3110: selector string. If the selector is made of multiple comma-
3111: separated selector items, it parses them one at a time and
3112: return the end of the selector string to be handled or NULL
3113: ----------------------------------------------------------------------*/
3114: #ifdef __STDC__
1.25 cvs 3115: static STRING ParseGenericSelector (STRING selector, STRING cssRule,
1.1 cvs 3116: GenericContext ctxt, Document doc, CSSInfoPtr css)
3117: #else
1.25 cvs 3118: static STRING ParseGenericSelector (selector, cssRule, ctxt, doc, css)
1.1 cvs 3119: STRING selector;
3120: STRING cssRule;
3121: GenericContext ctxt;
3122: Document doc;
3123: CSSInfoPtr css;
3124: #endif
3125: {
3126: ElementType elType;
3127: PSchema tsch;
1.25 cvs 3128: AttributeType attrType;
3129: CHAR_T sel[MAX_ANCESTORS * 50];
3130: STRING deb, cur;
3131: STRING structName;
3132: STRING names[MAX_ANCESTORS];
3133: STRING ids[MAX_ANCESTORS];
3134: STRING classes[MAX_ANCESTORS];
3135: STRING pseudoclasses[MAX_ANCESTORS];
3136: STRING attrs[MAX_ANCESTORS];
3137: STRING attrvals[MAX_ANCESTORS];
3138: int i, j, k, max;
3139: ThotBool isHTML;
1.1 cvs 3140:
3141: sel[0] = EOS;
3142: for (i = 0; i < MAX_ANCESTORS; i++)
3143: {
1.25 cvs 3144: names[i] = NULL;
3145: ids[i] = NULL;
3146: classes[i] = NULL;
3147: pseudoclasses[i] = NULL;
3148: attrs[i] = NULL;
3149: attrvals[i] = NULL;
3150:
3151: ctxt->name[i] = 0;
3152: ctxt->names_nb[i] = 0;
3153: ctxt->attrType[i] = 0;
3154: ctxt->attrText[i] = NULL;
1.1 cvs 3155: }
1.25 cvs 3156: ctxt->box = 0;
3157: ctxt->type = 0;
3158:
1.13 cvs 3159: selector = SkipBlanksAndComments (selector);
1.25 cvs 3160: deb = cur = &sel[0];
3161: max = 0; /* number of loops */
1.1 cvs 3162: while (1)
3163: {
1.25 cvs 3164: /* copy an item of the selector into sel[] */
1.1 cvs 3165: cur = deb;
3166: /* put one word in the sel buffer */
3167: while (*selector != EOS && *selector != ',' &&
3168: *selector != '.' && *selector != ':' &&
3169: *selector != '#' && !TtaIsBlank (selector))
3170: *cur++ = *selector++;
1.25 cvs 3171: *cur++ = EOS; /* close the first string in sel[] */
3172: if (deb[0] != EOS)
3173: names[max] = deb;
3174: else
3175: names[max] = NULL;
3176: classes[max] = NULL;
3177: pseudoclasses[max] = NULL;
3178: ids[max] = NULL;
3179: attrs[max] = NULL;
3180: attrvals[max] = NULL;
3181:
3182: /* now names[max] points to the beginning of the parsed item
3183: and cur to the next chain to be parsed */
1.1 cvs 3184: if (*selector == ':' || *selector == '.' || *selector == '#')
1.25 cvs 3185: /* keep the element name which precedes the id or
3186: pseudo class or the class */
1.1 cvs 3187: deb = cur;
3188:
3189: if (*selector == '.')
3190: {
1.25 cvs 3191: /* copy into sel[] the class */
3192: classes[max] = cur;
1.1 cvs 3193: selector++;
3194: while (*selector != EOS && *selector != ',' &&
3195: *selector != '.' && *selector != ':' &&
3196: !TtaIsBlank (selector))
3197: *cur++ = *selector++;
3198: *cur++ = EOS;
3199: }
3200: else if (*selector == ':')
3201: {
1.25 cvs 3202: /* copy into sel[] the pseudoclass */
3203: pseudoclasses[max]= cur;
1.1 cvs 3204: selector++;
3205: while (*selector != EOS && *selector != ',' &&
3206: *selector != '.' && *selector != ':' &&
3207: !TtaIsBlank (selector))
3208: *cur++ = *selector++;
3209: *cur++ = EOS;
3210: cur = deb;
3211: }
3212: else if (*selector == '#')
3213: {
1.25 cvs 3214: /* copy into sel[] the attribute */
3215: ids[max] = cur;
1.1 cvs 3216: selector++;
3217: while (*selector != EOS && *selector != ',' &&
3218: *selector != '.' && *selector != ':' &&
3219: !TtaIsBlank (selector))
3220: *cur++ = *selector++;
3221: *cur++ = EOS;
3222: cur = deb;
3223: }
1.25 cvs 3224: else if (*selector == '[')
1.1 cvs 3225: {
1.25 cvs 3226: /* copy into sel[] the attribute */
3227: attrs[max] = cur;
3228: selector++;
3229: while (*selector != EOS && *selector != ']' && *selector != '=')
3230: *cur++ = *selector++;
3231: if (*cur == '=')
3232: {
3233: /* there is a value "xxxx" */
3234: *cur++ = EOS;
3235: while (*selector != EOS && *selector != ']' && *selector != '"')
3236: selector++;
3237: if (*selector != EOS)
3238: {
3239: /* we are now parsing the attribute value */
3240: attrvals[max] = cur;
3241: selector++;
3242: while (*selector != EOS && *selector != '"')
3243: *cur++ = *selector++;
3244: if (*selector != EOS)
3245: selector++;
3246: }
3247: }
3248: *cur++ = EOS;
3249: cur = deb;
1.1 cvs 3250: }
3251:
1.25 cvs 3252: if (TtaIsBlank (selector))
1.1 cvs 3253: {
1.25 cvs 3254: selector = SkipBlanksAndComments (selector);
3255: while (*selector != EOS && *selector != ',')
3256: selector++;
1.1 cvs 3257: }
3258:
1.25 cvs 3259: /* is it a multi-level selector? */
1.1 cvs 3260: if (*selector == EOS)
3261: /* end of the selector */
3262: break;
3263: else if (*selector == ',')
3264: {
3265: /* end of the current selector */
3266: selector++;
3267: break;
3268: }
1.25 cvs 3269: else
3270: {
3271: /* shifts the list to make room for the new name */
3272: max++; /* a new level in ancestor tables */
3273: if (max == MAX_ANCESTORS)
3274: /* abort the CSS parsing */
3275: return (selector);
3276: for (i = max; i > 0; i--)
3277: {
3278: names[i] = names[i - 1];
3279: ids[i] = ids[i - 1];
3280: classes[i] = classes[i - 1];
3281: attrs[i] = attrs[i - 1];
3282: attrvals[i] = attrvals[i - 1];
3283: pseudoclasses[i] = pseudoclasses[i - 1];
3284: }
3285: }
1.1 cvs 3286: }
3287:
3288: /* Now set up the context block */
1.25 cvs 3289: i = 0;
3290: k = 0;
3291: j = 0;
3292: while (i <= max)
3293: {
3294: if (names[i])
3295: {
3296: /* get the new element type of this name */
3297: GIType (names[i], &elType, doc);
3298: if (i == 0)
3299: {
3300: /* Store the element type */
3301: ctxt->type = elType.ElTypeNum;
3302: ctxt->schema = elType.ElSSchema;
3303: }
3304: else if (elType.ElTypeNum != 0)
3305: {
3306: /* look at the current context to see if the type is already
3307: stored */
3308: j = 0;
3309: while (j < k && ctxt->name[j] != ctxt->name[i])
3310: j++;
3311: if (j == k)
3312: {
3313: /* add a new entry */
3314: k++;
3315: ctxt->name[j] = elType.ElTypeNum;
3316: if (j != 0)
3317: ctxt->names_nb[j] = 1;
3318: }
3319: else
3320: /* increment the number of ancestor levels */
3321: ctxt->names_nb[j]++;
3322: }
3323: else
3324: {
3325: /* add a new entry */
3326: j = k;
3327: k++;
3328: }
3329: }
1.1 cvs 3330: else
1.25 cvs 3331: {
3332: /* add a new entry */
3333: j = k;
3334: k++;
3335: }
3336:
3337: if (i > 0 && (classes[i] || pseudoclasses[i] || ids[i] || attrs[i]))
3338: /* Thot is not able to manage this kind of selector
3339: -> abort the CSS parsing */
1.1 cvs 3340: return (selector);
3341:
1.25 cvs 3342: /* store attributes information */
3343: if (classes[i])
3344: {
3345: ctxt->attrText[j] = classes[i];
3346: ctxt->attrType[j] = HTML_ATTR_Class;
3347: }
3348: else if (pseudoclasses[i])
3349: {
3350: ctxt->attrText[j] = pseudoclasses[i];
3351: ctxt->attrType[j] = HTML_ATTR_PseudoClass;
3352: }
3353: else if (ids[i])
3354: {
3355: ctxt->attrText[j] = ids[i];
3356: ctxt->attrType[j] = HTML_ATTR_ID;
3357: }
3358: else if (attrs[i])
3359: {
3360: MapHTMLAttribute (attrs[i], &attrType, names[i], doc);
3361: ctxt->attrText[j] = attrvals[i];
3362: ctxt->attrType[j] = attrType.AttrTypeNum;
3363: }
3364: i++;
1.1 cvs 3365: }
3366:
1.25 cvs 3367: /* sort the list of ancestors by name order */
3368: max = k;
3369: i = 1;
3370: while (i < max)
3371: for (k = i + 1; k < max; k++)
3372: if (ctxt->name[i] > ctxt->name[k])
3373: {
3374: j = ctxt->name[i];
3375: ctxt->name[i] = ctxt->name[k];
3376: ctxt->name[k] = j;
3377: j = ctxt->names_nb[i];
3378: ctxt->names_nb[i] = ctxt->names_nb[k];
3379: ctxt->names_nb[k] = j;
3380: j = ctxt->attrType[i];
3381: ctxt->attrType[i] = ctxt->attrType[k];
3382: ctxt->attrType[k] = j;
3383: cur = ctxt->attrText[i];
3384: ctxt->attrText[i] = ctxt->attrText[k];
3385: ctxt->attrText[k] = cur;
3386: }
3387:
3388: /* Get the schema name of the main element */
3389: if (ctxt->schema == NULL)
1.1 cvs 3390: ctxt->schema = TtaGetDocumentSSchema (doc);
1.17 cvs 3391: isHTML = (ustrcmp(TtaGetSSchemaName (ctxt->schema), TEXT("HTML")) == 0);
1.1 cvs 3392: tsch = GetPExtension (doc, ctxt->schema, css);
3393: structName = TtaGetSSchemaName (ctxt->schema);
3394: if (cssRule)
3395: ParseCSSRule (NULL, tsch, (PresentationContext) ctxt, cssRule, css, isHTML);
3396: return (selector);
3397: }
3398:
3399: /*----------------------------------------------------------------------
3400: ParseStyleDeclaration : parse one HTML style declaration
3401: stored in the header of a HTML document
3402: We expect the style string to be of the form :
3403: [
3404: e.g: pinky, awful { color: pink, font-family: helvetica }
3405: ----------------------------------------------------------------------*/
3406: #ifdef __STDC__
1.14 cvs 3407: static void ParseStyleDeclaration (Element el, STRING cssRule, Document doc, CSSInfoPtr css, ThotBool destroy)
1.1 cvs 3408: #else
3409: static void ParseStyleDeclaration (el, cssRule, doc, css, destroy)
3410: Element el;
3411: STRING cssRule;
3412: Document doc;
3413: CSSInfoPtr css;
1.14 cvs 3414: ThotBool destroy;
1.1 cvs 3415: #endif
3416: {
3417: GenericContext ctxt;
3418: STRING decl_end;
3419: STRING sel_end;
3420: STRING selector;
1.7 cvs 3421: CHAR_T saved1;
3422: CHAR_T saved2;
1.1 cvs 3423:
3424: /* separate the selectors string */
1.13 cvs 3425: cssRule = SkipBlanksAndComments (cssRule);
1.1 cvs 3426: decl_end = cssRule;
3427: while ((*decl_end != EOS) && (*decl_end != '{'))
3428: decl_end++;
3429: if (*decl_end == EOS)
3430: return;
3431: /* verify and clean the selector string */
3432: sel_end = decl_end - 1;
1.18 cvs 3433: while (*sel_end == SPACE || *sel_end == BSPACE ||
3434: *sel_end == EOL || *sel_end == __CR__)
1.1 cvs 3435: sel_end--;
3436: sel_end++;
3437: saved1 = *sel_end;
3438: *sel_end = EOS;
3439: selector = cssRule;
3440:
3441: /* now, deal with the content ... */
3442: decl_end++;
3443: cssRule = decl_end;
3444: while (*decl_end != EOS && *decl_end != '}')
3445: decl_end++;
3446: if (*decl_end == EOS)
3447: {
3448: fprintf (stderr, "Invalid STYLE declaration : %s\n", cssRule);
3449: return;
3450: }
3451: saved2 = *decl_end;
3452: *decl_end = EOS;
3453:
3454: /*
3455: * parse the style attribute string and install the corresponding
3456: * presentation attributes on the new element
3457: */
3458: ctxt = TtaGetGenericStyleContext (doc);
3459: if (ctxt == NULL)
3460: return;
3461: ctxt->destroy = destroy;
3462:
3463: while ((selector != NULL) && (*selector != EOS))
1.25 cvs 3464: selector = ParseGenericSelector (selector, cssRule, ctxt, doc, css);
1.1 cvs 3465: TtaFreeMemory (ctxt);
3466:
3467: /* restore the string to its original form ! */
3468: *sel_end = saved1;
3469: *decl_end = saved2;
3470: }
3471:
3472: /************************************************************************
3473: * *
3474: * EVALUATION FUNCTIONS / CASCADING AND OVERLOADING *
3475: * *
3476: ************************************************************************/
3477:
3478: /*----------------------------------------------------------------------
3479: IsImplicitClassName : return wether the Class name is an
3480: implicit one, eg "H1" or "H2 EM" meaning it's a GI name
3481: or an HTML context name.
3482: ----------------------------------------------------------------------*/
3483: #ifdef __STDC__
3484: int IsImplicitClassName (STRING class, Document doc)
3485: #else
3486: int IsImplicitClassName (class, doc)
3487: STRING class;
3488: Document doc;
3489: #endif
3490: {
1.25 cvs 3491: CHAR_T name[200];
3492: STRING cur = name, first;
3493: CHAR_T save;
1.1 cvs 3494: SSchema schema;
3495:
3496: /* make a local copy */
3497: ustrncpy (name, class, 199);
3498: name[199] = 0;
3499:
3500: /* loop looking if each word is a GI */
3501: while (*cur != 0)
3502: {
3503: first = cur;
3504: cur = SkipWord (cur);
3505: save = *cur;
3506: *cur = 0;
3507: schema = NULL;
3508: if (MapGI (first, &schema, doc) == -1)
3509: {
3510: return (0);
3511: }
3512: *cur = save;
1.13 cvs 3513: cur = SkipBlanksAndComments (cur);
1.1 cvs 3514: }
3515: return (1);
3516: }
3517:
3518: /************************************************************************
3519: * *
3520: * Functions Needed for support of HTML 3.2 : translate to CSS equiv *
3521: * *
3522: ************************************************************************/
3523:
3524: /*----------------------------------------------------------------------
3525: HTMLSetBackgroundColor :
3526: ----------------------------------------------------------------------*/
3527: #ifdef __STDC__
3528: void HTMLSetBackgroundColor (Document doc, Element el, STRING color)
3529: #else
3530: void HTMLSetBackgroundColor (doc, el, color)
3531: Document doc;
3532: Element el;
3533: STRING color;
3534: #endif
3535: {
1.7 cvs 3536: CHAR_T css_command[100];
1.1 cvs 3537:
1.17 cvs 3538: usprintf (css_command, TEXT("background-color: %s"), color);
1.1 cvs 3539: ParseHTMLSpecificStyle (el, css_command, doc, FALSE);
3540: }
3541:
3542: /*----------------------------------------------------------------------
3543: HTMLSetBackgroundImage :
3544: repeat = repeat value
3545: image = url of background image
3546: ----------------------------------------------------------------------*/
3547: #ifdef __STDC__
3548: void HTMLSetBackgroundImage (Document doc, Element el, int repeat, STRING image)
3549: #else
3550: void HTMLSetBackgroundImage (doc, el, repeat, image)
3551: Document doc;
3552: Element el;
3553: int repeat;
3554: STRING image;
3555: #endif
3556: {
1.7 cvs 3557: CHAR_T css_command[400];
1.1 cvs 3558:
3559: /******* check buffer overflow ********/
1.17 cvs 3560: usprintf (css_command, TEXT("background-image: url(%s); background-repeat: "), image);
1.1 cvs 3561: if (repeat == STYLE_REPEAT)
1.17 cvs 3562: ustrcat (css_command, TEXT("repeat"));
1.1 cvs 3563: else if (repeat == STYLE_HREPEAT)
1.17 cvs 3564: ustrcat (css_command, TEXT("repeat-x"));
1.1 cvs 3565: else if (repeat == STYLE_VREPEAT)
1.17 cvs 3566: ustrcat (css_command, TEXT("repeat-y"));
1.1 cvs 3567: else
1.17 cvs 3568: ustrcat (css_command, TEXT("no-repeat"));
1.1 cvs 3569: ParseHTMLSpecificStyle (el, css_command, doc, FALSE);
3570: }
3571:
3572: /*----------------------------------------------------------------------
3573: HTMLSetForegroundColor :
3574: ----------------------------------------------------------------------*/
3575: #ifdef __STDC__
3576: void HTMLSetForegroundColor (Document doc, Element el, STRING color)
3577: #else
3578: void HTMLSetForegroundColor (doc, el, color)
3579: Document doc;
3580: Element el;
3581: STRING color;
3582: #endif
3583: {
1.7 cvs 3584: CHAR_T css_command[100];
1.1 cvs 3585:
1.17 cvs 3586: usprintf (css_command, TEXT("color: %s"), color);
1.1 cvs 3587: ParseHTMLSpecificStyle (el, css_command, doc, FALSE);
3588: }
3589:
3590: /*----------------------------------------------------------------------
3591: HTMLResetBackgroundColor :
3592: ----------------------------------------------------------------------*/
3593: #ifdef __STDC__
3594: void HTMLResetBackgroundColor (Document doc, Element el)
3595: #else
3596: void HTMLResetBackgroundColor (doc, el)
3597: Document doc;
3598: Element el;
3599: #endif
3600: {
1.7 cvs 3601: CHAR_T css_command[100];
1.1 cvs 3602:
1.17 cvs 3603: usprintf (css_command, TEXT("background: xx"));
1.1 cvs 3604: ParseHTMLSpecificStyle (el, css_command, doc, TRUE);
3605: }
3606:
3607: /*----------------------------------------------------------------------
3608: HTMLResetBackgroundImage :
3609: ----------------------------------------------------------------------*/
3610: #ifdef __STDC__
3611: void HTMLResetBackgroundImage (Document doc, Element el)
3612: #else
3613: void HTMLResetBackgroundImage (doc, el)
3614: Document doc;
3615: Element el;
3616: #endif
3617: {
1.7 cvs 3618: CHAR_T css_command[1000];
1.1 cvs 3619:
1.17 cvs 3620: usprintf (css_command, TEXT("background-image: url(xx); background-repeat: repeat"));
1.1 cvs 3621: ParseHTMLSpecificStyle (el, css_command, doc, TRUE);
3622: }
3623:
3624: /*----------------------------------------------------------------------
3625: HTMLResetForegroundColor :
3626: ----------------------------------------------------------------------*/
3627: #ifdef __STDC__
3628: void HTMLResetForegroundColor (Document doc, Element el)
3629: #else
3630: void HTMLResetForegroundColor (doc, el)
3631: Document doc;
3632: Element el;
3633: #endif
3634: {
1.7 cvs 3635: CHAR_T css_command[100];
1.1 cvs 3636:
1.17 cvs 3637: usprintf (css_command, TEXT("color: xx"));
1.1 cvs 3638: ParseHTMLSpecificStyle (el, css_command, doc, TRUE);
3639: }
3640:
3641: /*----------------------------------------------------------------------
3642: HTMLSetAlinkColor :
3643: ----------------------------------------------------------------------*/
3644: #ifdef __STDC__
3645: void HTMLSetAlinkColor (Document doc, STRING color)
3646: #else
3647: void HTMLSetAlinkColor (doc, color)
3648: Document doc;
3649: STRING color;
3650: #endif
3651: {
1.7 cvs 3652: CHAR_T css_command[100];
1.1 cvs 3653:
1.17 cvs 3654: usprintf (css_command, TEXT("A:link { color : %s }"), color);
1.1 cvs 3655: ApplyCSSRules (NULL, css_command, doc, FALSE);
3656: }
3657:
3658: /*----------------------------------------------------------------------
3659: HTMLSetAactiveColor :
3660: ----------------------------------------------------------------------*/
3661: #ifdef __STDC__
3662: void HTMLSetAactiveColor (Document doc, STRING color)
3663: #else
3664: void HTMLSetAactiveColor (doc, color)
3665: Document doc;
3666: STRING color;
3667: #endif
3668: {
1.7 cvs 3669: CHAR_T css_command[100];
1.1 cvs 3670:
1.17 cvs 3671: usprintf (css_command, TEXT("A:active { color : %s }"), color);
1.1 cvs 3672: ApplyCSSRules (NULL, css_command, doc, FALSE);
3673: }
3674:
3675: /*----------------------------------------------------------------------
3676: HTMLSetAvisitedColor :
3677: ----------------------------------------------------------------------*/
3678: #ifdef __STDC__
3679: void HTMLSetAvisitedColor (Document doc, STRING color)
3680: #else
3681: void HTMLSetAvisitedColor (doc, color)
3682: Document doc;
3683: STRING color;
3684: #endif
3685: {
1.7 cvs 3686: CHAR_T css_command[100];
1.1 cvs 3687:
1.17 cvs 3688: usprintf (css_command, TEXT("A:visited { color : %s }"), color);
1.1 cvs 3689: ApplyCSSRules (NULL, css_command, doc, FALSE);
3690: }
3691:
3692: /*----------------------------------------------------------------------
3693: HTMLResetAlinkColor :
3694: ----------------------------------------------------------------------*/
3695: #ifdef __STDC__
3696: void HTMLResetAlinkColor (Document doc)
3697: #else
3698: void HTMLResetAlinkColor (doc)
3699: Document doc;
3700: #endif
3701: {
1.7 cvs 3702: CHAR_T css_command[100];
1.1 cvs 3703:
1.17 cvs 3704: usprintf (css_command, TEXT("A:link { color : red }"));
1.1 cvs 3705: ApplyCSSRules (NULL, css_command, doc, TRUE);
3706: }
3707:
3708: /*----------------------------------------------------------------------
3709: HTMLResetAactiveColor :
3710: ----------------------------------------------------------------------*/
3711: #ifdef __STDC__
3712: void HTMLResetAactiveColor (Document doc)
3713: #else
3714: void HTMLResetAactiveColor (doc)
3715: Document doc;
3716: #endif
3717: {
1.7 cvs 3718: CHAR_T css_command[100];
1.1 cvs 3719:
1.17 cvs 3720: usprintf (css_command, TEXT("A:active { color : red }"));
1.1 cvs 3721: ApplyCSSRules (NULL, css_command, doc, TRUE);
3722: }
3723:
3724: /*----------------------------------------------------------------------
3725: HTMLResetAvisitedColor :
3726: ----------------------------------------------------------------------*/
3727: #ifdef __STDC__
3728: void HTMLResetAvisitedColor (Document doc)
3729: #else
3730: void HTMLResetAvisitedColor (doc)
3731: Document doc;
3732: #endif
3733: {
1.7 cvs 3734: CHAR_T css_command[100];
1.1 cvs 3735:
1.17 cvs 3736: usprintf (css_command, TEXT("A:visited { color : red }"));
1.1 cvs 3737: ApplyCSSRules (NULL, css_command, doc, TRUE);
3738: }
3739:
3740: /*----------------------------------------------------------------------
3741: ApplyCSSRules: parse an CSS Style description stored in the
3742: header of a HTML document.
3743: ----------------------------------------------------------------------*/
3744: #ifdef __STDC__
1.14 cvs 3745: void ApplyCSSRules (Element el, STRING cssRule, Document doc, ThotBool destroy)
1.1 cvs 3746: #else
3747: void ApplyCSSRules (el, cssRule, doc, destroy)
3748: Element el;
3749: STRING cssRule;
3750: Document doc;
1.14 cvs 3751: ThotBool destroy;
1.1 cvs 3752: #endif
3753: {
3754: CSSInfoPtr css;
3755:
3756: css = SearchCSS (doc, NULL);
3757: if (css == NULL)
3758: /* create the document css */
3759: css = AddCSS (doc, doc, CSS_DOCUMENT_STYLE, NULL, NULL);
3760: ParseStyleDeclaration (el, cssRule, doc, css, destroy);
3761: }
3762:
3763: /*----------------------------------------------------------------------
3764: ReadCSSRules : is the front-end function called by the HTML parser
3765: when detecting a <STYLE TYPE="text/css"> indicating it's the
3766: beginning of a CSS fragment or when reading a file .css.
3767:
3768: The CSS parser has to handle <!-- ... --> constructs used to
3769: prevent prehistoric browser from displaying the CSS as a text
3770: content. It will stop on any sequence "<x" where x is different
3771: from ! and will return x as to the caller. Theorically x should
3772: be equal to / for the </STYLE> end of style.
3773:
3774: The parameter doc gives the document tree that contains CSS information.
3775: The parameter docRef gives the document to which CSS are to be applied.
3776: This function uses the current css context or creates it. It's able
1.23 cvs 3777: to work on the given buffer or call GetNextChar to read the parsed
1.1 cvs 3778: file.
3779: Parameter withUndo indicates whether the changes made in the document
3780: structure and content have to be registered in the Undo queue or not
3781: ----------------------------------------------------------------------*/
3782: #ifdef __STDC__
1.18 cvs 3783: CHAR_T ReadCSSRules (Document docRef, CSSInfoPtr css, STRING buffer, ThotBool withUndo)
1.1 cvs 3784: #else
1.18 cvs 3785: CHAR_T ReadCSSRules (docRef, css, buffer, withUndo)
1.1 cvs 3786: Document docRef;
3787: CSSInfoPtr css;
3788: STRING buffer;
1.14 cvs 3789: ThotBool withUndo;
1.1 cvs 3790: #endif
3791: {
1.13 cvs 3792: CHAR_T c;
3793: STRING cssRule, base, cur;
1.6 cvs 3794: DisplayMode dispMode;
1.19 cvs 3795: int index;
1.1 cvs 3796: int CSSindex;
3797: int CSScomment;
3798: int import;
3799: int openRule;
1.14 cvs 3800: ThotBool HTMLcomment;
3801: ThotBool toParse, eof;
3802: ThotBool ignoreMedia;
1.25 cvs 3803: ThotBool noRule;
1.1 cvs 3804:
3805: CSScomment = MAX_CSS_LENGTH;
3806: HTMLcomment = FALSE;
3807: CSSindex = 0;
3808: toParse = FALSE;
3809: noRule = FALSE;
3810: ignoreMedia = FALSE;
3811: import = MAX_CSS_LENGTH;
3812: eof = FALSE;
3813: openRule = 0;
3814: c = SPACE;
3815: index = 0;
1.6 cvs 3816: /* avoid too many redisplay */
3817: dispMode = TtaGetDisplayMode (docRef);
3818: if (dispMode == DisplayImmediately)
3819: TtaSetDisplayMode (docRef, DeferredDisplay);
1.18 cvs 3820:
3821: /* look for the CSS context */
3822: if (css == NULL)
3823: css = SearchCSS (docRef, NULL);
3824: if (css == NULL)
3825: css = AddCSS (docRef, docRef, CSS_DOCUMENT_STYLE, NULL, NULL);
1.1 cvs 3826:
1.25 cvs 3827: while (CSSindex < MAX_CSS_LENGTH && c != EOS && !eof)
1.1 cvs 3828: {
1.23 cvs 3829: c = buffer[index++];
3830: eof = (c == EOS);
1.1 cvs 3831: CSSbuffer[CSSindex] = c;
1.13 cvs 3832: if (CSScomment == MAX_CSS_LENGTH || c == '*' || c == '/' || c == '<')
1.1 cvs 3833: {
1.5 cvs 3834: /* we're not within a comment or we're parsing * or / */
3835: switch (c)
1.1 cvs 3836: {
1.5 cvs 3837: case '@':
3838: /* perhaps an import primitive */
3839: import = CSSindex;
3840: break;
3841: case ';':
3842: if (import != MAX_CSS_LENGTH)
3843: {
1.17 cvs 3844: if (ustrncasecmp (&CSSbuffer[import+1], TEXT("import"), 6))
1.5 cvs 3845: /* it's not an import */
3846: import = MAX_CSS_LENGTH;
3847: /* save the text */
3848: noRule = TRUE;
3849: }
3850: break;
3851: case '*':
1.13 cvs 3852: if (CSScomment == MAX_CSS_LENGTH &&
3853: CSSindex > 0 && CSSbuffer[CSSindex - 1] == '/')
1.5 cvs 3854: /* start a comment */
3855: CSScomment = CSSindex - 1;
3856: break;
3857: case '/':
1.8 cvs 3858: if (CSSindex > 1 &&
1.13 cvs 3859: CSScomment != MAX_CSS_LENGTH &&
3860: CSSbuffer[CSSindex - 1] == '*')
1.5 cvs 3861: {
1.25 cvs 3862: /* close a comment:and ignore its contents */
3863: CSSindex = CSScomment - 1; /* will be incremented later */
1.5 cvs 3864: CSScomment = MAX_CSS_LENGTH;
3865: }
1.25 cvs 3866: else if (CSScomment == MAX_CSS_LENGTH &&
3867: CSSindex > 0 &&
3868: CSSbuffer[CSSindex - 1] == '<')
1.5 cvs 3869: {
3870: /* this is the closing tag ! */
3871: CSSindex -= 2; /* remove </ from the CSS string */
1.13 cvs 3872: noRule = TRUE;
1.8 cvs 3873: }
1.5 cvs 3874: break;
3875: case '<':
1.25 cvs 3876: if (CSScomment == MAX_CSS_LENGTH)
1.5 cvs 3877: {
1.25 cvs 3878: /* only if we're not parsing a comment */
3879: c = buffer[index++];
3880: eof = (c == EOS);
3881: if (c == '!')
3882: {
3883: /* CSS within an HTML comment */
3884: HTMLcomment = TRUE;
3885: CSSindex++;
3886: CSSbuffer[CSSindex] = c;
3887: }
3888: else if (c == EOS)
3889: CSSindex++;
1.5 cvs 3890: }
3891: break;
3892: case '-':
3893: if (CSSindex > 0 && CSSbuffer[CSSindex - 1] == '-' && HTMLcomment)
3894: /* CSS within an HTML comment */
3895: noRule = TRUE;
3896: break;
3897: case '>':
3898: if (HTMLcomment)
3899: noRule = TRUE;
3900: break;
3901: case '{':
3902: openRule++;
3903: if (import != MAX_CSS_LENGTH && openRule == 1)
3904: {
3905: /* is it the screen concerned? */
3906: CSSbuffer[CSSindex+1] = EOS;
1.25 cvs 3907: if (TtaIsPrinting ())
3908: base = ustrstr (&CSSbuffer[import], TEXT("print"));
3909: else
3910: base = ustrstr (&CSSbuffer[import], TEXT("screen"));
1.5 cvs 3911: if (base == NULL)
3912: ignoreMedia = TRUE;
3913: noRule = TRUE;
3914: }
3915: break;
3916: case '}':
3917: openRule--;
3918: if (import != MAX_CSS_LENGTH && openRule == 0)
3919: {
3920: import = MAX_CSS_LENGTH;
3921: noRule = TRUE;
3922: ignoreMedia = FALSE;
3923: }
1.12 cvs 3924: else if (ignoreMedia && openRule == 0)
3925: {
3926: ignoreMedia = FALSE;
3927: noRule = TRUE;
3928: }
1.5 cvs 3929: else
3930: toParse = TRUE;
3931: break;
3932: default:
3933: break;
1.1 cvs 3934: }
3935: }
1.18 cvs 3936: if (c != __CR__)
1.13 cvs 3937: CSSindex++;
1.12 cvs 3938:
1.25 cvs 3939: if (CSSindex >= MAX_CSS_LENGTH || toParse || noRule)
1.1 cvs 3940: {
1.25 cvs 3941: if (CSScomment < MAX_CSS_LENGTH)
3942: {
3943: /* we're still parsing a comment: remove the text comment */
3944: CSSindex = CSScomment;
3945: /* set the origin of the comment in the next buffer */
3946: CSScomment = 0;
3947: }
1.1 cvs 3948: CSSbuffer[CSSindex] = EOS;
3949: /* parse a not empty string */
3950: if (CSSindex > 0)
3951: {
3952: /* apply CSS rule if it's not just a saving of text */
3953: if (!noRule && !ignoreMedia)
1.18 cvs 3954: ParseStyleDeclaration (NULL, CSSbuffer, docRef, css, FALSE);
1.1 cvs 3955: else if (import != MAX_CSS_LENGTH &&
1.17 cvs 3956: !ustrncasecmp (&CSSbuffer[import+1], TEXT("import"), 6))
1.1 cvs 3957: {
3958: /* import section */
3959: cssRule = &CSSbuffer[import+7];
3960: cssRule = TtaSkipBlanks (cssRule);
1.17 cvs 3961: if (!ustrncasecmp (cssRule, TEXT("url"), 3))
1.1 cvs 3962: {
1.13 cvs 3963: cssRule = &cssRule[3];
1.1 cvs 3964: cssRule = TtaSkipBlanks (cssRule);
3965: if (*cssRule == '(')
3966: {
3967: cssRule++;
3968: cssRule = TtaSkipBlanks (cssRule);
3969: base = cssRule;
3970: while (*cssRule != EOS && *cssRule != ')')
3971: cssRule++;
3972: *cssRule = EOS;
1.4 cvs 3973: LoadStyleSheet (base, docRef, NULL, css);
1.1 cvs 3974: }
3975: }
3976: /*** Caution: Strings can either be written with double quotes or
3977: with single quotes. Only double quotes are handled here.
3978: Escaped quotes are not handled. See function SkipQuotedString */
3979: else if (*cssRule == '"')
3980: {
3981: cssRule++;
3982: base = cssRule;
3983: while (*cssRule != EOS && *cssRule != '"')
3984: cssRule++;
3985: *cssRule = EOS;
1.4 cvs 3986: LoadStyleSheet (base, docRef, NULL, css);
1.1 cvs 3987: }
3988: import = MAX_CSS_LENGTH;
3989: }
3990: }
3991: toParse = FALSE;
3992: noRule = FALSE;
3993: CSSindex = 0;
3994: }
3995: }
1.6 cvs 3996: /* restore the display mode */
3997: if (dispMode == DisplayImmediately)
3998: TtaSetDisplayMode (docRef, dispMode);
1.1 cvs 3999: return (c);
4000: }
Webmaster