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

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

Webmaster