1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_STARMATH_INC_NODE_HXX
21 #define INCLUDED_STARMATH_INC_NODE_HXX
28 #include <o3tl/typed_flags_set.hxx>
33 enum class FontAttribute
{
41 template<> struct typed_flags
<FontAttribute
> : is_typed_flags
<FontAttribute
, 0x0003> {};
45 enum class FontSizeType
{
53 // flags to interdict respective status changes
54 enum class FontChangeMask
{
66 template<> struct typed_flags
<FontChangeMask
> : is_typed_flags
<FontChangeMask
, 0x003f> {};
73 class SmStructureNode
;
75 typedef std::vector
< SmNode
* > SmNodeArray
;
77 enum class SmScaleMode
86 /* 0*/ Table
, Brace
, Bracebody
, Oper
, Align
,
87 /* 5*/ Attribut
, Font
, UnHor
, BinHor
, BinVer
,
88 /*10*/ BinDiagonal
, SubSup
, Matrix
, Place
, Text
,
89 /*15*/ Special
, GlyphSpecial
, Math
, Blank
, Error
,
90 /*20*/ Line
, Expression
, PolyLine
, Root
, RootSymbol
,
91 /*25*/ Rectangle
, VerticalBrace
, MathIdent
95 class SmNode
: public SmRect
100 SmNodeType
const meType
;
101 SmScaleMode meScaleMode
;
102 RectHorAlign meRectHorAlign
;
103 FontChangeMask mnFlags
;
104 FontAttribute mnAttributes
;
107 // index in accessible text; -1 if not (yet) applicable
108 sal_Int32 mnAccIndex
;
111 SmNode(SmNodeType eNodeType
, const SmToken
&rNodeToken
);
114 SmNode(const SmNode
&) = delete;
115 SmNode
& operator=(const SmNode
&) = delete;
120 * Returns true if this is an instance of SmVisibleNode's subclass, false otherwise.
122 virtual bool IsVisible() const = 0;
124 virtual size_t GetNumSubNodes() const = 0;
125 virtual SmNode
* GetSubNode(size_t nIndex
) = 0;
126 const SmNode
* GetSubNode(size_t nIndex
) const
128 return const_cast<SmNode
*>(this)->GetSubNode(nIndex
);
131 virtual const SmNode
* GetLeftMost() const;
133 FontChangeMask
&Flags() { return mnFlags
; }
134 FontAttribute
&Attributes() { return mnAttributes
; }
136 bool IsPhantom() const { return mbIsPhantom
; }
137 void SetPhantom(bool bIsPhantom
);
138 void SetColor(const Color
&rColor
);
140 void SetAttribut(FontAttribute nAttrib
);
141 void ClearAttribut(FontAttribute nAttrib
);
143 const SmFace
& GetFont() const { return maFace
; };
144 SmFace
& GetFont() { return maFace
; };
146 void SetFont(const SmFace
&rFace
);
147 void SetFontSize(const Fraction
&rRelSize
, FontSizeType nType
);
148 void SetSize(const Fraction
&rScale
);
150 /** Prepare preliminary settings about font and text
151 * (e.g. maFace, meRectHorAlign, mnFlags, mnAttributes, etc.)
153 virtual void Prepare(const SmFormat
&rFormat
, const SmDocShell
&rDocShell
, int nDepth
);
154 void PrepareAttributes();
156 void SetRectHorAlign(RectHorAlign eHorAlign
, bool bApplyToSubTree
= true );
157 RectHorAlign
GetRectHorAlign() const { return meRectHorAlign
; }
159 const SmRect
& GetRect() const { return *this; }
161 void Move(const Point
&rPosition
);
162 void MoveTo(const Point
&rPosition
) { Move(rPosition
- GetTopLeft()); }
163 virtual void Arrange(OutputDevice
&rDev
, const SmFormat
&rFormat
) = 0;
164 virtual void CreateTextFromNode(OUStringBuffer
&rText
);
166 virtual void GetAccessibleText( OUStringBuffer
&rText
) const = 0;
167 sal_Int32
GetAccessibleIndex() const { return mnAccIndex
; }
168 void SetAccessibleIndex(sal_Int32 nAccIndex
) { mnAccIndex
= nAccIndex
; }
169 const SmNode
* FindNodeWithAccessibleIndex(sal_Int32 nAccIndex
) const;
171 sal_uInt16
GetRow() const { return sal::static_int_cast
<sal_uInt16
>(maNodeToken
.nRow
); }
172 sal_uInt16
GetColumn() const { return sal::static_int_cast
<sal_uInt16
>(maNodeToken
.nCol
); }
174 SmScaleMode
GetScaleMode() const { return meScaleMode
; }
175 void SetScaleMode(SmScaleMode eMode
) { meScaleMode
= eMode
; }
177 virtual void AdaptToX(OutputDevice
&rDev
, sal_uLong nWidth
);
178 virtual void AdaptToY(OutputDevice
&rDev
, sal_uLong nHeight
);
180 SmNodeType
GetType() const { return meType
; }
181 const SmToken
& GetToken() const { return maNodeToken
; }
183 const SmNode
* FindTokenAt(sal_uInt16 nRow
, sal_uInt16 nCol
) const;
184 const SmNode
* FindRectClosestTo(const Point
&rPoint
) const;
187 * Calls the method for this class on the visitor
189 virtual void Accept(SmVisitor
* pVisitor
) = 0;
191 /** True if this node is selected */
192 bool IsSelected() const {return mbIsSelected
;}
193 void SetSelected(bool Selected
) {mbIsSelected
= Selected
;}
195 /** Get the parent node of this node */
196 SmStructureNode
* GetParent(){ return mpParentNode
; }
197 const SmStructureNode
* GetParent() const { return mpParentNode
; }
198 /** Set the parent node */
199 void SetParent(SmStructureNode
* parent
){
200 mpParentNode
= parent
;
203 /** Set the token for this node */
204 void SetToken(SmToken
const & token
){
209 SmStructureNode
* mpParentNode
;
213 /** Abstract baseclass for all composite node
215 * Subclasses of this class can have subnodes. Nodes that doesn't derivate from
216 * this class does not have subnodes.
218 class SmStructureNode
: public SmNode
220 SmNodeArray maSubNodes
;
223 SmStructureNode(SmNodeType eNodeType
, const SmToken
&rNodeToken
, size_t nSize
= 0)
224 : SmNode(eNodeType
, rNodeToken
)
229 virtual ~SmStructureNode() override
;
231 virtual bool IsVisible() const override
;
233 virtual size_t GetNumSubNodes() const override
;
235 using SmNode::GetSubNode
;
236 virtual SmNode
* GetSubNode(size_t nIndex
) override
;
237 void ClearSubNodes();
238 void SetSubNodes(std::unique_ptr
<SmNode
> pFirst
, std::unique_ptr
<SmNode
> pSecond
, std::unique_ptr
<SmNode
> pThird
= nullptr);
239 void SetSubNodes(SmNodeArray
&& rNodeArray
);
241 virtual void GetAccessibleText( OUStringBuffer
&rText
) const override
;
243 SmNodeArray::iterator
begin() {return maSubNodes
.begin();}
244 SmNodeArray::iterator
end() {return maSubNodes
.end();}
245 SmNodeArray::reverse_iterator
rbegin() {return maSubNodes
.rbegin();}
246 SmNodeArray::reverse_iterator
rend() {return maSubNodes
.rend();}
248 /** Get the index of a child node
250 * Returns -1, if pSubNode isn't a subnode of this.
252 int IndexOfSubNode(SmNode
const * pSubNode
)
254 size_t nSize
= GetNumSubNodes();
255 for (size_t i
= 0; i
< nSize
; i
++)
256 if (pSubNode
== GetSubNode(i
))
261 void SetSubNode(size_t nIndex
, SmNode
* pNode
)
263 size_t size
= maSubNodes
.size();
266 //Resize subnodes array
267 maSubNodes
.resize(nIndex
+ 1);
268 //Set new slots to NULL except at nIndex
269 for (size_t i
= size
; i
< nIndex
; i
++)
270 maSubNodes
[i
] = nullptr;
272 maSubNodes
[nIndex
] = pNode
;
274 pNode
->SetParent(this);
278 /** Sets parent on children of this node */
279 void ClaimPaternity();
283 /** Abstract base class for all visible node
285 * Nodes that doesn't derivate from this class doesn't draw anything, but their
288 class SmVisibleNode
: public SmNode
291 SmVisibleNode(SmNodeType eNodeType
, const SmToken
&rNodeToken
)
292 : SmNode(eNodeType
, rNodeToken
)
297 virtual bool IsVisible() const override
;
298 virtual size_t GetNumSubNodes() const override
;
299 using SmNode::GetSubNode
;
300 virtual SmNode
* GetSubNode(size_t nIndex
) override
;
304 class SmGraphicNode
: public SmVisibleNode
307 SmGraphicNode(SmNodeType eNodeType
, const SmToken
&rNodeToken
)
308 : SmVisibleNode(eNodeType
, rNodeToken
)
313 virtual void GetAccessibleText( OUStringBuffer
&rText
) const override
;
317 /** Draws a rectangle
319 * Used for drawing the line in the OVER and OVERSTRIKE commands.
321 class SmRectangleNode
: public SmGraphicNode
326 explicit SmRectangleNode(const SmToken
&rNodeToken
)
327 : SmGraphicNode(SmNodeType::Rectangle
, rNodeToken
)
330 virtual void AdaptToX(OutputDevice
&rDev
, sal_uLong nWidth
) override
;
331 virtual void AdaptToY(OutputDevice
&rDev
, sal_uLong nHeight
) override
;
333 virtual void Arrange(OutputDevice
&rDev
, const SmFormat
&rFormat
) override
;
335 void CreateTextFromNode(OUStringBuffer
&rText
) override
;
336 void Accept(SmVisitor
* pVisitor
) override
;
340 /** Polygon line node
342 * Used to draw the slash of the WIDESLASH command by SmBinDiagonalNode.
344 class SmPolyLineNode
: public SmGraphicNode
346 tools::Polygon maPoly
;
351 explicit SmPolyLineNode(const SmToken
&rNodeToken
);
353 long GetWidth() const { return mnWidth
; }
354 tools::Polygon
&GetPolygon() { return maPoly
; }
356 virtual void AdaptToX(OutputDevice
&rDev
, sal_uLong nWidth
) override
;
357 virtual void AdaptToY(OutputDevice
&rDev
, sal_uLong nHeight
) override
;
359 virtual void Arrange(OutputDevice
&rDev
, const SmFormat
&rFormat
) override
;
361 void Accept(SmVisitor
* pVisitor
) override
;
367 * @remarks This class also serves as baseclass for all nodes that contains text.
369 class SmTextNode
: public SmVisibleNode
372 sal_uInt16 mnFontDesc
;
373 /** Index within text where the selection starts
374 * @remarks Only valid if SmNode::IsSelected() is true
376 sal_Int32 mnSelectionStart
;
377 /** Index within text where the selection ends
378 * @remarks Only valid if SmNode::IsSelected() is true
380 sal_Int32 mnSelectionEnd
;
383 SmTextNode(SmNodeType eNodeType
, const SmToken
&rNodeToken
, sal_uInt16 nFontDescP
);
386 SmTextNode(const SmToken
&rNodeToken
, sal_uInt16 nFontDescP
);
388 sal_uInt16
GetFontDesc() const { return mnFontDesc
; }
389 void SetText(const OUString
&rText
) { maText
= rText
; }
390 const OUString
& GetText() const { return maText
; }
391 /** Change the text of this node, including the underlying token */
392 void ChangeText(const OUString
&rText
) {
394 SmToken token
= GetToken();
396 SetToken(token
); //TODO: Merge this with AdjustFontDesc for better performance
399 /** Try to guess the correct FontDesc, used during visual editing */
400 void AdjustFontDesc();
401 /** Index within GetText() where the selection starts
402 * @remarks Only valid of SmNode::IsSelected() is true
404 sal_Int32
GetSelectionStart() const {return mnSelectionStart
;}
405 /** Index within GetText() where the selection end
406 * @remarks Only valid of SmNode::IsSelected() is true
408 sal_Int32
GetSelectionEnd() const {return mnSelectionEnd
;}
409 /** Set the index within GetText() where the selection starts */
410 void SetSelectionStart(sal_Int32 index
) {mnSelectionStart
= index
;}
411 /** Set the index within GetText() where the selection end */
412 void SetSelectionEnd(sal_Int32 index
) {mnSelectionEnd
= index
;}
414 virtual void Prepare(const SmFormat
&rFormat
, const SmDocShell
&rDocShell
, int nDepth
) override
;
415 virtual void Arrange(OutputDevice
&rDev
, const SmFormat
&rFormat
) override
;
416 virtual void CreateTextFromNode(OUStringBuffer
&rText
) override
;
418 virtual void GetAccessibleText( OUStringBuffer
&rText
) const override
;
419 void Accept(SmVisitor
* pVisitor
) override
;
421 Converts the character from StarMath's private area symbols to a matching Unicode
422 character, if necessary. To be used when converting GetText() to a normal text.
424 static sal_Unicode
ConvertSymbolToUnicode(sal_Unicode nIn
);
428 /** Special node for user defined characters
430 * Node used for pre- and user-defined characters from:
431 * officecfg/registry/data/org/openoffice/Office/Math.xcu
433 * This is just single characters, I think.
435 class SmSpecialNode
: public SmTextNode
437 bool const mbIsFromGreekSymbolSet
;
440 SmSpecialNode(SmNodeType eNodeType
, const SmToken
&rNodeToken
, sal_uInt16 _nFontDesc
);
443 explicit SmSpecialNode(const SmToken
&rNodeToken
);
445 virtual void Prepare(const SmFormat
&rFormat
, const SmDocShell
&rDocShell
, int nDepth
) override
;
446 virtual void Arrange(OutputDevice
&rDev
, const SmFormat
&rFormat
) override
;
448 void Accept(SmVisitor
* pVisitor
) override
;
452 /** Glyph node for custom operators
454 * This node is used with commands: oper, uoper and boper.
455 * E.g. in "A boper op B", "op" will be an instance of SmGlyphSpecialNode.
456 * "boper" simply interprets "op", the following token, as a binary operator.
457 * The command "uoper" interprets the following token as unary operator.
458 * For these commands an instance of SmGlyphSpecialNode is used for the
459 * operator token, following the command.
461 class SmGlyphSpecialNode
: public SmSpecialNode
464 explicit SmGlyphSpecialNode(const SmToken
&rNodeToken
)
465 : SmSpecialNode(SmNodeType::GlyphSpecial
, rNodeToken
, FNT_MATH
)
468 virtual void Arrange(OutputDevice
&rDev
, const SmFormat
&rFormat
) override
;
469 void Accept(SmVisitor
* pVisitor
) override
;
475 * Use for math symbols such as plus, minus and integral in the INT command.
477 class SmMathSymbolNode
: public SmSpecialNode
480 SmMathSymbolNode(SmNodeType eNodeType
, const SmToken
&rNodeToken
)
481 : SmSpecialNode(eNodeType
, rNodeToken
, FNT_MATH
)
483 sal_Unicode cChar
= GetToken().cMathChar
;
485 SetText(OUString(cChar
));
489 explicit SmMathSymbolNode(const SmToken
&rNodeToken
);
491 virtual void AdaptToX(OutputDevice
&rDev
, sal_uLong nWidth
) override
;
492 virtual void AdaptToY(OutputDevice
&rDev
, sal_uLong nHeight
) override
;
494 virtual void Prepare(const SmFormat
&rFormat
, const SmDocShell
&rDocShell
, int nDepth
) override
;
495 virtual void Arrange(OutputDevice
&rDev
, const SmFormat
&rFormat
) override
;
496 void CreateTextFromNode(OUStringBuffer
&rText
) override
;
497 void Accept(SmVisitor
* pVisitor
) override
;
503 * This behaves essentially the same as SmMathSymbolNode and is only used to
504 * represent math symbols that should be exported as <mi> elements rather than
507 class SmMathIdentifierNode
: public SmMathSymbolNode
510 explicit SmMathIdentifierNode(const SmToken
&rNodeToken
)
511 : SmMathSymbolNode(SmNodeType::MathIdent
, rNodeToken
) {}
517 * Root symbol node used by SmRootNode to create the root symbol, in front of
518 * the line with the line above. I don't think this node should be used for
521 class SmRootSymbolNode
: public SmMathSymbolNode
523 sal_uLong mnBodyWidth
; // width of body (argument) of root sign
526 explicit SmRootSymbolNode(const SmToken
&rNodeToken
)
527 : SmMathSymbolNode(SmNodeType::RootSymbol
, rNodeToken
)
532 sal_uLong
GetBodyWidth() const {return mnBodyWidth
;};
533 virtual void AdaptToX(OutputDevice
&rDev
, sal_uLong nHeight
) override
;
534 virtual void AdaptToY(OutputDevice
&rDev
, sal_uLong nHeight
) override
;
536 void Accept(SmVisitor
* pVisitor
) override
;
542 * Used to create the <?> command, that denotes place where something can be
544 * It is drawn as a square with a shadow.
546 class SmPlaceNode
: public SmMathSymbolNode
549 explicit SmPlaceNode(const SmToken
&rNodeToken
)
550 : SmMathSymbolNode(SmNodeType::Place
, rNodeToken
)
553 SmPlaceNode() : SmMathSymbolNode(SmNodeType::Place
, SmToken(TPLACE
, MS_PLACE
, "<?>")) {};
555 virtual void Prepare(const SmFormat
&rFormat
, const SmDocShell
&rDocShell
, int nDepth
) override
;
556 virtual void Arrange(OutputDevice
&rDev
, const SmFormat
&rFormat
) override
;
557 void Accept(SmVisitor
* pVisitor
) override
;
561 /** Error node, for parsing errors
563 * This node is used for parsing errors and draws a questionmark turned upside
564 * down (inverted question mark).
566 class SmErrorNode
: public SmMathSymbolNode
569 explicit SmErrorNode(const SmToken
&rNodeToken
)
570 : SmMathSymbolNode(SmNodeType::Error
, rNodeToken
)
572 SetText(OUString(MS_ERROR
));
575 virtual void Prepare(const SmFormat
&rFormat
, const SmDocShell
&rDocShell
, int nDepth
) override
;
576 virtual void Arrange(OutputDevice
&rDev
, const SmFormat
&rFormat
) override
;
577 void Accept(SmVisitor
* pVisitor
) override
;
583 * This is the root node for the formula tree. This node is also used for the
584 * STACK and BINOM commands. When used for root node, its
585 * children are instances of SmLineNode, and in some obscure cases the child
586 * can be an instance of SmExpressionNode, mainly when errors occur.
588 class SmTableNode
: public SmStructureNode
590 long mnFormulaBaseline
;
592 explicit SmTableNode(const SmToken
&rNodeToken
)
593 : SmStructureNode(SmNodeType::Table
, rNodeToken
)
594 , mnFormulaBaseline(0)
598 virtual const SmNode
* GetLeftMost() const override
;
600 virtual void Arrange(OutputDevice
&rDev
, const SmFormat
&rFormat
) override
;
601 long GetFormulaBaseline() const;
603 void Accept(SmVisitor
* pVisitor
) override
;
609 * Used as child of SmTableNode when the SmTableNode is the root node of the
612 class SmLineNode
: public SmStructureNode
614 bool mbUseExtraSpaces
;
617 SmLineNode(SmNodeType eNodeType
, const SmToken
&rNodeToken
)
618 : SmStructureNode(eNodeType
, rNodeToken
)
619 , mbUseExtraSpaces(true)
624 explicit SmLineNode(const SmToken
&rNodeToken
)
625 : SmStructureNode(SmNodeType::Line
, rNodeToken
)
626 , mbUseExtraSpaces(true)
630 void SetUseExtraSpaces(bool bVal
) { mbUseExtraSpaces
= bVal
; }
631 bool IsUseExtraSpaces() const { return mbUseExtraSpaces
; };
633 virtual void Prepare(const SmFormat
&rFormat
, const SmDocShell
&rDocShell
, int nDepth
) override
;
634 virtual void Arrange(OutputDevice
&rDev
, const SmFormat
&rFormat
) override
;
635 void Accept(SmVisitor
* pVisitor
) override
;
641 * Used whenever you have an expression such as "A OVER {B + C}", here there is
642 * an expression node that allows "B + C" to be the denominator of the
643 * SmBinVerNode, that the OVER command creates.
645 class SmExpressionNode
: public SmLineNode
648 explicit SmExpressionNode(const SmToken
&rNodeToken
)
649 : SmLineNode(SmNodeType::Expression
, rNodeToken
)
652 virtual void Arrange(OutputDevice
&rDev
, const SmFormat
&rFormat
) override
;
653 void CreateTextFromNode(OUStringBuffer
&rText
) override
;
654 void Accept(SmVisitor
* pVisitor
) override
;
658 /** Unary horizontal node
660 * The same as SmBinHorNode except this is for unary operators.
662 class SmUnHorNode
: public SmStructureNode
665 explicit SmUnHorNode(const SmToken
&rNodeToken
)
666 : SmStructureNode(SmNodeType::UnHor
, rNodeToken
, 2)
670 virtual void Arrange(OutputDevice
&rDev
, const SmFormat
&rFormat
) override
;
671 void Accept(SmVisitor
* pVisitor
) override
;
677 * Used for create square roots and other roots, example:
678 * \f$ \sqrt[\mbox{[Argument]}]{\mbox{[Body]}} \f$.
681 * 0: Argument (optional)<BR>
682 * 1: Symbol (instance of SmRootSymbolNode)<BR>
684 * Where argument is optional and may be NULL.
686 class SmRootNode
: public SmStructureNode
689 explicit SmRootNode(const SmToken
&rNodeToken
)
690 : SmStructureNode(SmNodeType::Root
, rNodeToken
, 3)
694 virtual void Arrange(OutputDevice
&rDev
, const SmFormat
&rFormat
) override
;
695 void CreateTextFromNode(OUStringBuffer
&rText
) override
;
696 void Accept(SmVisitor
* pVisitor
) override
;
699 const SmNode
* Argument() const;
700 SmRootSymbolNode
* Symbol();
701 const SmRootSymbolNode
* Symbol() const;
703 const SmNode
* Body() const;
707 /** Binary horizontal node
709 * This node is used for binary operators. In a formula such as "A + B".
712 * 0: Left operand<BR>
713 * 1: Binary operator<BR>
714 * 2: Right operand<BR>
716 * None of the children may be NULL.
718 class SmBinHorNode
: public SmStructureNode
721 explicit SmBinHorNode(const SmToken
&rNodeToken
)
722 : SmStructureNode(SmNodeType::BinHor
, rNodeToken
, 3)
726 virtual void Arrange(OutputDevice
&rDev
, const SmFormat
&rFormat
) override
;
727 void Accept(SmVisitor
* pVisitor
) override
;
730 const SmNode
* Symbol() const;
731 SmNode
* LeftOperand();
732 const SmNode
* LeftOperand() const;
733 SmNode
* RightOperand();
734 const SmNode
* RightOperand() const;
738 /** Binary horizontal node
740 * This node is used for creating the OVER command, consider the formula:
741 * "numerator OVER denominator", which looks like
742 * \f$ \frac{\mbox{numerator}}{\mbox{denominator}} \f$
746 * 1: Line (instance of SmRectangleNode)<BR>
748 * None of the children may be NULL.
750 class SmBinVerNode
: public SmStructureNode
753 explicit SmBinVerNode(const SmToken
&rNodeToken
)
754 : SmStructureNode(SmNodeType::BinVer
, rNodeToken
, 3)
758 virtual const SmNode
* GetLeftMost() const override
;
760 virtual void Arrange(OutputDevice
&rDev
, const SmFormat
&rFormat
) override
;
761 void CreateTextFromNode(OUStringBuffer
&rText
) override
;
762 void Accept(SmVisitor
* pVisitor
) override
;
766 /** Binary diagonal node
768 * Used for implementing the WIDESLASH command, example: "A WIDESLASH B".
771 * 0: Left operand<BR>
772 * 1: right operand<BR>
773 * 2: Line (instance of SmPolyLineNode).<BR>
774 * None of the children may be NULL.
776 class SmBinDiagonalNode
: public SmStructureNode
780 void GetOperPosSize(Point
&rPos
, Size
&rSize
,
781 const Point
&rDiagPoint
, double fAngleDeg
) const;
784 explicit SmBinDiagonalNode(const SmToken
&rNodeToken
)
785 : SmStructureNode(SmNodeType::BinDiagonal
, rNodeToken
, 3)
790 bool IsAscending() const { return mbAscending
; }
791 void SetAscending(bool bVal
) { mbAscending
= bVal
; }
793 virtual void Arrange(OutputDevice
&rDev
, const SmFormat
&rFormat
) override
;
794 void Accept(SmVisitor
* pVisitor
) override
;
798 /** Enum used to index sub-/supscripts in the 'maSubNodes' array
801 * See graphic for positions at char:
816 { CSUB
, CSUP
, RSUB
, RSUP
, LSUB
, LSUP
819 /** numbers of entries in the above enum (that is: the number of possible
822 #define SUBSUP_NUM_ENTRIES 6
824 /** Super- and subscript node
826 * Used for creating super- and subscripts for commands such as:
827 * "^", "_", "lsup", "lsub", "csup" and "csub".
828 * Example: "A^2" which looks like: \f$ A^2 \f$
830 * This node is also used for creating limits on SmOperNode, when
831 * "FROM" and "TO" commands are used with "INT", "SUM" or similar.
833 * Children of this node can be enumerated using the SmSubSup enum.
834 * Please note that children may be NULL, except for the body.
835 * It is recommended that you access children using GetBody() and
838 class SmSubSupNode
: public SmStructureNode
843 explicit SmSubSupNode(const SmToken
&rNodeToken
)
844 : SmStructureNode(SmNodeType::SubSup
, rNodeToken
, 1 + SUBSUP_NUM_ENTRIES
)
849 /** Get body (Not NULL) */
850 SmNode
* GetBody() { return GetSubNode(0); }
851 /** Get body (Not NULL) */
852 const SmNode
* GetBody() const
854 return const_cast<SmSubSupNode
*>(this)->GetBody();
857 void SetUseLimits(bool bVal
) { mbUseLimits
= bVal
; }
858 bool IsUseLimits() const { return mbUseLimits
; };
860 /** Get super- or subscript
861 * @remarks this method may return NULL.
863 SmNode
* GetSubSup(SmSubSup eSubSup
) { return GetSubNode(1 + eSubSup
); };
864 const SmNode
* GetSubSup(SmSubSup eSubSup
) const { return const_cast< SmSubSupNode
* >( this )->GetSubSup( eSubSup
); }
867 void SetBody(SmNode
* pBody
) { SetSubNode(0, pBody
); }
868 void SetSubSup(SmSubSup eSubSup
, SmNode
* pScript
) { SetSubNode( 1 + eSubSup
, pScript
); }
870 virtual void Arrange(OutputDevice
&rDev
, const SmFormat
&rFormat
) override
;
871 void CreateTextFromNode(OUStringBuffer
&rText
) override
;
872 void Accept(SmVisitor
* pVisitor
) override
;
877 /** Node for brace construction
879 * Used for "lbrace [body] rbrace" and similar constructions.
880 * Should look like \f$ \{\mbox{[body]}\} \f$
883 * 0: Opening brace<BR>
884 * 1: Body (usually SmBracebodyNode)<BR>
885 * 2: Closing brace<BR>
886 * None of the children can be NULL.
888 * Note that child 1 (Body) is usually SmBracebodyNode, but it can also be e.g. SmExpressionNode.
890 class SmBraceNode
: public SmStructureNode
893 explicit SmBraceNode(const SmToken
&rNodeToken
)
894 : SmStructureNode(SmNodeType::Brace
, rNodeToken
, 3)
898 SmMathSymbolNode
* OpeningBrace();
899 const SmMathSymbolNode
* OpeningBrace() const;
901 const SmNode
* Body() const;
902 SmMathSymbolNode
* ClosingBrace();
903 const SmMathSymbolNode
* ClosingBrace() const;
905 virtual void Arrange(OutputDevice
&rDev
, const SmFormat
&rFormat
) override
;
906 void CreateTextFromNode(OUStringBuffer
&rText
) override
;
907 void Accept(SmVisitor
* pVisitor
) override
;
911 /** Body of an SmBraceNode
913 * This usually only has one child an SmExpressionNode, however, it can also
914 * have other children.
915 * Consider the formula "lbrace [body1] mline [body2] rbrace", looks like:
916 * \f$ \{\mbox{[body1] | [body2]}\} \f$.
917 * In this case SmBracebodyNode will have three children, "[body1]", "|" and
920 class SmBracebodyNode
: public SmStructureNode
925 explicit SmBracebodyNode(const SmToken
&rNodeToken
)
926 : SmStructureNode(SmNodeType::Bracebody
, rNodeToken
)
931 virtual void Arrange(OutputDevice
&rDev
, const SmFormat
&rFormat
) override
;
932 long GetBodyHeight() const { return mnBodyHeight
; }
933 void Accept(SmVisitor
* pVisitor
) override
;
937 /** Node for vertical brace construction
939 * Used to implement commands "[body] underbrace [script]" and
940 * "[body] overbrace [script]".
941 * Underbrace should look like this \f$ \underbrace{\mbox{body}}_{\mbox{script}}\f$.
947 * (None of these children are optional, e.g. they must all be not NULL).
949 class SmVerticalBraceNode
: public SmStructureNode
952 explicit inline SmVerticalBraceNode(const SmToken
&rNodeToken
);
955 const SmNode
* Body() const;
956 SmMathSymbolNode
* Brace();
957 const SmMathSymbolNode
* Brace() const;
959 const SmNode
* Script() const;
961 virtual void Arrange(OutputDevice
&rDev
, const SmFormat
&rFormat
) override
;
962 void Accept(SmVisitor
* pVisitor
) override
;
966 inline SmVerticalBraceNode::SmVerticalBraceNode(const SmToken
&rNodeToken
)
967 : SmStructureNode(SmNodeType::VerticalBrace
, rNodeToken
, 3)
974 * Used for commands like SUM, INT and similar.
977 * 0: Operation (instance of SmMathSymbolNode or SmSubSupNode)<BR>
979 * None of the children may be NULL.
982 class SmOperNode
: public SmStructureNode
985 explicit SmOperNode(const SmToken
&rNodeToken
)
986 : SmStructureNode(SmNodeType::Oper
, rNodeToken
, 2)
990 SmNode
* GetSymbol();
991 const SmNode
* GetSymbol() const
993 return const_cast<SmOperNode
*>(this)->GetSymbol();
996 long CalcSymbolHeight(const SmNode
&rSymbol
, const SmFormat
&rFormat
) const;
998 virtual void Arrange(OutputDevice
&rDev
, const SmFormat
&rFormat
) override
;
999 void Accept(SmVisitor
* pVisitor
) override
;
1003 /** Node used for alignment
1005 * This node has exactly one child at index 0.
1007 class SmAlignNode
: public SmStructureNode
1010 explicit SmAlignNode(const SmToken
&rNodeToken
)
1011 : SmStructureNode(SmNodeType::Align
, rNodeToken
)
1014 virtual void Arrange(OutputDevice
&rDev
, const SmFormat
&rFormat
) override
;
1015 void Accept(SmVisitor
* pVisitor
) override
;
1021 * Used to give an attribute to another node. Used for commands such as:
1022 * UNDERLINE, OVERLINE, OVERSTRIKE, WIDEVEC, WIDEHARPOON, WIDEHAT and WIDETILDE.
1027 * None of these may be NULL.
1029 class SmAttributNode
: public SmStructureNode
1032 explicit SmAttributNode(const SmToken
&rNodeToken
)
1033 : SmStructureNode(SmNodeType::Attribut
, rNodeToken
, 2)
1036 virtual void Arrange(OutputDevice
&rDev
, const SmFormat
&rFormat
) override
;
1037 void CreateTextFromNode(OUStringBuffer
&rText
) override
;
1038 void Accept(SmVisitor
* pVisitor
) override
;
1040 SmNode
* Attribute();
1041 const SmNode
* Attribute() const;
1043 const SmNode
* Body() const;
1049 * Used to change the font of its children.
1051 class SmFontNode
: public SmStructureNode
1053 FontSizeType meSizeType
;
1054 Fraction maFontSize
;
1057 explicit SmFontNode(const SmToken
&rNodeToken
)
1058 : SmStructureNode(SmNodeType::Font
, rNodeToken
)
1059 , meSizeType(FontSizeType::MULTIPLY
)
1064 void SetSizeParameter(const Fraction
&rValue
, FontSizeType nType
);
1065 const Fraction
& GetSizeParameter() const {return maFontSize
;}
1066 FontSizeType
GetSizeType() const {return meSizeType
;}
1068 virtual void Prepare(const SmFormat
&rFormat
, const SmDocShell
&rDocShell
, int nDepth
) override
;
1069 virtual void Arrange(OutputDevice
&rDev
, const SmFormat
&rFormat
) override
;
1070 void CreateTextFromNode(OUStringBuffer
&rText
) override
;
1071 void Accept(SmVisitor
* pVisitor
) override
;
1077 * Used to implement the MATRIX command, example:
1078 * "matrix{ 1 # 2 ## 3 # 4}".
1080 class SmMatrixNode
: public SmStructureNode
1082 sal_uInt16 mnNumRows
,
1086 explicit SmMatrixNode(const SmToken
&rNodeToken
)
1087 : SmStructureNode(SmNodeType::Matrix
, rNodeToken
)
1093 sal_uInt16
GetNumRows() const {return mnNumRows
;}
1094 sal_uInt16
GetNumCols() const {return mnNumCols
;}
1095 void SetRowCol(sal_uInt16 nMatrixRows
, sal_uInt16 nMatrixCols
);
1097 virtual const SmNode
* GetLeftMost() const override
;
1099 virtual void Arrange(OutputDevice
&rDev
, const SmFormat
&rFormat
) override
;
1100 void CreateTextFromNode(OUStringBuffer
&rText
) override
;
1101 void Accept(SmVisitor
* pVisitor
) override
;
1105 /** Node for whitespace
1107 * Used to implement the commands "~" and "`". This node is just a blank space.
1109 class SmBlankNode
: public SmGraphicNode
1114 explicit SmBlankNode(const SmToken
&rNodeToken
)
1115 : SmGraphicNode(SmNodeType::Blank
, rNodeToken
)
1120 void IncreaseBy(const SmToken
&rToken
, sal_uInt32 nMultiplyBy
= 1);
1121 void Clear() { mnNum
= 0; }
1122 sal_uInt16
GetBlankNum() const { return mnNum
; }
1123 void SetBlankNum(sal_uInt16 nNumber
) { mnNum
= nNumber
; }
1125 virtual void Prepare(const SmFormat
&rFormat
, const SmDocShell
&rDocShell
, int nDepth
) override
;
1126 virtual void Arrange(OutputDevice
&rDev
, const SmFormat
&rFormat
) override
;
1127 void Accept(SmVisitor
* pVisitor
) override
;
1128 virtual void CreateTextFromNode(OUStringBuffer
&rText
) override
;
1132 inline SmNode
* SmRootNode::Argument()
1134 assert( GetNumSubNodes() == 3 );
1135 return GetSubNode( 0 );
1137 inline const SmNode
* SmRootNode::Argument() const
1139 return const_cast< SmRootNode
* >( this )->Argument();
1141 inline SmRootSymbolNode
* SmRootNode::Symbol()
1143 assert( GetNumSubNodes() == 3 );
1144 assert( GetSubNode( 1 )->GetType() == SmNodeType::RootSymbol
);
1145 return static_cast< SmRootSymbolNode
* >( GetSubNode( 1 ));
1147 inline const SmRootSymbolNode
* SmRootNode::Symbol() const
1149 return const_cast< SmRootNode
* >( this )->Symbol();
1151 inline SmNode
* SmRootNode::Body()
1153 assert( GetNumSubNodes() == 3 );
1154 return GetSubNode( 2 );
1156 inline const SmNode
* SmRootNode::Body() const
1158 return const_cast< SmRootNode
* >( this )->Body();
1162 inline SmNode
* SmBinHorNode::Symbol()
1164 assert( GetNumSubNodes() == 3 );
1165 return GetSubNode( 1 );
1167 inline const SmNode
* SmBinHorNode::Symbol() const
1169 return const_cast< SmBinHorNode
* >( this )->Symbol();
1171 inline SmNode
* SmBinHorNode::LeftOperand()
1173 assert( GetNumSubNodes() == 3 );
1174 return GetSubNode( 0 );
1176 inline const SmNode
* SmBinHorNode::LeftOperand() const
1178 return const_cast< SmBinHorNode
* >( this )->LeftOperand();
1180 inline SmNode
* SmBinHorNode::RightOperand()
1182 assert( GetNumSubNodes() == 3 );
1183 return GetSubNode( 2 );
1185 inline const SmNode
* SmBinHorNode::RightOperand() const
1187 return const_cast< SmBinHorNode
* >( this )->RightOperand();
1190 inline SmNode
* SmAttributNode::Attribute()
1192 assert( GetNumSubNodes() == 2 );
1193 return GetSubNode( 0 );
1195 inline const SmNode
* SmAttributNode::Attribute() const
1197 return const_cast< SmAttributNode
* >( this )->Attribute();
1199 inline SmNode
* SmAttributNode::Body()
1201 assert( GetNumSubNodes() == 2 );
1202 return GetSubNode( 1 );
1204 inline const SmNode
* SmAttributNode::Body() const
1206 return const_cast< SmAttributNode
* >( this )->Body();
1209 inline SmMathSymbolNode
* SmBraceNode::OpeningBrace()
1211 assert( GetNumSubNodes() == 3 );
1212 assert( GetSubNode( 0 )->GetType() == SmNodeType::Math
);
1213 return static_cast< SmMathSymbolNode
* >( GetSubNode( 0 ));
1215 inline const SmMathSymbolNode
* SmBraceNode::OpeningBrace() const
1217 return const_cast< SmBraceNode
* >( this )->OpeningBrace();
1219 inline SmNode
* SmBraceNode::Body()
1221 assert( GetNumSubNodes() == 3 );
1222 return GetSubNode( 1 );
1224 inline const SmNode
* SmBraceNode::Body() const
1226 return const_cast< SmBraceNode
* >( this )->Body();
1228 inline SmMathSymbolNode
* SmBraceNode::ClosingBrace()
1230 assert( GetNumSubNodes() == 3 );
1231 assert( GetSubNode( 2 )->GetType() == SmNodeType::Math
);
1232 return static_cast< SmMathSymbolNode
* >( GetSubNode( 2 ));
1234 inline const SmMathSymbolNode
* SmBraceNode::ClosingBrace() const
1236 return const_cast< SmBraceNode
* >( this )->ClosingBrace();
1239 inline SmNode
* SmVerticalBraceNode::Body()
1241 assert( GetNumSubNodes() == 3 );
1242 return GetSubNode( 0 );
1244 inline const SmNode
* SmVerticalBraceNode::Body() const
1246 return const_cast< SmVerticalBraceNode
* >( this )->Body();
1248 inline SmMathSymbolNode
* SmVerticalBraceNode::Brace()
1250 assert( GetNumSubNodes() == 3 );
1251 assert( GetSubNode( 1 )->GetType() == SmNodeType::Math
);
1252 return static_cast< SmMathSymbolNode
* >( GetSubNode( 1 ));
1254 inline const SmMathSymbolNode
* SmVerticalBraceNode::Brace() const
1256 return const_cast< SmVerticalBraceNode
* >( this )->Brace();
1258 inline SmNode
* SmVerticalBraceNode::Script()
1260 assert( GetNumSubNodes() == 3 );
1261 return GetSubNode( 2 );
1263 inline const SmNode
* SmVerticalBraceNode::Script() const
1265 return const_cast< SmVerticalBraceNode
* >( this )->Script();
1271 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */