Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/svg/qsvgstyle_p.h

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtSvg module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    142142{
    143143    QSvgExtraStates();
     144
    144145    qreal fillOpacity;
     146    qreal strokeOpacity;
     147    QSvgFont *svgFont;
     148    Qt::Alignment textAnchor;
     149    int fontWeight;
     150    Qt::FillRule fillRule;
     151    qreal strokeDashOffset;
     152    bool vectorEffect; // true if pen is cosmetic
    145153};
    146154
     
    170178};
    171179
     180class QSvgFillStyleProperty : public QSvgStyleProperty
     181{
     182public:
     183    virtual QBrush brush(QPainter *p, QSvgExtraStates &states) = 0;
     184    virtual void apply(QPainter *p, const QRectF &, QSvgNode *node, QSvgExtraStates &states);
     185    virtual void revert(QPainter *p, QSvgExtraStates &states);
     186};
     187
    172188class QSvgQualityStyle : public QSvgStyleProperty
    173189{
     
    217233{
    218234public:
    219     QSvgFillStyle(const QBrush &brush);
    220     QSvgFillStyle(QSvgStyleProperty *style);
     235    QSvgFillStyle();
    221236    virtual void apply(QPainter *p, const QRectF &, QSvgNode *node, QSvgExtraStates &states);
    222237    virtual void revert(QPainter *p, QSvgExtraStates &states);
     
    225240    void setFillRule(Qt::FillRule f);
    226241    void setFillOpacity(qreal opacity);
     242    void setFillStyle(QSvgFillStyleProperty* style);
     243    void setBrush(QBrush brush);
    227244
    228245    const QBrush & qbrush() const
     
    230247        return m_fill;
    231248    }
     249
     250    qreal fillOpacity() const
     251    {
     252        return m_fillOpacity;
     253    }
     254
     255    Qt::FillRule fillRule() const
     256    {
     257        return m_fillRule;
     258    }
     259
     260    QSvgFillStyleProperty* style() const
     261    {
     262        return m_style;
     263    }
     264
     265    void setGradientId(const QString &Id)
     266    {
     267        m_gradientId = Id;
     268    }
     269
     270    QString gradientId() const
     271    {
     272        return m_gradientId;
     273    }
     274
     275    void setGradientResolved(bool resolved)
     276    {
     277        m_gradientResolved = resolved;
     278    }
     279
     280    bool isGradientResolved() const
     281    {
     282        return m_gradientResolved;
     283    }
     284
    232285private:
    233286    // fill            v        v       'inherit' | <Paint.datatype>
     
    235288    QBrush m_fill;
    236289    QBrush m_oldFill;
    237     QSvgStyleProperty *m_style;
    238 
    239     bool         m_fillRuleSet;
     290    QSvgFillStyleProperty *m_style;
     291
    240292    Qt::FillRule m_fillRule;
    241     bool m_fillOpacitySet;
     293    Qt::FillRule m_oldFillRule;
    242294    qreal m_fillOpacity;
    243     qreal m_oldOpacity;
     295    qreal m_oldFillOpacity;
     296
     297    QString m_gradientId;
     298    uint m_gradientResolved : 1;
     299
     300    uint m_fillRuleSet : 1;
     301    uint m_fillOpacitySet : 1;
     302    uint m_fillSet : 1;
    244303};
    245304
     
    267326{
    268327public:
     328    static const int LIGHTER = -1;
     329    static const int BOLDER = 1;
     330
    269331    QSvgFontStyle(QSvgFont *font, QSvgTinyDocument *doc);
    270     QSvgFontStyle(const QFont &font, QSvgTinyDocument *doc);
    271     virtual void apply(QPainter *p, const QRectF &, QSvgNode *node, QSvgExtraStates &states);
    272     virtual void revert(QPainter *p, QSvgExtraStates &states);
    273     virtual Type type() const;
    274 
    275     void setPointSize(qreal size);
    276     qreal pointSize() const;
    277 
    278     //### hack to avoid having a separate style element for text-anchor
    279     QString textAnchor() const;
    280     void setTextAnchor(const QString &anchor);
     332    QSvgFontStyle();
     333    virtual void apply(QPainter *p, const QRectF &, QSvgNode *node, QSvgExtraStates &states);
     334    virtual void revert(QPainter *p, QSvgExtraStates &states);
     335    virtual Type type() const;
     336
     337    void setSize(qreal size)
     338    {
     339        // Store the _pixel_ size in the font. Since QFont::setPixelSize() only takes an int, call
     340        // QFont::SetPointSize() instead. Set proper font size just before rendering.
     341        m_qfont.setPointSize(size);
     342        m_sizeSet = 1;
     343    }
     344
     345    void setTextAnchor(Qt::Alignment anchor)
     346    {
     347        m_textAnchor = anchor;
     348        m_textAnchorSet = 1;
     349    }
     350
     351    void setFamily(const QString &family)
     352    {
     353        m_qfont.setFamily(family);
     354        m_familySet = 1;
     355    }
     356
     357    void setStyle(QFont::Style fontStyle) {
     358        m_qfont.setStyle(fontStyle);
     359        m_styleSet = 1;
     360    }
     361
     362    void setVariant(QFont::Capitalization fontVariant)
     363    {
     364        m_qfont.setCapitalization(fontVariant);
     365        m_variantSet = 1;
     366    }
     367
     368    static int SVGToQtWeight(int weight);
     369
     370    void setWeight(int weight)
     371    {
     372        m_weight = weight;
     373        m_weightSet = 1;
     374    }
    281375
    282376    QSvgFont * svgFont() const
    283377    {
    284         return m_font;
    285     }
    286     QSvgTinyDocument *doc() const
    287     {
    288         return m_doc;
    289     }
    290 
    291     const QFont & qfont() const
     378        return m_svgFont;
     379    }
     380
     381    const QFont &qfont() const
    292382    {
    293383        return m_qfont;
    294384    }
    295 private:
    296     QSvgFont *m_font;
    297     qreal     m_pointSize;
     385
     386    QSvgTinyDocument *doc() const {return m_doc;}
     387
     388private:
     389    QSvgFont *m_svgFont;
    298390    QSvgTinyDocument *m_doc;
    299 
    300     QString m_textAnchor;
    301 
    302391    QFont m_qfont;
    303     QFont m_oldFont;
     392
     393    int m_weight;
     394    Qt::Alignment m_textAnchor;
     395
     396    QSvgFont *m_oldSvgFont;
     397    QFont m_oldQFont;
     398    Qt::Alignment m_oldTextAnchor;
     399    int m_oldWeight;
     400
     401    uint m_familySet : 1;
     402    uint m_sizeSet : 1;
     403    uint m_styleSet : 1;
     404    uint m_variantSet : 1;
     405    uint m_weightSet : 1;
     406    uint m_textAnchorSet : 1;
    304407};
    305408
     
    307410{
    308411public:
    309     QSvgStrokeStyle(const QPen &pen);
    310     virtual void apply(QPainter *p, const QRectF &, QSvgNode *node, QSvgExtraStates &states);
    311     virtual void revert(QPainter *p, QSvgExtraStates &states);
    312     virtual Type type() const;
    313 
    314     const QPen & qpen() const
     412    QSvgStrokeStyle();
     413    virtual void apply(QPainter *p, const QRectF &, QSvgNode *node, QSvgExtraStates &states);
     414    virtual void revert(QPainter *p, QSvgExtraStates &states);
     415    virtual Type type() const;
     416
     417    void setStroke(QBrush brush)
     418    {
     419        m_stroke.setBrush(brush);
     420        m_style = 0;
     421        m_strokeSet = 1;
     422    }
     423
     424    void setStyle(QSvgFillStyleProperty *style)
     425    {
     426        m_style = style;
     427        m_strokeSet = 1;
     428    }
     429
     430    void setDashArray(const QVector<qreal> &dashes);
     431
     432    void setDashArrayNone()
     433    {
     434        m_stroke.setStyle(Qt::SolidLine);
     435        m_strokeDashArraySet = 1;
     436    }
     437
     438    void setDashOffset(qreal offset)
     439    {
     440        m_strokeDashOffset = offset;
     441        m_strokeDashOffsetSet = 1;
     442    }
     443
     444    void setLineCap(Qt::PenCapStyle cap)
     445    {
     446        m_stroke.setCapStyle(cap);
     447        m_strokeLineCapSet = 1;
     448    }
     449
     450    void setLineJoin(Qt::PenJoinStyle join)
     451    {
     452        m_stroke.setJoinStyle(join);
     453        m_strokeLineJoinSet = 1;
     454    }
     455
     456    void setMiterLimit(qreal limit)
     457    {
     458        m_stroke.setMiterLimit(limit);
     459        m_strokeMiterLimitSet = 1;
     460    }
     461
     462    void setOpacity(qreal opacity)
     463    {
     464        m_strokeOpacity = opacity;
     465        m_strokeOpacitySet = 1;
     466    }
     467
     468    void setWidth(qreal width)
     469    {
     470        m_stroke.setWidthF(width);
     471        m_strokeWidthSet = 1;
     472        Q_ASSERT(!m_strokeDashArraySet); // set width before dash array.
     473    }
     474
     475    qreal width()
     476    {
     477        return m_stroke.widthF();
     478    }
     479
     480    void setVectorEffect(bool nonScalingStroke)
     481    {
     482        m_vectorEffect = nonScalingStroke;
     483        m_vectorEffectSet = 1;
     484    }
     485
     486    QSvgFillStyleProperty* style() const
     487    {
     488        return m_style;
     489    }
     490
     491    void setGradientId(const QString &Id)
     492    {
     493        m_gradientId = Id;
     494    }
     495
     496    QString gradientId() const
     497    {
     498        return m_gradientId;
     499    }
     500
     501    void setGradientResolved(bool resolved)
     502    {
     503        m_gradientResolved = resolved;
     504    }
     505
     506    bool isGradientResolved() const
     507    {
     508        return m_gradientResolved;
     509    }
     510
     511    QPen stroke() const
    315512    {
    316513        return m_stroke;
    317514    }
     515
    318516private:
    319517    // stroke            v      v       'inherit' | <Paint.datatype>
     
    326524    // stroke-width      v      v       'inherit' | <StrokeWidthValue.datatype>
    327525    QPen m_stroke;
    328 
    329526    QPen m_oldStroke;
    330 };
    331 
    332 
    333 class QSvgSolidColorStyle : public QSvgStyleProperty
     527    qreal m_strokeOpacity;
     528    qreal m_oldStrokeOpacity;
     529    qreal m_strokeDashOffset;
     530    qreal m_oldStrokeDashOffset;
     531
     532    QSvgFillStyleProperty *m_style;
     533    QString m_gradientId;
     534    uint m_gradientResolved : 1;
     535    uint m_vectorEffect : 1;
     536    uint m_oldVectorEffect : 1;
     537
     538    uint m_strokeSet : 1;
     539    uint m_strokeDashArraySet : 1;
     540    uint m_strokeDashOffsetSet : 1;
     541    uint m_strokeLineCapSet : 1;
     542    uint m_strokeLineJoinSet : 1;
     543    uint m_strokeMiterLimitSet : 1;
     544    uint m_strokeOpacitySet : 1;
     545    uint m_strokeWidthSet : 1;
     546    uint m_vectorEffectSet : 1;
     547};
     548
     549class QSvgSolidColorStyle : public QSvgFillStyleProperty
    334550{
    335551public:
    336552    QSvgSolidColorStyle(const QColor &color);
    337     virtual void apply(QPainter *p, const QRectF &, QSvgNode *node, QSvgExtraStates &states);
    338     virtual void revert(QPainter *p, QSvgExtraStates &states);
    339553    virtual Type type() const;
    340554
     
    343557        return m_solidColor;
    344558    }
     559
     560    QBrush brush(QPainter *, QSvgExtraStates &)
     561    {
     562        return m_solidColor;
     563    }
     564
    345565private:
    346566    // solid-color       v      x       'inherit' | <SVGColor.datatype>
     
    352572};
    353573
    354 class QSvgGradientStyle : public QSvgStyleProperty
     574class QSvgGradientStyle : public QSvgFillStyleProperty
    355575{
    356576public:
    357577    QSvgGradientStyle(QGradient *grad);
    358578    ~QSvgGradientStyle() { delete m_gradient; }
    359     virtual void apply(QPainter *p, const QRectF &, QSvgNode *node, QSvgExtraStates &states);
    360     virtual void revert(QPainter *p, QSvgExtraStates &states);
    361579    virtual Type type() const;
    362580
     
    376594    }
    377595
    378     void addResolve(qreal offset);
    379 
    380596    bool gradientStopsSet() const
    381597    {
     
    387603        m_gradientStopsSet = set;
    388604    }
     605
     606    QBrush brush(QPainter *, QSvgExtraStates &);
    389607private:
    390608    QGradient      *m_gradient;
    391     QList<qreal>  m_resolvePoints;
    392 
    393     QBrush m_oldFill;
    394 
    395609    QMatrix m_matrix;
    396610
     
    431645        SkewY
    432646    };
     647    enum Additive
     648    {
     649        Sum,
     650        Replace
     651    };
    433652public:
    434653    QSvgAnimateTransform(int startMs, int endMs, int by = 0);
    435     void setArgs(TransformType type, const QVector<qreal> &args);
     654    void setArgs(TransformType type, Additive additive, const QVector<qreal> &args);
    436655    void setFreeze(bool freeze);
    437656    void setRepeatCount(qreal repeatCount);
     
    439658    virtual void revert(QPainter *p, QSvgExtraStates &states);
    440659    virtual Type type() const;
     660    QSvgAnimateTransform::Additive additiveType() const
     661    {
     662        return m_additive;
     663    }
     664
     665    bool animActive(qreal totalTimeElapsed)
     666    {
     667        if (totalTimeElapsed < m_from)
     668            return false;
     669        if (m_freeze || m_repeatCount < 0) // fill="freeze" or repeat="indefinite"
     670            return true;
     671        if (m_totalRunningTime == 0)
     672            return false;
     673        qreal animationFrame = (totalTimeElapsed - m_from) / m_totalRunningTime;
     674        if (animationFrame > m_repeatCount)
     675            return false;
     676        return true;
     677    }
     678
     679    bool transformApplied() const
     680    {
     681        return m_transformApplied;
     682    }
     683
     684    // Call this instead of revert if you know that revert is unnecessary.
     685    void clearTransformApplied()
     686    {
     687        m_transformApplied = false;
     688    }
     689
    441690protected:
    442691    void resolveMatrix(QSvgNode *node);
     
    445694    qreal m_totalRunningTime;
    446695    TransformType m_type;
     696    Additive m_additive;
    447697    QVector<qreal> m_args;
    448698    int m_count;
     
    452702    bool m_freeze;
    453703    qreal m_repeatCount;
     704    bool m_transformApplied;
    454705};
    455706
Note: See TracChangeset for help on using the changeset viewer.