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

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

Webmaster