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

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

Webmaster