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

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

Webmaster