Annotation of Amaya/amaya/styleparser.c, revision 1.24

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

Webmaster