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

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

Webmaster