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

1.1       cvs         1: /*
                      2:  *
1.165     vatton      3:  *  (c) COPYRIGHT INRIA and W3C, 1996-2003
1.1       cvs         4:  *  Please first read the full copyright statement in file COPYRIGHT.
                      5:  *
                      6:  */
1.164     quint       7: 
1.1       cvs         8: /*
1.164     quint       9:  * Everything directly related to the CSS syntax should now hopefully
1.1       cvs        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"
1.25      cvs        20: #include "fetchHTMLname.h"
1.100     vatton     21: #include "SVG.h"
1.107     cvs        22: #include "XML.h"
1.141     cvs        23: #include "document.h"
1.1       cvs        24: 
                     25: typedef struct _BackgroundImageCallbackBlock
                     26: {
                     27:   Element                     el;
                     28:   PSchema                     tsch;
                     29:   union
                     30:   {
                     31:     PresentationContextBlock  specific;
                     32:     GenericContextBlock       generic;
                     33:   } context;
                     34: }
                     35: BackgroundImageCallbackBlock, *BackgroundImageCallbackPtr;
                     36: 
                     37: #include "AHTURLTools_f.h"
                     38: #include "HTMLpresentation_f.h"
                     39: #include "HTMLimage_f.h"
                     40: #include "UIcss_f.h"
                     41: #include "css_f.h"
1.24      cvs        42: #include "fetchHTMLname_f.h"
1.91      cvs        43: #include "fetchXMLname_f.h"
1.1       cvs        44: #include "html2thot_f.h"
1.91      cvs        45: #include "init_f.h"
1.1       cvs        46: #include "styleparser_f.h"
                     47: 
                     48: #define MAX_BUFFER_LENGTH 200
                     49: /*
                     50:  * A PropertyParser is a function used to parse  the
                     51:  * description substring associated to a given style attribute
1.59      cvs        52:  * e.g.: "red" for a color attribute or "12pt bold helvetica"
1.1       cvs        53:  * for a font attribute.
                     54:  */
1.79      cvs        55: typedef char *(*PropertyParser) (Element element,
1.56      cvs        56:                                   PSchema tsch,
                     57:                                   PresentationContext context,
1.79      cvs        58:                                   char *cssRule,
1.56      cvs        59:                                   CSSInfoPtr css,
                     60:                                   ThotBool isHTML);
1.1       cvs        61: 
                     62: /* Description of the set of CSS properties supported */
                     63: typedef struct CSSProperty
                     64:   {
1.79      cvs        65:      char                *name;
1.25      cvs        66:      PropertyParser       parsing_function;
1.1       cvs        67:   }
                     68: CSSProperty;
                     69: 
                     70: struct unit_def
                     71: {
1.79      cvs        72:    char               *sign;
1.1       cvs        73:    unsigned int        unit;
                     74: };
                     75: 
                     76: static struct unit_def CSSUnitNames[] =
                     77: {
1.82      cvs        78:    {"pt", STYLE_UNIT_PT},
                     79:    {"pc", STYLE_UNIT_PC},
                     80:    {"in", STYLE_UNIT_IN},
                     81:    {"cm", STYLE_UNIT_CM},
                     82:    {"mm", STYLE_UNIT_MM},
                     83:    {"em", STYLE_UNIT_EM},
                     84:    {"px", STYLE_UNIT_PX},
                     85:    {"ex", STYLE_UNIT_XHEIGHT},
                     86:    {"%", STYLE_UNIT_PERCENT}
1.1       cvs        87: };
                     88: 
                     89: #define NB_UNITS (sizeof(CSSUnitNames) / sizeof(struct unit_def))
1.86      cvs        90: static char         *DocURL = NULL; /* The parsed CSS file */
                     91: static Document      ParsedDoc; /* The document to which CSS are to be applied */
                     92: static int           LineNumber = -1; /* The line where the error occurs */
1.93      vatton     93: static int           NewLineSkipped = 0;
1.116     vatton     94: static ThotBool      DoApply = TRUE;
1.1       cvs        95: 
                     96: /*----------------------------------------------------------------------
                     97:    SkipWord:                                                  
                     98:   ----------------------------------------------------------------------*/
1.79      cvs        99: static char *SkipWord (char *ptr)
1.1       cvs       100: {
1.168     vatton    101:   while (isalnum((int)*ptr) || *ptr == '-' || *ptr == '#' || *ptr == '%')
                    102:     ptr++;
1.1       cvs       103:   return (ptr);
                    104: }
                    105: 
                    106: /*----------------------------------------------------------------------
1.13      cvs       107:    SkipBlanksAndComments:                                                  
                    108:   ----------------------------------------------------------------------*/
1.82      cvs       109: char *SkipBlanksAndComments (char *ptr)
1.13      cvs       110: {
1.93      vatton    111:   /* skip spaces */
1.155     cheyroul  112:   while (*ptr == SPACE ||
                    113:         *ptr == BSPACE ||
                    114:         *ptr == EOL ||
                    115:         *ptr == TAB ||
                    116:         *ptr == __CR__)
1.93      vatton    117:     {
                    118:       if (*ptr == EOL)
                    119:        /* increment the number of newline skipped */
                    120:        NewLineSkipped++;
                    121:       ptr++;
                    122:     }
1.155     cheyroul  123:   while (ptr[0] == '/' &&
                    124:         ptr[1] == '*')
1.13      cvs       125:     {
                    126:       /* look for the end of the comment */
                    127:       ptr = &ptr[2];
                    128:       while (ptr[0] != EOS && (ptr[0] != '*' || ptr[1] != '/'))
                    129:        ptr++;
                    130:       if (ptr[0] != EOS)
                    131:        ptr = &ptr[2];
1.93      vatton    132:       /* skip spaces */
                    133:       while (*ptr == SPACE || *ptr == BSPACE || *ptr == EOL ||
                    134:             *ptr == TAB || *ptr == __CR__)
                    135:        {
                    136:          if (*ptr == EOL)
                    137:            /* increment the number of newline skipped */
                    138:            NewLineSkipped++;
                    139:          ptr++;
                    140:        }
1.13      cvs       141:     }
                    142:   return (ptr);
                    143: }
                    144: 
1.49      cvs       145: /*----------------------------------------------------------------------
1.161     quint     146:    SkipQuotedString
1.1       cvs       147:   ----------------------------------------------------------------------*/
1.79      cvs       148: static char *SkipQuotedString (char *ptr, char quote)
1.1       cvs       149: {
1.14      cvs       150:   ThotBool     stop;
1.1       cvs       151: 
                    152:   stop = FALSE;
                    153:   while (!stop)
                    154:     {
                    155:     if (*ptr == quote)
                    156:        {
                    157:        ptr++;
                    158:        stop = TRUE;
                    159:        }
1.82      cvs       160:     else if (*ptr == EOS)
1.1       cvs       161:        stop = TRUE;
1.82      cvs       162:     else if (*ptr == '\\')
1.1       cvs       163:        /* escape character */
                    164:        {
                    165:        ptr++;
1.82      cvs       166:        if ((*ptr >= '0' && *ptr <= '9') || (*ptr >= 'A' && *ptr <= 'F') ||
                    167:           (*ptr >= 'a' && *ptr <= 'f'))
1.1       cvs       168:          {
                    169:          ptr++;
1.82      cvs       170:           if ((*ptr >= '0' && *ptr <= '9') || (*ptr >= 'A' && *ptr <= 'F') ||
                    171:              (*ptr >= 'a' && *ptr <= 'f'))
1.1       cvs       172:             ptr++;
                    173:          }
                    174:        else
                    175:          ptr++;
                    176:        }
                    177:     else
                    178:        ptr++;
                    179:     }
                    180:   return (ptr);
                    181: }
                    182: 
                    183: /*----------------------------------------------------------------------
1.168     vatton    184:    CSSPrintError
1.86      cvs       185:    print the error message msg on stderr.
                    186:    When the line is 0 ask to expat the current line number
                    187:   ----------------------------------------------------------------------*/
1.168     vatton    188: static void CSSPrintError (char *msg, char *value)
1.86      cvs       189: {
                    190:   if (!TtaIsPrinting () && ParsedDoc > 0)
                    191:     {
                    192:       if (!ErrFile)
                    193:        {
1.90      cvs       194:          if (OpenParsingErrors (ParsedDoc) == FALSE)
1.86      cvs       195:            return;
                    196:        }
                    197: 
1.133     vatton    198:       if (DocURL)
1.86      cvs       199:        {
1.94      cvs       200:          fprintf (ErrFile, "*** Errors/warnings in %s\n", DocURL);
1.86      cvs       201:          /* set to NULL as long as the CSS file doesn't change */
                    202:          DocURL = NULL;
                    203:        }
1.89      cvs       204:       CSSErrorsFound = TRUE;
1.86      cvs       205:       if (LineNumber < 0)
1.162     quint     206:        fprintf (ErrFile, "  In Style attribute, %s \"%s\"\n", msg, value);
1.86      cvs       207:       else
1.162     quint     208:        fprintf (ErrFile, "  line %d: %s \"%s\"\n", LineNumber+NewLineSkipped,
1.93      vatton    209:                 msg, value);
1.86      cvs       210:     }
                    211: }
                    212: 
1.168     vatton    213: /*----------------------------------------------------------------------
                    214:    CSSParseError
                    215:    print the error message msg on stderr.
                    216:    When the line is 0 ask to expat the current line number
                    217:   ----------------------------------------------------------------------*/
                    218: static void CSSParseError (char *msg, char *value, char *endvalue)
                    219: {
                    220:   char        c = EOS;
                    221: 
                    222:   if (endvalue)
                    223:     {
                    224:       /* close the string here */
                    225:       c = *endvalue;
                    226:       *endvalue = EOS;
                    227:     }
                    228:   CSSPrintError (msg, value);
                    229:   if (endvalue)
                    230:     *endvalue = c;
                    231: }
                    232: 
1.89      cvs       233: 
1.86      cvs       234: /*----------------------------------------------------------------------
1.168     vatton    235:    SkipProperty skips a property and display and error message
1.86      cvs       236:   ----------------------------------------------------------------------*/
                    237: static char *SkipProperty (char *ptr)
                    238: {
                    239:   char       *deb;
                    240:   char        c;
                    241: 
                    242:   deb = ptr;
1.135     vatton    243:   while (*ptr != EOS && *ptr != ';' && *ptr != '}')
1.133     vatton    244:     {
                    245:       if (*ptr == '"' && (ptr == deb || ptr[-1] != '\\'))
                    246:        {
                    247:          /* skip to the end of the string "..." */
                    248:          ptr++;
                    249:          while (*ptr != '"' && ptr[-1] != '\\')
                    250:            ptr++;
                    251:        }
                    252:       ptr++;
                    253:     }
1.95      cvs       254:   /* print the skipped property */
1.86      cvs       255:   c = *ptr;
                    256:   *ptr = EOS;
1.95      cvs       257: #ifdef CSS_WARNING
1.86      cvs       258:   if (*deb != EOS)
1.168     vatton    259:     CSSPrintError ("CSS property ignored", deb);
1.95      cvs       260: #endif /* CSS_WARNING */
1.86      cvs       261:   *ptr = c;
                    262:   return (ptr);
                    263: }
                    264: 
                    265: /*----------------------------------------------------------------------
1.168     vatton    266:    SkipValue
                    267:    skips the value and display an error message if msg is not NULL
1.1       cvs       268:   ----------------------------------------------------------------------*/
1.168     vatton    269: static char *SkipValue (char *msg, char *ptr)
1.1       cvs       270: {
1.86      cvs       271:   char       *deb;
                    272:   char        c;
                    273: 
                    274:   deb = ptr;
1.135     vatton    275:   while (*ptr != EOS && *ptr != ';' && *ptr != '}')
1.133     vatton    276:     {
                    277:       if (*ptr == '"' && (ptr == deb || ptr[-1] != '\\'))
                    278:        {
                    279:          /* skip to the end of the string "..." */
                    280:          ptr++;
                    281:          while (*ptr != '"' && ptr[-1] != '\\')
                    282:            ptr++;
                    283:        }
                    284:       ptr++;
                    285:     }
1.95      cvs       286:   /* print the skipped property */
1.86      cvs       287:   c = *ptr;
                    288:   *ptr = EOS;
1.168     vatton    289:   if (msg && *deb != EOS && *deb != ',')
                    290:     CSSPrintError (msg, deb);
1.86      cvs       291:   *ptr = c;
1.1       cvs       292:   return (ptr);
                    293: }
                    294: 
                    295: /*----------------------------------------------------------------------
1.64      cvs       296:    ParseNumber:                                                  
                    297:    parse a number and returns the corresponding value.
1.1       cvs       298:   ----------------------------------------------------------------------*/
1.79      cvs       299: char *ParseNumber (char *cssRule, PresentationValue *pval)
1.1       cvs       300: {
                    301:   int                 val = 0;
                    302:   int                 minus = 0;
                    303:   int                 valid = 0;
                    304:   int                 f = 0;
1.14      cvs       305:   ThotBool            real = FALSE;
1.1       cvs       306: 
                    307:   pval->typed_data.unit = STYLE_UNIT_REL;
                    308:   pval->typed_data.real = FALSE;
1.82      cvs       309:   cssRule = SkipBlanksAndComments (cssRule);
                    310:   if (*cssRule == '-')
1.1       cvs       311:     {
                    312:       minus = 1;
                    313:       cssRule++;
1.82      cvs       314:       cssRule = SkipBlanksAndComments (cssRule);
1.1       cvs       315:     }
                    316: 
1.82      cvs       317:   if (*cssRule == '+')
1.1       cvs       318:     {
                    319:       cssRule++;
1.82      cvs       320:       cssRule = SkipBlanksAndComments (cssRule);
1.1       cvs       321:     }
                    322: 
1.82      cvs       323:   while ((*cssRule >= '0') && (*cssRule <= '9'))
1.1       cvs       324:     {
                    325:       val *= 10;
1.82      cvs       326:       val += *cssRule - '0';
1.1       cvs       327:       cssRule++;
                    328:       valid = 1;
                    329:     }
                    330: 
1.82      cvs       331:   if (*cssRule == '.')
1.1       cvs       332:     {
                    333:       real = TRUE;
                    334:       f = val;
                    335:       val = 0;
                    336:       cssRule++;
                    337:       /* keep only 3 digits */
1.82      cvs       338:       if (*cssRule >= '0' && *cssRule <= '9')
1.1       cvs       339:        {
1.82      cvs       340:          val = (*cssRule - '0') * 100;
1.1       cvs       341:          cssRule++;
1.82      cvs       342:          if (*cssRule >= '0' && *cssRule <= '9')
1.1       cvs       343:            {
1.82      cvs       344:              val += (*cssRule - '0') * 10;
1.1       cvs       345:              cssRule++;
1.82      cvs       346:              if ((*cssRule >= '0') && (*cssRule <= '9'))
1.1       cvs       347:                {
1.82      cvs       348:                  val += *cssRule - '0';
1.1       cvs       349:                  cssRule++;
                    350:                }
                    351:            }
                    352: 
1.82      cvs       353:          while (*cssRule >= '0' && *cssRule <= '9')
1.1       cvs       354:            cssRule++;
                    355:          valid = 1;
                    356:        }
                    357:     }
                    358: 
                    359:   if (!valid)
                    360:     {
                    361:       pval->typed_data.unit = STYLE_UNIT_INVALID;
                    362:       pval->typed_data.value = 0;
                    363:     }
                    364:   else
                    365:     {
                    366:       pval->typed_data.real = real;
                    367:       if (real)
                    368:        {
                    369:          if (minus)
                    370:            pval->typed_data.value = -(f * 1000 + val);
                    371:          else
                    372:            pval->typed_data.value = f * 1000 + val;
                    373:        }
                    374:       else
                    375:        {
                    376:          if (minus)
                    377:            pval->typed_data.value = -val;
                    378:          else
                    379:            pval->typed_data.value = val;
                    380:        }
1.64      cvs       381:     }
                    382:   return (cssRule);
                    383: }
1.155     cheyroul  384: /*----------------------------------------------------------------------
                    385:    ParseClampedUnit:                                                  
                    386:    parse a CSS Unit substring and returns the corresponding      
                    387:    value and its unit.
                    388:    [0,1]
                    389:    or
                    390:    [0,100] in %
                    391:   ----------------------------------------------------------------------*/
                    392: char *ParseClampedUnit (char *text,
                    393:                        PresentationValue *pval)
                    394: {
1.170     cheyroul  395:   float                clamped_value;
                    396:   int                  int_clamped_value;
1.155     cheyroul  397: 
                    398:   if (*(text + strlen (text) -1) == '%')
                    399:        {
1.170     cheyroul  400:          int_clamped_value = atoi (text);
                    401:          if (int_clamped_value < 0 ||
                    402:              int_clamped_value > 100)
                    403:            int_clamped_value = 1000;
1.155     cheyroul  404:          else
1.170     cheyroul  405:            int_clamped_value = int_clamped_value * 10;
1.155     cheyroul  406:        }
                    407:       else
                    408:        {
1.170     cheyroul  409:          clamped_value = (float) atof (text);
                    410:          if (clamped_value < 0.0
                    411:              || clamped_value > 1.0)
                    412:            int_clamped_value = 1000;
1.155     cheyroul  413:          else 
1.170     cheyroul  414:            int_clamped_value = (int) (clamped_value * 1000);
1.155     cheyroul  415:        }
                    416:       pval->typed_data.unit = STYLE_UNIT_REL;
1.170     cheyroul  417:       pval->typed_data.value = int_clamped_value;
                    418:       pval->typed_data.real = 0;
                    419:       pval->data = int_clamped_value;   
1.155     cheyroul  420:   return (SkipWord (text));
                    421: }
1.64      cvs       422: 
                    423: /*----------------------------------------------------------------------
                    424:    ParseCSSUnit:                                                  
                    425:    parse a CSS Unit substring and returns the corresponding      
                    426:    value and its unit.                                           
                    427:   ----------------------------------------------------------------------*/
1.82      cvs       428: char *ParseCSSUnit (char *cssRule, PresentationValue *pval)
1.64      cvs       429: {
                    430:   unsigned int        uni;
                    431: 
                    432:   pval->typed_data.unit = STYLE_UNIT_REL;
                    433:   cssRule = ParseNumber (cssRule, pval);
                    434:   if (pval->typed_data.unit == STYLE_UNIT_INVALID)
                    435:       cssRule = SkipWord (cssRule);
                    436:   else
                    437:     {
1.82      cvs       438:       cssRule = SkipBlanksAndComments (cssRule);
1.64      cvs       439:       for (uni = 0; uni < NB_UNITS; uni++)
                    440:        {
1.82      cvs       441:          if (!strncasecmp (CSSUnitNames[uni].sign, cssRule,
                    442:                             strlen (CSSUnitNames[uni].sign)))
1.64      cvs       443:            {
                    444:              pval->typed_data.unit = CSSUnitNames[uni].unit;
1.82      cvs       445:              return (cssRule + strlen (CSSUnitNames[uni].sign));
1.64      cvs       446:            }
                    447:        }
                    448:       /* not in the list of predefined units */
1.166     vatton    449:       pval->typed_data.unit = STYLE_UNIT_BOX;
1.1       cvs       450:     }
                    451:   return (cssRule);
                    452: }
                    453: 
1.43      cvs       454: /*----------------------------------------------------------------------
                    455:    ParseBorderValue                                       
                    456:   ----------------------------------------------------------------------*/
1.79      cvs       457: static char *ParseBorderValue (char *cssRule, PresentationValue *border)
1.43      cvs       458: {
1.168     vatton    459:   char             *ptr;
                    460: 
1.43      cvs       461:   /* first parse the attribute string */
                    462:    border->typed_data.value = 0;
1.44      cvs       463:    border->typed_data.unit = STYLE_UNIT_INVALID;
1.43      cvs       464:    border->typed_data.real = FALSE;
1.82      cvs       465:    if (!strncasecmp (cssRule, "thin", 4))
1.43      cvs       466:      {
1.44      cvs       467:        border->typed_data.unit = STYLE_UNIT_PX;
1.43      cvs       468:        border->typed_data.value = 1;
                    469:        cssRule = SkipWord (cssRule);
                    470:      }
1.82      cvs       471:    else if (!strncasecmp (cssRule, "medium", 6))
1.43      cvs       472:      {
1.44      cvs       473:        border->typed_data.unit = STYLE_UNIT_PX;
1.43      cvs       474:        border->typed_data.value = 3;
                    475:        cssRule = SkipWord (cssRule);
                    476:      }
1.82      cvs       477:    else if (!strncasecmp (cssRule, "thick", 5))
1.43      cvs       478:      {
1.44      cvs       479:        border->typed_data.unit = STYLE_UNIT_PX;
1.43      cvs       480:        border->typed_data.value = 5;
                    481:        cssRule = SkipWord (cssRule);
                    482:      }
1.110     vatton    483:    else if (isdigit (*cssRule) || *cssRule == '.')
1.166     vatton    484:      {
1.168     vatton    485:        ptr = cssRule;
1.166     vatton    486:        cssRule = ParseCSSUnit (cssRule, border);
1.168     vatton    487:        if (border->typed_data.value == 0)
                    488:         border->typed_data.unit = STYLE_UNIT_PX;
                    489:        else if (border->typed_data.unit == STYLE_UNIT_INVALID ||
                    490:                border->typed_data.unit == STYLE_UNIT_BOX)
                    491:         {
                    492:           border->typed_data.unit = STYLE_UNIT_INVALID;
                    493:           border->typed_data.value = 0;
                    494:           CSSParseError ("Invalid border-width value", ptr, cssRule);
                    495:         }
1.166     vatton    496:      }
1.43      cvs       497:    return (cssRule);
                    498: }
                    499: 
                    500: /*----------------------------------------------------------------------
                    501:    ParseBorderStyle                                      
                    502:   ----------------------------------------------------------------------*/
1.79      cvs       503: static char *ParseBorderStyle (char *cssRule, PresentationValue *border)
1.43      cvs       504: {
                    505:   /* first parse the attribute string */
                    506:    border->typed_data.value = 0;
                    507:    border->typed_data.unit = STYLE_UNIT_PX;
                    508:    border->typed_data.real = FALSE;
1.82      cvs       509:    if (!strncasecmp (cssRule, "none", 4))
1.43      cvs       510:      border->typed_data.value = STYLE_BORDERNONE;
1.82      cvs       511:    else if (!strncasecmp (cssRule, "hidden", 6))
1.43      cvs       512:      border->typed_data.value = STYLE_BORDERHIDDEN;
1.82      cvs       513:    else if (!strncasecmp (cssRule, "dotted", 6))
1.43      cvs       514:      border->typed_data.value = STYLE_BORDERDOTTED;
1.82      cvs       515:    else if (!strncasecmp (cssRule, "dashed", 6))
1.43      cvs       516:      border->typed_data.value = STYLE_BORDERDASHED;
1.82      cvs       517:    else if (!strncasecmp (cssRule, "solid", 5))
1.43      cvs       518:      border->typed_data.value = STYLE_BORDERSOLID;
1.82      cvs       519:    else if (!strncasecmp (cssRule, "double", 6))
1.43      cvs       520:      border->typed_data.value = STYLE_BORDERDOUBLE;
1.82      cvs       521:    else if (!strncasecmp (cssRule, "groove", 6))
1.43      cvs       522:      border->typed_data.value = STYLE_BORDERGROOVE;
1.82      cvs       523:    else if (!strncasecmp (cssRule, "ridge", 5))
1.43      cvs       524:      border->typed_data.value = STYLE_BORDERRIDGE;
1.82      cvs       525:    else if (!strncasecmp (cssRule, "inset", 5))
1.43      cvs       526:      border->typed_data.value = STYLE_BORDERINSET;
1.82      cvs       527:    else if (!strncasecmp (cssRule, "outset", 6))
1.43      cvs       528:      border->typed_data.value = STYLE_BORDEROUTSET;
                    529:    else
1.44      cvs       530:      {
                    531:        /* invalid style */
                    532:        border->typed_data.unit = STYLE_UNIT_INVALID;
                    533:        return (cssRule);
                    534:      }
1.43      cvs       535:    /* the value is parsed now */
                    536:    cssRule = SkipWord (cssRule);
                    537:    return (cssRule);
                    538: }
                    539: 
                    540: /*----------------------------------------------------------------------
1.59      cvs       541:    ParseCSSColor: parse a CSS color attribute string    
1.43      cvs       542:    we expect the input string describing the attribute to be     
                    543:    either a color name, a 3 tuple or an hexadecimal encoding.    
                    544:    The color used will be approximed from the current color      
                    545:    table                                                         
                    546:   ----------------------------------------------------------------------*/
1.79      cvs       547: static char *ParseCSSColor (char *cssRule, PresentationValue * val)
1.43      cvs       548: {
1.79      cvs       549:   char               *ptr;
1.43      cvs       550:   unsigned short      redval = (unsigned short) -1;
                    551:   unsigned short      greenval = 0;    /* composant of each RGB       */
                    552:   unsigned short      blueval = 0;     /* default to red if unknown ! */
                    553:   int                 best = 0;        /* best color in list found */
                    554: 
1.82      cvs       555:   cssRule = SkipBlanksAndComments (cssRule);
1.43      cvs       556:   val->typed_data.unit = STYLE_UNIT_INVALID;
                    557:   val->typed_data.real = FALSE;
                    558:   val->typed_data.value = 0;
1.57      cvs       559:   ptr = TtaGiveRGB (cssRule, &redval, &greenval, &blueval);
1.135     vatton    560:   if (!strncasecmp (cssRule, "inherit", 7))
                    561:     {
                    562:       cssRule = SkipWord (cssRule);
                    563:       return (cssRule);
                    564:     }
1.57      cvs       565:   if (ptr == cssRule)
1.43      cvs       566:     {
1.168     vatton    567:       cssRule = SkipWord (cssRule);
                    568:       CSSParseError ("Invalid color value", ptr, cssRule);
1.43      cvs       569:       val->typed_data.value = 0;
                    570:       val->typed_data.unit = STYLE_UNIT_INVALID;
                    571:     }
                    572:   else
                    573:     {
                    574:       best = TtaGetThotColor (redval, greenval, blueval);
                    575:       val->typed_data.value = best;
                    576:       val->typed_data.unit = STYLE_UNIT_REL;
1.57      cvs       577:       cssRule = ptr;
1.43      cvs       578:     }
                    579:   val->typed_data.real = FALSE;
1.65      cvs       580:   return (cssRule);
1.43      cvs       581: }
1.1       cvs       582: 
                    583: /*----------------------------------------------------------------------
1.117     vatton    584:   CheckImportantRule updates the field important of the context.
                    585:   ----------------------------------------------------------------------*/
                    586: static char *CheckImportantRule (char *cssRule, PresentationContext context)
                    587: {
                    588:   cssRule = SkipBlanksAndComments (cssRule);
1.120     vatton    589:   if (*cssRule != '!')
                    590:     context->important = FALSE;
                    591:   else
1.117     vatton    592:     {
1.120     vatton    593:       cssRule++;
                    594:       cssRule = SkipBlanksAndComments (cssRule);
                    595:       if (!strncasecmp (cssRule, "important", 9))
                    596:        {
                    597:          context->important = TRUE;
                    598:          cssRule += 9;
                    599:        }
                    600:       else
                    601:        context->important = FALSE;
1.117     vatton    602:     }
                    603:   return (cssRule);
                    604: }
                    605: 
                    606: /*----------------------------------------------------------------------
1.59      cvs       607:    ParseCSSBorderTopWidth: parse a CSS BorderTopWidth
1.1       cvs       608:    attribute string.                                          
                    609:   ----------------------------------------------------------------------*/
1.79      cvs       610: static char *ParseCSSBorderTopWidth (Element element, PSchema tsch,
                    611:                                       PresentationContext context, 
                    612:                                       char *cssRule, CSSInfoPtr css,
                    613:                                       ThotBool isHTML)
