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

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:         {
                   3376:           weight.typed_data.value = -3;
                   3377:           cssRule = SkipWord (cssRule);
                   3378:         }
                   3379:       else if (!strncasecmp (cssRule, "200", 3))
                   3380:         {
                   3381:           weight.typed_data.value = -2;
                   3382:           cssRule = SkipWord (cssRule);
                   3383:         }
                   3384:       else if (!strncasecmp (cssRule, "300", 3))
                   3385:         {
                   3386:           weight.typed_data.value = -1;
                   3387:           cssRule = SkipWord (cssRule);
                   3388:         }
                   3389:       else if (!strncasecmp (cssRule, "400", 3))
                   3390:         {
                   3391:           weight.typed_data.value = 0;
                   3392:           cssRule = SkipWord (cssRule);
                   3393:         }
                   3394:       else if (!strncasecmp (cssRule, "500", 3))
                   3395:         {
                   3396:           weight.typed_data.value = +1;
                   3397:           cssRule = SkipWord (cssRule);
                   3398:         }
                   3399:       else if (!strncasecmp (cssRule, "600", 3))
                   3400:         {
                   3401:           weight.typed_data.value = +2;
                   3402:           cssRule = SkipWord (cssRule);
                   3403:         }
                   3404:       else if (!strncasecmp (cssRule, "700", 3))
                   3405:         {
                   3406:           weight.typed_data.value = +3;
                   3407:           cssRule = SkipWord (cssRule);
                   3408:         }
                   3409:       else if (!strncasecmp (cssRule, "800", 3))
                   3410:         {
                   3411:           weight.typed_data.value = +4;
                   3412:           cssRule = SkipWord (cssRule);
                   3413:         }
                   3414:       else if (!strncasecmp (cssRule, "900", 3))
                   3415:         {
                   3416:           weight.typed_data.value = +5;
                   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:     }
                   3435:   else if (!strncasecmp (cssRule, "bolder", 6) ||
                   3436:            !strncasecmp (cssRule, "lighter", 7))
                   3437:     {
                   3438:       /* not implemented */
                   3439:       cssRule = SkipWord (cssRule);
                   3440:       return (cssRule);
                   3441:     }
                   3442:   else
                   3443:     return (cssRule);
                   3444: 
                   3445:   /*
                   3446:    * Here we have to reduce since only two font weight values are supported
                   3447:    * by the Thot presentation API.
                   3448:    */
                   3449:   if (weight.typed_data.unit != VALUE_INHERIT)
                   3450:     {
                   3451:       if (weight.typed_data.value > 0)
                   3452:         weight.typed_data.value = WeightBold;
                   3453:       else
                   3454:         weight.typed_data.value = WeightNormal;
                   3455:     }
                   3456: 
                   3457:   /* install the new presentation */
1.366     vatton   3458:   if (cssRule != ptr && DoDialog)
                   3459:     DisplayStyleValue ("font-weight", ptr, cssRule);
                   3460:   else if (DoApply)
1.327     vatton   3461:     TtaSetStylePresentation (PRWeight, element, tsch, context, weight);
                   3462:   return (cssRule);
                   3463: }
                   3464: 
                   3465: /*----------------------------------------------------------------------
                   3466:   ParseCSSFontWeight: parse a CSS font weight string   
                   3467:   we expect the input string describing the attribute to be     
                   3468:   normal, bold, bolder, lighter, 100, 200, 300, ... 900, inherit.
1.263     vatton   3469:   ----------------------------------------------------------------------*/
                   3470: static char *ParseCSSFontWeight (Element element, PSchema tsch,
1.327     vatton   3471:                                  PresentationContext context, char *cssRule,
                   3472:                                  CSSInfoPtr css, ThotBool isHTML)
