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

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

Webmaster