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

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

Webmaster