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

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

Webmaster