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

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

Webmaster