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

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

Webmaster