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

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

Webmaster