1.263     vatton   3473: {
                   3474:   char           *ptr;
                   3475:   
1.366     vatton   3476:   cssRule = SkipBlanksAndComments (cssRule);
1.263     vatton   3477:   ptr = cssRule;
                   3478:   cssRule = ParseACSSFontWeight (element, tsch, context, cssRule, css, isHTML);
                   3479:   if (ptr == cssRule)
                   3480:     cssRule = SkipValue ("Invalid font-weight value", cssRule);
                   3481:   return (cssRule);
                   3482: }
                   3483: 
                   3484: /*----------------------------------------------------------------------
1.327     vatton   3485:   ParseACSSFontVariant: parse a CSS font variant string     
                   3486:   we expect the input string describing the attribute to be     
                   3487:   normal or small-caps
1.1       cvs      3488:   ----------------------------------------------------------------------*/
1.263     vatton   3489: static char *ParseACSSFontVariant (Element element, PSchema tsch,
1.327     vatton   3490:                                    PresentationContext context, char *cssRule,
                   3491:                                    CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      3492: {
1.327     vatton   3493:   PresentationValue   style;
1.366     vatton   3494:   char               *ptr;
1.1       cvs      3495: 
1.327     vatton   3496:   style.typed_data.value = 0;
                   3497:   style.typed_data.unit = UNIT_REL;
                   3498:   style.typed_data.real = FALSE;
                   3499:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   3500:   ptr = cssRule;
1.327     vatton   3501:   if (!strncasecmp (cssRule, "small-caps", 10))
                   3502:     {
                   3503:       /* Not supported yet */
                   3504:       cssRule = SkipWord (cssRule);
                   3505:     }
                   3506:   else if (!strncasecmp (cssRule, "normal", 6))
                   3507:     {
                   3508:       /* Not supported yet */
                   3509:       cssRule = SkipWord (cssRule);
                   3510:     }
                   3511:   else if (!strncasecmp (cssRule, "inherit", 7))
                   3512:     {
                   3513:       /* Not supported yet */
                   3514:       cssRule = SkipWord (cssRule);
                   3515:     }
1.366     vatton   3516:   if (cssRule != ptr && DoDialog)
                   3517:     DisplayStyleValue ("font-variant", ptr, cssRule);
1.295     vatton   3518:   return (cssRule);
1.263     vatton   3519: }
1.1       cvs      3520: 
1.263     vatton   3521: /*----------------------------------------------------------------------
1.327     vatton   3522:   ParseCSSFontVariant: parse a CSS font variant string     
                   3523:   we expect the input string describing the attribute to be     
                   3524:   normal or small-caps
1.263     vatton   3525:   ----------------------------------------------------------------------*/
                   3526: static char *ParseCSSFontVariant (Element element, PSchema tsch,
1.327     vatton   3527:                                   PresentationContext context, char *cssRule,
                   3528:                                   CSSInfoPtr css, ThotBool isHTML)
1.263     vatton   3529: {
                   3530:   char           *ptr;
                   3531:   
                   3532:   ptr = cssRule;
                   3533:   cssRule = ParseACSSFontVariant (element, tsch, context, cssRule, css, isHTML);
                   3534:   if (ptr == cssRule)
                   3535:     cssRule = SkipValue ("Invalid font-variant value", cssRule);
                   3536:   return (cssRule);
1.1       cvs      3537: }
                   3538: 
                   3539: 
                   3540: /*----------------------------------------------------------------------
1.327     vatton   3541:   ParseACSSFontStyle: parse a CSS font style string     
                   3542:   we expect the input string describing the attribute to be     
                   3543:   normal, italic, oblique or inherit                         
1.1       cvs      3544:   ----------------------------------------------------------------------*/
1.263     vatton   3545: static char *ParseACSSFontStyle (Element element, PSchema tsch,
1.327     vatton   3546:                                  PresentationContext context, char *cssRule,
                   3547:                                  CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      3548: {
1.327     vatton   3549:   PresentationValue   style;
                   3550:   PresentationValue   size;
1.366     vatton   3551:   PresentationValue   previous_size;
                   3552:   char               *ptr;
1.1       cvs      3553: 
1.327     vatton   3554:   style.typed_data.value = 0;
                   3555:   style.typed_data.unit = UNIT_REL;
                   3556:   style.typed_data.real = FALSE;
                   3557:   size.typed_data.value = 0;
                   3558:   size.typed_data.unit = UNIT_REL;
                   3559:   size.typed_data.real = FALSE;
                   3560:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   3561:   ptr = cssRule;
1.327     vatton   3562:   if (!strncasecmp (cssRule, "italic", 6))
                   3563:     {
                   3564:       style.typed_data.value = StyleItalics;
                   3565:       cssRule = SkipWord (cssRule);
                   3566:     }
                   3567:   else if (!strncasecmp (cssRule, "oblique", 7))
                   3568:     {
                   3569:       style.typed_data.value = StyleOblique;
                   3570:       cssRule = SkipWord (cssRule);
                   3571:     }
                   3572:   else if (!strncasecmp (cssRule, "normal", 6))
                   3573:     {
                   3574:       style.typed_data.value = StyleRoman;
                   3575:       cssRule = SkipWord (cssRule);
                   3576:     }
                   3577:   else if (!strncasecmp (cssRule, "inherit", 7))
                   3578:     {
                   3579:       style.typed_data.unit = VALUE_INHERIT;
                   3580:       cssRule = SkipWord (cssRule);
                   3581:     }
                   3582:   else
                   3583:     /* invalid font style */
                   3584:     return (cssRule);
                   3585: 
                   3586:   /*
                   3587:    * install the new presentation.
                   3588:    */
1.366     vatton   3589:   if (style.typed_data.value != 0 || style.typed_data.unit == VALUE_INHERIT)
1.327     vatton   3590:     {
1.366     vatton   3591:       if (DoDialog)
                   3592:         DisplayStyleValue ("font-style", ptr, cssRule);
                   3593:       else if (DoApply)
                   3594:         TtaSetStylePresentation (PRStyle, element, tsch, context, style);
1.327     vatton   3595:     }
1.366     vatton   3596:   if (size.typed_data.value != 0)
1.327     vatton   3597:     {
1.366     vatton   3598:       if (DoDialog)
                   3599:         DisplayStyleValue ("font-style", ptr, cssRule);
                   3600:       else if (DoApply)
1.327     vatton   3601:         {
1.366     vatton   3602:           if (!TtaGetStylePresentation (PRSize, element, tsch, context, &previous_size))
                   3603:             {
                   3604:               /* !!!!!!!!!!!!!!!!!!!!!!!! Unit + relative !!!!!!!!!!!!!!!! */
                   3605:               size.typed_data.value += previous_size.typed_data.value;
                   3606:               TtaSetStylePresentation (PRSize, element, tsch, context, size);
                   3607:             }
                   3608:           else
                   3609:             {
                   3610:               size.typed_data.value = 10;
                   3611:               TtaSetStylePresentation (PRSize, element, tsch, context, size);
                   3612:             }
1.327     vatton   3613:         }
                   3614:     }
                   3615:   return (cssRule);
                   3616: }
                   3617: 
                   3618: /*----------------------------------------------------------------------
                   3619:   ParseCSSFontStyle: parse a CSS font style string     
                   3620:   we expect the input string describing the attribute to be     
                   3621:   italic, oblique or normal                         
1.263     vatton   3622:   ----------------------------------------------------------------------*/
                   3623: static char *ParseCSSFontStyle (Element element, PSchema tsch,
1.327     vatton   3624:                                 PresentationContext context, char *cssRule,
                   3625:                                 CSSInfoPtr css, ThotBool isHTML)
1.263     vatton   3626: {
                   3627:   char           *ptr;
                   3628:   
                   3629:   ptr = cssRule;
                   3630:   cssRule = ParseACSSFontStyle (element, tsch, context, cssRule, css, isHTML);
                   3631:   if (ptr == cssRule)
                   3632:     cssRule = SkipValue ("Invalid font-style value", cssRule);
                   3633:   return (cssRule);
                   3634: }
                   3635: 
                   3636: /*----------------------------------------------------------------------
1.59      cvs      3637:   ParseCSSFont: parse a CSS font attribute string
                   3638:   we expect the input string describing the attribute to be
                   3639:   !!!!!!                                  
1.1       cvs      3640:   ----------------------------------------------------------------------*/
1.79      cvs      3641: static char *ParseCSSFont (Element element, PSchema tsch,
1.327     vatton   3642:                            PresentationContext context, char *cssRule,
                   3643:                            CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      3644: {
1.270     vatton   3645:   char           *ptr, *p;
1.366     vatton   3646:   char           *start_value;
1.93      vatton   3647:   int             skippedNL;
1.272     vatton   3648:   ThotBool        variant = FALSE, style = FALSE, weight = FALSE, found; 
1.1       cvs      3649: 
1.82      cvs      3650:   cssRule = SkipBlanksAndComments (cssRule);
                   3651:   if (!strncasecmp (cssRule, "caption", 7))
1.263     vatton   3652:     cssRule += 7;
1.82      cvs      3653:   else if (!strncasecmp (cssRule, "icon", 4))
1.263     vatton   3654:     cssRule += 4;
1.82      cvs      3655:   else if (!strncasecmp (cssRule, "menu", 4))
1.263     vatton   3656:     cssRule += 4;
1.82      cvs      3657:   else if (!strncasecmp (cssRule, "message-box", 11))
1.263     vatton   3658:     cssRule += 11;
1.82      cvs      3659:   else if (!strncasecmp (cssRule, "small-caption", 13))
1.263     vatton   3660:     cssRule += 13;
1.82      cvs      3661:   else if (!strncasecmp (cssRule, "status-bar", 10))
1.263     vatton   3662:     cssRule += 10;
                   3663:   else if (!strncasecmp (cssRule, "inherit", 7))
1.293     quint    3664:     {
                   3665:       ParseACSSFontStyle (element, tsch, context, cssRule, css, isHTML);
                   3666:       ParseACSSFontVariant (element, tsch, context, cssRule, css, isHTML);
                   3667:       ParseACSSFontWeight (element, tsch, context, cssRule, css, isHTML);
                   3668:       ParseACSSFontSize (element, tsch, context, cssRule, css, isHTML, FALSE);
1.366     vatton   3669:       cssRule = SkipBlanksAndComments (cssRule);
                   3670:       start_value = cssRule;
1.293     quint    3671:       ParseACSSFontFamily (element, tsch, context, cssRule, css, isHTML);
                   3672:       cssRule += 7;
1.366     vatton   3673:       if (DoDialog)
                   3674:         DisplayStyleValue ("font-family", start_value, cssRule);
1.293     quint    3675:     }
1.1       cvs      3676:   else
1.43      cvs      3677:     {
1.270     vatton   3678:       ptr = NULL;
                   3679:       p = cssRule;
1.301     vatton   3680:       while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && p == cssRule)
1.327     vatton   3681:         {
                   3682:           found = FALSE;
                   3683:           /* style, variant, weight can appear in any order */
                   3684:           ptr = cssRule;
                   3685:           skippedNL = NewLineSkipped;
                   3686:           cssRule = ParseACSSFontStyle (element, tsch, context, cssRule, css, isHTML);
                   3687:           if (ptr != cssRule)
                   3688:             {
                   3689:               skippedNL = NewLineSkipped;
                   3690:               found = TRUE;
                   3691:               style = TRUE;
                   3692:             }
                   3693:           else
                   3694:             NewLineSkipped = skippedNL;
                   3695:           ptr = cssRule;
                   3696:           cssRule = ParseACSSFontVariant (element, tsch, context, cssRule, css, isHTML);
                   3697:           if (ptr != cssRule)
                   3698:             {
                   3699:               skippedNL = NewLineSkipped;
                   3700:               found = TRUE;
                   3701:               variant = TRUE;
                   3702:             }
                   3703:           else
                   3704:             NewLineSkipped = skippedNL;
                   3705:           ptr = cssRule;
                   3706:           cssRule = ParseACSSFontWeight (element, tsch, context, cssRule, css, isHTML);
                   3707:           if (ptr != cssRule)
                   3708:             {
                   3709:               skippedNL = NewLineSkipped;
                   3710:               found = TRUE;
                   3711:               weight = TRUE;
                   3712:             }
                   3713:           else
                   3714:             NewLineSkipped = skippedNL;
                   3715:           cssRule = SkipBlanksAndComments (cssRule);
                   3716:           p = ParseACSSFontSize (element, tsch, context, cssRule, css, isHTML, TRUE);
                   3717:           NewLineSkipped = skippedNL;
                   3718:           if (!found)
                   3719:             /* break the loop when the current value was not parsed */
                   3720:             p = cssRule + 1;
                   3721:         }
1.263     vatton   3722:       ptr = cssRule;
1.270     vatton   3723:       /* set default variant, style, weight */
                   3724:       if (!variant)
1.327     vatton   3725:         ParseACSSFontVariant (element, tsch, context, "normal", css, isHTML);
1.270     vatton   3726:       if (!style)
1.327     vatton   3727:         ParseACSSFontStyle (element, tsch, context, "normal", css, isHTML);
1.270     vatton   3728:       if (!weight)
1.327     vatton   3729:         ParseACSSFontWeight (element, tsch, context, "normal", css, isHTML);
1.270     vatton   3730:       /* now parse the font size and the font family */
1.301     vatton   3731:       if (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS)
1.327     vatton   3732:         cssRule = ParseACSSFontSize (element, tsch, context, cssRule, css, isHTML, FALSE);
1.301     vatton   3733:       if (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS)
1.366     vatton   3734:         {
                   3735:           cssRule = SkipBlanksAndComments (cssRule);
                   3736:           start_value = cssRule;
                   3737:           cssRule = ParseACSSFontFamily (element, tsch, context, cssRule, css, isHTML);
                   3738:           if (DoDialog)
                   3739:             DisplayStyleValue ("font-family", start_value, cssRule);
                   3740:         }
1.263     vatton   3741:       if (ptr == cssRule)
1.360     vatton   3742:         cssRule = SkipValue ("Invalid font value", cssRule);
1.43      cvs      3743:     }
1.263     vatton   3744:   cssRule = SkipBlanksAndComments (cssRule);
1.301     vatton   3745:   if (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS)
1.360     vatton   3746:     cssRule = SkipValue ("Invalid font value", cssRule);
1.43      cvs      3747:   return (cssRule);
1.1       cvs      3748: }
                   3749: 
                   3750: /*----------------------------------------------------------------------
1.356     quint    3751:   ParseCSSTextDecoration: parse a CSS text-decoration value.
                   3752:   We expect the input string to be none, inherit or a combination of
                   3753:   underline, overline, line-through, and blink.
1.1       cvs      3754:   ----------------------------------------------------------------------*/
1.79      cvs      3755: static char *ParseCSSTextDecoration (Element element, PSchema tsch,
1.327     vatton   3756:                                      PresentationContext context, char *cssRule,
                   3757:                                      CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      3758: {
1.327     vatton   3759:   PresentationValue   decor;
1.366     vatton   3760:   char               *ptr;
1.356     quint    3761:   ThotBool            ok;
1.327     vatton   3762: 
                   3763:   decor.typed_data.value = 0;
                   3764:   decor.typed_data.unit = UNIT_REL;
                   3765:   decor.typed_data.real = FALSE;
                   3766:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   3767:   ptr = cssRule;
1.356     quint    3768:   ok = TRUE;
1.327     vatton   3769:   if (!strncasecmp (cssRule, "none", 4))
                   3770:     {
                   3771:       decor.typed_data.value = NoUnderline;
                   3772:       cssRule += 4;
                   3773:     }
                   3774:   else if (!strncasecmp (cssRule, "inherit", 7))
                   3775:     {
                   3776:       decor.typed_data.unit = VALUE_INHERIT;
                   3777:       cssRule += 7;
                   3778:     }
                   3779:   else
                   3780:     {
1.356     quint    3781:       do
                   3782:         {
                   3783:           if (!strncasecmp (cssRule, "underline", 9))
                   3784:             {
                   3785:               decor.typed_data.value = Underline;
                   3786:               cssRule += 9;
                   3787:             }
                   3788:           else if (!strncasecmp (cssRule, "overline", 8))
                   3789:             {
                   3790:               decor.typed_data.value = Overline;
                   3791:               cssRule += 8;
                   3792:             }
                   3793:           else if (!strncasecmp (cssRule, "line-through", 12))
                   3794:             {
                   3795:               decor.typed_data.value = CrossOut;
                   3796:               cssRule += 12;
                   3797:             }
                   3798:           else if (!strncasecmp (cssRule, "blink", 5))
                   3799:             {
                   3800:               /* the blink text-decoration attribute is not supported */
                   3801:               cssRule += 5;
                   3802:             }
                   3803:           else
                   3804:             ok = FALSE;
                   3805:           if (ok)
                   3806:             {
                   3807:               cssRule = SkipBlanksAndComments (cssRule);
                   3808:             }
                   3809:         }
                   3810:       while (ok && (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS));
                   3811:     }
                   3812:   if (!ok)
                   3813:     {
1.327     vatton   3814:       cssRule = SkipValue ("Invalid text-decoration value", cssRule);
                   3815:       return (cssRule);
                   3816:     }
1.1       cvs      3817: 
1.327     vatton   3818:   /*
                   3819:    * install the new presentation.
                   3820:    */
1.366     vatton   3821:   if (decor.typed_data.value || decor.typed_data.unit == VALUE_INHERIT)
                   3822:     {
                   3823:       if (DoDialog)
                   3824:         DisplayStyleValue ("text-decoration", ptr, cssRule);
                   3825:       else if (DoApply)
                   3826:         TtaSetStylePresentation (PRUnderline, element, tsch, context, decor);
                   3827:     }
1.327     vatton   3828:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid text-decoration value");
                   3829:   return (cssRule);
1.1       cvs      3830: }
                   3831: 
                   3832: /*----------------------------------------------------------------------
1.327     vatton   3833:   ParseCSSHeight: parse a CSS height attribute
1.1       cvs      3834:   ----------------------------------------------------------------------*/
1.79      cvs      3835: static char *ParseCSSHeight (Element element, PSchema tsch,
1.327     vatton   3836:                              PresentationContext context, char *cssRule,
                   3837:                              CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      3838: {
1.117     vatton   3839:   PresentationValue   val;
1.168     vatton   3840:   char               *ptr;
1.93      vatton   3841: 
1.370     vatton   3842:   val.typed_data.real = FALSE;
1.117     vatton   3843:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   3844:   ptr = cssRule;
1.117     vatton   3845:   /* first parse the attribute string */
1.164     quint    3846:   if (!strncasecmp (cssRule, "auto", 4))
                   3847:     {
1.184     vatton   3848:       val.typed_data.unit = VALUE_AUTO;
1.164     quint    3849:       val.typed_data.value = 0;
1.288     vatton   3850:       cssRule += 4;
                   3851:       cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid height value");
1.164     quint    3852:     }
1.117     vatton   3853:   else
1.168     vatton   3854:     cssRule = ParseCSSUnit (cssRule, &val);
1.295     vatton   3855: 
1.168     vatton   3856:   if (val.typed_data.value != 0 &&
1.184     vatton   3857:       (val.typed_data.unit == UNIT_INVALID ||
                   3858:        val.typed_data.unit == UNIT_BOX))
1.211     vatton   3859:     {
                   3860:       CSSParseError ("height value", ptr, cssRule);
1.212     cvs      3861:       val.typed_data.unit = UNIT_PX;
1.211     vatton   3862:     }
1.366     vatton   3863: 
                   3864:   if (DoDialog)
                   3865:     DisplayStyleValue ("height", ptr, cssRule);
                   3866:   else if (DoApply)
1.295     vatton   3867:     /* install the new presentation */
                   3868:     TtaSetStylePresentation (PRHeight, element, tsch, context, val);
1.117     vatton   3869:   return (cssRule);
1.1       cvs      3870: }
                   3871: 
                   3872: /*----------------------------------------------------------------------
1.327     vatton   3873:   ParseCSSWidth: parse a CSS width attribute
1.1       cvs      3874:   ----------------------------------------------------------------------*/
1.79      cvs      3875: static char *ParseCSSWidth (Element element, PSchema tsch,
1.327     vatton   3876:                             PresentationContext context,
                   3877:                             char *cssRule, CSSInfoPtr css,
                   3878:                             ThotBool isHTML)
1.1       cvs      3879: {
1.117     vatton   3880:   PresentationValue   val;
1.168     vatton   3881:   char               *ptr;
1.93      vatton   3882: 
1.370     vatton   3883:   val.typed_data.real = FALSE;
1.117     vatton   3884:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   3885:   ptr = cssRule;
1.117     vatton   3886:   /* first parse the attribute string */
1.164     quint    3887:   if (!strncasecmp (cssRule, "auto", 4))
                   3888:     {
1.184     vatton   3889:       val.typed_data.unit = VALUE_AUTO;
1.164     quint    3890:       val.typed_data.value = 0;
1.288     vatton   3891:       cssRule += 4;
                   3892:       cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid width value");
1.164     quint    3893:     }
1.117     vatton   3894:   else
1.327     vatton   3895:     cssRule = ParseCSSUnit (cssRule, &val);
1.168     vatton   3896:   if (val.typed_data.value != 0 &&
1.184     vatton   3897:       (val.typed_data.unit == UNIT_INVALID ||
                   3898:        val.typed_data.unit == UNIT_BOX))
1.211     vatton   3899:     {
                   3900:       CSSParseError ("Invalid width value", ptr, cssRule);
1.212     cvs      3901:       val.typed_data.unit = UNIT_PX;
1.211     vatton   3902:     }
1.295     vatton   3903: 
1.366     vatton   3904:   if (DoDialog)
                   3905:     DisplayStyleValue ("width", ptr, cssRule);
                   3906:   else if (DoApply)
1.295     vatton   3907:     /* install the new presentation */
                   3908:     TtaSetStylePresentation (PRWidth, element, tsch, context, val);
1.117     vatton   3909:   return (cssRule);
1.1       cvs      3910: }
                   3911: 
                   3912: /*----------------------------------------------------------------------
1.327     vatton   3913:   ParseACSSMarginTop: parse a CSS margin-top attribute
1.1       cvs      3914:   ----------------------------------------------------------------------*/
1.296     vatton   3915: static char *ParseACSSMarginTop (Element element, PSchema tsch,
1.327     vatton   3916:                                  PresentationContext context,
                   3917:                                  char *cssRule, CSSInfoPtr css,
                   3918:                                  ThotBool isHTML)
1.1       cvs      3919: {
                   3920:   PresentationValue   margin;
1.168     vatton   3921:   char               *ptr;
1.1       cvs      3922:   
1.370     vatton   3923:   margin.typed_data.real = FALSE;
1.82      cvs      3924:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   3925:   ptr = cssRule;
1.1       cvs      3926:   /* first parse the attribute string */
1.164     quint    3927:   if (!strncasecmp (cssRule, "auto", 4))
                   3928:     {
1.184     vatton   3929:       margin.typed_data.unit = VALUE_AUTO;
1.164     quint    3930:       margin.typed_data.value = 0;
1.288     vatton   3931:       cssRule += 4;
1.164     quint    3932:     }
                   3933:   else
1.168     vatton   3934:     cssRule = ParseCSSUnit (cssRule, &margin);
1.295     vatton   3935: 
1.168     vatton   3936:   if (margin.typed_data.value != 0 &&
1.184     vatton   3937:       (margin.typed_data.unit == UNIT_INVALID ||
                   3938:        margin.typed_data.unit == UNIT_BOX))
1.169     vatton   3939:     CSSParseError ("Invalid margin-top value", ptr, cssRule);
1.366     vatton   3940:   else if (DoDialog)
                   3941:     {
                   3942:       if (All_sides)
                   3943:         DisplayStyleValue ("margin", ptr, cssRule);
                   3944:       else
                   3945:         DisplayStyleValue ("margin-top", ptr, cssRule);
                   3946:     }
1.168     vatton   3947:   else if (DoApply)
1.295     vatton   3948:     TtaSetStylePresentation (PRMarginTop, element, tsch, context, margin);
1.1       cvs      3949:   return (cssRule);
                   3950: }
                   3951: 
                   3952: /*----------------------------------------------------------------------
1.327     vatton   3953:   ParseCSSMarginTop: parse a CSS margin-top attribute
1.296     vatton   3954:   ----------------------------------------------------------------------*/
                   3955: static char *ParseCSSMarginTop (Element element, PSchema tsch,
1.327     vatton   3956:                                 PresentationContext context,
                   3957:                                 char *cssRule, CSSInfoPtr css,
                   3958:                                 ThotBool isHTML)
1.296     vatton   3959: {
                   3960:   char *ptr = cssRule;
                   3961: 
                   3962:   cssRule = ParseACSSMarginTop (element, tsch, context, ptr, css, isHTML);
                   3963:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid margin-top value");
                   3964:   return (cssRule);
                   3965: }
                   3966: 
                   3967: /*----------------------------------------------------------------------
                   3968:   ParseACSSMarginBottom: parse a CSS margin-bottom attribute
1.1       cvs      3969:   ----------------------------------------------------------------------*/
1.296     vatton   3970: static char *ParseACSSMarginBottom (Element element, PSchema tsch,
1.327     vatton   3971:                                     PresentationContext context,
                   3972:                                     char *cssRule, CSSInfoPtr css,
                   3973:                                     ThotBool isHTML)
1.1       cvs      3974: {
                   3975:   PresentationValue   margin;
1.168     vatton   3976:   char               *ptr;
1.1       cvs      3977:   
1.370     vatton   3978:   margin.typed_data.real = FALSE;
1.82      cvs      3979:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   3980:   ptr = cssRule;
1.1       cvs      3981:   /* first parse the attribute string */
1.164     quint    3982:   if (!strncasecmp (cssRule, "auto", 4))
                   3983:     {
1.184     vatton   3984:       margin.typed_data.unit = VALUE_AUTO;
1.164     quint    3985:       margin.typed_data.value = 0;
1.288     vatton   3986:       cssRule += 4;
1.164     quint    3987:     }
                   3988:   else
1.168     vatton   3989:     cssRule = ParseCSSUnit (cssRule, &margin);
1.295     vatton   3990: 
1.168     vatton   3991:   if (margin.typed_data.value != 0 &&
1.184     vatton   3992:       (margin.typed_data.unit == UNIT_INVALID ||
                   3993:        margin.typed_data.unit == UNIT_BOX))
1.169     vatton   3994:     CSSParseError ("Invalid margin-bottom value", ptr, cssRule);
1.366     vatton   3995:   else if (DoDialog)
                   3996:     DisplayStyleValue ("margin-bottom", ptr, cssRule);
1.168     vatton   3997:   else if (DoApply)
1.295     vatton   3998:     TtaSetStylePresentation (PRMarginBottom, element, tsch, context, margin);
1.1       cvs      3999:   return (cssRule);
                   4000: }
                   4001: 
                   4002: /*----------------------------------------------------------------------
1.296     vatton   4003:   ParseCSSMarginBottom: parse a CSS margin-bottom attribute
                   4004:   ----------------------------------------------------------------------*/
                   4005: static char *ParseCSSMarginBottom (Element element, PSchema tsch,
1.327     vatton   4006:                                    PresentationContext context,
                   4007:                                    char *cssRule, CSSInfoPtr css,
                   4008:                                    ThotBool isHTML)
1.296     vatton   4009: {
                   4010:   char *ptr = cssRule;
                   4011: 
                   4012:   cssRule = ParseACSSMarginBottom (element, tsch, context, ptr, css, isHTML);
                   4013:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid margin-bottom value");
                   4014:   return (cssRule);
                   4015: }
                   4016: 
                   4017: /*----------------------------------------------------------------------
                   4018:   ParseACSSMarginLeft: parse a CSS margin-left attribute string
1.1       cvs      4019:   ----------------------------------------------------------------------*/
1.296     vatton   4020: static char *ParseACSSMarginLeft (Element element, PSchema tsch,
1.327     vatton   4021:                                   PresentationContext context,
                   4022:                                   char *cssRule, CSSInfoPtr css,
                   4023:                                   ThotBool isHTML)
1.1       cvs      4024: {
                   4025:   PresentationValue   margin;
1.168     vatton   4026:   char               *ptr;
1.1       cvs      4027:   
1.370     vatton   4028:   margin.typed_data.real = FALSE;
1.82      cvs      4029:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   4030:   ptr = cssRule;
1.1       cvs      4031:   /* first parse the attribute string */
1.164     quint    4032:   if (!strncasecmp (cssRule, "auto", 4))
                   4033:     {
1.184     vatton   4034:       margin.typed_data.unit = VALUE_AUTO;
1.164     quint    4035:       margin.typed_data.value = 0;
1.288     vatton   4036:       cssRule += 4;
1.164     quint    4037:     }
                   4038:   else
1.168     vatton   4039:     cssRule = ParseCSSUnit (cssRule, &margin);
1.295     vatton   4040: 
1.168     vatton   4041:   if (margin.typed_data.value != 0 &&
1.184     vatton   4042:       (margin.typed_data.unit == UNIT_INVALID ||
                   4043:        margin.typed_data.unit == UNIT_BOX))
1.169     vatton   4044:     CSSParseError ("Invalid margin-left value", ptr, cssRule);
1.366     vatton   4045:   else if (DoDialog)
                   4046:     DisplayStyleValue ("margin-left", ptr, cssRule);
1.295     vatton   4047:   else if (DoApply && margin.typed_data.unit != UNIT_INVALID && DoApply)
1.327     vatton   4048:     TtaSetStylePresentation (PRMarginLeft, element, tsch, context, margin);
1.1       cvs      4049:   return (cssRule);
                   4050: }
                   4051: 
                   4052: /*----------------------------------------------------------------------
1.296     vatton   4053:   ParseCSSMarginBottom: parse a CSS margin-bottom attribute
                   4054:   ----------------------------------------------------------------------*/
                   4055: static char *ParseCSSMarginLeft (Element element, PSchema tsch,
1.327     vatton   4056:                                  PresentationContext context,
                   4057:                                  char *cssRule, CSSInfoPtr css,
                   4058:                                  ThotBool isHTML)
1.296     vatton   4059: {
                   4060:   char *ptr = cssRule;
                   4061: 
                   4062:   cssRule = ParseACSSMarginLeft (element, tsch, context, ptr, css, isHTML);
                   4063:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid margin-left value");
                   4064:   return (cssRule);
                   4065: }
                   4066: 
                   4067: 
                   4068: /*----------------------------------------------------------------------
                   4069:   ParseACSSMarginRight: parse a CSS margin-right attribute string
1.1       cvs      4070:   ----------------------------------------------------------------------*/
1.296     vatton   4071: static char *ParseACSSMarginRight (Element element, PSchema tsch,
1.327     vatton   4072:                                    PresentationContext context,
                   4073:                                    char *cssRule, CSSInfoPtr css,
                   4074:                                    ThotBool isHTML)
1.1       cvs      4075: {
                   4076:   PresentationValue   margin;
1.168     vatton   4077:   char               *ptr;
1.1       cvs      4078:   
1.370     vatton   4079:   margin.typed_data.real = FALSE;
1.82      cvs      4080:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   4081:   ptr = cssRule;
1.1       cvs      4082:   /* first parse the attribute string */
1.164     quint    4083:   if (!strncasecmp (cssRule, "auto", 4))
                   4084:     {
1.184     vatton   4085:       margin.typed_data.unit = VALUE_AUTO;
1.164     quint    4086:       margin.typed_data.value = 0;
1.288     vatton   4087:       cssRule += 4;
1.164     quint    4088:     }
                   4089:   else
1.168     vatton   4090:     cssRule = ParseCSSUnit (cssRule, &margin);
1.295     vatton   4091: 
1.168     vatton   4092:   if (margin.typed_data.value != 0 &&
1.184     vatton   4093:       (margin.typed_data.unit == UNIT_INVALID ||
                   4094:        margin.typed_data.unit == UNIT_BOX))
1.169     vatton   4095:     CSSParseError ("Invalid margin-right value", ptr, cssRule);
1.366     vatton   4096:   else if (DoDialog)
                   4097:     DisplayStyleValue ("margin-right", ptr, cssRule);
1.168     vatton   4098:   else if (DoApply)
1.295     vatton   4099:     TtaSetStylePresentation (PRMarginRight, element, tsch, context, margin);
1.1       cvs      4100:   return (cssRule);
                   4101: }
                   4102: 
                   4103: /*----------------------------------------------------------------------
1.296     vatton   4104:   ParseCSSMarginRight: parse a CSS margin-right attribute string
                   4105:   ----------------------------------------------------------------------*/
                   4106: static char *ParseCSSMarginRight (Element element, PSchema tsch,
1.327     vatton   4107:                                   PresentationContext context,
                   4108:                                   char *cssRule, CSSInfoPtr css,
                   4109:                                   ThotBool isHTML)
1.296     vatton   4110: {
                   4111:   char *ptr = cssRule;
                   4112: 
1.297     vatton   4113:   cssRule = ParseACSSMarginRight (element, tsch, context, ptr, css, isHTML);
1.296     vatton   4114:   cssRule = CSSCheckEndValue (ptr, cssRule, "Invalid margin-right value");
                   4115:   return (cssRule);
                   4116: }
                   4117: 
                   4118: /*----------------------------------------------------------------------
1.59      cvs      4119:   ParseCSSMargin: parse a CSS margin attribute string
1.1       cvs      4120:   ----------------------------------------------------------------------*/
1.79      cvs      4121: static char *ParseCSSMargin (Element element, PSchema tsch,
1.327     vatton   4122:                              PresentationContext context,
                   4123:                              char *cssRule, CSSInfoPtr css,
                   4124:                              ThotBool isHTML)
1.1       cvs      4125: {
1.79      cvs      4126:   char *ptrT, *ptrR, *ptrB, *ptrL;
1.366     vatton   4127:   int   skippedNL, n;
1.1       cvs      4128: 
1.82      cvs      4129:   ptrT = SkipBlanksAndComments (cssRule);
1.366     vatton   4130:   if (DoDialog)
                   4131:     n = NumberOfValues (ptrT);
                   4132:   if (DoDialog && n < 2)
1.1       cvs      4133:     {
1.366     vatton   4134:       // check if the margin dialog must be updated
                   4135:       All_sides = TRUE;
                   4136:       ptrR = ParseACSSMarginTop (element, tsch, context, ptrT, css, isHTML);
                   4137:       All_sides = FALSE;
1.1       cvs      4138:     }
                   4139:   else
                   4140:     {
1.366     vatton   4141:       /* First parse Margin-Top */
                   4142:       ptrR = ParseACSSMarginTop (element, tsch, context, ptrT, css, isHTML);
                   4143:       ptrR = SkipBlanksAndComments (ptrR);
                   4144:       if (*ptrR == ';' || *ptrR == '}' || *ptrR == EOS || *ptrR == ',')
1.327     vatton   4145:         {
                   4146:           skippedNL = NewLineSkipped;
1.366     vatton   4147:           cssRule = ptrR;
                   4148:           /* apply the Margin-Top to all */
                   4149:           ptrR = ParseACSSMarginRight (element, tsch, context, ptrT, css, isHTML);
1.327     vatton   4150:           NewLineSkipped = skippedNL;
1.366     vatton   4151:           ptrR = ParseACSSMarginBottom (element, tsch, context, ptrT, css, isHTML);
                   4152:           NewLineSkipped = skippedNL;
                   4153:           ptrR = ParseACSSMarginLeft (element, tsch, context, ptrT, css, isHTML);
1.327     vatton   4154:         }
1.1       cvs      4155:       else
1.327     vatton   4156:         {
1.366     vatton   4157:           /* parse Margin-Right */
                   4158:           ptrB = ParseACSSMarginRight (element, tsch, context, ptrR, css, isHTML);
                   4159:           ptrB = SkipBlanksAndComments (ptrB);
                   4160:           if (*ptrB == ';' || *ptrB == '}' || *ptrB == EOS || *ptrB == ',')
1.327     vatton   4161:             {
1.366     vatton   4162:               skippedNL = NewLineSkipped;
                   4163:               cssRule = ptrB;
                   4164:               /* apply the Margin-Top to Margin-Bottom */
                   4165:               ptrB = ParseACSSMarginBottom (element, tsch, context, ptrT, css, isHTML);
                   4166:               NewLineSkipped = skippedNL;
1.327     vatton   4167:               /* apply the Margin-Right to Margin-Left */
1.366     vatton   4168:               ptrB = ParseACSSMarginLeft (element, tsch, context, ptrR, css, isHTML);
1.327     vatton   4169:             }
                   4170:           else
1.366     vatton   4171:             {
                   4172:               /* parse Margin-Bottom */
                   4173:               ptrL = ParseACSSMarginBottom (element, tsch, context, ptrB, css, isHTML);
                   4174:               ptrL = SkipBlanksAndComments (ptrL);
                   4175:               if (*ptrL == ';' || *ptrL == '}' || *ptrL == EOS || *ptrL == ',')
                   4176:                 {
                   4177:                   cssRule = ptrL;
                   4178:                   /* apply the Margin-Right to Margin-Left */
                   4179:                   ptrL = ParseACSSMarginLeft (element, tsch, context, ptrR, css, isHTML);
                   4180:                 }
                   4181:               else
                   4182:                 /* parse Margin-Left */
                   4183:                 cssRule = ParseACSSMarginLeft (element, tsch, context, ptrL, css, isHTML);
                   4184:               cssRule = SkipBlanksAndComments (cssRule);
                   4185:             }
1.327     vatton   4186:         }
1.1       cvs      4187:     }
                   4188:   return (cssRule);
                   4189: }
                   4190: 
                   4191: /*----------------------------------------------------------------------
1.327     vatton   4192:   ParseCSSPaddingTop: parse a CSS PaddingTop attribute string
1.1       cvs      4193:   ----------------------------------------------------------------------*/
1.79      cvs      4194: static char *ParseCSSPaddingTop (Element element, PSchema tsch,
1.327     vatton   4195:                                  PresentationContext context,
                   4196:                                  char *cssRule, CSSInfoPtr css,
                   4197:                                  ThotBool isHTML)
1.1       cvs      4198: {
1.43      cvs      4199:   PresentationValue   padding;
1.168     vatton   4200:   char               *ptr;
1.370     vatton   4201:  
                   4202:   padding.typed_data.real = FALSE;
1.82      cvs      4203:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   4204:   ptr = cssRule;
1.43      cvs      4205:   /* first parse the attribute string */
                   4206:   cssRule = ParseCSSUnit (cssRule, &padding);
1.295     vatton   4207: 
1.168     vatton   4208:   if (padding.typed_data.value != 0 &&
1.184     vatton   4209:       (padding.typed_data.unit == UNIT_INVALID ||
                   4210:        padding.typed_data.unit == UNIT_BOX))
1.168     vatton   4211:     {
1.169     vatton   4212:       CSSParseError ("Invalid padding-top value", ptr, cssRule);
1.168     vatton   4213:       padding.typed_data.value = 0;
                   4214:     }
1.366     vatton   4215:   else if (DoDialog)
                   4216:     {
                   4217:       if (All_sides)
                   4218:         DisplayStyleValue ("padding", ptr, cssRule);
                   4219:       else
                   4220:         DisplayStyleValue ("padding-top", ptr, cssRule);
                   4221:     }
1.168     vatton   4222:   else if (DoApply)
1.295     vatton   4223:     TtaSetStylePresentation (PRPaddingTop, element, tsch, context, padding);
1.1       cvs      4224:   return (cssRule);
                   4225: }
                   4226: 
                   4227: /*----------------------------------------------------------------------
1.59      cvs      4228:   ParseCSSPaddingBottom: parse a CSS PaddingBottom attribute string
1.1       cvs      4229:   ----------------------------------------------------------------------*/
1.79      cvs      4230: static char *ParseCSSPaddingBottom (Element element, PSchema tsch,
1.327     vatton   4231:                                     PresentationContext context,
                   4232:                                     char *cssRule, CSSInfoPtr css,
                   4233:                                     ThotBool isHTML)
1.1       cvs      4234: {
1.43      cvs      4235:   PresentationValue   padding;
1.168     vatton   4236:   char               *ptr;
1.43      cvs      4237:   
1.370     vatton   4238:   padding.typed_data.real = FALSE;
1.82      cvs      4239:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   4240:   ptr = cssRule;
1.43      cvs      4241:   /* first parse the attribute string */
                   4242:   cssRule = ParseCSSUnit (cssRule, &padding);
1.168     vatton   4243:   if (padding.typed_data.value == 0)
1.184     vatton   4244:     padding.typed_data.unit = UNIT_EM;
1.295     vatton   4245: 
1.168     vatton   4246:   if (padding.typed_data.value != 0 &&
1.184     vatton   4247:       (padding.typed_data.unit == UNIT_INVALID ||
                   4248:        padding.typed_data.unit == UNIT_BOX))
1.168     vatton   4249:     {
1.169     vatton   4250:       CSSParseError ("Invalid padding-bottom value", ptr, cssRule);
1.168     vatton   4251:       padding.typed_data.value = 0;
                   4252:     }
1.366     vatton   4253:   else if (DoDialog)
                   4254:     DisplayStyleValue ("padding-bottom", ptr, cssRule);
1.168     vatton   4255:   else if (DoApply)
1.295     vatton   4256:     TtaSetStylePresentation (PRPaddingBottom, element, tsch, context, padding);
1.1       cvs      4257:   return (cssRule);
                   4258: }
                   4259: 
                   4260: /*----------------------------------------------------------------------
1.59      cvs      4261:   ParseCSSPaddingLeft: parse a CSS PaddingLeft attribute string.
1.1       cvs      4262:   ----------------------------------------------------------------------*/
1.79      cvs      4263: static char *ParseCSSPaddingLeft (Element element, PSchema tsch,
1.327     vatton   4264:                                   PresentationContext context,
                   4265:                                   char *cssRule, CSSInfoPtr css,
                   4266:                                   ThotBool isHTML)
1.1       cvs      4267: {
1.43      cvs      4268:   PresentationValue   padding;
1.168     vatton   4269:   char               *ptr;
1.43      cvs      4270:   
1.370     vatton   4271:   padding.typed_data.real = FALSE;
1.82      cvs      4272:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   4273:   ptr = cssRule;
1.43      cvs      4274:   /* first parse the attribute string */
                   4275:   cssRule = ParseCSSUnit (cssRule, &padding);
1.168     vatton   4276:   if (padding.typed_data.value == 0)
1.184     vatton   4277:     padding.typed_data.unit = UNIT_EM;
1.295     vatton   4278: 
1.168     vatton   4279:   if (padding.typed_data.value != 0 &&
1.184     vatton   4280:       (padding.typed_data.unit == UNIT_INVALID ||
                   4281:        padding.typed_data.unit == UNIT_BOX))
1.168     vatton   4282:     {
1.169     vatton   4283:       CSSParseError ("Invalid padding-left value", ptr, cssRule);
1.168     vatton   4284:       padding.typed_data.value = 0;
                   4285:     }
1.366     vatton   4286:   else if (DoDialog)
                   4287:     DisplayStyleValue ("padding-left", ptr, cssRule);
1.168     vatton   4288:   else if (DoApply)
1.295     vatton   4289:     TtaSetStylePresentation (PRPaddingLeft, element, tsch, context, padding);
1.1       cvs      4290:   return (cssRule);
                   4291: }
                   4292: 
                   4293: /*----------------------------------------------------------------------
1.59      cvs      4294:   ParseCSSPaddingRight: parse a CSS PaddingRight attribute string.
1.1       cvs      4295:   ----------------------------------------------------------------------*/
1.79      cvs      4296: static char *ParseCSSPaddingRight (Element element, PSchema tsch,
1.327     vatton   4297:                                    PresentationContext context,
                   4298:                                    char *cssRule, CSSInfoPtr css,
                   4299:                                    ThotBool isHTML)
1.1       cvs      4300: {
1.43      cvs      4301:   PresentationValue   padding;
1.168     vatton   4302:   char               *ptr;
1.43      cvs      4303:   
1.370     vatton   4304:   padding.typed_data.real = FALSE;
1.82      cvs      4305:   cssRule = SkipBlanksAndComments (cssRule);
1.168     vatton   4306:   ptr = cssRule;
1.43      cvs      4307:   /* first parse the attribute string */
                   4308:   cssRule = ParseCSSUnit (cssRule, &padding);
1.168     vatton   4309:   if (padding.typed_data.value == 0)
1.184     vatton   4310:     padding.typed_data.unit = UNIT_EM;
1.295     vatton   4311: 
1.168     vatton   4312:   if (padding.typed_data.value != 0 &&
1.184     vatton   4313:       (padding.typed_data.unit == UNIT_INVALID ||
                   4314:        padding.typed_data.unit == UNIT_BOX))
1.168     vatton   4315:     {
1.169     vatton   4316:       CSSParseError ("Invalid padding-right value", ptr, cssRule);
1.168     vatton   4317:       padding.typed_data.value = 0;
                   4318:     }
1.366     vatton   4319:   else if (DoDialog)
                   4320:     DisplayStyleValue ("padding-right", ptr, cssRule);
1.168     vatton   4321:   else if (DoApply)
1.295     vatton   4322:     TtaSetStylePresentation (PRPaddingRight, element, tsch, context, padding);
1.1       cvs      4323:   return (cssRule);
                   4324: }
                   4325: 
                   4326: /*----------------------------------------------------------------------
1.327     vatton   4327:   ParseCSSPadding: parse a CSS padding attribute string. 
1.1       cvs      4328:   ----------------------------------------------------------------------*/
1.79      cvs      4329: static char *ParseCSSPadding (Element element, PSchema tsch,
1.327     vatton   4330:                               PresentationContext context,
                   4331:                               char *cssRule, CSSInfoPtr css,
                   4332:                               ThotBool isHTML)
1.1       cvs      4333: {
1.79      cvs      4334:   char *ptrT, *ptrR, *ptrB, *ptrL;
1.366     vatton   4335:   int   skippedNL, n;
1.43      cvs      4336: 
1.82      cvs      4337:   ptrT = SkipBlanksAndComments (cssRule);
1.366     vatton   4338:   if (DoDialog)
                   4339:     n = NumberOfValues (ptrT);
                   4340:   if (DoDialog && n < 2)
1.43      cvs      4341:     {
1.366     vatton   4342:       // check if the padding dialog must be updated
                   4343:       All_sides = TRUE;
                   4344:       ptrR = ParseCSSPaddingTop (element, tsch, context, ptrT, css, isHTML);
                   4345:       All_sides = FALSE;
1.43      cvs      4346:     }
                   4347:   else
                   4348:     {
1.366     vatton   4349:       /* First parse Padding-Top */
                   4350:       ptrR = ParseCSSPaddingTop (element, tsch, context, ptrT, css, isHTML);
                   4351:       ptrR = SkipBlanksAndComments (ptrR);
                   4352:       if (*ptrR == ';' || *ptrR == EOS || *ptrR == ',')
1.327     vatton   4353:         {
                   4354:           skippedNL = NewLineSkipped;
1.366     vatton   4355:           cssRule = ptrR;
                   4356:           /* apply the Padding-Top to all */
                   4357:           ptrR = ParseCSSPaddingRight (element, tsch, context, ptrT, css, isHTML);
1.327     vatton   4358:           NewLineSkipped = skippedNL;
1.366     vatton   4359:           ptrR = ParseCSSPaddingBottom (element, tsch, context, ptrT, css, isHTML);
                   4360:           NewLineSkipped = skippedNL;
                   4361:           ptrR = ParseCSSPaddingLeft (element, tsch, context, ptrT, css, isHTML);
1.327     vatton   4362:         }
1.43      cvs      4363:       else
1.327     vatton   4364:         {
1.366     vatton   4365:           /* parse Padding-Right */
                   4366:           ptrB = ParseCSSPaddingRight (element, tsch, context, ptrR, css, isHTML);
                   4367:           ptrB = SkipBlanksAndComments (ptrB);
                   4368:           if (*ptrB == ';' || *ptrB == EOS || *ptrB == ',')
1.327     vatton   4369:             {
1.366     vatton   4370:               skippedNL = NewLineSkipped;
                   4371:               cssRule = ptrB;
                   4372:               /* apply the Padding-Top to Padding-Bottom */
                   4373:               ptrB = ParseCSSPaddingBottom (element, tsch, context, ptrT, css, isHTML);
                   4374:               NewLineSkipped = skippedNL;
1.327     vatton   4375:               /* apply the Padding-Right to Padding-Left */
1.366     vatton   4376:               ptrB = ParseCSSPaddingLeft (element, tsch, context, ptrR, css, isHTML);
1.327     vatton   4377:             }
                   4378:           else
1.366     vatton   4379:             {
                   4380:               /* parse Padding-Bottom */
                   4381:               ptrL = ParseCSSPaddingBottom (element, tsch, context, ptrB, css, isHTML);
                   4382:               ptrL = SkipBlanksAndComments (ptrL);
                   4383:               if (*ptrL == ';' || *ptrL == EOS || *ptrL == ',')
                   4384:                 {
                   4385:                   cssRule = ptrL;
                   4386:                   /* apply the Padding-Right to Padding-Left */
                   4387:                   ptrL = ParseCSSPaddingLeft (element, tsch, context, ptrR, css, isHTML);
                   4388:                 }
                   4389:               else
                   4390:                 /* parse Padding-Left */
                   4391:                 cssRule = ParseCSSPaddingLeft (element, tsch, context, ptrL, css, isHTML);
                   4392:               cssRule = SkipBlanksAndComments (cssRule);
                   4393:             }
1.327     vatton   4394:         }
1.43      cvs      4395:     }
1.1       cvs      4396:   return (cssRule);
                   4397: }
                   4398: 
                   4399: /*----------------------------------------------------------------------
1.327     vatton   4400:   ParseCSSForeground: parse a CSS foreground attribute 
1.1       cvs      4401:   ----------------------------------------------------------------------*/
1.79      cvs      4402: static char *ParseCSSForeground (Element element, PSchema tsch,
1.327     vatton   4403:                                  PresentationContext context,
                   4404:                                  char *cssRule,
                   4405:                                  CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      4406: {
1.117     vatton   4407:   PresentationValue   best;
1.262     vatton   4408:   char               *p;
1.1       cvs      4409: 
1.370     vatton   4410:   best.typed_data.real = FALSE;
1.366     vatton   4411:   cssRule = SkipBlanksAndComments (cssRule);
1.262     vatton   4412:   p = cssRule;
1.117     vatton   4413:   cssRule = ParseCSSColor (cssRule, &best);
1.366     vatton   4414:   if (best.typed_data.unit != UNIT_INVALID)
1.327     vatton   4415:     {
                   4416:       if (*cssRule != EOS && *cssRule !=';')
                   4417:         {
                   4418:           cssRule = SkipProperty (cssRule, FALSE);
1.366     vatton   4419:           CSSParseError ("Invalid color value", p, cssRule);
1.327     vatton   4420:         }
1.366     vatton   4421:       else if (DoDialog)
                   4422:         DisplayStyleValue ("color", p, cssRule);
                   4423:       else if (DoApply)
1.327     vatton   4424:         /* install the new presentation */
                   4425:         TtaSetStylePresentation (PRForeground, element, tsch, context, best);
                   4426:     }
                   4427:   return (cssRule);
1.1       cvs      4428: }
                   4429: 
                   4430: /*----------------------------------------------------------------------
1.59      cvs      4431:   ParseCSSBackgroundColor: parse a CSS background color attribute 
1.1       cvs      4432:   ----------------------------------------------------------------------*/
1.79      cvs      4433: static char *ParseCSSBackgroundColor (Element element, PSchema tsch,
1.327     vatton   4434:                                       PresentationContext context,
                   4435:                                       char *cssRule,
                   4436:                                       CSSInfoPtr css, ThotBool isHTML)
1.1       cvs      4437: {
                   4438:   PresentationValue     best;
1.366     vatton   4439:   char                 *ptr;
1.1       cvs      4440: 
1.370     vatton   4441:   best.typed_data.real = FALSE;
1.366     vatton   4442:   cssRule = SkipBlanksAndComments (cssRule);
                   4443:   ptr = cssRule;
1.184     vatton   4444:   best.typed_data.unit = UNIT_INVALID;
1.1       cvs      4445:   best.typed_data.real = FALSE;
1.198     vatton   4446:   if (!strncasecmp (cssRule, "transparent", 11))
1.1       cvs      4447:     {
1.184     vatton   4448:       best.typed_data.value = PATTERN_NONE;
                   4449:       best.typed_data.unit = UNIT_REL;
1.295     vatton   4450:       cssRule = SkipWord (cssRule);
1.116     vatton   4451:       if (DoApply)
1.327     vatton   4452:         TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
                   4453:     }
1.1       cvs      4454:   else
                   4455:     {
                   4456:       cssRule = ParseCSSColor (cssRule, &best);
1.366     vatton   4457:       if (best.typed_data.unit != UNIT_INVALID)
1.327     vatton   4458:         {
1.366     vatton   4459:           if (DoDialog)
                   4460:             DisplayStyleValue ("background-color", ptr, cssRule);
                   4461:           else if (DoApply)
                   4462:             {
                   4463:               /* install the new presentation. */
                   4464:               TtaSetStylePresentation (PRBackground, element, tsch, context, best);
                   4465:               /* thot specificity: need to set fill pattern for background color */
                   4466:               best.typed_data.value = PATTERN_BACKGROUND;
                   4467:               best.typed_data.unit = UNIT_REL;
                   4468:               TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
                   4469:               best.typed_data.value = 1;
                   4470:               best.typed_data.unit = UNIT_REL;
                   4471:               TtaSetStylePresentation (PRShowBox, element, tsch, context, best);
                   4472:             }
1.327     vatton   4473:         }
1.1       cvs      4474:     }
                   4475:   return (cssRule);
                   4476: }
                   4477: 
1.63      cvs      4478: /*----------------------------------------------------------------------
1.65      cvs      4479:   ParseSVGStroke: parse a SVG stroke property
                   4480:   ----------------------------------------------------------------------*/
1.79      cvs      4481: static char *ParseSVGStroke (Element element, PSchema tsch,
1.327     vatton   4482:                              PresentationContext context, char *cssRule,
                   4483:                              CSSInfoPtr css, ThotBool isHTML)
1.65      cvs      4484: {
                   4485:   PresentationValue     best;
1.245     quint    4486:   char                  *url;
1.65      cvs      4487: 
1.184     vatton   4488:   best.typed_data.unit = UNIT_INVALID;
1.65      cvs      4489:   best.typed_data.real = FALSE;
1.82      cvs      4490:   if (!strncasecmp (cssRule, "none", 4))
1.65      cvs      4491:     {
                   4492:       best.typed_data.value = -2;  /* -2 means transparent */
1.184     vatton   4493:       best.typed_data.unit = UNIT_REL;
1.65      cvs      4494:       cssRule = SkipWord (cssRule);
                   4495:     }
1.245     quint    4496:   else if (!strncasecmp (cssRule, "currentColor", 12))
                   4497:     {
1.293     quint    4498:       best.typed_data.unit = VALUE_INHERIT;
                   4499:       cssRule = SkipWord (cssRule);
1.245     quint    4500:     }
                   4501:   else if (!strncasecmp (cssRule, "url", 3))
                   4502:     {  
                   4503:       cssRule += 3;
                   4504:       cssRule = ParseCSSUrl (cssRule, &url);
                   4505:       /* **** do something with the url ***** */;
                   4506:       TtaFreeMemory (url);
                   4507:       /* **** caution: another color value may follow the uri (in case
1.327     vatton   4508:          the uri could ne be dereferenced) *** */
1.245     quint    4509:     }
1.65      cvs      4510:   else
1.293     quint    4511:     cssRule = ParseCSSColor (cssRule, &best);
                   4512: 
                   4513:   if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.295     vatton   4514:     /* install the new presentation */
                   4515:     TtaSetStylePresentation (PRForeground, element, tsch, context, best);
1.65      cvs      4516:   return (cssRule);
                   4517: }
                   4518: 
                   4519: /*----------------------------------------------------------------------
1.63      cvs      4520:   ParseSVGFill: parse a SVG fill property
                   4521:   ----------------------------------------------------------------------*/
1.79      cvs      4522: static char *ParseSVGFill (Element element, PSchema tsch,
1.327     vatton   4523:                            PresentationContext context, char *cssRule,
                   4524:                            CSSInfoPtr css, ThotBool isHTML)
1.63      cvs      4525: {
                   4526:   PresentationValue     best;
1.245     quint    4527:   char                  *url;
1.63      cvs      4528: 
1.184     vatton   4529:   best.typed_data.unit = UNIT_INVALID;
1.63      cvs      4530:   best.typed_data.real = FALSE;
1.82      cvs      4531:   if (!strncasecmp (cssRule, "none", 4))
1.63      cvs      4532:     {
1.184     vatton   4533:       best.typed_data.value = PATTERN_NONE;
                   4534:       best.typed_data.unit = UNIT_REL;
1.116     vatton   4535:       if (DoApply)
1.327     vatton   4536:         TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
1.65      cvs      4537:       cssRule = SkipWord (cssRule);
1.294     vatton   4538:       return (cssRule);
1.63      cvs      4539:     }
1.245     quint    4540:   else if (!strncasecmp (cssRule, "currentColor", 12))
                   4541:     {
1.293     quint    4542:       best.typed_data.unit = VALUE_INHERIT;
                   4543:       cssRule = SkipWord (cssRule);
1.245     quint    4544:     }
                   4545:   else if (!strncasecmp (cssRule, "url", 3))
                   4546:     {  
                   4547:       cssRule += 3;
                   4548:       cssRule = ParseCSSUrl (cssRule, &url);
                   4549:       /* **** do something with the url ***** */;
                   4550:       TtaFreeMemory (url);
                   4551:       /* **** caution: another color value may follow the uri (in case
1.327     vatton   4552:          the uri could ne be dereferenced) *** */
1.245     quint    4553:     }
1.63      cvs      4554:   else
1.327     vatton   4555:     cssRule = ParseCSSColor (cssRule, &best);
1.293     quint    4556: 
                   4557:   if (best.typed_data.unit != UNIT_INVALID && DoApply)
1.63      cvs      4558:     {
1.293     quint    4559:       /* install the new presentation. */
                   4560:       TtaSetStylePresentation (PRBackground, element, tsch, context, best);
                   4561:       /* thot specificity: need to set fill pattern for background color */
                   4562:       best.typed_data.value = PATTERN_BACKGROUND;
                   4563:       best.typed_data.unit = UNIT_REL;
                   4564:       TtaSetStylePresentation (PRFillPattern, element, tsch, context, best);
1.63      cvs      4565:     }
                   4566:   return (cssRule);
                   4567: }
1.161     quint    4568: 
1.155     cheyroul 4569: /*----------------------------------------------------------------------
1.346     quint    4570:   ParseSVGOpacity: parse a SVG opacity property
1.155     cheyroul 4571:   ----------------------------------------------------------------------*/
                   4572: static char *ParseSVGOpacity (Element element, PSchema tsch,
1.327     vatton   4573:                               PresentationContext context, char *cssRule,
                   4574:                               CSSInfoPtr css, ThotBool isHTML)
1.155     cheyroul 4575: {
                   4576:   PresentationValue     best;
1.63      cvs      4577: 
1.184     vatton   4578:   best.typed_data.unit = UNIT_INVALID;
1.155     cheyroul 4579:   best.typed_data.real = FALSE;
                   4580:   cssRule = ParseClampedUnit (cssRule, &best);
                   4581:   if (DoApply)
1.295     vatton   4582:     /* install the new presentation. */
                   4583:     TtaSetStylePresentation (PROpacity, element, tsch, context, best);
1.155     cheyroul 4584:   return (cssRule);
                   4585: }
1.346     quint    4586: 
1.170     cheyroul 4587: /*----------------------------------------------------------------------
1.346     quint    4588:   ParseSVGStrokeOpacity: parse a SVG stroke-opacity property
1.170     cheyroul 4589:   ----------------------------------------------------------------------*/
                   4590: static char *ParseSVGStrokeOpacity (Element element, PSchema tsch,
1.327     vatton   4591:                                     PresentationContext context, char *cssRule,
                   4592:                                     CSSInfoPtr css, ThotBool isHTML)
1.170     cheyroul 4593: {
                   4594:   PresentationValue     best;
1.161     quint    4595: 
1.184     vatton   4596:   best.typed_data.unit = UNIT_INVALID;
1.170     cheyroul 4597:   best.typed_data.real = FALSE;
                   4598:   cssRule = ParseClampedUnit (cssRule, &best);
                   4599:   if (DoApply)
1.295     vatton   4600:     /* install the new presentation. */
                   4601:     TtaSetStylePresentation (PRStrokeOpacity, element, tsch, context, best);
1.170     cheyroul 4602:   return (cssRule);
                   4603: }
1.346     quint    4604: 
1.170     cheyroul 4605: /*----------------------------------------------------------------------
1.346     quint    4606:   ParseSVGFillOpacity: parse a SVG fil-opacityl property
1.170     cheyroul 4607:   ----------------------------------------------------------------------*/
                   4608: static char *ParseSVGFillOpacity (Element element, PSchema tsch,
1.327     vatton   4609:                                   PresentationContext context, char *cssRule,
                   4610:                                   CSSInfoPtr css, ThotBool isHTML)
1.170     cheyroul 4611: {
                   4612:   PresentationValue     best;
                   4613: 
1.184     vatton   4614:   best.typed_data.unit = UNIT_INVALID;
1.170     cheyroul 4615:   best.typed_data.real = FALSE;
                   4616:   cssRule = ParseClampedUnit (cssRule, &best);
                   4617:   if (DoApply)
1.295     vatton   4618:     /* install the new presentation. */
                   4619:     TtaSetStylePresentation (PRFillOpacity, element, tsch, context, best);
1.170     cheyroul 4620:   return (cssRule);
                   4621: }
1.207     vatton   4622: 
1.1       cvs      4623: /*----------------------------------------------------------------------
1.327     vatton   4624:   GetCSSBackgroundURL searches a CSS BackgroundImage url within
                   4625:   the cssRule.
                   4626:   Returns NULL or a new allocated url string.
1.217     vatton   4627:   ----------------------------------------------------------------------*/
                   4628: char *GetCSSBackgroundURL (char *cssRule)
                   4629: {
                   4630:   char            *b, *url;
                   4631: 
                   4632:   url = NULL;
                   4633:   b = strstr (cssRule, "url");
                   4634:   if (b)
1.290     gully    4635:     b = ParseCSSUrl (b, &url);
1.217     vatton   4636:   return (url);
                   4637: }
                   4638: 
                   4639: /*----------------------------------------------------------------------
1.327     vatton   4640:   ParseCSSContent: parse the value of property "content"
1.217     vatton   4641:   ----------------------------------------------------------------------*/
                   4642: static char *ParseCSSContent (Element element, PSchema tsch,
1.327     vatton   4643:                               PresentationContext ctxt, char *cssRule,
                   4644:                               CSSInfoPtr css, ThotBool isHTML)
1.217     vatton   4645: {
1.312     quint    4646:   PresentationValue   value;
1.353     quint    4647:   char                *last, *start, quoteChar, savedChar;
                   4648:   int                 length, val;
1.366     vatton   4649:   char               *buffer, *p;
                   4650:   char               *start_value;
1.312     quint    4651:   ThotBool            repeat;
                   4652: 
                   4653:   value.typed_data.unit = UNIT_REL;
                   4654:   value.typed_data.real = FALSE;
                   4655:   value.typed_data.value = 0;
1.366     vatton   4656:   if (!DoDialog && DoApply)
1.347     quint    4657:     TtaSetStylePresentation (PRContent, element, tsch, ctxt, value);
1.217     vatton   4658:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   4659:   start_value = cssRule;
1.312     quint    4660:   repeat = TRUE;
                   4661:   while (repeat)
                   4662:     {
1.366     vatton   4663:       p = cssRule;
1.312     quint    4664:       if (!strncasecmp (cssRule, "normal", 6))
1.327     vatton   4665:         /* The pseudo-element is not generated */
                   4666:         {
                   4667:           /* @@@@@@ */
                   4668:           cssRule += 6;
                   4669:           repeat = FALSE;
                   4670:         }
1.331     quint    4671:       else if (!strncasecmp (cssRule, "none", 4))
                   4672:         /* The pseudo-element is not generated */
                   4673:         {
                   4674:           /* @@@@@@ */
                   4675:           cssRule += 4;
                   4676:           repeat = FALSE;
                   4677:         }
1.312     quint    4678:       else if (*cssRule == '"' || *cssRule == '\'')
1.327     vatton   4679:         /* It's a string */
                   4680:         {
                   4681:           quoteChar = *cssRule;
1.353     quint    4682:           /* how long is the string? */
                   4683:           last = cssRule;
                   4684:           last = SkipString (last);
                   4685:           length = last - cssRule;
                   4686:           /* get a buffer to store the string */
1.366     vatton   4687:           buffer = (char *)TtaGetMemory (length);
1.353     quint    4688:           p = buffer; /* beginning of the string */
1.327     vatton   4689:           cssRule++;
                   4690:           while (*cssRule != EOS && *cssRule != quoteChar)
1.353     quint    4691:             {
                   4692:               if (*cssRule == '\\')
                   4693:                 {
                   4694:                   cssRule++; /* skip the backslash */
                   4695:                   if ((*cssRule >= '0' && *cssRule <= '9') ||
                   4696:                       (*cssRule >= 'A' && *cssRule <= 'F') ||
                   4697:                       (*cssRule >= 'a' && *cssRule <= 'f'))
                   4698:                     {
                   4699:                       start = cssRule; /* first hex digit after the backslash*/
                   4700:                       cssRule++;
                   4701:                       while ((*cssRule >= '0' && *cssRule <= '9') ||
                   4702:                              (*cssRule >= 'A' && *cssRule <= 'F') ||
                   4703:                              (*cssRule >= 'a' && *cssRule <= 'f'))
                   4704:                         cssRule++;
                   4705:                       savedChar = *cssRule;
                   4706:                       *cssRule = EOS;
                   4707:                       sscanf (start, "%x", &val);
1.366     vatton   4708:                       TtaWCToMBstring ((wchar_t) val, (unsigned char **) &p);
1.353     quint    4709:                       *cssRule = savedChar;
                   4710:                     }
                   4711:                   else
                   4712:                     {
                   4713:                       *p = *cssRule;
                   4714:                       p++; cssRule++;
                   4715:                     }
                   4716:                 }
                   4717:               else
                   4718:                 {
                   4719:                   *p = *cssRule;
                   4720:                   p++; cssRule++;
                   4721:                 }
                   4722:             }
                   4723:           *p = EOS;
1.366     vatton   4724:           if (DoDialog)
                   4725:             {
                   4726:               DisplayStyleValue ("", start_value, p);
                   4727:               start_value = p;
                   4728:             }
                   4729:           else if (*cssRule != quoteChar)
1.327     vatton   4730:             cssRule = SkipProperty (cssRule, FALSE);
                   4731:           else
                   4732:             {
                   4733:               *cssRule = EOS;
                   4734:               value.typed_data.unit = UNIT_REL;
                   4735:               value.typed_data.real = FALSE;
1.353     quint    4736:               value.pointer = buffer;
1.347     quint    4737:               if (DoApply)
                   4738:                 TtaSetStylePresentation (PRContentString, element, tsch, ctxt,
                   4739:                                          value);
1.327     vatton   4740:               *cssRule = quoteChar;
                   4741:               cssRule++;
                   4742:             }
1.353     quint    4743:           TtaFreeMemory (buffer);
1.327     vatton   4744:         }
1.312     quint    4745:       else if (!strncasecmp (cssRule, "url", 3))
1.327     vatton   4746:         {  
                   4747:           cssRule += 3;
1.347     quint    4748:           cssRule = SetCSSImage (element, tsch, ctxt, cssRule, css,
                   4749:                                  PRContentURL);
1.366     vatton   4750:           if (DoDialog)
                   4751:             {
                   4752:               DisplayStyleValue ("", start_value, p);
                   4753:               start_value = p;
                   4754:             }
1.327     vatton   4755:         }
1.312     quint    4756:       else if (!strncasecmp (cssRule, "counter", 7))
1.327     vatton   4757:         {
                   4758:           cssRule += 7;
                   4759:           /* @@@@@@ */
1.366     vatton   4760:           if (DoDialog)
                   4761:             {
                   4762:               DisplayStyleValue ("", start_value, p);
                   4763:               start_value = p;
                   4764:             }
                   4765:           else
                   4766:             cssRule = SkipProperty (cssRule, FALSE);
1.327     vatton   4767:         }
1.312     quint    4768:       else if (!strncasecmp (cssRule, "counters", 8))
1.327     vatton   4769:         {
                   4770:           cssRule += 8;
                   4771:           /* @@@@@@ */
1.366     vatton   4772:           if (DoDialog)
                   4773:             {
                   4774:               DisplayStyleValue ("", start_value, p);
                   4775:               start_value = p;
                   4776:             }
                   4777:           else
                   4778:             cssRule = SkipProperty (cssRule, FALSE);
1.327     vatton   4779:         }
1.312     quint    4780:       else if (!strncasecmp (cssRule, "attr", 4))
1.327     vatton   4781:         {
1.347     quint    4782:           value.pointer = NULL;
1.327     vatton   4783:           cssRule += 4;
1.347     quint    4784:           cssRule = SkipBlanksAndComments (cssRule);
                   4785:           if (*cssRule == '(')
                   4786:             {
                   4787:               cssRule++;
                   4788:               cssRule = SkipBlanksAndComments (cssRule);
                   4789:               start = cssRule;
                   4790:               while (*cssRule != EOS && *cssRule != ')')
                   4791:                 cssRule++;
                   4792:               if (*cssRule != ')')
                   4793:                 cssRule = start;
                   4794:               else
                   4795:                 {
                   4796:                   last = cssRule;
                   4797:                   /* remove extra spaces */
                   4798:                   if (last[-1] == SPACE)
                   4799:                     {
                   4800:                       *last = SPACE;
                   4801:                       last--;
                   4802:                       while (last[-1] == SPACE)
                   4803:                         last--;
                   4804:                     }
                   4805:                   savedChar = *last;
                   4806:                   *last = EOS;
                   4807:                   value.typed_data.unit = UNIT_REL;
                   4808:                   value.typed_data.real = FALSE;
                   4809:                   value.pointer = start;
1.366     vatton   4810:                   if (DoDialog)
                   4811:                     {
                   4812:                       DisplayStyleValue ("", start_value, p);
                   4813:                       start_value = p;
                   4814:                     }
                   4815:                   else if (DoApply)
1.347     quint    4816:                     TtaSetStylePresentation (PRContentAttr, element, tsch,
                   4817:                                              ctxt, value);
                   4818:                   *last = savedChar;
                   4819:                 }
                   4820:             }
                   4821:           if (value.pointer == NULL)
                   4822:             {
1.353     quint    4823:               CSSParseError ("Invalid content value", (char*) p, cssRule);
1.366     vatton   4824:               if (DoDialog)
                   4825:                 {
                   4826:                   DisplayStyleValue ("", start_value, p);
                   4827:                   start_value = p;
                   4828:                 }
                   4829:               else
                   4830:                 cssRule = SkipProperty (cssRule, FALSE);
1.347     quint    4831:             }
                   4832:           cssRule++;
1.327     vatton   4833:         }
1.312     quint    4834:       else if (!strncasecmp (cssRule, "open-quote", 10))
1.327     vatton   4835:         {
                   4836:           cssRule += 10;
                   4837:           /* @@@@@@ */
                   4838:         }
1.312     quint    4839:       else if (!strncasecmp (cssRule, "close-quote", 11))
1.327     vatton   4840:         {
                   4841:           cssRule += 11;
                   4842:           /* @@@@@@ */
                   4843:         }
1.312     quint    4844:       else if (!strncasecmp (cssRule, "no-open-quote", 13))
1.327     vatton   4845:         {
                   4846:           cssRule += 13;
                   4847:           /* @@@@@@ */
                   4848:         }
1.312     quint    4849:       else if (!strncasecmp (cssRule, "no-close-quote", 14))
1.327     vatton   4850:         {
                   4851:           cssRule += 14;
                   4852:           /* @@@@@@ */
                   4853:         }
1.312     quint    4854:       else if (!strncasecmp (cssRule, "inherit", 7))
1.327     vatton   4855:         {
                   4856:           cssRule += 7;
                   4857:           /* @@@@@@ */
                   4858:           repeat = FALSE;
                   4859:         }
1.312     quint    4860:       else
1.327     vatton   4861:         {
1.353     quint    4862:           CSSParseError ("Invalid content value", (char*) p, cssRule);
1.366     vatton   4863:           if (DoDialog)
                   4864:             {
                   4865:               DisplayStyleValue ("", start_value, p);
                   4866:               start_value = p;
                   4867:             }
                   4868:           else
                   4869:             cssRule = SkipProperty (cssRule, FALSE);
1.327     vatton   4870:         }
1.312     quint    4871:       cssRule = SkipBlanksAndComments (cssRule);
                   4872:       if (repeat)
1.327     vatton   4873:         if (*cssRule == ';' || *cssRule == '}' || *cssRule == EOS ||
                   4874:             *cssRule == '!')
                   4875:           repeat = FALSE;
1.217     vatton   4876:     }
                   4877:   return (cssRule);
                   4878: }
1.1       cvs      4879: 
                   4880: /*----------------------------------------------------------------------
1.59      cvs      4881:   ParseCSSBackgroundImage: parse a CSS BackgroundImage attribute string.
1.1       cvs      4882:   ----------------------------------------------------------------------*/
1.79      cvs      4883: static char *ParseCSSBackgroundImage (Element element, PSchema tsch,
1.327     vatton   4884:                                       PresentationContext ctxt,
                   4885:                                       char *cssRule, CSSInfoPtr css,
                   4886:                                       ThotBool isHTML)
1.1       cvs      4887: {
1.49      cvs      4888:   PresentationValue          image, value;
1.357     quint    4889:   char                       *ptr;
1.148     vatton   4890: 
1.370     vatton   4891:   image.typed_data.real = FALSE;
                   4892:   value.typed_data.real = FALSE;
1.82      cvs      4893:   cssRule = SkipBlanksAndComments (cssRule);
1.357     quint    4894:   ptr = cssRule;
1.161     quint    4895:   if (!strncasecmp (cssRule, "none", 4))
                   4896:     {
1.260     vatton   4897:       cssRule += 4;
1.366     vatton   4898:       if (DoDialog)
                   4899:         DisplayStyleValue ("background-image", ptr, cssRule);
                   4900:       else if (DoApply)
1.327     vatton   4901:         {
                   4902:           /* no background image */
                   4903:           image.pointer = NULL;
                   4904:           TtaSetStylePresentation (PRBackgroundPicture, element, tsch, ctxt,
                   4905:                                    image);
                   4906:         }
1.161     quint    4907:     }
1.357     quint    4908:   else if (!strncasecmp (cssRule, "inherit", 7))
                   4909:     {
                   4910:       value.typed_data.unit = VALUE_INHERIT;
                   4911:       cssRule += 7;
1.366     vatton   4912:       if (DoDialog)
                   4913:         DisplayStyleValue ("background-image", ptr, cssRule);
1.357     quint    4914:     }
1.161     quint    4915:   else if (!strncasecmp (cssRule, "url", 3))
1.1       cvs      4916:     {  
                   4917:       cssRule += 3;
1.302     quint    4918:       cssRule = SetCSSImage (element, tsch, ctxt, cssRule, css,
1.327     vatton   4919:                              PRBackgroundPicture);
1.207     vatton   4920:       if (ctxt->destroy)
1.327     vatton   4921:         if (TtaGetStylePresentation (PRFillPattern, element, tsch, ctxt,
                   4922:                                      &value) < 0)
                   4923:           {
                   4924:             /* there is no FillPattern rule -> remove ShowBox rule */
                   4925:             value.typed_data.value = 1;
                   4926:             value.typed_data.unit = UNIT_REL;
                   4927:             value.typed_data.real = FALSE;
                   4928:             TtaSetStylePresentation (PRShowBox, element, tsch, ctxt, value);
                   4929:           }
1.18      cvs      4930:     }
1.357     quint    4931:   else
                   4932:     {
                   4933:       cssRule = SkipWord (cssRule);
                   4934:       CSSParseError ("Invalid background-image value", ptr, cssRule);
                   4935:       cssRule = SkipProperty (cssRule, FALSE);
                   4936:     }
1.18      cvs      4937:   return (cssRule);
                   4938: }
                   4939: 
                   4940: /*----------------------------------------------------------------------
1.295     vatton   4941:   ParseACSSBackgroundRepeat: parse a CSS BackgroundRepeat attribute string.
1.18      cvs      4942:   ----------------------------------------------------------------------*/
1.295     vatton   4943: static char *ParseACSSBackgroundRepeat (Element element, PSchema tsch,
1.327     vatton   4944:                                         PresentationContext ctxt,
                   4945:                                         char *cssRule, CSSInfoPtr css, ThotBool isHTML)
1.18      cvs      4946: {
                   4947:   PresentationValue   repeat;
1.366     vatton   4948:   char               *start_value;
1.18      cvs      4949: 
1.366     vatton   4950:   cssRule = SkipBlanksAndComments (cssRule);
                   4951:   start_value = cssRule;
1.184     vatton   4952:   repeat.typed_data.value = REALSIZE;
1.191     vatton   4953:   repeat.typed_data.unit = UNIT_BOX;
1.18      cvs      4954:   repeat.typed_data.real = FALSE;
1.82      cvs      4955:   cssRule = SkipBlanksAndComments (cssRule);
                   4956:   if (!strncasecmp (cssRule, "no-repeat", 9))
1.184     vatton   4957:     repeat.typed_data.value = REALSIZE;
1.82      cvs      4958:   else if (!strncasecmp (cssRule, "repeat-y", 8))
1.265     vatton   4959:     repeat.typed_data.value = YREPEAT;
1.82      cvs      4960:   else if (!strncasecmp (cssRule, "repeat-x", 8))
1.265     vatton   4961:     repeat.typed_data.value = XREPEAT;
1.82      cvs      4962:   else if (!strncasecmp (cssRule, "repeat", 6))
1.184     vatton   4963:     repeat.typed_data.value = REPEAT;
1.18      cvs      4964:   else
                   4965:     return (cssRule);
                   4966: 
1.295     vatton   4967:   cssRule = SkipWord (cssRule);
                   4968:   /* check if it's an important rule */
1.366     vatton   4969:   if (DoDialog)
                   4970:     DisplayStyleValue ("background-repeat", start_value, cssRule);
                   4971:   else if (DoApply)
1.295     vatton   4972:     /* install the new presentation */
1.362     quint    4973:     TtaSetStylePresentation (PRBackgroundRepeat, element, tsch, ctxt, repeat);
1.295     vatton   4974:   return (cssRule);
                   4975: }
                   4976: 
                   4977: /*----------------------------------------------------------------------
                   4978:   ParseCSSBackgroundRepeat: parse a CSS BackgroundRepeat attribute string.
                   4979:   ----------------------------------------------------------------------*/
                   4980: static char *ParseCSSBackgroundRepeat (Element element, PSchema tsch,
1.315     gully    4981:                                        PresentationContext ctxt,
                   4982:                                        char *cssRule, CSSInfoPtr css,
                   4983:                                        ThotBool isHTML)
1.295     vatton   4984: {
                   4985:   cssRule = ParseACSSBackgroundRepeat (element, tsch, ctxt,
1.315     gully    4986:                                        cssRule, css, isHTML);
                   4987:   if (cssRule)
1.117     vatton   4988:     {
1.295     vatton   4989:       cssRule = SkipValue ("Invalid background-repeat value", cssRule);
1.117     vatton   4990:       /* check if it's an important rule */
                   4991:     }
1.295     vatton   4992:   return cssRule;
1.18      cvs      4993: }
                   4994: 
                   4995: /*----------------------------------------------------------------------
1.327     vatton   4996:   ParseACSSBackgroundAttachment: parse a CSS BackgroundAttachment
                   4997:   attribute string.                                          
1.18      cvs      4998:   ----------------------------------------------------------------------*/
1.295     vatton   4999: static char *ParseACSSBackgroundAttachment (Element element, PSchema tsch,
1.327     vatton   5000:                                             PresentationContext ctxt,
                   5001:                                             char *cssRule, CSSInfoPtr css,
                   5002:                                             ThotBool isHTML)
1.18      cvs      5003: {
1.366     vatton   5004:   char               *start_value;
                   5005: 
1.163     quint    5006:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   5007:   start_value = cssRule;
1.163     quint    5008:   if (!strncasecmp (cssRule, "scroll", 6))
1.199     vatton   5009:     {
                   5010:       cssRule = SkipWord (cssRule);
                   5011:     }
1.163     quint    5012:   else if (!strncasecmp (cssRule, "fixed", 5))
1.199     vatton   5013:     {
                   5014:       cssRule = SkipWord (cssRule);
                   5015:     }
1.362     quint    5016:   else if (!strncasecmp (cssRule, "inherit", 7))
                   5017:     {
                   5018:       cssRule = SkipWord (cssRule);
                   5019:     }
1.366     vatton   5020:   if (start_value != cssRule && DoDialog)
                   5021:     DisplayStyleValue ("background-attachment", start_value, cssRule);
1.163     quint    5022:   return (cssRule);
1.1       cvs      5023: }
                   5024: 
                   5025: /*----------------------------------------------------------------------
1.327     vatton   5026:   ParseCSSBackgroundAttachment: parse a CSS BackgroundAttachment
                   5027:   attribute string.                                          
1.295     vatton   5028:   ----------------------------------------------------------------------*/
                   5029: static char *ParseCSSBackgroundAttachment (Element element, PSchema tsch,
1.327     vatton   5030:                                            PresentationContext ctxt,
                   5031:                                            char *cssRule, CSSInfoPtr css,
                   5032:                                            ThotBool isHTML)
1.295     vatton   5033: {
                   5034:   char     *ptr;
                   5035: 
                   5036:   ptr = cssRule;
                   5037:   cssRule = ParseACSSBackgroundAttachment (element, tsch, ctxt,
1.327     vatton   5038:                                            cssRule, css, isHTML);
1.295     vatton   5039:   if (ptr == cssRule)
1.366     vatton   5040:     cssRule = SkipValue ("Invalid background-attachment value", cssRule);
1.295     vatton   5041:   return cssRule;
                   5042: }
                   5043: 
                   5044: /*----------------------------------------------------------------------
1.327     vatton   5045:   ParseACSSBackgroundPosition: parse a CSS BackgroundPosition
                   5046:   attribute string.                                          
1.1       cvs      5047:   ----------------------------------------------------------------------*/
1.279     vatton   5048: static char *ParseACSSBackgroundPosition (Element element, PSchema tsch,
1.327     vatton   5049:                                           PresentationContext ctxt,
                   5050:                                           char *cssRule, CSSInfoPtr css,
1.362     quint    5051:                                           ThotBool isHTML, ThotBool *across)
1.1       cvs      5052: {
1.362     quint    5053:   PresentationValue   val;
                   5054:   char               *ptr;
1.1       cvs      5055: 
1.163     quint    5056:   cssRule = SkipBlanksAndComments (cssRule);
1.362     quint    5057:   ptr = cssRule;
                   5058:   val.typed_data.value = 0;
                   5059:   val.typed_data.real = FALSE;
                   5060:   val.typed_data.unit = UNIT_INVALID;
1.163     quint    5061:   if (!strncasecmp (cssRule, "left", 4))
1.362     quint    5062:     {
                   5063:       val.typed_data.value = 0;
                   5064:       val.typed_data.unit = UNIT_PERCENT;
                   5065:       cssRule += 4;
                   5066:       *across = TRUE;
                   5067:     }
1.163     quint    5068:   else if (!strncasecmp (cssRule, "right", 5))
1.362     quint    5069:     {
                   5070:       val.typed_data.value = 100;
                   5071:       val.typed_data.unit = UNIT_PERCENT;
                   5072:       cssRule += 5;
                   5073:       *across = TRUE;
                   5074:     }
1.163     quint    5075:   else if (!strncasecmp (cssRule, "center", 6))
1.362     quint    5076:     {
                   5077:       val.typed_data.value = 50;
                   5078:       val.typed_data.unit = UNIT_PERCENT;
                   5079:       cssRule += 6;
                   5080:     }
1.163     quint    5081:   else if (!strncasecmp (cssRule, "top", 3))
1.362     quint    5082:     {
                   5083:       val.typed_data.value = 0;
                   5084:       val.typed_data.unit = UNIT_PERCENT;
                   5085:       cssRule += 3;
                   5086:       *across = FALSE;
                   5087:     }
1.163     quint    5088:   else if (!strncasecmp (cssRule, "bottom", 6))
1.191     vatton   5089:     {
1.362     quint    5090:       val.typed_data.value = 100;
                   5091:       val.typed_data.unit = UNIT_PERCENT;
                   5092:       cssRule += 6;
                   5093:       *across = FALSE;
                   5094:     }
                   5095:   else if (!strncasecmp (cssRule, "inherit", 7))
                   5096:     {
                   5097:       val.typed_data.unit = VALUE_INHERIT;
                   5098:       cssRule += 7;
1.191     vatton   5099:     }
1.163     quint    5100:   else
1.362     quint    5101:     /* <length> or <percentage> */
                   5102:     {
                   5103:       cssRule = ParseCSSUnit (cssRule, &val);
                   5104:       if (val.typed_data.unit == UNIT_BOX && val.typed_data.value == 0)
                   5105:         /* 0 with no unit. Accept */
                   5106:         val.typed_data.unit = UNIT_PERCENT;
                   5107:     }
1.163     quint    5108: 
1.366     vatton   5109:   if (val.typed_data.unit != UNIT_INVALID && val.typed_data.unit != UNIT_BOX)
1.362     quint    5110:     {
1.366     vatton   5111:       if (DoDialog)
                   5112:         {
                   5113:           if (val.typed_data.unit == VALUE_INHERIT)
                   5114:             {
                   5115:               DisplayStyleValue ("background-positionH", ptr, cssRule);
                   5116:               DisplayStyleValue ("background-positionV", ptr, cssRule);
                   5117:             }
                   5118:           else if (*across)
                   5119:               DisplayStyleValue ("background-positionH", ptr, cssRule);
                   5120:           else
                   5121:               DisplayStyleValue ("background-positionV", ptr, cssRule);
                   5122:         }
                   5123:       else if (DoApply)
1.362     quint    5124:         /* install the new presentation */
                   5125:         {
                   5126:           if (val.typed_data.unit == VALUE_INHERIT)
                   5127:             /* "inherit" applies to both dimensions */
                   5128:             {
                   5129:               TtaSetStylePresentation (PRBackgroundHorizPos, element, tsch,
                   5130:                                        ctxt, val);
                   5131:               TtaSetStylePresentation (PRBackgroundVertPos, element, tsch,
                   5132:                                        ctxt, val);
                   5133:             }
                   5134:           else if (*across)
                   5135:             TtaSetStylePresentation (PRBackgroundHorizPos, element, tsch,
                   5136:                                      ctxt, val);
                   5137:           else
                   5138:             TtaSetStylePresentation (PRBackgroundVertPos, element, tsch,
                   5139:                                      ctxt, val);
                   5140:         }
                   5141:     }
1.279     vatton   5142:   return (cssRule);
                   5143: }
1.218     vatton   5144: 
1.279     vatton   5145: /*----------------------------------------------------------------------
1.327     vatton   5146:   ParseCSSBackgroundPosition: parse a CSS BackgroundPosition
                   5147:   attribute string.                                          
1.279     vatton   5148:   ----------------------------------------------------------------------*/
                   5149: static char *ParseCSSBackgroundPosition (Element element, PSchema tsch,
1.327     vatton   5150:                                          PresentationContext ctxt,
                   5151:                                          char *cssRule, CSSInfoPtr css,
                   5152:                                          ThotBool isHTML)
1.279     vatton   5153: {
1.295     vatton   5154:   char     *ptr;
1.362     quint    5155:   ThotBool  across;
1.295     vatton   5156: 
                   5157:   ptr = cssRule;
1.362     quint    5158:   across = TRUE;
                   5159:   cssRule = ParseACSSBackgroundPosition (element, tsch, ctxt, cssRule, css,
                   5160:                                          isHTML, &across);
1.295     vatton   5161:   if (ptr == cssRule)
1.360     vatton   5162:     cssRule = SkipValue ("Invalid background-position value", cssRule);
1.362     quint    5163:   else
1.298     vatton   5164:     {
1.362     quint    5165:       cssRule = SkipBlanksAndComments (cssRule);
                   5166:       if (*cssRule !=  ';' && *cssRule !=  '!' && *cssRule != EOS)
                   5167:         {
                   5168:           /* possible second value */
                   5169:           ptr = cssRule;
                   5170:           across = !across;
                   5171:           cssRule = ParseACSSBackgroundPosition (element, tsch, ctxt, cssRule,
                   5172:                                                  css, isHTML, &across);
                   5173:           if (ptr == cssRule)
                   5174:             cssRule = SkipValue ("Invalid background-position value", cssRule);
                   5175:         }
1.298     vatton   5176:     }
1.163     quint    5177:   return (cssRule);
1.18      cvs      5178: }
                   5179: 
                   5180: /*----------------------------------------------------------------------
1.327     vatton   5181:   ParseCSSBackground: parse a CSS background attribute 
1.18      cvs      5182:   ----------------------------------------------------------------------*/
1.79      cvs      5183: static char *ParseCSSBackground (Element element, PSchema tsch,
1.327     vatton   5184:                                  PresentationContext ctxt, char *cssRule,
                   5185:                                  CSSInfoPtr css, ThotBool isHTML)
1.18      cvs      5186: {
1.323     vatton   5187:   char           *ptr;
                   5188:   int             skippedNL;
1.362     quint    5189:   ThotBool        img, repeat, position, attach, color, across;
1.18      cvs      5190: 
1.82      cvs      5191:   cssRule = SkipBlanksAndComments (cssRule);
1.323     vatton   5192:   img = repeat = position = attach = color = FALSE;
1.362     quint    5193:   across = TRUE;
1.301     vatton   5194:   while (*cssRule != ';' && *cssRule != '}' && *cssRule != EOS && *cssRule != ',')
1.18      cvs      5195:     {
1.71      cvs      5196:       /* perhaps a Background Image */
1.198     vatton   5197:       if (!strncasecmp (cssRule, "url", 3) || !strncasecmp (cssRule, "none", 4))
1.327     vatton   5198:         {
1.334     vatton   5199:           if (!strncasecmp (cssRule, "none", 4))
                   5200:             repeat = TRUE;
1.327     vatton   5201:           cssRule = ParseCSSBackgroundImage (element, tsch, ctxt, cssRule,
                   5202:                                              css, isHTML);
                   5203:           img = TRUE;
                   5204:         }
1.18      cvs      5205:       /* perhaps a Background Attachment */
1.82      cvs      5206:       else if (!strncasecmp (cssRule, "scroll", 6) ||
                   5207:                !strncasecmp (cssRule, "fixed", 5))
1.327     vatton   5208:         {
                   5209:           cssRule = ParseACSSBackgroundAttachment (element, tsch, ctxt,
                   5210:                                                    cssRule, css, isHTML);
1.328     vatton   5211:           attach = repeat = TRUE;
1.327     vatton   5212:         }
1.18      cvs      5213:       /* perhaps a Background Repeat */
1.82      cvs      5214:       else if (!strncasecmp (cssRule, "no-repeat", 9) ||
                   5215:                !strncasecmp (cssRule, "repeat-y", 8)  ||
                   5216:                !strncasecmp (cssRule, "repeat-x", 8)  ||
                   5217:                !strncasecmp (cssRule, "repeat", 6))
1.327     vatton   5218:         {
                   5219:           cssRule = ParseACSSBackgroundRepeat (element, tsch, ctxt,
                   5220:                                                cssRule, css, isHTML);
                   5221:           repeat = TRUE;
                   5222:         }
1.18      cvs      5223:       /* perhaps a Background Position */
1.82      cvs      5224:       else if (!strncasecmp (cssRule, "left", 4)   ||
                   5225:                !strncasecmp (cssRule, "right", 5)  ||
                   5226:                !strncasecmp (cssRule, "center", 6) ||
                   5227:                !strncasecmp (cssRule, "top", 3)    ||
                   5228:                !strncasecmp (cssRule, "bottom", 6) ||
1.279     vatton   5229:                isdigit (*cssRule) || *cssRule == '.' || *cssRule == '-')
1.327     vatton   5230:         {
1.362     quint    5231:           cssRule = ParseACSSBackgroundPosition (element, tsch, ctxt, cssRule,
                   5232:                                                  css, isHTML, &across);
                   5233:           across = !across;
1.328     vatton   5234:           position = repeat = TRUE;
1.327     vatton   5235:         }
1.18      cvs      5236:       /* perhaps a Background Color */
1.323     vatton   5237:       else if (!color)
1.327     vatton   5238:         {
                   5239:           skippedNL = NewLineSkipped;
                   5240:           /* check if the rule has been found */
                   5241:           ptr = cssRule;
                   5242:           cssRule = ParseCSSBackgroundColor (element, tsch, ctxt,
                   5243:                                              cssRule, css, isHTML);
                   5244:           if (ptr == cssRule)
                   5245:             {
                   5246:               NewLineSkipped = skippedNL;
                   5247:               /* rule not found */
                   5248:               cssRule = SkipProperty (cssRule, FALSE);
                   5249:             }
                   5250:           else
                   5251:             color = TRUE;
                   5252:         }
1.328     vatton   5253:       else
1.327     vatton   5254:         cssRule = SkipProperty (cssRule, FALSE);
1.328     vatton   5255: 
1.82      cvs      5256:       cssRule = SkipBlanksAndComments (cssRule);
1.18      cvs      5257:     }
1.328     vatton   5258: 
                   5259:   if (color && !img)
                   5260:     ParseCSSBackgroundImage (element, tsch, ctxt, "none", css, isHTML);
                   5261:   
                   5262:   if (img && !repeat)
                   5263:     ParseACSSBackgroundRepeat (element, tsch, ctxt,
                   5264:                                "repeat", css, isHTML);
                   5265:   if (img && !position)
                   5266:     ParseACSSBackgroundPosition (element, tsch, ctxt,
1.362     quint    5267:                                  "0% 0%", css, isHTML, &across);
1.328     vatton   5268:   if (img && !attach)
                   5269:     ParseACSSBackgroundAttachment (element, tsch, ctxt,
                   5270:                                    "scroll", css, isHTML);
1.327     vatton   5271:   return (cssRule);
1.18      cvs      5272: }
                   5273: 
1.59      cvs      5274: /*----------------------------------------------------------------------
1.327     vatton   5275:   ParseCSSPageBreakBefore: parse a CSS page-break-before attribute 
1.59      cvs      5276:   ----------------------------------------------------------------------*/
1.79      cvs      5277: static char *ParseCSSPageBreakBefore (Element element, PSchema tsch,
1.327     vatton   5278:                                       PresentationContext ctxt, char *cssRule,
                   5279:                                       CSSInfoPtr css, ThotBool isHTML)
1.59      cvs      5280: {
                   5281:   PresentationValue   page;
1.366     vatton   5282:   char               *start_value;
1.59      cvs      5283: 
1.184     vatton   5284:   page.typed_data.unit = UNIT_INVALID;
1.59      cvs      5285:   page.typed_data.real = FALSE;
1.82      cvs      5286:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   5287:   start_value = cssRule;
1.82      cvs      5288:   if (!strncasecmp (cssRule, "auto", 4))
1.184     vatton   5289:     page.typed_data.value = PageAuto;
1.82      cvs      5290:   else if (!strncasecmp (cssRule, "always", 6))
1.59      cvs      5291:     {
1.184     vatton   5292:       page.typed_data.unit = UNIT_REL;
                   5293:       page.typed_data.value = PageAlways;
1.59      cvs      5294:     }
1.82      cvs      5295:   else if (!strncasecmp (cssRule, "avoid", 5))
1.59      cvs      5296:     {
1.184     vatton   5297:       page.typed_data.unit = UNIT_REL;
                   5298:       page.typed_data.value = PageAvoid;
1.59      cvs      5299:     }
1.82      cvs      5300:   else if (!strncasecmp (cssRule, "left", 4))
1.59      cvs      5301:     {
1.184     vatton   5302:       page.typed_data.unit = UNIT_REL;
                   5303:       page.typed_data.value = PageLeft;
1.59      cvs      5304:     }
1.82      cvs      5305:   else if (!strncasecmp (cssRule, "right", 5))
1.59      cvs      5306:     {
1.184     vatton   5307:       page.typed_data.unit = UNIT_REL;
                   5308:       page.typed_data.value = PageRight;
1.59      cvs      5309:     }
1.82      cvs      5310:   else if (!strncasecmp (cssRule, "inherit", 7))
1.59      cvs      5311:     {
1.293     quint    5312:       page.typed_data.unit = VALUE_INHERIT;
1.184     vatton   5313:       page.typed_data.value = PageInherit;
1.59      cvs      5314:     }
                   5315:   cssRule = SkipWord (cssRule);
                   5316:   /* install the new presentation */
1.366     vatton   5317:   if ((page.typed_data.unit == UNIT_REL && page.typed_data.value == PageAlways)
                   5318:       || page.typed_data.unit == VALUE_INHERIT)
                   5319:     {
                   5320:       if (DoDialog)
                   5321:         DisplayStyleValue ("page-break-before", start_value, cssRule);
                   5322:       else if (DoApply)
                   5323:         TtaSetStylePresentation (PRPageBefore, element, tsch, ctxt, page);
                   5324:     }
1.59      cvs      5325:   return (cssRule);
                   5326: }
                   5327: 
                   5328: /*----------------------------------------------------------------------
1.327     vatton   5329:   ParseCSSPageBreakAfter: parse a CSS page-break-after attribute 
1.59      cvs      5330:   ----------------------------------------------------------------------*/
1.79      cvs      5331: static char *ParseCSSPageBreakAfter (Element element, PSchema tsch,
1.327     vatton   5332:                                      PresentationContext ctxt,
                   5333:                                      char *cssRule, CSSInfoPtr css,
                   5334:                                      ThotBool isHTML)
1.59      cvs      5335: {
                   5336:   PresentationValue   page;
1.366     vatton   5337:   char               *start_value;
1.59      cvs      5338: 
1.184     vatton   5339:   page.typed_data.unit = UNIT_INVALID;
1.59      cvs      5340:   page.typed_data.real = FALSE;
1.82      cvs      5341:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   5342:   start_value = cssRule;
1.82      cvs      5343:   if (!strncasecmp (cssRule, "auto", 4))
1.184     vatton   5344:     page.typed_data.value = PageAuto;
1.82      cvs      5345:   else if (!strncasecmp (cssRule, "always", 6))
1.59      cvs      5346:     {
1.184     vatton   5347:       page.typed_data.unit = UNIT_REL;
                   5348:       page.typed_data.value = PageAlways;
1.59      cvs      5349:     }
1.82      cvs      5350:   else if (!strncasecmp (cssRule, "avoid", 5))
1.59      cvs      5351:     {
1.184     vatton   5352:       page.typed_data.unit = UNIT_REL;
                   5353:       page.typed_data.value = PageAvoid;
1.59      cvs      5354:     }
1.82      cvs      5355:   else if (!strncasecmp (cssRule, "left", 4))
1.59      cvs      5356:     {
1.184     vatton   5357:       page.typed_data.unit = UNIT_REL;
                   5358:       page.typed_data.value = PageLeft;
1.59      cvs      5359:     }
1.82      cvs      5360:   else if (!strncasecmp (cssRule, "right", 5))
1.59      cvs      5361:     {
1.184     vatton   5362:       page.typed_data.unit = UNIT_REL;
                   5363:       page.typed_data.value = PageRight;
1.59      cvs      5364:     }
1.82      cvs      5365:   else if (!strncasecmp (cssRule, "inherit", 7))
1.59      cvs      5366:     {
1.293     quint    5367:       page.typed_data.unit = VALUE_INHERIT;
1.184     vatton   5368:       page.typed_data.value = PageInherit;
1.59      cvs      5369:     }
                   5370:   cssRule = SkipWord (cssRule);
                   5371:   /* install the new presentation */
1.366     vatton   5372:   if (page.typed_data.unit == UNIT_REL || page.typed_data.unit == VALUE_INHERIT)
                   5373:     {
                   5374:       if (DoDialog)
                   5375:         DisplayStyleValue ("page-break-after", start_value, cssRule);
1.367     cvs      5376:       //else if (DoApply)
                   5377:         // TtaSetStylePresentation (PRPageAfter, element, tsch, ctxt, page);
1.366     vatton   5378:     }
1.59      cvs      5379:   return (cssRule);
                   5380: }
                   5381: 
                   5382: /*----------------------------------------------------------------------
1.327     vatton   5383:   ParseCSSPageBreakInside: parse a CSS page-break-inside attribute 
1.59      cvs      5384:   ----------------------------------------------------------------------*/
1.79      cvs      5385: static char *ParseCSSPageBreakInside (Element element, PSchema tsch,
1.327     vatton   5386:                                       PresentationContext ctxt,
                   5387:                                       char *cssRule, CSSInfoPtr css,
                   5388:                                       ThotBool isHTML)
1.59      cvs      5389: {
                   5390:   PresentationValue   page;
1.366     vatton   5391:   char               *start_value;
1.59      cvs      5392: 
1.184     vatton   5393:   page.typed_data.unit = UNIT_INVALID;
1.59      cvs      5394:   page.typed_data.real = FALSE;
1.82      cvs      5395:   cssRule = SkipBlanksAndComments (cssRule);
1.366     vatton   5396:   start_value = cssRule;
1.82      cvs      5397:   if (!strncasecmp (cssRule, "auto", 4))
1.59      cvs      5398:     {
1.184     vatton   5399:       /*page.typed_data.unit = UNIT_REL;*/
                   5400:       page.typed_data.value = PageAuto;
1.59      cvs      5401:     }
1.82      cvs      5402:   else if (!strncasecmp (cssRule, "avoid", 5))
1.59      cvs      5403:     {
1.184     vatton   5404:       page.typed_data.unit = UNIT_REL;
                   5405:       page.typed_data.value = PageAvoid;
1.59      cvs      5406:     }
1.82      cvs      5407:   else if (!strncasecmp (cssRule, "inherit", 7))
1.59      cvs      5408:     {
1.293     quint    5409:       /* page.typed_data.unit = VALUE_INHERIT; */
1.184     vatton   5410:       page.typed_data.value = PageInherit;
1.59      cvs      5411:     }
                   5412:   cssRule = SkipWord (cssRule);
                   5413:   /* install the new presentation */
1.366     vatton   5414:   if ((page.typed_data.unit == UNIT_REL || page.typed_data.unit == VALUE_INHERIT) &&
                   5415:       page.typed_data.value == PageAvoid)
                   5416:     {
                   5417:       if (DoDialog)
                   5418:         DisplayStyleValue ("page-break-inside", start_value, cssRule);
1.367     cvs      5419:       //else if (DoApply)
                   5420:         //TtaSetStylePresentation (PRPageInside, element, tsch, ctxt, page);
1.366     vatton   5421:     }
1.59      cvs      5422:   return (cssRule);
                   5423: }
1.18      cvs      5424: 
1.60      cvs      5425: /*----------------------------------------------------------------------
1.327     vatton   5426:   ParseSVGStrokeWidth: parse a SVG stroke-width property value.
1.60      cvs      5427:   ----------------------------------------------------------------------*/
1.79      cvs      5428: static char *ParseSVGStrokeWidth (Element element, PSchema tsch,
1.327     vatton   5429:                                   PresentationContext ctxt, char *cssRule,
                   5430:                                   CSSInfoPtr css, ThotBool isHTML)
1.60      cvs      5431: {
                   5432:   PresentationValue   width;
                   5433:   
1.82      cvs      5434:   cssRule = SkipBlanksAndComments (cssRule);
1.60      cvs      5435:   width.typed_data.value = 0;
1.184     vatton   5436:   width.typed_data.unit = UNIT_INVALID;
1.60      cvs      5437:   width.typed_data.real = FALSE;
1.110     vatton   5438:   if (isdigit (*cssRule) || *cssRule == '.')
1.166     vatton   5439:     {
1.327     vatton   5440:       cssRule = ParseCSSUnit (cssRule, &width);
                   5441:       if (width.typed_data.unit == UNIT_BOX)
                   5442:         width.typed_data.unit = UNIT_PX;
1.166     vatton   5443:     }
1.295     vatton   5444:   else
                   5445:     cssRule = SkipValue ("Invalid stroke-width value", cssRule);
                   5446: 
1.184     vatton   5447:   if (width.typed_data.unit != UNIT_INVALID && DoApply)
1.117     vatton   5448:     {
1.207     vatton   5449:       TtaSetStylePresentation (PRLineWeight, element, tsch, ctxt, width);
1.117     vatton   5450:       width.typed_data.value = 1;
1.184     vatton   5451:       width.typed_data.unit = UNIT_REL;
1.117     vatton   5452:     }
1.60      cvs      5453:   return (cssRule);
                   5454: }
                   5455: 
1.217     vatton   5456: /*----------------------------------------------------------------------
1.327     vatton   5457:   ParseCSSPosition: parse a CSS Position attribute string.
1.217     vatton   5458:   ----------------------------------------------------------------------*/
                   5459: static char *ParseCSSPosition (Element element, PSchema tsch,
1.327     vatton   5460:                                PresentationContext ctxt, char *cssRule,
                   5461:                                CSSInfoPtr css, ThotBool isHTML)
1.217     vatton   5462: {
1.305     quint    5463:   char               *ptr;
                   5464:   PresentationValue   pval;
1.217     vatton   5465: 
1.305     quint    5466:   pval.typed_data.value = 0;
                   5467:   pval.typed_data.unit = UNIT_BOX;
                   5468:   pval.typed_data.real = FALSE;
1.217     vatton   5469:   cssRule = SkipBlanksAndComments (cssRule);
                   5470:   ptr = cssRule;
                   5471:   if (!strncasecmp (cssRule, "static", 6))
1.337     vatton   5472:     {
                   5473:       pval.typed_data.value = PositionStatic;
                   5474:       cssRule += 6;
                   5475:     }
                   5476:   else if (!strncasecmp (cssRule, "relative", 8))
                   5477:     {
                   5478:       pval.typed_data.value = PositionRelative;
                   5479:       cssRule += 8;
                   5480:     }
1.217     vatton   5481:   else if (!strncasecmp (cssRule, "absolute", 8))
1.337     vatton   5482:     {
                   5483:       pval.typed_data.value = PositionAbsolute;
                   5484:       cssRule += 8;
                   5485:     }
1.217     vatton   5486:   else if (!strncasecmp (cssRule, "fixed", 5))
1.337     vatton   5487:     {
                   5488:       pval.typed_data.value = PositionFixed;
                   5489:       cssRule += 5;
                   5490:     }
1.217     vatton   5491:   else if (!strncasecmp (cssRule, "inherit", 7))
1.337     vatton   5492:     {
                   5493:       pval.typed_data.unit = VALUE_INHERIT;
                   5494:       cssRule += 7;
                   5495:     }
1.305     quint    5496: 
                   5497:   if (pval.typed_data.value == 0 && pval.typed_data.unit != VALUE_INHERIT)
                   5498:     {
                   5499:       cssRule = SkipValue ("Invalid position value", ptr);
                   5500:       cssRule = SkipValue (NULL, cssRule);
                   5501:     }
1.217     vatton   5502:   else
1.305     quint    5503:     {
1.337     vatton   5504:       cssRule = SkipBlanksAndComments (cssRule);
                   5505:       if (*cssRule != EOS && *cssRule != ';')
                   5506:         SkipValue ("Invalid position value", ptr);
1.366     vatton   5507:       else if (DoDialog)
                   5508:         DisplayStyleValue ("position", ptr, cssRule);
1.337     vatton   5509:       else if (DoApply)
1.327     vatton   5510:         TtaSetStylePresentation (PRPosition, element, tsch, ctxt, pval);
1.305     quint    5511:     }
1.217     vatton   5512:   return (cssRule);
                   5513: }
                   5514: 
                   5515: /*----------------------------------------------------------------------
1.327     vatton   5516:   ParseCSSTop: parse a CSS Top attribute
1.217     vatton   5517:   ----------------------------------------------------------------------*/
                   5518: static char *ParseCSSTop (Element element, PSchema tsch,
1.327     vatton   5519:                           PresentationContext context, char *cssRule,
                   5520:                           CSSInfoPtr css, ThotBool isHTML)
1.217     vatton   5521: {
                   5522:   PresentationValue   val;
                   5523:   char               *ptr;
                   5524: 
1.370     vatton   5525:   val.typed_data.real = FALSE;
1.217     vatton   5526:   cssRule = SkipBlanksAndComments (cssRule);
                   5527:   ptr = cssRule;
1.305     quint    5528:   /* first parse the value */
                   5529:   if (!strncasecmp (cssRule, "auto", 4))
1.217     vatton   5530:     {
                   5531:       val.typed_data.unit = VALUE_AUTO;
                   5532:       val.typed_data.value = 0;
                   5533:       cssRule = SkipWord (cssRule);
                   5534:     }
1.305     quint    5535:   else if (!strncasecmp (cssRule, "inherit", 7))
                   5536:     {
                   5537:       val.typed_data.unit = VALUE_INHERIT;
                   5538:       cssRule = SkipWord (cssRule);
                   5539:     }
1.217     vatton   5540:   else
                   5541:     cssRule = ParseCSSUnit (cssRule, &val);
                   5542:   if (val.typed_data.value != 0 &&
                   5543:       (val.typed_data.unit == UNIT_INVALID ||
                   5544:        val.typed_data.unit == UNIT_BOX))
                   5545:     {
1.218     vatton   5546:       cssRule = SkipValue ("top value", ptr);
1.217     vatton   5547:       val.typed_data.unit = UNIT_PX;
                   5548:     }
1.366     vatton   5549:   if (DoDialog)
                   5550:         DisplayStyleValue ("top", ptr, cssRule);
                   5551:   else if (DoApply)
1.305     quint    5552:     TtaSetStylePresentation (PRTop, element, tsch, context, val);
1.217     vatton   5553:   return (cssRule);
                   5554: }
                   5555: 
                   5556: /*----------------------------------------------------------------------
1.327     vatton   5557:   ParseCSSRight: parse a CSS Right attribute
1.217     vatton   5558:   ----------------------------------------------------------------------*/
                   5559: static char *ParseCSSRight (Element element, PSchema tsch,
1.327     vatton   5560:                             PresentationContext context, char *cssRule,
                   5561:                             CSSInfoPtr css, ThotBool isHTML)
1.217     vatton   5562: {
                   5563:   PresentationValue   val;
                   5564:   char               *ptr;
                   5565: 
1.370     vatton   5566:   val.typed_data.real = FALSE;
1.217     vatton   5567:   cssRule = SkipBlanksAndComments (cssRule);
                   5568:   ptr = cssRule;
                   5569:   /* first parse the attribute string */
1.305     quint    5570:   if (!strncasecmp (cssRule, "auto", 4))
1.217     vatton   5571:     {
                   5572:       val.typed_data.unit = VALUE_AUTO;
                   5573:       val.typed_data.value = 0;
                   5574:       cssRule = SkipWord (cssRule);
                   5575:     }
1.305     quint    5576:   else if (!strncasecmp (cssRule, "inherit", 7))
                   5577:     {
                   5578:       val.typed_data.unit = VALUE_INHERIT;
                   5579:       cssRule = SkipWord (cssRule);
                   5580:     }
1.217     vatton   5581:   else
                   5582:     cssRule = ParseCSSUnit (cssRule, &val);
                   5583:   if (val.typed_data.value != 0 &&
                   5584:       (val.typed_data.unit == UNIT_INVALID ||
                   5585:        val.typed_data.unit == UNIT_BOX))
                   5586:     {
1.218     vatton   5587:       cssRule = SkipValue ("right value", ptr);
1.217     vatton   5588:       val.typed_data.unit = UNIT_PX;
                   5589:     }
1.366     vatton   5590:   if (DoDialog)
                   5591:         DisplayStyleValue ("right", ptr, cssRule);
                   5592:   else if (DoApply)
1.305     quint    5593:     TtaSetStylePresentation (PRRight, element, tsch, context, val);
1.217     vatton   5594:   return (cssRule);
                   5595: }
                   5596: 
                   5597: /*----------------------------------------------------------------------
1.327     vatton   5598:   ParseCSSBottom: parse a CSS Bottom attribute
1.217     vatton   5599:   ----------------------------------------------------------------------*/
                   5600: static char *ParseCSSBottom (Element element, PSchema tsch,
1.327     vatton   5601:                              PresentationContext context, char *cssRule,
                   5602:                              CSSInfoPtr css, ThotBool isHTML)
1.217     vatton   5603: {
                   5604:   PresentationValue   val;
                   5605:   char               *ptr;
                   5606: 
1.370     vatton   5607:   val.typed_data.real = FALSE;
1.217     vatton   5608:   cssRule = SkipBlanksAndComments (cssRule);
                   5609:   ptr = cssRule;
                   5610:   /* first parse the attribute string */
1.305     quint    5611:   if (!strncasecmp (cssRule, "auto", 4))
1.217     vatton   5612:     {
                   5613:       val.typed_data.unit = VALUE_AUTO;
                   5614:       val.typed_data.value = 0;
                   5615:       cssRule = SkipWord (cssRule);
                   5616:     }
1.305     quint    5617:   else if (!strncasecmp (cssRule, "inherit", 7))
                   5618:     {
                   5619:       val.typed_data.unit = VALUE_INHERIT;
                   5620:       cssRule = SkipWord (cssRule);
                   5621:     }
1.217     vatton   5622:   else
                   5623:     cssRule = ParseCSSUnit (cssRule, &val);
                   5624:   if (val.typed_data.value != 0 &&
                   5625:       (val.typed_data.unit == UNIT_INVALID ||
                   5626:        val.typed_data.unit == UNIT_BOX))
                   5627:     {
1.218     vatton   5628:       cssRule = SkipValue ("bottom value", ptr);
1.217     vatton   5629:       val.typed_data.unit = UNIT_PX;
                   5630:     }
1.366     vatton   5631:   if (DoDialog)
                   5632:         DisplayStyleValue ("bottom", ptr, cssRule);
                   5633:   else if (DoApply)
1.305     quint    5634:     TtaSetStylePresentation (PRBottom, element, tsch, context, val);
1.217     vatton   5635:   return (cssRule);
                   5636: }
                   5637: 
                   5638: /*----------------------------------------------------------------------
1.327     vatton   5639:   ParseCSSLeft: parse a CSS Left attribute
1.217     vatton   5640:   ----------------------------------------------------------------------*/
                   5641: static char *ParseCSSLeft (Element element, PSchema tsch,
1.327     vatton   5642:                            PresentationContext context, char *cssRule,
                   5643:                            CSSInfoPtr css, ThotBool isHTML)
1.217     vatton   5644: {
                   5645:   PresentationValue   val;
                   5646:   char               *ptr;
                   5647: 
1.370     vatton   5648:   val.typed_data.real = FALSE;
1.217     vatton   5649:   cssRule = SkipBlanksAndComments (cssRule);
                   5650:   ptr = cssRule;
                   5651:   /* first parse the attribute string */
1.305     quint    5652:   if (!strncasecmp (cssRule, "auto", 4))
1.217     vatton   5653:     {
                   5654:       val.typed_data.unit = VALUE_AUTO;
                   5655:       val.typed_data.value = 0;
                   5656:       cssRule = SkipWord (cssRule);
                   5657:     }
1.305     quint    5658:   else if (!strncasecmp (cssRule, "inherit", 7))
                   5659:     {
                   5660:       val.typed_data.unit = VALUE_INHERIT;
                   5661:       cssRule = SkipWord (cssRule);
                   5662:     }
1.217     vatton   5663:   else
                   5664:     cssRule = ParseCSSUnit (cssRule, &val);
                   5665:   if (val.typed_data.value != 0 &&
                   5666:       (val.typed_data.unit == UNIT_INVALID ||
                   5667:        val.typed_data.unit == UNIT_BOX))
                   5668:     {
1.218     vatton   5669:       cssRule = SkipValue ("left value", ptr);
1.217     vatton   5670:       val.typed_data.unit = UNIT_PX;
                   5671:     }
1.366     vatton   5672:   if (DoDialog)
                   5673:         DisplayStyleValue ("left", ptr, cssRule);
                   5674:   else if (DoApply)
1.305     quint    5675:     TtaSetStylePresentation (PRLeft, element, tsch, context, val);
1.217     vatton   5676:   return (cssRule);
                   5677: }
                   5678: 
                   5679: /*----------------------------------------------------------------------
1.327     vatton   5680:   ParseCSSZIndex: parse a CSS z-index attribute
1.217     vatton   5681:   ----------------------------------------------------------------------*/
                   5682: static char *ParseCSSZIndex (Element element, PSchema tsch,
1.327     vatton   5683:                              PresentationContext context, char *cssRule,
                   5684:                              CSSInfoPtr css, ThotBool isHTML)
1.217     vatton   5685: {
                   5686:   PresentationValue   val;
                   5687:   char               *ptr;
                   5688: 
1.370     vatton   5689:   val.typed_data.real = FALSE;
1.217     vatton   5690:   cssRule = SkipBlanksAndComments (cssRule);
                   5691:   ptr = cssRule;
                   5692:   /* first parse the attribute string */
                   5693:   if (!strncasecmp (cssRule, "auto", 4) ||
                   5694:       !strncasecmp (cssRule, "inherit", 7))
                   5695:     {
                   5696:       val.typed_data.unit = VALUE_AUTO;
                   5697:       val.typed_data.value = 0;
                   5698:       cssRule = SkipWord (cssRule);
                   5699:     }
                   5700:   else
                   5701:     {
                   5702:       cssRule = ParseCSSUnit (cssRule, &val);
                   5703:       if (val.typed_data.unit != UNIT_BOX)
1.327     vatton   5704:         {
                   5705:           cssRule = SkipValue ("z-index value", ptr);
                   5706:           val.typed_data.unit = UNIT_BOX;
                   5707:         }
1.217     vatton   5708:     }
1.366     vatton   5709:   if (DoDialog)
                   5710:         DisplayStyleValue ("z-index", ptr, cssRule);
1.217     vatton   5711:   /***
1.327     vatton   5712:       if (DoApply)
                   5713:       TtaSetStylePresentation (PR, element, tsch, context, val);
1.217     vatton   5714:   ***/
                   5715:   return (cssRule);
                   5716: }
                   5717: 
1.340     quint    5718: /*----------------------------------------------------------------------
                   5719:  *
                   5720:  *     FUNCTIONS STYLE DECLARATIONS
                   5721:  *
                   5722:  *----------------------------------------------------------------------*/
1.18      cvs      5723: /*
1.59      cvs      5724:  * NOTE: Long attribute name MUST be placed before shortened ones !
1.18      cvs      5725:  *        e.g. "FONT-SIZE" must be placed before "FONT"
                   5726:  */
                   5727: static CSSProperty CSSProperties[] =
1.327     vatton   5728:   {
                   5729:     {"background-color", ParseCSSBackgroundColor},
                   5730:     {"background-image", ParseCSSBackgroundImage},
                   5731:     {"background-repeat", ParseCSSBackgroundRepeat},
                   5732:     {"background-attachment", ParseCSSBackgroundAttachment},
                   5733:     {"background-position", ParseCSSBackgroundPosition},
                   5734:     {"background", ParseCSSBackground},
                   5735:     {"border-top-width", ParseCSSBorderTopWidth},
                   5736:     {"border-right-width", ParseCSSBorderRightWidth},
                   5737:     {"border-bottom-width", ParseCSSBorderBottomWidth},
                   5738:     {"border-left-width", ParseCSSBorderLeftWidth},
                   5739:     {"border-width", ParseCSSBorderWidth},
                   5740:     {"border-top-color", ParseCSSBorderColorTop},
                   5741:     {"border-right-color", ParseCSSBorderColorRight},
                   5742:     {"border-bottom-color", ParseCSSBorderColorBottom},
                   5743:     {"border-left-color", ParseCSSBorderColorLeft},
                   5744:     {"border-color", ParseCSSBorderColor},
                   5745:     {"border-top-style", ParseCSSBorderStyleTop},
                   5746:     {"border-right-style", ParseCSSBorderStyleRight},
                   5747:     {"border-bottom-style", ParseCSSBorderStyleBottom},
                   5748:     {"border-left-style", ParseCSSBorderStyleLeft},
                   5749:     {"border-style", ParseCSSBorderStyle},
                   5750:     {"border-top", ParseCSSBorderTop},
                   5751:     {"border-right", ParseCSSBorderRight},
                   5752:     {"border-bottom", ParseCSSBorderBottom},
                   5753:     {"border-left", ParseCSSBorderLeft},
                   5754:     {"border", ParseCSSBorder},
                   5755:     {"bottom", ParseCSSBottom},
                   5756:     {"clear", ParseCSSClear},
                   5757:     {"color", ParseCSSForeground},
                   5758:     {"content", ParseCSSContent},
                   5759:     {"direction", ParseCSSDirection},
                   5760:     {"display", ParseCSSDisplay},
                   5761:     {"float", ParseCSSFloat},
                   5762:     {"font-family", ParseCSSFontFamily},
                   5763:     {"font-style", ParseCSSFontStyle},
                   5764:     {"font-variant", ParseCSSFontVariant},
                   5765:     {"font-weight", ParseCSSFontWeight},
                   5766:     {"font-size-adjust", ParseCSSFontSizeAdjust},
                   5767:     {"font-size", ParseCSSFontSize},
                   5768:     {"font", ParseCSSFont},
                   5769:     {"height", ParseCSSHeight},
                   5770:     {"left", ParseCSSLeft},
                   5771:     {"letter-spacing", ParseCSSLetterSpacing},
                   5772:     {"line-height", ParseCSSLineHeight},
                   5773:     {"list-style-type", ParseCSSListStyleType},
                   5774:     {"list-style-image", ParseCSSListStyleImage},
                   5775:     {"list-style-position", ParseCSSListStylePosition},
                   5776:     {"list-style", ParseCSSListStyle},
                   5777:     {"margin-bottom", ParseCSSMarginBottom},
                   5778:     {"margin-top", ParseCSSMarginTop},
                   5779:     {"margin-right", ParseCSSMarginRight},
                   5780:     {"margin-left", ParseCSSMarginLeft},
                   5781:     {"margin", ParseCSSMargin},
                   5782:     {"padding-top", ParseCSSPaddingTop},
                   5783:     {"padding-right", ParseCSSPaddingRight},
                   5784:     {"padding-bottom", ParseCSSPaddingBottom},
                   5785:     {"padding-left", ParseCSSPaddingLeft},
                   5786:     {"padding", ParseCSSPadding},
                   5787:     {"page-break-before", ParseCSSPageBreakBefore},
                   5788:     {"page-break-after", ParseCSSPageBreakAfter},
                   5789:     {"page-break-inside", ParseCSSPageBreakInside},
                   5790:     {"position", ParseCSSPosition},
                   5791:     {"right", ParseCSSRight},
                   5792:     {"text-align", ParseCSSTextAlign},
                   5793:     {"text-anchor", ParseCSSTextAnchor},
                   5794:     {"text-indent", ParseCSSTextIndent},
                   5795:     {"text-decoration", ParseCSSTextDecoration},
                   5796:     {"text-transform", ParseCSSTextTransform},
                   5797:     {"top", ParseCSSTop},
                   5798:     {"unicode-bidi", ParseCSSUnicodeBidi},
                   5799:     {"vertical-align", ParseCSSVerticalAlign},
                   5800:     {"white-space", ParseCSSWhiteSpace},
                   5801:     {"width", ParseCSSWidth},
1.333     vatton   5802:     {"visibility", ParseCSSVisibility},
1.327     vatton   5803:     {"word-spacing", ParseCSSWordSpacing},
                   5804:     {"z-index", ParseCSSZIndex},
                   5805: 
                   5806:     /* SVG extensions */
                   5807:     {"fill-opacity", ParseSVGFillOpacity},
                   5808:     {"fill", ParseSVGFill},
                   5809:     {"opacity", ParseSVGOpacity},
                   5810:     {"stroke-opacity", ParseSVGStrokeOpacity},
                   5811:     {"stroke-width", ParseSVGStrokeWidth},
                   5812:     {"stroke", ParseSVGStroke}
                   5813:   };
1.155     cheyroul 5814: 
1.18      cvs      5815: #define NB_CSSSTYLEATTRIBUTE (sizeof(CSSProperties) / sizeof(CSSProperty))
                   5816: 
                   5817: /*----------------------------------------------------------------------
1.327     vatton   5818:   ParseCSSRule: parse a CSS Style string                        
                   5819:   we expect the input string describing the style to be of the form
                   5820:   property: value [ ; property: value ]* 
                   5821:   but tolerate incorrect or incomplete input                    
1.18      cvs      5822:   ----------------------------------------------------------------------*/
1.366     vatton   5823: void  ParseCSSRule (Element element, PSchema tsch, PresentationContext ctxt,
                   5824:                     char *cssRule, CSSInfoPtr css, ThotBool isHTML)
1.18      cvs      5825: {
1.366     vatton   5826:   DisplayMode         dispMode = DisplayImmediately;
1.312     quint    5827:   char               *p = NULL, *next, *end;
1.214     quint    5828:   char               *valueStart;
1.18      cvs      5829:   int                 lg;
1.34      cvs      5830:   unsigned int        i;
1.76      cvs      5831:   ThotBool            found;
1.18      cvs      5832: 
1.34      cvs      5833:   /* avoid too many redisplay */
1.366     vatton   5834:   if (!DoDialog && ctxt->doc)
                   5835:     {
                   5836:       dispMode = TtaGetDisplayMode (ctxt->doc);
                   5837:       if (dispMode == DisplayImmediately)
                   5838:         TtaSetDisplayMode (ctxt->doc, DeferredDisplay);
                   5839:     }
1.34      cvs      5840: 
1.82      cvs      5841:   while (*cssRule != EOS)
1.18      cvs      5842:     {
1.82      cvs      5843:       cssRule = SkipBlanksAndComments (cssRule);
1.371     vatton   5844:       if (*cssRule == ';' || *cssRule < 0x20 ||
1.372     vatton   5845:           ((unsigned char)*cssRule) == 0xA0)
1.371     vatton   5846:         cssRule++;
                   5847:       else if (*cssRule < 0x41 || *cssRule > 0x7A ||
                   5848:           (*cssRule > 0x5A && *cssRule < 0x61))
1.352     vatton   5849:         {
                   5850:           end = SkipProperty (cssRule, FALSE);
1.357     quint    5851:           CSSParseError ("Invalid property", cssRule, end);
1.352     vatton   5852:           cssRule = end; 
                   5853:         }
1.194     vatton   5854:       else if (*cssRule != EOS)
1.327     vatton   5855:         {
                   5856:           found = FALSE;
                   5857:           /* look for the type of property */
                   5858:           for (i = 0; i < NB_CSSSTYLEATTRIBUTE && !found; i++)
                   5859:             {
                   5860:               lg = strlen (CSSProperties[i].name);
                   5861:               if (!strncasecmp (cssRule, CSSProperties[i].name, lg))
                   5862:                 {
                   5863:                   p = cssRule + lg;
                   5864:                   found = TRUE;
                   5865:                   i--;
                   5866:                 }
                   5867:             }
                   5868: 
1.360     vatton   5869:           // check if it's an important rule
                   5870:           CheckImportantRule (cssRule, ctxt);
1.327     vatton   5871:           if (i < NB_CSSSTYLEATTRIBUTE &&
                   5872:               !strcasecmp (CSSProperties[i].name, "content") &&
                   5873:               ((GenericContext)ctxt)->pseudo != PbBefore &&
                   5874:               ((GenericContext)ctxt)->pseudo != PbAfter)
1.340     quint    5875:             /* property content is allowed only for pseudo-elements :before and
                   5876:                :after */
1.327     vatton   5877:             {
1.352     vatton   5878:               end = SkipProperty (cssRule, FALSE);
1.327     vatton   5879:               CSSParseError ("content is allowed only for pseudo-elements",
                   5880:                              cssRule, end);
1.352     vatton   5881:               cssRule = end;
1.327     vatton   5882:             }
1.352     vatton   5883:           else if (i == NB_CSSSTYLEATTRIBUTE)
1.376     vatton   5884:             cssRule = SkipProperty (cssRule, !ctxt->destroy);
1.327     vatton   5885:           else
                   5886:             {
                   5887:               /* update index and skip the ":" indicator if present */
                   5888:               p = SkipBlanksAndComments (p);
                   5889:               if (*p == ':')
                   5890:                 {
                   5891:                   p++;
                   5892:                   p = SkipBlanksAndComments (p);
                   5893:                   /* try to parse the value associated with this property */
                   5894:                   if (CSSProperties[i].parsing_function != NULL)
                   5895:                     {
                   5896:                       valueStart = p;
                   5897:                       p = CSSProperties[i].parsing_function (element, tsch,
                   5898:                                                              ctxt, p, css, isHTML);
                   5899:                       if (!element && isHTML)
                   5900:                         {
                   5901:                           if  (ctxt->type == HTML_EL_Input)
                   5902:                             /* it's a generic rule for the HTML element input.
                   5903:                                Generate a Thot Pres rule for each kind of
                   5904:                                input element */
                   5905:                             {
                   5906:                               ctxt->type = HTML_EL_Text_Input;
                   5907:                               p = CSSProperties[i].parsing_function (element,
                   5908:                                                                      tsch, ctxt, valueStart, css, isHTML);
                   5909:                               ctxt->type = HTML_EL_Password_Input;
                   5910:                               p = CSSProperties[i].parsing_function (element,
                   5911:                                                                      tsch, ctxt, valueStart, css, isHTML);
                   5912:                               ctxt->type = HTML_EL_File_Input;
                   5913:                               p = CSSProperties[i].parsing_function (element,
                   5914:                                                                      tsch, ctxt, valueStart, css, isHTML);
                   5915:                               ctxt->type = HTML_EL_Checkbox_Input;
                   5916:                               p = CSSProperties[i].parsing_function (element,
                   5917:                                                                      tsch, ctxt, valueStart, css, isHTML);
                   5918:                               ctxt->type = HTML_EL_Radio_Input;
                   5919:                               p = CSSProperties[i].parsing_function (element,
                   5920:                                                                      tsch, ctxt, valueStart, css, isHTML);
                   5921:                               ctxt->type = HTML_EL_Submit_Input;
                   5922:                               p = CSSProperties[i].parsing_function (element,
                   5923:                                                                      tsch, ctxt, valueStart, css, isHTML);
                   5924:                               ctxt->type = HTML_EL_Reset_Input;
                   5925:                               p = CSSProperties[i].parsing_function (element,
                   5926:                                                                      tsch, ctxt, valueStart, css, isHTML);
                   5927:                               ctxt->type = HTML_EL_Button_Input;
                   5928:                               p = CSSProperties[i].parsing_function (element,
                   5929:                                                                      tsch, ctxt, valueStart, css, isHTML);
                   5930:                               ctxt->type = HTML_EL_Input;
                   5931:                             }
                   5932:                           else if (ctxt->type == HTML_EL_ruby)
                   5933:                             /* it's a generic rule for the HTML element ruby.
                   5934:                                Generate a Thot Pres rule for each kind of
                   5935:                                ruby element. */
                   5936:                             {
                   5937:                               ctxt->type = HTML_EL_simple_ruby;
                   5938:                               p = CSSProperties[i].parsing_function (element,
                   5939:                                                                      tsch, ctxt, valueStart, css, isHTML);
                   5940:                               ctxt->type = HTML_EL_complex_ruby;
                   5941:                               p = CSSProperties[i].parsing_function (element,
                   5942:                                                                      tsch, ctxt, valueStart, css, isHTML);
                   5943:                               ctxt->type = HTML_EL_ruby;
                   5944:                             }
                   5945:                         }
                   5946:                       /* update index and skip the ";" separator if present */
                   5947:                       next = SkipBlanksAndComments (p);
                   5948:                       if (*next != EOS && *next != ';')
                   5949:                         CSSParseError ("Missing closing ';'", cssRule, p);
                   5950:                       cssRule = next;
                   5951:                     }
                   5952:                 }
                   5953:               else
                   5954:                 cssRule = SkipProperty (cssRule, TRUE);
                   5955:             }
1.360     vatton   5956:           // skip important markup
                   5957:           cssRule = SkipImportantRule (cssRule);
                   5958: 
1.327     vatton   5959:         }
1.18      cvs      5960:       /* next property */
1.82      cvs      5961:       cssRule = SkipBlanksAndComments (cssRule);
1.89      cvs      5962:       if (*cssRule == '}')
1.327     vatton   5963:         {
                   5964:           cssRule++;
                   5965:           CSSPrintError ("Invalid character", "}");
                   5966:           cssRule = SkipBlanksAndComments (cssRule);
                   5967:         }
1.155     cheyroul 5968:       if (*cssRule == ',' ||
1.327     vatton   5969:           *cssRule == ';')
                   5970:         {
                   5971:           cssRule++;
                   5972:           cssRule = SkipBlanksAndComments (cssRule);
                   5973:         }
1.18      cvs      5974:     }
1.34      cvs      5975: 
                   5976:   /* restore the display mode */
1.366     vatton   5977:   if (!DoDialog && ctxt->doc && dispMode == DisplayImmediately)
1.207     vatton   5978:     TtaSetDisplayMode (ctxt->doc, dispMode);
1.18      cvs      5979: }
1.1       cvs      5980: 
1.111     cvs      5981: /*----------------------------------------------------------------------
1.327     vatton   5982:   ParseHTMLSpecificStyle: parse and apply a CSS Style string.
                   5983:   This function must be called when a specific style is applied to an
                   5984:   element.
                   5985:   The parameter specificity is the specificity of the style, 0 if it is
                   5986:   not really a CSS rule.
1.1       cvs      5987:   ----------------------------------------------------------------------*/
1.79      cvs      5988: void  ParseHTMLSpecificStyle (Element el, char *cssRule, Document doc,
1.377   ! quint    5989:                              int specificity, ThotBool destroy)
1.1       cvs      5990: {
1.257     vatton   5991:   DisplayMode         dispMode;
1.207     vatton   5992:   PresentationContext ctxt;
                   5993:   ElementType         elType;
                   5994:   ThotBool            isHTML;
1.1       cvs      5995: 
1.207     vatton   5996:   /*  A rule applying to BODY is really meant to address HTML */
                   5997:   elType = TtaGetElementType (el);
1.286     quint    5998:   NewLineSkipped = 0;
1.207     vatton   5999:   /* store the current line for eventually reported errors */
                   6000:   LineNumber = TtaGetElementLineNumber (el);
                   6001:   if (destroy)
                   6002:     /* no reported errors */
                   6003:     ParsedDoc = 0;
                   6004:   else if (ParsedDoc != doc)
                   6005:     {
                   6006:       /* update the context for reported errors */
                   6007:       ParsedDoc = doc;
1.348     vatton   6008:       Error_DocURL = DocumentURLs[doc];
1.207     vatton   6009:     }
                   6010:   isHTML = (strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML") == 0);
                   6011:   /* create the context of the Specific presentation driver */
                   6012:   ctxt = TtaGetSpecificStyleContext (doc);
                   6013:   if (ctxt == NULL)
                   6014:     return;
                   6015:   ctxt->type = elType.ElTypeNum;
                   6016:   ctxt->cssSpecificity = specificity;
1.236     quint    6017:   ctxt->cssLine = LineNumber;
1.207     vatton   6018:   ctxt->destroy = destroy;
                   6019:   /* first use of the context */
                   6020:   ctxt->uses = 1;
1.257     vatton   6021:   /* save the current display mode */
                   6022:   dispMode = TtaGetDisplayMode (doc);
1.207     vatton   6023:   /* Call the parser */
1.366     vatton   6024:   DoDialog = FALSE; // not parsing for CSS dialog
1.207     vatton   6025:   ParseCSSRule (el, NULL, (PresentationContext) ctxt, cssRule, NULL, isHTML);
1.257     vatton   6026:   /* restore the display mode if necessary */
                   6027:   TtaSetDisplayMode (doc, dispMode);
1.207     vatton   6028:   /* check if the context can be freed */
                   6029:   ctxt->uses -= 1;
                   6030:   if (ctxt->uses == 0)
                   6031:     /* no image loading */
                   6032:     TtaFreeMemory(ctxt);
1.1       cvs      6033: }
                   6034: 
1.366     vatton   6035: 
1.343     vatton   6036: /*----------------------------------------------------------------------
                   6037:   AddClassName adds the class name into the class list of css if it's
                   6038:   not already there.
                   6039:   ----------------------------------------------------------------------*/
                   6040: static void AddClassName (char *name, CSSInfoPtr css)
                   6041: {
1.344     cvs      6042:   int                   l, index, k, length, add;
1.343     vatton   6043:   char          *buf;
                   6044:   ThotBool       found, previous;
                   6045: 
                   6046:   l = strlen (name);
                   6047:   if (l == 0 || css == NULL)
                   6048:     return;
                   6049:   if (css->class_list)
                   6050:     {
                   6051:       buf = css->class_list;
                   6052:       length = strlen (css->class_list);
                   6053:     }
                   6054:   else
                   6055:     {
                   6056:       if (l > 200)
                   6057:         length = l + 1;
                   6058:       else
                   6059:         length = 200;
                   6060:       buf = (char *)TtaGetMemory (length * sizeof (char));
                   6061:       memset (buf, 0, length);
                   6062:       css->class_list = buf;
                   6063:       css->lg_class_list = length;
                   6064:       length = 0;
                   6065:     }
                   6066: 
                   6067:   /* compare that name with all class names already known */
                   6068:   index = 0;
                   6069:   found = FALSE;
                   6070:   previous = FALSE;
                   6071:   while (index < length && !found && !previous)
                   6072:     {
                   6073:       k = 0;
                   6074:       while (k < l && buf[index + k] != EOS && buf[index + k] != SPACE)
                   6075:         {
                   6076:           if (name[k] == buf[index+k])
                   6077:             k++;
                   6078:           else
                   6079:             {
                   6080:               previous = (name[k] < buf[index + k]);
                   6081:               break;
                   6082:             }
                   6083:         }
                   6084:       found = (k == l);
                   6085:       if (!previous)
                   6086:         {
                   6087:           index += k;
                   6088:           while (buf[index] != EOS && buf[index] != SPACE)
                   6089:             index++;
                   6090:           if (buf[index] == SPACE)
                   6091:             index++;
                   6092:         }
                   6093:     }
                   6094:   
                   6095:   if (!found)
                   6096:     /* this class name is not known, append it */
                   6097:     {
                   6098:       l++; /* add a space before */
                   6099:       if (css->lg_class_list <= length + l)
                   6100:         {
                   6101:           // increase the list size
                   6102:           if (l > 200)
                   6103:             add = l + 1;
                   6104:           else
                   6105:             add = 200 ;
                   6106:           buf = (char *)TtaRealloc (buf, css->lg_class_list + (add * sizeof (char)));
                   6107:           if (buf == NULL)
                   6108:             return;
                   6109:           else
                   6110:             {
                   6111:             css->class_list = buf;
                   6112:             memset (&buf[css->lg_class_list], 0, add);
                   6113:             css->lg_class_list += add;
                   6114:             }
                   6115:         }
                   6116: 
                   6117:       if (previous)
                   6118:         {
                   6119:           // move the tail of the current list
                   6120:           for (k = length; k >= index; k--)
                   6121:             buf[k+l] = buf[k];
                   6122:           /* add this new class name at the current position */
                   6123:            strcpy (&buf[index], name);
                   6124:           buf[index + l - 1] = SPACE;
                   6125:         }
                   6126:       else
                   6127:         {
                   6128:           /* add this new class name at the end */
                   6129:           if (index != 0)
                   6130:             buf[index++] = SPACE;
                   6131:           strcpy (&buf[index], name);
                   6132:         }
                   6133:      }
                   6134: }
                   6135: 
1.68      cvs      6136: 
1.1       cvs      6137: /*----------------------------------------------------------------------
1.207     vatton   6138:   ParseGenericSelector: Create a generic context for a given selector
                   6139:   string.
                   6140:   If the selector is made of multiple comma, it parses them one at a time
                   6141:   and return the end of the selector string to be handled or NULL.
1.231     vatton   6142:   The parameter ctxt gives the current style context which will be passed
                   6143:   to Thotlib.
                   6144:   The parameter css points to the current CSS context.
                   6145:   The parameter link points to the link element.
                   6146:   The parameter url gives the URL of the parsed style sheet.
1.1       cvs      6147:   ----------------------------------------------------------------------*/
1.207     vatton   6148: static char *ParseGenericSelector (char *selector, char *cssRule,
1.327     vatton   6149:                                    GenericContext ctxt, Document doc,
                   6150:                                    CSSInfoPtr css, Element link, char *url)
1.79      cvs      6151: {
                   6152:   ElementType        elType;
                   6153:   PSchema            tsch;
1.119     vatton   6154:   AttributeType      attrType;
1.240     quint    6155:   char              *deb, *cur, *sel, *next, c;
1.317     vatton   6156:   char              *schemaName, *mappedName, *saveURL;
1.79      cvs      6157:   char              *names[MAX_ANCESTORS];
1.355     quint    6158:   ThotBool           pseudoFirstChild[MAX_ANCESTORS];
1.340     quint    6159:   ElemRel            rel[MAX_ANCESTORS];
                   6160:   char              *attrnames[MAX_ANCESTORS];
                   6161:   int                attrnums[MAX_ANCESTORS];
                   6162:   int                attrlevels[MAX_ANCESTORS];
1.79      cvs      6163:   char              *attrvals[MAX_ANCESTORS];
1.133     vatton   6164:   AttrMatch          attrmatch[MAX_ANCESTORS];
1.340     quint    6165:   int                nbnames, nbattrs;
                   6166:   int                i, j;
1.256     vatton   6167:   int                att, kind;
1.118     vatton   6168:   int                specificity, xmlType;
1.217     vatton   6169:   int                skippedNL;
1.79      cvs      6170:   ThotBool           isHTML;
1.347     quint    6171:   ThotBool           level, quoted, doubleColon;
1.340     quint    6172: #define ATTR_ID 1
                   6173: #define ATTR_CLASS 2
                   6174: #define ATTR_PSEUDO 3
1.1       cvs      6175: 
1.207     vatton   6176:   sel = ctxt->sel;
1.82      cvs      6177:   sel[0] = EOS;
1.117     vatton   6178:   specificity = 0;
1.1       cvs      6179:   for (i = 0; i < MAX_ANCESTORS; i++)
                   6180:     {
1.25      cvs      6181:       names[i] = NULL;
1.355     quint    6182:       pseudoFirstChild[i] = FALSE;
1.340     quint    6183:       rel[i] = RelAncestor;
                   6184:       attrnames[i] = NULL;
                   6185:       attrnums[i] = 0;
                   6186:       attrlevels[i] = 0;
1.25      cvs      6187:       attrvals[i] = NULL;
1.133     vatton   6188:       attrmatch[i] = Txtmatch;
1.25      cvs      6189:       ctxt->name[i] = 0;
1.355     quint    6190:       ctxt->firstChild[i] = FALSE;
1.25      cvs      6191:       ctxt->attrType[i] = 0;
1.129     vatton   6192:       ctxt->attrLevel[i] = 0;
1.25      cvs      6193:       ctxt->attrText[i] = NULL;
1.178     quint    6194:       ctxt->attrMatch[i] = Txtmatch;
1.1       cvs      6195:     }
1.25      cvs      6196:   ctxt->box = 0;
1.312     quint    6197:   ctxt->var = 0;
1.306     quint    6198:   ctxt->pseudo = PbNone;
1.25      cvs      6199:   ctxt->type = 0;
1.366     vatton   6200:   DoDialog = FALSE; // not arsing for CSS dialog
1.114     quint    6201:   /* the specificity of the rule depends on the selector */
                   6202:   ctxt->cssSpecificity = 0;
1.231     vatton   6203:   /* localisation of the CSS rule */
                   6204:   ctxt->cssLine = LineNumber + NewLineSkipped;
                   6205:   ctxt->cssURL = url;
1.240     quint    6206: 
1.286     quint    6207:   skippedNL = NewLineSkipped;
1.82      cvs      6208:   selector = SkipBlanksAndComments (selector);
1.286     quint    6209:   NewLineSkipped = skippedNL;
1.27      cvs      6210:   cur = &sel[0];
1.340     quint    6211:   nbnames = 0;
                   6212:   nbattrs = 0;
1.1       cvs      6213:   while (1)
                   6214:     {
1.85      cvs      6215:       /* point to the following word in sel[] */
1.27      cvs      6216:       deb = cur;
1.25      cvs      6217:       /* copy an item of the selector into sel[] */
1.1       cvs      6218:       /* put one word in the sel buffer */
1.82      cvs      6219:       while (*selector != EOS && *selector != ',' &&
                   6220:              *selector != '.' && *selector != ':' &&
1.118     vatton   6221:              *selector != '#' && *selector != '[' &&
1.250     vatton   6222:              *selector != '>' && *selector != '+' &&
1.327     vatton   6223:              !TtaIsBlank (selector))
                   6224:         *cur++ = *selector++;
1.82      cvs      6225:       *cur++ = EOS; /* close the first string  in sel[] */
                   6226:       if (deb[0] != EOS)
1.340     quint    6227:         /* the selector starts with an element name */
1.327     vatton   6228:         {
                   6229:           if (deb[0] <= 64 && deb[0] != '*')
                   6230:             {
                   6231:               CSSPrintError ("Invalid element", deb);
                   6232:               return NULL;
                   6233:             }
                   6234:           else
                   6235:             {
                   6236:               names[0] = deb;
                   6237:               if (!strcmp (names[0], "html"))
                   6238:                 /* give a greater priority to the backgoud color of html */
                   6239:                 specificity += 3;
                   6240:               else
                   6241:                 /* selector "*" has specificity zero */
                   6242:                 if (strcmp (names[0], "*"))
                   6243:                   specificity += 1;
                   6244:             }
                   6245:         }
1.25      cvs      6246:       else
1.340     quint    6247:         names[0] = NULL; /* no element name */
1.226     quint    6248: 
1.340     quint    6249:       rel[0] = RelVoid;
1.25      cvs      6250: 
1.27      cvs      6251:       /* now names[0] points to the beginning of the parsed item
1.340     quint    6252:          and cur to the next string to be parsed */
1.129     vatton   6253:       while (*selector == '.' || *selector == ':' ||
1.327     vatton   6254:              *selector == '#' || *selector == '[')
                   6255:         {
                   6256:           /* point to the following word in sel[] */
                   6257:           deb = cur;
                   6258:           if (*selector == '.')
1.340     quint    6259:             /* class */
1.327     vatton   6260:             {
                   6261:               selector++;
1.340     quint    6262:               while (*selector != '.' && *selector != ':' &&
                   6263:                      *selector != '#' && *selector != '[' &&
                   6264:                      *selector != EOS && *selector != ',' &&
                   6265:                      *selector != '+' && *selector != '>' &&
1.327     vatton   6266:                      !TtaIsBlank (selector))
                   6267:                 {
                   6268:                   if (*selector == '\\')
                   6269:                     {
                   6270:                       selector++;
                   6271:                       if (*selector != EOS)
                   6272:                         *cur++ = *selector++;
                   6273:                     }
                   6274:                   else
                   6275:                     *cur++ = *selector++;
                   6276:                 }
                   6277:               /* close the word */
                   6278:               *cur++ = EOS;
1.340     quint    6279:               /* point to the class in sel[] if it's a valid name */
1.327     vatton   6280:               if (deb[0] <= 64)
                   6281:                 {
                   6282:                   CSSPrintError ("Invalid class", deb);
                   6283:                   DoApply = FALSE;
                   6284:                 }
                   6285:               else
                   6286:                 {
1.340     quint    6287:                   /* simulate selector [class ~= "xxx"] */
                   6288:                   nbattrs++;
                   6289:                   if (nbattrs == MAX_ANCESTORS)
                   6290:                     /* abort parsing */
                   6291:                     {
                   6292:                       CSSPrintError ("Selector too long", deb);
                   6293:                       return (selector);
                   6294:                     }
                   6295:                   for (i = nbattrs; i > 0; i--)
                   6296:                     {
                   6297:                       attrnames[i] = attrnames[i - 1];
                   6298:                       attrnums[i] = attrnums[i - 1];
                   6299:                       attrlevels[i] = attrlevels[i - 1];
                   6300:                       attrvals[i] = attrvals[i - 1];
                   6301:                       attrmatch[i] = attrmatch[i - 1];
                   6302:                     }
                   6303:                   attrnames[0] = NULL;
                   6304:                   attrnums[0] = ATTR_CLASS;
                   6305:                   attrlevels[0] = 0;
                   6306:                   attrmatch[0] = Txtword;
                   6307:                   attrvals[0] = deb;
1.327     vatton   6308:                   specificity += 10;
1.343     vatton   6309:                  }
1.327     vatton   6310:             }
                   6311:           else if (*selector == ':')
1.340     quint    6312:             /* pseudo-class or pseudo-element */
1.327     vatton   6313:             {
                   6314:               selector++;
1.347     quint    6315:               doubleColon = FALSE;
                   6316:               if (*selector == ':')
                   6317:                 /* it's a double "::". Probably CSS3 syntax */
                   6318:                 {
                   6319:                   selector++;
                   6320:                   doubleColon = TRUE;
                   6321:                 }
1.340     quint    6322:               while (*selector != '.' && *selector != ':' &&
                   6323:                      *selector != '#' && *selector != '[' &&
                   6324:                      *selector != EOS && *selector != ',' &&
                   6325:                      *selector != '+' && *selector != '>' &&
1.327     vatton   6326:                      !TtaIsBlank (selector))
                   6327:                 *cur++ = *selector++;
                   6328:               /* close the word */
                   6329:               *cur++ = EOS;
1.340     quint    6330:               /* point to the pseudo-class or pseudo-element in sel[] if it's
                   6331:                  a valid name */
1.355     quint    6332:               if (!strcmp (deb, "first-child"))
                   6333:                 /* first-child pseudo-class */
1.327     vatton   6334:                 {
1.355     quint    6335:                   pseudoFirstChild[0] = TRUE;
                   6336:                   specificity += 10;
1.327     vatton   6337:                 }
1.355     quint    6338:               else if (!strcmp (deb, "link") || !strcmp (deb, "visited"))
                   6339:                 /* link or visited pseudo-classes */
1.327     vatton   6340:                 {
1.355     quint    6341:                   nbattrs++;
                   6342:                   if (nbattrs == MAX_ANCESTORS)
                   6343:                     /* abort parsing */
1.347     quint    6344:                     {
1.355     quint    6345:                       CSSPrintError ("Selector too long", deb);
                   6346:                       return (selector);
1.347     quint    6347:                     }
1.355     quint    6348:                   for (i = nbattrs; i > 0; i--)
1.347     quint    6349:                     {
1.355     quint    6350:                       attrnames[i] = attrnames[i - 1];
                   6351:                       attrnums[i] = attrnums[i - 1];
                   6352:                       attrlevels[i] = attrlevels[i - 1];
                   6353:                       attrvals[i] = attrvals[i - 1];
                   6354:                       attrmatch[i] = attrmatch[i - 1];
1.347     quint    6355:                     }
1.355     quint    6356:                   attrnames[0] = NULL;
                   6357:                   attrnums[0] = ATTR_PSEUDO;
                   6358:                   attrlevels[0] = 0;
                   6359:                   attrmatch[0] = Txtmatch;
                   6360:                   attrvals[0] = deb;
                   6361:                   specificity += 10;
                   6362:                 }
                   6363:               else if (!strcmp (deb, "hover") || !strcmp (deb, "active") ||
                   6364:                        !strcmp (deb, "focus"))
                   6365:                 /* hover, active, focus pseudo-classes */
                   6366:                 {
                   6367:                   specificity += 10;
                   6368:                   /* not supported */
                   6369:                   DoApply = FALSE;
                   6370:                 }
                   6371:               else if (!strncmp (deb, "lang", 4))
                   6372:                 /* it's the lang pseudo-class */
                   6373:                 {
                   6374:                   if (deb[4] != '(' || deb[strlen(deb)-1] != ')')
                   6375:                     /* at least one parenthesis is missing. Error */
1.327     vatton   6376:                     {
1.355     quint    6377:                       CSSPrintError ("Invalid :lang pseudo-class", deb);
                   6378:                       DoApply = FALSE;
1.327     vatton   6379:                     }
                   6380:                   else
1.355     quint    6381:                     /* simulate selector [lang|="xxx"] */
1.340     quint    6382:                     {
                   6383:                       nbattrs++;
                   6384:                       if (nbattrs == MAX_ANCESTORS)
                   6385:                         /* abort parsing */
                   6386:                         {
                   6387:                           CSSPrintError ("Selector too long", deb);
                   6388:                           return (selector);
                   6389:                         }
1.355     quint    6390:                       deb[strlen(deb)-1] = EOS;
                   6391:                       deb[4] = EOS;
1.340     quint    6392:                       for (i = nbattrs; i > 0; i--)
                   6393:                         {
                   6394:                           attrnames[i] = attrnames[i - 1];
                   6395:                           attrnums[i] = attrnums[i - 1];
                   6396:                           attrlevels[i] = attrlevels[i - 1];
                   6397:                           attrvals[i] = attrvals[i - 1];
                   6398:                           attrmatch[i] = attrmatch[i - 1];
                   6399:                         }
1.355     quint    6400:                       attrnames[0] = deb;
                   6401:                       attrnums[0] = 0;
1.340     quint    6402:                       attrlevels[0] = 0;
1.355     quint    6403:                       attrmatch[0] = Txtsubstring;
                   6404:                       attrvals[0] = &deb[5];
                   6405:                       specificity += 10;
1.340     quint    6406:                     }
1.327     vatton   6407:                 }
1.355     quint    6408:               else if (!strcmp (deb, "first-line") ||
                   6409:                        !strcmp (deb, "first-letter"))
                   6410:                 /* pseudo-elements first-line or first-letter */
                   6411:                 {
                   6412:                   if (doubleColon)
                   6413:                     CSSPrintError ("Warning: \"::\" is CSS3 syntax", NULL);
                   6414:                   specificity += 1;
                   6415:                   /* not supported */
                   6416:                   DoApply = FALSE;
                   6417:                 }
                   6418:               else if (!strncmp (deb, "before", 6))
                   6419:                 /* pseudo-element before */
                   6420:                 {
                   6421:                   if (doubleColon)
                   6422:                     CSSPrintError ("Warning: \"::before\" is CSS3 syntax",
                   6423:                                    NULL);
                   6424:                   ctxt->pseudo = PbBefore;
                   6425:                   specificity += 1;
                   6426:                 }
                   6427:               else if (!strncmp (deb, "after", 5))
                   6428:                 /* pseudo-element after */
                   6429:                 {
                   6430:                   if (doubleColon)
                   6431:                     CSSPrintError ("Warning: \"::after\" is CSS3 syntax",
                   6432:                                    NULL);
                   6433:                   ctxt->pseudo = PbAfter;
                   6434:                   specificity += 1;
                   6435:                 }
                   6436:               else
                   6437:                 {
                   6438:                   CSSPrintError ("Invalid pseudo-element", deb);
                   6439:                   DoApply = FALSE;
                   6440:                 }
                   6441:               if (names[0] && !strcmp (names[0], "*"))
                   6442:                 names[0] = NULL;
1.327     vatton   6443:             }
                   6444:           else if (*selector == '#')
1.340     quint    6445:             /* unique identifier */
1.327     vatton   6446:             {
                   6447:               selector++;
1.340     quint    6448:               while (*selector != '.' && *selector != ':' &&
                   6449:                      *selector != '#' && *selector != '[' &&
                   6450:                      *selector != '+' && *selector != '>' &&
                   6451:                      *selector != EOS && *selector != ',' &&
1.327     vatton   6452:                      !TtaIsBlank (selector))
                   6453:                 *cur++ = *selector++;
                   6454:               /* close the word */
                   6455:               *cur++ = EOS;
                   6456:               /* point to the attribute in sel[] if it's valid name */
                   6457:               if (deb[0] <= 64)
                   6458:                 {
                   6459:                   CSSPrintError ("Invalid id", deb);
                   6460:                   DoApply = FALSE;
                   6461:                 }
                   6462:               else
                   6463:                 {
1.340     quint    6464:                   nbattrs++;
                   6465:                   if (nbattrs == MAX_ANCESTORS)
                   6466:                     /* abort parsing */
                   6467:                     {
                   6468:                       CSSPrintError ("Selector too long", deb);
                   6469:                       return (selector);
                   6470:                     }
                   6471:                   for (i = nbattrs; i > 0; i--)
                   6472:                     {
                   6473:                       attrnames[i] = attrnames[i - 1];
                   6474:                       attrnums[i] = attrnums[i - 1];
                   6475:                       attrlevels[i] = attrlevels[i - 1];
                   6476:                       attrvals[i] = attrvals[i - 1];
                   6477:                       attrmatch[i] = attrmatch[i - 1];
                   6478:                     }
                   6479:                   attrnames[0] = NULL;
                   6480:                   attrnums[0] = ATTR_ID;
                   6481:                   attrlevels[0] = 0;
                   6482:                   attrmatch[0] = Txtmatch;
                   6483:                   attrvals[0] = deb;
                   6484:                   specificity += 100;
                   6485:                   if (names[0] && !strcmp (names[0], "*"))
                   6486:                     names[0] = NULL;
1.327     vatton   6487:                 }
                   6488:             }
                   6489:           else if (*selector == '[')
                   6490:             {
                   6491:               selector++;
1.341     quint    6492:               selector = SkipBlanksAndComments (selector);
1.327     vatton   6493:               while (*selector != EOS && *selector != ']' &&
                   6494:                      *selector != '=' && *selector != '~' &&
1.341     quint    6495:                      *selector != '|' && *selector != '^' &&
                   6496:                      !TtaIsBlank (selector))
1.327     vatton   6497:                 *cur++ = *selector++;
1.341     quint    6498:               /* close the word (attribute name) */
1.327     vatton   6499:               *cur++ = EOS;
                   6500:               /* point to the attribute in sel[] if it's valid name */
                   6501:               if (deb[0] <= 64)
                   6502:                 {
                   6503:                   CSSPrintError ("Invalid attribute", deb);
                   6504:                   DoApply = FALSE;
                   6505:                 }
                   6506:               else
                   6507:                 {
1.340     quint    6508:                   nbattrs++;
                   6509:                   if (nbattrs == MAX_ANCESTORS)
                   6510:                     /* abort parsing */
                   6511:                     {
                   6512:                       CSSPrintError ("Selector too long", deb);
                   6513:                       return (selector);
                   6514:                     }
                   6515:                   for (i = nbattrs; i > 0; i--)
                   6516:                     {
                   6517:                       attrnames[i] = attrnames[i - 1];
                   6518:                       attrnums[i] = attrnums[i - 1];
                   6519:                       attrlevels[i] = attrlevels[i - 1];
                   6520:                       attrvals[i] = attrvals[i - 1];
                   6521:                       attrmatch[i] = attrmatch[i - 1];
                   6522:                     }
                   6523:                   attrnames[0] = deb;
                   6524:                   attrnums[0] = 0;
                   6525:                   attrlevels[0] = 0;
1.327     vatton   6526:                   specificity += 10;
1.340     quint    6527:                   /* check matching */
1.341     quint    6528:                   selector = SkipBlanksAndComments (selector);
1.340     quint    6529:                   if (*selector == '~')
                   6530:                     {
                   6531:                       attrmatch[0] = Txtword;
                   6532:                       selector++;
                   6533:                     }
                   6534:                   else if (*selector == '|')
                   6535:                     {
                   6536:                       attrmatch[0] = Txtsubstring;
                   6537:                       selector++;
                   6538:                     }
1.341     quint    6539:                   else if (*selector == '^')
                   6540:                     {
                   6541:                       attrmatch[0] = Txtsubstring;
                   6542:                       selector++;
                   6543:                     }
1.340     quint    6544:                   else
                   6545:                     attrmatch[0] = Txtmatch;
1.327     vatton   6546:                 }
                   6547:               if (*selector == '=')
                   6548:                 {
                   6549:                   /* look for a value "xxxx" */
                   6550:                   selector++;
1.341     quint    6551:                   selector = SkipBlanksAndComments (selector);
1.327     vatton   6552:                   if (*selector != '"')
                   6553:                     quoted = FALSE;
                   6554:                   else
                   6555:                     {
                   6556:                       quoted = TRUE;
                   6557:                       /* we are now parsing the attribute value */
                   6558:                       selector++;
                   6559:                     }
                   6560:                   deb = cur;
                   6561:                   while ((quoted &&
                   6562:                           (*selector != '"' ||
                   6563:                            (*selector == '"' && selector[-1] == '\\'))) ||
                   6564:                          (!quoted && *selector != ']'))
                   6565:                     {
                   6566:                       if (*selector == EOS)
                   6567:                         {
                   6568:                           CSSPrintError ("Invalid attribute value", deb);
                   6569:                           DoApply = FALSE;
                   6570:                         }
                   6571:                       else
                   6572:                         {
                   6573:                           if (attrmatch[0] == Txtword && TtaIsBlank (selector))
                   6574:                             {
                   6575:                               CSSPrintError ("No space allowed here: ", selector);
                   6576:                               DoApply = FALSE;
                   6577:                             }
                   6578:                           *cur++ = *selector;
                   6579:                         }
                   6580:                       selector++;
                   6581:                     }
                   6582:                   /* there is a value */
                   6583:                   if (quoted && *selector == '"')
                   6584:                     {
                   6585:                       selector++;
                   6586:                       quoted = FALSE;
                   6587:                     }
1.341     quint    6588:                   selector = SkipBlanksAndComments (selector);
1.327     vatton   6589:                   if (*selector != ']')
                   6590:                     {
                   6591:                       CSSPrintError ("Invalid attribute value", deb);
                   6592:                       DoApply = FALSE;
                   6593:                     }
                   6594:                   else
                   6595:                     {
                   6596:                       *cur++ = EOS;
                   6597:                       attrvals[0] = deb;
                   6598:                       selector++;
                   6599:                     }
                   6600:                 }
                   6601:               /* end of the attribute */
                   6602:               else if (*selector != ']')
                   6603:                 {
                   6604:                   selector[1] = EOS;
                   6605:                   CSSPrintError ("Invalid attribute", selector);
                   6606:                   selector += 2;
                   6607:                   DoApply = FALSE;
                   6608:                 }
                   6609:               else
                   6610:                 {
                   6611:                   selector++;
                   6612:                   if (names[0] && !strcmp (names[0], "*"))
                   6613:                     names[0] = NULL;
                   6614:                 }
                   6615:             }
                   6616:           else
                   6617:             {
                   6618:               /* not supported selector */
1.340     quint    6619:               while (*selector != '.' && *selector != ':' &&
                   6620:                      *selector != '#' && *selector != '[' &&
                   6621:                      *selector != EOS && *selector != ',' &&
                   6622:                      *selector != '+' && *selector != '>' &&
1.327     vatton   6623:                      !TtaIsBlank (selector))
                   6624:                 *cur++ = *selector++;
                   6625:               /* close the word */
                   6626:               *cur++ = EOS;
                   6627:               CSSPrintError ("Selector not supported:", deb);
                   6628:               DoApply = FALSE;     
                   6629:             }
                   6630:         }
1.1       cvs      6631: 
1.286     quint    6632:       skippedNL = NewLineSkipped;
1.82      cvs      6633:       selector = SkipBlanksAndComments (selector);
1.286     quint    6634:       NewLineSkipped = skippedNL;
                   6635: 
1.25      cvs      6636:       /* is it a multi-level selector? */
1.82      cvs      6637:       if (*selector == EOS)
1.327     vatton   6638:         /* end of the selector */
                   6639:         break;
1.82      cvs      6640:       else if (*selector == ',')
1.327     vatton   6641:         {
                   6642:           /* end of the current selector */
                   6643:           selector++;
                   6644:           skippedNL = NewLineSkipped;
                   6645:           next = SkipBlanksAndComments (selector);
                   6646:           NewLineSkipped = skippedNL;
                   6647:           if (*next == EOS)
                   6648:             /* nothing after the comma. Invalid selector */
                   6649:             {
                   6650:               /*CSSPrintError ("Syntax error:", selector);*/
                   6651:               return NULL;
                   6652:             }
                   6653:           break;
                   6654:         }
1.25      cvs      6655:       else
1.327     vatton   6656:         {
                   6657:           if (*selector == '>')
                   6658:             {
1.340     quint    6659:               /* handle parent */
1.327     vatton   6660:               selector++;
                   6661:               skippedNL = NewLineSkipped;
                   6662:               selector = SkipBlanksAndComments (selector);
                   6663:               NewLineSkipped = skippedNL;
1.340     quint    6664:               rel[0] = RelParent;
1.327     vatton   6665:             }
                   6666:           else if (*selector == '+')
                   6667:             {
1.340     quint    6668:               /* handle immediate sibling */
1.327     vatton   6669:               selector++;
                   6670:               skippedNL = NewLineSkipped;
                   6671:               selector = SkipBlanksAndComments (selector);
                   6672:               NewLineSkipped = skippedNL;
                   6673:               rel[0] = RelPrevious;
                   6674:             }
1.340     quint    6675:           else
                   6676:             rel[0] = RelAncestor;
                   6677:           nbnames++; /* a new level in ancestor tables */
                   6678:           if (nbnames == MAX_ANCESTORS)
                   6679:             /* abort parsing */
                   6680:             {
                   6681:               CSSPrintError ("Selector too long", deb);
                   6682:               return (selector);
                   6683:             }
                   6684:           /* shift the list to make room for the next part of the selector */
                   6685:           for (i = nbnames; i > 0; i--)
1.327     vatton   6686:             {
                   6687:               names[i] = names[i - 1];
1.355     quint    6688:               pseudoFirstChild[i] = pseudoFirstChild[i - 1];
1.327     vatton   6689:               rel[i] = rel[i - 1];
                   6690:             }
1.340     quint    6691:           /* increase the level of all attributes */
                   6692:           for (i = 0; i < nbattrs; i++)
                   6693:               attrlevels[i]++;
1.327     vatton   6694:         }
1.1       cvs      6695:     }
                   6696: 
1.343     vatton   6697:   /* Now update the list of classes defined by the CSS */
                   6698:   for (i = 0; i < nbattrs; i++)
                   6699:     if (attrvals[i] && attrnums[i] == ATTR_CLASS)
                   6700:       AddClassName (attrvals[i], css);
                   6701: 
1.1       cvs      6702:   /* Now set up the context block */
1.25      cvs      6703:   i = 0;
                   6704:   j = 0;
1.91      cvs      6705:   /* default schema name */
1.119     vatton   6706:   ctxt->schema = NULL;
1.340     quint    6707:   ctxt->nbElem = nbnames;
1.122     vatton   6708:   elType.ElSSchema = NULL;
1.355     quint    6709:   elType.ElTypeNum = 0;
1.122     vatton   6710:   schemaName = TtaGetSSchemaName(TtaGetDocumentSSchema (doc));
1.119     vatton   6711:   if (!strcmp (schemaName, "HTML"))
                   6712:     xmlType = XHTML_TYPE;
                   6713:   else if (!strcmp (schemaName, "MathML"))
                   6714:     xmlType = MATH_TYPE;
                   6715:   else if (!strcmp (schemaName, "SVG"))
                   6716:     xmlType = SVG_TYPE;
                   6717:   else if (!strcmp (schemaName, "XLink"))
                   6718:     xmlType = XLINK_TYPE;
                   6719:   else if (!strcmp (schemaName, "Annot"))
                   6720:     xmlType = ANNOT_TYPE;
                   6721:   else
                   6722:     xmlType = XML_TYPE;
1.340     quint    6723:   while (i <= nbnames)
1.25      cvs      6724:     {
1.340     quint    6725:       ctxt->rel[i] = rel[i];
1.355     quint    6726:       ctxt->firstChild[i] = pseudoFirstChild[i];
                   6727:       if (!names[i] && i > 0)
1.340     quint    6728:         ctxt->name[i] = HTML_EL_ANY_TYPE;
                   6729:       else
                   6730:         /* store element information */
1.327     vatton   6731:         {
                   6732:           /* get the element type of this name in the current document */
                   6733:           if (xmlType == XML_TYPE)
                   6734:             /* it's a generic XML document. Check the main document schema */
                   6735:             {
                   6736:               elType.ElSSchema = TtaGetDocumentSSchema (doc);
1.355     quint    6737:               elType.ElTypeNum = 0;
                   6738:               if (names[i])
                   6739:                 TtaGetXmlElementType (names[i], &elType, &mappedName, doc);
1.327     vatton   6740:               if (!elType.ElTypeNum)
                   6741:                 {
1.355     quint    6742:                   if (!names[i] || !strcmp (names[i], "*"))
1.327     vatton   6743:                     elType.ElTypeNum = HTML_EL_ANY_TYPE;
                   6744:                   else
                   6745:                     elType.ElSSchema = NULL;
                   6746:                 }
                   6747:             }
                   6748:           else
                   6749:             {
1.355     quint    6750:               if (!names[i] || !strcmp (names[i], "*"))
1.327     vatton   6751:                 {
                   6752:                   elType.ElSSchema = TtaGetDocumentSSchema (doc);
                   6753:                   elType.ElTypeNum = HTML_EL_ANY_TYPE;
                   6754:                 }
                   6755:               else
                   6756:                 MapXMLElementType (xmlType, names[i], &elType, &mappedName, &c,
                   6757:                                    &level, doc);
                   6758:             }
                   6759:           if (i == 0)
1.340     quint    6760:             /* rightmost part of the selector */
1.327     vatton   6761:             {
                   6762:               if (elType.ElSSchema == NULL)
                   6763:                 {
1.340     quint    6764:                   /* element name not found. Search in all loaded schemas */
1.355     quint    6765:                   if (names[i])
                   6766:                     TtaGetXmlElementType (names[i], &elType, NULL, doc);
1.327     vatton   6767:                   if (elType.ElSSchema)
                   6768:                     {
                   6769:                       /* the element type concerns an imported nature */
                   6770:                       schemaName = TtaGetSSchemaName(elType.ElSSchema);
                   6771:                       if (!strcmp (schemaName, "HTML"))
                   6772:                         {
                   6773:                           if (xmlType == XHTML_TYPE &&
                   6774:                               DocumentMeta[doc] && DocumentMeta[doc]->xmlformat)
                   6775:                             /* the selector was found but the case is not correct */
                   6776:                             elType.ElSSchema = NULL;
                   6777:                           else
                   6778:                             xmlType = XHTML_TYPE;
                   6779:                         }
                   6780:                       else if (!strcmp (schemaName, "MathML"))
                   6781:                         xmlType = MATH_TYPE;
                   6782:                       else if (!strcmp (schemaName, "SVG"))
                   6783:                         xmlType = SVG_TYPE;
                   6784:                       else if (!strcmp (schemaName, "XLink"))
                   6785:                         xmlType = XLINK_TYPE;
                   6786:                       else if (!strcmp (schemaName, "Annot"))
                   6787:                         xmlType = ANNOT_TYPE;
                   6788:                       else
                   6789:                         xmlType = XML_TYPE;
                   6790:                     }
1.118     vatton   6791: #ifdef XML_GENERIC
1.327     vatton   6792:                   else if (xmlType == XML_TYPE)
                   6793:                     {
                   6794:                       /* Creation of a new element type in the main schema */
                   6795:                       elType.ElSSchema = TtaGetDocumentSSchema (doc);
1.355     quint    6796:                       if (names[i])
                   6797:                         TtaAppendXmlElement (names[i], &elType, &mappedName,
                   6798:                                              doc);
1.327     vatton   6799:                     }
1.118     vatton   6800: #endif /* XML_GENERIC */
1.327     vatton   6801:                   else
                   6802:                     {
                   6803:                       if (xmlType != XHTML_TYPE)
                   6804:                         {
                   6805:                           MapXMLElementType (XHTML_TYPE, names[i], &elType,
                   6806:                                              &mappedName, &c, &level, doc);
                   6807:                           if (elType.ElSSchema)
                   6808:                             elType.ElSSchema = GetXHTMLSSchema (doc);
                   6809:                         }
                   6810:                       if (elType.ElSSchema == NULL && xmlType != MATH_TYPE)
                   6811:                         {
                   6812:                           MapXMLElementType (MATH_TYPE, names[i], &elType,
                   6813:                                              &mappedName, &c, &level, doc);
                   6814:                           if (elType.ElSSchema)
                   6815:                             elType.ElSSchema = GetMathMLSSchema (doc);
                   6816:                         }
                   6817:                       if (elType.ElSSchema == NULL && xmlType != SVG_TYPE)
                   6818:                         {
                   6819:                           MapXMLElementType (SVG_TYPE, names[i], &elType,
                   6820:                                              &mappedName, &c, &level, doc);
                   6821:                           if (elType.ElSSchema)
                   6822:                             elType.ElSSchema = GetSVGSSchema (doc);
                   6823:                         }
                   6824:                     }
                   6825:                 }
                   6826: 
                   6827:               if (elType.ElSSchema == NULL)
                   6828:                 /* cannot apply these CSS rules */
                   6829:                 DoApply = FALSE;
                   6830:               else
                   6831:                 {
1.340     quint    6832:                   /* Store the element type contained in the rightmost part of
                   6833:                      the selector */
                   6834:                   ctxt->schema = elType.ElSSchema;
1.327     vatton   6835:                   ctxt->type = elType.ElTypeNum;
                   6836:                   ctxt->name[0] = elType.ElTypeNum;
1.340     quint    6837:                   ctxt->rel[0] = RelVoid;
1.327     vatton   6838:                 }
                   6839:             }
1.340     quint    6840:           else
                   6841:             /* not the rightmost part of the selector */
1.327     vatton   6842:             {
1.340     quint    6843:               if (elType.ElTypeNum != 0)
                   6844:                 ctxt->name[i] = elType.ElTypeNum;
                   6845: #ifdef XML_GENERIC
                   6846:               else if (xmlType == XML_TYPE)
1.327     vatton   6847:                 {
1.340     quint    6848:                   TtaGetXmlElementType (names[i], &elType, NULL, doc);
                   6849:                   if (elType.ElTypeNum == 0)
1.327     vatton   6850:                     {
1.340     quint    6851:                       /* Creation of a new element type in the main schema */
                   6852:                       elType.ElSSchema = TtaGetDocumentSSchema (doc);
                   6853:                       TtaAppendXmlElement (names[i], &elType, &mappedName, doc);
1.327     vatton   6854:                     }
1.340     quint    6855:                   if (elType.ElTypeNum != 0)
                   6856:                     ctxt->name[i] = elType.ElTypeNum;
1.327     vatton   6857:                 }
1.340     quint    6858: #endif /* XML_GENERIC */
1.327     vatton   6859:             }
1.340     quint    6860:         }
                   6861: 
                   6862:       /* store attribute information for this element */
                   6863:       while (j < nbattrs && attrlevels[j] <= i)
                   6864:         {
                   6865:           if (attrnames[j] || attrnums[j])
1.327     vatton   6866:             {
1.340     quint    6867:               if (attrnums[j] > 0)
1.327     vatton   6868:                 {
1.340     quint    6869:                   if (attrnums[j] == ATTR_CLASS)
1.327     vatton   6870:                     {
1.340     quint    6871:                       if (xmlType == SVG_TYPE)
                   6872:                         ctxt->attrType[j] = SVG_ATTR_class;
                   6873:                       else if (xmlType == MATH_TYPE)
                   6874:                         ctxt->attrType[j] = MathML_ATTR_class;
                   6875:                       else if (xmlType == XHTML_TYPE)
                   6876:                         ctxt->attrType[j] = HTML_ATTR_Class;
1.327     vatton   6877:                       else
1.119     vatton   6878: #ifdef XML_GENERIC
1.340     quint    6879:                         ctxt->attrType[j] = XML_ATTR_class;
1.107     cvs      6880: #else /* XML_GENERIC */
1.340     quint    6881:                         ctxt->attrType[j] = HTML_ATTR_Class;
1.107     cvs      6882: #endif /* XML_GENERIC */
1.340     quint    6883:                     }
                   6884:                   else if (attrnums[j] == ATTR_PSEUDO)
                   6885:                     {
                   6886:                       if (xmlType == SVG_TYPE)
                   6887:                         ctxt->attrType[j] = SVG_ATTR_PseudoClass;
                   6888:                       else if (xmlType == MATH_TYPE)
                   6889:                         ctxt->attrType[j] = MathML_ATTR_PseudoClass;
                   6890:                       else if (xmlType == XHTML_TYPE)
                   6891:                         ctxt->attrType[j] = HTML_ATTR_PseudoClass;
                   6892:                       else
1.119     vatton   6893: #ifdef XML_GENERIC
1.340     quint    6894:                         ctxt->attrType[j] = XML_ATTR_PseudoClass;
1.107     cvs      6895: #else /* XML_GENERIC */
1.340     quint    6896:                         ctxt->attrType[j] = HTML_ATTR_PseudoClass;
1.107     cvs      6897: #endif /* XML_GENERIC */
1.340     quint    6898:                     }
                   6899:                   else if (attrnums[j] == ATTR_ID)
                   6900:                     {
                   6901:                       if (xmlType == SVG_TYPE)
                   6902:                         ctxt->attrType[j] = SVG_ATTR_id;
                   6903:                       else if (xmlType == MATH_TYPE)
                   6904:                         ctxt->attrType[j] = MathML_ATTR_id;
                   6905:                       else if (xmlType == XHTML_TYPE)
                   6906:                         ctxt->attrType[j] = HTML_ATTR_ID;
                   6907:                       else
1.119     vatton   6908: #ifdef XML_GENERIC
1.340     quint    6909:                         ctxt->attrType[j] = XML_ATTR_xmlid;
1.107     cvs      6910: #else /* XML_GENERIC */
1.340     quint    6911:                         ctxt->attrType[j] = HTML_ATTR_ID;
1.107     cvs      6912: #endif /* XML_GENERIC */
1.340     quint    6913:                     }
                   6914:                   attrType.AttrTypeNum = ctxt->attrType[j];
                   6915:                   attrType.AttrSSchema =  ctxt->schema;
                   6916:                 }
                   6917:               else if (attrnames[j])
                   6918:                 {
                   6919:                   if (xmlType == XML_TYPE)
                   6920:                     {
                   6921:                       if (ctxt->schema)
                   6922:                         attrType.AttrSSchema = ctxt->schema;
                   6923:                       else
                   6924:                         attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
                   6925:                       TtaGetXmlAttributeType (attrnames[j], &attrType, doc);
                   6926:                       att = attrType.AttrTypeNum;
                   6927:                       if (ctxt->schema == NULL && att != 0)
                   6928:                         ctxt->schema = attrType.AttrSSchema;
                   6929:                     }
                   6930:                   else
                   6931:                     {
                   6932:                       MapXMLAttribute (xmlType, attrnames[j], names[i], &level,
                   6933:                                        doc, &att);
                   6934:                       if (ctxt->schema == NULL && att != 0)
                   6935:                         ctxt->schema = TtaGetDocumentSSchema (doc);
                   6936:                     }
                   6937:                   if (att == 0 && ctxt->schema == NULL)
                   6938:                     /* Attribute name not found: Search in the list of all
                   6939:                        schemas loaded for this document */
                   6940:                     {
                   6941:                       attrType.AttrSSchema = NULL;
                   6942:                       TtaGetXmlAttributeType (attrnames[j], &attrType, doc);
                   6943:                       att = attrType.AttrTypeNum;
                   6944:                       if (att != 0)
                   6945:                         ctxt->schema = attrType.AttrSSchema;
                   6946:                     }
                   6947:                   attrType.AttrSSchema = ctxt->schema;
                   6948:                   attrType.AttrTypeNum = att;
                   6949:                   if (i == 0 && att == 0 && ctxt->schema == NULL)
                   6950:                     {
                   6951:                       /* Not found -> search in the list of loaded schemas */
                   6952:                       attrType.AttrSSchema = NULL;
                   6953:                       TtaGetXmlAttributeType (attrnames[j], &attrType, doc);
                   6954:                       att = attrType.AttrTypeNum;
                   6955:                       if (attrType.AttrSSchema)
                   6956:                         /* the element type concerns an imported nature */
                   6957:                         schemaName = TtaGetSSchemaName(attrType.AttrSSchema);
1.119     vatton   6958: #ifdef XML_GENERIC
1.340     quint    6959:                       else if (xmlType == XML_TYPE)
                   6960:                         {
                   6961:                           /* The attribute is not yet present in the tree */
                   6962:                           /* Create a new global attribute */
                   6963:                           attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
                   6964:                           TtaAppendXmlAttribute (attrnames[j], &attrType, doc);
                   6965:                         }
                   6966: #endif /* XML_GENERIC */
                   6967:                       if (attrType.AttrSSchema == NULL)
                   6968:                         /* cannot apply these CSS rules */
                   6969:                         DoApply = FALSE;
                   6970:                       else if (elType.ElSSchema)
                   6971:                         ctxt->schema = elType.ElSSchema;
                   6972:                       else
                   6973:                         ctxt->schema = attrType.AttrSSchema;
                   6974:                     }
                   6975:                   if (att == 0)
                   6976:                     {
                   6977:                       CSSPrintError ("Unknown attribute", attrnames[j]);
                   6978:                       DoApply = FALSE;     
                   6979:                     }
                   6980:                   else
1.345     quint    6981:                     {
                   6982:                       ctxt->attrType[j] = att;
                   6983:                       if (att == DummyAttribute && !strcmp (schemaName,"HTML"))
                   6984:                         /* it's the "type" attribute for an "input" element.
                   6985:                            In the tree, it is represented by the element type,
                   6986:                            not by an attribute */
                   6987:                         {
                   6988:                           ctxt->attrType[j] = 0;
                   6989:                           if (attrvals[j] && attrmatch[i] == Txtmatch)
                   6990:                             /* a value is specified for attribute type. This
                   6991:                                value provides the Thot element type */
                   6992:                             {
                   6993:                               MapXMLAttributeValue (xmlType, attrvals[j],
                   6994:                                                     &attrType, &kind);
                   6995:                               /* attrType contains the element type */
                   6996:                               if (i == 0)
                   6997:                                 ctxt->type = kind;
                   6998:                               ctxt->name[i] = kind;
                   6999:                             } 
                   7000:                         }
                   7001:                     }
1.340     quint    7002:                 }
                   7003:               if (ctxt->attrType[j])
1.327     vatton   7004:                 {
1.340     quint    7005:                   /* check the attribute type */
                   7006:                   if (!strcmp (schemaName, "HTML"))
                   7007:                     xmlType = XHTML_TYPE;
                   7008:                   else if (!strcmp (schemaName, "MathML"))
                   7009:                     xmlType = MATH_TYPE;
                   7010:                   else if (!strcmp (schemaName, "SVG"))
                   7011:                     xmlType = SVG_TYPE;
                   7012:                   else if (!strcmp (schemaName, "XLink"))
                   7013:                     xmlType = XLINK_TYPE;
                   7014:                   else if (!strcmp (schemaName, "Annot"))
                   7015:                     xmlType = ANNOT_TYPE;
                   7016:                   else
                   7017:                     xmlType = XML_TYPE;
                   7018:                   kind = TtaGetAttributeKind (attrType);
                   7019:                   if (kind == 0 && attrvals[j])
                   7020:                     {
                   7021:                       /* enumerated value */
                   7022:                       MapXMLAttributeValue (xmlType, attrvals[j], &attrType,
                   7023:                                             &kind);
                   7024:                       /* store the attribute value */
                   7025:                       ctxt->attrText[j] = (char *) kind;
                   7026:                     }
                   7027:                   else
                   7028:                     ctxt->attrText[j] = attrvals[j];
                   7029:                   /* update attrLevel */
                   7030:                   ctxt->attrMatch[j] = attrmatch[j];
                   7031:                   ctxt->attrLevel[j] = attrlevels[j];
                   7032:                     }
                   7033:               j++;
1.327     vatton   7034:             }
                   7035:         }
1.340     quint    7036:       /* add a new entry */
1.25      cvs      7037:       i++;
1.119     vatton   7038:       if (i == 1 && ctxt->schema == NULL)
1.327     vatton   7039:         /* use the document schema */
                   7040:         ctxt->schema = TtaGetDocumentSSchema (doc);
1.1       cvs      7041:     }
1.340     quint    7042: 
1.312     quint    7043:   ctxt->important = FALSE;
1.117     vatton   7044:   /* set the selector specificity */
                   7045:   ctxt->cssSpecificity = specificity;
1.25      cvs      7046:   /* Get the schema name of the main element */
1.119     vatton   7047:   schemaName = TtaGetSSchemaName (ctxt->schema);
                   7048:   isHTML = (strcmp (schemaName, "HTML") == 0);
1.206     vatton   7049:   tsch = GetPExtension (doc, ctxt->schema, css, link);
1.217     vatton   7050:   skippedNL = NewLineSkipped;
1.119     vatton   7051:   if (tsch && cssRule)
1.317     vatton   7052:     {
                   7053:       if (css)
1.327     vatton   7054:         {
                   7055:           /* point the right URL for loaded images */
                   7056:           saveURL = css->url;
                   7057:           css->url = url;
                   7058:         }
1.317     vatton   7059:       else
1.327     vatton   7060:         saveURL = NULL;
                   7061:       ParseCSSRule (NULL, tsch, (PresentationContext) ctxt, cssRule, css, isHTML);
1.317     vatton   7062:       if (css)
1.327     vatton   7063:         /* restore previous url */
                   7064:         css->url = saveURL;
1.317     vatton   7065:     }
1.116     vatton   7066:   /* future CSS rules should apply */
                   7067:   DoApply = TRUE;
1.217     vatton   7068:   if (selector)
                   7069:     NewLineSkipped = skippedNL;
1.1       cvs      7070:   return (selector);
                   7071: }
                   7072: 
                   7073: /*----------------------------------------------------------------------
1.206     vatton   7074:   ParseStyleDeclaration: parse a style declaration stored in the style
                   7075:   element of a document                       
                   7076:   We expect the style string to be of the form:                   
                   7077:   .pinky, .awful { color: pink; font-family: helvetica }        
1.231     vatton   7078:   The parameter css points to the current CSS context.
                   7079:   The parameter link points to the link element.
                   7080:   The parameter url gives the URL of the parsed style sheet.
1.1       cvs      7081:   ----------------------------------------------------------------------*/
1.206     vatton   7082: static void ParseStyleDeclaration (Element el, char *cssRule, Document doc,
1.327     vatton   7083:                                    CSSInfoPtr css, Element link, char *url,
                   7084:                                    ThotBool destroy)
1.1       cvs      7085: {
1.79      cvs      7086:   GenericContext      ctxt;
                   7087:   char               *decl_end;
                   7088:   char               *sel_end;
                   7089:   char               *selector;
1.1       cvs      7090: 
                   7091:   /* separate the selectors string */
1.82      cvs      7092:   cssRule = SkipBlanksAndComments (cssRule);
1.1       cvs      7093:   decl_end = cssRule;
1.82      cvs      7094:   while (*decl_end != EOS && *decl_end != '{')
1.286     quint    7095:     {
                   7096:       if (*decl_end == EOL)
1.327     vatton   7097:         NewLineSkipped++;
1.286     quint    7098:       decl_end++;
                   7099:     }
1.82      cvs      7100:   if (*decl_end == EOS)
1.86      cvs      7101:     {
1.168     vatton   7102:       CSSPrintError ("Invalid selector", cssRule);
1.86      cvs      7103:       return;
                   7104:     }
1.1       cvs      7105:   /* verify and clean the selector string */
                   7106:   sel_end = decl_end - 1;
1.82      cvs      7107:   while (*sel_end == SPACE || *sel_end == BSPACE ||
1.327     vatton   7108:          *sel_end == EOL || *sel_end == CR)
1.1       cvs      7109:     sel_end--;
                   7110:   sel_end++;
1.82      cvs      7111:   *sel_end = EOS;
1.1       cvs      7112:   selector = cssRule;
                   7113: 
                   7114:   /* now, deal with the content ... */
                   7115:   decl_end++;
                   7116:   cssRule = decl_end;
1.137     vatton   7117:   decl_end = &cssRule[strlen (cssRule) - 1];
                   7118:   if (*decl_end != '{')
                   7119:     *decl_end = EOS;
1.1       cvs      7120:   /*
                   7121:    * parse the style attribute string and install the corresponding
                   7122:    * presentation attributes on the new element
                   7123:    */
                   7124:   ctxt = TtaGetGenericStyleContext (doc);
                   7125:   if (ctxt == NULL)
                   7126:     return;
                   7127:   ctxt->destroy = destroy;
1.207     vatton   7128:   /* first use of the context */
                   7129:   ctxt->uses = 1;
1.197     vatton   7130:   while (selector && *selector != EOS)
1.363     vatton   7131:     {
                   7132:       if (ctxt->uses > 1)
                   7133:         {
                   7134:           /* this context is waiting for a callback */
                   7135:           ctxt = TtaGetGenericStyleContext (doc);
                   7136:           if (ctxt == NULL)
                   7137:             return;
                   7138:           ctxt->destroy = destroy;
                   7139:           /* first use of the context */
                   7140:           ctxt->uses = 1; 
                   7141:         }
                   7142:       selector = ParseGenericSelector (selector, cssRule, ctxt, doc, css,
                   7143:                                        link, url);
                   7144:     }
1.207     vatton   7145:   /* check if the context can be freed */
                   7146:   ctxt->uses -= 1;
                   7147:   if (ctxt->uses == 0)
                   7148:     /* no image loading */
                   7149:     TtaFreeMemory (ctxt);
1.1       cvs      7150: }
                   7151: 
                   7152: /************************************************************************
                   7153:  *                                                                     *  
                   7154:  *     EVALUATION FUNCTIONS / CASCADING AND OVERLOADING                *
                   7155:  *                                                                     *  
                   7156:  ************************************************************************/
                   7157: 
                   7158: /*----------------------------------------------------------------------
1.327     vatton   7159:   IsImplicitClassName: return wether the Class name is an        
                   7160:   implicit one, eg "H1" or "H2 EM" meaning it's a GI name       
                   7161:   or an HTML context name.                                      
1.1       cvs      7162:   ----------------------------------------------------------------------*/
1.248     gully    7163: int IsImplicitClassName (char *class_, Document doc)
1.1       cvs      7164: {
1.327     vatton   7165:   char         name[200];
                   7166:   char        *cur = name;
                   7167:   char        *first; 
                   7168:   char         save;
                   7169:   SSchema      schema;
                   7170: 
                   7171:   /* make a local copy */
                   7172:   strncpy (name, class_, 199);
                   7173:   name[199] = 0;
                   7174: 
                   7175:   /* loop looking if each word is a GI */
                   7176:   while (*cur != 0)
                   7177:     {
                   7178:       first = cur;
                   7179:       cur = SkipWord (cur);
                   7180:       save = *cur;
                   7181:       *cur = 0;
                   7182:       schema = NULL;
                   7183:       if (MapGI (first, &schema, doc) == -1)
                   7184:         {
                   7185:           return (0);
                   7186:         }
                   7187:       *cur = save;
                   7188:       cur = SkipBlanksAndComments (cur);
                   7189:     }
                   7190:   return (1);
1.1       cvs      7191: }
                   7192: 
                   7193: /************************************************************************
1.114     quint    7194:  *  Functions needed for support of HTML: translate to CSS equivalent   *
1.1       cvs      7195:  ************************************************************************/
                   7196: 
                   7197: /*----------------------------------------------------------------------
1.327     vatton   7198:   HTMLSetBackgroundColor:
1.1       cvs      7199:   ----------------------------------------------------------------------*/
1.264     vatton   7200: void HTMLSetBackgroundColor (Document doc, Element el, int specificity,
1.327     vatton   7201:                              char *color)
1.1       cvs      7202: {
1.350     vatton   7203:   char             css_command[1000];
1.1       cvs      7204: 
1.327     vatton   7205:   sprintf (css_command, "background-color: %s", color);
                   7206:   ParseHTMLSpecificStyle (el, css_command, doc, specificity, FALSE);
1.1       cvs      7207: }
                   7208: 
                   7209: /*----------------------------------------------------------------------
1.327     vatton   7210:   HTMLSetForegroundColor:                                        
1.1       cvs      7211:   ----------------------------------------------------------------------*/
1.264     vatton   7212: void HTMLSetForegroundColor (Document doc, Element el, int specificity,
1.327     vatton   7213:                              char *color)
1.1       cvs      7214: {
1.350     vatton   7215:   char           css_command[1000];
1.1       cvs      7216: 
1.327     vatton   7217:   sprintf (css_command, "color: %s", color);
                   7218:   ParseHTMLSpecificStyle (el, css_command, doc, specificity, FALSE);
1.1       cvs      7219: }
                   7220: 
                   7221: /*----------------------------------------------------------------------
1.327     vatton   7222:   HTMLResetBackgroundColor:                                      
1.1       cvs      7223:   ----------------------------------------------------------------------*/
1.97      vatton   7224: void HTMLResetBackgroundColor (Document doc, Element el)
1.1       cvs      7225: {
1.350     vatton   7226:   char           css_command[1000];
1.1       cvs      7227: 
1.327     vatton   7228:   sprintf (css_command, "background: red");
                   7229:   ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1       cvs      7230: }
                   7231: 
                   7232: /*----------------------------------------------------------------------
1.327     vatton   7233:   HTMLResetBackgroundImage:                                      
1.1       cvs      7234:   ----------------------------------------------------------------------*/
1.97      vatton   7235: void HTMLResetBackgroundImage (Document doc, Element el)
1.1       cvs      7236: {
1.327     vatton   7237:   char           css_command[1000];
1.1       cvs      7238: 
1.327     vatton   7239:   sprintf (css_command, "background-image: url(xx); background-repeat: repeat");
                   7240:   ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1       cvs      7241: }
                   7242: 
                   7243: /*----------------------------------------------------------------------
1.327     vatton   7244:   HTMLResetForegroundColor:                                      
1.1       cvs      7245:   ----------------------------------------------------------------------*/
1.97      vatton   7246: void HTMLResetForegroundColor (Document doc, Element el)
1.1       cvs      7247: {
1.350     vatton   7248:   char           css_command[1000];
1.1       cvs      7249: 
1.327     vatton   7250:   /* it's not necessary to well know the current color but it must be valid */
                   7251:   sprintf (css_command, "color: red");
                   7252:   ParseHTMLSpecificStyle (el, css_command, doc, 0, TRUE);
1.1       cvs      7253: }
                   7254: 
                   7255: /*----------------------------------------------------------------------
1.327     vatton   7256:   HTMLSetAlinkColor:                                             
1.1       cvs      7257:   ----------------------------------------------------------------------*/
1.208     vatton   7258: void HTMLSetAlinkColor (Document doc, Element el, char *color)
1.1       cvs      7259: {
1.350     vatton   7260:   char           css_command[1000];
1.1       cvs      7261: 
1.327     vatton   7262:   sprintf (css_command, ":link { color: %s }", color);
                   7263:   ApplyCSSRules (el, css_command, doc, FALSE);
1.1       cvs      7264: }
                   7265: 
                   7266: /*----------------------------------------------------------------------
1.327     vatton   7267:   HTMLSetAactiveColor:                                           
1.1       cvs      7268:   ----------------------------------------------------------------------*/
1.208     vatton   7269: void HTMLSetAactiveColor (Document doc, Element el, char *color)
1.1       cvs      7270: {
1.350     vatton   7271:   char           css_command[1000];
1.1       cvs      7272: 
1.327     vatton   7273:   sprintf (css_command, ":active { color: %s }", color);
                   7274:   ApplyCSSRules (el, css_command, doc, FALSE);
1.1       cvs      7275: }
                   7276: 
                   7277: /*----------------------------------------------------------------------
1.327     vatton   7278:   HTMLSetAvisitedColor:                                          
1.1       cvs      7279:   ----------------------------------------------------------------------*/
1.208     vatton   7280: void HTMLSetAvisitedColor (Document doc, Element el, char *color)
1.1       cvs      7281: {
1.350     vatton   7282:   char           css_command[1000];
1.1       cvs      7283: 
1.327     vatton   7284:   sprintf (css_command, ":visited { color: %s }", color);
                   7285:   ApplyCSSRules (el, css_command, doc, FALSE);
1.1       cvs      7286: }
                   7287: 
                   7288: /*----------------------------------------------------------------------
1.327     vatton   7289:   HTMLResetAlinkColor:                                           
1.1       cvs      7290:   ----------------------------------------------------------------------*/
1.208     vatton   7291: void HTMLResetAlinkColor (Document doc, Element el)
1.1       cvs      7292: {
1.350     vatton   7293:   char           css_command[1000];
1.1       cvs      7294: 
1.327     vatton   7295:   sprintf (css_command, ":link { color: red }");
                   7296:   ApplyCSSRules (el, css_command, doc, TRUE);
1.1       cvs      7297: }
                   7298: 
                   7299: /*----------------------------------------------------------------------
1.327     vatton   7300:   HTMLResetAactiveColor:                                                 
1.1       cvs      7301:   ----------------------------------------------------------------------*/
1.208     vatton   7302: void HTMLResetAactiveColor (Document doc, Element el)
1.1       cvs      7303: {
1.350     vatton   7304:   char           css_command[1000];
1.1       cvs      7305: 
1.327     vatton   7306:   sprintf (css_command, ":active { color: red }");
                   7307:   ApplyCSSRules (el, css_command, doc, TRUE);
1.1       cvs      7308: }
                   7309: 
                   7310: /*----------------------------------------------------------------------
1.327     vatton   7311:   HTMLResetAvisitedColor:                                        
1.1       cvs      7312:   ----------------------------------------------------------------------*/
1.208     vatton   7313: void HTMLResetAvisitedColor (Document doc, Element el)
1.1       cvs      7314: {
1.350     vatton   7315:   char           css_command[1000];
1.1       cvs      7316: 
1.327     vatton   7317:   sprintf (css_command, ":visited { color: red }");
                   7318:   ApplyCSSRules (el, css_command, doc, TRUE);
1.1       cvs      7319: }
                   7320: 
                   7321: /*----------------------------------------------------------------------
1.206     vatton   7322:   ApplyCSSRules: parse a CSS Style description stored in the header of
                   7323:   a HTML document.
1.1       cvs      7324:   ----------------------------------------------------------------------*/
1.79      cvs      7325: void ApplyCSSRules (Element el, char *cssRule, Document doc, ThotBool destroy)
1.1       cvs      7326: {
1.206     vatton   7327:   CSSInfoPtr          css;
                   7328:   PInfoPtr            pInfo;
1.207     vatton   7329:   ThotBool            loadcss;
                   7330: 
                   7331:   /* check if we have to load CSS */
                   7332:   TtaGetEnvBoolean ("LOAD_CSS", &loadcss);
                   7333:   if (!loadcss)
                   7334:     return;
1.376     vatton   7335:   LineNumber = TtaGetElementLineNumber (el);
1.206     vatton   7336:   css = SearchCSS (doc, NULL, el, &pInfo);
1.1       cvs      7337:   if (css == NULL)
1.209     vatton   7338:     {
                   7339:       /* create the document css context */
                   7340:       css = AddCSS (doc, doc, CSS_DOCUMENT_STYLE, CSS_ALL, NULL, NULL, el);
                   7341:       pInfo = css->infos[doc];
                   7342:     }
1.206     vatton   7343:   else if (pInfo == NULL)
                   7344:     /* create the entry into the css context */
                   7345:     pInfo = AddInfoCSS (doc, css, CSS_DOCUMENT_STYLE, CSS_ALL, el);
1.209     vatton   7346:   if (pInfo->PiEnabled)
1.376     vatton   7347:     ParseStyleDeclaration (el, cssRule, doc, css, el, NULL, destroy);
                   7348:   LineNumber = -1;
1.1       cvs      7349: }
                   7350: 
                   7351: /*----------------------------------------------------------------------
1.327     vatton   7352:   ReadCSSRules:  is the front-end function called by the document parser
                   7353:   when detecting a <style type="text/css"> indicating it's the
                   7354:   beginning of a CSS fragment or when reading a file .css.
1.1       cvs      7355:   
1.327     vatton   7356:   The CSS parser has to handle <!-- ... --> constructs used to
                   7357:   prevent prehistoric browser from displaying the CSS as a text
                   7358:   content. It will stop on any sequence "<x" where x is different
                   7359:   from ! and will return x as to the caller. Theorically x should
                   7360:   be equal to / for the </style> end of style.
                   7361:   The parameter doc gives the document tree that contains CSS information.
                   7362:   The parameter docRef gives the document to which CSS are to be applied.
                   7363:   This function uses the current css context or creates it. It's able
                   7364:   to work on the given buffer or call GetNextChar to read the parsed
                   7365:   file.
                   7366:   The parameter url gives the URL of the parsed style sheet.
                   7367:   The parameter numberOfLinesRead gives the number of lines already
                   7368:   read in the file.
                   7369:   The parameter withUndo indicates whether the changes made in the document
                   7370:   structure and content have to be registered in the Undo queue or not.
1.1       cvs      7371:   ----------------------------------------------------------------------*/
1.133     vatton   7372: char ReadCSSRules (Document docRef, CSSInfoPtr css, char *buffer, char *url,
1.343     vatton   7373:                    int numberOfLinesRead, ThotBool withUndo, Element link)
1.1       cvs      7374: {
1.6       cvs      7375:   DisplayMode         dispMode;
1.206     vatton   7376:   CSSInfoPtr          refcss = NULL;
1.321     vatton   7377:   CSSmedia            css_media = CSS_ALL;
1.206     vatton   7378:   PInfoPtr            pInfo;
1.321     vatton   7379:   char                c;
1.138     vatton   7380:   char               *cssRule, *base, *saveDocURL, *ptr;
1.19      cvs      7381:   int                 index;
1.1       cvs      7382:   int                 CSSindex;
1.327     vatton   7383:   int                 CSScomment;
1.1       cvs      7384:   int                 import;
1.358     quint    7385:   int                 openBlock;
1.93      vatton   7386:   int                 newlines;
1.358     quint    7387:   int                 page;
1.14      cvs      7388:   ThotBool            HTMLcomment;
1.342     vatton   7389:   ThotBool            toParse, eof, quoted, s_quoted;
1.358     quint    7390:   ThotBool            ignore, media, lineComment;
1.234     vatton   7391:   ThotBool            noRule, ignoreImport, fontface;
1.1       cvs      7392: 
1.327     vatton   7393:   CSScomment = MAX_CSS_LENGTH;
1.1       cvs      7394:   HTMLcomment = FALSE;
                   7395:   CSSindex = 0;
                   7396:   toParse = FALSE;
                   7397:   noRule = FALSE;
1.234     vatton   7398:   media = FALSE;
1.88      cvs      7399:   ignoreImport = FALSE;
1.342     vatton   7400:   ignore = lineComment = FALSE;
1.358     quint    7401:   page = 0;
1.342     vatton   7402:   quoted = s_quoted = FALSE;
1.234     vatton   7403:   fontface = FALSE;
1.1       cvs      7404:   eof = FALSE;
1.358     quint    7405:   openBlock = 0;
1.234     vatton   7406:   import = MAX_CSS_LENGTH;
1.82      cvs      7407:   c = SPACE;
1.1       cvs      7408:   index = 0;
1.134     vatton   7409:   base = NULL;
1.310     vatton   7410:   /* entering the CSS parsing */
1.311     vatton   7411:   Style_parsing++;
1.93      vatton   7412:   /* number of new lines parsed */
                   7413:   newlines = 0;
1.6       cvs      7414:   /* avoid too many redisplay */
                   7415:   dispMode = TtaGetDisplayMode (docRef);
                   7416:   if (dispMode == DisplayImmediately)
                   7417:     TtaSetDisplayMode (docRef, DeferredDisplay);
1.18      cvs      7418: 
                   7419:   /* look for the CSS context */
                   7420:   if (css == NULL)
1.206     vatton   7421:     css = SearchCSS (docRef, NULL, link, &pInfo);
1.207     vatton   7422:   else
                   7423:     pInfo = css->infos[docRef];
1.18      cvs      7424:   if (css == NULL)
1.206     vatton   7425:     {
                   7426:       css = AddCSS (docRef, docRef, CSS_DOCUMENT_STYLE, CSS_ALL, NULL, NULL, link);
                   7427:       pInfo = css->infos[docRef];
                   7428:     }
                   7429:   else if (pInfo == NULL)
                   7430:     pInfo = AddInfoCSS (docRef, css, CSS_DOCUMENT_STYLE, CSS_ALL, link);
1.174     vatton   7431:   /* look for the CSS descriptor that points to the extension schema */
                   7432:   refcss = css;
1.224     vatton   7433:   if (pInfo && pInfo->PiCategory == CSS_IMPORT)
1.173     cvs      7434:     {
1.206     vatton   7435:       while (refcss &&
1.327     vatton   7436:              refcss->infos[docRef] && refcss->infos[docRef]->PiCategory == CSS_IMPORT)
                   7437:         refcss = refcss->NextCSS;
1.206     vatton   7438:       if (refcss)
1.327     vatton   7439:         pInfo = refcss->infos[docRef];
1.173     cvs      7440:     }
                   7441: 
1.343     vatton   7442:   /* register parsed CSS file and the document to which CSS are to be applied */
1.86      cvs      7443:   ParsedDoc = docRef;
1.343     vatton   7444:   /* clean up the list of classes */
                   7445:   TtaFreeMemory (refcss->class_list);
                   7446:   refcss->class_list = NULL;
1.133     vatton   7447:   if (url)
1.348     vatton   7448:     Error_DocURL = url;
1.86      cvs      7449:   else
                   7450:     /* the CSS source in within the document itself */
1.348     vatton   7451:     Error_DocURL = DocumentURLs[docRef];
1.86      cvs      7452:   LineNumber = numberOfLinesRead + 1;
1.93      vatton   7453:   NewLineSkipped = 0;
1.217     vatton   7454:   newlines = 0;
1.82      cvs      7455:   while (CSSindex < MAX_CSS_LENGTH && c != EOS && !eof)
                   7456:     {
                   7457:       c = buffer[index++];
                   7458:       eof = (c == EOS);
                   7459:       CSSbuffer[CSSindex] = c;
1.342     vatton   7460:       if (!lineComment &&
                   7461:           (CSScomment == MAX_CSS_LENGTH || c == '*' || c == '/' || c == '<' || c == EOL))
1.327     vatton   7462:         {
                   7463:           /* we're not within a comment or we're parsing * or / */
                   7464:           switch (c)
                   7465:             {
                   7466:             case '@': /* perhaps an import primitive */
1.342     vatton   7467:               if (!fontface && !page && !quoted && !s_quoted)
1.327     vatton   7468:                 import = CSSindex;
                   7469:               break;
                   7470:             case ';':
1.342     vatton   7471:               if (!quoted && !s_quoted && !media && import != MAX_CSS_LENGTH)
1.327     vatton   7472:                 { 
                   7473:                   if (strncasecmp (&CSSbuffer[import+1], "import", 6))
                   7474:                     /* it's not an import */
                   7475:                     import = MAX_CSS_LENGTH;
                   7476:                   /* save the text */
                   7477:                   noRule = TRUE;
                   7478:                 }
                   7479:               break;
                   7480:             case '*':
1.342     vatton   7481:               if (!quoted && !s_quoted && CSScomment == MAX_CSS_LENGTH && CSSindex > 0 &&
1.327     vatton   7482:                   CSSbuffer[CSSindex - 1] == '/')
                   7483:                 /* start a comment */
                   7484:                 CSScomment = CSSindex - 1;
                   7485:               break;
                   7486:             case '/':
1.342     vatton   7487:               if (!quoted && !s_quoted && CSSindex > 1 && CSScomment != MAX_CSS_LENGTH &&
1.327     vatton   7488:                   CSSbuffer[CSSindex - 1] == '*')
                   7489:                 {
                   7490:                   while (CSSindex > 0 && CSSindex >= CSScomment)
                   7491:                     {
                   7492:                       if ( CSSbuffer[CSSindex] == EOL)
                   7493:                         {
                   7494:                           LineNumber ++;
                   7495:                           newlines --;
                   7496:                         }
                   7497:                       CSSindex--;
                   7498:                     }
                   7499:                   CSSindex = CSScomment - 1; /* will be incremented later */
                   7500:                   CSScomment = MAX_CSS_LENGTH;
                   7501:                   /* clean up the buffer */
                   7502:                   if (newlines && CSSindex > 0)
                   7503:                     while (CSSindex > 0 &&
                   7504:                            (CSSbuffer[CSSindex] == SPACE ||
                   7505:                             CSSbuffer[CSSindex] == BSPACE ||
                   7506:                             CSSbuffer[CSSindex] == EOL ||
                   7507:                             CSSbuffer[CSSindex] == TAB ||
                   7508:                             CSSbuffer[CSSindex] == __CR__))
                   7509:                       {
                   7510:                         if ( CSSbuffer[CSSindex] == EOL)
                   7511:                           {
                   7512:                             LineNumber ++;
                   7513:                             newlines --;
                   7514:                           }
                   7515:                         CSSindex--;
                   7516:                       }
                   7517:                 }
1.342     vatton   7518:               else if (!fontface && !page && !quoted && !s_quoted &&
1.327     vatton   7519:                        CSScomment == MAX_CSS_LENGTH && CSSindex > 0 &&
                   7520:                        CSSbuffer[CSSindex - 1] ==  '<')
                   7521:                 {
                   7522:                   /* this is the closing tag ! */
                   7523:                   CSSindex -= 2; /* remove </ from the CSS string */
                   7524:                   noRule = TRUE;
1.342     vatton   7525:                 }
                   7526:               else if (!quoted && !s_quoted &&
                   7527:                        (CSSindex == 1 || (CSSindex > 1 && CSSbuffer[CSSindex - 2] == EOL))  &&
                   7528:                        CSScomment == MAX_CSS_LENGTH &&
                   7529:                        CSSbuffer[CSSindex - 1] == '/')
                   7530:                 {
                   7531:                   CSSindex--;
                   7532:                   lineComment = TRUE;
                   7533:                 }
                   7534:                 
1.327     vatton   7535:               break;
                   7536:             case '<':
1.342     vatton   7537:               if (!fontface && !page && !quoted && !s_quoted &&
1.327     vatton   7538:                   CSScomment == MAX_CSS_LENGTH)
                   7539:                 {
                   7540:                   /* only if we're not parsing a comment */
                   7541:                   c = buffer[index++];
                   7542:                   eof = (c == EOS);
                   7543:                   if (c == '!')
                   7544:                     {
                   7545:                       /* CSS within an HTML comment */
                   7546:                       HTMLcomment = TRUE;
                   7547:                       CSSindex++;
                   7548:                       CSSbuffer[CSSindex] = c;
                   7549:                     }
                   7550:                   else if (c == EOS)
                   7551:                     CSSindex++;
                   7552:                 }
                   7553:               break;
                   7554:             case '-':
1.342     vatton   7555:               if (!fontface && !page && !quoted && !s_quoted &&
1.327     vatton   7556:                   CSSindex > 0 && CSSbuffer[CSSindex - 1] == '-' &&
                   7557:                   HTMLcomment)
                   7558:                 /* CSS within an HTML comment */
                   7559:                 noRule = TRUE;
                   7560:               break;
                   7561:             case '>':
1.342     vatton   7562:               if (!fontface && !page && !quoted && !s_quoted && HTMLcomment)
1.327     vatton   7563:                 noRule = TRUE;
                   7564:               break;
                   7565:             case ' ':
1.358     quint    7566:               if (!quoted && !s_quoted && import != MAX_CSS_LENGTH && openBlock == 0)
1.327     vatton   7567:                 media = !strncasecmp (&CSSbuffer[import+1], "media", 5);
                   7568:               break;
                   7569:             case '{':
1.342     vatton   7570:               if (!quoted && !s_quoted)
1.327     vatton   7571:                 {
1.358     quint    7572:                   openBlock++;
1.327     vatton   7573:                   if (import != MAX_CSS_LENGTH)
                   7574:                     {
1.358     quint    7575:                       if (openBlock == 1 && media)
1.327     vatton   7576:                         {
                   7577:                           /* is it the screen concerned? */
                   7578:                           CSSbuffer[CSSindex+1] = EOS;
                   7579:                           css_media = CheckMediaCSS (&CSSbuffer[import+7]);
                   7580:                           if (TtaIsPrinting ())
                   7581:                             ignore = (css_media != CSS_ALL && css_media != CSS_PRINT);
                   7582:                           else
                   7583:                             ignore = (css_media != CSS_ALL && css_media != CSS_SCREEN);
                   7584:                           noRule = TRUE;
                   7585:                         }
                   7586:                       else if (!strncasecmp (&CSSbuffer[import+1], "page", 4))
1.358     quint    7587:                         /* it is a @page block */
1.327     vatton   7588:                         {
1.358     quint    7589:                           page = openBlock;/*remember the level of this block*/
1.327     vatton   7590:                           noRule = TRUE;
                   7591:                         }
                   7592:                       else if (!strncasecmp (&CSSbuffer[import+1], "font-face", 9))
                   7593:                         {
                   7594:                           fontface = TRUE;
                   7595:                           noRule = TRUE;
                   7596:                         }
                   7597:                     }
                   7598:                 }
                   7599:               break;
                   7600:             case '}':
1.342     vatton   7601:               if (!quoted && !s_quoted)
1.327     vatton   7602:                 {
1.358     quint    7603:                   if (page == openBlock)
                   7604:                     /* closing the @page block */
1.327     vatton   7605:                     {
                   7606:                       noRule = TRUE;
1.358     quint    7607:                       page = 0; /* close the page section */
1.327     vatton   7608:                     }
                   7609:                   else if (fontface)
                   7610:                     {
                   7611:                       noRule = TRUE;
                   7612:                       fontface = FALSE; /* close the fontface section */
                   7613:                     }
1.358     quint    7614:                   else if (openBlock == 1 && import != MAX_CSS_LENGTH)
1.327     vatton   7615:                     {
                   7616:                       import = MAX_CSS_LENGTH;
                   7617:                       noRule = TRUE;
                   7618:                       ignore = FALSE;
                   7619:                       media = FALSE;
                   7620:                     }
1.358     quint    7621:                   else if (!page)
1.327     vatton   7622:                     toParse = TRUE;
1.358     quint    7623:                   openBlock--;
1.327     vatton   7624:                 }
                   7625:               break;
                   7626:             case '"':
                   7627:               if (quoted)
                   7628:                 {
1.342     vatton   7629:                   if (CSSindex > 0 && CSSbuffer[CSSindex - 1] != '\\')
1.327     vatton   7630:                     quoted = FALSE;
                   7631:                 }
1.342     vatton   7632:               else if (!s_quoted)
1.327     vatton   7633:                 quoted = TRUE;
                   7634:               break;
1.342     vatton   7635:              case '\'':
                   7636:               if (s_quoted)
                   7637:                 {
                   7638:                   if (CSSindex > 0 && CSSbuffer[CSSindex - 1] != '\\')
                   7639:                     s_quoted = FALSE;
                   7640:                 }
                   7641:               else if (!quoted)
                   7642:                 s_quoted = TRUE;
                   7643:               break;
                   7644:            default:
1.327     vatton   7645:               if (c == EOL)
                   7646:                 {
                   7647:                   newlines++;
                   7648:                 }
                   7649:               break;
                   7650:             }
1.82      cvs      7651:         }
1.93      vatton   7652:       else if (c == EOL)
1.327     vatton   7653:         {
                   7654:           LineNumber++;
1.342     vatton   7655:           lineComment = FALSE;
1.327     vatton   7656:           c = CR;
                   7657:         }
1.234     vatton   7658: 
1.342     vatton   7659:       if (!lineComment && c != CR)
1.327     vatton   7660:         CSSindex++;
1.82      cvs      7661: 
                   7662:       if (CSSindex >= MAX_CSS_LENGTH && CSScomment < MAX_CSS_LENGTH)
1.327     vatton   7663:         /* we're still parsing a comment: remove the text comment */
                   7664:         CSSindex = CSScomment;
1.82      cvs      7665: 
                   7666:       if (CSSindex >= MAX_CSS_LENGTH || toParse || noRule)
1.327     vatton   7667:         {
                   7668:           CSSbuffer[CSSindex] = EOS;
                   7669:           /* parse a not empty string */
                   7670:           if (CSSindex > 0)
                   7671:             {
1.50      cvs      7672:               /* apply CSS rule if it's not just a saving of text */
1.234     vatton   7673:               if (!noRule && !ignore)
1.327     vatton   7674:                 {
                   7675:                   /* future import rules must be ignored */
                   7676:                   ignoreImport = TRUE;
                   7677:                   NewLineSkipped = 0;
                   7678:                   ParseStyleDeclaration (NULL, CSSbuffer, docRef, refcss,
                   7679:                                          pInfo->PiLink, url, FALSE);
                   7680:                   LineNumber += newlines;
                   7681:                   newlines = 0;
                   7682:                 }
1.82      cvs      7683:               else if (import != MAX_CSS_LENGTH &&
1.327     vatton   7684:                        !strncasecmp (&CSSbuffer[import+1], "import", 6))
                   7685:                 {
                   7686:                   /* import section */
                   7687:                   cssRule = &CSSbuffer[import+7];
                   7688:                   cssRule = TtaSkipBlanks (cssRule);
                   7689:                   /* save the current line number */
                   7690:                   newlines += LineNumber;
                   7691:                   if (!strncasecmp (cssRule, "url", 3))
                   7692:                     {
1.50      cvs      7693:                       cssRule = &cssRule[3];
1.82      cvs      7694:                       cssRule = TtaSkipBlanks (cssRule);
                   7695:                       if (*cssRule == '(')
1.327     vatton   7696:                         {
                   7697:                           cssRule++;
                   7698:                           cssRule = TtaSkipBlanks (cssRule);
                   7699:                           quoted = (*cssRule == '"' || *cssRule == '\'');
                   7700:                           if (quoted)
                   7701:                             cssRule++;
                   7702:                           base = cssRule;
                   7703:                           while (*cssRule != EOS && *cssRule != ')')
                   7704:                             cssRule++;
                   7705:                           if (quoted)
                   7706:                             {
                   7707:                               /* isolate the file name */
                   7708:                               cssRule[-1] = EOS;
                   7709:                               quoted = FALSE;
                   7710:                             }
                   7711:                           else
                   7712:                             {
                   7713:                               /* remove extra spaces */
                   7714:                               if (cssRule[-1] == SPACE)
                   7715:                                 {
                   7716:                                   *cssRule = SPACE;
                   7717:                                   cssRule--;
                   7718:                                   while (cssRule[-1] == SPACE)
                   7719:                                     cssRule--;
                   7720:                                 }
                   7721:                             }
                   7722:                           *cssRule = EOS;
                   7723:                         }
                   7724:                     }
                   7725:                   else if (*cssRule == '"')
                   7726:                     {
                   7727:                       /*
                   7728:                         Do we have to accept single quotes?
                   7729:                         Double quotes are accepted here.
                   7730:                         Escaped quotes are not handled. See function SkipQuotedString
                   7731:                       */
                   7732:                       cssRule++;
                   7733:                       cssRule = TtaSkipBlanks (cssRule);
                   7734:                       base = cssRule;
                   7735:                       while (*cssRule != EOS &&
                   7736:                              (*cssRule != '"' ||
                   7737:                               (*cssRule == '"' && cssRule[-1] == '\\')))
                   7738:                         cssRule++;
                   7739:                       /* isolate the file name */
                   7740:                       *cssRule = EOS;
                   7741:                     }
                   7742:                   /* check if a media is defined */
                   7743:                   cssRule++;
                   7744:                   cssRule = TtaSkipBlanks (cssRule);
                   7745:                   if (*cssRule != ';')
                   7746:                     {
                   7747:                       css_media = CheckMediaCSS (cssRule);
                   7748:                       if (TtaIsPrinting ())
                   7749:                         ignoreImport = (css_media != CSS_ALL && css_media != CSS_PRINT);
                   7750:                       else
                   7751:                         ignoreImport = (css_media != CSS_ALL && css_media != CSS_SCREEN);
                   7752:                     }
                   7753:                   if (!ignoreImport)
                   7754:                     {
                   7755:                       /* save the displayed URL when an error is reported */
1.348     vatton   7756:                       saveDocURL = Error_DocURL;
1.327     vatton   7757:                       ptr = TtaStrdup (base);
                   7758:                       /* get the CSS URI in UTF-8 */
                   7759:                       /*ptr = ReallocUTF8String (ptr, docRef);*/
                   7760:                       LoadStyleSheet (base, docRef, (Element) css, css,
                   7761:                                       url, pInfo->PiMedia,
                   7762:                                       pInfo->PiCategory == CSS_USER_STYLE);
                   7763:                       /* restore the displayed URL when an error is reported */
1.348     vatton   7764:                       Error_DocURL = saveDocURL;
1.327     vatton   7765:                       TtaFreeMemory (ptr);
                   7766:                     }
                   7767:                   /* restore the number of lines */
                   7768:                   LineNumber = newlines;
                   7769:                   newlines = 0;
                   7770:                   NewLineSkipped = 0;
                   7771:                   import = MAX_CSS_LENGTH;
                   7772:                 }
                   7773:               else
                   7774:                 {
                   7775:                   LineNumber += newlines;
                   7776:                   newlines = 0;
                   7777:                 }
                   7778:             }
                   7779:           toParse = FALSE;
                   7780:           noRule = FALSE;
                   7781:           CSSindex = 0;
1.50      cvs      7782:         }
1.82      cvs      7783:     }
1.310     vatton   7784:   /* closing the CSS parsing */
1.311     vatton   7785:   Style_parsing--;
1.330     cvs      7786:   if (RedisplayImages == 0 && RedisplayBGImage && Style_parsing == 0)
1.310     vatton   7787:     {
1.311     vatton   7788:       /* CSS parsing finishes after a BG image was loaded */
1.310     vatton   7789:       RedisplayBGImage = FALSE;
1.330     cvs      7790:       if (dispMode != NoComputedDisplay)
                   7791:         {
                   7792:           RedisplayDoc = 0;
                   7793:           //printf ("ReadCSS Show BGimages\n");
                   7794:           TtaSetDisplayMode (docRef, NoComputedDisplay);
                   7795:           TtaSetDisplayMode (docRef, dispMode);
                   7796:         }
1.310     vatton   7797:     }
1.330     cvs      7798:   else if (dispMode != NoComputedDisplay)
1.311     vatton   7799:     /* restore the display mode */
                   7800:     TtaSetDisplayMode (docRef, dispMode);
1.86      cvs      7801: 
                   7802:   /* Prepare the context for style attributes */
1.348     vatton   7803:   Error_DocURL = DocumentURLs[docRef];
1.86      cvs      7804:   LineNumber = -1;
1.1       cvs      7805:   return (c);
                   7806: }

Webmaster