Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/blahtexml/source/BlahtexCore/MathmlNode.h
blob: dc4307ac8b82a52b7b2ac27e2a83089fe3796b2d (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
169
170
171
172
173
// File "MathmlNode.h"
//
// blahtex (version 0.4.4)
// a TeX to MathML converter designed with MediaWiki in mind
// Copyright (C) 2006, David Harvey
//
// blahtexml (version 0.5)
// Copyright (C) 2007-2008, Gilles Van Assche
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

#ifndef BLAHTEX_MATHMLNODE_H
#define BLAHTEX_MATHMLNODE_H

#include <iostream>
#include <map>
#include <list>
#include <string>
#include "Misc.h"

#ifdef BLAHTEXML_USING_XERCES
#include <xercesc/sax2/ContentHandler.hpp>
XERCES_CPP_NAMESPACE_USE
#endif

namespace blahtex
{

// MathmlFont lists all possible MathML "mathvariant" values. Blahtex
// uses these to record fonts in the layout tree; they get converted to
// MathML 1.x font attributes if needed.
enum MathmlFont
{
    cMathmlFontNormal,
    cMathmlFontBold,
    cMathmlFontItalic,
    cMathmlFontBoldItalic,
    cMathmlFontDoubleStruck,
    cMathmlFontBoldFraktur,
    cMathmlFontScript,
    cMathmlFontBoldScript,
    cMathmlFontFraktur,
    cMathmlFontSansSerif,
    cMathmlFontBoldSansSerif,
    cMathmlFontSansSerifItalic,
    cMathmlFontSansSerifBoldItalic,
    cMathmlFontMonospace
};

// String versions of the MathML mathvariant fonts.
// (See enum MathmlFont in LayoutTree.h.)
extern std::wstring gMathmlFontStrings[];


// Represents a node in an MathML tree.
struct MathmlNode
{
    enum Type
    {
        // Leaf nodes types ("token elements" in MathML documentation):
        cTypeMi,
        cTypeMo,
        cTypeMn,
        cTypeMspace,
        cTypeMtext,
        
        // Internal nodes types:
        cTypeMrow,
        cTypeMstyle,
        cTypeMsub,
        cTypeMsup,
        cTypeMsubsup,
        cTypeMunder,
        cTypeMover,
        cTypeMunderover,
        cTypeMfrac,
        cTypeMsqrt,
        cTypeMroot,
        cTypeMtable,
        cTypeMtr,
        cTypeMtd,
        cTypeMpadded
    }
    mType;

    enum Attribute
    {
        cAttributeDisplaystyle,
        cAttributeScriptlevel,
        cAttributeMathvariant,
        cAttributeMathcolor,
        cAttributeLspace,
        cAttributeRspace,
        cAttributeWidth,
        cAttributeStretchy,
        cAttributeMinsize,
        cAttributeMaxsize,
        cAttributeAccent,
        cAttributeMovablelimits,
        cAttributeLinethickness,
        cAttributeColumnalign,
        cAttributeColumnspacing,
        cAttributeRowspacing,
        cAttributeFontfamily,
        cAttributeFontstyle,
        cAttributeFontweight
    };

    std::map<Attribute, std::wstring> mAttributes;

    // mText is only used for leaf nodes: it holds the text that is
    // displayed between the opening and closing tags
    std::wstring mText;
    
    // mChildren is only used for internal nodes
    std::list<MathmlNode*> mChildren;
    
    MathmlNode(Type type, const std::wstring& text = L"") :
        mType(type),
        mText(text)
    { }
    
    ~MathmlNode();
    
    // This function adds mathvariant (for MathML 2.0) or fontstyle/
    // fontweight/fontfamily (for MathML 1.x) as appropriate to this node
    // to obtain the desired font. It knows about MathML defaults (like the
    // annoying automatic italic for single character <mi> nodes).
    void AddFontAttributes(
        MathmlFont desiredFont,
        const MathmlOptions& options
    );
    
    
    // Print() recursively prints the tree rooted at this node to the
    // given output stream.
    //
    // XML entities translated according to EncodingOptions.
    //
    // If "indent" is true, it will print each tag pair on a new line, and
    // add appropriate indenting.
    void Print(
        std::wostream& os,
        const EncodingOptions& options,
        bool indent,
        int depth = 0
    ) const;

    // Used internally by Print:
    void PrintType(std::wostream& os) const;
    void PrintAttributes(std::wostream& os) const;
#ifdef BLAHTEXML_USING_XERCES
    void PrintAsSAX2(ContentHandler& sax, const std::wstring& prefix, bool ignoreFirstmrow) const;
#endif
};

}

#endif

// end of file @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@