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

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

Webmaster