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

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

Webmaster