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

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

Webmaster