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