1.1       cvs       614: {
1.41      cvs       615:   PresentationValue   border;
                    616:   
1.82      cvs       617:   cssRule = SkipBlanksAndComments (cssRule);
1.43      cvs       618:   cssRule = ParseBorderValue (cssRule, &border);
1.116     vatton    619:   if (border.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.44      cvs       620:     {
1.117     vatton    621:       /* check if it's an important rule */
                    622:       if (tsch)
                    623:        cssRule = CheckImportantRule (cssRule, context);
1.44      cvs       624:       TtaSetStylePresentation (PRBorderTopWidth, element, tsch, context, border);
                    625:       border.typed_data.value = 1;
                    626:       border.typed_data.unit = STYLE_UNIT_REL;
                    627:     }
1.1       cvs       628:   return (cssRule);
                    629: }
                    630: 
                    631: /*----------------------------------------------------------------------
1.59      cvs       632:    ParseCSSBorderBottomWidth: parse a CSS BorderBottomWidth
1.1       cvs       633:    attribute string.                                          
                    634:   ----------------------------------------------------------------------*/
1.79      cvs       635: static char *ParseCSSBorderBottomWidth (Element element, PSchema tsch,
                    636:                                          PresentationContext context,
                    637:                                          char *cssRule, CSSInfoPtr css,
                    638:                                          ThotBool isHTML)
1.1       cvs       639: {
1.41      cvs       640:   PresentationValue   border;
                    641:   
1.82      cvs       642:   cssRule = SkipBlanksAndComments (cssRule);
1.41      cvs       643:   /* first parse the attribute string */
1.43      cvs       644:   cssRule = ParseBorderValue (cssRule, &border);
1.116     vatton    645:   if (border.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.44      cvs       646:     {
1.117     vatton    647:       /* check if it's an important rule */
                    648:       if (tsch)
                    649:        cssRule = CheckImportantRule (cssRule, context);
1.44      cvs       650:       TtaSetStylePresentation (PRBorderBottomWidth, element, tsch, context, border);
                    651:       border.typed_data.value = 1;
                    652:       border.typed_data.unit = STYLE_UNIT_REL;
                    653:     }
1.1       cvs       654:   return (cssRule);
                    655: }
                    656: 
                    657: /*----------------------------------------------------------------------
1.59      cvs       658:    ParseCSSBorderLeftWidth: parse a CSS BorderLeftWidth
1.1       cvs       659:    attribute string.                                          
                    660:   ----------------------------------------------------------------------*/
1.79      cvs       661: static char *ParseCSSBorderLeftWidth (Element element, PSchema tsch,
                    662:                                        PresentationContext context,
                    663:                                        char *cssRule, CSSInfoPtr css,
                    664:                                        ThotBool isHTML)
1.1       cvs       665: {
1.41      cvs       666:   PresentationValue   border;
                    667:   
1.82      cvs       668:   cssRule = SkipBlanksAndComments (cssRule);
1.41      cvs       669:   /* first parse the attribute string */
1.43      cvs       670:   cssRule = ParseBorderValue (cssRule, &border);
1.116     vatton    671:   if (border.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.44      cvs       672:     {
1.117     vatton    673:       /* check if it's an important rule */
                    674:       if (tsch)
                    675:        cssRule = CheckImportantRule (cssRule, context);
1.44      cvs       676:       TtaSetStylePresentation (PRBorderLeftWidth, element, tsch, context, border);
                    677:       border.typed_data.value = 1;
                    678:       border.typed_data.unit = STYLE_UNIT_REL;
                    679:     }
1.1       cvs       680:   return (cssRule);
                    681: }
                    682: 
                    683: /*----------------------------------------------------------------------
1.59      cvs       684:    ParseCSSBorderRightWidth: parse a CSS BorderRightWidth
1.1       cvs       685:    attribute string.                                          
                    686:   ----------------------------------------------------------------------*/
1.79      cvs       687: static char *ParseCSSBorderRightWidth (Element element, PSchema tsch,
                    688:                                         PresentationContext context,
                    689:                                         char *cssRule, CSSInfoPtr css,
                    690:                                         ThotBool isHTML)
1.1       cvs       691: {
1.41      cvs       692:   PresentationValue   border;
                    693:   
1.82      cvs       694:   cssRule = SkipBlanksAndComments (cssRule);
1.41      cvs       695:   /* first parse the attribute string */
1.43      cvs       696:   cssRule = ParseBorderValue (cssRule, &border);
1.116     vatton    697:   if (border.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.44      cvs       698:     {
1.117     vatton    699:       /* check if it's an important rule */
                    700:       if (tsch)
                    701:        cssRule = CheckImportantRule (cssRule, context);
1.44      cvs       702:       TtaSetStylePresentation (PRBorderRightWidth, element, tsch, context, border);
                    703:       border.typed_data.value = 1;
                    704:       border.typed_data.unit = STYLE_UNIT_REL;
                    705:     }
1.1       cvs       706:   return (cssRule);
                    707: }
                    708: 
                    709: /*----------------------------------------------------------------------
1.59      cvs       710:    ParseCSSBorderWidth: parse a CSS BorderWidth
1.1       cvs       711:    attribute string.                                          
                    712:   ----------------------------------------------------------------------*/
1.79      cvs       713: static char *ParseCSSBorderWidth (Element element, PSchema tsch,
                    714:                                    PresentationContext context,
                    715:                                    char *cssRule, CSSInfoPtr css,
                    716:                                    ThotBool isHTML)
1.1       cvs       717: {
1.79      cvs       718:   char *ptrT, *ptrR, *ptrB, *ptrL;
1.93      vatton    719:   int   skippedNL;
1.41      cvs       720: 
1.82      cvs       721:   ptrT = SkipBlanksAndComments (cssRule);
1.42      cvs       722:   /* First parse Border-Top */
                    723:   ptrR = ParseCSSBorderTopWidth (element, tsch, context, ptrT, css, isHTML);
1.82      cvs       724:   ptrR = SkipBlanksAndComments (ptrR);
                    725:   if (*ptrR == ';' || *ptrR == EOS || *ptrR == ',')
1.42      cvs       726:     {
1.93      vatton    727:       skippedNL = NewLineSkipped;
1.42      cvs       728:       cssRule = ptrR;
                    729:       /* apply the Border-Top to all */
                    730:       ptrR = ParseCSSBorderRightWidth (element, tsch, context, ptrT, css, isHTML);
1.93      vatton    731:       NewLineSkipped = skippedNL;
1.42      cvs       732:       ptrR = ParseCSSBorderBottomWidth (element, tsch, context, ptrT, css, isHTML);
1.93      vatton    733:       NewLineSkipped = skippedNL;
1.42      cvs       734:       ptrR = ParseCSSBorderLeftWidth (element, tsch, context, ptrT, css, isHTML);
                    735:     }
                    736:   else
                    737:     {
                    738:       /* parse Border-Right */
                    739:       ptrB = ParseCSSBorderRightWidth (element, tsch, context, ptrR, css, isHTML);
1.82      cvs       740:       ptrB = SkipBlanksAndComments (ptrB);
                    741:       if (*ptrB == ';' || *ptrB == EOS || *ptrB == ',')
1.42      cvs       742:        {
1.93      vatton    743:          skippedNL = NewLineSkipped;
1.42      cvs       744:          cssRule = ptrB;
                    745:          /* apply the Border-Top to Border-Bottom */
                    746:          ptrB = ParseCSSBorderBottomWidth (element, tsch, context, ptrT, css, isHTML);
1.93      vatton    747:          NewLineSkipped = skippedNL;
1.42      cvs       748:          /* apply the Border-Right to Border-Left */
                    749:          ptrB = ParseCSSBorderLeftWidth (element, tsch, context, ptrR, css, isHTML);
                    750:        }
                    751:       else
                    752:        {
                    753:          /* parse Border-Bottom */
                    754:          ptrL = ParseCSSBorderBottomWidth (element, tsch, context, ptrB, css, isHTML);
1.82      cvs       755:          ptrL = SkipBlanksAndComments (ptrL);
                    756:          if (*ptrL == ';' || *ptrL == EOS || *ptrL == ',')
1.42      cvs       757:            {
                    758:              cssRule = ptrL;
                    759:              /* apply the Border-Right to Border-Left */
                    760:              ptrL = ParseCSSBorderLeftWidth (element, tsch, context, ptrR, css, isHTML);
                    761:            }
                    762:          else
                    763:            /* parse Border-Left */
                    764:            cssRule = ParseCSSBorderLeftWidth (element, tsch, context, ptrL, css, isHTML);
1.82      cvs       765:          cssRule = SkipBlanksAndComments (cssRule);
1.42      cvs       766:        }
                    767:     }
1.1       cvs       768:   return (cssRule);
                    769: }
                    770: 
                    771: /*----------------------------------------------------------------------
1.59      cvs       772:    ParseCSSBorderColorTop: parse a CSS BorderColorTop
1.1       cvs       773:    attribute string.                                          
                    774:   ----------------------------------------------------------------------*/
1.79      cvs       775: static char *ParseCSSBorderColorTop (Element element, PSchema tsch,
                    776:                                     PresentationContext context,
                    777:                                     char *cssRule, CSSInfoPtr css,
                    778:                                     ThotBool isHTML)
1.1       cvs       779: {
1.117     vatton    780:   PresentationValue   best;
1.43      cvs       781: 
1.117     vatton    782:   cssRule = ParseCSSColor (cssRule, &best);
                    783:   if (best.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
                    784:     {
                    785:       /* check if it's an important rule */
                    786:       if (tsch)
                    787:        cssRule = CheckImportantRule (cssRule, context);
                    788:       /* install the new presentation */
                    789:       TtaSetStylePresentation (PRBorderTopColor, element, tsch, context, best);
                    790:     }
                    791:   return (cssRule);
1.1       cvs       792: }
                    793: 
                    794: /*----------------------------------------------------------------------
1.59      cvs       795:    ParseCSSBorderColorLeft: parse a CSS BorderColorLeft
1.42      cvs       796:    attribute string.                                          
                    797:   ----------------------------------------------------------------------*/
1.79      cvs       798: static char *ParseCSSBorderColorLeft (Element element, PSchema tsch,
                    799:                                      PresentationContext context,
                    800:                                      char *cssRule, CSSInfoPtr css,
                    801:                                      ThotBool isHTML)
1.42      cvs       802: {
1.117     vatton    803:   PresentationValue   best;
                    804:   
                    805:   cssRule = ParseCSSColor (cssRule, &best);
                    806:   if (best.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
                    807:     {
                    808:       /* check if it's an important rule */
                    809:       if (tsch)
                    810:        cssRule = CheckImportantRule (cssRule, context);
                    811:       /* install the new presentation */
                    812:       TtaSetStylePresentation (PRBorderLeftColor, element, tsch, context, best);
                    813:     }
                    814:   return (cssRule);
1.42      cvs       815: }
                    816: 
                    817: /*----------------------------------------------------------------------
1.59      cvs       818:    ParseCSSBorderColorBottom: parse a CSS BorderColorBottom
1.42      cvs       819:    attribute string.                                          
                    820:   ----------------------------------------------------------------------*/
1.79      cvs       821: static char *ParseCSSBorderColorBottom (Element element, PSchema tsch,
                    822:                                        PresentationContext context,
                    823:                                        char *cssRule, CSSInfoPtr css,
                    824:                                        ThotBool isHTML)
1.42      cvs       825: {
1.117     vatton    826:   PresentationValue   best;
1.43      cvs       827: 
1.117     vatton    828:   cssRule = ParseCSSColor (cssRule, &best);
                    829:   if (best.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
                    830:     {
                    831:       /* check if it's an important rule */
                    832:       if (tsch)
                    833:        cssRule = CheckImportantRule (cssRule, context);
                    834:       /* install the new presentation */
                    835:       TtaSetStylePresentation (PRBorderBottomColor, element, tsch, context, best);
                    836:     }
1.65      cvs       837:    return (cssRule);
1.42      cvs       838: }
                    839: 
                    840: /*----------------------------------------------------------------------
1.59      cvs       841:    ParseCSSBorderColorRight: parse a CSS BorderColorRight
1.1       cvs       842:    attribute string.                                          
                    843:   ----------------------------------------------------------------------*/
1.79      cvs       844: static char *ParseCSSBorderColorRight (Element element, PSchema tsch,
                    845:                                       PresentationContext context,
                    846:                                       char *cssRule, CSSInfoPtr css,
                    847:                                       ThotBool isHTML)
1.1       cvs       848: {
1.117     vatton    849:   PresentationValue   best;
1.43      cvs       850: 
1.117     vatton    851:   cssRule = ParseCSSColor (cssRule, &best);
                    852:   if (best.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
                    853:     {
                    854:       /* check if it's an important rule */
                    855:       if (tsch)
                    856:        cssRule = CheckImportantRule (cssRule, context);
                    857:       /* install the new presentation */
                    858:       TtaSetStylePresentation (PRBorderRightColor, element, tsch, context, best);
                    859:     }
                    860:   return (cssRule);
1.1       cvs       861: }
                    862: 
                    863: /*----------------------------------------------------------------------
1.59      cvs       864:    ParseCSSBorderColor: parse a CSS border-color        
1.42      cvs       865:    attribute string.                                          
                    866:   ----------------------------------------------------------------------*/
1.79      cvs       867: static char *ParseCSSBorderColor (Element element, PSchema tsch,
                    868:                                  PresentationContext context,
                    869:                                  char *cssRule, CSSInfoPtr css,
                    870:                                  ThotBool isHTML)
1.42      cvs       871: {
1.79      cvs       872:   char *ptrT, *ptrR, *ptrB, *ptrL;
1.93      vatton    873:   int   skippedNL;
1.42      cvs       874: 
1.82      cvs       875:   ptrT = SkipBlanksAndComments (cssRule);
1.42      cvs       876:   /* First parse Border-Top */
1.43      cvs       877:   ptrR = ParseCSSBorderColorTop (element, tsch, context, ptrT, css, isHTML);
1.82      cvs       878:   ptrR = SkipBlanksAndComments (ptrR);
                    879:   if (*ptrR == ';' || *ptrR == EOS || *ptrR == ',')
1.42      cvs       880:     {
1.93      vatton    881:       skippedNL = NewLineSkipped;
1.42      cvs       882:       cssRule = ptrR;
                    883:       /* apply the Border-Top to all */
1.43      cvs       884:       ptrR = ParseCSSBorderColorRight (element, tsch, context, ptrT, css, isHTML);
1.93      vatton    885:          NewLineSkipped = skippedNL;
1.43      cvs       886:       ptrR = ParseCSSBorderColorBottom (element, tsch, context, ptrT, css, isHTML);
1.93      vatton    887:          NewLineSkipped = skippedNL;
1.43      cvs       888:       ptrR = ParseCSSBorderColorLeft (element, tsch, context, ptrT, css, isHTML);
1.42      cvs       889:     }
                    890:   else
                    891:     {
                    892:       /* parse Border-Right */
1.43      cvs       893:       ptrB = ParseCSSBorderColorRight (element, tsch, context, ptrR, css, isHTML);
1.82      cvs       894:       ptrB = SkipBlanksAndComments (ptrB);
                    895:       if (*ptrB == ';' || *ptrB == EOS || *ptrB == ',')
1.42      cvs       896:        {
1.93      vatton    897:          skippedNL = NewLineSkipped;
1.42      cvs       898:          cssRule = ptrB;
                    899:          /* apply the Border-Top to Border-Bottom */
1.43      cvs       900:          ptrB = ParseCSSBorderColorBottom (element, tsch, context, ptrT, css, isHTML);
1.93      vatton    901:          NewLineSkipped = skippedNL;
1.42      cvs       902:          /* apply the Border-Right to Border-Left */
1.43      cvs       903:          ptrB = ParseCSSBorderColorLeft (element, tsch, context, ptrR, css, isHTML);
1.42      cvs       904:        }
                    905:       else
                    906:        {
1.93      vatton    907:          skippedNL = NewLineSkipped;
1.42      cvs       908:          /* parse Border-Bottom */
1.43      cvs       909:          ptrL = ParseCSSBorderColorBottom (element, tsch, context, ptrB, css, isHTML);
1.93      vatton    910:          NewLineSkipped = skippedNL;
1.82      cvs       911:          ptrL = SkipBlanksAndComments (ptrL);
                    912:          if (*ptrL == ';' || *ptrL == EOS || *ptrL == ',')
1.42      cvs       913:            {
                    914:              cssRule = ptrL;
                    915:              /* apply the Border-Right to Border-Left */
1.43      cvs       916:              ptrL = ParseCSSBorderColorLeft (element, tsch, context, ptrR, css, isHTML);
1.42      cvs       917:            }
                    918:          else
                    919:            /* parse Border-Left */
1.43      cvs       920:            cssRule = ParseCSSBorderColorLeft (element, tsch, context, ptrL, css, isHTML);
1.82      cvs       921:          cssRule = SkipBlanksAndComments (cssRule);
1.42      cvs       922:        }
                    923:     }
                    924:   return (cssRule);
                    925: }
                    926: 
                    927: /*----------------------------------------------------------------------
1.59      cvs       928:    ParseCSSBorderStyleTop: parse a CSS BorderStyleTop
1.42      cvs       929:    attribute string.                                          
                    930:   ----------------------------------------------------------------------*/
1.79      cvs       931: static char *ParseCSSBorderStyleTop (Element element, PSchema tsch,
                    932:                                     PresentationContext context,
                    933:                                     char *cssRule, CSSInfoPtr css,
                    934:                                     ThotBool isHTML)
1.42      cvs       935: {
1.43      cvs       936:   PresentationValue   border;
                    937:   
1.82      cvs       938:   cssRule = SkipBlanksAndComments (cssRule);
1.43      cvs       939:   cssRule = ParseBorderStyle (cssRule, &border);
1.116     vatton    940:   if (border.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.117     vatton    941:     {
                    942:       /* check if it's an important rule */
                    943:       if (tsch)
                    944:        cssRule = CheckImportantRule (cssRule, context);
                    945:       TtaSetStylePresentation (PRBorderTopStyle, element, tsch, context, border);
                    946:     }
1.42      cvs       947:   return (cssRule);
                    948: }
                    949: 
                    950: /*----------------------------------------------------------------------
1.59      cvs       951:    ParseCSSBorderStyleLeft: parse a CSS BorderStyleLeft
1.42      cvs       952:    attribute string.                                          
                    953:   ----------------------------------------------------------------------*/
1.79      cvs       954: static char *ParseCSSBorderStyleLeft (Element element, PSchema tsch,
                    955:                                      PresentationContext context,
                    956:                                      char *cssRule, CSSInfoPtr css,
                    957:                                      ThotBool isHTML)
1.42      cvs       958: {
1.43      cvs       959:   PresentationValue   border;
                    960:   
1.82      cvs       961:   cssRule = SkipBlanksAndComments (cssRule);
1.43      cvs       962:   cssRule = ParseBorderStyle (cssRule, &border);
1.116     vatton    963:   if (border.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.117     vatton    964:     {
                    965:       /* check if it's an important rule */
                    966:       if (tsch)
                    967:        cssRule = CheckImportantRule (cssRule, context);
                    968:       TtaSetStylePresentation (PRBorderLeftStyle, element, tsch, context, border);
                    969:     }
1.42      cvs       970:   return (cssRule);
                    971: }
                    972: 
                    973: /*----------------------------------------------------------------------
1.59      cvs       974:    ParseCSSBorderStyleBottom: parse a CSS BorderStyleBottom
1.1       cvs       975:    attribute string.                                          
                    976:   ----------------------------------------------------------------------*/
1.79      cvs       977: static char *ParseCSSBorderStyleBottom (Element element, PSchema tsch,
                    978:                                        PresentationContext context,
                    979:                                        char *cssRule, CSSInfoPtr css,
                    980:                                        ThotBool isHTML)
1.1       cvs       981: {
1.43      cvs       982:   PresentationValue   border;
                    983:   
1.82      cvs       984:   cssRule = SkipBlanksAndComments (cssRule);
1.43      cvs       985:   cssRule = ParseBorderStyle (cssRule, &border);
1.116     vatton    986:   if (border.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.117     vatton    987:     {
                    988:       /* check if it's an important rule */
                    989:       if (tsch)
                    990:        cssRule = CheckImportantRule (cssRule, context);
                    991:       TtaSetStylePresentation (PRBorderBottomStyle, element, tsch, context, border);
                    992:     }
1.1       cvs       993:   return (cssRule);
                    994: }
                    995: 
                    996: /*----------------------------------------------------------------------
1.59      cvs       997:    ParseCSSBorderStyleRight: parse a CSS BorderStyleRight
1.1       cvs       998:    attribute string.                                          
                    999:   ----------------------------------------------------------------------*/
1.79      cvs      1000: static char *ParseCSSBorderStyleRight (Element element, PSchema tsch,
                   1001:                                       PresentationContext context,
                   1002:                                       char *cssRule, CSSInfoPtr css,
                   1003:                                       ThotBool isHTML)
1.1       cvs      1004: {
1.43      cvs      1005:   PresentationValue   border;
                   1006:   
1.82      cvs      1007:   cssRule = SkipBlanksAndComments (cssRule);
1.43      cvs      1008:   cssRule = ParseBorderStyle (cssRule, &border);
1.116     vatton   1009:   if (border.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.117     vatton   1010:     {
                   1011:       /* check if it's an important rule */
                   1012:       if (tsch)
                   1013:        cssRule = CheckImportantRule (cssRule, context);
                   1014:       TtaSetStylePresentation (PRBorderRightStyle, element, tsch, context, border);
                   1015:     }
1.1       cvs      1016:   return (cssRule);
                   1017: }
                   1018: 
                   1019: /*----------------------------------------------------------------------
1.59      cvs      1020:    ParseCSSBorderStyleStyle: parse a CSS border-style        
1.1       cvs      1021:    attribute string.                                          
                   1022:   ----------------------------------------------------------------------*/
1.79      cvs      1023: static char *ParseCSSBorderStyle (Element element, PSchema tsch,
                   1024:                                  PresentationContext context,
                   1025:                                  char *cssRule, CSSInfoPtr css,
                   1026:                                  ThotBool isHTML)
1.1       cvs      1027: {
1.79      cvs      1028:   char *ptrT, *ptrR, *ptrB, *ptrL;
1.93      vatton   1029:   int   skippedNL;
1.42      cvs      1030: 
1.82      cvs      1031:   ptrT = SkipBlanksAndComments (cssRule);
1.42      cvs      1032:   /* First parse Border-Top */
1.43      cvs      1033:   ptrR = ParseCSSBorderStyleTop (element, tsch, context, ptrT, css, isHTML);
1.82      cvs      1034:   ptrR = SkipBlanksAndComments (ptrR);
                   1035:   if (*ptrR == ';' || *ptrR == EOS || *ptrR == ',')
1.42      cvs      1036:     {
1.93      vatton   1037:       skippedNL = NewLineSkipped;
1.42      cvs      1038:       cssRule = ptrR;
                   1039:       /* apply the Border-Top to all */
1.43      cvs      1040:       ptrR = ParseCSSBorderStyleRight (element, tsch, context, ptrT, css, isHTML);
1.93      vatton   1041:       NewLineSkipped = skippedNL;
1.43      cvs      1042:       ptrR = ParseCSSBorderStyleBottom (element, tsch, context, ptrT, css, isHTML);
1.93      vatton   1043:       NewLineSkipped = skippedNL;
1.43      cvs      1044:       ptrR = ParseCSSBorderStyleLeft (element, tsch, context, ptrT, css, isHTML);
1.42      cvs      1045:     }
                   1046:   else
                   1047:     {
                   1048:       /* parse Border-Right */
1.43      cvs      1049:       ptrB = ParseCSSBorderStyleRight (element, tsch, context, ptrR, css, isHTML);
1.82      cvs      1050:       ptrB = SkipBlanksAndComments (ptrB);
                   1051:       if (*ptrB == ';' || *ptrB == EOS || *ptrB == ',')
1.42      cvs      1052:        {
1.93      vatton   1053:          skippedNL = NewLineSkipped;
1.42      cvs      1054:          cssRule = ptrB;
                   1055:          /* apply the Border-Top to Border-Bottom */
1.43      cvs      1056:          ptrB = ParseCSSBorderStyleBottom (element, tsch, context, ptrT, css, isHTML);
1.93      vatton   1057:          NewLineSkipped = skippedNL;
1.42      cvs      1058:          /* apply the Border-Right to Border-Left */
1.43      cvs      1059:          ptrB = ParseCSSBorderStyleLeft (element, tsch, context, ptrR, css, isHTML);
1.42      cvs      1060:        }
                   1061:       else
                   1062:        {
                   1063:          /* parse Border-Bottom */
1.43      cvs      1064:          ptrL = ParseCSSBorderStyleBottom (element, tsch, context, ptrB, css, isHTML);
1.82      cvs      1065:          ptrL = SkipBlanksAndComments (ptrL);
                   1066:          if (*ptrL == ';' || *ptrL == EOS || *ptrL == ',')
1.42      cvs      1067:            {
                   1068:              cssRule = ptrL;
                   1069:              /* apply the Border-Right to Border-Left */
1.43      cvs      1070:              ptrL = ParseCSSBorderStyleLeft (element, tsch, context, ptrR, css, isHTML);
1.42      cvs      1071:            }
                   1072:          else
                   1073:            /* parse Border-Left */
1.43      cvs      1074:            cssRule = ParseCSSBorderStyleLeft (element, tsch, context, ptrL, css, isHTML);
1.82      cvs      1075:          cssRule = SkipBlanksAndComments (cssRule);
1.42      cvs      1076:        }
                   1077:     }
                   1078:   return (cssRule);
                   1079: }
                   1080: 
                   1081: /*----------------------------------------------------------------------
1.59      cvs      1082:    ParseCSSBorderTop: parse a CSS BorderTop
1.42      cvs      1083:    attribute string.                                          
                   1084:   ----------------------------------------------------------------------*/
1.79      cvs      1085: static char *ParseCSSBorderTop (Element element, PSchema tsch,
                   1086:                                PresentationContext context, char *cssRule,
                   1087:                                CSSInfoPtr css, ThotBool isHTML)
1.42      cvs      1088: {
1.79      cvs      1089:   char           *ptr;
1.43      cvs      1090: 
1.82      cvs      1091:   cssRule = SkipBlanksAndComments (cssRule);
                   1092:   while (*cssRule != ';' && *cssRule != EOS && *cssRule != ',')
1.43      cvs      1093:     {
                   1094:       ptr = cssRule;
                   1095:       cssRule = ParseCSSBorderStyleTop (element, tsch, context, cssRule, css, isHTML);
                   1096:       if (ptr == cssRule)
                   1097:        cssRule = ParseCSSBorderTopWidth (element, tsch, context, cssRule, css, isHTML);
                   1098:       if (ptr == cssRule)
                   1099:        cssRule = ParseCSSBorderColorTop (element, tsch, context, cssRule, css, isHTML);
                   1100:       if (ptr == cssRule)
                   1101:        /* rule not found */
1.168     vatton   1102:        cssRule = SkipValue ("Invalid border value", cssRule);
1.82      cvs      1103:       cssRule = SkipBlanksAndComments (cssRule);
1.43      cvs      1104:     }
1.42      cvs      1105:   return (cssRule);
                   1106: }
                   1107: 
                   1108: /*----------------------------------------------------------------------
1.59      cvs      1109:    ParseCSSBorderLeft: parse a CSS BorderLeft
1.42      cvs      1110:    attribute string.                                          
                   1111:   ----------------------------------------------------------------------*/
1.79      cvs      1112: static char *ParseCSSBorderLeft (Element element, PSchema tsch,
                   1113:                                 PresentationContext context, char *cssRule,
                   1114:                                 CSSInfoPtr css, ThotBool isHTML)
1.42      cvs      1115: {
1.79      cvs      1116:   char           *ptr;
1.43      cvs      1117: 
1.82      cvs      1118:   cssRule = SkipBlanksAndComments (cssRule);
                   1119:   while (*cssRule != ';' && *cssRule != EOS && *cssRule != ',')
1.43      cvs      1120:     {
                   1121:       ptr = cssRule;
                   1122:       cssRule = ParseCSSBorderStyleLeft (element, tsch, context, cssRule, css, isHTML);
                   1123:       if (ptr == cssRule)
                   1124:        cssRule = ParseCSSBorderLeftWidth (element, tsch, context, cssRule, css, isHTML);
                   1125:       if (ptr == cssRule)
                   1126:        cssRule = ParseCSSBorderColorLeft (element, tsch, context, cssRule, css, isHTML);
                   1127:       if (ptr == cssRule)
                   1128:        /* rule not found */
1.168     vatton   1129:        cssRule = SkipValue ("Invalid border value", cssRule);
1.82      cvs      1130:       cssRule = SkipBlanksAndComments (cssRule);
1.43      cvs      1131:     }
1.1       cvs      1132:   return (cssRule);
                   1133: }
                   1134: 
                   1135: /*----------------------------------------------------------------------
1.59      cvs      1136:    ParseCSSBorderBottom: parse a CSS BorderBottom
1.1       cvs      1137:    attribute string.                                          
                   1138:   ----------------------------------------------------------------------*/
1.79      cvs      1139: static char *ParseCSSBorderBottom (Element element, PSchema tsch,
                   1140:                                   PresentationContext context, char *cssRule,
                   1141:                                   CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      1142: {
1.79      cvs      1143:   char           *ptr;
1.43      cvs      1144: 
1.82      cvs      1145:   cssRule = SkipBlanksAndComments (cssRule);
                   1146:   while (*cssRule != ';' && *cssRule != EOS && *cssRule != ',')
1.43      cvs      1147:     {
                   1148:       ptr = cssRule;
                   1149:       cssRule = ParseCSSBorderStyleBottom (element, tsch, context, cssRule, css, isHTML);
                   1150:       if (ptr == cssRule)
                   1151:        cssRule = ParseCSSBorderBottomWidth (element, tsch, context, cssRule, css, isHTML);
                   1152:       if (ptr == cssRule)
                   1153:        cssRule = ParseCSSBorderColorBottom (element, tsch, context, cssRule, css, isHTML);
                   1154:       if (ptr == cssRule)
                   1155:        /* rule not found */
1.168     vatton   1156:        cssRule = SkipValue ("Invalid border value", cssRule);
1.82      cvs      1157:       cssRule = SkipBlanksAndComments (cssRule);
1.43      cvs      1158:     }
1.1       cvs      1159:   return (cssRule);
                   1160: }
                   1161: 
                   1162: /*----------------------------------------------------------------------
1.59      cvs      1163:    ParseCSSBorderRight: parse a CSS BorderRight
1.1       cvs      1164:    attribute string.                                          
                   1165:   ----------------------------------------------------------------------*/
1.79      cvs      1166: static char *ParseCSSBorderRight (Element element, PSchema tsch,
                   1167:                                  PresentationContext context, char *cssRule,
                   1168:                                  CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      1169: {
1.79      cvs      1170:   char            *ptr;
1.43      cvs      1171: 
1.82      cvs      1172:   cssRule = SkipBlanksAndComments (cssRule);
                   1173:   while (*cssRule != ';' && *cssRule != EOS && *cssRule != ',')
1.43      cvs      1174:     {
                   1175:       ptr = cssRule;
                   1176:       cssRule = ParseCSSBorderStyleRight (element, tsch, context, cssRule, css, isHTML);
                   1177:       if (ptr == cssRule)
                   1178:        cssRule = ParseCSSBorderRightWidth (element, tsch, context, cssRule, css, isHTML);
                   1179:       if (ptr == cssRule)
                   1180:        cssRule = ParseCSSBorderColorRight (element, tsch, context, cssRule, css, isHTML);
                   1181:       if (ptr == cssRule)
                   1182:        /* rule not found */
1.168     vatton   1183:        cssRule = SkipValue ("Invalid border value", cssRule);
1.82      cvs      1184:       cssRule = SkipBlanksAndComments (cssRule);
1.43      cvs      1185:     }
1.1       cvs      1186:   return (cssRule);
                   1187: }
                   1188: 
                   1189: /*----------------------------------------------------------------------
1.59      cvs      1190:    ParseCSSBorder: parse a CSS border        
1.42      cvs      1191:    attribute string.                                          
                   1192:   ----------------------------------------------------------------------*/
1.79      cvs      1193: static char *ParseCSSBorder (Element element, PSchema tsch,
                   1194:                             PresentationContext context, char *cssRule,
                   1195:                             CSSInfoPtr css, ThotBool isHTML)
1.42      cvs      1196: {
1.79      cvs      1197:   char *ptrT, *ptrR;
1.93      vatton   1198:   int   skippedNL;
1.42      cvs      1199: 
1.82      cvs      1200:   ptrT = SkipBlanksAndComments (cssRule);
1.42      cvs      1201:   /* First parse Border-Top */
                   1202:   ptrR = ParseCSSBorderTop (element, tsch, context, ptrT, css, isHTML);
1.82      cvs      1203:   ptrR = SkipBlanksAndComments (ptrR);
                   1204:   if (*ptrR == ';' || *ptrR == EOS || *ptrR == ',')
1.42      cvs      1205:     {
1.93      vatton   1206:       skippedNL = NewLineSkipped;
1.42      cvs      1207:       cssRule = ptrR;
                   1208:       /* apply the Border-Top to all */
                   1209:       ptrR = ParseCSSBorderRight (element, tsch, context, ptrT, css, isHTML);
1.93      vatton   1210:       NewLineSkipped = skippedNL;
1.42      cvs      1211:       ptrR = ParseCSSBorderBottom (element, tsch, context, ptrT, css, isHTML);
1.93      vatton   1212:       NewLineSkipped = skippedNL;
1.42      cvs      1213:       ptrR = ParseCSSBorderLeft (element, tsch, context, ptrT, css, isHTML);
                   1214:     }
                   1215:   return (cssRule);
                   1216: }
                   1217: 
                   1218: /*----------------------------------------------------------------------
1.59      cvs      1219:    ParseCSSClear: parse a CSS clear attribute string    
1.1       cvs      1220:   ----------------------------------------------------------------------*/
1.79      cvs      1221: static char *ParseCSSClear (Element element, PSchema tsch,
                   1222:                            PresentationContext context, char *cssRule,
                   1223:                            CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      1224: {
1.168     vatton   1225:   cssRule = SkipValue (NULL, cssRule);
1.1       cvs      1226:   return (cssRule);
                   1227: }
                   1228: 
                   1229: /*----------------------------------------------------------------------
1.59      cvs      1230:    ParseCSSDisplay: parse a CSS display attribute string        
1.1       cvs      1231:   ----------------------------------------------------------------------*/
1.79      cvs      1232: static char *ParseCSSDisplay (Element element, PSchema tsch,
                   1233:                              PresentationContext context, char *cssRule,
                   1234:                              CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      1235: {
                   1236:    PresentationValue   pval;
1.168     vatton   1237:    char               *ptr;
1.1       cvs      1238: 
                   1239:    pval.typed_data.unit = STYLE_UNIT_REL;
                   1240:    pval.typed_data.real = FALSE;
1.82      cvs      1241:    cssRule = SkipBlanksAndComments (cssRule);
1.126     vatton   1242:    if (!strncasecmp (cssRule, "none", 4))
1.1       cvs      1243:      {
1.124     quint    1244:        pval.typed_data.value = 0;
1.116     vatton   1245:        if (DoApply)
1.117     vatton   1246:        {
                   1247:          if (tsch)
                   1248:            cssRule = CheckImportantRule (cssRule, context);
1.116     vatton   1249:          TtaSetStylePresentation (PRVisibility, element, tsch, context, pval);
1.117     vatton   1250:        }
1.1       cvs      1251:        cssRule = SkipWord (cssRule);
                   1252:      }
                   1253:    else
1.126     vatton   1254:      {
                   1255:        if (!strncasecmp (cssRule, "block", 5))
                   1256:         pval.typed_data.value = STYLE_DISPLAYBLOCK;
                   1257:        else if (!strncasecmp (cssRule, "inline", 6))
                   1258:         pval.typed_data.value = STYLE_DISPLAYINLINE;
                   1259:        else if (!strncasecmp (cssRule, "list-item", 9))
                   1260:        pval.typed_data.value = STYLE_DISPLAYLISTITEM;
1.128     vatton   1261:        else if (!strncasecmp (cssRule, "run-in", 6))
1.126     vatton   1262:         pval.typed_data.value = STYLE_DISPLAYRUNIN;
                   1263:        else if (!strncasecmp (cssRule, "compact", 7))
                   1264:         pval.typed_data.value = STYLE_DISPLAYCOMPACT;
                   1265:        else if (!strncasecmp (cssRule, "marker", 6))
                   1266:         pval.typed_data.value = STYLE_DISPLAYMARKER;
                   1267:        else
                   1268:         {
1.128     vatton   1269:           if (strncasecmp (cssRule, "table-row-group", 15) &&
                   1270:               strncasecmp (cssRule, "table-column-group", 18) &&
                   1271:               strncasecmp (cssRule, "table-header-group", 5) &&
                   1272:               strncasecmp (cssRule, "table-footer-group", 6) &&
                   1273:               strncasecmp (cssRule, "table-row", 9) &&
                   1274:               strncasecmp (cssRule, "table-column", 12) &&
                   1275:               strncasecmp (cssRule, "table-cell", 10) &&
                   1276:               strncasecmp (cssRule, "table-caption", 13) &&
                   1277:               strncasecmp (cssRule, "table", 5) &&
                   1278:               strncasecmp (cssRule, "inherit", 7))
1.168     vatton   1279:             {
                   1280:               ptr = cssRule;
                   1281:               cssRule = SkipWord (cssRule);
                   1282:               CSSParseError ("Invalid display value", ptr, cssRule);
                   1283:             }
1.126     vatton   1284:           return (cssRule);
                   1285:         }
1.34      cvs      1286: 
1.126     vatton   1287:        if (DoApply)
                   1288:         {
                   1289:           if (tsch)
                   1290:             cssRule = CheckImportantRule (cssRule, context);
                   1291:           TtaSetStylePresentation (PRDisplay, element, tsch, context, pval);
                   1292:         }
                   1293:        cssRule = SkipWord (cssRule);
                   1294:      }
1.1       cvs      1295:    return (cssRule);
                   1296: }
                   1297: 
                   1298: /*----------------------------------------------------------------------
1.59      cvs      1299:    ParseCSSFloat: parse a CSS float attribute string    
1.1       cvs      1300:   ----------------------------------------------------------------------*/
1.79      cvs      1301: static char *ParseCSSFloat (Element element, PSchema tsch,
                   1302:                            PresentationContext context, char *cssRule,
                   1303:                            CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      1304: {
1.168     vatton   1305:   cssRule = SkipValue (NULL, cssRule);
1.1       cvs      1306:   return (cssRule);
                   1307: }
                   1308: 
                   1309: /*----------------------------------------------------------------------
1.59      cvs      1310:    ParseCSSLetterSpacing: parse a CSS letter-spacing    
1.1       cvs      1311:    attribute string.                                          
                   1312:   ----------------------------------------------------------------------*/
1.79      cvs      1313: static char *ParseCSSLetterSpacing (Element element, PSchema tsch,
                   1314:                                    PresentationContext context, char *cssRule,
                   1315:                                    CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      1316: {
1.168     vatton   1317:   cssRule = SkipValue (NULL, cssRule);
1.1       cvs      1318:   return (cssRule);
                   1319: }
                   1320: 
                   1321: /*----------------------------------------------------------------------
1.59      cvs      1322:    ParseCSSListStyleType: parse a CSS list-style-type
1.1       cvs      1323:    attribute string.                                          
                   1324:   ----------------------------------------------------------------------*/
1.79      cvs      1325: static char *ParseCSSListStyleType (Element element, PSchema tsch,
                   1326:                                    PresentationContext context, char *cssRule,
                   1327:                                    CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      1328: {
1.168     vatton   1329:   cssRule = SkipValue (NULL, cssRule);
1.1       cvs      1330:   return (cssRule);
                   1331: }
                   1332: 
                   1333: /*----------------------------------------------------------------------
1.59      cvs      1334:    ParseCSSListStyleImage: parse a CSS list-style-image
1.1       cvs      1335:    attribute string.                                          
                   1336:   ----------------------------------------------------------------------*/
1.79      cvs      1337: static char *ParseCSSListStyleImage (Element element, PSchema tsch,
                   1338:                                     PresentationContext context, char *cssRule,
                   1339:                                     CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      1340: {
1.168     vatton   1341:   cssRule = SkipValue (NULL, cssRule);
1.1       cvs      1342:   return (cssRule);
                   1343: }
                   1344: 
                   1345: /*----------------------------------------------------------------------
1.59      cvs      1346:    ParseCSSListStylePosition: parse a CSS list-style-position
1.1       cvs      1347:    attribute string.                                          
                   1348:   ----------------------------------------------------------------------*/
1.79      cvs      1349: static char *ParseCSSListStylePosition (Element element, PSchema tsch,
                   1350:                                        PresentationContext context,
                   1351:                                        char *cssRule, CSSInfoPtr css,
                   1352:                                        ThotBool isHTML)
1.1       cvs      1353: {
1.168     vatton   1354:   cssRule = SkipValue (NULL, cssRule);
1.1       cvs      1355:   return (cssRule);
                   1356: }
                   1357: 
                   1358: /*----------------------------------------------------------------------
1.59      cvs      1359:    ParseCSSListStyle: parse a CSS list-style            
1.1       cvs      1360:    attribute string.                                          
                   1361:   ----------------------------------------------------------------------*/
1.79      cvs      1362: static char *ParseCSSListStyle (Element element, PSchema tsch,
                   1363:                                PresentationContext context, char *cssRule,
                   1364:                                CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      1365: {
1.168     vatton   1366:   cssRule = SkipValue (NULL, cssRule);
1.1       cvs      1367:   return (cssRule);
                   1368: }
                   1369: 
                   1370: /*----------------------------------------------------------------------
1.59      cvs      1371:    ParseCSSTextAlign: parse a CSS text-align            
1.1       cvs      1372:    attribute string.                                          
                   1373:   ----------------------------------------------------------------------*/
1.79      cvs      1374: static char *ParseCSSTextAlign (Element element, PSchema tsch,
                   1375:                                PresentationContext context, char *cssRule,
                   1376:                                CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      1377: {
                   1378:    PresentationValue   align;
1.168     vatton   1379:    char               *ptr;
1.1       cvs      1380: 
                   1381:    align.typed_data.value = 0;
                   1382:    align.typed_data.unit = STYLE_UNIT_REL;
                   1383:    align.typed_data.real = FALSE;
                   1384: 
1.82      cvs      1385:    cssRule = SkipBlanksAndComments (cssRule);
                   1386:    if (!strncasecmp (cssRule, "left", 4))
1.1       cvs      1387:      {
                   1388:        align.typed_data.value = AdjustLeft;
                   1389:        cssRule = SkipWord (cssRule);
                   1390:      }
1.82      cvs      1391:    else if (!strncasecmp (cssRule, "right", 5))
1.1       cvs      1392:      {
                   1393:        align.typed_data.value = AdjustRight;
                   1394:        cssRule = SkipWord (cssRule);
                   1395:      }
1.82      cvs      1396:    else if (!strncasecmp (cssRule, "center", 6))
1.1       cvs      1397:      {
                   1398:        align.typed_data.value = Centered;
                   1399:        cssRule = SkipWord (cssRule);
                   1400:      }
1.82      cvs      1401:    else if (!strncasecmp (cssRule, "justify", 7))
1.1       cvs      1402:      {
1.81      cvs      1403:        align.typed_data.value = Justify;
1.1       cvs      1404:        cssRule = SkipWord (cssRule);
                   1405:      }
                   1406:    else
                   1407:      {
1.168     vatton   1408:        ptr = cssRule;
                   1409:        cssRule = SkipWord (cssRule);
                   1410:        CSSParseError ("Invalid text-align value", ptr, cssRule);
1.1       cvs      1411:        return (cssRule);
                   1412:      }
                   1413: 
                   1414:    /*
                   1415:     * install the new presentation.
                   1416:     */
1.116     vatton   1417:    if (align.typed_data.value && DoApply)
1.117     vatton   1418:      {
                   1419:        if (tsch)
                   1420:         cssRule = CheckImportantRule (cssRule, context);
                   1421:        TtaSetStylePresentation (PRAdjust, element, tsch, context, align);
                   1422:      }
1.1       cvs      1423:    return (cssRule);
                   1424: }
                   1425: 
                   1426: /*----------------------------------------------------------------------
1.112     quint    1427:    ParseCSSDirection: parse a CSS direction property
                   1428:   ----------------------------------------------------------------------*/
                   1429: static char *ParseCSSDirection (Element element, PSchema tsch,
                   1430:                                PresentationContext context, char *cssRule,
                   1431:                                CSSInfoPtr css, ThotBool isHTML)
                   1432: {
                   1433:    PresentationValue   direction;
1.168     vatton   1434:    char               *ptr;
1.112     quint    1435: 
                   1436:    direction.typed_data.value = 0;
                   1437:    direction.typed_data.unit = STYLE_UNIT_REL;
                   1438:    direction.typed_data.real = FALSE;
                   1439: 
                   1440:    cssRule = SkipBlanksAndComments (cssRule);
                   1441:    if (!strncasecmp (cssRule, "ltr", 3))
                   1442:      {
                   1443:        direction.typed_data.value = STYLE_LEFTTORIGHT;
                   1444:        cssRule = SkipWord (cssRule);
                   1445:      }
                   1446:    else if (!strncasecmp (cssRule, "rtl", 3))
                   1447:      {
                   1448:        direction.typed_data.value = STYLE_RIGHTTOLEFT;
                   1449:        cssRule = SkipWord (cssRule);
                   1450:      }
                   1451:    else if (!strncasecmp (cssRule, "inherit", 7))
                   1452:      {
                   1453:        /* not implemented */
                   1454:        cssRule = SkipWord (cssRule);
                   1455:        return (cssRule);
                   1456:      }
                   1457:    else
                   1458:      {
1.168     vatton   1459:        ptr = cssRule;
                   1460:        cssRule = SkipWord (cssRule);
                   1461:        CSSParseError ("Invalid direction value", ptr, cssRule);
1.112     quint    1462:        return (cssRule);
                   1463:      }
                   1464: 
                   1465:    /*
                   1466:     * install the new presentation.
                   1467:     */
1.116     vatton   1468:    if (direction.typed_data.value && DoApply)
1.117     vatton   1469:      {
                   1470:        if (tsch)
                   1471:         cssRule = CheckImportantRule (cssRule, context);
                   1472:        TtaSetStylePresentation (PRDirection, element, tsch, context, direction);
                   1473:      }
1.112     quint    1474:    return (cssRule);
                   1475: }
                   1476: 
                   1477: /*----------------------------------------------------------------------
1.113     quint    1478:    ParseCSSUnicodeBidi: parse a CSS unicode-bidi property
                   1479:   ----------------------------------------------------------------------*/
                   1480: static char *ParseCSSUnicodeBidi (Element element, PSchema tsch,
                   1481:                                  PresentationContext context, char *cssRule,
                   1482:                                  CSSInfoPtr css, ThotBool isHTML)
                   1483: {
                   1484:    PresentationValue   bidi;
1.168     vatton   1485:    char               *ptr;
1.113     quint    1486: 
                   1487:    bidi.typed_data.value = 0;
                   1488:    bidi.typed_data.unit = STYLE_UNIT_REL;
                   1489:    bidi.typed_data.real = FALSE;
                   1490: 
                   1491:    cssRule = SkipBlanksAndComments (cssRule);
                   1492:    if (!strncasecmp (cssRule, "normal", 6))
                   1493:      {
                   1494:        bidi.typed_data.value = STYLE_BIDINORMAL;
                   1495:        cssRule = SkipWord (cssRule);
                   1496:      }
                   1497:    else if (!strncasecmp (cssRule, "embed", 5))
                   1498:      {
                   1499:        bidi.typed_data.value = STYLE_BIDIEMBED;
                   1500:        cssRule = SkipWord (cssRule);
                   1501:      }
                   1502:    else if (!strncasecmp (cssRule, "override", 8))
                   1503:      {
                   1504:        bidi.typed_data.value = STYLE_BIDIOVERRIDE;
                   1505:        cssRule = SkipWord (cssRule);
                   1506:      }
                   1507:    else if (!strncasecmp (cssRule, "inherit", 7))
                   1508:      {
                   1509:        /* not implemented */
                   1510:        cssRule = SkipWord (cssRule);
                   1511:        return (cssRule);
                   1512:      }
                   1513:    else
                   1514:      {
1.168     vatton   1515:        ptr = cssRule;
                   1516:        cssRule = SkipWord (cssRule);
                   1517:        CSSParseError ("Invalid unicode-bidi value", ptr, cssRule);
1.113     quint    1518:        return (cssRule);
                   1519:      }
                   1520: 
                   1521:    /*
                   1522:     * install the new presentation.
                   1523:     */
1.116     vatton   1524:    if (bidi.typed_data.value && DoApply)
1.117     vatton   1525:      {
                   1526:        if (tsch)
                   1527:         cssRule = CheckImportantRule (cssRule, context);
                   1528:        TtaSetStylePresentation (PRUnicodeBidi, element, tsch, context, bidi);
                   1529:      }
1.113     quint    1530:    return (cssRule);
                   1531: }
                   1532: 
                   1533: /*----------------------------------------------------------------------
1.168     vatton   1534:    ParseCSSTextIndent: parse a CSS text-indent
1.1       cvs      1535:    attribute string.                                          
                   1536:   ----------------------------------------------------------------------*/
1.79      cvs      1537: static char *ParseCSSTextIndent (Element element, PSchema tsch,
                   1538:                                 PresentationContext context, char *cssRule,
                   1539:                                 CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      1540: {
                   1541:    PresentationValue   pval;
1.168     vatton   1542:    char               *ptr;
1.1       cvs      1543: 
1.82      cvs      1544:    cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   1545:    ptr = cssRule;
1.1       cvs      1546:    cssRule = ParseCSSUnit (cssRule, &pval);
1.168     vatton   1547:    if (pval.typed_data.value == 0)
1.166     vatton   1548:      pval.typed_data.unit = STYLE_UNIT_PX;
1.168     vatton   1549:    else if (pval.typed_data.unit == STYLE_UNIT_INVALID ||
                   1550:        pval.typed_data.unit == STYLE_UNIT_BOX)
                   1551:      {
                   1552:        CSSParseError ("Invalid text-indent value", ptr, cssRule);
                   1553:        return (cssRule);
                   1554:      }
1.1       cvs      1555:    /* install the attribute */
1.116     vatton   1556:    if (DoApply)
1.117     vatton   1557:      {
                   1558:        if (tsch)
                   1559:         cssRule = CheckImportantRule (cssRule, context);
                   1560:        TtaSetStylePresentation (PRIndent, element, tsch, context, pval);
                   1561:      }
1.1       cvs      1562:    return (cssRule);
                   1563: }
                   1564: 
                   1565: /*----------------------------------------------------------------------
1.59      cvs      1566:    ParseCSSTextTransform: parse a CSS text-transform    
1.1       cvs      1567:    attribute string.                                          
                   1568:   ----------------------------------------------------------------------*/
1.79      cvs      1569: static char *ParseCSSTextTransform (Element element, PSchema tsch,
                   1570:                                    PresentationContext context, char *cssRule,
                   1571:                                    CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      1572: {
1.168     vatton   1573:   cssRule = SkipValue (NULL, cssRule);
1.1       cvs      1574:   return (cssRule);
                   1575: }
                   1576: 
                   1577: /*----------------------------------------------------------------------
1.59      cvs      1578:    ParseCSSVerticalAlign: parse a CSS vertical-align    
1.1       cvs      1579:    attribute string.                                          
                   1580:   ----------------------------------------------------------------------*/
1.79      cvs      1581: static char *ParseCSSVerticalAlign (Element element, PSchema tsch,
                   1582:                                    PresentationContext context, char *cssRule,
                   1583:                                    CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      1584: {
1.168     vatton   1585:   cssRule = SkipValue (NULL, cssRule);
1.1       cvs      1586:   return (cssRule);
                   1587: }
                   1588: 
                   1589: /*----------------------------------------------------------------------
1.59      cvs      1590:    ParseCSSWhiteSpace: parse a CSS white-space          
1.1       cvs      1591:    attribute string.                                          
                   1592:   ----------------------------------------------------------------------*/
1.79      cvs      1593: static char *ParseCSSWhiteSpace (Element element, PSchema tsch,
                   1594:                                 PresentationContext context, char *cssRule,
                   1595:                                 CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      1596: {
1.82      cvs      1597:    cssRule = SkipBlanksAndComments (cssRule);
                   1598:    if (!strncasecmp (cssRule, "normal", 6))
1.1       cvs      1599:      cssRule = SkipWord (cssRule);
1.82      cvs      1600:    else if (!strncasecmp (cssRule, "pre", 3))
1.1       cvs      1601:      cssRule = SkipWord (cssRule);
                   1602:    else
                   1603:      return (cssRule);
                   1604:    return (cssRule);
                   1605: }
                   1606: 
                   1607: /*----------------------------------------------------------------------
1.59      cvs      1608:    ParseCSSWordSpacing: parse a CSS word-spacing        
1.1       cvs      1609:    attribute string.                                          
                   1610:   ----------------------------------------------------------------------*/
1.79      cvs      1611: static char *ParseCSSWordSpacing (Element element, PSchema tsch,
                   1612:                                  PresentationContext context, char *cssRule,
                   1613:                                  CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      1614: {
1.168     vatton   1615:   cssRule = SkipValue (NULL, cssRule);
1.1       cvs      1616:   return (cssRule);
                   1617: }
                   1618: 
                   1619: /*----------------------------------------------------------------------
1.162     quint    1620:    ParseCSSLineHeight: parse a CSS line-height property
1.25      cvs      1621:   ----------------------------------------------------------------------*/
1.162     quint    1622: static char *ParseCSSLineHeight (Element element, PSchema tsch,
1.166     vatton   1623:                                 PresentationContext context, char *cssRule,
                   1624:                                 CSSInfoPtr css, ThotBool isHTML)
1.25      cvs      1625: {
1.162     quint    1626:   PresentationValue   pval;
                   1627:   char                *ptr;
                   1628: 
                   1629:   ptr = cssRule;
                   1630:   if (!strncasecmp (cssRule, "normal", 6))
                   1631:     {
                   1632:       pval.typed_data.unit = STYLE_UNIT_REL;
                   1633:       pval.typed_data.real = TRUE;
                   1634:       pval.typed_data.value = 1100;
                   1635:       cssRule = SkipWord (cssRule);
                   1636:     }
                   1637:   else if (!strncasecmp (cssRule, "inherit", 7))
                   1638:     {
                   1639:       cssRule = SkipWord (cssRule);
                   1640:       return (cssRule);
                   1641:     }
                   1642:   else
                   1643:     cssRule = ParseCSSUnit (cssRule, &pval);
1.25      cvs      1644: 
1.162     quint    1645:   if (pval.typed_data.unit == STYLE_UNIT_INVALID)
1.168     vatton   1646:     CSSParseError ("Invalid line-height value", ptr, cssRule);
1.162     quint    1647:   else if (DoApply)
                   1648:     {
1.166     vatton   1649:       /* install the new presentation */
                   1650:       if (pval.typed_data.unit == STYLE_UNIT_BOX)
                   1651:        pval.typed_data.unit = STYLE_UNIT_EM;
1.162     quint    1652:       if (tsch)
                   1653:        cssRule = CheckImportantRule (cssRule, context);
                   1654:       TtaSetStylePresentation (PRLineSpacing, element, tsch, context, pval);
                   1655:     }
                   1656:   return (cssRule);
1.25      cvs      1657: }
                   1658: 
                   1659: /*----------------------------------------------------------------------
1.59      cvs      1660:    ParseCSSFontSize: parse a CSS font size attr string  
1.1       cvs      1661:    we expect the input string describing the attribute to be     
                   1662:    xx-small, x-small, small, medium, large, x-large, xx-large      
                   1663:    or an absolute size, or an imcrement relative to the parent     
                   1664:   ----------------------------------------------------------------------*/
1.79      cvs      1665: static char *ParseCSSFontSize (Element element, PSchema tsch,
                   1666:                               PresentationContext context, char *cssRule,
                   1667:                               CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      1668: {
1.171   ! quint    1669:    ElementType         elType;
1.1       cvs      1670:    PresentationValue   pval;
1.137     vatton   1671:    char               *ptr = NULL, *ptr1 = NULL;
1.14      cvs      1672:    ThotBool           real;
1.1       cvs      1673: 
                   1674:    pval.typed_data.real = FALSE;
1.82      cvs      1675:    cssRule = SkipBlanksAndComments (cssRule);
                   1676:    if (!strncasecmp (cssRule, "larger", 6))
1.1       cvs      1677:      {
                   1678:        pval.typed_data.unit = STYLE_UNIT_PERCENT;
                   1679:        pval.typed_data.value = 130;
                   1680:        cssRule = SkipWord (cssRule);
                   1681:      }
1.82      cvs      1682:    else if (!strncasecmp (cssRule, "smaller", 7))
1.1       cvs      1683:      {
                   1684:        pval.typed_data.unit = STYLE_UNIT_PERCENT;
                   1685:        pval.typed_data.value = 80;
                   1686:        cssRule = SkipWord (cssRule);
                   1687:      }
1.82      cvs      1688:    else if (!strncasecmp (cssRule, "xx-small", 8))
1.1       cvs      1689:      {
                   1690:        pval.typed_data.unit = STYLE_UNIT_REL;
                   1691:        pval.typed_data.value = 1;
                   1692:        cssRule = SkipWord (cssRule);
                   1693:      }
1.82      cvs      1694:    else if (!strncasecmp (cssRule, "x-small", 7))
1.1       cvs      1695:      {
                   1696:        pval.typed_data.unit = STYLE_UNIT_REL;
                   1697:        pval.typed_data.value = 2;
                   1698:        cssRule = SkipWord (cssRule);
                   1699:      }
1.82      cvs      1700:    else if (!strncasecmp (cssRule, "small", 5))
1.1       cvs      1701:      {
                   1702:        pval.typed_data.unit = STYLE_UNIT_REL;
                   1703:        pval.typed_data.value = 3;
                   1704:        cssRule = SkipWord (cssRule);
                   1705:      }
1.82      cvs      1706:    else if (!strncasecmp (cssRule, "medium", 6))
1.1       cvs      1707:      {
                   1708:        pval.typed_data.unit = STYLE_UNIT_REL;
                   1709:        pval.typed_data.value = 4;
                   1710:        cssRule = SkipWord (cssRule);
                   1711:      }
1.82      cvs      1712:    else if (!strncasecmp (cssRule, "large", 5))
1.1       cvs      1713:      {
                   1714:        pval.typed_data.unit = STYLE_UNIT_REL;
                   1715:        pval.typed_data.value = 5;
                   1716:        cssRule = SkipWord (cssRule);
                   1717:      }
1.82      cvs      1718:    else if (!strncasecmp (cssRule, "x-large", 7))
1.1       cvs      1719:      {
                   1720:        pval.typed_data.unit = STYLE_UNIT_REL;
                   1721:        pval.typed_data.value = 6;
                   1722:        cssRule = SkipWord (cssRule);
                   1723:      }
1.82      cvs      1724:    else if (!strncasecmp (cssRule, "xx-large", 8))
1.1       cvs      1725:      {
                   1726:        pval.typed_data.unit = STYLE_UNIT_REL;
                   1727:        pval.typed_data.value = 7;
                   1728:        cssRule = SkipWord (cssRule);
                   1729:      }
1.171   ! quint    1730:    else if (!isdigit (*cssRule) && *cssRule != '.')
        !          1731:      return (cssRule);
1.1       cvs      1732:    else
                   1733:      {
1.25      cvs      1734:        /* look for a '/' within the current cssRule */
1.137     vatton   1735:        ptr1 = strchr (cssRule, ';');
1.82      cvs      1736:        ptr = strchr (cssRule, '/');
1.137     vatton   1737:        if (ptr && (ptr1 == NULL || ptr < ptr1))
1.25      cvs      1738:         {
                   1739:           /* keep the line spacing rule */
1.82      cvs      1740:           ptr[0] = EOS;
1.25      cvs      1741:           ptr = &ptr[1];
                   1742:         }
1.137     vatton   1743:        else
                   1744:         ptr = NULL;
1.171   ! quint    1745:        
1.1       cvs      1746:        cssRule = ParseCSSUnit (cssRule, &pval);
1.171   ! quint    1747: 
        !          1748:        if (pval.typed_data.unit == STYLE_UNIT_BOX)
        !          1749:         /* no unit specified */
        !          1750:         {
        !          1751:           elType = TtaGetElementType(element);
        !          1752:           if (!strcmp(TtaGetSSchemaName (elType.ElSSchema), "SVG"))
        !          1753:             /* we are working for an SVG element. No unit means pixels */
        !          1754:             pval.typed_data.unit = STYLE_UNIT_PX;
        !          1755:         }
1.168     vatton   1756:        if (pval.typed_data.value != 0 &&
                   1757:           (pval.typed_data.unit == STYLE_UNIT_INVALID ||
                   1758:            pval.typed_data.unit == STYLE_UNIT_BOX ||
                   1759:            pval.typed_data.value < 0))
                   1760:         /* not a valid value */
1.1       cvs      1761:         return (cssRule);
1.166     vatton   1762:        else if (pval.typed_data.unit == STYLE_UNIT_REL && pval.typed_data.value > 0)
1.1       cvs      1763:         /* CSS relative sizes have to be higher than Thot ones */
                   1764:         pval.typed_data.value += 1;
                   1765:        else 
                   1766:         {
                   1767:           real = pval.typed_data.real;
1.168     vatton   1768:           if (pval.typed_data.unit == STYLE_UNIT_EM)
1.1       cvs      1769:             {
                   1770:               if (real)
                   1771:                 {
                   1772:                   pval.typed_data.value /= 10;
1.11      cvs      1773:                   pval.typed_data.real = FALSE;
1.1       cvs      1774:                   real = FALSE;
                   1775:                 }
                   1776:               else
                   1777:                 pval.typed_data.value *= 100;
                   1778:               pval.typed_data.unit = STYLE_UNIT_PERCENT;
                   1779:             }
1.146     quint    1780:           else if (pval.typed_data.unit == STYLE_UNIT_XHEIGHT)
                   1781:             {
                   1782:               /* a font size expressed in ex is converted into a percentage.
                   1783:                  For example, "3ex" is converted into "180%", supposing
                   1784:                  that 1ex is approximately 0.6 times the height of the
                   1785:                  current font */
                   1786:               if (real)
                   1787:                 {
                   1788:                   pval.typed_data.value *= 6;
                   1789:                   pval.typed_data.value /= 100;
                   1790:                   pval.typed_data.real = FALSE;
                   1791:                   real = FALSE;
                   1792:                 }
                   1793:               else
                   1794:                 pval.typed_data.value *= 60;
                   1795:               pval.typed_data.unit = STYLE_UNIT_PERCENT;
                   1796:             }
1.1       cvs      1797:         }
                   1798:      }
                   1799: 
1.25      cvs      1800:    /* install the presentation style */
1.116     vatton   1801:    if (DoApply)
1.117     vatton   1802:      {
                   1803:        if (tsch)
                   1804:         cssRule = CheckImportantRule (cssRule, context);
                   1805:        TtaSetStylePresentation (PRSize, element, tsch, context, pval);
                   1806:      }
                   1807:    if (ptr)
1.162     quint    1808:      cssRule = ParseCSSLineHeight (element, tsch, context, ptr, css, isHTML);
1.1       cvs      1809:    return (cssRule);
                   1810: }
                   1811: 
                   1812: /*----------------------------------------------------------------------
1.59      cvs      1813:    ParseCSSFontFamily: parse a CSS font family string   
1.1       cvs      1814:    we expect the input string describing the attribute to be     
                   1815:    a common generic font style name                                
                   1816:   ----------------------------------------------------------------------*/
1.79      cvs      1817: static char *ParseCSSFontFamily (Element element, PSchema tsch,
                   1818:                                 PresentationContext context, char *cssRule,
                   1819:                                 CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      1820: {
                   1821:   PresentationValue   font;
1.79      cvs      1822:   char              quoteChar;
1.1       cvs      1823: 
                   1824:   font.typed_data.value = 0;
                   1825:   font.typed_data.unit = STYLE_UNIT_REL;
                   1826:   font.typed_data.real = FALSE;
1.82      cvs      1827:   cssRule = SkipBlanksAndComments (cssRule);
                   1828:   if (*cssRule == '"' || *cssRule == '\'')
1.1       cvs      1829:      {
                   1830:      quoteChar = *cssRule;
                   1831:      cssRule++;
                   1832:      }
                   1833:   else
1.82      cvs      1834:      quoteChar = EOS;
1.1       cvs      1835: 
1.92      cvs      1836:   if (!strncasecmp (cssRule, "times", 5) &&
                   1837:       (quoteChar == EOS || quoteChar == cssRule[5]))
1.86      cvs      1838:     {
1.1       cvs      1839:       font.typed_data.value = STYLE_FONT_TIMES;
1.86      cvs      1840:       cssRule += 5;
                   1841:     }
1.92      cvs      1842:   else if (!strncasecmp (cssRule, "serif", 5) &&
                   1843:       (quoteChar == EOS || quoteChar == cssRule[5]))
1.86      cvs      1844:     {
1.1       cvs      1845:       font.typed_data.value = STYLE_FONT_TIMES;
1.86      cvs      1846:       cssRule += 5;
1.92      cvs      1847:       if (quoteChar != EOS)
                   1848:        cssRule++;
1.86      cvs      1849:     }
1.92      cvs      1850:   else if (!strncasecmp (cssRule, "helvetica", 9) &&
                   1851:       (quoteChar == EOS || quoteChar == cssRule[9]))
1.86      cvs      1852:     {
                   1853:      font.typed_data.value = STYLE_FONT_HELVETICA;
                   1854:       cssRule += 9;
1.92      cvs      1855:       if (quoteChar != EOS)
                   1856:        cssRule++;
1.86      cvs      1857:     }
1.92      cvs      1858:   else if (!strncasecmp (cssRule, "verdana", 7) &&
                   1859:       (quoteChar == EOS || quoteChar == cssRule[7]))
1.86      cvs      1860:     {
1.1       cvs      1861:       font.typed_data.value = STYLE_FONT_HELVETICA;
1.86      cvs      1862:       cssRule += 7;
1.92      cvs      1863:       if (quoteChar != EOS)
                   1864:        cssRule++;
1.86      cvs      1865:     }
1.92      cvs      1866:   else if (!strncasecmp (cssRule, "sans-serif", 10) &&
                   1867:       (quoteChar == EOS || quoteChar == cssRule[10]))
1.86      cvs      1868:     {
1.1       cvs      1869:       font.typed_data.value = STYLE_FONT_HELVETICA;
1.86      cvs      1870:       cssRule += 10;
1.92      cvs      1871:       if (quoteChar != EOS)
                   1872:        cssRule++;
1.86      cvs      1873:     }
1.92      cvs      1874:   else if (!strncasecmp (cssRule, "courier", 7) &&
                   1875:       (quoteChar == EOS || quoteChar == cssRule[7]))
1.86      cvs      1876:     {
1.1       cvs      1877:       font.typed_data.value = STYLE_FONT_COURIER;
1.86      cvs      1878:       cssRule += 7;
1.92      cvs      1879:       if (quoteChar != EOS)
                   1880:        cssRule++;
1.86      cvs      1881:     }
1.92      cvs      1882:   else if (!strncasecmp (cssRule, "monospace", 9) &&
                   1883:       (quoteChar == EOS || quoteChar == cssRule[9]))
1.86      cvs      1884:     {
1.1       cvs      1885:       font.typed_data.value = STYLE_FONT_COURIER;
1.86      cvs      1886:       cssRule += 9;
1.92      cvs      1887:       if (quoteChar != EOS)
                   1888:        cssRule++;
1.86      cvs      1889:     }
1.1       cvs      1890:   else
                   1891:     /* unknown font name.  Skip it */
                   1892:     {
1.92      cvs      1893:       if (quoteChar != EOS)
1.54      cvs      1894:          cssRule = SkipQuotedString (cssRule, quoteChar);
1.86      cvs      1895:       else
1.1       cvs      1896:          cssRule = SkipWord (cssRule);
1.82      cvs      1897:       cssRule = SkipBlanksAndComments (cssRule);
                   1898:       if (*cssRule == ',')
1.1       cvs      1899:        {
1.86      cvs      1900:          cssRule++;
                   1901:          cssRule = ParseCSSFontFamily (element, tsch, context, cssRule, css, isHTML);
                   1902:          return (cssRule);
1.1       cvs      1903:        }
                   1904:     }
                   1905: 
                   1906:   if (font.typed_data.value != 0)
                   1907:      {
1.93      vatton   1908:        cssRule = SkipBlanksAndComments (cssRule);
1.133     vatton   1909:       if (*cssRule == ',')
                   1910:        {
                   1911:          cssRule++;
1.168     vatton   1912:          cssRule = SkipValue (NULL, cssRule);
1.133     vatton   1913:        }
1.93      vatton   1914:        /* install the new presentation */
1.116     vatton   1915:        if (DoApply)
1.117     vatton   1916:         {
                   1917:           if (tsch)
                   1918:             cssRule = CheckImportantRule (cssRule, context);
                   1919:           TtaSetStylePresentation (PRFont, element, tsch, context, font);
                   1920:         }
1.1       cvs      1921:      }
                   1922:   return (cssRule);
                   1923: }
                   1924: 
                   1925: /*----------------------------------------------------------------------
1.59      cvs      1926:    ParseCSSFontWeight: parse a CSS font weight string   
1.1       cvs      1927:    we expect the input string describing the attribute to be     
1.20      cvs      1928:    normal, bold, bolder, lighter, 100, 200, 300, ... 900, inherit.
1.1       cvs      1929:   ----------------------------------------------------------------------*/
1.79      cvs      1930: static char *ParseCSSFontWeight (Element element, PSchema tsch,
                   1931:                                 PresentationContext context, char *cssRule,
                   1932:                                 CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      1933: {
1.20      cvs      1934:    PresentationValue   weight;
1.1       cvs      1935: 
                   1936:    weight.typed_data.value = 0;
                   1937:    weight.typed_data.unit = STYLE_UNIT_REL;
                   1938:    weight.typed_data.real = FALSE;
1.82      cvs      1939:    cssRule = SkipBlanksAndComments (cssRule);
                   1940:    if (!strncasecmp (cssRule, "100", 3) && !isalpha (cssRule[3]))
1.1       cvs      1941:      {
                   1942:        weight.typed_data.value = -3;
                   1943:        cssRule = SkipWord (cssRule);
                   1944:      }
1.82      cvs      1945:    else if (!strncasecmp (cssRule, "200", 3) && !isalpha (cssRule[3]))
1.1       cvs      1946:      {
                   1947:        weight.typed_data.value = -2;
                   1948:        cssRule = SkipWord (cssRule);
                   1949:      }
1.82      cvs      1950:    else if (!strncasecmp (cssRule, "300", 3) && ! isalpha(cssRule[3]))
1.1       cvs      1951:      {
                   1952:        weight.typed_data.value = -1;
                   1953:        cssRule = SkipWord (cssRule);
                   1954:      }
1.82      cvs      1955:    else if (!strncasecmp (cssRule, "normal", 6) || (!strncasecmp (cssRule, "400", 3) && !isalpha (cssRule[3])))
1.1       cvs      1956:      {
                   1957:        weight.typed_data.value = 0;
                   1958:        cssRule = SkipWord (cssRule);
                   1959:      }
1.82      cvs      1960:    else if (!strncasecmp (cssRule, "500", 3) && !isalpha (cssRule[3]))
1.1       cvs      1961:      {
                   1962:        weight.typed_data.value = +1;
                   1963:        cssRule = SkipWord (cssRule);
                   1964:      }
1.82      cvs      1965:    else if (!strncasecmp (cssRule, "600", 3) && !isalpha (cssRule[3]))
1.1       cvs      1966:      {
                   1967:        weight.typed_data.value = +2;
                   1968:        cssRule = SkipWord (cssRule);
                   1969:      }
1.82      cvs      1970:    else if (!strncasecmp (cssRule, "bold", 4) || (!strncasecmp (cssRule, "700", 3) && !isalpha (cssRule[3])))
1.1       cvs      1971:      {
                   1972:        weight.typed_data.value = +3;
                   1973:        cssRule = SkipWord (cssRule);
                   1974:      }
1.82      cvs      1975:    else if (!strncasecmp (cssRule, "800", 3) && !isalpha (cssRule[3]))
1.1       cvs      1976:      {
                   1977:        weight.typed_data.value = +4;
                   1978:        cssRule = SkipWord (cssRule);
                   1979:      }
1.82      cvs      1980:    else if (!strncasecmp (cssRule, "900", 3) && !isalpha (cssRule[3]))
1.1       cvs      1981:      {
                   1982:        weight.typed_data.value = +5;
                   1983:        cssRule = SkipWord (cssRule);
                   1984:      }
1.82      cvs      1985:    else if (!strncasecmp (cssRule, "inherit", 7) || !strncasecmp (cssRule, "bolder", 6) || !strncasecmp (cssRule, "lighter", 7))
1.1       cvs      1986:      {
                   1987:      /* not implemented */
                   1988:      cssRule = SkipWord (cssRule);
                   1989:      return (cssRule);
                   1990:      }
                   1991:    else
                   1992:      return (cssRule);
                   1993: 
                   1994:    /*
1.20      cvs      1995:     * Here we have to reduce since only two font weight values are supported
1.1       cvs      1996:     * by the Thot presentation API.
                   1997:     */
1.20      cvs      1998:     if (weight.typed_data.value > 0)
                   1999:        weight.typed_data.value = STYLE_WEIGHT_BOLD;
                   2000:     else
                   2001:        weight.typed_data.value = STYLE_WEIGHT_NORMAL;
1.1       cvs      2002: 
                   2003:    /* install the new presentation */
1.116     vatton   2004:     if (DoApply)
1.117     vatton   2005:      {
                   2006:        if (tsch)
                   2007:         cssRule = CheckImportantRule (cssRule, context);
                   2008:        TtaSetStylePresentation (PRWeight, element, tsch, context, weight);
                   2009:      }
1.1       cvs      2010:    return (cssRule);
                   2011: }
                   2012: 
                   2013: /*----------------------------------------------------------------------
1.59      cvs      2014:    ParseCSSFontVariant: parse a CSS font variant string     
1.1       cvs      2015:    we expect the input string describing the attribute to be     
                   2016:    normal or small-caps
                   2017:   ----------------------------------------------------------------------*/
1.79      cvs      2018: static char *ParseCSSFontVariant (Element element, PSchema tsch,
                   2019:                                  PresentationContext context, char *cssRule,
                   2020:                                  CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      2021: {
                   2022:    PresentationValue   style;
                   2023: 
                   2024:    style.typed_data.value = 0;
                   2025:    style.typed_data.unit = STYLE_UNIT_REL;
                   2026:    style.typed_data.real = FALSE;
1.82      cvs      2027:    cssRule = SkipBlanksAndComments (cssRule);
                   2028:    if (!strncasecmp (cssRule, "small-caps", 10))
1.1       cvs      2029:      {
                   2030:        /* Not supported yet */
                   2031:        cssRule = SkipWord (cssRule);
                   2032:      }
1.82      cvs      2033:    else if (!strncasecmp (cssRule, "normal", 6))
1.1       cvs      2034:      {
                   2035:        /* Not supported yet */
                   2036:        cssRule = SkipWord (cssRule);
                   2037:      }
1.82      cvs      2038:    else if (!strncasecmp (cssRule, "inherit", 7))
1.1       cvs      2039:      {
                   2040:        /* Not supported yet */
                   2041:        cssRule = SkipWord (cssRule);
                   2042:      }
                   2043:    else
                   2044:        return (cssRule);
                   2045: 
                   2046:    return (cssRule);
                   2047: }
                   2048: 
                   2049: 
                   2050: /*----------------------------------------------------------------------
1.59      cvs      2051:    ParseCSSFontStyle: parse a CSS font style string     
1.1       cvs      2052:    we expect the input string describing the attribute to be     
                   2053:    italic, oblique or normal                         
                   2054:   ----------------------------------------------------------------------*/
1.79      cvs      2055: static char *ParseCSSFontStyle (Element element, PSchema tsch,
                   2056:                                PresentationContext context, char *cssRule,
                   2057:                                CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      2058: {
                   2059:    PresentationValue   style;
                   2060:    PresentationValue   size;
                   2061: 
                   2062:    style.typed_data.value = 0;
                   2063:    style.typed_data.unit = STYLE_UNIT_REL;
                   2064:    style.typed_data.real = FALSE;
                   2065:    size.typed_data.value = 0;
                   2066:    size.typed_data.unit = STYLE_UNIT_REL;
                   2067:    size.typed_data.real = FALSE;
1.82      cvs      2068:    cssRule = SkipBlanksAndComments (cssRule);
                   2069:    if (!strncasecmp (cssRule, "italic", 6))
1.1       cvs      2070:      {
                   2071:        style.typed_data.value = STYLE_FONT_ITALICS;
                   2072:        cssRule = SkipWord (cssRule);
                   2073:      }
1.82      cvs      2074:    else if (!strncasecmp (cssRule, "oblique", 7))
1.1       cvs      2075:      {
                   2076:        style.typed_data.value = STYLE_FONT_OBLIQUE;
                   2077:        cssRule = SkipWord (cssRule);
                   2078:      }
1.82      cvs      2079:    else if (!strncasecmp (cssRule, "normal", 6))
1.1       cvs      2080:      {
                   2081:        style.typed_data.value = STYLE_FONT_ROMAN;
                   2082:        cssRule = SkipWord (cssRule);
                   2083:      }
1.108     cvs      2084:    else if (!strncasecmp (cssRule, "inherit", 7))
                   2085:      {
                   2086:        /* not implemented */
                   2087:        cssRule = SkipWord (cssRule);
                   2088:        return (cssRule);
                   2089:      }
1.1       cvs      2090:    else
                   2091:      {
                   2092:        /* invalid font style */
1.108     cvs      2093:        return (cssRule);
1.1       cvs      2094:      }
                   2095: 
                   2096:    /*
                   2097:     * install the new presentation.
                   2098:     */
1.116     vatton   2099:    if (style.typed_data.value != 0 && DoApply)
1.117     vatton   2100:      {
                   2101:        if (tsch)
                   2102:         cssRule = CheckImportantRule (cssRule, context);
1.20      cvs      2103:         TtaSetStylePresentation (PRStyle, element, tsch, context, style);
1.117     vatton   2104:      }
1.116     vatton   2105:    if (size.typed_data.value != 0 && DoApply)
1.1       cvs      2106:      {
                   2107:        PresentationValue   previous_size;
                   2108: 
                   2109:        if (!TtaGetStylePresentation (PRSize, element, tsch, context, &previous_size))
                   2110:          {
                   2111:             /* !!!!!!!!!!!!!!!!!!!!!!!! Unite + relatif !!!!!!!!!!!!!!!! */
                   2112:             size.typed_data.value += previous_size.typed_data.value;
                   2113:             TtaSetStylePresentation (PRSize, element, tsch, context, size);
                   2114:          }
                   2115:        else
                   2116:          {
                   2117:             size.typed_data.value = 10;
                   2118:             TtaSetStylePresentation (PRSize, element, tsch, context, size);
                   2119:          }
                   2120:      }
                   2121:    return (cssRule);
                   2122: }
                   2123: 
                   2124: /*----------------------------------------------------------------------
1.59      cvs      2125:   ParseCSSFont: parse a CSS font attribute string
                   2126:   we expect the input string describing the attribute to be
                   2127:   !!!!!!                                  
1.1       cvs      2128:   ----------------------------------------------------------------------*/
1.79      cvs      2129: static char *ParseCSSFont (Element element, PSchema tsch,
                   2130:                           PresentationContext context, char *cssRule,
                   2131:                           CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      2132: {
1.79      cvs      2133:   char           *ptr;
1.93      vatton   2134:   int             skippedNL;
1.1       cvs      2135: 
1.82      cvs      2136:   cssRule = SkipBlanksAndComments (cssRule);
                   2137:   if (!strncasecmp (cssRule, "caption", 7))
1.1       cvs      2138:     ;
1.82      cvs      2139:   else if (!strncasecmp (cssRule, "icon", 4))
1.1       cvs      2140:     ;
1.82      cvs      2141:   else if (!strncasecmp (cssRule, "menu", 4))
1.1       cvs      2142:     ;
1.82      cvs      2143:   else if (!strncasecmp (cssRule, "message-box", 11))
1.1       cvs      2144:     ;
1.82      cvs      2145:   else if (!strncasecmp (cssRule, "small-caption", 13))
1.1       cvs      2146:     ;
1.82      cvs      2147:   else if (!strncasecmp (cssRule, "status-bar", 10))
1.1       cvs      2148:     ;
                   2149:   else
1.43      cvs      2150:     {
1.133     vatton   2151:       while (*cssRule != ';' && *cssRule != EOS)
1.43      cvs      2152:        {
1.72      cvs      2153:          ptr = cssRule;
1.93      vatton   2154:          skippedNL = NewLineSkipped;
1.72      cvs      2155:          cssRule = ParseCSSFontStyle (element, tsch, context, cssRule, css, isHTML);
                   2156:          if (ptr == cssRule)
1.93      vatton   2157:            {
                   2158:              NewLineSkipped = skippedNL;
                   2159:              cssRule = ParseCSSFontVariant (element, tsch, context, cssRule, css, isHTML);
                   2160:            }
1.72      cvs      2161:          if (ptr == cssRule)
1.93      vatton   2162:            {
                   2163:              NewLineSkipped = skippedNL;
                   2164:              cssRule = ParseCSSFontWeight (element, tsch, context, cssRule, css, isHTML);
                   2165:            }
1.72      cvs      2166:          if (ptr == cssRule)
1.93      vatton   2167:            {
                   2168:              NewLineSkipped = skippedNL;
                   2169:              cssRule = ParseCSSFontSize (element, tsch, context, cssRule, css, isHTML);
                   2170:            }
1.72      cvs      2171:          if (ptr == cssRule)
1.93      vatton   2172:            {
                   2173:              NewLineSkipped = skippedNL;
                   2174:              cssRule = ParseCSSFontFamily (element, tsch, context, cssRule, css, isHTML);
                   2175:            }
1.99      vatton   2176:          if (ptr == cssRule)
1.168     vatton   2177:            cssRule = SkipValue ("Invalid font value", cssRule);
1.82      cvs      2178:          cssRule = SkipBlanksAndComments (cssRule);
1.43      cvs      2179:        }
                   2180:     }
                   2181:   return (cssRule);
1.1       cvs      2182: }
                   2183: 
                   2184: /*----------------------------------------------------------------------
1.59      cvs      2185:   ParseCSSTextDecoration: parse a CSS text decor string   
                   2186:   we expect the input string describing the attribute to be     
1.109     cvs      2187:   underline, overline, line-through, blink or none.
1.1       cvs      2188:   ----------------------------------------------------------------------*/
1.79      cvs      2189: static char *ParseCSSTextDecoration (Element element, PSchema tsch,
                   2190:                                     PresentationContext context, char *cssRule,
                   2191:                                     CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      2192: {
                   2193:    PresentationValue   decor;
1.168     vatton   2194:    char               *ptr;
1.1       cvs      2195: 
                   2196:    decor.typed_data.value = 0;
                   2197:    decor.typed_data.unit = STYLE_UNIT_REL;
                   2198:    decor.typed_data.real = FALSE;
1.82      cvs      2199:    cssRule = SkipBlanksAndComments (cssRule);
1.142     quint    2200:    if (!strncasecmp (cssRule, "none", strlen ("none")))
                   2201:      {
                   2202:        decor.typed_data.value = NoUnderline;
                   2203:        cssRule = SkipWord (cssRule);
                   2204:      }
                   2205:    else if (!strncasecmp (cssRule, "underline", strlen ("underline")))
1.1       cvs      2206:      {
                   2207:        decor.typed_data.value = Underline;
                   2208:        cssRule = SkipWord (cssRule);
                   2209:      }
1.82      cvs      2210:    else if (!strncasecmp (cssRule, "overline", strlen ("overline")))
1.1       cvs      2211:      {
                   2212:        decor.typed_data.value = Overline;
                   2213:        cssRule = SkipWord (cssRule);
                   2214:      }
1.82      cvs      2215:    else if (!strncasecmp (cssRule, "line-through", strlen ("line-through")))
1.1       cvs      2216:      {
                   2217:        decor.typed_data.value = CrossOut;
                   2218:        cssRule = SkipWord (cssRule);
                   2219:      }
1.82      cvs      2220:    else if (!strncasecmp (cssRule, "blink", strlen ("blink")))
1.1       cvs      2221:      {
1.109     cvs      2222:        /* the blink text-decoration attribute is not supported */
1.1       cvs      2223:        cssRule = SkipWord (cssRule);
                   2224:      }
1.142     quint    2225:    else if (!strncasecmp (cssRule, "inherit", 7))
1.1       cvs      2226:      {
1.142     quint    2227:        cssRule = SkipWord (cssRule);
                   2228:        return (cssRule);
1.1       cvs      2229:      }
                   2230:    else
                   2231:      {
1.168     vatton   2232:        ptr = cssRule;
                   2233:        cssRule = SkipWord (cssRule);
                   2234:        CSSParseError ("Invalid text-decoration value", ptr, cssRule);
1.1       cvs      2235:        return (cssRule);
                   2236:      }
                   2237: 
                   2238:    /*
                   2239:     * install the new presentation.
                   2240:     */
1.116     vatton   2241:    if (decor.typed_data.value && DoApply)
1.1       cvs      2242:      {
1.117     vatton   2243:        if (tsch)
                   2244:         cssRule = CheckImportantRule (cssRule, context);
1.1       cvs      2245:        TtaSetStylePresentation (PRUnderline, element, tsch, context, decor);
                   2246:      }
                   2247:    return (cssRule);
                   2248: }
                   2249: 
                   2250: /*----------------------------------------------------------------------
1.59      cvs      2251:    ParseCSSHeight: parse a CSS height attribute
1.1       cvs      2252:   ----------------------------------------------------------------------*/
1.79      cvs      2253: static char *ParseCSSHeight (Element element, PSchema tsch,
1.93      vatton   2254:                             PresentationContext context, char *cssRule,
                   2255:                             CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      2256: {
1.117     vatton   2257:   PresentationValue   val;
1.168     vatton   2258:   char               *ptr;
1.93      vatton   2259: 
1.117     vatton   2260:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   2261:   ptr = cssRule;
1.117     vatton   2262:   /* first parse the attribute string */
1.164     quint    2263:   if (!strncasecmp (cssRule, "auto", 4))
                   2264:     {
                   2265:       val.typed_data.unit = STYLE_VALUE_AUTO;
                   2266:       val.typed_data.value = 0;
                   2267:       val.typed_data.real = FALSE;
                   2268:       cssRule = SkipWord (cssRule);
                   2269:     }
1.117     vatton   2270:   else
1.168     vatton   2271:     cssRule = ParseCSSUnit (cssRule, &val);
                   2272:   if (val.typed_data.value != 0 &&
                   2273:       (val.typed_data.unit == STYLE_UNIT_INVALID ||
                   2274:        val.typed_data.unit == STYLE_UNIT_BOX))
                   2275:     CSSParseError ("height value", ptr, cssRule);
                   2276:   else if (DoApply)
1.117     vatton   2277:     {
1.164     quint    2278:       if (tsch)
                   2279:        cssRule = CheckImportantRule (cssRule, context);
                   2280:       /* install the new presentation */
                   2281:       TtaSetStylePresentation (PRHeight, element, tsch, context, val);
1.117     vatton   2282:     }
                   2283:   return (cssRule);
1.1       cvs      2284: }
                   2285: 
                   2286: /*----------------------------------------------------------------------
1.59      cvs      2287:    ParseCSSWidth: parse a CSS width attribute
1.1       cvs      2288:   ----------------------------------------------------------------------*/
1.79      cvs      2289: static char *ParseCSSWidth (Element element, PSchema tsch,
1.78      cvs      2290:                              PresentationContext context,
1.79      cvs      2291:                              char *cssRule, CSSInfoPtr css,
1.78      cvs      2292:                              ThotBool isHTML)
1.1       cvs      2293: {
1.117     vatton   2294:   PresentationValue   val;
1.168     vatton   2295:   char               *ptr;
1.93      vatton   2296: 
1.117     vatton   2297:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   2298:   ptr = cssRule;
1.117     vatton   2299:   /* first parse the attribute string */
1.164     quint    2300:   if (!strncasecmp (cssRule, "auto", 4))
                   2301:     {
                   2302:       val.typed_data.unit = STYLE_VALUE_AUTO;
                   2303:       val.typed_data.value = 0;
                   2304:       val.typed_data.real = FALSE;
                   2305:       cssRule = SkipWord (cssRule);
                   2306:     }
1.117     vatton   2307:   else
1.164     quint    2308:       cssRule = ParseCSSUnit (cssRule, &val);
1.168     vatton   2309:   if (val.typed_data.value != 0 &&
                   2310:       (val.typed_data.unit == STYLE_UNIT_INVALID ||
                   2311:        val.typed_data.unit == STYLE_UNIT_BOX))
                   2312:     CSSParseError ("Invalid width value", ptr, cssRule);
                   2313:   else if (DoApply)
1.117     vatton   2314:     {
1.164     quint    2315:       if (tsch)
                   2316:        cssRule = CheckImportantRule (cssRule, context);
                   2317:       /* install the new presentation */
                   2318:       TtaSetStylePresentation (PRWidth, element, tsch, context, val);
1.117     vatton   2319:     }
                   2320:   return (cssRule);
1.1       cvs      2321: }
                   2322: 
                   2323: /*----------------------------------------------------------------------
1.59      cvs      2324:    ParseCSSMarginTop: parse a CSS margin-top attribute
1.1       cvs      2325:   ----------------------------------------------------------------------*/
1.79      cvs      2326: static char *ParseCSSMarginTop (Element element, PSchema tsch,
1.78      cvs      2327:                                  PresentationContext context,
1.79      cvs      2328:                                  char *cssRule, CSSInfoPtr css,
1.78      cvs      2329:                                  ThotBool isHTML)
1.1       cvs      2330: {
                   2331:   PresentationValue   margin;
1.168     vatton   2332:   char               *ptr;
1.1       cvs      2333:   
1.82      cvs      2334:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   2335:   ptr = cssRule;
1.1       cvs      2336:   /* first parse the attribute string */
1.164     quint    2337:   if (!strncasecmp (cssRule, "auto", 4))
                   2338:     {
                   2339:       margin.typed_data.unit = STYLE_VALUE_AUTO;
                   2340:       margin.typed_data.value = 0;
                   2341:       margin.typed_data.real = FALSE;
                   2342:       cssRule = SkipWord (cssRule);
                   2343:     }
                   2344:   else
1.168     vatton   2345:     cssRule = ParseCSSUnit (cssRule, &margin);
                   2346:   if (margin.typed_data.value != 0 &&
                   2347:       (margin.typed_data.unit == STYLE_UNIT_INVALID ||
                   2348:        margin.typed_data.unit == STYLE_UNIT_BOX))
1.169     vatton   2349:     CSSParseError ("Invalid margin-top value", ptr, cssRule);
1.168     vatton   2350:   else if (DoApply)
1.117     vatton   2351:      {
                   2352:        if (tsch)
                   2353:         cssRule = CheckImportantRule (cssRule, context);
                   2354:        TtaSetStylePresentation (PRMarginTop, element, tsch, context, margin);
                   2355:      }
1.1       cvs      2356:   return (cssRule);
                   2357: }
                   2358: 
                   2359: /*----------------------------------------------------------------------
1.59      cvs      2360:   ParseCSSMarginBottom: parse a CSS margin-bottom attribute
1.1       cvs      2361:   ----------------------------------------------------------------------*/
1.79      cvs      2362: static char *ParseCSSMarginBottom (Element element, PSchema tsch,
1.78      cvs      2363:                                     PresentationContext context,
1.79      cvs      2364:                                     char *cssRule, CSSInfoPtr css,
1.78      cvs      2365:                                     ThotBool isHTML)
1.1       cvs      2366: {
                   2367:   PresentationValue   margin;
1.168     vatton   2368:   char               *ptr;
1.1       cvs      2369:   
1.82      cvs      2370:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   2371:   ptr = cssRule;
1.1       cvs      2372:   /* first parse the attribute string */
1.164     quint    2373:   if (!strncasecmp (cssRule, "auto", 4))
                   2374:     {
                   2375:       margin.typed_data.unit = STYLE_VALUE_AUTO;
                   2376:       margin.typed_data.value = 0;
                   2377:       margin.typed_data.real = FALSE;
                   2378:       cssRule = SkipWord (cssRule);
                   2379:     }
                   2380:   else
1.168     vatton   2381:     cssRule = ParseCSSUnit (cssRule, &margin);
                   2382:   if (margin.typed_data.value != 0 &&
                   2383:       (margin.typed_data.unit == STYLE_UNIT_INVALID ||
                   2384:        margin.typed_data.unit == STYLE_UNIT_BOX))
1.169     vatton   2385:     CSSParseError ("Invalid margin-bottom value", ptr, cssRule);
1.168     vatton   2386:   else if (DoApply)
1.117     vatton   2387:      {
                   2388:        if (tsch)
                   2389:         cssRule = CheckImportantRule (cssRule, context);
                   2390:        TtaSetStylePresentation (PRMarginBottom, element, tsch, context, margin);
                   2391:      }
1.1       cvs      2392:   return (cssRule);
                   2393: }
                   2394: 
                   2395: /*----------------------------------------------------------------------
1.59      cvs      2396:   ParseCSSMarginLeft: parse a CSS margin-left attribute string
1.1       cvs      2397:   ----------------------------------------------------------------------*/
1.79      cvs      2398: static char *ParseCSSMarginLeft (Element element, PSchema tsch,
1.78      cvs      2399:                                   PresentationContext context,
1.79      cvs      2400:                                   char *cssRule, CSSInfoPtr css,
1.78      cvs      2401:                                   ThotBool isHTML)
1.1       cvs      2402: {
                   2403:   PresentationValue   margin;
1.168     vatton   2404:   char               *ptr;
1.1       cvs      2405:   
1.82      cvs      2406:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   2407:   ptr = cssRule;
1.1       cvs      2408:   /* first parse the attribute string */
1.164     quint    2409:   if (!strncasecmp (cssRule, "auto", 4))
                   2410:     {
                   2411:       margin.typed_data.unit = STYLE_VALUE_AUTO;
                   2412:       margin.typed_data.value = 0;
                   2413:       margin.typed_data.real = FALSE;
                   2414:       cssRule = SkipWord (cssRule);
                   2415:     }
                   2416:   else
1.168     vatton   2417:     cssRule = ParseCSSUnit (cssRule, &margin);
                   2418:   if (margin.typed_data.value != 0 &&
                   2419:       (margin.typed_data.unit == STYLE_UNIT_INVALID ||
                   2420:        margin.typed_data.unit == STYLE_UNIT_BOX))
1.169     vatton   2421:     CSSParseError ("Invalid margin-left value", ptr, cssRule);
1.168     vatton   2422:   else if (DoApply)
1.116     vatton   2423:   if (margin.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.117     vatton   2424:      {
                   2425:        if (tsch)
                   2426:         cssRule = CheckImportantRule (cssRule, context);
                   2427:        TtaSetStylePresentation (PRMarginLeft, element, tsch, context, margin);
                   2428:      }
1.1       cvs      2429:   return (cssRule);
                   2430: }
                   2431: 
                   2432: /*----------------------------------------------------------------------
1.59      cvs      2433:   ParseCSSMarginRight: parse a CSS margin-right attribute string
1.1       cvs      2434:   ----------------------------------------------------------------------*/
1.79      cvs      2435: static char *ParseCSSMarginRight (Element element, PSchema tsch,
1.78      cvs      2436:                                    PresentationContext context,
1.79      cvs      2437:                                    char *cssRule, CSSInfoPtr css,
1.78      cvs      2438:                                    ThotBool isHTML)
1.1       cvs      2439: {
                   2440:   PresentationValue   margin;
1.168     vatton   2441:   char               *ptr;
1.1       cvs      2442:   
1.82      cvs      2443:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   2444:   ptr = cssRule;
1.1       cvs      2445:   /* first parse the attribute string */
1.164     quint    2446:   if (!strncasecmp (cssRule, "auto", 4))
                   2447:     {
                   2448:       margin.typed_data.unit = STYLE_VALUE_AUTO;
                   2449:       margin.typed_data.value = 0;
                   2450:       margin.typed_data.real = FALSE;
                   2451:       cssRule = SkipWord (cssRule);
                   2452:     }
                   2453:   else
1.168     vatton   2454:     cssRule = ParseCSSUnit (cssRule, &margin);
                   2455:   if (margin.typed_data.value != 0 &&
                   2456:       (margin.typed_data.unit == STYLE_UNIT_INVALID ||
                   2457:        margin.typed_data.unit == STYLE_UNIT_BOX))
1.169     vatton   2458:     CSSParseError ("Invalid margin-right value", ptr, cssRule);
1.168     vatton   2459:   else if (DoApply)
1.117     vatton   2460:      {
                   2461:        if (tsch)
                   2462:         cssRule = CheckImportantRule (cssRule, context);
                   2463:        TtaSetStylePresentation (PRMarginRight, element, tsch, context, margin);
                   2464:      }
1.1       cvs      2465:   return (cssRule);
                   2466: }
                   2467: 
                   2468: /*----------------------------------------------------------------------
1.59      cvs      2469:   ParseCSSMargin: parse a CSS margin attribute string
1.1       cvs      2470:   ----------------------------------------------------------------------*/
1.79      cvs      2471: static char *ParseCSSMargin (Element element, PSchema tsch,
1.78      cvs      2472:                               PresentationContext context,
1.79      cvs      2473:                               char *cssRule, CSSInfoPtr css,
1.78      cvs      2474:                               ThotBool isHTML)
1.1       cvs      2475: {
1.79      cvs      2476:   char *ptrT, *ptrR, *ptrB, *ptrL;
1.93      vatton   2477:   int   skippedNL;
1.1       cvs      2478: 
1.82      cvs      2479:   ptrT = SkipBlanksAndComments (cssRule);
1.1       cvs      2480:   /* First parse Margin-Top */
                   2481:   ptrR = ParseCSSMarginTop (element, tsch, context, ptrT, css, isHTML);
1.82      cvs      2482:   ptrR = SkipBlanksAndComments (ptrR);
                   2483:   if (*ptrR == ';' || *ptrR == EOS || *ptrR == ',')
1.1       cvs      2484:     {
1.93      vatton   2485:       skippedNL = NewLineSkipped;
1.1       cvs      2486:       cssRule = ptrR;
                   2487:       /* apply the Margin-Top to all */
                   2488:       ptrR = ParseCSSMarginRight (element, tsch, context, ptrT, css, isHTML);
1.93      vatton   2489:       NewLineSkipped = skippedNL;
1.1       cvs      2490:       ptrR = ParseCSSMarginBottom (element, tsch, context, ptrT, css, isHTML);
1.93      vatton   2491:       NewLineSkipped = skippedNL;
1.1       cvs      2492:       ptrR = ParseCSSMarginLeft (element, tsch, context, ptrT, css, isHTML);
                   2493:     }
                   2494:   else
                   2495:     {
                   2496:       /* parse Margin-Right */
                   2497:       ptrB = ParseCSSMarginRight (element, tsch, context, ptrR, css, isHTML);
1.82      cvs      2498:       ptrB = SkipBlanksAndComments (ptrB);
                   2499:       if (*ptrB == ';' || *ptrB == EOS || *ptrB == ',')
1.1       cvs      2500:        {
1.93      vatton   2501:          skippedNL = NewLineSkipped;
1.1       cvs      2502:          cssRule = ptrB;
                   2503:          /* apply the Margin-Top to Margin-Bottom */
                   2504:          ptrB = ParseCSSMarginBottom (element, tsch, context, ptrT, css, isHTML);
1.93      vatton   2505:          NewLineSkipped = skippedNL;
1.1       cvs      2506:          /* apply the Margin-Right to Margin-Left */
                   2507:          ptrB = ParseCSSMarginLeft (element, tsch, context, ptrR, css, isHTML);
                   2508:        }
                   2509:       else
                   2510:        {
                   2511:          /* parse Margin-Bottom */
                   2512:          ptrL = ParseCSSMarginBottom (element, tsch, context, ptrB, css, isHTML);
1.82      cvs      2513:          ptrL = SkipBlanksAndComments (ptrL);
                   2514:          if (*ptrL == ';' || *ptrL == EOS || *ptrL == ',')
1.1       cvs      2515:            {
                   2516:              cssRule = ptrL;
                   2517:              /* apply the Margin-Right to Margin-Left */
                   2518:              ptrL = ParseCSSMarginLeft (element, tsch, context, ptrR, css, isHTML);
                   2519:            }
                   2520:          else
                   2521:            /* parse Margin-Left */
                   2522:            cssRule = ParseCSSMarginLeft (element, tsch, context, ptrL, css, isHTML);
1.82      cvs      2523:          cssRule = SkipBlanksAndComments (cssRule);
1.1       cvs      2524:        }
                   2525:     }
                   2526:   return (cssRule);
                   2527: }
                   2528: 
                   2529: /*----------------------------------------------------------------------
1.59      cvs      2530:    ParseCSSPaddingTop: parse a CSS PaddingTop attribute string
1.1       cvs      2531:   ----------------------------------------------------------------------*/
1.79      cvs      2532: static char *ParseCSSPaddingTop (Element element, PSchema tsch,
1.78      cvs      2533:                                 PresentationContext context,
1.79      cvs      2534:                                   char *cssRule, CSSInfoPtr css,
1.78      cvs      2535:                                   ThotBool isHTML)
1.1       cvs      2536: {
1.43      cvs      2537:   PresentationValue   padding;
1.168     vatton   2538:   char               *ptr;
1.43      cvs      2539:   
1.82      cvs      2540:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   2541:   ptr = cssRule;
1.43      cvs      2542:   /* first parse the attribute string */
                   2543:   cssRule = ParseCSSUnit (cssRule, &padding);
1.168     vatton   2544:   if (padding.typed_data.value != 0 &&
                   2545:       (padding.typed_data.unit == STYLE_UNIT_INVALID ||
                   2546:        padding.typed_data.unit == STYLE_UNIT_BOX))
                   2547:     {
1.169     vatton   2548:       CSSParseError ("Invalid padding-top value", ptr, cssRule);
1.168     vatton   2549:       padding.typed_data.value = 0;
                   2550:     }
                   2551:   else if (DoApply)
1.117     vatton   2552:      {
                   2553:        if (tsch)
                   2554:         cssRule = CheckImportantRule (cssRule, context);
                   2555:        TtaSetStylePresentation (PRPaddingTop, element, tsch, context, padding);
                   2556:      }
1.1       cvs      2557:   return (cssRule);
                   2558: }
                   2559: 
                   2560: /*----------------------------------------------------------------------
1.59      cvs      2561:   ParseCSSPaddingBottom: parse a CSS PaddingBottom attribute string
1.1       cvs      2562:   ----------------------------------------------------------------------*/
1.79      cvs      2563: static char *ParseCSSPaddingBottom (Element element, PSchema tsch,
1.78      cvs      2564:                                      PresentationContext context,
1.79      cvs      2565:                                      char *cssRule, CSSInfoPtr css,
1.78      cvs      2566:                                      ThotBool isHTML)
1.1       cvs      2567: {
1.43      cvs      2568:   PresentationValue   padding;
1.168     vatton   2569:   char               *ptr;
1.43      cvs      2570:   
1.82      cvs      2571:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   2572:   ptr = cssRule;
1.43      cvs      2573:   /* first parse the attribute string */
                   2574:   cssRule = ParseCSSUnit (cssRule, &padding);
1.168     vatton   2575:   if (padding.typed_data.value == 0)
1.166     vatton   2576:     padding.typed_data.unit = STYLE_UNIT_EM;
1.168     vatton   2577:   if (padding.typed_data.value != 0 &&
                   2578:       (padding.typed_data.unit == STYLE_UNIT_INVALID ||
                   2579:        padding.typed_data.unit == STYLE_UNIT_BOX))
                   2580:     {
1.169     vatton   2581:       CSSParseError ("Invalid padding-bottom value", ptr, cssRule);
1.168     vatton   2582:       padding.typed_data.value = 0;
                   2583:     }
                   2584:   else if (DoApply)
1.117     vatton   2585:      {
                   2586:        if (tsch)
                   2587:         cssRule = CheckImportantRule (cssRule, context);
                   2588:        TtaSetStylePresentation (PRPaddingBottom, element, tsch, context, padding);
                   2589:      }
1.1       cvs      2590:   return (cssRule);
                   2591: }
                   2592: 
                   2593: /*----------------------------------------------------------------------
1.59      cvs      2594:   ParseCSSPaddingLeft: parse a CSS PaddingLeft attribute string.
1.1       cvs      2595:   ----------------------------------------------------------------------*/
1.79      cvs      2596: static char *ParseCSSPaddingLeft (Element element, PSchema tsch,
1.78      cvs      2597:                                    PresentationContext context,
1.79      cvs      2598:                                    char *cssRule, CSSInfoPtr css,
1.78      cvs      2599:                                    ThotBool isHTML)
1.1       cvs      2600: {
1.43      cvs      2601:   PresentationValue   padding;
1.168     vatton   2602:   char               *ptr;
1.43      cvs      2603:   
1.82      cvs      2604:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   2605:   ptr = cssRule;
1.43      cvs      2606:   /* first parse the attribute string */
                   2607:   cssRule = ParseCSSUnit (cssRule, &padding);
1.168     vatton   2608:   if (padding.typed_data.value == 0)
1.166     vatton   2609:     padding.typed_data.unit = STYLE_UNIT_EM;
1.168     vatton   2610:   if (padding.typed_data.value != 0 &&
                   2611:       (padding.typed_data.unit == STYLE_UNIT_INVALID ||
                   2612:        padding.typed_data.unit == STYLE_UNIT_BOX))
                   2613:     {
1.169     vatton   2614:       CSSParseError ("Invalid padding-left value", ptr, cssRule);
1.168     vatton   2615:       padding.typed_data.value = 0;
                   2616:     }
                   2617:   else if (DoApply)
1.117     vatton   2618:     {
                   2619:       if (tsch)
                   2620:        cssRule = CheckImportantRule (cssRule, context);
1.43      cvs      2621:       TtaSetStylePresentation (PRPaddingLeft, element, tsch, context, padding);
1.117     vatton   2622:     }
1.1       cvs      2623:   return (cssRule);
                   2624: }
                   2625: 
                   2626: /*----------------------------------------------------------------------
1.59      cvs      2627:   ParseCSSPaddingRight: parse a CSS PaddingRight attribute string.
1.1       cvs      2628:   ----------------------------------------------------------------------*/
1.79      cvs      2629: static char *ParseCSSPaddingRight (Element element, PSchema tsch,
1.78      cvs      2630:                                     PresentationContext context,
1.79      cvs      2631:                                     char *cssRule, CSSInfoPtr css,
1.78      cvs      2632:                                     ThotBool isHTML)
1.1       cvs      2633: {
1.43      cvs      2634:   PresentationValue   padding;
1.168     vatton   2635:   char               *ptr;
1.43      cvs      2636:   
1.82      cvs      2637:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   2638:   ptr = cssRule;
1.43      cvs      2639:   /* first parse the attribute string */
                   2640:   cssRule = ParseCSSUnit (cssRule, &padding);
1.168     vatton   2641:   if (padding.typed_data.value == 0)
1.166     vatton   2642:     padding.typed_data.unit = STYLE_UNIT_EM;
1.168     vatton   2643:   if (padding.typed_data.value != 0 &&
                   2644:       (padding.typed_data.unit == STYLE_UNIT_INVALID ||
                   2645:        padding.typed_data.unit == STYLE_UNIT_BOX))
                   2646:     {
1.169     vatton   2647:       CSSParseError ("Invalid padding-right value", ptr, cssRule);
1.168     vatton   2648:       padding.typed_data.value = 0;
                   2649:     }
                   2650:   else if (DoApply)
1.117     vatton   2651:     {
                   2652:       if (tsch)
                   2653:        cssRule = CheckImportantRule (cssRule, context);
1.43      cvs      2654:       TtaSetStylePresentation (PRPaddingRight, element, tsch, context, padding);
1.117     vatton   2655:     }
1.1       cvs      2656:   return (cssRule);
                   2657: }
                   2658: 
                   2659: /*----------------------------------------------------------------------
1.59      cvs      2660:    ParseCSSPadding: parse a CSS padding attribute string. 
1.1       cvs      2661:   ----------------------------------------------------------------------*/
1.79      cvs      2662: static char *ParseCSSPadding (Element element, PSchema tsch,
1.78      cvs      2663:                                PresentationContext context,
1.79      cvs      2664:                                char *cssRule, CSSInfoPtr css,
1.78      cvs      2665:                                ThotBool isHTML)
1.1       cvs      2666: {
1.79      cvs      2667:   char *ptrT, *ptrR, *ptrB, *ptrL;
1.93      vatton   2668:   int   skippedNL;
1.43      cvs      2669: 
1.82      cvs      2670:   ptrT = SkipBlanksAndComments (cssRule);
1.43      cvs      2671:   /* First parse Padding-Top */
                   2672:   ptrR = ParseCSSPaddingTop (element, tsch, context, ptrT, css, isHTML);
1.82      cvs      2673:   ptrR = SkipBlanksAndComments (ptrR);
                   2674:   if (*ptrR == ';' || *ptrR == EOS || *ptrR == ',')
1.43      cvs      2675:     {
1.93      vatton   2676:       skippedNL = NewLineSkipped;
1.43      cvs      2677:       cssRule = ptrR;
                   2678:       /* apply the Padding-Top to all */
                   2679:       ptrR = ParseCSSPaddingRight (element, tsch, context, ptrT, css, isHTML);
1.93      vatton   2680:       NewLineSkipped = skippedNL;
1.43      cvs      2681:       ptrR = ParseCSSPaddingBottom (element, tsch, context, ptrT, css, isHTML);
1.93      vatton   2682:       NewLineSkipped = skippedNL;
1.43      cvs      2683:       ptrR = ParseCSSPaddingLeft (element, tsch, context, ptrT, css, isHTML);
                   2684:     }
                   2685:   else
                   2686:     {
                   2687:       /* parse Padding-Right */
                   2688:       ptrB = ParseCSSPaddingRight (element, tsch, context, ptrR, css, isHTML);
1.82      cvs      2689:       ptrB = SkipBlanksAndComments (ptrB);
                   2690:       if (*ptrB == ';' || *ptrB == EOS || *ptrB == ',')
1.43      cvs      2691:        {
1.93      vatton   2692:          skippedNL = NewLineSkipped;
1.43      cvs      2693:          cssRule = ptrB;
                   2694:          /* apply the Padding-Top to Padding-Bottom */
                   2695:          ptrB = ParseCSSPaddingBottom (element, tsch, context, ptrT, css, isHTML);
1.93      vatton   2696:          NewLineSkipped = skippedNL;
1.43      cvs      2697:          /* apply the Padding-Right to Padding-Left */
                   2698:          ptrB = ParseCSSPaddingLeft (element, tsch, context, ptrR, css, isHTML);
                   2699:        }
                   2700:       else
                   2701:        {
                   2702:          /* parse Padding-Bottom */
                   2703:          ptrL = ParseCSSPaddingBottom (element, tsch, context, ptrB, css, isHTML);
1.82      cvs      2704:          ptrL = SkipBlanksAndComments (ptrL);
                   2705:          if (*ptrL == ';' || *ptrL == EOS || *ptrL == ',')
1.43      cvs      2706:            {
                   2707:              cssRule = ptrL;
                   2708:              /* apply the Padding-Right to Padding-Left */
                   2709:              ptrL = ParseCSSPaddingLeft (element, tsch, context, ptrR, css, isHTML);
                   2710:            }
                   2711:          else
                   2712:            /* parse Padding-Left */
                   2713:            cssRule = ParseCSSPaddingLeft (element, tsch, context, ptrL, css, isHTML);
1.82      cvs      2714:          cssRule = SkipBlanksAndComments (cssRule);
1.43      cvs      2715:        }
                   2716:     }
1.1       cvs      2717:   return (cssRule);
                   2718: }
                   2719: 
                   2720: /*----------------------------------------------------------------------
1.59      cvs      2721:    ParseCSSForeground: parse a CSS foreground attribute 
1.1       cvs      2722:   ----------------------------------------------------------------------*/
1.79      cvs      2723: static char *ParseCSSForeground (Element element, PSchema tsch,
1.78      cvs      2724:                                          PresentationContext context,
1.79      cvs      2725:                                          char *cssRule,
1.78      cvs      2726:                                          CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      2727: {
1.117     vatton   2728:   PresentationValue   best;
1.1       cvs      2729: 
1.117     vatton   2730:   cssRule = ParseCSSColor (cssRule, &best);
                   2731:   if (best.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
                   2732:      {
                   2733:        if (tsch)
                   2734:         cssRule = CheckImportantRule (cssRule, context);
                   2735:        /* install the new presentation */
                   2736:        TtaSetStylePresentation (PRForeground, element, tsch, context, best);
                   2737:      }
1.1       cvs      2738:    return (cssRule);
                   2739: }
                   2740: 
                   2741: /*----------------------------------------------------------------------
1.59      cvs      2742:   ParseCSSBackgroundColor: parse a CSS background color attribute 
1.1       cvs      2743:   ----------------------------------------------------------------------*/
1.79      cvs      2744: static char *ParseCSSBackgroundColor (Element element, PSchema tsch,
1.78      cvs      2745:                                        PresentationContext context,
1.79      cvs      2746:                                        char *cssRule,
1.78      cvs      2747:                                        CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      2748: {
                   2749:   PresentationValue     best;
                   2750: 
                   2751:   best.typed_data.unit = STYLE_UNIT_INVALID;
                   2752:   best.typed_data.real = FALSE;
1.82      cvs      2753:   if (!strncasecmp (cssRule, "transparent", strlen ("transparent")))
1.1       cvs      2754:     {
                   2755:       best.typed_data.value = STYLE_PATTERN_NONE;
                   2756:       best.typed_data.unit = STYLE_UNIT_REL;
1.116     vatton   2757:       if (DoApply)
1.117     vatton   2758:        {
                   2759:          if (tsch)
                   2760:            cssRule = CheckImportantRule (cssRule, context);
                   2761:          TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
                   2762:        }
1.65      cvs      2763:       cssRule = SkipWord (cssRule);
1.1       cvs      2764:     }
                   2765:   else
                   2766:     {
                   2767:       cssRule = ParseCSSColor (cssRule, &best);
1.116     vatton   2768:       if (best.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.1       cvs      2769:        {
1.117     vatton   2770:          if (tsch)
                   2771:            cssRule = CheckImportantRule (cssRule, context);
1.1       cvs      2772:          /* install the new presentation. */
                   2773:          TtaSetStylePresentation (PRBackground, element, tsch, context, best);
1.59      cvs      2774:          /* thot specificity: need to set fill pattern for background color */
1.1       cvs      2775:          best.typed_data.value = STYLE_PATTERN_BACKGROUND;
                   2776:          best.typed_data.unit = STYLE_UNIT_REL;
                   2777:          TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
                   2778:          best.typed_data.value = 1;
                   2779:          best.typed_data.unit = STYLE_UNIT_REL;
                   2780:          TtaSetStylePresentation (PRShowBox, element, tsch, context, best);
                   2781:        }
                   2782:     }
                   2783:   return (cssRule);
                   2784: }
                   2785: 
1.63      cvs      2786: /*----------------------------------------------------------------------
1.65      cvs      2787:   ParseSVGStroke: parse a SVG stroke property
                   2788:   ----------------------------------------------------------------------*/
1.79      cvs      2789: static char *ParseSVGStroke (Element element, PSchema tsch,
                   2790:                             PresentationContext context, char *cssRule,
                   2791:                             CSSInfoPtr css, ThotBool isHTML)
1.65      cvs      2792: {
                   2793:   PresentationValue     best;
                   2794: 
                   2795:   best.typed_data.unit = STYLE_UNIT_INVALID;
                   2796:   best.typed_data.real = FALSE;
1.82      cvs      2797:   if (!strncasecmp (cssRule, "none", 4))
1.65      cvs      2798:     {
                   2799:       best.typed_data.value = -2;  /* -2 means transparent */
                   2800:       best.typed_data.unit = STYLE_UNIT_REL;
1.116     vatton   2801:       if (DoApply)
1.117     vatton   2802:        {
                   2803:          if (tsch)
                   2804:            cssRule = CheckImportantRule (cssRule, context);
                   2805:          TtaSetStylePresentation (PRForeground, element, tsch, context, best);
                   2806:        }
1.65      cvs      2807:       cssRule = SkipWord (cssRule);
                   2808:     }
                   2809:   else
                   2810:     {
                   2811:       cssRule = ParseCSSColor (cssRule, &best);
1.116     vatton   2812:       if (best.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.117     vatton   2813:        {
                   2814:          if (tsch)
                   2815:            cssRule = CheckImportantRule (cssRule, context);
                   2816:          /* install the new presentation */
                   2817:          TtaSetStylePresentation (PRForeground, element, tsch, context, best);
                   2818:        }
1.65      cvs      2819:     }
                   2820:   return (cssRule);
                   2821: }
                   2822: 
                   2823: /*----------------------------------------------------------------------
1.63      cvs      2824:   ParseSVGFill: parse a SVG fill property
                   2825:   ----------------------------------------------------------------------*/
1.79      cvs      2826: static char *ParseSVGFill (Element element, PSchema tsch,
                   2827:                           PresentationContext context, char *cssRule,
                   2828:                           CSSInfoPtr css, ThotBool isHTML)
1.63      cvs      2829: {
                   2830:   PresentationValue     best;
                   2831: 
                   2832:   best.typed_data.unit = STYLE_UNIT_INVALID;
                   2833:   best.typed_data.real = FALSE;
1.82      cvs      2834:   if (!strncasecmp (cssRule, "none", 4))
1.63      cvs      2835:     {
                   2836:       best.typed_data.value = STYLE_PATTERN_NONE;
                   2837:       best.typed_data.unit = STYLE_UNIT_REL;
1.116     vatton   2838:       if (DoApply)
1.117     vatton   2839:        {
                   2840:          if (tsch)
                   2841:            cssRule = CheckImportantRule (cssRule, context);
                   2842:          TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
                   2843:        }
1.65      cvs      2844:       cssRule = SkipWord (cssRule);
1.63      cvs      2845:     }
                   2846:   else
                   2847:     {
                   2848:       cssRule = ParseCSSColor (cssRule, &best);
1.162     quint    2849:       if (best.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.63      cvs      2850:        {
1.117     vatton   2851:          if (tsch)
                   2852:            cssRule = CheckImportantRule (cssRule, context);
1.63      cvs      2853:          /* install the new presentation. */
                   2854:          TtaSetStylePresentation (PRBackground, element, tsch, context, best);
                   2855:          /* thot specificity: need to set fill pattern for background color */
                   2856:          best.typed_data.value = STYLE_PATTERN_BACKGROUND;
                   2857:          best.typed_data.unit = STYLE_UNIT_REL;
                   2858:          TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
                   2859:        }
                   2860:     }
                   2861:   return (cssRule);
                   2862: }
1.161     quint    2863: 
1.155     cheyroul 2864: /*----------------------------------------------------------------------
                   2865:   ParseSVGOpacity: parse a SVG fill property
                   2866:   ----------------------------------------------------------------------*/
                   2867: static char *ParseSVGOpacity (Element element, PSchema tsch,
                   2868:                              PresentationContext context, char *cssRule,
                   2869:                              CSSInfoPtr css, ThotBool isHTML)
                   2870: {
                   2871:   PresentationValue     best;
1.63      cvs      2872: 
1.155     cheyroul 2873:   best.typed_data.unit = STYLE_UNIT_INVALID;
                   2874:   best.typed_data.real = FALSE;
                   2875:   cssRule = ParseClampedUnit (cssRule, &best);
                   2876:   if (DoApply)
                   2877:     {
                   2878:       if (tsch)
                   2879:        cssRule = CheckImportantRule (cssRule, context);
                   2880:       /* install the new presentation. */
                   2881:       TtaSetStylePresentation (PROpacity, element,
                   2882:                               tsch, context, best);
                   2883:     }
                   2884:   return (cssRule);
                   2885: }
1.170     cheyroul 2886: /*----------------------------------------------------------------------
                   2887:   ParseSVGOpacity: parse a SVG fill property
                   2888:   ----------------------------------------------------------------------*/
                   2889: static char *ParseSVGStrokeOpacity (Element element, PSchema tsch,
                   2890:                              PresentationContext context, char *cssRule,
                   2891:                              CSSInfoPtr css, ThotBool isHTML)
                   2892: {
                   2893:   PresentationValue     best;
1.161     quint    2894: 
1.170     cheyroul 2895:   best.typed_data.unit = STYLE_UNIT_INVALID;
                   2896:   best.typed_data.real = FALSE;
                   2897:   cssRule = ParseClampedUnit (cssRule, &best);
                   2898:   if (DoApply)
                   2899:     {
                   2900:       if (tsch)
                   2901:        cssRule = CheckImportantRule (cssRule, context);
                   2902:       /* install the new presentation. */
                   2903:       TtaSetStylePresentation (PRStrokeOpacity, element,
                   2904:                               tsch, context, best);
                   2905:     }
                   2906:   return (cssRule);
                   2907: }
                   2908: /*----------------------------------------------------------------------
                   2909:   ParseSVGOpacity: parse a SVG fill property
                   2910:   ----------------------------------------------------------------------*/
                   2911: static char *ParseSVGFillOpacity (Element element, PSchema tsch,
                   2912:                              PresentationContext context, char *cssRule,
                   2913:                              CSSInfoPtr css, ThotBool isHTML)
                   2914: {
                   2915:   PresentationValue     best;
                   2916: 
                   2917:   best.typed_data.unit = STYLE_UNIT_INVALID;
                   2918:   best.typed_data.real = FALSE;
                   2919:   cssRule = ParseClampedUnit (cssRule, &best);
                   2920:   if (DoApply)
                   2921:     {
                   2922:       if (tsch)
                   2923:        cssRule = CheckImportantRule (cssRule, context);
                   2924:       /* install the new presentation. */
                   2925:       TtaSetStylePresentation (PRFillOpacity, element,
                   2926:                               tsch, context, best);
                   2927:     }
                   2928:   return (cssRule);
                   2929: }
1.1       cvs      2930: /*----------------------------------------------------------------------
1.59      cvs      2931:   ParseCSSBackgroundImageCallback: Callback called asynchronously by
                   2932:   FetchImage when a background image has been fetched.
1.1       cvs      2933:   ----------------------------------------------------------------------*/
1.82      cvs      2934: void ParseCSSBackgroundImageCallback (Document doc, Element element,
                   2935:                                      char *file, void *extra)
1.1       cvs      2936: {
1.82      cvs      2937:   DisplayMode                dispMode;
                   2938:   BackgroundImageCallbackPtr callblock;
                   2939:   Element                    el;
                   2940:   PSchema                    tsch;
                   2941:   PresentationContext        context;
                   2942:   PresentationValue          image;
                   2943:   PresentationValue          value;
1.1       cvs      2944: 
1.82      cvs      2945:   callblock = (BackgroundImageCallbackPtr) extra;
1.34      cvs      2946:   if (callblock == NULL)
                   2947:     return;
1.1       cvs      2948: 
1.34      cvs      2949:   /* avoid too many redisplay */
                   2950:   dispMode = TtaGetDisplayMode (doc);
                   2951:   if (dispMode == DisplayImmediately)
                   2952:     TtaSetDisplayMode (doc, DeferredDisplay);
                   2953: 
                   2954:   el = callblock->el;
                   2955:   tsch = callblock->tsch;
                   2956:   context = &callblock->context.specific;
                   2957: 
                   2958:   /* Ok the image was fetched, finish the background-image handling */
                   2959:   image.pointer = file;
                   2960:   TtaSetStylePresentation (PRBackgroundPicture, el, tsch, context, image);
1.1       cvs      2961: 
1.70      cvs      2962:   /* enforce the showbox */
1.34      cvs      2963:   value.typed_data.value = 1;
                   2964:   value.typed_data.unit = STYLE_UNIT_REL;
                   2965:   value.typed_data.real = FALSE;
                   2966:   TtaSetStylePresentation (PRShowBox, el, tsch, context, value);
                   2967: 
                   2968:   TtaFreeMemory (callblock);
                   2969:   /* restore the display mode */
                   2970:   if (dispMode == DisplayImmediately)
                   2971:     TtaSetDisplayMode (doc, dispMode);
1.1       cvs      2972: }
                   2973: 
                   2974: /*----------------------------------------------------------------------
                   2975:    GetCSSBackgroundURL searches a CSS BackgroundImage url within
                   2976:    the styleString.
                   2977:    Returns NULL or a new allocated url string.
                   2978:   ----------------------------------------------------------------------*/
1.79      cvs      2979: char *GetCSSBackgroundURL (char *styleString)
1.1       cvs      2980: {
1.79      cvs      2981:   char            *b, *e, *ptr;
                   2982:   int              len;
1.1       cvs      2983: 
                   2984:   ptr = NULL;
1.82      cvs      2985:   b = strstr (styleString, "url");
1.1       cvs      2986:   if (b != NULL)
                   2987:     {
                   2988:       b += 3;
1.82      cvs      2989:       b = SkipBlanksAndComments (b);
                   2990:       if (*b == '(')
1.1       cvs      2991:        {
                   2992:          b++;
1.82      cvs      2993:          b = SkipBlanksAndComments (b);
1.161     quint    2994:          /*** Escaped quotes are not handled. See function SkipQuotedString */
1.82      cvs      2995:          if (*b == '"')
1.1       cvs      2996:            {
                   2997:              b++;
                   2998:              /* search the url end */
                   2999:              e = b;
1.82      cvs      3000:              while (*e != EOS && *e != '"')
1.1       cvs      3001:                e++;
                   3002:            }
1.161     quint    3003:          else if (*b == '\'')
                   3004:            {
                   3005:              b++;
                   3006:              /* search the url end */
                   3007:              e = b;
                   3008:              while (*e != EOS && *e != '\'')
                   3009:                e++;
                   3010:            }
1.1       cvs      3011:          else
                   3012:            {
                   3013:              /* search the url end */
                   3014:              e = b;
1.82      cvs      3015:              while (*e != EOS && *e != ')')
1.1       cvs      3016:                e++;
                   3017:            }
1.82      cvs      3018:          if (*e != EOS)
1.1       cvs      3019:            {
                   3020:              len = (int)(e - b);
1.82      cvs      3021:              ptr = (char*) TtaGetMemory (len+1);
                   3022:              strncpy (ptr, b, len);
                   3023:              ptr[len] = EOS;
1.1       cvs      3024:            }
                   3025:        }
                   3026:     }
                   3027:   return (ptr);
                   3028: }
                   3029: 
                   3030: 
                   3031: /*----------------------------------------------------------------------
1.59      cvs      3032:   ParseCSSBackgroundImage: parse a CSS BackgroundImage attribute string.
1.1       cvs      3033:   ----------------------------------------------------------------------*/
1.79      cvs      3034: static char *ParseCSSBackgroundImage (Element element, PSchema tsch,
                   3035:                                      PresentationContext context,
                   3036:                                      char *cssRule, CSSInfoPtr css,
                   3037:                                      ThotBool isHTML)
1.1       cvs      3038: {
1.149     vatton   3039:   GenericContext             ctxt = (GenericContext) context;
1.49      cvs      3040:   Element                    el;
1.1       cvs      3041:   BackgroundImageCallbackPtr callblock;
1.49      cvs      3042:   PresentationValue          image, value;
1.79      cvs      3043:   char                      *url;
1.82      cvs      3044:   char                      *bg_image;
1.79      cvs      3045:   char                       saved;
                   3046:   char                      *base;
                   3047:   char                       tempname[MAX_LENGTH];
                   3048:   char                       imgname[MAX_LENGTH];
1.148     vatton   3049: 
1.163     quint    3050:   if (element)
1.148     vatton   3051:     el = element;
1.163     quint    3052:   else
                   3053:     /* default element for FetchImage */
                   3054:     el = TtaGetMainRoot (context->doc);
                   3055:     
1.1       cvs      3056:   url = NULL;
1.82      cvs      3057:   cssRule = SkipBlanksAndComments (cssRule);
1.161     quint    3058:   if (!strncasecmp (cssRule, "none", 4))
                   3059:     {
                   3060:       image.pointer = NULL;
                   3061:       TtaSetStylePresentation (PRBackgroundPicture, element, tsch, context,
                   3062:                               image);
                   3063:     }
                   3064:   else if (!strncasecmp (cssRule, "url", 3))
1.1       cvs      3065:     {  
                   3066:       cssRule += 3;
1.82      cvs      3067:       cssRule = SkipBlanksAndComments (cssRule);
1.1       cvs      3068:       if (*cssRule == '(')
                   3069:        {
                   3070:          cssRule++;
1.82      cvs      3071:          cssRule = SkipBlanksAndComments (cssRule);
1.161     quint    3072:          /*** Escaped quotes are not handled. See function SkipQuotedString */
1.1       cvs      3073:          if (*cssRule == '"')
                   3074:            {
                   3075:              cssRule++;
                   3076:              base = cssRule;
1.82      cvs      3077:              while (*cssRule != EOS && *cssRule != '"')
1.1       cvs      3078:                cssRule++;
                   3079:            }
1.161     quint    3080:          else if (*cssRule == '\'')
                   3081:            {
                   3082:              cssRule++;
                   3083:              base = cssRule;
                   3084:              while (*cssRule != EOS && *cssRule != '\'')
                   3085:                cssRule++;
                   3086:            }
1.1       cvs      3087:          else
                   3088:            {
                   3089:              base = cssRule;
                   3090:              while (*cssRule != EOS && *cssRule != ')')
                   3091:                cssRule++;
                   3092:            }
                   3093:          saved = *cssRule;
1.82      cvs      3094:          *cssRule = EOS;
                   3095:          url = TtaStrdup (base);
1.1       cvs      3096:          *cssRule = saved;
1.161     quint    3097:          if (saved == '"' || saved == '\'')
                   3098:            /* we need to skip the quote character and possinble spaces */
                   3099:            {
                   3100:              cssRule++;            
                   3101:              cssRule = SkipBlanksAndComments (cssRule);
                   3102:            }
1.1       cvs      3103:        }
                   3104:       cssRule++;
                   3105: 
                   3106:       if (context->destroy)
                   3107:        {
                   3108:          /* remove the background image PRule */
                   3109:          image.pointer = NULL;
                   3110:          TtaSetStylePresentation (PRBackgroundPicture, element, tsch, context, image);
                   3111:          if (TtaGetStylePresentation (PRFillPattern, element, tsch, context, &value) < 0)
                   3112:            {
                   3113:              /* there is no FillPattern rule -> remove ShowBox rule */
                   3114:              value.typed_data.value = 1;
                   3115:              value.typed_data.unit = STYLE_UNIT_REL;
                   3116:              value.typed_data.real = FALSE;
                   3117:              TtaSetStylePresentation (PRShowBox, element, tsch, context, value);
                   3118:            }
                   3119:        }
                   3120:       else if (url)
                   3121:        {
1.30      cvs      3122:          bg_image = TtaGetEnvString ("ENABLE_BG_IMAGES");
1.82      cvs      3123:          if (bg_image == NULL || !strcasecmp (bg_image, "yes"))
1.161     quint    3124:            /* background images are enabled */
1.1       cvs      3125:            {
                   3126:              callblock = (BackgroundImageCallbackPtr) TtaGetMemory(sizeof(BackgroundImageCallbackBlock));
                   3127:              if (callblock != NULL)
                   3128:                {
                   3129:                  callblock->el = element;
                   3130:                  callblock->tsch = tsch;
                   3131:                  if (element == NULL)
1.149     vatton   3132:                    memcpy (&callblock->context.generic, ctxt,
                   3133:                            sizeof (GenericContextBlock));
1.18      cvs      3134:                  else
1.149     vatton   3135:                    memcpy (&callblock->context.specific, context,
                   3136:                            sizeof(PresentationContextBlock));
1.18      cvs      3137: 
                   3138:                  /* check if the image url is related to an external CSS */
                   3139:                  if (css != NULL && css->category == CSS_EXTERNAL_STYLE)
                   3140:                    {
                   3141:                      NormalizeURL (url, 0, tempname, imgname, css->url);
                   3142:                      /* fetch and display background image of element */
1.161     quint    3143:                      FetchImage (context->doc, el, tempname, AMAYA_LOAD_IMAGE,
                   3144:                                  ParseCSSBackgroundImageCallback, callblock);
1.18      cvs      3145:                    }
                   3146:                  else
1.161     quint    3147:                    FetchImage (context->doc, el, url, AMAYA_LOAD_IMAGE,
                   3148:                                ParseCSSBackgroundImageCallback, callblock);
1.18      cvs      3149:                }
                   3150:            }
                   3151: 
                   3152:          if (url)
                   3153:            TtaFreeMemory (url);
                   3154:        }
                   3155:     }
                   3156:   return (cssRule);
                   3157: }
                   3158: 
                   3159: /*----------------------------------------------------------------------
1.59      cvs      3160:   ParseCSSBackgroundRepeat: parse a CSS BackgroundRepeat attribute string.
1.18      cvs      3161:   ----------------------------------------------------------------------*/
1.79      cvs      3162: static char *ParseCSSBackgroundRepeat (Element element, PSchema tsch,
1.97      vatton   3163:                                       PresentationContext context,
                   3164:                                       char *cssRule, CSSInfoPtr css, ThotBool isHTML)
1.18      cvs      3165: {
                   3166:   PresentationValue   repeat;
                   3167: 
                   3168:   repeat.typed_data.value = STYLE_REALSIZE;
                   3169:   repeat.typed_data.unit = STYLE_UNIT_REL;
                   3170:   repeat.typed_data.real = FALSE;
1.82      cvs      3171:   cssRule = SkipBlanksAndComments (cssRule);
                   3172:   if (!strncasecmp (cssRule, "no-repeat", 9))
1.18      cvs      3173:     repeat.typed_data.value = STYLE_REALSIZE;
1.82      cvs      3174:   else if (!strncasecmp (cssRule, "repeat-y", 8))
1.18      cvs      3175:     repeat.typed_data.value = STYLE_VREPEAT;
1.82      cvs      3176:   else if (!strncasecmp (cssRule, "repeat-x", 8))
1.18      cvs      3177:     repeat.typed_data.value = STYLE_HREPEAT;
1.82      cvs      3178:   else if (!strncasecmp (cssRule, "repeat", 6))
1.18      cvs      3179:     repeat.typed_data.value = STYLE_REPEAT;
                   3180:   else
                   3181:     return (cssRule);
                   3182: 
                   3183:    /* install the new presentation */
1.116     vatton   3184:   if (DoApply)
1.117     vatton   3185:     {
                   3186:       /* check if it's an important rule */
                   3187:       if (tsch)
                   3188:        cssRule = CheckImportantRule (cssRule, context);
                   3189:       TtaSetStylePresentation (PRPictureMode, element, tsch, context, repeat);
                   3190:     }
1.18      cvs      3191:   cssRule = SkipWord (cssRule);
1.163     quint    3192:   return (cssRule);
1.18      cvs      3193: }
                   3194: 
                   3195: /*----------------------------------------------------------------------
1.59      cvs      3196:    ParseCSSBackgroundAttachment: parse a CSS BackgroundAttachment
1.18      cvs      3197:    attribute string.                                          
                   3198:   ----------------------------------------------------------------------*/
1.79      cvs      3199: static char *ParseCSSBackgroundAttachment (Element element, PSchema tsch,
                   3200:                                           PresentationContext context,
                   3201:                                           char *cssRule, CSSInfoPtr css,
                   3202:                                           ThotBool isHTML)
1.18      cvs      3203: {
1.163     quint    3204:   cssRule = SkipBlanksAndComments (cssRule);
                   3205:   if (!strncasecmp (cssRule, "scroll", 6))
                   3206:     cssRule = SkipWord (cssRule);
                   3207:   else if (!strncasecmp (cssRule, "fixed", 5))
                   3208:     cssRule = SkipWord (cssRule);
                   3209:   return (cssRule);
1.1       cvs      3210: }
                   3211: 
                   3212: /*----------------------------------------------------------------------
1.59      cvs      3213:    ParseCSSBackgroundPosition: parse a CSS BackgroundPosition
1.1       cvs      3214:    attribute string.                                          
                   3215:   ----------------------------------------------------------------------*/
1.79      cvs      3216: static char *ParseCSSBackgroundPosition (Element element, PSchema tsch,
                   3217:                                         PresentationContext context,
                   3218:                                         char *cssRule, CSSInfoPtr css,
                   3219:                                         ThotBool isHTML)
1.1       cvs      3220: {
1.18      cvs      3221:   PresentationValue     repeat;
                   3222:   ThotBool              ok;
1.1       cvs      3223: 
1.163     quint    3224:   cssRule = SkipBlanksAndComments (cssRule);
                   3225:   ok = TRUE;
                   3226:   if (!strncasecmp (cssRule, "left", 4))
                   3227:     cssRule = SkipWord (cssRule);
                   3228:   else if (!strncasecmp (cssRule, "right", 5))
                   3229:     cssRule = SkipWord (cssRule);
                   3230:   else if (!strncasecmp (cssRule, "center", 6))
                   3231:     cssRule = SkipWord (cssRule);
                   3232:   else if (!strncasecmp (cssRule, "top", 3))
                   3233:     cssRule = SkipWord (cssRule);
                   3234:   else if (!strncasecmp (cssRule, "bottom", 6))
                   3235:     cssRule = SkipWord (cssRule);
                   3236:   else if (isdigit (*cssRule) || *cssRule == '.')
                   3237:     cssRule = SkipWord (cssRule);
                   3238:   else
                   3239:     ok = FALSE;
                   3240: 
                   3241:   if (ok && DoApply)
1.148     vatton   3242:     {
1.163     quint    3243:       /* force realsize for the background image */
                   3244:       repeat.typed_data.value = STYLE_REALSIZE;
                   3245:       repeat.typed_data.unit = STYLE_UNIT_REL;
                   3246:       repeat.typed_data.real = FALSE;
                   3247:       /* check if it's an important rule */
                   3248:       if (tsch)
                   3249:        cssRule = CheckImportantRule (cssRule, context);
                   3250:       TtaSetStylePresentation (PRPictureMode, element, tsch, context, repeat);
1.148     vatton   3251:     }
1.163     quint    3252:   return (cssRule);
1.18      cvs      3253: }
                   3254: 
                   3255: /*----------------------------------------------------------------------
1.59      cvs      3256:    ParseCSSBackground: parse a CSS background attribute 
1.18      cvs      3257:   ----------------------------------------------------------------------*/
1.79      cvs      3258: static char *ParseCSSBackground (Element element, PSchema tsch,
                   3259:                                 PresentationContext context, char *cssRule,
                   3260:                                 CSSInfoPtr css, ThotBool isHTML)
1.18      cvs      3261: {
1.79      cvs      3262:   char     *ptr;
1.93      vatton   3263:   int   skippedNL;
1.18      cvs      3264: 
1.82      cvs      3265:   cssRule = SkipBlanksAndComments (cssRule);
                   3266:   while (*cssRule != ';' && *cssRule != EOS && *cssRule != ',')
1.18      cvs      3267:     {
1.71      cvs      3268:       /* perhaps a Background Image */
1.82      cvs      3269:       if (!strncasecmp (cssRule, "url", 3))
1.63      cvs      3270:          cssRule = ParseCSSBackgroundImage (element, tsch, context, cssRule,
                   3271:                                            css, isHTML);
1.18      cvs      3272:       /* perhaps a Background Attachment */
1.82      cvs      3273:       else if (!strncasecmp (cssRule, "scroll", 6) ||
                   3274:                !strncasecmp (cssRule, "fixed", 5))
1.63      cvs      3275:        cssRule = ParseCSSBackgroundAttachment (element, tsch, context,
                   3276:                                                cssRule, css, isHTML);
1.18      cvs      3277:       /* perhaps a Background Repeat */
1.82      cvs      3278:       else if (!strncasecmp (cssRule, "no-repeat", 9) ||
                   3279:                !strncasecmp (cssRule, "repeat-y", 8)  ||
                   3280:                !strncasecmp (cssRule, "repeat-x", 8)  ||
                   3281:                !strncasecmp (cssRule, "repeat", 6))
                   3282:        cssRule = ParseCSSBackgroundRepeat (element, tsch, context,
                   3283:                                            cssRule, css, isHTML);
1.18      cvs      3284:       /* perhaps a Background Position */
1.82      cvs      3285:       else if (!strncasecmp (cssRule, "left", 4)   ||
                   3286:                !strncasecmp (cssRule, "right", 5)  ||
                   3287:                !strncasecmp (cssRule, "center", 6) ||
                   3288:                !strncasecmp (cssRule, "top", 3)    ||
                   3289:                !strncasecmp (cssRule, "bottom", 6) ||
1.110     vatton   3290:                isdigit (*cssRule) || *cssRule == '.')
1.63      cvs      3291:            cssRule = ParseCSSBackgroundPosition (element, tsch, context,
                   3292:                                                 cssRule, css, isHTML);
1.18      cvs      3293:       /* perhaps a Background Color */
                   3294:       else
                   3295:        {
1.93      vatton   3296:          skippedNL = NewLineSkipped;
1.18      cvs      3297:          /* check if the rule has been found */
                   3298:          ptr = cssRule;
1.82      cvs      3299:          cssRule = ParseCSSBackgroundColor (element, tsch, context,
                   3300:                                             cssRule, css, isHTML);
1.43      cvs      3301:          if (ptr == cssRule)
1.93      vatton   3302:            {
                   3303:              NewLineSkipped = skippedNL;
                   3304:              /* rule not found */
                   3305:              cssRule = SkipProperty (cssRule);
                   3306:            }
1.18      cvs      3307:        }
1.82      cvs      3308:       cssRule = SkipBlanksAndComments (cssRule);
1.18      cvs      3309:     }
                   3310:    return (cssRule);
                   3311: }
                   3312: 
1.59      cvs      3313: /*----------------------------------------------------------------------
1.60      cvs      3314:  ParseCSSPageBreakBefore: parse a CSS page-break-before attribute 
1.59      cvs      3315:   ----------------------------------------------------------------------*/
1.79      cvs      3316: static char *ParseCSSPageBreakBefore (Element element, PSchema tsch,
                   3317:                                      PresentationContext context, char *cssRule,
                   3318:                                      CSSInfoPtr css, ThotBool isHTML)
1.59      cvs      3319: {
                   3320:   PresentationValue   page;
                   3321: 
                   3322:   page.typed_data.unit = STYLE_UNIT_INVALID;
                   3323:   page.typed_data.real = FALSE;
1.82      cvs      3324:   cssRule = SkipBlanksAndComments (cssRule);
                   3325:   if (!strncasecmp (cssRule, "auto", 4))
1.59      cvs      3326:     {
                   3327:       /*page.typed_data.unit = STYLE_UNIT_REL;*/
                   3328:       page.typed_data.value = STYLE_AUTO;
                   3329:     }
1.82      cvs      3330:   else if (!strncasecmp (cssRule, "always", 6))
1.59      cvs      3331:     {
                   3332:       page.typed_data.unit = STYLE_UNIT_REL;
                   3333:       page.typed_data.value = STYLE_ALWAYS;
                   3334:     }
1.82      cvs      3335:   else if (!strncasecmp (cssRule, "avoid", 5))
1.59      cvs      3336:     {
                   3337:       page.typed_data.unit = STYLE_UNIT_REL;
                   3338:       page.typed_data.value = STYLE_AVOID;
                   3339:     }
1.82      cvs      3340:   else if (!strncasecmp (cssRule, "left", 4))
1.59      cvs      3341:     {
                   3342:       page.typed_data.unit = STYLE_UNIT_REL;
                   3343:       page.typed_data.value = STYLE_PAGELEFT;
                   3344:     }
1.82      cvs      3345:   else if (!strncasecmp (cssRule, "right", 5))
1.59      cvs      3346:     {
                   3347:       page.typed_data.unit = STYLE_UNIT_REL;
                   3348:       page.typed_data.value = STYLE_PAGERIGHT;
                   3349:     }
1.82      cvs      3350:   else if (!strncasecmp (cssRule, "inherit", 7))
1.59      cvs      3351:     {
                   3352:       /*page.typed_data.unit = STYLE_UNIT_REL;*/
                   3353:       page.typed_data.value = STYLE_INHERIT;
                   3354:     }
                   3355:   cssRule = SkipWord (cssRule);
                   3356:   /* install the new presentation */
                   3357:   if (page.typed_data.unit == STYLE_UNIT_REL &&
1.116     vatton   3358:       page.typed_data.value == STYLE_ALWAYS && DoApply)
1.117     vatton   3359:     {
                   3360:       /* check if it's an important rule */
                   3361:       if (tsch)
                   3362:        cssRule = CheckImportantRule (cssRule, context);
                   3363:       TtaSetStylePresentation (PRPageBefore, element, tsch, context, page);
                   3364:     }
1.59      cvs      3365:   return (cssRule);
                   3366: }
                   3367: 
                   3368: /*----------------------------------------------------------------------
1.60      cvs      3369:  ParseCSSPageBreakAfter: parse a CSS page-break-after attribute 
1.59      cvs      3370:   ----------------------------------------------------------------------*/
1.79      cvs      3371: static char *ParseCSSPageBreakAfter (Element element, PSchema tsch,
                   3372:                                     PresentationContext context,
                   3373:                                     char *cssRule, CSSInfoPtr css,
                   3374:                                     ThotBool isHTML)
1.59      cvs      3375: {
                   3376:   PresentationValue   page;
                   3377: 
                   3378:   page.typed_data.unit = STYLE_UNIT_INVALID;
                   3379:   page.typed_data.real = FALSE;
1.82      cvs      3380:   cssRule = SkipBlanksAndComments (cssRule);
                   3381:   if (!strncasecmp (cssRule, "auto", 4))
1.59      cvs      3382:     {
                   3383:       /*page.typed_data.unit = STYLE_UNIT_REL;*/
                   3384:       page.typed_data.value = STYLE_AUTO;
                   3385:     }
1.82      cvs      3386:   else if (!strncasecmp (cssRule, "always", 6))
1.59      cvs      3387:     {
                   3388:       page.typed_data.unit = STYLE_UNIT_REL;
                   3389:       page.typed_data.value = STYLE_ALWAYS;
                   3390:     }
1.82      cvs      3391:   else if (!strncasecmp (cssRule, "avoid", 5))
1.59      cvs      3392:     {
                   3393:       page.typed_data.unit = STYLE_UNIT_REL;
                   3394:       page.typed_data.value = STYLE_AVOID;
                   3395:     }
1.82      cvs      3396:   else if (!strncasecmp (cssRule, "left", 4))
1.59      cvs      3397:     {
                   3398:       page.typed_data.unit = STYLE_UNIT_REL;
                   3399:       page.typed_data.value = STYLE_PAGELEFT;
                   3400:     }
1.82      cvs      3401:   else if (!strncasecmp (cssRule, "right", 5))
1.59      cvs      3402:     {
                   3403:       page.typed_data.unit = STYLE_UNIT_REL;
                   3404:       page.typed_data.value = STYLE_PAGERIGHT;
                   3405:     }
1.82      cvs      3406:   else if (!strncasecmp (cssRule, "inherit", 7))
1.59      cvs      3407:     {
                   3408:       /*page.typed_data.unit = STYLE_UNIT_REL;*/
                   3409:       page.typed_data.value = STYLE_INHERIT;
                   3410:     }
                   3411:   cssRule = SkipWord (cssRule);
                   3412:   /* install the new presentation */
1.116     vatton   3413:   /*if (page.typed_data.unit == STYLE_UNIT_REL && DoApply)
1.117     vatton   3414:     {
                   3415:     if (tsch)
                   3416:     cssRule = CheckImportantRule (cssRule, context);
                   3417:     TtaSetStylePresentation (PRPageAfter, element, tsch, context, page);
                   3418:     }*/
1.59      cvs      3419:   return (cssRule);
                   3420: }
                   3421: 
                   3422: /*----------------------------------------------------------------------
1.60      cvs      3423:  ParseCSSPageBreakInside: parse a CSS page-break-inside attribute 
1.59      cvs      3424:   ----------------------------------------------------------------------*/
1.79      cvs      3425: static char *ParseCSSPageBreakInside (Element element, PSchema tsch,
                   3426:                                      PresentationContext context,
                   3427:                                      char *cssRule, CSSInfoPtr css,
                   3428:                                      ThotBool isHTML)
1.59      cvs      3429: {
                   3430:   PresentationValue   page;
                   3431: 
                   3432:   page.typed_data.unit = STYLE_UNIT_INVALID;
                   3433:   page.typed_data.real = FALSE;
1.82      cvs      3434:   cssRule = SkipBlanksAndComments (cssRule);
                   3435:   if (!strncasecmp (cssRule, "auto", 4))
1.59      cvs      3436:     {
                   3437:       /*page.typed_data.unit = STYLE_UNIT_REL;*/
                   3438:       page.typed_data.value = STYLE_AUTO;
                   3439:     }
1.82      cvs      3440:   else if (!strncasecmp (cssRule, "avoid", 5))
1.59      cvs      3441:     {
                   3442:       page.typed_data.unit = STYLE_UNIT_REL;
                   3443:       page.typed_data.value = STYLE_AVOID;
                   3444:     }
1.82      cvs      3445:   else if (!strncasecmp (cssRule, "inherit", 7))
1.59      cvs      3446:     {
                   3447:       /*page.typed_data.unit = STYLE_UNIT_REL;*/
                   3448:       page.typed_data.value = STYLE_INHERIT;
                   3449:     }
                   3450:   cssRule = SkipWord (cssRule);
                   3451:   /* install the new presentation */
1.96      vatton   3452:   /*if (page.typed_data.unit == STYLE_UNIT_REL &&
1.117     vatton   3453:     page.typed_data.value == STYLE_AVOID && DoApply)
                   3454:     {
                   3455:     if (tsch)
                   3456:     cssRule = CheckImportantRule (cssRule, context);
                   3457:     TtaSetStylePresentation (PRPageInside, element, tsch, context, page);
                   3458:     }*/
1.59      cvs      3459:   return (cssRule);
                   3460: }
1.18      cvs      3461: 
                   3462: 
1.60      cvs      3463: /*----------------------------------------------------------------------
1.117     vatton   3464:    ParseSVGStrokeWidth: parse a SVG stroke-width property value.   
1.60      cvs      3465:   ----------------------------------------------------------------------*/
1.79      cvs      3466: static char *ParseSVGStrokeWidth (Element element, PSchema tsch,
                   3467:                                  PresentationContext context, char *cssRule,
                   3468:                                  CSSInfoPtr css, ThotBool isHTML)
1.60      cvs      3469: {
                   3470:   PresentationValue   width;
                   3471:   
1.82      cvs      3472:   cssRule = SkipBlanksAndComments (cssRule);
1.60      cvs      3473:   width.typed_data.value = 0;
                   3474:   width.typed_data.unit = STYLE_UNIT_INVALID;
                   3475:   width.typed_data.real = FALSE;
1.110     vatton   3476:   if (isdigit (*cssRule) || *cssRule == '.')
1.166     vatton   3477:     {
1.60      cvs      3478:      cssRule = ParseCSSUnit (cssRule, &width);
1.166     vatton   3479:      if (width.typed_data.unit == STYLE_UNIT_BOX)
                   3480:        width.typed_data.unit = STYLE_UNIT_PX;
                   3481:     }
1.116     vatton   3482:   if (width.typed_data.unit != STYLE_UNIT_INVALID && DoApply)
1.117     vatton   3483:     {
                   3484:       /* check if it's an important rule */
                   3485:       if (tsch)
                   3486:        cssRule = CheckImportantRule (cssRule, context);
                   3487:       TtaSetStylePresentation (PRLineWeight, element, tsch, context, width);
                   3488:       width.typed_data.value = 1;
                   3489:       width.typed_data.unit = STYLE_UNIT_REL;
                   3490:     }
1.60      cvs      3491:   return (cssRule);
                   3492: }
                   3493: 
1.18      cvs      3494: /************************************************************************
                   3495:  *                                                                     *  
                   3496:  *     FUNCTIONS STYLE DECLARATIONS                                    *
                   3497:  *                                                                     *  
                   3498:  ************************************************************************/
                   3499: /*
1.59      cvs      3500:  * NOTE: Long attribute name MUST be placed before shortened ones !
1.18      cvs      3501:  *        e.g. "FONT-SIZE" must be placed before "FONT"
                   3502:  */
                   3503: static CSSProperty CSSProperties[] =
                   3504: {
1.82      cvs      3505:    {"font-family", ParseCSSFontFamily},
                   3506:    {"font-style", ParseCSSFontStyle},
                   3507:    {"font-variant", ParseCSSFontVariant},
                   3508:    {"font-weight", ParseCSSFontWeight},
                   3509:    {"font-size", ParseCSSFontSize},
                   3510:    {"font", ParseCSSFont},
                   3511: 
                   3512:    {"color", ParseCSSForeground},
                   3513:    {"background-color", ParseCSSBackgroundColor},
                   3514:    {"background-image", ParseCSSBackgroundImage},
                   3515:    {"background-repeat", ParseCSSBackgroundRepeat},
                   3516:    {"background-attachment", ParseCSSBackgroundAttachment},
                   3517:    {"background-position", ParseCSSBackgroundPosition},
                   3518:    {"background", ParseCSSBackground},
                   3519: 
                   3520:    {"word-spacing", ParseCSSWordSpacing},
                   3521:    {"letter-spacing", ParseCSSLetterSpacing},
                   3522:    {"text-decoration", ParseCSSTextDecoration},
                   3523:    {"vertical-align", ParseCSSVerticalAlign},
                   3524:    {"text-transform", ParseCSSTextTransform},
                   3525:    {"text-align", ParseCSSTextAlign},
                   3526:    {"text-indent", ParseCSSTextIndent},
1.162     quint    3527:    {"line-height", ParseCSSLineHeight},
1.82      cvs      3528: 
1.112     quint    3529:    {"direction", ParseCSSDirection},
1.113     quint    3530:    {"unicode-bidi", ParseCSSUnicodeBidi},
1.112     quint    3531: 
1.82      cvs      3532:    {"margin-top", ParseCSSMarginTop},
                   3533:    {"margin-right", ParseCSSMarginRight},
                   3534:    {"margin-bottom", ParseCSSMarginBottom},
                   3535:    {"margin-left", ParseCSSMarginLeft},
                   3536:    {"margin", ParseCSSMargin},
                   3537: 
                   3538:    {"padding-top", ParseCSSPaddingTop},
                   3539:    {"padding-right", ParseCSSPaddingRight},
                   3540:    {"padding-bottom", ParseCSSPaddingBottom},
                   3541:    {"padding-left", ParseCSSPaddingLeft},
                   3542:    {"padding", ParseCSSPadding},
                   3543: 
                   3544:    {"border-top-width", ParseCSSBorderTopWidth},
                   3545:    {"border-right-width", ParseCSSBorderRightWidth},
                   3546:    {"border-bottom-width", ParseCSSBorderBottomWidth},
                   3547:    {"border-left-width", ParseCSSBorderLeftWidth},
                   3548:    {"border-width", ParseCSSBorderWidth},
                   3549:    {"border-top-color", ParseCSSBorderColorTop},
                   3550:    {"border-right-color", ParseCSSBorderColorRight},
                   3551:    {"border-bottom-color", ParseCSSBorderColorBottom},
                   3552:    {"border-left-color", ParseCSSBorderColorLeft},
                   3553:    {"border-color", ParseCSSBorderColor},
                   3554:    {"border-top-style", ParseCSSBorderStyleTop},
                   3555:    {"border-right-style", ParseCSSBorderStyleRight},
                   3556:    {"border-bottom-style", ParseCSSBorderStyleBottom},
                   3557:    {"border-left-style", ParseCSSBorderStyleLeft},
                   3558:    {"border-style", ParseCSSBorderStyle},
                   3559:    {"border-top", ParseCSSBorderTop},
                   3560:    {"border-right", ParseCSSBorderRight},
                   3561:    {"border-bottom", ParseCSSBorderBottom},
                   3562:    {"border-left", ParseCSSBorderLeft},
                   3563:    {"border", ParseCSSBorder},
                   3564: 
                   3565:    {"width", ParseCSSWidth},
                   3566:    {"height", ParseCSSHeight},
                   3567:    {"float", ParseCSSFloat},
                   3568:    {"clear", ParseCSSClear},
                   3569: 
                   3570:    {"display", ParseCSSDisplay},
                   3571:    {"white-space", ParseCSSWhiteSpace},
                   3572: 
                   3573:    {"list-style-type", ParseCSSListStyleType},
                   3574:    {"list-style-image", ParseCSSListStyleImage},
                   3575:    {"list-style-position", ParseCSSListStylePosition},
                   3576:    {"list-style", ParseCSSListStyle},
                   3577: 
                   3578:    {"page-break-before", ParseCSSPageBreakBefore},
                   3579:    {"page-break-after", ParseCSSPageBreakAfter},
                   3580:    {"page-break-inside", ParseCSSPageBreakInside},
1.60      cvs      3581: 
                   3582:    /* SVG extensions */
1.170     cheyroul 3583:    {"stroke-opacity", ParseSVGStrokeOpacity},
1.82      cvs      3584:    {"stroke-width", ParseSVGStrokeWidth},
                   3585:    {"stroke", ParseSVGStroke},
1.170     cheyroul 3586: 
                   3587:    {"fill-opacity", ParseSVGFillOpacity},
1.155     cheyroul 3588:    {"fill", ParseSVGFill},
1.170     cheyroul 3589: 
1.155     cheyroul 3590:    {"opacity", ParseSVGOpacity}
1.18      cvs      3591: };
1.155     cheyroul 3592: 
1.18      cvs      3593: #define NB_CSSSTYLEATTRIBUTE (sizeof(CSSProperties) / sizeof(CSSProperty))
                   3594: 
                   3595: /*----------------------------------------------------------------------
1.59      cvs      3596:    ParseCSSRule: parse a CSS Style string                        
1.18      cvs      3597:    we expect the input string describing the style to be of the  
1.59      cvs      3598:    form: PRORPERTY: DESCRIPTION [ ; PROPERTY: DESCRIPTION ] * 
1.18      cvs      3599:    but tolerate incorrect or incomplete input                    
                   3600:   ----------------------------------------------------------------------*/
1.79      cvs      3601: static void  ParseCSSRule (Element element, PSchema tsch,
                   3602:                           PresentationContext context, char *cssRule,
                   3603:                           CSSInfoPtr css, ThotBool isHTML)
1.18      cvs      3604: {
1.34      cvs      3605:   DisplayMode         dispMode;
1.79      cvs      3606:   char               *p = NULL;
1.18      cvs      3607:   int                 lg;
1.34      cvs      3608:   unsigned int        i;
1.76      cvs      3609:   ThotBool            found;
1.18      cvs      3610: 
1.34      cvs      3611:   /* avoid too many redisplay */
                   3612:   dispMode = TtaGetDisplayMode (context->doc);
                   3613:   if (dispMode == DisplayImmediately)
                   3614:     TtaSetDisplayMode (context->doc, DeferredDisplay);
                   3615: 
1.82      cvs      3616:   while (*cssRule != EOS)
1.18      cvs      3617:     {
1.82      cvs      3618:       cssRule = SkipBlanksAndComments (cssRule);
1.153     vatton   3619:       if (*cssRule < 0x41 || *cssRule > 0x7A ||
1.133     vatton   3620:          (*cssRule > 0x5A && *cssRule < 0x60))
1.153     vatton   3621:        cssRule++;
                   3622:       else
1.89      cvs      3623:        {
1.153     vatton   3624:          found = FALSE;
                   3625:          /* look for the type of property */
                   3626:          for (i = 0; i < NB_CSSSTYLEATTRIBUTE && !found; i++)
1.18      cvs      3627:            {
1.153     vatton   3628:              lg = strlen (CSSProperties[i].name);
                   3629:              if (!strncasecmp (cssRule, CSSProperties[i].name, lg))
                   3630:                {
                   3631:                  p = cssRule + lg;
                   3632:                  found = TRUE;
                   3633:                  i--;
                   3634:                }
1.18      cvs      3635:            }
1.153     vatton   3636:          if (i == NB_CSSSTYLEATTRIBUTE)
                   3637:            cssRule = SkipProperty (cssRule);
                   3638:          else
1.18      cvs      3639:            {
1.153     vatton   3640:              /* update index and skip the ":" indicator if present */
1.86      cvs      3641:              p = SkipBlanksAndComments (p);
1.153     vatton   3642:              if (*p == ':')
1.61      cvs      3643:                {
1.153     vatton   3644:                  p++;
                   3645:                  p = SkipBlanksAndComments (p);
                   3646:                  /* try to parse the value associated with this property */
                   3647:                  if (CSSProperties[i].parsing_function != NULL)
                   3648:                    {
                   3649:                      p = CSSProperties[i].parsing_function (element, tsch, context,
                   3650:                                                             p, css, isHTML);
                   3651:                      /* update index and skip the ";" separator if present */
                   3652:                      cssRule = p;
                   3653:                    }
1.61      cvs      3654:                }
1.153     vatton   3655:              else
                   3656:                cssRule = SkipProperty (cssRule);
1.18      cvs      3657:            }
                   3658:        }
                   3659:       /* next property */
1.82      cvs      3660:       cssRule = SkipBlanksAndComments (cssRule);
1.89      cvs      3661:       if (*cssRule == '}')
                   3662:        {
                   3663:          cssRule++;
1.168     vatton   3664:          CSSPrintError ("Invalid character", "}");
1.89      cvs      3665:          cssRule = SkipBlanksAndComments (cssRule);
                   3666:        }
1.155     cheyroul 3667:       if (*cssRule == ',' ||
                   3668:          *cssRule == ';')
1.18      cvs      3669:        {
                   3670:          cssRule++;
1.82      cvs      3671:          cssRule = SkipBlanksAndComments (cssRule);
1.18      cvs      3672:        }
                   3673:     }
1.34      cvs      3674: 
                   3675:   /* restore the display mode */
                   3676:   if (dispMode == DisplayImmediately)
                   3677:     TtaSetDisplayMode (context->doc, dispMode);
1.18      cvs      3678: }
1.1       cvs      3679: 
1.111     cvs      3680: /*----------------------------------------------------------------------
                   3681:  AddBorderStyleValue
                   3682:  -----------------------------------------------------------------------*/
                   3683: static void AddBorderStyleValue (char *buffer, int value)
                   3684: {
                   3685:   switch (value)
                   3686:     {
                   3687:     case STYLE_BORDERNONE:
                   3688:       strcat (buffer, "none");
                   3689:       break;
                   3690:     case STYLE_BORDERHIDDEN:
                   3691:       strcat (buffer, "hidden");
                   3692:       break;
                   3693:     case STYLE_BORDERDOTTED:
                   3694:       strcat (buffer, "dotted");
                   3695:       break;
                   3696:     case STYLE_BORDERDASHED:
                   3697:       strcat (buffer, "dashed");
                   3698:       break;
                   3699:     case STYLE_BORDERSOLID:
                   3700:       strcat (buffer, "solid");
                   3701:       break;
                   3702:     case STYLE_BORDERDOUBLE:
                   3703:       strcat (buffer, "double");
                   3704:       break;
                   3705:     case STYLE_BORDERGROOVE:
                   3706:       strcat (buffer, "groove");
                   3707:       break;
                   3708:     case STYLE_BORDERRIDGE:
                   3709:       strcat (buffer, "ridge");
                   3710:       break;
                   3711:     case STYLE_BORDERINSET:
                   3712:       strcat (buffer, "inset");
                   3713:       break;
                   3714:     case STYLE_BORDEROUTSET:
                   3715:       strcat (buffer, "outset");
                   3716:       break;
                   3717:     }
                   3718: }
1.1       cvs      3719: 
                   3720: /*----------------------------------------------------------------------
1.59      cvs      3721:  PToCss:  translate a PresentationSetting to the
1.18      cvs      3722:      equivalent CSS string, and add it to the buffer given as the
1.67      cvs      3723:      argument. It is used when extracting the CSS string from actual
                   3724:      presentation.
                   3725:      el is the element for which the style rule is generated
1.18      cvs      3726:  
                   3727:   All the possible values returned by the presentation drivers are
                   3728:   described in thotlib/include/presentation.h
                   3729:  -----------------------------------------------------------------------*/
1.79      cvs      3730: void PToCss (PresentationSetting settings, char *buffer, int len, Element el)
1.1       cvs      3731: {
1.76      cvs      3732:   ElementType         elType;
1.18      cvs      3733:   float               fval = 0;
                   3734:   unsigned short      red, green, blue;
                   3735:   int                 add_unit = 0;
                   3736:   unsigned int        unit, i;
                   3737:   ThotBool            real = FALSE;
                   3738: 
1.82      cvs      3739:   buffer[0] = EOS;
1.18      cvs      3740:   if (len < 40)
                   3741:     return;
                   3742: 
                   3743:   unit = settings->value.typed_data.unit;
                   3744:   if (settings->value.typed_data.real)
                   3745:     {
                   3746:       real = TRUE;
                   3747:       fval = (float) settings->value.typed_data.value;
                   3748:       fval /= 1000;
                   3749:     }
1.1       cvs      3750: 
1.18      cvs      3751:   switch (settings->type)
1.1       cvs      3752:     {
1.18      cvs      3753:     case PRVisibility:
                   3754:       break;
1.111     cvs      3755:     case PRHeight:
                   3756:       if (real)
                   3757:        sprintf (buffer, "height: %g", fval);
                   3758:       else
                   3759:        sprintf (buffer, "height: %d", settings->value.typed_data.value);
                   3760:       add_unit = 1;
                   3761:       break;
                   3762:     case PRWidth:
                   3763:       if (real)
                   3764:        sprintf (buffer, "width: %g", fval);
                   3765:       else
                   3766:        sprintf (buffer, "width: %d", settings->value.typed_data.value);
                   3767:       add_unit = 1;
                   3768:       break;
                   3769:     case PRMarginTop:
                   3770:       if (real)
                   3771:        sprintf (buffer, "margin-top: %g", fval);
                   3772:       else
                   3773:        sprintf (buffer, "margin-top: %d",settings->value.typed_data.value);
                   3774:       add_unit = 1;
                   3775:       break;
                   3776:     case PRMarginBottom:
                   3777:       if (real)
                   3778:        sprintf (buffer, "margin-bottom: %g", fval);
                   3779:       else
                   3780:        sprintf (buffer, "margin-bottom: %d",
                   3781:                 settings->value.typed_data.value);
                   3782:       add_unit = 1;
                   3783:       break;
                   3784:     case PRMarginLeft:
                   3785:       if (real)
                   3786:        sprintf (buffer, "margin-left: %g", fval);
                   3787:       else
1.164     quint    3788:        sprintf (buffer, "margin-left: %d", settings->value.typed_data.value);
1.111     cvs      3789:       add_unit = 1;
                   3790:       break;
                   3791:     case PRMarginRight:
                   3792:       if (real)
                   3793:        sprintf (buffer, "margin-right: %g", fval);
                   3794:       else
1.164     quint    3795:        sprintf (buffer, "margin-right: %d", settings->value.typed_data.value);
1.111     cvs      3796:       add_unit = 1;
                   3797:       break;
                   3798:     case PRPaddingTop:
                   3799:       if (real)
                   3800:        sprintf (buffer, "padding-top: %g", fval);
                   3801:       else
1.164     quint    3802:        sprintf (buffer, "padding-top: %d", settings->value.typed_data.value);
1.111     cvs      3803:       add_unit = 1;
                   3804:       break;
                   3805:     case PRPaddingBottom:
                   3806:       if (real)
                   3807:        sprintf (buffer, "padding-bottom: %g", fval);
                   3808:       else
                   3809:        sprintf (buffer, "padding-bottom: %d",
                   3810:                 settings->value.typed_data.value);
                   3811:       add_unit = 1;
                   3812:       break;
                   3813:     case PRPaddingLeft:
                   3814:       if (real)
                   3815:        sprintf (buffer, "padding-left: %g", fval);
                   3816:       else
1.164     quint    3817:        sprintf (buffer, "padding-left: %d", settings->value.typed_data.value);
1.111     cvs      3818:       add_unit = 1;
                   3819:       break;
                   3820:     case PRPaddingRight:
                   3821:       if (real)
                   3822:        sprintf (buffer, "padding-right: %g", fval);
                   3823:       else
                   3824:        sprintf (buffer, "padding-right: %d",
                   3825:                  settings->value.typed_data.value);
                   3826:       add_unit = 1;
                   3827:       break;
                   3828:     case PRBorderTopWidth:
                   3829:       if (real)
                   3830:        sprintf (buffer, "border-top-width: %g", fval);
                   3831:       else
                   3832:        sprintf (buffer, "border-top-width: %d",
                   3833:                 settings->value.typed_data.value);
                   3834:       add_unit = 1;
                   3835:       break;
                   3836:     case PRBorderBottomWidth:
                   3837:       if (real)
                   3838:        sprintf (buffer, "border-bottom-width: %g", fval);
                   3839:       else
                   3840:        sprintf (buffer, "border-bottom-width: %d",
                   3841:                 settings->value.typed_data.value);
                   3842:       add_unit = 1;
                   3843:       break;
                   3844:     case PRBorderLeftWidth:
                   3845:       if (real)
                   3846:        sprintf (buffer, "border-left-width: %g", fval);
                   3847:       else
                   3848:        sprintf (buffer, "border-left-width: %d",
                   3849:                 settings->value.typed_data.value);
                   3850:       add_unit = 1;
                   3851:       break;
                   3852:     case PRBorderRightWidth:
                   3853:       if (real)
                   3854:        sprintf (buffer, "border-right-width: %g", fval);
                   3855:       else
                   3856:        sprintf (buffer, "border-right-width: %d",
                   3857:                 settings->value.typed_data.value);
                   3858:       add_unit = 1;
                   3859:       break;
                   3860:     case PRBorderTopColor:
                   3861:       TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
                   3862:       elType = TtaGetElementType(el);
                   3863:       sprintf (buffer, "border-top-color: #%02X%02X%02X", red, green, blue);
                   3864:       break;
                   3865:     case PRBorderRightColor:
                   3866:       TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
                   3867:       elType = TtaGetElementType(el);
                   3868:       sprintf (buffer, "border-right-color: #%02X%02X%02X", red, green, blue);
                   3869:       break;
                   3870:     case PRBorderBottomColor:
                   3871:       TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
                   3872:       elType = TtaGetElementType(el);
                   3873:       sprintf (buffer, "border-bottom-color: #%02X%02X%02X", red, green, blue);
1.18      cvs      3874:       break;
1.111     cvs      3875:     case PRBorderLeftColor:
                   3876:       TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
                   3877:       elType = TtaGetElementType(el);
                   3878:       sprintf (buffer, "border-left-color: #%02X%02X%02X", red, green, blue);
1.20      cvs      3879:       break;
1.111     cvs      3880:     case PRBorderTopStyle:
                   3881:       strcpy (buffer, "border-top-style: ");
                   3882:       AddBorderStyleValue (buffer, settings->value.typed_data.value);
                   3883:       break;
                   3884:     case PRBorderRightStyle:
                   3885:       strcpy (buffer, "border-right-style: ");
                   3886:       AddBorderStyleValue (buffer, settings->value.typed_data.value);
                   3887:       break;
                   3888:     case PRBorderBottomStyle:
                   3889:       strcpy (buffer, "border-bottom-style: ");
                   3890:       AddBorderStyleValue (buffer, settings->value.typed_data.value);
                   3891:       break;
                   3892:     case PRBorderLeftStyle:
                   3893:       strcpy (buffer, "border-left-style: ");
                   3894:       AddBorderStyleValue (buffer, settings->value.typed_data.value);
1.18      cvs      3895:       break;
                   3896:     case PRSize:
                   3897:       if (unit == STYLE_UNIT_REL)
                   3898:        {
                   3899:          if (real)
                   3900:            {
1.82      cvs      3901:              sprintf (buffer, "font-size: %g", fval);
1.18      cvs      3902:              add_unit = 1;
                   3903:            }
                   3904:          else
                   3905:            switch (settings->value.typed_data.value)
                   3906:              {
                   3907:              case 1:
1.82      cvs      3908:                strcpy (buffer, "font-size: xx-small");
1.18      cvs      3909:                break;
                   3910:              case 2:
1.82      cvs      3911:                strcpy (buffer, "font-size: x-small");
1.18      cvs      3912:                break;
                   3913:              case 3:
1.82      cvs      3914:                strcpy (buffer, "font-size: small");
1.18      cvs      3915:                break;
                   3916:              case 4:
1.82      cvs      3917:                strcpy (buffer, "font-size: medium");
1.18      cvs      3918:                break;
                   3919:              case 5:
1.82      cvs      3920:                strcpy (buffer, "font-size: large");
1.18      cvs      3921:                break;
                   3922:              case 6:
1.82      cvs      3923:                strcpy (buffer, "font-size: x-large");
1.18      cvs      3924:                break;
                   3925:              case 7:
                   3926:              case 8:
                   3927:              case 9:
                   3928:              case 10:
                   3929:              case 11:
                   3930:              case 12:
1.82      cvs      3931:                strcpy (buffer, "font-size: xx-large");
1.18      cvs      3932:                break;
                   3933:              }
                   3934:        }
                   3935:       else
                   3936:        {
                   3937:          if (real)
1.82      cvs      3938:            sprintf (buffer, "font-size: %g", fval);
1.18      cvs      3939:          else
1.82      cvs      3940:            sprintf (buffer, "font-size: %d",
1.67      cvs      3941:                      settings->value.typed_data.value);
1.18      cvs      3942:          add_unit = 1;
                   3943:        }
                   3944:       break;
1.111     cvs      3945:     case PRStyle:
                   3946:       switch (settings->value.typed_data.value)
                   3947:        {
                   3948:        case STYLE_FONT_ROMAN:
                   3949:          strcpy (buffer, "font-style: normal");
                   3950:          break;
                   3951:        case STYLE_FONT_ITALICS:
                   3952:          strcpy (buffer, "font-style: italic");
                   3953:          break;
                   3954:        case STYLE_FONT_OBLIQUE:
                   3955:          strcpy (buffer, "font-style: oblique");
                   3956:          break;
                   3957:        }
                   3958:       break;
                   3959:     case PRWeight:
                   3960:       switch (settings->value.typed_data.value)
                   3961:        {
                   3962:        case STYLE_WEIGHT_BOLD:
                   3963:          strcpy (buffer, "font-weight: bold");
                   3964:          break;
                   3965:        case STYLE_WEIGHT_NORMAL:
                   3966:          strcpy (buffer, "font-weight: normal");
                   3967:          break;
                   3968:        }
                   3969:       break;
                   3970:     case PRFont:
                   3971:       switch (settings->value.typed_data.value)
                   3972:        {
                   3973:        case STYLE_FONT_HELVETICA:
                   3974:          strcpy (buffer, "font-family: helvetica");
                   3975:          break;
                   3976:        case STYLE_FONT_TIMES:
                   3977:          strcpy (buffer, "font-family: times");
                   3978:          break;
                   3979:        case STYLE_FONT_COURIER:
                   3980:          strcpy (buffer, "font-family: courier");
                   3981:          break;
                   3982:        }
                   3983:       break;
1.18      cvs      3984:     case PRUnderline:
                   3985:       switch (settings->value.typed_data.value)
                   3986:        {
                   3987:        case STYLE_UNDERLINE:
1.82      cvs      3988:          strcpy (buffer, "text-decoration: underline");
1.18      cvs      3989:          break;
                   3990:        case STYLE_OVERLINE:
1.82      cvs      3991:          strcpy (buffer, "text-decoration: overline");
1.18      cvs      3992:          break;
                   3993:        case STYLE_CROSSOUT:
1.82      cvs      3994:          strcpy (buffer, "text-decoration: line-through");
1.18      cvs      3995:          break;
                   3996:        }
                   3997:       break;
1.111     cvs      3998:     case PRThickness:
                   3999:       break;
1.18      cvs      4000:     case PRIndent:
                   4001:       if (real)
1.82      cvs      4002:        sprintf (buffer, "text-indent: %g", fval);
1.18      cvs      4003:       else
1.82      cvs      4004:        sprintf (buffer, "text-indent: %d",
1.67      cvs      4005:                  settings->value.typed_data.value);
1.18      cvs      4006:       add_unit = 1;
                   4007:       break;
                   4008:     case PRLineSpacing:
                   4009:       if (real)
1.82      cvs      4010:        sprintf (buffer, "line-height: %g", fval);
1.1       cvs      4011:       else
1.82      cvs      4012:        sprintf (buffer, "line-height: %d",
1.67      cvs      4013:                  settings->value.typed_data.value);
1.18      cvs      4014:       add_unit = 1;
                   4015:       break;
1.111     cvs      4016:     case PRDepth:
                   4017:       break;
1.18      cvs      4018:     case PRAdjust:
                   4019:       switch (settings->value.typed_data.value)
1.1       cvs      4020:        {
1.18      cvs      4021:        case STYLE_ADJUSTLEFT:
1.82      cvs      4022:          strcpy (buffer, "text-align: left");
1.18      cvs      4023:          break;
                   4024:        case STYLE_ADJUSTRIGHT:
1.82      cvs      4025:          strcpy (buffer, "text-align: right");
1.18      cvs      4026:          break;
                   4027:        case STYLE_ADJUSTCENTERED:
1.82      cvs      4028:          strcpy (buffer, "text-align: center");
1.18      cvs      4029:          break;
                   4030:        case STYLE_ADJUSTLEFTWITHDOTS:
1.82      cvs      4031:          strcpy (buffer, "text-align: left");
1.81      cvs      4032:          break;
                   4033:         case STYLE_ADJUSTJUSTIFY:
1.82      cvs      4034:          strcpy (buffer, "text-align: justify");
1.112     quint    4035:          break;
                   4036:        }
                   4037:       break;
                   4038:     case PRDirection:
                   4039:       switch (settings->value.typed_data.value)
                   4040:        {
                   4041:        case STYLE_LEFTTORIGHT:
                   4042:          strcpy (buffer, "direction: ltr");
                   4043:          break;
                   4044:        case STYLE_RIGHTTOLEFT:
                   4045:          strcpy (buffer, "direction: rtl");
1.113     quint    4046:          break;
                   4047:        }
                   4048:       break;
                   4049:     case PRUnicodeBidi:
                   4050:       switch (settings->value.typed_data.value)
                   4051:        {
                   4052:        case STYLE_BIDINORMAL:
                   4053:          strcpy (buffer, "unicode-bidi: normal");
                   4054:          break;
                   4055:        case STYLE_BIDIEMBED:
                   4056:          strcpy (buffer, "unicode-bidi: embed");
                   4057:          break;
                   4058:        case STYLE_BIDIOVERRIDE:
                   4059:          strcpy (buffer, "unicode-bidi: bidi-override");
1.18      cvs      4060:          break;
1.1       cvs      4061:        }
1.18      cvs      4062:       break;
1.111     cvs      4063:     case PRLineStyle:
                   4064:       break;
1.126     vatton   4065:     case PRDisplay:
                   4066:       switch (settings->value.typed_data.value)
                   4067:        {
                   4068:        case STYLE_DISPLAYINLINE:
                   4069:          strcpy (buffer, "display: inline");
                   4070:          break;
                   4071:        case STYLE_DISPLAYBLOCK:
                   4072:          strcpy (buffer, "display: block");
                   4073:          break;
                   4074:        case STYLE_DISPLAYLISTITEM:
                   4075:          strcpy (buffer, "display: list-item");
                   4076:          break;
                   4077:        case STYLE_DISPLAYRUNIN:
                   4078:          strcpy (buffer, "display: runin");
                   4079:          break;
                   4080:        case STYLE_DISPLAYCOMPACT:
                   4081:          strcpy (buffer, "display: compact");
                   4082:          break;
                   4083:        case STYLE_DISPLAYMARKER:
                   4084:          strcpy (buffer, "display: marker");
                   4085:          break;
                   4086:        default:
                   4087:          break;
                   4088:        }
                   4089:       break;
1.111     cvs      4090:     case PRLineWeight:
                   4091:       elType = TtaGetElementType(el);
                   4092: #ifdef _SVG
                   4093:       if (!strcmp(TtaGetSSchemaName (elType.ElSSchema), "SVG"))
                   4094: #endif /* _SVG */
                   4095:        {
                   4096:          if (real)
                   4097:            sprintf (buffer, "stroke-width: %g", fval);
                   4098:          else
                   4099:            sprintf (buffer, "stroke-width: %d",
                   4100:                      settings->value.typed_data.value);
                   4101:        }
                   4102:       add_unit = 1;
1.18      cvs      4103:       break;
                   4104:     case PRFillPattern:
                   4105:       break;
                   4106:     case PRBackground:
                   4107:       TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
1.76      cvs      4108:       elType = TtaGetElementType(el);
1.100     vatton   4109: #ifdef _SVG
                   4110:       if (strcmp(TtaGetSSchemaName (elType.ElSSchema), "SVG") == 0)
1.82      cvs      4111:        sprintf (buffer, "fill: #%02X%02X%02X", red, green, blue);
1.67      cvs      4112:       else
1.100     vatton   4113: #endif /* _SVG */
1.82      cvs      4114:          sprintf (buffer, "background-color: #%02X%02X%02X", red, green,
1.67      cvs      4115:                   blue);
1.18      cvs      4116:       break;
                   4117:     case PRForeground:
                   4118:       TtaGiveThotRGB (settings->value.typed_data.value, &red, &green, &blue);
1.76      cvs      4119:       elType = TtaGetElementType(el);
1.100     vatton   4120: #ifdef _SVG
                   4121:       if (strcmp(TtaGetSSchemaName (elType.ElSSchema), "SVG") == 0)
1.82      cvs      4122:        sprintf (buffer, "stroke: #%02X%02X%02X", red, green, blue);
1.67      cvs      4123:       else
1.100     vatton   4124: #endif /* _SVG */
1.82      cvs      4125:        sprintf (buffer, "color: #%02X%02X%02X", red, green, blue);
1.67      cvs      4126:       break;
1.111     cvs      4127:     case PRHyphenate:
1.18      cvs      4128:       break;
1.111     cvs      4129:     case PRVertOverflow:
1.18      cvs      4130:       break;
1.111     cvs      4131:     case PRHorizOverflow:
1.18      cvs      4132:       break;
                   4133:     case PRBackgroundPicture:
                   4134:       if (settings->value.pointer != NULL)
1.82      cvs      4135:        sprintf (buffer, "background-image: url(%s)",
1.67      cvs      4136:                  (char*)(settings->value.pointer));
1.1       cvs      4137:       else
1.82      cvs      4138:        sprintf (buffer, "background-image: none");
1.18      cvs      4139:       break;
                   4140:     case PRPictureMode:
                   4141:       switch (settings->value.typed_data.value)
1.1       cvs      4142:        {
1.18      cvs      4143:        case STYLE_REALSIZE:
1.82      cvs      4144:          sprintf (buffer, "background-repeat: no-repeat");
1.18      cvs      4145:          break;
                   4146:        case STYLE_REPEAT:
1.82      cvs      4147:          sprintf (buffer, "background-repeat: repeat");
1.18      cvs      4148:          break;
                   4149:        case STYLE_VREPEAT:
1.82      cvs      4150:          sprintf (buffer, "background-repeat: repeat-y");
1.18      cvs      4151:          break;
                   4152:        case STYLE_HREPEAT:
1.82      cvs      4153:          sprintf (buffer, "background-repeat: repeat-x");
1.18      cvs      4154:          break;
1.1       cvs      4155:        }
1.18      cvs      4156:       break;
                   4157:     default:
                   4158:       break;
1.1       cvs      4159:     }
                   4160: 
1.18      cvs      4161:   if (add_unit)
1.1       cvs      4162:     {
1.18      cvs      4163:       /* add the unit string to the CSS string */
                   4164:       for (i = 0; i < NB_UNITS; i++)
1.1       cvs      4165:        {
1.18      cvs      4166:          if (CSSUnitNames[i].unit == unit)
1.1       cvs      4167:            {
1.82      cvs      4168:              strcat (buffer, CSSUnitNames[i].sign);
1.18      cvs      4169:              break;
1.1       cvs      4170:            }
                   4171:        }
                   4172:     }
                   4173: }
                   4174: 
                   4175: /*----------------------------------------------------------------------
1.59      cvs      4176:    ParseHTMLSpecificStyle: parse and apply a CSS Style string.
1.18      cvs      4177:    This function must be called when a specific style is applied to an
                   4178:    element.
1.114     quint    4179:    The parameter specificity is the specificity of the style, 0 if it is
                   4180:    not really a CSS rule.
1.1       cvs      4181:   ----------------------------------------------------------------------*/
1.79      cvs      4182: void  ParseHTMLSpecificStyle (Element el, char *cssRule, Document doc,
1.114     quint    4183:                              int specificity, ThotBool destroy)
1.1       cvs      4184: {
                   4185:    PresentationContext context;
                   4186:    ElementType         elType;
1.14      cvs      4187:    ThotBool            isHTML;
1.1       cvs      4188: 
                   4189:    /*  A rule applying to BODY is really meant to address HTML */
                   4190:    elType = TtaGetElementType (el);
1.89      cvs      4191: 
1.86      cvs      4192:    /* store the current line for eventually reported errors */
                   4193:    LineNumber = TtaGetElementLineNumber (el);
1.89      cvs      4194:    if (destroy)
                   4195:      /* no reported errors */
                   4196:      ParsedDoc = 0;
                   4197:    else if (ParsedDoc != doc)
                   4198:      {
                   4199:        /* update the context for reported errors */
                   4200:        ParsedDoc = doc;
                   4201:        DocURL = DocumentURLs[doc];
                   4202:      }
1.82      cvs      4203:    isHTML = (strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML") == 0);
1.1       cvs      4204:    /* create the context of the Specific presentation driver */
                   4205:    context = TtaGetSpecificStyleContext (doc);
                   4206:    if (context == NULL)
                   4207:      return;
                   4208:    context->type = elType.ElTypeNum;
1.114     quint    4209:    context->cssSpecificity = specificity;
1.1       cvs      4210:    context->destroy = destroy;
                   4211:    /* Call the parser */
1.155     cheyroul 4212:    ParseCSSRule (el, NULL,
                   4213:                 (PresentationContext) context,
                   4214:                 cssRule, NULL, isHTML);
1.1       cvs      4215:    /* free the context */
                   4216:    TtaFreeMemory(context);
                   4217: }
                   4218: 
1.68      cvs      4219: 
1.1       cvs      4220: /*----------------------------------------------------------------------
1.59      cvs      4221:    ParseGenericSelector: Create a generic context for a given 
1.1       cvs      4222:    selector string. If the selector is made of multiple comma- 
                   4223:    separated selector items, it parses them one at a time and  
                   4224:    return the end of the selector string to be handled or NULL 
                   4225:   ----------------------------------------------------------------------*/
1.79      cvs      4226: static char *ParseGenericSelector (char *selector, char *cssRule,
                   4227:                                   GenericContext ctxt, Document doc,
                   4228:                                   CSSInfoPtr css)
                   4229: {
                   4230:   ElementType        elType;
                   4231:   PSchema            tsch;
1.119     vatton   4232:   AttributeType      attrType;
1.79      cvs      4233:   char               sel[MAX_ANCESTORS * 50];
1.118     vatton   4234:   char              *deb, *cur, c;
                   4235:   char              *schemaName, *mappedName;
1.79      cvs      4236:   char              *names[MAX_ANCESTORS];
                   4237:   char              *ids[MAX_ANCESTORS];
                   4238:   char              *classes[MAX_ANCESTORS];
                   4239:   char              *pseudoclasses[MAX_ANCESTORS];
                   4240:   char              *attrs[MAX_ANCESTORS];
                   4241:   char              *attrvals[MAX_ANCESTORS];
1.133     vatton   4242:   AttrMatch          attrmatch[MAX_ANCESTORS];
1.91      cvs      4243:   int                i, j, k, max;
1.125     vatton   4244:   int                att, maxAttr, kind;
1.118     vatton   4245:   int                specificity, xmlType;
1.79      cvs      4246:   ThotBool           isHTML;
                   4247:   ThotBool           level;
1.1       cvs      4248: 
1.82      cvs      4249:   sel[0] = EOS;
1.117     vatton   4250:   specificity = 0;
1.1       cvs      4251:   for (i = 0; i < MAX_ANCESTORS; i++)
                   4252:     {
1.25      cvs      4253:       names[i] = NULL;
                   4254:       ids[i] = NULL;
                   4255:       classes[i] = NULL;
                   4256:       pseudoclasses[i] = NULL;
                   4257:       attrs[i] = NULL;
                   4258:       attrvals[i] = NULL;
1.133     vatton   4259:       attrmatch[i] = Txtmatch;
1.25      cvs      4260:       ctxt->name[i] = 0;
                   4261:       ctxt->names_nb[i] = 0;
                   4262:       ctxt->attrType[i] = 0;
1.129     vatton   4263:       ctxt->attrLevel[i] = 0;
1.25      cvs      4264:       ctxt->attrText[i] = NULL;
1.133     vatton   4265:       ctxt->attrMatch[1] = Txtmatch;
1.1       cvs      4266:     }
1.25      cvs      4267:   ctxt->box = 0;
                   4268:   ctxt->type = 0;
1.114     quint    4269:   /* the specificity of the rule depends on the selector */
                   4270:   ctxt->cssSpecificity = 0;
1.25      cvs      4271:   
1.82      cvs      4272:   selector = SkipBlanksAndComments (selector);
1.27      cvs      4273:   cur = &sel[0];
1.25      cvs      4274:   max = 0; /* number of loops */
1.1       cvs      4275:   while (1)
                   4276:     {
1.85      cvs      4277:       /* point to the following word in sel[] */
1.27      cvs      4278:       deb = cur;
1.25      cvs      4279:       /* copy an item of the selector into sel[] */
1.1       cvs      4280:       /* put one word in the sel buffer */
1.82      cvs      4281:       while (*selector != EOS && *selector != ',' &&
                   4282:              *selector != '.' && *selector != ':' &&
1.118     vatton   4283:              *selector != '#' && *selector != '[' &&
1.130     vatton   4284:              *selector != '*' && *selector != '>' &&
1.118     vatton   4285:             !TtaIsBlank (selector))
1.50      cvs      4286:             *cur++ = *selector++;
1.82      cvs      4287:       *cur++ = EOS; /* close the first string  in sel[] */
                   4288:       if (deb[0] != EOS)
1.117     vatton   4289:        {
                   4290:          names[0] = deb;
1.150     vatton   4291:          if (!strcmp (names[0], "html"))
1.149     vatton   4292:            /* give a greater priority to the backgoud color of html */
                   4293:            specificity += 3;
                   4294:          else
                   4295:            specificity += 1;
1.117     vatton   4296:        }
1.25      cvs      4297:       else
1.27      cvs      4298:        names[0] = NULL;
                   4299:       classes[0] = NULL;
                   4300:       pseudoclasses[0] = NULL;
                   4301:       ids[0] = NULL;
                   4302:       attrs[0] = NULL;
                   4303:       attrvals[0] = NULL;
1.25      cvs      4304: 
1.27      cvs      4305:       /* now names[0] points to the beginning of the parsed item
1.25      cvs      4306:         and cur to the next chain to be parsed */
1.129     vatton   4307:       while (*selector == '.' || *selector == ':' ||
1.130     vatton   4308:             *selector == '#' || *selector == '[' ||
                   4309:             *selector == '*' || *selector == '>')
1.129     vatton   4310:       {
1.85      cvs      4311:        /* point to the following word in sel[] */
                   4312:        deb = cur;
1.129     vatton   4313:        if (*selector == '.')
                   4314:          {
                   4315:            selector++;
                   4316:            while (*selector != EOS && *selector != ',' &&
                   4317:                   *selector != '.' && *selector != ':' &&
                   4318:                   !TtaIsBlank (selector))
                   4319:              *cur++ = *selector++;
                   4320:            /* close the word */
                   4321:            *cur++ = EOS;
                   4322:            /* point to the class in sel[] if it's valid name */
                   4323:            if (deb[0] <= 64)
                   4324:              {
1.168     vatton   4325:                CSSPrintError ("Invalid class", deb);
1.116     vatton   4326:                DoApply = FALSE;
1.129     vatton   4327:              }
                   4328:            else
                   4329:              {
                   4330:                classes[0] = deb;
1.117     vatton   4331:                specificity += 10;
1.129     vatton   4332:              }
                   4333:          }
                   4334:        else if (*selector == ':')
                   4335:          {
                   4336:            selector++;
                   4337:            while (*selector != EOS && *selector != ',' &&
                   4338:                   *selector != '.' && *selector != ':' &&
                   4339:                   !TtaIsBlank (selector))
                   4340:              *cur++ = *selector++;
                   4341:            /* close the word */
                   4342:            *cur++ = EOS;
                   4343:            /* point to the pseudoclass in sel[] if it's valid name */
                   4344:            if (deb[0] <= 64)
                   4345:              {
1.168     vatton   4346:                CSSPrintError ("Invalid pseudoclass", deb);
1.129     vatton   4347:                DoApply = FALSE;
                   4348:              }
                   4349:            else
                   4350:              {
                   4351:                if (!strcmp (deb, "first-letter") ||
                   4352:                    !strcmp (deb, "first-line") ||
                   4353:                    !strcmp (deb, "before") ||
                   4354:                    !strcmp (deb, "after"))
                   4355:                  /* not supported */
1.116     vatton   4356:                  DoApply = FALSE;
1.129     vatton   4357:                else
                   4358:                  specificity += 10;
                   4359:                pseudoclasses[0]= deb;
                   4360:              }
                   4361:          }
                   4362:        else if (*selector == '#')
                   4363:          {
                   4364:            selector++;
                   4365:            while (*selector != EOS && *selector != ',' &&
                   4366:                   *selector != '.' && *selector != ':' &&
                   4367:                   !TtaIsBlank (selector))
                   4368:              *cur++ = *selector++;
                   4369:            /* close the word */
                   4370:            *cur++ = EOS;
                   4371:            /* point to the attribute in sel[] if it's valid name */
                   4372:            if (deb[0] <= 64)
                   4373:              {
1.168     vatton   4374:                CSSPrintError ("Invalid id", deb);
1.129     vatton   4375:                DoApply = FALSE;
                   4376:              }
                   4377:            else
                   4378:              {
                   4379:                ids[0] = deb;
                   4380:                specificity += 100;
                   4381:              }
                   4382:          }
                   4383:        else if (*selector == '[')
                   4384:          {
1.118     vatton   4385:            selector++;
1.129     vatton   4386:            while (*selector != EOS && *selector != ']' &&
1.131     vatton   4387:                   *selector != '=' && *selector != '~' &&
1.133     vatton   4388:                   *selector != '|' && *selector != '^' &&
                   4389:                   *selector != '!')
1.129     vatton   4390:              *cur++ = *selector++;
1.133     vatton   4391:            /* check matching */
                   4392:            if (*selector == '~')
                   4393:              {
                   4394:                attrmatch[0] = Txtword;
                   4395:                selector++;
                   4396:              }
                   4397:            else if (*selector == '|')
                   4398:              {
                   4399:                attrmatch[0] = Txtsubstring;
                   4400:                selector++;
                   4401:              }
                   4402:            else
                   4403:              attrmatch[0] = Txtmatch;
1.129     vatton   4404:            /* close the word */
                   4405:            *cur++ = EOS;
                   4406:            /* point to the attribute in sel[] if it's valid name */
                   4407:            if (deb[0] <= 64)
                   4408:              {
1.168     vatton   4409:                CSSPrintError ("Invalid attribute", deb);
1.129     vatton   4410:                DoApply = FALSE;
                   4411:              }
                   4412:            else
                   4413:              {
                   4414:                attrs[0] = deb;
                   4415:                specificity += 10;
                   4416:              }
                   4417:            if (*selector == '=')
                   4418:              {
                   4419:                /* look for a value "xxxx" */
                   4420:                selector++;
                   4421:                if (*selector != '"')
                   4422:                  {
1.168     vatton   4423:                    CSSPrintError ("Invalid attribute value", deb);
1.129     vatton   4424:                    DoApply = FALSE;
                   4425:                  }
                   4426:                else
                   4427:                  {
                   4428:                    /* we are now parsing the attribute value */
                   4429:                    selector++;
                   4430:                    deb = cur;
                   4431:                    while (*selector != '"')
                   4432:                      {
                   4433:                        if (*selector == EOS)
                   4434:                          {
1.168     vatton   4435:                            CSSPrintError ("Invalid attribute value", deb);
1.129     vatton   4436:                            DoApply = FALSE;
                   4437:                          }
                   4438:                        else
1.133     vatton   4439:                          {
                   4440:                            *cur++ = tolower (*selector);
                   4441:                            selector++;
                   4442:                          }
1.129     vatton   4443:                      }
                   4444:                    /* there is a value */
                   4445:                    if (*selector == '"')
                   4446:                      {
                   4447:                        selector++;
                   4448:                        *cur++ = EOS;
                   4449:                        attrvals[0] = deb;
                   4450:                      }
                   4451:                  }
                   4452:              }
                   4453:            /* end of the attribute */
                   4454:            if (*selector != ']')
                   4455:              {
1.133     vatton   4456:                selector[1] = EOS;
1.168     vatton   4457:                CSSPrintError ("Not supported selector", selector);
1.133     vatton   4458:                selector += 2;
1.129     vatton   4459:                DoApply = FALSE;
                   4460:              }
                   4461:            else
                   4462:              selector++;
1.130     vatton   4463:          }
                   4464:        else
                   4465:          {
                   4466:            /* not supported selector */
                   4467:            while (*selector != EOS && *selector != ',' &&
                   4468:                   *selector != '.' && *selector != ':' &&
                   4469:                   !TtaIsBlank (selector))
                   4470:              *cur++ = *selector++;
                   4471:            /* close the word */
                   4472:            *cur++ = EOS;
1.168     vatton   4473:            CSSPrintError ("Not supported selector", deb);
1.130     vatton   4474:            DoApply = FALSE;        
1.129     vatton   4475:          }
                   4476:       }
1.1       cvs      4477: 
1.82      cvs      4478:       selector = SkipBlanksAndComments (selector);
1.25      cvs      4479:       /* is it a multi-level selector? */
1.82      cvs      4480:       if (*selector == EOS)
1.1       cvs      4481:        /* end of the selector */
                   4482:        break;
1.82      cvs      4483:       else if (*selector == ',')
1.1       cvs      4484:        {
                   4485:          /* end of the current selector */
                   4486:          selector++;
                   4487:          break;
                   4488:        }
1.25      cvs      4489:       else
                   4490:        {
1.143     vatton   4491:          if (*selector == '>')
                   4492:            {
                   4493:              /* handle immediat parent as a simple parent */
                   4494:              selector++;
                   4495:              selector = SkipBlanksAndComments (selector);
                   4496:            }
1.25      cvs      4497:          /* shifts the list to make room for the new name */
                   4498:          max++; /* a new level in ancestor tables */
                   4499:          if (max == MAX_ANCESTORS)
                   4500:            /* abort the CSS parsing */
                   4501:            return (selector);
                   4502:          for (i = max; i > 0; i--)
                   4503:            {
                   4504:              names[i] = names[i - 1];
                   4505:              ids[i] = ids[i - 1];
                   4506:              classes[i] = classes[i - 1];
1.133     vatton   4507:              pseudoclasses[i] = pseudoclasses[i - 1];
1.25      cvs      4508:              attrs[i] = attrs[i - 1];
                   4509:              attrvals[i] = attrvals[i - 1];
1.133     vatton   4510:              attrmatch[i] = attrmatch[i - 1];
1.25      cvs      4511:            }
                   4512:        }
1.1       cvs      4513:     }
                   4514: 
                   4515:   /* Now set up the context block */
1.25      cvs      4516:   i = 0;
                   4517:   k = 0;
                   4518:   j = 0;
1.35      cvs      4519:   maxAttr = 0;
1.91      cvs      4520:   /* default schema name */
1.119     vatton   4521:   ctxt->schema = NULL;
1.122     vatton   4522:   elType.ElSSchema = NULL;
                   4523:   schemaName = TtaGetSSchemaName(TtaGetDocumentSSchema (doc));
1.119     vatton   4524:   if (!strcmp (schemaName, "HTML"))
                   4525:     xmlType = XHTML_TYPE;
                   4526:   else if (!strcmp (schemaName, "MathML"))
                   4527:     xmlType = MATH_TYPE;
                   4528:   else if (!strcmp (schemaName, "SVG"))
                   4529:     xmlType = SVG_TYPE;
                   4530:   else if (!strcmp (schemaName, "XLink"))
                   4531:     xmlType = XLINK_TYPE;
                   4532:   else if (!strcmp (schemaName, "Annot"))
                   4533:     xmlType = ANNOT_TYPE;
                   4534:   else
                   4535:     xmlType = XML_TYPE;
1.25      cvs      4536:   while (i <= max)
                   4537:     {
                   4538:       if (names[i])
                   4539:        {
1.118     vatton   4540:          /* get the element type of this name in the current document */
                   4541:          MapXMLElementType (xmlType, names[i], &elType, &mappedName, &c, &level, doc);
1.25      cvs      4542:          if (i == 0)
                   4543:            {
1.106     cvs      4544:              if (elType.ElSSchema == NULL)
                   4545:                {
1.119     vatton   4546:                  /* Search in the list of loaded schemas */
1.106     cvs      4547:                  TtaGetXmlElementType (names[i], &elType, NULL, doc);
1.119     vatton   4548:                  if (elType.ElSSchema)
                   4549:                    {
1.154     vatton   4550:                      /* the element type concerns an imported nature */
1.119     vatton   4551:                      schemaName = TtaGetSSchemaName(elType.ElSSchema);
                   4552:                      if (!strcmp (schemaName, "HTML"))
                   4553:                        xmlType = XHTML_TYPE;
                   4554:                      else if (!strcmp (schemaName, "MathML"))
                   4555:                        xmlType = MATH_TYPE;
                   4556:                      else if (!strcmp (schemaName, "SVG"))
                   4557:                        xmlType = SVG_TYPE;
                   4558:                      else if (!strcmp (schemaName, "XLink"))
                   4559:                        xmlType = XLINK_TYPE;
                   4560:                      else if (!strcmp (schemaName, "Annot"))
                   4561:                        xmlType = ANNOT_TYPE;
                   4562:                      else
                   4563:                        xmlType = XML_TYPE;
                   4564:                    }
1.118     vatton   4565: #ifdef XML_GENERIC
1.119     vatton   4566:                  else if (xmlType == XML_TYPE)
1.106     cvs      4567:                    {
                   4568:                      /* Creation of a new element type in the main schema */
                   4569:                      elType.ElSSchema = TtaGetDocumentSSchema (doc);
1.118     vatton   4570:                      TtaAppendXmlElement (names[i], &elType, &mappedName, doc);
1.106     cvs      4571:                    }
1.118     vatton   4572: #endif /* XML_GENERIC */
1.122     vatton   4573:                  else
                   4574:                    {
                   4575:                      if (xmlType != XHTML_TYPE)
                   4576:                        {
                   4577:                          MapXMLElementType (XHTML_TYPE, names[i], &elType,
                   4578:                                             &mappedName, &c, &level, doc);
                   4579:                          if (elType.ElSSchema)
1.123     vatton   4580:                            elType.ElSSchema = GetXHTMLSSchema (doc);
1.122     vatton   4581:                        }
                   4582:                      if (elType.ElSSchema == NULL && xmlType != MATH_TYPE)
                   4583:                        {
                   4584:                          MapXMLElementType (MATH_TYPE, names[i], &elType,
                   4585:                                             &mappedName, &c, &level, doc);
                   4586:                          if (elType.ElSSchema)
1.123     vatton   4587:                            elType.ElSSchema = GetMathMLSSchema (doc);
1.122     vatton   4588:                        }
                   4589:                      if (elType.ElSSchema == NULL && xmlType != SVG_TYPE)
                   4590:                        {
                   4591:                          MapXMLElementType (SVG_TYPE, names[i], &elType,
                   4592:                                             &mappedName, &c, &level, doc);
                   4593:                          if (elType.ElSSchema)
1.123     vatton   4594:                            elType.ElSSchema = GetSVGSSchema (doc);
1.122     vatton   4595:                        }
                   4596:                    }
1.118     vatton   4597:                }
1.119     vatton   4598: 
1.118     vatton   4599:              if (elType.ElSSchema == NULL)
                   4600:                /* cannot apply these CSS rules */
                   4601:                DoApply = FALSE;
                   4602:              else
                   4603:                {
                   4604:                  /* Store the element type */
                   4605:                  ctxt->type = elType.ElTypeNum;
                   4606:                  ctxt->name[0] = elType.ElTypeNum;
                   4607:                  ctxt->names_nb[0] = 0;
                   4608:                  ctxt->schema = elType.ElSSchema;
1.106     cvs      4609:                }
1.25      cvs      4610:            }
                   4611:          else if (elType.ElTypeNum != 0)
                   4612:            {
                   4613:              /* look at the current context to see if the type is already
                   4614:                 stored */
1.121     vatton   4615:              j = 1;
1.32      cvs      4616:              while (j < k && ctxt->name[j] != elType.ElTypeNum)
1.25      cvs      4617:                j++;
                   4618:              if (j == k)
                   4619:                {
                   4620:                  ctxt->name[j] = elType.ElTypeNum;
                   4621:                  if (j != 0)
1.121     vatton   4622:                    ctxt->names_nb[j] = 1;
1.25      cvs      4623:                }
                   4624:              else
                   4625:                /* increment the number of ancestor levels */
                   4626:                ctxt->names_nb[j]++;
                   4627:            }
1.154     vatton   4628: #ifdef XML_GENERIC
                   4629:          else if (xmlType == XML_TYPE)
                   4630:            {
1.158     vatton   4631:              TtaGetXmlElementType (names[i], &elType, NULL, doc);
                   4632:              if (elType.ElTypeNum == 0)
                   4633:                {
                   4634:                  /* Creation of a new element type in the main schema */
                   4635:                  elType.ElSSchema = TtaGetDocumentSSchema (doc);
                   4636:                  TtaAppendXmlElement (names[i], &elType, &mappedName, doc);
                   4637:                }
1.154     vatton   4638:              if (elType.ElTypeNum != 0)
                   4639:                {
                   4640:                  /* look at the current context to see if the type is already
                   4641:                     stored */
                   4642:                  j = 1;
                   4643:                  while (j < k && ctxt->name[j] != elType.ElTypeNum)
                   4644:                    j++;
                   4645:                  if (j == k)
                   4646:                    {
                   4647:                      ctxt->name[j] = elType.ElTypeNum;
                   4648:                      if (j != 0)
                   4649:                        ctxt->names_nb[j] = 1;
                   4650:                    }
                   4651:                  else
                   4652:                    /* increment the number of ancestor levels */
                   4653:                    ctxt->names_nb[j]++;
                   4654:                }
                   4655:            }
                   4656: #endif /* XML_GENERIC */
1.25      cvs      4657:          else
1.117     vatton   4658:            j = k;
1.25      cvs      4659:        }
1.117     vatton   4660:       else
                   4661:        j = k;
1.1       cvs      4662: 
1.25      cvs      4663:       /* store attributes information */
                   4664:       if (classes[i])
                   4665:        {
                   4666:          ctxt->attrText[j] = classes[i];
1.119     vatton   4667:          if (xmlType == SVG_TYPE)
1.100     vatton   4668:            ctxt->attrType[j] = SVG_ATTR_class;
1.119     vatton   4669:          else if (xmlType == MATH_TYPE)
1.91      cvs      4670:            ctxt->attrType[j] = MathML_ATTR_class;
1.119     vatton   4671:          else if (xmlType == XHTML_TYPE)
1.107     cvs      4672:            ctxt->attrType[j] = HTML_ATTR_Class;
                   4673:          else
1.119     vatton   4674: #ifdef XML_GENERIC
1.107     cvs      4675:            ctxt->attrType[j] = XML_ATTR_class;
                   4676: #else /* XML_GENERIC */
1.91      cvs      4677:            ctxt->attrType[j] = HTML_ATTR_Class;
1.107     cvs      4678: #endif /* XML_GENERIC */
1.157     vatton   4679:          ctxt->attrMatch[j] = attrmatch[i];
1.79      cvs      4680:          /* add a new entry */
1.80      cvs      4681:          maxAttr = i + 1;
1.129     vatton   4682:          /* update attrLevel */
                   4683:          ctxt->attrLevel[j] = i;
                   4684:          j++;
1.25      cvs      4685:        }
1.79      cvs      4686:       if (pseudoclasses[i])
1.25      cvs      4687:        {
                   4688:          ctxt->attrText[j] = pseudoclasses[i];
1.119     vatton   4689:          if (xmlType == SVG_TYPE)
1.100     vatton   4690:            ctxt->attrType[j] = SVG_ATTR_PseudoClass;
1.119     vatton   4691:          else if (xmlType == MATH_TYPE)
1.91      cvs      4692:            ctxt->attrType[j] = MathML_ATTR_PseudoClass;
1.119     vatton   4693:          else if (xmlType == XHTML_TYPE)
1.107     cvs      4694:            ctxt->attrType[j] = HTML_ATTR_PseudoClass;
                   4695:          else
1.119     vatton   4696: #ifdef XML_GENERIC
1.107     cvs      4697:            ctxt->attrType[j] = XML_ATTR_PseudoClass;
                   4698: #else /* XML_GENERIC */
1.91      cvs      4699:            ctxt->attrType[j] = HTML_ATTR_PseudoClass;
1.107     cvs      4700: #endif /* XML_GENERIC */
1.157     vatton   4701:          ctxt->attrMatch[j] = attrmatch[i];
1.79      cvs      4702:          /* add a new entry */
1.80      cvs      4703:          maxAttr = i + 1;
1.129     vatton   4704:          /* update attrLevel */
                   4705:          ctxt->attrLevel[j] = i;
                   4706:          j++;
1.25      cvs      4707:        }
1.79      cvs      4708:       if (ids[i])
1.25      cvs      4709:        {
                   4710:          ctxt->attrText[j] = ids[i];
1.119     vatton   4711:          if (xmlType == SVG_TYPE)
1.100     vatton   4712:            ctxt->attrType[j] = SVG_ATTR_id;
1.119     vatton   4713:          else if (xmlType == MATH_TYPE)
1.91      cvs      4714:            ctxt->attrType[j] = MathML_ATTR_id;
1.119     vatton   4715:          else if (xmlType == XHTML_TYPE)
1.107     cvs      4716:            ctxt->attrType[j] = HTML_ATTR_ID;
                   4717:          else
1.119     vatton   4718: #ifdef XML_GENERIC
1.107     cvs      4719:            ctxt->attrType[j] = XML_ATTR_id;
                   4720: #else /* XML_GENERIC */
1.91      cvs      4721:            ctxt->attrType[j] = HTML_ATTR_ID;
1.107     cvs      4722: #endif /* XML_GENERIC */
1.157     vatton   4723:          ctxt->attrMatch[j] = attrmatch[i];
1.80      cvs      4724:          /* add a new entry */
                   4725:          maxAttr = i + 1;
1.129     vatton   4726:          /* update attrLevel */
                   4727:          ctxt->attrLevel[j] = i;
                   4728:          j++;
1.25      cvs      4729:        }
1.79      cvs      4730:       if (attrs[i])
1.25      cvs      4731:        {
1.125     vatton   4732:          /* it's an attribute */
1.119     vatton   4733:          MapXMLAttribute (xmlType, attrs[i], names[i], &level, doc, &att);
1.127     quint    4734:          if (att == DummyAttribute && !strcmp (schemaName, "HTML"))
                   4735:            /* it's the "type" attribute for an "input" element. In the tree
                   4736:               it's represented by the element type, not by an attribute */
                   4737:            att = 0;
1.119     vatton   4738:          ctxt->attrType[j] = att;
1.133     vatton   4739:          ctxt->attrMatch[j] = attrmatch[i];
1.125     vatton   4740:          attrType.AttrSSchema = ctxt->schema;
                   4741:          attrType.AttrTypeNum = att;
1.119     vatton   4742:          if (i == 0 && att == 0 && ctxt->schema == NULL)
                   4743:            {
1.125     vatton   4744:              /* Not found -> search in the list of loaded schemas */
1.119     vatton   4745:              attrType.AttrSSchema = NULL;
                   4746:              TtaGetXmlAttributeType (attrs[i], &attrType, doc);
                   4747:              ctxt->attrType[j] = attrType.AttrTypeNum;
                   4748:              if (attrType.AttrSSchema)
1.125     vatton   4749:                /* the element type concerns an imported nature */
                   4750:                schemaName = TtaGetSSchemaName(attrType.AttrSSchema);
1.119     vatton   4751: #ifdef XML_GENERIC
                   4752:              else if (xmlType == XML_TYPE)
                   4753:                {
                   4754:                  /* The attribute is not yet present in the tree */
                   4755:                  /* Create a new global attribute */
                   4756:                  attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
                   4757:                  TtaAppendXmlAttribute (attrs[i], &attrType, doc);
                   4758:                }
                   4759: #endif /* XML_GENERIC */
                   4760: 
                   4761:              if (attrType.AttrSSchema == NULL)
                   4762:                /* cannot apply these CSS rules */
                   4763:                DoApply = FALSE;
1.136     quint    4764:              else if (elType.ElSSchema)
                   4765:                ctxt->schema = elType.ElSSchema;
1.119     vatton   4766:              else
1.136     quint    4767:                ctxt->schema = attrType.AttrSSchema;
1.119     vatton   4768:            }
1.125     vatton   4769:          /* check the attribute type */
                   4770:          if (!strcmp (schemaName, "HTML"))
                   4771:            xmlType = XHTML_TYPE;
                   4772:          else if (!strcmp (schemaName, "MathML"))
                   4773:            xmlType = MATH_TYPE;
                   4774:          else if (!strcmp (schemaName, "SVG"))
                   4775:            xmlType = SVG_TYPE;
                   4776:          else if (!strcmp (schemaName, "XLink"))
                   4777:            xmlType = XLINK_TYPE;
                   4778:          else if (!strcmp (schemaName, "Annot"))
                   4779:            xmlType = ANNOT_TYPE;
                   4780:          else
                   4781:            xmlType = XML_TYPE;
                   4782:          kind = TtaGetAttributeKind (attrType);
                   4783:          if (kind == 0 && attrvals[i])
                   4784:            {
                   4785:              /* enumerated value */
                   4786:              MapXMLAttributeValue (xmlType, attrvals[i], attrType, &kind);
                   4787:              /* store the attribute value */
                   4788:              ctxt->attrText[j] = (char *) kind;
                   4789:            }
                   4790:          else
                   4791:            ctxt->attrText[j] = attrvals[i];
1.80      cvs      4792:          maxAttr = i + 1;
1.129     vatton   4793:          /* update attrLevel */
                   4794:          ctxt->attrLevel[j] = i;
                   4795:          j++;
1.25      cvs      4796:        }
                   4797:       i++;
1.117     vatton   4798:       /* add a new entry */
                   4799:       k++;
1.129     vatton   4800:       if (k < j)
                   4801:        k = j;
1.119     vatton   4802:       if (i == 1 && ctxt->schema == NULL)
                   4803:        /* use the document schema */
                   4804:        ctxt->schema = TtaGetDocumentSSchema (doc);
1.1       cvs      4805:     }
1.117     vatton   4806:   /* set the selector specificity */
                   4807:   ctxt->cssSpecificity = specificity;
1.25      cvs      4808:   /* sort the list of ancestors by name order */
                   4809:   max = k;
                   4810:   i = 1;
                   4811:   while (i < max)
1.28      cvs      4812:     {
                   4813:       for (k = i + 1; k < max; k++)
                   4814:        if (ctxt->name[i] > ctxt->name[k])
                   4815:          {
                   4816:            j = ctxt->name[i];
                   4817:            ctxt->name[i] = ctxt->name[k];
                   4818:            ctxt->name[k] = j;
                   4819:            j = ctxt->names_nb[i];
                   4820:            ctxt->names_nb[i] = ctxt->names_nb[k];
                   4821:            ctxt->names_nb[k] = j;
                   4822:            j = ctxt->attrType[i];
                   4823:            ctxt->attrType[i] = ctxt->attrType[k];
                   4824:            ctxt->attrType[k] = j;
                   4825:            cur = ctxt->attrText[i];
                   4826:            ctxt->attrText[i] = ctxt->attrText[k];
                   4827:            ctxt->attrText[k] = cur;
                   4828:          }
                   4829:       i++;
                   4830:     }
1.84      cvs      4831: 
1.25      cvs      4832:   /* Get the schema name of the main element */
1.119     vatton   4833:   schemaName = TtaGetSSchemaName (ctxt->schema);
                   4834:   isHTML = (strcmp (schemaName, "HTML") == 0);
                   4835:   tsch = GetPExtension (doc, ctxt->schema, css);
                   4836:   if (tsch && cssRule)
                   4837:     ParseCSSRule (NULL, tsch, (PresentationContext) ctxt, cssRule, css, isHTML);
1.116     vatton   4838:   /* future CSS rules should apply */
                   4839:   DoApply = TRUE;
1.1       cvs      4840:   return (selector);
                   4841: }
                   4842: 
                   4843: /*----------------------------------------------------------------------
1.73      cvs      4844:    ParseStyleDeclaration: parse a style declaration    
                   4845:    stored in the style element of a document                       
1.59      cvs      4846:    We expect the style string to be of the form:                   
1.1       cvs      4847:    [                                                                
                   4848:    e.g: pinky, awful { color: pink, font-family: helvetica }        
                   4849:   ----------------------------------------------------------------------*/
1.79      cvs      4850: static void  ParseStyleDeclaration (Element el, char *cssRule, Document doc,
                   4851:                                    CSSInfoPtr css, ThotBool destroy)
1.1       cvs      4852: {
1.79      cvs      4853:   GenericContext      ctxt;
                   4854:   char               *decl_end;
                   4855:   char               *sel_end;
                   4856:   char               *selector;
1.1       cvs      4857: 
                   4858:   /* separate the selectors string */
1.82      cvs      4859:   cssRule = SkipBlanksAndComments (cssRule);
1.1       cvs      4860:   decl_end = cssRule;
1.82      cvs      4861:   while (*decl_end != EOS && *decl_end != '{')
1.1       cvs      4862:     decl_end++;
1.82      cvs      4863:   if (*decl_end == EOS)
1.86      cvs      4864:     {
1.168     vatton   4865:       CSSPrintError ("Invalid selector", cssRule);
1.86      cvs      4866:       return;
                   4867:     }
1.1       cvs      4868:   /* verify and clean the selector string */
                   4869:   sel_end = decl_end - 1;
1.82      cvs      4870:   while (*sel_end == SPACE || *sel_end == BSPACE ||
                   4871:         *sel_end == EOL || *sel_end == CR)
1.1       cvs      4872:     sel_end--;
                   4873:   sel_end++;
1.82      cvs      4874:   *sel_end = EOS;
1.1       cvs      4875:   selector = cssRule;
                   4876: 
                   4877:   /* now, deal with the content ... */
                   4878:   decl_end++;
                   4879:   cssRule = decl_end;
1.137     vatton   4880:   decl_end = &cssRule[strlen (cssRule) - 1];
                   4881:   if (*decl_end != '{')
                   4882:     *decl_end = EOS;
1.1       cvs      4883:   /*
                   4884:    * parse the style attribute string and install the corresponding
                   4885:    * presentation attributes on the new element
                   4886:    */
                   4887:   ctxt = TtaGetGenericStyleContext (doc);
                   4888:   if (ctxt == NULL)
                   4889:     return;
                   4890:   ctxt->destroy = destroy;
                   4891: 
1.82      cvs      4892:   while ((selector != NULL) && (*selector != EOS))
1.25      cvs      4893:     selector = ParseGenericSelector (selector, cssRule, ctxt, doc, css);
1.1       cvs      4894:   TtaFreeMemory (ctxt);
                   4895: }
                   4896: 
                   4897: /************************************************************************
                   4898:  *                                                                     *  
                   4899:  *     EVALUATION FUNCTIONS / CASCADING AND OVERLOADING                *
                   4900:  *                                                                     *  
                   4901:  ************************************************************************/
                   4902: 
                   4903: /*----------------------------------------------------------------------
1.59      cvs      4904:    IsImplicitClassName: return wether the Class name is an        
1.1       cvs      4905:    implicit one, eg "H1" or "H2 EM" meaning it's a GI name       
                   4906:    or an HTML context name.                                      
                   4907:   ----------------------------------------------------------------------*/
1.79      cvs      4908: int         IsImplicitClassName (char *class, Document doc)
1.1       cvs      4909: {
1.79      cvs      4910:    char         name[200];
                   4911:    char        *cur = name;
                   4912:    char        *first; 
                   4913:    char         save;
                   4914:    SSchema      schema;
1.1       cvs      4915: 
                   4916:    /* make a local copy */
1.82      cvs      4917:    strncpy (name, class, 199);
1.1       cvs      4918:    name[199] = 0;
                   4919: 
                   4920:    /* loop looking if each word is a GI */
                   4921:    while (*cur != 0)
                   4922:      {
                   4923:        first = cur;
                   4924:        cur = SkipWord (cur);
                   4925:        save = *cur;
                   4926:        *cur = 0;
                   4927:        schema = NULL;
                   4928:        if (MapGI (first, &schema, doc) == -1)
                   4929:          {
                   4930:             return (0);
                   4931:          }
                   4932:        *cur = save;
1.82      cvs      4933:        cur = SkipBlanksAndComments (cur);
1.1       cvs      4934:      }
                   4935:    return (1);
                   4936: }
                   4937: 
                   4938: /************************************************************************
                   4939:  *                                                                     *  
1.114     quint    4940:  *  Functions needed for support of HTML: translate to CSS equivalent   *
1.1       cvs      4941:  *                                                                     *  
                   4942:  ************************************************************************/
                   4943: 
                   4944: /*----------------------------------------------------------------------
1.59      cvs      4945:    HTMLSetBackgroundColor:
1.1       cvs      4946:   ----------------------------------------------------------------------*/
1.79      cvs      4947: void    HTMLSetBackgroundColor (Document doc, Element el, char *color)
1.1       cvs      4948: {
1.79      cvs      4949:    char             css_command[100];
1.1       cvs      4950: 
1.82      cvs      4951:    sprintf (css_command, "background-color: %s", color);
1.114     quint    4952:    ParseHTMLSpecificStyle (el, css_command, doc, 0, FALSE);
1.1       cvs      4953: }
                   4954: 
                   4955: /*----------------------------------------------------------------------
1.59      cvs      4956:    HTMLSetForegroundColor:                                        
1.1       cvs      4957:   ----------------------------------------------------------------------*/
1.97      vatton   4958: void HTMLSetForegroundColor (Document doc, Element el, char *color)
1.1       cvs      4959: {
1.79      cvs      4960:    char           css_command[100];
1.1       cvs      4961: 
1.82      cvs      4962:    sprintf (css_command, "color: %s", color);
1.114     quint    4963:    ParseHTMLSpecificStyle (el, css_command, doc, 0, FALSE);
1.1       cvs      4964: }
                   4965: 
                   4966: /*----------------------------------------------------------------------
1.59      cvs      4967:    HTMLResetBackgroundColor:                                      
1.1       cvs      4968:   ----------------------------------------------------------------------*/
1.97      vatton   4969: void HTMLResetBackgroundColor (Document doc, Element el)
1.1       cvs      4970: {
1.79      cvs      4971:    char           css_command[100];
1.1       cvs      4972: 
1.82      cvs      4973:    sprintf (css_command, "background: red");
1.114     quint    4974:    ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1       cvs      4975: }
                   4976: 
                   4977: /*----------------------------------------------------------------------
1.59      cvs      4978:    HTMLResetBackgroundImage:                                      
1.1       cvs      4979:   ----------------------------------------------------------------------*/
1.97      vatton   4980: void HTMLResetBackgroundImage (Document doc, Element el)
1.1       cvs      4981: {
1.79      cvs      4982:    char           css_command[1000];
1.1       cvs      4983: 
1.82      cvs      4984:    sprintf (css_command, "background-image: url(xx); background-repeat: repeat");
1.114     quint    4985:    ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1       cvs      4986: }
                   4987: 
                   4988: /*----------------------------------------------------------------------
1.59      cvs      4989:    HTMLResetForegroundColor:                                      
1.1       cvs      4990:   ----------------------------------------------------------------------*/
1.97      vatton   4991: void HTMLResetForegroundColor (Document doc, Element el)
1.1       cvs      4992: {
1.79      cvs      4993:    char           css_command[100];
1.1       cvs      4994: 
1.36      cvs      4995:    /* it's not necessary to well know the current color but it must be valid */
1.82      cvs      4996:    sprintf (css_command, "color: red");
1.114     quint    4997:    ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1       cvs      4998: }
                   4999: 
                   5000: /*----------------------------------------------------------------------
1.59      cvs      5001:    HTMLSetAlinkColor:                                             
1.1       cvs      5002:   ----------------------------------------------------------------------*/
1.97      vatton   5003: void HTMLSetAlinkColor (Document doc, char *color)
1.1       cvs      5004: {
1.79      cvs      5005:    char           css_command[100];
1.1       cvs      5006: 
1.82      cvs      5007:    sprintf (css_command, "a:link { color: %s }", color);
1.1       cvs      5008:    ApplyCSSRules (NULL, css_command, doc, FALSE);
                   5009: }
                   5010: 
                   5011: /*----------------------------------------------------------------------
1.59      cvs      5012:    HTMLSetAactiveColor:                                           
1.1       cvs      5013:   ----------------------------------------------------------------------*/
1.97      vatton   5014: void HTMLSetAactiveColor (Document doc, char *color)
1.1       cvs      5015: {
1.79      cvs      5016:    char           css_command[100];
1.1       cvs      5017: 
1.82      cvs      5018:    sprintf (css_command, "a:active { color: %s }", color);
1.1       cvs      5019:    ApplyCSSRules (NULL, css_command, doc, FALSE);
                   5020: }
                   5021: 
                   5022: /*----------------------------------------------------------------------
1.59      cvs      5023:    HTMLSetAvisitedColor:                                          
1.1       cvs      5024:   ----------------------------------------------------------------------*/
1.79      cvs      5025: void                HTMLSetAvisitedColor (Document doc, char *color)
1.1       cvs      5026: {
1.79      cvs      5027:    char           css_command[100];
1.1       cvs      5028: 
1.82      cvs      5029:    sprintf (css_command, "a:visited { color: %s }", color);
1.1       cvs      5030:    ApplyCSSRules (NULL, css_command, doc, FALSE);
                   5031: }
                   5032: 
                   5033: /*----------------------------------------------------------------------
1.59      cvs      5034:    HTMLResetAlinkColor:                                           
1.1       cvs      5035:   ----------------------------------------------------------------------*/
                   5036: void                HTMLResetAlinkColor (Document doc)
                   5037: {
1.79      cvs      5038:    char           css_command[100];
1.1       cvs      5039: 
1.82      cvs      5040:    sprintf (css_command, "a:link { color: red }");
1.1       cvs      5041:    ApplyCSSRules (NULL, css_command, doc, TRUE);
                   5042: }
                   5043: 
                   5044: /*----------------------------------------------------------------------
1.59      cvs      5045:    HTMLResetAactiveColor:                                                 
1.1       cvs      5046:   ----------------------------------------------------------------------*/
                   5047: void                HTMLResetAactiveColor (Document doc)
                   5048: {
1.79      cvs      5049:    char           css_command[100];
1.1       cvs      5050: 
1.82      cvs      5051:    sprintf (css_command, "a:active { color: red }");
1.1       cvs      5052:    ApplyCSSRules (NULL, css_command, doc, TRUE);
                   5053: }
                   5054: 
                   5055: /*----------------------------------------------------------------------
1.59      cvs      5056:    HTMLResetAvisitedColor:                                        
1.1       cvs      5057:   ----------------------------------------------------------------------*/
                   5058: void                HTMLResetAvisitedColor (Document doc)
                   5059: {
1.79      cvs      5060:    char           css_command[100];
1.1       cvs      5061: 
1.82      cvs      5062:    sprintf (css_command, "a:visited { color: red }");
1.1       cvs      5063:    ApplyCSSRules (NULL, css_command, doc, TRUE);
                   5064: }
                   5065: 
                   5066: /*----------------------------------------------------------------------
1.73      cvs      5067:   ApplyCSSRules: parse a CSS Style description stored in the
1.1       cvs      5068:   header of a HTML document.
                   5069:   ----------------------------------------------------------------------*/
1.79      cvs      5070: void ApplyCSSRules (Element el, char *cssRule, Document doc, ThotBool destroy)
1.1       cvs      5071: {
                   5072:   CSSInfoPtr        css;
                   5073: 
1.144     quint    5074:   css = SearchCSS (doc, NULL, el);
1.1       cvs      5075:   if (css == NULL)
                   5076:     /* create the document css */
1.144     quint    5077:     css = AddCSS (doc, doc, CSS_DOCUMENT_STYLE, NULL, NULL, el);
1.1       cvs      5078:   ParseStyleDeclaration (el, cssRule, doc, css, destroy); 
                   5079: }
                   5080: 
                   5081: /*----------------------------------------------------------------------
1.145     quint    5082:    ReadCSSRules:  is the front-end function called by the document parser
                   5083:    when detecting a <style type="text/css"> indicating it's the
1.1       cvs      5084:    beginning of a CSS fragment or when reading a file .css.
                   5085:   
                   5086:    The CSS parser has to handle <!-- ... --> constructs used to
                   5087:    prevent prehistoric browser from displaying the CSS as a text
                   5088:    content. It will stop on any sequence "<x" where x is different
                   5089:    from ! and will return x as to the caller. Theorically x should
1.145     quint    5090:    be equal to / for the </style> end of style.
1.1       cvs      5091:    The parameter doc gives the document tree that contains CSS information.
                   5092:    The parameter docRef gives the document to which CSS are to be applied.
                   5093:    This function uses the current css context or creates it. It's able
1.23      cvs      5094:    to work on the given buffer or call GetNextChar to read the parsed
1.1       cvs      5095:    file.
1.133     vatton   5096:    The parameter url gives the URL of the style shheet parsed.
1.86      cvs      5097:    Parameter numberOfLinesRead indicates the number of lines already
                   5098:    read in the file.
1.1       cvs      5099:    Parameter withUndo indicates whether the changes made in the document
1.145     quint    5100:    structure and content have to be registered in the Undo queue or not.
                   5101:    refElement is the element (image or use, for instance) that references
                   5102:    the document containing the style element to be parsed.
1.1       cvs      5103:   ----------------------------------------------------------------------*/
1.133     vatton   5104: char ReadCSSRules (Document docRef, CSSInfoPtr css, char *buffer, char *url,
1.144     quint    5105:                   int numberOfLinesRead, ThotBool withUndo,
1.145     quint    5106:                   Element styleElement, Element refElement)
1.1       cvs      5107: {
1.6       cvs      5108:   DisplayMode         dispMode;
1.82      cvs      5109:   char                c;
1.138     vatton   5110:   char               *cssRule, *base, *saveDocURL, *ptr;
1.19      cvs      5111:   int                 index;
1.1       cvs      5112:   int                 CSSindex;
                   5113:   int                 CSScomment;
                   5114:   int                 import;
                   5115:   int                 openRule;
1.93      vatton   5116:   int                 newlines;
1.14      cvs      5117:   ThotBool            HTMLcomment;
1.102     vatton   5118:   ThotBool            toParse, eof, quoted;
1.36      cvs      5119:   ThotBool            ignoreMedia, media;
1.88      cvs      5120:   ThotBool            noRule, ignoreImport;
1.1       cvs      5121: 
                   5122:   CSScomment = MAX_CSS_LENGTH;
                   5123:   HTMLcomment = FALSE;
                   5124:   CSSindex = 0;
                   5125:   toParse = FALSE;
                   5126:   noRule = FALSE;
1.36      cvs      5127:   media =  FALSE;
1.88      cvs      5128:   ignoreImport = FALSE;
1.1       cvs      5129:   ignoreMedia = FALSE;
                   5130:   import = MAX_CSS_LENGTH;
                   5131:   eof = FALSE;
                   5132:   openRule = 0;
1.82      cvs      5133:   c = SPACE;
1.1       cvs      5134:   index = 0;
1.134     vatton   5135:   base = NULL;
1.135     vatton   5136:   quoted = FALSE;
1.93      vatton   5137:   /* number of new lines parsed */
                   5138:   newlines = 0;
1.6       cvs      5139:   /* avoid too many redisplay */
                   5140:   dispMode = TtaGetDisplayMode (docRef);
                   5141:   if (dispMode == DisplayImmediately)
                   5142:     TtaSetDisplayMode (docRef, DeferredDisplay);
1.18      cvs      5143: 
                   5144:   /* look for the CSS context */
                   5145:   if (css == NULL)
1.144     quint    5146:     css = SearchCSS (docRef, NULL, styleElement);
1.18      cvs      5147:   if (css == NULL)
1.144     quint    5148:     css = AddCSS (docRef, docRef, CSS_DOCUMENT_STYLE, NULL, NULL,
                   5149:                  styleElement);
1.145     quint    5150:   if (css)
                   5151:     css->refEl = refElement;
1.1       cvs      5152: 
1.144     quint    5153:   /* register parsed CSS file and the document to which CSS are to be applied*/
1.86      cvs      5154:   ParsedDoc = docRef;
1.133     vatton   5155:   if (url)
                   5156:     DocURL = url;
1.86      cvs      5157:   else
                   5158:     /* the CSS source in within the document itself */
                   5159:     DocURL = DocumentURLs[docRef];
                   5160:   LineNumber = numberOfLinesRead + 1;
1.93      vatton   5161:   NewLineSkipped = 0;
1.82      cvs      5162:   while (CSSindex < MAX_CSS_LENGTH && c != EOS && !eof)
                   5163:     {
                   5164:       c = buffer[index++];
                   5165:       eof = (c == EOS);
                   5166:       CSSbuffer[CSSindex] = c;
                   5167:       if (CSScomment == MAX_CSS_LENGTH ||
                   5168:          c == '*' || c == '/' || c == '<')
                   5169:        {
                   5170:          /* we're not within a comment or we're parsing * or / */
                   5171:          switch (c)
                   5172:            {
                   5173:            case '@': /* perhaps an import primitive */
1.135     vatton   5174:              if (!quoted)
                   5175:                import = CSSindex;
1.82      cvs      5176:              break;
                   5177:            case ';':
1.135     vatton   5178:              if (!quoted && !media && import != MAX_CSS_LENGTH)
1.82      cvs      5179:                { 
                   5180:                  if (strncasecmp (&CSSbuffer[import+1], "import", 6))
                   5181:                    /* it's not an import */
                   5182:                    import = MAX_CSS_LENGTH;
                   5183:                  /* save the text */
                   5184:                  noRule = TRUE;
                   5185:                }
                   5186:              break;
                   5187:            case '*':
1.135     vatton   5188:              if (!quoted && CSScomment == MAX_CSS_LENGTH && CSSindex > 0 &&
1.82      cvs      5189:                  CSSbuffer[CSSindex - 1] == '/')
                   5190:                /* start a comment */
                   5191:                CSScomment = CSSindex - 1;
                   5192:              break;
                   5193:            case '/':
1.135     vatton   5194:              if (!quoted && CSSindex > 1 && CSScomment != MAX_CSS_LENGTH &&
1.82      cvs      5195:                  CSSbuffer[CSSindex - 1] == '*')
                   5196:                {
                   5197:                  /* close a comment:and ignore its contents */
                   5198:                  CSSindex = CSScomment - 1; /* will be incremented later */
                   5199:                  CSScomment = MAX_CSS_LENGTH;
1.93      vatton   5200:                  /* clean up the buffer */
1.103     vatton   5201:                  if (newlines && CSSindex > 0)
                   5202:                    while (CSSindex > 0 &&
                   5203:                           (CSSbuffer[CSSindex] == SPACE ||
                   5204:                            CSSbuffer[CSSindex] == BSPACE ||
                   5205:                            CSSbuffer[CSSindex] == EOL ||
                   5206:                            CSSbuffer[CSSindex] == TAB ||
                   5207:                            CSSbuffer[CSSindex] == __CR__))
1.93      vatton   5208:                      {
                   5209:                        if ( CSSbuffer[CSSindex] == EOL)
                   5210:                          {
                   5211:                            LineNumber ++;
                   5212:                            newlines --;
                   5213:                          }
                   5214:                      CSSindex--;
                   5215:                      }
1.82      cvs      5216:                }
1.135     vatton   5217:              else if (!quoted && CSScomment == MAX_CSS_LENGTH && CSSindex > 0 &&
1.82      cvs      5218:                       CSSbuffer[CSSindex - 1] ==  '<')
                   5219:                {
                   5220:                  /* this is the closing tag ! */
                   5221:                  CSSindex -= 2; /* remove </ from the CSS string */
                   5222:                  noRule = TRUE;
                   5223:                } 
                   5224:              break;
                   5225:            case '<':
1.135     vatton   5226:              if (!quoted && CSScomment == MAX_CSS_LENGTH)
1.82      cvs      5227:                {
                   5228:                  /* only if we're not parsing a comment */
                   5229:                  c = buffer[index++];
                   5230:                  eof = (c == EOS);
                   5231:                  if (c == '!')
                   5232:                    {
                   5233:                      /* CSS within an HTML comment */
                   5234:                      HTMLcomment = TRUE;
                   5235:                      CSSindex++;
                   5236:                      CSSbuffer[CSSindex] = c;
                   5237:                    }
                   5238:                  else if (c == EOS)
                   5239:                    CSSindex++;
                   5240:                }
                   5241:              break;
                   5242:            case '-':
1.135     vatton   5243:              if (!quoted && CSSindex > 0 && CSSbuffer[CSSindex - 1] == '-' &&
1.82      cvs      5244:                  HTMLcomment)
                   5245:                /* CSS within an HTML comment */
                   5246:                noRule = TRUE;
                   5247:              break;
                   5248:            case '>':
1.135     vatton   5249:              if (!quoted && HTMLcomment)
1.82      cvs      5250:                noRule = TRUE;
                   5251:              break;
                   5252:            case ' ':
1.135     vatton   5253:              if (!quoted && import != MAX_CSS_LENGTH && openRule == 0)
1.162     quint    5254:                media = !strncasecmp (&CSSbuffer[import+1], "media", 5);
1.82      cvs      5255:              break;
                   5256:            case '{':
1.135     vatton   5257:              if (!quoted)
1.82      cvs      5258:                {
1.135     vatton   5259:                  openRule++;
                   5260:                  if (import != MAX_CSS_LENGTH && openRule == 1 && media)
                   5261:                    {
                   5262:                      /* is it the screen concerned? */
                   5263:                      CSSbuffer[CSSindex+1] = EOS;
                   5264:                      if (TtaIsPrinting ())
                   5265:                        base = strstr (&CSSbuffer[import], "print");
                   5266:                      else
                   5267:                        base = strstr (&CSSbuffer[import], "screen");
                   5268:                      if (base == NULL)
                   5269:                        base = strstr (&CSSbuffer[import], "all");
                   5270:                      if (base == NULL)
                   5271:                        ignoreMedia = TRUE;
                   5272:                      noRule = TRUE;
                   5273:                    }
                   5274:                }
                   5275:              break;
                   5276:            case '}':
                   5277:              if (!quoted)
                   5278:                {
                   5279:                  openRule--;
                   5280:                  if (import != MAX_CSS_LENGTH && openRule == 0)
                   5281:                    {
                   5282:                      import = MAX_CSS_LENGTH;
                   5283:                      noRule = TRUE;
                   5284:                      ignoreMedia = FALSE;
                   5285:                      media = FALSE;
                   5286:                    }
1.82      cvs      5287:                  else
1.135     vatton   5288:                    toParse = TRUE;
1.82      cvs      5289:                }
                   5290:              break;
1.135     vatton   5291:            case '"':
                   5292:              if (quoted)
1.82      cvs      5293:                {
1.135     vatton   5294:                  if (CSSbuffer[CSSindex - 1] != '\\')
                   5295:                    quoted = FALSE;
1.82      cvs      5296:                }
                   5297:              else
1.135     vatton   5298:                quoted = TRUE;
1.82      cvs      5299:              break;
                   5300:            default:
1.86      cvs      5301:              if (c == EOL)
1.93      vatton   5302:                newlines++;
1.82      cvs      5303:              break;
                   5304:            }
                   5305:         }
1.93      vatton   5306:       else if (c == EOL)
                   5307:        LineNumber++;
1.82      cvs      5308:       if (c != CR)
                   5309:        CSSindex++;
                   5310: 
                   5311:       if (CSSindex >= MAX_CSS_LENGTH && CSScomment < MAX_CSS_LENGTH)
                   5312:        /* we're still parsing a comment: remove the text comment */
                   5313:        CSSindex = CSScomment;
                   5314: 
                   5315:       if (CSSindex >= MAX_CSS_LENGTH || toParse || noRule)
                   5316:        {
                   5317:          CSSbuffer[CSSindex] = EOS;
                   5318:          /* parse a not empty string */
                   5319:          if (CSSindex > 0)
                   5320:            {
1.50      cvs      5321:               /* apply CSS rule if it's not just a saving of text */
                   5322:               if (!noRule && !ignoreMedia)
1.88      cvs      5323:                {
                   5324:                  /* future import rules must be ignored */
                   5325:                  ignoreImport = TRUE;
                   5326:                  ParseStyleDeclaration (NULL, CSSbuffer, docRef, css, FALSE);
1.93      vatton   5327:                  LineNumber += newlines;
                   5328:                  newlines = 0;
                   5329:                  NewLineSkipped = 0;
1.88      cvs      5330:                }
1.82      cvs      5331:               else if (import != MAX_CSS_LENGTH &&
                   5332:                       !strncasecmp (&CSSbuffer[import+1], "import", 6))
                   5333:                {
                   5334:                  /* import section */
                   5335:                  cssRule = &CSSbuffer[import+7];
                   5336:                  cssRule = TtaSkipBlanks (cssRule);
1.93      vatton   5337:                  /* save the current line number */
                   5338:                  newlines += LineNumber;
1.82      cvs      5339:                  if (!strncasecmp (cssRule, "url", 3))
                   5340:                    {
1.50      cvs      5341:                       cssRule = &cssRule[3];
1.82      cvs      5342:                       cssRule = TtaSkipBlanks (cssRule);
                   5343:                       if (*cssRule == '(')
                   5344:                        {
                   5345:                          cssRule++;
                   5346:                          cssRule = TtaSkipBlanks (cssRule);
1.102     vatton   5347:                          quoted = (*cssRule == '"' || *cssRule == '\'');
                   5348:                          if (quoted)
                   5349:                            cssRule++;
1.82      cvs      5350:                          base = cssRule;
                   5351:                          while (*cssRule != EOS && *cssRule != ')')
                   5352:                            cssRule++;
1.102     vatton   5353:                          if (quoted)
1.167     vatton   5354:                            {
                   5355:                              /* isolate the file name */
                   5356:                              cssRule[-1] = EOS;
                   5357:                              quoted = FALSE;
                   5358:                            }
1.160     vatton   5359:                          *cssRule = EOS;
1.82      cvs      5360:                        }
                   5361:                    }
1.87      cvs      5362:                  else if (*cssRule == '"')
                   5363:                    {
1.88      cvs      5364:                      /*
                   5365:                        Do we have to accept single quotes?
                   5366:                        Double quotes are acceted here.
                   5367:                        Escaped quotes are not handled. See function SkipQuotedString
                   5368:                      */
1.87      cvs      5369:                      cssRule++;
                   5370:                      cssRule = TtaSkipBlanks (cssRule);
                   5371:                      base = cssRule;
                   5372:                      while (*cssRule != EOS && *cssRule != '"')
                   5373:                        cssRule++;
1.160     vatton   5374:                      /* isolate the file name */
                   5375:                      *cssRule = EOS;
1.133     vatton   5376:                    }
                   5377:                  /* check if a media is defined */
                   5378:                  cssRule++;
                   5379:                  cssRule = TtaSkipBlanks (cssRule);
                   5380:                  if (*cssRule != ';')
                   5381:                    {
                   5382:                      if (TtaIsPrinting ())
                   5383:                        ignoreImport = (strncasecmp (cssRule, "print", 5) &&
                   5384:                                        strncasecmp (cssRule, "all", 3));
                   5385:                      else
                   5386:                        ignoreImport = (strncasecmp (cssRule, "screen", 6) &&
                   5387:                                        strncasecmp (cssRule, "all", 3));
                   5388:                    }
                   5389:                  if (!ignoreImport)
                   5390:                    {
                   5391:                      /* save the displayed URL when an error is reported */
                   5392:                      saveDocURL = DocURL;
1.138     vatton   5393:                      ptr = TtaStrdup (base);
                   5394:                      /* get the CSS URI in UTF-8 */
                   5395:                      ptr = ReallocUTF8String (ptr, docRef);
1.133     vatton   5396:                      LoadStyleSheet (base, docRef, NULL, css,
                   5397:                                      css->media[docRef],
                   5398:                                      css->category == CSS_USER_STYLE);
                   5399:                      /* restore the displayed URL when an error is reported */
                   5400:                      DocURL = saveDocURL;
1.138     vatton   5401:                      TtaFreeMemory (ptr);
1.82      cvs      5402:                    }
1.93      vatton   5403:                  /* restore the number of lines */
                   5404:                  LineNumber = newlines;
                   5405:                  newlines = 0;
1.82      cvs      5406:                  import = MAX_CSS_LENGTH;
                   5407:                }
1.93      vatton   5408:                
1.82      cvs      5409:            }
                   5410:          toParse = FALSE;
                   5411:          noRule = FALSE;
                   5412:          CSSindex = 0;
1.50      cvs      5413:         }
1.82      cvs      5414:     }
1.6       cvs      5415:   /* restore the display mode */
                   5416:   if (dispMode == DisplayImmediately)
1.82      cvs      5417:     TtaSetDisplayMode (docRef, dispMode);
1.86      cvs      5418: 
                   5419:   /* Prepare the context for style attributes */
                   5420:   DocURL = DocumentURLs[docRef];
                   5421:   LineNumber = -1;
1.1       cvs      5422:   return (c);
                   5423: }
1.89      cvs      5424: 

Webmaster