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

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

Webmaster