1 // Copyright (C) 2000-2007, Luca Padovani <padovani@sti.uniurb.it>.
2 //
3 // This file is part of GtkMathView, a flexible, high-quality rendering
4 // engine for MathML documents.
5 //
6 // GtkMathView is free software; you can redistribute it and/or modify it
7 // under the terms of the GNU Lesser General Public License as published
8 // by the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // GtkMathView is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19 #include <config.h>
20
21 #include <cassert>
22
23 #include "defs.h"
24 #include "AreaFactory.hh"
25 #include "MathMLSpaceElement.hh"
26 #include "MathMLValueConversion.hh"
27 #include "MathMLAttributeSignatures.hh"
28 #include "FormattingContext.hh"
29 #include "MathGraphicDevice.hh"
30
MathMLSpaceElement(const SmartPtr<class MathMLNamespaceContext> & context)31 MathMLSpaceElement::MathMLSpaceElement(const SmartPtr<class MathMLNamespaceContext>& context)
32 : MathMLElement(context)
33 {
34 breakability = T_AUTO;
35 }
36
~MathMLSpaceElement()37 MathMLSpaceElement::~MathMLSpaceElement()
38 { }
39
40 AreaRef
format(FormattingContext & ctxt)41 MathMLSpaceElement::format(FormattingContext& ctxt)
42 {
43 if (dirtyLayout())
44 {
45 ctxt.push(this);
46
47 scaled width;
48 if (SmartPtr<Value> value = GET_ATTRIBUTE_VALUE(MathML, Space, width))
49 width = ctxt.MGD()->evaluate(ctxt, toLength(value, ctxt), scaled::zero());
50 else
51 assert(false);
52
53 scaled height;
54 if (SmartPtr<Value> value = GET_ATTRIBUTE_VALUE(MathML, Space, height))
55 height = ctxt.MGD()->evaluate(ctxt, toLength(value, ctxt), scaled::zero());
56
57 scaled depth;
58 if (SmartPtr<Value> value = GET_ATTRIBUTE_VALUE(MathML, Space, depth))
59 depth = ctxt.MGD()->evaluate(ctxt, toLength(value, ctxt), scaled::zero());
60
61
62 #if 0
63 // fixme this should detect the presence of attributes in a different way
64 if (!IsSet(T_WIDTH) && !IsSet(T_HEIGHT) && !IsSet(T_DEPTH))
65 {
66 lineBreak = true;
67 autoLineBreak = IsSet(T_LINEBREAK);
68 if (!autoLineBreak)
69 breakability = ToTokenId(GET_ATTRIBUTE_VALUE(MathML, Space, linebreak));
70 }
71 else
72 #endif
73 lineBreak = false;
74
75 if (lineBreak)
76 setArea(0);
77 else
78 {
79 AreaRef res = ctxt.MGD()->getFactory()->box(ctxt.MGD()->getFactory()->horizontalSpace(scaled::zero()), BoundingBox(width, height, depth));
80 setArea(ctxt.MGD()->wrapper(ctxt, res));
81 }
82
83 ctxt.pop();
84 resetDirtyLayout();
85 }
86
87 return getArea();
88 }
89
90 bool
IsSpace() const91 MathMLSpaceElement::IsSpace() const
92 {
93 return true;
94 }
95
96 bool
IsSpaceLike() const97 MathMLSpaceElement::IsSpaceLike() const
98 {
99 return true;
100 }
101