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

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

Webmaster