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

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

Webmaster