Changeset 6730 in webkit


Ignore:
Timestamp:
May 28, 2004 2:40:42 PM (20 years ago)
Author:
rjw
Message:

setStrokeColor and setFillColor now support
old school web color string, oswcs+alpha, gray, gray+alpha,
rgba, and cmyka.

Reviewed by jay-lo.

  • khtml/css/cssparser.cpp: (CSSParser::parseColor): (CSSParser::parseColorFromValue):
  • khtml/css/cssparser.h: Made parseColor static public class method
  • khtml/ecma/kjs_html.cpp: (KJS::Context2DFunction::tryCall):
Location:
trunk/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog-2005-08-23

    r6728 r6730  
     12004-05-28  Richard Williamson   <rjw@apple.com>
     2
     3        setStrokeColor and setFillColor now support
     4        old school web color string, oswcs+alpha, gray, gray+alpha,
     5        rgba, and cmyka.
     6
     7        Reviewed by jay-lo.
     8
     9        * khtml/css/cssparser.cpp:
     10        (CSSParser::parseColor):
     11        (CSSParser::parseColorFromValue):
     12        * khtml/css/cssparser.h: Made parseColor static public class method
     13        * khtml/ecma/kjs_html.cpp:
     14        (KJS::Context2DFunction::tryCall):
     15
    1162004-05-28  David Hyatt  <hyatt@apple.com>
    217
  • trunk/WebCore/khtml/css/cssparser.cpp

    r6728 r6730  
    16631663
    16641664
    1665 static bool parseColor(const QString &name, QRgb& rgb)
     1665bool CSSParser::parseColor(const QString &name, QRgb& rgb)
    16661666{
    16671667    int len = name.length();
     
    17151715        QString str;
    17161716        str.sprintf( "%06d", (int)(value->fValue+.5) );
    1717         if (!::parseColor( str, c ))
     1717        if (!CSSParser::parseColor( str, c ))
    17181718            return 0;
    17191719    } else if ( value->unit == CSSPrimitiveValue::CSS_RGBCOLOR ||
    17201720                value->unit == CSSPrimitiveValue::CSS_IDENT ||
    17211721                value->unit == CSSPrimitiveValue::CSS_DIMENSION ) {
    1722         if (!::parseColor( qString( value->string ), c))
     1722        if (!CSSParser::parseColor( qString( value->string ), c))
    17231723            return 0;
    17241724    }
  • trunk/WebCore/khtml/css/cssparser.h

    r6037 r6730  
    2525
    2626#include <qstring.h>
     27#include <qcolor.h>
    2728#include <dom/dom_string.h>
    2829#include "xml/dom_atomicstring.h"
     
    132133        CSSPrimitiveValueImpl *parseColorFromValue(Value* val);
    133134
     135        static bool parseColor(const QString &name, QRgb& rgb);
     136
    134137        // CSS3 Parsing Routines (for properties specific to CSS3)
    135138        bool parseShadow(int propId, bool important);
  • trunk/WebCore/khtml/ecma/kjs_html.cpp

    r6727 r6730  
    5252
    5353#include <kdebug.h>
     54
     55#include "cssparser.h"
    5456
    5557#include "qcolor.h"
     
    33853387        }
    33863388        case Context2D::SetStrokeColor: {
    3387             if (args.size() < 1 || args.size() > 2) {
    3388                 Object err = Error::create(exec,SyntaxError);
    3389                 exec->setException(err);
    3390                 return err;
     3389            // string arg = named color
     3390            // string arg, number arg = named color, alpha
     3391            // number arg = gray color
     3392            // number arg, number arg = gray color, alpha
     3393            // 4 args (string or number) = r, g, b, a
     3394            // 5 args (string or number) = c, m, y, k, a
     3395            int numArgs = args.size();
     3396            switch (numArgs) {
     3397                case 1: {
     3398                    if (args[0].type() == StringType) {
     3399                        QRgb rgb = 0;
     3400                        DOM::CSSParser::parseColor(args[0].toString(exec).qstring(), rgb);
     3401                        QColor color(rgb);
     3402                        CGContextSetRGBStrokeColor(drawingContext, color.red(), color.green(), color.blue(), 1.);
     3403                    }
     3404                    else {
     3405                        float g = (float)args[0].toNumber(exec);
     3406                        CGContextSetGrayStrokeColor(drawingContext, g, 1.);
     3407                    }
     3408                }
     3409                break;
     3410                case 2: {
     3411                    float a = args[1].toNumber(exec);
     3412                    if (args[0].type() == StringType) {
     3413                        QRgb rgb = 0;
     3414                        DOM::CSSParser::parseColor(args[0].toString(exec).qstring(), rgb);
     3415                        QColor color(rgb);
     3416                        CGContextSetRGBStrokeColor(drawingContext, color.red(), color.green(), color.blue(), a);
     3417                    }
     3418                    else {
     3419                        float g = (float)args[0].toNumber(exec);
     3420                        CGContextSetGrayStrokeColor(drawingContext, g, a);
     3421                    }
     3422                }
     3423                break;
     3424                case 4: {
     3425                    float r = (float)args[0].toNumber(exec);
     3426                    float g = (float)args[1].toNumber(exec);
     3427                    float b = (float)args[2].toNumber(exec);
     3428                    float a = (float)args[3].toNumber(exec);
     3429                    CGContextSetRGBStrokeColor(drawingContext, r, g, b, a);
     3430                }
     3431                break;
     3432                case 5: {
     3433                    float c = (float)args[0].toNumber(exec);
     3434                    float m = (float)args[1].toNumber(exec);
     3435                    float y = (float)args[2].toNumber(exec);
     3436                    float k = (float)args[3].toNumber(exec);
     3437                    float a = (float)args[4].toNumber(exec);
     3438                    CGContextSetCMYKStrokeColor(drawingContext, c, m, y, k, a);
     3439                }
     3440                default: {
     3441                    Object err = Error::create(exec,SyntaxError);
     3442                    exec->setException(err);
     3443                    return err;
     3444                }
    33913445            }
    3392             QColor color;
    3393             if (args.size() > 0)
    3394                 color = QColor(args[0].toString(exec).ascii());
    3395             float alpha;
    3396             if (args.size() > 1)
    3397                 alpha = (float)args[1].toNumber(exec);
    3398             else
    3399                 alpha = 1.;
    3400             CGContextSetRGBStrokeColor(drawingContext, color.red(), color.green(), color.blue(), alpha);
    34013446            break;
    34023447        }
    34033448        case Context2D::SetFillColor: {
    3404             if (args.size() < 1 || args.size() > 2) {
    3405                 Object err = Error::create(exec,SyntaxError);
    3406                 exec->setException(err);
    3407                 return err;
     3449            // string arg = named color
     3450            // string arg, number arg = named color, alpha
     3451            // number arg = gray color
     3452            // number arg, number arg = gray color, alpha
     3453            // 4 args (string or number) = r, g, b, a
     3454            // 5 args (string or number) = c, m, y, k, a
     3455            int numArgs = args.size();
     3456            switch (numArgs) {
     3457                case 1: {
     3458                    if (args[0].type() == StringType) {
     3459                        QRgb rgb = 0;
     3460                        DOM::CSSParser::parseColor(args[0].toString(exec).qstring(), rgb);
     3461                        QColor color(rgb);
     3462                        CGContextSetRGBFillColor(drawingContext, color.red(), color.green(), color.blue(), 1.);
     3463                    }
     3464                    else {
     3465                        float g = (float)args[0].toNumber(exec);
     3466                        CGContextSetGrayFillColor(drawingContext, g, 1.);
     3467                    }
     3468                }
     3469                break;
     3470                case 2: {
     3471                    float a = args[1].toNumber(exec);
     3472                    if (args[0].type() == StringType) {
     3473                        QRgb rgb = 0;
     3474                        DOM::CSSParser::parseColor(args[0].toString(exec).qstring(), rgb);
     3475                        QColor color(rgb);
     3476                        CGContextSetRGBFillColor(drawingContext, color.red(), color.green(), color.blue(), a);
     3477                    }
     3478                    else {
     3479                        float g = (float)args[0].toNumber(exec);
     3480                        CGContextSetGrayFillColor(drawingContext, g, a);
     3481                    }
     3482                }
     3483                break;
     3484                case 4: {
     3485                    float r = (float)args[0].toNumber(exec);
     3486                    float g = (float)args[1].toNumber(exec);
     3487                    float b = (float)args[2].toNumber(exec);
     3488                    float a = (float)args[3].toNumber(exec);
     3489                    CGContextSetRGBFillColor(drawingContext, r, g, b, a);
     3490                }
     3491                break;
     3492                case 5: {
     3493                    float c = (float)args[0].toNumber(exec);
     3494                    float m = (float)args[1].toNumber(exec);
     3495                    float y = (float)args[2].toNumber(exec);
     3496                    float k = (float)args[3].toNumber(exec);
     3497                    float a = (float)args[4].toNumber(exec);
     3498                    CGContextSetCMYKStrokeColor(drawingContext, c, m, y, k, a);
     3499                }
     3500                default: {
     3501                    Object err = Error::create(exec,SyntaxError);
     3502                    exec->setException(err);
     3503                    return err;
     3504                }
    34083505            }
    3409             QColor color;
    3410             if (args.size() > 0)
    3411                 color = QColor(args[0].toString(exec).ascii());
    3412             float alpha;
    3413             if (args.size() > 1)
    3414                 alpha = (float)args[1].toNumber(exec);
    3415             else
    3416                 alpha = 1.;
    3417             CGContextSetRGBFillColor(drawingContext, color.red(), color.green(), color.blue(), alpha);
    34183506            break;
    34193507        }
Note: See TracChangeset for help on using the changeset viewer.