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