summaryrefslogtreecommitdiffstats
path: root/lib/kformula/tokenstyleelement.h
blob: 3789a0f4dca9825fdfaf0a331231b346edcd3c79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/* This file is part of the KDE project
   Copyright (C) 2006 Alfredo Beaumont Sainz <alfredo.beaumont@gmail.com>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#ifndef TOKENSTYLEELEMENT_H
#define TOKENSTYLEELEMENT_H

#include "kformuladefs.h"
#include "sequenceelement.h"

KFORMULA_NAMESPACE_BEGIN

/**
 * This class handles mathematical style attributes common to token elements,
 * as explained in MathML Spec, Section 3.2.2.
 *
 * It is in charge of reading and saving elements' attributes and setting
 * rendering information according to these attributes.
 */
class TokenStyleElement : public SequenceElement {
    typedef SequenceElement inherited;
public:

    TokenStyleElement( BasicElement* parent = 0 );

    virtual void calcSizes( const ContextStyle& context,
                            ContextStyle::TextStyle tstyle,
                            ContextStyle::IndexStyle istyle,
                            StyleAttributes& style );

    virtual void draw( TQPainter& painter, const LuPixelRect& r,
                       const ContextStyle& context,
                       ContextStyle::TextStyle tstyle,
                       ContextStyle::IndexStyle istyle,
                       StyleAttributes& style,
                       const LuPixelPoint& parentOrigin );

protected:
    virtual bool readAttributesFromMathMLDom( const TQDomElement &element );
    virtual void writeMathMLAttributes( TQDomElement& element ) const ;

    void setAbsoluteSize( double s, bool fontsize = false );
    void setRelativeSize( double s, bool fontsize = false );
    void setPixelSize( double s, bool fontsize = false );

    void setCharStyle( CharStyle cs ) { 
        m_charStyle = cs;
        m_customMathVariant = true; 
    }
    CharStyle charStyle() const { return m_charStyle; }

    void setCharFamily( CharFamily cf ) { 
        m_charFamily = cf; 
        m_customMathVariant = true;
    }
    CharFamily charFamily() const { return m_charFamily; }

    void setMathColor( const TQColor& c ) {
        m_mathColor = c; 
        m_customMathColor = true;
    }
    TQColor mathColor() const { return m_mathColor; }

    void setMathBackground( const TQColor& bg ) { 
        m_mathBackground = bg; 
        m_customMathBackground = true;
    }
    TQColor mathBackground() const { return m_mathBackground; }

    void setFontWeight( bool w ) { 
        m_fontWeight = w;
        m_customFontWeight = true; 
    }
    bool fontWeight() const { return m_fontWeight; }

    void setFontStyle( bool s ) { 
        m_fontStyle = s;
        m_customFontStyle = true;
    }
    bool fontStyle() const { return m_fontStyle; }

    void setFontFamily( const TQString& s ) { 
        m_fontFamily = s;
        m_customFontFamily = true;
    }
    TQString fontFamily() const { return m_fontFamily; }

    void setColor( const TQColor& c ) { 
        m_color = c; 
        m_customColor = true;
    }
    TQColor color() const { return m_color; }

    bool customMathVariant() const { return m_customMathVariant; }
    bool customMathColor() const { return m_customMathColor; }
    bool customMathBackground() const { return m_customMathBackground; }
    bool customFontWeight() const { return m_customFontWeight; }
    bool customFontStyle() const { return m_customFontStyle; }
    bool customFontFamily() const { return m_customFontFamily; }
    bool customColor() const { return m_customColor; }

    virtual void setStyleSize( const ContextStyle& context, StyleAttributes& style );
    /**
     * Set the mathvariant related info in style stacks, including info for
     * deprecated attributes. It may be redefined by token elements whose
     * behaviour differs from default one (e.g. identifiers)
     */
    virtual void setStyleVariant( StyleAttributes& style );

    void setStyleColor( StyleAttributes& style );
    virtual void setStyleBackground( StyleAttributes& style );

    virtual void resetStyle( StyleAttributes& style );
    /**
     * Return RGB string from HTML Colors. See HTML Spec, section 6.5
     */
    TQString getHtmlColor( const TQString& colorStr );

private:

    double sizeFactor( const ContextStyle& context, double factor );

    // MathML 2.0 attributes
    SizeType m_mathSizeType;
    double m_mathSize;
    CharStyle m_charStyle;
    CharFamily m_charFamily;
    TQColor m_mathColor;
    TQColor m_mathBackground;

    // Deprecated MathML 1.01 attributes
    SizeType m_fontSizeType;
    double m_fontSize;
    TQString m_fontFamily;
    TQColor m_color;
    bool m_fontWeight;
    bool m_fontStyle;

    // MathML 2.0 attributes set ?
    bool m_customMathVariant;
    bool m_customMathColor;
    bool m_customMathBackground;

    // Deprecated MathML 1.01 attributes set ?
    bool m_customFontWeight;
    bool m_customFontStyle;
    bool m_customFontFamily;
    bool m_customColor;
};

KFORMULA_NAMESPACE_END

#endif // TOKENSTYLEELEMENT_H