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

1.1       cvs         1: /*
                      2:  *
1.437   ! quint       3:  *  (c) COPYRIGHT INRIA and W3C, 1996-2010
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"
1.406     quint      38: #include "HTMLtable_f.h"
1.1       cvs        39: #include "UIcss_f.h"
                     40: #include "css_f.h"
1.24      cvs        41: #include "fetchHTMLname_f.h"
1.91      cvs        42: #include "fetchXMLname_f.h"
1.1       cvs        43: #include "html2thot_f.h"
1.91      cvs        44: #include "init_f.h"
1.1       cvs        45: #include "styleparser_f.h"
1.424     quint      46: #include "SVGbuilder_f.h"
1.366     vatton     47: #include "wxdialogapi_f.h"
1.1       cvs        48: 
                     49: #define MAX_BUFFER_LENGTH 200
                     50: /*
                     51:  * A PropertyParser is a function used to parse  the
                     52:  * description substring associated to a given style attribute
1.59      cvs        53:  * e.g.: "red" for a color attribute or "12pt bold helvetica"
1.1       cvs        54:  * for a font attribute.
                     55:  */
1.79      cvs        56: typedef char *(*PropertyParser) (Element element,
1.327     vatton     57:                                  PSchema tsch,
                     58:                                  PresentationContext context,
                     59:                                  char *cssRule,
                     60:                                  CSSInfoPtr css,
                     61:                                  ThotBool isHTML);
1.1       cvs        62: 
                     63: /* Description of the set of CSS properties supported */
                     64: typedef struct CSSProperty
1.327     vatton     65: {
1.405     kia        66:   const char          *name;
1.327     vatton     67:   PropertyParser       parsing_function;
                     68: }
1.1       cvs        69: CSSProperty;
                     70: 
1.86      cvs        71: static int           LineNumber = -1; /* The line where the error occurs */
1.93      vatton     72: static int           NewLineSkipped = 0;
1.311     vatton     73: static int           RedisplayImages = 0; /* number of BG images loading */
                     74: static int           Style_parsing = 0; /* > 0 when parsing a set of CSS rules */
1.360     vatton     75: static char         *ImportantPos = NULL;
1.310     vatton     76: static ThotBool      RedisplayBGImage = FALSE; /* TRUE when a BG image is inserted */
1.116     vatton     77: static ThotBool      DoApply = TRUE;
1.366     vatton     78: static ThotBool      All_sides = FALSE; // TRUE when "boder valus must be displayed
1.437   ! quint      79: static char          CSSbuffer[MAX_CSS_LENGTH + 1];
1.366     vatton     80: 
1.1       cvs        81: 
                     82: /*----------------------------------------------------------------------
1.327     vatton     83:   SkipWord:                                                  
1.1       cvs        84:   ----------------------------------------------------------------------*/
1.79      cvs        85: static char *SkipWord (char *ptr)
1.1       cvs        86: {
1.402     vatton     87:   while (isalnum((int)*ptr) || *ptr == '-' || *ptr == '#' || *ptr == '%' || *ptr == '.')
1.168     vatton     88:     ptr++;
1.1       cvs        89:   return (ptr);
                     90: }
                     91: 
                     92: /*----------------------------------------------------------------------
1.327     vatton     93:   SkipBlanksAndComments:                                                  
1.13      cvs        94:   ----------------------------------------------------------------------*/
1.82      cvs        95: char *SkipBlanksAndComments (char *ptr)
1.13      cvs        96: {
1.93      vatton     97:   /* skip spaces */
1.155     cheyroul   98:   while (*ptr == SPACE ||
1.327     vatton     99:          *ptr == BSPACE ||
                    100:          *ptr == EOL ||
                    101:          *ptr == TAB ||
                    102:          *ptr == __CR__)
1.93      vatton    103:     {
                    104:       if (*ptr == EOL)
1.327     vatton    105:         /* increment the number of newline skipped */
                    106:         NewLineSkipped++;
1.93      vatton    107:       ptr++;
                    108:     }
1.399     vatton    109:   while (ptr[0] == '/' && ptr[1] == '*')
1.13      cvs       110:     {
                    111:       /* look for the end of the comment */
                    112:       ptr = &ptr[2];
                    113:       while (ptr[0] != EOS && (ptr[0] != '*' || ptr[1] != '/'))
1.327     vatton    114:         ptr++;
1.13      cvs       115:       if (ptr[0] != EOS)
1.327     vatton    116:         ptr = &ptr[2];
1.93      vatton    117:       /* skip spaces */
                    118:       while (*ptr == SPACE || *ptr == BSPACE || *ptr == EOL ||
1.327     vatton    119:              *ptr == TAB || *ptr == __CR__)
                    120:         {
                    121:           if (*ptr == EOL)
                    122:             /* increment the number of newline skipped */
                    123:             NewLineSkipped++;
                    124:           ptr++;
                    125:         }
1.13      cvs       126:     }
                    127:   return (ptr);
                    128: }
                    129: 
1.366     vatton    130: 
                    131: /*----------------------------------------------------------------------
                    132:   Number of values
                    133:   ----------------------------------------------------------------------*/
                    134: static int NumberOfValues (char *ptr)
                    135: {
                    136:   int n = 0;
1.402     vatton    137:   while (*ptr != EOS && *ptr != ';' &&  *ptr != '}' &&  *ptr != ',')
1.366     vatton    138:     {
                    139:       ptr = SkipBlanksAndComments (ptr);
                    140:       n++;
                    141:       ptr = SkipWord (ptr);
                    142:     }
                    143:   return n;
                    144: }
                    145: 
1.49      cvs       146: /*----------------------------------------------------------------------
1.327     vatton    147:   SkipQuotedString
1.1       cvs       148:   ----------------------------------------------------------------------*/
1.79      cvs       149: static char *SkipQuotedString (char *ptr, char quote)
1.1       cvs       150: {
1.14      cvs       151:   ThotBool     stop;
1.1       cvs       152: 
                    153:   stop = FALSE;
                    154:   while (!stop)
                    155:     {
1.327     vatton    156:       if (*ptr == quote)
                    157:         {
                    158:           ptr++;
                    159:           stop = TRUE;
                    160:         }
                    161:       else if (*ptr == EOS)
                    162:         stop = TRUE;
                    163:       else if (*ptr == '\\')
                    164:         /* escape character */
                    165:         {
                    166:           ptr++;
1.82      cvs       167:           if ((*ptr >= '0' && *ptr <= '9') || (*ptr >= 'A' && *ptr <= 'F') ||
1.327     vatton    168:               (*ptr >= 'a' && *ptr <= 'f'))
                    169:             {
                    170:               ptr++;
                    171:               if ((*ptr >= '0' && *ptr <= '9') || (*ptr >= 'A' && *ptr <= 'F') ||
                    172:                   (*ptr >= 'a' && *ptr <= 'f'))
                    173:                 ptr++;
                    174:             }
                    175:           else
                    176:             ptr++;
                    177:         }
                    178:       else
                    179:         ptr++;
1.1       cvs       180:     }
                    181:   return (ptr);
                    182: }
                    183: 
                    184: /*----------------------------------------------------------------------
1.327     vatton    185:   CSSPrintError
                    186:   print the error message msg on stderr.
1.436     quint     187:   When the line is 0 ask expat the current line number
1.86      cvs       188:   ----------------------------------------------------------------------*/
1.389     vatton    189: static void CSSPrintError (const char *msg, const char *value)
1.86      cvs       190: {
1.419     vatton    191:   if (!IgnoreErrors && !DoDialog && !TtaIsPrinting () && ParsedDoc > 0)
1.86      cvs       192:     {
                    193:       if (!ErrFile)
1.327     vatton    194:         {
                    195:           if (OpenParsingErrors (ParsedDoc) == FALSE)
                    196:             return;
                    197:         }
1.86      cvs       198: 
1.308     vatton    199:       /* check if a CSS error file shoulb be updated too */
                    200:       if (ParsedCSS > 0 && !CSSErrFile)
1.327     vatton    201:         OpenParsingErrors (ParsedCSS);
1.308     vatton    202: 
1.348     vatton    203:       if (Error_DocURL)
1.327     vatton    204:         {
1.348     vatton    205:           fprintf (ErrFile, "\n*** Errors/warnings in %s\n", Error_DocURL);
1.327     vatton    206:           /* set to NULL as long as the CSS file doesn't change */
1.348     vatton    207:           Error_DocURL = NULL;
1.327     vatton    208:         }
1.89      cvs       209:       CSSErrorsFound = TRUE;
1.86      cvs       210:       if (LineNumber < 0)
1.347     quint     211:         {
                    212:           if (value)
                    213:             fprintf (ErrFile, "  In style attribute, %s \"%s\"\n", msg, value);
                    214:           else
                    215:             fprintf (ErrFile, "  In style attribute, %s\n", msg);
                    216:         }
1.86      cvs       217:       else
1.327     vatton    218:         {
1.347     quint     219:           if (value)
                    220:             fprintf (ErrFile, "@  line %d: %s \"%s\"\n",
                    221:                      LineNumber+NewLineSkipped, msg, value);
                    222:           else
                    223:             fprintf (ErrFile, "@  line %d: %s\n", LineNumber+NewLineSkipped,
                    224:                      msg);
1.327     vatton    225:           if (CSSErrFile)
1.347     quint     226:             {
                    227:               if (value)
                    228:                 fprintf (CSSErrFile, "@  line %d: %s \"%s\"\n",
                    229:                          LineNumber+NewLineSkipped, msg, value);
                    230:               else
                    231:                 fprintf (CSSErrFile, "@  line %d: %s\n",
                    232:                          LineNumber+NewLineSkipped, msg);
                    233:             }
1.327     vatton    234:         }
1.86      cvs       235:     }
                    236: }
                    237: 
1.168     vatton    238: /*----------------------------------------------------------------------
1.327     vatton    239:   CSSParseError
                    240:   print the error message msg on stderr.
1.168     vatton    241:   ----------------------------------------------------------------------*/
1.389     vatton    242: static void CSSParseError (const char *msg, const char *value, char *endvalue)
1.168     vatton    243: {
1.230     quint     244:   char        c = EOS;
1.168     vatton    245: 
                    246:   if (endvalue)
                    247:     {
                    248:       /* close the string here */
                    249:       c = *endvalue;
                    250:       *endvalue = EOS;
                    251:     }
                    252:   CSSPrintError (msg, value);
                    253:   if (endvalue)
                    254:     *endvalue = c;
                    255: }
                    256: 
1.288     vatton    257: /*----------------------------------------------------------------------
1.342     vatton    258:   SkipString move to the end of the string
                    259:   ----------------------------------------------------------------------*/
                    260: static char *SkipString (char *ptr)
                    261: {
                    262:   char        c = *ptr;
                    263: 
                    264:   ptr++;
                    265:   while (*ptr != EOS &&
                    266:          (*ptr != c || (*ptr == c && ptr[-1] == '\\')))
                    267:     ptr++;
                    268:   return ptr;
                    269: }
                    270: 
                    271: /*----------------------------------------------------------------------
1.327     vatton    272:   CSSCheckEndValue
                    273:   print an error message if another character is found
1.288     vatton    274:   ----------------------------------------------------------------------*/
1.405     kia       275: static char *CSSCheckEndValue (char *cssRule, char *endvalue, const char *msg)
1.288     vatton    276: {
                    277:   char        c = EOS;
                    278:   if (*endvalue != EOS && *endvalue != SPACE && *endvalue != '/' &&
1.316     quint     279:       *endvalue != ';' && *endvalue != '}' && *endvalue != EOL && 
                    280:       *endvalue != TAB && *endvalue !=  __CR__)
1.288     vatton    281:     {
                    282:       while (*endvalue != EOS && *endvalue != SPACE && *endvalue != '/' &&
1.327     vatton    283:              *endvalue != ';' && *endvalue != '}' && *endvalue != EOL &&
                    284:              *endvalue != TAB && *endvalue !=  __CR__)
1.342     vatton    285:         {
                    286:           if (*endvalue == '"' || *endvalue == '\'')
                    287:             endvalue = SkipString (endvalue);
                    288:           if (*endvalue != EOS)
                    289:             endvalue++;
                    290:         }
1.288     vatton    291:       /* close the string here */
                    292:       c = *endvalue;
                    293:       *endvalue = EOS;
                    294:       CSSPrintError (msg, cssRule);
                    295:       *endvalue = c;
                    296:     }
                    297:   return endvalue;
                    298: }
                    299: 
1.89      cvs       300: 
1.86      cvs       301: /*----------------------------------------------------------------------
1.327     vatton    302:   SkipProperty skips a property and display and error message
1.86      cvs       303:   ----------------------------------------------------------------------*/
1.234     vatton    304: static char *SkipProperty (char *ptr, ThotBool reportError)
1.86      cvs       305: {
                    306:   char       *deb;
                    307:   char        c;
1.404     vatton    308:   ThotBool    warn;
1.86      cvs       309: 
1.404     vatton    310:   // check if Amaya should report CSS warnings
                    311:   TtaGetEnvBoolean ("CSS_WARN", &warn);
                    312:   if (!warn)
                    313:     reportError = FALSE;
1.86      cvs       314:   deb = ptr;
1.431     quint     315:   while (*ptr != EOS && *ptr != ';' && *ptr != '}')
1.133     vatton    316:     {
1.342     vatton    317:       if (*ptr == '"' || *ptr == '\'')
                    318:         ptr = SkipString (ptr);
                    319:       if (*ptr != EOS)
                    320:         ptr++;
1.133     vatton    321:     }
1.95      cvs       322:   /* print the skipped property */
1.86      cvs       323:   c = *ptr;
1.386     vatton    324:   if (*ptr != EOS)
                    325:     *ptr = EOS;
1.366     vatton    326:   if (DoDialog)
                    327:     DisplayStyleValue ("", deb, ptr);
                    328:   else if (reportError && *deb != EOS &&
                    329:            strncasecmp (deb, "azimuth", 7) &&
                    330:            strncasecmp (deb, "border-collapse", 15) &&
                    331:            strncasecmp (deb, "border-spacing", 14) &&
                    332:            strncasecmp (deb, "caption-side", 12) &&
                    333:            strncasecmp (deb, "clip", 4) &&
                    334:            strncasecmp (deb, "cue-after", 9) &&
                    335:            strncasecmp (deb, "cue-before", 10) &&
                    336:            strncasecmp (deb, "cue", 3) &&
                    337:            strncasecmp (deb, "cursor", 6) &&
                    338:            strncasecmp (deb, "elevation", 9) &&
                    339:            strncasecmp (deb, "empty-cells", 11) &&
                    340:            strncasecmp (deb, "font-strech", 11) &&
                    341:            strncasecmp (deb, "letter-spacing", 14) &&
                    342:            strncasecmp (deb, "marker-offset", 12) &&
                    343:            strncasecmp (deb, "orphans", 7) &&
                    344:            strncasecmp (deb, "outline-color", 13) &&
                    345:            strncasecmp (deb, "outline-style", 13) &&
                    346:            strncasecmp (deb, "outline-width", 13) &&
                    347:            strncasecmp (deb, "outline", 7) &&
                    348:            strncasecmp (deb, "overflow", 8) &&
                    349:            strncasecmp (deb, "pause-after", 11) &&
                    350:            strncasecmp (deb, "pause-before", 12) &&
                    351:            strncasecmp (deb, "pause", 5) &&
                    352:            strncasecmp (deb, "quotes", 6) &&
                    353:            strncasecmp (deb, "richness", 8) &&
                    354:            strncasecmp (deb, "speech-rate", 11) &&
                    355:            strncasecmp (deb, "speak-header", 12) &&
                    356:            strncasecmp (deb, "speak-punctuation", 17) &&
                    357:            strncasecmp (deb, "speak-numeral", 13) &&
                    358:            strncasecmp (deb, "speak", 5) &&
                    359:            strncasecmp (deb, "pitch-range", 11) &&
                    360:            strncasecmp (deb, "pitch", 5) &&
                    361:            strncasecmp (deb, "stress", 6) &&
                    362:            strncasecmp (deb, "table-layout", 12) &&
                    363:            strncasecmp (deb, "text-shadow", 11) &&
                    364:            strncasecmp (deb, "voice-family", 12) &&
                    365:            strncasecmp (deb, "volume", 6) &&
                    366:            strncasecmp (deb, "widows", 6))
1.205     quint     367:     CSSPrintError ("CSS property ignored:", deb);
1.386     vatton    368:   if (c != EOS)
                    369:     *ptr = c;
1.86      cvs       370:   return (ptr);
                    371: }
                    372: 
                    373: /*----------------------------------------------------------------------
1.327     vatton    374:   SkipValue
                    375:   skips the value and display an error message if msg is not NULL
1.1       cvs       376:   ----------------------------------------------------------------------*/
1.405     kia       377: static char *SkipValue (const char *msg, char *ptr)
1.1       cvs       378: {
1.86      cvs       379:   char       *deb;
                    380:   char        c;
                    381: 
                    382:   deb = ptr;
1.387     quint     383:   while (*ptr != EOS && *ptr != ';' && *ptr != '}' && *ptr != '\n')
1.133     vatton    384:     {
1.342     vatton    385:       if (*ptr == '"' || *ptr == '\'')
                    386:         ptr = SkipString (ptr);
                    387:       if (*ptr != EOS)
                    388:         ptr++;
1.133     vatton    389:     }
1.95      cvs       390:   /* print the skipped property */
1.86      cvs       391:   c = *ptr;
1.397     vatton    392:   if (c != EOS)
                    393:     *ptr = EOS;
1.168     vatton    394:   if (msg && *deb != EOS && *deb != ',')
                    395:     CSSPrintError (msg, deb);
1.397     vatton    396:   if (c != EOS)
                    397:     *ptr = c;
1.1       cvs       398:   return (ptr);
                    399: }
                    400: 
                    401: /*----------------------------------------------------------------------
1.327     vatton    402:   ParseNumber:                                                  
                    403:   parse a number and returns the corresponding value.
1.1       cvs       404:   ----------------------------------------------------------------------*/
1.79      cvs       405: char *ParseNumber (char *cssRule, PresentationValue *pval)
1.1       cvs       406: {
                    407:   int                 val = 0;
                    408:   int                 minus = 0;
                    409:   int                 valid = 0;
                    410:   int                 f = 0;
1.14      cvs       411:   ThotBool            real = FALSE;
1.1       cvs       412: 
1.184     vatton    413:   pval->typed_data.unit = UNIT_REL;
1.1       cvs       414:   pval->typed_data.real = FALSE;
1.82      cvs       415:   cssRule = SkipBlanksAndComments (cssRule);
                    416:   if (*cssRule == '-')
1.1       cvs       417:     {
                    418:       minus = 1;
                    419:       cssRule++;
1.82      cvs       420:       cssRule = SkipBlanksAndComments (cssRule);
1.1       cvs       421:     }
1.387     quint     422:   else if (*cssRule == '+')
1.1       cvs       423:     {
                    424:       cssRule++;
1.82      cvs       425:       cssRule = SkipBlanksAndComments (cssRule);
1.1       cvs       426:     }
                    427: 
1.82      cvs       428:   while ((*cssRule >= '0') && (*cssRule <= '9'))
1.1       cvs       429:     {
                    430:       val *= 10;
1.82      cvs       431:       val += *cssRule - '0';
1.1       cvs       432:       cssRule++;
                    433:       valid = 1;
                    434:     }
                    435: 
1.82      cvs       436:   if (*cssRule == '.')
1.1       cvs       437:     {
                    438:       real = TRUE;
                    439:       f = val;
                    440:       val = 0;
                    441:       cssRule++;
                    442:       /* keep only 3 digits */
1.82      cvs       443:       if (*cssRule >= '0' && *cssRule <= '9')
1.327     vatton    444:         {
                    445:           val = (*cssRule - '0') * 100;
                    446:           cssRule++;
                    447:           if (*cssRule >= '0' && *cssRule <= '9')
                    448:             {
                    449:               val += (*cssRule - '0') * 10;
                    450:               cssRule++;
                    451:               if ((*cssRule >= '0') && (*cssRule <= '9'))
                    452:                 {
                    453:                   val += *cssRule - '0';
                    454:                   cssRule++;
                    455:                 }
                    456:             }
                    457: 
                    458:           while (*cssRule >= '0' && *cssRule <= '9')
                    459:             cssRule++;
                    460:           valid = 1;
                    461:         }
1.1       cvs       462:     }
                    463: 
                    464:   if (!valid)
                    465:     {
1.184     vatton    466:       pval->typed_data.unit = UNIT_INVALID;
1.1       cvs       467:       pval->typed_data.value = 0;
                    468:     }
                    469:   else
                    470:     {
                    471:       pval->typed_data.real = real;
                    472:       if (real)
1.327     vatton    473:         {
                    474:           if (minus)
                    475:             pval->typed_data.value = -(f * 1000 + val);
                    476:           else
                    477:             pval->typed_data.value = f * 1000 + val;
                    478:         }
1.1       cvs       479:       else
1.327     vatton    480:         {
                    481:           if (minus)
                    482:             pval->typed_data.value = -val;
                    483:           else
                    484:             pval->typed_data.value = val;
                    485:         }
1.64      cvs       486:     }
                    487:   return (cssRule);
                    488: }
1.195     vatton    489: 
1.155     cheyroul  490: /*----------------------------------------------------------------------
1.407     vatton    491:   ParseCSSUnit a number followed by a CSS Unit and returns the corresponding      
1.327     vatton    492:   value and its unit.                                           
1.64      cvs       493:   ----------------------------------------------------------------------*/
1.82      cvs       494: char *ParseCSSUnit (char *cssRule, PresentationValue *pval)
1.64      cvs       495: {
1.368     vatton    496:   char               *p;
1.64      cvs       497:   unsigned int        uni;
                    498: 
1.184     vatton    499:   pval->typed_data.unit = UNIT_REL;
1.64      cvs       500:   cssRule = ParseNumber (cssRule, pval);
1.184     vatton    501:   if (pval->typed_data.unit == UNIT_INVALID)
1.387     quint     502:     /* it does not start with a valid number */
1.327     vatton    503:     cssRule = SkipWord (cssRule);
1.64      cvs       504:   else
                    505:     {
1.369     quint     506:       /* is there a space after the number? */
1.368     vatton    507:       p = cssRule;
1.82      cvs       508:       cssRule = SkipBlanksAndComments (cssRule);
1.368     vatton    509:       if (p == cssRule)
1.369     quint     510:         /* no space */
1.368     vatton    511:         p = NULL;
1.369     quint     512:       else
                    513:         /* a space is here. restore the pointer */
                    514:         cssRule = p;
1.231     vatton    515:       uni = 0;
                    516:       while (CSSUnitNames[uni].sign)
1.327     vatton    517:         {
                    518:           if (!strncasecmp (CSSUnitNames[uni].sign, cssRule,
                    519:                             strlen (CSSUnitNames[uni].sign)))
1.369     quint     520:             /* this is a correct unit */
1.327     vatton    521:             {
                    522:               pval->typed_data.unit = CSSUnitNames[uni].unit;
1.368     vatton    523:               if (p)
1.369     quint     524:                 /* there was a space before the unit. Syntax error */
1.368     vatton    525:                 pval->typed_data.unit = UNIT_INVALID;
1.327     vatton    526:               return (cssRule + strlen (CSSUnitNames[uni].sign));
                    527:             }
                    528:           else
                    529:             uni++;
                    530:         }
1.369     quint     531:       /* not in the list of accepted units */
1.184     vatton    532:       pval->typed_data.unit = UNIT_BOX;
1.1       cvs       533:     }
                    534:   return (cssRule);
                    535: }
                    536: 
1.43      cvs       537: /*----------------------------------------------------------------------
1.327     vatton    538:   ParseClampedUnit:                                                  
                    539:   parse a CSS Unit substring and returns the corresponding value and unit.
                    540:   [0,1]
1.239     vatton    541:   ----------------------------------------------------------------------*/
                    542: char *ParseClampedUnit (char *cssRule, PresentationValue *pval)
                    543: {
1.251     vatton    544:   char           *p;
                    545: 
                    546:   p = cssRule;
1.239     vatton    547:   cssRule = ParseNumber (cssRule, pval);
1.301     vatton    548:   if (*cssRule != EOS && *cssRule != SPACE && *cssRule != ';' && *cssRule != '}')
1.418     quint     549:     /* the value contains something after the number. Invalid */
1.239     vatton    550:     {
1.251     vatton    551:       cssRule++;
1.239     vatton    552:       pval->typed_data.unit = UNIT_REL;
                    553:       if (pval->typed_data.value > 100)
1.327     vatton    554:         pval->typed_data.value = 1000;
1.239     vatton    555:       else
1.327     vatton    556:         pval->typed_data.value *= 10;
1.251     vatton    557:       CSSParseError ("Invalid value", p, cssRule);
1.239     vatton    558:     }
                    559:   else
1.418     quint     560:     /* it's a number. Check its value */
1.239     vatton    561:     {
                    562:       pval->typed_data.unit = UNIT_REL;
                    563:       if (pval->typed_data.real)
1.327     vatton    564:         pval->typed_data.real = FALSE;
1.239     vatton    565:       else if (pval->typed_data.value > 1)
1.327     vatton    566:         {
                    567:           pval->typed_data.value = 1000;
                    568:           CSSParseError ("Invalid value", p, cssRule);
                    569:         }
1.251     vatton    570:       else if (pval->typed_data.value < 0)
1.327     vatton    571:         {
                    572:           pval->typed_data.value = 0;
                    573:           CSSParseError ("Invalid value", p, cssRule);
                    574:         }
1.239     vatton    575:       else
1.327     vatton    576:         pval->typed_data.value *= 1000;
1.239     vatton    577:     }
                    578:   pval->data = pval->typed_data.value;
                    579:   return (cssRule);
                    580: }
                    581: 
                    582: 
                    583: /*----------------------------------------------------------------------
1.327     vatton    584:   ParseABorderValue                                       
1.43      cvs       585:   ----------------------------------------------------------------------*/
1.288     vatton    586: static char *ParseABorderValue (char *cssRule, PresentationValue *border)
1.43      cvs       587: {
1.288     vatton    588:   char             *ptr = cssRule;
1.168     vatton    589: 
1.43      cvs       590:   /* first parse the attribute string */
1.319     quint     591:   border->typed_data.value = 0;
                    592:   border->typed_data.unit = UNIT_INVALID;
                    593:   border->typed_data.real = FALSE;
                    594:   if (!strncasecmp (cssRule, "thin", 4))
                    595:     {
                    596:       border->typed_data.unit = UNIT_PX;
                    597:       border->typed_data.value = 1;
                    598:       cssRule += 4;
                    599:     }
                    600:   else if (!strncasecmp (cssRule, "medium", 6))
                    601:     {
                    602:       border->typed_data.unit = UNIT_PX;
                    603:       border->typed_data.value = 3;
                    604:       cssRule += 6;
                    605:     }
                    606:   else if (!strncasecmp (cssRule, "thick", 5))
                    607:     {
                    608:       border->typed_data.unit = UNIT_PX;
                    609:       border->typed_data.value = 5;
                    610:       cssRule += 5;
                    611:     }
                    612:   else if (!strncasecmp (cssRule, "inherit", 7))
                    613:     {
                    614:       border->typed_data.unit = VALUE_INHERIT;
                    615:       cssRule += 7;
                    616:     }
                    617:   else if (isdigit (*cssRule) || *cssRule == '.')
                    618:     {
                    619:       cssRule = ParseCSSUnit (cssRule, border);
1.387     quint     620:       if (border->typed_data.value == 0 &&
                    621:           border->typed_data.unit != UNIT_INVALID)
1.327     vatton    622:         border->typed_data.unit = UNIT_PX;
1.319     quint     623:       else if (border->typed_data.unit == UNIT_INVALID ||
1.327     vatton    624:                border->typed_data.unit == UNIT_BOX ||
                    625:                border->typed_data.unit == UNIT_PERCENT)
                    626:         {
                    627:           border->typed_data.unit = UNIT_INVALID;
                    628:           border->typed_data.value = 0;
                    629:           CSSParseError ("Invalid border-width value", ptr, cssRule);
                    630:         }
1.319     quint     631:     }
                    632:   return (cssRule);
1.43      cvs       633: }
                    634: 
1.288     vatton    635: 
                    636: /*----------------------------------------------------------------------
1.327     vatton    637:   ParseBorderStyle                                      
1.43      cvs       638:   ----------------------------------------------------------------------*/
1.79      cvs       639: static char *ParseBorderStyle (char *cssRule, PresentationValue *border)
1.43      cvs       640: {
1.431     quint     641:   char             *ptr = cssRule;
                    642: 
1.43      cvs       643:   /* first parse the attribute string */
1.327     vatton    644:   border->typed_data.value = 0;
                    645:   border->typed_data.unit = UNIT_PX;
                    646:   border->typed_data.real = FALSE;
                    647:   if (!strncasecmp (cssRule, "none", 4))
                    648:     {
                    649:       border->typed_data.value = BorderStyleNone;
                    650:       cssRule += 4;
                    651:     }
                    652:   else if (!strncasecmp (cssRule, "hidden", 6))
                    653:     {
                    654:       border->typed_data.value = BorderStyleHidden;
                    655:       cssRule += 6;
                    656:     }
                    657:   else if (!strncasecmp (cssRule, "dotted", 6))
                    658:     {
1.288     vatton    659:       cssRule += 6;
1.327     vatton    660:       border->typed_data.value = BorderStyleDotted;
1.288     vatton    661:     }
1.327     vatton    662:   else if (!strncasecmp (cssRule, "dashed", 6))
                    663:     {
                    664:       border->typed_data.value = BorderStyleDashed;
                    665:       cssRule += 6;
                    666:     }
                    667:   else if (!strncasecmp (cssRule, "solid", 5))
                    668:     {
                    669:       border->typed_data.value = BorderStyleSolid;
                    670:       cssRule += 5;
                    671:     }
                    672:   else if (!strncasecmp (cssRule, "double", 6))
                    673:     {
                    674:       border->typed_data.value = BorderStyleDouble;
                    675:       cssRule += 6;
                    676:     }
                    677:   else if (!strncasecmp (cssRule, "groove", 6))
                    678:     {
                    679:       border->typed_data.value = BorderStyleGroove;
                    680:       cssRule += 6;
                    681:     }
                    682:   else if (!strncasecmp (cssRule, "ridge", 5))
                    683:     {
                    684:       border->typed_data.value = BorderStyleRidge;
                    685:       cssRule += 5;
                    686:     }
                    687:   else if (!strncasecmp (cssRule, "inset", 5))
                    688:     {
                    689:       border->typed_data.value = BorderStyleInset;
                    690:       cssRule += 5;
                    691:     }
                    692:   else if (!strncasecmp (cssRule, "outset", 6))
                    693:     {
                    694:       border->typed_data.value = BorderStyleOutset;
                    695:       cssRule += 6;
                    696:     }
                    697:   else
                    698:     {
                    699:       /* invalid style */
                    700:       border->typed_data.unit = UNIT_INVALID;
                    701:       return (cssRule);
                    702:     }
1.431     quint     703:   if (border->typed_data.value != 0)
                    704:     cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid border-style value");
1.327     vatton    705:   return (cssRule);
1.43      cvs       706: }
                    707: 
                    708: /*----------------------------------------------------------------------
1.327     vatton    709:   ParseCSSColor: parse a CSS color attribute string    
                    710:   we expect the input string describing the attribute to be     
                    711:   either a color name, a 3 tuple or an hexadecimal encoding.    
                    712:   The color used will be approximed from the current color      
                    713:   table                                                         
1.43      cvs       714:   ----------------------------------------------------------------------*/
1.79      cvs       715: static char *ParseCSSColor (char *cssRule, PresentationValue * val)
1.43      cvs       716: {
1.79      cvs       717:   char               *ptr;
1.43      cvs       718:   unsigned short      redval = (unsigned short) -1;
                    719:   unsigned short      greenval = 0;    /* composant of each RGB       */
                    720:   unsigned short      blueval = 0;     /* default to red if unknown ! */
                    721:   int                 best = 0;        /* best color in list found */
1.404     vatton    722:   ThotBool            warn;
1.43      cvs       723: 
1.82      cvs       724:   cssRule = SkipBlanksAndComments (cssRule);
1.184     vatton    725:   val->typed_data.unit = UNIT_INVALID;
1.43      cvs       726:   val->typed_data.real = FALSE;
                    727:   val->typed_data.value = 0;
1.57      cvs       728:   ptr = TtaGiveRGB (cssRule, &redval, &greenval, &blueval);
1.292     vatton    729:   if (!strncasecmp (cssRule, "InactiveCaptionText", 19))
                    730:     {
1.364     vatton    731:       val->typed_data.unit = VALUE_INHERIT;
1.292     vatton    732:       cssRule += 19;
                    733:     }
                    734:   else if (!strncasecmp (cssRule, "ThreeDLightShadow", 17))
                    735:     {
1.364     vatton    736:       val->typed_data.unit = VALUE_INHERIT;
1.292     vatton    737:       cssRule += 17;
                    738:     }
                    739:   else if (!strncasecmp (cssRule, "ThreeDDarkShadow", 16))
                    740:     {
1.364     vatton    741:       val->typed_data.unit = VALUE_INHERIT;
1.292     vatton    742:       cssRule += 16;
                    743:     }
                    744:   else if (!strncasecmp (cssRule, "ButtonHighlight", 15) ||
1.327     vatton    745:            !strncasecmp (cssRule, "InactiveCaption", 15) ||
                    746:            !strncasecmp (cssRule, "ThreeDHighlight", 15))
1.292     vatton    747:     {
1.364     vatton    748:       val->typed_data.unit = VALUE_INHERIT;
1.292     vatton    749:       cssRule += 15;
                    750:     }
                    751:   else if (!strncasecmp (cssRule, "InactiveBorder", 14) ||
1.327     vatton    752:            !strncasecmp (cssRule, "InfoBackground", 14))
1.292     vatton    753:     {
1.364     vatton    754:       val->typed_data.unit = VALUE_INHERIT;
1.292     vatton    755:       cssRule += 14;
                    756:     }
                    757:   else if (!strncasecmp (cssRule, "ActiveCaption", 13) ||
1.327     vatton    758:            !strncasecmp (cssRule, "HighlightText", 13))
1.292     vatton    759:     {
1.364     vatton    760:       val->typed_data.unit = VALUE_INHERIT;
1.292     vatton    761:       cssRule += 13;
                    762:     }
                    763:   else if (!strncasecmp (cssRule, "ActiveBorder", 12) ||
1.327     vatton    764:            !strncasecmp (cssRule, "AppWorkspace", 12) ||
                    765:            !strncasecmp (cssRule, "ButtonShadow", 12) ||
                    766:            !strncasecmp (cssRule, "ThreeDShadow", 12))
1.292     vatton    767:     {
1.364     vatton    768:       val->typed_data.unit = VALUE_INHERIT;
1.292     vatton    769:       cssRule += 12;
                    770:     }
                    771:   else if (!strncasecmp (cssRule, "CaptionText", 11) ||
1.327     vatton    772:            !strncasecmp (cssRule, "WindowFrame", 11))
1.292     vatton    773:     {
1.364     vatton    774:       val->typed_data.unit = VALUE_INHERIT;
1.292     vatton    775:       cssRule += 11;
                    776:     }
                    777:   else if (!strncasecmp (cssRule, "Background", 10) ||
1.327     vatton    778:            !strncasecmp (cssRule, "ButtonFace", 10) ||
                    779:            !strncasecmp (cssRule, "ButtonText", 10) ||
                    780:            !strncasecmp (cssRule, "ThreeDFace", 10) ||
                    781:            !strncasecmp (cssRule, "WindowText", 10))
1.292     vatton    782:     {
1.364     vatton    783:       val->typed_data.unit = VALUE_INHERIT;
1.292     vatton    784:       cssRule += 10;
                    785:     }
                    786:   else if (!strncasecmp (cssRule, "Highlight", 9) ||
1.327     vatton    787:            !strncasecmp (cssRule, "Scrollbar", 9))
1.292     vatton    788:     {
1.364     vatton    789:       val->typed_data.unit = VALUE_INHERIT;
1.292     vatton    790:       cssRule += 9;
                    791:     }
                    792:   else if (!strncasecmp (cssRule, "GrayText", 8) ||
1.327     vatton    793:            !strncasecmp (cssRule, "InfoText", 8) ||
                    794:            !strncasecmp (cssRule, "MenuText", 8))
1.292     vatton    795:     {
1.364     vatton    796:       val->typed_data.unit = VALUE_INHERIT;
1.292     vatton    797:       cssRule += 8;
                    798:     }
                    799:   else if (!strncasecmp (cssRule, "Window", 6))
                    800:     {
1.364     vatton    801:       val->typed_data.unit = VALUE_INHERIT;
1.292     vatton    802:       cssRule += 6;
                    803:     }
                    804:   else if (!strncasecmp (cssRule, "Menu", 5))
                    805:     {
1.364     vatton    806:       val->typed_data.unit = VALUE_INHERIT;
1.292     vatton    807:       cssRule += 5;
                    808:     }
1.293     quint     809:   else if (!strncasecmp (cssRule, "inherit", 7))
                    810:     {
                    811:       val->typed_data.unit = VALUE_INHERIT;
                    812:       cssRule += 7;
                    813:     }
1.404     vatton    814:   else if (!strncasecmp (cssRule, "hsl", 3))
                    815:     {
                    816:       val->typed_data.unit = VALUE_INHERIT;
                    817:       // check if Amaya should report CSS warnings
                    818:       TtaGetEnvBoolean ("CSS_WARN", &warn);
                    819:       if (warn)
                    820:        cssRule = SkipValue ("Warning: CSS3 value not supported", cssRule);
                    821:       else
                    822:        cssRule = SkipValue (NULL, cssRule);
                    823:     }
                    824:   else if (!strncasecmp (cssRule, "rgba", 4))
                    825:     {
                    826:       val->typed_data.unit = VALUE_INHERIT;
                    827:       // check if Amaya should report CSS warnings
                    828:       TtaGetEnvBoolean ("CSS_WARN", &warn);
                    829:       if (warn)
                    830:        cssRule = SkipValue ("Warning: CSS3 value not supported", cssRule);
                    831:       else
                    832:        cssRule = SkipValue (NULL, cssRule);
                    833:     }
1.57      cvs       834:   if (ptr == cssRule)
1.43      cvs       835:     {
1.404     vatton    836:       cssRule = SkipValue ("Invalid color value", cssRule);
1.43      cvs       837:       val->typed_data.value = 0;
1.184     vatton    838:       val->typed_data.unit = UNIT_INVALID;
1.43      cvs       839:     }
1.293     quint     840:   else if (val->typed_data.unit != VALUE_INHERIT)
1.43      cvs       841:     {
                    842:       best = TtaGetThotColor (redval, greenval, blueval);
                    843:       val->typed_data.value = best;
1.184     vatton    844:       val->typed_data.unit = UNIT_REL;
1.57      cvs       845:       cssRule = ptr;
1.43      cvs       846:     }
                    847:   val->typed_data.real = FALSE;
1.262     vatton    848:   cssRule = SkipBlanksAndComments (cssRule);
1.65      cvs       849:   return (cssRule);
1.43      cvs       850: }
1.1       cvs       851: 
                    852: /*----------------------------------------------------------------------
1.231     vatton    853:   CheckImportantRule updates the field important of the context and
                    854:   the line number.
1.117     vatton    855:   ----------------------------------------------------------------------*/
1.360     vatton    856: static void CheckImportantRule (char *cssRule, PresentationContext context)
1.117     vatton    857: {
1.276     vatton    858:   PresentationContextBlock dummyctxt;
                    859: 
                    860:   if (context == NULL)
                    861:     /* no context provided */
                    862:     context = &dummyctxt;
                    863: 
1.117     vatton    864:   cssRule = SkipBlanksAndComments (cssRule);
1.360     vatton    865:   while (*cssRule != EOS && *cssRule != '!' && *cssRule != ';')
                    866:     cssRule++;
1.120     vatton    867:   if (*cssRule != '!')
                    868:     context->important = FALSE;
                    869:   else
1.117     vatton    870:     {
1.120     vatton    871:       cssRule++;
1.360     vatton    872:       ImportantPos = cssRule;
1.120     vatton    873:       cssRule = SkipBlanksAndComments (cssRule);
                    874:       if (!strncasecmp (cssRule, "important", 9))
1.327     vatton    875:         {
1.360     vatton    876:           ImportantPos[-1] = EOS;
1.327     vatton    877:           context->important = TRUE;
                    878:         }
1.120     vatton    879:       else
1.360     vatton    880:         {
                    881:           ImportantPos = NULL;
                    882:           context->important = FALSE;
                    883:         }
                    884:     }
                    885: }
                    886: 
                    887: /*----------------------------------------------------------------------
                    888:   SkipImportantRule skips important markup
                    889:   ----------------------------------------------------------------------*/
                    890: static char *SkipImportantRule (char *cssRule)
                    891: {
                    892:   if (ImportantPos)
                    893:     {
                    894:       ImportantPos[-1] = '!';
1.361     vatton    895:       cssRule = ImportantPos;
                    896:       cssRule = SkipBlanksAndComments (cssRule);
                    897:       cssRule += 9;
1.360     vatton    898:       ImportantPos = NULL;
1.117     vatton    899:     }
1.360     vatton    900:   cssRule = SkipBlanksAndComments (cssRule);
1.117     vatton    901:   return (cssRule);
                    902: }
                    903: 
                    904: /*----------------------------------------------------------------------
1.327     vatton    905:   ParseCSSBorderTopWidth: parse a CSS BorderTopWidth
                    906:   attribute string.                                          
1.1       cvs       907:   ----------------------------------------------------------------------*/
1.79      cvs       908: static char *ParseCSSBorderTopWidth (Element element, PSchema tsch,
1.327     vatton    909:                                      PresentationContext context, 
                    910:                                      char *cssRule, CSSInfoPtr css,
                    911:                                      ThotBool isHTML)
1.1       cvs       912: {
1.41      cvs       913:   PresentationValue   border;
1.366     vatton    914:   char               *start_value = cssRule;
1.41      cvs       915:   
1.82      cvs       916:   cssRule = SkipBlanksAndComments (cssRule);
1.288     vatton    917:   cssRule = ParseABorderValue (cssRule, &border);
1.366     vatton    918:   if (border.typed_data.unit != UNIT_INVALID)
                    919:     {
                    920:       if (DoDialog)
                    921:         {
                    922:           if (All_sides)
                    923:             DisplayStyleValue ("border-width", start_value, cssRule);
                    924:           else
                    925:             DisplayStyleValue ("border-top-width", start_value, cssRule);
                    926:         }
                    927:       else if (DoApply)
                    928:         TtaSetStylePresentation (PRBorderTopWidth, element, tsch, context, border);
                    929:     }
1.1       cvs       930:   return (cssRule);
                    931: }
                    932: 
                    933: /*----------------------------------------------------------------------
1.327     vatton    934:   ParseCSSBorderBottomWidth: parse a CSS BorderBottomWidth
                    935:   attribute string.                                          
1.1       cvs       936:   ----------------------------------------------------------------------*/
1.79      cvs       937: static char *ParseCSSBorderBottomWidth (Element element, PSchema tsch,
1.327     vatton    938:                                         PresentationContext context,
                    939:                                         char *cssRule, CSSInfoPtr css,
                    940:                                         ThotBool isHTML)
1.1       cvs       941: {
1.41      cvs       942:   PresentationValue   border;
1.366     vatton    943:   char               *start_value = cssRule;
1.41      cvs       944:   
1.82      cvs       945:   cssRule = SkipBlanksAndComments (cssRule);
1.41      cvs       946:   /* first parse the attribute string */
1.288     vatton    947:   cssRule = ParseABorderValue (cssRule, &border);
1.366     vatton    948:   if (border.typed_data.unit != UNIT_INVALID)
                    949:     {
                    950:       if (DoDialog)
                    951:         DisplayStyleValue ("border-bottom-width", start_value, cssRule);
                    952:       else if (DoApply)
                    953:         TtaSetStylePresentation (PRBorderBottomWidth, element, tsch, context, border);
                    954:     }
1.1       cvs       955:   return (cssRule);
                    956: }
                    957: 
                    958: /*----------------------------------------------------------------------
1.327     vatton    959:   ParseCSSBorderLeftWidth: parse a CSS BorderLeftWidth
                    960:   attribute string.                                          
1.1       cvs       961:   ----------------------------------------------------------------------*/
1.79      cvs       962: static char *ParseCSSBorderLeftWidth (Element element, PSchema tsch,
1.327     vatton    963:                                       PresentationContext context,
                    964:                                       char *cssRule, CSSInfoPtr css,
                    965:                                       ThotBool isHTML)
1.1       cvs       966: {
1.41      cvs       967:   PresentationValue   border;
1.366     vatton    968:   char               *start_value = cssRule;
1.41      cvs       969:   
1.82      cvs       970:   cssRule = SkipBlanksAndComments (cssRule);
1.41      cvs       971:   /* first parse the attribute string */
1.288     vatton    972:   cssRule = ParseABorderValue (cssRule, &border);
1.366     vatton    973:   if (border.typed_data.unit != UNIT_INVALID)
                    974:     {
                    975:       if (DoDialog)
                    976:         DisplayStyleValue ("border-left-width", start_value, cssRule);
                    977:       else if (DoApply)
                    978:         TtaSetStylePresentation (PRBorderLeftWidth, element, tsch, context, border);
                    979:     }
1.1       cvs       980:   return (cssRule);
                    981: }
                    982: 
                    983: /*----------------------------------------------------------------------
1.327     vatton    984:   ParseCSSBorderRightWidth: parse a CSS BorderRightWidth
                    985:   attribute string.                                          
1.1       cvs       986:   ----------------------------------------------------------------------*/
1.79      cvs       987: static char *ParseCSSBorderRightWidth (Element element, PSchema tsch,
1.327     vatton    988:                                        PresentationContext context,
                    989:                                        char *cssRule, CSSInfoPtr css,
                    990:                                        ThotBool isHTML)
1.1       cvs       991: {
1.41      cvs       992:   PresentationValue   border;
1.366     vatton    993:   char               *start_value = cssRule;
1.41      cvs       994:   
1.82      cvs       995:   cssRule = SkipBlanksAndComments (cssRule);
1.41      cvs       996:   /* first parse the attribute string */
1.288     vatton    997:   cssRule = ParseABorderValue (cssRule, &border);
1.184     vatton    998:   if (border.typed_data.unit != UNIT_INVALID && DoApply)
1.366     vatton    999:     {
                   1000:       if (DoDialog)
                   1001:         DisplayStyleValue ("border-right-width", start_value, cssRule);
                   1002:       else if (DoApply)
                   1003:         TtaSetStylePresentation (PRBorderRightWidth, element, tsch, context, border);
                   1004:     }
1.1       cvs      1005:   return (cssRule);
                   1006: }
                   1007: 
                   1008: /*----------------------------------------------------------------------
1.327     vatton   1009:   ParseCSSBorderWidth: parse a CSS BorderWidth
                   1010:   attribute string.                                          
1.1       cvs      1011:   ----------------------------------------------------------------------*/
1.79      cvs      1012: static char *ParseCSSBorderWidth (Element element, PSchema tsch,
1.327     vatton   1013:                                   PresentationContext context,
                   1014:                                   char *cssRule, CSSInfoPtr css,
                   1015:                                   ThotBool isHTML)
1.1       cvs      1016: {
1.79      cvs      1017:   char *ptrT, *ptrR, *ptrB, *ptrL;
1.366     vatton   1018:   int   skippedNL, n;
1.41      cvs      1019: 
1.82      cvs      1020:   ptrT = SkipBlanksAndComments (cssRule);
1.366     vatton   1021:   if (DoDialog)
                   1022:     n = NumberOfValues (ptrT);
                   1023:   if (DoDialog && n < 2)
1.42      cvs      1024:     {
1.366     vatton   1025:       // check if the border dialog must be updated
                   1026:       All_sides = TRUE;
                   1027:      ptrR = ParseCSSBorderTopWidth (element, tsch, context, ptrT, css, isHTML);
                   1028:       All_sides = FALSE;
1.42      cvs      1029:     }
                   1030:   else
                   1031:     {
1.366     vatton   1032:       /* First parse Border-Top */
                   1033:       ptrR = ParseCSSBorderTopWidth (element, tsch, context, ptrT, css, isHTML);
1.415     vatton   1034:       if (ptrR == ptrT)
                   1035:        {
                   1036:          // invalid value
                   1037:           cssRule = SkipValue ("Invalid border-width value", ptrT);
                   1038:          return (cssRule);
                   1039:        }
1.366     vatton   1040:       ptrR = SkipBlanksAndComments (ptrR);
                   1041:       if (*ptrR == ';' || *ptrR == '}' || *ptrR == EOS || *ptrR == ',')
1.327     vatton   1042:         {
                   1043:           skippedNL = NewLineSkipped;
1.366     vatton   1044:           cssRule = ptrR;
                   1045:           /* apply the Border-Top to all */
                   1046:           ptrR = ParseCSSBorderRightWidth (element, tsch, context, ptrT, css, isHTML);
                   1047:           NewLineSkipped = skippedNL;
                   1048:           ptrR = ParseCSSBorderBottomWidth (element, tsch, context, ptrT, css, isHTML);
1.327     vatton   1049:           NewLineSkipped = skippedNL;
1.366     vatton   1050:           ptrR = ParseCSSBorderLeftWidth (element, tsch, context, ptrT, css, isHTML);
1.327     vatton   1051:         }
1.42      cvs      1052:       else
1.327     vatton   1053:         {
1.366     vatton   1054:           /* parse Border-Right */
                   1055:           ptrB = ParseCSSBorderRightWidth (element, tsch, context, ptrR, css, isHTML);
                   1056:           ptrB = SkipBlanksAndComments (ptrB);
                   1057:           if (*ptrB == ';' || *ptrB == '}' || *ptrB == EOS || *ptrB == ',')
1.327     vatton   1058:             {
1.366     vatton   1059:               skippedNL = NewLineSkipped;
                   1060:               cssRule = ptrB;
                   1061:               /* apply the Border-Top to Border-Bottom */
                   1062:               ptrB = ParseCSSBorderBottomWidth (element, tsch, context, ptrT, css, isHTML);
                   1063:               NewLineSkipped = skippedNL;
1.327     vatton   1064:               /* apply the Border-Right to Border-Left */
1.366     vatton   1065:               ptrB = ParseCSSBorderLeftWidth (element, tsch, context, ptrR, css, isHTML);
1.327     vatton   1066:             }
                   1067:           else
1.366     vatton   1068:             {
                   1069:               /* parse Border-Bottom */
                   1070:               ptrL = ParseCSSBorderBottomWidth (element, tsch, context, ptrB, css, isHTML);
                   1071:               ptrL = SkipBlanksAndComments (ptrL);
                   1072:               if (*ptrL == ';' || *ptrL == '}' || *ptrL == EOS || *ptrL == ',')
                   1073:                 {
                   1074:                   cssRule = ptrL;
                   1075:                   /* apply the Border-Right to Border-Left */
                   1076:                   ptrL = ParseCSSBorderLeftWidth (element, tsch, context, ptrR, css, isHTML);
                   1077:                 }
                   1078:               else
                   1079:                 /* parse Border-Left */
                   1080:                 cssRule = ParseCSSBorderLeftWidth (element, tsch, context, ptrL, css, isHTML);
                   1081:               cssRule = SkipBlanksAndComments (cssRule);
                   1082:             }
1.327     vatton   1083:         }
1.42      cvs      1084:     }
1.1       cvs      1085:   return (cssRule);
                   1086: }
                   1087: 
                   1088: /*----------------------------------------------------------------------
1.327     vatton   1089:   ParseCSSBorderColorTop: parse a CSS BorderColorTop
                   1090:   attribute string.                                          
1.1       cvs      1091:   ----------------------------------------------------------------------*/
1.79      cvs      1092: static char *ParseCSSBorderColorTop (Element element, PSchema tsch,
1.327     vatton   1093:                                      PresentationContext context,
                   1094:                                      char *cssRule, CSSInfoPtr css,
                   1095:                                      ThotBool isHTML)
1.1       cvs      1096: {
1.117     vatton   1097:   PresentationValue   best;
1.366     vatton   1098:   char               *start_value = cssRule;
1.43      cvs      1099: 
1.234     vatton   1100:   if (!strncasecmp (cssRule, "transparent", 11))
                   1101:     {
                   1102:       best.typed_data.value = -2;  /* -2 means transparent */
                   1103:       best.typed_data.unit = UNIT_REL;
                   1104:       cssRule = SkipWord (cssRule);
                   1105:     }
                   1106:   else
                   1107:     cssRule = ParseCSSColor (cssRule, &best);
1.366     vatton   1108:   if (best.typed_data.unit != UNIT_INVALID)
                   1109:     {
                   1110:       if (DoDialog)
                   1111:         {
                   1112:           if (All_sides)
                   1113:             DisplayStyleValue ("border-color", start_value, cssRule);
                   1114:           else
                   1115:             DisplayStyleValue ("border-top-color", start_value, cssRule);
                   1116:         }
                   1117:       else if (DoApply)
                   1118:         /* install the new presentation */
                   1119:         TtaSetStylePresentation (PRBorderTopColor, element, tsch, context, best);
                   1120:     }
1.117     vatton   1121:   return (cssRule);
1.1       cvs      1122: }
                   1123: 
                   1124: /*----------------------------------------------------------------------
1.327     vatton   1125:   ParseCSSBorderColorLeft: parse a CSS BorderColorLeft
                   1126:   attribute string.                                          
1.42      cvs      1127:   ----------------------------------------------------------------------*/
1.79      cvs      1128: static char *ParseCSSBorderColorLeft (Element element, PSchema tsch,
1.327     vatton   1129:                                       PresentationContext context,
                   1130:                                       char *cssRule, CSSInfoPtr css,
                   1131:                                       ThotBool isHTML)
1.42      cvs      1132: {
1.117     vatton   1133:   PresentationValue   best;
1.366     vatton   1134:   char               *start_value = cssRule;
1.117     vatton   1135:   
1.234     vatton   1136:   if (!strncasecmp (cssRule, "transparent", 11))
                   1137:     {
                   1138:       best.typed_data.value = -2;  /* -2 means transparent */
                   1139:       best.typed_data.unit = UNIT_REL;
                   1140:       cssRule = SkipWord (cssRule);
                   1141:     }
                   1142:   else
                   1143:     cssRule = ParseCSSColor (cssRule, &best);
1.184     vatton   1144:   if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.366     vatton   1145:     {
                   1146:       if (DoDialog)
                   1147:         DisplayStyleValue ("border-left-color", start_value, cssRule);
                   1148:       else if (DoApply)
                   1149:         /* install the new presentation */
                   1150:         TtaSetStylePresentation (PRBorderLeftColor, element, tsch, context, best);
                   1151:     }
1.117     vatton   1152:   return (cssRule);
1.42      cvs      1153: }
                   1154: 
                   1155: /*----------------------------------------------------------------------
1.327     vatton   1156:   ParseCSSBorderColorBottom: parse a CSS BorderColorBottom
                   1157:   attribute string.                                          
1.42      cvs      1158:   ----------------------------------------------------------------------*/
1.79      cvs      1159: static char *ParseCSSBorderColorBottom (Element element, PSchema tsch,
1.327     vatton   1160:                                         PresentationContext context,
                   1161:                                         char *cssRule, CSSInfoPtr css,
                   1162:                                         ThotBool isHTML)
1.42      cvs      1163: {
1.117     vatton   1164:   PresentationValue   best;
1.366     vatton   1165:   char               *start_value = cssRule;
1.43      cvs      1166: 
1.234     vatton   1167:   if (!strncasecmp (cssRule, "transparent", 11))
                   1168:     {
                   1169:       best.typed_data.value = -2;  /* -2 means transparent */
                   1170:       best.typed_data.unit = UNIT_REL;
                   1171:       cssRule = SkipWord (cssRule);
                   1172:     }
                   1173:   else
                   1174:     cssRule = ParseCSSColor (cssRule, &best);
1.184     vatton   1175:   if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.366     vatton   1176:     {
                   1177:       if (DoDialog)
                   1178:         DisplayStyleValue ("border-bottom-color", start_value, cssRule);
                   1179:       else if (DoApply)
                   1180:         /* install the new presentation */
                   1181:         TtaSetStylePresentation (PRBorderBottomColor, element, tsch, context, best);
                   1182:     }
1.327     vatton   1183:   return (cssRule);
1.42      cvs      1184: }
                   1185: 
                   1186: /*----------------------------------------------------------------------
1.327     vatton   1187:   ParseCSSBorderColorRight: parse a CSS BorderColorRight
                   1188:   attribute string.                                          
1.1       cvs      1189:   ----------------------------------------------------------------------*/
1.79      cvs      1190: static char *ParseCSSBorderColorRight (Element element, PSchema tsch,
1.327     vatton   1191:                                        PresentationContext context,
                   1192:                                        char *cssRule, CSSInfoPtr css,
                   1193:                                        ThotBool isHTML)
1.1       cvs      1194: {
1.117     vatton   1195:   PresentationValue   best;
1.366     vatton   1196:   char               *start_value = cssRule;
1.43      cvs      1197: 
1.234     vatton   1198:   if (!strncasecmp (cssRule, "transparent", 11))
                   1199:     {
                   1200:       best.typed_data.value = -2;  /* -2 means transparent */
                   1201:       best.typed_data.unit = UNIT_REL;
                   1202:       cssRule = SkipWord (cssRule);
                   1203:     }
                   1204:   else
                   1205:     cssRule = ParseCSSColor (cssRule, &best);
1.184     vatton   1206:   if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.366     vatton   1207:     {
                   1208:       if (DoDialog)
                   1209:         DisplayStyleValue ("border-right-color", start_value, cssRule);
                   1210:       else if (DoApply)
                   1211:         TtaSetStylePresentation (PRBorderRightColor, element, tsch, context, best);
                   1212:     }
1.117     vatton   1213:   return (cssRule);
1.1       cvs      1214: }
                   1215: 
                   1216: /*----------------------------------------------------------------------
1.327     vatton   1217:   ParseCSSBorderColor: parse a CSS border-color        
                   1218:   attribute string.                                          
1.42      cvs      1219:   ----------------------------------------------------------------------*/
1.79      cvs      1220: static char *ParseCSSBorderColor (Element element, PSchema tsch,
1.327     vatton   1221:                                   PresentationContext context,
                   1222:                                   char *cssRule, CSSInfoPtr css,
                   1223:                                   ThotBool isHTML)
1.42      cvs      1224: {
1.79      cvs      1225:   char *ptrT, *ptrR, *ptrB, *ptrL;
1.366     vatton   1226:   int   skippedNL, n;
1.42      cvs      1227: 
1.82      cvs      1228:   ptrT = SkipBlanksAndComments (cssRule);
1.366     vatton   1229:   if (DoDialog)
                   1230:     n = NumberOfValues (ptrT);
                   1231:   if (DoDialog && n < 2)
1.42      cvs      1232:     {
1.366     vatton   1233:       // check if the border dialog must be updated
                   1234:       All_sides = TRUE;
                   1235:      ptrR = ParseCSSBorderColorTop (element, tsch, context, ptrT, css, isHTML);
                   1236:       All_sides = FALSE;
1.42      cvs      1237:     }
                   1238:   else
                   1239:     {
1.366     vatton   1240:       /* First parse Border-Top */
                   1241:       ptrR = ParseCSSBorderColorTop (element, tsch, context, ptrT, css, isHTML);
                   1242:       ptrR = SkipBlanksAndComments (ptrR);
                   1243:       if (*ptrR == ';' || *ptrR == '}' || *ptrR == EOS || *ptrR == ',')
1.327     vatton   1244:         {
                   1245:           skippedNL = NewLineSkipped;
1.366     vatton   1246:           cssRule = ptrR;
                   1247:           /* apply the Border-Top to all */
                   1248:           ptrR = ParseCSSBorderColorRight (element, tsch, context, ptrT, css, isHTML);
                   1249:           NewLineSkipped = skippedNL;
                   1250:           ptrR = ParseCSSBorderColorBottom (element, tsch, context, ptrT, css, isHTML);
1.327     vatton   1251:           NewLineSkipped = skippedNL;
1.366     vatton   1252:           ptrR = ParseCSSBorderColorLeft (element, tsch, context, ptrT, css, isHTML);
1.327     vatton   1253:         }
1.42      cvs      1254:       else
1.327     vatton   1255:         {
1.366     vatton   1256:           /* parse Border-Right */
                   1257:           ptrB = ParseCSSBorderColorRight (element, tsch, context, ptrR, css, isHTML);
                   1258:           ptrB = SkipBlanksAndComments (ptrB);
                   1259:           if (*ptrB == ';' || *ptrB == '}' || *ptrB == EOS || *ptrB == ',')
1.327     vatton   1260:             {
1.366     vatton   1261:               skippedNL = NewLineSkipped;
                   1262:               cssRule = ptrB;
                   1263:               /* apply the Border-Top to Border-Bottom */
                   1264:               ptrB = ParseCSSBorderColorBottom (element, tsch, context, ptrT, css, isHTML);
                   1265:               NewLineSkipped = skippedNL;
1.327     vatton   1266:               /* apply the Border-Right to Border-Left */
1.366     vatton   1267:               ptrB = ParseCSSBorderColorLeft (element, tsch, context, ptrR, css, isHTML);
1.327     vatton   1268:             }
                   1269:           else
1.366     vatton   1270:             {
                   1271:               skippedNL = NewLineSkipped;
                   1272:               /* parse Border-Bottom */
                   1273:               ptrL = ParseCSSBorderColorBottom (element, tsch, context, ptrB, css, isHTML);
                   1274:               NewLineSkipped = skippedNL;
                   1275:               ptrL = SkipBlanksAndComments (ptrL);
                   1276:               if (*ptrL == ';' || *ptrL == '}' || *ptrL == EOS || *ptrL == ',')
                   1277:                 {
                   1278:                   cssRule = ptrL;
                   1279:                   /* apply the Border-Right to Border-Left */
                   1280:                   ptrL = ParseCSSBorderColorLeft (element, tsch, context, ptrR, css, isHTML);
                   1281:                 }
                   1282:               else
                   1283:                 /* parse Border-Left */
                   1284:                 cssRule = ParseCSSBorderColorLeft (element, tsch, context, ptrL, css, isHTML);
                   1285:               cssRule = SkipBlanksAndComments (cssRule);
                   1286:             }
1.327     vatton   1287:         }
1.42      cvs      1288:     }
                   1289:   return (cssRule);
                   1290: }
                   1291: 
                   1292: /*----------------------------------------------------------------------
1.327     vatton   1293:   ParseCSSBorderStyleTop: parse a CSS BorderStyleTop
                   1294:   attribute string.                                          
1.42      cvs      1295:   ----------------------------------------------------------------------*/
1.79      cvs      1296: static char *ParseCSSBorderStyleTop (Element element, PSchema tsch,
1.327     vatton   1297:                                      PresentationContext context,
                   1298:                                      char *cssRule, CSSInfoPtr css,
                   1299:                                      ThotBool isHTML)
1.42      cvs      1300: {
1.43      cvs      1301:   PresentationValue   border;
1.366     vatton   1302:   char               *start_value;
1.43      cvs      1303:   
1.82      cvs      1304:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   1305:   start_value = cssRule;
1.43      cvs      1306:   cssRule = ParseBorderStyle (cssRule, &border);
1.366     vatton   1307:   if (border.typed_data.unit != UNIT_INVALID)
                   1308:     {
                   1309:       if (DoDialog)
                   1310:         {
                   1311:           if (All_sides)
                   1312:             DisplayStyleValue ("border-style", start_value, cssRule);
                   1313:           else
                   1314:             DisplayStyleValue ("border-top-style", start_value, cssRule);
                   1315:         }
                   1316:       else if (DoApply)
                   1317:         TtaSetStylePresentation (PRBorderTopStyle, element, tsch, context, border);
                   1318:     }
1.42      cvs      1319:   return (cssRule);
                   1320: }
                   1321: 
                   1322: /*----------------------------------------------------------------------
1.327     vatton   1323:   ParseCSSBorderStyleLeft: parse a CSS BorderStyleLeft
                   1324:   attribute string.                                          
1.42      cvs      1325:   ----------------------------------------------------------------------*/
1.79      cvs      1326: static char *ParseCSSBorderStyleLeft (Element element, PSchema tsch,
1.327     vatton   1327:                                       PresentationContext context,
                   1328:                                       char *cssRule, CSSInfoPtr css,
                   1329:                                       ThotBool isHTML)
1.42      cvs      1330: {
1.43      cvs      1331:   PresentationValue   border;
1.366     vatton   1332:   char               *start_value;
1.43      cvs      1333:   
1.82      cvs      1334:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   1335:   start_value = cssRule;
1.43      cvs      1336:   cssRule = ParseBorderStyle (cssRule, &border);
1.366     vatton   1337:   if (border.typed_data.unit != UNIT_INVALID)
                   1338:     {
                   1339:       if (DoDialog)
                   1340:         DisplayStyleValue ("border-left-style", start_value, cssRule);
                   1341:       else if (DoApply)
                   1342:         TtaSetStylePresentation (PRBorderLeftStyle, element, tsch, context, border);
                   1343:     }
1.42      cvs      1344:   return (cssRule);
                   1345: }
                   1346: 
                   1347: /*----------------------------------------------------------------------
1.327     vatton   1348:   ParseCSSBorderStyleBottom: parse a CSS BorderStyleBottom
                   1349:   attribute string.                                          
1.1       cvs      1350:   ----------------------------------------------------------------------*/
1.79      cvs      1351: static char *ParseCSSBorderStyleBottom (Element element, PSchema tsch,
1.327     vatton   1352:                                         PresentationContext context,
                   1353:                                         char *cssRule, CSSInfoPtr css,
                   1354:                                         ThotBool isHTML)
1.1       cvs      1355: {
1.43      cvs      1356:   PresentationValue   border;
1.366     vatton   1357:   char               *start_value;
1.43      cvs      1358:   
1.82      cvs      1359:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   1360:   start_value = cssRule;
1.43      cvs      1361:   cssRule = ParseBorderStyle (cssRule, &border);
1.366     vatton   1362:   if (border.typed_data.unit != UNIT_INVALID)
                   1363:     {
                   1364:       if (DoDialog)
                   1365:         DisplayStyleValue ("border-bottom-style", start_value, cssRule);
                   1366:       else if (DoApply)
                   1367:         TtaSetStylePresentation (PRBorderBottomStyle, element, tsch, context, border);
                   1368:     }
1.1       cvs      1369:   return (cssRule);
                   1370: }
                   1371: 
                   1372: /*----------------------------------------------------------------------
1.327     vatton   1373:   ParseCSSBorderStyleRight: parse a CSS BorderStyleRight
                   1374:   attribute string.                                          
1.1       cvs      1375:   ----------------------------------------------------------------------*/
1.79      cvs      1376: static char *ParseCSSBorderStyleRight (Element element, PSchema tsch,
1.327     vatton   1377:                                        PresentationContext context,
                   1378:                                        char *cssRule, CSSInfoPtr css,
                   1379:                                        ThotBool isHTML)
1.1       cvs      1380: {
1.43      cvs      1381:   PresentationValue   border;
1.366     vatton   1382:   char               *start_value;
1.43      cvs      1383:   
1.82      cvs      1384:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   1385:   start_value = cssRule;
1.43      cvs      1386:   cssRule = ParseBorderStyle (cssRule, &border);
1.184     vatton   1387:   if (border.typed_data.unit != UNIT_INVALID && DoApply)
1.366     vatton   1388:     {
                   1389:       if (DoDialog)
                   1390:         DisplayStyleValue ("border-right-style", start_value, cssRule);
                   1391:       else if (DoApply)
                   1392:         TtaSetStylePresentation (PRBorderRightStyle, element, tsch, context, border);
                   1393:     }
1.1       cvs      1394:   return (cssRule);
                   1395: }
                   1396: 
                   1397: /*----------------------------------------------------------------------
1.349     quint    1398:   ParseCSSBorderStyle: parse a CSS border-style attribute string.
1.1       cvs      1399:   ----------------------------------------------------------------------*/
1.79      cvs      1400: static char *ParseCSSBorderStyle (Element element, PSchema tsch,
1.327     vatton   1401:                                   PresentationContext context,
                   1402:                                   char *cssRule, CSSInfoPtr css,
                   1403:                                   ThotBool isHTML)
1.1       cvs      1404: {
1.79      cvs      1405:   char *ptrT, *ptrR, *ptrB, *ptrL;
1.366     vatton   1406:   int   skippedNL, n;
1.42      cvs      1407: 
1.82      cvs      1408:   ptrT = SkipBlanksAndComments (cssRule);
1.366     vatton   1409:   if (DoDialog)
                   1410:     n = NumberOfValues (ptrT);
                   1411:   if (DoDialog && n < 2)
1.42      cvs      1412:     {
1.366     vatton   1413:       // check if the border dialog must be updated
                   1414:       All_sides = TRUE;
                   1415:      ptrR =  ParseCSSBorderStyleTop(element, tsch, context, ptrT, css, isHTML);
                   1416:       All_sides = FALSE;
1.42      cvs      1417:     }
                   1418:   else
                   1419:     {
1.366     vatton   1420:       /* First parse Border-Top */
                   1421:       ptrR = ParseCSSBorderStyleTop (element, tsch, context, ptrT, css, isHTML);
                   1422:       ptrR = SkipBlanksAndComments (ptrR);
                   1423:       if (*ptrR == ';' || *ptrR == '}' || *ptrR == EOS || *ptrR == ',')
1.327     vatton   1424:         {
                   1425:           skippedNL = NewLineSkipped;
1.366     vatton   1426:           cssRule = ptrR;
                   1427:           /* apply the Border-Top to all */
                   1428:           ptrR = ParseCSSBorderStyleRight (element, tsch, context, ptrT, css, isHTML);
                   1429:           NewLineSkipped = skippedNL;
                   1430:           ptrR = ParseCSSBorderStyleBottom (element, tsch, context, ptrT, css, isHTML);
1.327     vatton   1431:           NewLineSkipped = skippedNL;
1.366     vatton   1432:           ptrR = ParseCSSBorderStyleLeft (element, tsch, context, ptrT, css, isHTML);
1.327     vatton   1433:         }
1.42      cvs      1434:       else
1.327     vatton   1435:         {
1.366     vatton   1436:           /* parse Border-Right */
                   1437:           ptrB = ParseCSSBorderStyleRight (element, tsch, context, ptrR, css, isHTML);
                   1438:           ptrB = SkipBlanksAndComments (ptrB);
                   1439:           if (*ptrB == ';' || *ptrR == '}' || *ptrB == EOS || *ptrB == ',')
1.327     vatton   1440:             {
1.366     vatton   1441:               skippedNL = NewLineSkipped;
                   1442:               cssRule = ptrB;
                   1443:               /* apply the Border-Top to Border-Bottom */
                   1444:               ptrB = ParseCSSBorderStyleBottom (element, tsch, context, ptrT, css, isHTML);
                   1445:               NewLineSkipped = skippedNL;
1.327     vatton   1446:               /* apply the Border-Right to Border-Left */
1.366     vatton   1447:               ptrB = ParseCSSBorderStyleLeft (element, tsch, context, ptrR, css, isHTML);
1.327     vatton   1448:             }
                   1449:           else
1.366     vatton   1450:             {
                   1451:               /* parse Border-Bottom */
                   1452:               ptrL = ParseCSSBorderStyleBottom (element, tsch, context, ptrB, css, isHTML);
                   1453:               ptrL = SkipBlanksAndComments (ptrL);
                   1454:               if (*ptrL == ';' || *ptrR == '}' || *ptrL == EOS || *ptrL == ',')
                   1455:                 {
                   1456:                   cssRule = ptrL;
                   1457:                   /* apply the Border-Right to Border-Left */
                   1458:                   ptrL = ParseCSSBorderStyleLeft (element, tsch, context, ptrR, css, isHTML);
                   1459:                 }
                   1460:               else
                   1461:                 /* parse Border-Left */
                   1462:                 cssRule = ParseCSSBorderStyleLeft (element, tsch, context, ptrL, css, isHTML);
                   1463:               cssRule = SkipBlanksAndComments (cssRule);
                   1464:             }
1.327     vatton   1465:         }
1.42      cvs      1466:     }
                   1467:   return (cssRule);
                   1468: }
                   1469: 
                   1470: /*----------------------------------------------------------------------
1.327     vatton   1471:   ParseCSSBorderTop: parse a CSS BorderTop
                   1472:   attribute string.                                          
1.42      cvs      1473:   ----------------------------------------------------------------------*/
1.79      cvs      1474: static char *ParseCSSBorderTop (Element element, PSchema tsch,
1.327     vatton   1475:                                 PresentationContext context, char *cssRule,
                   1476:                                 CSSInfoPtr css, ThotBool isHTML)
1.42      cvs      1477: {
1.370     vatton   1478:   PresentationValue   best;
                   1479:   char               *ptr;
                   1480:   ThotBool            style, width, color;
1.43      cvs      1481: 
1.82      cvs      1482:   cssRule = SkipBlanksAndComments (cssRule);
1.322     vatton   1483:   /* register given values */
1.337     vatton   1484:   if (!strncmp (cssRule, "none", 4))
1.370     vatton   1485:     style = width = color = TRUE;
1.337     vatton   1486:   else
1.370     vatton   1487:     style = width = color = FALSE;
1.301     vatton   1488:   while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.43      cvs      1489:     {
                   1490:       ptr = cssRule;
                   1491:       cssRule = ParseCSSBorderStyleTop (element, tsch, context, cssRule, css, isHTML);
                   1492:       if (ptr == cssRule)
1.327     vatton   1493:         {
                   1494:           cssRule = ParseCSSBorderTopWidth (element, tsch, context, cssRule, css, isHTML);
                   1495:           if (ptr == cssRule)
1.370     vatton   1496:             {
                   1497:               cssRule = ParseCSSBorderColorTop (element, tsch, context, cssRule, css, isHTML);
                   1498:               if (ptr != cssRule)
                   1499:                 color = TRUE;
                   1500:             }
1.327     vatton   1501:           else
                   1502:             width = TRUE;
                   1503:           if (ptr == cssRule)
                   1504:             {
                   1505:               /* rule not found */
                   1506:               cssRule = SkipValue ("Invalid border value", cssRule);
                   1507:               return (cssRule);
                   1508:             }
                   1509:         }
1.322     vatton   1510:       else
1.327     vatton   1511:         style = TRUE;
1.82      cvs      1512:       cssRule = SkipBlanksAndComments (cssRule);
1.43      cvs      1513:     }
1.322     vatton   1514: 
                   1515:   if (!width)
1.405     kia      1516:     ParseCSSBorderTopWidth (element, tsch, context, (char*)"medium", css, isHTML);
1.322     vatton   1517:   if (!style)
1.405     kia      1518:     ParseCSSBorderStyleTop (element, tsch, context, (char*)"none", css, isHTML);
1.370     vatton   1519:   if (!color && DoApply)
                   1520:     {
                   1521:       /* get the box color */
                   1522:       best.typed_data.value = -1;
                   1523:       best.typed_data.unit = UNIT_REL; 
                   1524:       best.typed_data.real = FALSE;
                   1525:       TtaSetStylePresentation (PRBorderTopColor, element, tsch, context, best);
                   1526:     }
1.42      cvs      1527:   return (cssRule);
                   1528: }
                   1529: 
                   1530: /*----------------------------------------------------------------------
1.327     vatton   1531:   ParseCSSBorderLeft: parse a CSS BorderLeft
                   1532:   attribute string.                                          
1.42      cvs      1533:   ----------------------------------------------------------------------*/
1.79      cvs      1534: static char *ParseCSSBorderLeft (Element element, PSchema tsch,
1.327     vatton   1535:                                  PresentationContext context, char *cssRule,
                   1536:                                  CSSInfoPtr css, ThotBool isHTML)
1.42      cvs      1537: {
1.370     vatton   1538:   PresentationValue   best;
                   1539:   char               *ptr;
                   1540:   ThotBool            style, width, color;
1.43      cvs      1541: 
1.82      cvs      1542:   cssRule = SkipBlanksAndComments (cssRule);
1.322     vatton   1543:   /* register given values */
1.337     vatton   1544:   if (!strncmp (cssRule, "none", 4))
1.370     vatton   1545:     style = width = color = TRUE;
1.337     vatton   1546:   else
1.370     vatton   1547:     style = width = color = FALSE;
1.301     vatton   1548:   while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.43      cvs      1549:     {
                   1550:       ptr = cssRule;
                   1551:       cssRule = ParseCSSBorderStyleLeft (element, tsch, context, cssRule, css, isHTML);
                   1552:       if (ptr == cssRule)
1.327     vatton   1553:         {
                   1554:           cssRule = ParseCSSBorderLeftWidth (element, tsch, context, cssRule, css, isHTML);
                   1555:           if (ptr == cssRule)
1.370     vatton   1556:             {
                   1557:               cssRule = ParseCSSBorderColorLeft (element, tsch, context, cssRule, css, isHTML);
                   1558:               if (ptr != cssRule)
                   1559:                 color = TRUE;
                   1560:             }
1.327     vatton   1561:           else
                   1562:             width = TRUE;
                   1563:           if (ptr == cssRule)
                   1564:             {
                   1565:               /* rule not found */
                   1566:               cssRule = SkipValue ("Invalid border value", cssRule);
                   1567:               return (cssRule);
                   1568:             }
                   1569:         }
1.322     vatton   1570:       else
1.327     vatton   1571:         style = TRUE;
                   1572:       cssRule = SkipBlanksAndComments (cssRule);
1.43      cvs      1573:     }
1.322     vatton   1574: 
                   1575:   if (!width)
1.405     kia      1576:     ParseCSSBorderLeftWidth (element, tsch, context, (char*)"medium", css, isHTML);
1.322     vatton   1577:   if (!style)
1.405     kia      1578:     ParseCSSBorderStyleLeft (element, tsch, context, (char*)"none", css, isHTML);
1.370     vatton   1579:   if (!color && DoApply)
                   1580:     {
                   1581:       /* get the box color */
                   1582:       best.typed_data.value = -1;
                   1583:       best.typed_data.unit = UNIT_REL;
                   1584:       best.typed_data.real = FALSE;
                   1585:       TtaSetStylePresentation (PRBorderLeftColor, element, tsch, context, best);
                   1586:     }
1.1       cvs      1587:   return (cssRule);
                   1588: }
                   1589: 
                   1590: /*----------------------------------------------------------------------
1.327     vatton   1591:   ParseCSSBorderBottom: parse a CSS BorderBottom
                   1592:   attribute string.                                          
1.1       cvs      1593:   ----------------------------------------------------------------------*/
1.79      cvs      1594: static char *ParseCSSBorderBottom (Element element, PSchema tsch,
1.327     vatton   1595:                                    PresentationContext context, char *cssRule,
                   1596:                                    CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      1597: {
1.370     vatton   1598:   PresentationValue   best;
                   1599:   char               *ptr;
                   1600:   ThotBool            style, width, color;
1.43      cvs      1601: 
1.82      cvs      1602:   cssRule = SkipBlanksAndComments (cssRule);
1.322     vatton   1603:   /* register given values */
1.337     vatton   1604:   if (!strncmp (cssRule, "none", 4))
1.370     vatton   1605:     style = width = color = TRUE;
1.337     vatton   1606:   else
1.370     vatton   1607:     style = width = color = FALSE;
1.301     vatton   1608:   while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.43      cvs      1609:     {
                   1610:       ptr = cssRule;
                   1611:       cssRule = ParseCSSBorderStyleBottom (element, tsch, context, cssRule, css, isHTML);
                   1612:       if (ptr == cssRule)
1.327     vatton   1613:         {
                   1614:           cssRule = ParseCSSBorderBottomWidth (element, tsch, context, cssRule, css, isHTML);
                   1615:           if (ptr == cssRule)
1.370     vatton   1616:             {
                   1617:               cssRule = ParseCSSBorderColorBottom (element, tsch, context, cssRule, css, isHTML);
                   1618:               if (ptr != cssRule)
                   1619:                 color = TRUE;
                   1620:             }
1.327     vatton   1621:           else
                   1622:             width = TRUE;
                   1623:           if (ptr == cssRule)
                   1624:             {
                   1625:               /* rule not found */
                   1626:               cssRule = SkipValue ("Invalid border value", cssRule);
                   1627:               return (cssRule);
                   1628:             }
                   1629:         }
1.322     vatton   1630:       else
1.327     vatton   1631:         style = TRUE;
1.82      cvs      1632:       cssRule = SkipBlanksAndComments (cssRule);
1.43      cvs      1633:     }
1.322     vatton   1634: 
                   1635:   if (!width)
1.405     kia      1636:     ParseCSSBorderBottomWidth (element, tsch, context, (char*)"medium", css, isHTML);
1.322     vatton   1637:   if (!style)
1.405     kia      1638:     ParseCSSBorderStyleBottom (element, tsch, context, (char*)"none", css, isHTML);
1.370     vatton   1639:   if (!color && DoApply)
                   1640:     {
                   1641:       /* get the box color */
                   1642:       best.typed_data.value = -1;
                   1643:       best.typed_data.unit = UNIT_REL;
                   1644:       best.typed_data.real = FALSE;
                   1645:       TtaSetStylePresentation (PRBorderBottomColor, element, tsch, context, best);
                   1646:     }
1.1       cvs      1647:   return (cssRule);
                   1648: }
                   1649: 
                   1650: /*----------------------------------------------------------------------
1.327     vatton   1651:   ParseCSSBorderRight: parse a CSS BorderRight
                   1652:   attribute string.                                          
1.1       cvs      1653:   ----------------------------------------------------------------------*/
1.79      cvs      1654: static char *ParseCSSBorderRight (Element element, PSchema tsch,
1.327     vatton   1655:                                   PresentationContext context, char *cssRule,
                   1656:                                   CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      1657: {
1.370     vatton   1658:   PresentationValue   best;
                   1659:   char               *ptr;
                   1660:   ThotBool            style, width, color;
1.43      cvs      1661: 
1.82      cvs      1662:   cssRule = SkipBlanksAndComments (cssRule);
1.322     vatton   1663:   /* register given values */
1.337     vatton   1664:   if (!strncmp (cssRule, "none", 4))
1.370     vatton   1665:     style = width = color = TRUE;
1.337     vatton   1666:   else
1.370     vatton   1667:     style = width = color = FALSE;
1.301     vatton   1668:   while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.43      cvs      1669:     {
                   1670:       ptr = cssRule;
                   1671:       cssRule = ParseCSSBorderStyleRight (element, tsch, context, cssRule, css, isHTML);
                   1672:       if (ptr == cssRule)
1.327     vatton   1673:         {
                   1674:           cssRule = ParseCSSBorderRightWidth (element, tsch, context, cssRule, css, isHTML);
                   1675:           if (ptr == cssRule)
1.370     vatton   1676:             {
                   1677:               cssRule = ParseCSSBorderColorRight (element, tsch, context, cssRule, css, isHTML);
                   1678:               if (ptr != cssRule)
                   1679:                 color = TRUE;
                   1680:             }
1.327     vatton   1681:           else
                   1682:             width = TRUE;
                   1683:           if (ptr == cssRule)
                   1684:             {
                   1685:               /* rule not found */
                   1686:               cssRule = SkipValue ("Invalid border value", cssRule);
                   1687:               return (cssRule);
                   1688:             }
                   1689:         }
1.322     vatton   1690:       else
1.327     vatton   1691:         style = TRUE;
1.82      cvs      1692:       cssRule = SkipBlanksAndComments (cssRule);
1.43      cvs      1693:     }
1.322     vatton   1694: 
                   1695:   if (!width)
1.405     kia      1696:     ParseCSSBorderRightWidth (element, tsch, context, (char*)"medium", css, isHTML);
1.322     vatton   1697:   if (!style)
1.405     kia      1698:     ParseCSSBorderStyleRight (element, tsch, context, (char*)"none", css, isHTML);
1.370     vatton   1699:   if (!color && DoApply)
                   1700:     {
                   1701:       /* get the box color */
                   1702:       best.typed_data.value = -1;
                   1703:       best.typed_data.unit = UNIT_REL;
1.374     vatton   1704:       best.typed_data.real = FALSE;
1.370     vatton   1705:       TtaSetStylePresentation (PRBorderRightColor, element, tsch, context, best);
                   1706:     }
1.1       cvs      1707:   return (cssRule);
                   1708: }
                   1709: 
                   1710: /*----------------------------------------------------------------------
1.327     vatton   1711:   ParseCSSBorder: parse a CSS border        
                   1712:   attribute string.                                          
1.42      cvs      1713:   ----------------------------------------------------------------------*/
1.79      cvs      1714: static char *ParseCSSBorder (Element element, PSchema tsch,
1.327     vatton   1715:                              PresentationContext context, char *cssRule,
                   1716:                              CSSInfoPtr css, ThotBool isHTML)
1.42      cvs      1717: {
1.79      cvs      1718:   char *ptrT, *ptrR;
1.366     vatton   1719:   int   skippedNL, n;
1.42      cvs      1720: 
1.82      cvs      1721:   ptrT = SkipBlanksAndComments (cssRule);
1.366     vatton   1722:   if (DoDialog)
                   1723:     n = NumberOfValues (ptrT);
                   1724:   if (DoDialog && n < 4)
1.42      cvs      1725:     {
1.366     vatton   1726:       // check if the border dialog must be updated
                   1727:       All_sides = TRUE;
                   1728:      ptrR = ParseCSSBorderTop (element, tsch, context, ptrT, css, isHTML);
                   1729:       All_sides = FALSE;
                   1730:     }
                   1731:   else
                   1732:     {
                   1733:       /* First parse Border-Top */
                   1734:       ptrR = ParseCSSBorderTop (element, tsch, context, ptrT, css, isHTML);
                   1735:       ptrR = SkipBlanksAndComments (ptrR);
                   1736:       if (*ptrR == ';' || *ptrR == '}' || *ptrR == EOS || *ptrR == ',')
                   1737:         {
                   1738:           skippedNL = NewLineSkipped;
                   1739:           cssRule = ptrR;
                   1740:           /* apply the Border-Top to all */
                   1741:           ptrR = ParseCSSBorderRight (element, tsch, context, ptrT, css, isHTML);
                   1742:           NewLineSkipped = skippedNL;
                   1743:           ptrR = ParseCSSBorderBottom (element, tsch, context, ptrT, css, isHTML);
                   1744:           NewLineSkipped = skippedNL;
                   1745:           ptrR = ParseCSSBorderLeft (element, tsch, context, ptrT, css, isHTML);
                   1746:         }
1.42      cvs      1747:     }
                   1748:   return (cssRule);
                   1749: }
                   1750: 
1.218     vatton   1751: 
1.42      cvs      1752: /*----------------------------------------------------------------------
1.327     vatton   1753:   ParseCSSFloat: parse a CSS float attribute string    
1.184     vatton   1754:   ----------------------------------------------------------------------*/
                   1755: static char *ParseCSSFloat (Element element, PSchema tsch,
1.327     vatton   1756:                             PresentationContext context, char *cssRule,
                   1757:                             CSSInfoPtr css, ThotBool isHTML)
1.184     vatton   1758: {
1.257     vatton   1759:   DisplayMode         dispMode;
1.184     vatton   1760:   PresentationValue   pval;
1.288     vatton   1761:   char               *ptr = cssRule;
1.404     vatton   1762:   ThotBool            warn;
1.184     vatton   1763: 
1.404     vatton   1764:   // check if Amaya should report CSS warnings
                   1765:   TtaGetEnvBoolean ("CSS_WARN", &warn);
1.184     vatton   1766:   pval.typed_data.value = 0;
1.187     vatton   1767:   pval.typed_data.unit = UNIT_BOX;
1.192     cvs      1768:   pval.typed_data.real = FALSE;
1.190     vatton   1769:   if (!strncasecmp (cssRule, "inherit", 7))
                   1770:     {
1.293     quint    1771:       pval.typed_data.unit = VALUE_INHERIT;
1.288     vatton   1772:       cssRule += 7;
1.190     vatton   1773:     }
1.184     vatton   1774:   if (!strncasecmp (cssRule, "none", 4))
1.288     vatton   1775:     {
                   1776:       pval.typed_data.value = FloatNone;
1.293     quint    1777:       cssRule += 4;
1.288     vatton   1778:     }
1.184     vatton   1779:   else if (!strncasecmp (cssRule, "left", 4))
1.288     vatton   1780:     {
                   1781:       pval.typed_data.value = FloatLeft;
1.293     quint    1782:       cssRule += 4;
1.288     vatton   1783:     }
1.184     vatton   1784:   else if (!strncasecmp (cssRule, "right", 5))
1.288     vatton   1785:     {
                   1786:       pval.typed_data.value = FloatRight;
1.293     quint    1787:       cssRule += 5;
1.288     vatton   1788:     }
1.184     vatton   1789: 
1.293     quint    1790:   if (pval.typed_data.value == 0 && pval.typed_data.unit != VALUE_INHERIT)
1.359     quint    1791:     {
                   1792:       if (!strncasecmp (cssRule, "top", 3) ||
                   1793:           !strncasecmp (cssRule, "bottom", 6) ||
                   1794:           !strncasecmp (cssRule, "inside", 6) ||
                   1795:           !strncasecmp (cssRule, "outside", 7) ||
                   1796:           !strncasecmp (cssRule, "start", 5) ||
                   1797:           !strncasecmp (cssRule, "end", 3))
1.404     vatton   1798:        {
                   1799:          if (warn)
                   1800:            cssRule = SkipValue ("Warning: CSS3 value not supported", cssRule);
                   1801:          else
                   1802:            cssRule = SkipValue (NULL, cssRule);
                   1803:        }
1.359     quint    1804:       else
                   1805:         cssRule = SkipValue ("Invalid float value", cssRule);
                   1806:     }
1.184     vatton   1807:   else
                   1808:     {
1.366     vatton   1809:       if (DoDialog)
                   1810:         DisplayStyleValue ("float", ptr, cssRule);
                   1811:       else if (DoApply)
1.327     vatton   1812:         {
                   1813:           dispMode = TtaGetDisplayMode (context->doc);
                   1814:           if (dispMode != NoComputedDisplay)
                   1815:             {
                   1816:               /* force a redisplay of the whole document */
                   1817:               TtaSetDisplayMode (context->doc, NoComputedDisplay);
1.257     vatton   1818: #ifdef AMAYA_DEBUG
1.327     vatton   1819:               /*printf ("Force NoComputedDisplay doc=%d\n", context->doc);*/
1.257     vatton   1820: #endif /* AMAYA_DEBUG */
1.327     vatton   1821:             }
                   1822:           TtaSetStylePresentation (PRFloat, element, tsch, context, pval);
                   1823:         }
1.288     vatton   1824:       cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid float value");
1.184     vatton   1825:     }
                   1826:   return (cssRule);
                   1827: }
                   1828: 
                   1829: /*----------------------------------------------------------------------
1.327     vatton   1830:   ParseCSSClear: parse a CSS clear rule 
1.1       cvs      1831:   ----------------------------------------------------------------------*/
1.79      cvs      1832: static char *ParseCSSClear (Element element, PSchema tsch,
1.327     vatton   1833:                             PresentationContext context, char *cssRule,
                   1834:                             CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      1835: {
1.184     vatton   1836:   PresentationValue   pval;
1.366     vatton   1837:   char               *start_value = cssRule;
1.184     vatton   1838: 
                   1839:   pval.typed_data.value = 0;
1.187     vatton   1840:   pval.typed_data.unit = UNIT_BOX;
1.193     vatton   1841:   pval.typed_data.real = FALSE;
1.190     vatton   1842:   if (!strncasecmp (cssRule, "inherit", 7))
1.293     quint    1843:     pval.typed_data.unit = VALUE_INHERIT;
1.184     vatton   1844:   if (!strncasecmp (cssRule, "none", 4))
                   1845:     pval.typed_data.value = ClearNone;
                   1846:   else if (!strncasecmp (cssRule, "left", 4))
                   1847:     pval.typed_data.value = ClearLeft;
                   1848:   else if (!strncasecmp (cssRule, "right", 5))
                   1849:     pval.typed_data.value = ClearRight;
                   1850:   else if (!strncasecmp (cssRule, "both", 4))
                   1851:     pval.typed_data.value = ClearBoth;
                   1852: 
1.293     quint    1853:   if (pval.typed_data.value == 0 && pval.typed_data.unit != VALUE_INHERIT)
1.295     vatton   1854:     {
                   1855:       cssRule = SkipValue ("Invalid clear value", cssRule);
                   1856:       cssRule = SkipValue (NULL, cssRule);
                   1857:     }
1.184     vatton   1858:   else
                   1859:     {
1.295     vatton   1860:       cssRule = SkipValue (NULL, cssRule);
1.366     vatton   1861:       if (DoDialog)
                   1862:         DisplayStyleValue ("clear", start_value, cssRule);
                   1863:       else if (DoApply)
1.327     vatton   1864:         TtaSetStylePresentation (PRClear, element, tsch, context, pval);
1.184     vatton   1865:     }
                   1866:   return (cssRule);
                   1867: }
                   1868: 
                   1869: /*----------------------------------------------------------------------
1.333     vatton   1870:   ParseCSSVisibility: parse a CSS visibility attribute string        
                   1871:   ----------------------------------------------------------------------*/
                   1872: static char *ParseCSSVisibility(Element element, PSchema tsch,
                   1873:                                 PresentationContext context, char *cssRule,
                   1874:                                 CSSInfoPtr css, ThotBool isHTML)
                   1875: {
                   1876:   PresentationValue   pval;
1.366     vatton   1877:   char               *ptr;
1.333     vatton   1878: 
                   1879:   pval.typed_data.unit = UNIT_REL;
                   1880:   pval.typed_data.real = FALSE;
                   1881:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   1882:   ptr = cssRule;
1.333     vatton   1883:   if (!strncasecmp (cssRule, "hidden", 6))
                   1884:     {
                   1885:       cssRule += 6;
                   1886:       pval.typed_data.value = VsHidden;
                   1887:     }
                   1888:   else if (!strncasecmp (cssRule, "visible", 7))
                   1889:     {
                   1890:       cssRule += 7;
                   1891:       pval.typed_data.value = VsVisible;
                   1892:     }
                   1893:   else if (!strncasecmp (cssRule, "collapse", 8))
                   1894:     {
                   1895:       cssRule += 8;
                   1896:       pval.typed_data.value = VsCollapse;
                   1897:     }
                   1898:   else if (!strncasecmp (cssRule, "inherit", 7))
                   1899:     {
                   1900:       cssRule += 7;
                   1901:       pval.typed_data.value = VsInherit;
                   1902:     }
                   1903:   else
                   1904:     {
                   1905:       cssRule = SkipValue ("Invalid visibility value", cssRule);
                   1906:       return (cssRule);
                   1907:     }
1.366     vatton   1908:   if (DoDialog)
                   1909:     DisplayStyleValue ("visibility", ptr, cssRule);
                   1910:   else if (DoApply)
1.333     vatton   1911:     TtaSetStylePresentation (PRVis, element, tsch, context, pval);
                   1912:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid visibility value");
                   1913:   return (cssRule);
                   1914: }
                   1915: 
                   1916: 
                   1917: /*----------------------------------------------------------------------
1.327     vatton   1918:   ParseCSSDisplay: parse a CSS display attribute string        
1.1       cvs      1919:   ----------------------------------------------------------------------*/
1.79      cvs      1920: static char *ParseCSSDisplay (Element element, PSchema tsch,
1.327     vatton   1921:                               PresentationContext context, char *cssRule,
                   1922:                               CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      1923: {
1.184     vatton   1924:   PresentationValue   pval;
1.366     vatton   1925:   char               *ptr;
1.404     vatton   1926:   ThotBool            warn;
1.1       cvs      1927: 
1.184     vatton   1928:   pval.typed_data.unit = UNIT_REL;
                   1929:   pval.typed_data.real = FALSE;
                   1930:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   1931:   ptr = cssRule;
1.184     vatton   1932:   if (!strncasecmp (cssRule, "none", 4))
1.288     vatton   1933:     {
                   1934:       cssRule += 4;
                   1935:       pval.typed_data.value = DisplayNone;
                   1936:     }
1.277     quint    1937:   else if (!strncasecmp (cssRule, "block", 5))
1.288     vatton   1938:     {
                   1939:       cssRule += 5;
                   1940:       pval.typed_data.value = Block;
                   1941:     }
1.303     vatton   1942:   else if (!strncasecmp (cssRule, "inline-block", 12))
                   1943:     {
                   1944:       cssRule += 12;
                   1945:       pval.typed_data.value = InlineBlock;
                   1946:     }
1.277     quint    1947:   else if (!strncasecmp (cssRule, "inline", 6))
1.288     vatton   1948:     {
                   1949:       cssRule += 6;
                   1950:       pval.typed_data.value = Inline;
                   1951:     }
1.277     quint    1952:   else if (!strncasecmp (cssRule, "list-item", 9))
1.288     vatton   1953:     {
                   1954:       cssRule += 9;
                   1955:       pval.typed_data.value = ListItem;
                   1956:     }
1.277     quint    1957:   else if (!strncasecmp (cssRule, "run-in", 6))
1.288     vatton   1958:     {
                   1959:       cssRule += 6;
                   1960:       pval.typed_data.value = RunIn;
                   1961:     }
1.293     quint    1962:   else if (!strncasecmp (cssRule, "inherit", 7))
                   1963:     {
                   1964:       cssRule += 7;
                   1965:       pval.typed_data.unit = VALUE_INHERIT;
                   1966:     }
1.277     quint    1967:   else
1.184     vatton   1968:     {
1.404     vatton   1969:       TtaGetEnvBoolean ("CSS_WARN", &warn);
                   1970:       if (warn &&
                   1971:          strncasecmp (cssRule, "table-row-group", 15) &&
1.327     vatton   1972:           strncasecmp (cssRule, "table-column-group", 18) &&
                   1973:           strncasecmp (cssRule, "table-header-group", 5) &&
                   1974:           strncasecmp (cssRule, "table-footer-group", 6) &&
                   1975:           strncasecmp (cssRule, "table-row", 9) &&
                   1976:           strncasecmp (cssRule, "table-column", 12) &&
                   1977:           strncasecmp (cssRule, "table-cell", 10) &&
                   1978:           strncasecmp (cssRule, "table-caption", 13) &&
                   1979:           strncasecmp (cssRule, "inline-table", 12) &&
                   1980:           strncasecmp (cssRule, "table", 5))
                   1981:         cssRule = SkipValue ("Display value not supported", cssRule);
1.281     quint    1982:       else
1.327     vatton   1983:         cssRule = SkipWord (cssRule);
1.277     quint    1984:       return (cssRule);
1.184     vatton   1985:     }
1.277     quint    1986: 
1.366     vatton   1987:   if (DoDialog)
                   1988:     DisplayStyleValue ("display", ptr, cssRule);
                   1989:   else if (DoApply)
1.295     vatton   1990:     TtaSetStylePresentation (PRDisplay, element, tsch, context, pval);
1.288     vatton   1991:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid display value");
1.1       cvs      1992:   return (cssRule);
                   1993: }
                   1994: 
                   1995: /*----------------------------------------------------------------------
1.327     vatton   1996:   ParseCSSLetterSpacing: parse a CSS letter-spacing    
                   1997:   attribute string.                                          
1.1       cvs      1998:   ----------------------------------------------------------------------*/
1.79      cvs      1999: static char *ParseCSSLetterSpacing (Element element, PSchema tsch,
1.327     vatton   2000:                                     PresentationContext context, char *cssRule,
                   2001:                                     CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      2002: {
1.366     vatton   2003:   char               *start_value = cssRule;
                   2004: 
1.168     vatton   2005:   cssRule = SkipValue (NULL, cssRule);
1.366     vatton   2006:   if (DoDialog)
                   2007:     DisplayStyleValue ("letter-spacing", start_value, cssRule);
1.1       cvs      2008:   return (cssRule);
                   2009: }
                   2010: 
                   2011: /*----------------------------------------------------------------------
1.436     quint    2012:   ParseCounterStyle: parse a CSS counter style.
1.1       cvs      2013:   ----------------------------------------------------------------------*/
1.436     quint    2014: static char *ParseCounterStyle (char *cssRule, PresentationValue *pval,
                   2015:                                char *start_value)
1.1       cvs      2016: {
1.436     quint    2017:   (*pval).typed_data.unit = UNIT_REL;
                   2018:   (*pval).typed_data.real = FALSE;
1.281     quint    2019:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   2020:   start_value = cssRule;
1.281     quint    2021:   if (!strncasecmp (cssRule, "disc", 4))
1.288     vatton   2022:     {
                   2023:       cssRule += 4;
1.436     quint    2024:       (*pval).typed_data.value = Disc;
1.288     vatton   2025:     }
1.281     quint    2026:   else if (!strncasecmp (cssRule, "circle", 6))
1.293     quint    2027:     {
1.288     vatton   2028:       cssRule += 6;
1.436     quint    2029:       (*pval).typed_data.value = Circle;
1.293     quint    2030:     }
1.281     quint    2031:   else if (!strncasecmp (cssRule, "square", 6))
1.293     quint    2032:     {
1.288     vatton   2033:       cssRule += 6;
1.436     quint    2034:       (*pval).typed_data.value = Square;
1.293     quint    2035:     }
1.283     quint    2036:   else if (!strncasecmp (cssRule, "decimal-leading-zero", 20))
1.293     quint    2037:     {
1.288     vatton   2038:       cssRule += 20;
1.436     quint    2039:       (*pval).typed_data.value = DecimalLeadingZero;
1.293     quint    2040:     }
1.281     quint    2041:   else if (!strncasecmp (cssRule, "decimal", 7))
1.293     quint    2042:     {
1.288     vatton   2043:       cssRule += 7;
1.436     quint    2044:       (*pval).typed_data.value = Decimal;
1.293     quint    2045:     }
1.281     quint    2046:   else if (!strncasecmp (cssRule, "lower-roman", 11))
1.293     quint    2047:     {
1.288     vatton   2048:       cssRule += 11;
1.436     quint    2049:       (*pval).typed_data.value = LowerRoman;
1.293     quint    2050:     }
1.281     quint    2051:   else if (!strncasecmp (cssRule, "upper-roman", 11))
1.293     quint    2052:     {
1.288     vatton   2053:       cssRule += 11;
1.436     quint    2054:       (*pval).typed_data.value = UpperRoman;
1.293     quint    2055:     }
1.281     quint    2056:   else if (!strncasecmp (cssRule, "lower-greek", 11))
1.293     quint    2057:     {
1.288     vatton   2058:       cssRule += 11;
1.436     quint    2059:       (*pval).typed_data.value = LowerGreek;
1.293     quint    2060:     }
1.281     quint    2061:   else if (!strncasecmp (cssRule, "lower-latin", 11))
1.293     quint    2062:     {
1.288     vatton   2063:       cssRule += 11;
1.436     quint    2064:       (*pval).typed_data.value = LowerLatin;
1.293     quint    2065:     }
1.281     quint    2066:   else if (!strncasecmp (cssRule, "lower-alpha", 11))
1.293     quint    2067:     {
1.288     vatton   2068:       cssRule += 11;
1.436     quint    2069:       (*pval).typed_data.value = LowerLatin;
1.293     quint    2070:     }
1.281     quint    2071:   else if (!strncasecmp (cssRule, "upper-latin", 11))
1.293     quint    2072:     {
1.288     vatton   2073:       cssRule += 11;
1.436     quint    2074:       (*pval).typed_data.value = UpperLatin;
1.293     quint    2075:     }
1.281     quint    2076:   else if (!strncasecmp (cssRule, "upper-alpha", 11))
1.293     quint    2077:     {
1.288     vatton   2078:       cssRule += 11;
1.436     quint    2079:       (*pval).typed_data.value = UpperLatin;
1.293     quint    2080:     }
1.281     quint    2081:   else if (!strncasecmp (cssRule, "armenian", 8))
1.293     quint    2082:     {
1.288     vatton   2083:       cssRule += 8;
1.436     quint    2084:       (*pval).typed_data.value = Decimal;
1.293     quint    2085:     }
1.281     quint    2086:   else if (!strncasecmp (cssRule, "georgian", 8))
1.293     quint    2087:     {
1.288     vatton   2088:       cssRule += 8;
1.436     quint    2089:       (*pval).typed_data.value = Decimal;
1.293     quint    2090:     }
1.281     quint    2091:   else if (!strncasecmp (cssRule, "none", 4))
1.293     quint    2092:     {
1.288     vatton   2093:       cssRule += 4;
1.436     quint    2094:       (*pval).typed_data.value = ListStyleTypeNone;
1.293     quint    2095:     }
1.281     quint    2096:   else if (!strncasecmp (cssRule, "inherit", 7))
                   2097:     {
1.293     quint    2098:       cssRule += 7;
1.436     quint    2099:       (*pval).typed_data.unit = VALUE_INHERIT;
1.281     quint    2100:     }
                   2101:   else
1.436     quint    2102:     cssRule = SkipValue ("Invalid list-style-type value", cssRule);
                   2103:   return (cssRule);
                   2104: }
                   2105: 
                   2106: /*----------------------------------------------------------------------
                   2107:   ParseACSSListStyleType: parse a CSS list-style-type
                   2108:   attribute string.                                          
                   2109:   ----------------------------------------------------------------------*/
                   2110: static char *ParseACSSListStyleType (Element element, PSchema tsch,
                   2111:                                      PresentationContext context, char *cssRule,
                   2112:                                      CSSInfoPtr css, ThotBool isHTML)
                   2113: {
                   2114:   PresentationValue   pval;
                   2115:   char               *start_value;
1.281     quint    2116: 
1.436     quint    2117:   cssRule = ParseCounterStyle (cssRule, &pval, start_value);
1.366     vatton   2118:   if (DoDialog)
                   2119:     DisplayStyleValue ("list-style-type", start_value, cssRule);
                   2120:   else if (DoApply)
1.295     vatton   2121:     TtaSetStylePresentation (PRListStyleType, element, tsch, context, pval);
1.318     vatton   2122:   return (cssRule);
                   2123: }
                   2124: 
                   2125: /*----------------------------------------------------------------------
1.327     vatton   2126:   ParseCSSListStyleType: parse a CSS list-style-type
                   2127:   attribute string.                                          
1.318     vatton   2128:   ----------------------------------------------------------------------*/
                   2129: static char *ParseCSSListStyleType (Element element, PSchema tsch,
1.327     vatton   2130:                                     PresentationContext context, char *cssRule,
                   2131:                                     CSSInfoPtr css, ThotBool isHTML)
1.318     vatton   2132: {
                   2133:   char               *ptr = cssRule;
                   2134:   cssRule = ParseACSSListStyleType (element, tsch, context, cssRule, css,
1.327     vatton   2135:                                     isHTML);
1.288     vatton   2136:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid list-style-type value");
1.318     vatton   2137:   return cssRule;
1.1       cvs      2138: }
                   2139: 
                   2140: /*----------------------------------------------------------------------
1.281     quint    2141:   ParseCSSUrl: parse an URL
1.375     vatton   2142:   Parse the url content (don't start with "url")
                   2143:   Return the next pointer in the CSS string
                   2144:   If a correct URL is found, it's returned in url (this string must
                   2145:   be freed)
1.281     quint    2146:   ----------------------------------------------------------------------*/
                   2147: static char *ParseCSSUrl (char *cssRule, char **url)
                   2148: {
                   2149:   char                       saved;
                   2150:   char                      *base, *ptr;
                   2151: 
                   2152:   cssRule = SkipBlanksAndComments (cssRule);
                   2153:   saved = *cssRule;
                   2154:   if (*cssRule == '(')
                   2155:     {
                   2156:       cssRule++;
                   2157:       cssRule = SkipBlanksAndComments (cssRule);
                   2158:       /*** Escaped quotes are not handled. See function SkipQuotedString */
                   2159:       if (*cssRule == '"')
1.327     vatton   2160:         {
                   2161:           cssRule++;
                   2162:           base = cssRule;
                   2163:           while (*cssRule != EOS && *cssRule != '"')
                   2164:             cssRule++;
                   2165:         }
1.281     quint    2166:       else if (*cssRule == '\'')
1.327     vatton   2167:         {
                   2168:           cssRule++;
                   2169:           base = cssRule;
                   2170:           while (*cssRule != EOS && *cssRule != '\'')
                   2171:             cssRule++;
                   2172:         }
1.281     quint    2173:       else
1.327     vatton   2174:         {
                   2175:           base = cssRule;
                   2176:           while (*cssRule != EOS && *cssRule != ')')
                   2177:             cssRule++;
                   2178:         }
1.281     quint    2179:       /* keep the current position */
                   2180:       ptr = cssRule;
1.402     vatton   2181:       if (saved == '(')
1.327     vatton   2182:         {
                   2183:           /* remove extra spaces */
                   2184:           if (cssRule[-1] == SPACE)
                   2185:             {
                   2186:               *cssRule = SPACE;
                   2187:               cssRule--;
                   2188:               while (cssRule[-1] == SPACE)
                   2189:                 cssRule--;
                   2190:             }
                   2191:         }
1.281     quint    2192:       saved = *cssRule;
                   2193:       *cssRule = EOS;
                   2194:       *url = TtaStrdup (base);
                   2195:       *cssRule = saved;
                   2196:       if (saved == '"' || saved == '\'')
1.327     vatton   2197:         /* we need to skip the quote character and possible spaces */
                   2198:         {
                   2199:           cssRule++;
                   2200:           cssRule = SkipBlanksAndComments (cssRule);
                   2201:         }
1.281     quint    2202:       else
1.327     vatton   2203:         cssRule = ptr;
1.281     quint    2204:     }
                   2205:   cssRule++;
                   2206:   return cssRule;
                   2207: }
                   2208: 
                   2209: /*----------------------------------------------------------------------
1.302     quint    2210:   ParseCSSImageCallback: Callback called asynchronously by
                   2211:   FetchImage when a CSS image (background-image or list-style-image)
                   2212:   has been fetched.
                   2213:   ----------------------------------------------------------------------*/
                   2214: void ParseCSSImageCallback (Document doc, Element element, char *file,
1.327     vatton   2215:                             void *extra, ThotBool isnew)
1.302     quint    2216: {
                   2217:   DisplayMode                dispMode = DisplayImmediately;
                   2218:   CSSImageCallbackPtr        callblock;
                   2219:   Element                    el;
                   2220:   PSchema                    tsch;
1.401     vatton   2221:   Document                   redisplaydoc;
                   2222:   PInfoPtr                   pInfo = NULL;
1.302     quint    2223:   CSSInfoPtr                 css;
                   2224:   PresentationContext        ctxt;
                   2225:   PresentationValue          image;
                   2226:   PresentationValue          value;
1.400     vatton   2227:   ThotBool                   found;
1.302     quint    2228: 
                   2229:   callblock = (CSSImageCallbackPtr) extra;
                   2230:   if (callblock == NULL)
                   2231:     return;
                   2232: 
1.400     vatton   2233:   css = callblock->css;
1.302     quint    2234:   el = callblock->el;
                   2235:   tsch = callblock->tsch;
                   2236:   ctxt = callblock->ctxt;
1.401     vatton   2237:   redisplaydoc = ctxt->doc;
1.302     quint    2238:   if (doc == 0 && !isnew)
                   2239:     /* apply to the current document only */
1.401     vatton   2240:     doc = redisplaydoc;
1.302     quint    2241:   if (doc)
1.401     vatton   2242:     redisplaydoc = doc;
1.302     quint    2243:   else
                   2244:     {
                   2245:       /* check if the CSS still exists */
                   2246:       css = CSSList;
                   2247:       while (css && css != callblock->css)
1.327     vatton   2248:         css = css->NextCSS;
1.302     quint    2249:       if (css == NULL)
1.400     vatton   2250:         // the presentation schema doesn't exist anymore
1.327     vatton   2251:         tsch = NULL;
1.302     quint    2252:     }
1.400     vatton   2253: 
1.401     vatton   2254:   if (tsch && css && ctxt && redisplaydoc)
1.400     vatton   2255:     {
                   2256:       // check if the presentation schema is still there
1.401     vatton   2257:       pInfo = css->infos[redisplaydoc];
                   2258:       if (pInfo == NULL && DocumentURLs[redisplaydoc] == NULL)
                   2259:         {
                   2260:           // the redisplaydoc was probably an object
                   2261:           while (redisplaydoc > 0 && pInfo == 0)
                   2262:             pInfo = css->infos[--redisplaydoc];
                   2263:           if (redisplaydoc)
                   2264:             ctxt->doc = redisplaydoc;
                   2265:         }
                   2266: 
1.400     vatton   2267:       found = FALSE;
                   2268:       while (!found && pInfo)
                   2269:         {
                   2270:           found = (pInfo->PiSchemas && tsch == pInfo->PiSchemas->PiPSchema);
                   2271:           pInfo = pInfo->PiNext;
                   2272:         }
                   2273:       if (!found)
                   2274:         tsch = NULL;
                   2275:    }
                   2276: 
1.302     quint    2277:   if (el || tsch)
                   2278:     {
                   2279:       /* Ok the image was fetched */
                   2280:       image.typed_data.unit = UNIT_REL;
                   2281:       image.typed_data.real = FALSE;
                   2282:       image.pointer = file;
                   2283:       TtaSetStylePresentation (callblock->ruleType, el, tsch, ctxt, image);
                   2284:       
                   2285:       if (callblock->ruleType == PRBackgroundPicture)
1.327     vatton   2286:         /* enforce the showbox */
                   2287:         {
                   2288:           value.typed_data.value = 1;
                   2289:           value.typed_data.unit = UNIT_REL;
                   2290:           value.typed_data.real = FALSE;
                   2291:           TtaSetStylePresentation (PRShowBox, el, tsch, ctxt, value);
                   2292:         }
1.302     quint    2293:       /* check if the context can be freed */
                   2294:       ctxt->uses -= 1;
                   2295:       if (ctxt->uses == 0)
1.327     vatton   2296:         /* no other image loading */
                   2297:         TtaFreeMemory (ctxt);
1.302     quint    2298:     }
                   2299: 
                   2300:   TtaFreeMemory (callblock);
1.330     cvs      2301:   if (css)
                   2302:     RedisplayImages--;
1.401     vatton   2303:   if (redisplaydoc &&
                   2304:       /* check if all background images are now loaded */
                   2305:       (css == NULL || (pInfo && Style_parsing == 0 && RedisplayImages == 0)))
                   2306:     {
                   2307:       /* don't manage a document used by make book */
                   2308:       if (DocumentMeta[redisplaydoc] == NULL ||
                   2309:           DocumentMeta[redisplaydoc]->method != CE_MAKEBOOK)
1.327     vatton   2310:         {
                   2311:           /* Change the Display Mode to take into account the new
                   2312:              presentation */
1.401     vatton   2313:           dispMode = TtaGetDisplayMode (redisplaydoc);
1.313     vatton   2314:           /* force the redisplay of this box */
1.435     vatton   2315:           if (dispMode == DisplayImmediately)
                   2316:             TtaSetDisplayMode (redisplaydoc, NoComputedDisplay);
1.401     vatton   2317:           TtaSetDisplayMode (redisplaydoc, dispMode);
1.327     vatton   2318:         }
1.330     cvs      2319:       RedisplayBGImage = FALSE;
1.302     quint    2320:     }
1.310     vatton   2321:   else
1.328     vatton   2322:     RedisplayBGImage = TRUE;
1.302     quint    2323: }
                   2324: 
                   2325: /*----------------------------------------------------------------------
                   2326:   SetCSSImage fetch the image referred by a background-image or a
                   2327:   list-style-image property.
                   2328:   ----------------------------------------------------------------------*/
                   2329: static char *SetCSSImage (Element element, PSchema tsch,
1.327     vatton   2330:                           PresentationContext ctxt, char *cssRule,
                   2331:                           CSSInfoPtr css, unsigned int ruleType)
1.302     quint    2332: {
                   2333:   CSSImageCallbackPtr        callblock;
                   2334:   Element                    el;
1.304     cvs      2335:   PresentationValue          image;
1.366     vatton   2336:   char                      *url, *ptr;
1.302     quint    2337:   char                      *bg_image;
                   2338:   char                       tempname[MAX_LENGTH];
                   2339:   char                       imgname[MAX_LENGTH];
                   2340: 
                   2341:   if (element)
                   2342:     el = element;
                   2343:   else
                   2344:     /* default element for FetchImage */
                   2345:     el = TtaGetMainRoot (ctxt->doc);
                   2346:   url = NULL;
1.370     vatton   2347:   image.typed_data.real = FALSE;
1.302     quint    2348:   cssRule = ParseCSSUrl (cssRule, &url);
1.414     vatton   2349:   if (strlen (url) > MAX_LENGTH / 4)
                   2350:     url[MAX_LENGTH / 4] = EOS;
1.366     vatton   2351:   ptr = cssRule;
1.302     quint    2352:   if (ctxt->destroy)
                   2353:     {
                   2354:       /* remove the background image PRule */
                   2355:       image.pointer = NULL;
1.366     vatton   2356:       TtaSetStylePresentation (ruleType, element, tsch, ctxt, image);
1.302     quint    2357:     }
1.366     vatton   2358:   else if (url)
1.302     quint    2359:     {
1.366     vatton   2360:       if (css && css->url)
                   2361:         /* the image concerns a CSS file */
                   2362:         NormalizeURL (url, 0, tempname, imgname, css->url);
                   2363:       else
                   2364:         /* the image concerns a style element */
                   2365:         NormalizeURL (url, ctxt->doc, tempname, imgname, NULL);
                   2366:       if (DoDialog)
                   2367:         {
                   2368:           if (ruleType == PRBackgroundPicture)
                   2369:             DisplayStyleValue ("background-image", tempname, &tempname[MAX_LENGTH-1]);
                   2370:           else if (ruleType == PRListStyleImage)
                   2371:             DisplayStyleValue ("list-style-image", tempname, &tempname[MAX_LENGTH-1]);
                   2372:           else if (ruleType == PRContentURL)
                   2373:             DisplayStyleValue ("", ptr, cssRule);
                   2374:         }
                   2375:       else if (DoApply)
                   2376:         {
                   2377:           bg_image = TtaGetEnvString ("ENABLE_BG_IMAGES");
                   2378:           if (bg_image == NULL || !strcasecmp (bg_image, "yes"))
                   2379:             /* background images are enabled */
                   2380:             {
                   2381:               callblock = (CSSImageCallbackPtr) TtaGetMemory (sizeof (CSSImageCallbackBlock));
                   2382:               if (callblock)
                   2383:                 {
                   2384:                   callblock->el = element;
                   2385:                   callblock->tsch = tsch;
                   2386:                   callblock->css = css;
                   2387:                   callblock->ctxt = ctxt;
                   2388:                   callblock->ruleType = ruleType;
                   2389:                   /* new use of the context */
                   2390:                   ctxt->uses += 1;
                   2391:                   /* check if the image url is related to an external CSS */
                   2392:                   if (css)
                   2393:                     {
                   2394:                       /* fetch and display background image of element */
                   2395:                       if (FetchImage (0, el, tempname, AMAYA_LOAD_IMAGE,
                   2396:                                       ParseCSSImageCallback, callblock))
                   2397:                         RedisplayImages++;
                   2398:                     }
1.327     vatton   2399:                   else
1.366     vatton   2400:                     FetchImage (ctxt->doc, el, url, AMAYA_LOAD_IMAGE,
                   2401:                                 ParseCSSImageCallback, callblock);
1.327     vatton   2402:                 }
                   2403:             }
                   2404:         }
1.366     vatton   2405:       TtaFreeMemory (url);
1.302     quint    2406:     }
                   2407:   return (cssRule);
                   2408: }
                   2409: 
                   2410: /*----------------------------------------------------------------------
1.327     vatton   2411:   ParseACSSListStyleImage: parse a CSS list-style-image
                   2412:   attribute string.                                          
1.1       cvs      2413:   ----------------------------------------------------------------------*/
1.318     vatton   2414: static char *ParseACSSListStyleImage (Element element, PSchema tsch,
1.327     vatton   2415:                                       PresentationContext ctxt,
                   2416:                                       char *cssRule, CSSInfoPtr css,
                   2417:                                       ThotBool isHTML)
1.1       cvs      2418: {
1.288     vatton   2419:   char               *url;
1.366     vatton   2420:   char               *start_value;
1.293     quint    2421:   PresentationValue   pval;
1.281     quint    2422: 
1.293     quint    2423:   pval.typed_data.unit = UNIT_REL;
                   2424:   pval.typed_data.real = FALSE;
1.281     quint    2425:   url = NULL;
                   2426:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   2427:   start_value = cssRule;
1.281     quint    2428:   if (!strncasecmp (cssRule, "none", 4))
                   2429:     {
                   2430:       cssRule += 4;
1.302     quint    2431:       pval.typed_data.value = 0;
1.366     vatton   2432:       if (DoDialog)
                   2433:         DisplayStyleValue ("list-style-image", start_value, cssRule);
                   2434:       else if (DoApply)
1.327     vatton   2435:         TtaSetStylePresentation (PRListStyleImage, element, tsch, ctxt, pval);
1.281     quint    2436:     }
                   2437:   else if (!strncasecmp (cssRule, "url", 3))
                   2438:     {  
                   2439:       cssRule += 3;
1.302     quint    2440:       cssRule = SetCSSImage (element, tsch, ctxt, cssRule, css,
1.327     vatton   2441:                              PRListStyleImage);
1.281     quint    2442:     }
                   2443:   else if (!strncasecmp (cssRule, "inherit", 7))
1.288     vatton   2444:     {
                   2445:       cssRule += 7;
1.293     quint    2446:       pval.typed_data.unit = VALUE_INHERIT;
1.366     vatton   2447:       if (DoDialog)
                   2448:         DisplayStyleValue ("list-style-image", start_value, cssRule);
                   2449:       else if (DoApply)
1.327     vatton   2450:         TtaSetStylePresentation (PRListStyleImage, element, tsch, ctxt, pval);
                   2451:     }
1.281     quint    2452:   else
1.295     vatton   2453:       cssRule = SkipValue ("Invalid list-style-image value", cssRule);
1.1       cvs      2454:   return (cssRule);
                   2455: }
                   2456: 
                   2457: /*----------------------------------------------------------------------
1.327     vatton   2458:   ParseCSSListStyleImage: parse a CSS list-style-image
                   2459:   attribute string.                                          
1.318     vatton   2460:   ----------------------------------------------------------------------*/
                   2461: static char *ParseCSSListStyleImage (Element element, PSchema tsch,
1.327     vatton   2462:                                      PresentationContext ctxt,
                   2463:                                      char *cssRule, CSSInfoPtr css,
                   2464:                                      ThotBool isHTML)
1.318     vatton   2465: {
                   2466:   char               *ptr = cssRule;
                   2467:   cssRule = ParseACSSListStyleImage (element, tsch, ctxt, cssRule, css,
1.327     vatton   2468:                                      isHTML);
1.318     vatton   2469:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid list-style-image value");
                   2470:   return cssRule;
                   2471: }
                   2472: 
                   2473: /*----------------------------------------------------------------------
1.327     vatton   2474:   ParseACSSListStylePosition: parse a CSS list-style-position
                   2475:   attribute string.                                          
1.1       cvs      2476:   ----------------------------------------------------------------------*/
1.318     vatton   2477: static char *ParseACSSListStylePosition (Element element, PSchema tsch,
1.327     vatton   2478:                                          PresentationContext context,
                   2479:                                          char *cssRule, CSSInfoPtr css,
                   2480:                                          ThotBool isHTML)
1.1       cvs      2481: {
1.281     quint    2482:   PresentationValue   pval;
1.366     vatton   2483:   char               *start_value;
1.281     quint    2484: 
                   2485:   pval.typed_data.unit = UNIT_REL;
                   2486:   pval.typed_data.real = FALSE;
                   2487:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   2488:   start_value = cssRule;
1.281     quint    2489:   if (!strncasecmp (cssRule, "inside", 6))
1.288     vatton   2490:     {
                   2491:       pval.typed_data.value = Inside;
                   2492:       cssRule += 6;
                   2493:     }
1.281     quint    2494:   else if (!strncasecmp (cssRule, "outside", 7))
1.288     vatton   2495:     {
                   2496:       pval.typed_data.value = Outside;
                   2497:       cssRule += 7;
                   2498:     }
1.293     quint    2499:   else if (!strncasecmp (cssRule, "inherit", 7))
                   2500:     {
                   2501:       pval.typed_data.unit = VALUE_INHERIT;
                   2502:       cssRule += 7;
                   2503:     }
1.281     quint    2504:   else
                   2505:     {
1.293     quint    2506:       cssRule = SkipValue ("Invalid list-style-position value", cssRule);
1.281     quint    2507:       return (cssRule);
                   2508:     }
1.293     quint    2509: 
1.366     vatton   2510:   if (DoDialog)
                   2511:     DisplayStyleValue ("list-style-position", start_value, cssRule);
                   2512:   else if (DoApply)
1.295     vatton   2513:     TtaSetStylePresentation (PRListStylePosition, element, tsch, context, pval);
1.327     vatton   2514:   return (cssRule);
1.318     vatton   2515: }
                   2516: 
                   2517: /*----------------------------------------------------------------------
1.327     vatton   2518:   ParseCSSListStylePosition: parse a CSS list-style-position
                   2519:   attribute string.                                          
1.318     vatton   2520:   ----------------------------------------------------------------------*/
                   2521: static char *ParseCSSListStylePosition (Element element, PSchema tsch,
1.327     vatton   2522:                                         PresentationContext context,
                   2523:                                         char *cssRule, CSSInfoPtr css,
                   2524:                                         ThotBool isHTML)
1.318     vatton   2525: {
                   2526:   char               *ptr = cssRule;
                   2527:   cssRule = ParseACSSListStylePosition (element, tsch, context, cssRule, css,
1.327     vatton   2528:                                         isHTML);
1.288     vatton   2529:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid list-style-position value");
1.318     vatton   2530:   return cssRule;
1.1       cvs      2531: }
                   2532: 
                   2533: /*----------------------------------------------------------------------
1.327     vatton   2534:   ParseCSSListStyle: parse a CSS list-style value string.                                          
1.1       cvs      2535:   ----------------------------------------------------------------------*/
1.79      cvs      2536: static char *ParseCSSListStyle (Element element, PSchema tsch,
1.327     vatton   2537:                                 PresentationContext ctxt, char *cssRule,
                   2538:                                 CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      2539: {
1.318     vatton   2540:   char               *ptr = cssRule;
                   2541:   int                 skippedNL;
1.281     quint    2542: 
                   2543:   cssRule = SkipBlanksAndComments (cssRule);
1.301     vatton   2544:   while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.281     quint    2545:     {
1.316     quint    2546:       skippedNL = NewLineSkipped;
1.281     quint    2547:       /* perhaps a list-style-image */
                   2548:       if (!strncasecmp (cssRule, "url", 3))
1.327     vatton   2549:         cssRule = ParseACSSListStyleImage (element, tsch, ctxt, cssRule, css,
                   2550:                                            isHTML);
1.281     quint    2551:       /* perhaps a list-style-position */
                   2552:       else if (!strncasecmp (cssRule, "inside", 6) ||
                   2553:                !strncasecmp (cssRule, "outside", 7))
1.327     vatton   2554:         cssRule = ParseACSSListStylePosition (element, tsch, ctxt, cssRule,
                   2555:                                               css, isHTML);
1.281     quint    2556:       /* perhaps a list-style-type */
                   2557:       else if (!strncasecmp (cssRule, "disc", 4) ||
1.327     vatton   2558:                !strncasecmp (cssRule, "circle", 6) ||
                   2559:                !strncasecmp (cssRule, "square", 6) ||
                   2560:                !strncasecmp (cssRule, "decimal", 7) ||
                   2561:                !strncasecmp (cssRule, "decimal-leading-zero", 20) ||
                   2562:                !strncasecmp (cssRule, "lower-roman", 11) ||
                   2563:                !strncasecmp (cssRule, "upper-roman", 11) ||
                   2564:                !strncasecmp (cssRule, "lower-greek", 11) ||
                   2565:                !strncasecmp (cssRule, "lower-latin", 11) ||
                   2566:                !strncasecmp (cssRule, "lower-alpha", 11) ||
                   2567:                !strncasecmp (cssRule, "upper-latin", 11) ||
                   2568:                !strncasecmp (cssRule, "upper-alpha", 11) ||
                   2569:                !strncasecmp (cssRule, "armenian", 8) ||
                   2570:                !strncasecmp (cssRule, "georgian", 8) ||
                   2571:                !strncasecmp (cssRule, "none", 4) ||
                   2572:                !strncasecmp (cssRule, "inherit", 7))
                   2573:         cssRule = ParseACSSListStyleType (element, tsch, ctxt, cssRule, css,
                   2574:                                           isHTML);
1.281     quint    2575:       else
1.327     vatton   2576:         {
                   2577:           NewLineSkipped = skippedNL;
                   2578:           /* rule not found */
                   2579:           cssRule = SkipProperty (cssRule, FALSE);
                   2580:         }
1.281     quint    2581:       cssRule = SkipBlanksAndComments (cssRule);
                   2582:     }
1.318     vatton   2583:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid list-style value");
1.1       cvs      2584:   return (cssRule);
                   2585: }
                   2586: 
                   2587: /*----------------------------------------------------------------------
1.327     vatton   2588:   ParseCSSTextAlign: parse a CSS text-align            
                   2589:   attribute string.                                          
1.1       cvs      2590:   ----------------------------------------------------------------------*/
1.79      cvs      2591: static char *ParseCSSTextAlign (Element element, PSchema tsch,
1.327     vatton   2592:                                 PresentationContext context, char *cssRule,
                   2593:                                 CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      2594: {
1.366     vatton   2595:   char               *ptr;
1.327     vatton   2596:   PresentationValue   align;
                   2597: 
                   2598:   align.typed_data.value = 0;
                   2599:   align.typed_data.unit = UNIT_REL;
                   2600:   align.typed_data.real = FALSE;
                   2601: 
                   2602:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   2603:   ptr = cssRule;
1.327     vatton   2604:   if (!strncasecmp (cssRule, "left", 4))
                   2605:     {
                   2606:       align.typed_data.value = AdjustLeft;
                   2607:       cssRule += 4;
                   2608:     }
                   2609:   else if (!strncasecmp (cssRule, "right", 5))
                   2610:     {
                   2611:       align.typed_data.value = AdjustRight;
                   2612:       cssRule += 5;
                   2613:     }
                   2614:   else if (!strncasecmp (cssRule, "center", 6))
                   2615:     {
                   2616:       align.typed_data.value = Centered;
                   2617:       cssRule += 6;
                   2618:     }
                   2619:   else if (!strncasecmp (cssRule, "justify", 7))
                   2620:     {
                   2621:       align.typed_data.value = Justify;
                   2622:       cssRule += 7;
                   2623:     }
                   2624:   else
                   2625:     {
                   2626:       cssRule = SkipValue ("Invalid text-align value", cssRule);
                   2627:       return (cssRule);
                   2628:     }
1.1       cvs      2629: 
1.327     vatton   2630:   /*
                   2631:    * install the new presentation.
                   2632:    */
1.366     vatton   2633:   if (align.typed_data.value)
                   2634:     {
                   2635:       if (DoDialog)
                   2636:         DisplayStyleValue ("text-align", ptr, cssRule);
                   2637:       else if (DoApply)
                   2638:         TtaSetStylePresentation (PRAdjust, element, tsch, context, align);
                   2639:     }
1.327     vatton   2640:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid text-align value");
                   2641:   return (cssRule);
1.1       cvs      2642: }
                   2643: 
                   2644: /*----------------------------------------------------------------------
1.243     quint    2645:   ParseCSSTextAnchor: parse a CSS text-anchor property (SVG property)
                   2646:   We use the Thot Adjust PRule to represent the text-anchor property
                   2647:   for CSS 1.0, as Adjust is not used otherwise in this context.
                   2648:   ----------------------------------------------------------------------*/
                   2649: static char *ParseCSSTextAnchor (Element element, PSchema tsch,
1.327     vatton   2650:                                  PresentationContext context, char *cssRule,
                   2651:                                  CSSInfoPtr css, ThotBool isHTML)
1.243     quint    2652: {
1.327     vatton   2653:   PresentationValue   align;
1.366     vatton   2654:   char               *ptr;
1.327     vatton   2655: 
                   2656:   align.typed_data.value = 0;
                   2657:   align.typed_data.unit = UNIT_REL;
                   2658:   align.typed_data.real = FALSE;
1.243     quint    2659: 
1.327     vatton   2660:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   2661:   ptr = cssRule;
1.327     vatton   2662:   if (!strncasecmp (cssRule, "start", 5))
                   2663:     {
                   2664:       align.typed_data.value = AdjustLeft;
                   2665:       cssRule += 5;
                   2666:     }
                   2667:   else if (!strncasecmp (cssRule, "middle", 6))
                   2668:     {
                   2669:       align.typed_data.value = Centered;
                   2670:       cssRule += 6;
                   2671:     }
                   2672:   else if (!strncasecmp (cssRule, "end", 3))
                   2673:     {
                   2674:       align.typed_data.value = AdjustRight;
                   2675:       cssRule += 3;
                   2676:     }
                   2677:   else if (!strncasecmp (cssRule, "inherit", 7))
                   2678:     {
                   2679:       align.typed_data.unit = VALUE_INHERIT;
                   2680:       cssRule += 7;
                   2681:     }
                   2682:   else
                   2683:     {
                   2684:       cssRule = SkipValue ("Invalid text-anchor value", cssRule);
1.295     vatton   2685:       return (cssRule);
1.327     vatton   2686:     }
1.243     quint    2687: 
1.327     vatton   2688:   /*
                   2689:    * install the new presentation.
                   2690:    */
1.366     vatton   2691:   if (align.typed_data.value || align.typed_data.unit == VALUE_INHERIT)
                   2692:     {
                   2693:       if (DoDialog)
                   2694:         DisplayStyleValue ("text-anchor", ptr, cssRule);
                   2695:       else if (DoApply)
                   2696:         TtaSetStylePresentation (PRAdjust, element, tsch, context, align);
                   2697:     }
1.327     vatton   2698:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid text-anchor value");
                   2699:   return (cssRule);
1.243     quint    2700: }
                   2701: 
                   2702: /*----------------------------------------------------------------------
1.327     vatton   2703:   ParseCSSDirection: parse a CSS direction property
1.112     quint    2704:   ----------------------------------------------------------------------*/
                   2705: static char *ParseCSSDirection (Element element, PSchema tsch,
1.327     vatton   2706:                                 PresentationContext context, char *cssRule,
                   2707:                                 CSSInfoPtr css, ThotBool isHTML)
1.112     quint    2708: {
1.327     vatton   2709:   PresentationValue   direction;
1.366     vatton   2710:   char               *ptr;
1.327     vatton   2711: 
                   2712:   direction.typed_data.value = 0;
                   2713:   direction.typed_data.unit = UNIT_REL;
                   2714:   direction.typed_data.real = FALSE;
                   2715: 
                   2716:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   2717:   ptr = cssRule;
1.327     vatton   2718:   if (!strncasecmp (cssRule, "ltr", 3))
                   2719:     {
                   2720:       direction.typed_data.value = LeftToRight;
                   2721:       cssRule += 3;
                   2722:     }
                   2723:   else if (!strncasecmp (cssRule, "rtl", 3))
                   2724:     {
                   2725:       direction.typed_data.value = RightToLeft;
                   2726:       cssRule += 3;
                   2727:     }
                   2728:   else if (!strncasecmp (cssRule, "inherit", 7))
                   2729:     {
                   2730:       direction.typed_data.unit = VALUE_INHERIT;
                   2731:       cssRule += 7;
                   2732:     }
                   2733:   else
                   2734:     {
                   2735:       cssRule = SkipValue ("Invalid direction value", cssRule);
                   2736:       return (cssRule);
                   2737:     }
1.112     quint    2738: 
1.327     vatton   2739:   /*
                   2740:    * install the new presentation.
                   2741:    */
1.366     vatton   2742:   if (direction.typed_data.value || direction.typed_data.unit == VALUE_INHERIT)
                   2743:     {
                   2744:       if (DoDialog)
                   2745:         DisplayStyleValue ("direction", ptr, cssRule);
                   2746:       else if (DoApply)
                   2747:         TtaSetStylePresentation (PRDirection, element, tsch, context, direction);
                   2748:     }
1.327     vatton   2749:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid direction value");
                   2750:   return (cssRule);
1.112     quint    2751: }
                   2752: 
                   2753: /*----------------------------------------------------------------------
1.327     vatton   2754:   ParseCSSUnicodeBidi: parse a CSS unicode-bidi property
1.113     quint    2755:   ----------------------------------------------------------------------*/
                   2756: static char *ParseCSSUnicodeBidi (Element element, PSchema tsch,
1.327     vatton   2757:                                   PresentationContext context, char *cssRule,
                   2758:                                   CSSInfoPtr css, ThotBool isHTML)
1.113     quint    2759: {
1.327     vatton   2760:   PresentationValue   bidi;
1.366     vatton   2761:   char               *ptr;
1.113     quint    2762: 
1.327     vatton   2763:   bidi.typed_data.value = 0;
                   2764:   bidi.typed_data.unit = UNIT_REL;
                   2765:   bidi.typed_data.real = FALSE;
                   2766: 
                   2767:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   2768:   ptr = cssRule;
1.327     vatton   2769:   if (!strncasecmp (cssRule, "normal", 6))
                   2770:     {
                   2771:       bidi.typed_data.value = Normal;
                   2772:       cssRule += 6;
                   2773:     }
                   2774:   else if (!strncasecmp (cssRule, "embed", 5))
                   2775:     {
                   2776:       bidi.typed_data.value = Embed;
                   2777:       cssRule += 5;
                   2778:     }
                   2779:   else if (!strncasecmp (cssRule, "bidi-override", 13))
                   2780:     {
                   2781:       bidi.typed_data.value = Override;
                   2782:       cssRule += 13;
                   2783:     }
                   2784:   else if (!strncasecmp (cssRule, "inherit", 7))
                   2785:     {
                   2786:       bidi.typed_data.unit = VALUE_INHERIT;
                   2787:       cssRule += 7;
                   2788:     }
                   2789:   else
                   2790:     {
                   2791:       cssRule = SkipValue ("Invalid unicode-bidi value", cssRule);
1.295     vatton   2792:       return (cssRule);
1.327     vatton   2793:     }
1.113     quint    2794: 
1.327     vatton   2795:   /*
                   2796:    * install the new presentation.
                   2797:    */
1.366     vatton   2798:   if (bidi.typed_data.value || bidi.typed_data.unit == VALUE_INHERIT)
                   2799:     {
                   2800:       if (DoDialog)
                   2801:         DisplayStyleValue ("unicode-bidi", ptr, cssRule);
                   2802:       else if (DoApply)
                   2803:         TtaSetStylePresentation (PRUnicodeBidi, element, tsch, context, bidi);
                   2804:     }
1.327     vatton   2805:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid unicode-bidi value");
                   2806:   return (cssRule);
1.113     quint    2807: }
                   2808: 
                   2809: /*----------------------------------------------------------------------
1.327     vatton   2810:   ParseCSSTextIndent: parse a CSS text-indent
                   2811:   attribute string.                                          
1.1       cvs      2812:   ----------------------------------------------------------------------*/
1.79      cvs      2813: static char *ParseCSSTextIndent (Element element, PSchema tsch,
1.327     vatton   2814:                                  PresentationContext context, char *cssRule,
                   2815:                                  CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      2816: {
1.327     vatton   2817:   PresentationValue   pval;
                   2818:   char               *ptr;
1.1       cvs      2819: 
1.370     vatton   2820:   pval.typed_data.real = FALSE;
1.327     vatton   2821:   cssRule = SkipBlanksAndComments (cssRule);
                   2822:   ptr = cssRule;
                   2823:   cssRule = ParseCSSUnit (cssRule, &pval);
1.387     quint    2824:   if (pval.typed_data.value == 0 &&
                   2825:       pval.typed_data.unit != UNIT_INVALID)
1.327     vatton   2826:     pval.typed_data.unit = UNIT_PX;
                   2827:   else if (pval.typed_data.unit == UNIT_INVALID ||
                   2828:            pval.typed_data.unit == UNIT_BOX)
                   2829:     {
                   2830:       CSSParseError ("Invalid text-indent value", ptr, cssRule);
                   2831:       return (cssRule);
                   2832:     }
                   2833:   /* install the attribute */
1.366     vatton   2834:   if (DoDialog)
                   2835:     DisplayStyleValue ("text-indent", ptr, cssRule);
                   2836:   else if (DoApply)
1.327     vatton   2837:     TtaSetStylePresentation (PRIndent, element, tsch, context, pval);
                   2838:   return (cssRule);
1.1       cvs      2839: }
                   2840: 
                   2841: /*----------------------------------------------------------------------
1.327     vatton   2842:   ParseCSSTextTransform: parse a CSS text-transform    
                   2843:   attribute string.                                          
1.1       cvs      2844:   ----------------------------------------------------------------------*/
1.79      cvs      2845: static char *ParseCSSTextTransform (Element element, PSchema tsch,
1.327     vatton   2846:                                     PresentationContext context, char *cssRule,
                   2847:                                     CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      2848: {
1.366     vatton   2849:   char               *ptr;
                   2850: 
                   2851:   cssRule = SkipBlanksAndComments (cssRule);
                   2852:   ptr = cssRule;
1.168     vatton   2853:   cssRule = SkipValue (NULL, cssRule);
1.366     vatton   2854:   if (DoDialog)
                   2855:     DisplayStyleValue ("text-transform", ptr, cssRule);
1.1       cvs      2856:   return (cssRule);
                   2857: }
                   2858: 
                   2859: /*----------------------------------------------------------------------
1.327     vatton   2860:   ParseCSSVerticalAlign: parse a CSS vertical-align    
                   2861:   attribute string.                                          
1.1       cvs      2862:   ----------------------------------------------------------------------*/
1.79      cvs      2863: static char *ParseCSSVerticalAlign (Element element, PSchema tsch,
1.327     vatton   2864:                                     PresentationContext context, char *cssRule,
                   2865:                                     CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      2866: {
1.273     quint    2867:   char                 *ptr;
                   2868:   PresentationValue    pval;
                   2869: 
                   2870:   pval.typed_data.unit = UNIT_REL;
                   2871:   pval.typed_data.real = FALSE;
                   2872:   cssRule = SkipBlanksAndComments (cssRule);
1.288     vatton   2873:   ptr = cssRule;
1.273     quint    2874:   if (!strncasecmp (cssRule, "baseline", 8))
                   2875:     {
                   2876:       pval.typed_data.value = 0;
1.288     vatton   2877:       cssRule += 8;
1.273     quint    2878:     }
                   2879:   else if (!strncasecmp (cssRule, "sub", 3))
                   2880:     {
                   2881:       pval.typed_data.value = -3;
1.288     vatton   2882:       cssRule += 3;
1.273     quint    2883:     }
                   2884:   else if (!strncasecmp (cssRule, "super", 5))
                   2885:     {
                   2886:       pval.typed_data.value = 4;
1.288     vatton   2887:       cssRule += 5;
1.273     quint    2888:     }
                   2889:   else if (!strncasecmp (cssRule, "top", 3))
                   2890:     {
1.275     quint    2891:       pval.typed_data.unit = UNIT_INVALID;      /* Not supported yet */
1.274     vatton   2892:       pval.typed_data.value = 0;
1.288     vatton   2893:       cssRule += 3;
1.273     quint    2894:     }
                   2895:   else if (!strncasecmp (cssRule, "text-top", 8))
                   2896:     {
1.275     quint    2897:       pval.typed_data.unit = UNIT_INVALID;      /* Not supported yet */
1.274     vatton   2898:       pval.typed_data.value = 0;
1.288     vatton   2899:       cssRule += 8;
1.273     quint    2900:     }
                   2901:   else if (!strncasecmp (cssRule, "middle", 6))
                   2902:     {
1.275     quint    2903:       pval.typed_data.unit = UNIT_INVALID;      /* Not supported yet */
1.274     vatton   2904:       pval.typed_data.value = 0;
1.288     vatton   2905:       cssRule += 6;
1.273     quint    2906:     }
                   2907:   else if (!strncasecmp (cssRule, "bottom", 6))
                   2908:     {
1.275     quint    2909:       pval.typed_data.unit = UNIT_INVALID;      /* Not supported yet */
1.274     vatton   2910:       pval.typed_data.value = 0;
1.288     vatton   2911:       cssRule += 6;
1.273     quint    2912:     }
                   2913:   else if (!strncasecmp (cssRule, "text-bottom", 11))
                   2914:     {
1.275     quint    2915:       pval.typed_data.unit = UNIT_INVALID;      /* Not supported yet */
1.274     vatton   2916:       pval.typed_data.value = 0;
1.288     vatton   2917:       cssRule += 11;
1.273     quint    2918:     }
                   2919:   else if (!strncasecmp (cssRule, "inherit", 7))
                   2920:     {
1.293     quint    2921:       pval.typed_data.unit = VALUE_INHERIT;
1.274     vatton   2922:       pval.typed_data.value = 0;
1.288     vatton   2923:       cssRule +=7;
1.273     quint    2924:     }
                   2925:   else
                   2926:     {
                   2927:       /* parse <percentage> or <length> */
                   2928:       cssRule = ParseCSSUnit (cssRule, &pval);
                   2929:       if (pval.typed_data.unit == UNIT_INVALID)
1.327     vatton   2930:         {
                   2931:           pval.typed_data.value = 0;
                   2932:           CSSParseError ("Invalid vertical-align value", ptr, cssRule);
                   2933:           return (cssRule);
                   2934:         }
1.273     quint    2935:       else if (pval.typed_data.value == 0)
1.327     vatton   2936:         pval.typed_data.unit = UNIT_PX;
1.273     quint    2937:       else if (pval.typed_data.unit == UNIT_BOX)
1.327     vatton   2938:         pval.typed_data.unit = UNIT_EM;
1.273     quint    2939:       else if (pval.typed_data.unit == UNIT_PERCENT)
1.327     vatton   2940:         /* it's a percentage */
                   2941:         {
                   2942:           /* convert it into a relative size */
                   2943:           pval.typed_data.unit = UNIT_REL;
                   2944:           pval.typed_data.value /= 10;
                   2945:         }
1.273     quint    2946:     }
1.295     vatton   2947: 
1.366     vatton   2948:   if (pval.typed_data.unit != UNIT_INVALID)
                   2949:     {
                   2950:       if (DoDialog)
                   2951:         DisplayStyleValue ("vertical-align", ptr, cssRule);
                   2952:       else if (DoApply)
                   2953:         TtaSetStylePresentation (PRHorizRef, element, tsch, context, pval);
                   2954:     }
1.288     vatton   2955:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid vertical-align value");
1.1       cvs      2956:   return (cssRule);
                   2957: }
                   2958: 
                   2959: /*----------------------------------------------------------------------
1.327     vatton   2960:   ParseCSSWhiteSpace: parse a CSS white-space          
                   2961:   attribute string.                                          
1.1       cvs      2962:   ----------------------------------------------------------------------*/
1.79      cvs      2963: static char *ParseCSSWhiteSpace (Element element, PSchema tsch,
1.327     vatton   2964:                                  PresentationContext context, char *cssRule,
                   2965:                                  CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      2966: {
1.366     vatton   2967:   char *ptr;
1.288     vatton   2968: 
1.327     vatton   2969:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   2970:   ptr = cssRule;
1.327     vatton   2971:   if (!strncasecmp (cssRule, "normal", 6))
                   2972:     cssRule += 6;
1.432     vatton   2973:   else if (!strncasecmp (cssRule, "pre-wrap", 8))
                   2974:     cssRule += 8;
                   2975:   else if (!strncasecmp (cssRule, "pre-line", 8))
                   2976:     cssRule += 8;
1.327     vatton   2977:   else if (!strncasecmp (cssRule, "pre", 3))
                   2978:     cssRule += 3;
                   2979:   else if (!strncasecmp (cssRule, "nowrap", 6))
                   2980:     cssRule += 6;
                   2981:   else if (!strncasecmp (cssRule, "inherit", 7))
                   2982:     cssRule += 7;
                   2983:   else
                   2984:     cssRule = SkipValue ("Invalid white-space value", cssRule);
                   2985: 
1.387     quint    2986:   if (ptr != cssRule && DoDialog)
1.366     vatton   2987:     DisplayStyleValue ("white-space", ptr, cssRule);
1.327     vatton   2988:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid white-space value");
                   2989:   return (cssRule);
1.1       cvs      2990: }
                   2991: 
                   2992: /*----------------------------------------------------------------------
1.327     vatton   2993:   ParseCSSWordSpacing: parse a CSS word-spacing        
                   2994:   attribute string.                                          
1.1       cvs      2995:   ----------------------------------------------------------------------*/
1.79      cvs      2996: static char *ParseCSSWordSpacing (Element element, PSchema tsch,
1.327     vatton   2997:                                   PresentationContext context, char *cssRule,
                   2998:                                   CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      2999: {
1.366     vatton   3000:   char *ptr;
                   3001: 
                   3002:   cssRule = SkipBlanksAndComments (cssRule);
                   3003:   ptr = cssRule;
1.168     vatton   3004:   cssRule = SkipValue (NULL, cssRule);
1.366     vatton   3005:   if (DoDialog)
                   3006:     DisplayStyleValue ("word-spacing", ptr, cssRule);
1.1       cvs      3007:   return (cssRule);
                   3008: }
                   3009: 
                   3010: /*----------------------------------------------------------------------
1.327     vatton   3011:   ParseCSSLineHeight: parse a CSS line-height property
1.25      cvs      3012:   ----------------------------------------------------------------------*/
1.162     quint    3013: static char *ParseCSSLineHeight (Element element, PSchema tsch,
1.327     vatton   3014:                                  PresentationContext context, char *cssRule,
                   3015:                                  CSSInfoPtr css, ThotBool isHTML)
1.25      cvs      3016: {
1.162     quint    3017:   PresentationValue   pval;
1.288     vatton   3018:   char               *ptr;
1.162     quint    3019: 
1.370     vatton   3020:   pval.typed_data.real = FALSE;
1.366     vatton   3021:   cssRule = SkipBlanksAndComments (cssRule);
1.162     quint    3022:   ptr = cssRule;
                   3023:   if (!strncasecmp (cssRule, "normal", 6))
                   3024:     {
1.184     vatton   3025:       pval.typed_data.unit = UNIT_REL;
1.162     quint    3026:       pval.typed_data.real = TRUE;
                   3027:       pval.typed_data.value = 1100;
1.288     vatton   3028:       cssRule += 6;
1.162     quint    3029:     }
                   3030:   else if (!strncasecmp (cssRule, "inherit", 7))
                   3031:     {
1.293     quint    3032:       pval.typed_data.unit = VALUE_INHERIT;
1.354     quint    3033:       cssRule += 7;
1.162     quint    3034:     }
                   3035:   else
                   3036:     cssRule = ParseCSSUnit (cssRule, &pval);
1.25      cvs      3037: 
1.184     vatton   3038:   if (pval.typed_data.unit == UNIT_INVALID)
1.168     vatton   3039:     CSSParseError ("Invalid line-height value", ptr, cssRule);
1.387     quint    3040:   else if (DoDialog)
1.366     vatton   3041:     DisplayStyleValue ("line-height", ptr, cssRule);
1.162     quint    3042:   else if (DoApply)
                   3043:     {
1.166     vatton   3044:       /* install the new presentation */
1.184     vatton   3045:       if (pval.typed_data.unit == UNIT_BOX)
1.327     vatton   3046:         pval.typed_data.unit = UNIT_EM;
1.162     quint    3047:       TtaSetStylePresentation (PRLineSpacing, element, tsch, context, pval);
                   3048:     }
                   3049:   return (cssRule);
1.25      cvs      3050: }
                   3051: 
                   3052: /*----------------------------------------------------------------------
1.327     vatton   3053:   ParseCSSFontSizeAdjust: parse a CSS fontsizeAdjust attr string  
                   3054:   we expect the input string describing the attribute to be     
                   3055:   xx-small, x-small, small, medium, large, x-large, xx-large      
                   3056:   or an absolute size, or an imcrement relative to the parent     
1.1       cvs      3057:   ----------------------------------------------------------------------*/
1.219     vatton   3058: static char *ParseCSSFontSizeAdjust (Element element, PSchema tsch,
1.327     vatton   3059:                                      PresentationContext context, char *cssRule,
                   3060:                                      CSSInfoPtr css, ThotBool isHTML)
1.219     vatton   3061: {
1.366     vatton   3062: 
                   3063:   cssRule = SkipBlanksAndComments (cssRule);
1.234     vatton   3064:   cssRule = SkipProperty (cssRule, FALSE);
1.222     quint    3065:   return (cssRule);
1.219     vatton   3066: }
                   3067: 
                   3068: /*----------------------------------------------------------------------
1.327     vatton   3069:   ParseACSSFontSize: parse a CSS font size attr string  
                   3070:   we expect the input string describing the attribute to be     
                   3071:   xx-small, x-small, small, medium, large, x-large, xx-large      
                   3072:   or an absolute size, or an imcrement relative to the parent.
                   3073:   The parameter check is TRUE if the rule is just checked.
1.219     vatton   3074:   ----------------------------------------------------------------------*/
1.270     vatton   3075: static char *ParseACSSFontSize (Element element, PSchema tsch,
1.327     vatton   3076:                                 PresentationContext context, char *cssRule,
                   3077:                                 CSSInfoPtr css, ThotBool isHTML, ThotBool check)
1.1       cvs      3078: {
1.327     vatton   3079:   ElementType         elType;
                   3080:   PresentationValue   pval;
1.369     quint    3081:   char               *ptr = NULL, *ptr1 = NULL, *ptr2 = NULL;
1.366     vatton   3082:   char               *start_value;
1.369     quint    3083:   ThotBool               real, error, linespace = FALSE;
1.327     vatton   3084: 
1.369     quint    3085:   error = FALSE;
1.327     vatton   3086:   pval.typed_data.real = FALSE;
                   3087:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   3088:   start_value = cssRule;
1.327     vatton   3089:   /* look for a '/' within the current cssRule */
                   3090:   ptr1 = strchr (cssRule, ';');
                   3091:   ptr = strchr (cssRule, '/');
                   3092:   if (ptr && (ptr1 == NULL || ptr < ptr1))
                   3093:     {
                   3094:       /* keep the line spacing rule */
                   3095:       linespace = TRUE;
                   3096:       ptr[0] = EOS;
                   3097:     }
                   3098:   else
                   3099:     ptr = NULL;
                   3100:   ptr1 = cssRule;
1.289     vatton   3101:   /* relative size */
1.327     vatton   3102:   if (!strncasecmp (cssRule, "larger", 6))
                   3103:     {
                   3104:       pval.typed_data.unit = UNIT_PERCENT;
                   3105:       pval.typed_data.value = 130;
                   3106:       cssRule += 6;
                   3107:     }
                   3108:   else if (!strncasecmp (cssRule, "smaller", 7))
                   3109:     {
                   3110:       pval.typed_data.unit = UNIT_PERCENT;
                   3111:       pval.typed_data.value = 80;
                   3112:       cssRule += 7;
                   3113:     }
                   3114:   /* absolute size */
                   3115:   else if (!strncasecmp (cssRule, "xx-small", 8))
                   3116:     {
                   3117:       pval.typed_data.unit = UNIT_PT;
1.336     vatton   3118:       pval.typed_data.value = 6;
1.327     vatton   3119:       cssRule += 8;
                   3120:     }
                   3121:   else if (!strncasecmp (cssRule, "x-small", 7))
                   3122:     {
                   3123:       pval.typed_data.unit = UNIT_PT;
1.336     vatton   3124:       pval.typed_data.value = 8;
1.327     vatton   3125:       cssRule += 7;
                   3126:     }
                   3127:   else if (!strncasecmp (cssRule, "small", 5))
                   3128:     {
                   3129:       pval.typed_data.unit = UNIT_PT;
1.336     vatton   3130:       pval.typed_data.value = 10;
1.327     vatton   3131:       cssRule += 5;
                   3132:     }
                   3133:   else if (!strncasecmp (cssRule, "medium", 6))
                   3134:     {
                   3135:       pval.typed_data.unit = UNIT_PT;
                   3136:       pval.typed_data.value = 12;
                   3137:       cssRule += 6;
                   3138:     }
                   3139:   else if (!strncasecmp (cssRule, "large", 5))
                   3140:     {
                   3141:       pval.typed_data.unit = UNIT_PT;
                   3142:       pval.typed_data.value = 13;
                   3143:       cssRule += 5;
                   3144:     }
                   3145:   else if (!strncasecmp (cssRule, "x-large", 7))
                   3146:     {
                   3147:       pval.typed_data.unit = UNIT_PT;
                   3148:       pval.typed_data.value = 14;
                   3149:       cssRule += 7;
                   3150:     }
                   3151:   else if (!strncasecmp (cssRule, "xx-large", 8))
                   3152:     {
                   3153:       pval.typed_data.unit = UNIT_PT;
                   3154:       pval.typed_data.value = 16;
                   3155:       cssRule += 8;
                   3156:     }
                   3157:   else if (!strncasecmp (cssRule, "inherit", 7))
                   3158:     {
                   3159:       pval.typed_data.unit = VALUE_INHERIT;
                   3160:       pval.typed_data.value = 0;
                   3161:       cssRule += 7;
                   3162:     }
                   3163:   /* length or percentage */
                   3164:   else if (!isdigit (*cssRule) && *cssRule != '.')
                   3165:     {
                   3166:       if (!check)
1.360     vatton   3167:         cssRule = SkipValue ("Invalid font-size value", cssRule);
1.369     quint    3168:       error = TRUE;
1.327     vatton   3169:     }
                   3170:   else
                   3171:     {       
                   3172:       cssRule = ParseCSSUnit (cssRule, &pval);
                   3173:       if (pval.typed_data.unit == UNIT_BOX)
                   3174:         /* no unit specified */
                   3175:         {
                   3176:           elType = TtaGetElementType(element);
                   3177:           if (!strcmp(TtaGetSSchemaName (elType.ElSSchema), "SVG"))
                   3178:             /* we are working for an SVG element. No unit means pixels */
                   3179:             pval.typed_data.unit = UNIT_PX;
                   3180:         }
1.387     quint    3181:       if (pval.typed_data.unit == UNIT_INVALID ||
                   3182:           (pval.typed_data.value != 0 && pval.typed_data.unit == UNIT_BOX) ||
                   3183:           pval.typed_data.value < 0)
1.327     vatton   3184:         /* not a valid value */
1.369     quint    3185:         {
                   3186:           if (!check)
                   3187:             {
                   3188:               ptr2 = SkipWord (cssRule);
                   3189:               CSSParseError ("Invalid font-size value", ptr1, ptr2);
                   3190:             }
                   3191:           error = TRUE;
                   3192:         }
1.327     vatton   3193:       else if (pval.typed_data.unit == UNIT_REL && pval.typed_data.value > 0)
                   3194:         /* CSS relative sizes have to be higher than Thot ones */
                   3195:         pval.typed_data.value += 1;
                   3196:       else 
                   3197:         {
                   3198:           real = pval.typed_data.real;
                   3199:           if (pval.typed_data.unit == UNIT_EM)
                   3200:             {
                   3201:               if (real)
                   3202:                 {
                   3203:                   pval.typed_data.value /= 10;
                   3204:                   pval.typed_data.real = FALSE;
                   3205:                   real = FALSE;
                   3206:                 }
                   3207:               else
                   3208:                 pval.typed_data.value *= 100;
                   3209:               pval.typed_data.unit = UNIT_PERCENT;
                   3210:             }
                   3211:           else if (pval.typed_data.unit == UNIT_XHEIGHT)
                   3212:             {
                   3213:               /* a font size expressed in ex is converted into a percentage.
                   3214:                  For example, "3ex" is converted into "180%", supposing
                   3215:                  that 1ex is approximately 0.6 times the height of the
                   3216:                  current font */
                   3217:               if (real)
                   3218:                 {
                   3219:                   pval.typed_data.value *= 6;
                   3220:                   pval.typed_data.value /= 100;
                   3221:                   pval.typed_data.real = FALSE;
                   3222:                   real = FALSE;
                   3223:                 }
                   3224:               else
                   3225:                 pval.typed_data.value *= 60;
                   3226:               pval.typed_data.unit = UNIT_PERCENT;
                   3227:             }
                   3228:         }
                   3229:     }
                   3230: 
                   3231:   /* install the presentation style */
1.369     quint    3232:   if (!check && !error)
1.366     vatton   3233:     {
                   3234:       if (DoDialog)
                   3235:         DisplayStyleValue ("font-size", start_value, cssRule);
                   3236:       else if (DoApply)
                   3237:         TtaSetStylePresentation (PRSize, element, tsch, context, pval);
                   3238:     }
1.327     vatton   3239:   if (!check && ptr)
                   3240:     cssRule = ParseCSSLineHeight (element, tsch, context, &ptr[1], css, isHTML);
                   3241:   if (linespace)
                   3242:     *ptr = '/';
                   3243: 
                   3244:   return (cssRule);
                   3245: }
                   3246: 
                   3247: /*----------------------------------------------------------------------
                   3248:   ParseCSSFontSize: parse a CSS font size attr string  
                   3249:   we expect the input string describing the attribute to be     
                   3250:   xx-small, x-small, small, medium, large, x-large, xx-large      
                   3251:   or an absolute size, or an imcrement relative to the parent     
1.270     vatton   3252:   ----------------------------------------------------------------------*/
                   3253: static char *ParseCSSFontSize (Element element, PSchema tsch,
1.327     vatton   3254:                                PresentationContext context, char *cssRule,
                   3255:                                CSSInfoPtr css, ThotBool isHTML)
1.270     vatton   3256: {
1.299     vatton   3257:   char               *ptr = cssRule;
1.295     vatton   3258:   cssRule = ParseACSSFontSize (element, tsch, context, cssRule, css, isHTML, FALSE);
1.299     vatton   3259:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid font-size value");
1.295     vatton   3260:   return cssRule;
1.270     vatton   3261: }
                   3262: 
                   3263: /*----------------------------------------------------------------------
1.327     vatton   3264:   ParseACSSFontFamily: parse a CSS font family string   
                   3265:   we expect the input string describing the attribute to be     
                   3266:   a common generic font style name                                
1.1       cvs      3267:   ----------------------------------------------------------------------*/
1.268     vatton   3268: static char *ParseACSSFontFamily (Element element, PSchema tsch,
1.327     vatton   3269:                                   PresentationContext context, char *cssRule,
                   3270:                                   CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      3271: {
                   3272:   PresentationValue   font;
1.252     vatton   3273:   char                quoteChar, *p;
1.1       cvs      3274: 
                   3275:   font.typed_data.value = 0;
1.184     vatton   3276:   font.typed_data.unit = UNIT_REL;
1.1       cvs      3277:   font.typed_data.real = FALSE;
1.82      cvs      3278:   cssRule = SkipBlanksAndComments (cssRule);
                   3279:   if (*cssRule == '"' || *cssRule == '\'')
1.327     vatton   3280:     {
                   3281:       quoteChar = *cssRule;
                   3282:       cssRule++;
                   3283:     }
1.1       cvs      3284:   else
1.327     vatton   3285:     quoteChar = EOS;
1.1       cvs      3286: 
1.293     quint    3287:   if (!strncasecmp (cssRule, "inherit", 7) && quoteChar == EOS)
                   3288:     {
                   3289:       font.typed_data.unit = VALUE_INHERIT;
                   3290:       cssRule += 7;
                   3291:     }
                   3292:   else if (!strncasecmp (cssRule, "times", 5) &&
1.327     vatton   3293:            (quoteChar == EOS || quoteChar == cssRule[5]))
1.86      cvs      3294:     {
1.184     vatton   3295:       font.typed_data.value = FontTimes;
1.86      cvs      3296:       cssRule += 5;
                   3297:     }
1.92      cvs      3298:   else if (!strncasecmp (cssRule, "serif", 5) &&
1.327     vatton   3299:            (quoteChar == EOS || quoteChar == cssRule[5]))
1.86      cvs      3300:     {
1.184     vatton   3301:       font.typed_data.value = FontTimes;
1.86      cvs      3302:       cssRule += 5;
1.92      cvs      3303:       if (quoteChar != EOS)
1.327     vatton   3304:         cssRule++;
1.86      cvs      3305:     }
1.92      cvs      3306:   else if (!strncasecmp (cssRule, "helvetica", 9) &&
1.327     vatton   3307:            (quoteChar == EOS || quoteChar == cssRule[9]))
1.86      cvs      3308:     {
1.327     vatton   3309:       font.typed_data.value = FontHelvetica;
1.86      cvs      3310:       cssRule += 9;
1.92      cvs      3311:       if (quoteChar != EOS)
1.327     vatton   3312:         cssRule++;
1.86      cvs      3313:     }
1.92      cvs      3314:   else if (!strncasecmp (cssRule, "verdana", 7) &&
1.327     vatton   3315:            (quoteChar == EOS || quoteChar == cssRule[7]))
1.86      cvs      3316:     {
1.184     vatton   3317:       font.typed_data.value = FontHelvetica;
1.86      cvs      3318:       cssRule += 7;
1.92      cvs      3319:       if (quoteChar != EOS)
1.327     vatton   3320:         cssRule++;
1.86      cvs      3321:     }
1.92      cvs      3322:   else if (!strncasecmp (cssRule, "sans-serif", 10) &&
1.327     vatton   3323:            (quoteChar == EOS || quoteChar == cssRule[10]))
1.86      cvs      3324:     {
1.184     vatton   3325:       font.typed_data.value = FontHelvetica;
1.86      cvs      3326:       cssRule += 10;
1.92      cvs      3327:       if (quoteChar != EOS)
1.327     vatton   3328:         cssRule++;
1.86      cvs      3329:     }
1.268     vatton   3330:   else if (!strncasecmp (cssRule, "courier new", 11) &&
1.327     vatton   3331:            (quoteChar == EOS || quoteChar == cssRule[11]))
1.268     vatton   3332:     {
                   3333:       font.typed_data.value = FontCourier;
                   3334:       cssRule += 11;
                   3335:       if (quoteChar != EOS)
1.327     vatton   3336:         cssRule++;
1.268     vatton   3337:     }
1.92      cvs      3338:   else if (!strncasecmp (cssRule, "courier", 7) &&
1.327     vatton   3339:            (quoteChar == EOS || quoteChar == cssRule[7]))
1.86      cvs      3340:     {
1.184     vatton   3341:       font.typed_data.value = FontCourier;
1.86      cvs      3342:       cssRule += 7;
1.92      cvs      3343:       if (quoteChar != EOS)
1.327     vatton   3344:         cssRule++;
1.86      cvs      3345:     }
1.92      cvs      3346:   else if (!strncasecmp (cssRule, "monospace", 9) &&
1.327     vatton   3347:            (quoteChar == EOS || quoteChar == cssRule[9]))
1.86      cvs      3348:     {
1.184     vatton   3349:       font.typed_data.value = FontCourier;
1.86      cvs      3350:       cssRule += 9;
1.92      cvs      3351:       if (quoteChar != EOS)
1.327     vatton   3352:         cssRule++;
1.86      cvs      3353:     }
1.1       cvs      3354:   else
                   3355:     /* unknown font name.  Skip it */
                   3356:     {
1.252     vatton   3357:       p = cssRule;
1.92      cvs      3358:       if (quoteChar != EOS)
1.327     vatton   3359:         cssRule = SkipQuotedString (cssRule, quoteChar);
1.86      cvs      3360:       else
1.383     quint    3361:         /* unquoted font name. The name may contain spaces */
                   3362:         {
                   3363:           cssRule = SkipWord (cssRule);
                   3364:           while (*cssRule == SPACE || *cssRule == BSPACE || *cssRule == EOL ||
                   3365:               *cssRule == TAB || *cssRule == __CR__)
                   3366:             {
                   3367:               cssRule = SkipBlanksAndComments (cssRule);
                   3368:               if (*cssRule != ','  && *cssRule != ';'  && *cssRule != '}' &&
                   3369:                   *cssRule != EOS)
                   3370:                 cssRule = SkipWord (cssRule);
                   3371:             }
                   3372:         }
1.252     vatton   3373:       while (p == cssRule &&
1.327     vatton   3374:              *cssRule != ','  && *cssRule != ';'  && *cssRule != '}' && *cssRule != EOS)
                   3375:         {
                   3376:           cssRule++;
                   3377:           p = cssRule;
                   3378:           cssRule = SkipWord (cssRule);
                   3379:         }
1.82      cvs      3380:       cssRule = SkipBlanksAndComments (cssRule);
                   3381:       if (*cssRule == ',')
1.327     vatton   3382:         {
                   3383:           /* recursive call to ParseCSSFontFamily */
                   3384:           cssRule++;
                   3385:           cssRule = ParseACSSFontFamily (element, tsch, context, cssRule, css, isHTML);
                   3386:           return (cssRule);
                   3387:         }
1.1       cvs      3388:     }
                   3389: 
1.239     vatton   3390:   /* skip other values */
                   3391:   cssRule = SkipBlanksAndComments (cssRule);
                   3392:   while (*cssRule == ',')
                   3393:     {
                   3394:       cssRule++;
                   3395:       cssRule = SkipValue (NULL, cssRule);
                   3396:       cssRule = SkipBlanksAndComments (cssRule);
                   3397:     }
                   3398: 
1.366     vatton   3399:   if (font.typed_data.value != 0 || font.typed_data.unit == VALUE_INHERIT)
                   3400:     {
                   3401:       if (!DoDialog && DoApply)
                   3402:         /* install the new presentation */
                   3403:         TtaSetStylePresentation (PRFont, element, tsch, context, font);
                   3404:     }
1.1       cvs      3405:   return (cssRule);
                   3406: }
                   3407: 
                   3408: /*----------------------------------------------------------------------
1.327     vatton   3409:   ParseCSSFontFamily: parse a CSS font family string   
                   3410:   we expect the input string describing the attribute to be     
                   3411:   a common generic font style name                                
1.268     vatton   3412:   ----------------------------------------------------------------------*/
                   3413: static char *ParseCSSFontFamily (Element element, PSchema tsch,
1.327     vatton   3414:                                  PresentationContext context, char *cssRule,
                   3415:                                  CSSInfoPtr css, ThotBool isHTML)
1.268     vatton   3416: {
1.366     vatton   3417:   char               *start_value;
                   3418: 
                   3419:   cssRule = SkipBlanksAndComments (cssRule);
                   3420:   start_value = cssRule;
1.268     vatton   3421:   cssRule = ParseACSSFontFamily (element, tsch, context, cssRule, css, isHTML);
                   3422:   /* skip extra values */
1.301     vatton   3423:   while (cssRule && *cssRule != ';' && *cssRule != '}' && *cssRule != EOS)
1.268     vatton   3424:     cssRule++;
1.366     vatton   3425:   if (DoDialog)
                   3426:     DisplayStyleValue ("font-family", start_value, cssRule);
1.268     vatton   3427:   return (cssRule);
                   3428: }
                   3429: 
                   3430: /*----------------------------------------------------------------------
1.327     vatton   3431:   ParseACSSFontWeight: parse a CSS font weight string   
                   3432:   we expect the input string describing the attribute to be     
                   3433:   normal, bold, bolder, lighter, 100, 200, 300, ... 900, inherit.
1.1       cvs      3434:   ----------------------------------------------------------------------*/
1.263     vatton   3435: static char *ParseACSSFontWeight (Element element, PSchema tsch,
1.327     vatton   3436:                                   PresentationContext context, char *cssRule,
                   3437:                                   CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      3438: {
1.327     vatton   3439:   PresentationValue   weight;
1.366     vatton   3440:   char               *ptr;
1.1       cvs      3441: 
1.327     vatton   3442:   weight.typed_data.value = 0;
                   3443:   weight.typed_data.unit = UNIT_REL;
                   3444:   weight.typed_data.real = FALSE;
                   3445:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   3446:   ptr = cssRule;
1.351     quint    3447:   if (isdigit (*cssRule) && *cssRule != '0' &&
                   3448:       cssRule[1] == '0' && cssRule[2] == '0' &&
                   3449:       (cssRule[3] == EOS || cssRule[3] == SPACE || cssRule[3] == '/' ||
                   3450:        cssRule[3] == ';' || cssRule[3] == '}' || cssRule[3] == EOL || 
                   3451:        cssRule[3] == TAB || cssRule[3] ==  __CR__))
1.327     vatton   3452:     {
1.351     quint    3453:       if (!strncasecmp (cssRule, "100", 3))
                   3454:         {
1.379     quint    3455:           weight.typed_data.value = -4;
1.351     quint    3456:           cssRule = SkipWord (cssRule);
                   3457:         }
                   3458:       else if (!strncasecmp (cssRule, "200", 3))
                   3459:         {
1.379     quint    3460:           weight.typed_data.value = -3;
1.351     quint    3461:           cssRule = SkipWord (cssRule);
                   3462:         }
                   3463:       else if (!strncasecmp (cssRule, "300", 3))
                   3464:         {
1.379     quint    3465:           weight.typed_data.value = -2;
1.351     quint    3466:           cssRule = SkipWord (cssRule);
                   3467:         }
                   3468:       else if (!strncasecmp (cssRule, "400", 3))
                   3469:         {
1.379     quint    3470:           weight.typed_data.value = -1;
1.351     quint    3471:           cssRule = SkipWord (cssRule);
                   3472:         }
                   3473:       else if (!strncasecmp (cssRule, "500", 3))
                   3474:         {
1.379     quint    3475:           weight.typed_data.value = 0;
1.351     quint    3476:           cssRule = SkipWord (cssRule);
                   3477:         }
                   3478:       else if (!strncasecmp (cssRule, "600", 3))
                   3479:         {
1.379     quint    3480:           weight.typed_data.value = +1;
1.351     quint    3481:           cssRule = SkipWord (cssRule);
                   3482:         }
                   3483:       else if (!strncasecmp (cssRule, "700", 3))
                   3484:         {
1.379     quint    3485:           weight.typed_data.value = +2;
1.351     quint    3486:           cssRule = SkipWord (cssRule);
                   3487:         }
                   3488:       else if (!strncasecmp (cssRule, "800", 3))
                   3489:         {
1.379     quint    3490:           weight.typed_data.value = +3;
1.351     quint    3491:           cssRule = SkipWord (cssRule);
                   3492:         }
                   3493:       else if (!strncasecmp (cssRule, "900", 3))
                   3494:         {
1.379     quint    3495:           weight.typed_data.value = +4;
1.351     quint    3496:           cssRule = SkipWord (cssRule);
                   3497:         }
1.327     vatton   3498:     }
1.351     quint    3499:   else if (!strncasecmp (cssRule, "normal", 6))
1.327     vatton   3500:     {
                   3501:       weight.typed_data.value = 0;
                   3502:       cssRule = SkipWord (cssRule);
                   3503:     }
1.351     quint    3504:   else if (!strncasecmp (cssRule, "bold", 4))
1.327     vatton   3505:     {
                   3506:       weight.typed_data.value = +3;
                   3507:       cssRule = SkipWord (cssRule);
                   3508:     }
                   3509:   else if (!strncasecmp (cssRule, "inherit", 7))
                   3510:     {
                   3511:       weight.typed_data.unit = VALUE_INHERIT;
                   3512:       cssRule += 7;
                   3513:     }
1.379     quint    3514:   else if (!strncasecmp (cssRule, "bolder", 6))
1.327     vatton   3515:     {
1.379     quint    3516:       weight.typed_data.value = +2;
                   3517:       cssRule = SkipWord (cssRule);
                   3518:     }
                   3519: 
                   3520:   else if (!strncasecmp (cssRule, "lighter", 7))
                   3521:     {
                   3522:       weight.typed_data.value = -1;
1.327     vatton   3523:       cssRule = SkipWord (cssRule);
                   3524:     }
                   3525:   else
                   3526:     return (cssRule);
                   3527: 
                   3528:   /*
                   3529:    * Here we have to reduce since only two font weight values are supported
                   3530:    * by the Thot presentation API.
                   3531:    */
                   3532:   if (weight.typed_data.unit != VALUE_INHERIT)
                   3533:     {
                   3534:       if (weight.typed_data.value > 0)
                   3535:         weight.typed_data.value = WeightBold;
                   3536:       else
                   3537:         weight.typed_data.value = WeightNormal;
                   3538:     }
                   3539: 
                   3540:   /* install the new presentation */
1.366     vatton   3541:   if (cssRule != ptr && DoDialog)
                   3542:     DisplayStyleValue ("font-weight", ptr, cssRule);
                   3543:   else if (DoApply)
1.327     vatton   3544:     TtaSetStylePresentation (PRWeight, element, tsch, context, weight);
                   3545:   return (cssRule);
                   3546: }
                   3547: 
                   3548: /*----------------------------------------------------------------------
                   3549:   ParseCSSFontWeight: parse a CSS font weight string   
                   3550:   we expect the input string describing the attribute to be     
                   3551:   normal, bold, bolder, lighter, 100, 200, 300, ... 900, inherit.
1.263     vatton   3552:   ----------------------------------------------------------------------*/
                   3553: static char *ParseCSSFontWeight (Element element, PSchema tsch,
1.327     vatton   3554:                                  PresentationContext context, char *cssRule,
                   3555:                                  CSSInfoPtr css, ThotBool isHTML)
1.263     vatton   3556: {
                   3557:   char           *ptr;
                   3558:   
1.366     vatton   3559:   cssRule = SkipBlanksAndComments (cssRule);
1.263     vatton   3560:   ptr = cssRule;
                   3561:   cssRule = ParseACSSFontWeight (element, tsch, context, cssRule, css, isHTML);
                   3562:   if (ptr == cssRule)
                   3563:     cssRule = SkipValue ("Invalid font-weight value", cssRule);
                   3564:   return (cssRule);
                   3565: }
                   3566: 
                   3567: /*----------------------------------------------------------------------
1.327     vatton   3568:   ParseACSSFontVariant: parse a CSS font variant string     
                   3569:   we expect the input string describing the attribute to be     
                   3570:   normal or small-caps
1.1       cvs      3571:   ----------------------------------------------------------------------*/
1.263     vatton   3572: static char *ParseACSSFontVariant (Element element, PSchema tsch,
1.327     vatton   3573:                                    PresentationContext context, char *cssRule,
                   3574:                                    CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      3575: {
1.327     vatton   3576:   PresentationValue   style;
1.366     vatton   3577:   char               *ptr;
1.1       cvs      3578: 
1.327     vatton   3579:   style.typed_data.value = 0;
                   3580:   style.typed_data.unit = UNIT_REL;
                   3581:   style.typed_data.real = FALSE;
                   3582:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   3583:   ptr = cssRule;
1.327     vatton   3584:   if (!strncasecmp (cssRule, "small-caps", 10))
                   3585:     {
1.381     quint    3586:       style.typed_data.value = VariantSmallCaps;
1.327     vatton   3587:       cssRule = SkipWord (cssRule);
                   3588:     }
                   3589:   else if (!strncasecmp (cssRule, "normal", 6))
                   3590:     {
1.381     quint    3591:       style.typed_data.value = VariantNormal;
1.327     vatton   3592:       cssRule = SkipWord (cssRule);
                   3593:     }
                   3594:   else if (!strncasecmp (cssRule, "inherit", 7))
                   3595:     {
1.381     quint    3596:       style.typed_data.unit = VALUE_INHERIT;
1.327     vatton   3597:       cssRule = SkipWord (cssRule);
                   3598:     }
1.381     quint    3599:   else
                   3600:     /* invalid font-variant */
                   3601:     return (cssRule);
                   3602: 
                   3603:   if (style.typed_data.value != 0 || style.typed_data.unit == VALUE_INHERIT)
                   3604:     {
                   3605:       if (DoDialog)
                   3606:         DisplayStyleValue ("font-variant", ptr, cssRule);
                   3607:       else if (DoApply)
                   3608:         TtaSetStylePresentation (PRVariant, element, tsch, context, style);
                   3609:     }
1.295     vatton   3610:   return (cssRule);
1.263     vatton   3611: }
1.1       cvs      3612: 
1.263     vatton   3613: /*----------------------------------------------------------------------
1.327     vatton   3614:   ParseCSSFontVariant: parse a CSS font variant string     
                   3615:   we expect the input string describing the attribute to be     
                   3616:   normal or small-caps
1.263     vatton   3617:   ----------------------------------------------------------------------*/
                   3618: static char *ParseCSSFontVariant (Element element, PSchema tsch,
1.327     vatton   3619:                                   PresentationContext context, char *cssRule,
                   3620:                                   CSSInfoPtr css, ThotBool isHTML)
1.263     vatton   3621: {
                   3622:   char           *ptr;
                   3623:   
                   3624:   ptr = cssRule;
                   3625:   cssRule = ParseACSSFontVariant (element, tsch, context, cssRule, css, isHTML);
                   3626:   if (ptr == cssRule)
                   3627:     cssRule = SkipValue ("Invalid font-variant value", cssRule);
                   3628:   return (cssRule);
1.1       cvs      3629: }
                   3630: 
                   3631: 
                   3632: /*----------------------------------------------------------------------
1.327     vatton   3633:   ParseACSSFontStyle: parse a CSS font style string     
                   3634:   we expect the input string describing the attribute to be     
                   3635:   normal, italic, oblique or inherit                         
1.1       cvs      3636:   ----------------------------------------------------------------------*/
1.263     vatton   3637: static char *ParseACSSFontStyle (Element element, PSchema tsch,
1.327     vatton   3638:                                  PresentationContext context, char *cssRule,
                   3639:                                  CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      3640: {
1.327     vatton   3641:   PresentationValue   style;
                   3642:   PresentationValue   size;
1.366     vatton   3643:   PresentationValue   previous_size;
                   3644:   char               *ptr;
1.1       cvs      3645: 
1.327     vatton   3646:   style.typed_data.value = 0;
                   3647:   style.typed_data.unit = UNIT_REL;
                   3648:   style.typed_data.real = FALSE;
                   3649:   size.typed_data.value = 0;
                   3650:   size.typed_data.unit = UNIT_REL;
                   3651:   size.typed_data.real = FALSE;
                   3652:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   3653:   ptr = cssRule;
1.327     vatton   3654:   if (!strncasecmp (cssRule, "italic", 6))
                   3655:     {
                   3656:       style.typed_data.value = StyleItalics;
                   3657:       cssRule = SkipWord (cssRule);
                   3658:     }
                   3659:   else if (!strncasecmp (cssRule, "oblique", 7))
                   3660:     {
                   3661:       style.typed_data.value = StyleOblique;
                   3662:       cssRule = SkipWord (cssRule);
                   3663:     }
                   3664:   else if (!strncasecmp (cssRule, "normal", 6))
                   3665:     {
                   3666:       style.typed_data.value = StyleRoman;
                   3667:       cssRule = SkipWord (cssRule);
                   3668:     }
                   3669:   else if (!strncasecmp (cssRule, "inherit", 7))
                   3670:     {
                   3671:       style.typed_data.unit = VALUE_INHERIT;
                   3672:       cssRule = SkipWord (cssRule);
                   3673:     }
                   3674:   else
                   3675:     /* invalid font style */
                   3676:     return (cssRule);
                   3677: 
                   3678:   /*
                   3679:    * install the new presentation.
                   3680:    */
1.366     vatton   3681:   if (style.typed_data.value != 0 || style.typed_data.unit == VALUE_INHERIT)
1.327     vatton   3682:     {
1.366     vatton   3683:       if (DoDialog)
                   3684:         DisplayStyleValue ("font-style", ptr, cssRule);
                   3685:       else if (DoApply)
                   3686:         TtaSetStylePresentation (PRStyle, element, tsch, context, style);
1.327     vatton   3687:     }
1.366     vatton   3688:   if (size.typed_data.value != 0)
1.327     vatton   3689:     {
1.366     vatton   3690:       if (DoDialog)
                   3691:         DisplayStyleValue ("font-style", ptr, cssRule);
                   3692:       else if (DoApply)
1.327     vatton   3693:         {
1.366     vatton   3694:           if (!TtaGetStylePresentation (PRSize, element, tsch, context, &previous_size))
                   3695:             {
                   3696:               /* !!!!!!!!!!!!!!!!!!!!!!!! Unit + relative !!!!!!!!!!!!!!!! */
                   3697:               size.typed_data.value += previous_size.typed_data.value;
                   3698:               TtaSetStylePresentation (PRSize, element, tsch, context, size);
                   3699:             }
                   3700:           else
                   3701:             {
                   3702:               size.typed_data.value = 10;
                   3703:               TtaSetStylePresentation (PRSize, element, tsch, context, size);
                   3704:             }
1.327     vatton   3705:         }
                   3706:     }
                   3707:   return (cssRule);
                   3708: }
                   3709: 
                   3710: /*----------------------------------------------------------------------
                   3711:   ParseCSSFontStyle: parse a CSS font style string     
                   3712:   we expect the input string describing the attribute to be     
                   3713:   italic, oblique or normal                         
1.263     vatton   3714:   ----------------------------------------------------------------------*/
                   3715: static char *ParseCSSFontStyle (Element element, PSchema tsch,
1.327     vatton   3716:                                 PresentationContext context, char *cssRule,
                   3717:                                 CSSInfoPtr css, ThotBool isHTML)
1.263     vatton   3718: {
                   3719:   char           *ptr;
                   3720:   
                   3721:   ptr = cssRule;
                   3722:   cssRule = ParseACSSFontStyle (element, tsch, context, cssRule, css, isHTML);
                   3723:   if (ptr == cssRule)
                   3724:     cssRule = SkipValue ("Invalid font-style value", cssRule);
                   3725:   return (cssRule);
                   3726: }
                   3727: 
                   3728: /*----------------------------------------------------------------------
1.59      cvs      3729:   ParseCSSFont: parse a CSS font attribute string
                   3730:   we expect the input string describing the attribute to be
                   3731:   !!!!!!                                  
1.1       cvs      3732:   ----------------------------------------------------------------------*/
1.79      cvs      3733: static char *ParseCSSFont (Element element, PSchema tsch,
1.327     vatton   3734:                            PresentationContext context, char *cssRule,
                   3735:                            CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      3736: {
1.270     vatton   3737:   char           *ptr, *p;
1.366     vatton   3738:   char           *start_value;
1.93      vatton   3739:   int             skippedNL;
1.272     vatton   3740:   ThotBool        variant = FALSE, style = FALSE, weight = FALSE, found; 
1.1       cvs      3741: 
1.82      cvs      3742:   cssRule = SkipBlanksAndComments (cssRule);
                   3743:   if (!strncasecmp (cssRule, "caption", 7))
1.263     vatton   3744:     cssRule += 7;
1.82      cvs      3745:   else if (!strncasecmp (cssRule, "icon", 4))
1.263     vatton   3746:     cssRule += 4;
1.82      cvs      3747:   else if (!strncasecmp (cssRule, "menu", 4))
1.263     vatton   3748:     cssRule += 4;
1.82      cvs      3749:   else if (!strncasecmp (cssRule, "message-box", 11))
1.263     vatton   3750:     cssRule += 11;
1.82      cvs      3751:   else if (!strncasecmp (cssRule, "small-caption", 13))
1.263     vatton   3752:     cssRule += 13;
1.82      cvs      3753:   else if (!strncasecmp (cssRule, "status-bar", 10))
1.263     vatton   3754:     cssRule += 10;
                   3755:   else if (!strncasecmp (cssRule, "inherit", 7))
1.293     quint    3756:     {
                   3757:       ParseACSSFontStyle (element, tsch, context, cssRule, css, isHTML);
                   3758:       ParseACSSFontVariant (element, tsch, context, cssRule, css, isHTML);
                   3759:       ParseACSSFontWeight (element, tsch, context, cssRule, css, isHTML);
                   3760:       ParseACSSFontSize (element, tsch, context, cssRule, css, isHTML, FALSE);
1.366     vatton   3761:       cssRule = SkipBlanksAndComments (cssRule);
                   3762:       start_value = cssRule;
1.293     quint    3763:       ParseACSSFontFamily (element, tsch, context, cssRule, css, isHTML);
                   3764:       cssRule += 7;
1.366     vatton   3765:       if (DoDialog)
                   3766:         DisplayStyleValue ("font-family", start_value, cssRule);
1.293     quint    3767:     }
1.1       cvs      3768:   else
1.43      cvs      3769:     {
1.270     vatton   3770:       ptr = NULL;
                   3771:       p = cssRule;
1.301     vatton   3772:       while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && p == cssRule)
1.327     vatton   3773:         {
                   3774:           found = FALSE;
                   3775:           /* style, variant, weight can appear in any order */
                   3776:           ptr = cssRule;
                   3777:           skippedNL = NewLineSkipped;
                   3778:           cssRule = ParseACSSFontStyle (element, tsch, context, cssRule, css, isHTML);
                   3779:           if (ptr != cssRule)
                   3780:             {
                   3781:               skippedNL = NewLineSkipped;
                   3782:               found = TRUE;
                   3783:               style = TRUE;
                   3784:             }
                   3785:           else
                   3786:             NewLineSkipped = skippedNL;
                   3787:           ptr = cssRule;
                   3788:           cssRule = ParseACSSFontVariant (element, tsch, context, cssRule, css, isHTML);
                   3789:           if (ptr != cssRule)
                   3790:             {
                   3791:               skippedNL = NewLineSkipped;
                   3792:               found = TRUE;
                   3793:               variant = TRUE;
                   3794:             }
                   3795:           else
                   3796:             NewLineSkipped = skippedNL;
                   3797:           ptr = cssRule;
                   3798:           cssRule = ParseACSSFontWeight (element, tsch, context, cssRule, css, isHTML);
                   3799:           if (ptr != cssRule)
                   3800:             {
                   3801:               skippedNL = NewLineSkipped;
                   3802:               found = TRUE;
                   3803:               weight = TRUE;
                   3804:             }
                   3805:           else
                   3806:             NewLineSkipped = skippedNL;
                   3807:           cssRule = SkipBlanksAndComments (cssRule);
                   3808:           p = ParseACSSFontSize (element, tsch, context, cssRule, css, isHTML, TRUE);
                   3809:           NewLineSkipped = skippedNL;
                   3810:           if (!found)
                   3811:             /* break the loop when the current value was not parsed */
                   3812:             p = cssRule + 1;
                   3813:         }
1.263     vatton   3814:       ptr = cssRule;
1.270     vatton   3815:       /* set default variant, style, weight */
                   3816:       if (!variant)
1.405     kia      3817:         ParseACSSFontVariant (element, tsch, context, (char*)"normal", css, isHTML);
1.270     vatton   3818:       if (!style)
1.405     kia      3819:         ParseACSSFontStyle (element, tsch, context, (char*)"normal", css, isHTML);
1.270     vatton   3820:       if (!weight)
1.405     kia      3821:         ParseACSSFontWeight (element, tsch, context, (char*)"normal", css, isHTML);
1.270     vatton   3822:       /* now parse the font size and the font family */
1.301     vatton   3823:       if (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS)
1.327     vatton   3824:         cssRule = ParseACSSFontSize (element, tsch, context, cssRule, css, isHTML, FALSE);
1.301     vatton   3825:       if (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS)
1.366     vatton   3826:         {
                   3827:           cssRule = SkipBlanksAndComments (cssRule);
                   3828:           start_value = cssRule;
                   3829:           cssRule = ParseACSSFontFamily (element, tsch, context, cssRule, css, isHTML);
                   3830:           if (DoDialog)
                   3831:             DisplayStyleValue ("font-family", start_value, cssRule);
                   3832:         }
1.263     vatton   3833:       if (ptr == cssRule)
1.360     vatton   3834:         cssRule = SkipValue ("Invalid font value", cssRule);
1.43      cvs      3835:     }
1.263     vatton   3836:   cssRule = SkipBlanksAndComments (cssRule);
1.301     vatton   3837:   if (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS)
1.360     vatton   3838:     cssRule = SkipValue ("Invalid font value", cssRule);
1.43      cvs      3839:   return (cssRule);
1.1       cvs      3840: }
                   3841: 
                   3842: /*----------------------------------------------------------------------
1.356     quint    3843:   ParseCSSTextDecoration: parse a CSS text-decoration value.
                   3844:   We expect the input string to be none, inherit or a combination of
                   3845:   underline, overline, line-through, and blink.
1.1       cvs      3846:   ----------------------------------------------------------------------*/
1.79      cvs      3847: static char *ParseCSSTextDecoration (Element element, PSchema tsch,
1.327     vatton   3848:                                      PresentationContext context, char *cssRule,
                   3849:                                      CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      3850: {
1.327     vatton   3851:   PresentationValue   decor;
1.366     vatton   3852:   char               *ptr;
1.356     quint    3853:   ThotBool            ok;
1.327     vatton   3854: 
                   3855:   decor.typed_data.value = 0;
                   3856:   decor.typed_data.unit = UNIT_REL;
                   3857:   decor.typed_data.real = FALSE;
                   3858:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   3859:   ptr = cssRule;
1.356     quint    3860:   ok = TRUE;
1.327     vatton   3861:   if (!strncasecmp (cssRule, "none", 4))
                   3862:     {
                   3863:       decor.typed_data.value = NoUnderline;
                   3864:       cssRule += 4;
                   3865:     }
                   3866:   else if (!strncasecmp (cssRule, "inherit", 7))
                   3867:     {
                   3868:       decor.typed_data.unit = VALUE_INHERIT;
                   3869:       cssRule += 7;
                   3870:     }
                   3871:   else
                   3872:     {
1.356     quint    3873:       do
                   3874:         {
                   3875:           if (!strncasecmp (cssRule, "underline", 9))
                   3876:             {
                   3877:               decor.typed_data.value = Underline;
                   3878:               cssRule += 9;
                   3879:             }
                   3880:           else if (!strncasecmp (cssRule, "overline", 8))
                   3881:             {
                   3882:               decor.typed_data.value = Overline;
                   3883:               cssRule += 8;
                   3884:             }
                   3885:           else if (!strncasecmp (cssRule, "line-through", 12))
                   3886:             {
                   3887:               decor.typed_data.value = CrossOut;
                   3888:               cssRule += 12;
                   3889:             }
                   3890:           else if (!strncasecmp (cssRule, "blink", 5))
                   3891:             {
                   3892:               /* the blink text-decoration attribute is not supported */
                   3893:               cssRule += 5;
                   3894:             }
                   3895:           else
                   3896:             ok = FALSE;
                   3897:           if (ok)
                   3898:             {
                   3899:               cssRule = SkipBlanksAndComments (cssRule);
                   3900:             }
                   3901:         }
                   3902:       while (ok && (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS));
                   3903:     }
                   3904:   if (!ok)
                   3905:     {
1.327     vatton   3906:       cssRule = SkipValue ("Invalid text-decoration value", cssRule);
                   3907:       return (cssRule);
                   3908:     }
1.1       cvs      3909: 
1.327     vatton   3910:   /*
                   3911:    * install the new presentation.
                   3912:    */
1.366     vatton   3913:   if (decor.typed_data.value || decor.typed_data.unit == VALUE_INHERIT)
                   3914:     {
                   3915:       if (DoDialog)
                   3916:         DisplayStyleValue ("text-decoration", ptr, cssRule);
                   3917:       else if (DoApply)
                   3918:         TtaSetStylePresentation (PRUnderline, element, tsch, context, decor);
                   3919:     }
1.327     vatton   3920:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid text-decoration value");
                   3921:   return (cssRule);
1.1       cvs      3922: }
                   3923: 
                   3924: /*----------------------------------------------------------------------
1.327     vatton   3925:   ParseCSSHeight: parse a CSS height attribute
1.1       cvs      3926:   ----------------------------------------------------------------------*/
1.79      cvs      3927: static char *ParseCSSHeight (Element element, PSchema tsch,
1.327     vatton   3928:                              PresentationContext context, char *cssRule,
                   3929:                              CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      3930: {
1.117     vatton   3931:   PresentationValue   val;
1.168     vatton   3932:   char               *ptr;
1.93      vatton   3933: 
1.370     vatton   3934:   val.typed_data.real = FALSE;
1.117     vatton   3935:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   3936:   ptr = cssRule;
1.117     vatton   3937:   /* first parse the attribute string */
1.164     quint    3938:   if (!strncasecmp (cssRule, "auto", 4))
                   3939:     {
1.184     vatton   3940:       val.typed_data.unit = VALUE_AUTO;
1.164     quint    3941:       val.typed_data.value = 0;
1.288     vatton   3942:       cssRule += 4;
                   3943:       cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid height value");
1.164     quint    3944:     }
1.117     vatton   3945:   else
1.168     vatton   3946:     cssRule = ParseCSSUnit (cssRule, &val);
1.295     vatton   3947: 
1.387     quint    3948:   if (val.typed_data.unit == UNIT_INVALID ||
                   3949:       (val.typed_data.value != 0 &&
1.184     vatton   3950:        val.typed_data.unit == UNIT_BOX))
1.387     quint    3951:     CSSParseError ("height value", ptr, cssRule);
                   3952:   else if (DoDialog)
1.366     vatton   3953:     DisplayStyleValue ("height", ptr, cssRule);
                   3954:   else if (DoApply)
1.295     vatton   3955:     /* install the new presentation */
                   3956:     TtaSetStylePresentation (PRHeight, element, tsch, context, val);
1.117     vatton   3957:   return (cssRule);
1.1       cvs      3958: }
                   3959: 
                   3960: /*----------------------------------------------------------------------
1.382     vatton   3961:   ParseCSSMaxHeight: parse a CSS height attribute
                   3962:   ----------------------------------------------------------------------*/
                   3963: static char *ParseCSSMaxHeight (Element element, PSchema tsch,
                   3964:                              PresentationContext context, char *cssRule,
                   3965:                              CSSInfoPtr css, ThotBool isHTML)
                   3966: {
                   3967:   PresentationValue   val;
                   3968:   char               *ptr;
                   3969: 
                   3970:   val.typed_data.real = FALSE;
                   3971:   cssRule = SkipBlanksAndComments (cssRule);
                   3972:   ptr = cssRule;
                   3973:   /* first parse the attribute string */
                   3974:   if (!strncasecmp (cssRule, "auto", 4))
                   3975:     {
                   3976:       val.typed_data.unit = VALUE_AUTO;
                   3977:       val.typed_data.value = 0;
                   3978:       cssRule += 4;
                   3979:       cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid height value");
                   3980:     }
                   3981:   else
                   3982:     cssRule = ParseCSSUnit (cssRule, &val);
                   3983: 
1.387     quint    3984:   if (val.typed_data.unit == UNIT_INVALID ||
                   3985:       (val.typed_data.value != 0 &&
1.382     vatton   3986:        val.typed_data.unit == UNIT_BOX))
1.387     quint    3987:     CSSParseError ("height value", ptr, cssRule);
                   3988:   else if (DoDialog)
1.382     vatton   3989:     DisplayStyleValue ("max-height", ptr, cssRule);
1.390     vatton   3990:   /*else if (DoApply)
                   3991:     install the new presentation
                   3992:     TtaSetStylePresentation (PRHeight, element, tsch, context, val)*/;
1.382     vatton   3993:   return (cssRule);
                   3994: }
                   3995: 
                   3996: /*----------------------------------------------------------------------
                   3997:   ParseCSSMinHeight: parse a CSS height attribute
                   3998:   ----------------------------------------------------------------------*/
                   3999: static char *ParseCSSMinHeight (Element element, PSchema tsch,
                   4000:                              PresentationContext context, char *cssRule,
                   4001:                              CSSInfoPtr css, ThotBool isHTML)
                   4002: {
                   4003:   PresentationValue   val;
                   4004:   char               *ptr;
                   4005: 
                   4006:   val.typed_data.real = FALSE;
                   4007:   cssRule = SkipBlanksAndComments (cssRule);
                   4008:   ptr = cssRule;
                   4009:   /* first parse the attribute string */
                   4010:   if (!strncasecmp (cssRule, "auto", 4))
                   4011:     {
                   4012:       val.typed_data.unit = VALUE_AUTO;
                   4013:       val.typed_data.value = 0;
                   4014:       cssRule += 4;
                   4015:       cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid height value");
                   4016:     }
                   4017:   else
                   4018:     cssRule = ParseCSSUnit (cssRule, &val);
                   4019: 
1.387     quint    4020:   if (val.typed_data.unit == UNIT_INVALID ||
                   4021:       (val.typed_data.value != 0 &&
1.382     vatton   4022:        val.typed_data.unit == UNIT_BOX))
1.387     quint    4023:     CSSParseError ("height value", ptr, cssRule);
                   4024:   else if (DoDialog)
1.382     vatton   4025:     DisplayStyleValue ("min-height", ptr, cssRule);
1.390     vatton   4026:   /*else if (DoApply)*/
1.382     vatton   4027:     /* install the new presentation */
1.384     vatton   4028:     /*TtaSetStylePresentation (PRHeight, element, tsch, context, val)*/;
1.382     vatton   4029:   return (cssRule);
                   4030: }
                   4031: 
                   4032: /*----------------------------------------------------------------------
1.327     vatton   4033:   ParseCSSWidth: parse a CSS width attribute
1.1       cvs      4034:   ----------------------------------------------------------------------*/
1.79      cvs      4035: static char *ParseCSSWidth (Element element, PSchema tsch,
1.327     vatton   4036:                             PresentationContext context,
                   4037:                             char *cssRule, CSSInfoPtr css,
                   4038:                             ThotBool isHTML)
1.1       cvs      4039: {
1.117     vatton   4040:   PresentationValue   val;
1.168     vatton   4041:   char               *ptr;
1.93      vatton   4042: 
1.370     vatton   4043:   val.typed_data.real = FALSE;
1.117     vatton   4044:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   4045:   ptr = cssRule;
1.117     vatton   4046:   /* first parse the attribute string */
1.164     quint    4047:   if (!strncasecmp (cssRule, "auto", 4))
                   4048:     {
1.184     vatton   4049:       val.typed_data.unit = VALUE_AUTO;
1.164     quint    4050:       val.typed_data.value = 0;
1.288     vatton   4051:       cssRule += 4;
                   4052:       cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid width value");
1.164     quint    4053:     }
1.117     vatton   4054:   else
1.327     vatton   4055:     cssRule = ParseCSSUnit (cssRule, &val);
1.387     quint    4056:   if (val.typed_data.unit == UNIT_INVALID ||
                   4057:       (val.typed_data.value != 0 &&
1.184     vatton   4058:        val.typed_data.unit == UNIT_BOX))
1.387     quint    4059:     CSSParseError ("Invalid width value", ptr, cssRule);
                   4060:   else if (DoDialog)
1.366     vatton   4061:     DisplayStyleValue ("width", ptr, cssRule);
                   4062:   else if (DoApply)
1.295     vatton   4063:     /* install the new presentation */
                   4064:     TtaSetStylePresentation (PRWidth, element, tsch, context, val);
1.117     vatton   4065:   return (cssRule);
1.1       cvs      4066: }
                   4067: 
                   4068: /*----------------------------------------------------------------------
1.382     vatton   4069:   ParseCSSMaxWidth: parse a CSS width attribute
                   4070:   ----------------------------------------------------------------------*/
                   4071: static char *ParseCSSMaxWidth (Element element, PSchema tsch,
                   4072:                                PresentationContext context,
                   4073:                                char *cssRule, CSSInfoPtr css,
                   4074:                                ThotBool isHTML)
                   4075: {
                   4076:   PresentationValue   val;
                   4077:   char               *ptr;
                   4078: 
                   4079:   val.typed_data.real = FALSE;
                   4080:   cssRule = SkipBlanksAndComments (cssRule);
                   4081:   ptr = cssRule;
                   4082:   /* first parse the attribute string */
                   4083:   if (!strncasecmp (cssRule, "auto", 4))
                   4084:     {
                   4085:       val.typed_data.unit = VALUE_AUTO;
                   4086:       val.typed_data.value = 0;
                   4087:       cssRule += 4;
                   4088:       cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid width value");
                   4089:     }
                   4090:   else
                   4091:     cssRule = ParseCSSUnit (cssRule, &val);
1.387     quint    4092:   if (val.typed_data.unit == UNIT_INVALID ||
                   4093:       (val.typed_data.value != 0 &&
1.382     vatton   4094:        val.typed_data.unit == UNIT_BOX))
                   4095:       CSSParseError ("Invalid width value", ptr, cssRule);
1.387     quint    4096:   else if (DoDialog)
1.382     vatton   4097:     DisplayStyleValue ("max-width", ptr, cssRule);
1.408     vatton   4098:   /*else if (DoApply)*/
1.382     vatton   4099:     /* install the new presentation */
1.384     vatton   4100:     /*TtaSetStylePresentation (PRWidth, element, tsch, context, val)*/;
1.382     vatton   4101:   return (cssRule);
                   4102: }
                   4103: 
                   4104: /*----------------------------------------------------------------------
                   4105:   ParseCSSMinWidth: parse a CSS width attribute
                   4106:   ----------------------------------------------------------------------*/
                   4107: static char *ParseCSSMinWidth (Element element, PSchema tsch,
                   4108:                                PresentationContext context,
                   4109:                                char *cssRule, CSSInfoPtr css,
                   4110:                                ThotBool isHTML)
                   4111: {
                   4112:   PresentationValue   val;
                   4113:   char               *ptr;
                   4114: 
                   4115:   val.typed_data.real = FALSE;
                   4116:   cssRule = SkipBlanksAndComments (cssRule);
                   4117:   ptr = cssRule;
                   4118:   /* first parse the attribute string */
                   4119:   if (!strncasecmp (cssRule, "auto", 4))
                   4120:     {
                   4121:       val.typed_data.unit = VALUE_AUTO;
                   4122:       val.typed_data.value = 0;
                   4123:       cssRule += 4;
                   4124:       cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid width value");
                   4125:     }
                   4126:   else
                   4127:     cssRule = ParseCSSUnit (cssRule, &val);
1.387     quint    4128:   if (val.typed_data.unit == UNIT_INVALID ||
                   4129:       (val.typed_data.value != 0 &&
1.382     vatton   4130:        val.typed_data.unit == UNIT_BOX))
1.387     quint    4131:     CSSParseError ("Invalid width value", ptr, cssRule);
                   4132:   else if (DoDialog)
1.382     vatton   4133:     DisplayStyleValue ("min-width", ptr, cssRule);
1.408     vatton   4134:   /*else if (DoApply)*/
1.382     vatton   4135:     /* install the new presentation */
1.384     vatton   4136:     /*TtaSetStylePresentation (PRWidth, element, tsch, context, val)*/;
1.382     vatton   4137:   return (cssRule);
                   4138: }
                   4139: 
                   4140: /*----------------------------------------------------------------------
1.391     vatton   4141:   GetEmMarginValue returns the em value 
                   4142:   ----------------------------------------------------------------------*/
                   4143: int GetEmValue (char *data, Element el, Document doc)
                   4144: {
                   4145:   PresentationValue   val;
                   4146:   char               *ptr;
                   4147:   int                 value;
                   4148: 
                   4149:   val.typed_data.real = FALSE;
                   4150:   ptr = SkipBlanksAndComments (data);
                   4151:   if (!strncasecmp (data, "auto", 4))
                   4152:     value = TtaGetPixelValue (0, VALUE_AUTO, el, doc);
                   4153:   else
                   4154:     {
                   4155:       ptr = ParseCSSUnit (data, &val);
                   4156:       value = TtaGetPixelValue (val.typed_data.value, val.typed_data.unit,
                   4157:                              el, doc);
                   4158:     }
                   4159:   return TtaGetLogicalValue (value, UNIT_EM, el, doc);
                   4160: }
                   4161: 
                   4162: /*----------------------------------------------------------------------
1.327     vatton   4163:   ParseACSSMarginTop: parse a CSS margin-top attribute
1.1       cvs      4164:   ----------------------------------------------------------------------*/
1.296     vatton   4165: static char *ParseACSSMarginTop (Element element, PSchema tsch,
1.327     vatton   4166:                                  PresentationContext context,
                   4167:                                  char *cssRule, CSSInfoPtr css,
                   4168:                                  ThotBool isHTML)
1.1       cvs      4169: {
                   4170:   PresentationValue   margin;
1.168     vatton   4171:   char               *ptr;
1.1       cvs      4172:   
1.370     vatton   4173:   margin.typed_data.real = FALSE;
1.82      cvs      4174:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   4175:   ptr = cssRule;
1.1       cvs      4176:   /* first parse the attribute string */
1.164     quint    4177:   if (!strncasecmp (cssRule, "auto", 4))
                   4178:     {
1.184     vatton   4179:       margin.typed_data.unit = VALUE_AUTO;
1.164     quint    4180:       margin.typed_data.value = 0;
1.288     vatton   4181:       cssRule += 4;
1.164     quint    4182:     }
1.404     vatton   4183:   else if (!strncasecmp (cssRule, "inherit", 7))
                   4184:     {
                   4185:       margin.typed_data.unit = VALUE_AUTO;
                   4186:       margin.typed_data.value = 0;
                   4187:       cssRule += 7;
                   4188:     }
1.164     quint    4189:   else
1.168     vatton   4190:     cssRule = ParseCSSUnit (cssRule, &margin);
1.295     vatton   4191: 
1.387     quint    4192:   if (margin.typed_data.unit == UNIT_INVALID ||
                   4193:       (margin.typed_data.value != 0 &&
1.184     vatton   4194:        margin.typed_data.unit == UNIT_BOX))
1.169     vatton   4195:     CSSParseError ("Invalid margin-top value", ptr, cssRule);
1.366     vatton   4196:   else if (DoDialog)
                   4197:     {
                   4198:       if (All_sides)
                   4199:         DisplayStyleValue ("margin", ptr, cssRule);
                   4200:       else
                   4201:         DisplayStyleValue ("margin-top", ptr, cssRule);
                   4202:     }
1.168     vatton   4203:   else if (DoApply)
1.295     vatton   4204:     TtaSetStylePresentation (PRMarginTop, element, tsch, context, margin);
1.1       cvs      4205:   return (cssRule);
                   4206: }
                   4207: 
                   4208: /*----------------------------------------------------------------------
1.327     vatton   4209:   ParseCSSMarginTop: parse a CSS margin-top attribute
1.296     vatton   4210:   ----------------------------------------------------------------------*/
                   4211: static char *ParseCSSMarginTop (Element element, PSchema tsch,
1.327     vatton   4212:                                 PresentationContext context,
                   4213:                                 char *cssRule, CSSInfoPtr css,
                   4214:                                 ThotBool isHTML)
1.296     vatton   4215: {
                   4216:   char *ptr = cssRule;
                   4217: 
                   4218:   cssRule = ParseACSSMarginTop (element, tsch, context, ptr, css, isHTML);
                   4219:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid margin-top value");
                   4220:   return (cssRule);
                   4221: }
                   4222: 
                   4223: /*----------------------------------------------------------------------
                   4224:   ParseACSSMarginBottom: parse a CSS margin-bottom attribute
1.1       cvs      4225:   ----------------------------------------------------------------------*/
1.296     vatton   4226: static char *ParseACSSMarginBottom (Element element, PSchema tsch,
1.327     vatton   4227:                                     PresentationContext context,
                   4228:                                     char *cssRule, CSSInfoPtr css,
                   4229:                                     ThotBool isHTML)
1.1       cvs      4230: {
                   4231:   PresentationValue   margin;
1.168     vatton   4232:   char               *ptr;
1.1       cvs      4233:   
1.370     vatton   4234:   margin.typed_data.real = FALSE;
1.82      cvs      4235:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   4236:   ptr = cssRule;
1.1       cvs      4237:   /* first parse the attribute string */
1.164     quint    4238:   if (!strncasecmp (cssRule, "auto", 4))
                   4239:     {
1.184     vatton   4240:       margin.typed_data.unit = VALUE_AUTO;
1.164     quint    4241:       margin.typed_data.value = 0;
1.288     vatton   4242:       cssRule += 4;
1.164     quint    4243:     }
1.404     vatton   4244:   else if (!strncasecmp (cssRule, "inherit", 7))
                   4245:     {
                   4246:       margin.typed_data.unit = VALUE_AUTO;
                   4247:       margin.typed_data.value = 0;
                   4248:       cssRule += 7;
                   4249:     }
1.164     quint    4250:   else
1.168     vatton   4251:     cssRule = ParseCSSUnit (cssRule, &margin);
1.295     vatton   4252: 
1.387     quint    4253:   if (margin.typed_data.unit == UNIT_INVALID ||
                   4254:       (margin.typed_data.value != 0 &&
1.184     vatton   4255:        margin.typed_data.unit == UNIT_BOX))
1.169     vatton   4256:     CSSParseError ("Invalid margin-bottom value", ptr, cssRule);
1.366     vatton   4257:   else if (DoDialog)
                   4258:     DisplayStyleValue ("margin-bottom", ptr, cssRule);
1.168     vatton   4259:   else if (DoApply)
1.295     vatton   4260:     TtaSetStylePresentation (PRMarginBottom, element, tsch, context, margin);
1.1       cvs      4261:   return (cssRule);
                   4262: }
                   4263: 
                   4264: /*----------------------------------------------------------------------
1.296     vatton   4265:   ParseCSSMarginBottom: parse a CSS margin-bottom attribute
                   4266:   ----------------------------------------------------------------------*/
                   4267: static char *ParseCSSMarginBottom (Element element, PSchema tsch,
1.327     vatton   4268:                                    PresentationContext context,
                   4269:                                    char *cssRule, CSSInfoPtr css,
                   4270:                                    ThotBool isHTML)
1.296     vatton   4271: {
                   4272:   char *ptr = cssRule;
                   4273: 
                   4274:   cssRule = ParseACSSMarginBottom (element, tsch, context, ptr, css, isHTML);
                   4275:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid margin-bottom value");
                   4276:   return (cssRule);
                   4277: }
                   4278: 
                   4279: /*----------------------------------------------------------------------
                   4280:   ParseACSSMarginLeft: parse a CSS margin-left attribute string
1.1       cvs      4281:   ----------------------------------------------------------------------*/
1.296     vatton   4282: static char *ParseACSSMarginLeft (Element element, PSchema tsch,
1.327     vatton   4283:                                   PresentationContext context,
                   4284:                                   char *cssRule, CSSInfoPtr css,
                   4285:                                   ThotBool isHTML)
1.1       cvs      4286: {
                   4287:   PresentationValue   margin;
1.168     vatton   4288:   char               *ptr;
1.1       cvs      4289:   
1.370     vatton   4290:   margin.typed_data.real = FALSE;
1.82      cvs      4291:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   4292:   ptr = cssRule;
1.1       cvs      4293:   /* first parse the attribute string */
1.164     quint    4294:   if (!strncasecmp (cssRule, "auto", 4))
                   4295:     {
1.184     vatton   4296:       margin.typed_data.unit = VALUE_AUTO;
1.164     quint    4297:       margin.typed_data.value = 0;
1.288     vatton   4298:       cssRule += 4;
1.164     quint    4299:     }
                   4300:   else
1.168     vatton   4301:     cssRule = ParseCSSUnit (cssRule, &margin);
1.295     vatton   4302: 
1.387     quint    4303:   if (margin.typed_data.unit == UNIT_INVALID ||
                   4304:       (margin.typed_data.value != 0 &&
1.184     vatton   4305:        margin.typed_data.unit == UNIT_BOX))
1.169     vatton   4306:     CSSParseError ("Invalid margin-left value", ptr, cssRule);
1.366     vatton   4307:   else if (DoDialog)
                   4308:     DisplayStyleValue ("margin-left", ptr, cssRule);
1.295     vatton   4309:   else if (DoApply && margin.typed_data.unit != UNIT_INVALID && DoApply)
1.327     vatton   4310:     TtaSetStylePresentation (PRMarginLeft, element, tsch, context, margin);
1.1       cvs      4311:   return (cssRule);
                   4312: }
                   4313: 
                   4314: /*----------------------------------------------------------------------
1.296     vatton   4315:   ParseCSSMarginBottom: parse a CSS margin-bottom attribute
                   4316:   ----------------------------------------------------------------------*/
                   4317: static char *ParseCSSMarginLeft (Element element, PSchema tsch,
1.327     vatton   4318:                                  PresentationContext context,
                   4319:                                  char *cssRule, CSSInfoPtr css,
                   4320:                                  ThotBool isHTML)
1.296     vatton   4321: {
                   4322:   char *ptr = cssRule;
                   4323: 
                   4324:   cssRule = ParseACSSMarginLeft (element, tsch, context, ptr, css, isHTML);
                   4325:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid margin-left value");
                   4326:   return (cssRule);
                   4327: }
                   4328: 
                   4329: 
                   4330: /*----------------------------------------------------------------------
                   4331:   ParseACSSMarginRight: parse a CSS margin-right attribute string
1.1       cvs      4332:   ----------------------------------------------------------------------*/
1.296     vatton   4333: static char *ParseACSSMarginRight (Element element, PSchema tsch,
1.327     vatton   4334:                                    PresentationContext context,
                   4335:                                    char *cssRule, CSSInfoPtr css,
                   4336:                                    ThotBool isHTML)
1.1       cvs      4337: {
                   4338:   PresentationValue   margin;
1.168     vatton   4339:   char               *ptr;
1.1       cvs      4340:   
1.370     vatton   4341:   margin.typed_data.real = FALSE;
1.82      cvs      4342:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   4343:   ptr = cssRule;
1.1       cvs      4344:   /* first parse the attribute string */
1.164     quint    4345:   if (!strncasecmp (cssRule, "auto", 4))
                   4346:     {
1.184     vatton   4347:       margin.typed_data.unit = VALUE_AUTO;
1.164     quint    4348:       margin.typed_data.value = 0;
1.288     vatton   4349:       cssRule += 4;
1.164     quint    4350:     }
1.404     vatton   4351:   else if (!strncasecmp (cssRule, "inherit", 7))
                   4352:     {
                   4353:       margin.typed_data.unit = VALUE_AUTO;
                   4354:       margin.typed_data.value = 0;
                   4355:       cssRule += 7;
                   4356:     }
1.164     quint    4357:   else
1.168     vatton   4358:     cssRule = ParseCSSUnit (cssRule, &margin);
1.295     vatton   4359: 
1.387     quint    4360:   if (margin.typed_data.unit == UNIT_INVALID ||
                   4361:       (margin.typed_data.value != 0 &&
1.184     vatton   4362:        margin.typed_data.unit == UNIT_BOX))
1.169     vatton   4363:     CSSParseError ("Invalid margin-right value", ptr, cssRule);
1.366     vatton   4364:   else if (DoDialog)
                   4365:     DisplayStyleValue ("margin-right", ptr, cssRule);
1.168     vatton   4366:   else if (DoApply)
1.295     vatton   4367:     TtaSetStylePresentation (PRMarginRight, element, tsch, context, margin);
1.1       cvs      4368:   return (cssRule);
                   4369: }
                   4370: 
                   4371: /*----------------------------------------------------------------------
1.296     vatton   4372:   ParseCSSMarginRight: parse a CSS margin-right attribute string
                   4373:   ----------------------------------------------------------------------*/
                   4374: static char *ParseCSSMarginRight (Element element, PSchema tsch,
1.327     vatton   4375:                                   PresentationContext context,
                   4376:                                   char *cssRule, CSSInfoPtr css,
                   4377:                                   ThotBool isHTML)
1.296     vatton   4378: {
                   4379:   char *ptr = cssRule;
                   4380: 
1.297     vatton   4381:   cssRule = ParseACSSMarginRight (element, tsch, context, ptr, css, isHTML);
1.296     vatton   4382:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid margin-right value");
                   4383:   return (cssRule);
                   4384: }
                   4385: 
                   4386: /*----------------------------------------------------------------------
1.59      cvs      4387:   ParseCSSMargin: parse a CSS margin attribute string
1.1       cvs      4388:   ----------------------------------------------------------------------*/
1.79      cvs      4389: static char *ParseCSSMargin (Element element, PSchema tsch,
1.327     vatton   4390:                              PresentationContext context,
                   4391:                              char *cssRule, CSSInfoPtr css,
                   4392:                              ThotBool isHTML)
1.1       cvs      4393: {
1.79      cvs      4394:   char *ptrT, *ptrR, *ptrB, *ptrL;
1.366     vatton   4395:   int   skippedNL, n;
1.1       cvs      4396: 
1.82      cvs      4397:   ptrT = SkipBlanksAndComments (cssRule);
1.366     vatton   4398:   if (DoDialog)
                   4399:     n = NumberOfValues (ptrT);
                   4400:   if (DoDialog && n < 2)
1.1       cvs      4401:     {
1.366     vatton   4402:       // check if the margin dialog must be updated
                   4403:       All_sides = TRUE;
                   4404:       ptrR = ParseACSSMarginTop (element, tsch, context, ptrT, css, isHTML);
                   4405:       All_sides = FALSE;
1.1       cvs      4406:     }
                   4407:   else
                   4408:     {
1.366     vatton   4409:       /* First parse Margin-Top */
                   4410:       ptrR = ParseACSSMarginTop (element, tsch, context, ptrT, css, isHTML);
                   4411:       ptrR = SkipBlanksAndComments (ptrR);
                   4412:       if (*ptrR == ';' || *ptrR == '}' || *ptrR == EOS || *ptrR == ',')
1.327     vatton   4413:         {
                   4414:           skippedNL = NewLineSkipped;
1.366     vatton   4415:           cssRule = ptrR;
                   4416:           /* apply the Margin-Top to all */
                   4417:           ptrR = ParseACSSMarginRight (element, tsch, context, ptrT, css, isHTML);
1.327     vatton   4418:           NewLineSkipped = skippedNL;
1.366     vatton   4419:           ptrR = ParseACSSMarginBottom (element, tsch, context, ptrT, css, isHTML);
                   4420:           NewLineSkipped = skippedNL;
                   4421:           ptrR = ParseACSSMarginLeft (element, tsch, context, ptrT, css, isHTML);
1.327     vatton   4422:         }
1.1       cvs      4423:       else
1.327     vatton   4424:         {
1.366     vatton   4425:           /* parse Margin-Right */
                   4426:           ptrB = ParseACSSMarginRight (element, tsch, context, ptrR, css, isHTML);
                   4427:           ptrB = SkipBlanksAndComments (ptrB);
                   4428:           if (*ptrB == ';' || *ptrB == '}' || *ptrB == EOS || *ptrB == ',')
1.327     vatton   4429:             {
1.366     vatton   4430:               skippedNL = NewLineSkipped;
                   4431:               cssRule = ptrB;
                   4432:               /* apply the Margin-Top to Margin-Bottom */
                   4433:               ptrB = ParseACSSMarginBottom (element, tsch, context, ptrT, css, isHTML);
                   4434:               NewLineSkipped = skippedNL;
1.327     vatton   4435:               /* apply the Margin-Right to Margin-Left */
1.366     vatton   4436:               ptrB = ParseACSSMarginLeft (element, tsch, context, ptrR, css, isHTML);
1.327     vatton   4437:             }
                   4438:           else
1.366     vatton   4439:             {
                   4440:               /* parse Margin-Bottom */
                   4441:               ptrL = ParseACSSMarginBottom (element, tsch, context, ptrB, css, isHTML);
                   4442:               ptrL = SkipBlanksAndComments (ptrL);
                   4443:               if (*ptrL == ';' || *ptrL == '}' || *ptrL == EOS || *ptrL == ',')
                   4444:                 {
                   4445:                   cssRule = ptrL;
                   4446:                   /* apply the Margin-Right to Margin-Left */
                   4447:                   ptrL = ParseACSSMarginLeft (element, tsch, context, ptrR, css, isHTML);
                   4448:                 }
                   4449:               else
                   4450:                 /* parse Margin-Left */
                   4451:                 cssRule = ParseACSSMarginLeft (element, tsch, context, ptrL, css, isHTML);
                   4452:               cssRule = SkipBlanksAndComments (cssRule);
                   4453:             }
1.327     vatton   4454:         }
1.1       cvs      4455:     }
                   4456:   return (cssRule);
                   4457: }
                   4458: 
                   4459: /*----------------------------------------------------------------------
1.418     quint    4460:   ParseCSSOpacity: parse a CSS opacity property
                   4461:   ----------------------------------------------------------------------*/
                   4462: static char *ParseCSSOpacity (Element element, PSchema tsch,
                   4463:                               PresentationContext context, char *cssRule,
                   4464:                               CSSInfoPtr css, ThotBool isHTML)
                   4465: {
                   4466:   PresentationValue     opacity;
                   4467: 
                   4468:   opacity.typed_data.unit = UNIT_INVALID;
                   4469:   opacity.typed_data.real = FALSE;
                   4470:   if (!strncasecmp (cssRule, "inherit", 7))
                   4471:     {
                   4472:       opacity.typed_data.unit = VALUE_INHERIT;
                   4473:       cssRule += 7;
                   4474:     }
                   4475:   else
                   4476:     cssRule = ParseClampedUnit (cssRule, &opacity);
                   4477:   if (DoApply)
                   4478:     /* install the new presentation. */
                   4479:     TtaSetStylePresentation (PROpacity, element, tsch, context, opacity);
                   4480:   return (cssRule);
                   4481: }
                   4482: 
                   4483: /*----------------------------------------------------------------------
1.327     vatton   4484:   ParseCSSPaddingTop: parse a CSS PaddingTop attribute string
1.1       cvs      4485:   ----------------------------------------------------------------------*/
1.79      cvs      4486: static char *ParseCSSPaddingTop (Element element, PSchema tsch,
1.327     vatton   4487:                                  PresentationContext context,
                   4488:                                  char *cssRule, CSSInfoPtr css,
                   4489:                                  ThotBool isHTML)
1.1       cvs      4490: {
1.43      cvs      4491:   PresentationValue   padding;
1.168     vatton   4492:   char               *ptr;
1.370     vatton   4493:  
                   4494:   padding.typed_data.real = FALSE;
1.82      cvs      4495:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   4496:   ptr = cssRule;
1.43      cvs      4497:   /* first parse the attribute string */
                   4498:   cssRule = ParseCSSUnit (cssRule, &padding);
1.295     vatton   4499: 
1.387     quint    4500:   if (padding.typed_data.unit == UNIT_INVALID ||
                   4501:       (padding.typed_data.value != 0 &&
1.184     vatton   4502:        padding.typed_data.unit == UNIT_BOX))
1.387     quint    4503:     CSSParseError ("Invalid padding-top value", ptr, cssRule);
1.366     vatton   4504:   else if (DoDialog)
                   4505:     {
                   4506:       if (All_sides)
                   4507:         DisplayStyleValue ("padding", ptr, cssRule);
                   4508:       else
                   4509:         DisplayStyleValue ("padding-top", ptr, cssRule);
                   4510:     }
1.168     vatton   4511:   else if (DoApply)
1.295     vatton   4512:     TtaSetStylePresentation (PRPaddingTop, element, tsch, context, padding);
1.1       cvs      4513:   return (cssRule);
                   4514: }
                   4515: 
                   4516: /*----------------------------------------------------------------------
1.59      cvs      4517:   ParseCSSPaddingBottom: parse a CSS PaddingBottom attribute string
1.1       cvs      4518:   ----------------------------------------------------------------------*/
1.79      cvs      4519: static char *ParseCSSPaddingBottom (Element element, PSchema tsch,
1.327     vatton   4520:                                     PresentationContext context,
                   4521:                                     char *cssRule, CSSInfoPtr css,
                   4522:                                     ThotBool isHTML)
1.1       cvs      4523: {
1.43      cvs      4524:   PresentationValue   padding;
1.168     vatton   4525:   char               *ptr;
1.43      cvs      4526:   
1.370     vatton   4527:   padding.typed_data.real = FALSE;
1.82      cvs      4528:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   4529:   ptr = cssRule;
1.43      cvs      4530:   /* first parse the attribute string */
                   4531:   cssRule = ParseCSSUnit (cssRule, &padding);
1.387     quint    4532:   if (padding.typed_data.value == 0 && padding.typed_data.unit != UNIT_INVALID)
1.184     vatton   4533:     padding.typed_data.unit = UNIT_EM;
1.295     vatton   4534: 
1.387     quint    4535:   if (padding.typed_data.unit == UNIT_INVALID ||
                   4536:       (padding.typed_data.value != 0 &&
1.184     vatton   4537:        padding.typed_data.unit == UNIT_BOX))
1.387     quint    4538:     CSSParseError ("Invalid padding-bottom value", ptr, cssRule);
1.366     vatton   4539:   else if (DoDialog)
                   4540:     DisplayStyleValue ("padding-bottom", ptr, cssRule);
1.168     vatton   4541:   else if (DoApply)
1.295     vatton   4542:     TtaSetStylePresentation (PRPaddingBottom, element, tsch, context, padding);
1.1       cvs      4543:   return (cssRule);
                   4544: }
                   4545: 
                   4546: /*----------------------------------------------------------------------
1.59      cvs      4547:   ParseCSSPaddingLeft: parse a CSS PaddingLeft attribute string.
1.1       cvs      4548:   ----------------------------------------------------------------------*/
1.79      cvs      4549: static char *ParseCSSPaddingLeft (Element element, PSchema tsch,
1.327     vatton   4550:                                   PresentationContext context,
                   4551:                                   char *cssRule, CSSInfoPtr css,
                   4552:                                   ThotBool isHTML)
1.1       cvs      4553: {
1.43      cvs      4554:   PresentationValue   padding;
1.168     vatton   4555:   char               *ptr;
1.43      cvs      4556:   
1.370     vatton   4557:   padding.typed_data.real = FALSE;
1.82      cvs      4558:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   4559:   ptr = cssRule;
1.43      cvs      4560:   /* first parse the attribute string */
                   4561:   cssRule = ParseCSSUnit (cssRule, &padding);
1.387     quint    4562:   if (padding.typed_data.value == 0 && padding.typed_data.unit != UNIT_INVALID)
1.184     vatton   4563:     padding.typed_data.unit = UNIT_EM;
1.295     vatton   4564: 
1.387     quint    4565:   if (padding.typed_data.unit == UNIT_INVALID ||
                   4566:       (padding.typed_data.value != 0 &&
1.184     vatton   4567:        padding.typed_data.unit == UNIT_BOX))
1.168     vatton   4568:     {
1.169     vatton   4569:       CSSParseError ("Invalid padding-left value", ptr, cssRule);
1.168     vatton   4570:       padding.typed_data.value = 0;
                   4571:     }
1.366     vatton   4572:   else if (DoDialog)
                   4573:     DisplayStyleValue ("padding-left", ptr, cssRule);
1.168     vatton   4574:   else if (DoApply)
1.295     vatton   4575:     TtaSetStylePresentation (PRPaddingLeft, element, tsch, context, padding);
1.1       cvs      4576:   return (cssRule);
                   4577: }
                   4578: 
                   4579: /*----------------------------------------------------------------------
1.59      cvs      4580:   ParseCSSPaddingRight: parse a CSS PaddingRight attribute string.
1.1       cvs      4581:   ----------------------------------------------------------------------*/
1.79      cvs      4582: static char *ParseCSSPaddingRight (Element element, PSchema tsch,
1.327     vatton   4583:                                    PresentationContext context,
                   4584:                                    char *cssRule, CSSInfoPtr css,
                   4585:                                    ThotBool isHTML)
1.1       cvs      4586: {
1.43      cvs      4587:   PresentationValue   padding;
1.168     vatton   4588:   char               *ptr;
1.43      cvs      4589:   
1.370     vatton   4590:   padding.typed_data.real = FALSE;
1.82      cvs      4591:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   4592:   ptr = cssRule;
1.43      cvs      4593:   /* first parse the attribute string */
                   4594:   cssRule = ParseCSSUnit (cssRule, &padding);
1.387     quint    4595:   if (padding.typed_data.value == 0 && padding.typed_data.unit != UNIT_INVALID)
1.184     vatton   4596:     padding.typed_data.unit = UNIT_EM;
1.295     vatton   4597: 
1.387     quint    4598:   if (padding.typed_data.unit == UNIT_INVALID ||
                   4599:       (padding.typed_data.value != 0 &&
1.184     vatton   4600:        padding.typed_data.unit == UNIT_BOX))
1.387     quint    4601:     CSSParseError ("Invalid padding-right value", ptr, cssRule);
1.366     vatton   4602:   else if (DoDialog)
                   4603:     DisplayStyleValue ("padding-right", ptr, cssRule);
1.168     vatton   4604:   else if (DoApply)
1.295     vatton   4605:     TtaSetStylePresentation (PRPaddingRight, element, tsch, context, padding);
1.1       cvs      4606:   return (cssRule);
                   4607: }
                   4608: 
                   4609: /*----------------------------------------------------------------------
1.327     vatton   4610:   ParseCSSPadding: parse a CSS padding attribute string. 
1.1       cvs      4611:   ----------------------------------------------------------------------*/
1.79      cvs      4612: static char *ParseCSSPadding (Element element, PSchema tsch,
1.327     vatton   4613:                               PresentationContext context,
                   4614:                               char *cssRule, CSSInfoPtr css,
                   4615:                               ThotBool isHTML)
1.1       cvs      4616: {
1.79      cvs      4617:   char *ptrT, *ptrR, *ptrB, *ptrL;
1.366     vatton   4618:   int   skippedNL, n;
1.43      cvs      4619: 
1.82      cvs      4620:   ptrT = SkipBlanksAndComments (cssRule);
1.366     vatton   4621:   if (DoDialog)
                   4622:     n = NumberOfValues (ptrT);
                   4623:   if (DoDialog && n < 2)
1.43      cvs      4624:     {
1.366     vatton   4625:       // check if the padding dialog must be updated
                   4626:       All_sides = TRUE;
                   4627:       ptrR = ParseCSSPaddingTop (element, tsch, context, ptrT, css, isHTML);
                   4628:       All_sides = FALSE;
1.43      cvs      4629:     }
                   4630:   else
                   4631:     {
1.366     vatton   4632:       /* First parse Padding-Top */
                   4633:       ptrR = ParseCSSPaddingTop (element, tsch, context, ptrT, css, isHTML);
                   4634:       ptrR = SkipBlanksAndComments (ptrR);
                   4635:       if (*ptrR == ';' || *ptrR == EOS || *ptrR == ',')
1.327     vatton   4636:         {
                   4637:           skippedNL = NewLineSkipped;
1.366     vatton   4638:           cssRule = ptrR;
                   4639:           /* apply the Padding-Top to all */
                   4640:           ptrR = ParseCSSPaddingRight (element, tsch, context, ptrT, css, isHTML);
1.327     vatton   4641:           NewLineSkipped = skippedNL;
1.366     vatton   4642:           ptrR = ParseCSSPaddingBottom (element, tsch, context, ptrT, css, isHTML);
                   4643:           NewLineSkipped = skippedNL;
                   4644:           ptrR = ParseCSSPaddingLeft (element, tsch, context, ptrT, css, isHTML);
1.327     vatton   4645:         }
1.43      cvs      4646:       else
1.327     vatton   4647:         {
1.366     vatton   4648:           /* parse Padding-Right */
                   4649:           ptrB = ParseCSSPaddingRight (element, tsch, context, ptrR, css, isHTML);
                   4650:           ptrB = SkipBlanksAndComments (ptrB);
                   4651:           if (*ptrB == ';' || *ptrB == EOS || *ptrB == ',')
1.327     vatton   4652:             {
1.366     vatton   4653:               skippedNL = NewLineSkipped;
                   4654:               cssRule = ptrB;
                   4655:               /* apply the Padding-Top to Padding-Bottom */
                   4656:               ptrB = ParseCSSPaddingBottom (element, tsch, context, ptrT, css, isHTML);
                   4657:               NewLineSkipped = skippedNL;
1.327     vatton   4658:               /* apply the Padding-Right to Padding-Left */
1.366     vatton   4659:               ptrB = ParseCSSPaddingLeft (element, tsch, context, ptrR, css, isHTML);
1.327     vatton   4660:             }
                   4661:           else
1.366     vatton   4662:             {
                   4663:               /* parse Padding-Bottom */
                   4664:               ptrL = ParseCSSPaddingBottom (element, tsch, context, ptrB, css, isHTML);
                   4665:               ptrL = SkipBlanksAndComments (ptrL);
                   4666:               if (*ptrL == ';' || *ptrL == EOS || *ptrL == ',')
                   4667:                 {
                   4668:                   cssRule = ptrL;
                   4669:                   /* apply the Padding-Right to Padding-Left */
                   4670:                   ptrL = ParseCSSPaddingLeft (element, tsch, context, ptrR, css, isHTML);
                   4671:                 }
                   4672:               else
                   4673:                 /* parse Padding-Left */
                   4674:                 cssRule = ParseCSSPaddingLeft (element, tsch, context, ptrL, css, isHTML);
                   4675:               cssRule = SkipBlanksAndComments (cssRule);
                   4676:             }
1.327     vatton   4677:         }
1.43      cvs      4678:     }
1.1       cvs      4679:   return (cssRule);
                   4680: }
                   4681: 
                   4682: /*----------------------------------------------------------------------
1.327     vatton   4683:   ParseCSSForeground: parse a CSS foreground attribute 
1.1       cvs      4684:   ----------------------------------------------------------------------*/
1.79      cvs      4685: static char *ParseCSSForeground (Element element, PSchema tsch,
1.327     vatton   4686:                                  PresentationContext context,
                   4687:                                  char *cssRule,
                   4688:                                  CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      4689: {
1.425     quint    4690:   ElementType         elType;
1.117     vatton   4691:   PresentationValue   best;
1.262     vatton   4692:   char               *p;
1.1       cvs      4693: 
1.370     vatton   4694:   best.typed_data.real = FALSE;
1.366     vatton   4695:   cssRule = SkipBlanksAndComments (cssRule);
1.262     vatton   4696:   p = cssRule;
1.117     vatton   4697:   cssRule = ParseCSSColor (cssRule, &best);
1.366     vatton   4698:   if (best.typed_data.unit != UNIT_INVALID)
1.327     vatton   4699:     {
                   4700:       if (*cssRule != EOS && *cssRule !=';')
                   4701:         {
                   4702:           cssRule = SkipProperty (cssRule, FALSE);
1.366     vatton   4703:           CSSParseError ("Invalid color value", p, cssRule);
1.327     vatton   4704:         }
1.366     vatton   4705:       else if (DoDialog)
                   4706:         DisplayStyleValue ("color", p, cssRule);
                   4707:       else if (DoApply)
1.327     vatton   4708:         /* install the new presentation */
1.425     quint    4709:        {
                   4710:           elType = TtaGetElementType(element);
                   4711:           if (!strcmp(TtaGetSSchemaName (elType.ElSSchema), "SVG"))
                   4712:             /* we are working for an SVG element */
                   4713:            TtaSetStylePresentation (PRColor, element, tsch, context, best);
                   4714:          else
                   4715:            TtaSetStylePresentation (PRForeground, element, tsch, context,best);
                   4716:        }
1.327     vatton   4717:     }
                   4718:   return (cssRule);
1.1       cvs      4719: }
                   4720: 
                   4721: /*----------------------------------------------------------------------
1.59      cvs      4722:   ParseCSSBackgroundColor: parse a CSS background color attribute 
1.1       cvs      4723:   ----------------------------------------------------------------------*/
1.79      cvs      4724: static char *ParseCSSBackgroundColor (Element element, PSchema tsch,
1.327     vatton   4725:                                       PresentationContext context,
                   4726:                                       char *cssRule,
                   4727:                                       CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      4728: {
                   4729:   PresentationValue     best;
1.366     vatton   4730:   char                 *ptr;
1.1       cvs      4731: 
1.370     vatton   4732:   best.typed_data.real = FALSE;
1.366     vatton   4733:   cssRule = SkipBlanksAndComments (cssRule);
                   4734:   ptr = cssRule;
1.184     vatton   4735:   best.typed_data.unit = UNIT_INVALID;
1.1       cvs      4736:   best.typed_data.real = FALSE;
1.198     vatton   4737:   if (!strncasecmp (cssRule, "transparent", 11))
1.1       cvs      4738:     {
1.184     vatton   4739:       best.typed_data.value = PATTERN_NONE;
                   4740:       best.typed_data.unit = UNIT_REL;
1.295     vatton   4741:       cssRule = SkipWord (cssRule);
1.116     vatton   4742:       if (DoApply)
1.327     vatton   4743:         TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
                   4744:     }
1.1       cvs      4745:   else
                   4746:     {
                   4747:       cssRule = ParseCSSColor (cssRule, &best);
1.366     vatton   4748:       if (best.typed_data.unit != UNIT_INVALID)
1.327     vatton   4749:         {
1.366     vatton   4750:           if (DoDialog)
                   4751:             DisplayStyleValue ("background-color", ptr, cssRule);
                   4752:           else if (DoApply)
                   4753:             {
                   4754:               /* install the new presentation. */
                   4755:               TtaSetStylePresentation (PRBackground, element, tsch, context, best);
                   4756:               /* thot specificity: need to set fill pattern for background color */
                   4757:               best.typed_data.value = PATTERN_BACKGROUND;
                   4758:               best.typed_data.unit = UNIT_REL;
                   4759:               TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
                   4760:               best.typed_data.value = 1;
                   4761:               best.typed_data.unit = UNIT_REL;
                   4762:               TtaSetStylePresentation (PRShowBox, element, tsch, context, best);
                   4763:             }
1.327     vatton   4764:         }
1.1       cvs      4765:     }
                   4766:   return (cssRule);
                   4767: }
                   4768: 
1.63      cvs      4769: /*----------------------------------------------------------------------
1.65      cvs      4770:   ParseSVGStroke: parse a SVG stroke property
                   4771:   ----------------------------------------------------------------------*/
1.79      cvs      4772: static char *ParseSVGStroke (Element element, PSchema tsch,
1.327     vatton   4773:                              PresentationContext context, char *cssRule,
                   4774:                              CSSInfoPtr css, ThotBool isHTML)
1.65      cvs      4775: {
1.428     quint    4776:   PresentationValue     best, color;
1.245     quint    4777:   char                  *url;
1.65      cvs      4778: 
1.184     vatton   4779:   best.typed_data.unit = UNIT_INVALID;
1.65      cvs      4780:   best.typed_data.real = FALSE;
1.82      cvs      4781:   if (!strncasecmp (cssRule, "none", 4))
1.65      cvs      4782:     {
                   4783:       best.typed_data.value = -2;  /* -2 means transparent */
1.184     vatton   4784:       best.typed_data.unit = UNIT_REL;
1.65      cvs      4785:       cssRule = SkipWord (cssRule);
                   4786:     }
1.425     quint    4787:   else if (!strncasecmp (cssRule, "inherit", 7))
1.245     quint    4788:     {
1.293     quint    4789:       best.typed_data.unit = VALUE_INHERIT;
                   4790:       cssRule = SkipWord (cssRule);
1.245     quint    4791:     }
1.425     quint    4792:   else if (!strncasecmp (cssRule, "currentColor", 12))
                   4793:     {
                   4794:       best.typed_data.unit = VALUE_CURRENT;
                   4795:       cssRule = SkipWord (cssRule);
                   4796:     }
1.245     quint    4797:   else if (!strncasecmp (cssRule, "url", 3))
                   4798:     {  
                   4799:       cssRule += 3;
                   4800:       cssRule = ParseCSSUrl (cssRule, &url);
                   4801:       /* **** do something with the url ***** */;
                   4802:       TtaFreeMemory (url);
1.428     quint    4803:       /* a color property may follow the url */
                   4804:       cssRule = SkipBlanksAndComments (cssRule);
                   4805:       if (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS &&
                   4806:          *cssRule != ',')
                   4807:        /* we expect a color property here */
                   4808:        {
                   4809:          cssRule = ParseCSSColor (cssRule, &color);
                   4810:          /* ***** do something with the color we have just parsed */
                   4811:        }
1.245     quint    4812:     }
1.65      cvs      4813:   else
1.293     quint    4814:     cssRule = ParseCSSColor (cssRule, &best);
                   4815: 
                   4816:   if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.295     vatton   4817:     /* install the new presentation */
                   4818:     TtaSetStylePresentation (PRForeground, element, tsch, context, best);
1.65      cvs      4819:   return (cssRule);
                   4820: }
                   4821: 
                   4822: /*----------------------------------------------------------------------
1.63      cvs      4823:   ParseSVGFill: parse a SVG fill property
                   4824:   ----------------------------------------------------------------------*/
1.79      cvs      4825: static char *ParseSVGFill (Element element, PSchema tsch,
1.327     vatton   4826:                            PresentationContext context, char *cssRule,
                   4827:                            CSSInfoPtr css, ThotBool isHTML)
1.63      cvs      4828: {
1.428     quint    4829:   PresentationValue     fill, color;
1.245     quint    4830:   char                  *url;
1.429     quint    4831:   int                   pattern;
1.63      cvs      4832: 
1.426     quint    4833:   url = NULL;
1.428     quint    4834:   fill.typed_data.unit = UNIT_INVALID;
                   4835:   fill.typed_data.real = FALSE;
1.429     quint    4836:   pattern = PATTERN_BACKGROUND;
1.82      cvs      4837:   if (!strncasecmp (cssRule, "none", 4))
1.63      cvs      4838:     {
1.429     quint    4839:       pattern = PATTERN_NONE;
                   4840:       fill.typed_data.value = -2;
1.428     quint    4841:       fill.typed_data.unit = UNIT_REL;
1.65      cvs      4842:       cssRule = SkipWord (cssRule);
1.63      cvs      4843:     }
1.425     quint    4844:   else if (!strncasecmp (cssRule, "currentColor", 12))
                   4845:     {
1.428     quint    4846:       fill.typed_data.unit = VALUE_CURRENT;
1.425     quint    4847:       cssRule = SkipWord (cssRule);
                   4848:     }
1.245     quint    4849:   else if (!strncasecmp (cssRule, "url", 3))
                   4850:     {  
                   4851:       cssRule += 3;
                   4852:       cssRule = ParseCSSUrl (cssRule, &url);
1.428     quint    4853:       fill.typed_data.unit = VALUE_URL;
                   4854:       fill.pointer = url;
                   4855:       /* a color property may follow the url */
                   4856:       cssRule = SkipBlanksAndComments (cssRule);
                   4857:       if (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS &&
                   4858:          *cssRule != ',')
                   4859:        /* we expect a color property here */
                   4860:        {
                   4861:          cssRule = ParseCSSColor (cssRule, &color);
                   4862:          /* @@@@@@ do something with the color we have just parsed */
                   4863:        }
                   4864:     }
                   4865:   else if (!strncasecmp (cssRule, "inherit", 7))
                   4866:     {
                   4867:       fill.typed_data.unit = VALUE_INHERIT;
                   4868:       cssRule = SkipWord (cssRule);
1.245     quint    4869:     }
1.63      cvs      4870:   else
1.428     quint    4871:     cssRule = ParseCSSColor (cssRule, &fill);
1.293     quint    4872: 
1.428     quint    4873:   if (fill.typed_data.unit != UNIT_INVALID && DoApply)
1.63      cvs      4874:     {
1.293     quint    4875:       /* install the new presentation. */
1.428     quint    4876:       TtaSetStylePresentation (PRBackground, element, tsch, context, fill);
1.426     quint    4877:       if (url)
                   4878:        TtaFreeMemory (url);
1.293     quint    4879:       /* thot specificity: need to set fill pattern for background color */
1.429     quint    4880:       fill.typed_data.value = pattern;
1.428     quint    4881:       fill.typed_data.unit = UNIT_REL;
                   4882:       TtaSetStylePresentation (PRFillPattern, element, tsch, context, fill);
1.63      cvs      4883:     }
                   4884:   return (cssRule);
                   4885: }
1.161     quint    4886: 
1.155     cheyroul 4887: /*----------------------------------------------------------------------
1.424     quint    4888:   ParseSVGStopColor: parse a SVG stop-color property
                   4889:   ----------------------------------------------------------------------*/
                   4890: static char *ParseSVGStopColor (Element element, PSchema tsch,
                   4891:                                PresentationContext context, char *cssRule,
                   4892:                                CSSInfoPtr css, ThotBool isHTML)
                   4893: {
1.425     quint    4894:   PresentationValue     best;
                   4895: 
                   4896:   best.typed_data.unit = UNIT_INVALID;
                   4897:   best.typed_data.real = FALSE;
                   4898:   if (!strncasecmp (cssRule, "inherit", 7))
                   4899:     {
                   4900:       best.typed_data.unit = VALUE_INHERIT;
                   4901:       cssRule = SkipWord (cssRule);
                   4902:     }
                   4903:   else if (!strncasecmp (cssRule, "currentColor", 12))
                   4904:     {
                   4905:       best.typed_data.unit = VALUE_CURRENT;
                   4906:       cssRule = SkipWord (cssRule);
                   4907:     }
                   4908:   else
                   4909:     cssRule = ParseCSSColor (cssRule, &best);
                   4910: 
                   4911:   if (best.typed_data.unit != UNIT_INVALID && DoApply)
                   4912:     /* install the new presentation */
                   4913:     TtaSetStylePresentation (PRStopColor, element, tsch, context, best);
                   4914:   return (cssRule);
                   4915: }
                   4916: 
                   4917: /*----------------------------------------------------------------------
1.427     quint    4918:   ParseCSSColor: parse a CSS color attribute string    
                   4919:   we expect the input string describing the attribute to be     
                   4920:   either a color name, a 3 tuple or an hexadecimal encoding.    
                   4921:   The color used will be approximed from the current color      
                   4922:   table                                                         
                   4923:   ----------------------------------------------------------------------*/
1.430     vatton   4924: static char *ParseSVGMarkerValue (char *cssRule, PresentationValue *val, char **url)
1.427     quint    4925: {
1.430     vatton   4926:   *url = NULL;
1.427     quint    4927:   val->typed_data.unit = UNIT_INVALID;
                   4928:   val->typed_data.real = FALSE;
                   4929:   if (!strncasecmp (cssRule, "none", 4))
                   4930:     {
                   4931:       val->typed_data.unit = UNIT_REL;
                   4932:       val->typed_data.value = 0;
                   4933:       cssRule += 4;
                   4934:     }
                   4935:   else if (!strncasecmp (cssRule, "inherit", 7))
                   4936:     {
                   4937:       val->typed_data.unit = VALUE_INHERIT;
                   4938:       cssRule += 7;
                   4939:     }
                   4940:   else if (!strncasecmp (cssRule, "url", 3))
                   4941:     {  
                   4942:       cssRule += 3;
1.430     vatton   4943:       cssRule = ParseCSSUrl (cssRule, url);
1.427     quint    4944:       val->typed_data.unit = VALUE_URL;
1.430     vatton   4945:       val->pointer = *url;
1.427     quint    4946:     }
                   4947:   return cssRule;
                   4948: }
                   4949: 
                   4950: /*----------------------------------------------------------------------
                   4951:   ParseSVGMarker: parse a SVG marker property
                   4952:   ----------------------------------------------------------------------*/
                   4953: static char *ParseSVGMarker (Element element, PSchema tsch,
                   4954:                             PresentationContext context, char *cssRule,
                   4955:                             CSSInfoPtr css, ThotBool isHTML)
                   4956: {
                   4957:   PresentationValue     marker;
                   4958:   char                  *url;
                   4959: 
                   4960:   url = NULL;
1.430     vatton   4961:   cssRule = ParseSVGMarkerValue (cssRule, &marker, &url);
1.427     quint    4962:   if (marker.typed_data.unit != UNIT_INVALID && DoApply)
                   4963:     /* install the new presentation. */
                   4964:     TtaSetStylePresentation (PRMarker, element, tsch, context, marker);
                   4965:   if (url)
                   4966:     TtaFreeMemory (url);
                   4967:   return (cssRule);
                   4968: }
                   4969: 
                   4970: /*----------------------------------------------------------------------
                   4971:   ParseSVGMarkerEnd: parse a SVG marker-end property
                   4972:   ----------------------------------------------------------------------*/
                   4973: static char *ParseSVGMarkerEnd (Element element, PSchema tsch,
                   4974:                                PresentationContext context, char *cssRule,
                   4975:                                CSSInfoPtr css, ThotBool isHTML)
                   4976: {
                   4977:   PresentationValue     marker;
                   4978:   char                  *url;
                   4979: 
                   4980:   url = NULL;
1.430     vatton   4981:   cssRule = ParseSVGMarkerValue (cssRule, &marker, &url);
1.427     quint    4982:   if (marker.typed_data.unit != UNIT_INVALID && DoApply)
                   4983:     /* install the new presentation. */
                   4984:     TtaSetStylePresentation (PRMarkerEnd, element, tsch, context, marker);
                   4985:   if (url)
                   4986:     TtaFreeMemory (url);
                   4987:   return (cssRule);
                   4988: }
                   4989: 
                   4990: /*----------------------------------------------------------------------
                   4991:   ParseSVGMarkerMid: parse a SVG marker-mid property
                   4992:   ----------------------------------------------------------------------*/
                   4993: static char *ParseSVGMarkerMid (Element element, PSchema tsch,
                   4994:                                PresentationContext context, char *cssRule,
                   4995:                                CSSInfoPtr css, ThotBool isHTML)
                   4996: {
                   4997:   PresentationValue     marker;
                   4998:   char                  *url;
                   4999: 
                   5000:   url = NULL;
1.430     vatton   5001:   cssRule = ParseSVGMarkerValue (cssRule, &marker, &url);
1.427     quint    5002:   if (marker.typed_data.unit != UNIT_INVALID && DoApply)
                   5003:     /* install the new presentation. */
                   5004:     TtaSetStylePresentation (PRMarkerMid, element, tsch, context, marker);
                   5005:   if (url)
                   5006:     TtaFreeMemory (url);
                   5007:   return (cssRule);
                   5008: }
                   5009: 
                   5010: /*----------------------------------------------------------------------
                   5011:   ParseSVGMarkerStart: parse a SVG marker-start property
                   5012:   ----------------------------------------------------------------------*/
                   5013: static char *ParseSVGMarkerStart (Element element, PSchema tsch,
                   5014:                                  PresentationContext context, char *cssRule,
                   5015:                                  CSSInfoPtr css, ThotBool isHTML)
                   5016: {
                   5017:   PresentationValue     marker;
                   5018:   char                  *url;
                   5019: 
                   5020:   url = NULL;
1.430     vatton   5021:   cssRule = ParseSVGMarkerValue (cssRule, &marker, &url);
1.427     quint    5022:   if (marker.typed_data.unit != UNIT_INVALID && DoApply)
                   5023:     /* install the new presentation. */
                   5024:     TtaSetStylePresentation (PRMarkerStart, element, tsch, context, marker);
                   5025:   if (url)
                   5026:     TtaFreeMemory (url);
                   5027:   return (cssRule);
                   5028: }
                   5029: 
                   5030: /*----------------------------------------------------------------------
1.425     quint    5031:   ParseSVGStopOpacity: parse a SVG opacity property
                   5032:   ----------------------------------------------------------------------*/
                   5033: static char *ParseSVGStopOpacity (Element element, PSchema tsch,
                   5034:                                  PresentationContext context, char *cssRule,
                   5035:                                  CSSInfoPtr css, ThotBool isHTML)
                   5036: {
                   5037:   PresentationValue     opacity;
                   5038: 
                   5039:   opacity.typed_data.unit = UNIT_INVALID;
                   5040:   opacity.typed_data.real = FALSE;
                   5041:   if (!strncasecmp (cssRule, "inherit", 7))
                   5042:     {
                   5043:       opacity.typed_data.unit = VALUE_INHERIT;
                   5044:       cssRule += 7;
                   5045:     }
                   5046:   else
                   5047:     cssRule = ParseClampedUnit (cssRule, &opacity);
                   5048:   if (opacity.typed_data.unit != UNIT_INVALID && DoApply)
                   5049:     /* install the new presentation. */
                   5050:     TtaSetStylePresentation (PRStopOpacity, element, tsch, context, opacity);
1.424     quint    5051:   return (cssRule);
                   5052: }
                   5053: 
                   5054: /*----------------------------------------------------------------------
1.346     quint    5055:   ParseSVGOpacity: parse a SVG opacity property
1.155     cheyroul 5056:   ----------------------------------------------------------------------*/
                   5057: static char *ParseSVGOpacity (Element element, PSchema tsch,
1.327     vatton   5058:                               PresentationContext context, char *cssRule,
                   5059:                               CSSInfoPtr css, ThotBool isHTML)
1.155     cheyroul 5060: {
1.425     quint    5061:   PresentationValue     opacity;
1.63      cvs      5062: 
1.425     quint    5063:   opacity.typed_data.unit = UNIT_INVALID;
                   5064:   opacity.typed_data.real = FALSE;
                   5065:   if (!strncasecmp (cssRule, "inherit", 7))
                   5066:     {
                   5067:       opacity.typed_data.unit = VALUE_INHERIT;
                   5068:       cssRule += 7;
                   5069:     }
                   5070:   else
                   5071:     cssRule = ParseClampedUnit (cssRule, &opacity);
                   5072:   if (opacity.typed_data.unit != UNIT_INVALID && DoApply)
1.295     vatton   5073:     /* install the new presentation. */
1.425     quint    5074:     TtaSetStylePresentation (PROpacity, element, tsch, context, opacity);
1.155     cheyroul 5075:   return (cssRule);
                   5076: }
1.346     quint    5077: 
1.170     cheyroul 5078: /*----------------------------------------------------------------------
1.346     quint    5079:   ParseSVGStrokeOpacity: parse a SVG stroke-opacity property
1.170     cheyroul 5080:   ----------------------------------------------------------------------*/
                   5081: static char *ParseSVGStrokeOpacity (Element element, PSchema tsch,
1.327     vatton   5082:                                     PresentationContext context, char *cssRule,
                   5083:                                     CSSInfoPtr css, ThotBool isHTML)
1.170     cheyroul 5084: {
1.425     quint    5085:   PresentationValue     opacity;
1.161     quint    5086: 
1.425     quint    5087:   opacity.typed_data.unit = UNIT_INVALID;
                   5088:   opacity.typed_data.real = FALSE;
                   5089:   if (!strncasecmp (cssRule, "inherit", 7))
                   5090:     {
                   5091:       opacity.typed_data.unit = VALUE_INHERIT;
                   5092:       cssRule += 7;
                   5093:     }
                   5094:   else
                   5095:     cssRule = ParseClampedUnit (cssRule, &opacity);
                   5096:   if (opacity.typed_data.unit != UNIT_INVALID && DoApply)
1.295     vatton   5097:     /* install the new presentation. */
1.425     quint    5098:     TtaSetStylePresentation (PRStrokeOpacity, element, tsch, context, opacity);
1.170     cheyroul 5099:   return (cssRule);
                   5100: }
1.346     quint    5101: 
1.170     cheyroul 5102: /*----------------------------------------------------------------------
1.420     vatton   5103:   ParseSVGFillOpacity: parse a SVG fill-opacityl property
1.170     cheyroul 5104:   ----------------------------------------------------------------------*/
                   5105: static char *ParseSVGFillOpacity (Element element, PSchema tsch,
1.327     vatton   5106:                                   PresentationContext context, char *cssRule,
                   5107:                                   CSSInfoPtr css, ThotBool isHTML)
1.170     cheyroul 5108: {
1.425     quint    5109:   PresentationValue     opacity;
1.170     cheyroul 5110: 
1.425     quint    5111:   opacity.typed_data.unit = UNIT_INVALID;
                   5112:   opacity.typed_data.real = FALSE;
                   5113:   if (!strncasecmp (cssRule, "inherit", 7))
                   5114:     {
                   5115:       opacity.typed_data.unit = VALUE_INHERIT;
                   5116:       cssRule += 7;
                   5117:     }
                   5118:   else
                   5119:     cssRule = ParseClampedUnit (cssRule, &opacity);
                   5120:   if (opacity.typed_data.unit != UNIT_INVALID && DoApply)
1.295     vatton   5121:     /* install the new presentation. */
1.425     quint    5122:     TtaSetStylePresentation (PRFillOpacity, element, tsch, context, opacity);
1.170     cheyroul 5123:   return (cssRule);
                   5124: }
1.207     vatton   5125: 
1.1       cvs      5126: /*----------------------------------------------------------------------
1.420     vatton   5127:   ParseSVGFillRule: parse a SVG fill-rule property
                   5128:   ----------------------------------------------------------------------*/
                   5129: static char *ParseSVGFillRule (Element element, PSchema tsch,
                   5130:                                PresentationContext context, char *cssRule,
                   5131:                                CSSInfoPtr css, ThotBool isHTML)
                   5132: {
                   5133:   PresentationValue     best;
                   5134: 
                   5135:   best.typed_data.unit = UNIT_INVALID;
                   5136:   best.typed_data.real = FALSE;
                   5137:   if (!strncasecmp (cssRule, "inherit", 7))
                   5138:     {
                   5139:       best.typed_data.unit = VALUE_INHERIT;
                   5140:       best.typed_data.value = 0;
                   5141:       cssRule = SkipWord (cssRule);
                   5142:     }
                   5143:   else if (!strncasecmp (cssRule, "nonzero", 7))
                   5144:     {
                   5145:       best.typed_data.unit = VALUE_AUTO;
1.421     quint    5146:       best.typed_data.value = NonZero;
1.420     vatton   5147:       cssRule = SkipWord (cssRule);
                   5148:     }
                   5149:   else if (!strncasecmp (cssRule, "evenodd", 7))
                   5150:     {
                   5151:       best.typed_data.unit = VALUE_AUTO;
1.421     quint    5152:       best.typed_data.value = EvenOdd;
1.420     vatton   5153:       cssRule = SkipWord (cssRule);
                   5154:     }
                   5155: 
                   5156:   if (DoApply)
                   5157:     /* install the new presentation. */
                   5158:     TtaSetStylePresentation (PRFillRule, element, tsch, context, best);
                   5159:   return (cssRule);
                   5160: }
                   5161: 
                   5162: /*----------------------------------------------------------------------
1.327     vatton   5163:   GetCSSBackgroundURL searches a CSS BackgroundImage url within
                   5164:   the cssRule.
                   5165:   Returns NULL or a new allocated url string.
1.217     vatton   5166:   ----------------------------------------------------------------------*/
                   5167: char *GetCSSBackgroundURL (char *cssRule)
                   5168: {
                   5169:   char            *b, *url;
                   5170: 
                   5171:   url = NULL;
                   5172:   b = strstr (cssRule, "url");
                   5173:   if (b)
1.290     gully    5174:     b = ParseCSSUrl (b, &url);
1.217     vatton   5175:   return (url);
                   5176: }
                   5177: 
                   5178: /*----------------------------------------------------------------------
1.327     vatton   5179:   ParseCSSContent: parse the value of property "content"
1.217     vatton   5180:   ----------------------------------------------------------------------*/
                   5181: static char *ParseCSSContent (Element element, PSchema tsch,
1.327     vatton   5182:                               PresentationContext ctxt, char *cssRule,
                   5183:                               CSSInfoPtr css, ThotBool isHTML)
1.217     vatton   5184: {
1.436     quint    5185:   PresentationValue   value, pval;
1.353     quint    5186:   char                *last, *start, quoteChar, savedChar;
1.437   ! quint    5187:   int                 length, val, l;
1.366     vatton   5188:   char               *buffer, *p;
                   5189:   char               *start_value;
1.434     quint    5190:   wchar_t             wc;
                   5191:   ThotBool            repeat, done;
1.312     quint    5192: 
                   5193:   value.typed_data.unit = UNIT_REL;
                   5194:   value.typed_data.real = FALSE;
                   5195:   value.typed_data.value = 0;
1.366     vatton   5196:   if (!DoDialog && DoApply)
1.347     quint    5197:     TtaSetStylePresentation (PRContent, element, tsch, ctxt, value);
1.217     vatton   5198:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   5199:   start_value = cssRule;
1.312     quint    5200:   repeat = TRUE;
                   5201:   while (repeat)
                   5202:     {
1.366     vatton   5203:       p = cssRule;
1.312     quint    5204:       if (!strncasecmp (cssRule, "normal", 6))
1.327     vatton   5205:         /* The pseudo-element is not generated */
                   5206:         {
                   5207:           /* @@@@@@ */
                   5208:           cssRule += 6;
                   5209:           repeat = FALSE;
                   5210:         }
1.331     quint    5211:       else if (!strncasecmp (cssRule, "none", 4))
                   5212:         /* The pseudo-element is not generated */
                   5213:         {
                   5214:           /* @@@@@@ */
                   5215:           cssRule += 4;
                   5216:           repeat = FALSE;
                   5217:         }
1.312     quint    5218:       else if (*cssRule == '"' || *cssRule == '\'')
1.327     vatton   5219:         /* It's a string */
                   5220:         {
                   5221:           quoteChar = *cssRule;
1.353     quint    5222:           /* how long is the string? */
1.437   ! quint    5223:           last = SkipString (cssRule);
1.353     quint    5224:           length = last - cssRule;
                   5225:           /* get a buffer to store the string */
1.434     quint    5226:           buffer = (char *)TtaGetMemory (3 * length);
1.353     quint    5227:           p = buffer; /* beginning of the string */
1.327     vatton   5228:           cssRule++;
1.437   ! quint    5229: 
        !          5230:           l = TtaGetNextWCFromString (&wc, (unsigned char **) &cssRule, UTF_8);
        !          5231:           while (wc != EOS && wc != quoteChar && l > 0)
1.353     quint    5232:             {
1.434     quint    5233:              done = FALSE;
1.437   ! quint    5234:               if (wc == '\\')
1.353     quint    5235:                 {
                   5236:                   cssRule++; /* skip the backslash */
                   5237:                   if ((*cssRule >= '0' && *cssRule <= '9') ||
                   5238:                       (*cssRule >= 'A' && *cssRule <= 'F') ||
                   5239:                       (*cssRule >= 'a' && *cssRule <= 'f'))
                   5240:                     {
                   5241:                       start = cssRule; /* first hex digit after the backslash*/
                   5242:                       cssRule++;
                   5243:                       while ((*cssRule >= '0' && *cssRule <= '9') ||
                   5244:                              (*cssRule >= 'A' && *cssRule <= 'F') ||
                   5245:                              (*cssRule >= 'a' && *cssRule <= 'f'))
                   5246:                         cssRule++;
                   5247:                       savedChar = *cssRule;
                   5248:                       *cssRule = EOS;
                   5249:                       sscanf (start, "%x", &val);
1.366     vatton   5250:                       TtaWCToMBstring ((wchar_t) val, (unsigned char **) &p);
1.353     quint    5251:                       *cssRule = savedChar;
1.437   ! quint    5252:                      wc = savedChar;
1.434     quint    5253:                      done = TRUE;
1.353     quint    5254:                     }
                   5255:                 }
1.434     quint    5256:               if (!done)
1.353     quint    5257:                 {
1.434     quint    5258:                  TtaWCToMBstring (wc, (unsigned char **) &p);
1.437   ! quint    5259:                   cssRule+= l;
        !          5260:                   l = TtaGetNextWCFromString (&wc, (unsigned char **) &cssRule,
        !          5261:                                              UTF_8);
1.353     quint    5262:                 }
                   5263:             }
                   5264:           *p = EOS;
1.366     vatton   5265:           if (DoDialog)
                   5266:             {
                   5267:               DisplayStyleValue ("", start_value, p);
                   5268:               start_value = p;
                   5269:             }
                   5270:           else if (*cssRule != quoteChar)
1.327     vatton   5271:             cssRule = SkipProperty (cssRule, FALSE);
                   5272:           else
                   5273:             {
                   5274:               *cssRule = EOS;
                   5275:               value.typed_data.unit = UNIT_REL;
                   5276:               value.typed_data.real = FALSE;
1.353     quint    5277:               value.pointer = buffer;
1.347     quint    5278:               if (DoApply)
                   5279:                 TtaSetStylePresentation (PRContentString, element, tsch, ctxt,
                   5280:                                          value);
1.327     vatton   5281:               *cssRule = quoteChar;
                   5282:               cssRule++;
                   5283:             }
1.353     quint    5284:           TtaFreeMemory (buffer);
1.327     vatton   5285:         }
1.312     quint    5286:       else if (!strncasecmp (cssRule, "url", 3))
1.327     vatton   5287:         {  
                   5288:           cssRule += 3;
1.347     quint    5289:           cssRule = SetCSSImage (element, tsch, ctxt, cssRule, css,
                   5290:                                  PRContentURL);
1.366     vatton   5291:           if (DoDialog)
                   5292:             {
                   5293:               DisplayStyleValue ("", start_value, p);
                   5294:               start_value = p;
                   5295:             }
1.327     vatton   5296:         }
1.312     quint    5297:       else if (!strncasecmp (cssRule, "counter", 7))
1.327     vatton   5298:         {
1.436     quint    5299:           value.pointer = NULL;
1.327     vatton   5300:           cssRule += 7;
1.436     quint    5301:          cssRule = SkipBlanksAndComments (cssRule);
                   5302:          if (*cssRule == '(')
                   5303:            {
                   5304:              cssRule++;
                   5305:              cssRule = SkipBlanksAndComments (cssRule);
                   5306:              start = cssRule;
                   5307:              while (*cssRule != EOS && *cssRule != ')' && *cssRule != ',')
                   5308:                cssRule++;
                   5309:              if (*cssRule != ')' && *cssRule != ',')
                   5310:                cssRule = start;
                   5311:              else
                   5312:                {
                   5313:                   /* remove extra spaces */
                   5314:                  last = cssRule;
                   5315:                   while (last[-1] == SPACE || last[-1] == TAB)
                   5316:                    last--;
                   5317:                   savedChar = *last;
                   5318:                   *last = EOS;
                   5319:                   value.pointer = start;
                   5320:                   if (DoDialog)
                   5321:                     {
                   5322:                       DisplayStyleValue ("", start_value, p);
                   5323:                       start_value = p;
                   5324:                     }
                   5325:                   else if (DoApply)
                   5326:                     TtaSetStylePresentation (PRContentCounter, element, tsch,
                   5327:                                              ctxt, value);
                   5328:                   *last = savedChar;
                   5329:                  if (*cssRule == ',')
                   5330:                    /* parse the counter style */
                   5331:                    {
                   5332:                      cssRule++;
                   5333:                      cssRule = ParseCounterStyle (cssRule, &pval, start_value);
                   5334:                      cssRule = SkipBlanksAndComments (cssRule);
                   5335:                      if (*cssRule == ')')
                   5336:                        {
                   5337:                          cssRule++;
                   5338:                          TtaSetStylePresentation (PRContentCounterStyle,
                   5339:                                                   element, tsch, ctxt, pval);
                   5340:                        }
                   5341:                    }
                   5342:                }
                   5343:            }
                   5344:           if (value.pointer == NULL)
1.366     vatton   5345:             {
1.436     quint    5346:               CSSParseError ("Invalid content value", (char*) p, cssRule);
                   5347:               if (DoDialog)
                   5348:                 {
                   5349:                   DisplayStyleValue ("", start_value, p);
                   5350:                   start_value = p;
                   5351:                 }
                   5352:               else
                   5353:                 cssRule = SkipProperty (cssRule, FALSE);
1.366     vatton   5354:             }
1.436     quint    5355:           cssRule++;
1.327     vatton   5356:         }
1.312     quint    5357:       else if (!strncasecmp (cssRule, "counters", 8))
1.327     vatton   5358:         {
                   5359:           cssRule += 8;
                   5360:           /* @@@@@@ */
1.366     vatton   5361:           if (DoDialog)
                   5362:             {
                   5363:               DisplayStyleValue ("", start_value, p);
                   5364:               start_value = p;
                   5365:             }
                   5366:           else
1.436     quint    5367:            {
                   5368:              cssRule = SkipProperty (cssRule, FALSE);
                   5369:            }
1.327     vatton   5370:         }
1.312     quint    5371:       else if (!strncasecmp (cssRule, "attr", 4))
1.327     vatton   5372:         {
1.347     quint    5373:           value.pointer = NULL;
1.327     vatton   5374:           cssRule += 4;
1.347     quint    5375:           cssRule = SkipBlanksAndComments (cssRule);
                   5376:           if (*cssRule == '(')
                   5377:             {
                   5378:               cssRule++;
                   5379:               cssRule = SkipBlanksAndComments (cssRule);
                   5380:               start = cssRule;
                   5381:               while (*cssRule != EOS && *cssRule != ')')
                   5382:                 cssRule++;
                   5383:               if (*cssRule != ')')
                   5384:                 cssRule = start;
                   5385:               else
                   5386:                 {
                   5387:                   last = cssRule;
                   5388:                   /* remove extra spaces */
1.436     quint    5389:                  while (last[-1] == SPACE || last[-1] == TAB)
                   5390:                    last--;
1.347     quint    5391:                   savedChar = *last;
                   5392:                   *last = EOS;
                   5393:                   value.typed_data.unit = UNIT_REL;
                   5394:                   value.typed_data.real = FALSE;
                   5395:                   value.pointer = start;
1.366     vatton   5396:                   if (DoDialog)
                   5397:                     {
                   5398:                       DisplayStyleValue ("", start_value, p);
                   5399:                       start_value = p;
                   5400:                     }
                   5401:                   else if (DoApply)
1.347     quint    5402:                     TtaSetStylePresentation (PRContentAttr, element, tsch,
                   5403:                                              ctxt, value);
                   5404:                   *last = savedChar;
                   5405:                 }
                   5406:             }
                   5407:           if (value.pointer == NULL)
                   5408:             {
1.353     quint    5409:               CSSParseError ("Invalid content value", (char*) p, cssRule);
1.366     vatton   5410:               if (DoDialog)
                   5411:                 {
                   5412:                   DisplayStyleValue ("", start_value, p);
                   5413:                   start_value = p;
                   5414:                 }
                   5415:               else
                   5416:                 cssRule = SkipProperty (cssRule, FALSE);
1.347     quint    5417:             }
                   5418:           cssRule++;
1.327     vatton   5419:         }
1.312     quint    5420:       else if (!strncasecmp (cssRule, "open-quote", 10))
1.327     vatton   5421:         {
                   5422:           cssRule += 10;
                   5423:           /* @@@@@@ */
                   5424:         }
1.312     quint    5425:       else if (!strncasecmp (cssRule, "close-quote", 11))
1.327     vatton   5426:         {
                   5427:           cssRule += 11;
                   5428:           /* @@@@@@ */
                   5429:         }
1.312     quint    5430:       else if (!strncasecmp (cssRule, "no-open-quote", 13))
1.327     vatton   5431:         {
                   5432:           cssRule += 13;
                   5433:           /* @@@@@@ */
                   5434:         }
1.312     quint    5435:       else if (!strncasecmp (cssRule, "no-close-quote", 14))
1.327     vatton   5436:         {
                   5437:           cssRule += 14;
                   5438:           /* @@@@@@ */
                   5439:         }
1.312     quint    5440:       else if (!strncasecmp (cssRule, "inherit", 7))
1.327     vatton   5441:         {
                   5442:           cssRule += 7;
                   5443:           /* @@@@@@ */
                   5444:           repeat = FALSE;
                   5445:         }
1.312     quint    5446:       else
1.327     vatton   5447:         {
1.353     quint    5448:           CSSParseError ("Invalid content value", (char*) p, cssRule);
1.366     vatton   5449:           if (DoDialog)
                   5450:             {
                   5451:               DisplayStyleValue ("", start_value, p);
                   5452:               start_value = p;
                   5453:             }
                   5454:           else
                   5455:             cssRule = SkipProperty (cssRule, FALSE);
1.327     vatton   5456:         }
1.312     quint    5457:       cssRule = SkipBlanksAndComments (cssRule);
                   5458:       if (repeat)
1.327     vatton   5459:         if (*cssRule == ';' || *cssRule == '}' || *cssRule == EOS ||
                   5460:             *cssRule == '!')
                   5461:           repeat = FALSE;
1.217     vatton   5462:     }
                   5463:   return (cssRule);
                   5464: }
1.1       cvs      5465: 
                   5466: /*----------------------------------------------------------------------
1.436     quint    5467:   ParseCSSCounterOp: parse a CSS counter operation (increment or reset,
                   5468:   depending on type).
                   5469:   ----------------------------------------------------------------------*/
                   5470: static char *ParseCSSCounterOp (Element element, PSchema tsch,
                   5471:                                PresentationContext ctxt,
                   5472:                                char *cssRule, unsigned int type)
                   5473: {
                   5474:   PresentationValue  pval;
                   5475:   char              *start, *start_value, *p, *buff;
                   5476:   char               saved;
                   5477: 
                   5478:   cssRule = SkipBlanksAndComments (cssRule);
                   5479:   if (!strncasecmp (cssRule, "inherit", 7))
                   5480:     {
                   5481:       pval.typed_data.unit = VALUE_INHERIT;
                   5482:       cssRule += 7;
                   5483:       /* @@@@ do something */
                   5484:     }
                   5485:   else if (!strncasecmp (cssRule, "none", 4))
                   5486:     {
                   5487:       pval.typed_data.value = 0;
                   5488:       cssRule += 4;
                   5489:       /* @@@@ do something */
                   5490:     }
                   5491:   else
                   5492:     {
                   5493:       start_value = cssRule;
                   5494:       /* there may be multiple counter names (each possibly followed by an
                   5495:         integer)  */
                   5496:       do
                   5497:        {
                   5498:          p = cssRule;
                   5499:          /* name of a counter */
                   5500:          start = cssRule;
                   5501:          cssRule = SkipWord (cssRule);
                   5502:          saved = *cssRule;
                   5503:          *cssRule = EOS;
                   5504:           buff = TtaStrdup (start);
                   5505:          *cssRule = saved;
                   5506:          pval.pointer = buff;
                   5507:          /* set default value of parameter */
                   5508:          if (type == PRCounterReset)
                   5509:            pval.data = 0;
                   5510:          else if (type == PRCounterIncrement)
                   5511:            pval.data = 1;
                   5512:          /* use the actual value of parameter (integer) if it is specified */
                   5513:          cssRule = ParseNumber (cssRule, &pval);
                   5514:          if (pval.typed_data.unit != UNIT_INVALID)
                   5515:            /* there is an integer, the value of the parameter */
                   5516:            {
                   5517:              pval.data = pval.typed_data.value;
                   5518:              cssRule = SkipBlanksAndComments (cssRule);
                   5519:            }
                   5520:          if (DoDialog)
                   5521:            {
                   5522:              DisplayStyleValue ("", start_value, p);
                   5523:              start_value = p;
                   5524:            }
                   5525:          else if (DoApply)
                   5526:            TtaSetStylePresentation (type, element, tsch, ctxt, pval);
                   5527:           TtaFreeMemory (buff);
                   5528:        }
                   5529:       while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS &&
                   5530:             *cssRule != ',');
                   5531:     }
                   5532:   cssRule = SkipBlanksAndComments (cssRule);
                   5533:   return (cssRule);
                   5534: }
                   5535: 
                   5536: /*----------------------------------------------------------------------
                   5537:   ParseCSSCounterIncrement: parse a CSS counter-increment property
                   5538:   ----------------------------------------------------------------------*/
                   5539: static char *ParseCSSCounterIncrement (Element element, PSchema tsch,
                   5540:                                       PresentationContext ctxt,
                   5541:                                       char *cssRule, CSSInfoPtr css,
                   5542:                                       ThotBool isHTML)
                   5543: {
                   5544:   return ParseCSSCounterOp (element, tsch, ctxt, cssRule, PRCounterIncrement);
                   5545: }
                   5546: 
                   5547: /*----------------------------------------------------------------------
                   5548:   ParseCSSCounterReset: parse a CSS counter-reset property
                   5549:   ----------------------------------------------------------------------*/
                   5550: static char *ParseCSSCounterReset (Element element, PSchema tsch,
                   5551:                                   PresentationContext ctxt,
                   5552:                                   char *cssRule, CSSInfoPtr css,
                   5553:                                   ThotBool isHTML)
                   5554: {
                   5555:   return ParseCSSCounterOp (element, tsch, ctxt, cssRule, PRCounterReset);
                   5556: }
                   5557: 
                   5558: /*----------------------------------------------------------------------
1.59      cvs      5559:   ParseCSSBackgroundImage: parse a CSS BackgroundImage attribute string.
1.1       cvs      5560:   ----------------------------------------------------------------------*/
1.79      cvs      5561: static char *ParseCSSBackgroundImage (Element element, PSchema tsch,
1.327     vatton   5562:                                       PresentationContext ctxt,
                   5563:                                       char *cssRule, CSSInfoPtr css,
                   5564:                                       ThotBool isHTML)
1.1       cvs      5565: {
1.49      cvs      5566:   PresentationValue          image, value;
1.357     quint    5567:   char                       *ptr;
1.148     vatton   5568: 
1.370     vatton   5569:   image.typed_data.real = FALSE;
                   5570:   value.typed_data.real = FALSE;
1.82      cvs      5571:   cssRule = SkipBlanksAndComments (cssRule);
1.357     quint    5572:   ptr = cssRule;
1.161     quint    5573:   if (!strncasecmp (cssRule, "none", 4))
                   5574:     {
1.260     vatton   5575:       cssRule += 4;
1.366     vatton   5576:       if (DoDialog)
                   5577:         DisplayStyleValue ("background-image", ptr, cssRule);
                   5578:       else if (DoApply)
1.327     vatton   5579:         {
                   5580:           /* no background image */
                   5581:           image.pointer = NULL;
                   5582:           TtaSetStylePresentation (PRBackgroundPicture, element, tsch, ctxt,
                   5583:                                    image);
                   5584:         }
1.161     quint    5585:     }
1.357     quint    5586:   else if (!strncasecmp (cssRule, "inherit", 7))
                   5587:     {
                   5588:       value.typed_data.unit = VALUE_INHERIT;
                   5589:       cssRule += 7;
1.366     vatton   5590:       if (DoDialog)
                   5591:         DisplayStyleValue ("background-image", ptr, cssRule);
1.357     quint    5592:     }
1.161     quint    5593:   else if (!strncasecmp (cssRule, "url", 3))
1.1       cvs      5594:     {  
                   5595:       cssRule += 3;
1.302     quint    5596:       cssRule = SetCSSImage (element, tsch, ctxt, cssRule, css,
1.327     vatton   5597:                              PRBackgroundPicture);
1.207     vatton   5598:       if (ctxt->destroy)
1.327     vatton   5599:         if (TtaGetStylePresentation (PRFillPattern, element, tsch, ctxt,
                   5600:                                      &value) < 0)
                   5601:           {
                   5602:             /* there is no FillPattern rule -> remove ShowBox rule */
                   5603:             value.typed_data.value = 1;
                   5604:             value.typed_data.unit = UNIT_REL;
                   5605:             value.typed_data.real = FALSE;
                   5606:             TtaSetStylePresentation (PRShowBox, element, tsch, ctxt, value);
                   5607:           }
1.18      cvs      5608:     }
1.357     quint    5609:   else
                   5610:     {
                   5611:       cssRule = SkipWord (cssRule);
                   5612:       CSSParseError ("Invalid background-image value", ptr, cssRule);
                   5613:       cssRule = SkipProperty (cssRule, FALSE);
                   5614:     }
1.18      cvs      5615:   return (cssRule);
                   5616: }
                   5617: 
                   5618: /*----------------------------------------------------------------------
1.295     vatton   5619:   ParseACSSBackgroundRepeat: parse a CSS BackgroundRepeat attribute string.
1.18      cvs      5620:   ----------------------------------------------------------------------*/
1.295     vatton   5621: static char *ParseACSSBackgroundRepeat (Element element, PSchema tsch,
1.327     vatton   5622:                                         PresentationContext ctxt,
                   5623:                                         char *cssRule, CSSInfoPtr css, ThotBool isHTML)
1.18      cvs      5624: {
                   5625:   PresentationValue   repeat;
1.366     vatton   5626:   char               *start_value;
1.18      cvs      5627: 
1.366     vatton   5628:   cssRule = SkipBlanksAndComments (cssRule);
                   5629:   start_value = cssRule;
1.184     vatton   5630:   repeat.typed_data.value = REALSIZE;
1.191     vatton   5631:   repeat.typed_data.unit = UNIT_BOX;
1.18      cvs      5632:   repeat.typed_data.real = FALSE;
1.82      cvs      5633:   cssRule = SkipBlanksAndComments (cssRule);
                   5634:   if (!strncasecmp (cssRule, "no-repeat", 9))
1.184     vatton   5635:     repeat.typed_data.value = REALSIZE;
1.82      cvs      5636:   else if (!strncasecmp (cssRule, "repeat-y", 8))
1.265     vatton   5637:     repeat.typed_data.value = YREPEAT;
1.82      cvs      5638:   else if (!strncasecmp (cssRule, "repeat-x", 8))
1.265     vatton   5639:     repeat.typed_data.value = XREPEAT;
1.82      cvs      5640:   else if (!strncasecmp (cssRule, "repeat", 6))
1.184     vatton   5641:     repeat.typed_data.value = REPEAT;
1.18      cvs      5642:   else
                   5643:     return (cssRule);
                   5644: 
1.295     vatton   5645:   cssRule = SkipWord (cssRule);
                   5646:   /* check if it's an important rule */
1.366     vatton   5647:   if (DoDialog)
                   5648:     DisplayStyleValue ("background-repeat", start_value, cssRule);
                   5649:   else if (DoApply)
1.295     vatton   5650:     /* install the new presentation */
1.362     quint    5651:     TtaSetStylePresentation (PRBackgroundRepeat, element, tsch, ctxt, repeat);
1.295     vatton   5652:   return (cssRule);
                   5653: }
                   5654: 
                   5655: /*----------------------------------------------------------------------
                   5656:   ParseCSSBackgroundRepeat: parse a CSS BackgroundRepeat attribute string.
                   5657:   ----------------------------------------------------------------------*/
                   5658: static char *ParseCSSBackgroundRepeat (Element element, PSchema tsch,
1.315     gully    5659:                                        PresentationContext ctxt,
                   5660:                                        char *cssRule, CSSInfoPtr css,
                   5661:                                        ThotBool isHTML)
1.295     vatton   5662: {
1.388     carcone  5663: 
                   5664:   char     *ptr;
                   5665: 
                   5666:   ptr = cssRule;
1.295     vatton   5667:   cssRule = ParseACSSBackgroundRepeat (element, tsch, ctxt,
1.315     gully    5668:                                        cssRule, css, isHTML);
1.388     carcone  5669: 
                   5670:   if (ptr == cssRule)
1.117     vatton   5671:     {
1.295     vatton   5672:       cssRule = SkipValue ("Invalid background-repeat value", cssRule);
1.117     vatton   5673:       /* check if it's an important rule */
                   5674:     }
1.295     vatton   5675:   return cssRule;
1.18      cvs      5676: }
                   5677: 
                   5678: /*----------------------------------------------------------------------
1.327     vatton   5679:   ParseACSSBackgroundAttachment: parse a CSS BackgroundAttachment
                   5680:   attribute string.                                          
1.18      cvs      5681:   ----------------------------------------------------------------------*/
1.295     vatton   5682: static char *ParseACSSBackgroundAttachment (Element element, PSchema tsch,
1.327     vatton   5683:                                             PresentationContext ctxt,
                   5684:                                             char *cssRule, CSSInfoPtr css,
                   5685:                                             ThotBool isHTML)
1.18      cvs      5686: {
1.366     vatton   5687:   char               *start_value;
                   5688: 
1.163     quint    5689:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   5690:   start_value = cssRule;
1.163     quint    5691:   if (!strncasecmp (cssRule, "scroll", 6))
1.199     vatton   5692:     {
                   5693:       cssRule = SkipWord (cssRule);
                   5694:     }
1.163     quint    5695:   else if (!strncasecmp (cssRule, "fixed", 5))
1.199     vatton   5696:     {
                   5697:       cssRule = SkipWord (cssRule);
                   5698:     }
1.362     quint    5699:   else if (!strncasecmp (cssRule, "inherit", 7))
                   5700:     {
                   5701:       cssRule = SkipWord (cssRule);
                   5702:     }
1.366     vatton   5703:   if (start_value != cssRule && DoDialog)
                   5704:     DisplayStyleValue ("background-attachment", start_value, cssRule);
1.163     quint    5705:   return (cssRule);
1.1       cvs      5706: }
                   5707: 
                   5708: /*----------------------------------------------------------------------
1.327     vatton   5709:   ParseCSSBackgroundAttachment: parse a CSS BackgroundAttachment
                   5710:   attribute string.                                          
1.295     vatton   5711:   ----------------------------------------------------------------------*/
                   5712: static char *ParseCSSBackgroundAttachment (Element element, PSchema tsch,
1.327     vatton   5713:                                            PresentationContext ctxt,
                   5714:                                            char *cssRule, CSSInfoPtr css,
                   5715:                                            ThotBool isHTML)
1.295     vatton   5716: {
                   5717:   char     *ptr;
                   5718: 
                   5719:   ptr = cssRule;
                   5720:   cssRule = ParseACSSBackgroundAttachment (element, tsch, ctxt,
1.327     vatton   5721:                                            cssRule, css, isHTML);
1.295     vatton   5722:   if (ptr == cssRule)
1.366     vatton   5723:     cssRule = SkipValue ("Invalid background-attachment value", cssRule);
1.295     vatton   5724:   return cssRule;
                   5725: }
                   5726: 
                   5727: /*----------------------------------------------------------------------
1.327     vatton   5728:   ParseACSSBackgroundPosition: parse a CSS BackgroundPosition
                   5729:   attribute string.                                          
1.1       cvs      5730:   ----------------------------------------------------------------------*/
1.279     vatton   5731: static char *ParseACSSBackgroundPosition (Element element, PSchema tsch,
1.327     vatton   5732:                                           PresentationContext ctxt,
                   5733:                                           char *cssRule, CSSInfoPtr css,
1.362     quint    5734:                                           ThotBool isHTML, ThotBool *across)
1.1       cvs      5735: {
1.362     quint    5736:   PresentationValue   val;
                   5737:   char               *ptr;
1.1       cvs      5738: 
1.163     quint    5739:   cssRule = SkipBlanksAndComments (cssRule);
1.362     quint    5740:   ptr = cssRule;
                   5741:   val.typed_data.value = 0;
                   5742:   val.typed_data.real = FALSE;
                   5743:   val.typed_data.unit = UNIT_INVALID;
1.163     quint    5744:   if (!strncasecmp (cssRule, "left", 4))
1.362     quint    5745:     {
                   5746:       val.typed_data.value = 0;
                   5747:       val.typed_data.unit = UNIT_PERCENT;
                   5748:       cssRule += 4;
                   5749:       *across = TRUE;
                   5750:     }
1.163     quint    5751:   else if (!strncasecmp (cssRule, "right", 5))
1.362     quint    5752:     {
                   5753:       val.typed_data.value = 100;
                   5754:       val.typed_data.unit = UNIT_PERCENT;
                   5755:       cssRule += 5;
                   5756:       *across = TRUE;
                   5757:     }
1.163     quint    5758:   else if (!strncasecmp (cssRule, "center", 6))
1.362     quint    5759:     {
                   5760:       val.typed_data.value = 50;
                   5761:       val.typed_data.unit = UNIT_PERCENT;
                   5762:       cssRule += 6;
                   5763:     }
1.163     quint    5764:   else if (!strncasecmp (cssRule, "top", 3))
1.362     quint    5765:     {
                   5766:       val.typed_data.value = 0;
                   5767:       val.typed_data.unit = UNIT_PERCENT;
                   5768:       cssRule += 3;
                   5769:       *across = FALSE;
                   5770:     }
1.163     quint    5771:   else if (!strncasecmp (cssRule, "bottom", 6))
1.191     vatton   5772:     {
1.362     quint    5773:       val.typed_data.value = 100;
                   5774:       val.typed_data.unit = UNIT_PERCENT;
                   5775:       cssRule += 6;
                   5776:       *across = FALSE;
                   5777:     }
                   5778:   else if (!strncasecmp (cssRule, "inherit", 7))
                   5779:     {
                   5780:       val.typed_data.unit = VALUE_INHERIT;
                   5781:       cssRule += 7;
1.191     vatton   5782:     }
1.163     quint    5783:   else
1.362     quint    5784:     /* <length> or <percentage> */
                   5785:     {
                   5786:       cssRule = ParseCSSUnit (cssRule, &val);
                   5787:       if (val.typed_data.unit == UNIT_BOX && val.typed_data.value == 0)
                   5788:         /* 0 with no unit. Accept */
                   5789:         val.typed_data.unit = UNIT_PERCENT;
                   5790:     }
1.163     quint    5791: 
1.366     vatton   5792:   if (val.typed_data.unit != UNIT_INVALID && val.typed_data.unit != UNIT_BOX)
1.362     quint    5793:     {
1.366     vatton   5794:       if (DoDialog)
                   5795:         {
                   5796:           if (val.typed_data.unit == VALUE_INHERIT)
                   5797:             {
                   5798:               DisplayStyleValue ("background-positionH", ptr, cssRule);
                   5799:               DisplayStyleValue ("background-positionV", ptr, cssRule);
                   5800:             }
                   5801:           else if (*across)
                   5802:               DisplayStyleValue ("background-positionH", ptr, cssRule);
                   5803:           else
                   5804:               DisplayStyleValue ("background-positionV", ptr, cssRule);
                   5805:         }
                   5806:       else if (DoApply)
1.362     quint    5807:         /* install the new presentation */
                   5808:         {
                   5809:           if (val.typed_data.unit == VALUE_INHERIT)
                   5810:             /* "inherit" applies to both dimensions */
                   5811:             {
                   5812:               TtaSetStylePresentation (PRBackgroundHorizPos, element, tsch,
                   5813:                                        ctxt, val);
                   5814:               TtaSetStylePresentation (PRBackgroundVertPos, element, tsch,
                   5815:                                        ctxt, val);
                   5816:             }
                   5817:           else if (*across)
                   5818:             TtaSetStylePresentation (PRBackgroundHorizPos, element, tsch,
                   5819:                                      ctxt, val);
                   5820:           else
                   5821:             TtaSetStylePresentation (PRBackgroundVertPos, element, tsch,
                   5822:                                      ctxt, val);
                   5823:         }
                   5824:     }
1.279     vatton   5825:   return (cssRule);
                   5826: }
1.218     vatton   5827: 
1.279     vatton   5828: /*----------------------------------------------------------------------
1.327     vatton   5829:   ParseCSSBackgroundPosition: parse a CSS BackgroundPosition
                   5830:   attribute string.                                          
1.279     vatton   5831:   ----------------------------------------------------------------------*/
                   5832: static char *ParseCSSBackgroundPosition (Element element, PSchema tsch,
1.327     vatton   5833:                                          PresentationContext ctxt,
                   5834:                                          char *cssRule, CSSInfoPtr css,
                   5835:                                          ThotBool isHTML)
1.279     vatton   5836: {
1.295     vatton   5837:   char     *ptr;
1.362     quint    5838:   ThotBool  across;
1.295     vatton   5839: 
                   5840:   ptr = cssRule;
1.362     quint    5841:   across = TRUE;
                   5842:   cssRule = ParseACSSBackgroundPosition (element, tsch, ctxt, cssRule, css,
                   5843:                                          isHTML, &across);
1.295     vatton   5844:   if (ptr == cssRule)
1.360     vatton   5845:     cssRule = SkipValue ("Invalid background-position value", cssRule);
1.362     quint    5846:   else
1.298     vatton   5847:     {
1.362     quint    5848:       cssRule = SkipBlanksAndComments (cssRule);
                   5849:       if (*cssRule !=  ';' && *cssRule !=  '!' && *cssRule != EOS)
                   5850:         {
                   5851:           /* possible second value */
                   5852:           ptr = cssRule;
                   5853:           across = !across;
                   5854:           cssRule = ParseACSSBackgroundPosition (element, tsch, ctxt, cssRule,
                   5855:                                                  css, isHTML, &across);
                   5856:           if (ptr == cssRule)
                   5857:             cssRule = SkipValue ("Invalid background-position value", cssRule);
                   5858:         }
1.298     vatton   5859:     }
1.163     quint    5860:   return (cssRule);
1.18      cvs      5861: }
                   5862: 
                   5863: /*----------------------------------------------------------------------
1.327     vatton   5864:   ParseCSSBackground: parse a CSS background attribute 
1.18      cvs      5865:   ----------------------------------------------------------------------*/
1.79      cvs      5866: static char *ParseCSSBackground (Element element, PSchema tsch,
1.327     vatton   5867:                                  PresentationContext ctxt, char *cssRule,
                   5868:                                  CSSInfoPtr css, ThotBool isHTML)
1.18      cvs      5869: {
1.323     vatton   5870:   char           *ptr;
                   5871:   int             skippedNL;
1.362     quint    5872:   ThotBool        img, repeat, position, attach, color, across;
1.18      cvs      5873: 
1.82      cvs      5874:   cssRule = SkipBlanksAndComments (cssRule);
1.323     vatton   5875:   img = repeat = position = attach = color = FALSE;
1.362     quint    5876:   across = TRUE;
1.301     vatton   5877:   while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.18      cvs      5878:     {
1.71      cvs      5879:       /* perhaps a Background Image */
1.198     vatton   5880:       if (!strncasecmp (cssRule, "url", 3) || !strncasecmp (cssRule, "none", 4))
1.327     vatton   5881:         {
1.334     vatton   5882:           if (!strncasecmp (cssRule, "none", 4))
1.423     vatton   5883:             {
                   5884:               repeat = TRUE;
                   5885:               ParseCSSBackgroundColor (element, tsch, ctxt, "transparent",
                   5886:                                        css, isHTML);
                   5887:             }
1.327     vatton   5888:           cssRule = ParseCSSBackgroundImage (element, tsch, ctxt, cssRule,
                   5889:                                              css, isHTML);
                   5890:           img = TRUE;
                   5891:         }
1.18      cvs      5892:       /* perhaps a Background Attachment */
1.82      cvs      5893:       else if (!strncasecmp (cssRule, "scroll", 6) ||
                   5894:                !strncasecmp (cssRule, "fixed", 5))
1.327     vatton   5895:         {
                   5896:           cssRule = ParseACSSBackgroundAttachment (element, tsch, ctxt,
                   5897:                                                    cssRule, css, isHTML);
1.328     vatton   5898:           attach = repeat = TRUE;
1.327     vatton   5899:         }
1.18      cvs      5900:       /* perhaps a Background Repeat */
1.82      cvs      5901:       else if (!strncasecmp (cssRule, "no-repeat", 9) ||
                   5902:                !strncasecmp (cssRule, "repeat-y", 8)  ||
                   5903:                !strncasecmp (cssRule, "repeat-x", 8)  ||
                   5904:                !strncasecmp (cssRule, "repeat", 6))
1.327     vatton   5905:         {
                   5906:           cssRule = ParseACSSBackgroundRepeat (element, tsch, ctxt,
                   5907:                                                cssRule, css, isHTML);
                   5908:           repeat = TRUE;
                   5909:         }
1.18      cvs      5910:       /* perhaps a Background Position */
1.82      cvs      5911:       else if (!strncasecmp (cssRule, "left", 4)   ||
                   5912:                !strncasecmp (cssRule, "right", 5)  ||
                   5913:                !strncasecmp (cssRule, "center", 6) ||
                   5914:                !strncasecmp (cssRule, "top", 3)    ||
                   5915:                !strncasecmp (cssRule, "bottom", 6) ||
1.279     vatton   5916:                isdigit (*cssRule) || *cssRule == '.' || *cssRule == '-')
1.327     vatton   5917:         {
1.362     quint    5918:           cssRule = ParseACSSBackgroundPosition (element, tsch, ctxt, cssRule,
                   5919:                                                  css, isHTML, &across);
                   5920:           across = !across;
1.328     vatton   5921:           position = repeat = TRUE;
1.327     vatton   5922:         }
1.18      cvs      5923:       /* perhaps a Background Color */
1.323     vatton   5924:       else if (!color)
1.327     vatton   5925:         {
                   5926:           skippedNL = NewLineSkipped;
                   5927:           /* check if the rule has been found */
                   5928:           ptr = cssRule;
                   5929:           cssRule = ParseCSSBackgroundColor (element, tsch, ctxt,
                   5930:                                              cssRule, css, isHTML);
                   5931:           if (ptr == cssRule)
                   5932:             {
                   5933:               NewLineSkipped = skippedNL;
                   5934:               /* rule not found */
                   5935:               cssRule = SkipProperty (cssRule, FALSE);
                   5936:             }
                   5937:           else
                   5938:             color = TRUE;
                   5939:         }
1.328     vatton   5940:       else
1.327     vatton   5941:         cssRule = SkipProperty (cssRule, FALSE);
1.328     vatton   5942: 
1.82      cvs      5943:       cssRule = SkipBlanksAndComments (cssRule);
1.18      cvs      5944:     }
1.328     vatton   5945: 
                   5946:   if (color && !img)
1.405     kia      5947:     ParseCSSBackgroundImage (element, tsch, ctxt, (char*)
                   5948:         "none", css, isHTML);
1.328     vatton   5949:   
                   5950:   if (img && !repeat)
                   5951:     ParseACSSBackgroundRepeat (element, tsch, ctxt,
1.405     kia      5952:         (char*)"repeat", css, isHTML);
1.328     vatton   5953:   if (img && !position)
                   5954:     ParseACSSBackgroundPosition (element, tsch, ctxt,
1.405     kia      5955:         (char*)"0% 0%", css, isHTML, &across);
1.328     vatton   5956:   if (img && !attach)
                   5957:     ParseACSSBackgroundAttachment (element, tsch, ctxt,
1.405     kia      5958:                                    (char*)"scroll", css, isHTML);
1.327     vatton   5959:   return (cssRule);
1.18      cvs      5960: }
                   5961: 
1.59      cvs      5962: /*----------------------------------------------------------------------
1.327     vatton   5963:   ParseCSSPageBreakBefore: parse a CSS page-break-before attribute 
1.59      cvs      5964:   ----------------------------------------------------------------------*/
1.79      cvs      5965: static char *ParseCSSPageBreakBefore (Element element, PSchema tsch,
1.327     vatton   5966:                                       PresentationContext ctxt, char *cssRule,
                   5967:                                       CSSInfoPtr css, ThotBool isHTML)
1.59      cvs      5968: {
                   5969:   PresentationValue   page;
1.366     vatton   5970:   char               *start_value;
1.59      cvs      5971: 
1.184     vatton   5972:   page.typed_data.unit = UNIT_INVALID;
1.59      cvs      5973:   page.typed_data.real = FALSE;
1.82      cvs      5974:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   5975:   start_value = cssRule;
1.82      cvs      5976:   if (!strncasecmp (cssRule, "auto", 4))
1.184     vatton   5977:     page.typed_data.value = PageAuto;
1.82      cvs      5978:   else if (!strncasecmp (cssRule, "always", 6))
1.59      cvs      5979:     {
1.184     vatton   5980:       page.typed_data.unit = UNIT_REL;
                   5981:       page.typed_data.value = PageAlways;
1.59      cvs      5982:     }
1.82      cvs      5983:   else if (!strncasecmp (cssRule, "avoid", 5))
1.59      cvs      5984:     {
1.184     vatton   5985:       page.typed_data.unit = UNIT_REL;
                   5986:       page.typed_data.value = PageAvoid;
1.59      cvs      5987:     }
1.82      cvs      5988:   else if (!strncasecmp (cssRule, "left", 4))
1.59      cvs      5989:     {
1.184     vatton   5990:       page.typed_data.unit = UNIT_REL;
                   5991:       page.typed_data.value = PageLeft;
1.59      cvs      5992:     }
1.82      cvs      5993:   else if (!strncasecmp (cssRule, "right", 5))
1.59      cvs      5994:     {
1.184     vatton   5995:       page.typed_data.unit = UNIT_REL;
                   5996:       page.typed_data.value = PageRight;
1.59      cvs      5997:     }
1.82      cvs      5998:   else if (!strncasecmp (cssRule, "inherit", 7))
1.59      cvs      5999:     {
1.293     quint    6000:       page.typed_data.unit = VALUE_INHERIT;
1.184     vatton   6001:       page.typed_data.value = PageInherit;
1.59      cvs      6002:     }
                   6003:   cssRule = SkipWord (cssRule);
                   6004:   /* install the new presentation */
1.366     vatton   6005:   if ((page.typed_data.unit == UNIT_REL && page.typed_data.value == PageAlways)
                   6006:       || page.typed_data.unit == VALUE_INHERIT)
                   6007:     {
                   6008:       if (DoDialog)
                   6009:         DisplayStyleValue ("page-break-before", start_value, cssRule);
                   6010:       else if (DoApply)
                   6011:         TtaSetStylePresentation (PRPageBefore, element, tsch, ctxt, page);
                   6012:     }
1.59      cvs      6013:   return (cssRule);
                   6014: }
                   6015: 
                   6016: /*----------------------------------------------------------------------
1.327     vatton   6017:   ParseCSSPageBreakAfter: parse a CSS page-break-after attribute 
1.59      cvs      6018:   ----------------------------------------------------------------------*/
1.79      cvs      6019: static char *ParseCSSPageBreakAfter (Element element, PSchema tsch,
1.327     vatton   6020:                                      PresentationContext ctxt,
                   6021:                                      char *cssRule, CSSInfoPtr css,
                   6022:                                      ThotBool isHTML)
1.59      cvs      6023: {
                   6024:   PresentationValue   page;
1.366     vatton   6025:   char               *start_value;
1.59      cvs      6026: 
1.184     vatton   6027:   page.typed_data.unit = UNIT_INVALID;
1.59      cvs      6028:   page.typed_data.real = FALSE;
1.82      cvs      6029:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   6030:   start_value = cssRule;
1.82      cvs      6031:   if (!strncasecmp (cssRule, "auto", 4))
1.184     vatton   6032:     page.typed_data.value = PageAuto;
1.82      cvs      6033:   else if (!strncasecmp (cssRule, "always", 6))
1.59      cvs      6034:     {
1.184     vatton   6035:       page.typed_data.unit = UNIT_REL;
                   6036:       page.typed_data.value = PageAlways;
1.59      cvs      6037:     }
1.82      cvs      6038:   else if (!strncasecmp (cssRule, "avoid", 5))
1.59      cvs      6039:     {
1.184     vatton   6040:       page.typed_data.unit = UNIT_REL;
                   6041:       page.typed_data.value = PageAvoid;
1.59      cvs      6042:     }
1.82      cvs      6043:   else if (!strncasecmp (cssRule, "left", 4))
1.59      cvs      6044:     {
1.184     vatton   6045:       page.typed_data.unit = UNIT_REL;
                   6046:       page.typed_data.value = PageLeft;
1.59      cvs      6047:     }
1.82      cvs      6048:   else if (!strncasecmp (cssRule, "right", 5))
1.59      cvs      6049:     {
1.184     vatton   6050:       page.typed_data.unit = UNIT_REL;
                   6051:       page.typed_data.value = PageRight;
1.59      cvs      6052:     }
1.82      cvs      6053:   else if (!strncasecmp (cssRule, "inherit", 7))
1.59      cvs      6054:     {
1.293     quint    6055:       page.typed_data.unit = VALUE_INHERIT;
1.184     vatton   6056:       page.typed_data.value = PageInherit;
1.59      cvs      6057:     }
                   6058:   cssRule = SkipWord (cssRule);
                   6059:   /* install the new presentation */
1.366     vatton   6060:   if (page.typed_data.unit == UNIT_REL || page.typed_data.unit == VALUE_INHERIT)
                   6061:     {
                   6062:       if (DoDialog)
                   6063:         DisplayStyleValue ("page-break-after", start_value, cssRule);
1.367     cvs      6064:       //else if (DoApply)
                   6065:         // TtaSetStylePresentation (PRPageAfter, element, tsch, ctxt, page);
1.366     vatton   6066:     }
1.59      cvs      6067:   return (cssRule);
                   6068: }
                   6069: 
                   6070: /*----------------------------------------------------------------------
1.327     vatton   6071:   ParseCSSPageBreakInside: parse a CSS page-break-inside attribute 
1.59      cvs      6072:   ----------------------------------------------------------------------*/
1.79      cvs      6073: static char *ParseCSSPageBreakInside (Element element, PSchema tsch,
1.327     vatton   6074:                                       PresentationContext ctxt,
                   6075:                                       char *cssRule, CSSInfoPtr css,
                   6076:                                       ThotBool isHTML)
1.59      cvs      6077: {
                   6078:   PresentationValue   page;
1.366     vatton   6079:   char               *start_value;
1.59      cvs      6080: 
1.184     vatton   6081:   page.typed_data.unit = UNIT_INVALID;
1.59      cvs      6082:   page.typed_data.real = FALSE;
1.82      cvs      6083:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   6084:   start_value = cssRule;
1.82      cvs      6085:   if (!strncasecmp (cssRule, "auto", 4))
1.59      cvs      6086:     {
1.184     vatton   6087:       /*page.typed_data.unit = UNIT_REL;*/
                   6088:       page.typed_data.value = PageAuto;
1.59      cvs      6089:     }
1.82      cvs      6090:   else if (!strncasecmp (cssRule, "avoid", 5))
1.59      cvs      6091:     {
1.184     vatton   6092:       page.typed_data.unit = UNIT_REL;
                   6093:       page.typed_data.value = PageAvoid;
1.59      cvs      6094:     }
1.82      cvs      6095:   else if (!strncasecmp (cssRule, "inherit", 7))
1.59      cvs      6096:     {
1.293     quint    6097:       /* page.typed_data.unit = VALUE_INHERIT; */
1.184     vatton   6098:       page.typed_data.value = PageInherit;
1.59      cvs      6099:     }
                   6100:   cssRule = SkipWord (cssRule);
                   6101:   /* install the new presentation */
1.366     vatton   6102:   if ((page.typed_data.unit == UNIT_REL || page.typed_data.unit == VALUE_INHERIT) &&
                   6103:       page.typed_data.value == PageAvoid)
                   6104:     {
                   6105:       if (DoDialog)
                   6106:         DisplayStyleValue ("page-break-inside", start_value, cssRule);
1.367     cvs      6107:       //else if (DoApply)
                   6108:         //TtaSetStylePresentation (PRPageInside, element, tsch, ctxt, page);
1.366     vatton   6109:     }
1.59      cvs      6110:   return (cssRule);
                   6111: }
1.18      cvs      6112: 
1.60      cvs      6113: /*----------------------------------------------------------------------
1.327     vatton   6114:   ParseSVGStrokeWidth: parse a SVG stroke-width property value.
1.60      cvs      6115:   ----------------------------------------------------------------------*/
1.79      cvs      6116: static char *ParseSVGStrokeWidth (Element element, PSchema tsch,
1.327     vatton   6117:                                   PresentationContext ctxt, char *cssRule,
                   6118:                                   CSSInfoPtr css, ThotBool isHTML)
1.60      cvs      6119: {
                   6120:   PresentationValue   width;
                   6121:   
1.82      cvs      6122:   cssRule = SkipBlanksAndComments (cssRule);
1.60      cvs      6123:   width.typed_data.value = 0;
1.184     vatton   6124:   width.typed_data.unit = UNIT_INVALID;
1.60      cvs      6125:   width.typed_data.real = FALSE;
1.110     vatton   6126:   if (isdigit (*cssRule) || *cssRule == '.')
1.166     vatton   6127:     {
1.327     vatton   6128:       cssRule = ParseCSSUnit (cssRule, &width);
                   6129:       if (width.typed_data.unit == UNIT_BOX)
                   6130:         width.typed_data.unit = UNIT_PX;
1.166     vatton   6131:     }
1.295     vatton   6132:   else
                   6133:     cssRule = SkipValue ("Invalid stroke-width value", cssRule);
                   6134: 
1.184     vatton   6135:   if (width.typed_data.unit != UNIT_INVALID && DoApply)
1.117     vatton   6136:     {
1.207     vatton   6137:       TtaSetStylePresentation (PRLineWeight, element, tsch, ctxt, width);
1.117     vatton   6138:       width.typed_data.value = 1;
1.184     vatton   6139:       width.typed_data.unit = UNIT_REL;
1.117     vatton   6140:     }
1.60      cvs      6141:   return (cssRule);
                   6142: }
                   6143: 
1.217     vatton   6144: /*----------------------------------------------------------------------
1.327     vatton   6145:   ParseCSSPosition: parse a CSS Position attribute string.
1.217     vatton   6146:   ----------------------------------------------------------------------*/
                   6147: static char *ParseCSSPosition (Element element, PSchema tsch,
1.327     vatton   6148:                                PresentationContext ctxt, char *cssRule,
                   6149:                                CSSInfoPtr css, ThotBool isHTML)
1.217     vatton   6150: {
1.305     quint    6151:   char               *ptr;
                   6152:   PresentationValue   pval;
1.217     vatton   6153: 
1.305     quint    6154:   pval.typed_data.value = 0;
                   6155:   pval.typed_data.unit = UNIT_BOX;
                   6156:   pval.typed_data.real = FALSE;
1.217     vatton   6157:   cssRule = SkipBlanksAndComments (cssRule);
                   6158:   ptr = cssRule;
                   6159:   if (!strncasecmp (cssRule, "static", 6))
1.337     vatton   6160:     {
                   6161:       pval.typed_data.value = PositionStatic;
                   6162:       cssRule += 6;
                   6163:     }
                   6164:   else if (!strncasecmp (cssRule, "relative", 8))
                   6165:     {
                   6166:       pval.typed_data.value = PositionRelative;
                   6167:       cssRule += 8;
                   6168:     }
1.217     vatton   6169:   else if (!strncasecmp (cssRule, "absolute", 8))
1.337     vatton   6170:     {
                   6171:       pval.typed_data.value = PositionAbsolute;
                   6172:       cssRule += 8;
                   6173:     }
1.217     vatton   6174:   else if (!strncasecmp (cssRule, "fixed", 5))
1.337     vatton   6175:     {
                   6176:       pval.typed_data.value = PositionFixed;
                   6177:       cssRule += 5;
                   6178:     }
1.217     vatton   6179:   else if (!strncasecmp (cssRule, "inherit", 7))
1.337     vatton   6180:     {
                   6181:       pval.typed_data.unit = VALUE_INHERIT;
                   6182:       cssRule += 7;
                   6183:     }
1.305     quint    6184: 
                   6185:   if (pval.typed_data.value == 0 && pval.typed_data.unit != VALUE_INHERIT)
                   6186:     {
                   6187:       cssRule = SkipValue ("Invalid position value", ptr);
                   6188:       cssRule = SkipValue (NULL, cssRule);
                   6189:     }
1.217     vatton   6190:   else
1.305     quint    6191:     {
1.337     vatton   6192:       cssRule = SkipBlanksAndComments (cssRule);
                   6193:       if (*cssRule != EOS && *cssRule != ';')
                   6194:         SkipValue ("Invalid position value", ptr);
1.366     vatton   6195:       else if (DoDialog)
                   6196:         DisplayStyleValue ("position", ptr, cssRule);
1.337     vatton   6197:       else if (DoApply)
1.327     vatton   6198:         TtaSetStylePresentation (PRPosition, element, tsch, ctxt, pval);
1.305     quint    6199:     }
1.217     vatton   6200:   return (cssRule);
                   6201: }
                   6202: 
                   6203: /*----------------------------------------------------------------------
1.327     vatton   6204:   ParseCSSTop: parse a CSS Top attribute
1.217     vatton   6205:   ----------------------------------------------------------------------*/
                   6206: static char *ParseCSSTop (Element element, PSchema tsch,
1.327     vatton   6207:                           PresentationContext context, char *cssRule,
                   6208:                           CSSInfoPtr css, ThotBool isHTML)
1.217     vatton   6209: {
                   6210:   PresentationValue   val;
                   6211:   char               *ptr;
                   6212: 
1.370     vatton   6213:   val.typed_data.real = FALSE;
1.217     vatton   6214:   cssRule = SkipBlanksAndComments (cssRule);
                   6215:   ptr = cssRule;
1.305     quint    6216:   /* first parse the value */
                   6217:   if (!strncasecmp (cssRule, "auto", 4))
1.217     vatton   6218:     {
                   6219:       val.typed_data.unit = VALUE_AUTO;
                   6220:       val.typed_data.value = 0;
                   6221:       cssRule = SkipWord (cssRule);
                   6222:     }
1.305     quint    6223:   else if (!strncasecmp (cssRule, "inherit", 7))
                   6224:     {
                   6225:       val.typed_data.unit = VALUE_INHERIT;
                   6226:       cssRule = SkipWord (cssRule);
                   6227:     }
1.217     vatton   6228:   else
                   6229:     cssRule = ParseCSSUnit (cssRule, &val);
1.387     quint    6230: 
                   6231:   if (val.typed_data.unit == UNIT_INVALID ||
                   6232:       (val.typed_data.value != 0 &&
1.217     vatton   6233:        val.typed_data.unit == UNIT_BOX))
                   6234:     {
1.387     quint    6235:       cssRule = SkipValue ("Invalid top value", ptr);
                   6236:       if (val.typed_data.unit == UNIT_BOX)
                   6237:         val.typed_data.unit = UNIT_PX;
                   6238:       else
                   6239:         return (cssRule);
1.217     vatton   6240:     }
1.366     vatton   6241:   if (DoDialog)
1.387     quint    6242:     DisplayStyleValue ("top", ptr, cssRule);
1.366     vatton   6243:   else if (DoApply)
1.305     quint    6244:     TtaSetStylePresentation (PRTop, element, tsch, context, val);
1.217     vatton   6245:   return (cssRule);
                   6246: }
                   6247: 
                   6248: /*----------------------------------------------------------------------
1.327     vatton   6249:   ParseCSSRight: parse a CSS Right attribute
1.217     vatton   6250:   ----------------------------------------------------------------------*/
                   6251: static char *ParseCSSRight (Element element, PSchema tsch,
1.327     vatton   6252:                             PresentationContext context, char *cssRule,
                   6253:                             CSSInfoPtr css, ThotBool isHTML)
1.217     vatton   6254: {
                   6255:   PresentationValue   val;
                   6256:   char               *ptr;
                   6257: 
1.370     vatton   6258:   val.typed_data.real = FALSE;
1.217     vatton   6259:   cssRule = SkipBlanksAndComments (cssRule);
                   6260:   ptr = cssRule;
                   6261:   /* first parse the attribute string */
1.305     quint    6262:   if (!strncasecmp (cssRule, "auto", 4))
1.217     vatton   6263:     {
                   6264:       val.typed_data.unit = VALUE_AUTO;
                   6265:       val.typed_data.value = 0;
                   6266:       cssRule = SkipWord (cssRule);
                   6267:     }
1.305     quint    6268:   else if (!strncasecmp (cssRule, "inherit", 7))
                   6269:     {
                   6270:       val.typed_data.unit = VALUE_INHERIT;
                   6271:       cssRule = SkipWord (cssRule);
                   6272:     }
1.217     vatton   6273:   else
                   6274:     cssRule = ParseCSSUnit (cssRule, &val);
1.387     quint    6275: 
                   6276:   if (val.typed_data.unit == UNIT_INVALID ||
                   6277:       (val.typed_data.value != 0 &&
1.217     vatton   6278:        val.typed_data.unit == UNIT_BOX))
                   6279:     {
1.387     quint    6280:       cssRule = SkipValue ("Invalid right value", ptr);
                   6281:       if (val.typed_data.unit == UNIT_BOX)
                   6282:         val.typed_data.unit = UNIT_PX;
                   6283:       else
                   6284:         return (cssRule);
1.217     vatton   6285:     }
1.366     vatton   6286:   if (DoDialog)
                   6287:         DisplayStyleValue ("right", ptr, cssRule);
                   6288:   else if (DoApply)
1.305     quint    6289:     TtaSetStylePresentation (PRRight, element, tsch, context, val);
1.217     vatton   6290:   return (cssRule);
                   6291: }
                   6292: 
                   6293: /*----------------------------------------------------------------------
1.327     vatton   6294:   ParseCSSBottom: parse a CSS Bottom attribute
1.217     vatton   6295:   ----------------------------------------------------------------------*/
                   6296: static char *ParseCSSBottom (Element element, PSchema tsch,
1.327     vatton   6297:                              PresentationContext context, char *cssRule,
                   6298:                              CSSInfoPtr css, ThotBool isHTML)
1.217     vatton   6299: {
                   6300:   PresentationValue   val;
                   6301:   char               *ptr;
                   6302: 
1.370     vatton   6303:   val.typed_data.real = FALSE;
1.217     vatton   6304:   cssRule = SkipBlanksAndComments (cssRule);
                   6305:   ptr = cssRule;
                   6306:   /* first parse the attribute string */
1.305     quint    6307:   if (!strncasecmp (cssRule, "auto", 4))
1.217     vatton   6308:     {
                   6309:       val.typed_data.unit = VALUE_AUTO;
                   6310:       val.typed_data.value = 0;
                   6311:       cssRule = SkipWord (cssRule);
                   6312:     }
1.305     quint    6313:   else if (!strncasecmp (cssRule, "inherit", 7))
                   6314:     {
                   6315:       val.typed_data.unit = VALUE_INHERIT;
                   6316:       cssRule = SkipWord (cssRule);
                   6317:     }
1.217     vatton   6318:   else
                   6319:     cssRule = ParseCSSUnit (cssRule, &val);
1.387     quint    6320: 
                   6321:   if (val.typed_data.unit == UNIT_INVALID ||
                   6322:       (val.typed_data.value != 0 &&
1.217     vatton   6323:        val.typed_data.unit == UNIT_BOX))
                   6324:     {
1.387     quint    6325:       cssRule = SkipValue ("Invalid bottom value", ptr);
                   6326:       if (val.typed_data.unit == UNIT_BOX)
                   6327:         val.typed_data.unit = UNIT_PX;
                   6328:       else
                   6329:         return (cssRule);
1.217     vatton   6330:     }
1.366     vatton   6331:   if (DoDialog)
                   6332:         DisplayStyleValue ("bottom", ptr, cssRule);
                   6333:   else if (DoApply)
1.305     quint    6334:     TtaSetStylePresentation (PRBottom, element, tsch, context, val);
1.217     vatton   6335:   return (cssRule);
                   6336: }
                   6337: 
                   6338: /*----------------------------------------------------------------------
1.327     vatton   6339:   ParseCSSLeft: parse a CSS Left attribute
1.217     vatton   6340:   ----------------------------------------------------------------------*/
                   6341: static char *ParseCSSLeft (Element element, PSchema tsch,
1.327     vatton   6342:                            PresentationContext context, char *cssRule,
                   6343:                            CSSInfoPtr css, ThotBool isHTML)
1.217     vatton   6344: {
                   6345:   PresentationValue   val;
                   6346:   char               *ptr;
                   6347: 
1.370     vatton   6348:   val.typed_data.real = FALSE;
1.217     vatton   6349:   cssRule = SkipBlanksAndComments (cssRule);
                   6350:   ptr = cssRule;
                   6351:   /* first parse the attribute string */
1.305     quint    6352:   if (!strncasecmp (cssRule, "auto", 4))
1.217     vatton   6353:     {
                   6354:       val.typed_data.unit = VALUE_AUTO;
                   6355:       val.typed_data.value = 0;
                   6356:       cssRule = SkipWord (cssRule);
                   6357:     }
1.305     quint    6358:   else if (!strncasecmp (cssRule, "inherit", 7))
                   6359:     {
                   6360:       val.typed_data.unit = VALUE_INHERIT;
                   6361:       cssRule = SkipWord (cssRule);
                   6362:     }
1.217     vatton   6363:   else
                   6364:     cssRule = ParseCSSUnit (cssRule, &val);
1.387     quint    6365: 
                   6366:   if (val.typed_data.unit == UNIT_INVALID ||
                   6367:       (val.typed_data.value != 0 &&
1.217     vatton   6368:        val.typed_data.unit == UNIT_BOX))
                   6369:     {
1.387     quint    6370:       cssRule = SkipValue ("Invalid left value", ptr);
                   6371:       if (val.typed_data.unit == UNIT_BOX)
                   6372:         val.typed_data.unit = UNIT_PX;
                   6373:       else
                   6374:         return (cssRule);
1.217     vatton   6375:     }
1.366     vatton   6376:   if (DoDialog)
                   6377:         DisplayStyleValue ("left", ptr, cssRule);
                   6378:   else if (DoApply)
1.305     quint    6379:     TtaSetStylePresentation (PRLeft, element, tsch, context, val);
1.217     vatton   6380:   return (cssRule);
                   6381: }
                   6382: 
                   6383: /*----------------------------------------------------------------------
1.327     vatton   6384:   ParseCSSZIndex: parse a CSS z-index attribute
1.217     vatton   6385:   ----------------------------------------------------------------------*/
                   6386: static char *ParseCSSZIndex (Element element, PSchema tsch,
1.327     vatton   6387:                              PresentationContext context, char *cssRule,
                   6388:                              CSSInfoPtr css, ThotBool isHTML)
1.217     vatton   6389: {
                   6390:   PresentationValue   val;
                   6391:   char               *ptr;
                   6392: 
1.370     vatton   6393:   val.typed_data.real = FALSE;
1.217     vatton   6394:   cssRule = SkipBlanksAndComments (cssRule);
                   6395:   ptr = cssRule;
                   6396:   /* first parse the attribute string */
1.420     vatton   6397:   if (!strncasecmp (cssRule, "auto", 4))
1.217     vatton   6398:     {
                   6399:       val.typed_data.unit = VALUE_AUTO;
                   6400:       val.typed_data.value = 0;
                   6401:       cssRule = SkipWord (cssRule);
                   6402:     }
1.420     vatton   6403:   else if (!strncasecmp (cssRule, "inherit", 7))
                   6404:     {
                   6405:       val.typed_data.unit = VALUE_INHERIT;
                   6406:       val.typed_data.value = 0;
                   6407:       cssRule = SkipWord (cssRule);
                   6408:     }
1.217     vatton   6409:   else
                   6410:     {
                   6411:       cssRule = ParseCSSUnit (cssRule, &val);
                   6412:       if (val.typed_data.unit != UNIT_BOX)
1.327     vatton   6413:         {
1.387     quint    6414:           cssRule = SkipValue ("Invalid z-index value", ptr);
                   6415:           return (cssRule);
1.327     vatton   6416:         }
1.420     vatton   6417:       val.typed_data.value = - val.typed_data.value;
1.217     vatton   6418:     }
1.366     vatton   6419:   if (DoDialog)
1.420     vatton   6420:     DisplayStyleValue ("z-index", ptr, cssRule);
                   6421:   else if (DoApply)
                   6422:     TtaSetStylePresentation (PRDepth, element, tsch, context, val);
1.217     vatton   6423:   return (cssRule);
                   6424: }
                   6425: 
1.340     quint    6426: /*----------------------------------------------------------------------
                   6427:  *
1.436     quint    6428:  *     STYLE PROPERTY DECLARATIONS
1.340     quint    6429:  *
                   6430:  *----------------------------------------------------------------------*/
1.18      cvs      6431: /*
1.436     quint    6432:  * NOTE: Long property names MUST be placed before shortened ones !
                   6433:  *        e.g. "font-size" must be placed before "font"
1.18      cvs      6434:  */
                   6435: static CSSProperty CSSProperties[] =
1.327     vatton   6436:   {
                   6437:     {"background-color", ParseCSSBackgroundColor},
                   6438:     {"background-image", ParseCSSBackgroundImage},
                   6439:     {"background-repeat", ParseCSSBackgroundRepeat},
                   6440:     {"background-attachment", ParseCSSBackgroundAttachment},
                   6441:     {"background-position", ParseCSSBackgroundPosition},
                   6442:     {"background", ParseCSSBackground},
                   6443:     {"border-top-width", ParseCSSBorderTopWidth},
                   6444:     {"border-right-width", ParseCSSBorderRightWidth},
                   6445:     {"border-bottom-width", ParseCSSBorderBottomWidth},
                   6446:     {"border-left-width", ParseCSSBorderLeftWidth},
                   6447:     {"border-width", ParseCSSBorderWidth},
                   6448:     {"border-top-color", ParseCSSBorderColorTop},
                   6449:     {"border-right-color", ParseCSSBorderColorRight},
                   6450:     {"border-bottom-color", ParseCSSBorderColorBottom},
                   6451:     {"border-left-color", ParseCSSBorderColorLeft},
                   6452:     {"border-color", ParseCSSBorderColor},
                   6453:     {"border-top-style", ParseCSSBorderStyleTop},
                   6454:     {"border-right-style", ParseCSSBorderStyleRight},
                   6455:     {"border-bottom-style", ParseCSSBorderStyleBottom},
                   6456:     {"border-left-style", ParseCSSBorderStyleLeft},
                   6457:     {"border-style", ParseCSSBorderStyle},
                   6458:     {"border-top", ParseCSSBorderTop},
                   6459:     {"border-right", ParseCSSBorderRight},
                   6460:     {"border-bottom", ParseCSSBorderBottom},
                   6461:     {"border-left", ParseCSSBorderLeft},
                   6462:     {"border", ParseCSSBorder},
                   6463:     {"bottom", ParseCSSBottom},
                   6464:     {"clear", ParseCSSClear},
                   6465:     {"color", ParseCSSForeground},
                   6466:     {"content", ParseCSSContent},
1.436     quint    6467:     {"counter-increment", ParseCSSCounterIncrement},
                   6468:     {"counter-reset", ParseCSSCounterReset},
1.327     vatton   6469:     {"direction", ParseCSSDirection},
                   6470:     {"display", ParseCSSDisplay},
                   6471:     {"float", ParseCSSFloat},
                   6472:     {"font-family", ParseCSSFontFamily},
                   6473:     {"font-style", ParseCSSFontStyle},
                   6474:     {"font-variant", ParseCSSFontVariant},
                   6475:     {"font-weight", ParseCSSFontWeight},
                   6476:     {"font-size-adjust", ParseCSSFontSizeAdjust},
                   6477:     {"font-size", ParseCSSFontSize},
                   6478:     {"font", ParseCSSFont},
1.382     vatton   6479:     {"max-height", ParseCSSMaxHeight},
                   6480:     {"min-height", ParseCSSMinHeight},
1.327     vatton   6481:     {"height", ParseCSSHeight},
                   6482:     {"left", ParseCSSLeft},
                   6483:     {"letter-spacing", ParseCSSLetterSpacing},
                   6484:     {"line-height", ParseCSSLineHeight},
                   6485:     {"list-style-type", ParseCSSListStyleType},
                   6486:     {"list-style-image", ParseCSSListStyleImage},
                   6487:     {"list-style-position", ParseCSSListStylePosition},
                   6488:     {"list-style", ParseCSSListStyle},
                   6489:     {"margin-bottom", ParseCSSMarginBottom},
                   6490:     {"margin-top", ParseCSSMarginTop},
                   6491:     {"margin-right", ParseCSSMarginRight},
                   6492:     {"margin-left", ParseCSSMarginLeft},
                   6493:     {"margin", ParseCSSMargin},
1.418     quint    6494:     {"opacity", ParseCSSOpacity},
1.327     vatton   6495:     {"padding-top", ParseCSSPaddingTop},
                   6496:     {"padding-right", ParseCSSPaddingRight},
                   6497:     {"padding-bottom", ParseCSSPaddingBottom},
                   6498:     {"padding-left", ParseCSSPaddingLeft},
                   6499:     {"padding", ParseCSSPadding},
                   6500:     {"page-break-before", ParseCSSPageBreakBefore},
                   6501:     {"page-break-after", ParseCSSPageBreakAfter},
                   6502:     {"page-break-inside", ParseCSSPageBreakInside},
                   6503:     {"position", ParseCSSPosition},
                   6504:     {"right", ParseCSSRight},
                   6505:     {"text-align", ParseCSSTextAlign},
                   6506:     {"text-anchor", ParseCSSTextAnchor},
                   6507:     {"text-indent", ParseCSSTextIndent},
                   6508:     {"text-decoration", ParseCSSTextDecoration},
                   6509:     {"text-transform", ParseCSSTextTransform},
                   6510:     {"top", ParseCSSTop},
                   6511:     {"unicode-bidi", ParseCSSUnicodeBidi},
                   6512:     {"vertical-align", ParseCSSVerticalAlign},
                   6513:     {"white-space", ParseCSSWhiteSpace},
1.382     vatton   6514:     {"max-width", ParseCSSMaxWidth},
                   6515:     {"min-width", ParseCSSMinWidth},
1.327     vatton   6516:     {"width", ParseCSSWidth},
1.333     vatton   6517:     {"visibility", ParseCSSVisibility},
1.327     vatton   6518:     {"word-spacing", ParseCSSWordSpacing},
                   6519:     {"z-index", ParseCSSZIndex},
                   6520: 
                   6521:     /* SVG extensions */
                   6522:     {"fill-opacity", ParseSVGFillOpacity},
1.420     vatton   6523:     {"fill-rule", ParseSVGFillRule},
1.327     vatton   6524:     {"fill", ParseSVGFill},
1.427     quint    6525:     {"marker-end", ParseSVGMarkerEnd},
                   6526:     {"marker-mid", ParseSVGMarkerMid},
                   6527:     {"marker-start", ParseSVGMarkerStart},
                   6528:     {"marker", ParseSVGMarker},
1.327     vatton   6529:     {"opacity", ParseSVGOpacity},
1.424     quint    6530:     {"stop-color", ParseSVGStopColor},
1.425     quint    6531:     {"stop-opacity", ParseSVGStopOpacity},
1.327     vatton   6532:     {"stroke-opacity", ParseSVGStrokeOpacity},
                   6533:     {"stroke-width", ParseSVGStrokeWidth},
                   6534:     {"stroke", ParseSVGStroke}
                   6535:   };
1.155     cheyroul 6536: 
1.18      cvs      6537: #define NB_CSSSTYLEATTRIBUTE (sizeof(CSSProperties) / sizeof(CSSProperty))
                   6538: 
                   6539: /*----------------------------------------------------------------------
1.327     vatton   6540:   ParseCSSRule: parse a CSS Style string                        
                   6541:   we expect the input string describing the style to be of the form
                   6542:   property: value [ ; property: value ]* 
                   6543:   but tolerate incorrect or incomplete input                    
1.18      cvs      6544:   ----------------------------------------------------------------------*/
1.366     vatton   6545: void  ParseCSSRule (Element element, PSchema tsch, PresentationContext ctxt,
                   6546:                     char *cssRule, CSSInfoPtr css, ThotBool isHTML)
1.18      cvs      6547: {
1.366     vatton   6548:   DisplayMode         dispMode = DisplayImmediately;
1.312     quint    6549:   char               *p = NULL, *next, *end;
1.214     quint    6550:   char               *valueStart;
1.18      cvs      6551:   int                 lg;
1.34      cvs      6552:   unsigned int        i;
1.76      cvs      6553:   ThotBool            found;
1.18      cvs      6554: 
1.34      cvs      6555:   /* avoid too many redisplay */
1.366     vatton   6556:   if (!DoDialog && ctxt->doc)
                   6557:     {
                   6558:       dispMode = TtaGetDisplayMode (ctxt->doc);
                   6559:       if (dispMode == DisplayImmediately)
                   6560:         TtaSetDisplayMode (ctxt->doc, DeferredDisplay);
                   6561:     }
1.34      cvs      6562: 
1.82      cvs      6563:   while (*cssRule != EOS)
1.18      cvs      6564:     {
1.82      cvs      6565:       cssRule = SkipBlanksAndComments (cssRule);
1.371     vatton   6566:       if (*cssRule == ';' || *cssRule < 0x20 ||
1.372     vatton   6567:           ((unsigned char)*cssRule) == 0xA0)
1.371     vatton   6568:         cssRule++;
                   6569:       else if (*cssRule < 0x41 || *cssRule > 0x7A ||
                   6570:           (*cssRule > 0x5A && *cssRule < 0x61))
1.352     vatton   6571:         {
                   6572:           end = SkipProperty (cssRule, FALSE);
1.385     vatton   6573:           if (cssRule[0] != '-')
                   6574:             CSSParseError ("Invalid property", cssRule, end);
1.352     vatton   6575:           cssRule = end; 
                   6576:         }
1.194     vatton   6577:       else if (*cssRule != EOS)
1.327     vatton   6578:         {
                   6579:           found = FALSE;
                   6580:           /* look for the type of property */
                   6581:           for (i = 0; i < NB_CSSSTYLEATTRIBUTE && !found; i++)
                   6582:             {
                   6583:               lg = strlen (CSSProperties[i].name);
                   6584:               if (!strncasecmp (cssRule, CSSProperties[i].name, lg))
                   6585:                 {
                   6586:                   p = cssRule + lg;
                   6587:                   found = TRUE;
                   6588:                   i--;
                   6589:                 }
                   6590:             }
                   6591: 
1.360     vatton   6592:           // check if it's an important rule
                   6593:           CheckImportantRule (cssRule, ctxt);
1.327     vatton   6594:           if (i < NB_CSSSTYLEATTRIBUTE &&
                   6595:               !strcasecmp (CSSProperties[i].name, "content") &&
                   6596:               ((GenericContext)ctxt)->pseudo != PbBefore &&
                   6597:               ((GenericContext)ctxt)->pseudo != PbAfter)
1.340     quint    6598:             /* property content is allowed only for pseudo-elements :before and
                   6599:                :after */
1.327     vatton   6600:             {
1.352     vatton   6601:               end = SkipProperty (cssRule, FALSE);
1.327     vatton   6602:               CSSParseError ("content is allowed only for pseudo-elements",
                   6603:                              cssRule, end);
1.352     vatton   6604:               cssRule = end;
1.327     vatton   6605:             }
1.352     vatton   6606:           else if (i == NB_CSSSTYLEATTRIBUTE)
1.376     vatton   6607:             cssRule = SkipProperty (cssRule, !ctxt->destroy);
1.327     vatton   6608:           else
                   6609:             {
                   6610:               /* update index and skip the ":" indicator if present */
                   6611:               p = SkipBlanksAndComments (p);
                   6612:               if (*p == ':')
                   6613:                 {
                   6614:                   p++;
                   6615:                   p = SkipBlanksAndComments (p);
                   6616:                   /* try to parse the value associated with this property */
                   6617:                   if (CSSProperties[i].parsing_function != NULL)
                   6618:                     {
                   6619:                       valueStart = p;
                   6620:                       p = CSSProperties[i].parsing_function (element, tsch,
                   6621:                                                              ctxt, p, css, isHTML);
                   6622:                       if (!element && isHTML)
                   6623:                         {
                   6624:                           if  (ctxt->type == HTML_EL_Input)
                   6625:                             /* it's a generic rule for the HTML element input.
                   6626:                                Generate a Thot Pres rule for each kind of
                   6627:                                input element */
                   6628:                             {
                   6629:                               ctxt->type = HTML_EL_Text_Input;
                   6630:                               p = CSSProperties[i].parsing_function (element,
                   6631:                                                                      tsch, ctxt, valueStart, css, isHTML);
                   6632:                               ctxt->type = HTML_EL_Password_Input;
                   6633:                               p = CSSProperties[i].parsing_function (element,
                   6634:                                                                      tsch, ctxt, valueStart, css, isHTML);
                   6635:                               ctxt->type = HTML_EL_File_Input;
                   6636:                               p = CSSProperties[i].parsing_function (element,
                   6637:                                                                      tsch, ctxt, valueStart, css, isHTML);
                   6638:                               ctxt->type = HTML_EL_Checkbox_Input;
                   6639:                               p = CSSProperties[i].parsing_function (element,
                   6640:                                                                      tsch, ctxt, valueStart, css, isHTML);
                   6641:                               ctxt->type = HTML_EL_Radio_Input;
                   6642:                               p = CSSProperties[i].parsing_function (element,
                   6643:                                                                      tsch, ctxt, valueStart, css, isHTML);
                   6644:                               ctxt->type = HTML_EL_Submit_Input;
                   6645:                               p = CSSProperties[i].parsing_function (element,
                   6646:                                                                      tsch, ctxt, valueStart, css, isHTML);
                   6647:                               ctxt->type = HTML_EL_Reset_Input;
                   6648:                               p = CSSProperties[i].parsing_function (element,
                   6649:                                                                      tsch, ctxt, valueStart, css, isHTML);
                   6650:                               ctxt->type = HTML_EL_Button_Input;
                   6651:                               p = CSSProperties[i].parsing_function (element,
                   6652:                                                                      tsch, ctxt, valueStart, css, isHTML);
                   6653:                               ctxt->type = HTML_EL_Input;
                   6654:                             }
                   6655:                           else if (ctxt->type == HTML_EL_ruby)
                   6656:                             /* it's a generic rule for the HTML element ruby.
                   6657:                                Generate a Thot Pres rule for each kind of
                   6658:                                ruby element. */
                   6659:                             {
                   6660:                               ctxt->type = HTML_EL_simple_ruby;
                   6661:                               p = CSSProperties[i].parsing_function (element,
                   6662:                                                                      tsch, ctxt, valueStart, css, isHTML);
                   6663:                               ctxt->type = HTML_EL_complex_ruby;
                   6664:                               p = CSSProperties[i].parsing_function (element,
                   6665:                                                                      tsch, ctxt, valueStart, css, isHTML);
                   6666:                               ctxt->type = HTML_EL_ruby;
                   6667:                             }
                   6668:                         }
                   6669:                       /* update index and skip the ";" separator if present */
                   6670:                       next = SkipBlanksAndComments (p);
                   6671:                       if (*next != EOS && *next != ';')
1.431     quint    6672:                         CSSParseError ("Missing closing ';' after", cssRule, p);
1.327     vatton   6673:                       cssRule = next;
                   6674:                     }
                   6675:                 }
                   6676:               else
                   6677:                 cssRule = SkipProperty (cssRule, TRUE);
                   6678:             }
1.360     vatton   6679:           // skip important markup
                   6680:           cssRule = SkipImportantRule (cssRule);
                   6681: 
1.327     vatton   6682:         }
1.18      cvs      6683:       /* next property */
1.82      cvs      6684:       cssRule = SkipBlanksAndComments (cssRule);
1.89      cvs      6685:       if (*cssRule == '}')
1.327     vatton   6686:         {
                   6687:           cssRule++;
                   6688:           CSSPrintError ("Invalid character", "}");
                   6689:           cssRule = SkipBlanksAndComments (cssRule);
                   6690:         }
1.155     cheyroul 6691:       if (*cssRule == ',' ||
1.327     vatton   6692:           *cssRule == ';')
                   6693:         {
                   6694:           cssRule++;
                   6695:           cssRule = SkipBlanksAndComments (cssRule);
                   6696:         }
1.18      cvs      6697:     }
1.34      cvs      6698: 
                   6699:   /* restore the display mode */
1.366     vatton   6700:   if (!DoDialog && ctxt->doc && dispMode == DisplayImmediately)
1.207     vatton   6701:     TtaSetDisplayMode (ctxt->doc, dispMode);
1.18      cvs      6702: }
1.1       cvs      6703: 
1.111     cvs      6704: /*----------------------------------------------------------------------
1.327     vatton   6705:   ParseHTMLSpecificStyle: parse and apply a CSS Style string.
                   6706:   This function must be called when a specific style is applied to an
                   6707:   element.
                   6708:   The parameter specificity is the specificity of the style, 0 if it is
                   6709:   not really a CSS rule.
1.1       cvs      6710:   ----------------------------------------------------------------------*/
1.79      cvs      6711: void  ParseHTMLSpecificStyle (Element el, char *cssRule, Document doc,
1.377     quint    6712:                              int specificity, ThotBool destroy)
1.1       cvs      6713: {
1.257     vatton   6714:   DisplayMode         dispMode;
1.207     vatton   6715:   PresentationContext ctxt;
                   6716:   ElementType         elType;
1.413     vatton   6717:   char               *buff, *ptr, *end;
1.207     vatton   6718:   ThotBool            isHTML;
1.1       cvs      6719: 
1.207     vatton   6720:   /*  A rule applying to BODY is really meant to address HTML */
                   6721:   elType = TtaGetElementType (el);
1.286     quint    6722:   NewLineSkipped = 0;
1.207     vatton   6723:   /* store the current line for eventually reported errors */
                   6724:   LineNumber = TtaGetElementLineNumber (el);
                   6725:   if (destroy)
                   6726:     /* no reported errors */
                   6727:     ParsedDoc = 0;
                   6728:   else if (ParsedDoc != doc)
                   6729:     {
                   6730:       /* update the context for reported errors */
                   6731:       ParsedDoc = doc;
1.348     vatton   6732:       Error_DocURL = DocumentURLs[doc];
1.207     vatton   6733:     }
                   6734:   isHTML = (strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML") == 0);
                   6735:   /* create the context of the Specific presentation driver */
                   6736:   ctxt = TtaGetSpecificStyleContext (doc);
                   6737:   if (ctxt == NULL)
                   6738:     return;
                   6739:   ctxt->type = elType.ElTypeNum;
                   6740:   ctxt->cssSpecificity = specificity;
1.236     quint    6741:   ctxt->cssLine = LineNumber;
1.207     vatton   6742:   ctxt->destroy = destroy;
                   6743:   /* first use of the context */
                   6744:   ctxt->uses = 1;
1.257     vatton   6745:   /* save the current display mode */
                   6746:   dispMode = TtaGetDisplayMode (doc);
1.207     vatton   6747:   /* Call the parser */
1.366     vatton   6748:   DoDialog = FALSE; // not parsing for CSS dialog
1.406     quint    6749:   /* if it is a property applied to a COL or a COLGROUP element in a HTML table,
                   6750:      associate the property to the corresponding Table_head or cell elements,
                   6751:      depending on the property. */
1.413     vatton   6752:   ptr = strstr (cssRule, "background-color");
                   6753:   if (ptr && isHTML &&
1.406     quint    6754:       (elType.ElTypeNum == HTML_EL_COL || elType.ElTypeNum == HTML_EL_COLGROUP))
1.413     vatton   6755:     {
                   6756:       end = strstr (ptr, ";");
                   6757:       if (end)
                   6758:         {
                   6759:           buff = TtaStrdup (ptr);
                   6760:           end = strstr (buff, ";");
                   6761:           *end = EOS;
                   6762:           ColApplyCSSRule (el, (PresentationContext) ctxt, buff, NULL);
                   6763:           TtaFreeMemory (buff);
                   6764:         }
                   6765:       else
                   6766:         ColApplyCSSRule (el, (PresentationContext) ctxt, ptr, NULL);
                   6767:     }
1.406     quint    6768:   else
                   6769:     ParseCSSRule (el, NULL, ctxt, cssRule, NULL, isHTML);
                   6770: 
1.257     vatton   6771:   /* restore the display mode if necessary */
1.417     vatton   6772:   if (dispMode != NoComputedDisplay)
                   6773:     TtaSetDisplayMode (doc, dispMode);
1.207     vatton   6774:   /* check if the context can be freed */
                   6775:   ctxt->uses -= 1;
                   6776:   if (ctxt->uses == 0)
                   6777:     /* no image loading */
                   6778:     TtaFreeMemory(ctxt);
1.1       cvs      6779: }
                   6780: 
1.366     vatton   6781: 
1.343     vatton   6782: /*----------------------------------------------------------------------
                   6783:   AddClassName adds the class name into the class list of css if it's
                   6784:   not already there.
                   6785:   ----------------------------------------------------------------------*/
                   6786: static void AddClassName (char *name, CSSInfoPtr css)
                   6787: {
1.344     cvs      6788:   int                   l, index, k, length, add;
1.343     vatton   6789:   char          *buf;
                   6790:   ThotBool       found, previous;
                   6791: 
                   6792:   l = strlen (name);
                   6793:   if (l == 0 || css == NULL)
                   6794:     return;
                   6795:   if (css->class_list)
                   6796:     {
                   6797:       buf = css->class_list;
                   6798:       length = strlen (css->class_list);
                   6799:     }
                   6800:   else
                   6801:     {
                   6802:       if (l > 200)
                   6803:         length = l + 1;
                   6804:       else
                   6805:         length = 200;
                   6806:       buf = (char *)TtaGetMemory (length * sizeof (char));
                   6807:       memset (buf, 0, length);
                   6808:       css->class_list = buf;
                   6809:       css->lg_class_list = length;
                   6810:       length = 0;
                   6811:     }
                   6812: 
                   6813:   /* compare that name with all class names already known */
                   6814:   index = 0;
                   6815:   found = FALSE;
                   6816:   previous = FALSE;
                   6817:   while (index < length && !found && !previous)
                   6818:     {
                   6819:       k = 0;
                   6820:       while (k < l && buf[index + k] != EOS && buf[index + k] != SPACE)
                   6821:         {
                   6822:           if (name[k] == buf[index+k])
                   6823:             k++;
                   6824:           else
                   6825:             {
                   6826:               previous = (name[k] < buf[index + k]);
                   6827:               break;
                   6828:             }
                   6829:         }
                   6830:       found = (k == l);
                   6831:       if (!previous)
                   6832:         {
                   6833:           index += k;
                   6834:           while (buf[index] != EOS && buf[index] != SPACE)
                   6835:             index++;
                   6836:           if (buf[index] == SPACE)
                   6837:             index++;
                   6838:         }
                   6839:     }
                   6840:   
                   6841:   if (!found)
                   6842:     /* this class name is not known, append it */
                   6843:     {
                   6844:       l++; /* add a space before */
                   6845:       if (css->lg_class_list <= length + l)
                   6846:         {
                   6847:           // increase the list size
                   6848:           if (l > 200)
                   6849:             add = l + 1;
                   6850:           else
                   6851:             add = 200 ;
                   6852:           buf = (char *)TtaRealloc (buf, css->lg_class_list + (add * sizeof (char)));
                   6853:           if (buf == NULL)
                   6854:             return;
                   6855:           else
                   6856:             {
                   6857:             css->class_list = buf;
                   6858:             memset (&buf[css->lg_class_list], 0, add);
                   6859:             css->lg_class_list += add;
                   6860:             }
                   6861:         }
                   6862: 
                   6863:       if (previous)
                   6864:         {
                   6865:           // move the tail of the current list
                   6866:           for (k = length; k >= index; k--)
                   6867:             buf[k+l] = buf[k];
                   6868:           /* add this new class name at the current position */
                   6869:            strcpy (&buf[index], name);
                   6870:           buf[index + l - 1] = SPACE;
                   6871:         }
                   6872:       else
                   6873:         {
                   6874:           /* add this new class name at the end */
                   6875:           if (index != 0)
                   6876:             buf[index++] = SPACE;
                   6877:           strcpy (&buf[index], name);
                   6878:         }
                   6879:      }
                   6880: }
                   6881: 
1.68      cvs      6882: 
1.1       cvs      6883: /*----------------------------------------------------------------------
1.207     vatton   6884:   ParseGenericSelector: Create a generic context for a given selector
                   6885:   string.
                   6886:   If the selector is made of multiple comma, it parses them one at a time
                   6887:   and return the end of the selector string to be handled or NULL.
1.231     vatton   6888:   The parameter ctxt gives the current style context which will be passed
                   6889:   to Thotlib.
                   6890:   The parameter css points to the current CSS context.
                   6891:   The parameter link points to the link element.
                   6892:   The parameter url gives the URL of the parsed style sheet.
1.1       cvs      6893:   ----------------------------------------------------------------------*/
1.207     vatton   6894: static char *ParseGenericSelector (char *selector, char *cssRule,
1.327     vatton   6895:                                    GenericContext ctxt, Document doc,
                   6896:                                    CSSInfoPtr css, Element link, char *url)
1.79      cvs      6897: {
                   6898:   ElementType        elType;
                   6899:   PSchema            tsch;
1.119     vatton   6900:   AttributeType      attrType;
1.398     vatton   6901:   char              *deb, *cur, *sel, *next, *limit, c;
1.317     vatton   6902:   char              *schemaName, *mappedName, *saveURL;
1.79      cvs      6903:   char              *names[MAX_ANCESTORS];
1.355     quint    6904:   ThotBool           pseudoFirstChild[MAX_ANCESTORS];
1.340     quint    6905:   ElemRel            rel[MAX_ANCESTORS];
                   6906:   char              *attrnames[MAX_ANCESTORS];
                   6907:   int                attrnums[MAX_ANCESTORS];
                   6908:   int                attrlevels[MAX_ANCESTORS];
1.79      cvs      6909:   char              *attrvals[MAX_ANCESTORS];
1.133     vatton   6910:   AttrMatch          attrmatch[MAX_ANCESTORS];
1.340     quint    6911:   int                nbnames, nbattrs;
                   6912:   int                i, j;
1.256     vatton   6913:   int                att, kind;
1.118     vatton   6914:   int                specificity, xmlType;
1.217     vatton   6915:   int                skippedNL;
1.404     vatton   6916:   ThotBool           isHTML, noname, warn;
1.347     quint    6917:   ThotBool           level, quoted, doubleColon;
1.340     quint    6918: #define ATTR_ID 1
                   6919: #define ATTR_CLASS 2
                   6920: #define ATTR_PSEUDO 3
1.1       cvs      6921: 
1.404     vatton   6922:   // check if Amaya should report CSS warnings
                   6923:   TtaGetEnvBoolean ("CSS_WARN", &warn);
1.207     vatton   6924:   sel = ctxt->sel;
1.82      cvs      6925:   sel[0] = EOS;
1.398     vatton   6926:   // get the limit of the string
                   6927:   limit = &sel[MAX_ANCESTORS * 50 -1];
                   6928:   *limit = EOS;
1.117     vatton   6929:   specificity = 0;
1.1       cvs      6930:   for (i = 0; i < MAX_ANCESTORS; i++)
                   6931:     {
1.25      cvs      6932:       names[i] = NULL;
1.355     quint    6933:       pseudoFirstChild[i] = FALSE;
1.340     quint    6934:       rel[i] = RelAncestor;
                   6935:       attrnames[i] = NULL;
                   6936:       attrnums[i] = 0;
                   6937:       attrlevels[i] = 0;
1.25      cvs      6938:       attrvals[i] = NULL;
1.133     vatton   6939:       attrmatch[i] = Txtmatch;
1.25      cvs      6940:       ctxt->name[i] = 0;
1.355     quint    6941:       ctxt->firstChild[i] = FALSE;
1.25      cvs      6942:       ctxt->attrType[i] = 0;
1.129     vatton   6943:       ctxt->attrLevel[i] = 0;
1.25      cvs      6944:       ctxt->attrText[i] = NULL;
1.178     quint    6945:       ctxt->attrMatch[i] = Txtmatch;
1.1       cvs      6946:     }
1.25      cvs      6947:   ctxt->box = 0;
1.312     quint    6948:   ctxt->var = 0;
1.306     quint    6949:   ctxt->pseudo = PbNone;
1.25      cvs      6950:   ctxt->type = 0;
1.366     vatton   6951:   DoDialog = FALSE; // not arsing for CSS dialog
1.114     quint    6952:   /* the specificity of the rule depends on the selector */
                   6953:   ctxt->cssSpecificity = 0;
1.231     vatton   6954:   /* localisation of the CSS rule */
                   6955:   ctxt->cssLine = LineNumber + NewLineSkipped;
                   6956:   ctxt->cssURL = url;
1.240     quint    6957: 
1.286     quint    6958:   skippedNL = NewLineSkipped;
1.82      cvs      6959:   selector = SkipBlanksAndComments (selector);
1.286     quint    6960:   NewLineSkipped = skippedNL;
1.27      cvs      6961:   cur = &sel[0];
1.340     quint    6962:   nbnames = 0;
                   6963:   nbattrs = 0;
1.1       cvs      6964:   while (1)
                   6965:     {
1.85      cvs      6966:       /* point to the following word in sel[] */
1.27      cvs      6967:       deb = cur;
1.25      cvs      6968:       /* copy an item of the selector into sel[] */
1.1       cvs      6969:       /* put one word in the sel buffer */
1.82      cvs      6970:       while (*selector != EOS && *selector != ',' &&
                   6971:              *selector != '.' && *selector != ':' &&
1.118     vatton   6972:              *selector != '#' && *selector != '[' &&
1.250     vatton   6973:              *selector != '>' && *selector != '+' &&
1.398     vatton   6974:              !TtaIsBlank (selector) && cur < limit)
1.327     vatton   6975:         *cur++ = *selector++;
1.82      cvs      6976:       *cur++ = EOS; /* close the first string  in sel[] */
1.380     vatton   6977:       noname = TRUE;
1.82      cvs      6978:       if (deb[0] != EOS)
1.340     quint    6979:         /* the selector starts with an element name */
1.327     vatton   6980:         {
                   6981:           if (deb[0] <= 64 && deb[0] != '*')
                   6982:             {
                   6983:               CSSPrintError ("Invalid element", deb);
1.380     vatton   6984:               names[0] = NULL; /* no element name */
                   6985:               DoApply = FALSE;
1.327     vatton   6986:             }
                   6987:           else
                   6988:             {
1.380     vatton   6989:               noname = FALSE;
1.327     vatton   6990:               names[0] = deb;
                   6991:               if (!strcmp (names[0], "html"))
                   6992:                 /* give a greater priority to the backgoud color of html */
                   6993:                 specificity += 3;
                   6994:               else
                   6995:                 /* selector "*" has specificity zero */
                   6996:                 if (strcmp (names[0], "*"))
                   6997:                   specificity += 1;
                   6998:             }
                   6999:         }
1.25      cvs      7000:       else
1.340     quint    7001:         names[0] = NULL; /* no element name */
1.226     quint    7002: 
1.340     quint    7003:       rel[0] = RelVoid;
1.27      cvs      7004:       /* now names[0] points to the beginning of the parsed item
1.340     quint    7005:          and cur to the next string to be parsed */
1.129     vatton   7006:       while (*selector == '.' || *selector == ':' ||
1.327     vatton   7007:              *selector == '#' || *selector == '[')
                   7008:         {
                   7009:           /* point to the following word in sel[] */
                   7010:           deb = cur;
                   7011:           if (*selector == '.')
1.340     quint    7012:             /* class */
1.327     vatton   7013:             {
                   7014:               selector++;
1.340     quint    7015:               while (*selector != '.' && *selector != ':' &&
                   7016:                      *selector != '#' && *selector != '[' &&
                   7017:                      *selector != EOS && *selector != ',' &&
                   7018:                      *selector != '+' && *selector != '>' &&
1.398     vatton   7019:                      !TtaIsBlank (selector) && cur < limit)
1.327     vatton   7020:                 {
                   7021:                   if (*selector == '\\')
                   7022:                     {
                   7023:                       selector++;
                   7024:                       if (*selector != EOS)
                   7025:                         *cur++ = *selector++;
                   7026:                     }
                   7027:                   else
                   7028:                     *cur++ = *selector++;
                   7029:                 }
                   7030:               /* close the word */
                   7031:               *cur++ = EOS;
1.340     quint    7032:               /* point to the class in sel[] if it's a valid name */
1.327     vatton   7033:               if (deb[0] <= 64)
                   7034:                 {
                   7035:                   CSSPrintError ("Invalid class", deb);
                   7036:                   DoApply = FALSE;
                   7037:                 }
                   7038:               else
                   7039:                 {
1.340     quint    7040:                   /* simulate selector [class ~= "xxx"] */
                   7041:                   nbattrs++;
                   7042:                   if (nbattrs == MAX_ANCESTORS)
                   7043:                     /* abort parsing */
                   7044:                     {
                   7045:                       CSSPrintError ("Selector too long", deb);
                   7046:                       return (selector);
                   7047:                     }
                   7048:                   for (i = nbattrs; i > 0; i--)
                   7049:                     {
                   7050:                       attrnames[i] = attrnames[i - 1];
                   7051:                       attrnums[i] = attrnums[i - 1];
                   7052:                       attrlevels[i] = attrlevels[i - 1];
                   7053:                       attrvals[i] = attrvals[i - 1];
                   7054:                       attrmatch[i] = attrmatch[i - 1];
                   7055:                     }
                   7056:                   attrnames[0] = NULL;
                   7057:                   attrnums[0] = ATTR_CLASS;
                   7058:                   attrlevels[0] = 0;
                   7059:                   attrmatch[0] = Txtword;
                   7060:                   attrvals[0] = deb;
1.327     vatton   7061:                   specificity += 10;
1.343     vatton   7062:                  }
1.327     vatton   7063:             }
                   7064:           else if (*selector == ':')
1.340     quint    7065:             /* pseudo-class or pseudo-element */
1.327     vatton   7066:             {
                   7067:               selector++;
1.347     quint    7068:               doubleColon = FALSE;
                   7069:               if (*selector == ':')
                   7070:                 /* it's a double "::". Probably CSS3 syntax */
                   7071:                 {
                   7072:                   selector++;
                   7073:                   doubleColon = TRUE;
                   7074:                 }
1.340     quint    7075:               while (*selector != '.' && *selector != ':' &&
                   7076:                      *selector != '#' && *selector != '[' &&
                   7077:                      *selector != EOS && *selector != ',' &&
                   7078:                      *selector != '+' && *selector != '>' &&
1.398     vatton   7079:                      !TtaIsBlank (selector) && cur < limit)
1.327     vatton   7080:                 *cur++ = *selector++;
                   7081:               /* close the word */
                   7082:               *cur++ = EOS;
1.340     quint    7083:               /* point to the pseudo-class or pseudo-element in sel[] if it's
                   7084:                  a valid name */
1.355     quint    7085:               if (!strcmp (deb, "first-child"))
                   7086:                 /* first-child pseudo-class */
1.327     vatton   7087:                 {
1.355     quint    7088:                   pseudoFirstChild[0] = TRUE;
                   7089:                   specificity += 10;
1.327     vatton   7090:                 }
1.355     quint    7091:               else if (!strcmp (deb, "link") || !strcmp (deb, "visited"))
                   7092:                 /* link or visited pseudo-classes */
1.327     vatton   7093:                 {
1.355     quint    7094:                   nbattrs++;
                   7095:                   if (nbattrs == MAX_ANCESTORS)
                   7096:                     /* abort parsing */
1.347     quint    7097:                     {
1.355     quint    7098:                       CSSPrintError ("Selector too long", deb);
                   7099:                       return (selector);
1.347     quint    7100:                     }
1.355     quint    7101:                   for (i = nbattrs; i > 0; i--)
1.347     quint    7102:                     {
1.355     quint    7103:                       attrnames[i] = attrnames[i - 1];
                   7104:                       attrnums[i] = attrnums[i - 1];
                   7105:                       attrlevels[i] = attrlevels[i - 1];
                   7106:                       attrvals[i] = attrvals[i - 1];
                   7107:                       attrmatch[i] = attrmatch[i - 1];
1.347     quint    7108:                     }
1.355     quint    7109:                   attrnames[0] = NULL;
                   7110:                   attrnums[0] = ATTR_PSEUDO;
                   7111:                   attrlevels[0] = 0;
                   7112:                   attrmatch[0] = Txtmatch;
                   7113:                   attrvals[0] = deb;
                   7114:                   specificity += 10;
                   7115:                 }
                   7116:               else if (!strcmp (deb, "hover") || !strcmp (deb, "active") ||
                   7117:                        !strcmp (deb, "focus"))
                   7118:                 /* hover, active, focus pseudo-classes */
                   7119:                 {
1.403     vatton   7120:                   attrnames[0] = NULL;
                   7121:                   attrnums[0] = ATTR_PSEUDO;
                   7122:                   attrlevels[0] = 0;
                   7123:                   attrmatch[0] = Txtmatch;
                   7124:                   attrvals[0] = deb;
1.355     quint    7125:                   specificity += 10;
                   7126:                   /* not supported */
                   7127:                   DoApply = FALSE;
                   7128:                 }
                   7129:               else if (!strncmp (deb, "lang", 4))
                   7130:                 /* it's the lang pseudo-class */
                   7131:                 {
                   7132:                   if (deb[4] != '(' || deb[strlen(deb)-1] != ')')
                   7133:                     /* at least one parenthesis is missing. Error */
1.327     vatton   7134:                     {
1.355     quint    7135:                       CSSPrintError ("Invalid :lang pseudo-class", deb);
                   7136:                       DoApply = FALSE;
1.327     vatton   7137:                     }
                   7138:                   else
1.355     quint    7139:                     /* simulate selector [lang|="xxx"] */
1.340     quint    7140:                     {
                   7141:                       nbattrs++;
                   7142:                       if (nbattrs == MAX_ANCESTORS)
                   7143:                         /* abort parsing */
                   7144:                         {
                   7145:                           CSSPrintError ("Selector too long", deb);
                   7146:                           return (selector);
                   7147:                         }
1.355     quint    7148:                       deb[strlen(deb)-1] = EOS;
                   7149:                       deb[4] = EOS;
1.340     quint    7150:                       for (i = nbattrs; i > 0; i--)
                   7151:                         {
                   7152:                           attrnames[i] = attrnames[i - 1];
                   7153:                           attrnums[i] = attrnums[i - 1];
                   7154:                           attrlevels[i] = attrlevels[i - 1];
                   7155:                           attrvals[i] = attrvals[i - 1];
                   7156:                           attrmatch[i] = attrmatch[i - 1];
                   7157:                         }
1.355     quint    7158:                       attrnames[0] = deb;
                   7159:                       attrnums[0] = 0;
1.340     quint    7160:                       attrlevels[0] = 0;
1.355     quint    7161:                       attrmatch[0] = Txtsubstring;
                   7162:                       attrvals[0] = &deb[5];
                   7163:                       specificity += 10;
1.340     quint    7164:                     }
1.327     vatton   7165:                 }
1.355     quint    7166:               else if (!strcmp (deb, "first-line") ||
                   7167:                        !strcmp (deb, "first-letter"))
                   7168:                 /* pseudo-elements first-line or first-letter */
                   7169:                 {
1.404     vatton   7170:                   if (doubleColon && warn)
1.355     quint    7171:                     CSSPrintError ("Warning: \"::\" is CSS3 syntax", NULL);
                   7172:                   specificity += 1;
                   7173:                   /* not supported */
                   7174:                   DoApply = FALSE;
                   7175:                 }
                   7176:               else if (!strncmp (deb, "before", 6))
                   7177:                 /* pseudo-element before */
                   7178:                 {
1.404     vatton   7179:                   if (doubleColon && warn)
1.355     quint    7180:                     CSSPrintError ("Warning: \"::before\" is CSS3 syntax",
                   7181:                                    NULL);
                   7182:                   ctxt->pseudo = PbBefore;
                   7183:                   specificity += 1;
                   7184:                 }
                   7185:               else if (!strncmp (deb, "after", 5))
                   7186:                 /* pseudo-element after */
                   7187:                 {
1.404     vatton   7188:                   if (doubleColon && warn)
1.355     quint    7189:                     CSSPrintError ("Warning: \"::after\" is CSS3 syntax",
                   7190:                                    NULL);
                   7191:                   ctxt->pseudo = PbAfter;
                   7192:                   specificity += 1;
                   7193:                 }
1.433     vatton   7194:               else if (!strncmp (deb, "target", 6))
1.404     vatton   7195:                 {
1.433     vatton   7196:                   if (warn)
1.404     vatton   7197:                    CSSPrintError ("Warning: \":target\" is CSS3 syntax",
                   7198:                                    NULL);
                   7199:                   specificity += 1;
                   7200:                   DoApply = FALSE;
                   7201:                 }
1.433     vatton   7202:               else if (!strncmp (deb, "not", 3) ||
                   7203:                        !strncmp (deb, "only", 4) ||
                   7204:                        !strncmp (deb, "last", 4))
                   7205:                 {
                   7206:                   if (warn)
                   7207:                    CSSPrintError ("Warning: Not supported CSS3 syntax",
                   7208:                                    NULL);
                   7209:                   specificity += 1;
                   7210:                   DoApply = FALSE;
                   7211:                 }
                   7212:               else
1.355     quint    7213:                 {
                   7214:                   CSSPrintError ("Invalid pseudo-element", deb);
                   7215:                   DoApply = FALSE;
                   7216:                 }
                   7217:               if (names[0] && !strcmp (names[0], "*"))
                   7218:                 names[0] = NULL;
1.327     vatton   7219:             }
                   7220:           else if (*selector == '#')
1.340     quint    7221:             /* unique identifier */
1.327     vatton   7222:             {
                   7223:               selector++;
1.340     quint    7224:               while (*selector != '.' && *selector != ':' &&
                   7225:                      *selector != '#' && *selector != '[' &&
                   7226:                      *selector != '+' && *selector != '>' &&
                   7227:                      *selector != EOS && *selector != ',' &&
1.398     vatton   7228:                      !TtaIsBlank (selector) && cur < limit)
1.327     vatton   7229:                 *cur++ = *selector++;
                   7230:               /* close the word */
                   7231:               *cur++ = EOS;
                   7232:               /* point to the attribute in sel[] if it's valid name */
                   7233:               if (deb[0] <= 64)
                   7234:                 {
                   7235:                   CSSPrintError ("Invalid id", deb);
                   7236:                   DoApply = FALSE;
                   7237:                 }
                   7238:               else
                   7239:                 {
1.340     quint    7240:                   nbattrs++;
                   7241:                   if (nbattrs == MAX_ANCESTORS)
                   7242:                     /* abort parsing */
                   7243:                     {
                   7244:                       CSSPrintError ("Selector too long", deb);
                   7245:                       return (selector);
                   7246:                     }
                   7247:                   for (i = nbattrs; i > 0; i--)
                   7248:                     {
                   7249:                       attrnames[i] = attrnames[i - 1];
                   7250:                       attrnums[i] = attrnums[i - 1];
                   7251:                       attrlevels[i] = attrlevels[i - 1];
                   7252:                       attrvals[i] = attrvals[i - 1];
                   7253:                       attrmatch[i] = attrmatch[i - 1];
                   7254:                     }
                   7255:                   attrnames[0] = NULL;
                   7256:                   attrnums[0] = ATTR_ID;
                   7257:                   attrlevels[0] = 0;
                   7258:                   attrmatch[0] = Txtmatch;
                   7259:                   attrvals[0] = deb;
                   7260:                   specificity += 100;
                   7261:                   if (names[0] && !strcmp (names[0], "*"))
                   7262:                     names[0] = NULL;
1.327     vatton   7263:                 }
                   7264:             }
                   7265:           else if (*selector == '[')
                   7266:             {
                   7267:               selector++;
1.341     quint    7268:               selector = SkipBlanksAndComments (selector);
1.327     vatton   7269:               while (*selector != EOS && *selector != ']' &&
                   7270:                      *selector != '=' && *selector != '~' &&
1.341     quint    7271:                      *selector != '|' && *selector != '^' &&
1.396     vatton   7272:                       *selector != '$' &&  *selector != '*' &&
1.398     vatton   7273:                      !TtaIsBlank (selector) && cur < limit)
1.327     vatton   7274:                 *cur++ = *selector++;
1.341     quint    7275:               /* close the word (attribute name) */
1.327     vatton   7276:               *cur++ = EOS;
                   7277:               /* point to the attribute in sel[] if it's valid name */
                   7278:               if (deb[0] <= 64)
                   7279:                 {
                   7280:                   CSSPrintError ("Invalid attribute", deb);
                   7281:                   DoApply = FALSE;
                   7282:                 }
                   7283:               else
                   7284:                 {
1.340     quint    7285:                   nbattrs++;
                   7286:                   if (nbattrs == MAX_ANCESTORS)
                   7287:                     /* abort parsing */
                   7288:                     {
                   7289:                       CSSPrintError ("Selector too long", deb);
                   7290:                       return (selector);
                   7291:                     }
                   7292:                   for (i = nbattrs; i > 0; i--)
                   7293:                     {
                   7294:                       attrnames[i] = attrnames[i - 1];
                   7295:                       attrnums[i] = attrnums[i - 1];
                   7296:                       attrlevels[i] = attrlevels[i - 1];
                   7297:                       attrvals[i] = attrvals[i - 1];
                   7298:                       attrmatch[i] = attrmatch[i - 1];
                   7299:                     }
                   7300:                   attrnames[0] = deb;
                   7301:                   attrnums[0] = 0;
                   7302:                   attrlevels[0] = 0;
1.378     quint    7303:                   attrvals[0] = NULL;
                   7304:                   attrmatch[0] = Txtmatch;
1.327     vatton   7305:                   specificity += 10;
1.340     quint    7306:                   /* check matching */
1.341     quint    7307:                   selector = SkipBlanksAndComments (selector);
1.340     quint    7308:                   if (*selector == '~')
                   7309:                     {
                   7310:                       attrmatch[0] = Txtword;
                   7311:                       selector++;
                   7312:                     }
1.396     vatton   7313:                   else if (*selector == '|' || *selector == '$' || *selector == '*')
1.340     quint    7314:                     {
1.404     vatton   7315:                       if (*selector == '$' && warn)
1.396     vatton   7316:                         CSSPrintError ("Warning: \"$=\" is CSS3 syntax", NULL);
1.404     vatton   7317:                       if (*selector == '*' && warn)
1.396     vatton   7318:                         CSSPrintError ("Warning: \"*=\" is CSS3 syntax", NULL);
1.340     quint    7319:                       attrmatch[0] = Txtsubstring;
                   7320:                       selector++;
                   7321:                     }
1.341     quint    7322:                   else if (*selector == '^')
                   7323:                     {
                   7324:                       attrmatch[0] = Txtsubstring;
                   7325:                       selector++;
                   7326:                     }
1.340     quint    7327:                   else
                   7328:                     attrmatch[0] = Txtmatch;
1.327     vatton   7329:                 }
                   7330:               if (*selector == '=')
                   7331:                 {
                   7332:                   /* look for a value "xxxx" */
                   7333:                   selector++;
1.341     quint    7334:                   selector = SkipBlanksAndComments (selector);
1.327     vatton   7335:                   if (*selector != '"')
                   7336:                     quoted = FALSE;
                   7337:                   else
                   7338:                     {
                   7339:                       quoted = TRUE;
                   7340:                       /* we are now parsing the attribute value */
                   7341:                       selector++;
                   7342:                     }
                   7343:                   deb = cur;
1.398     vatton   7344:                   while ((quoted && cur < limit &&
1.327     vatton   7345:                           (*selector != '"' ||
                   7346:                            (*selector == '"' && selector[-1] == '\\'))) ||
                   7347:                          (!quoted && *selector != ']'))
                   7348:                     {
                   7349:                       if (*selector == EOS)
                   7350:                         {
                   7351:                           CSSPrintError ("Invalid attribute value", deb);
                   7352:                           DoApply = FALSE;
                   7353:                         }
                   7354:                       else
                   7355:                         {
                   7356:                           if (attrmatch[0] == Txtword && TtaIsBlank (selector))
                   7357:                             {
                   7358:                               CSSPrintError ("No space allowed here: ", selector);
                   7359:                               DoApply = FALSE;
                   7360:                             }
                   7361:                           *cur++ = *selector;
                   7362:                         }
                   7363:                       selector++;
                   7364:                     }
                   7365:                   /* there is a value */
                   7366:                   if (quoted && *selector == '"')
                   7367:                     {
                   7368:                       selector++;
                   7369:                       quoted = FALSE;
                   7370:                     }
1.341     quint    7371:                   selector = SkipBlanksAndComments (selector);
1.327     vatton   7372:                   if (*selector != ']')
                   7373:                     {
                   7374:                       CSSPrintError ("Invalid attribute value", deb);
                   7375:                       DoApply = FALSE;
                   7376:                     }
                   7377:                   else
                   7378:                     {
                   7379:                       *cur++ = EOS;
                   7380:                       attrvals[0] = deb;
                   7381:                       selector++;
                   7382:                     }
                   7383:                 }
                   7384:               /* end of the attribute */
                   7385:               else if (*selector != ']')
                   7386:                 {
                   7387:                   selector[1] = EOS;
                   7388:                   CSSPrintError ("Invalid attribute", selector);
                   7389:                   selector += 2;
                   7390:                   DoApply = FALSE;
                   7391:                 }
                   7392:               else
                   7393:                 {
                   7394:                   selector++;
                   7395:                   if (names[0] && !strcmp (names[0], "*"))
                   7396:                     names[0] = NULL;
                   7397:                 }
                   7398:             }
                   7399:           else
                   7400:             {
                   7401:               /* not supported selector */
1.340     quint    7402:               while (*selector != '.' && *selector != ':' &&
                   7403:                      *selector != '#' && *selector != '[' &&
                   7404:                      *selector != EOS && *selector != ',' &&
                   7405:                      *selector != '+' && *selector != '>' &&
1.398     vatton   7406:                      !TtaIsBlank (selector) && cur < limit)
1.327     vatton   7407:                 *cur++ = *selector++;
                   7408:               /* close the word */
                   7409:               *cur++ = EOS;
                   7410:               CSSPrintError ("Selector not supported:", deb);
                   7411:               DoApply = FALSE;     
                   7412:             }
                   7413:         }
1.1       cvs      7414: 
1.286     quint    7415:       skippedNL = NewLineSkipped;
1.82      cvs      7416:       selector = SkipBlanksAndComments (selector);
1.286     quint    7417:       NewLineSkipped = skippedNL;
                   7418: 
1.380     vatton   7419:       if (noname && !pseudoFirstChild[0] && attrnums[0] == 0 && attrnames[0] == NULL)
                   7420:         {
                   7421:           *cur++ = EOS;
                   7422:           CSSPrintError ("Invalid Selector", deb);
                   7423:           DoApply = FALSE;         
                   7424:         }
1.25      cvs      7425:       /* is it a multi-level selector? */
1.82      cvs      7426:       if (*selector == EOS)
1.327     vatton   7427:         /* end of the selector */
                   7428:         break;
1.82      cvs      7429:       else if (*selector == ',')
1.327     vatton   7430:         {
                   7431:           /* end of the current selector */
                   7432:           selector++;
                   7433:           skippedNL = NewLineSkipped;
                   7434:           next = SkipBlanksAndComments (selector);
                   7435:           NewLineSkipped = skippedNL;
                   7436:           if (*next == EOS)
                   7437:             /* nothing after the comma. Invalid selector */
                   7438:             {
1.380     vatton   7439:               CSSPrintError ("Syntax error:", selector);
                   7440:               selector = NULL;
1.327     vatton   7441:             }
                   7442:           break;
                   7443:         }
1.25      cvs      7444:       else
1.327     vatton   7445:         {
                   7446:           if (*selector == '>')
                   7447:             {
1.340     quint    7448:               /* handle parent */
1.327     vatton   7449:               selector++;
                   7450:               skippedNL = NewLineSkipped;
                   7451:               selector = SkipBlanksAndComments (selector);
                   7452:               NewLineSkipped = skippedNL;
1.340     quint    7453:               rel[0] = RelParent;
1.327     vatton   7454:             }
                   7455:           else if (*selector == '+')
                   7456:             {
1.340     quint    7457:               /* handle immediate sibling */
1.327     vatton   7458:               selector++;
                   7459:               skippedNL = NewLineSkipped;
                   7460:               selector = SkipBlanksAndComments (selector);
                   7461:               NewLineSkipped = skippedNL;
                   7462:               rel[0] = RelPrevious;
                   7463:             }
1.340     quint    7464:           else
                   7465:             rel[0] = RelAncestor;
                   7466:           nbnames++; /* a new level in ancestor tables */
                   7467:           if (nbnames == MAX_ANCESTORS)
                   7468:             /* abort parsing */
                   7469:             {
                   7470:               CSSPrintError ("Selector too long", deb);
                   7471:               return (selector);
                   7472:             }
                   7473:           /* shift the list to make room for the next part of the selector */
                   7474:           for (i = nbnames; i > 0; i--)
1.327     vatton   7475:             {
                   7476:               names[i] = names[i - 1];
1.355     quint    7477:               pseudoFirstChild[i] = pseudoFirstChild[i - 1];
1.327     vatton   7478:               rel[i] = rel[i - 1];
                   7479:             }
1.340     quint    7480:           /* increase the level of all attributes */
                   7481:           for (i = 0; i < nbattrs; i++)
                   7482:               attrlevels[i]++;
1.327     vatton   7483:         }
1.1       cvs      7484:     }
                   7485: 
1.343     vatton   7486:   /* Now update the list of classes defined by the CSS */
                   7487:   for (i = 0; i < nbattrs; i++)
                   7488:     if (attrvals[i] && attrnums[i] == ATTR_CLASS)
                   7489:       AddClassName (attrvals[i], css);
                   7490: 
1.1       cvs      7491:   /* Now set up the context block */
1.25      cvs      7492:   i = 0;
                   7493:   j = 0;
1.91      cvs      7494:   /* default schema name */
1.119     vatton   7495:   ctxt->schema = NULL;
1.340     quint    7496:   ctxt->nbElem = nbnames;
1.122     vatton   7497:   elType.ElSSchema = NULL;
1.355     quint    7498:   elType.ElTypeNum = 0;
1.122     vatton   7499:   schemaName = TtaGetSSchemaName(TtaGetDocumentSSchema (doc));
1.119     vatton   7500:   if (!strcmp (schemaName, "HTML"))
                   7501:     xmlType = XHTML_TYPE;
                   7502:   else if (!strcmp (schemaName, "MathML"))
                   7503:     xmlType = MATH_TYPE;
                   7504:   else if (!strcmp (schemaName, "SVG"))
                   7505:     xmlType = SVG_TYPE;
                   7506:   else if (!strcmp (schemaName, "XLink"))
                   7507:     xmlType = XLINK_TYPE;
                   7508:   else if (!strcmp (schemaName, "Annot"))
                   7509:     xmlType = ANNOT_TYPE;
                   7510:   else
                   7511:     xmlType = XML_TYPE;
1.340     quint    7512:   while (i <= nbnames)
1.25      cvs      7513:     {
1.340     quint    7514:       ctxt->rel[i] = rel[i];
1.355     quint    7515:       ctxt->firstChild[i] = pseudoFirstChild[i];
                   7516:       if (!names[i] && i > 0)
1.340     quint    7517:         ctxt->name[i] = HTML_EL_ANY_TYPE;
                   7518:       else
                   7519:         /* store element information */
1.327     vatton   7520:         {
                   7521:           /* get the element type of this name in the current document */
                   7522:           if (xmlType == XML_TYPE)
                   7523:             /* it's a generic XML document. Check the main document schema */
                   7524:             {
                   7525:               elType.ElSSchema = TtaGetDocumentSSchema (doc);
1.355     quint    7526:               elType.ElTypeNum = 0;
                   7527:               if (names[i])
                   7528:                 TtaGetXmlElementType (names[i], &elType, &mappedName, doc);
1.327     vatton   7529:               if (!elType.ElTypeNum)
                   7530:                 {
1.355     quint    7531:                   if (!names[i] || !strcmp (names[i], "*"))
1.327     vatton   7532:                     elType.ElTypeNum = HTML_EL_ANY_TYPE;
                   7533:                   else
                   7534:                     elType.ElSSchema = NULL;
                   7535:                 }
                   7536:             }
                   7537:           else
                   7538:             {
1.355     quint    7539:               if (!names[i] || !strcmp (names[i], "*"))
1.327     vatton   7540:                 {
                   7541:                   elType.ElSSchema = TtaGetDocumentSSchema (doc);
                   7542:                   elType.ElTypeNum = HTML_EL_ANY_TYPE;
                   7543:                 }
                   7544:               else
                   7545:                 MapXMLElementType (xmlType, names[i], &elType, &mappedName, &c,
                   7546:                                    &level, doc);
                   7547:             }
                   7548:           if (i == 0)
1.340     quint    7549:             /* rightmost part of the selector */
1.327     vatton   7550:             {
                   7551:               if (elType.ElSSchema == NULL)
                   7552:                 {
1.340     quint    7553:                   /* element name not found. Search in all loaded schemas */
1.355     quint    7554:                   if (names[i])
                   7555:                     TtaGetXmlElementType (names[i], &elType, NULL, doc);
1.327     vatton   7556:                   if (elType.ElSSchema)
                   7557:                     {
                   7558:                       /* the element type concerns an imported nature */
                   7559:                       schemaName = TtaGetSSchemaName(elType.ElSSchema);
                   7560:                       if (!strcmp (schemaName, "HTML"))
                   7561:                         {
                   7562:                           if (xmlType == XHTML_TYPE &&
                   7563:                               DocumentMeta[doc] && DocumentMeta[doc]->xmlformat)
                   7564:                             /* the selector was found but the case is not correct */
                   7565:                             elType.ElSSchema = NULL;
                   7566:                           else
                   7567:                             xmlType = XHTML_TYPE;
                   7568:                         }
                   7569:                       else if (!strcmp (schemaName, "MathML"))
                   7570:                         xmlType = MATH_TYPE;
                   7571:                       else if (!strcmp (schemaName, "SVG"))
                   7572:                         xmlType = SVG_TYPE;
                   7573:                       else if (!strcmp (schemaName, "XLink"))
                   7574:                         xmlType = XLINK_TYPE;
                   7575:                       else if (!strcmp (schemaName, "Annot"))
                   7576:                         xmlType = ANNOT_TYPE;
                   7577:                       else
                   7578:                         xmlType = XML_TYPE;
                   7579:                     }
1.118     vatton   7580: #ifdef XML_GENERIC
1.327     vatton   7581:                   else if (xmlType == XML_TYPE)
                   7582:                     {
                   7583:                       /* Creation of a new element type in the main schema */
                   7584:                       elType.ElSSchema = TtaGetDocumentSSchema (doc);
1.355     quint    7585:                       if (names[i])
                   7586:                         TtaAppendXmlElement (names[i], &elType, &mappedName,
                   7587:                                              doc);
1.327     vatton   7588:                     }
1.118     vatton   7589: #endif /* XML_GENERIC */
1.327     vatton   7590:                   else
                   7591:                     {
                   7592:                       if (xmlType != XHTML_TYPE)
                   7593:                         {
                   7594:                           MapXMLElementType (XHTML_TYPE, names[i], &elType,
                   7595:                                              &mappedName, &c, &level, doc);
                   7596:                           if (elType.ElSSchema)
                   7597:                             elType.ElSSchema = GetXHTMLSSchema (doc);
                   7598:                         }
                   7599:                       if (elType.ElSSchema == NULL && xmlType != MATH_TYPE)
                   7600:                         {
                   7601:                           MapXMLElementType (MATH_TYPE, names[i], &elType,
                   7602:                                              &mappedName, &c, &level, doc);
                   7603:                           if (elType.ElSSchema)
                   7604:                             elType.ElSSchema = GetMathMLSSchema (doc);
                   7605:                         }
                   7606:                       if (elType.ElSSchema == NULL && xmlType != SVG_TYPE)
                   7607:                         {
                   7608:                           MapXMLElementType (SVG_TYPE, names[i], &elType,
                   7609:                                              &mappedName, &c, &level, doc);
                   7610:                           if (elType.ElSSchema)
                   7611:                             elType.ElSSchema = GetSVGSSchema (doc);
                   7612:                         }
                   7613:                     }
                   7614:                 }
                   7615: 
                   7616:               if (elType.ElSSchema == NULL)
                   7617:                 /* cannot apply these CSS rules */
                   7618:                 DoApply = FALSE;
                   7619:               else
                   7620:                 {
1.340     quint    7621:                   /* Store the element type contained in the rightmost part of
                   7622:                      the selector */
                   7623:                   ctxt->schema = elType.ElSSchema;
1.327     vatton   7624:                   ctxt->type = elType.ElTypeNum;
                   7625:                   ctxt->name[0] = elType.ElTypeNum;
1.340     quint    7626:                   ctxt->rel[0] = RelVoid;
1.327     vatton   7627:                 }
                   7628:             }
1.340     quint    7629:           else
                   7630:             /* not the rightmost part of the selector */
1.327     vatton   7631:             {
1.340     quint    7632:               if (elType.ElTypeNum != 0)
                   7633:                 ctxt->name[i] = elType.ElTypeNum;
                   7634: #ifdef XML_GENERIC
                   7635:               else if (xmlType == XML_TYPE)
1.327     vatton   7636:                 {
1.340     quint    7637:                   TtaGetXmlElementType (names[i], &elType, NULL, doc);
                   7638:                   if (elType.ElTypeNum == 0)
1.327     vatton   7639:                     {
1.340     quint    7640:                       /* Creation of a new element type in the main schema */
                   7641:                       elType.ElSSchema = TtaGetDocumentSSchema (doc);
                   7642:                       TtaAppendXmlElement (names[i], &elType, &mappedName, doc);
1.327     vatton   7643:                     }
1.340     quint    7644:                   if (elType.ElTypeNum != 0)
                   7645:                     ctxt->name[i] = elType.ElTypeNum;
1.327     vatton   7646:                 }
1.340     quint    7647: #endif /* XML_GENERIC */
1.327     vatton   7648:             }
1.340     quint    7649:         }
                   7650: 
                   7651:       /* store attribute information for this element */
                   7652:       while (j < nbattrs && attrlevels[j] <= i)
                   7653:         {
                   7654:           if (attrnames[j] || attrnums[j])
1.327     vatton   7655:             {
1.340     quint    7656:               if (attrnums[j] > 0)
1.327     vatton   7657:                 {
1.340     quint    7658:                   if (attrnums[j] == ATTR_CLASS)
1.327     vatton   7659:                     {
1.340     quint    7660:                       if (xmlType == SVG_TYPE)
                   7661:                         ctxt->attrType[j] = SVG_ATTR_class;
                   7662:                       else if (xmlType == MATH_TYPE)
                   7663:                         ctxt->attrType[j] = MathML_ATTR_class;
                   7664:                       else if (xmlType == XHTML_TYPE)
                   7665:                         ctxt->attrType[j] = HTML_ATTR_Class;
1.327     vatton   7666:                       else
1.119     vatton   7667: #ifdef XML_GENERIC
1.340     quint    7668:                         ctxt->attrType[j] = XML_ATTR_class;
1.107     cvs      7669: #else /* XML_GENERIC */
1.340     quint    7670:                         ctxt->attrType[j] = HTML_ATTR_Class;
1.107     cvs      7671: #endif /* XML_GENERIC */
1.340     quint    7672:                     }
                   7673:                   else if (attrnums[j] == ATTR_PSEUDO)
                   7674:                     {
                   7675:                       if (xmlType == SVG_TYPE)
                   7676:                         ctxt->attrType[j] = SVG_ATTR_PseudoClass;
                   7677:                       else if (xmlType == MATH_TYPE)
                   7678:                         ctxt->attrType[j] = MathML_ATTR_PseudoClass;
                   7679:                       else if (xmlType == XHTML_TYPE)
                   7680:                         ctxt->attrType[j] = HTML_ATTR_PseudoClass;
                   7681:                       else
1.119     vatton   7682: #ifdef XML_GENERIC
1.340     quint    7683:                         ctxt->attrType[j] = XML_ATTR_PseudoClass;
1.107     cvs      7684: #else /* XML_GENERIC */
1.340     quint    7685:                         ctxt->attrType[j] = HTML_ATTR_PseudoClass;
1.107     cvs      7686: #endif /* XML_GENERIC */
1.340     quint    7687:                     }
                   7688:                   else if (attrnums[j] == ATTR_ID)
                   7689:                     {
                   7690:                       if (xmlType == SVG_TYPE)
                   7691:                         ctxt->attrType[j] = SVG_ATTR_id;
                   7692:                       else if (xmlType == MATH_TYPE)
                   7693:                         ctxt->attrType[j] = MathML_ATTR_id;
                   7694:                       else if (xmlType == XHTML_TYPE)
                   7695:                         ctxt->attrType[j] = HTML_ATTR_ID;
                   7696:                       else
1.119     vatton   7697: #ifdef XML_GENERIC
1.340     quint    7698:                         ctxt->attrType[j] = XML_ATTR_xmlid;
1.107     cvs      7699: #else /* XML_GENERIC */
1.340     quint    7700:                         ctxt->attrType[j] = HTML_ATTR_ID;
1.107     cvs      7701: #endif /* XML_GENERIC */
1.340     quint    7702:                     }
                   7703:                   attrType.AttrTypeNum = ctxt->attrType[j];
                   7704:                   attrType.AttrSSchema =  ctxt->schema;
                   7705:                 }
                   7706:               else if (attrnames[j])
                   7707:                 {
                   7708:                   if (xmlType == XML_TYPE)
                   7709:                     {
                   7710:                       if (ctxt->schema)
                   7711:                         attrType.AttrSSchema = ctxt->schema;
                   7712:                       else
                   7713:                         attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
                   7714:                       TtaGetXmlAttributeType (attrnames[j], &attrType, doc);
                   7715:                       att = attrType.AttrTypeNum;
                   7716:                       if (ctxt->schema == NULL && att != 0)
                   7717:                         ctxt->schema = attrType.AttrSSchema;
                   7718:                     }
                   7719:                   else
                   7720:                     {
                   7721:                       MapXMLAttribute (xmlType, attrnames[j], names[i], &level,
                   7722:                                        doc, &att);
                   7723:                       if (ctxt->schema == NULL && att != 0)
                   7724:                         ctxt->schema = TtaGetDocumentSSchema (doc);
                   7725:                     }
1.393     quint    7726:                   if (att == 0 && xmlType != XML_TYPE)
1.340     quint    7727:                     /* Attribute name not found: Search in the list of all
                   7728:                        schemas loaded for this document */
                   7729:                     {
                   7730:                       attrType.AttrSSchema = NULL;
                   7731:                       TtaGetXmlAttributeType (attrnames[j], &attrType, doc);
                   7732:                       att = attrType.AttrTypeNum;
                   7733:                       if (att != 0)
1.393     quint    7734:                         {
                   7735:                           ctxt->schema = attrType.AttrSSchema;
                   7736:                           schemaName = TtaGetSSchemaName(attrType.AttrSSchema);
                   7737:                         }
1.340     quint    7738:                     }
                   7739:                   attrType.AttrSSchema = ctxt->schema;
                   7740:                   attrType.AttrTypeNum = att;
1.412     vatton   7741:                   if ((i == 0 || xmlType == XML_TYPE) && att == 0)
1.340     quint    7742:                     {
1.119     vatton   7743: #ifdef XML_GENERIC
1.393     quint    7744:                       if (xmlType == XML_TYPE)
1.340     quint    7745:                         {
                   7746:                           /* The attribute is not yet present in the tree */
                   7747:                           /* Create a new global attribute */
                   7748:                           attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
                   7749:                           TtaAppendXmlAttribute (attrnames[j], &attrType, doc);
1.393     quint    7750:                           att = attrType.AttrTypeNum;
1.340     quint    7751:                         }
                   7752: #endif /* XML_GENERIC */
                   7753:                       if (attrType.AttrSSchema == NULL)
                   7754:                         /* cannot apply these CSS rules */
                   7755:                         DoApply = FALSE;
                   7756:                       else if (elType.ElSSchema)
                   7757:                         ctxt->schema = elType.ElSSchema;
                   7758:                       else
                   7759:                         ctxt->schema = attrType.AttrSSchema;
                   7760:                     }
                   7761:                   if (att == 0)
                   7762:                     {
                   7763:                       CSSPrintError ("Unknown attribute", attrnames[j]);
                   7764:                       DoApply = FALSE;     
                   7765:                     }
                   7766:                   else
1.345     quint    7767:                     {
                   7768:                       ctxt->attrType[j] = att;
                   7769:                       if (att == DummyAttribute && !strcmp (schemaName,"HTML"))
                   7770:                         /* it's the "type" attribute for an "input" element.
                   7771:                            In the tree, it is represented by the element type,
                   7772:                            not by an attribute */
                   7773:                         {
                   7774:                           ctxt->attrType[j] = 0;
                   7775:                           if (attrvals[j] && attrmatch[i] == Txtmatch)
                   7776:                             /* a value is specified for attribute type. This
                   7777:                                value provides the Thot element type */
                   7778:                             {
                   7779:                               MapXMLAttributeValue (xmlType, attrvals[j],
                   7780:                                                     &attrType, &kind);
                   7781:                               /* attrType contains the element type */
                   7782:                               if (i == 0)
                   7783:                                 ctxt->type = kind;
                   7784:                               ctxt->name[i] = kind;
                   7785:                             } 
                   7786:                         }
                   7787:                     }
1.340     quint    7788:                 }
                   7789:               if (ctxt->attrType[j])
1.327     vatton   7790:                 {
1.340     quint    7791:                   /* check the attribute type */
                   7792:                   if (!strcmp (schemaName, "HTML"))
                   7793:                     xmlType = XHTML_TYPE;
                   7794:                   else if (!strcmp (schemaName, "MathML"))
                   7795:                     xmlType = MATH_TYPE;
                   7796:                   else if (!strcmp (schemaName, "SVG"))
                   7797:                     xmlType = SVG_TYPE;
                   7798:                   else if (!strcmp (schemaName, "XLink"))
                   7799:                     xmlType = XLINK_TYPE;
                   7800:                   else if (!strcmp (schemaName, "Annot"))
                   7801:                     xmlType = ANNOT_TYPE;
                   7802:                   else
                   7803:                     xmlType = XML_TYPE;
                   7804:                   kind = TtaGetAttributeKind (attrType);
                   7805:                   if (kind == 0 && attrvals[j])
                   7806:                     {
                   7807:                       /* enumerated value */
                   7808:                       MapXMLAttributeValue (xmlType, attrvals[j], &attrType,
                   7809:                                             &kind);
                   7810:                       /* store the attribute value */
                   7811:                       ctxt->attrText[j] = (char *) kind;
                   7812:                     }
                   7813:                   else
                   7814:                     ctxt->attrText[j] = attrvals[j];
                   7815:                   /* update attrLevel */
                   7816:                   ctxt->attrMatch[j] = attrmatch[j];
                   7817:                   ctxt->attrLevel[j] = attrlevels[j];
                   7818:                     }
                   7819:               j++;
1.327     vatton   7820:             }
                   7821:         }
1.340     quint    7822:       /* add a new entry */
1.25      cvs      7823:       i++;
1.119     vatton   7824:       if (i == 1 && ctxt->schema == NULL)
1.327     vatton   7825:         /* use the document schema */
                   7826:         ctxt->schema = TtaGetDocumentSSchema (doc);
1.1       cvs      7827:     }
1.340     quint    7828: 
1.312     quint    7829:   ctxt->important = FALSE;
1.117     vatton   7830:   /* set the selector specificity */
                   7831:   ctxt->cssSpecificity = specificity;
1.25      cvs      7832:   /* Get the schema name of the main element */
1.119     vatton   7833:   schemaName = TtaGetSSchemaName (ctxt->schema);
                   7834:   isHTML = (strcmp (schemaName, "HTML") == 0);
1.206     vatton   7835:   tsch = GetPExtension (doc, ctxt->schema, css, link);
1.217     vatton   7836:   skippedNL = NewLineSkipped;
1.380     vatton   7837:   if (DoApply && tsch && cssRule)
1.317     vatton   7838:     {
                   7839:       if (css)
1.327     vatton   7840:         {
                   7841:           /* point the right URL for loaded images */
                   7842:           saveURL = css->url;
                   7843:           css->url = url;
                   7844:         }
1.317     vatton   7845:       else
1.327     vatton   7846:         saveURL = NULL;
                   7847:       ParseCSSRule (NULL, tsch, (PresentationContext) ctxt, cssRule, css, isHTML);
1.317     vatton   7848:       if (css)
1.327     vatton   7849:         /* restore previous url */
                   7850:         css->url = saveURL;
1.317     vatton   7851:     }
1.116     vatton   7852:   /* future CSS rules should apply */
                   7853:   DoApply = TRUE;
1.217     vatton   7854:   if (selector)
                   7855:     NewLineSkipped = skippedNL;
1.1       cvs      7856:   return (selector);
                   7857: }
                   7858: 
                   7859: /*----------------------------------------------------------------------
1.206     vatton   7860:   ParseStyleDeclaration: parse a style declaration stored in the style
                   7861:   element of a document                       
                   7862:   We expect the style string to be of the form:                   
                   7863:   .pinky, .awful { color: pink; font-family: helvetica }        
1.231     vatton   7864:   The parameter css points to the current CSS context.
                   7865:   The parameter link points to the link element.
                   7866:   The parameter url gives the URL of the parsed style sheet.
1.1       cvs      7867:   ----------------------------------------------------------------------*/
1.206     vatton   7868: static void ParseStyleDeclaration (Element el, char *cssRule, Document doc,
1.327     vatton   7869:                                    CSSInfoPtr css, Element link, char *url,
                   7870:                                    ThotBool destroy)
1.1       cvs      7871: {
1.79      cvs      7872:   GenericContext      ctxt;
                   7873:   char               *decl_end;
                   7874:   char               *sel_end;
                   7875:   char               *selector;
1.1       cvs      7876: 
                   7877:   /* separate the selectors string */
1.82      cvs      7878:   cssRule = SkipBlanksAndComments (cssRule);
1.1       cvs      7879:   decl_end = cssRule;
1.82      cvs      7880:   while (*decl_end != EOS && *decl_end != '{')
1.286     quint    7881:     {
                   7882:       if (*decl_end == EOL)
1.327     vatton   7883:         NewLineSkipped++;
1.286     quint    7884:       decl_end++;
                   7885:     }
1.82      cvs      7886:   if (*decl_end == EOS)
1.86      cvs      7887:     {
1.168     vatton   7888:       CSSPrintError ("Invalid selector", cssRule);
1.86      cvs      7889:       return;
                   7890:     }
1.1       cvs      7891:   /* verify and clean the selector string */
                   7892:   sel_end = decl_end - 1;
1.82      cvs      7893:   while (*sel_end == SPACE || *sel_end == BSPACE ||
1.411     vatton   7894:          *sel_end == EOL || *sel_end == __CR__)
1.1       cvs      7895:     sel_end--;
                   7896:   sel_end++;
1.82      cvs      7897:   *sel_end = EOS;
1.1       cvs      7898:   selector = cssRule;
                   7899: 
                   7900:   /* now, deal with the content ... */
                   7901:   decl_end++;
                   7902:   cssRule = decl_end;
1.137     vatton   7903:   decl_end = &cssRule[strlen (cssRule) - 1];
1.398     vatton   7904:   if (*decl_end != '{' && *decl_end != EOS)
1.137     vatton   7905:     *decl_end = EOS;
1.1       cvs      7906:   /*
                   7907:    * parse the style attribute string and install the corresponding
                   7908:    * presentation attributes on the new element
                   7909:    */
                   7910:   ctxt = TtaGetGenericStyleContext (doc);
                   7911:   if (ctxt == NULL)
                   7912:     return;
                   7913:   ctxt->destroy = destroy;
1.207     vatton   7914:   /* first use of the context */
                   7915:   ctxt->uses = 1;
1.197     vatton   7916:   while (selector && *selector != EOS)
1.363     vatton   7917:     {
                   7918:       if (ctxt->uses > 1)
                   7919:         {
                   7920:           /* this context is waiting for a callback */
                   7921:           ctxt = TtaGetGenericStyleContext (doc);
                   7922:           if (ctxt == NULL)
                   7923:             return;
                   7924:           ctxt->destroy = destroy;
                   7925:           /* first use of the context */
                   7926:           ctxt->uses = 1; 
                   7927:         }
                   7928:       selector = ParseGenericSelector (selector, cssRule, ctxt, doc, css,
                   7929:                                        link, url);
                   7930:     }
1.207     vatton   7931:   /* check if the context can be freed */
                   7932:   ctxt->uses -= 1;
                   7933:   if (ctxt->uses == 0)
                   7934:     /* no image loading */
                   7935:     TtaFreeMemory (ctxt);
1.1       cvs      7936: }
                   7937: 
                   7938: /************************************************************************
                   7939:  *                                                                     *  
                   7940:  *     EVALUATION FUNCTIONS / CASCADING AND OVERLOADING                *
                   7941:  *                                                                     *  
                   7942:  ************************************************************************/
                   7943: 
                   7944: /*----------------------------------------------------------------------
1.327     vatton   7945:   IsImplicitClassName: return wether the Class name is an        
                   7946:   implicit one, eg "H1" or "H2 EM" meaning it's a GI name       
                   7947:   or an HTML context name.                                      
1.1       cvs      7948:   ----------------------------------------------------------------------*/
1.248     gully    7949: int IsImplicitClassName (char *class_, Document doc)
1.1       cvs      7950: {
1.327     vatton   7951:   char         name[200];
                   7952:   char        *cur = name;
                   7953:   char        *first; 
                   7954:   char         save;
                   7955:   SSchema      schema;
                   7956: 
                   7957:   /* make a local copy */
                   7958:   strncpy (name, class_, 199);
                   7959:   name[199] = 0;
                   7960: 
                   7961:   /* loop looking if each word is a GI */
                   7962:   while (*cur != 0)
                   7963:     {
                   7964:       first = cur;
                   7965:       cur = SkipWord (cur);
                   7966:       save = *cur;
                   7967:       *cur = 0;
                   7968:       schema = NULL;
                   7969:       if (MapGI (first, &schema, doc) == -1)
                   7970:         {
                   7971:           return (0);
                   7972:         }
                   7973:       *cur = save;
                   7974:       cur = SkipBlanksAndComments (cur);
                   7975:     }
                   7976:   return (1);
1.1       cvs      7977: }
                   7978: 
                   7979: /************************************************************************
1.114     quint    7980:  *  Functions needed for support of HTML: translate to CSS equivalent   *
1.1       cvs      7981:  ************************************************************************/
                   7982: 
                   7983: /*----------------------------------------------------------------------
1.409     vatton   7984:   SetBodyAbsolutePosition:
                   7985:   ----------------------------------------------------------------------*/
                   7986: void SetBodyAbsolutePosition (Document doc)
                   7987: {
                   7988:   Element              root, body;
                   7989:   ElementType          elType;
                   7990: 
                   7991:   if (DocumentTypes[doc] != docHTML)
                   7992:     return;
                   7993:   root = TtaGetMainRoot (doc);
                   7994:   elType =  TtaGetElementType(root);
                   7995:   elType.ElTypeNum = HTML_EL_BODY;
                   7996:   body = TtaSearchTypedElement (elType, SearchInTree, root);
                   7997:   if (body)
1.410     vatton   7998:     ParseHTMLSpecificStyle (body, (char *)"position:absolute", doc, 200, FALSE);
1.409     vatton   7999: }
                   8000: 
                   8001: /*----------------------------------------------------------------------
1.327     vatton   8002:   HTMLSetBackgroundColor:
1.1       cvs      8003:   ----------------------------------------------------------------------*/
1.264     vatton   8004: void HTMLSetBackgroundColor (Document doc, Element el, int specificity,
1.327     vatton   8005:                              char *color)
1.1       cvs      8006: {
1.350     vatton   8007:   char             css_command[1000];
1.1       cvs      8008: 
1.416     vatton   8009:   snprintf (css_command, 1000, "background-color: %50s", color);
1.327     vatton   8010:   ParseHTMLSpecificStyle (el, css_command, doc, specificity, FALSE);
1.1       cvs      8011: }
                   8012: 
                   8013: /*----------------------------------------------------------------------
1.327     vatton   8014:   HTMLSetForegroundColor:                                        
1.1       cvs      8015:   ----------------------------------------------------------------------*/
1.264     vatton   8016: void HTMLSetForegroundColor (Document doc, Element el, int specificity,
1.327     vatton   8017:                              char *color)
1.1       cvs      8018: {
1.350     vatton   8019:   char           css_command[1000];
1.1       cvs      8020: 
1.416     vatton   8021:   snprintf (css_command, 1000, "color: %50s", color);
1.327     vatton   8022:   ParseHTMLSpecificStyle (el, css_command, doc, specificity, FALSE);
1.1       cvs      8023: }
                   8024: 
                   8025: /*----------------------------------------------------------------------
1.327     vatton   8026:   HTMLResetBackgroundColor:                                      
1.1       cvs      8027:   ----------------------------------------------------------------------*/
1.97      vatton   8028: void HTMLResetBackgroundColor (Document doc, Element el)
1.1       cvs      8029: {
1.350     vatton   8030:   char           css_command[1000];
1.1       cvs      8031: 
1.327     vatton   8032:   sprintf (css_command, "background: red");
                   8033:   ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1       cvs      8034: }
                   8035: 
                   8036: /*----------------------------------------------------------------------
1.327     vatton   8037:   HTMLResetBackgroundImage:                                      
1.1       cvs      8038:   ----------------------------------------------------------------------*/
1.97      vatton   8039: void HTMLResetBackgroundImage (Document doc, Element el)
1.1       cvs      8040: {
1.327     vatton   8041:   char           css_command[1000];
1.1       cvs      8042: 
1.416     vatton   8043:   snprintf (css_command, 1000, "background-image: url(xx); background-repeat: repeat");
1.327     vatton   8044:   ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1       cvs      8045: }
                   8046: 
                   8047: /*----------------------------------------------------------------------
1.327     vatton   8048:   HTMLResetForegroundColor:                                      
1.1       cvs      8049:   ----------------------------------------------------------------------*/
1.97      vatton   8050: void HTMLResetForegroundColor (Document doc, Element el)
1.1       cvs      8051: {
1.350     vatton   8052:   char           css_command[1000];
1.1       cvs      8053: 
1.327     vatton   8054:   /* it's not necessary to well know the current color but it must be valid */
                   8055:   sprintf (css_command, "color: red");
                   8056:   ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1       cvs      8057: }
                   8058: 
                   8059: /*----------------------------------------------------------------------
1.327     vatton   8060:   HTMLSetAlinkColor:                                             
1.1       cvs      8061:   ----------------------------------------------------------------------*/
1.208     vatton   8062: void HTMLSetAlinkColor (Document doc, Element el, char *color)
1.1       cvs      8063: {
1.350     vatton   8064:   char           css_command[1000];
1.1       cvs      8065: 
1.416     vatton   8066:   snprintf (css_command, 1000, ":link { color: %50s }", color);
1.327     vatton   8067:   ApplyCSSRules (el, css_command, doc, FALSE);
1.1       cvs      8068: }
                   8069: 
                   8070: /*----------------------------------------------------------------------
1.327     vatton   8071:   HTMLSetAactiveColor:                                           
1.1       cvs      8072:   ----------------------------------------------------------------------*/
1.208     vatton   8073: void HTMLSetAactiveColor (Document doc, Element el, char *color)
1.1       cvs      8074: {
1.350     vatton   8075:   char           css_command[1000];
1.1       cvs      8076: 
1.416     vatton   8077:   snprintf (css_command, 1000, ":active { color: %50s }", color);
1.327     vatton   8078:   ApplyCSSRules (el, css_command, doc, FALSE);
1.1       cvs      8079: }
                   8080: 
                   8081: /*----------------------------------------------------------------------
1.327     vatton   8082:   HTMLSetAvisitedColor:                                          
1.1       cvs      8083:   ----------------------------------------------------------------------*/
1.208     vatton   8084: void HTMLSetAvisitedColor (Document doc, Element el, char *color)
1.1       cvs      8085: {
1.350     vatton   8086:   char           css_command[1000];
1.1       cvs      8087: 
1.416     vatton   8088:   snprintf (css_command, 1000, ":visited { color: %50s }", color);
1.327     vatton   8089:   ApplyCSSRules (el, css_command, doc, FALSE);
1.1       cvs      8090: }
                   8091: 
                   8092: /*----------------------------------------------------------------------
1.327     vatton   8093:   HTMLResetAlinkColor:                                           
1.1       cvs      8094:   ----------------------------------------------------------------------*/
1.208     vatton   8095: void HTMLResetAlinkColor (Document doc, Element el)
1.1       cvs      8096: {
1.350     vatton   8097:   char           css_command[1000];
1.1       cvs      8098: 
1.327     vatton   8099:   sprintf (css_command, ":link { color: red }");
                   8100:   ApplyCSSRules (el, css_command, doc, TRUE);
1.1       cvs      8101: }
                   8102: 
                   8103: /*----------------------------------------------------------------------
1.327     vatton   8104:   HTMLResetAactiveColor:                                                 
1.1       cvs      8105:   ----------------------------------------------------------------------*/
1.208     vatton   8106: void HTMLResetAactiveColor (Document doc, Element el)
1.1       cvs      8107: {
1.350     vatton   8108:   char           css_command[1000];
1.1       cvs      8109: 
1.327     vatton   8110:   sprintf (css_command, ":active { color: red }");
                   8111:   ApplyCSSRules (el, css_command, doc, TRUE);
1.1       cvs      8112: }
                   8113: 
                   8114: /*----------------------------------------------------------------------
1.327     vatton   8115:   HTMLResetAvisitedColor:                                        
1.1       cvs      8116:   ----------------------------------------------------------------------*/
1.208     vatton   8117: void HTMLResetAvisitedColor (Document doc, Element el)
1.1       cvs      8118: {
1.350     vatton   8119:   char           css_command[1000];
1.1       cvs      8120: 
1.327     vatton   8121:   sprintf (css_command, ":visited { color: red }");
                   8122:   ApplyCSSRules (el, css_command, doc, TRUE);
1.1       cvs      8123: }
                   8124: 
                   8125: /*----------------------------------------------------------------------
1.206     vatton   8126:   ApplyCSSRules: parse a CSS Style description stored in the header of
                   8127:   a HTML document.
1.1       cvs      8128:   ----------------------------------------------------------------------*/
1.79      cvs      8129: void ApplyCSSRules (Element el, char *cssRule, Document doc, ThotBool destroy)
1.1       cvs      8130: {
1.206     vatton   8131:   CSSInfoPtr          css;
                   8132:   PInfoPtr            pInfo;
1.207     vatton   8133:   ThotBool            loadcss;
                   8134: 
                   8135:   /* check if we have to load CSS */
                   8136:   TtaGetEnvBoolean ("LOAD_CSS", &loadcss);
                   8137:   if (!loadcss)
                   8138:     return;
1.376     vatton   8139:   LineNumber = TtaGetElementLineNumber (el);
1.206     vatton   8140:   css = SearchCSS (doc, NULL, el, &pInfo);
1.1       cvs      8141:   if (css == NULL)
1.209     vatton   8142:     {
                   8143:       /* create the document css context */
                   8144:       css = AddCSS (doc, doc, CSS_DOCUMENT_STYLE, CSS_ALL, NULL, NULL, el);
                   8145:       pInfo = css->infos[doc];
                   8146:     }
1.206     vatton   8147:   else if (pInfo == NULL)
                   8148:     /* create the entry into the css context */
                   8149:     pInfo = AddInfoCSS (doc, css, CSS_DOCUMENT_STYLE, CSS_ALL, el);
1.209     vatton   8150:   if (pInfo->PiEnabled)
1.376     vatton   8151:     ParseStyleDeclaration (el, cssRule, doc, css, el, NULL, destroy);
                   8152:   LineNumber = -1;
1.1       cvs      8153: }
                   8154: 
                   8155: /*----------------------------------------------------------------------
1.327     vatton   8156:   ReadCSSRules:  is the front-end function called by the document parser
                   8157:   when detecting a <style type="text/css"> indicating it's the
                   8158:   beginning of a CSS fragment or when reading a file .css.
1.1       cvs      8159:   
1.327     vatton   8160:   The CSS parser has to handle <!-- ... --> constructs used to
                   8161:   prevent prehistoric browser from displaying the CSS as a text
                   8162:   content. It will stop on any sequence "<x" where x is different
                   8163:   from ! and will return x as to the caller. Theorically x should
                   8164:   be equal to / for the </style> end of style.
                   8165:   The parameter doc gives the document tree that contains CSS information.
                   8166:   The parameter docRef gives the document to which CSS are to be applied.
                   8167:   This function uses the current css context or creates it. It's able
                   8168:   to work on the given buffer or call GetNextChar to read the parsed
                   8169:   file.
                   8170:   The parameter url gives the URL of the parsed style sheet.
                   8171:   The parameter numberOfLinesRead gives the number of lines already
                   8172:   read in the file.
                   8173:   The parameter withUndo indicates whether the changes made in the document
                   8174:   structure and content have to be registered in the Undo queue or not.
1.1       cvs      8175:   ----------------------------------------------------------------------*/
1.133     vatton   8176: char ReadCSSRules (Document docRef, CSSInfoPtr css, char *buffer, char *url,
1.343     vatton   8177:                    int numberOfLinesRead, ThotBool withUndo, Element link)
1.1       cvs      8178: {
1.6       cvs      8179:   DisplayMode         dispMode;
1.206     vatton   8180:   CSSInfoPtr          refcss = NULL;
1.321     vatton   8181:   CSSmedia            css_media = CSS_ALL;
1.206     vatton   8182:   PInfoPtr            pInfo;
1.321     vatton   8183:   char                c;
1.138     vatton   8184:   char               *cssRule, *base, *saveDocURL, *ptr;
1.19      cvs      8185:   int                 index;
1.1       cvs      8186:   int                 CSSindex;
1.327     vatton   8187:   int                 CSScomment;
1.1       cvs      8188:   int                 import;
1.358     quint    8189:   int                 openBlock;
1.93      vatton   8190:   int                 newlines;
1.358     quint    8191:   int                 page;
1.14      cvs      8192:   ThotBool            HTMLcomment;
1.342     vatton   8193:   ThotBool            toParse, eof, quoted, s_quoted;
1.358     quint    8194:   ThotBool            ignore, media, lineComment;
1.234     vatton   8195:   ThotBool            noRule, ignoreImport, fontface;
1.1       cvs      8196: 
1.327     vatton   8197:   CSScomment = MAX_CSS_LENGTH;
1.1       cvs      8198:   HTMLcomment = FALSE;
                   8199:   CSSindex = 0;
                   8200:   toParse = FALSE;
                   8201:   noRule = FALSE;
1.234     vatton   8202:   media = FALSE;
1.88      cvs      8203:   ignoreImport = FALSE;
1.342     vatton   8204:   ignore = lineComment = FALSE;
1.358     quint    8205:   page = 0;
1.342     vatton   8206:   quoted = s_quoted = FALSE;
1.234     vatton   8207:   fontface = FALSE;
1.1       cvs      8208:   eof = FALSE;
1.358     quint    8209:   openBlock = 0;
1.234     vatton   8210:   import = MAX_CSS_LENGTH;
1.82      cvs      8211:   c = SPACE;
1.1       cvs      8212:   index = 0;
1.134     vatton   8213:   base = NULL;
1.310     vatton   8214:   /* entering the CSS parsing */
1.311     vatton   8215:   Style_parsing++;
1.93      vatton   8216:   /* number of new lines parsed */
                   8217:   newlines = 0;
1.6       cvs      8218:   /* avoid too many redisplay */
                   8219:   dispMode = TtaGetDisplayMode (docRef);
                   8220:   if (dispMode == DisplayImmediately)
                   8221:     TtaSetDisplayMode (docRef, DeferredDisplay);
1.18      cvs      8222: 
                   8223:   /* look for the CSS context */
                   8224:   if (css == NULL)
1.206     vatton   8225:     css = SearchCSS (docRef, NULL, link, &pInfo);
1.207     vatton   8226:   else
                   8227:     pInfo = css->infos[docRef];
1.18      cvs      8228:   if (css == NULL)
1.206     vatton   8229:     {
                   8230:       css = AddCSS (docRef, docRef, CSS_DOCUMENT_STYLE, CSS_ALL, NULL, NULL, link);
                   8231:       pInfo = css->infos[docRef];
                   8232:     }
                   8233:   else if (pInfo == NULL)
                   8234:     pInfo = AddInfoCSS (docRef, css, CSS_DOCUMENT_STYLE, CSS_ALL, link);
1.174     vatton   8235:   /* look for the CSS descriptor that points to the extension schema */
                   8236:   refcss = css;
1.224     vatton   8237:   if (pInfo && pInfo->PiCategory == CSS_IMPORT)
1.173     cvs      8238:     {
1.206     vatton   8239:       while (refcss &&
1.327     vatton   8240:              refcss->infos[docRef] && refcss->infos[docRef]->PiCategory == CSS_IMPORT)
                   8241:         refcss = refcss->NextCSS;
1.206     vatton   8242:       if (refcss)
1.327     vatton   8243:         pInfo = refcss->infos[docRef];
1.173     cvs      8244:     }
                   8245: 
1.343     vatton   8246:   /* register parsed CSS file and the document to which CSS are to be applied */
1.395     vatton   8247:   if (DocumentMeta[docRef] == NULL || DocumentMeta[docRef]->method != CE_MAKEBOOK)
                   8248:     ParsedDoc = docRef;
                   8249:   else
                   8250:     ParsedDoc = 0;
1.343     vatton   8251:   /* clean up the list of classes */
                   8252:   TtaFreeMemory (refcss->class_list);
                   8253:   refcss->class_list = NULL;
1.133     vatton   8254:   if (url)
1.348     vatton   8255:     Error_DocURL = url;
1.86      cvs      8256:   else
                   8257:     /* the CSS source in within the document itself */
1.348     vatton   8258:     Error_DocURL = DocumentURLs[docRef];
1.86      cvs      8259:   LineNumber = numberOfLinesRead + 1;
1.93      vatton   8260:   NewLineSkipped = 0;
1.217     vatton   8261:   newlines = 0;
1.392     carcone  8262: 
                   8263:   /* Search for an UTF-8 BOM character (EF BB BF) */
                   8264:   if (index == 0 && strlen(buffer) > 2 &&
                   8265:       (unsigned char) buffer[0] == 0xEF &&
                   8266:       (unsigned char) buffer[1] == 0xBB &&
                   8267:       (unsigned char) buffer[2] == 0xBF)
                   8268:     {
                   8269:       index = 3;
                   8270:     }
                   8271: 
                   8272:   /* Search for an UTF-16 Big Endian BOM character (FE FF) */
                   8273:   if (index == 0 && strlen(buffer) > 1 &&
                   8274:       (unsigned char) buffer[0] == 0xFE &&
                   8275:       (unsigned char) buffer[1] == 0xFF)
                   8276:     {
                   8277:       index = 2;
                   8278:     }
                   8279: 
                   8280:   /* Search for an UTF-16 Little Endian BOM character (FF FE) */
                   8281:   if (index == 0 && strlen(buffer) > 1 &&
                   8282:       (unsigned char) buffer[0] == 0xFF &&
                   8283:       (unsigned char) buffer[1] == 0xFE)
                   8284:     {
                   8285:       index = 2;
                   8286:     }
                   8287:   
1.82      cvs      8288:   while (CSSindex < MAX_CSS_LENGTH && c != EOS && !eof)
                   8289:     {
                   8290:       c = buffer[index++];
                   8291:       eof = (c == EOS);
                   8292:       CSSbuffer[CSSindex] = c;
1.342     vatton   8293:       if (!lineComment &&
                   8294:           (CSScomment == MAX_CSS_LENGTH || c == '*' || c == '/' || c == '<' || c == EOL))
1.327     vatton   8295:         {
                   8296:           /* we're not within a comment or we're parsing * or / */
                   8297:           switch (c)
                   8298:             {
                   8299:             case '@': /* perhaps an import primitive */
1.342     vatton   8300:               if (!fontface && !page && !quoted && !s_quoted)
1.327     vatton   8301:                 import = CSSindex;
                   8302:               break;
                   8303:             case ';':
1.342     vatton   8304:               if (!quoted && !s_quoted && !media && import != MAX_CSS_LENGTH)
1.327     vatton   8305:                 { 
                   8306:                   if (strncasecmp (&CSSbuffer[import+1], "import", 6))
                   8307:                     /* it's not an import */
                   8308:                     import = MAX_CSS_LENGTH;
                   8309:                   /* save the text */
                   8310:                   noRule = TRUE;
                   8311:                 }
                   8312:               break;
                   8313:             case '*':
1.342     vatton   8314:               if (!quoted && !s_quoted && CSScomment == MAX_CSS_LENGTH && CSSindex > 0 &&
1.327     vatton   8315:                   CSSbuffer[CSSindex - 1] == '/')
                   8316:                 /* start a comment */
                   8317:                 CSScomment = CSSindex - 1;
                   8318:               break;
                   8319:             case '/':
1.342     vatton   8320:               if (!quoted && !s_quoted && CSSindex > 1 && CSScomment != MAX_CSS_LENGTH &&
1.399     vatton   8321:                   CSSbuffer[CSSindex - 1] == '*' && CSSindex != CSScomment + 2)
1.327     vatton   8322:                 {
                   8323:                   while (CSSindex > 0 && CSSindex >= CSScomment)
                   8324:                     {
                   8325:                       if ( CSSbuffer[CSSindex] == EOL)
                   8326:                         {
                   8327:                           LineNumber ++;
                   8328:                           newlines --;
                   8329:                         }
                   8330:                       CSSindex--;
                   8331:                     }
                   8332:                   CSSindex = CSScomment - 1; /* will be incremented later */
                   8333:                   CSScomment = MAX_CSS_LENGTH;
                   8334:                   /* clean up the buffer */
                   8335:                   if (newlines && CSSindex > 0)
                   8336:                     while (CSSindex > 0 &&
                   8337:                            (CSSbuffer[CSSindex] == SPACE ||
                   8338:                             CSSbuffer[CSSindex] == BSPACE ||
                   8339:                             CSSbuffer[CSSindex] == EOL ||
                   8340:                             CSSbuffer[CSSindex] == TAB ||
                   8341:                             CSSbuffer[CSSindex] == __CR__))
                   8342:                       {
                   8343:                         if ( CSSbuffer[CSSindex] == EOL)
                   8344:                           {
                   8345:                             LineNumber ++;
                   8346:                             newlines --;
                   8347:                           }
                   8348:                         CSSindex--;
                   8349:                       }
                   8350:                 }
1.342     vatton   8351:               else if (!fontface && !page && !quoted && !s_quoted &&
1.327     vatton   8352:                        CSScomment == MAX_CSS_LENGTH && CSSindex > 0 &&
                   8353:                        CSSbuffer[CSSindex - 1] ==  '<')
                   8354:                 {
                   8355:                   /* this is the closing tag ! */
                   8356:                   CSSindex -= 2; /* remove </ from the CSS string */
                   8357:                   noRule = TRUE;
1.342     vatton   8358:                 }
                   8359:               else if (!quoted && !s_quoted &&
                   8360:                        (CSSindex == 1 || (CSSindex > 1 && CSSbuffer[CSSindex - 2] == EOL))  &&
                   8361:                        CSScomment == MAX_CSS_LENGTH &&
                   8362:                        CSSbuffer[CSSindex - 1] == '/')
                   8363:                 {
                   8364:                   CSSindex--;
                   8365:                   lineComment = TRUE;
                   8366:                 }
                   8367:                 
1.327     vatton   8368:               break;
                   8369:             case '<':
1.342     vatton   8370:               if (!fontface && !page && !quoted && !s_quoted &&
1.327     vatton   8371:                   CSScomment == MAX_CSS_LENGTH)
                   8372:                 {
                   8373:                   /* only if we're not parsing a comment */
                   8374:                   c = buffer[index++];
                   8375:                   eof = (c == EOS);
                   8376:                   if (c == '!')
                   8377:                     {
                   8378:                       /* CSS within an HTML comment */
                   8379:                       HTMLcomment = TRUE;
                   8380:                       CSSindex++;
                   8381:                       CSSbuffer[CSSindex] = c;
                   8382:                     }
                   8383:                   else if (c == EOS)
                   8384:                     CSSindex++;
                   8385:                 }
                   8386:               break;
                   8387:             case '-':
1.342     vatton   8388:               if (!fontface && !page && !quoted && !s_quoted &&
1.327     vatton   8389:                   CSSindex > 0 && CSSbuffer[CSSindex - 1] == '-' &&
                   8390:                   HTMLcomment)
                   8391:                 /* CSS within an HTML comment */
                   8392:                 noRule = TRUE;
                   8393:               break;
                   8394:             case '>':
1.342     vatton   8395:               if (!fontface && !page && !quoted && !s_quoted && HTMLcomment)
1.327     vatton   8396:                 noRule = TRUE;
                   8397:               break;
                   8398:             case ' ':
1.358     quint    8399:               if (!quoted && !s_quoted && import != MAX_CSS_LENGTH && openBlock == 0)
1.327     vatton   8400:                 media = !strncasecmp (&CSSbuffer[import+1], "media", 5);
                   8401:               break;
                   8402:             case '{':
1.342     vatton   8403:               if (!quoted && !s_quoted)
1.327     vatton   8404:                 {
1.358     quint    8405:                   openBlock++;
1.327     vatton   8406:                   if (import != MAX_CSS_LENGTH)
                   8407:                     {
1.358     quint    8408:                       if (openBlock == 1 && media)
1.327     vatton   8409:                         {
                   8410:                           /* is it the screen concerned? */
                   8411:                           CSSbuffer[CSSindex+1] = EOS;
                   8412:                           css_media = CheckMediaCSS (&CSSbuffer[import+7]);
                   8413:                           if (TtaIsPrinting ())
                   8414:                             ignore = (css_media != CSS_ALL && css_media != CSS_PRINT);
                   8415:                           else
                   8416:                             ignore = (css_media != CSS_ALL && css_media != CSS_SCREEN);
                   8417:                           noRule = TRUE;
                   8418:                         }
                   8419:                       else if (!strncasecmp (&CSSbuffer[import+1], "page", 4))
1.358     quint    8420:                         /* it is a @page block */
1.327     vatton   8421:                         {
1.358     quint    8422:                           page = openBlock;/*remember the level of this block*/
1.327     vatton   8423:                           noRule = TRUE;
                   8424:                         }
                   8425:                       else if (!strncasecmp (&CSSbuffer[import+1], "font-face", 9))
                   8426:                         {
                   8427:                           fontface = TRUE;
                   8428:                           noRule = TRUE;
                   8429:                         }
                   8430:                     }
                   8431:                 }
                   8432:               break;
                   8433:             case '}':
1.342     vatton   8434:               if (!quoted && !s_quoted)
1.327     vatton   8435:                 {
1.358     quint    8436:                   if (page == openBlock)
                   8437:                     /* closing the @page block */
1.327     vatton   8438:                     {
                   8439:                       noRule = TRUE;
1.358     quint    8440:                       page = 0; /* close the page section */
1.327     vatton   8441:                     }
                   8442:                   else if (fontface)
                   8443:                     {
                   8444:                       noRule = TRUE;
                   8445:                       fontface = FALSE; /* close the fontface section */
                   8446:                     }
1.358     quint    8447:                   else if (openBlock == 1 && import != MAX_CSS_LENGTH)
1.327     vatton   8448:                     {
                   8449:                       import = MAX_CSS_LENGTH;
                   8450:                       noRule = TRUE;
                   8451:                       ignore = FALSE;
                   8452:                       media = FALSE;
                   8453:                     }
1.358     quint    8454:                   else if (!page)
1.327     vatton   8455:                     toParse = TRUE;
1.358     quint    8456:                   openBlock--;
1.327     vatton   8457:                 }
                   8458:               break;
                   8459:             case '"':
                   8460:               if (quoted)
                   8461:                 {
1.342     vatton   8462:                   if (CSSindex > 0 && CSSbuffer[CSSindex - 1] != '\\')
1.327     vatton   8463:                     quoted = FALSE;
                   8464:                 }
1.342     vatton   8465:               else if (!s_quoted)
1.327     vatton   8466:                 quoted = TRUE;
                   8467:               break;
1.342     vatton   8468:              case '\'':
                   8469:               if (s_quoted)
                   8470:                 {
                   8471:                   if (CSSindex > 0 && CSSbuffer[CSSindex - 1] != '\\')
                   8472:                     s_quoted = FALSE;
                   8473:                 }
                   8474:               else if (!quoted)
                   8475:                 s_quoted = TRUE;
                   8476:               break;
                   8477:            default:
1.327     vatton   8478:               if (c == EOL)
                   8479:                 {
                   8480:                   newlines++;
                   8481:                 }
                   8482:               break;
                   8483:             }
1.82      cvs      8484:         }
1.93      vatton   8485:       else if (c == EOL)
1.327     vatton   8486:         {
                   8487:           LineNumber++;
1.342     vatton   8488:           lineComment = FALSE;
1.411     vatton   8489:           c = __CR__;
1.327     vatton   8490:         }
1.234     vatton   8491: 
1.411     vatton   8492:       if (!lineComment && c != __CR__)
1.327     vatton   8493:         CSSindex++;
1.82      cvs      8494: 
                   8495:       if (CSSindex >= MAX_CSS_LENGTH && CSScomment < MAX_CSS_LENGTH)
1.327     vatton   8496:         /* we're still parsing a comment: remove the text comment */
                   8497:         CSSindex = CSScomment;
1.82      cvs      8498: 
                   8499:       if (CSSindex >= MAX_CSS_LENGTH || toParse || noRule)
1.327     vatton   8500:         {
                   8501:           CSSbuffer[CSSindex] = EOS;
                   8502:           /* parse a not empty string */
                   8503:           if (CSSindex > 0)
                   8504:             {
1.50      cvs      8505:               /* apply CSS rule if it's not just a saving of text */
1.234     vatton   8506:               if (!noRule && !ignore)
1.327     vatton   8507:                 {
                   8508:                   /* future import rules must be ignored */
                   8509:                   ignoreImport = TRUE;
                   8510:                   NewLineSkipped = 0;
                   8511:                   ParseStyleDeclaration (NULL, CSSbuffer, docRef, refcss,
                   8512:                                          pInfo->PiLink, url, FALSE);
                   8513:                   LineNumber += newlines;
                   8514:                   newlines = 0;
                   8515:                 }
1.82      cvs      8516:               else if (import != MAX_CSS_LENGTH &&
1.327     vatton   8517:                        !strncasecmp (&CSSbuffer[import+1], "import", 6))
                   8518:                 {
                   8519:                   /* import section */
                   8520:                   cssRule = &CSSbuffer[import+7];
1.405     kia      8521:                   cssRule = (char*)TtaSkipBlanks (cssRule);
1.327     vatton   8522:                   /* save the current line number */
                   8523:                   newlines += LineNumber;
                   8524:                   if (!strncasecmp (cssRule, "url", 3))
                   8525:                     {
1.50      cvs      8526:                       cssRule = &cssRule[3];
1.405     kia      8527:                       cssRule = (char*)TtaSkipBlanks (cssRule);
1.82      cvs      8528:                       if (*cssRule == '(')
1.327     vatton   8529:                         {
                   8530:                           cssRule++;
1.405     kia      8531:                           cssRule = (char*)TtaSkipBlanks (cssRule);
1.327     vatton   8532:                           quoted = (*cssRule == '"' || *cssRule == '\'');
                   8533:                           if (quoted)
                   8534:                             cssRule++;
                   8535:                           base = cssRule;
                   8536:                           while (*cssRule != EOS && *cssRule != ')')
                   8537:                             cssRule++;
                   8538:                           if (quoted)
                   8539:                             {
                   8540:                               /* isolate the file name */
                   8541:                               cssRule[-1] = EOS;
                   8542:                               quoted = FALSE;
                   8543:                             }
                   8544:                           else
                   8545:                             {
                   8546:                               /* remove extra spaces */
                   8547:                               if (cssRule[-1] == SPACE)
                   8548:                                 {
                   8549:                                   *cssRule = SPACE;
                   8550:                                   cssRule--;
                   8551:                                   while (cssRule[-1] == SPACE)
                   8552:                                     cssRule--;
                   8553:                                 }
                   8554:                             }
                   8555:                           *cssRule = EOS;
                   8556:                         }
                   8557:                     }
                   8558:                   else if (*cssRule == '"')
                   8559:                     {
                   8560:                       /*
                   8561:                         Do we have to accept single quotes?
                   8562:                         Double quotes are accepted here.
                   8563:                         Escaped quotes are not handled. See function SkipQuotedString
                   8564:                       */
                   8565:                       cssRule++;
1.405     kia      8566:                       cssRule = (char*)TtaSkipBlanks (cssRule);
1.327     vatton   8567:                       base = cssRule;
                   8568:                       while (*cssRule != EOS &&
                   8569:                              (*cssRule != '"' ||
                   8570:                               (*cssRule == '"' && cssRule[-1] == '\\')))
                   8571:                         cssRule++;
                   8572:                       /* isolate the file name */
                   8573:                       *cssRule = EOS;
                   8574:                     }
                   8575:                   /* check if a media is defined */
                   8576:                   cssRule++;
1.405     kia      8577:                   cssRule = (char*)TtaSkipBlanks (cssRule);
1.327     vatton   8578:                   if (*cssRule != ';')
                   8579:                     {
                   8580:                       css_media = CheckMediaCSS (cssRule);
                   8581:                       if (TtaIsPrinting ())
                   8582:                         ignoreImport = (css_media != CSS_ALL && css_media != CSS_PRINT);
                   8583:                       else
                   8584:                         ignoreImport = (css_media != CSS_ALL && css_media != CSS_SCREEN);
                   8585:                     }
                   8586:                   if (!ignoreImport)
                   8587:                     {
                   8588:                       /* save the displayed URL when an error is reported */
1.348     vatton   8589:                       saveDocURL = Error_DocURL;
1.327     vatton   8590:                       ptr = TtaStrdup (base);
                   8591:                       /* get the CSS URI in UTF-8 */
                   8592:                       /*ptr = ReallocUTF8String (ptr, docRef);*/
                   8593:                       LoadStyleSheet (base, docRef, (Element) css, css,
                   8594:                                       url, pInfo->PiMedia,
                   8595:                                       pInfo->PiCategory == CSS_USER_STYLE);
                   8596:                       /* restore the displayed URL when an error is reported */
1.348     vatton   8597:                       Error_DocURL = saveDocURL;
1.327     vatton   8598:                       TtaFreeMemory (ptr);
                   8599:                     }
                   8600:                   /* restore the number of lines */
                   8601:                   LineNumber = newlines;
                   8602:                   newlines = 0;
                   8603:                   NewLineSkipped = 0;
                   8604:                   import = MAX_CSS_LENGTH;
                   8605:                 }
                   8606:               else
                   8607:                 {
                   8608:                   LineNumber += newlines;
                   8609:                   newlines = 0;
                   8610:                 }
                   8611:             }
                   8612:           toParse = FALSE;
                   8613:           noRule = FALSE;
                   8614:           CSSindex = 0;
1.50      cvs      8615:         }
1.82      cvs      8616:     }
1.310     vatton   8617:   /* closing the CSS parsing */
1.311     vatton   8618:   Style_parsing--;
1.330     cvs      8619:   if (RedisplayImages == 0 && RedisplayBGImage && Style_parsing == 0)
1.310     vatton   8620:     {
1.311     vatton   8621:       /* CSS parsing finishes after a BG image was loaded */
1.310     vatton   8622:       RedisplayBGImage = FALSE;
1.330     cvs      8623:       if (dispMode != NoComputedDisplay)
                   8624:         {
                   8625:           //printf ("ReadCSS Show BGimages\n");
                   8626:           TtaSetDisplayMode (docRef, NoComputedDisplay);
                   8627:           TtaSetDisplayMode (docRef, dispMode);
                   8628:         }
1.310     vatton   8629:     }
1.330     cvs      8630:   else if (dispMode != NoComputedDisplay)
1.311     vatton   8631:     /* restore the display mode */
                   8632:     TtaSetDisplayMode (docRef, dispMode);
1.86      cvs      8633: 
                   8634:   /* Prepare the context for style attributes */
1.348     vatton   8635:   Error_DocURL = DocumentURLs[docRef];
1.86      cvs      8636:   LineNumber = -1;
1.1       cvs      8637:   return (c);
                   8638: }

Webmaster