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

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

Webmaster