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

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

Webmaster