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

1.1       cvs         1: /*
                      2:  *
1.312     quint       3:  *  (c) COPYRIGHT INRIA and W3C, 1996-2005
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: 
1.302     quint      25: typedef struct _CSSImageCallbackBlock
1.1       cvs        26: {
1.207     vatton     27:   Element                el;
                     28:   PSchema                tsch;
                     29:   CSSInfoPtr             css;
                     30:   PresentationContext    ctxt;
1.302     quint      31:   unsigned int           ruleType;
1.1       cvs        32: }
1.302     quint      33: CSSImageCallbackBlock, *CSSImageCallbackPtr;
1.1       cvs        34: 
                     35: #include "AHTURLTools_f.h"
                     36: #include "HTMLpresentation_f.h"
                     37: #include "HTMLimage_f.h"
                     38: #include "UIcss_f.h"
                     39: #include "css_f.h"
1.24      cvs        40: #include "fetchHTMLname_f.h"
1.91      cvs        41: #include "fetchXMLname_f.h"
1.1       cvs        42: #include "html2thot_f.h"
1.91      cvs        43: #include "init_f.h"
1.1       cvs        44: #include "styleparser_f.h"
                     45: 
                     46: #define MAX_BUFFER_LENGTH 200
                     47: /*
                     48:  * A PropertyParser is a function used to parse  the
                     49:  * description substring associated to a given style attribute
1.59      cvs        50:  * e.g.: "red" for a color attribute or "12pt bold helvetica"
1.1       cvs        51:  * for a font attribute.
                     52:  */
1.79      cvs        53: typedef char *(*PropertyParser) (Element element,
1.327     vatton     54:                                  PSchema tsch,
                     55:                                  PresentationContext context,
                     56:                                  char *cssRule,
                     57:                                  CSSInfoPtr css,
                     58:                                  ThotBool isHTML);
1.1       cvs        59: 
                     60: /* Description of the set of CSS properties supported */
                     61: typedef struct CSSProperty
1.327     vatton     62: {
                     63:   char                *name;
                     64:   PropertyParser       parsing_function;
                     65: }
1.1       cvs        66: CSSProperty;
                     67: 
1.86      cvs        68: static char         *DocURL = NULL; /* The parsed CSS file */
                     69: static int           LineNumber = -1; /* The line where the error occurs */
1.93      vatton     70: static int           NewLineSkipped = 0;
1.311     vatton     71: static int           RedisplayImages = 0; /* number of BG images loading */
                     72: static int           RedisplayDoc = 0; /* document to be redisplayed */
                     73: static int           Style_parsing = 0; /* > 0 when parsing a set of CSS rules */
1.310     vatton     74: static ThotBool      RedisplayBGImage = FALSE; /* TRUE when a BG image is inserted */
1.116     vatton     75: static ThotBool      DoApply = TRUE;
1.1       cvs        76: 
                     77: /*----------------------------------------------------------------------
1.327     vatton     78:   SkipWord:                                                  
1.1       cvs        79:   ----------------------------------------------------------------------*/
1.79      cvs        80: static char *SkipWord (char *ptr)
1.1       cvs        81: {
1.168     vatton     82:   while (isalnum((int)*ptr) || *ptr == '-' || *ptr == '#' || *ptr == '%')
                     83:     ptr++;
1.1       cvs        84:   return (ptr);
                     85: }
                     86: 
                     87: /*----------------------------------------------------------------------
1.327     vatton     88:   SkipBlanksAndComments:                                                  
1.13      cvs        89:   ----------------------------------------------------------------------*/
1.82      cvs        90: char *SkipBlanksAndComments (char *ptr)
1.13      cvs        91: {
1.93      vatton     92:   /* skip spaces */
1.155     cheyroul   93:   while (*ptr == SPACE ||
1.327     vatton     94:          *ptr == BSPACE ||
                     95:          *ptr == EOL ||
                     96:          *ptr == TAB ||
                     97:          *ptr == __CR__)
1.93      vatton     98:     {
                     99:       if (*ptr == EOL)
1.327     vatton    100:         /* increment the number of newline skipped */
                    101:         NewLineSkipped++;
1.93      vatton    102:       ptr++;
                    103:     }
1.155     cheyroul  104:   while (ptr[0] == '/' &&
1.327     vatton    105:          ptr[1] == '*')
1.13      cvs       106:     {
                    107:       /* look for the end of the comment */
                    108:       ptr = &ptr[2];
                    109:       while (ptr[0] != EOS && (ptr[0] != '*' || ptr[1] != '/'))
1.327     vatton    110:         ptr++;
1.13      cvs       111:       if (ptr[0] != EOS)
1.327     vatton    112:         ptr = &ptr[2];
1.93      vatton    113:       /* skip spaces */
                    114:       while (*ptr == SPACE || *ptr == BSPACE || *ptr == EOL ||
1.327     vatton    115:              *ptr == TAB || *ptr == __CR__)
                    116:         {
                    117:           if (*ptr == EOL)
                    118:             /* increment the number of newline skipped */
                    119:             NewLineSkipped++;
                    120:           ptr++;
                    121:         }
1.13      cvs       122:     }
                    123:   return (ptr);
                    124: }
                    125: 
1.49      cvs       126: /*----------------------------------------------------------------------
1.327     vatton    127:   SkipQuotedString
1.1       cvs       128:   ----------------------------------------------------------------------*/
1.79      cvs       129: static char *SkipQuotedString (char *ptr, char quote)
1.1       cvs       130: {
1.14      cvs       131:   ThotBool     stop;
1.1       cvs       132: 
                    133:   stop = FALSE;
                    134:   while (!stop)
                    135:     {
1.327     vatton    136:       if (*ptr == quote)
                    137:         {
                    138:           ptr++;
                    139:           stop = TRUE;
                    140:         }
                    141:       else if (*ptr == EOS)
                    142:         stop = TRUE;
                    143:       else if (*ptr == '\\')
                    144:         /* escape character */
                    145:         {
                    146:           ptr++;
1.82      cvs       147:           if ((*ptr >= '0' && *ptr <= '9') || (*ptr >= 'A' && *ptr <= 'F') ||
1.327     vatton    148:               (*ptr >= 'a' && *ptr <= 'f'))
                    149:             {
                    150:               ptr++;
                    151:               if ((*ptr >= '0' && *ptr <= '9') || (*ptr >= 'A' && *ptr <= 'F') ||
                    152:                   (*ptr >= 'a' && *ptr <= 'f'))
                    153:                 ptr++;
                    154:             }
                    155:           else
                    156:             ptr++;
                    157:         }
                    158:       else
                    159:         ptr++;
1.1       cvs       160:     }
                    161:   return (ptr);
                    162: }
                    163: 
                    164: /*----------------------------------------------------------------------
1.327     vatton    165:   CSSPrintError
                    166:   print the error message msg on stderr.
                    167:   When the line is 0 ask to expat the current line number
1.86      cvs       168:   ----------------------------------------------------------------------*/
1.168     vatton    169: static void CSSPrintError (char *msg, char *value)
1.86      cvs       170: {
                    171:   if (!TtaIsPrinting () && ParsedDoc > 0)
                    172:     {
                    173:       if (!ErrFile)
1.327     vatton    174:         {
                    175:           if (OpenParsingErrors (ParsedDoc) == FALSE)
                    176:             return;
                    177:         }
1.86      cvs       178: 
1.308     vatton    179:       /* check if a CSS error file shoulb be updated too */
                    180:       if (ParsedCSS > 0 && !CSSErrFile)
1.327     vatton    181:         OpenParsingErrors (ParsedCSS);
1.308     vatton    182: 
1.133     vatton    183:       if (DocURL)
1.327     vatton    184:         {
                    185:           fprintf (ErrFile, "\n*** Errors/warnings in %s\n", DocURL);
                    186:           /* set to NULL as long as the CSS file doesn't change */
                    187:           DocURL = NULL;
                    188:         }
1.89      cvs       189:       CSSErrorsFound = TRUE;
1.86      cvs       190:       if (LineNumber < 0)
1.327     vatton    191:         fprintf (ErrFile, "  In style attribute, %s \"%s\"\n", msg, value);
1.86      cvs       192:       else
1.327     vatton    193:         {
                    194:           fprintf (ErrFile, "@  line %d: %s \"%s\"\n",
                    195:                    LineNumber+NewLineSkipped, msg, value);
                    196:           if (CSSErrFile)
                    197:             fprintf (CSSErrFile, "@  line %d: %s \"%s\"\n",
                    198:                      LineNumber+NewLineSkipped, msg, value);
                    199:         }
1.86      cvs       200:     }
                    201: }
                    202: 
1.168     vatton    203: /*----------------------------------------------------------------------
1.327     vatton    204:   CSSParseError
                    205:   print the error message msg on stderr.
                    206:   When the line is 0 ask expat about the current line number
1.168     vatton    207:   ----------------------------------------------------------------------*/
                    208: static void CSSParseError (char *msg, char *value, char *endvalue)
                    209: {
1.230     quint     210:   char        c = EOS;
1.168     vatton    211: 
                    212:   if (endvalue)
                    213:     {
                    214:       /* close the string here */
                    215:       c = *endvalue;
                    216:       *endvalue = EOS;
                    217:     }
                    218:   CSSPrintError (msg, value);
                    219:   if (endvalue)
                    220:     *endvalue = c;
                    221: }
                    222: 
1.288     vatton    223: /*----------------------------------------------------------------------
1.327     vatton    224:   CSSCheckEndValue
                    225:   print an error message if another character is found
1.288     vatton    226:   ----------------------------------------------------------------------*/
                    227: static char *CSSCheckEndValue (char *cssRule, char *endvalue, char *msg)
                    228: {
                    229:   char        c = EOS;
                    230:   if (*endvalue != EOS && *endvalue != SPACE && *endvalue != '/' &&
1.316     quint     231:       *endvalue != ';' && *endvalue != '}' && *endvalue != EOL && 
                    232:       *endvalue != TAB && *endvalue !=  __CR__)
1.288     vatton    233:     {
                    234:       while (*endvalue != EOS && *endvalue != SPACE && *endvalue != '/' &&
1.327     vatton    235:              *endvalue != ';' && *endvalue != '}' && *endvalue != EOL &&
                    236:              *endvalue != TAB && *endvalue !=  __CR__)
                    237:         endvalue++;
1.288     vatton    238:       /* close the string here */
                    239:       c = *endvalue;
                    240:       *endvalue = EOS;
                    241:       CSSPrintError (msg, cssRule);
                    242:       *endvalue = c;
                    243:     }
                    244:   return endvalue;
                    245: }
                    246: 
1.89      cvs       247: 
1.86      cvs       248: /*----------------------------------------------------------------------
1.327     vatton    249:   SkipProperty skips a property and display and error message
1.86      cvs       250:   ----------------------------------------------------------------------*/
1.234     vatton    251: static char *SkipProperty (char *ptr, ThotBool reportError)
1.86      cvs       252: {
                    253:   char       *deb;
1.291     cvs       254: #ifdef IV
1.86      cvs       255:   char        c;
1.291     cvs       256: #endif
1.86      cvs       257: 
                    258:   deb = ptr;
1.301     vatton    259:   while (*ptr != EOS && *ptr != ';' && *ptr != '}' && *ptr != '}')
1.133     vatton    260:     {
1.194     vatton    261:       if (*ptr == '"' && (ptr == deb || ptr[-1] != '\\'))
1.327     vatton    262:         {
                    263:           /* skip to the end of the string "..." */
                    264:           ptr++;
                    265:           while (*ptr != EOS &&
                    266:                  (*ptr != '"' || (*ptr == '"' && ptr[-1] == '\\')))
                    267:             ptr++;
                    268:         }
1.133     vatton    269:       ptr++;
                    270:     }
1.288     vatton    271: #ifdef IV
1.95      cvs       272:   /* print the skipped property */
1.86      cvs       273:   c = *ptr;
                    274:   *ptr = EOS;
1.234     vatton    275:   if (reportError && *deb != EOS &&
1.259     vatton    276:       strncasecmp (deb, "border-collapse", 15) &&
1.234     vatton    277:       strncasecmp (deb, "border-spacing", 14) &&
                    278:       strncasecmp (deb, "caption-side", 12) &&
                    279:       strncasecmp (deb, "clip", 4) &&
                    280:       strncasecmp (deb, "counter-increment", 16) &&
                    281:       strncasecmp (deb, "counter-reset", 13) &&
                    282:       strncasecmp (deb, "cursor", 6) &&
                    283:       strncasecmp (deb, "empty-cells", 11) &&
1.259     vatton    284:       strncasecmp (deb, "font-strech", 11) &&
1.234     vatton    285:       strncasecmp (deb, "letter-spacing", 14) &&
1.242     vatton    286:       strncasecmp (deb, "marker-offset", 12) &&
1.234     vatton    287:       strncasecmp (deb, "max-height", 10) &&
                    288:       strncasecmp (deb, "max-width", 9) &&
                    289:       strncasecmp (deb, "min-height", 10) &&
                    290:       strncasecmp (deb, "min-width", 9) &&
                    291:       strncasecmp (deb, "orphans", 7) &&
                    292:       strncasecmp (deb, "outline-color", 13) &&
                    293:       strncasecmp (deb, "outline-style", 13) &&
                    294:       strncasecmp (deb, "outline-width", 13) &&
                    295:       strncasecmp (deb, "outline", 7) &&
                    296:       strncasecmp (deb, "overflow", 8) &&
                    297:       strncasecmp (deb, "quotes", 6) &&
                    298:       strncasecmp (deb, "table-layout", 12) &&
1.259     vatton    299:       strncasecmp (deb, "text-shadow", 11) &&
1.234     vatton    300:       strncasecmp (deb, "visibility", 10) &&
1.258     vatton    301:       strncasecmp (deb, "widows", 6))
1.205     quint     302:     CSSPrintError ("CSS property ignored:", deb);
1.86      cvs       303:   *ptr = c;
1.288     vatton    304: #endif /* IV */
1.86      cvs       305:   return (ptr);
                    306: }
                    307: 
                    308: /*----------------------------------------------------------------------
1.327     vatton    309:   SkipValue
                    310:   skips the value and display an error message if msg is not NULL
1.1       cvs       311:   ----------------------------------------------------------------------*/
1.168     vatton    312: static char *SkipValue (char *msg, char *ptr)
1.1       cvs       313: {
1.86      cvs       314:   char       *deb;
                    315:   char        c;
                    316: 
                    317:   deb = ptr;
1.301     vatton    318:   while (*ptr != EOS && *ptr != ';' && *ptr != '}' && *ptr != '}')
1.133     vatton    319:     {
                    320:       if (*ptr == '"' && (ptr == deb || ptr[-1] != '\\'))
1.327     vatton    321:         {
                    322:           /* skip to the end of the string "..." */
                    323:           ptr++;
                    324:           while (*ptr != '"' || (ptr[0] == '"' && ptr[-1] == '\\'))
                    325:             ptr++;
                    326:         }
1.133     vatton    327:       ptr++;
                    328:     }
1.95      cvs       329:   /* print the skipped property */
1.86      cvs       330:   c = *ptr;
                    331:   *ptr = EOS;
1.168     vatton    332:   if (msg && *deb != EOS && *deb != ',')
                    333:     CSSPrintError (msg, deb);
1.86      cvs       334:   *ptr = c;
1.1       cvs       335:   return (ptr);
                    336: }
                    337: 
                    338: /*----------------------------------------------------------------------
1.327     vatton    339:   ParseNumber:                                                  
                    340:   parse a number and returns the corresponding value.
1.1       cvs       341:   ----------------------------------------------------------------------*/
1.79      cvs       342: char *ParseNumber (char *cssRule, PresentationValue *pval)
1.1       cvs       343: {
                    344:   int                 val = 0;
                    345:   int                 minus = 0;
                    346:   int                 valid = 0;
                    347:   int                 f = 0;
1.14      cvs       348:   ThotBool            real = FALSE;
1.1       cvs       349: 
1.184     vatton    350:   pval->typed_data.unit = UNIT_REL;
1.1       cvs       351:   pval->typed_data.real = FALSE;
1.82      cvs       352:   cssRule = SkipBlanksAndComments (cssRule);
                    353:   if (*cssRule == '-')
1.1       cvs       354:     {
                    355:       minus = 1;
                    356:       cssRule++;
1.82      cvs       357:       cssRule = SkipBlanksAndComments (cssRule);
1.1       cvs       358:     }
                    359: 
1.82      cvs       360:   if (*cssRule == '+')
1.1       cvs       361:     {
                    362:       cssRule++;
1.82      cvs       363:       cssRule = SkipBlanksAndComments (cssRule);
1.1       cvs       364:     }
                    365: 
1.82      cvs       366:   while ((*cssRule >= '0') && (*cssRule <= '9'))
1.1       cvs       367:     {
                    368:       val *= 10;
1.82      cvs       369:       val += *cssRule - '0';
1.1       cvs       370:       cssRule++;
                    371:       valid = 1;
                    372:     }
                    373: 
1.82      cvs       374:   if (*cssRule == '.')
1.1       cvs       375:     {
                    376:       real = TRUE;
                    377:       f = val;
                    378:       val = 0;
                    379:       cssRule++;
                    380:       /* keep only 3 digits */
1.82      cvs       381:       if (*cssRule >= '0' && *cssRule <= '9')
1.327     vatton    382:         {
                    383:           val = (*cssRule - '0') * 100;
                    384:           cssRule++;
                    385:           if (*cssRule >= '0' && *cssRule <= '9')
                    386:             {
                    387:               val += (*cssRule - '0') * 10;
                    388:               cssRule++;
                    389:               if ((*cssRule >= '0') && (*cssRule <= '9'))
                    390:                 {
                    391:                   val += *cssRule - '0';
                    392:                   cssRule++;
                    393:                 }
                    394:             }
                    395: 
                    396:           while (*cssRule >= '0' && *cssRule <= '9')
                    397:             cssRule++;
                    398:           valid = 1;
                    399:         }
1.1       cvs       400:     }
                    401: 
                    402:   if (!valid)
                    403:     {
1.184     vatton    404:       pval->typed_data.unit = UNIT_INVALID;
1.1       cvs       405:       pval->typed_data.value = 0;
                    406:     }
                    407:   else
                    408:     {
                    409:       pval->typed_data.real = real;
                    410:       if (real)
1.327     vatton    411:         {
                    412:           if (minus)
                    413:             pval->typed_data.value = -(f * 1000 + val);
                    414:           else
                    415:             pval->typed_data.value = f * 1000 + val;
                    416:         }
1.1       cvs       417:       else
1.327     vatton    418:         {
                    419:           if (minus)
                    420:             pval->typed_data.value = -val;
                    421:           else
                    422:             pval->typed_data.value = val;
                    423:         }
1.64      cvs       424:     }
                    425:   return (cssRule);
                    426: }
1.195     vatton    427: 
1.155     cheyroul  428: /*----------------------------------------------------------------------
1.327     vatton    429:   ParseCSSUnit:                                                  
                    430:   parse a CSS Unit substring and returns the corresponding      
                    431:   value and its unit.                                           
1.64      cvs       432:   ----------------------------------------------------------------------*/
1.82      cvs       433: char *ParseCSSUnit (char *cssRule, PresentationValue *pval)
1.64      cvs       434: {
                    435:   unsigned int        uni;
                    436: 
1.184     vatton    437:   pval->typed_data.unit = UNIT_REL;
1.64      cvs       438:   cssRule = ParseNumber (cssRule, pval);
1.184     vatton    439:   if (pval->typed_data.unit == UNIT_INVALID)
1.327     vatton    440:     cssRule = SkipWord (cssRule);
1.64      cvs       441:   else
                    442:     {
1.82      cvs       443:       cssRule = SkipBlanksAndComments (cssRule);
1.231     vatton    444:       uni = 0;
                    445:       while (CSSUnitNames[uni].sign)
1.327     vatton    446:         {
                    447:           if (!strncasecmp (CSSUnitNames[uni].sign, cssRule,
                    448:                             strlen (CSSUnitNames[uni].sign)))
                    449:             {
                    450:               pval->typed_data.unit = CSSUnitNames[uni].unit;
                    451:               return (cssRule + strlen (CSSUnitNames[uni].sign));
                    452:             }
                    453:           else
                    454:             uni++;
                    455:         }
1.64      cvs       456:       /* not in the list of predefined units */
1.184     vatton    457:       pval->typed_data.unit = UNIT_BOX;
1.1       cvs       458:     }
                    459:   return (cssRule);
                    460: }
                    461: 
1.43      cvs       462: /*----------------------------------------------------------------------
1.327     vatton    463:   ParseClampedUnit:                                                  
                    464:   parse a CSS Unit substring and returns the corresponding value and unit.
                    465:   [0,1]
1.239     vatton    466:   ----------------------------------------------------------------------*/
                    467: char *ParseClampedUnit (char *cssRule, PresentationValue *pval)
                    468: {
1.251     vatton    469:   char           *p;
                    470: 
                    471:   p = cssRule;
1.239     vatton    472:   cssRule = ParseNumber (cssRule, pval);
1.301     vatton    473:   if (*cssRule != EOS && *cssRule != SPACE && *cssRule != ';' && *cssRule != '}')
1.239     vatton    474:     {
1.251     vatton    475:       cssRule++;
1.239     vatton    476:       pval->typed_data.unit = UNIT_REL;
                    477:       if (pval->typed_data.value > 100)
1.327     vatton    478:         pval->typed_data.value = 1000;
1.239     vatton    479:       else
1.327     vatton    480:         pval->typed_data.value *= 10;
1.251     vatton    481:       CSSParseError ("Invalid value", p, cssRule);
1.239     vatton    482:     }
                    483:   else
                    484:     {
                    485:       pval->typed_data.unit = UNIT_REL;
                    486:       if (pval->typed_data.real)
1.327     vatton    487:         pval->typed_data.real = FALSE;
1.239     vatton    488:       else if (pval->typed_data.value > 1)
1.327     vatton    489:         {
                    490:           pval->typed_data.value = 1000;
                    491:           CSSParseError ("Invalid value", p, cssRule);
                    492:         }
1.251     vatton    493:       else if (pval->typed_data.value < 0)
1.327     vatton    494:         {
                    495:           pval->typed_data.value = 0;
                    496:           CSSParseError ("Invalid value", p, cssRule);
                    497:         }
1.239     vatton    498:       else
1.327     vatton    499:         pval->typed_data.value *= 1000;
1.239     vatton    500:     }
                    501:   pval->data = pval->typed_data.value;
                    502:   return (cssRule);
                    503: }
                    504: 
                    505: 
                    506: /*----------------------------------------------------------------------
1.327     vatton    507:   ParseABorderValue                                       
1.43      cvs       508:   ----------------------------------------------------------------------*/
1.288     vatton    509: static char *ParseABorderValue (char *cssRule, PresentationValue *border)
1.43      cvs       510: {
1.288     vatton    511:   char             *ptr = cssRule;
1.168     vatton    512: 
1.43      cvs       513:   /* first parse the attribute string */
1.319     quint     514:   border->typed_data.value = 0;
                    515:   border->typed_data.unit = UNIT_INVALID;
                    516:   border->typed_data.real = FALSE;
                    517:   if (!strncasecmp (cssRule, "thin", 4))
                    518:     {
                    519:       border->typed_data.unit = UNIT_PX;
                    520:       border->typed_data.value = 1;
                    521:       cssRule += 4;
                    522:     }
                    523:   else if (!strncasecmp (cssRule, "medium", 6))
                    524:     {
                    525:       border->typed_data.unit = UNIT_PX;
                    526:       border->typed_data.value = 3;
                    527:       cssRule += 6;
                    528:     }
                    529:   else if (!strncasecmp (cssRule, "thick", 5))
                    530:     {
                    531:       border->typed_data.unit = UNIT_PX;
                    532:       border->typed_data.value = 5;
                    533:       cssRule += 5;
                    534:     }
                    535:   else if (!strncasecmp (cssRule, "inherit", 7))
                    536:     {
                    537:       border->typed_data.unit = VALUE_INHERIT;
                    538:       cssRule += 7;
                    539:     }
                    540:   else if (isdigit (*cssRule) || *cssRule == '.')
                    541:     {
                    542:       cssRule = ParseCSSUnit (cssRule, border);
                    543:       if (border->typed_data.value == 0)
1.327     vatton    544:         border->typed_data.unit = UNIT_PX;
1.319     quint     545:       else if (border->typed_data.unit == UNIT_INVALID ||
1.327     vatton    546:                border->typed_data.unit == UNIT_BOX ||
                    547:                border->typed_data.unit == UNIT_PERCENT)
                    548:         {
                    549:           border->typed_data.unit = UNIT_INVALID;
                    550:           border->typed_data.value = 0;
                    551:           CSSParseError ("Invalid border-width value", ptr, cssRule);
                    552:         }
1.319     quint     553:     }
                    554:   return (cssRule);
1.43      cvs       555: }
                    556: 
1.288     vatton    557: 
                    558: /*----------------------------------------------------------------------
1.327     vatton    559:   ParseBorderStyle                                      
1.43      cvs       560:   ----------------------------------------------------------------------*/
1.79      cvs       561: static char *ParseBorderStyle (char *cssRule, PresentationValue *border)
1.43      cvs       562: {
                    563:   /* first parse the attribute string */
1.327     vatton    564:   border->typed_data.value = 0;
                    565:   border->typed_data.unit = UNIT_PX;
                    566:   border->typed_data.real = FALSE;
                    567:   if (!strncasecmp (cssRule, "none", 4))
                    568:     {
                    569:       border->typed_data.value = BorderStyleNone;
                    570:       cssRule += 4;
                    571:     }
                    572:   else if (!strncasecmp (cssRule, "hidden", 6))
                    573:     {
                    574:       border->typed_data.value = BorderStyleHidden;
                    575:       cssRule += 6;
                    576:     }
                    577:   else if (!strncasecmp (cssRule, "dotted", 6))
                    578:     {
1.288     vatton    579:       cssRule += 6;
1.327     vatton    580:       border->typed_data.value = BorderStyleDotted;
1.288     vatton    581:     }
1.327     vatton    582:   else if (!strncasecmp (cssRule, "dashed", 6))
                    583:     {
                    584:       border->typed_data.value = BorderStyleDashed;
                    585:       cssRule += 6;
                    586:     }
                    587:   else if (!strncasecmp (cssRule, "solid", 5))
                    588:     {
                    589:       border->typed_data.value = BorderStyleSolid;
                    590:       cssRule += 5;
                    591:     }
                    592:   else if (!strncasecmp (cssRule, "double", 6))
                    593:     {
                    594:       border->typed_data.value = BorderStyleDouble;
                    595:       cssRule += 6;
                    596:     }
                    597:   else if (!strncasecmp (cssRule, "groove", 6))
                    598:     {
                    599:       border->typed_data.value = BorderStyleGroove;
                    600:       cssRule += 6;
                    601:     }
                    602:   else if (!strncasecmp (cssRule, "ridge", 5))
                    603:     {
                    604:       border->typed_data.value = BorderStyleRidge;
                    605:       cssRule += 5;
                    606:     }
                    607:   else if (!strncasecmp (cssRule, "inset", 5))
                    608:     {
                    609:       border->typed_data.value = BorderStyleInset;
                    610:       cssRule += 5;
                    611:     }
                    612:   else if (!strncasecmp (cssRule, "outset", 6))
                    613:     {
                    614:       border->typed_data.value = BorderStyleOutset;
                    615:       cssRule += 6;
                    616:     }
                    617:   else
                    618:     {
                    619:       /* invalid style */
                    620:       border->typed_data.unit = UNIT_INVALID;
                    621:       return (cssRule);
                    622:     }
                    623:   /* the value is parsed now */
                    624:   /*cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid border-style value");*/
                    625:   return (cssRule);
1.43      cvs       626: }
                    627: 
                    628: /*----------------------------------------------------------------------
1.327     vatton    629:   ParseCSSColor: parse a CSS color attribute string    
                    630:   we expect the input string describing the attribute to be     
                    631:   either a color name, a 3 tuple or an hexadecimal encoding.    
                    632:   The color used will be approximed from the current color      
                    633:   table                                                         
1.43      cvs       634:   ----------------------------------------------------------------------*/
1.79      cvs       635: static char *ParseCSSColor (char *cssRule, PresentationValue * val)
1.43      cvs       636: {
1.79      cvs       637:   char               *ptr;
1.43      cvs       638:   unsigned short      redval = (unsigned short) -1;
                    639:   unsigned short      greenval = 0;    /* composant of each RGB       */
                    640:   unsigned short      blueval = 0;     /* default to red if unknown ! */
                    641:   int                 best = 0;        /* best color in list found */
                    642: 
1.82      cvs       643:   cssRule = SkipBlanksAndComments (cssRule);
1.184     vatton    644:   val->typed_data.unit = UNIT_INVALID;
1.43      cvs       645:   val->typed_data.real = FALSE;
                    646:   val->typed_data.value = 0;
1.57      cvs       647:   ptr = TtaGiveRGB (cssRule, &redval, &greenval, &blueval);
1.292     vatton    648:   if (!strncasecmp (cssRule, "InactiveCaptionText", 19))
                    649:     {
                    650:       cssRule += 19;
                    651:     }
                    652:   else if (!strncasecmp (cssRule, "ThreeDLightShadow", 17))
                    653:     {
                    654:       cssRule += 17;
                    655:     }
                    656:   else if (!strncasecmp (cssRule, "ThreeDDarkShadow", 16))
                    657:     {
                    658:       cssRule += 16;
                    659:     }
                    660:   else if (!strncasecmp (cssRule, "ButtonHighlight", 15) ||
1.327     vatton    661:            !strncasecmp (cssRule, "InactiveCaption", 15) ||
                    662:            !strncasecmp (cssRule, "ThreeDHighlight", 15))
1.292     vatton    663:     {
                    664:       cssRule += 15;
                    665:     }
                    666:   else if (!strncasecmp (cssRule, "InactiveBorder", 14) ||
1.327     vatton    667:            !strncasecmp (cssRule, "InfoBackground", 14))
1.292     vatton    668:     {
                    669:       cssRule += 14;
                    670:     }
                    671:   else if (!strncasecmp (cssRule, "ActiveCaption", 13) ||
1.327     vatton    672:            !strncasecmp (cssRule, "HighlightText", 13))
1.292     vatton    673:     {
                    674:       cssRule += 13;
                    675:     }
                    676:   else if (!strncasecmp (cssRule, "ActiveBorder", 12) ||
1.327     vatton    677:            !strncasecmp (cssRule, "AppWorkspace", 12) ||
                    678:            !strncasecmp (cssRule, "ButtonShadow", 12) ||
                    679:            !strncasecmp (cssRule, "ThreeDShadow", 12))
1.292     vatton    680:     {
                    681:       cssRule += 12;
                    682:     }
                    683:   else if (!strncasecmp (cssRule, "CaptionText", 11) ||
1.327     vatton    684:            !strncasecmp (cssRule, "WindowFrame", 11))
1.292     vatton    685:     {
                    686:       cssRule += 11;
                    687:     }
                    688:   else if (!strncasecmp (cssRule, "Background", 10) ||
1.327     vatton    689:            !strncasecmp (cssRule, "ButtonFace", 10) ||
                    690:            !strncasecmp (cssRule, "ButtonText", 10) ||
                    691:            !strncasecmp (cssRule, "ThreeDFace", 10) ||
                    692:            !strncasecmp (cssRule, "WindowText", 10))
1.292     vatton    693:     {
                    694:       cssRule += 10;
                    695:     }
                    696:   else if (!strncasecmp (cssRule, "Highlight", 9) ||
1.327     vatton    697:            !strncasecmp (cssRule, "Scrollbar", 9))
1.292     vatton    698:     {
                    699:       cssRule += 9;
                    700:     }
                    701:   else if (!strncasecmp (cssRule, "GrayText", 8) ||
1.327     vatton    702:            !strncasecmp (cssRule, "InfoText", 8) ||
                    703:            !strncasecmp (cssRule, "MenuText", 8))
1.292     vatton    704:     {
                    705:       cssRule += 8;
                    706:     }
                    707:   else if (!strncasecmp (cssRule, "Window", 6))
                    708:     {
                    709:       cssRule += 6;
                    710:     }
                    711:   else if (!strncasecmp (cssRule, "Menu", 5))
                    712:     {
                    713:       cssRule += 5;
                    714:     }
1.293     quint     715:   else if (!strncasecmp (cssRule, "inherit", 7))
                    716:     {
                    717:       val->typed_data.unit = VALUE_INHERIT;
                    718:       cssRule += 7;
                    719:     }
1.292     vatton    720: 
1.57      cvs       721:   if (ptr == cssRule)
1.43      cvs       722:     {
1.168     vatton    723:       cssRule = SkipWord (cssRule);
                    724:       CSSParseError ("Invalid color value", ptr, cssRule);
1.43      cvs       725:       val->typed_data.value = 0;
1.184     vatton    726:       val->typed_data.unit = UNIT_INVALID;
1.43      cvs       727:     }
1.293     quint     728:   else if (val->typed_data.unit != VALUE_INHERIT)
1.43      cvs       729:     {
                    730:       best = TtaGetThotColor (redval, greenval, blueval);
                    731:       val->typed_data.value = best;
1.184     vatton    732:       val->typed_data.unit = UNIT_REL;
1.57      cvs       733:       cssRule = ptr;
1.43      cvs       734:     }
                    735:   val->typed_data.real = FALSE;
1.262     vatton    736:   cssRule = SkipBlanksAndComments (cssRule);
1.65      cvs       737:   return (cssRule);
1.43      cvs       738: }
1.1       cvs       739: 
                    740: /*----------------------------------------------------------------------
1.231     vatton    741:   CheckImportantRule updates the field important of the context and
                    742:   the line number.
1.117     vatton    743:   ----------------------------------------------------------------------*/
                    744: static char *CheckImportantRule (char *cssRule, PresentationContext context)
                    745: {
1.276     vatton    746:   PresentationContextBlock dummyctxt;
                    747: 
                    748:   if (context == NULL)
                    749:     /* no context provided */
                    750:     context = &dummyctxt;
                    751: 
1.117     vatton    752:   cssRule = SkipBlanksAndComments (cssRule);
1.231     vatton    753:   /* update the line number */
                    754:   context->cssLine = LineNumber + NewLineSkipped;
1.120     vatton    755:   if (*cssRule != '!')
                    756:     context->important = FALSE;
                    757:   else
1.117     vatton    758:     {
1.120     vatton    759:       cssRule++;
                    760:       cssRule = SkipBlanksAndComments (cssRule);
                    761:       if (!strncasecmp (cssRule, "important", 9))
1.327     vatton    762:         {
                    763:           context->important = TRUE;
                    764:           cssRule += 9;
                    765:         }
1.120     vatton    766:       else
1.327     vatton    767:         context->important = FALSE;
1.117     vatton    768:     }
                    769:   return (cssRule);
                    770: }
                    771: 
                    772: /*----------------------------------------------------------------------
1.327     vatton    773:   ParseCSSBorderTopWidth: parse a CSS BorderTopWidth
                    774:   attribute string.                                          
1.1       cvs       775:   ----------------------------------------------------------------------*/
1.79      cvs       776: static char *ParseCSSBorderTopWidth (Element element, PSchema tsch,
1.327     vatton    777:                                      PresentationContext context, 
                    778:                                      char *cssRule, CSSInfoPtr css,
                    779:                                      ThotBool isHTML)
1.1       cvs       780: {
1.41      cvs       781:   PresentationValue   border;
                    782:   
1.82      cvs       783:   cssRule = SkipBlanksAndComments (cssRule);
1.288     vatton    784:   cssRule = ParseABorderValue (cssRule, &border);
1.295     vatton    785:   /* check if it's an important rule */
                    786:   cssRule = CheckImportantRule (cssRule, context);
1.184     vatton    787:   if (border.typed_data.unit != UNIT_INVALID && DoApply)
1.44      cvs       788:     {
                    789:       TtaSetStylePresentation (PRBorderTopWidth, element, tsch, context, border);
                    790:       border.typed_data.value = 1;
1.184     vatton    791:       border.typed_data.unit = UNIT_REL;
1.44      cvs       792:     }
1.1       cvs       793:   return (cssRule);
                    794: }
                    795: 
                    796: /*----------------------------------------------------------------------
1.327     vatton    797:   ParseCSSBorderBottomWidth: parse a CSS BorderBottomWidth
                    798:   attribute string.                                          
1.1       cvs       799:   ----------------------------------------------------------------------*/
1.79      cvs       800: static char *ParseCSSBorderBottomWidth (Element element, PSchema tsch,
1.327     vatton    801:                                         PresentationContext context,
                    802:                                         char *cssRule, CSSInfoPtr css,
                    803:                                         ThotBool isHTML)
1.1       cvs       804: {
1.41      cvs       805:   PresentationValue   border;
                    806:   
1.82      cvs       807:   cssRule = SkipBlanksAndComments (cssRule);
1.41      cvs       808:   /* first parse the attribute string */
1.288     vatton    809:   cssRule = ParseABorderValue (cssRule, &border);
1.295     vatton    810:   /* check if it's an important rule */
                    811:   cssRule = CheckImportantRule (cssRule, context);
1.184     vatton    812:   if (border.typed_data.unit != UNIT_INVALID && DoApply)
1.44      cvs       813:     {
                    814:       TtaSetStylePresentation (PRBorderBottomWidth, element, tsch, context, border);
                    815:       border.typed_data.value = 1;
1.184     vatton    816:       border.typed_data.unit = UNIT_REL;
1.44      cvs       817:     }
1.1       cvs       818:   return (cssRule);
                    819: }
                    820: 
                    821: /*----------------------------------------------------------------------
1.327     vatton    822:   ParseCSSBorderLeftWidth: parse a CSS BorderLeftWidth
                    823:   attribute string.                                          
1.1       cvs       824:   ----------------------------------------------------------------------*/
1.79      cvs       825: static char *ParseCSSBorderLeftWidth (Element element, PSchema tsch,
1.327     vatton    826:                                       PresentationContext context,
                    827:                                       char *cssRule, CSSInfoPtr css,
                    828:                                       ThotBool isHTML)
1.1       cvs       829: {
1.41      cvs       830:   PresentationValue   border;
                    831:   
1.82      cvs       832:   cssRule = SkipBlanksAndComments (cssRule);
1.41      cvs       833:   /* first parse the attribute string */
1.288     vatton    834:   cssRule = ParseABorderValue (cssRule, &border);
1.295     vatton    835:   /* check if it's an important rule */
                    836:   cssRule = CheckImportantRule (cssRule, context);
1.184     vatton    837:   if (border.typed_data.unit != UNIT_INVALID && DoApply)
1.44      cvs       838:     {
                    839:       TtaSetStylePresentation (PRBorderLeftWidth, element, tsch, context, border);
                    840:       border.typed_data.value = 1;
1.184     vatton    841:       border.typed_data.unit = UNIT_REL;
1.44      cvs       842:     }
1.1       cvs       843:   return (cssRule);
                    844: }
                    845: 
                    846: /*----------------------------------------------------------------------
1.327     vatton    847:   ParseCSSBorderRightWidth: parse a CSS BorderRightWidth
                    848:   attribute string.                                          
1.1       cvs       849:   ----------------------------------------------------------------------*/
1.79      cvs       850: static char *ParseCSSBorderRightWidth (Element element, PSchema tsch,
1.327     vatton    851:                                        PresentationContext context,
                    852:                                        char *cssRule, CSSInfoPtr css,
                    853:                                        ThotBool isHTML)
1.1       cvs       854: {
1.41      cvs       855:   PresentationValue   border;
                    856:   
1.82      cvs       857:   cssRule = SkipBlanksAndComments (cssRule);
1.41      cvs       858:   /* first parse the attribute string */
1.288     vatton    859:   cssRule = ParseABorderValue (cssRule, &border);
1.295     vatton    860:   /* check if it's an important rule */
                    861:   cssRule = CheckImportantRule (cssRule, context);
1.184     vatton    862:   if (border.typed_data.unit != UNIT_INVALID && DoApply)
1.44      cvs       863:     {
                    864:       TtaSetStylePresentation (PRBorderRightWidth, element, tsch, context, border);
                    865:       border.typed_data.value = 1;
1.184     vatton    866:       border.typed_data.unit = UNIT_REL;
1.44      cvs       867:     }
1.1       cvs       868:   return (cssRule);
                    869: }
                    870: 
                    871: /*----------------------------------------------------------------------
1.327     vatton    872:   ParseCSSBorderWidth: parse a CSS BorderWidth
                    873:   attribute string.                                          
1.1       cvs       874:   ----------------------------------------------------------------------*/
1.79      cvs       875: static char *ParseCSSBorderWidth (Element element, PSchema tsch,
1.327     vatton    876:                                   PresentationContext context,
                    877:                                   char *cssRule, CSSInfoPtr css,
                    878:                                   ThotBool isHTML)
1.1       cvs       879: {
1.79      cvs       880:   char *ptrT, *ptrR, *ptrB, *ptrL;
1.93      vatton    881:   int   skippedNL;
1.41      cvs       882: 
1.82      cvs       883:   ptrT = SkipBlanksAndComments (cssRule);
1.42      cvs       884:   /* First parse Border-Top */
                    885:   ptrR = ParseCSSBorderTopWidth (element, tsch, context, ptrT, css, isHTML);
1.82      cvs       886:   ptrR = SkipBlanksAndComments (ptrR);
1.301     vatton    887:   if (*ptrR == ';' || *ptrR == '}' || *ptrR == EOS || *ptrR == ',')
1.42      cvs       888:     {
1.93      vatton    889:       skippedNL = NewLineSkipped;
1.42      cvs       890:       cssRule = ptrR;
                    891:       /* apply the Border-Top to all */
                    892:       ptrR = ParseCSSBorderRightWidth (element, tsch, context, ptrT, css, isHTML);
1.93      vatton    893:       NewLineSkipped = skippedNL;
1.42      cvs       894:       ptrR = ParseCSSBorderBottomWidth (element, tsch, context, ptrT, css, isHTML);
1.93      vatton    895:       NewLineSkipped = skippedNL;
1.42      cvs       896:       ptrR = ParseCSSBorderLeftWidth (element, tsch, context, ptrT, css, isHTML);
                    897:     }
                    898:   else
                    899:     {
                    900:       /* parse Border-Right */
                    901:       ptrB = ParseCSSBorderRightWidth (element, tsch, context, ptrR, css, isHTML);
1.82      cvs       902:       ptrB = SkipBlanksAndComments (ptrB);
1.301     vatton    903:       if (*ptrB == ';' || *ptrB == '}' || *ptrB == EOS || *ptrB == ',')
1.327     vatton    904:         {
                    905:           skippedNL = NewLineSkipped;
                    906:           cssRule = ptrB;
                    907:           /* apply the Border-Top to Border-Bottom */
                    908:           ptrB = ParseCSSBorderBottomWidth (element, tsch, context, ptrT, css, isHTML);
                    909:           NewLineSkipped = skippedNL;
                    910:           /* apply the Border-Right to Border-Left */
                    911:           ptrB = ParseCSSBorderLeftWidth (element, tsch, context, ptrR, css, isHTML);
                    912:         }
1.42      cvs       913:       else
1.327     vatton    914:         {
                    915:           /* parse Border-Bottom */
                    916:           ptrL = ParseCSSBorderBottomWidth (element, tsch, context, ptrB, css, isHTML);
                    917:           ptrL = SkipBlanksAndComments (ptrL);
                    918:           if (*ptrL == ';' || *ptrL == '}' || *ptrL == EOS || *ptrL == ',')
                    919:             {
                    920:               cssRule = ptrL;
                    921:               /* apply the Border-Right to Border-Left */
                    922:               ptrL = ParseCSSBorderLeftWidth (element, tsch, context, ptrR, css, isHTML);
                    923:             }
                    924:           else
                    925:             /* parse Border-Left */
                    926:             cssRule = ParseCSSBorderLeftWidth (element, tsch, context, ptrL, css, isHTML);
                    927:           cssRule = SkipBlanksAndComments (cssRule);
                    928:         }
1.42      cvs       929:     }
1.1       cvs       930:   return (cssRule);
                    931: }
                    932: 
                    933: /*----------------------------------------------------------------------
1.327     vatton    934:   ParseCSSBorderColorTop: parse a CSS BorderColorTop
                    935:   attribute string.                                          
1.1       cvs       936:   ----------------------------------------------------------------------*/
1.79      cvs       937: static char *ParseCSSBorderColorTop (Element element, PSchema tsch,
1.327     vatton    938:                                      PresentationContext context,
                    939:                                      char *cssRule, CSSInfoPtr css,
                    940:                                      ThotBool isHTML)
1.1       cvs       941: {
1.117     vatton    942:   PresentationValue   best;
1.43      cvs       943: 
1.234     vatton    944:   if (!strncasecmp (cssRule, "transparent", 11))
                    945:     {
                    946:       best.typed_data.value = -2;  /* -2 means transparent */
                    947:       best.typed_data.unit = UNIT_REL;
                    948:       cssRule = SkipWord (cssRule);
                    949:     }
                    950:   else
                    951:     cssRule = ParseCSSColor (cssRule, &best);
1.295     vatton    952:   /* check if it's an important rule */
                    953:   cssRule = CheckImportantRule (cssRule, context);
1.184     vatton    954:   if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.117     vatton    955:     {
                    956:       /* install the new presentation */
                    957:       TtaSetStylePresentation (PRBorderTopColor, element, tsch, context, best);
                    958:     }
                    959:   return (cssRule);
1.1       cvs       960: }
                    961: 
                    962: /*----------------------------------------------------------------------
1.327     vatton    963:   ParseCSSBorderColorLeft: parse a CSS BorderColorLeft
                    964:   attribute string.                                          
1.42      cvs       965:   ----------------------------------------------------------------------*/
1.79      cvs       966: static char *ParseCSSBorderColorLeft (Element element, PSchema tsch,
1.327     vatton    967:                                       PresentationContext context,
                    968:                                       char *cssRule, CSSInfoPtr css,
                    969:                                       ThotBool isHTML)
1.42      cvs       970: {
1.117     vatton    971:   PresentationValue   best;
                    972:   
1.234     vatton    973:   if (!strncasecmp (cssRule, "transparent", 11))
                    974:     {
                    975:       best.typed_data.value = -2;  /* -2 means transparent */
                    976:       best.typed_data.unit = UNIT_REL;
                    977:       cssRule = SkipWord (cssRule);
                    978:     }
                    979:   else
                    980:     cssRule = ParseCSSColor (cssRule, &best);
1.295     vatton    981:   /* check if it's an important rule */
                    982:   cssRule = CheckImportantRule (cssRule, context);
1.184     vatton    983:   if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.117     vatton    984:     {
                    985:       /* install the new presentation */
                    986:       TtaSetStylePresentation (PRBorderLeftColor, element, tsch, context, best);
                    987:     }
                    988:   return (cssRule);
1.42      cvs       989: }
                    990: 
                    991: /*----------------------------------------------------------------------
1.327     vatton    992:   ParseCSSBorderColorBottom: parse a CSS BorderColorBottom
                    993:   attribute string.                                          
1.42      cvs       994:   ----------------------------------------------------------------------*/
1.79      cvs       995: static char *ParseCSSBorderColorBottom (Element element, PSchema tsch,
1.327     vatton    996:                                         PresentationContext context,
                    997:                                         char *cssRule, CSSInfoPtr css,
                    998:                                         ThotBool isHTML)
1.42      cvs       999: {
1.117     vatton   1000:   PresentationValue   best;
1.43      cvs      1001: 
1.234     vatton   1002:   if (!strncasecmp (cssRule, "transparent", 11))
                   1003:     {
                   1004:       best.typed_data.value = -2;  /* -2 means transparent */
                   1005:       best.typed_data.unit = UNIT_REL;
                   1006:       cssRule = SkipWord (cssRule);
                   1007:     }
                   1008:   else
                   1009:     cssRule = ParseCSSColor (cssRule, &best);
1.295     vatton   1010:   /* check if it's an important rule */
                   1011:   cssRule = CheckImportantRule (cssRule, context);
1.184     vatton   1012:   if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.117     vatton   1013:     {
                   1014:       /* install the new presentation */
                   1015:       TtaSetStylePresentation (PRBorderBottomColor, element, tsch, context, best);
                   1016:     }
1.327     vatton   1017:   return (cssRule);
1.42      cvs      1018: }
                   1019: 
                   1020: /*----------------------------------------------------------------------
1.327     vatton   1021:   ParseCSSBorderColorRight: parse a CSS BorderColorRight
                   1022:   attribute string.                                          
1.1       cvs      1023:   ----------------------------------------------------------------------*/
1.79      cvs      1024: static char *ParseCSSBorderColorRight (Element element, PSchema tsch,
1.327     vatton   1025:                                        PresentationContext context,
                   1026:                                        char *cssRule, CSSInfoPtr css,
                   1027:                                        ThotBool isHTML)
1.1       cvs      1028: {
1.117     vatton   1029:   PresentationValue   best;
1.43      cvs      1030: 
1.234     vatton   1031:   if (!strncasecmp (cssRule, "transparent", 11))
                   1032:     {
                   1033:       best.typed_data.value = -2;  /* -2 means transparent */
                   1034:       best.typed_data.unit = UNIT_REL;
                   1035:       cssRule = SkipWord (cssRule);
                   1036:     }
                   1037:   else
                   1038:     cssRule = ParseCSSColor (cssRule, &best);
1.295     vatton   1039:   cssRule = CheckImportantRule (cssRule, context);
1.184     vatton   1040:   if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.117     vatton   1041:     {
                   1042:       /* check if it's an important rule */
                   1043:       /* install the new presentation */
                   1044:       TtaSetStylePresentation (PRBorderRightColor, element, tsch, context, best);
                   1045:     }
                   1046:   return (cssRule);
1.1       cvs      1047: }
                   1048: 
                   1049: /*----------------------------------------------------------------------
1.327     vatton   1050:   ParseCSSBorderColor: parse a CSS border-color        
                   1051:   attribute string.                                          
1.42      cvs      1052:   ----------------------------------------------------------------------*/
1.79      cvs      1053: static char *ParseCSSBorderColor (Element element, PSchema tsch,
1.327     vatton   1054:                                   PresentationContext context,
                   1055:                                   char *cssRule, CSSInfoPtr css,
                   1056:                                   ThotBool isHTML)
1.42      cvs      1057: {
1.79      cvs      1058:   char *ptrT, *ptrR, *ptrB, *ptrL;
1.93      vatton   1059:   int   skippedNL;
1.42      cvs      1060: 
1.82      cvs      1061:   ptrT = SkipBlanksAndComments (cssRule);
1.42      cvs      1062:   /* First parse Border-Top */
1.43      cvs      1063:   ptrR = ParseCSSBorderColorTop (element, tsch, context, ptrT, css, isHTML);
1.82      cvs      1064:   ptrR = SkipBlanksAndComments (ptrR);
1.301     vatton   1065:   if (*ptrR == ';' || *ptrR == '}' || *ptrR == EOS || *ptrR == ',')
1.42      cvs      1066:     {
1.93      vatton   1067:       skippedNL = NewLineSkipped;
1.42      cvs      1068:       cssRule = ptrR;
                   1069:       /* apply the Border-Top to all */
1.43      cvs      1070:       ptrR = ParseCSSBorderColorRight (element, tsch, context, ptrT, css, isHTML);
1.327     vatton   1071:       NewLineSkipped = skippedNL;
1.43      cvs      1072:       ptrR = ParseCSSBorderColorBottom (element, tsch, context, ptrT, css, isHTML);
1.327     vatton   1073:       NewLineSkipped = skippedNL;
1.43      cvs      1074:       ptrR = ParseCSSBorderColorLeft (element, tsch, context, ptrT, css, isHTML);
1.42      cvs      1075:     }
                   1076:   else
                   1077:     {
                   1078:       /* parse Border-Right */
1.43      cvs      1079:       ptrB = ParseCSSBorderColorRight (element, tsch, context, ptrR, css, isHTML);
1.82      cvs      1080:       ptrB = SkipBlanksAndComments (ptrB);
1.301     vatton   1081:       if (*ptrB == ';' || *ptrB == '}' || *ptrB == EOS || *ptrB == ',')
1.327     vatton   1082:         {
                   1083:           skippedNL = NewLineSkipped;
                   1084:           cssRule = ptrB;
                   1085:           /* apply the Border-Top to Border-Bottom */
                   1086:           ptrB = ParseCSSBorderColorBottom (element, tsch, context, ptrT, css, isHTML);
                   1087:           NewLineSkipped = skippedNL;
                   1088:           /* apply the Border-Right to Border-Left */
                   1089:           ptrB = ParseCSSBorderColorLeft (element, tsch, context, ptrR, css, isHTML);
                   1090:         }
1.42      cvs      1091:       else
1.327     vatton   1092:         {
                   1093:           skippedNL = NewLineSkipped;
                   1094:           /* parse Border-Bottom */
                   1095:           ptrL = ParseCSSBorderColorBottom (element, tsch, context, ptrB, css, isHTML);
                   1096:           NewLineSkipped = skippedNL;
                   1097:           ptrL = SkipBlanksAndComments (ptrL);
                   1098:           if (*ptrL == ';' || *ptrL == '}' || *ptrL == EOS || *ptrL == ',')
                   1099:             {
                   1100:               cssRule = ptrL;
                   1101:               /* apply the Border-Right to Border-Left */
                   1102:               ptrL = ParseCSSBorderColorLeft (element, tsch, context, ptrR, css, isHTML);
                   1103:             }
                   1104:           else
                   1105:             /* parse Border-Left */
                   1106:             cssRule = ParseCSSBorderColorLeft (element, tsch, context, ptrL, css, isHTML);
                   1107:           cssRule = SkipBlanksAndComments (cssRule);
                   1108:         }
1.42      cvs      1109:     }
                   1110:   return (cssRule);
                   1111: }
                   1112: 
                   1113: /*----------------------------------------------------------------------
1.327     vatton   1114:   ParseCSSBorderStyleTop: parse a CSS BorderStyleTop
                   1115:   attribute string.                                          
1.42      cvs      1116:   ----------------------------------------------------------------------*/
1.79      cvs      1117: static char *ParseCSSBorderStyleTop (Element element, PSchema tsch,
1.327     vatton   1118:                                      PresentationContext context,
                   1119:                                      char *cssRule, CSSInfoPtr css,
                   1120:                                      ThotBool isHTML)
1.42      cvs      1121: {
1.43      cvs      1122:   PresentationValue   border;
                   1123:   
1.82      cvs      1124:   cssRule = SkipBlanksAndComments (cssRule);
1.43      cvs      1125:   cssRule = ParseBorderStyle (cssRule, &border);
1.295     vatton   1126:   cssRule = CheckImportantRule (cssRule, context);
1.184     vatton   1127:   if (border.typed_data.unit != UNIT_INVALID && DoApply)
1.117     vatton   1128:     {
                   1129:       /* check if it's an important rule */
                   1130:       TtaSetStylePresentation (PRBorderTopStyle, element, tsch, context, border);
                   1131:     }
1.42      cvs      1132:   return (cssRule);
                   1133: }
                   1134: 
                   1135: /*----------------------------------------------------------------------
1.327     vatton   1136:   ParseCSSBorderStyleLeft: parse a CSS BorderStyleLeft
                   1137:   attribute string.                                          
1.42      cvs      1138:   ----------------------------------------------------------------------*/
1.79      cvs      1139: static char *ParseCSSBorderStyleLeft (Element element, PSchema tsch,
1.327     vatton   1140:                                       PresentationContext context,
                   1141:                                       char *cssRule, CSSInfoPtr css,
                   1142:                                       ThotBool isHTML)
1.42      cvs      1143: {
1.43      cvs      1144:   PresentationValue   border;
                   1145:   
1.82      cvs      1146:   cssRule = SkipBlanksAndComments (cssRule);
1.43      cvs      1147:   cssRule = ParseBorderStyle (cssRule, &border);
1.295     vatton   1148:   cssRule = CheckImportantRule (cssRule, context);
1.184     vatton   1149:   if (border.typed_data.unit != UNIT_INVALID && DoApply)
1.117     vatton   1150:     {
                   1151:       /* check if it's an important rule */
                   1152:       TtaSetStylePresentation (PRBorderLeftStyle, element, tsch, context, border);
                   1153:     }
1.42      cvs      1154:   return (cssRule);
                   1155: }
                   1156: 
                   1157: /*----------------------------------------------------------------------
1.327     vatton   1158:   ParseCSSBorderStyleBottom: parse a CSS BorderStyleBottom
                   1159:   attribute string.                                          
1.1       cvs      1160:   ----------------------------------------------------------------------*/
1.79      cvs      1161: static char *ParseCSSBorderStyleBottom (Element element, PSchema tsch,
1.327     vatton   1162:                                         PresentationContext context,
                   1163:                                         char *cssRule, CSSInfoPtr css,
                   1164:                                         ThotBool isHTML)
1.1       cvs      1165: {
1.43      cvs      1166:   PresentationValue   border;
                   1167:   
1.82      cvs      1168:   cssRule = SkipBlanksAndComments (cssRule);
1.43      cvs      1169:   cssRule = ParseBorderStyle (cssRule, &border);
1.295     vatton   1170:   cssRule = CheckImportantRule (cssRule, context);
1.184     vatton   1171:   if (border.typed_data.unit != UNIT_INVALID && DoApply)
1.117     vatton   1172:     {
                   1173:       /* check if it's an important rule */
                   1174:       TtaSetStylePresentation (PRBorderBottomStyle, element, tsch, context, border);
                   1175:     }
1.1       cvs      1176:   return (cssRule);
                   1177: }
                   1178: 
                   1179: /*----------------------------------------------------------------------
1.327     vatton   1180:   ParseCSSBorderStyleRight: parse a CSS BorderStyleRight
                   1181:   attribute string.                                          
1.1       cvs      1182:   ----------------------------------------------------------------------*/
1.79      cvs      1183: static char *ParseCSSBorderStyleRight (Element element, PSchema tsch,
1.327     vatton   1184:                                        PresentationContext context,
                   1185:                                        char *cssRule, CSSInfoPtr css,
                   1186:                                        ThotBool isHTML)
1.1       cvs      1187: {
1.43      cvs      1188:   PresentationValue   border;
                   1189:   
1.82      cvs      1190:   cssRule = SkipBlanksAndComments (cssRule);
1.43      cvs      1191:   cssRule = ParseBorderStyle (cssRule, &border);
1.295     vatton   1192:   cssRule = CheckImportantRule (cssRule, context);
1.184     vatton   1193:   if (border.typed_data.unit != UNIT_INVALID && DoApply)
1.117     vatton   1194:     {
                   1195:       /* check if it's an important rule */
                   1196:       TtaSetStylePresentation (PRBorderRightStyle, element, tsch, context, border);
                   1197:     }
1.1       cvs      1198:   return (cssRule);
                   1199: }
                   1200: 
                   1201: /*----------------------------------------------------------------------
1.327     vatton   1202:   ParseCSSBorderStyleStyle: parse a CSS border-style        
                   1203:   attribute string.                                          
1.1       cvs      1204:   ----------------------------------------------------------------------*/
1.79      cvs      1205: static char *ParseCSSBorderStyle (Element element, PSchema tsch,
1.327     vatton   1206:                                   PresentationContext context,
                   1207:                                   char *cssRule, CSSInfoPtr css,
                   1208:                                   ThotBool isHTML)
1.1       cvs      1209: {
1.79      cvs      1210:   char *ptrT, *ptrR, *ptrB, *ptrL;
1.93      vatton   1211:   int   skippedNL;
1.42      cvs      1212: 
1.82      cvs      1213:   ptrT = SkipBlanksAndComments (cssRule);
1.42      cvs      1214:   /* First parse Border-Top */
1.43      cvs      1215:   ptrR = ParseCSSBorderStyleTop (element, tsch, context, ptrT, css, isHTML);
1.82      cvs      1216:   ptrR = SkipBlanksAndComments (ptrR);
1.301     vatton   1217:   if (*ptrR == ';' || *ptrR == '}' || *ptrR == EOS || *ptrR == ',')
1.42      cvs      1218:     {
1.93      vatton   1219:       skippedNL = NewLineSkipped;
1.42      cvs      1220:       cssRule = ptrR;
                   1221:       /* apply the Border-Top to all */
1.43      cvs      1222:       ptrR = ParseCSSBorderStyleRight (element, tsch, context, ptrT, css, isHTML);
1.93      vatton   1223:       NewLineSkipped = skippedNL;
1.43      cvs      1224:       ptrR = ParseCSSBorderStyleBottom (element, tsch, context, ptrT, css, isHTML);
1.93      vatton   1225:       NewLineSkipped = skippedNL;
1.43      cvs      1226:       ptrR = ParseCSSBorderStyleLeft (element, tsch, context, ptrT, css, isHTML);
1.42      cvs      1227:     }
                   1228:   else
                   1229:     {
                   1230:       /* parse Border-Right */
1.43      cvs      1231:       ptrB = ParseCSSBorderStyleRight (element, tsch, context, ptrR, css, isHTML);
1.82      cvs      1232:       ptrB = SkipBlanksAndComments (ptrB);
1.301     vatton   1233:       if (*ptrB == ';' || *ptrR == '}' || *ptrB == EOS || *ptrB == ',')
1.327     vatton   1234:         {
                   1235:           skippedNL = NewLineSkipped;
                   1236:           cssRule = ptrB;
                   1237:           /* apply the Border-Top to Border-Bottom */
                   1238:           ptrB = ParseCSSBorderStyleBottom (element, tsch, context, ptrT, css, isHTML);
                   1239:           NewLineSkipped = skippedNL;
                   1240:           /* apply the Border-Right to Border-Left */
                   1241:           ptrB = ParseCSSBorderStyleLeft (element, tsch, context, ptrR, css, isHTML);
                   1242:         }
1.42      cvs      1243:       else
1.327     vatton   1244:         {
                   1245:           /* parse Border-Bottom */
                   1246:           ptrL = ParseCSSBorderStyleBottom (element, tsch, context, ptrB, css, isHTML);
                   1247:           ptrL = SkipBlanksAndComments (ptrL);
                   1248:           if (*ptrL == ';' || *ptrR == '}' || *ptrL == EOS || *ptrL == ',')
                   1249:             {
                   1250:               cssRule = ptrL;
                   1251:               /* apply the Border-Right to Border-Left */
                   1252:               ptrL = ParseCSSBorderStyleLeft (element, tsch, context, ptrR, css, isHTML);
                   1253:             }
                   1254:           else
                   1255:             /* parse Border-Left */
                   1256:             cssRule = ParseCSSBorderStyleLeft (element, tsch, context, ptrL, css, isHTML);
                   1257:           cssRule = SkipBlanksAndComments (cssRule);
                   1258:         }
1.42      cvs      1259:     }
                   1260:   return (cssRule);
                   1261: }
                   1262: 
                   1263: /*----------------------------------------------------------------------
1.327     vatton   1264:   ParseCSSBorderTop: parse a CSS BorderTop
                   1265:   attribute string.                                          
1.42      cvs      1266:   ----------------------------------------------------------------------*/
1.79      cvs      1267: static char *ParseCSSBorderTop (Element element, PSchema tsch,
1.327     vatton   1268:                                 PresentationContext context, char *cssRule,
                   1269:                                 CSSInfoPtr css, ThotBool isHTML)
1.42      cvs      1270: {
1.79      cvs      1271:   char           *ptr;
1.322     vatton   1272:   ThotBool        style, width;
1.43      cvs      1273: 
1.82      cvs      1274:   cssRule = SkipBlanksAndComments (cssRule);
1.322     vatton   1275:   /* register given values */
                   1276:   style = width = FALSE;
1.301     vatton   1277:   while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.43      cvs      1278:     {
                   1279:       ptr = cssRule;
                   1280:       cssRule = ParseCSSBorderStyleTop (element, tsch, context, cssRule, css, isHTML);
                   1281:       if (ptr == cssRule)
1.327     vatton   1282:         {
                   1283:           cssRule = ParseCSSBorderTopWidth (element, tsch, context, cssRule, css, isHTML);
                   1284:           if (ptr == cssRule)
                   1285:             cssRule = ParseCSSBorderColorTop (element, tsch, context, cssRule, css, isHTML);
                   1286:           else
                   1287:             width = TRUE;
                   1288:           if (ptr == cssRule)
                   1289:             {
                   1290:               /* rule not found */
                   1291:               cssRule = SkipValue ("Invalid border value", cssRule);
                   1292:               cssRule = CheckImportantRule (cssRule, context);
                   1293:               return (cssRule);
                   1294:             }
                   1295:         }
1.322     vatton   1296:       else
1.327     vatton   1297:         style = TRUE;
1.82      cvs      1298:       cssRule = SkipBlanksAndComments (cssRule);
1.43      cvs      1299:     }
1.322     vatton   1300: 
                   1301:   if (!width)
                   1302:     ParseCSSBorderTopWidth (element, tsch, context, "medium", css, isHTML);
                   1303:   if (!style)
                   1304:     ParseCSSBorderStyleTop (element, tsch, context, "none", css, isHTML);
                   1305:   cssRule = CheckImportantRule (cssRule, context);
1.42      cvs      1306:   return (cssRule);
                   1307: }
                   1308: 
                   1309: /*----------------------------------------------------------------------
1.327     vatton   1310:   ParseCSSBorderLeft: parse a CSS BorderLeft
                   1311:   attribute string.                                          
1.42      cvs      1312:   ----------------------------------------------------------------------*/
1.79      cvs      1313: static char *ParseCSSBorderLeft (Element element, PSchema tsch,
1.327     vatton   1314:                                  PresentationContext context, char *cssRule,
                   1315:                                  CSSInfoPtr css, ThotBool isHTML)
1.42      cvs      1316: {
1.79      cvs      1317:   char           *ptr;
1.322     vatton   1318:   ThotBool        style, width;
1.43      cvs      1319: 
1.82      cvs      1320:   cssRule = SkipBlanksAndComments (cssRule);
1.322     vatton   1321:   /* register given values */
                   1322:   style = width = FALSE;
1.301     vatton   1323:   while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.43      cvs      1324:     {
                   1325:       ptr = cssRule;
                   1326:       cssRule = ParseCSSBorderStyleLeft (element, tsch, context, cssRule, css, isHTML);
                   1327:       if (ptr == cssRule)
1.327     vatton   1328:         {
                   1329:           cssRule = ParseCSSBorderLeftWidth (element, tsch, context, cssRule, css, isHTML);
                   1330:           if (ptr == cssRule)
                   1331:             cssRule = ParseCSSBorderColorLeft (element, tsch, context, cssRule, css, isHTML);
                   1332:           else
                   1333:             width = TRUE;
                   1334:           if (ptr == cssRule)
                   1335:             {
                   1336:               /* rule not found */
                   1337:               cssRule = SkipValue ("Invalid border value", cssRule);
                   1338:               cssRule = CheckImportantRule (cssRule, context);
                   1339:               return (cssRule);
                   1340:             }
                   1341:         }
1.322     vatton   1342:       else
1.327     vatton   1343:         style = TRUE;
                   1344:       cssRule = SkipBlanksAndComments (cssRule);
1.43      cvs      1345:     }
1.322     vatton   1346: 
                   1347:   if (!width)
                   1348:     ParseCSSBorderLeftWidth (element, tsch, context, "medium", css, isHTML);
                   1349:   if (!style)
                   1350:     ParseCSSBorderStyleLeft (element, tsch, context, "none", css, isHTML);
                   1351:   cssRule = CheckImportantRule (cssRule, context);
1.1       cvs      1352:   return (cssRule);
                   1353: }
                   1354: 
                   1355: /*----------------------------------------------------------------------
1.327     vatton   1356:   ParseCSSBorderBottom: parse a CSS BorderBottom
                   1357:   attribute string.                                          
1.1       cvs      1358:   ----------------------------------------------------------------------*/
1.79      cvs      1359: static char *ParseCSSBorderBottom (Element element, PSchema tsch,
1.327     vatton   1360:                                    PresentationContext context, char *cssRule,
                   1361:                                    CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      1362: {
1.79      cvs      1363:   char           *ptr;
1.322     vatton   1364:   ThotBool        style, width;
1.43      cvs      1365: 
1.82      cvs      1366:   cssRule = SkipBlanksAndComments (cssRule);
1.322     vatton   1367:   /* register given values */
                   1368:   style = width = FALSE;
1.301     vatton   1369:   while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.43      cvs      1370:     {
                   1371:       ptr = cssRule;
                   1372:       cssRule = ParseCSSBorderStyleBottom (element, tsch, context, cssRule, css, isHTML);
                   1373:       if (ptr == cssRule)
1.327     vatton   1374:         {
                   1375:           cssRule = ParseCSSBorderBottomWidth (element, tsch, context, cssRule, css, isHTML);
                   1376:           if (ptr == cssRule)
                   1377:             cssRule = ParseCSSBorderColorBottom (element, tsch, context, cssRule, css, isHTML);
                   1378:           else
                   1379:             width = TRUE;
                   1380:           if (ptr == cssRule)
                   1381:             {
                   1382:               /* rule not found */
                   1383:               cssRule = SkipValue ("Invalid border value", cssRule);
                   1384:               cssRule = CheckImportantRule (cssRule, context);
                   1385:               return (cssRule);
                   1386:             }
                   1387:         }
1.322     vatton   1388:       else
1.327     vatton   1389:         style = TRUE;
1.82      cvs      1390:       cssRule = SkipBlanksAndComments (cssRule);
1.43      cvs      1391:     }
1.322     vatton   1392: 
                   1393:   if (!width)
                   1394:     ParseCSSBorderBottomWidth (element, tsch, context, "medium", css, isHTML);
                   1395:   if (!style)
                   1396:     ParseCSSBorderStyleBottom (element, tsch, context, "none", css, isHTML);
                   1397:   cssRule = CheckImportantRule (cssRule, context);
1.1       cvs      1398:   return (cssRule);
                   1399: }
                   1400: 
                   1401: /*----------------------------------------------------------------------
1.327     vatton   1402:   ParseCSSBorderRight: parse a CSS BorderRight
                   1403:   attribute string.                                          
1.1       cvs      1404:   ----------------------------------------------------------------------*/
1.79      cvs      1405: static char *ParseCSSBorderRight (Element element, PSchema tsch,
1.327     vatton   1406:                                   PresentationContext context, char *cssRule,
                   1407:                                   CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      1408: {
1.79      cvs      1409:   char            *ptr;
1.322     vatton   1410:   ThotBool        style, width;
1.43      cvs      1411: 
1.82      cvs      1412:   cssRule = SkipBlanksAndComments (cssRule);
1.322     vatton   1413:   /* register given values */
                   1414:   style = width = FALSE;
1.301     vatton   1415:   while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.43      cvs      1416:     {
                   1417:       ptr = cssRule;
                   1418:       cssRule = ParseCSSBorderStyleRight (element, tsch, context, cssRule, css, isHTML);
                   1419:       if (ptr == cssRule)
1.327     vatton   1420:         {
                   1421:           cssRule = ParseCSSBorderRightWidth (element, tsch, context, cssRule, css, isHTML);
                   1422:           if (ptr == cssRule)
                   1423:             cssRule = ParseCSSBorderColorRight (element, tsch, context, cssRule, css, isHTML);
                   1424:           else
                   1425:             width = TRUE;
                   1426:           if (ptr == cssRule)
                   1427:             {
                   1428:               /* rule not found */
                   1429:               cssRule = SkipValue ("Invalid border value", cssRule);
                   1430:               cssRule = CheckImportantRule (cssRule, context);
                   1431:               return (cssRule);
                   1432:             }
                   1433:         }
1.322     vatton   1434:       else
1.327     vatton   1435:         style = TRUE;
1.82      cvs      1436:       cssRule = SkipBlanksAndComments (cssRule);
1.43      cvs      1437:     }
1.322     vatton   1438: 
                   1439:   if (!width)
                   1440:     ParseCSSBorderRightWidth (element, tsch, context, "medium", css, isHTML);
                   1441:   if (!style)
                   1442:     ParseCSSBorderStyleRight (element, tsch, context, "none", css, isHTML);
                   1443:   cssRule = CheckImportantRule (cssRule, context);
1.1       cvs      1444:   return (cssRule);
                   1445: }
                   1446: 
                   1447: /*----------------------------------------------------------------------
1.327     vatton   1448:   ParseCSSBorder: parse a CSS border        
                   1449:   attribute string.                                          
1.42      cvs      1450:   ----------------------------------------------------------------------*/
1.79      cvs      1451: static char *ParseCSSBorder (Element element, PSchema tsch,
1.327     vatton   1452:                              PresentationContext context, char *cssRule,
                   1453:                              CSSInfoPtr css, ThotBool isHTML)
1.42      cvs      1454: {
1.79      cvs      1455:   char *ptrT, *ptrR;
1.93      vatton   1456:   int   skippedNL;
1.42      cvs      1457: 
1.82      cvs      1458:   ptrT = SkipBlanksAndComments (cssRule);
1.42      cvs      1459:   /* First parse Border-Top */
                   1460:   ptrR = ParseCSSBorderTop (element, tsch, context, ptrT, css, isHTML);
1.82      cvs      1461:   ptrR = SkipBlanksAndComments (ptrR);
1.301     vatton   1462:   if (*ptrR == ';' || *ptrR == '}' || *ptrR == EOS || *ptrR == ',')
1.42      cvs      1463:     {
1.93      vatton   1464:       skippedNL = NewLineSkipped;
1.42      cvs      1465:       cssRule = ptrR;
                   1466:       /* apply the Border-Top to all */
                   1467:       ptrR = ParseCSSBorderRight (element, tsch, context, ptrT, css, isHTML);
1.93      vatton   1468:       NewLineSkipped = skippedNL;
1.42      cvs      1469:       ptrR = ParseCSSBorderBottom (element, tsch, context, ptrT, css, isHTML);
1.93      vatton   1470:       NewLineSkipped = skippedNL;
1.42      cvs      1471:       ptrR = ParseCSSBorderLeft (element, tsch, context, ptrT, css, isHTML);
                   1472:     }
                   1473:   return (cssRule);
                   1474: }
                   1475: 
1.218     vatton   1476: 
1.42      cvs      1477: /*----------------------------------------------------------------------
1.327     vatton   1478:   ParseCSSFloat: parse a CSS float attribute string    
1.184     vatton   1479:   ----------------------------------------------------------------------*/
                   1480: static char *ParseCSSFloat (Element element, PSchema tsch,
1.327     vatton   1481:                             PresentationContext context, char *cssRule,
                   1482:                             CSSInfoPtr css, ThotBool isHTML)
1.184     vatton   1483: {
1.257     vatton   1484:   DisplayMode         dispMode;
1.184     vatton   1485:   PresentationValue   pval;
1.288     vatton   1486:   char               *ptr = cssRule;
1.184     vatton   1487: 
                   1488:   pval.typed_data.value = 0;
1.187     vatton   1489:   pval.typed_data.unit = UNIT_BOX;
1.192     cvs      1490:   pval.typed_data.real = FALSE;
1.190     vatton   1491:   if (!strncasecmp (cssRule, "inherit", 7))
                   1492:     {
1.293     quint    1493:       pval.typed_data.unit = VALUE_INHERIT;
1.288     vatton   1494:       cssRule += 7;
1.190     vatton   1495:     }
1.184     vatton   1496:   if (!strncasecmp (cssRule, "none", 4))
1.288     vatton   1497:     {
                   1498:       pval.typed_data.value = FloatNone;
1.293     quint    1499:       cssRule += 4;
1.288     vatton   1500:     }
1.184     vatton   1501:   else if (!strncasecmp (cssRule, "left", 4))
1.288     vatton   1502:     {
                   1503:       pval.typed_data.value = FloatLeft;
1.293     quint    1504:       cssRule += 4;
1.288     vatton   1505:     }
1.184     vatton   1506:   else if (!strncasecmp (cssRule, "right", 5))
1.288     vatton   1507:     {
                   1508:       pval.typed_data.value = FloatRight;
1.293     quint    1509:       cssRule += 5;
1.288     vatton   1510:     }
1.184     vatton   1511: 
1.293     quint    1512:   if (pval.typed_data.value == 0 && pval.typed_data.unit != VALUE_INHERIT)
1.211     vatton   1513:     cssRule = SkipValue ("Invalid float value", cssRule);
1.184     vatton   1514:   else
                   1515:     {
1.295     vatton   1516:       cssRule = CheckImportantRule (cssRule, context);
1.184     vatton   1517:       if (DoApply)
1.327     vatton   1518:         {
                   1519:           dispMode = TtaGetDisplayMode (context->doc);
                   1520:           if (dispMode != NoComputedDisplay)
                   1521:             {
                   1522:               /* force a redisplay of the whole document */
                   1523:               TtaSetDisplayMode (context->doc, NoComputedDisplay);
1.257     vatton   1524: #ifdef AMAYA_DEBUG
1.327     vatton   1525:               /*printf ("Force NoComputedDisplay doc=%d\n", context->doc);*/
1.257     vatton   1526: #endif /* AMAYA_DEBUG */
1.327     vatton   1527:             }
                   1528:           TtaSetStylePresentation (PRFloat, element, tsch, context, pval);
                   1529:         }
1.288     vatton   1530:       cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid float value");
1.184     vatton   1531:     }
                   1532:   return (cssRule);
                   1533: }
                   1534: 
                   1535: /*----------------------------------------------------------------------
1.327     vatton   1536:   ParseCSSClear: parse a CSS clear rule 
1.1       cvs      1537:   ----------------------------------------------------------------------*/
1.79      cvs      1538: static char *ParseCSSClear (Element element, PSchema tsch,
1.327     vatton   1539:                             PresentationContext context, char *cssRule,
                   1540:                             CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      1541: {
1.184     vatton   1542:   PresentationValue   pval;
                   1543: 
                   1544:   pval.typed_data.value = 0;
1.187     vatton   1545:   pval.typed_data.unit = UNIT_BOX;
1.193     vatton   1546:   pval.typed_data.real = FALSE;
1.190     vatton   1547:   if (!strncasecmp (cssRule, "inherit", 7))
1.293     quint    1548:     pval.typed_data.unit = VALUE_INHERIT;
1.184     vatton   1549:   if (!strncasecmp (cssRule, "none", 4))
                   1550:     pval.typed_data.value = ClearNone;
                   1551:   else if (!strncasecmp (cssRule, "left", 4))
                   1552:     pval.typed_data.value = ClearLeft;
                   1553:   else if (!strncasecmp (cssRule, "right", 5))
                   1554:     pval.typed_data.value = ClearRight;
                   1555:   else if (!strncasecmp (cssRule, "both", 4))
                   1556:     pval.typed_data.value = ClearBoth;
                   1557: 
1.293     quint    1558:   if (pval.typed_data.value == 0 && pval.typed_data.unit != VALUE_INHERIT)
1.295     vatton   1559:     {
                   1560:       cssRule = SkipValue ("Invalid clear value", cssRule);
                   1561:       cssRule = CheckImportantRule (cssRule, context);
                   1562:       cssRule = SkipValue (NULL, cssRule);
                   1563:     }
1.184     vatton   1564:   else
                   1565:     {
1.295     vatton   1566:       cssRule = SkipValue (NULL, cssRule);
                   1567:       cssRule = CheckImportantRule (cssRule, context);
1.184     vatton   1568:       if (DoApply)
1.327     vatton   1569:         TtaSetStylePresentation (PRClear, element, tsch, context, pval);
1.184     vatton   1570:     }
                   1571:   return (cssRule);
                   1572: }
                   1573: 
                   1574: /*----------------------------------------------------------------------
1.327     vatton   1575:   ParseCSSDisplay: parse a CSS display attribute string        
1.1       cvs      1576:   ----------------------------------------------------------------------*/
1.79      cvs      1577: static char *ParseCSSDisplay (Element element, PSchema tsch,
1.327     vatton   1578:                               PresentationContext context, char *cssRule,
                   1579:                               CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      1580: {
1.184     vatton   1581:   PresentationValue   pval;
1.288     vatton   1582:   char               *ptr = cssRule;
1.1       cvs      1583: 
1.184     vatton   1584:   pval.typed_data.unit = UNIT_REL;
                   1585:   pval.typed_data.real = FALSE;
                   1586:   cssRule = SkipBlanksAndComments (cssRule);
                   1587:   if (!strncasecmp (cssRule, "none", 4))
1.288     vatton   1588:     {
                   1589:       cssRule += 4;
                   1590:       pval.typed_data.value = DisplayNone;
                   1591:     }
1.277     quint    1592:   else if (!strncasecmp (cssRule, "block", 5))
1.288     vatton   1593:     {
                   1594:       cssRule += 5;
                   1595:       pval.typed_data.value = Block;
                   1596:     }
1.303     vatton   1597:   else if (!strncasecmp (cssRule, "inline-block", 12))
                   1598:     {
                   1599:       cssRule += 12;
                   1600:       pval.typed_data.value = InlineBlock;
                   1601:     }
1.277     quint    1602:   else if (!strncasecmp (cssRule, "inline", 6))
1.288     vatton   1603:     {
                   1604:       cssRule += 6;
                   1605:       pval.typed_data.value = Inline;
                   1606:     }
1.277     quint    1607:   else if (!strncasecmp (cssRule, "list-item", 9))
1.288     vatton   1608:     {
                   1609:       cssRule += 9;
                   1610:       pval.typed_data.value = ListItem;
                   1611:     }
1.277     quint    1612:   else if (!strncasecmp (cssRule, "run-in", 6))
1.288     vatton   1613:     {
                   1614:       cssRule += 6;
                   1615:       pval.typed_data.value = RunIn;
                   1616:     }
1.293     quint    1617:   else if (!strncasecmp (cssRule, "inherit", 7))
                   1618:     {
                   1619:       cssRule += 7;
                   1620:       pval.typed_data.unit = VALUE_INHERIT;
                   1621:     }
1.277     quint    1622:   else
1.184     vatton   1623:     {
1.277     quint    1624:       if (strncasecmp (cssRule, "table-row-group", 15) &&
1.327     vatton   1625:           strncasecmp (cssRule, "table-column-group", 18) &&
                   1626:           strncasecmp (cssRule, "table-header-group", 5) &&
                   1627:           strncasecmp (cssRule, "table-footer-group", 6) &&
                   1628:           strncasecmp (cssRule, "table-row", 9) &&
                   1629:           strncasecmp (cssRule, "table-column", 12) &&
                   1630:           strncasecmp (cssRule, "table-cell", 10) &&
                   1631:           strncasecmp (cssRule, "table-caption", 13) &&
                   1632:           strncasecmp (cssRule, "inline-table", 12) &&
                   1633:           strncasecmp (cssRule, "table", 5))
                   1634:         cssRule = SkipValue ("Display value not supported", cssRule);
1.281     quint    1635:       else
1.327     vatton   1636:         cssRule = SkipWord (cssRule);
1.277     quint    1637:       return (cssRule);
1.184     vatton   1638:     }
1.277     quint    1639: 
1.295     vatton   1640:   cssRule = CheckImportantRule (cssRule, context);
1.277     quint    1641:   if (DoApply)
1.295     vatton   1642:     TtaSetStylePresentation (PRDisplay, element, tsch, context, pval);
1.288     vatton   1643:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid display value");
1.1       cvs      1644:   return (cssRule);
                   1645: }
                   1646: 
                   1647: /*----------------------------------------------------------------------
1.327     vatton   1648:   ParseCSSLetterSpacing: parse a CSS letter-spacing    
                   1649:   attribute string.                                          
1.1       cvs      1650:   ----------------------------------------------------------------------*/
1.79      cvs      1651: static char *ParseCSSLetterSpacing (Element element, PSchema tsch,
1.327     vatton   1652:                                     PresentationContext context, char *cssRule,
                   1653:                                     CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      1654: {
1.168     vatton   1655:   cssRule = SkipValue (NULL, cssRule);
1.295     vatton   1656:   cssRule = CheckImportantRule (cssRule, context);
1.1       cvs      1657:   return (cssRule);
                   1658: }
                   1659: 
                   1660: /*----------------------------------------------------------------------
1.327     vatton   1661:   ParseACSSListStyleType: parse a CSS list-style-type
                   1662:   attribute string.                                          
1.1       cvs      1663:   ----------------------------------------------------------------------*/
1.318     vatton   1664: static char *ParseACSSListStyleType (Element element, PSchema tsch,
1.327     vatton   1665:                                      PresentationContext context, char *cssRule,
                   1666:                                      CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      1667: {
1.281     quint    1668:   PresentationValue   pval;
                   1669: 
                   1670:   pval.typed_data.unit = UNIT_REL;
                   1671:   pval.typed_data.real = FALSE;
                   1672:   cssRule = SkipBlanksAndComments (cssRule);
                   1673:   if (!strncasecmp (cssRule, "disc", 4))
1.288     vatton   1674:     {
                   1675:       cssRule += 4;
                   1676:       pval.typed_data.value = Disc;
                   1677:     }
1.281     quint    1678:   else if (!strncasecmp (cssRule, "circle", 6))
1.293     quint    1679:     {
1.288     vatton   1680:       cssRule += 6;
                   1681:       pval.typed_data.value = Circle;
1.293     quint    1682:     }
1.281     quint    1683:   else if (!strncasecmp (cssRule, "square", 6))
1.293     quint    1684:     {
1.288     vatton   1685:       cssRule += 6;
1.293     quint    1686:       pval.typed_data.value = Square;
                   1687:     }
1.283     quint    1688:   else if (!strncasecmp (cssRule, "decimal-leading-zero", 20))
1.293     quint    1689:     {
1.288     vatton   1690:       cssRule += 20;
1.293     quint    1691:       pval.typed_data.value = DecimalLeadingZero;
                   1692:     }
1.281     quint    1693:   else if (!strncasecmp (cssRule, "decimal", 7))
1.293     quint    1694:     {
1.288     vatton   1695:       cssRule += 7;
1.293     quint    1696:       pval.typed_data.value = Decimal;
                   1697:     }
1.281     quint    1698:   else if (!strncasecmp (cssRule, "lower-roman", 11))
1.293     quint    1699:     {
1.288     vatton   1700:       cssRule += 11;
1.293     quint    1701:       pval.typed_data.value = LowerRoman;
                   1702:     }
1.281     quint    1703:   else if (!strncasecmp (cssRule, "upper-roman", 11))
1.293     quint    1704:     {
1.288     vatton   1705:       cssRule += 11;
1.293     quint    1706:       pval.typed_data.value = UpperRoman;
                   1707:     }
1.281     quint    1708:   else if (!strncasecmp (cssRule, "lower-greek", 11))
1.293     quint    1709:     {
1.288     vatton   1710:       cssRule += 11;
1.293     quint    1711:       pval.typed_data.value = LowerGreek;
                   1712:     }
1.281     quint    1713:   else if (!strncasecmp (cssRule, "lower-latin", 11))
1.293     quint    1714:     {
1.288     vatton   1715:       cssRule += 11;
1.293     quint    1716:       pval.typed_data.value = LowerLatin;
                   1717:     }
1.281     quint    1718:   else if (!strncasecmp (cssRule, "lower-alpha", 11))
1.293     quint    1719:     {
1.288     vatton   1720:       cssRule += 11;
1.293     quint    1721:       pval.typed_data.value = LowerLatin;
                   1722:     }
1.281     quint    1723:   else if (!strncasecmp (cssRule, "upper-latin", 11))
1.293     quint    1724:     {
1.288     vatton   1725:       cssRule += 11;
1.293     quint    1726:       pval.typed_data.value = UpperLatin;
                   1727:     }
1.281     quint    1728:   else if (!strncasecmp (cssRule, "upper-alpha", 11))
1.293     quint    1729:     {
1.288     vatton   1730:       cssRule += 11;
1.293     quint    1731:       pval.typed_data.value = UpperLatin;
                   1732:     }
1.281     quint    1733:   else if (!strncasecmp (cssRule, "armenian", 8))
1.293     quint    1734:     {
1.288     vatton   1735:       cssRule += 8;
1.293     quint    1736:       pval.typed_data.value = Decimal;
                   1737:     }
1.281     quint    1738:   else if (!strncasecmp (cssRule, "georgian", 8))
1.293     quint    1739:     {
1.288     vatton   1740:       cssRule += 8;
1.293     quint    1741:       pval.typed_data.value = Decimal;
                   1742:     }
1.281     quint    1743:   else if (!strncasecmp (cssRule, "none", 4))
1.293     quint    1744:     {
1.288     vatton   1745:       cssRule += 4;
1.293     quint    1746:       pval.typed_data.value = ListStyleTypeNone;
                   1747:     }
1.281     quint    1748:   else if (!strncasecmp (cssRule, "inherit", 7))
                   1749:     {
1.293     quint    1750:       cssRule += 7;
                   1751:       pval.typed_data.unit = VALUE_INHERIT;
1.281     quint    1752:     }
                   1753:   else
                   1754:     {
                   1755:       cssRule = SkipValue ("Invalid list-style-type value", cssRule);
                   1756:       return (cssRule);
                   1757:     }
                   1758: 
1.295     vatton   1759:   cssRule = CheckImportantRule (cssRule, context);
1.281     quint    1760:   if (DoApply)
1.295     vatton   1761:     TtaSetStylePresentation (PRListStyleType, element, tsch, context, pval);
1.318     vatton   1762:   return (cssRule);
                   1763: }
                   1764: 
                   1765: /*----------------------------------------------------------------------
1.327     vatton   1766:   ParseCSSListStyleType: parse a CSS list-style-type
                   1767:   attribute string.                                          
1.318     vatton   1768:   ----------------------------------------------------------------------*/
                   1769: static char *ParseCSSListStyleType (Element element, PSchema tsch,
1.327     vatton   1770:                                     PresentationContext context, char *cssRule,
                   1771:                                     CSSInfoPtr css, ThotBool isHTML)
1.318     vatton   1772: {
                   1773:   char               *ptr = cssRule;
                   1774:   cssRule = ParseACSSListStyleType (element, tsch, context, cssRule, css,
1.327     vatton   1775:                                     isHTML);
1.288     vatton   1776:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid list-style-type value");
1.318     vatton   1777:   return cssRule;
1.1       cvs      1778: }
                   1779: 
                   1780: /*----------------------------------------------------------------------
1.281     quint    1781:   ParseCSSUrl: parse an URL
                   1782:   ----------------------------------------------------------------------*/
                   1783: static char *ParseCSSUrl (char *cssRule, char **url)
                   1784: {
                   1785:   char                       saved;
                   1786:   char                      *base, *ptr;
                   1787: 
                   1788:   cssRule = SkipBlanksAndComments (cssRule);
                   1789:   saved = *cssRule;
                   1790:   if (*cssRule == '(')
                   1791:     {
                   1792:       cssRule++;
                   1793:       cssRule = SkipBlanksAndComments (cssRule);
                   1794:       /*** Escaped quotes are not handled. See function SkipQuotedString */
                   1795:       if (*cssRule == '"')
1.327     vatton   1796:         {
                   1797:           cssRule++;
                   1798:           base = cssRule;
                   1799:           while (*cssRule != EOS && *cssRule != '"')
                   1800:             cssRule++;
                   1801:         }
1.281     quint    1802:       else if (*cssRule == '\'')
1.327     vatton   1803:         {
                   1804:           cssRule++;
                   1805:           base = cssRule;
                   1806:           while (*cssRule != EOS && *cssRule != '\'')
                   1807:             cssRule++;
                   1808:         }
1.281     quint    1809:       else
1.327     vatton   1810:         {
                   1811:           base = cssRule;
                   1812:           while (*cssRule != EOS && *cssRule != ')')
                   1813:             cssRule++;
                   1814:         }
1.281     quint    1815:       /* keep the current position */
                   1816:       ptr = cssRule;
                   1817:       if (saved == ')')
1.327     vatton   1818:         {
                   1819:           /* remove extra spaces */
                   1820:           if (cssRule[-1] == SPACE)
                   1821:             {
                   1822:               *cssRule = SPACE;
                   1823:               cssRule--;
                   1824:               while (cssRule[-1] == SPACE)
                   1825:                 cssRule--;
                   1826:             }
                   1827:         }
1.281     quint    1828:       saved = *cssRule;
                   1829:       *cssRule = EOS;
                   1830:       *url = TtaStrdup (base);
                   1831:       *cssRule = saved;
                   1832:       if (saved == '"' || saved == '\'')
1.327     vatton   1833:         /* we need to skip the quote character and possible spaces */
                   1834:         {
                   1835:           cssRule++;
                   1836:           cssRule = SkipBlanksAndComments (cssRule);
                   1837:         }
1.281     quint    1838:       else
1.327     vatton   1839:         cssRule = ptr;
1.281     quint    1840:     }
                   1841:   cssRule++;
                   1842:   return cssRule;
                   1843: }
                   1844: 
                   1845: /*----------------------------------------------------------------------
1.302     quint    1846:   ParseCSSImageCallback: Callback called asynchronously by
                   1847:   FetchImage when a CSS image (background-image or list-style-image)
                   1848:   has been fetched.
                   1849:   ----------------------------------------------------------------------*/
                   1850: void ParseCSSImageCallback (Document doc, Element element, char *file,
1.327     vatton   1851:                             void *extra, ThotBool isnew)
1.302     quint    1852: {
                   1853:   DisplayMode                dispMode = DisplayImmediately;
                   1854:   CSSImageCallbackPtr        callblock;
                   1855:   Element                    el;
                   1856:   PSchema                    tsch;
                   1857:   CSSInfoPtr                 css;
                   1858:   PInfoPtr                   pInfo;
                   1859:   PresentationContext        ctxt;
                   1860:   PresentationValue          image;
                   1861:   PresentationValue          value;
                   1862:   ThotBool                   enabled;
                   1863: 
                   1864:   callblock = (CSSImageCallbackPtr) extra;
                   1865:   if (callblock == NULL)
                   1866:     return;
                   1867: 
                   1868:   css = NULL;
                   1869:   el = callblock->el;
                   1870:   tsch = callblock->tsch;
                   1871:   ctxt = callblock->ctxt;
                   1872:   if (doc == 0 && !isnew)
                   1873:     /* apply to the current document only */
                   1874:     doc = ctxt->doc;
                   1875:   if (doc)
                   1876:     {
                   1877:       /* avoid too many redisplay */
                   1878:       dispMode = TtaGetDisplayMode (doc);
                   1879:       if (dispMode == DisplayImmediately)
1.327     vatton   1880:         TtaSetDisplayMode (doc, DeferredDisplay);
1.302     quint    1881:     }
                   1882:   else
                   1883:     {
                   1884:       /* check if the CSS still exists */
                   1885:       css = CSSList;
                   1886:       while (css && css != callblock->css)
1.327     vatton   1887:         css = css->NextCSS;
1.302     quint    1888:       if (css == NULL)
1.327     vatton   1889:         tsch = NULL;
1.302     quint    1890:     }
                   1891: 
                   1892:   if (el || tsch)
                   1893:     {
                   1894:       /* Ok the image was fetched */
                   1895:       image.typed_data.unit = UNIT_REL;
                   1896:       image.typed_data.real = FALSE;
                   1897:       image.pointer = file;
                   1898:       TtaSetStylePresentation (callblock->ruleType, el, tsch, ctxt, image);
                   1899:       
                   1900:       if (callblock->ruleType == PRBackgroundPicture)
1.327     vatton   1901:         /* enforce the showbox */
                   1902:         {
                   1903:           value.typed_data.value = 1;
                   1904:           value.typed_data.unit = UNIT_REL;
                   1905:           value.typed_data.real = FALSE;
                   1906:           TtaSetStylePresentation (PRShowBox, el, tsch, ctxt, value);
                   1907:         }
1.302     quint    1908:       /* check if the context can be freed */
                   1909:       ctxt->uses -= 1;
                   1910:       if (ctxt->uses == 0)
1.327     vatton   1911:         /* no other image loading */
                   1912:         TtaFreeMemory (ctxt);
1.302     quint    1913:     }
                   1914: 
                   1915:   TtaFreeMemory (callblock);
1.311     vatton   1916:   RedisplayImages--;
1.302     quint    1917:   if (doc)
                   1918:     {
                   1919:       if (dispMode == DisplayImmediately)
1.327     vatton   1920:         /* restore the display mode */
                   1921:         TtaSetDisplayMode (doc, dispMode);
1.302     quint    1922:     }
1.311     vatton   1923:   else if (css && Style_parsing == 0 && RedisplayImages == 0 && RedisplayDoc)
1.302     quint    1924:     {
1.310     vatton   1925:       /* all background images are now loaded */
1.311     vatton   1926:       doc = RedisplayDoc;
                   1927:       if (css->infos[doc] &&
1.327     vatton   1928:           /* don't manage a document used by make book */
                   1929:           (DocumentMeta[doc] == NULL ||
                   1930:            DocumentMeta[doc]->method != CE_MAKEBOOK))
                   1931:         {
                   1932:           pInfo = css->infos[doc];
                   1933:           enabled = FALSE;
                   1934:           while (pInfo && !enabled)
                   1935:             {
                   1936:               enabled = pInfo->PiEnabled;
                   1937:               pInfo = pInfo->PiNext;
                   1938:             }
                   1939:           /* Change the Display Mode to take into account the new
                   1940:              presentation */
                   1941:           dispMode = TtaGetDisplayMode (doc);
1.328   ! vatton   1942: printf ("ParseCSSImageCallback Show BGimages\n");
1.313     vatton   1943:           /* force the redisplay of this box */
                   1944:           TtaSetDisplayMode (doc, NoComputedDisplay);
1.327     vatton   1945:           TtaSetDisplayMode (doc, dispMode);
                   1946:           RedisplayBGImage = FALSE;
                   1947:         }
1.302     quint    1948:     }
1.310     vatton   1949:   else
1.328   ! vatton   1950:     RedisplayBGImage = TRUE;
1.302     quint    1951: }
                   1952: 
                   1953: /*----------------------------------------------------------------------
                   1954:   SetCSSImage fetch the image referred by a background-image or a
                   1955:   list-style-image property.
                   1956:   ----------------------------------------------------------------------*/
                   1957: static char *SetCSSImage (Element element, PSchema tsch,
1.327     vatton   1958:                           PresentationContext ctxt, char *cssRule,
                   1959:                           CSSInfoPtr css, unsigned int ruleType)
1.302     quint    1960: {
                   1961:   CSSImageCallbackPtr        callblock;
                   1962:   Element                    el;
                   1963:   char                      *url;
1.304     cvs      1964:   PresentationValue          image;
1.302     quint    1965:   char                      *bg_image;
                   1966:   char                       tempname[MAX_LENGTH];
                   1967:   char                       imgname[MAX_LENGTH];
                   1968: 
                   1969:   if (element)
                   1970:     el = element;
                   1971:   else
                   1972:     /* default element for FetchImage */
                   1973:     el = TtaGetMainRoot (ctxt->doc);
                   1974:   url = NULL;
                   1975:   cssRule = ParseCSSUrl (cssRule, &url);
                   1976:   cssRule = CheckImportantRule (cssRule, ctxt);
                   1977:   if (ctxt->destroy)
                   1978:     {
                   1979:       /* remove the background image PRule */
                   1980:       image.pointer = NULL;
                   1981:       TtaSetStylePresentation (ruleType, element, tsch, ctxt,image);
                   1982:     }
                   1983:   else if (url)
                   1984:     {
                   1985:       bg_image = TtaGetEnvString ("ENABLE_BG_IMAGES");
                   1986:       if (bg_image == NULL || !strcasecmp (bg_image, "yes"))
1.327     vatton   1987:         /* background images are enabled */
                   1988:         {
                   1989:           callblock = (CSSImageCallbackPtr) TtaGetMemory (sizeof (CSSImageCallbackBlock));
                   1990:           if (callblock)
                   1991:             {
                   1992:               callblock->el = element;
                   1993:               callblock->tsch = tsch;
                   1994:               callblock->css = css;
                   1995:               callblock->ctxt = ctxt;
                   1996:               callblock->ruleType = ruleType;
                   1997:               /* new use of the context */
                   1998:               ctxt->uses += 1;
                   1999:               RedisplayImages++;
                   2000:               /* check if the image url is related to an external CSS */
                   2001:               if (css)
                   2002:                 {
                   2003:                   RedisplayDoc = ctxt->doc;
                   2004:                   if (css->url)
                   2005:                     /* the image concerns a CSS file */
                   2006:                     NormalizeURL (url, 0, tempname, imgname, css->url);
                   2007:                   else
                   2008:                     /* the image concerns a style element */
                   2009:                     NormalizeURL (url, ctxt->doc, tempname, imgname, NULL);
                   2010:                   /* fetch and display background image of element */
                   2011:                   FetchImage (0, el, tempname, AMAYA_LOAD_IMAGE,
                   2012:                               ParseCSSImageCallback, callblock);
                   2013:                 }
                   2014:               else
                   2015:                 FetchImage (ctxt->doc, el, url, AMAYA_LOAD_IMAGE,
                   2016:                             ParseCSSImageCallback, callblock);
                   2017:             }
                   2018:         }
1.302     quint    2019:     }
                   2020:   if (url)
                   2021:     TtaFreeMemory (url);
                   2022:   return (cssRule);
                   2023: }
                   2024: 
                   2025: /*----------------------------------------------------------------------
1.327     vatton   2026:   ParseACSSListStyleImage: parse a CSS list-style-image
                   2027:   attribute string.                                          
1.1       cvs      2028:   ----------------------------------------------------------------------*/
1.318     vatton   2029: static char *ParseACSSListStyleImage (Element element, PSchema tsch,
1.327     vatton   2030:                                       PresentationContext ctxt,
                   2031:                                       char *cssRule, CSSInfoPtr css,
                   2032:                                       ThotBool isHTML)
1.1       cvs      2033: {
1.288     vatton   2034:   char               *url;
1.293     quint    2035:   PresentationValue   pval;
1.281     quint    2036: 
1.293     quint    2037:   pval.typed_data.unit = UNIT_REL;
                   2038:   pval.typed_data.real = FALSE;
1.281     quint    2039:   url = NULL;
                   2040:   cssRule = SkipBlanksAndComments (cssRule);
                   2041:   if (!strncasecmp (cssRule, "none", 4))
                   2042:     {
                   2043:       cssRule += 4;
                   2044:       cssRule = CheckImportantRule (cssRule, ctxt);
1.302     quint    2045:       pval.typed_data.value = 0;
                   2046:       if (DoApply)
1.327     vatton   2047:         TtaSetStylePresentation (PRListStyleImage, element, tsch, ctxt, pval);
1.281     quint    2048:     }
                   2049:   else if (!strncasecmp (cssRule, "url", 3))
                   2050:     {  
                   2051:       cssRule += 3;
1.302     quint    2052:       cssRule = SetCSSImage (element, tsch, ctxt, cssRule, css,
1.327     vatton   2053:                              PRListStyleImage);
1.281     quint    2054:     }
                   2055:   else if (!strncasecmp (cssRule, "inherit", 7))
1.288     vatton   2056:     {
                   2057:       cssRule += 7;
1.293     quint    2058:       pval.typed_data.unit = VALUE_INHERIT;
1.295     vatton   2059:       cssRule = CheckImportantRule (cssRule, ctxt);
1.293     quint    2060:       if (DoApply)
1.327     vatton   2061:         TtaSetStylePresentation (PRListStyleImage, element, tsch, ctxt, pval);
                   2062:     }
1.281     quint    2063:   else
1.295     vatton   2064:     {
                   2065:       cssRule = SkipValue ("Invalid list-style-image value", cssRule);
                   2066:       cssRule = CheckImportantRule (cssRule, ctxt);
                   2067:     }
1.1       cvs      2068:   return (cssRule);
                   2069: }
                   2070: 
                   2071: /*----------------------------------------------------------------------
1.327     vatton   2072:   ParseCSSListStyleImage: parse a CSS list-style-image
                   2073:   attribute string.                                          
1.318     vatton   2074:   ----------------------------------------------------------------------*/
                   2075: static char *ParseCSSListStyleImage (Element element, PSchema tsch,
1.327     vatton   2076:                                      PresentationContext ctxt,
                   2077:                                      char *cssRule, CSSInfoPtr css,
                   2078:                                      ThotBool isHTML)
1.318     vatton   2079: {
                   2080:   char               *ptr = cssRule;
                   2081:   cssRule = ParseACSSListStyleImage (element, tsch, ctxt, cssRule, css,
1.327     vatton   2082:                                      isHTML);
1.318     vatton   2083:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid list-style-image value");
                   2084:   return cssRule;
                   2085: }
                   2086: 
                   2087: /*----------------------------------------------------------------------
1.327     vatton   2088:   ParseACSSListStylePosition: parse a CSS list-style-position
                   2089:   attribute string.                                          
1.1       cvs      2090:   ----------------------------------------------------------------------*/
1.318     vatton   2091: static char *ParseACSSListStylePosition (Element element, PSchema tsch,
1.327     vatton   2092:                                          PresentationContext context,
                   2093:                                          char *cssRule, CSSInfoPtr css,
                   2094:                                          ThotBool isHTML)
1.1       cvs      2095: {
1.281     quint    2096:   PresentationValue   pval;
                   2097: 
                   2098:   pval.typed_data.unit = UNIT_REL;
                   2099:   pval.typed_data.real = FALSE;
                   2100:   cssRule = SkipBlanksAndComments (cssRule);
                   2101:   if (!strncasecmp (cssRule, "inside", 6))
1.288     vatton   2102:     {
                   2103:       pval.typed_data.value = Inside;
                   2104:       cssRule += 6;
                   2105:     }
1.281     quint    2106:   else if (!strncasecmp (cssRule, "outside", 7))
1.288     vatton   2107:     {
                   2108:       pval.typed_data.value = Outside;
                   2109:       cssRule += 7;
                   2110:     }
1.293     quint    2111:   else if (!strncasecmp (cssRule, "inherit", 7))
                   2112:     {
                   2113:       pval.typed_data.unit = VALUE_INHERIT;
                   2114:       cssRule += 7;
                   2115:     }
1.281     quint    2116:   else
                   2117:     {
1.293     quint    2118:       cssRule = SkipValue ("Invalid list-style-position value", cssRule);
1.295     vatton   2119:       cssRule = CheckImportantRule (cssRule, context);
1.281     quint    2120:       return (cssRule);
                   2121:     }
1.293     quint    2122: 
1.295     vatton   2123:   cssRule = CheckImportantRule (cssRule, context);
1.281     quint    2124:   if (DoApply)
1.295     vatton   2125:     TtaSetStylePresentation (PRListStylePosition, element, tsch, context, pval);
1.327     vatton   2126:   return (cssRule);
1.318     vatton   2127: }
                   2128: 
                   2129: /*----------------------------------------------------------------------
1.327     vatton   2130:   ParseCSSListStylePosition: parse a CSS list-style-position
                   2131:   attribute string.                                          
1.318     vatton   2132:   ----------------------------------------------------------------------*/
                   2133: static char *ParseCSSListStylePosition (Element element, PSchema tsch,
1.327     vatton   2134:                                         PresentationContext context,
                   2135:                                         char *cssRule, CSSInfoPtr css,
                   2136:                                         ThotBool isHTML)
1.318     vatton   2137: {
                   2138:   char               *ptr = cssRule;
                   2139:   cssRule = ParseACSSListStylePosition (element, tsch, context, cssRule, css,
1.327     vatton   2140:                                         isHTML);
1.288     vatton   2141:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid list-style-position value");
1.318     vatton   2142:   return cssRule;
1.1       cvs      2143: }
                   2144: 
                   2145: /*----------------------------------------------------------------------
1.327     vatton   2146:   ParseCSSListStyle: parse a CSS list-style value string.                                          
1.1       cvs      2147:   ----------------------------------------------------------------------*/
1.79      cvs      2148: static char *ParseCSSListStyle (Element element, PSchema tsch,
1.327     vatton   2149:                                 PresentationContext ctxt, char *cssRule,
                   2150:                                 CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      2151: {
1.318     vatton   2152:   char               *ptr = cssRule;
                   2153:   int                 skippedNL;
1.281     quint    2154: 
                   2155:   cssRule = SkipBlanksAndComments (cssRule);
1.301     vatton   2156:   while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.281     quint    2157:     {
1.316     quint    2158:       skippedNL = NewLineSkipped;
1.281     quint    2159:       /* perhaps a list-style-image */
                   2160:       if (!strncasecmp (cssRule, "url", 3))
1.327     vatton   2161:         cssRule = ParseACSSListStyleImage (element, tsch, ctxt, cssRule, css,
                   2162:                                            isHTML);
1.281     quint    2163:       /* perhaps a list-style-position */
                   2164:       else if (!strncasecmp (cssRule, "inside", 6) ||
                   2165:                !strncasecmp (cssRule, "outside", 7))
1.327     vatton   2166:         cssRule = ParseACSSListStylePosition (element, tsch, ctxt, cssRule,
                   2167:                                               css, isHTML);
1.281     quint    2168:       /* perhaps a list-style-type */
                   2169:       else if (!strncasecmp (cssRule, "disc", 4) ||
1.327     vatton   2170:                !strncasecmp (cssRule, "circle", 6) ||
                   2171:                !strncasecmp (cssRule, "square", 6) ||
                   2172:                !strncasecmp (cssRule, "decimal", 7) ||
                   2173:                !strncasecmp (cssRule, "decimal-leading-zero", 20) ||
                   2174:                !strncasecmp (cssRule, "lower-roman", 11) ||
                   2175:                !strncasecmp (cssRule, "upper-roman", 11) ||
                   2176:                !strncasecmp (cssRule, "lower-greek", 11) ||
                   2177:                !strncasecmp (cssRule, "lower-latin", 11) ||
                   2178:                !strncasecmp (cssRule, "lower-alpha", 11) ||
                   2179:                !strncasecmp (cssRule, "upper-latin", 11) ||
                   2180:                !strncasecmp (cssRule, "upper-alpha", 11) ||
                   2181:                !strncasecmp (cssRule, "armenian", 8) ||
                   2182:                !strncasecmp (cssRule, "georgian", 8) ||
                   2183:                !strncasecmp (cssRule, "none", 4) ||
                   2184:                !strncasecmp (cssRule, "inherit", 7))
                   2185:         cssRule = ParseACSSListStyleType (element, tsch, ctxt, cssRule, css,
                   2186:                                           isHTML);
1.281     quint    2187:       else
1.327     vatton   2188:         {
                   2189:           NewLineSkipped = skippedNL;
                   2190:           /* rule not found */
                   2191:           cssRule = SkipProperty (cssRule, FALSE);
                   2192:         }
1.281     quint    2193:       cssRule = SkipBlanksAndComments (cssRule);
                   2194:     }
1.318     vatton   2195:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid list-style value");
1.1       cvs      2196:   return (cssRule);
                   2197: }
                   2198: 
                   2199: /*----------------------------------------------------------------------
1.327     vatton   2200:   ParseCSSTextAlign: parse a CSS text-align            
                   2201:   attribute string.                                          
1.1       cvs      2202:   ----------------------------------------------------------------------*/
1.79      cvs      2203: static char *ParseCSSTextAlign (Element element, PSchema tsch,
1.327     vatton   2204:                                 PresentationContext context, char *cssRule,
                   2205:                                 CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      2206: {
1.327     vatton   2207:   char *ptr = cssRule;
                   2208:   PresentationValue   align;
                   2209: 
                   2210:   align.typed_data.value = 0;
                   2211:   align.typed_data.unit = UNIT_REL;
                   2212:   align.typed_data.real = FALSE;
                   2213: 
                   2214:   cssRule = SkipBlanksAndComments (cssRule);
                   2215:   if (!strncasecmp (cssRule, "left", 4))
                   2216:     {
                   2217:       align.typed_data.value = AdjustLeft;
                   2218:       cssRule += 4;
                   2219:     }
                   2220:   else if (!strncasecmp (cssRule, "right", 5))
                   2221:     {
                   2222:       align.typed_data.value = AdjustRight;
                   2223:       cssRule += 5;
                   2224:     }
                   2225:   else if (!strncasecmp (cssRule, "center", 6))
                   2226:     {
                   2227:       align.typed_data.value = Centered;
                   2228:       cssRule += 6;
                   2229:     }
                   2230:   else if (!strncasecmp (cssRule, "justify", 7))
                   2231:     {
                   2232:       align.typed_data.value = Justify;
                   2233:       cssRule += 7;
                   2234:     }
                   2235:   else
                   2236:     {
                   2237:       cssRule = SkipValue ("Invalid text-align value", cssRule);
                   2238:       cssRule = CheckImportantRule (cssRule, context);
                   2239:       return (cssRule);
                   2240:     }
1.1       cvs      2241: 
1.327     vatton   2242:   /*
                   2243:    * install the new presentation.
                   2244:    */
                   2245:   cssRule = CheckImportantRule (cssRule, context);
                   2246:   if (align.typed_data.value && DoApply)
                   2247:     TtaSetStylePresentation (PRAdjust, element, tsch, context, align);
                   2248:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid text-align value");
                   2249:   return (cssRule);
1.1       cvs      2250: }
                   2251: 
                   2252: /*----------------------------------------------------------------------
1.243     quint    2253:   ParseCSSTextAnchor: parse a CSS text-anchor property (SVG property)
                   2254:   We use the Thot Adjust PRule to represent the text-anchor property
                   2255:   for CSS 1.0, as Adjust is not used otherwise in this context.
                   2256:   ----------------------------------------------------------------------*/
                   2257: static char *ParseCSSTextAnchor (Element element, PSchema tsch,
1.327     vatton   2258:                                  PresentationContext context, char *cssRule,
                   2259:                                  CSSInfoPtr css, ThotBool isHTML)
1.243     quint    2260: {
1.327     vatton   2261:   PresentationValue   align;
                   2262:   char               *ptr = cssRule;
                   2263: 
                   2264:   align.typed_data.value = 0;
                   2265:   align.typed_data.unit = UNIT_REL;
                   2266:   align.typed_data.real = FALSE;
1.243     quint    2267: 
1.327     vatton   2268:   cssRule = SkipBlanksAndComments (cssRule);
                   2269:   if (!strncasecmp (cssRule, "start", 5))
                   2270:     {
                   2271:       align.typed_data.value = AdjustLeft;
                   2272:       cssRule += 5;
                   2273:     }
                   2274:   else if (!strncasecmp (cssRule, "middle", 6))
                   2275:     {
                   2276:       align.typed_data.value = Centered;
                   2277:       cssRule += 6;
                   2278:     }
                   2279:   else if (!strncasecmp (cssRule, "end", 3))
                   2280:     {
                   2281:       align.typed_data.value = AdjustRight;
                   2282:       cssRule += 3;
                   2283:     }
                   2284:   else if (!strncasecmp (cssRule, "inherit", 7))
                   2285:     {
                   2286:       align.typed_data.unit = VALUE_INHERIT;
                   2287:       cssRule += 7;
                   2288:     }
                   2289:   else
                   2290:     {
                   2291:       cssRule = SkipValue ("Invalid text-anchor value", cssRule);
                   2292:       cssRule = CheckImportantRule (cssRule, context);
1.295     vatton   2293:       return (cssRule);
1.327     vatton   2294:     }
1.243     quint    2295: 
1.327     vatton   2296:   /*
                   2297:    * install the new presentation.
                   2298:    */
                   2299:   cssRule = CheckImportantRule (cssRule, context);
                   2300:   if (DoApply &&
                   2301:       (align.typed_data.value || align.typed_data.unit == VALUE_INHERIT))
                   2302:     TtaSetStylePresentation (PRAdjust, element, tsch, context, align);
                   2303:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid text-anchor value");
                   2304:   return (cssRule);
1.243     quint    2305: }
                   2306: 
                   2307: /*----------------------------------------------------------------------
1.327     vatton   2308:   ParseCSSDirection: parse a CSS direction property
1.112     quint    2309:   ----------------------------------------------------------------------*/
                   2310: static char *ParseCSSDirection (Element element, PSchema tsch,
1.327     vatton   2311:                                 PresentationContext context, char *cssRule,
                   2312:                                 CSSInfoPtr css, ThotBool isHTML)
1.112     quint    2313: {
1.327     vatton   2314:   PresentationValue   direction;
                   2315:   char               *ptr = cssRule;
                   2316: 
                   2317:   direction.typed_data.value = 0;
                   2318:   direction.typed_data.unit = UNIT_REL;
                   2319:   direction.typed_data.real = FALSE;
                   2320: 
                   2321:   cssRule = SkipBlanksAndComments (cssRule);
                   2322:   if (!strncasecmp (cssRule, "ltr", 3))
                   2323:     {
                   2324:       direction.typed_data.value = LeftToRight;
                   2325:       cssRule += 3;
                   2326:     }
                   2327:   else if (!strncasecmp (cssRule, "rtl", 3))
                   2328:     {
                   2329:       direction.typed_data.value = RightToLeft;
                   2330:       cssRule += 3;
                   2331:     }
                   2332:   else if (!strncasecmp (cssRule, "inherit", 7))
                   2333:     {
                   2334:       direction.typed_data.unit = VALUE_INHERIT;
                   2335:       cssRule += 7;
                   2336:     }
                   2337:   else
                   2338:     {
                   2339:       cssRule = SkipValue ("Invalid direction value", cssRule);
                   2340:       cssRule = CheckImportantRule (cssRule, context);
                   2341:       return (cssRule);
                   2342:     }
1.112     quint    2343: 
1.327     vatton   2344:   /*
                   2345:    * install the new presentation.
                   2346:    */
                   2347:   cssRule = CheckImportantRule (cssRule, context);
                   2348:   if (DoApply &&
                   2349:       (direction.typed_data.value || direction.typed_data.unit == VALUE_INHERIT))
                   2350:     TtaSetStylePresentation (PRDirection, element, tsch, context, direction);
                   2351:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid direction value");
                   2352:   return (cssRule);
1.112     quint    2353: }
                   2354: 
                   2355: /*----------------------------------------------------------------------
1.327     vatton   2356:   ParseCSSUnicodeBidi: parse a CSS unicode-bidi property
1.113     quint    2357:   ----------------------------------------------------------------------*/
                   2358: static char *ParseCSSUnicodeBidi (Element element, PSchema tsch,
1.327     vatton   2359:                                   PresentationContext context, char *cssRule,
                   2360:                                   CSSInfoPtr css, ThotBool isHTML)
1.113     quint    2361: {
1.327     vatton   2362:   PresentationValue   bidi;
                   2363:   char               *ptr = cssRule;
1.113     quint    2364: 
1.327     vatton   2365:   bidi.typed_data.value = 0;
                   2366:   bidi.typed_data.unit = UNIT_REL;
                   2367:   bidi.typed_data.real = FALSE;
                   2368: 
                   2369:   cssRule = SkipBlanksAndComments (cssRule);
                   2370:   if (!strncasecmp (cssRule, "normal", 6))
                   2371:     {
                   2372:       bidi.typed_data.value = Normal;
                   2373:       cssRule += 6;
                   2374:     }
                   2375:   else if (!strncasecmp (cssRule, "embed", 5))
                   2376:     {
                   2377:       bidi.typed_data.value = Embed;
                   2378:       cssRule += 5;
                   2379:     }
                   2380:   else if (!strncasecmp (cssRule, "bidi-override", 13))
                   2381:     {
                   2382:       bidi.typed_data.value = Override;
                   2383:       cssRule += 13;
                   2384:     }
                   2385:   else if (!strncasecmp (cssRule, "inherit", 7))
                   2386:     {
                   2387:       bidi.typed_data.unit = VALUE_INHERIT;
                   2388:       cssRule += 7;
                   2389:     }
                   2390:   else
                   2391:     {
                   2392:       cssRule = SkipValue ("Invalid unicode-bidi value", cssRule);
                   2393:       cssRule = CheckImportantRule (cssRule, context);
1.295     vatton   2394:       return (cssRule);
1.327     vatton   2395:     }
1.113     quint    2396: 
1.327     vatton   2397:   /*
                   2398:    * install the new presentation.
                   2399:    */
                   2400:   cssRule = CheckImportantRule (cssRule, context);
                   2401:   if (DoApply &&
                   2402:       (bidi.typed_data.value || bidi.typed_data.unit == VALUE_INHERIT))
                   2403:     TtaSetStylePresentation (PRUnicodeBidi, element, tsch, context, bidi);
                   2404:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid unicode-bidi value");
                   2405:   return (cssRule);
1.113     quint    2406: }
                   2407: 
                   2408: /*----------------------------------------------------------------------
1.327     vatton   2409:   ParseCSSTextIndent: parse a CSS text-indent
                   2410:   attribute string.                                          
1.1       cvs      2411:   ----------------------------------------------------------------------*/
1.79      cvs      2412: static char *ParseCSSTextIndent (Element element, PSchema tsch,
1.327     vatton   2413:                                  PresentationContext context, char *cssRule,
                   2414:                                  CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      2415: {
1.327     vatton   2416:   PresentationValue   pval;
                   2417:   char               *ptr;
1.1       cvs      2418: 
1.327     vatton   2419:   cssRule = SkipBlanksAndComments (cssRule);
                   2420:   ptr = cssRule;
                   2421:   cssRule = ParseCSSUnit (cssRule, &pval);
                   2422:   if (pval.typed_data.value == 0)
                   2423:     pval.typed_data.unit = UNIT_PX;
                   2424:   else if (pval.typed_data.unit == UNIT_INVALID ||
                   2425:            pval.typed_data.unit == UNIT_BOX)
                   2426:     {
                   2427:       CSSParseError ("Invalid text-indent value", ptr, cssRule);
                   2428:       cssRule = CheckImportantRule (cssRule, context);
                   2429:       return (cssRule);
                   2430:     }
                   2431:   /* install the attribute */
                   2432:   cssRule = CheckImportantRule (cssRule, context);
                   2433:   if (DoApply)
                   2434:     TtaSetStylePresentation (PRIndent, element, tsch, context, pval);
                   2435:   return (cssRule);
1.1       cvs      2436: }
                   2437: 
                   2438: /*----------------------------------------------------------------------
1.327     vatton   2439:   ParseCSSTextTransform: parse a CSS text-transform    
                   2440:   attribute string.                                          
1.1       cvs      2441:   ----------------------------------------------------------------------*/
1.79      cvs      2442: static char *ParseCSSTextTransform (Element element, PSchema tsch,
1.327     vatton   2443:                                     PresentationContext context, char *cssRule,
                   2444:                                     CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      2445: {
1.168     vatton   2446:   cssRule = SkipValue (NULL, cssRule);
1.295     vatton   2447:   cssRule = CheckImportantRule (cssRule, context);
1.1       cvs      2448:   return (cssRule);
                   2449: }
                   2450: 
                   2451: /*----------------------------------------------------------------------
1.327     vatton   2452:   ParseCSSVerticalAlign: parse a CSS vertical-align    
                   2453:   attribute string.                                          
1.1       cvs      2454:   ----------------------------------------------------------------------*/
1.79      cvs      2455: static char *ParseCSSVerticalAlign (Element element, PSchema tsch,
1.327     vatton   2456:                                     PresentationContext context, char *cssRule,
                   2457:                                     CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      2458: {
1.273     quint    2459:   char                 *ptr;
                   2460:   PresentationValue    pval;
                   2461: 
                   2462:   pval.typed_data.unit = UNIT_REL;
                   2463:   pval.typed_data.real = FALSE;
                   2464:   cssRule = SkipBlanksAndComments (cssRule);
1.288     vatton   2465:   ptr = cssRule;
1.273     quint    2466:   if (!strncasecmp (cssRule, "baseline", 8))
                   2467:     {
                   2468:       pval.typed_data.value = 0;
1.288     vatton   2469:       cssRule += 8;
1.273     quint    2470:     }
                   2471:   else if (!strncasecmp (cssRule, "sub", 3))
                   2472:     {
                   2473:       pval.typed_data.value = -3;
1.288     vatton   2474:       cssRule += 3;
1.273     quint    2475:     }
                   2476:   else if (!strncasecmp (cssRule, "super", 5))
                   2477:     {
                   2478:       pval.typed_data.value = 4;
1.288     vatton   2479:       cssRule += 5;
1.273     quint    2480:     }
                   2481:   else if (!strncasecmp (cssRule, "top", 3))
                   2482:     {
1.275     quint    2483:       pval.typed_data.unit = UNIT_INVALID;      /* Not supported yet */
1.274     vatton   2484:       pval.typed_data.value = 0;
1.288     vatton   2485:       cssRule += 3;
1.273     quint    2486:     }
                   2487:   else if (!strncasecmp (cssRule, "text-top", 8))
                   2488:     {
1.275     quint    2489:       pval.typed_data.unit = UNIT_INVALID;      /* Not supported yet */
1.274     vatton   2490:       pval.typed_data.value = 0;
1.288     vatton   2491:       cssRule += 8;
1.273     quint    2492:     }
                   2493:   else if (!strncasecmp (cssRule, "middle", 6))
                   2494:     {
1.275     quint    2495:       pval.typed_data.unit = UNIT_INVALID;      /* Not supported yet */
1.274     vatton   2496:       pval.typed_data.value = 0;
1.288     vatton   2497:       cssRule += 6;
1.273     quint    2498:     }
                   2499:   else if (!strncasecmp (cssRule, "bottom", 6))
                   2500:     {
1.275     quint    2501:       pval.typed_data.unit = UNIT_INVALID;      /* Not supported yet */
1.274     vatton   2502:       pval.typed_data.value = 0;
1.288     vatton   2503:       cssRule += 6;
1.273     quint    2504:     }
                   2505:   else if (!strncasecmp (cssRule, "text-bottom", 11))
                   2506:     {
1.275     quint    2507:       pval.typed_data.unit = UNIT_INVALID;      /* Not supported yet */
1.274     vatton   2508:       pval.typed_data.value = 0;
1.288     vatton   2509:       cssRule += 11;
1.273     quint    2510:     }
                   2511:   else if (!strncasecmp (cssRule, "inherit", 7))
                   2512:     {
1.293     quint    2513:       pval.typed_data.unit = VALUE_INHERIT;
1.274     vatton   2514:       pval.typed_data.value = 0;
1.288     vatton   2515:       cssRule +=7;
1.273     quint    2516:     }
                   2517:   else
                   2518:     {
                   2519:       /* parse <percentage> or <length> */
                   2520:       cssRule = ParseCSSUnit (cssRule, &pval);
                   2521:       if (pval.typed_data.unit == UNIT_INVALID)
1.327     vatton   2522:         {
                   2523:           pval.typed_data.value = 0;
                   2524:           CSSParseError ("Invalid vertical-align value", ptr, cssRule);
                   2525:           cssRule = CheckImportantRule (cssRule, context);
                   2526:           return (cssRule);
                   2527:         }
1.273     quint    2528:       else if (pval.typed_data.value == 0)
1.327     vatton   2529:         pval.typed_data.unit = UNIT_PX;
1.273     quint    2530:       else if (pval.typed_data.unit == UNIT_BOX)
1.327     vatton   2531:         pval.typed_data.unit = UNIT_EM;
1.273     quint    2532:       else if (pval.typed_data.unit == UNIT_PERCENT)
1.327     vatton   2533:         /* it's a percentage */
                   2534:         {
                   2535:           /* convert it into a relative size */
                   2536:           pval.typed_data.unit = UNIT_REL;
                   2537:           pval.typed_data.value /= 10;
                   2538:         }
1.273     quint    2539:     }
1.295     vatton   2540: 
                   2541:   cssRule = CheckImportantRule (cssRule, context);
1.273     quint    2542:   if (pval.typed_data.unit != UNIT_INVALID && DoApply)
                   2543:     TtaSetStylePresentation (PRHorizRef, element, tsch, context, pval);
1.288     vatton   2544:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid vertical-align value");
1.1       cvs      2545:   return (cssRule);
                   2546: }
                   2547: 
                   2548: /*----------------------------------------------------------------------
1.327     vatton   2549:   ParseCSSWhiteSpace: parse a CSS white-space          
                   2550:   attribute string.                                          
1.1       cvs      2551:   ----------------------------------------------------------------------*/
1.79      cvs      2552: static char *ParseCSSWhiteSpace (Element element, PSchema tsch,
1.327     vatton   2553:                                  PresentationContext context, char *cssRule,
                   2554:                                  CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      2555: {
1.288     vatton   2556:   char *ptr = cssRule;
                   2557: 
1.327     vatton   2558:   cssRule = SkipBlanksAndComments (cssRule);
                   2559:   if (!strncasecmp (cssRule, "normal", 6))
                   2560:     cssRule += 6;
                   2561:   else if (!strncasecmp (cssRule, "pre", 3))
                   2562:     cssRule += 3;
                   2563:   else if (!strncasecmp (cssRule, "nowrap", 6))
                   2564:     cssRule += 6;
                   2565:   else if (!strncasecmp (cssRule, "pre-wrap", 8))
                   2566:     cssRule += 8;
                   2567:   else if (!strncasecmp (cssRule, "pre-line", 8))
                   2568:     cssRule += 8;
                   2569:   else if (!strncasecmp (cssRule, "inherit", 7))
                   2570:     cssRule += 7;
                   2571:   else
                   2572:     cssRule = SkipValue ("Invalid white-space value", cssRule);
                   2573: 
                   2574:   cssRule = CheckImportantRule (cssRule, context);
                   2575:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid white-space value");
                   2576:   return (cssRule);
1.1       cvs      2577: }
                   2578: 
                   2579: /*----------------------------------------------------------------------
1.327     vatton   2580:   ParseCSSWordSpacing: parse a CSS word-spacing        
                   2581:   attribute string.                                          
1.1       cvs      2582:   ----------------------------------------------------------------------*/
1.79      cvs      2583: static char *ParseCSSWordSpacing (Element element, PSchema tsch,
1.327     vatton   2584:                                   PresentationContext context, char *cssRule,
                   2585:                                   CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      2586: {
1.168     vatton   2587:   cssRule = SkipValue (NULL, cssRule);
1.295     vatton   2588:   cssRule = CheckImportantRule (cssRule, context);
1.1       cvs      2589:   return (cssRule);
                   2590: }
                   2591: 
                   2592: /*----------------------------------------------------------------------
1.327     vatton   2593:   ParseCSSLineHeight: parse a CSS line-height property
1.25      cvs      2594:   ----------------------------------------------------------------------*/
1.162     quint    2595: static char *ParseCSSLineHeight (Element element, PSchema tsch,
1.327     vatton   2596:                                  PresentationContext context, char *cssRule,
                   2597:                                  CSSInfoPtr css, ThotBool isHTML)
1.25      cvs      2598: {
1.162     quint    2599:   PresentationValue   pval;
1.288     vatton   2600:   char               *ptr;
1.162     quint    2601: 
                   2602:   ptr = cssRule;
                   2603:   if (!strncasecmp (cssRule, "normal", 6))
                   2604:     {
1.184     vatton   2605:       pval.typed_data.unit = UNIT_REL;
1.162     quint    2606:       pval.typed_data.real = TRUE;
                   2607:       pval.typed_data.value = 1100;
1.288     vatton   2608:       cssRule += 6;
1.162     quint    2609:     }
                   2610:   else if (!strncasecmp (cssRule, "inherit", 7))
                   2611:     {
1.293     quint    2612:       pval.typed_data.unit = VALUE_INHERIT;
1.288     vatton   2613:       cssRule += 6;
1.162     quint    2614:     }
                   2615:   else
                   2616:     cssRule = ParseCSSUnit (cssRule, &pval);
1.25      cvs      2617: 
1.295     vatton   2618:   cssRule = CheckImportantRule (cssRule, context);
1.184     vatton   2619:   if (pval.typed_data.unit == UNIT_INVALID)
1.168     vatton   2620:     CSSParseError ("Invalid line-height value", ptr, cssRule);
1.162     quint    2621:   else if (DoApply)
                   2622:     {
1.166     vatton   2623:       /* install the new presentation */
1.184     vatton   2624:       if (pval.typed_data.unit == UNIT_BOX)
1.327     vatton   2625:         pval.typed_data.unit = UNIT_EM;
1.162     quint    2626:       TtaSetStylePresentation (PRLineSpacing, element, tsch, context, pval);
                   2627:     }
                   2628:   return (cssRule);
1.25      cvs      2629: }
                   2630: 
                   2631: /*----------------------------------------------------------------------
1.327     vatton   2632:   ParseCSSFontSizeAdjust: parse a CSS fontsizeAdjust attr string  
                   2633:   we expect the input string describing the attribute to be     
                   2634:   xx-small, x-small, small, medium, large, x-large, xx-large      
                   2635:   or an absolute size, or an imcrement relative to the parent     
1.1       cvs      2636:   ----------------------------------------------------------------------*/
1.219     vatton   2637: static char *ParseCSSFontSizeAdjust (Element element, PSchema tsch,
1.327     vatton   2638:                                      PresentationContext context, char *cssRule,
                   2639:                                      CSSInfoPtr css, ThotBool isHTML)
1.219     vatton   2640: {
1.234     vatton   2641:   cssRule = SkipProperty (cssRule, FALSE);
1.222     quint    2642:   return (cssRule);
1.219     vatton   2643: }
                   2644: 
                   2645: /*----------------------------------------------------------------------
1.327     vatton   2646:   ParseACSSFontSize: parse a CSS font size attr string  
                   2647:   we expect the input string describing the attribute to be     
                   2648:   xx-small, x-small, small, medium, large, x-large, xx-large      
                   2649:   or an absolute size, or an imcrement relative to the parent.
                   2650:   The parameter check is TRUE if the rule is just checked.
1.219     vatton   2651:   ----------------------------------------------------------------------*/
1.270     vatton   2652: static char *ParseACSSFontSize (Element element, PSchema tsch,
1.327     vatton   2653:                                 PresentationContext context, char *cssRule,
                   2654:                                 CSSInfoPtr css, ThotBool isHTML, ThotBool check)
1.1       cvs      2655: {
1.327     vatton   2656:   ElementType         elType;
                   2657:   PresentationValue   pval;
                   2658:   char               *ptr = NULL, *ptr1 = NULL;
                   2659:   ThotBool            real, linespace = FALSE;
                   2660: 
                   2661:   pval.typed_data.real = FALSE;
                   2662:   cssRule = SkipBlanksAndComments (cssRule);
                   2663:   /* look for a '/' within the current cssRule */
                   2664:   ptr1 = strchr (cssRule, ';');
                   2665:   ptr = strchr (cssRule, '/');
                   2666:   if (ptr && (ptr1 == NULL || ptr < ptr1))
                   2667:     {
                   2668:       /* keep the line spacing rule */
                   2669:       linespace = TRUE;
                   2670:       ptr[0] = EOS;
                   2671:     }
                   2672:   else
                   2673:     ptr = NULL;
                   2674:   ptr1 = cssRule;
1.289     vatton   2675:   /* relative size */
1.327     vatton   2676:   if (!strncasecmp (cssRule, "larger", 6))
                   2677:     {
                   2678:       pval.typed_data.unit = UNIT_PERCENT;
                   2679:       pval.typed_data.value = 130;
                   2680:       cssRule += 6;
                   2681:     }
                   2682:   else if (!strncasecmp (cssRule, "smaller", 7))
                   2683:     {
                   2684:       pval.typed_data.unit = UNIT_PERCENT;
                   2685:       pval.typed_data.value = 80;
                   2686:       cssRule += 7;
                   2687:     }
                   2688:   /* absolute size */
                   2689:   else if (!strncasecmp (cssRule, "xx-small", 8))
                   2690:     {
                   2691:       pval.typed_data.unit = UNIT_PT;
                   2692:       pval.typed_data.value = 8;
                   2693:       cssRule += 8;
                   2694:     }
                   2695:   else if (!strncasecmp (cssRule, "x-small", 7))
                   2696:     {
                   2697:       pval.typed_data.unit = UNIT_PT;
                   2698:       pval.typed_data.value = 10;
                   2699:       cssRule += 7;
                   2700:     }
                   2701:   else if (!strncasecmp (cssRule, "small", 5))
                   2702:     {
                   2703:       pval.typed_data.unit = UNIT_PT;
                   2704:       pval.typed_data.value = 11;
                   2705:       cssRule += 5;
                   2706:     }
                   2707:   else if (!strncasecmp (cssRule, "medium", 6))
                   2708:     {
                   2709:       pval.typed_data.unit = UNIT_PT;
                   2710:       pval.typed_data.value = 12;
                   2711:       cssRule += 6;
                   2712:     }
                   2713:   else if (!strncasecmp (cssRule, "large", 5))
                   2714:     {
                   2715:       pval.typed_data.unit = UNIT_PT;
                   2716:       pval.typed_data.value = 13;
                   2717:       cssRule += 5;
                   2718:     }
                   2719:   else if (!strncasecmp (cssRule, "x-large", 7))
                   2720:     {
                   2721:       pval.typed_data.unit = UNIT_PT;
                   2722:       pval.typed_data.value = 14;
                   2723:       cssRule += 7;
                   2724:     }
                   2725:   else if (!strncasecmp (cssRule, "xx-large", 8))
                   2726:     {
                   2727:       pval.typed_data.unit = UNIT_PT;
                   2728:       pval.typed_data.value = 16;
                   2729:       cssRule += 8;
                   2730:     }
                   2731:   else if (!strncasecmp (cssRule, "inherit", 7))
                   2732:     {
                   2733:       pval.typed_data.unit = VALUE_INHERIT;
                   2734:       pval.typed_data.value = 0;
                   2735:       cssRule += 7;
                   2736:     }
                   2737:   /* length or percentage */
                   2738:   else if (!isdigit (*cssRule) && *cssRule != '.')
                   2739:     {
                   2740:       if (!check)
                   2741:         {
                   2742:           cssRule = SkipValue ("Invalid font-size value", cssRule);
                   2743:           cssRule = CheckImportantRule (cssRule, context);
                   2744:         }
                   2745:       return (cssRule);
                   2746:     }
                   2747:   else
                   2748:     {       
                   2749:       cssRule = ParseCSSUnit (cssRule, &pval);
                   2750:       if (pval.typed_data.unit == UNIT_BOX)
                   2751:         /* no unit specified */
                   2752:         {
                   2753:           elType = TtaGetElementType(element);
                   2754:           if (!strcmp(TtaGetSSchemaName (elType.ElSSchema), "SVG"))
                   2755:             /* we are working for an SVG element. No unit means pixels */
                   2756:             pval.typed_data.unit = UNIT_PX;
                   2757:         }
                   2758:       if (pval.typed_data.value != 0 &&
                   2759:           (pval.typed_data.unit == UNIT_INVALID ||
                   2760:            pval.typed_data.unit == UNIT_BOX ||
                   2761:            pval.typed_data.value < 0))
                   2762:         /* not a valid value */
                   2763:         return (cssRule);
                   2764:       else if (pval.typed_data.unit == UNIT_REL && pval.typed_data.value > 0)
                   2765:         /* CSS relative sizes have to be higher than Thot ones */
                   2766:         pval.typed_data.value += 1;
                   2767:       else 
                   2768:         {
                   2769:           real = pval.typed_data.real;
                   2770:           if (pval.typed_data.unit == UNIT_EM)
                   2771:             {
                   2772:               if (real)
                   2773:                 {
                   2774:                   pval.typed_data.value /= 10;
                   2775:                   pval.typed_data.real = FALSE;
                   2776:                   real = FALSE;
                   2777:                 }
                   2778:               else
                   2779:                 pval.typed_data.value *= 100;
                   2780:               pval.typed_data.unit = UNIT_PERCENT;
                   2781:             }
                   2782:           else if (pval.typed_data.unit == UNIT_XHEIGHT)
                   2783:             {
                   2784:               /* a font size expressed in ex is converted into a percentage.
                   2785:                  For example, "3ex" is converted into "180%", supposing
                   2786:                  that 1ex is approximately 0.6 times the height of the
                   2787:                  current font */
                   2788:               if (real)
                   2789:                 {
                   2790:                   pval.typed_data.value *= 6;
                   2791:                   pval.typed_data.value /= 100;
                   2792:                   pval.typed_data.real = FALSE;
                   2793:                   real = FALSE;
                   2794:                 }
                   2795:               else
                   2796:                 pval.typed_data.value *= 60;
                   2797:               pval.typed_data.unit = UNIT_PERCENT;
                   2798:             }
                   2799:         }
                   2800:     }
                   2801: 
                   2802:   /* install the presentation style */
                   2803:   cssRule = CheckImportantRule (cssRule, context);
                   2804:   if (!check && DoApply)
                   2805:     TtaSetStylePresentation (PRSize, element, tsch, context, pval);
                   2806:   if (!check && ptr)
                   2807:     cssRule = ParseCSSLineHeight (element, tsch, context, &ptr[1], css, isHTML);
                   2808:   if (linespace)
                   2809:     *ptr = '/';
                   2810: 
                   2811:   return (cssRule);
                   2812: }
                   2813: 
                   2814: /*----------------------------------------------------------------------
                   2815:   ParseCSSFontSize: parse a CSS font size attr string  
                   2816:   we expect the input string describing the attribute to be     
                   2817:   xx-small, x-small, small, medium, large, x-large, xx-large      
                   2818:   or an absolute size, or an imcrement relative to the parent     
1.270     vatton   2819:   ----------------------------------------------------------------------*/
                   2820: static char *ParseCSSFontSize (Element element, PSchema tsch,
1.327     vatton   2821:                                PresentationContext context, char *cssRule,
                   2822:                                CSSInfoPtr css, ThotBool isHTML)
1.270     vatton   2823: {
1.299     vatton   2824:   char               *ptr = cssRule;
1.295     vatton   2825:   cssRule = ParseACSSFontSize (element, tsch, context, cssRule, css, isHTML, FALSE);
                   2826:   cssRule = CheckImportantRule (cssRule, context);
1.299     vatton   2827:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid font-size value");
1.295     vatton   2828:   return cssRule;
1.270     vatton   2829: }
                   2830: 
                   2831: /*----------------------------------------------------------------------
1.327     vatton   2832:   ParseACSSFontFamily: parse a CSS font family string   
                   2833:   we expect the input string describing the attribute to be     
                   2834:   a common generic font style name                                
1.1       cvs      2835:   ----------------------------------------------------------------------*/
1.268     vatton   2836: static char *ParseACSSFontFamily (Element element, PSchema tsch,
1.327     vatton   2837:                                   PresentationContext context, char *cssRule,
                   2838:                                   CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      2839: {
                   2840:   PresentationValue   font;
1.252     vatton   2841:   char                quoteChar, *p;
1.1       cvs      2842: 
                   2843:   font.typed_data.value = 0;
1.184     vatton   2844:   font.typed_data.unit = UNIT_REL;
1.1       cvs      2845:   font.typed_data.real = FALSE;
1.82      cvs      2846:   cssRule = SkipBlanksAndComments (cssRule);
                   2847:   if (*cssRule == '"' || *cssRule == '\'')
1.327     vatton   2848:     {
                   2849:       quoteChar = *cssRule;
                   2850:       cssRule++;
                   2851:     }
1.1       cvs      2852:   else
1.327     vatton   2853:     quoteChar = EOS;
1.1       cvs      2854: 
1.293     quint    2855:   if (!strncasecmp (cssRule, "inherit", 7) && quoteChar == EOS)
                   2856:     {
                   2857:       font.typed_data.unit = VALUE_INHERIT;
                   2858:       cssRule += 7;
                   2859:     }
                   2860:   else if (!strncasecmp (cssRule, "times", 5) &&
1.327     vatton   2861:            (quoteChar == EOS || quoteChar == cssRule[5]))
1.86      cvs      2862:     {
1.184     vatton   2863:       font.typed_data.value = FontTimes;
1.86      cvs      2864:       cssRule += 5;
                   2865:     }
1.92      cvs      2866:   else if (!strncasecmp (cssRule, "serif", 5) &&
1.327     vatton   2867:            (quoteChar == EOS || quoteChar == cssRule[5]))
1.86      cvs      2868:     {
1.184     vatton   2869:       font.typed_data.value = FontTimes;
1.86      cvs      2870:       cssRule += 5;
1.92      cvs      2871:       if (quoteChar != EOS)
1.327     vatton   2872:         cssRule++;
1.86      cvs      2873:     }
1.92      cvs      2874:   else if (!strncasecmp (cssRule, "helvetica", 9) &&
1.327     vatton   2875:            (quoteChar == EOS || quoteChar == cssRule[9]))
1.86      cvs      2876:     {
1.327     vatton   2877:       font.typed_data.value = FontHelvetica;
1.86      cvs      2878:       cssRule += 9;
1.92      cvs      2879:       if (quoteChar != EOS)
1.327     vatton   2880:         cssRule++;
1.86      cvs      2881:     }
1.92      cvs      2882:   else if (!strncasecmp (cssRule, "verdana", 7) &&
1.327     vatton   2883:            (quoteChar == EOS || quoteChar == cssRule[7]))
1.86      cvs      2884:     {
1.184     vatton   2885:       font.typed_data.value = FontHelvetica;
1.86      cvs      2886:       cssRule += 7;
1.92      cvs      2887:       if (quoteChar != EOS)
1.327     vatton   2888:         cssRule++;
1.86      cvs      2889:     }
1.92      cvs      2890:   else if (!strncasecmp (cssRule, "sans-serif", 10) &&
1.327     vatton   2891:            (quoteChar == EOS || quoteChar == cssRule[10]))
1.86      cvs      2892:     {
1.184     vatton   2893:       font.typed_data.value = FontHelvetica;
1.86      cvs      2894:       cssRule += 10;
1.92      cvs      2895:       if (quoteChar != EOS)
1.327     vatton   2896:         cssRule++;
1.86      cvs      2897:     }
1.268     vatton   2898:   else if (!strncasecmp (cssRule, "courier new", 11) &&
1.327     vatton   2899:            (quoteChar == EOS || quoteChar == cssRule[11]))
1.268     vatton   2900:     {
                   2901:       font.typed_data.value = FontCourier;
                   2902:       cssRule += 11;
                   2903:       if (quoteChar != EOS)
1.327     vatton   2904:         cssRule++;
1.268     vatton   2905:     }
1.92      cvs      2906:   else if (!strncasecmp (cssRule, "courier", 7) &&
1.327     vatton   2907:            (quoteChar == EOS || quoteChar == cssRule[7]))
1.86      cvs      2908:     {
1.184     vatton   2909:       font.typed_data.value = FontCourier;
1.86      cvs      2910:       cssRule += 7;
1.92      cvs      2911:       if (quoteChar != EOS)
1.327     vatton   2912:         cssRule++;
1.86      cvs      2913:     }
1.92      cvs      2914:   else if (!strncasecmp (cssRule, "monospace", 9) &&
1.327     vatton   2915:            (quoteChar == EOS || quoteChar == cssRule[9]))
1.86      cvs      2916:     {
1.184     vatton   2917:       font.typed_data.value = FontCourier;
1.86      cvs      2918:       cssRule += 9;
1.92      cvs      2919:       if (quoteChar != EOS)
1.327     vatton   2920:         cssRule++;
1.86      cvs      2921:     }
1.1       cvs      2922:   else
                   2923:     /* unknown font name.  Skip it */
                   2924:     {
1.252     vatton   2925:       p = cssRule;
1.92      cvs      2926:       if (quoteChar != EOS)
1.327     vatton   2927:         cssRule = SkipQuotedString (cssRule, quoteChar);
1.86      cvs      2928:       else
1.327     vatton   2929:         cssRule = SkipWord (cssRule);
1.252     vatton   2930:       while (p == cssRule &&
1.327     vatton   2931:              *cssRule != ','  && *cssRule != ';'  && *cssRule != '}' && *cssRule != EOS)
                   2932:         {
                   2933:           cssRule++;
                   2934:           p = cssRule;
                   2935:           cssRule = SkipWord (cssRule);
                   2936:         }
1.82      cvs      2937:       cssRule = SkipBlanksAndComments (cssRule);
                   2938:       if (*cssRule == ',')
1.327     vatton   2939:         {
                   2940:           /* recursive call to ParseCSSFontFamily */
                   2941:           cssRule++;
                   2942:           cssRule = ParseACSSFontFamily (element, tsch, context, cssRule, css, isHTML);
                   2943:           return (cssRule);
                   2944:         }
1.1       cvs      2945:     }
                   2946: 
1.239     vatton   2947:   /* skip other values */
                   2948:   cssRule = SkipBlanksAndComments (cssRule);
                   2949:   while (*cssRule == ',')
                   2950:     {
                   2951:       cssRule++;
                   2952:       cssRule = SkipValue (NULL, cssRule);
                   2953:       cssRule = SkipBlanksAndComments (cssRule);
                   2954:     }
                   2955: 
1.295     vatton   2956:   cssRule = CheckImportantRule (cssRule, context);
                   2957:   if ((font.typed_data.value != 0 || font.typed_data.unit == VALUE_INHERIT) &&
                   2958:       DoApply)
                   2959:     /* install the new presentation */
                   2960:     TtaSetStylePresentation (PRFont, element, tsch, context, font);
1.1       cvs      2961:   return (cssRule);
                   2962: }
                   2963: 
                   2964: /*----------------------------------------------------------------------
1.327     vatton   2965:   ParseCSSFontFamily: parse a CSS font family string   
                   2966:   we expect the input string describing the attribute to be     
                   2967:   a common generic font style name                                
1.268     vatton   2968:   ----------------------------------------------------------------------*/
                   2969: static char *ParseCSSFontFamily (Element element, PSchema tsch,
1.327     vatton   2970:                                  PresentationContext context, char *cssRule,
                   2971:                                  CSSInfoPtr css, ThotBool isHTML)
1.268     vatton   2972: {
                   2973:   cssRule = ParseACSSFontFamily (element, tsch, context, cssRule, css, isHTML);
                   2974:   /* skip extra values */
1.301     vatton   2975:   while (cssRule && *cssRule != ';' && *cssRule != '}' && *cssRule != EOS)
1.268     vatton   2976:     cssRule++;
                   2977:   return (cssRule);
                   2978: }
                   2979: 
                   2980: /*----------------------------------------------------------------------
1.327     vatton   2981:   ParseACSSFontWeight: parse a CSS font weight string   
                   2982:   we expect the input string describing the attribute to be     
                   2983:   normal, bold, bolder, lighter, 100, 200, 300, ... 900, inherit.
1.1       cvs      2984:   ----------------------------------------------------------------------*/
1.263     vatton   2985: static char *ParseACSSFontWeight (Element element, PSchema tsch,
1.327     vatton   2986:                                   PresentationContext context, char *cssRule,
                   2987:                                   CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      2988: {
1.327     vatton   2989:   PresentationValue   weight;
1.1       cvs      2990: 
1.327     vatton   2991:   weight.typed_data.value = 0;
                   2992:   weight.typed_data.unit = UNIT_REL;
                   2993:   weight.typed_data.real = FALSE;
                   2994:   cssRule = SkipBlanksAndComments (cssRule);
                   2995:   if (!strncasecmp (cssRule, "100", 3) && cssRule[3] != '%' &&
                   2996:       !isalpha (cssRule[3]))
                   2997:     {
                   2998:       weight.typed_data.value = -3;
                   2999:       cssRule = SkipWord (cssRule);
                   3000:     }
                   3001:   else if (!strncasecmp (cssRule, "200", 3) && !isalpha (cssRule[3]))
                   3002:     {
                   3003:       weight.typed_data.value = -2;
                   3004:       cssRule = SkipWord (cssRule);
                   3005:     }
                   3006:   else if (!strncasecmp (cssRule, "300", 3) && ! isalpha(cssRule[3]))
                   3007:     {
                   3008:       weight.typed_data.value = -1;
                   3009:       cssRule = SkipWord (cssRule);
                   3010:     }
                   3011:   else if (!strncasecmp (cssRule, "normal", 6) ||
                   3012:            (!strncasecmp (cssRule, "400", 3) && !isalpha (cssRule[3])))
                   3013:     {
                   3014:       weight.typed_data.value = 0;
                   3015:       cssRule = SkipWord (cssRule);
                   3016:     }
                   3017:   else if (!strncasecmp (cssRule, "500", 3) && !isalpha (cssRule[3]))
                   3018:     {
                   3019:       weight.typed_data.value = +1;
                   3020:       cssRule = SkipWord (cssRule);
                   3021:     }
                   3022:   else if (!strncasecmp (cssRule, "600", 3) && !isalpha (cssRule[3]))
                   3023:     {
                   3024:       weight.typed_data.value = +2;
                   3025:       cssRule = SkipWord (cssRule);
                   3026:     }
                   3027:   else if (!strncasecmp (cssRule, "bold", 4) ||
                   3028:            (!strncasecmp (cssRule, "700", 3) && !isalpha (cssRule[3])))
                   3029:     {
                   3030:       weight.typed_data.value = +3;
                   3031:       cssRule = SkipWord (cssRule);
                   3032:     }
                   3033:   else if (!strncasecmp (cssRule, "800", 3) && !isalpha (cssRule[3]))
                   3034:     {
                   3035:       weight.typed_data.value = +4;
                   3036:       cssRule = SkipWord (cssRule);
                   3037:     }
                   3038:   else if (!strncasecmp (cssRule, "900", 3) && !isalpha (cssRule[3]))
                   3039:     {
                   3040:       weight.typed_data.value = +5;
                   3041:       cssRule = SkipWord (cssRule);
                   3042:     }
                   3043:   else if (!strncasecmp (cssRule, "inherit", 7))
                   3044:     {
                   3045:       weight.typed_data.unit = VALUE_INHERIT;
                   3046:       cssRule += 7;
                   3047:     }
                   3048:   else if (!strncasecmp (cssRule, "bolder", 6) ||
                   3049:            !strncasecmp (cssRule, "lighter", 7))
                   3050:     {
                   3051:       /* not implemented */
                   3052:       cssRule = SkipWord (cssRule);
                   3053:       return (cssRule);
                   3054:     }
                   3055:   else
                   3056:     return (cssRule);
                   3057: 
                   3058:   /*
                   3059:    * Here we have to reduce since only two font weight values are supported
                   3060:    * by the Thot presentation API.
                   3061:    */
                   3062:   if (weight.typed_data.unit != VALUE_INHERIT)
                   3063:     {
                   3064:       if (weight.typed_data.value > 0)
                   3065:         weight.typed_data.value = WeightBold;
                   3066:       else
                   3067:         weight.typed_data.value = WeightNormal;
                   3068:     }
                   3069: 
                   3070:   /* install the new presentation */
                   3071:   cssRule = CheckImportantRule (cssRule, context);
                   3072:   if (DoApply)
                   3073:     TtaSetStylePresentation (PRWeight, element, tsch, context, weight);
                   3074:   return (cssRule);
                   3075: }
                   3076: 
                   3077: /*----------------------------------------------------------------------
                   3078:   ParseCSSFontWeight: parse a CSS font weight string   
                   3079:   we expect the input string describing the attribute to be     
                   3080:   normal, bold, bolder, lighter, 100, 200, 300, ... 900, inherit.
1.263     vatton   3081:   ----------------------------------------------------------------------*/
                   3082: static char *ParseCSSFontWeight (Element element, PSchema tsch,
1.327     vatton   3083:                                  PresentationContext context, char *cssRule,
                   3084:                                  CSSInfoPtr css, ThotBool isHTML)
1.263     vatton   3085: {
                   3086:   char           *ptr;
                   3087:   
                   3088:   ptr = cssRule;
                   3089:   cssRule = ParseACSSFontWeight (element, tsch, context, cssRule, css, isHTML);
                   3090:   if (ptr == cssRule)
                   3091:     cssRule = SkipValue ("Invalid font-weight value", cssRule);
1.295     vatton   3092:   cssRule = CheckImportantRule (cssRule, context);
1.263     vatton   3093:   return (cssRule);
                   3094: }
                   3095: 
                   3096: /*----------------------------------------------------------------------
1.327     vatton   3097:   ParseACSSFontVariant: parse a CSS font variant string     
                   3098:   we expect the input string describing the attribute to be     
                   3099:   normal or small-caps
1.1       cvs      3100:   ----------------------------------------------------------------------*/
1.263     vatton   3101: static char *ParseACSSFontVariant (Element element, PSchema tsch,
1.327     vatton   3102:                                    PresentationContext context, char *cssRule,
                   3103:                                    CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      3104: {
1.327     vatton   3105:   PresentationValue   style;
1.1       cvs      3106: 
1.327     vatton   3107:   style.typed_data.value = 0;
                   3108:   style.typed_data.unit = UNIT_REL;
                   3109:   style.typed_data.real = FALSE;
                   3110:   cssRule = SkipBlanksAndComments (cssRule);
                   3111:   if (!strncasecmp (cssRule, "small-caps", 10))
                   3112:     {
                   3113:       /* Not supported yet */
                   3114:       cssRule = SkipWord (cssRule);
                   3115:     }
                   3116:   else if (!strncasecmp (cssRule, "normal", 6))
                   3117:     {
                   3118:       /* Not supported yet */
                   3119:       cssRule = SkipWord (cssRule);
                   3120:     }
                   3121:   else if (!strncasecmp (cssRule, "inherit", 7))
                   3122:     {
                   3123:       /* Not supported yet */
                   3124:       cssRule = SkipWord (cssRule);
                   3125:     }
1.295     vatton   3126:   return (cssRule);
1.263     vatton   3127: }
1.1       cvs      3128: 
1.263     vatton   3129: /*----------------------------------------------------------------------
1.327     vatton   3130:   ParseCSSFontVariant: parse a CSS font variant string     
                   3131:   we expect the input string describing the attribute to be     
                   3132:   normal or small-caps
1.263     vatton   3133:   ----------------------------------------------------------------------*/
                   3134: static char *ParseCSSFontVariant (Element element, PSchema tsch,
1.327     vatton   3135:                                   PresentationContext context, char *cssRule,
                   3136:                                   CSSInfoPtr css, ThotBool isHTML)
1.263     vatton   3137: {
                   3138:   char           *ptr;
                   3139:   
                   3140:   ptr = cssRule;
                   3141:   cssRule = ParseACSSFontVariant (element, tsch, context, cssRule, css, isHTML);
                   3142:   if (ptr == cssRule)
                   3143:     cssRule = SkipValue ("Invalid font-variant value", cssRule);
1.295     vatton   3144:   cssRule = CheckImportantRule (cssRule, context);
1.263     vatton   3145:   return (cssRule);
1.1       cvs      3146: }
                   3147: 
                   3148: 
                   3149: /*----------------------------------------------------------------------
1.327     vatton   3150:   ParseACSSFontStyle: parse a CSS font style string     
                   3151:   we expect the input string describing the attribute to be     
                   3152:   normal, italic, oblique or inherit                         
1.1       cvs      3153:   ----------------------------------------------------------------------*/
1.263     vatton   3154: static char *ParseACSSFontStyle (Element element, PSchema tsch,
1.327     vatton   3155:                                  PresentationContext context, char *cssRule,
                   3156:                                  CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      3157: {
1.327     vatton   3158:   PresentationValue   style;
                   3159:   PresentationValue   size;
1.1       cvs      3160: 
1.327     vatton   3161:   style.typed_data.value = 0;
                   3162:   style.typed_data.unit = UNIT_REL;
                   3163:   style.typed_data.real = FALSE;
                   3164:   size.typed_data.value = 0;
                   3165:   size.typed_data.unit = UNIT_REL;
                   3166:   size.typed_data.real = FALSE;
                   3167:   cssRule = SkipBlanksAndComments (cssRule);
                   3168:   if (!strncasecmp (cssRule, "italic", 6))
                   3169:     {
                   3170:       style.typed_data.value = StyleItalics;
                   3171:       cssRule = SkipWord (cssRule);
                   3172:     }
                   3173:   else if (!strncasecmp (cssRule, "oblique", 7))
                   3174:     {
                   3175:       style.typed_data.value = StyleOblique;
                   3176:       cssRule = SkipWord (cssRule);
                   3177:     }
                   3178:   else if (!strncasecmp (cssRule, "normal", 6))
                   3179:     {
                   3180:       style.typed_data.value = StyleRoman;
                   3181:       cssRule = SkipWord (cssRule);
                   3182:     }
                   3183:   else if (!strncasecmp (cssRule, "inherit", 7))
                   3184:     {
                   3185:       style.typed_data.unit = VALUE_INHERIT;
                   3186:       cssRule = SkipWord (cssRule);
                   3187:     }
                   3188:   else
                   3189:     /* invalid font style */
                   3190:     return (cssRule);
                   3191: 
                   3192:   /*
                   3193:    * install the new presentation.
                   3194:    */
                   3195:   cssRule = CheckImportantRule (cssRule, context);
                   3196:   if (DoApply &&
                   3197:       (style.typed_data.value != 0 || style.typed_data.unit == VALUE_INHERIT))
                   3198:     {
                   3199:       TtaSetStylePresentation (PRStyle, element, tsch, context, style);
                   3200:     }
                   3201:   if (size.typed_data.value != 0 && DoApply)
                   3202:     {
                   3203:       PresentationValue   previous_size;
                   3204: 
                   3205:       if (!TtaGetStylePresentation (PRSize, element, tsch, context, &previous_size))
                   3206:         {
                   3207:           /* !!!!!!!!!!!!!!!!!!!!!!!! Unit + relative !!!!!!!!!!!!!!!! */
                   3208:           size.typed_data.value += previous_size.typed_data.value;
                   3209:           TtaSetStylePresentation (PRSize, element, tsch, context, size);
                   3210:         }
                   3211:       else
                   3212:         {
                   3213:           size.typed_data.value = 10;
                   3214:           TtaSetStylePresentation (PRSize, element, tsch, context, size);
                   3215:         }
                   3216:     }
                   3217:   return (cssRule);
                   3218: }
                   3219: 
                   3220: /*----------------------------------------------------------------------
                   3221:   ParseCSSFontStyle: parse a CSS font style string     
                   3222:   we expect the input string describing the attribute to be     
                   3223:   italic, oblique or normal                         
1.263     vatton   3224:   ----------------------------------------------------------------------*/
                   3225: static char *ParseCSSFontStyle (Element element, PSchema tsch,
1.327     vatton   3226:                                 PresentationContext context, char *cssRule,
                   3227:                                 CSSInfoPtr css, ThotBool isHTML)
1.263     vatton   3228: {
                   3229:   char           *ptr;
                   3230:   
                   3231:   ptr = cssRule;
                   3232:   cssRule = ParseACSSFontStyle (element, tsch, context, cssRule, css, isHTML);
                   3233:   if (ptr == cssRule)
                   3234:     cssRule = SkipValue ("Invalid font-style value", cssRule);
1.295     vatton   3235:   cssRule = CheckImportantRule (cssRule, context);
1.263     vatton   3236:   return (cssRule);
                   3237: }
                   3238: 
                   3239: /*----------------------------------------------------------------------
1.59      cvs      3240:   ParseCSSFont: parse a CSS font attribute string
                   3241:   we expect the input string describing the attribute to be
                   3242:   !!!!!!                                  
1.1       cvs      3243:   ----------------------------------------------------------------------*/
1.79      cvs      3244: static char *ParseCSSFont (Element element, PSchema tsch,
1.327     vatton   3245:                            PresentationContext context, char *cssRule,
                   3246:                            CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      3247: {
1.270     vatton   3248:   char           *ptr, *p;
1.93      vatton   3249:   int             skippedNL;
1.272     vatton   3250:   ThotBool        variant = FALSE, style = FALSE, weight = FALSE, found; 
1.1       cvs      3251: 
1.82      cvs      3252:   cssRule = SkipBlanksAndComments (cssRule);
                   3253:   if (!strncasecmp (cssRule, "caption", 7))
1.263     vatton   3254:     cssRule += 7;
1.82      cvs      3255:   else if (!strncasecmp (cssRule, "icon", 4))
1.263     vatton   3256:     cssRule += 4;
1.82      cvs      3257:   else if (!strncasecmp (cssRule, "menu", 4))
1.263     vatton   3258:     cssRule += 4;
1.82      cvs      3259:   else if (!strncasecmp (cssRule, "message-box", 11))
1.263     vatton   3260:     cssRule += 11;
1.82      cvs      3261:   else if (!strncasecmp (cssRule, "small-caption", 13))
1.263     vatton   3262:     cssRule += 13;
1.82      cvs      3263:   else if (!strncasecmp (cssRule, "status-bar", 10))
1.263     vatton   3264:     cssRule += 10;
                   3265:   else if (!strncasecmp (cssRule, "inherit", 7))
1.293     quint    3266:     {
                   3267:       ParseACSSFontStyle (element, tsch, context, cssRule, css, isHTML);
                   3268:       ParseACSSFontVariant (element, tsch, context, cssRule, css, isHTML);
                   3269:       ParseACSSFontWeight (element, tsch, context, cssRule, css, isHTML);
                   3270:       ParseACSSFontSize (element, tsch, context, cssRule, css, isHTML, FALSE);
                   3271:       ParseACSSFontFamily (element, tsch, context, cssRule, css, isHTML);
                   3272:       cssRule += 7;
                   3273:     }
1.1       cvs      3274:   else
1.43      cvs      3275:     {
1.270     vatton   3276:       ptr = NULL;
                   3277:       p = cssRule;
1.301     vatton   3278:       while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && p == cssRule)
1.327     vatton   3279:         {
                   3280:           found = FALSE;
                   3281:           /* style, variant, weight can appear in any order */
                   3282:           ptr = cssRule;
                   3283:           skippedNL = NewLineSkipped;
                   3284:           cssRule = ParseACSSFontStyle (element, tsch, context, cssRule, css, isHTML);
                   3285:           if (ptr != cssRule)
                   3286:             {
                   3287:               skippedNL = NewLineSkipped;
                   3288:               found = TRUE;
                   3289:               style = TRUE;
                   3290:             }
                   3291:           else
                   3292:             NewLineSkipped = skippedNL;
                   3293:           ptr = cssRule;
                   3294:           cssRule = ParseACSSFontVariant (element, tsch, context, cssRule, css, isHTML);
                   3295:           if (ptr != cssRule)
                   3296:             {
                   3297:               skippedNL = NewLineSkipped;
                   3298:               found = TRUE;
                   3299:               variant = TRUE;
                   3300:             }
                   3301:           else
                   3302:             NewLineSkipped = skippedNL;
                   3303:           ptr = cssRule;
                   3304:           cssRule = ParseACSSFontWeight (element, tsch, context, cssRule, css, isHTML);
                   3305:           if (ptr != cssRule)
                   3306:             {
                   3307:               skippedNL = NewLineSkipped;
                   3308:               found = TRUE;
                   3309:               weight = TRUE;
                   3310:             }
                   3311:           else
                   3312:             NewLineSkipped = skippedNL;
                   3313:           cssRule = SkipBlanksAndComments (cssRule);
                   3314:           p = ParseACSSFontSize (element, tsch, context, cssRule, css, isHTML, TRUE);
                   3315:           NewLineSkipped = skippedNL;
                   3316:           if (!found)
                   3317:             /* break the loop when the current value was not parsed */
                   3318:             p = cssRule + 1;
                   3319:         }
1.263     vatton   3320:       ptr = cssRule;
1.270     vatton   3321:       /* set default variant, style, weight */
                   3322:       if (!variant)
1.327     vatton   3323:         ParseACSSFontVariant (element, tsch, context, "normal", css, isHTML);
1.270     vatton   3324:       if (!style)
1.327     vatton   3325:         ParseACSSFontStyle (element, tsch, context, "normal", css, isHTML);
1.270     vatton   3326:       if (!weight)
1.327     vatton   3327:         ParseACSSFontWeight (element, tsch, context, "normal", css, isHTML);
1.270     vatton   3328:       /* now parse the font size and the font family */
1.301     vatton   3329:       if (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS)
1.327     vatton   3330:         cssRule = ParseACSSFontSize (element, tsch, context, cssRule, css, isHTML, FALSE);
1.301     vatton   3331:       if (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS)
1.327     vatton   3332:         cssRule = ParseACSSFontFamily (element, tsch, context, cssRule, css, isHTML);
1.263     vatton   3333:       if (ptr == cssRule)
1.327     vatton   3334:         {
                   3335:           cssRule = SkipValue ("Invalid font value", cssRule);
                   3336:           cssRule = CheckImportantRule (cssRule, context);
                   3337:         }
1.43      cvs      3338:     }
1.263     vatton   3339:   cssRule = SkipBlanksAndComments (cssRule);
1.301     vatton   3340:   if (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS)
1.295     vatton   3341:     {
                   3342:       cssRule = SkipValue ("Invalid font value", cssRule);
                   3343:       cssRule = CheckImportantRule (cssRule, context);
                   3344:     }
1.43      cvs      3345:   return (cssRule);
1.1       cvs      3346: }
                   3347: 
                   3348: /*----------------------------------------------------------------------
1.59      cvs      3349:   ParseCSSTextDecoration: parse a CSS text decor string   
                   3350:   we expect the input string describing the attribute to be     
1.109     cvs      3351:   underline, overline, line-through, blink or none.
1.1       cvs      3352:   ----------------------------------------------------------------------*/
1.79      cvs      3353: static char *ParseCSSTextDecoration (Element element, PSchema tsch,
1.327     vatton   3354:                                      PresentationContext context, char *cssRule,
                   3355:                                      CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      3356: {
1.327     vatton   3357:   PresentationValue   decor;
                   3358:   char               *ptr = cssRule;
                   3359: 
                   3360:   decor.typed_data.value = 0;
                   3361:   decor.typed_data.unit = UNIT_REL;
                   3362:   decor.typed_data.real = FALSE;
                   3363:   cssRule = SkipBlanksAndComments (cssRule);
                   3364:   if (!strncasecmp (cssRule, "none", 4))
                   3365:     {
                   3366:       decor.typed_data.value = NoUnderline;
                   3367:       cssRule += 4;
                   3368:     }
                   3369:   else if (!strncasecmp (cssRule, "underline", 9))
                   3370:     {
                   3371:       decor.typed_data.value = Underline;
                   3372:       cssRule += 9;
                   3373:     }
                   3374:   else if (!strncasecmp (cssRule, "overline", 8))
                   3375:     {
                   3376:       decor.typed_data.value = Overline;
                   3377:       cssRule += 8;
                   3378:     }
                   3379:   else if (!strncasecmp (cssRule, "line-through", 12))
                   3380:     {
                   3381:       decor.typed_data.value = CrossOut;
                   3382:       cssRule += 12;
                   3383:     }
                   3384:   else if (!strncasecmp (cssRule, "blink", 5))
                   3385:     {
                   3386:       /* the blink text-decoration attribute is not supported */
                   3387:       cssRule += 5;
                   3388:     }
                   3389:   else if (!strncasecmp (cssRule, "inherit", 7))
                   3390:     {
                   3391:       decor.typed_data.unit = VALUE_INHERIT;
                   3392:       cssRule += 7;
                   3393:     }
                   3394:   else
                   3395:     {
                   3396:       cssRule = SkipValue ("Invalid text-decoration value", cssRule);
                   3397:       cssRule = CheckImportantRule (cssRule, context);
                   3398:       return (cssRule);
                   3399:     }
1.1       cvs      3400: 
1.327     vatton   3401:   /*
                   3402:    * install the new presentation.
                   3403:    */
                   3404:   cssRule = CheckImportantRule (cssRule, context);
                   3405:   if (DoApply &&
                   3406:       (decor.typed_data.value || decor.typed_data.unit == VALUE_INHERIT))
                   3407:     TtaSetStylePresentation (PRUnderline, element, tsch, context, decor);
                   3408:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid text-decoration value");
                   3409:   return (cssRule);
1.1       cvs      3410: }
                   3411: 
                   3412: /*----------------------------------------------------------------------
1.327     vatton   3413:   ParseCSSHeight: parse a CSS height attribute
1.1       cvs      3414:   ----------------------------------------------------------------------*/
1.79      cvs      3415: static char *ParseCSSHeight (Element element, PSchema tsch,
1.327     vatton   3416:                              PresentationContext context, char *cssRule,
                   3417:                              CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      3418: {
1.117     vatton   3419:   PresentationValue   val;
1.168     vatton   3420:   char               *ptr;
1.93      vatton   3421: 
1.117     vatton   3422:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   3423:   ptr = cssRule;
1.117     vatton   3424:   /* first parse the attribute string */
1.164     quint    3425:   if (!strncasecmp (cssRule, "auto", 4))
                   3426:     {
1.184     vatton   3427:       val.typed_data.unit = VALUE_AUTO;
1.164     quint    3428:       val.typed_data.value = 0;
                   3429:       val.typed_data.real = FALSE;
1.288     vatton   3430:       cssRule += 4;
1.295     vatton   3431:       cssRule = CheckImportantRule (cssRule, context);
                   3432:       cssRule = CheckImportantRule (cssRule, context);
1.288     vatton   3433:       cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid height value");
1.164     quint    3434:     }
1.117     vatton   3435:   else
1.168     vatton   3436:     cssRule = ParseCSSUnit (cssRule, &val);
1.295     vatton   3437: 
1.168     vatton   3438:   if (val.typed_data.value != 0 &&
1.184     vatton   3439:       (val.typed_data.unit == UNIT_INVALID ||
                   3440:        val.typed_data.unit == UNIT_BOX))
1.211     vatton   3441:     {
                   3442:       CSSParseError ("height value", ptr, cssRule);
1.212     cvs      3443:       val.typed_data.unit = UNIT_PX;
1.211     vatton   3444:     }
1.295     vatton   3445:   cssRule = CheckImportantRule (cssRule, context);
1.211     vatton   3446:   if (DoApply)
1.295     vatton   3447:     /* install the new presentation */
                   3448:     TtaSetStylePresentation (PRHeight, element, tsch, context, val);
1.117     vatton   3449:   return (cssRule);
1.1       cvs      3450: }
                   3451: 
                   3452: /*----------------------------------------------------------------------
1.327     vatton   3453:   ParseCSSWidth: parse a CSS width attribute
1.1       cvs      3454:   ----------------------------------------------------------------------*/
1.79      cvs      3455: static char *ParseCSSWidth (Element element, PSchema tsch,
1.327     vatton   3456:                             PresentationContext context,
                   3457:                             char *cssRule, CSSInfoPtr css,
                   3458:                             ThotBool isHTML)
1.1       cvs      3459: {
1.117     vatton   3460:   PresentationValue   val;
1.168     vatton   3461:   char               *ptr;
1.93      vatton   3462: 
1.117     vatton   3463:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   3464:   ptr = cssRule;
1.117     vatton   3465:   /* first parse the attribute string */
1.164     quint    3466:   if (!strncasecmp (cssRule, "auto", 4))
                   3467:     {
1.184     vatton   3468:       val.typed_data.unit = VALUE_AUTO;
1.164     quint    3469:       val.typed_data.value = 0;
                   3470:       val.typed_data.real = FALSE;
1.288     vatton   3471:       cssRule += 4;
1.295     vatton   3472:       cssRule = CheckImportantRule (cssRule, context);
1.288     vatton   3473:       cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid width value");
1.164     quint    3474:     }
1.117     vatton   3475:   else
1.327     vatton   3476:     cssRule = ParseCSSUnit (cssRule, &val);
1.168     vatton   3477:   if (val.typed_data.value != 0 &&
1.184     vatton   3478:       (val.typed_data.unit == UNIT_INVALID ||
                   3479:        val.typed_data.unit == UNIT_BOX))
1.211     vatton   3480:     {
                   3481:       CSSParseError ("Invalid width value", ptr, cssRule);
1.295     vatton   3482:       cssRule = CheckImportantRule (cssRule, context);
1.212     cvs      3483:       val.typed_data.unit = UNIT_PX;
1.211     vatton   3484:     }
1.295     vatton   3485: 
                   3486:   cssRule = CheckImportantRule (cssRule, context);
1.211     vatton   3487:   if (DoApply)
1.295     vatton   3488:     /* install the new presentation */
                   3489:     TtaSetStylePresentation (PRWidth, element, tsch, context, val);
1.117     vatton   3490:   return (cssRule);
1.1       cvs      3491: }
                   3492: 
                   3493: /*----------------------------------------------------------------------
1.327     vatton   3494:   ParseACSSMarginTop: parse a CSS margin-top attribute
1.1       cvs      3495:   ----------------------------------------------------------------------*/
1.296     vatton   3496: static char *ParseACSSMarginTop (Element element, PSchema tsch,
1.327     vatton   3497:                                  PresentationContext context,
                   3498:                                  char *cssRule, CSSInfoPtr css,
                   3499:                                  ThotBool isHTML)
1.1       cvs      3500: {
                   3501:   PresentationValue   margin;
1.168     vatton   3502:   char               *ptr;
1.1       cvs      3503:   
1.82      cvs      3504:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   3505:   ptr = cssRule;
1.1       cvs      3506:   /* first parse the attribute string */
1.164     quint    3507:   if (!strncasecmp (cssRule, "auto", 4))
                   3508:     {
1.184     vatton   3509:       margin.typed_data.unit = VALUE_AUTO;
1.164     quint    3510:       margin.typed_data.value = 0;
                   3511:       margin.typed_data.real = FALSE;
1.288     vatton   3512:       cssRule += 4;
1.295     vatton   3513:       cssRule = CheckImportantRule (cssRule, context);
1.164     quint    3514:     }
                   3515:   else
1.168     vatton   3516:     cssRule = ParseCSSUnit (cssRule, &margin);
1.295     vatton   3517: 
                   3518:   cssRule = CheckImportantRule (cssRule, context);
1.168     vatton   3519:   if (margin.typed_data.value != 0 &&
1.184     vatton   3520:       (margin.typed_data.unit == UNIT_INVALID ||
                   3521:        margin.typed_data.unit == UNIT_BOX))
1.169     vatton   3522:     CSSParseError ("Invalid margin-top value", ptr, cssRule);
1.168     vatton   3523:   else if (DoApply)
1.295     vatton   3524:     TtaSetStylePresentation (PRMarginTop, element, tsch, context, margin);
1.1       cvs      3525:   return (cssRule);
                   3526: }
                   3527: 
                   3528: /*----------------------------------------------------------------------
1.327     vatton   3529:   ParseCSSMarginTop: parse a CSS margin-top attribute
1.296     vatton   3530:   ----------------------------------------------------------------------*/
                   3531: static char *ParseCSSMarginTop (Element element, PSchema tsch,
1.327     vatton   3532:                                 PresentationContext context,
                   3533:                                 char *cssRule, CSSInfoPtr css,
                   3534:                                 ThotBool isHTML)
1.296     vatton   3535: {
                   3536:   char *ptr = cssRule;
                   3537: 
                   3538:   cssRule = ParseACSSMarginTop (element, tsch, context, ptr, css, isHTML);
                   3539:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid margin-top value");
                   3540:   return (cssRule);
                   3541: }
                   3542: 
                   3543: /*----------------------------------------------------------------------
                   3544:   ParseACSSMarginBottom: parse a CSS margin-bottom attribute
1.1       cvs      3545:   ----------------------------------------------------------------------*/
1.296     vatton   3546: static char *ParseACSSMarginBottom (Element element, PSchema tsch,
1.327     vatton   3547:                                     PresentationContext context,
                   3548:                                     char *cssRule, CSSInfoPtr css,
                   3549:                                     ThotBool isHTML)
1.1       cvs      3550: {
                   3551:   PresentationValue   margin;
1.168     vatton   3552:   char               *ptr;
1.1       cvs      3553:   
1.82      cvs      3554:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   3555:   ptr = cssRule;
1.1       cvs      3556:   /* first parse the attribute string */
1.164     quint    3557:   if (!strncasecmp (cssRule, "auto", 4))
                   3558:     {
1.184     vatton   3559:       margin.typed_data.unit = VALUE_AUTO;
1.164     quint    3560:       margin.typed_data.value = 0;
                   3561:       margin.typed_data.real = FALSE;
1.288     vatton   3562:       cssRule += 4;
1.295     vatton   3563:       cssRule = CheckImportantRule (cssRule, context);
1.164     quint    3564:     }
                   3565:   else
1.168     vatton   3566:     cssRule = ParseCSSUnit (cssRule, &margin);
1.295     vatton   3567: 
                   3568:   cssRule = CheckImportantRule (cssRule, context);
1.168     vatton   3569:   if (margin.typed_data.value != 0 &&
1.184     vatton   3570:       (margin.typed_data.unit == UNIT_INVALID ||
                   3571:        margin.typed_data.unit == UNIT_BOX))
1.169     vatton   3572:     CSSParseError ("Invalid margin-bottom value", ptr, cssRule);
1.168     vatton   3573:   else if (DoApply)
1.295     vatton   3574:     TtaSetStylePresentation (PRMarginBottom, element, tsch, context, margin);
1.1       cvs      3575:   return (cssRule);
                   3576: }
                   3577: 
                   3578: /*----------------------------------------------------------------------
1.296     vatton   3579:   ParseCSSMarginBottom: parse a CSS margin-bottom attribute
                   3580:   ----------------------------------------------------------------------*/
                   3581: static char *ParseCSSMarginBottom (Element element, PSchema tsch,
1.327     vatton   3582:                                    PresentationContext context,
                   3583:                                    char *cssRule, CSSInfoPtr css,
                   3584:                                    ThotBool isHTML)
1.296     vatton   3585: {
                   3586:   char *ptr = cssRule;
                   3587: 
                   3588:   cssRule = ParseACSSMarginBottom (element, tsch, context, ptr, css, isHTML);
                   3589:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid margin-bottom value");
                   3590:   return (cssRule);
                   3591: }
                   3592: 
                   3593: /*----------------------------------------------------------------------
                   3594:   ParseACSSMarginLeft: parse a CSS margin-left attribute string
1.1       cvs      3595:   ----------------------------------------------------------------------*/
1.296     vatton   3596: static char *ParseACSSMarginLeft (Element element, PSchema tsch,
1.327     vatton   3597:                                   PresentationContext context,
                   3598:                                   char *cssRule, CSSInfoPtr css,
                   3599:                                   ThotBool isHTML)
1.1       cvs      3600: {
                   3601:   PresentationValue   margin;
1.168     vatton   3602:   char               *ptr;
1.1       cvs      3603:   
1.82      cvs      3604:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   3605:   ptr = cssRule;
1.1       cvs      3606:   /* first parse the attribute string */
1.164     quint    3607:   if (!strncasecmp (cssRule, "auto", 4))
                   3608:     {
1.184     vatton   3609:       margin.typed_data.unit = VALUE_AUTO;
1.164     quint    3610:       margin.typed_data.value = 0;
                   3611:       margin.typed_data.real = FALSE;
1.288     vatton   3612:       cssRule += 4;
1.295     vatton   3613:       cssRule = CheckImportantRule (cssRule, context);
1.164     quint    3614:     }
                   3615:   else
1.168     vatton   3616:     cssRule = ParseCSSUnit (cssRule, &margin);
1.295     vatton   3617: 
                   3618:   cssRule = CheckImportantRule (cssRule, context);
1.168     vatton   3619:   if (margin.typed_data.value != 0 &&
1.184     vatton   3620:       (margin.typed_data.unit == UNIT_INVALID ||
                   3621:        margin.typed_data.unit == UNIT_BOX))
1.169     vatton   3622:     CSSParseError ("Invalid margin-left value", ptr, cssRule);
1.295     vatton   3623:   else if (DoApply && margin.typed_data.unit != UNIT_INVALID && DoApply)
1.327     vatton   3624:     TtaSetStylePresentation (PRMarginLeft, element, tsch, context, margin);
1.1       cvs      3625:   return (cssRule);
                   3626: }
                   3627: 
                   3628: /*----------------------------------------------------------------------
1.296     vatton   3629:   ParseCSSMarginBottom: parse a CSS margin-bottom attribute
                   3630:   ----------------------------------------------------------------------*/
                   3631: static char *ParseCSSMarginLeft (Element element, PSchema tsch,
1.327     vatton   3632:                                  PresentationContext context,
                   3633:                                  char *cssRule, CSSInfoPtr css,
                   3634:                                  ThotBool isHTML)
1.296     vatton   3635: {
                   3636:   char *ptr = cssRule;
                   3637: 
                   3638:   cssRule = ParseACSSMarginLeft (element, tsch, context, ptr, css, isHTML);
                   3639:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid margin-left value");
                   3640:   return (cssRule);
                   3641: }
                   3642: 
                   3643: 
                   3644: /*----------------------------------------------------------------------
                   3645:   ParseACSSMarginRight: parse a CSS margin-right attribute string
1.1       cvs      3646:   ----------------------------------------------------------------------*/
1.296     vatton   3647: static char *ParseACSSMarginRight (Element element, PSchema tsch,
1.327     vatton   3648:                                    PresentationContext context,
                   3649:                                    char *cssRule, CSSInfoPtr css,
                   3650:                                    ThotBool isHTML)
1.1       cvs      3651: {
                   3652:   PresentationValue   margin;
1.168     vatton   3653:   char               *ptr;
1.1       cvs      3654:   
1.82      cvs      3655:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   3656:   ptr = cssRule;
1.1       cvs      3657:   /* first parse the attribute string */
1.164     quint    3658:   if (!strncasecmp (cssRule, "auto", 4))
                   3659:     {
1.184     vatton   3660:       margin.typed_data.unit = VALUE_AUTO;
1.164     quint    3661:       margin.typed_data.value = 0;
                   3662:       margin.typed_data.real = FALSE;
1.288     vatton   3663:       cssRule += 4;
1.295     vatton   3664:       cssRule = CheckImportantRule (cssRule, context);
1.164     quint    3665:     }
                   3666:   else
1.168     vatton   3667:     cssRule = ParseCSSUnit (cssRule, &margin);
1.295     vatton   3668: 
                   3669:   cssRule = CheckImportantRule (cssRule, context);
1.168     vatton   3670:   if (margin.typed_data.value != 0 &&
1.184     vatton   3671:       (margin.typed_data.unit == UNIT_INVALID ||
                   3672:        margin.typed_data.unit == UNIT_BOX))
1.169     vatton   3673:     CSSParseError ("Invalid margin-right value", ptr, cssRule);
1.168     vatton   3674:   else if (DoApply)
1.295     vatton   3675:     TtaSetStylePresentation (PRMarginRight, element, tsch, context, margin);
1.1       cvs      3676:   return (cssRule);
                   3677: }
                   3678: 
                   3679: /*----------------------------------------------------------------------
1.296     vatton   3680:   ParseCSSMarginRight: parse a CSS margin-right attribute string
                   3681:   ----------------------------------------------------------------------*/
                   3682: static char *ParseCSSMarginRight (Element element, PSchema tsch,
1.327     vatton   3683:                                   PresentationContext context,
                   3684:                                   char *cssRule, CSSInfoPtr css,
                   3685:                                   ThotBool isHTML)
1.296     vatton   3686: {
                   3687:   char *ptr = cssRule;
                   3688: 
1.297     vatton   3689:   cssRule = ParseACSSMarginRight (element, tsch, context, ptr, css, isHTML);
1.296     vatton   3690:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid margin-right value");
                   3691:   return (cssRule);
                   3692: }
                   3693: 
                   3694: /*----------------------------------------------------------------------
1.59      cvs      3695:   ParseCSSMargin: parse a CSS margin attribute string
1.1       cvs      3696:   ----------------------------------------------------------------------*/
1.79      cvs      3697: static char *ParseCSSMargin (Element element, PSchema tsch,
1.327     vatton   3698:                              PresentationContext context,
                   3699:                              char *cssRule, CSSInfoPtr css,
                   3700:                              ThotBool isHTML)
1.1       cvs      3701: {
1.79      cvs      3702:   char *ptrT, *ptrR, *ptrB, *ptrL;
1.93      vatton   3703:   int   skippedNL;
1.1       cvs      3704: 
1.82      cvs      3705:   ptrT = SkipBlanksAndComments (cssRule);
1.1       cvs      3706:   /* First parse Margin-Top */
1.296     vatton   3707:   ptrR = ParseACSSMarginTop (element, tsch, context, ptrT, css, isHTML);
1.82      cvs      3708:   ptrR = SkipBlanksAndComments (ptrR);
1.301     vatton   3709:   if (*ptrR == ';' || *ptrR == '}' || *ptrR == EOS || *ptrR == ',')
1.1       cvs      3710:     {
1.93      vatton   3711:       skippedNL = NewLineSkipped;
1.1       cvs      3712:       cssRule = ptrR;
                   3713:       /* apply the Margin-Top to all */
1.296     vatton   3714:       ptrR = ParseACSSMarginRight (element, tsch, context, ptrT, css, isHTML);
1.93      vatton   3715:       NewLineSkipped = skippedNL;
1.296     vatton   3716:       ptrR = ParseACSSMarginBottom (element, tsch, context, ptrT, css, isHTML);
1.93      vatton   3717:       NewLineSkipped = skippedNL;
1.296     vatton   3718:       ptrR = ParseACSSMarginLeft (element, tsch, context, ptrT, css, isHTML);
1.1       cvs      3719:     }
                   3720:   else
                   3721:     {
                   3722:       /* parse Margin-Right */
1.296     vatton   3723:       ptrB = ParseACSSMarginRight (element, tsch, context, ptrR, css, isHTML);
1.82      cvs      3724:       ptrB = SkipBlanksAndComments (ptrB);
1.301     vatton   3725:       if (*ptrB == ';' || *ptrB == '}' || *ptrB == EOS || *ptrB == ',')
1.327     vatton   3726:         {
                   3727:           skippedNL = NewLineSkipped;
                   3728:           cssRule = ptrB;
                   3729:           /* apply the Margin-Top to Margin-Bottom */
                   3730:           ptrB = ParseACSSMarginBottom (element, tsch, context, ptrT, css, isHTML);
                   3731:           NewLineSkipped = skippedNL;
                   3732:           /* apply the Margin-Right to Margin-Left */
                   3733:           ptrB = ParseACSSMarginLeft (element, tsch, context, ptrR, css, isHTML);
                   3734:         }
1.1       cvs      3735:       else
1.327     vatton   3736:         {
                   3737:           /* parse Margin-Bottom */
                   3738:           ptrL = ParseACSSMarginBottom (element, tsch, context, ptrB, css, isHTML);
                   3739:           ptrL = SkipBlanksAndComments (ptrL);
                   3740:           if (*ptrL == ';' || *ptrL == '}' || *ptrL == EOS || *ptrL == ',')
                   3741:             {
                   3742:               cssRule = ptrL;
                   3743:               /* apply the Margin-Right to Margin-Left */
                   3744:               ptrL = ParseACSSMarginLeft (element, tsch, context, ptrR, css, isHTML);
                   3745:             }
                   3746:           else
                   3747:             /* parse Margin-Left */
                   3748:             cssRule = ParseACSSMarginLeft (element, tsch, context, ptrL, css, isHTML);
                   3749:           cssRule = SkipBlanksAndComments (cssRule);
                   3750:         }
1.1       cvs      3751:     }
                   3752:   return (cssRule);
                   3753: }
                   3754: 
                   3755: /*----------------------------------------------------------------------
1.327     vatton   3756:   ParseCSSPaddingTop: parse a CSS PaddingTop attribute string
1.1       cvs      3757:   ----------------------------------------------------------------------*/
1.79      cvs      3758: static char *ParseCSSPaddingTop (Element element, PSchema tsch,
1.327     vatton   3759:                                  PresentationContext context,
                   3760:                                  char *cssRule, CSSInfoPtr css,
                   3761:                                  ThotBool isHTML)
1.1       cvs      3762: {
1.43      cvs      3763:   PresentationValue   padding;
1.168     vatton   3764:   char               *ptr;
1.43      cvs      3765:   
1.82      cvs      3766:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   3767:   ptr = cssRule;
1.43      cvs      3768:   /* first parse the attribute string */
                   3769:   cssRule = ParseCSSUnit (cssRule, &padding);
1.295     vatton   3770: 
                   3771:   cssRule = CheckImportantRule (cssRule, context);
1.168     vatton   3772:   if (padding.typed_data.value != 0 &&
1.184     vatton   3773:       (padding.typed_data.unit == UNIT_INVALID ||
                   3774:        padding.typed_data.unit == UNIT_BOX))
1.168     vatton   3775:     {
1.169     vatton   3776:       CSSParseError ("Invalid padding-top value", ptr, cssRule);
1.168     vatton   3777:       padding.typed_data.value = 0;
                   3778:     }
                   3779:   else if (DoApply)
1.295     vatton   3780:     TtaSetStylePresentation (PRPaddingTop, element, tsch, context, padding);
1.1       cvs      3781:   return (cssRule);
                   3782: }
                   3783: 
                   3784: /*----------------------------------------------------------------------
1.59      cvs      3785:   ParseCSSPaddingBottom: parse a CSS PaddingBottom attribute string
1.1       cvs      3786:   ----------------------------------------------------------------------*/
1.79      cvs      3787: static char *ParseCSSPaddingBottom (Element element, PSchema tsch,
1.327     vatton   3788:                                     PresentationContext context,
                   3789:                                     char *cssRule, CSSInfoPtr css,
                   3790:                                     ThotBool isHTML)
1.1       cvs      3791: {
1.43      cvs      3792:   PresentationValue   padding;
1.168     vatton   3793:   char               *ptr;
1.43      cvs      3794:   
1.82      cvs      3795:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   3796:   ptr = cssRule;
1.43      cvs      3797:   /* first parse the attribute string */
                   3798:   cssRule = ParseCSSUnit (cssRule, &padding);
1.168     vatton   3799:   if (padding.typed_data.value == 0)
1.184     vatton   3800:     padding.typed_data.unit = UNIT_EM;
1.295     vatton   3801: 
                   3802:   cssRule = CheckImportantRule (cssRule, context);
1.168     vatton   3803:   if (padding.typed_data.value != 0 &&
1.184     vatton   3804:       (padding.typed_data.unit == UNIT_INVALID ||
                   3805:        padding.typed_data.unit == UNIT_BOX))
1.168     vatton   3806:     {
1.169     vatton   3807:       CSSParseError ("Invalid padding-bottom value", ptr, cssRule);
1.168     vatton   3808:       padding.typed_data.value = 0;
                   3809:     }
                   3810:   else if (DoApply)
1.295     vatton   3811:     TtaSetStylePresentation (PRPaddingBottom, element, tsch, context, padding);
1.1       cvs      3812:   return (cssRule);
                   3813: }
                   3814: 
                   3815: /*----------------------------------------------------------------------
1.59      cvs      3816:   ParseCSSPaddingLeft: parse a CSS PaddingLeft attribute string.
1.1       cvs      3817:   ----------------------------------------------------------------------*/
1.79      cvs      3818: static char *ParseCSSPaddingLeft (Element element, PSchema tsch,
1.327     vatton   3819:                                   PresentationContext context,
                   3820:                                   char *cssRule, CSSInfoPtr css,
                   3821:                                   ThotBool isHTML)
1.1       cvs      3822: {
1.43      cvs      3823:   PresentationValue   padding;
1.168     vatton   3824:   char               *ptr;
1.43      cvs      3825:   
1.82      cvs      3826:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   3827:   ptr = cssRule;
1.43      cvs      3828:   /* first parse the attribute string */
                   3829:   cssRule = ParseCSSUnit (cssRule, &padding);
1.168     vatton   3830:   if (padding.typed_data.value == 0)
1.184     vatton   3831:     padding.typed_data.unit = UNIT_EM;
1.295     vatton   3832: 
                   3833:   cssRule = CheckImportantRule (cssRule, context);
1.168     vatton   3834:   if (padding.typed_data.value != 0 &&
1.184     vatton   3835:       (padding.typed_data.unit == UNIT_INVALID ||
                   3836:        padding.typed_data.unit == UNIT_BOX))
1.168     vatton   3837:     {
1.169     vatton   3838:       CSSParseError ("Invalid padding-left value", ptr, cssRule);
1.168     vatton   3839:       padding.typed_data.value = 0;
                   3840:     }
                   3841:   else if (DoApply)
1.295     vatton   3842:     TtaSetStylePresentation (PRPaddingLeft, element, tsch, context, padding);
1.1       cvs      3843:   return (cssRule);
                   3844: }
                   3845: 
                   3846: /*----------------------------------------------------------------------
1.59      cvs      3847:   ParseCSSPaddingRight: parse a CSS PaddingRight attribute string.
1.1       cvs      3848:   ----------------------------------------------------------------------*/
1.79      cvs      3849: static char *ParseCSSPaddingRight (Element element, PSchema tsch,
1.327     vatton   3850:                                    PresentationContext context,
                   3851:                                    char *cssRule, CSSInfoPtr css,
                   3852:                                    ThotBool isHTML)
1.1       cvs      3853: {
1.43      cvs      3854:   PresentationValue   padding;
1.168     vatton   3855:   char               *ptr;
1.43      cvs      3856:   
1.82      cvs      3857:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   3858:   ptr = cssRule;
1.43      cvs      3859:   /* first parse the attribute string */
                   3860:   cssRule = ParseCSSUnit (cssRule, &padding);
1.168     vatton   3861:   if (padding.typed_data.value == 0)
1.184     vatton   3862:     padding.typed_data.unit = UNIT_EM;
1.295     vatton   3863: 
                   3864:   cssRule = CheckImportantRule (cssRule, context);
1.168     vatton   3865:   if (padding.typed_data.value != 0 &&
1.184     vatton   3866:       (padding.typed_data.unit == UNIT_INVALID ||
                   3867:        padding.typed_data.unit == UNIT_BOX))
1.168     vatton   3868:     {
1.169     vatton   3869:       CSSParseError ("Invalid padding-right value", ptr, cssRule);
1.168     vatton   3870:       padding.typed_data.value = 0;
                   3871:     }
                   3872:   else if (DoApply)
1.295     vatton   3873:     TtaSetStylePresentation (PRPaddingRight, element, tsch, context, padding);
1.1       cvs      3874:   return (cssRule);
                   3875: }
                   3876: 
                   3877: /*----------------------------------------------------------------------
1.327     vatton   3878:   ParseCSSPadding: parse a CSS padding attribute string. 
1.1       cvs      3879:   ----------------------------------------------------------------------*/
1.79      cvs      3880: static char *ParseCSSPadding (Element element, PSchema tsch,
1.327     vatton   3881:                               PresentationContext context,
                   3882:                               char *cssRule, CSSInfoPtr css,
                   3883:                               ThotBool isHTML)
1.1       cvs      3884: {
1.79      cvs      3885:   char *ptrT, *ptrR, *ptrB, *ptrL;
1.93      vatton   3886:   int   skippedNL;
1.43      cvs      3887: 
1.82      cvs      3888:   ptrT = SkipBlanksAndComments (cssRule);
1.43      cvs      3889:   /* First parse Padding-Top */
                   3890:   ptrR = ParseCSSPaddingTop (element, tsch, context, ptrT, css, isHTML);
1.82      cvs      3891:   ptrR = SkipBlanksAndComments (ptrR);
                   3892:   if (*ptrR == ';' || *ptrR == EOS || *ptrR == ',')
1.43      cvs      3893:     {
1.93      vatton   3894:       skippedNL = NewLineSkipped;
1.43      cvs      3895:       cssRule = ptrR;
                   3896:       /* apply the Padding-Top to all */
                   3897:       ptrR = ParseCSSPaddingRight (element, tsch, context, ptrT, css, isHTML);
1.93      vatton   3898:       NewLineSkipped = skippedNL;
1.43      cvs      3899:       ptrR = ParseCSSPaddingBottom (element, tsch, context, ptrT, css, isHTML);
1.93      vatton   3900:       NewLineSkipped = skippedNL;
1.43      cvs      3901:       ptrR = ParseCSSPaddingLeft (element, tsch, context, ptrT, css, isHTML);
                   3902:     }
                   3903:   else
                   3904:     {
                   3905:       /* parse Padding-Right */
                   3906:       ptrB = ParseCSSPaddingRight (element, tsch, context, ptrR, css, isHTML);
1.82      cvs      3907:       ptrB = SkipBlanksAndComments (ptrB);
                   3908:       if (*ptrB == ';' || *ptrB == EOS || *ptrB == ',')
1.327     vatton   3909:         {
                   3910:           skippedNL = NewLineSkipped;
                   3911:           cssRule = ptrB;
                   3912:           /* apply the Padding-Top to Padding-Bottom */
                   3913:           ptrB = ParseCSSPaddingBottom (element, tsch, context, ptrT, css, isHTML);
                   3914:           NewLineSkipped = skippedNL;
                   3915:           /* apply the Padding-Right to Padding-Left */
                   3916:           ptrB = ParseCSSPaddingLeft (element, tsch, context, ptrR, css, isHTML);
                   3917:         }
1.43      cvs      3918:       else
1.327     vatton   3919:         {
                   3920:           /* parse Padding-Bottom */
                   3921:           ptrL = ParseCSSPaddingBottom (element, tsch, context, ptrB, css, isHTML);
                   3922:           ptrL = SkipBlanksAndComments (ptrL);
                   3923:           if (*ptrL == ';' || *ptrL == EOS || *ptrL == ',')
                   3924:             {
                   3925:               cssRule = ptrL;
                   3926:               /* apply the Padding-Right to Padding-Left */
                   3927:               ptrL = ParseCSSPaddingLeft (element, tsch, context, ptrR, css, isHTML);
                   3928:             }
                   3929:           else
                   3930:             /* parse Padding-Left */
                   3931:             cssRule = ParseCSSPaddingLeft (element, tsch, context, ptrL, css, isHTML);
                   3932:           cssRule = SkipBlanksAndComments (cssRule);
                   3933:         }
1.43      cvs      3934:     }
1.1       cvs      3935:   return (cssRule);
                   3936: }
                   3937: 
                   3938: /*----------------------------------------------------------------------
1.327     vatton   3939:   ParseCSSForeground: parse a CSS foreground attribute 
1.1       cvs      3940:   ----------------------------------------------------------------------*/
1.79      cvs      3941: static char *ParseCSSForeground (Element element, PSchema tsch,
1.327     vatton   3942:                                  PresentationContext context,
                   3943:                                  char *cssRule,
                   3944:                                  CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      3945: {
1.117     vatton   3946:   PresentationValue   best;
1.262     vatton   3947:   char               *p;
1.1       cvs      3948: 
1.262     vatton   3949:   p = cssRule;
1.117     vatton   3950:   cssRule = ParseCSSColor (cssRule, &best);
1.295     vatton   3951:   cssRule = CheckImportantRule (cssRule, context);
1.184     vatton   3952:   if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.327     vatton   3953:     {
                   3954:       if (*cssRule != EOS && *cssRule !=';')
                   3955:         {
                   3956:           cssRule = SkipProperty (cssRule, FALSE);
                   3957:           CSSParseError ("Invalid value", p, cssRule);
                   3958:         }
                   3959:       else
                   3960:         /* install the new presentation */
                   3961:         TtaSetStylePresentation (PRForeground, element, tsch, context, best);
                   3962:     }
                   3963:   return (cssRule);
1.1       cvs      3964: }
                   3965: 
                   3966: /*----------------------------------------------------------------------
1.59      cvs      3967:   ParseCSSBackgroundColor: parse a CSS background color attribute 
1.1       cvs      3968:   ----------------------------------------------------------------------*/
1.79      cvs      3969: static char *ParseCSSBackgroundColor (Element element, PSchema tsch,
1.327     vatton   3970:                                       PresentationContext context,
                   3971:                                       char *cssRule,
                   3972:                                       CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      3973: {
                   3974:   PresentationValue     best;
                   3975: 
1.184     vatton   3976:   best.typed_data.unit = UNIT_INVALID;
1.1       cvs      3977:   best.typed_data.real = FALSE;
1.198     vatton   3978:   if (!strncasecmp (cssRule, "transparent", 11))
1.1       cvs      3979:     {
1.184     vatton   3980:       best.typed_data.value = PATTERN_NONE;
                   3981:       best.typed_data.unit = UNIT_REL;
1.295     vatton   3982:       cssRule = SkipWord (cssRule);
                   3983:       cssRule = CheckImportantRule (cssRule, context);
1.116     vatton   3984:       if (DoApply)
1.327     vatton   3985:         TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
                   3986:     }
1.1       cvs      3987:   else
                   3988:     {
                   3989:       cssRule = ParseCSSColor (cssRule, &best);
1.295     vatton   3990:       cssRule = CheckImportantRule (cssRule, context);
1.184     vatton   3991:       if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.327     vatton   3992:         {
                   3993:           /* install the new presentation. */
                   3994:           TtaSetStylePresentation (PRBackground, element, tsch, context, best);
                   3995:           /* thot specificity: need to set fill pattern for background color */
                   3996:           best.typed_data.value = PATTERN_BACKGROUND;
                   3997:           best.typed_data.unit = UNIT_REL;
                   3998:           TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
                   3999:           best.typed_data.value = 1;
                   4000:           best.typed_data.unit = UNIT_REL;
                   4001:           TtaSetStylePresentation (PRShowBox, element, tsch, context, best);
                   4002:         }
1.1       cvs      4003:     }
                   4004:   return (cssRule);
                   4005: }
                   4006: 
1.63      cvs      4007: /*----------------------------------------------------------------------
1.65      cvs      4008:   ParseSVGStroke: parse a SVG stroke property
                   4009:   ----------------------------------------------------------------------*/
1.79      cvs      4010: static char *ParseSVGStroke (Element element, PSchema tsch,
1.327     vatton   4011:                              PresentationContext context, char *cssRule,
                   4012:                              CSSInfoPtr css, ThotBool isHTML)
1.65      cvs      4013: {
                   4014:   PresentationValue     best;
1.245     quint    4015:   char                  *url;
1.65      cvs      4016: 
1.184     vatton   4017:   best.typed_data.unit = UNIT_INVALID;
1.65      cvs      4018:   best.typed_data.real = FALSE;
1.82      cvs      4019:   if (!strncasecmp (cssRule, "none", 4))
1.65      cvs      4020:     {
                   4021:       best.typed_data.value = -2;  /* -2 means transparent */
1.184     vatton   4022:       best.typed_data.unit = UNIT_REL;
1.65      cvs      4023:       cssRule = SkipWord (cssRule);
                   4024:     }
1.245     quint    4025:   else if (!strncasecmp (cssRule, "currentColor", 12))
                   4026:     {
1.293     quint    4027:       best.typed_data.unit = VALUE_INHERIT;
                   4028:       cssRule = SkipWord (cssRule);
1.245     quint    4029:     }
                   4030:   else if (!strncasecmp (cssRule, "url", 3))
                   4031:     {  
                   4032:       cssRule += 3;
                   4033:       cssRule = ParseCSSUrl (cssRule, &url);
                   4034:       /* **** do something with the url ***** */;
                   4035:       TtaFreeMemory (url);
                   4036:       /* **** caution: another color value may follow the uri (in case
1.327     vatton   4037:          the uri could ne be dereferenced) *** */
1.245     quint    4038:     }
1.65      cvs      4039:   else
1.293     quint    4040:     cssRule = ParseCSSColor (cssRule, &best);
                   4041: 
1.295     vatton   4042:   cssRule = CheckImportantRule (cssRule, context);
1.293     quint    4043:   if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.295     vatton   4044:     /* install the new presentation */
                   4045:     TtaSetStylePresentation (PRForeground, element, tsch, context, best);
1.65      cvs      4046:   return (cssRule);
                   4047: }
                   4048: 
                   4049: /*----------------------------------------------------------------------
1.63      cvs      4050:   ParseSVGFill: parse a SVG fill property
                   4051:   ----------------------------------------------------------------------*/
1.79      cvs      4052: static char *ParseSVGFill (Element element, PSchema tsch,
1.327     vatton   4053:                            PresentationContext context, char *cssRule,
                   4054:                            CSSInfoPtr css, ThotBool isHTML)
1.63      cvs      4055: {
                   4056:   PresentationValue     best;
1.245     quint    4057:   char                  *url;
1.63      cvs      4058: 
1.184     vatton   4059:   best.typed_data.unit = UNIT_INVALID;
1.63      cvs      4060:   best.typed_data.real = FALSE;
1.82      cvs      4061:   if (!strncasecmp (cssRule, "none", 4))
1.63      cvs      4062:     {
1.184     vatton   4063:       best.typed_data.value = PATTERN_NONE;
                   4064:       best.typed_data.unit = UNIT_REL;
1.295     vatton   4065:       cssRule = CheckImportantRule (cssRule, context);
1.116     vatton   4066:       if (DoApply)
1.327     vatton   4067:         TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
1.65      cvs      4068:       cssRule = SkipWord (cssRule);
1.294     vatton   4069:       return (cssRule);
1.63      cvs      4070:     }
1.245     quint    4071:   else if (!strncasecmp (cssRule, "currentColor", 12))
                   4072:     {
1.293     quint    4073:       best.typed_data.unit = VALUE_INHERIT;
                   4074:       cssRule = SkipWord (cssRule);
1.245     quint    4075:     }
                   4076:   else if (!strncasecmp (cssRule, "url", 3))
                   4077:     {  
                   4078:       cssRule += 3;
                   4079:       cssRule = ParseCSSUrl (cssRule, &url);
                   4080:       /* **** do something with the url ***** */;
                   4081:       TtaFreeMemory (url);
                   4082:       /* **** caution: another color value may follow the uri (in case
1.327     vatton   4083:          the uri could ne be dereferenced) *** */
1.245     quint    4084:     }
1.63      cvs      4085:   else
1.327     vatton   4086:     cssRule = ParseCSSColor (cssRule, &best);
1.293     quint    4087: 
1.295     vatton   4088:   cssRule = CheckImportantRule (cssRule, context);
1.293     quint    4089:   if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.63      cvs      4090:     {
1.293     quint    4091:       /* install the new presentation. */
                   4092:       TtaSetStylePresentation (PRBackground, element, tsch, context, best);
                   4093:       /* thot specificity: need to set fill pattern for background color */
                   4094:       best.typed_data.value = PATTERN_BACKGROUND;
                   4095:       best.typed_data.unit = UNIT_REL;
                   4096:       TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
1.63      cvs      4097:     }
                   4098:   return (cssRule);
                   4099: }
1.161     quint    4100: 
1.155     cheyroul 4101: /*----------------------------------------------------------------------
                   4102:   ParseSVGOpacity: parse a SVG fill property
                   4103:   ----------------------------------------------------------------------*/
                   4104: static char *ParseSVGOpacity (Element element, PSchema tsch,
1.327     vatton   4105:                               PresentationContext context, char *cssRule,
                   4106:                               CSSInfoPtr css, ThotBool isHTML)
1.155     cheyroul 4107: {
                   4108:   PresentationValue     best;
1.63      cvs      4109: 
1.184     vatton   4110:   best.typed_data.unit = UNIT_INVALID;
1.155     cheyroul 4111:   best.typed_data.real = FALSE;
                   4112:   cssRule = ParseClampedUnit (cssRule, &best);
1.295     vatton   4113:   cssRule = CheckImportantRule (cssRule, context);
1.155     cheyroul 4114:   if (DoApply)
1.295     vatton   4115:     /* install the new presentation. */
                   4116:     TtaSetStylePresentation (PROpacity, element, tsch, context, best);
1.155     cheyroul 4117:   return (cssRule);
                   4118: }
1.170     cheyroul 4119: /*----------------------------------------------------------------------
                   4120:   ParseSVGOpacity: parse a SVG fill property
                   4121:   ----------------------------------------------------------------------*/
                   4122: static char *ParseSVGStrokeOpacity (Element element, PSchema tsch,
1.327     vatton   4123:                                     PresentationContext context, char *cssRule,
                   4124:                                     CSSInfoPtr css, ThotBool isHTML)
1.170     cheyroul 4125: {
                   4126:   PresentationValue     best;
1.161     quint    4127: 
1.184     vatton   4128:   best.typed_data.unit = UNIT_INVALID;
1.170     cheyroul 4129:   best.typed_data.real = FALSE;
                   4130:   cssRule = ParseClampedUnit (cssRule, &best);
1.295     vatton   4131:   cssRule = CheckImportantRule (cssRule, context);
1.170     cheyroul 4132:   if (DoApply)
1.295     vatton   4133:     /* install the new presentation. */
                   4134:     TtaSetStylePresentation (PRStrokeOpacity, element, tsch, context, best);
1.170     cheyroul 4135:   return (cssRule);
                   4136: }
                   4137: /*----------------------------------------------------------------------
                   4138:   ParseSVGOpacity: parse a SVG fill property
                   4139:   ----------------------------------------------------------------------*/
                   4140: static char *ParseSVGFillOpacity (Element element, PSchema tsch,
1.327     vatton   4141:                                   PresentationContext context, char *cssRule,
                   4142:                                   CSSInfoPtr css, ThotBool isHTML)
1.170     cheyroul 4143: {
                   4144:   PresentationValue     best;
                   4145: 
1.184     vatton   4146:   best.typed_data.unit = UNIT_INVALID;
1.170     cheyroul 4147:   best.typed_data.real = FALSE;
                   4148:   cssRule = ParseClampedUnit (cssRule, &best);
1.295     vatton   4149:   cssRule = CheckImportantRule (cssRule, context);
1.170     cheyroul 4150:   if (DoApply)
1.295     vatton   4151:     /* install the new presentation. */
                   4152:     TtaSetStylePresentation (PRFillOpacity, element, tsch, context, best);
1.170     cheyroul 4153:   return (cssRule);
                   4154: }
1.207     vatton   4155: 
1.1       cvs      4156: /*----------------------------------------------------------------------
1.327     vatton   4157:   GetCSSBackgroundURL searches a CSS BackgroundImage url within
                   4158:   the cssRule.
                   4159:   Returns NULL or a new allocated url string.
1.217     vatton   4160:   ----------------------------------------------------------------------*/
                   4161: char *GetCSSBackgroundURL (char *cssRule)
                   4162: {
                   4163:   char            *b, *url;
                   4164: 
                   4165:   url = NULL;
                   4166:   b = strstr (cssRule, "url");
                   4167:   if (b)
1.290     gully    4168:     b = ParseCSSUrl (b, &url);
1.217     vatton   4169:   return (url);
                   4170: }
                   4171: 
                   4172: /*----------------------------------------------------------------------
1.327     vatton   4173:   ParseCSSContent: parse the value of property "content"
1.217     vatton   4174:   ----------------------------------------------------------------------*/
                   4175: static char *ParseCSSContent (Element element, PSchema tsch,
1.327     vatton   4176:                               PresentationContext ctxt, char *cssRule,
                   4177:                               CSSInfoPtr css, ThotBool isHTML)
1.217     vatton   4178: {
1.312     quint    4179:   PresentationValue   value;
                   4180:   char                *p, quoteChar;
                   4181:   ThotBool            repeat;
                   4182: 
                   4183:   value.typed_data.unit = UNIT_REL;
                   4184:   value.typed_data.real = FALSE;
                   4185:   value.typed_data.value = 0;
                   4186:   TtaSetStylePresentation (PRContent, element, tsch, ctxt, value);
1.217     vatton   4187:   cssRule = SkipBlanksAndComments (cssRule);
1.312     quint    4188:   repeat = TRUE;
                   4189:   while (repeat)
                   4190:     {
                   4191:       p = cssRule;
                   4192:       if (!strncasecmp (cssRule, "normal", 6))
1.327     vatton   4193:         /* The pseudo-element is not generated */
                   4194:         {
                   4195:           /* @@@@@@ */
                   4196:           cssRule += 6;
                   4197:           repeat = FALSE;
                   4198:         }
1.312     quint    4199:       else if (*cssRule == '"' || *cssRule == '\'')
1.327     vatton   4200:         /* It's a string */
                   4201:         {
                   4202:           quoteChar = *cssRule;
                   4203:           cssRule++;
                   4204:           p = cssRule;
                   4205:           /**** escape characters are not handled.
                   4206:                 See function SkipQuotedString ******/
                   4207:           while (*cssRule != EOS && *cssRule != quoteChar)
                   4208:             cssRule++;
                   4209:           if (*cssRule != quoteChar)
                   4210:             cssRule = SkipProperty (cssRule, FALSE);
                   4211:           else
                   4212:             {
                   4213:               *cssRule = EOS;
                   4214:               value.typed_data.unit = UNIT_REL;
                   4215:               value.typed_data.real = FALSE;
                   4216:               value.pointer = p;
                   4217:               TtaSetStylePresentation (PRContentString, element, tsch, ctxt,
                   4218:                                        value);
                   4219:               *cssRule = quoteChar;
                   4220:               cssRule++;
                   4221:             }
                   4222:         }
1.312     quint    4223:       else if (!strncasecmp (cssRule, "url", 3))
1.327     vatton   4224:         {  
                   4225:           cssRule += 3;
                   4226:           cssRule = SetCSSImage (element, tsch, ctxt, cssRule, css, PRContentURL);
                   4227:         }
1.312     quint    4228:       else if (!strncasecmp (cssRule, "counter", 7))
1.327     vatton   4229:         {
                   4230:           cssRule += 7;
                   4231:           /* @@@@@@ */
                   4232:           cssRule = SkipProperty (cssRule, FALSE);
                   4233:         }
1.312     quint    4234:       else if (!strncasecmp (cssRule, "counters", 8))
1.327     vatton   4235:         {
                   4236:           cssRule += 8;
                   4237:           /* @@@@@@ */
                   4238:           cssRule = SkipProperty (cssRule, FALSE);
                   4239:         }
1.312     quint    4240:       else if (!strncasecmp (cssRule, "attr", 4))
1.327     vatton   4241:         {
                   4242:           cssRule += 4;
                   4243:           /* @@@@@@ */
                   4244:           cssRule = SkipProperty (cssRule, FALSE);
                   4245:         }
1.312     quint    4246:       else if (!strncasecmp (cssRule, "open-quote", 10))
1.327     vatton   4247:         {
                   4248:           cssRule += 10;
                   4249:           /* @@@@@@ */
                   4250:         }
1.312     quint    4251:       else if (!strncasecmp (cssRule, "close-quote", 11))
1.327     vatton   4252:         {
                   4253:           cssRule += 11;
                   4254:           /* @@@@@@ */
                   4255:         }
1.312     quint    4256:       else if (!strncasecmp (cssRule, "no-open-quote", 13))
1.327     vatton   4257:         {
                   4258:           cssRule += 13;
                   4259:           /* @@@@@@ */
                   4260:         }
1.312     quint    4261:       else if (!strncasecmp (cssRule, "no-close-quote", 14))
1.327     vatton   4262:         {
                   4263:           cssRule += 14;
                   4264:           /* @@@@@@ */
                   4265:         }
1.312     quint    4266:       else if (!strncasecmp (cssRule, "inherit", 7))
1.327     vatton   4267:         {
                   4268:           cssRule += 7;
                   4269:           /* @@@@@@ */
                   4270:           repeat = FALSE;
                   4271:         }
1.312     quint    4272:       else
1.327     vatton   4273:         {
                   4274:           CSSParseError ("Invalid content value", p, cssRule);
                   4275:           cssRule = SkipProperty (cssRule, FALSE);
                   4276:         }
1.312     quint    4277:       cssRule = SkipBlanksAndComments (cssRule);
                   4278:       if (repeat)
1.327     vatton   4279:         if (*cssRule == ';' || *cssRule == '}' || *cssRule == EOS ||
                   4280:             *cssRule == '!')
                   4281:           repeat = FALSE;
1.217     vatton   4282:     }
1.312     quint    4283:   cssRule = CheckImportantRule (cssRule, ctxt);
1.217     vatton   4284:   return (cssRule);
                   4285: }
1.1       cvs      4286: 
                   4287: /*----------------------------------------------------------------------
1.59      cvs      4288:   ParseCSSBackgroundImage: parse a CSS BackgroundImage attribute string.
1.1       cvs      4289:   ----------------------------------------------------------------------*/
1.79      cvs      4290: static char *ParseCSSBackgroundImage (Element element, PSchema tsch,
1.327     vatton   4291:                                       PresentationContext ctxt,
                   4292:                                       char *cssRule, CSSInfoPtr css,
                   4293:                                       ThotBool isHTML)
1.1       cvs      4294: {
1.49      cvs      4295:   PresentationValue          image, value;
1.148     vatton   4296: 
1.82      cvs      4297:   cssRule = SkipBlanksAndComments (cssRule);
1.161     quint    4298:   if (!strncasecmp (cssRule, "none", 4))
                   4299:     {
1.260     vatton   4300:       cssRule += 4;
1.276     vatton   4301:       cssRule = CheckImportantRule (cssRule, ctxt);
1.247     quint    4302:       if (DoApply)
1.327     vatton   4303:         {
                   4304:           /* no background image */
                   4305:           image.pointer = NULL;
                   4306:           TtaSetStylePresentation (PRBackgroundPicture, element, tsch, ctxt,
                   4307:                                    image);
                   4308:         }
1.161     quint    4309:     }
                   4310:   else if (!strncasecmp (cssRule, "url", 3))
1.1       cvs      4311:     {  
                   4312:       cssRule += 3;
1.302     quint    4313:       cssRule = SetCSSImage (element, tsch, ctxt, cssRule, css,
1.327     vatton   4314:                              PRBackgroundPicture);
1.207     vatton   4315:       if (ctxt->destroy)
1.327     vatton   4316:         if (TtaGetStylePresentation (PRFillPattern, element, tsch, ctxt,
                   4317:                                      &value) < 0)
                   4318:           {
                   4319:             /* there is no FillPattern rule -> remove ShowBox rule */
                   4320:             value.typed_data.value = 1;
                   4321:             value.typed_data.unit = UNIT_REL;
                   4322:             value.typed_data.real = FALSE;
                   4323:             TtaSetStylePresentation (PRShowBox, element, tsch, ctxt, value);
                   4324:           }
1.18      cvs      4325:     }
                   4326:   return (cssRule);
                   4327: }
                   4328: 
                   4329: /*----------------------------------------------------------------------
1.295     vatton   4330:   ParseACSSBackgroundRepeat: parse a CSS BackgroundRepeat attribute string.
1.18      cvs      4331:   ----------------------------------------------------------------------*/
1.295     vatton   4332: static char *ParseACSSBackgroundRepeat (Element element, PSchema tsch,
1.327     vatton   4333:                                         PresentationContext ctxt,
                   4334:                                         char *cssRule, CSSInfoPtr css, ThotBool isHTML)
1.18      cvs      4335: {
                   4336:   PresentationValue   repeat;
                   4337: 
1.184     vatton   4338:   repeat.typed_data.value = REALSIZE;
1.191     vatton   4339:   repeat.typed_data.unit = UNIT_BOX;
1.18      cvs      4340:   repeat.typed_data.real = FALSE;
1.82      cvs      4341:   cssRule = SkipBlanksAndComments (cssRule);
                   4342:   if (!strncasecmp (cssRule, "no-repeat", 9))
1.184     vatton   4343:     repeat.typed_data.value = REALSIZE;
1.82      cvs      4344:   else if (!strncasecmp (cssRule, "repeat-y", 8))
1.265     vatton   4345:     repeat.typed_data.value = YREPEAT;
1.82      cvs      4346:   else if (!strncasecmp (cssRule, "repeat-x", 8))
1.265     vatton   4347:     repeat.typed_data.value = XREPEAT;
1.82      cvs      4348:   else if (!strncasecmp (cssRule, "repeat", 6))
1.184     vatton   4349:     repeat.typed_data.value = REPEAT;
1.18      cvs      4350:   else
                   4351:     return (cssRule);
                   4352: 
1.295     vatton   4353:   cssRule = SkipWord (cssRule);
                   4354:   /* check if it's an important rule */
                   4355:   cssRule = CheckImportantRule (cssRule, ctxt);
1.116     vatton   4356:   if (DoApply)
1.295     vatton   4357:     /* install the new presentation */
                   4358:     TtaSetStylePresentation (PRPictureMode, element, tsch, ctxt, repeat);
                   4359:   return (cssRule);
                   4360: }
                   4361: 
                   4362: /*----------------------------------------------------------------------
                   4363:   ParseCSSBackgroundRepeat: parse a CSS BackgroundRepeat attribute string.
                   4364:   ----------------------------------------------------------------------*/
                   4365: static char *ParseCSSBackgroundRepeat (Element element, PSchema tsch,
1.315     gully    4366:                                        PresentationContext ctxt,
                   4367:                                        char *cssRule, CSSInfoPtr css,
                   4368:                                        ThotBool isHTML)
1.295     vatton   4369: {
                   4370:   cssRule = ParseACSSBackgroundRepeat (element, tsch, ctxt,
1.315     gully    4371:                                        cssRule, css, isHTML);
                   4372:   if (cssRule)
1.117     vatton   4373:     {
1.295     vatton   4374:       cssRule = SkipValue ("Invalid background-repeat value", cssRule);
1.117     vatton   4375:       /* check if it's an important rule */
1.276     vatton   4376:       cssRule = CheckImportantRule (cssRule, ctxt);
1.117     vatton   4377:     }
1.295     vatton   4378:   return cssRule;
1.18      cvs      4379: }
                   4380: 
                   4381: /*----------------------------------------------------------------------
1.327     vatton   4382:   ParseACSSBackgroundAttachment: parse a CSS BackgroundAttachment
                   4383:   attribute string.                                          
1.18      cvs      4384:   ----------------------------------------------------------------------*/
1.295     vatton   4385: static char *ParseACSSBackgroundAttachment (Element element, PSchema tsch,
1.327     vatton   4386:                                             PresentationContext ctxt,
                   4387:                                             char *cssRule, CSSInfoPtr css,
                   4388:                                             ThotBool isHTML)
1.18      cvs      4389: {
1.163     quint    4390:   cssRule = SkipBlanksAndComments (cssRule);
                   4391:   if (!strncasecmp (cssRule, "scroll", 6))
1.199     vatton   4392:     {
                   4393:       cssRule = SkipWord (cssRule);
                   4394:     }
1.163     quint    4395:   else if (!strncasecmp (cssRule, "fixed", 5))
1.199     vatton   4396:     {
                   4397:       cssRule = SkipWord (cssRule);
                   4398:     }
1.163     quint    4399:   return (cssRule);
1.1       cvs      4400: }
                   4401: 
                   4402: /*----------------------------------------------------------------------
1.327     vatton   4403:   ParseCSSBackgroundAttachment: parse a CSS BackgroundAttachment
                   4404:   attribute string.                                          
1.295     vatton   4405:   ----------------------------------------------------------------------*/
                   4406: static char *ParseCSSBackgroundAttachment (Element element, PSchema tsch,
1.327     vatton   4407:                                            PresentationContext ctxt,
                   4408:                                            char *cssRule, CSSInfoPtr css,
                   4409:                                            ThotBool isHTML)
1.295     vatton   4410: {
                   4411:   char     *ptr;
                   4412: 
                   4413:   ptr = cssRule;
                   4414:   cssRule = ParseACSSBackgroundAttachment (element, tsch, ctxt,
1.327     vatton   4415:                                            cssRule, css, isHTML);
1.295     vatton   4416:   if (ptr == cssRule)
                   4417:     {
                   4418:       cssRule = SkipValue ("Invalid background-attachement value", cssRule);
                   4419:       /* check if it's an important rule */
                   4420:       cssRule = CheckImportantRule (cssRule, ctxt);
                   4421:     }
                   4422:   return cssRule;
                   4423: }
                   4424: 
                   4425: /*----------------------------------------------------------------------
1.327     vatton   4426:   ParseACSSBackgroundPosition: parse a CSS BackgroundPosition
                   4427:   attribute string.                                          
1.1       cvs      4428:   ----------------------------------------------------------------------*/
1.279     vatton   4429: static char *ParseACSSBackgroundPosition (Element element, PSchema tsch,
1.327     vatton   4430:                                           PresentationContext ctxt,
                   4431:                                           char *cssRule, CSSInfoPtr css,
                   4432:                                           ThotBool isHTML)
1.1       cvs      4433: {
1.18      cvs      4434:   PresentationValue     repeat;
1.200     vatton   4435:   char                 *ptr;
1.18      cvs      4436:   ThotBool              ok;
1.1       cvs      4437: 
1.163     quint    4438:   cssRule = SkipBlanksAndComments (cssRule);
                   4439:   ok = TRUE;
                   4440:   if (!strncasecmp (cssRule, "left", 4))
                   4441:     cssRule = SkipWord (cssRule);
                   4442:   else if (!strncasecmp (cssRule, "right", 5))
                   4443:     cssRule = SkipWord (cssRule);
                   4444:   else if (!strncasecmp (cssRule, "center", 6))
                   4445:     cssRule = SkipWord (cssRule);
                   4446:   else if (!strncasecmp (cssRule, "top", 3))
                   4447:     cssRule = SkipWord (cssRule);
                   4448:   else if (!strncasecmp (cssRule, "bottom", 6))
                   4449:     cssRule = SkipWord (cssRule);
1.279     vatton   4450:   else if (isdigit (*cssRule) || *cssRule == '.' || *cssRule == '-')
1.191     vatton   4451:     {
1.206     vatton   4452:       while (*cssRule != EOS && *cssRule != SPACE &&
1.327     vatton   4453:              *cssRule != ',' && *cssRule != ';')
                   4454:         cssRule++;
1.191     vatton   4455:     }
1.163     quint    4456:   else
                   4457:     ok = FALSE;
                   4458: 
                   4459:   if (ok && DoApply)
1.148     vatton   4460:     {
1.199     vatton   4461:       /* force no-repeat for that background image */
1.200     vatton   4462:       ptr = "no-repeat";
1.295     vatton   4463:       ParseACSSBackgroundRepeat (element, tsch, ctxt, ptr, css, isHTML);
1.163     quint    4464:       /* force realsize for the background image */
1.184     vatton   4465:       repeat.typed_data.value = REALSIZE;
                   4466:       repeat.typed_data.unit = UNIT_REL;
1.163     quint    4467:       repeat.typed_data.real = FALSE;
                   4468:       /* check if it's an important rule */
1.276     vatton   4469:       cssRule = CheckImportantRule (cssRule, ctxt);
1.207     vatton   4470:       /*TtaSetStylePresentation (PRPictureMode, element, tsch, ctxt, repeat);*/
1.279     vatton   4471:     }
                   4472:   cssRule = SkipBlanksAndComments (cssRule);
                   4473:   return (cssRule);
                   4474: }
1.218     vatton   4475: 
1.279     vatton   4476: /*----------------------------------------------------------------------
1.327     vatton   4477:   ParseCSSBackgroundPosition: parse a CSS BackgroundPosition
                   4478:   attribute string.                                          
1.279     vatton   4479:   ----------------------------------------------------------------------*/
                   4480: static char *ParseCSSBackgroundPosition (Element element, PSchema tsch,
1.327     vatton   4481:                                          PresentationContext ctxt,
                   4482:                                          char *cssRule, CSSInfoPtr css,
                   4483:                                          ThotBool isHTML)
1.279     vatton   4484: {
1.295     vatton   4485:   char     *ptr;
                   4486: 
                   4487:   ptr = cssRule;
1.279     vatton   4488:   cssRule = ParseACSSBackgroundPosition (element, tsch, ctxt,
1.327     vatton   4489:                                          cssRule, css, isHTML);
1.295     vatton   4490:   if (ptr == cssRule)
1.279     vatton   4491:     cssRule = ParseACSSBackgroundPosition (element, tsch, ctxt,
1.327     vatton   4492:                                            cssRule, css, isHTML);
1.295     vatton   4493:   if (ptr == cssRule)
                   4494:     {
                   4495:       cssRule = SkipValue ("Invalid background-position value", cssRule);
                   4496:       /* check if it's an important rule */
                   4497:       cssRule = CheckImportantRule (cssRule, ctxt);
                   4498:     }
1.298     vatton   4499:   else if (*cssRule !=  ';' && *cssRule != EOS)
                   4500:     {
                   4501:       /* possible second value */
                   4502:       ptr = cssRule;
                   4503:       cssRule = ParseACSSBackgroundPosition (element, tsch, ctxt,
1.327     vatton   4504:                                              cssRule, css, isHTML);
1.298     vatton   4505:       if (ptr == cssRule)
1.327     vatton   4506:         cssRule = ParseACSSBackgroundPosition (element, tsch, ctxt,
                   4507:                                                cssRule, css, isHTML);
1.298     vatton   4508:       if (ptr == cssRule)
1.327     vatton   4509:         {
                   4510:           cssRule = SkipValue ("Invalid background-position value", cssRule);
                   4511:           /* check if it's an important rule */
                   4512:           cssRule = CheckImportantRule (cssRule, ctxt);
                   4513:         }
1.298     vatton   4514:     }
1.163     quint    4515:   return (cssRule);
1.18      cvs      4516: }
                   4517: 
                   4518: /*----------------------------------------------------------------------
1.327     vatton   4519:   ParseCSSBackground: parse a CSS background attribute 
1.18      cvs      4520:   ----------------------------------------------------------------------*/
1.79      cvs      4521: static char *ParseCSSBackground (Element element, PSchema tsch,
1.327     vatton   4522:                                  PresentationContext ctxt, char *cssRule,
                   4523:                                  CSSInfoPtr css, ThotBool isHTML)
1.18      cvs      4524: {
1.323     vatton   4525:   char           *ptr;
                   4526:   int             skippedNL;
                   4527:   ThotBool        img, repeat, position, attach, color;
1.18      cvs      4528: 
1.82      cvs      4529:   cssRule = SkipBlanksAndComments (cssRule);
1.323     vatton   4530:   img = repeat = position = attach = color = FALSE;
1.301     vatton   4531:   while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.18      cvs      4532:     {
1.71      cvs      4533:       /* perhaps a Background Image */
1.198     vatton   4534:       if (!strncasecmp (cssRule, "url", 3) || !strncasecmp (cssRule, "none", 4))
1.327     vatton   4535:         {
                   4536:           cssRule = ParseCSSBackgroundImage (element, tsch, ctxt, cssRule,
                   4537:                                              css, isHTML);
                   4538:           img = TRUE;
                   4539:         }
1.18      cvs      4540:       /* perhaps a Background Attachment */
1.82      cvs      4541:       else if (!strncasecmp (cssRule, "scroll", 6) ||
                   4542:                !strncasecmp (cssRule, "fixed", 5))
1.327     vatton   4543:         {
                   4544:           cssRule = ParseACSSBackgroundAttachment (element, tsch, ctxt,
                   4545:                                                    cssRule, css, isHTML);
1.328   ! vatton   4546:           attach = repeat = TRUE;
1.327     vatton   4547:         }
1.18      cvs      4548:       /* perhaps a Background Repeat */
1.82      cvs      4549:       else if (!strncasecmp (cssRule, "no-repeat", 9) ||
                   4550:                !strncasecmp (cssRule, "repeat-y", 8)  ||
                   4551:                !strncasecmp (cssRule, "repeat-x", 8)  ||
                   4552:                !strncasecmp (cssRule, "repeat", 6))
1.327     vatton   4553:         {
                   4554:           cssRule = ParseACSSBackgroundRepeat (element, tsch, ctxt,
                   4555:                                                cssRule, css, isHTML);
                   4556:           repeat = TRUE;
                   4557:         }
1.18      cvs      4558:       /* perhaps a Background Position */
1.82      cvs      4559:       else if (!strncasecmp (cssRule, "left", 4)   ||
                   4560:                !strncasecmp (cssRule, "right", 5)  ||
                   4561:                !strncasecmp (cssRule, "center", 6) ||
                   4562:                !strncasecmp (cssRule, "top", 3)    ||
                   4563:                !strncasecmp (cssRule, "bottom", 6) ||
1.279     vatton   4564:                isdigit (*cssRule) || *cssRule == '.' || *cssRule == '-')
1.327     vatton   4565:         {
                   4566:           cssRule = ParseACSSBackgroundPosition (element, tsch, ctxt,
                   4567:                                                  cssRule, css, isHTML);
1.328   ! vatton   4568:           position = repeat = TRUE;
1.327     vatton   4569:         }
1.18      cvs      4570:       /* perhaps a Background Color */
1.323     vatton   4571:       else if (!color)
1.327     vatton   4572:         {
                   4573:           skippedNL = NewLineSkipped;
                   4574:           /* check if the rule has been found */
                   4575:           ptr = cssRule;
                   4576:           cssRule = ParseCSSBackgroundColor (element, tsch, ctxt,
                   4577:                                              cssRule, css, isHTML);
                   4578:           if (ptr == cssRule)
                   4579:             {
                   4580:               NewLineSkipped = skippedNL;
                   4581:               /* rule not found */
                   4582:               cssRule = SkipProperty (cssRule, FALSE);
                   4583:             }
                   4584:           else
                   4585:             color = TRUE;
                   4586:         }
1.328   ! vatton   4587:       else
1.327     vatton   4588:         cssRule = SkipProperty (cssRule, FALSE);
1.328   ! vatton   4589: 
1.82      cvs      4590:       cssRule = SkipBlanksAndComments (cssRule);
1.18      cvs      4591:     }
1.328   ! vatton   4592: 
        !          4593:   if (color && !img)
        !          4594:     ParseCSSBackgroundImage (element, tsch, ctxt, "none", css, isHTML);
        !          4595:   
        !          4596:   if (img && !repeat)
        !          4597:     ParseACSSBackgroundRepeat (element, tsch, ctxt,
        !          4598:                                "repeat", css, isHTML);
        !          4599:   if (img && !position)
        !          4600:     ParseACSSBackgroundPosition (element, tsch, ctxt,
        !          4601:                                  "0% 0%", css, isHTML);
        !          4602:   if (img && !attach)
        !          4603:     ParseACSSBackgroundAttachment (element, tsch, ctxt,
        !          4604:                                    "scroll", css, isHTML);
1.327     vatton   4605:   return (cssRule);
1.18      cvs      4606: }
                   4607: 
1.59      cvs      4608: /*----------------------------------------------------------------------
1.327     vatton   4609:   ParseCSSPageBreakBefore: parse a CSS page-break-before attribute 
1.59      cvs      4610:   ----------------------------------------------------------------------*/
1.79      cvs      4611: static char *ParseCSSPageBreakBefore (Element element, PSchema tsch,
1.327     vatton   4612:                                       PresentationContext ctxt, char *cssRule,
                   4613:                                       CSSInfoPtr css, ThotBool isHTML)
1.59      cvs      4614: {
                   4615:   PresentationValue   page;
                   4616: 
1.184     vatton   4617:   page.typed_data.unit = UNIT_INVALID;
1.59      cvs      4618:   page.typed_data.real = FALSE;
1.82      cvs      4619:   cssRule = SkipBlanksAndComments (cssRule);
                   4620:   if (!strncasecmp (cssRule, "auto", 4))
1.184     vatton   4621:     page.typed_data.value = PageAuto;
1.82      cvs      4622:   else if (!strncasecmp (cssRule, "always", 6))
1.59      cvs      4623:     {
1.184     vatton   4624:       page.typed_data.unit = UNIT_REL;
                   4625:       page.typed_data.value = PageAlways;
1.59      cvs      4626:     }
1.82      cvs      4627:   else if (!strncasecmp (cssRule, "avoid", 5))
1.59      cvs      4628:     {
1.184     vatton   4629:       page.typed_data.unit = UNIT_REL;
                   4630:       page.typed_data.value = PageAvoid;
1.59      cvs      4631:     }
1.82      cvs      4632:   else if (!strncasecmp (cssRule, "left", 4))
1.59      cvs      4633:     {
1.184     vatton   4634:       page.typed_data.unit = UNIT_REL;
                   4635:       page.typed_data.value = PageLeft;
1.59      cvs      4636:     }
1.82      cvs      4637:   else if (!strncasecmp (cssRule, "right", 5))
1.59      cvs      4638:     {
1.184     vatton   4639:       page.typed_data.unit = UNIT_REL;
                   4640:       page.typed_data.value = PageRight;
1.59      cvs      4641:     }
1.82      cvs      4642:   else if (!strncasecmp (cssRule, "inherit", 7))
1.59      cvs      4643:     {
1.293     quint    4644:       page.typed_data.unit = VALUE_INHERIT;
1.184     vatton   4645:       page.typed_data.value = PageInherit;
1.59      cvs      4646:     }
                   4647:   cssRule = SkipWord (cssRule);
1.295     vatton   4648:   /* check if it's an important rule */
                   4649:   cssRule = CheckImportantRule (cssRule, ctxt);
1.59      cvs      4650:   /* install the new presentation */
1.295     vatton   4651:   if (DoApply &&
                   4652:       ((page.typed_data.unit == UNIT_REL && page.typed_data.value == PageAlways)
                   4653:        || page.typed_data.unit == VALUE_INHERIT))
                   4654:     TtaSetStylePresentation (PRPageBefore, element, tsch, ctxt, page);
1.59      cvs      4655:   return (cssRule);
                   4656: }
                   4657: 
                   4658: /*----------------------------------------------------------------------
1.327     vatton   4659:   ParseCSSPageBreakAfter: parse a CSS page-break-after attribute 
1.59      cvs      4660:   ----------------------------------------------------------------------*/
1.79      cvs      4661: static char *ParseCSSPageBreakAfter (Element element, PSchema tsch,
1.327     vatton   4662:                                      PresentationContext ctxt,
                   4663:                                      char *cssRule, CSSInfoPtr css,
                   4664:                                      ThotBool isHTML)
1.59      cvs      4665: {
                   4666:   PresentationValue   page;
                   4667: 
1.184     vatton   4668:   page.typed_data.unit = UNIT_INVALID;
1.59      cvs      4669:   page.typed_data.real = FALSE;
1.82      cvs      4670:   cssRule = SkipBlanksAndComments (cssRule);
                   4671:   if (!strncasecmp (cssRule, "auto", 4))
1.184     vatton   4672:     page.typed_data.value = PageAuto;
1.82      cvs      4673:   else if (!strncasecmp (cssRule, "always", 6))
1.59      cvs      4674:     {
1.184     vatton   4675:       page.typed_data.unit = UNIT_REL;
                   4676:       page.typed_data.value = PageAlways;
1.59      cvs      4677:     }
1.82      cvs      4678:   else if (!strncasecmp (cssRule, "avoid", 5))
1.59      cvs      4679:     {
1.184     vatton   4680:       page.typed_data.unit = UNIT_REL;
                   4681:       page.typed_data.value = PageAvoid;
1.59      cvs      4682:     }
1.82      cvs      4683:   else if (!strncasecmp (cssRule, "left", 4))
1.59      cvs      4684:     {
1.184     vatton   4685:       page.typed_data.unit = UNIT_REL;
                   4686:       page.typed_data.value = PageLeft;
1.59      cvs      4687:     }
1.82      cvs      4688:   else if (!strncasecmp (cssRule, "right", 5))
1.59      cvs      4689:     {
1.184     vatton   4690:       page.typed_data.unit = UNIT_REL;
                   4691:       page.typed_data.value = PageRight;
1.59      cvs      4692:     }
1.82      cvs      4693:   else if (!strncasecmp (cssRule, "inherit", 7))
1.59      cvs      4694:     {
1.293     quint    4695:       page.typed_data.unit = VALUE_INHERIT;
1.184     vatton   4696:       page.typed_data.value = PageInherit;
1.59      cvs      4697:     }
                   4698:   cssRule = SkipWord (cssRule);
1.295     vatton   4699:   /* check if it's an important rule */
                   4700:   cssRule = CheckImportantRule (cssRule, ctxt);
1.314     gully    4701: #if 0
1.59      cvs      4702:   /* install the new presentation */
1.295     vatton   4703:   if (DoApply &&
                   4704:       (page.typed_data.unit == UNIT_REL ||
                   4705:        page.typed_data.unit == VALUE_INHERIT))
                   4706:     /* TtaSetStylePresentation (PRPageAfter, element, tsch, ctxt, page) */;
1.314     gully    4707: #endif /* 0 */
1.59      cvs      4708:   return (cssRule);
                   4709: }
                   4710: 
                   4711: /*----------------------------------------------------------------------
1.327     vatton   4712:   ParseCSSPageBreakInside: parse a CSS page-break-inside attribute 
1.59      cvs      4713:   ----------------------------------------------------------------------*/
1.79      cvs      4714: static char *ParseCSSPageBreakInside (Element element, PSchema tsch,
1.327     vatton   4715:                                       PresentationContext ctxt,
                   4716:                                       char *cssRule, CSSInfoPtr css,
                   4717:                                       ThotBool isHTML)
1.59      cvs      4718: {
                   4719:   PresentationValue   page;
                   4720: 
1.184     vatton   4721:   page.typed_data.unit = UNIT_INVALID;
1.59      cvs      4722:   page.typed_data.real = FALSE;
1.82      cvs      4723:   cssRule = SkipBlanksAndComments (cssRule);
                   4724:   if (!strncasecmp (cssRule, "auto", 4))
1.59      cvs      4725:     {
1.184     vatton   4726:       /*page.typed_data.unit = UNIT_REL;*/
                   4727:       page.typed_data.value = PageAuto;
1.59      cvs      4728:     }
1.82      cvs      4729:   else if (!strncasecmp (cssRule, "avoid", 5))
1.59      cvs      4730:     {
1.184     vatton   4731:       page.typed_data.unit = UNIT_REL;
                   4732:       page.typed_data.value = PageAvoid;
1.59      cvs      4733:     }
1.82      cvs      4734:   else if (!strncasecmp (cssRule, "inherit", 7))
1.59      cvs      4735:     {
1.293     quint    4736:       /* page.typed_data.unit = VALUE_INHERIT; */
1.184     vatton   4737:       page.typed_data.value = PageInherit;
1.59      cvs      4738:     }
                   4739:   cssRule = SkipWord (cssRule);
1.295     vatton   4740:   cssRule = CheckImportantRule (cssRule, ctxt);
1.59      cvs      4741:   /* install the new presentation */
1.293     quint    4742:   /*if ((page.typed_data.unit == UNIT_REL ||
                   4743:     page.typed_data.unit == VALUE_INHERIT) &&
1.184     vatton   4744:     page.typed_data.value == PageAvoid && DoApply)
1.295     vatton   4745:     TtaSetStylePresentation (PRPageInside, element, tsch, ctxt, page);*/
1.59      cvs      4746:   return (cssRule);
                   4747: }
1.18      cvs      4748: 
1.60      cvs      4749: /*----------------------------------------------------------------------
1.327     vatton   4750:   ParseSVGStrokeWidth: parse a SVG stroke-width property value.
1.60      cvs      4751:   ----------------------------------------------------------------------*/
1.79      cvs      4752: static char *ParseSVGStrokeWidth (Element element, PSchema tsch,
1.327     vatton   4753:                                   PresentationContext ctxt, char *cssRule,
                   4754:                                   CSSInfoPtr css, ThotBool isHTML)
1.60      cvs      4755: {
                   4756:   PresentationValue   width;
                   4757:   
1.82      cvs      4758:   cssRule = SkipBlanksAndComments (cssRule);
1.60      cvs      4759:   width.typed_data.value = 0;
1.184     vatton   4760:   width.typed_data.unit = UNIT_INVALID;
1.60      cvs      4761:   width.typed_data.real = FALSE;
1.110     vatton   4762:   if (isdigit (*cssRule) || *cssRule == '.')
1.166     vatton   4763:     {
1.327     vatton   4764:       cssRule = ParseCSSUnit (cssRule, &width);
                   4765:       if (width.typed_data.unit == UNIT_BOX)
                   4766:         width.typed_data.unit = UNIT_PX;
1.166     vatton   4767:     }
1.295     vatton   4768:   else
                   4769:     cssRule = SkipValue ("Invalid stroke-width value", cssRule);
                   4770: 
                   4771:   /* check if it's an important rule */
                   4772:   cssRule = CheckImportantRule (cssRule, ctxt);
1.184     vatton   4773:   if (width.typed_data.unit != UNIT_INVALID && DoApply)
1.117     vatton   4774:     {
1.207     vatton   4775:       TtaSetStylePresentation (PRLineWeight, element, tsch, ctxt, width);
1.117     vatton   4776:       width.typed_data.value = 1;
1.184     vatton   4777:       width.typed_data.unit = UNIT_REL;
1.117     vatton   4778:     }
1.60      cvs      4779:   return (cssRule);
                   4780: }
                   4781: 
1.217     vatton   4782: /*----------------------------------------------------------------------
1.327     vatton   4783:   ParseCSSPosition: parse a CSS Position attribute string.
1.217     vatton   4784:   ----------------------------------------------------------------------*/
                   4785: static char *ParseCSSPosition (Element element, PSchema tsch,
1.327     vatton   4786:                                PresentationContext ctxt, char *cssRule,
                   4787:                                CSSInfoPtr css, ThotBool isHTML)
1.217     vatton   4788: {
1.305     quint    4789:   char               *ptr;
                   4790:   PresentationValue   pval;
1.217     vatton   4791: 
1.305     quint    4792:   pval.typed_data.value = 0;
                   4793:   pval.typed_data.unit = UNIT_BOX;
                   4794:   pval.typed_data.real = FALSE;
1.217     vatton   4795:   cssRule = SkipBlanksAndComments (cssRule);
                   4796:   ptr = cssRule;
                   4797:   if (!strncasecmp (cssRule, "static", 6))
1.305     quint    4798:     pval.typed_data.value = PositionStatic;
1.217     vatton   4799:   else if (!strncasecmp (cssRule, "relative", 7))
1.305     quint    4800:     pval.typed_data.value = PositionRelative;
1.217     vatton   4801:   else if (!strncasecmp (cssRule, "absolute", 8))
1.305     quint    4802:     pval.typed_data.value = PositionAbsolute;
1.217     vatton   4803:   else if (!strncasecmp (cssRule, "fixed", 5))
1.305     quint    4804:     pval.typed_data.value = PositionFixed;
1.217     vatton   4805:   else if (!strncasecmp (cssRule, "inherit", 7))
1.305     quint    4806:     pval.typed_data.unit = VALUE_INHERIT;
                   4807: 
                   4808:   if (pval.typed_data.value == 0 && pval.typed_data.unit != VALUE_INHERIT)
                   4809:     {
                   4810:       cssRule = SkipValue ("Invalid position value", ptr);
                   4811:       cssRule = CheckImportantRule (cssRule, ctxt);
                   4812:       cssRule = SkipValue (NULL, cssRule);
                   4813:     }
1.217     vatton   4814:   else
1.305     quint    4815:     {
                   4816:       cssRule = SkipValue (NULL, cssRule);
                   4817:       cssRule = CheckImportantRule (cssRule, ctxt);
                   4818:       if (DoApply)
1.327     vatton   4819:         TtaSetStylePresentation (PRPosition, element, tsch, ctxt, pval);
1.305     quint    4820:     }
1.217     vatton   4821:   return (cssRule);
                   4822: }
                   4823: 
                   4824: /*----------------------------------------------------------------------
1.327     vatton   4825:   ParseCSSTop: parse a CSS Top attribute
1.217     vatton   4826:   ----------------------------------------------------------------------*/
                   4827: static char *ParseCSSTop (Element element, PSchema tsch,
1.327     vatton   4828:                           PresentationContext context, char *cssRule,
                   4829:                           CSSInfoPtr css, ThotBool isHTML)
1.217     vatton   4830: {
                   4831:   PresentationValue   val;
                   4832:   char               *ptr;
                   4833: 
                   4834:   cssRule = SkipBlanksAndComments (cssRule);
                   4835:   ptr = cssRule;
1.305     quint    4836:   /* first parse the value */
                   4837:   if (!strncasecmp (cssRule, "auto", 4))
1.217     vatton   4838:     {
                   4839:       val.typed_data.unit = VALUE_AUTO;
                   4840:       val.typed_data.value = 0;
                   4841:       val.typed_data.real = FALSE;
                   4842:       cssRule = SkipWord (cssRule);
                   4843:     }
1.305     quint    4844:   else if (!strncasecmp (cssRule, "inherit", 7))
                   4845:     {
                   4846:       val.typed_data.unit = VALUE_INHERIT;
                   4847:       cssRule = SkipWord (cssRule);
                   4848:     }
1.217     vatton   4849:   else
                   4850:     cssRule = ParseCSSUnit (cssRule, &val);
                   4851:   if (val.typed_data.value != 0 &&
                   4852:       (val.typed_data.unit == UNIT_INVALID ||
                   4853:        val.typed_data.unit == UNIT_BOX))
                   4854:     {
1.218     vatton   4855:       cssRule = SkipValue ("top value", ptr);
1.217     vatton   4856:       val.typed_data.unit = UNIT_PX;
                   4857:     }
1.295     vatton   4858:   cssRule = CheckImportantRule (cssRule, context);
1.217     vatton   4859:   if (DoApply)
1.305     quint    4860:     TtaSetStylePresentation (PRTop, element, tsch, context, val);
1.217     vatton   4861:   return (cssRule);
                   4862: }
                   4863: 
                   4864: /*----------------------------------------------------------------------
1.327     vatton   4865:   ParseCSSRight: parse a CSS Right attribute
1.217     vatton   4866:   ----------------------------------------------------------------------*/
                   4867: static char *ParseCSSRight (Element element, PSchema tsch,
1.327     vatton   4868:                             PresentationContext context, char *cssRule,
                   4869:                             CSSInfoPtr css, ThotBool isHTML)
1.217     vatton   4870: {
                   4871:   PresentationValue   val;
                   4872:   char               *ptr;
                   4873: 
                   4874:   cssRule = SkipBlanksAndComments (cssRule);
                   4875:   ptr = cssRule;
                   4876:   /* first parse the attribute string */
1.305     quint    4877:   if (!strncasecmp (cssRule, "auto", 4))
1.217     vatton   4878:     {
                   4879:       val.typed_data.unit = VALUE_AUTO;
                   4880:       val.typed_data.value = 0;
                   4881:       val.typed_data.real = FALSE;
                   4882:       cssRule = SkipWord (cssRule);
                   4883:     }
1.305     quint    4884:   else if (!strncasecmp (cssRule, "inherit", 7))
                   4885:     {
                   4886:       val.typed_data.unit = VALUE_INHERIT;
                   4887:       cssRule = SkipWord (cssRule);
                   4888:     }
1.217     vatton   4889:   else
                   4890:     cssRule = ParseCSSUnit (cssRule, &val);
                   4891:   if (val.typed_data.value != 0 &&
                   4892:       (val.typed_data.unit == UNIT_INVALID ||
                   4893:        val.typed_data.unit == UNIT_BOX))
                   4894:     {
1.218     vatton   4895:       cssRule = SkipValue ("right value", ptr);
1.217     vatton   4896:       val.typed_data.unit = UNIT_PX;
                   4897:     }
1.295     vatton   4898:   cssRule = CheckImportantRule (cssRule, context);
1.217     vatton   4899:   if (DoApply)
1.305     quint    4900:     TtaSetStylePresentation (PRRight, element, tsch, context, val);
1.217     vatton   4901:   return (cssRule);
                   4902: }
                   4903: 
                   4904: /*----------------------------------------------------------------------
1.327     vatton   4905:   ParseCSSBottom: parse a CSS Bottom attribute
1.217     vatton   4906:   ----------------------------------------------------------------------*/
                   4907: static char *ParseCSSBottom (Element element, PSchema tsch,
1.327     vatton   4908:                              PresentationContext context, char *cssRule,
                   4909:                              CSSInfoPtr css, ThotBool isHTML)
1.217     vatton   4910: {
                   4911:   PresentationValue   val;
                   4912:   char               *ptr;
                   4913: 
                   4914:   cssRule = SkipBlanksAndComments (cssRule);
                   4915:   ptr = cssRule;
                   4916:   /* first parse the attribute string */
1.305     quint    4917:   if (!strncasecmp (cssRule, "auto", 4))
1.217     vatton   4918:     {
                   4919:       val.typed_data.unit = VALUE_AUTO;
                   4920:       val.typed_data.value = 0;
                   4921:       val.typed_data.real = FALSE;
                   4922:       cssRule = SkipWord (cssRule);
                   4923:     }
1.305     quint    4924:   else if (!strncasecmp (cssRule, "inherit", 7))
                   4925:     {
                   4926:       val.typed_data.unit = VALUE_INHERIT;
                   4927:       cssRule = SkipWord (cssRule);
                   4928:     }
1.217     vatton   4929:   else
                   4930:     cssRule = ParseCSSUnit (cssRule, &val);
                   4931:   if (val.typed_data.value != 0 &&
                   4932:       (val.typed_data.unit == UNIT_INVALID ||
                   4933:        val.typed_data.unit == UNIT_BOX))
                   4934:     {
1.218     vatton   4935:       cssRule = SkipValue ("bottom value", ptr);
1.217     vatton   4936:       val.typed_data.unit = UNIT_PX;
                   4937:     }
1.295     vatton   4938:   cssRule = CheckImportantRule (cssRule, context);
1.217     vatton   4939:   if (DoApply)
1.305     quint    4940:     TtaSetStylePresentation (PRBottom, element, tsch, context, val);
1.217     vatton   4941:   return (cssRule);
                   4942: }
                   4943: 
                   4944: /*----------------------------------------------------------------------
1.327     vatton   4945:   ParseCSSLeft: parse a CSS Left attribute
1.217     vatton   4946:   ----------------------------------------------------------------------*/
                   4947: static char *ParseCSSLeft (Element element, PSchema tsch,
1.327     vatton   4948:                            PresentationContext context, char *cssRule,
                   4949:                            CSSInfoPtr css, ThotBool isHTML)
1.217     vatton   4950: {
                   4951:   PresentationValue   val;
                   4952:   char               *ptr;
                   4953: 
                   4954:   cssRule = SkipBlanksAndComments (cssRule);
                   4955:   ptr = cssRule;
                   4956:   /* first parse the attribute string */
1.305     quint    4957:   if (!strncasecmp (cssRule, "auto", 4))
1.217     vatton   4958:     {
                   4959:       val.typed_data.unit = VALUE_AUTO;
                   4960:       val.typed_data.value = 0;
                   4961:       val.typed_data.real = FALSE;
                   4962:       cssRule = SkipWord (cssRule);
                   4963:     }
1.305     quint    4964:   else if (!strncasecmp (cssRule, "inherit", 7))
                   4965:     {
                   4966:       val.typed_data.unit = VALUE_INHERIT;
                   4967:       cssRule = SkipWord (cssRule);
                   4968:     }
1.217     vatton   4969:   else
                   4970:     cssRule = ParseCSSUnit (cssRule, &val);
                   4971:   if (val.typed_data.value != 0 &&
                   4972:       (val.typed_data.unit == UNIT_INVALID ||
                   4973:        val.typed_data.unit == UNIT_BOX))
                   4974:     {
1.218     vatton   4975:       cssRule = SkipValue ("left value", ptr);
1.217     vatton   4976:       val.typed_data.unit = UNIT_PX;
                   4977:     }
1.295     vatton   4978:   cssRule = CheckImportantRule (cssRule, context);
1.217     vatton   4979:   if (DoApply)
1.305     quint    4980:     TtaSetStylePresentation (PRLeft, element, tsch, context, val);
1.217     vatton   4981:   return (cssRule);
                   4982: }
                   4983: 
                   4984: /*----------------------------------------------------------------------
1.327     vatton   4985:   ParseCSSZIndex: parse a CSS z-index attribute
1.217     vatton   4986:   ----------------------------------------------------------------------*/
                   4987: static char *ParseCSSZIndex (Element element, PSchema tsch,
1.327     vatton   4988:                              PresentationContext context, char *cssRule,
                   4989:                              CSSInfoPtr css, ThotBool isHTML)
1.217     vatton   4990: {
                   4991:   PresentationValue   val;
                   4992:   char               *ptr;
                   4993: 
                   4994:   cssRule = SkipBlanksAndComments (cssRule);
                   4995:   ptr = cssRule;
                   4996:   /* first parse the attribute string */
                   4997:   if (!strncasecmp (cssRule, "auto", 4) ||
                   4998:       !strncasecmp (cssRule, "inherit", 7))
                   4999:     {
                   5000:       val.typed_data.unit = VALUE_AUTO;
                   5001:       val.typed_data.value = 0;
                   5002:       val.typed_data.real = FALSE;
                   5003:       cssRule = SkipWord (cssRule);
                   5004:     }
                   5005:   else
                   5006:     {
                   5007:       cssRule = ParseCSSUnit (cssRule, &val);
                   5008:       if (val.typed_data.unit != UNIT_BOX)
1.327     vatton   5009:         {
                   5010:           cssRule = SkipValue ("z-index value", ptr);
                   5011:           val.typed_data.unit = UNIT_BOX;
                   5012:         }
1.217     vatton   5013:     }
1.295     vatton   5014:   cssRule = CheckImportantRule (cssRule, context);
1.217     vatton   5015:   /***
1.327     vatton   5016:       if (DoApply)
                   5017:       TtaSetStylePresentation (PR, element, tsch, context, val);
1.217     vatton   5018:   ***/
                   5019:   return (cssRule);
                   5020: }
                   5021: 
1.18      cvs      5022: /************************************************************************
                   5023:  *                                                                     *  
                   5024:  *     FUNCTIONS STYLE DECLARATIONS                                    *
                   5025:  *                                                                     *  
                   5026:  ************************************************************************/
                   5027: /*
1.59      cvs      5028:  * NOTE: Long attribute name MUST be placed before shortened ones !
1.18      cvs      5029:  *        e.g. "FONT-SIZE" must be placed before "FONT"
                   5030:  */
                   5031: static CSSProperty CSSProperties[] =
1.327     vatton   5032:   {
                   5033:     {"background-color", ParseCSSBackgroundColor},
                   5034:     {"background-image", ParseCSSBackgroundImage},
                   5035:     {"background-repeat", ParseCSSBackgroundRepeat},
                   5036:     {"background-attachment", ParseCSSBackgroundAttachment},
                   5037:     {"background-position", ParseCSSBackgroundPosition},
                   5038:     {"background", ParseCSSBackground},
                   5039:     {"border-top-width", ParseCSSBorderTopWidth},
                   5040:     {"border-right-width", ParseCSSBorderRightWidth},
                   5041:     {"border-bottom-width", ParseCSSBorderBottomWidth},
                   5042:     {"border-left-width", ParseCSSBorderLeftWidth},
                   5043:     {"border-width", ParseCSSBorderWidth},
                   5044:     {"border-top-color", ParseCSSBorderColorTop},
                   5045:     {"border-right-color", ParseCSSBorderColorRight},
                   5046:     {"border-bottom-color", ParseCSSBorderColorBottom},
                   5047:     {"border-left-color", ParseCSSBorderColorLeft},
                   5048:     {"border-color", ParseCSSBorderColor},
                   5049:     {"border-top-style", ParseCSSBorderStyleTop},
                   5050:     {"border-right-style", ParseCSSBorderStyleRight},
                   5051:     {"border-bottom-style", ParseCSSBorderStyleBottom},
                   5052:     {"border-left-style", ParseCSSBorderStyleLeft},
                   5053:     {"border-style", ParseCSSBorderStyle},
                   5054:     {"border-top", ParseCSSBorderTop},
                   5055:     {"border-right", ParseCSSBorderRight},
                   5056:     {"border-bottom", ParseCSSBorderBottom},
                   5057:     {"border-left", ParseCSSBorderLeft},
                   5058:     {"border", ParseCSSBorder},
                   5059:     {"bottom", ParseCSSBottom},
                   5060:     {"clear", ParseCSSClear},
                   5061:     {"color", ParseCSSForeground},
                   5062:     {"content", ParseCSSContent},
                   5063:     {"direction", ParseCSSDirection},
                   5064:     {"display", ParseCSSDisplay},
                   5065:     {"float", ParseCSSFloat},
                   5066:     {"font-family", ParseCSSFontFamily},
                   5067:     {"font-style", ParseCSSFontStyle},
                   5068:     {"font-variant", ParseCSSFontVariant},
                   5069:     {"font-weight", ParseCSSFontWeight},
                   5070:     {"font-size-adjust", ParseCSSFontSizeAdjust},
                   5071:     {"font-size", ParseCSSFontSize},
                   5072:     {"font", ParseCSSFont},
                   5073:     {"height", ParseCSSHeight},
                   5074:     {"left", ParseCSSLeft},
                   5075:     {"letter-spacing", ParseCSSLetterSpacing},
                   5076:     {"line-height", ParseCSSLineHeight},
                   5077:     {"list-style-type", ParseCSSListStyleType},
                   5078:     {"list-style-image", ParseCSSListStyleImage},
                   5079:     {"list-style-position", ParseCSSListStylePosition},
                   5080:     {"list-style", ParseCSSListStyle},
                   5081:     {"margin-bottom", ParseCSSMarginBottom},
                   5082:     {"margin-top", ParseCSSMarginTop},
                   5083:     {"margin-right", ParseCSSMarginRight},
                   5084:     {"margin-left", ParseCSSMarginLeft},
                   5085:     {"margin", ParseCSSMargin},
                   5086:     {"padding-top", ParseCSSPaddingTop},
                   5087:     {"padding-right", ParseCSSPaddingRight},
                   5088:     {"padding-bottom", ParseCSSPaddingBottom},
                   5089:     {"padding-left", ParseCSSPaddingLeft},
                   5090:     {"padding", ParseCSSPadding},
                   5091:     {"page-break-before", ParseCSSPageBreakBefore},
                   5092:     {"page-break-after", ParseCSSPageBreakAfter},
                   5093:     {"page-break-inside", ParseCSSPageBreakInside},
                   5094:     {"position", ParseCSSPosition},
                   5095:     {"right", ParseCSSRight},
                   5096:     {"text-align", ParseCSSTextAlign},
                   5097:     {"text-anchor", ParseCSSTextAnchor},
                   5098:     {"text-indent", ParseCSSTextIndent},
                   5099:     {"text-decoration", ParseCSSTextDecoration},
                   5100:     {"text-transform", ParseCSSTextTransform},
                   5101:     {"top", ParseCSSTop},
                   5102:     {"unicode-bidi", ParseCSSUnicodeBidi},
                   5103:     {"vertical-align", ParseCSSVerticalAlign},
                   5104:     {"white-space", ParseCSSWhiteSpace},
                   5105:     {"width", ParseCSSWidth},
                   5106:     {"word-spacing", ParseCSSWordSpacing},
                   5107:     {"z-index", ParseCSSZIndex},
                   5108: 
                   5109:     /* SVG extensions */
                   5110:     {"fill-opacity", ParseSVGFillOpacity},
                   5111:     {"fill", ParseSVGFill},
                   5112:     {"opacity", ParseSVGOpacity},
                   5113:     {"stroke-opacity", ParseSVGStrokeOpacity},
                   5114:     {"stroke-width", ParseSVGStrokeWidth},
                   5115:     {"stroke", ParseSVGStroke}
                   5116:   };
1.155     cheyroul 5117: 
1.18      cvs      5118: #define NB_CSSSTYLEATTRIBUTE (sizeof(CSSProperties) / sizeof(CSSProperty))
                   5119: 
                   5120: /*----------------------------------------------------------------------
1.327     vatton   5121:   ParseCSSRule: parse a CSS Style string                        
                   5122:   we expect the input string describing the style to be of the form
                   5123:   property: value [ ; property: value ]* 
                   5124:   but tolerate incorrect or incomplete input                    
1.18      cvs      5125:   ----------------------------------------------------------------------*/
1.79      cvs      5126: static void  ParseCSSRule (Element element, PSchema tsch,
1.327     vatton   5127:                            PresentationContext ctxt, char *cssRule,
                   5128:                            CSSInfoPtr css, ThotBool isHTML)
1.18      cvs      5129: {
1.34      cvs      5130:   DisplayMode         dispMode;
1.312     quint    5131:   char               *p = NULL, *next, *end;
1.214     quint    5132:   char               *valueStart;
1.18      cvs      5133:   int                 lg;
1.34      cvs      5134:   unsigned int        i;
1.76      cvs      5135:   ThotBool            found;
1.18      cvs      5136: 
1.34      cvs      5137:   /* avoid too many redisplay */
1.207     vatton   5138:   dispMode = TtaGetDisplayMode (ctxt->doc);
1.34      cvs      5139:   if (dispMode == DisplayImmediately)
1.207     vatton   5140:     TtaSetDisplayMode (ctxt->doc, DeferredDisplay);
1.34      cvs      5141: 
1.82      cvs      5142:   while (*cssRule != EOS)
1.18      cvs      5143:     {
1.82      cvs      5144:       cssRule = SkipBlanksAndComments (cssRule);
1.153     vatton   5145:       if (*cssRule < 0x41 || *cssRule > 0x7A ||
1.327     vatton   5146:           (*cssRule > 0x5A && *cssRule < 0x60))
                   5147:         cssRule++;
1.194     vatton   5148:       else if (*cssRule != EOS)
1.327     vatton   5149:         {
                   5150:           found = FALSE;
                   5151:           /* look for the type of property */
                   5152:           for (i = 0; i < NB_CSSSTYLEATTRIBUTE && !found; i++)
                   5153:             {
                   5154:               lg = strlen (CSSProperties[i].name);
                   5155:               if (!strncasecmp (cssRule, CSSProperties[i].name, lg))
                   5156:                 {
                   5157:                   p = cssRule + lg;
                   5158:                   found = TRUE;
                   5159:                   i--;
                   5160:                 }
                   5161:             }
                   5162: 
                   5163:           if (i < NB_CSSSTYLEATTRIBUTE &&
                   5164:               !strcasecmp (CSSProperties[i].name, "content") &&
                   5165:               ((GenericContext)ctxt)->pseudo != PbBefore &&
                   5166:               ((GenericContext)ctxt)->pseudo != PbAfter)
                   5167:             /* property content is allowed only for pseudo-elements before and
                   5168:                after */
                   5169:             {
                   5170:               end = cssRule;
                   5171:               end = SkipProperty (end, TRUE);
                   5172:               CSSParseError ("content is allowed only for pseudo-elements",
                   5173:                              cssRule, end);
                   5174:               i = NB_CSSSTYLEATTRIBUTE;
                   5175:             }
                   5176:           if (i == NB_CSSSTYLEATTRIBUTE)
                   5177:             cssRule = SkipProperty (cssRule, TRUE);
                   5178:           else
                   5179:             {
                   5180:               /* update index and skip the ":" indicator if present */
                   5181:               p = SkipBlanksAndComments (p);
                   5182:               if (*p == ':')
                   5183:                 {
                   5184:                   p++;
                   5185:                   p = SkipBlanksAndComments (p);
                   5186:                   /* try to parse the value associated with this property */
                   5187:                   if (CSSProperties[i].parsing_function != NULL)
                   5188:                     {
                   5189:                       valueStart = p;
                   5190:                       p = CSSProperties[i].parsing_function (element, tsch,
                   5191:                                                              ctxt, p, css, isHTML);
                   5192:                       if (!element && isHTML)
                   5193:                         {
                   5194:                           if  (ctxt->type == HTML_EL_Input)
                   5195:                             /* it's a generic rule for the HTML element input.
                   5196:                                Generate a Thot Pres rule for each kind of
                   5197:                                input element */
                   5198:                             {
                   5199:                               ctxt->type = HTML_EL_Text_Input;
                   5200:                               p = CSSProperties[i].parsing_function (element,
                   5201:                                                                      tsch, ctxt, valueStart, css, isHTML);
                   5202:                               ctxt->type = HTML_EL_Password_Input;
                   5203:                               p = CSSProperties[i].parsing_function (element,
                   5204:                                                                      tsch, ctxt, valueStart, css, isHTML);
                   5205:                               ctxt->type = HTML_EL_File_Input;
                   5206:                               p = CSSProperties[i].parsing_function (element,
                   5207:                                                                      tsch, ctxt, valueStart, css, isHTML);
                   5208:                               ctxt->type = HTML_EL_Checkbox_Input;
                   5209:                               p = CSSProperties[i].parsing_function (element,
                   5210:                                                                      tsch, ctxt, valueStart, css, isHTML);
                   5211:                               ctxt->type = HTML_EL_Radio_Input;
                   5212:                               p = CSSProperties[i].parsing_function (element,
                   5213:                                                                      tsch, ctxt, valueStart, css, isHTML);
                   5214:                               ctxt->type = HTML_EL_Submit_Input;
                   5215:                               p = CSSProperties[i].parsing_function (element,
                   5216:                                                                      tsch, ctxt, valueStart, css, isHTML);
                   5217:                               ctxt->type = HTML_EL_Reset_Input;
                   5218:                               p = CSSProperties[i].parsing_function (element,
                   5219:                                                                      tsch, ctxt, valueStart, css, isHTML);
                   5220:                               ctxt->type = HTML_EL_Button_Input;
                   5221:                               p = CSSProperties[i].parsing_function (element,
                   5222:                                                                      tsch, ctxt, valueStart, css, isHTML);
                   5223:                               ctxt->type = HTML_EL_Input;
                   5224:                             }
                   5225:                           else if (ctxt->type == HTML_EL_ruby)
                   5226:                             /* it's a generic rule for the HTML element ruby.
                   5227:                                Generate a Thot Pres rule for each kind of
                   5228:                                ruby element. */
                   5229:                             {
                   5230:                               ctxt->type = HTML_EL_simple_ruby;
                   5231:                               p = CSSProperties[i].parsing_function (element,
                   5232:                                                                      tsch, ctxt, valueStart, css, isHTML);
                   5233:                               ctxt->type = HTML_EL_complex_ruby;
                   5234:                               p = CSSProperties[i].parsing_function (element,
                   5235:                                                                      tsch, ctxt, valueStart, css, isHTML);
                   5236:                               ctxt->type = HTML_EL_ruby;
                   5237:                             }
                   5238:                         }
                   5239:                       /* update index and skip the ";" separator if present */
                   5240:                       next = SkipBlanksAndComments (p);
                   5241:                       if (*next != EOS && *next != ';')
                   5242:                         CSSParseError ("Missing closing ';'", cssRule, p);
                   5243:                       cssRule = next;
                   5244:                     }
                   5245:                 }
                   5246:               else
                   5247:                 cssRule = SkipProperty (cssRule, TRUE);
                   5248:             }
                   5249:         }
1.18      cvs      5250:       /* next property */
1.82      cvs      5251:       cssRule = SkipBlanksAndComments (cssRule);
1.89      cvs      5252:       if (*cssRule == '}')
1.327     vatton   5253:         {
                   5254:           cssRule++;
                   5255:           CSSPrintError ("Invalid character", "}");
                   5256:           cssRule = SkipBlanksAndComments (cssRule);
                   5257:         }
1.155     cheyroul 5258:       if (*cssRule == ',' ||
1.327     vatton   5259:           *cssRule == ';')
                   5260:         {
                   5261:           cssRule++;
                   5262:           cssRule = SkipBlanksAndComments (cssRule);
                   5263:         }
1.18      cvs      5264:     }
1.34      cvs      5265: 
                   5266:   /* restore the display mode */
                   5267:   if (dispMode == DisplayImmediately)
1.207     vatton   5268:     TtaSetDisplayMode (ctxt->doc, dispMode);
1.18      cvs      5269: }
1.1       cvs      5270: 
1.111     cvs      5271: /*----------------------------------------------------------------------
1.327     vatton   5272:   ParseHTMLSpecificStyle: parse and apply a CSS Style string.
                   5273:   This function must be called when a specific style is applied to an
                   5274:   element.
                   5275:   The parameter specificity is the specificity of the style, 0 if it is
                   5276:   not really a CSS rule.
1.1       cvs      5277:   ----------------------------------------------------------------------*/
1.79      cvs      5278: void  ParseHTMLSpecificStyle (Element el, char *cssRule, Document doc,
1.327     vatton   5279:                               int specificity, ThotBool destroy)
1.1       cvs      5280: {
1.257     vatton   5281:   DisplayMode         dispMode;
1.207     vatton   5282:   PresentationContext ctxt;
                   5283:   ElementType         elType;
                   5284:   ThotBool            isHTML;
1.1       cvs      5285: 
1.207     vatton   5286:   /*  A rule applying to BODY is really meant to address HTML */
                   5287:   elType = TtaGetElementType (el);
1.286     quint    5288:   NewLineSkipped = 0;
1.207     vatton   5289:   /* store the current line for eventually reported errors */
                   5290:   LineNumber = TtaGetElementLineNumber (el);
                   5291:   if (destroy)
                   5292:     /* no reported errors */
                   5293:     ParsedDoc = 0;
                   5294:   else if (ParsedDoc != doc)
                   5295:     {
                   5296:       /* update the context for reported errors */
                   5297:       ParsedDoc = doc;
                   5298:       DocURL = DocumentURLs[doc];
                   5299:     }
                   5300:   isHTML = (strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML") == 0);
                   5301:   /* create the context of the Specific presentation driver */
                   5302:   ctxt = TtaGetSpecificStyleContext (doc);
                   5303:   if (ctxt == NULL)
                   5304:     return;
                   5305:   ctxt->type = elType.ElTypeNum;
                   5306:   ctxt->cssSpecificity = specificity;
1.236     quint    5307:   ctxt->cssLine = LineNumber;
1.207     vatton   5308:   ctxt->destroy = destroy;
                   5309:   /* first use of the context */
                   5310:   ctxt->uses = 1;
1.257     vatton   5311:   /* save the current display mode */
                   5312:   dispMode = TtaGetDisplayMode (doc);
1.207     vatton   5313:   /* Call the parser */
                   5314:   ParseCSSRule (el, NULL, (PresentationContext) ctxt, cssRule, NULL, isHTML);
1.257     vatton   5315:   /* restore the display mode if necessary */
                   5316:   TtaSetDisplayMode (doc, dispMode);
1.207     vatton   5317:   /* check if the context can be freed */
                   5318:   ctxt->uses -= 1;
                   5319:   if (ctxt->uses == 0)
                   5320:     /* no image loading */
                   5321:     TtaFreeMemory(ctxt);
1.1       cvs      5322: }
                   5323: 
1.68      cvs      5324: 
1.1       cvs      5325: /*----------------------------------------------------------------------
1.207     vatton   5326:   ParseGenericSelector: Create a generic context for a given selector
                   5327:   string.
                   5328:   If the selector is made of multiple comma, it parses them one at a time
                   5329:   and return the end of the selector string to be handled or NULL.
1.231     vatton   5330:   The parameter ctxt gives the current style context which will be passed
                   5331:   to Thotlib.
                   5332:   The parameter css points to the current CSS context.
                   5333:   The parameter link points to the link element.
                   5334:   The parameter url gives the URL of the parsed style sheet.
1.1       cvs      5335:   ----------------------------------------------------------------------*/
1.207     vatton   5336: static char *ParseGenericSelector (char *selector, char *cssRule,
1.327     vatton   5337:                                    GenericContext ctxt, Document doc,
                   5338:                                    CSSInfoPtr css, Element link, char *url)
1.79      cvs      5339: {
                   5340:   ElementType        elType;
                   5341:   PSchema            tsch;
1.119     vatton   5342:   AttributeType      attrType;
1.240     quint    5343:   char              *deb, *cur, *sel, *next, c;
1.317     vatton   5344:   char              *schemaName, *mappedName, *saveURL;
1.79      cvs      5345:   char              *names[MAX_ANCESTORS];
                   5346:   char              *ids[MAX_ANCESTORS];
                   5347:   char              *classes[MAX_ANCESTORS];
                   5348:   char              *pseudoclasses[MAX_ANCESTORS];
                   5349:   char              *attrs[MAX_ANCESTORS];
                   5350:   char              *attrvals[MAX_ANCESTORS];
1.133     vatton   5351:   AttrMatch          attrmatch[MAX_ANCESTORS];
1.255     vatton   5352:   ElemRel            rel[MAX_ANCESTORS];
1.91      cvs      5353:   int                i, j, k, max;
1.256     vatton   5354:   int                att, kind;
1.118     vatton   5355:   int                specificity, xmlType;
1.217     vatton   5356:   int                skippedNL;
1.79      cvs      5357:   ThotBool           isHTML;
1.183     vatton   5358:   ThotBool           level, quoted;
1.1       cvs      5359: 
1.207     vatton   5360:   sel = ctxt->sel;
1.82      cvs      5361:   sel[0] = EOS;
1.117     vatton   5362:   specificity = 0;
1.1       cvs      5363:   for (i = 0; i < MAX_ANCESTORS; i++)
                   5364:     {
1.25      cvs      5365:       names[i] = NULL;
                   5366:       ids[i] = NULL;
                   5367:       classes[i] = NULL;
                   5368:       pseudoclasses[i] = NULL;
                   5369:       attrs[i] = NULL;
                   5370:       attrvals[i] = NULL;
1.133     vatton   5371:       attrmatch[i] = Txtmatch;
1.255     vatton   5372:       rel[i] = RelAncestor;
1.25      cvs      5373:       ctxt->name[i] = 0;
                   5374:       ctxt->names_nb[i] = 0;
                   5375:       ctxt->attrType[i] = 0;
1.129     vatton   5376:       ctxt->attrLevel[i] = 0;
1.25      cvs      5377:       ctxt->attrText[i] = NULL;
1.178     quint    5378:       ctxt->attrMatch[i] = Txtmatch;
1.1       cvs      5379:     }
1.25      cvs      5380:   ctxt->box = 0;
1.312     quint    5381:   ctxt->var = 0;
1.306     quint    5382:   ctxt->pseudo = PbNone;
1.25      cvs      5383:   ctxt->type = 0;
1.114     quint    5384:   /* the specificity of the rule depends on the selector */
                   5385:   ctxt->cssSpecificity = 0;
1.231     vatton   5386:   /* localisation of the CSS rule */
                   5387:   ctxt->cssLine = LineNumber + NewLineSkipped;
                   5388:   ctxt->cssURL = url;
1.240     quint    5389: 
1.286     quint    5390:   skippedNL = NewLineSkipped;
1.82      cvs      5391:   selector = SkipBlanksAndComments (selector);
1.286     quint    5392:   NewLineSkipped = skippedNL;
1.27      cvs      5393:   cur = &sel[0];
1.25      cvs      5394:   max = 0; /* number of loops */
1.1       cvs      5395:   while (1)
                   5396:     {
1.85      cvs      5397:       /* point to the following word in sel[] */
1.27      cvs      5398:       deb = cur;
1.25      cvs      5399:       /* copy an item of the selector into sel[] */
1.1       cvs      5400:       /* put one word in the sel buffer */
1.82      cvs      5401:       while (*selector != EOS && *selector != ',' &&
                   5402:              *selector != '.' && *selector != ':' &&
1.118     vatton   5403:              *selector != '#' && *selector != '[' &&
1.250     vatton   5404:              *selector != '>' && *selector != '+' &&
1.327     vatton   5405:              !TtaIsBlank (selector))
                   5406:         *cur++ = *selector++;
1.82      cvs      5407:       *cur++ = EOS; /* close the first string  in sel[] */
                   5408:       if (deb[0] != EOS)
1.327     vatton   5409:         {
                   5410:           if (deb[0] <= 64 && deb[0] != '*')
                   5411:             {
                   5412:               CSSPrintError ("Invalid element", deb);
                   5413:               return NULL;
                   5414:             }
                   5415:           else
                   5416:             {
                   5417:               names[0] = deb;
                   5418:               if (!strcmp (names[0], "html"))
                   5419:                 /* give a greater priority to the backgoud color of html */
                   5420:                 specificity += 3;
                   5421:               else
                   5422:                 /* selector "*" has specificity zero */
                   5423:                 if (strcmp (names[0], "*"))
                   5424:                   specificity += 1;
                   5425:             }
                   5426:         }
1.25      cvs      5427:       else
1.327     vatton   5428:         names[0] = NULL;
1.226     quint    5429: 
1.27      cvs      5430:       classes[0] = NULL;
                   5431:       pseudoclasses[0] = NULL;
                   5432:       ids[0] = NULL;
                   5433:       attrs[0] = NULL;
                   5434:       attrvals[0] = NULL;
1.267     vatton   5435:       attrmatch[0] = Txtmatch;
1.320     quint    5436:       rel[0] = RelAncestor;
1.25      cvs      5437: 
1.27      cvs      5438:       /* now names[0] points to the beginning of the parsed item
1.327     vatton   5439:          and cur to the next chain to be parsed */
1.129     vatton   5440:       while (*selector == '.' || *selector == ':' ||
1.327     vatton   5441:              *selector == '#' || *selector == '[')
                   5442:         {
                   5443:           /* point to the following word in sel[] */
                   5444:           deb = cur;
                   5445:           if (*selector == '.')
                   5446:             {
                   5447:               selector++;
                   5448:               while (*selector != EOS && *selector != ',' &&
                   5449:                      *selector != '.' && *selector != ':' &&
                   5450:                      !TtaIsBlank (selector))
                   5451:                 {
                   5452:                   if (*selector == '\\')
                   5453:                     {
                   5454:                       selector++;
                   5455:                       if (*selector != EOS)
                   5456:                         *cur++ = *selector++;
                   5457:                     }
                   5458:                   else
                   5459:                     *cur++ = *selector++;
                   5460:                 }
                   5461:               /* close the word */
                   5462:               *cur++ = EOS;
                   5463:               /* point to the class in sel[] if it's valid name */
                   5464:               if (deb[0] <= 64)
                   5465:                 {
                   5466:                   CSSPrintError ("Invalid class", deb);
                   5467:                   DoApply = FALSE;
                   5468:                 }
                   5469:               else
                   5470:                 {
                   5471:                   classes[0] = deb;
                   5472:                   specificity += 10;
                   5473:                   if (names[0] && !strcmp (names[0], "*"))
                   5474:                     names[0] = NULL;
                   5475:                 }
                   5476:             }
                   5477:           else if (*selector == ':')
                   5478:             {
                   5479:               selector++;
                   5480:               while (*selector != EOS && *selector != ',' &&
                   5481:                      *selector != '.' && *selector != ':' &&
                   5482:                      !TtaIsBlank (selector))
                   5483:                 *cur++ = *selector++;
                   5484:               /* close the word */
                   5485:               *cur++ = EOS;
                   5486:               /* point to the pseudoclass in sel[] if it's a valid name */
                   5487:               if (deb[0] <= 64)
                   5488:                 {
                   5489:                   CSSPrintError ("Invalid pseudoclass", deb);
                   5490:                   DoApply = FALSE;
                   5491:                 }
                   5492:               else
                   5493:                 {
                   5494:                   if (!strcmp (deb, "first-letter") ||
                   5495:                       !strcmp (deb, "first-line") ||
                   5496:                       !strcmp (deb, "hover") ||
                   5497:                       !strcmp (deb, "focus"))
                   5498:                     /* not supported */
                   5499:                     DoApply = FALSE;
                   5500:                   else
                   5501:                     specificity += 10;
                   5502:                   if (!strncmp (deb, "before", 6) || !strncmp (deb, "after", 5))
                   5503:                     pseudoclasses[0] = deb;
                   5504:                   else if (!strncmp (deb, "lang", 4))
                   5505:                     /* it's the lang pseudo-class */
                   5506:                     {
                   5507:                       if (deb[4] != '(' || deb[strlen(deb)-1] != ')')
                   5508:                         /* at least one paranthesis is missing. Error */
                   5509:                         {
                   5510:                           CSSPrintError ("Invalid :lang pseudoclass", deb);
                   5511:                           DoApply = FALSE;
                   5512:                         }
                   5513:                       else
                   5514:                         /* simulate selector [lang|="xxx"] if there is no
                   5515:                            attribute yet in the selector */
                   5516:                         if (!attrs[0])
                   5517:                           {
                   5518:                             deb[strlen(deb)-1] = EOS;
                   5519:                             deb[4] = EOS;
                   5520:                             attrmatch[0] = Txtsubstring;
                   5521:                             attrs[0] = deb;
                   5522:                             attrvals[0] = &deb[5];
                   5523:                           }
                   5524:                     }
                   5525:                   else
                   5526:                     pseudoclasses[0] = deb;
                   5527:                   if (names[0] && !strcmp (names[0], "*"))
                   5528:                     names[0] = NULL;
                   5529:                 }
                   5530:             }
                   5531:           else if (*selector == '#')
                   5532:             {
                   5533:               selector++;
                   5534:               while (*selector != EOS && *selector != ',' &&
                   5535:                      *selector != '.' && *selector != ':' &&
                   5536:                      *selector != '#' &&
                   5537:                      !TtaIsBlank (selector))
                   5538:                 *cur++ = *selector++;
                   5539:               /* close the word */
                   5540:               *cur++ = EOS;
                   5541:               /* point to the attribute in sel[] if it's valid name */
                   5542:               if (deb[0] <= 64)
                   5543:                 {
                   5544:                   CSSPrintError ("Invalid id", deb);
                   5545:                   DoApply = FALSE;
                   5546:                 }
                   5547:               else
                   5548:                 {
                   5549:                   if (ids[0] && strcmp(ids[0], deb))
                   5550:                     {
                   5551:                       CSSPrintError ("Too many ids", deb);
                   5552:                       DoApply = FALSE;
                   5553:                     }            
                   5554:                   else
                   5555:                     {
                   5556:                       ids[0] = deb;
                   5557:                       specificity += 100;
                   5558:                       if (names[0] && !strcmp (names[0], "*"))
                   5559:                         names[0] = NULL;
                   5560:                     }
                   5561:                 }
                   5562:             }
                   5563:           else if (*selector == '[')
                   5564:             {
                   5565:               selector++;
                   5566:               while (*selector != EOS && *selector != ']' &&
                   5567:                      *selector != '=' && *selector != '~' &&
                   5568:                      *selector != '|' && *selector != '^' &&
                   5569:                      *selector != '!')
                   5570:                 *cur++ = *selector++;
                   5571:               /* check matching */
                   5572:               if (*selector == '~')
                   5573:                 {
                   5574:                   attrmatch[0] = Txtword;
                   5575:                   selector++;
                   5576:                 }
                   5577:               else if (*selector == '|')
                   5578:                 {
                   5579:                   attrmatch[0] = Txtsubstring;
                   5580:                   selector++;
                   5581:                 }
                   5582:               else
                   5583:                 attrmatch[0] = Txtmatch;
                   5584:               /* close the word */
                   5585:               *cur++ = EOS;
                   5586:               /* point to the attribute in sel[] if it's valid name */
                   5587:               if (deb[0] <= 64)
                   5588:                 {
                   5589:                   CSSPrintError ("Invalid attribute", deb);
                   5590:                   DoApply = FALSE;
                   5591:                 }
                   5592:               else
                   5593:                 {
                   5594:                   attrs[0] = deb;
                   5595:                   specificity += 10;
                   5596:                 }
                   5597:               if (*selector == '=')
                   5598:                 {
                   5599:                   /* look for a value "xxxx" */
                   5600:                   selector++;
                   5601:                   if (*selector != '"')
                   5602:                     quoted = FALSE;
                   5603:                   else
                   5604:                     {
                   5605:                       quoted = TRUE;
                   5606:                       /* we are now parsing the attribute value */
                   5607:                       selector++;
                   5608:                     }
                   5609:                   deb = cur;
                   5610:                   while ((quoted &&
                   5611:                           (*selector != '"' ||
                   5612:                            (*selector == '"' && selector[-1] == '\\'))) ||
                   5613:                          (!quoted && *selector != ']'))
                   5614:                     {
                   5615:                       if (*selector == EOS)
                   5616:                         {
                   5617:                           CSSPrintError ("Invalid attribute value", deb);
                   5618:                           DoApply = FALSE;
                   5619:                         }
                   5620:                       else
                   5621:                         {
                   5622:                           if (attrmatch[0] == Txtword && TtaIsBlank (selector))
                   5623:                             {
                   5624:                               CSSPrintError ("No space allowed here: ", selector);
                   5625:                               DoApply = FALSE;
                   5626:                             }
                   5627:                           *cur++ = *selector;
                   5628:                         }
                   5629:                       selector++;
                   5630:                     }
                   5631:                   /* there is a value */
                   5632:                   if (quoted && *selector == '"')
                   5633:                     {
                   5634:                       selector++;
                   5635:                       quoted = FALSE;
                   5636:                     }
                   5637:                   if (*selector != ']')
                   5638:                     {
                   5639:                       CSSPrintError ("Invalid attribute value", deb);
                   5640:                       DoApply = FALSE;
                   5641:                     }
                   5642:                   else
                   5643:                     {
                   5644:                       *cur++ = EOS;
                   5645:                       attrvals[0] = deb;
                   5646:                       selector++;
                   5647:                     }
                   5648:                 }
                   5649:               /* end of the attribute */
                   5650:               else if (*selector != ']')
                   5651:                 {
                   5652:                   selector[1] = EOS;
                   5653:                   CSSPrintError ("Invalid attribute", selector);
                   5654:                   selector += 2;
                   5655:                   DoApply = FALSE;
                   5656:                 }
                   5657:               else
                   5658:                 {
                   5659:                   selector++;
                   5660:                   if (names[0] && !strcmp (names[0], "*"))
                   5661:                     names[0] = NULL;
                   5662:                 }
                   5663:             }
                   5664:           else
                   5665:             {
                   5666:               /* not supported selector */
                   5667:               while (*selector != EOS && *selector != ',' &&
                   5668:                      *selector != '.' && *selector != ':' &&
                   5669:                      !TtaIsBlank (selector))
                   5670:                 *cur++ = *selector++;
                   5671:               /* close the word */
                   5672:               *cur++ = EOS;
                   5673:               CSSPrintError ("Selector not supported:", deb);
                   5674:               DoApply = FALSE;     
                   5675:             }
                   5676:         }
1.1       cvs      5677: 
1.286     quint    5678:       skippedNL = NewLineSkipped;
1.82      cvs      5679:       selector = SkipBlanksAndComments (selector);
1.286     quint    5680:       NewLineSkipped = skippedNL;
                   5681: 
1.25      cvs      5682:       /* is it a multi-level selector? */
1.82      cvs      5683:       if (*selector == EOS)
1.327     vatton   5684:         /* end of the selector */
                   5685:         break;
1.82      cvs      5686:       else if (*selector == ',')
1.327     vatton   5687:         {
                   5688:           /* end of the current selector */
                   5689:           selector++;
                   5690:           skippedNL = NewLineSkipped;
                   5691:           next = SkipBlanksAndComments (selector);
                   5692:           NewLineSkipped = skippedNL;
                   5693:           if (*next == EOS)
                   5694:             /* nothing after the comma. Invalid selector */
                   5695:             {
                   5696:               /*CSSPrintError ("Syntax error:", selector);*/
                   5697:               return NULL;
                   5698:             }
                   5699:           break;
                   5700:         }
1.25      cvs      5701:       else
1.327     vatton   5702:         {
                   5703:           if (*selector == '>')
                   5704:             {
                   5705:               /* handle immediat parent as a simple parent */
                   5706:               selector++;
                   5707:               skippedNL = NewLineSkipped;
                   5708:               selector = SkipBlanksAndComments (selector);
                   5709:               NewLineSkipped = skippedNL;
                   5710:               rel[0] = RelImmediat;
                   5711:             }
                   5712:           else if (*selector == '+')
                   5713:             {
                   5714:               /* handle immediat parent as a simple parent */
                   5715:               selector++;
                   5716:               skippedNL = NewLineSkipped;
                   5717:               selector = SkipBlanksAndComments (selector);
                   5718:               NewLineSkipped = skippedNL;
                   5719:               rel[0] = RelPrevious;
                   5720:             }
                   5721:           /* shifts the list to make room for the new name */
                   5722:           max++; /* a new level in ancestor tables */
                   5723:           if (max == MAX_ANCESTORS)
                   5724:             /* abort the CSS parsing */
                   5725:             return (selector);
                   5726:           for (i = max; i > 0; i--)
                   5727:             {
                   5728:               names[i] = names[i - 1];
                   5729:               ids[i] = ids[i - 1];
                   5730:               classes[i] = classes[i - 1];
                   5731:               pseudoclasses[i] = pseudoclasses[i - 1];
                   5732:               attrs[i] = attrs[i - 1];
                   5733:               attrvals[i] = attrvals[i - 1];
                   5734:               attrmatch[i] = attrmatch[i - 1];
                   5735:               rel[i] = rel[i - 1];
                   5736:             }
                   5737:         }
1.1       cvs      5738:     }
                   5739: 
                   5740:   /* Now set up the context block */
1.25      cvs      5741:   i = 0;
                   5742:   k = 0;
                   5743:   j = 0;
1.91      cvs      5744:   /* default schema name */
1.119     vatton   5745:   ctxt->schema = NULL;
1.122     vatton   5746:   elType.ElSSchema = NULL;
                   5747:   schemaName = TtaGetSSchemaName(TtaGetDocumentSSchema (doc));
1.119     vatton   5748:   if (!strcmp (schemaName, "HTML"))
                   5749:     xmlType = XHTML_TYPE;
                   5750:   else if (!strcmp (schemaName, "MathML"))
                   5751:     xmlType = MATH_TYPE;
                   5752:   else if (!strcmp (schemaName, "SVG"))
                   5753:     xmlType = SVG_TYPE;
                   5754:   else if (!strcmp (schemaName, "XLink"))
                   5755:     xmlType = XLINK_TYPE;
                   5756:   else if (!strcmp (schemaName, "Annot"))
                   5757:     xmlType = ANNOT_TYPE;
                   5758:   else
                   5759:     xmlType = XML_TYPE;
1.256     vatton   5760:   while (i <= max && j < MAX_ANCESTORS)
1.25      cvs      5761:     {
                   5762:       if (names[i])
1.327     vatton   5763:         {
                   5764:           /* get the element type of this name in the current document */
                   5765:           if (xmlType == XML_TYPE)
                   5766:             /* it's a generic XML document. Check the main document schema */
                   5767:             {
                   5768:               elType.ElSSchema = TtaGetDocumentSSchema (doc);
                   5769:               TtaGetXmlElementType (names[i], &elType, &mappedName, doc);
                   5770:               if (!elType.ElTypeNum)
                   5771:                 {
                   5772:                   if (!strcmp (names[i], "*"))
                   5773:                     elType.ElTypeNum = HTML_EL_ANY_TYPE;
                   5774:                   else
                   5775:                     elType.ElSSchema = NULL;
                   5776:                 }
                   5777:             }
                   5778:           else
                   5779:             {
                   5780:               if (!strcmp (names[i], "*"))
                   5781:                 {
                   5782:                   elType.ElSSchema = TtaGetDocumentSSchema (doc);
                   5783:                   elType.ElTypeNum = HTML_EL_ANY_TYPE;
                   5784:                 }
                   5785:               else
                   5786:                 MapXMLElementType (xmlType, names[i], &elType, &mappedName, &c,
                   5787:                                    &level, doc);
                   5788:             }
                   5789:           if (i == 0)
                   5790:             {
                   5791:               if (elType.ElSSchema == NULL)
                   5792:                 {
                   5793:                   /* Selector not found: Search in the list of loaded schemas */
                   5794:                   TtaGetXmlElementType (names[i], &elType, NULL, doc);
                   5795:                   if (elType.ElSSchema)
                   5796:                     {
                   5797:                       /* the element type concerns an imported nature */
                   5798:                       schemaName = TtaGetSSchemaName(elType.ElSSchema);
                   5799:                       if (!strcmp (schemaName, "HTML"))
                   5800:                         {
                   5801:                           if (xmlType == XHTML_TYPE &&
                   5802:                               DocumentMeta[doc] && DocumentMeta[doc]->xmlformat)
                   5803:                             /* the selector was found but the case is not correct */
                   5804:                             elType.ElSSchema = NULL;
                   5805:                           else
                   5806:                             xmlType = XHTML_TYPE;
                   5807:                         }
                   5808:                       else if (!strcmp (schemaName, "MathML"))
                   5809:                         xmlType = MATH_TYPE;
                   5810:                       else if (!strcmp (schemaName, "SVG"))
                   5811:                         xmlType = SVG_TYPE;
                   5812:                       else if (!strcmp (schemaName, "XLink"))
                   5813:                         xmlType = XLINK_TYPE;
                   5814:                       else if (!strcmp (schemaName, "Annot"))
                   5815:                         xmlType = ANNOT_TYPE;
                   5816:                       else
                   5817:                         xmlType = XML_TYPE;
                   5818:                     }
1.118     vatton   5819: #ifdef XML_GENERIC
1.327     vatton   5820:                   else if (xmlType == XML_TYPE)
                   5821:                     {
                   5822:                       /* Creation of a new element type in the main schema */
                   5823:                       elType.ElSSchema = TtaGetDocumentSSchema (doc);
                   5824:                       TtaAppendXmlElement (names[i], &elType, &mappedName, doc);
                   5825:                     }
1.118     vatton   5826: #endif /* XML_GENERIC */
1.327     vatton   5827:                   else
                   5828:                     {
                   5829:                       if (xmlType != XHTML_TYPE)
                   5830:                         {
                   5831:                           MapXMLElementType (XHTML_TYPE, names[i], &elType,
                   5832:                                              &mappedName, &c, &level, doc);
                   5833:                           if (elType.ElSSchema)
                   5834:                             elType.ElSSchema = GetXHTMLSSchema (doc);
                   5835:                         }
                   5836:                       if (elType.ElSSchema == NULL && xmlType != MATH_TYPE)
                   5837:                         {
                   5838:                           MapXMLElementType (MATH_TYPE, names[i], &elType,
                   5839:                                              &mappedName, &c, &level, doc);
                   5840:                           if (elType.ElSSchema)
                   5841:                             elType.ElSSchema = GetMathMLSSchema (doc);
                   5842:                         }
                   5843:                       if (elType.ElSSchema == NULL && xmlType != SVG_TYPE)
                   5844:                         {
                   5845:                           MapXMLElementType (SVG_TYPE, names[i], &elType,
                   5846:                                              &mappedName, &c, &level, doc);
                   5847:                           if (elType.ElSSchema)
                   5848:                             elType.ElSSchema = GetSVGSSchema (doc);
                   5849:                         }
                   5850:                     }
                   5851:                 }
                   5852: 
                   5853:               if (elType.ElSSchema == NULL)
                   5854:                 /* cannot apply these CSS rules */
                   5855:                 DoApply = FALSE;
                   5856:               else
                   5857:                 {
                   5858:                   /* Store the element type */
                   5859:                   ctxt->type = elType.ElTypeNum;
                   5860:                   ctxt->name[0] = elType.ElTypeNum;
                   5861:                   ctxt->names_nb[0] = 0;
                   5862:                   ctxt->rel[0] = RelAncestor;
                   5863:                   ctxt->schema = elType.ElSSchema;
                   5864:                 }
                   5865:             }
                   5866:           else if (elType.ElTypeNum != 0)
                   5867:             {
                   5868:               /* look at the current context to see if the type is already
                   5869:                  stored */
                   5870:               j = 1;
                   5871:               while (j < k &&
                   5872:                      (ctxt->name[j] != elType.ElTypeNum ||
                   5873:                       ctxt->rel[j] != RelAncestor))
                   5874:                 j++;
                   5875:               if (j == k)
                   5876:                 {
                   5877:                   ctxt->name[j] = elType.ElTypeNum;
                   5878:                   if (j != 0)
                   5879:                     {
                   5880:                       ctxt->names_nb[j] = 1;
                   5881:                       ctxt->rel[j] = rel[i];
                   5882:                     }
                   5883:                 }
                   5884:               else
                   5885:                 /* increment the number of ancestor levels */
                   5886:                 ctxt->names_nb[j]++;
                   5887:             }
1.154     vatton   5888: #ifdef XML_GENERIC
1.327     vatton   5889:           else if (xmlType == XML_TYPE)
                   5890:             {
                   5891:               TtaGetXmlElementType (names[i], &elType, NULL, doc);
                   5892:               if (elType.ElTypeNum == 0)
                   5893:                 {
                   5894:                   /* Creation of a new element type in the main schema */
                   5895:                   elType.ElSSchema = TtaGetDocumentSSchema (doc);
                   5896:                   TtaAppendXmlElement (names[i], &elType, &mappedName, doc);
                   5897:                 }
                   5898:               if (elType.ElTypeNum != 0)
                   5899:                 {
                   5900:                   /* look at the current context to see if the type is already
                   5901:                      stored */
                   5902:                   j = 1;
                   5903:                   while (j < k &&
                   5904:                          (ctxt->name[j] != elType.ElTypeNum ||
                   5905:                           ctxt->rel[j] != RelAncestor))
                   5906:                     j++;
                   5907:                   if (j == k)
                   5908:                     {
                   5909:                       ctxt->name[j] = elType.ElTypeNum;
                   5910:                       if (j != 0)
                   5911:                         {
                   5912:                           ctxt->names_nb[j] = 1;
                   5913:                           ctxt->rel[j] = rel[i];
                   5914:                         }
                   5915:                       else
                   5916:                         ctxt->rel[j] = RelAncestor;
                   5917:                     }
                   5918:                   else
                   5919:                     /* increment the number of ancestor levels */
                   5920:                     ctxt->names_nb[j]++;
                   5921:                 }
                   5922:             }
1.154     vatton   5923: #endif /* XML_GENERIC */
1.327     vatton   5924:           else
                   5925:             j = k;
                   5926:         }
1.117     vatton   5927:       else
1.327     vatton   5928:         j = k;
1.1       cvs      5929: 
1.25      cvs      5930:       /* store attributes information */
                   5931:       if (classes[i])
1.327     vatton   5932:         {
                   5933:           ctxt->attrText[j] = classes[i];
                   5934:           if (xmlType == SVG_TYPE)
                   5935:             ctxt->attrType[j] = SVG_ATTR_class;
                   5936:           else if (xmlType == MATH_TYPE)
                   5937:             ctxt->attrType[j] = MathML_ATTR_class;
                   5938:           else if (xmlType == XHTML_TYPE)
                   5939:             ctxt->attrType[j] = HTML_ATTR_Class;
                   5940:           else
1.119     vatton   5941: #ifdef XML_GENERIC
1.327     vatton   5942:             ctxt->attrType[j] = XML_ATTR_class;
1.107     cvs      5943: #else /* XML_GENERIC */
1.327     vatton   5944:           ctxt->attrType[j] = HTML_ATTR_Class;
1.107     cvs      5945: #endif /* XML_GENERIC */
1.327     vatton   5946:           /* a "class" attribute on an element may contain several
                   5947:              words, one for each class it matches */
                   5948:           ctxt->attrMatch[j] = Txtword;
                   5949:           /* add a new entry */
                   5950:           /* update attrLevel */
                   5951:           ctxt->attrLevel[j] = i;
                   5952:           j++;
                   5953:         }
1.79      cvs      5954:       if (pseudoclasses[i])
1.327     vatton   5955:         {
                   5956:           ctxt->attrText[j] = pseudoclasses[i];
                   5957:           if (!strncmp (deb, "before", 6))
                   5958:             ctxt->pseudo = PbBefore;
                   5959:           else if (!strncmp (deb, "after", 5))
                   5960:             ctxt->pseudo = PbAfter;
                   5961:           else
                   5962:             {
                   5963:               if (xmlType == SVG_TYPE)
                   5964:                 ctxt->attrType[j] = SVG_ATTR_PseudoClass;
                   5965:               else if (xmlType == MATH_TYPE)
                   5966:                 ctxt->attrType[j] = MathML_ATTR_PseudoClass;
                   5967:               else if (xmlType == XHTML_TYPE)
                   5968:                 ctxt->attrType[j] = HTML_ATTR_PseudoClass;
                   5969:               else
1.119     vatton   5970: #ifdef XML_GENERIC
1.327     vatton   5971:                 ctxt->attrType[j] = XML_ATTR_PseudoClass;
1.107     cvs      5972: #else /* XML_GENERIC */
1.327     vatton   5973:               ctxt->attrType[j] = HTML_ATTR_PseudoClass;
1.107     cvs      5974: #endif /* XML_GENERIC */
1.327     vatton   5975:               ctxt->attrMatch[j] = Txtmatch;
                   5976:             }
                   5977:           /* add a new entry */
                   5978:           /* update attrLevel */
                   5979:           ctxt->attrLevel[j] = i;
                   5980:           j++;
                   5981:         }
1.79      cvs      5982:       if (ids[i])
1.327     vatton   5983:         {
                   5984:           ctxt->attrText[j] = ids[i];
                   5985:           if (xmlType == SVG_TYPE)
                   5986:             ctxt->attrType[j] = SVG_ATTR_id;
                   5987:           else if (xmlType == MATH_TYPE)
                   5988:             ctxt->attrType[j] = MathML_ATTR_id;
                   5989:           else if (xmlType == XHTML_TYPE)
                   5990:             ctxt->attrType[j] = HTML_ATTR_ID;
                   5991:           else
1.119     vatton   5992: #ifdef XML_GENERIC
1.327     vatton   5993:             ctxt->attrType[j] = XML_ATTR_xmlid;
1.107     cvs      5994: #else /* XML_GENERIC */
1.327     vatton   5995:           ctxt->attrType[j] = HTML_ATTR_ID;
1.107     cvs      5996: #endif /* XML_GENERIC */
1.327     vatton   5997:           ctxt->attrMatch[j] = Txtmatch;
                   5998:           /* add a new entry */
                   5999:           /* update attrLevel */
                   6000:           ctxt->attrLevel[j] = i;
                   6001:           j++;
                   6002:         }
1.79      cvs      6003:       if (attrs[i])
1.327     vatton   6004:         {
                   6005:           /* it's an attribute */
                   6006:           if (xmlType == XML_TYPE)
                   6007:             {
                   6008:               attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
                   6009:               TtaGetXmlAttributeType (attrs[i], &attrType, doc);
                   6010:               att = attrType.AttrTypeNum;
                   6011:             }
                   6012:           else
                   6013:             {
                   6014:               MapXMLAttribute (xmlType, attrs[i], names[i], &level, doc, &att);
                   6015:               if (ctxt->schema == NULL && att != 0)
                   6016:                 ctxt->schema = TtaGetDocumentSSchema (doc);
                   6017:             }
                   6018:           if (att == 0)
                   6019:             /* Attribute name not found: Search in the list of all loaded
                   6020:                schemas */
                   6021:             {
                   6022:               attrType.AttrSSchema = NULL;
                   6023:               TtaGetXmlAttributeType (attrs[i], &attrType, doc);
                   6024:               att = attrType.AttrTypeNum;
                   6025:             }
                   6026:           if (att == DummyAttribute && !strcmp (schemaName, "HTML"))
                   6027:             /* it's the "type" attribute for an "input" element. In the tree
                   6028:                it's represented by the element type, not by an attribute */
                   6029:             att = 0;
                   6030:           ctxt->attrType[j] = att;
                   6031:           ctxt->attrMatch[j] = attrmatch[i];
                   6032:           attrType.AttrSSchema = ctxt->schema;
                   6033:           attrType.AttrTypeNum = att;
                   6034:           if (i == 0 && att == 0 && ctxt->schema == NULL)
                   6035:             {
                   6036:               /* Not found -> search in the list of loaded schemas */
                   6037:               attrType.AttrSSchema = NULL;
                   6038:               TtaGetXmlAttributeType (attrs[i], &attrType, doc);
                   6039:               ctxt->attrType[j] = attrType.AttrTypeNum;
                   6040:               if (attrType.AttrSSchema)
                   6041:                 /* the element type concerns an imported nature */
                   6042:                 schemaName = TtaGetSSchemaName(attrType.AttrSSchema);
1.119     vatton   6043: #ifdef XML_GENERIC
1.327     vatton   6044:               else if (xmlType == XML_TYPE)
                   6045:                 {
                   6046:                   /* The attribute is not yet present in the tree */
                   6047:                   /* Create a new global attribute */
                   6048:                   attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
                   6049:                   TtaAppendXmlAttribute (attrs[i], &attrType, doc);
                   6050:                 }
1.119     vatton   6051: #endif /* XML_GENERIC */
                   6052: 
1.327     vatton   6053:               if (attrType.AttrSSchema == NULL)
                   6054:                 /* cannot apply these CSS rules */
                   6055:                 DoApply = FALSE;
                   6056:               else if (elType.ElSSchema)
                   6057:                 ctxt->schema = elType.ElSSchema;
                   6058:               else
                   6059:                 ctxt->schema = attrType.AttrSSchema;
                   6060:             }
                   6061:           /* check the attribute type */
                   6062:           if (!strcmp (schemaName, "HTML"))
                   6063:             xmlType = XHTML_TYPE;
                   6064:           else if (!strcmp (schemaName, "MathML"))
                   6065:             xmlType = MATH_TYPE;
                   6066:           else if (!strcmp (schemaName, "SVG"))
                   6067:             xmlType = SVG_TYPE;
                   6068:           else if (!strcmp (schemaName, "XLink"))
                   6069:             xmlType = XLINK_TYPE;
                   6070:           else if (!strcmp (schemaName, "Annot"))
                   6071:             xmlType = ANNOT_TYPE;
                   6072:           else
                   6073:             xmlType = XML_TYPE;
                   6074:           kind = TtaGetAttributeKind (attrType);
                   6075:           if (kind == 0 && attrvals[i])
                   6076:             {
                   6077:               /* enumerated value */
                   6078:               MapXMLAttributeValue (xmlType, attrvals[i], &attrType, &kind);
                   6079:               /* store the attribute value */
                   6080:               ctxt->attrText[j] = (char *) kind;
                   6081:             }
                   6082:           else
                   6083:             ctxt->attrText[j] = attrvals[i];
                   6084:           /* update attrLevel */
                   6085:           ctxt->attrLevel[j] = i;
                   6086:           j++;
                   6087:         }
1.25      cvs      6088:       i++;
1.117     vatton   6089:       /* add a new entry */
                   6090:       k++;
1.129     vatton   6091:       if (k < j)
1.327     vatton   6092:         k = j;
1.119     vatton   6093:       if (i == 1 && ctxt->schema == NULL)
1.327     vatton   6094:         /* use the document schema */
                   6095:         ctxt->schema = TtaGetDocumentSSchema (doc);
1.1       cvs      6096:     }
1.312     quint    6097:   ctxt->important = FALSE;
1.117     vatton   6098:   /* set the selector specificity */
                   6099:   ctxt->cssSpecificity = specificity;
1.25      cvs      6100:   /* Get the schema name of the main element */
1.119     vatton   6101:   schemaName = TtaGetSSchemaName (ctxt->schema);
                   6102:   isHTML = (strcmp (schemaName, "HTML") == 0);
1.206     vatton   6103:   tsch = GetPExtension (doc, ctxt->schema, css, link);
1.217     vatton   6104:   skippedNL = NewLineSkipped;
1.119     vatton   6105:   if (tsch && cssRule)
1.317     vatton   6106:     {
                   6107:       if (css)
1.327     vatton   6108:         {
                   6109:           /* point the right URL for loaded images */
                   6110:           saveURL = css->url;
                   6111:           css->url = url;
                   6112:         }
1.317     vatton   6113:       else
1.327     vatton   6114:         saveURL = NULL;
                   6115:       ParseCSSRule (NULL, tsch, (PresentationContext) ctxt, cssRule, css, isHTML);
1.317     vatton   6116:       if (css)
1.327     vatton   6117:         /* restore previous url */
                   6118:         css->url = saveURL;
1.317     vatton   6119:     }
1.116     vatton   6120:   /* future CSS rules should apply */
                   6121:   DoApply = TRUE;
1.217     vatton   6122:   if (selector)
                   6123:     NewLineSkipped = skippedNL;
1.1       cvs      6124:   return (selector);
                   6125: }
                   6126: 
                   6127: /*----------------------------------------------------------------------
1.206     vatton   6128:   ParseStyleDeclaration: parse a style declaration stored in the style
                   6129:   element of a document                       
                   6130:   We expect the style string to be of the form:                   
                   6131:   .pinky, .awful { color: pink; font-family: helvetica }        
1.231     vatton   6132:   The parameter css points to the current CSS context.
                   6133:   The parameter link points to the link element.
                   6134:   The parameter url gives the URL of the parsed style sheet.
1.1       cvs      6135:   ----------------------------------------------------------------------*/
1.206     vatton   6136: static void ParseStyleDeclaration (Element el, char *cssRule, Document doc,
1.327     vatton   6137:                                    CSSInfoPtr css, Element link, char *url,
                   6138:                                    ThotBool destroy)
1.1       cvs      6139: {
1.79      cvs      6140:   GenericContext      ctxt;
                   6141:   char               *decl_end;
                   6142:   char               *sel_end;
                   6143:   char               *selector;
1.1       cvs      6144: 
                   6145:   /* separate the selectors string */
1.82      cvs      6146:   cssRule = SkipBlanksAndComments (cssRule);
1.1       cvs      6147:   decl_end = cssRule;
1.82      cvs      6148:   while (*decl_end != EOS && *decl_end != '{')
1.286     quint    6149:     {
                   6150:       if (*decl_end == EOL)
1.327     vatton   6151:         NewLineSkipped++;
1.286     quint    6152:       decl_end++;
                   6153:     }
1.82      cvs      6154:   if (*decl_end == EOS)
1.86      cvs      6155:     {
1.168     vatton   6156:       CSSPrintError ("Invalid selector", cssRule);
1.86      cvs      6157:       return;
                   6158:     }
1.1       cvs      6159:   /* verify and clean the selector string */
                   6160:   sel_end = decl_end - 1;
1.82      cvs      6161:   while (*sel_end == SPACE || *sel_end == BSPACE ||
1.327     vatton   6162:          *sel_end == EOL || *sel_end == CR)
1.1       cvs      6163:     sel_end--;
                   6164:   sel_end++;
1.82      cvs      6165:   *sel_end = EOS;
1.1       cvs      6166:   selector = cssRule;
                   6167: 
                   6168:   /* now, deal with the content ... */
                   6169:   decl_end++;
                   6170:   cssRule = decl_end;
1.137     vatton   6171:   decl_end = &cssRule[strlen (cssRule) - 1];
                   6172:   if (*decl_end != '{')
                   6173:     *decl_end = EOS;
1.1       cvs      6174:   /*
                   6175:    * parse the style attribute string and install the corresponding
                   6176:    * presentation attributes on the new element
                   6177:    */
                   6178:   ctxt = TtaGetGenericStyleContext (doc);
                   6179:   if (ctxt == NULL)
                   6180:     return;
                   6181:   ctxt->destroy = destroy;
1.207     vatton   6182:   /* first use of the context */
                   6183:   ctxt->uses = 1;
1.197     vatton   6184:   while (selector && *selector != EOS)
1.231     vatton   6185:     selector = ParseGenericSelector (selector, cssRule, ctxt, doc, css,
1.327     vatton   6186:                                      link, url);
1.207     vatton   6187:   /* check if the context can be freed */
                   6188:   ctxt->uses -= 1;
                   6189:   if (ctxt->uses == 0)
                   6190:     /* no image loading */
                   6191:     TtaFreeMemory (ctxt);
1.1       cvs      6192: }
                   6193: 
                   6194: /************************************************************************
                   6195:  *                                                                     *  
                   6196:  *     EVALUATION FUNCTIONS / CASCADING AND OVERLOADING                *
                   6197:  *                                                                     *  
                   6198:  ************************************************************************/
                   6199: 
                   6200: /*----------------------------------------------------------------------
1.327     vatton   6201:   IsImplicitClassName: return wether the Class name is an        
                   6202:   implicit one, eg "H1" or "H2 EM" meaning it's a GI name       
                   6203:   or an HTML context name.                                      
1.1       cvs      6204:   ----------------------------------------------------------------------*/
1.248     gully    6205: int IsImplicitClassName (char *class_, Document doc)
1.1       cvs      6206: {
1.327     vatton   6207:   char         name[200];
                   6208:   char        *cur = name;
                   6209:   char        *first; 
                   6210:   char         save;
                   6211:   SSchema      schema;
                   6212: 
                   6213:   /* make a local copy */
                   6214:   strncpy (name, class_, 199);
                   6215:   name[199] = 0;
                   6216: 
                   6217:   /* loop looking if each word is a GI */
                   6218:   while (*cur != 0)
                   6219:     {
                   6220:       first = cur;
                   6221:       cur = SkipWord (cur);
                   6222:       save = *cur;
                   6223:       *cur = 0;
                   6224:       schema = NULL;
                   6225:       if (MapGI (first, &schema, doc) == -1)
                   6226:         {
                   6227:           return (0);
                   6228:         }
                   6229:       *cur = save;
                   6230:       cur = SkipBlanksAndComments (cur);
                   6231:     }
                   6232:   return (1);
1.1       cvs      6233: }
                   6234: 
                   6235: /************************************************************************
                   6236:  *                                                                     *  
1.114     quint    6237:  *  Functions needed for support of HTML: translate to CSS equivalent   *
1.1       cvs      6238:  *                                                                     *  
                   6239:  ************************************************************************/
                   6240: 
                   6241: /*----------------------------------------------------------------------
1.327     vatton   6242:   HTMLSetBackgroundColor:
1.1       cvs      6243:   ----------------------------------------------------------------------*/
1.264     vatton   6244: void HTMLSetBackgroundColor (Document doc, Element el, int specificity,
1.327     vatton   6245:                              char *color)
1.1       cvs      6246: {
1.327     vatton   6247:   char             css_command[100];
1.1       cvs      6248: 
1.327     vatton   6249:   sprintf (css_command, "background-color: %s", color);
                   6250:   ParseHTMLSpecificStyle (el, css_command, doc, specificity, FALSE);
1.1       cvs      6251: }
                   6252: 
                   6253: /*----------------------------------------------------------------------
1.327     vatton   6254:   HTMLSetForegroundColor:                                        
1.1       cvs      6255:   ----------------------------------------------------------------------*/
1.264     vatton   6256: void HTMLSetForegroundColor (Document doc, Element el, int specificity,
1.327     vatton   6257:                              char *color)
1.1       cvs      6258: {
1.327     vatton   6259:   char           css_command[100];
1.1       cvs      6260: 
1.327     vatton   6261:   sprintf (css_command, "color: %s", color);
                   6262:   ParseHTMLSpecificStyle (el, css_command, doc, specificity, FALSE);
1.1       cvs      6263: }
                   6264: 
                   6265: /*----------------------------------------------------------------------
1.327     vatton   6266:   HTMLResetBackgroundColor:                                      
1.1       cvs      6267:   ----------------------------------------------------------------------*/
1.97      vatton   6268: void HTMLResetBackgroundColor (Document doc, Element el)
1.1       cvs      6269: {
1.327     vatton   6270:   char           css_command[100];
1.1       cvs      6271: 
1.327     vatton   6272:   sprintf (css_command, "background: red");
                   6273:   ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1       cvs      6274: }
                   6275: 
                   6276: /*----------------------------------------------------------------------
1.327     vatton   6277:   HTMLResetBackgroundImage:                                      
1.1       cvs      6278:   ----------------------------------------------------------------------*/
1.97      vatton   6279: void HTMLResetBackgroundImage (Document doc, Element el)
1.1       cvs      6280: {
1.327     vatton   6281:   char           css_command[1000];
1.1       cvs      6282: 
1.327     vatton   6283:   sprintf (css_command, "background-image: url(xx); background-repeat: repeat");
                   6284:   ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1       cvs      6285: }
                   6286: 
                   6287: /*----------------------------------------------------------------------
1.327     vatton   6288:   HTMLResetForegroundColor:                                      
1.1       cvs      6289:   ----------------------------------------------------------------------*/
1.97      vatton   6290: void HTMLResetForegroundColor (Document doc, Element el)
1.1       cvs      6291: {
1.327     vatton   6292:   char           css_command[100];
1.1       cvs      6293: 
1.327     vatton   6294:   /* it's not necessary to well know the current color but it must be valid */
                   6295:   sprintf (css_command, "color: red");
                   6296:   ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1       cvs      6297: }
                   6298: 
                   6299: /*----------------------------------------------------------------------
1.327     vatton   6300:   HTMLSetAlinkColor:                                             
1.1       cvs      6301:   ----------------------------------------------------------------------*/
1.208     vatton   6302: void HTMLSetAlinkColor (Document doc, Element el, char *color)
1.1       cvs      6303: {
1.327     vatton   6304:   char           css_command[100];
1.1       cvs      6305: 
1.327     vatton   6306:   sprintf (css_command, ":link { color: %s }", color);
                   6307:   ApplyCSSRules (el, css_command, doc, FALSE);
1.1       cvs      6308: }
                   6309: 
                   6310: /*----------------------------------------------------------------------
1.327     vatton   6311:   HTMLSetAactiveColor:                                           
1.1       cvs      6312:   ----------------------------------------------------------------------*/
1.208     vatton   6313: void HTMLSetAactiveColor (Document doc, Element el, char *color)
1.1       cvs      6314: {
1.327     vatton   6315:   char           css_command[100];
1.1       cvs      6316: 
1.327     vatton   6317:   sprintf (css_command, ":active { color: %s }", color);
                   6318:   ApplyCSSRules (el, css_command, doc, FALSE);
1.1       cvs      6319: }
                   6320: 
                   6321: /*----------------------------------------------------------------------
1.327     vatton   6322:   HTMLSetAvisitedColor:                                          
1.1       cvs      6323:   ----------------------------------------------------------------------*/
1.208     vatton   6324: void HTMLSetAvisitedColor (Document doc, Element el, char *color)
1.1       cvs      6325: {
1.327     vatton   6326:   char           css_command[100];
1.1       cvs      6327: 
1.327     vatton   6328:   sprintf (css_command, ":visited { color: %s }", color);
                   6329:   ApplyCSSRules (el, css_command, doc, FALSE);
1.1       cvs      6330: }
                   6331: 
                   6332: /*----------------------------------------------------------------------
1.327     vatton   6333:   HTMLResetAlinkColor:                                           
1.1       cvs      6334:   ----------------------------------------------------------------------*/
1.208     vatton   6335: void HTMLResetAlinkColor (Document doc, Element el)
1.1       cvs      6336: {
1.327     vatton   6337:   char           css_command[100];
1.1       cvs      6338: 
1.327     vatton   6339:   sprintf (css_command, ":link { color: red }");
                   6340:   ApplyCSSRules (el, css_command, doc, TRUE);
1.1       cvs      6341: }
                   6342: 
                   6343: /*----------------------------------------------------------------------
1.327     vatton   6344:   HTMLResetAactiveColor:                                                 
1.1       cvs      6345:   ----------------------------------------------------------------------*/
1.208     vatton   6346: void HTMLResetAactiveColor (Document doc, Element el)
1.1       cvs      6347: {
1.327     vatton   6348:   char           css_command[100];
1.1       cvs      6349: 
1.327     vatton   6350:   sprintf (css_command, ":active { color: red }");
                   6351:   ApplyCSSRules (el, css_command, doc, TRUE);
1.1       cvs      6352: }
                   6353: 
                   6354: /*----------------------------------------------------------------------
1.327     vatton   6355:   HTMLResetAvisitedColor:                                        
1.1       cvs      6356:   ----------------------------------------------------------------------*/
1.208     vatton   6357: void HTMLResetAvisitedColor (Document doc, Element el)
1.1       cvs      6358: {
1.327     vatton   6359:   char           css_command[100];
1.1       cvs      6360: 
1.327     vatton   6361:   sprintf (css_command, ":visited { color: red }");
                   6362:   ApplyCSSRules (el, css_command, doc, TRUE);
1.1       cvs      6363: }
                   6364: 
                   6365: /*----------------------------------------------------------------------
1.206     vatton   6366:   ApplyCSSRules: parse a CSS Style description stored in the header of
                   6367:   a HTML document.
1.1       cvs      6368:   ----------------------------------------------------------------------*/
1.79      cvs      6369: void ApplyCSSRules (Element el, char *cssRule, Document doc, ThotBool destroy)
1.1       cvs      6370: {
1.206     vatton   6371:   CSSInfoPtr          css;
                   6372:   PInfoPtr            pInfo;
1.207     vatton   6373:   ThotBool            loadcss;
                   6374: 
                   6375:   /* check if we have to load CSS */
                   6376:   TtaGetEnvBoolean ("LOAD_CSS", &loadcss);
                   6377:   if (!loadcss)
                   6378:     return;
1.1       cvs      6379: 
1.206     vatton   6380:   css = SearchCSS (doc, NULL, el, &pInfo);
1.1       cvs      6381:   if (css == NULL)
1.209     vatton   6382:     {
                   6383:       /* create the document css context */
                   6384:       css = AddCSS (doc, doc, CSS_DOCUMENT_STYLE, CSS_ALL, NULL, NULL, el);
                   6385:       pInfo = css->infos[doc];
                   6386:     }
1.206     vatton   6387:   else if (pInfo == NULL)
                   6388:     /* create the entry into the css context */
                   6389:     pInfo = AddInfoCSS (doc, css, CSS_DOCUMENT_STYLE, CSS_ALL, el);
1.209     vatton   6390:   if (pInfo->PiEnabled)
1.231     vatton   6391:     ParseStyleDeclaration (el, cssRule, doc, css, el, NULL, destroy); 
1.1       cvs      6392: }
                   6393: 
                   6394: /*----------------------------------------------------------------------
1.327     vatton   6395:   ReadCSSRules:  is the front-end function called by the document parser
                   6396:   when detecting a <style type="text/css"> indicating it's the
                   6397:   beginning of a CSS fragment or when reading a file .css.
1.1       cvs      6398:   
1.327     vatton   6399:   The CSS parser has to handle <!-- ... --> constructs used to
                   6400:   prevent prehistoric browser from displaying the CSS as a text
                   6401:   content. It will stop on any sequence "<x" where x is different
                   6402:   from ! and will return x as to the caller. Theorically x should
                   6403:   be equal to / for the </style> end of style.
                   6404:   The parameter doc gives the document tree that contains CSS information.
                   6405:   The parameter docRef gives the document to which CSS are to be applied.
                   6406:   This function uses the current css context or creates it. It's able
                   6407:   to work on the given buffer or call GetNextChar to read the parsed
                   6408:   file.
                   6409:   The parameter url gives the URL of the parsed style sheet.
                   6410:   The parameter numberOfLinesRead gives the number of lines already
                   6411:   read in the file.
                   6412:   The parameter withUndo indicates whether the changes made in the document
                   6413:   structure and content have to be registered in the Undo queue or not.
1.1       cvs      6414:   ----------------------------------------------------------------------*/
1.133     vatton   6415: char ReadCSSRules (Document docRef, CSSInfoPtr css, char *buffer, char *url,
1.327     vatton   6416:                    int numberOfLinesRead, ThotBool withUndo,
                   6417:                    Element link)
1.1       cvs      6418: {
1.6       cvs      6419:   DisplayMode         dispMode;
1.206     vatton   6420:   CSSInfoPtr          refcss = NULL;
1.321     vatton   6421:   CSSmedia            css_media = CSS_ALL;
1.206     vatton   6422:   PInfoPtr            pInfo;
1.321     vatton   6423:   char                c;
1.138     vatton   6424:   char               *cssRule, *base, *saveDocURL, *ptr;
1.19      cvs      6425:   int                 index;
1.1       cvs      6426:   int                 CSSindex;
1.327     vatton   6427:   int                 CSScomment;
1.1       cvs      6428:   int                 import;
                   6429:   int                 openRule;
1.93      vatton   6430:   int                 newlines;
1.14      cvs      6431:   ThotBool            HTMLcomment;
1.102     vatton   6432:   ThotBool            toParse, eof, quoted;
1.234     vatton   6433:   ThotBool            ignore, media, page;
                   6434:   ThotBool            noRule, ignoreImport, fontface;
1.1       cvs      6435: 
1.327     vatton   6436:   CSScomment = MAX_CSS_LENGTH;
1.1       cvs      6437:   HTMLcomment = FALSE;
                   6438:   CSSindex = 0;
                   6439:   toParse = FALSE;
                   6440:   noRule = FALSE;
1.234     vatton   6441:   media = FALSE;
1.88      cvs      6442:   ignoreImport = FALSE;
1.234     vatton   6443:   ignore = FALSE;
                   6444:   page = FALSE;
                   6445:   quoted = FALSE;
                   6446:   fontface = FALSE;
1.1       cvs      6447:   eof = FALSE;
                   6448:   openRule = 0;
1.234     vatton   6449:   import = MAX_CSS_LENGTH;
1.82      cvs      6450:   c = SPACE;
1.1       cvs      6451:   index = 0;
1.134     vatton   6452:   base = NULL;
1.310     vatton   6453:   /* entering the CSS parsing */
1.311     vatton   6454:   Style_parsing++;
1.93      vatton   6455:   /* number of new lines parsed */
                   6456:   newlines = 0;
1.6       cvs      6457:   /* avoid too many redisplay */
                   6458:   dispMode = TtaGetDisplayMode (docRef);
                   6459:   if (dispMode == DisplayImmediately)
                   6460:     TtaSetDisplayMode (docRef, DeferredDisplay);
1.18      cvs      6461: 
                   6462:   /* look for the CSS context */
                   6463:   if (css == NULL)
1.206     vatton   6464:     css = SearchCSS (docRef, NULL, link, &pInfo);
1.207     vatton   6465:   else
                   6466:     pInfo = css->infos[docRef];
1.18      cvs      6467:   if (css == NULL)
1.206     vatton   6468:     {
                   6469:       css = AddCSS (docRef, docRef, CSS_DOCUMENT_STYLE, CSS_ALL, NULL, NULL, link);
                   6470:       pInfo = css->infos[docRef];
                   6471:     }
                   6472:   else if (pInfo == NULL)
                   6473:     pInfo = AddInfoCSS (docRef, css, CSS_DOCUMENT_STYLE, CSS_ALL, link);
1.174     vatton   6474:   /* look for the CSS descriptor that points to the extension schema */
                   6475:   refcss = css;
1.224     vatton   6476:   if (pInfo && pInfo->PiCategory == CSS_IMPORT)
1.173     cvs      6477:     {
1.206     vatton   6478:       while (refcss &&
1.327     vatton   6479:              refcss->infos[docRef] && refcss->infos[docRef]->PiCategory == CSS_IMPORT)
                   6480:         refcss = refcss->NextCSS;
1.206     vatton   6481:       if (refcss)
1.327     vatton   6482:         pInfo = refcss->infos[docRef];
1.173     cvs      6483:     }
                   6484: 
1.144     quint    6485:   /* register parsed CSS file and the document to which CSS are to be applied*/
1.86      cvs      6486:   ParsedDoc = docRef;
1.133     vatton   6487:   if (url)
                   6488:     DocURL = url;
1.86      cvs      6489:   else
                   6490:     /* the CSS source in within the document itself */
                   6491:     DocURL = DocumentURLs[docRef];
                   6492:   LineNumber = numberOfLinesRead + 1;
1.93      vatton   6493:   NewLineSkipped = 0;
1.217     vatton   6494:   newlines = 0;
1.82      cvs      6495:   while (CSSindex < MAX_CSS_LENGTH && c != EOS && !eof)
                   6496:     {
                   6497:       c = buffer[index++];
                   6498:       eof = (c == EOS);
                   6499:       CSSbuffer[CSSindex] = c;
1.327     vatton   6500:       if (CSScomment == MAX_CSS_LENGTH ||
1.326     vatton   6501:           c == '*' || c == '/' || c == '<' || c == EOL)
1.327     vatton   6502:         {
                   6503:           /* we're not within a comment or we're parsing * or / */
                   6504:           switch (c)
                   6505:             {
                   6506:             case '@': /* perhaps an import primitive */
                   6507:               if (!fontface && !page && !quoted)
                   6508:                 import = CSSindex;
                   6509:               break;
                   6510:             case ';':
                   6511:               if (!quoted && !media && import != MAX_CSS_LENGTH)
                   6512:                 { 
                   6513:                   if (strncasecmp (&CSSbuffer[import+1], "import", 6))
                   6514:                     /* it's not an import */
                   6515:                     import = MAX_CSS_LENGTH;
                   6516:                   /* save the text */
                   6517:                   noRule = TRUE;
                   6518:                 }
                   6519:               break;
                   6520:             case '*':
                   6521:               if (!quoted && CSScomment == MAX_CSS_LENGTH && CSSindex > 0 &&
                   6522:                   CSSbuffer[CSSindex - 1] == '/')
                   6523:                 /* start a comment */
                   6524:                 CSScomment = CSSindex - 1;
                   6525:               break;
                   6526:             case '/':
                   6527:               if (!quoted && CSSindex > 1 && CSScomment != MAX_CSS_LENGTH &&
                   6528:                   CSSbuffer[CSSindex - 1] == '*')
                   6529:                 {
                   6530:                   while (CSSindex > 0 && CSSindex >= CSScomment)
                   6531:                     {
                   6532:                       if ( CSSbuffer[CSSindex] == EOL)
                   6533:                         {
                   6534:                           LineNumber ++;
                   6535:                           newlines --;
                   6536:                         }
                   6537:                       CSSindex--;
                   6538:                     }
                   6539:                   CSSindex = CSScomment - 1; /* will be incremented later */
                   6540:                   CSScomment = MAX_CSS_LENGTH;
                   6541:                   /* clean up the buffer */
                   6542:                   if (newlines && CSSindex > 0)
                   6543:                     while (CSSindex > 0 &&
                   6544:                            (CSSbuffer[CSSindex] == SPACE ||
                   6545:                             CSSbuffer[CSSindex] == BSPACE ||
                   6546:                             CSSbuffer[CSSindex] == EOL ||
                   6547:                             CSSbuffer[CSSindex] == TAB ||
                   6548:                             CSSbuffer[CSSindex] == __CR__))
                   6549:                       {
                   6550:                         if ( CSSbuffer[CSSindex] == EOL)
                   6551:                           {
                   6552:                             LineNumber ++;
                   6553:                             newlines --;
                   6554:                           }
                   6555:                         CSSindex--;
                   6556:                       }
                   6557:                 }
                   6558:               else if (!fontface && !page && !quoted &&
                   6559:                        CSScomment == MAX_CSS_LENGTH && CSSindex > 0 &&
                   6560:                        CSSbuffer[CSSindex - 1] ==  '<')
                   6561:                 {
                   6562:                   /* this is the closing tag ! */
                   6563:                   CSSindex -= 2; /* remove </ from the CSS string */
                   6564:                   noRule = TRUE;
                   6565:                 } 
                   6566:               break;
                   6567:             case '<':
                   6568:               if (!fontface && !page && !quoted &&
                   6569:                   CSScomment == MAX_CSS_LENGTH)
                   6570:                 {
                   6571:                   /* only if we're not parsing a comment */
                   6572:                   c = buffer[index++];
                   6573:                   eof = (c == EOS);
                   6574:                   if (c == '!')
                   6575:                     {
                   6576:                       /* CSS within an HTML comment */
                   6577:                       HTMLcomment = TRUE;
                   6578:                       CSSindex++;
                   6579:                       CSSbuffer[CSSindex] = c;
                   6580:                     }
                   6581:                   else if (c == EOS)
                   6582:                     CSSindex++;
                   6583:                 }
                   6584:               break;
                   6585:             case '-':
                   6586:               if (!fontface && !page && !quoted &&
                   6587:                   CSSindex > 0 && CSSbuffer[CSSindex - 1] == '-' &&
                   6588:                   HTMLcomment)
                   6589:                 /* CSS within an HTML comment */
                   6590:                 noRule = TRUE;
                   6591:               break;
                   6592:             case '>':
                   6593:               if (!fontface && !page && !quoted && HTMLcomment)
                   6594:                 noRule = TRUE;
                   6595:               break;
                   6596:             case ' ':
                   6597:               if (!quoted && import != MAX_CSS_LENGTH && openRule == 0)
                   6598:                 media = !strncasecmp (&CSSbuffer[import+1], "media", 5);
                   6599:               break;
                   6600:             case '{':
                   6601:               if (!quoted)
                   6602:                 {
                   6603:                   openRule++;
                   6604:                   if (import != MAX_CSS_LENGTH)
                   6605:                     {
                   6606:                       if (openRule == 1 && media)
                   6607:                         {
                   6608:                           /* is it the screen concerned? */
                   6609:                           CSSbuffer[CSSindex+1] = EOS;
                   6610:                           css_media = CheckMediaCSS (&CSSbuffer[import+7]);
                   6611:                           if (TtaIsPrinting ())
                   6612:                             ignore = (css_media != CSS_ALL && css_media != CSS_PRINT);
                   6613:                           else
                   6614:                             ignore = (css_media != CSS_ALL && css_media != CSS_SCREEN);
                   6615:                           noRule = TRUE;
                   6616:                         }
                   6617:                       else if (!strncasecmp (&CSSbuffer[import+1], "page", 4))
                   6618:                         {
                   6619:                           page = TRUE;
                   6620:                           noRule = TRUE;
                   6621:                         }
                   6622:                       else if (!strncasecmp (&CSSbuffer[import+1], "font-face", 9))
                   6623:                         {
                   6624:                           fontface = TRUE;
                   6625:                           noRule = TRUE;
                   6626:                         }
                   6627:                     }
                   6628:                 }
                   6629:               break;
                   6630:             case '}':
                   6631:               if (!quoted)
                   6632:                 {
                   6633:                   openRule--;
                   6634:                   if (page)
                   6635:                     {
                   6636:                       noRule = TRUE;
                   6637:                       page = FALSE; /* close the page section */
                   6638:                     }
                   6639:                   else if (fontface)
                   6640:                     {
                   6641:                       noRule = TRUE;
                   6642:                       fontface = FALSE; /* close the fontface section */
                   6643:                     }
                   6644:                   else if (openRule == 0 && import != MAX_CSS_LENGTH)
                   6645:                     {
                   6646:                       import = MAX_CSS_LENGTH;
                   6647:                       noRule = TRUE;
                   6648:                       ignore = FALSE;
                   6649:                       media = FALSE;
                   6650:                     }
                   6651:                   else
                   6652:                     toParse = TRUE;
                   6653:                 }
                   6654:               break;
                   6655:             case '"':
                   6656:               if (quoted)
                   6657:                 {
                   6658:                   if (CSSbuffer[CSSindex - 1] != '\\')
                   6659:                     quoted = FALSE;
                   6660:                 }
                   6661:               else
                   6662:                 quoted = TRUE;
                   6663:               break;
                   6664:             default:
                   6665:               if (c == EOL)
                   6666:                 {
                   6667:                   newlines++;
                   6668:                 }
                   6669:               break;
                   6670:             }
1.82      cvs      6671:         }
1.93      vatton   6672:       else if (c == EOL)
1.327     vatton   6673:         {
                   6674:           LineNumber++;
                   6675:           c = CR;
                   6676:         }
1.234     vatton   6677: 
1.82      cvs      6678:       if (c != CR)
1.327     vatton   6679:         CSSindex++;
1.82      cvs      6680: 
                   6681:       if (CSSindex >= MAX_CSS_LENGTH && CSScomment < MAX_CSS_LENGTH)
1.327     vatton   6682:         /* we're still parsing a comment: remove the text comment */
                   6683:         CSSindex = CSScomment;
1.82      cvs      6684: 
                   6685:       if (CSSindex >= MAX_CSS_LENGTH || toParse || noRule)
1.327     vatton   6686:         {
                   6687:           CSSbuffer[CSSindex] = EOS;
                   6688:           /* parse a not empty string */
                   6689:           if (CSSindex > 0)
                   6690:             {
1.50      cvs      6691:               /* apply CSS rule if it's not just a saving of text */
1.234     vatton   6692:               if (!noRule && !ignore)
1.327     vatton   6693:                 {
                   6694:                   /* future import rules must be ignored */
                   6695:                   ignoreImport = TRUE;
                   6696:                   NewLineSkipped = 0;
                   6697:                   ParseStyleDeclaration (NULL, CSSbuffer, docRef, refcss,
                   6698:                                          pInfo->PiLink, url, FALSE);
                   6699:                   LineNumber += newlines;
                   6700:                   newlines = 0;
                   6701:                 }
1.82      cvs      6702:               else if (import != MAX_CSS_LENGTH &&
1.327     vatton   6703:                        !strncasecmp (&CSSbuffer[import+1], "import", 6))
                   6704:                 {
                   6705:                   /* import section */
                   6706:                   cssRule = &CSSbuffer[import+7];
                   6707:                   cssRule = TtaSkipBlanks (cssRule);
                   6708:                   /* save the current line number */
                   6709:                   newlines += LineNumber;
                   6710:                   if (!strncasecmp (cssRule, "url", 3))
                   6711:                     {
1.50      cvs      6712:                       cssRule = &cssRule[3];
1.82      cvs      6713:                       cssRule = TtaSkipBlanks (cssRule);
                   6714:                       if (*cssRule == '(')
1.327     vatton   6715:                         {
                   6716:                           cssRule++;
                   6717:                           cssRule = TtaSkipBlanks (cssRule);
                   6718:                           quoted = (*cssRule == '"' || *cssRule == '\'');
                   6719:                           if (quoted)
                   6720:                             cssRule++;
                   6721:                           base = cssRule;
                   6722:                           while (*cssRule != EOS && *cssRule != ')')
                   6723:                             cssRule++;
                   6724:                           if (quoted)
                   6725:                             {
                   6726:                               /* isolate the file name */
                   6727:                               cssRule[-1] = EOS;
                   6728:                               quoted = FALSE;
                   6729:                             }
                   6730:                           else
                   6731:                             {
                   6732:                               /* remove extra spaces */
                   6733:                               if (cssRule[-1] == SPACE)
                   6734:                                 {
                   6735:                                   *cssRule = SPACE;
                   6736:                                   cssRule--;
                   6737:                                   while (cssRule[-1] == SPACE)
                   6738:                                     cssRule--;
                   6739:                                 }
                   6740:                             }
                   6741:                           *cssRule = EOS;
                   6742:                         }
                   6743:                     }
                   6744:                   else if (*cssRule == '"')
                   6745:                     {
                   6746:                       /*
                   6747:                         Do we have to accept single quotes?
                   6748:                         Double quotes are accepted here.
                   6749:                         Escaped quotes are not handled. See function SkipQuotedString
                   6750:                       */
                   6751:                       cssRule++;
                   6752:                       cssRule = TtaSkipBlanks (cssRule);
                   6753:                       base = cssRule;
                   6754:                       while (*cssRule != EOS &&
                   6755:                              (*cssRule != '"' ||
                   6756:                               (*cssRule == '"' && cssRule[-1] == '\\')))
                   6757:                         cssRule++;
                   6758:                       /* isolate the file name */
                   6759:                       *cssRule = EOS;
                   6760:                     }
                   6761:                   /* check if a media is defined */
                   6762:                   cssRule++;
                   6763:                   cssRule = TtaSkipBlanks (cssRule);
                   6764:                   if (*cssRule != ';')
                   6765:                     {
                   6766:                       css_media = CheckMediaCSS (cssRule);
                   6767:                       if (TtaIsPrinting ())
                   6768:                         ignoreImport = (css_media != CSS_ALL && css_media != CSS_PRINT);
                   6769:                       else
                   6770:                         ignoreImport = (css_media != CSS_ALL && css_media != CSS_SCREEN);
                   6771:                     }
                   6772:                   if (!ignoreImport)
                   6773:                     {
                   6774:                       /* save the displayed URL when an error is reported */
                   6775:                       saveDocURL = DocURL;
                   6776:                       ptr = TtaStrdup (base);
                   6777:                       /* get the CSS URI in UTF-8 */
                   6778:                       /*ptr = ReallocUTF8String (ptr, docRef);*/
                   6779:                       LoadStyleSheet (base, docRef, (Element) css, css,
                   6780:                                       url, pInfo->PiMedia,
                   6781:                                       pInfo->PiCategory == CSS_USER_STYLE);
                   6782:                       /* restore the displayed URL when an error is reported */
                   6783:                       DocURL = saveDocURL;
                   6784:                       TtaFreeMemory (ptr);
                   6785:                     }
                   6786:                   /* restore the number of lines */
                   6787:                   LineNumber = newlines;
                   6788:                   newlines = 0;
                   6789:                   NewLineSkipped = 0;
                   6790:                   import = MAX_CSS_LENGTH;
                   6791:                 }
                   6792:               else
                   6793:                 {
                   6794:                   LineNumber += newlines;
                   6795:                   newlines = 0;
                   6796:                 }
                   6797:             }
                   6798:           toParse = FALSE;
                   6799:           noRule = FALSE;
                   6800:           CSSindex = 0;
1.50      cvs      6801:         }
1.82      cvs      6802:     }
1.310     vatton   6803:   /* closing the CSS parsing */
1.311     vatton   6804:   Style_parsing--;
1.328   ! vatton   6805:   if (RedisplayImages == 0 && RedisplayBGImage)
1.310     vatton   6806:     {
1.311     vatton   6807:       /* CSS parsing finishes after a BG image was loaded */
1.310     vatton   6808:       RedisplayBGImage = FALSE;
1.311     vatton   6809:       RedisplayDoc = 0;
1.313     vatton   6810:       //printf ("ReadCSS Show BGimages\n");
1.310     vatton   6811:       TtaSetDisplayMode (docRef, NoComputedDisplay);
                   6812:       TtaSetDisplayMode (docRef, dispMode);
                   6813:     }
1.311     vatton   6814:   else if (dispMode == DisplayImmediately)
                   6815:     /* restore the display mode */
                   6816:     TtaSetDisplayMode (docRef, dispMode);
1.86      cvs      6817: 
                   6818:   /* Prepare the context for style attributes */
                   6819:   DocURL = DocumentURLs[docRef];
                   6820:   LineNumber = -1;
1.1       cvs      6821:   return (c);
                   6822: }

Webmaster