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

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

Webmaster