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

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

Webmaster