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

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

Webmaster