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

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

Webmaster