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

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

Webmaster