Bump version to 21.06.18.1
[LibreOffice.git] / starmath / inc / node.hxx
blob3bdb6bac6c9c94e5a5bcea68264e90497cf617cd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 /** The SmNode is the basic structure of formula data.
22 * Each token is stored in one node of specific kind.
23 * They can have SmNodeType. It allows to identify node type after abstraction.
24 * Here goes the subclasses tree:
26 * SmRect
27 * SmNode
28 * SmStructureNode Head of tree diagram
29 * SmTableNode binom
30 * SmLineNode A line
31 * SmExpressionNode { content }
32 * SmUnHorNode unary operators +-; -+; +x; -x; ...
33 * SmRootNode Root structure
34 * SmBinHorNode binary operators A + B
35 * SmBinVerNode over; frac; ...
36 * SmBinDiagonalNode wideslash
37 * SmSubSupNode csub, csup, lsub, from, to, ...
38 * SmBraceNode (); []; left lbrace right rbrace; ...
39 * SmBracebodyNode ( content ); [ content ]; ...
40 * SmVerticalBraceNode overbrace; underbrace;
41 * SmOperNode sum from to; int from to;
42 * SmAlignNode text alignment
43 * SmAttributNode font attributes; bold;
44 * SmFontNode font serif; ...
45 * SmMatrixNode matrix
46 * SmVisibleNode drawable node
47 * SmGraphicNode graphics display
48 * SmRectangleNode
49 * SmPolyLineNode overline; underline; widehat; ...
50 * SmBlankNode blank space; ~; ...
51 * SmTextNode "text"; func functname; ...
52 * SmSpecialNode
53 * SmGlyphSpecialNode %symbolname
54 * SmMathSymbolNode math symbols
55 * SmMathIdentifierNode variable
56 * SmRootSymbolNode root symbol
57 * SmPlaceNode <?>
58 * SmErrorNode red ? for errors
62 #ifndef INCLUDED_STARMATH_INC_NODE_HXX
63 #define INCLUDED_STARMATH_INC_NODE_HXX
65 #include "types.hxx"
66 #include "token.hxx"
67 #include "rect.hxx"
68 #include "format.hxx"
70 #include <o3tl/typed_flags_set.hxx>
71 #include <rtl/ustrbuf.hxx>
73 #include <cassert>
74 #include <vector>
76 enum class FontAttribute {
77 None = 0x0000,
78 Bold = 0x0001,
79 Italic = 0x0002
82 namespace o3tl
84 template<> struct typed_flags<FontAttribute> : is_typed_flags<FontAttribute, 0x0003> {};
88 enum class FontSizeType {
89 ABSOLUT = 1,
90 PLUS = 2,
91 MINUS = 3,
92 MULTIPLY = 4,
93 DIVIDE = 5
96 // flags to interdict respective status changes
97 enum class FontChangeMask {
98 None = 0x0000,
99 Face = 0x0001,
100 Size = 0x0002,
101 Bold = 0x0004,
102 Italic = 0x0008,
103 Color = 0x0010,
104 Phantom = 0x0020
107 namespace o3tl
109 template<> struct typed_flags<FontChangeMask> : is_typed_flags<FontChangeMask, 0x003f> {};
113 class SmVisitor;
114 class SmDocShell;
115 class SmNode;
116 class SmStructureNode;
118 typedef std::vector< SmNode * > SmNodeArray;
120 enum class SmScaleMode
122 None,
123 Width,
124 Height
127 enum class SmNodeType
129 /* 0*/ Table, Brace, Bracebody, Oper, Align,
130 /* 5*/ Attribut, Font, UnHor, BinHor, BinVer,
131 /*10*/ BinDiagonal, SubSup, Matrix, Place, Text,
132 /*15*/ Special, GlyphSpecial, Math, Blank, Error,
133 /*20*/ Line, Expression, PolyLine, Root, RootSymbol,
134 /*25*/ Rectangle, VerticalBrace, MathIdent
138 class SmNode : public SmRect
141 SmFace maFace;
142 SmToken maNodeToken;
143 SmNodeType meType;
144 SmScaleMode meScaleMode;
145 RectHorAlign meRectHorAlign;
146 FontChangeMask mnFlags;
147 FontAttribute mnAttributes;
148 bool mbIsPhantom;
149 bool mbIsSelected;
150 // index in accessible text; -1 if not (yet) applicable
151 sal_Int32 mnAccIndex;
153 protected:
154 SmNode(SmNodeType eNodeType, const SmToken &rNodeToken);
156 public:
157 SmNode(const SmNode&) = delete;
158 SmNode& operator=(const SmNode&) = delete;
160 virtual ~SmNode();
163 * Checks node visibility.
164 * Returns true if this is an instance of SmVisibleNode's subclass, false otherwise.
165 * @return node visibility
167 virtual bool IsVisible() const = 0;
170 * Gets the number of subnodes.
171 * @return number of subnodes
173 virtual size_t GetNumSubNodes() const = 0;
176 * Gets the subnode of index nIndex.
177 * @param nIndex
178 * @return subnode of index nIndex
180 virtual SmNode * GetSubNode(size_t nIndex) = 0;
181 const SmNode * GetSubNode(size_t nIndex) const
182 { return const_cast<SmNode *>(this)->GetSubNode(nIndex); }
184 virtual const SmNode * GetLeftMost() const;
187 * Gets the FontChangeMask flags.
188 * @return FontChangeMask flags
190 FontChangeMask &Flags() { return mnFlags; }
193 * Gets the font attributes.
194 * @return font attributes
196 FontAttribute &Attributes() { return mnAttributes; }
199 * Checks if it is a visible node rendered invisible.
200 * @return rendered visibility
202 bool IsPhantom() const { return mbIsPhantom; }
205 * Sets the render visibility of a visible node to bIsPhantom.
206 * @param bIsPhantom
207 * @return
209 void SetPhantom(bool bIsPhantom);
212 * Sets the font color.
213 * @param rColor
214 * @return
216 void SetColor(const Color &rColor);
219 * Sets the font attribute nAttrib.
220 * Check FontAttribute class.
221 * @param nAttrib
222 * @return
224 void SetAttribut(FontAttribute nAttrib);
227 * Clears the font attribute nAttrib.
228 * Check FontAttribute class.
229 * @param nAttrib
230 * @return
232 void ClearAttribut(FontAttribute nAttrib);
235 * Gets the font.
236 * @return font
238 const SmFace & GetFont() const { return maFace; };
239 SmFace & GetFont() { return maFace; };
242 * Sets the font to rFace.
243 * @param rFace
244 * @return
246 void SetFont(const SmFace &rFace);
249 * Sets the font size to rRelSize with type nType.
250 * Check FontSizeType for details.
251 * @param rRelSize
252 * @param nType
253 * @return
255 void SetFontSize(const Fraction &rRelSize, FontSizeType nType);
258 * Sets the font size to rRelSize with type FontSizeType::ABSOLUT.
259 * @param rScale
260 * @return
262 void SetSize(const Fraction &rScale);
265 * Prepare preliminary settings about font and text
266 * (e.g. maFace, meRectHorAlign, mnFlags, mnAttributes, etc.)
267 * @param rFormat
268 * @param rDocShell
269 * @param nDepth
270 * @return
272 virtual void Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell, int nDepth);
275 * Prepare preliminary font attributes
276 * Called on Prepare(...).
277 * @return
279 void PrepareAttributes();
282 * Sets the alignment of the text.
283 * Check RectHorAlign class for details.
284 * The subtrees will be affected if bApplyToSubTree.
285 * @param eHorAlign
286 * @param bApplyToSubTree
287 * @return
289 void SetRectHorAlign(RectHorAlign eHorAlign, bool bApplyToSubTree = true );
292 * Gets the alignment of the text.
293 * @return alignment of the text
295 RectHorAlign GetRectHorAlign() const { return meRectHorAlign; }
298 * Parses itself to SmRect.
299 * @return this
301 const SmRect & GetRect() const { return *this; }
304 * Moves the rectangle by rVector.
305 * @param rVector
306 * @return
308 void Move(const Point &rVector);
311 * Moves the rectangle to rPoint, being the top left corner the origin.
312 * @param rPoint
313 * @return
315 void MoveTo(const Point &rPoint) { Move(rPoint - GetTopLeft()); }
318 * Prepares the SmRect to render.
319 * @param rDev
320 * @param rFormat
321 * @return
323 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) = 0;
326 * Appends to rText the node text.
327 * @param rText
328 * @return
330 virtual void GetAccessibleText( OUStringBuffer &rText ) const = 0;
333 * Gets the node accessible index.
334 * Used for visual editing.
335 * @return node accessible index
337 sal_Int32 GetAccessibleIndex() const { return mnAccIndex; }
340 * Sets the node accessible index to nAccIndex.
341 * Used for visual editing.
342 * @param nAccIndex
343 * @return
345 void SetAccessibleIndex(sal_Int32 nAccIndex) { mnAccIndex = nAccIndex; }
348 * Finds the node with accessible index nAccIndex.
349 * Used for visual editing.
350 * @param nAccIndex
351 * @return node with accessible index nAccIndex
353 const SmNode * FindNodeWithAccessibleIndex(sal_Int32 nAccIndex) const;
356 * Gets the line in the text where the node is located.
357 * It is used to do the visual <-> text correspondence.
358 * @return line
360 sal_uInt16 GetRow() const { return sal::static_int_cast<sal_uInt16>(maNodeToken.nRow); }
363 * Gets the column of the line in the text where the node is located.
364 * It is used to do the visual <-> text correspondence.
365 * @return column
367 sal_uInt16 GetColumn() const { return sal::static_int_cast<sal_uInt16>(maNodeToken.nCol); }
370 * Gets the scale mode.
371 * @return scale mode
373 SmScaleMode GetScaleMode() const { return meScaleMode; }
376 * Sets the scale mode to eMode.
377 * @param eMode
378 * @return
380 void SetScaleMode(SmScaleMode eMode) { meScaleMode = eMode; }
382 //visual stuff TODO comment
383 virtual void AdaptToX(OutputDevice &rDev, sal_uLong nWidth);
384 virtual void AdaptToY(OutputDevice &rDev, sal_uLong nHeight);
387 * Gets the node type.
388 * @return node type
390 SmNodeType GetType() const { return meType; }
393 * Gets the token.
394 * The token contains the data extracted from the text mode.
395 * Ej: text, type (sub, sup, int,...), row and column,...
396 * @return node type
398 const SmToken & GetToken() const { return maNodeToken; }
399 SmToken & GetToken() { return maNodeToken; }
402 * Finds the node from the position in the text.
403 * It is used to do the visual <-> text correspondence.
404 * @param nRow
405 * @param nCol
406 * @return the given node
408 const SmNode * FindTokenAt(sal_uInt16 nRow, sal_uInt16 nCol) const;
411 * Finds the closest rectangle in the screen.
412 * @param rPoint
413 * @return the given node
415 const SmNode * FindRectClosestTo(const Point &rPoint) const;
418 * Accept a visitor.
419 * Calls the method for this class on the visitor.
420 * @param pVisitor
421 * @return
423 virtual void Accept(SmVisitor* pVisitor) = 0;
426 * Checks if the node is selected.
427 * @return the node is selected
429 bool IsSelected() const {return mbIsSelected;}
432 * Sets the node to Selected.
433 * @param Selected
434 * @return
436 void SetSelected(bool Selected) {mbIsSelected = Selected;}
439 * Gets the parent node of this node.
440 * @return parent node
442 const SmStructureNode* GetParent() const { return mpParentNode; }
443 SmStructureNode* GetParent() { return mpParentNode; }
446 * Sets the parent node.
447 * @param parent
448 * @return
450 void SetParent(SmStructureNode* parent){ mpParentNode = parent; }
453 * Sets the token for this node.
454 * @param token
455 * @return
457 void SetToken(SmToken const & token){ maNodeToken = token; }
459 private:
460 SmStructureNode* mpParentNode;
464 /** Abstract baseclass for all composite node
466 * Subclasses of this class can have subnodes. Nodes that doesn't derivate from
467 * this class does not have subnodes.
469 class SmStructureNode : public SmNode
471 SmNodeArray maSubNodes;
473 protected:
474 SmStructureNode(SmNodeType eNodeType, const SmToken &rNodeToken, size_t nSize = 0)
475 : SmNode(eNodeType, rNodeToken)
476 , maSubNodes(nSize) {}
478 public:
479 virtual ~SmStructureNode() override;
482 * Checks node visibility.
483 * Returns true if this is an instance of SmVisibleNode's subclass, false otherwise.
484 * @return node visibility
486 virtual bool IsVisible() const override;
489 * Gets the number of subnodes.
490 * @return number of subnodes
492 virtual size_t GetNumSubNodes() const override;
495 * Gets the subnode of index nIndex.
496 * @param nIndex
497 * @return subnode of index nIndex
499 using SmNode::GetSubNode;
500 virtual SmNode * GetSubNode(size_t nIndex) override;
503 * Does the cleaning of the subnodes.
504 * @return
506 void ClearSubNodes();
509 * Sets subnodes, used for operators.
510 * @param pFirst
511 * @param pSecond
512 * @param pThird
513 * @return
515 void SetSubNodes(std::unique_ptr<SmNode> pFirst, std::unique_ptr<SmNode> pSecond,
516 std::unique_ptr<SmNode> pThird = nullptr);
519 * Sets subnodes.
520 * @param rNodeArray
521 * @return
523 void SetSubNodes(SmNodeArray&& rNodeArray);
526 * Appends to rText the node text.
527 * @param rText
528 * @return
530 virtual void GetAccessibleText( OUStringBuffer &rText ) const override;
533 * Gets the first subnode.
534 * @return first subnode
536 SmNodeArray::iterator begin() {return maSubNodes.begin();}
539 * Gets the last subnode.
540 * @return last subnode
542 SmNodeArray::iterator end() {return maSubNodes.end();}
545 * Gets the last subnode.
546 * @return last subnode
548 SmNodeArray::reverse_iterator rbegin() {return maSubNodes.rbegin();}
551 * Gets the first subnode.
552 * @return first subnode
554 SmNodeArray::reverse_iterator rend() {return maSubNodes.rend();}
557 * Get the index of the child node pSubNode.
558 * Returns -1, if pSubNode isn't a subnode of this.
559 * @param pSubNode
560 * @return index of the child node
562 int IndexOfSubNode(SmNode const * pSubNode);
565 * Sets the subnode pNode at nIndex.
566 * If necessary increases the subnodes length.
567 * @param nIndex
568 * @param pNode
569 * @return
571 void SetSubNode(size_t nIndex, SmNode* pNode);
573 private:
574 /** Sets parent on children of this node */
575 void ClaimPaternity();
579 /** Abstract base class for all visible node
581 * Nodes that doesn't derivate from this class doesn't draw anything, but their
582 * children.
584 class SmVisibleNode : public SmNode
586 protected:
587 SmVisibleNode(SmNodeType eNodeType, const SmToken &rNodeToken)
588 : SmNode(eNodeType, rNodeToken) {}
590 public:
593 * Checks node visibility.
594 * Returns true if this is an instance of SmVisibleNode's subclass, false otherwise.
595 * @return node visibility
597 virtual bool IsVisible() const override;
600 * Gets the number of subnodes.
601 * @return number of subnodes
603 virtual size_t GetNumSubNodes() const override;
606 * Gets the subnode of index nIndex.
607 * @param nIndex
608 * @return subnode of index nIndex
610 using SmNode::GetSubNode;
611 virtual SmNode * GetSubNode(size_t nIndex) override;
615 class SmGraphicNode : public SmVisibleNode
617 protected:
618 SmGraphicNode(SmNodeType eNodeType, const SmToken &rNodeToken)
619 : SmVisibleNode(eNodeType, rNodeToken) {}
621 public:
624 * Appends to rText the node text.
625 * @param rText
626 * @return
628 virtual void GetAccessibleText( OUStringBuffer &rText ) const override;
632 /** Draws a rectangle
634 * Used for drawing the line in the OVER and OVERSTRIKE commands.
636 class SmRectangleNode final : public SmGraphicNode
638 Size maToSize;
640 public:
641 explicit SmRectangleNode(const SmToken &rNodeToken)
642 : SmGraphicNode(SmNodeType::Rectangle, rNodeToken)
645 //visual stuff TODO comment
646 virtual void AdaptToX(OutputDevice &rDev, sal_uLong nWidth) override;
647 virtual void AdaptToY(OutputDevice &rDev, sal_uLong nHeight) override;
650 * Prepares the SmRect to render.
651 * @param rDev
652 * @param rFormat
653 * @return
655 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
658 * Accept a visitor.
659 * Calls the method for this class on the visitor.
660 * @param pVisitor
661 * @return
663 void Accept(SmVisitor* pVisitor) override;
667 /** Polygon line node
669 * Used to draw the slash of the WIDESLASH command by SmBinDiagonalNode.
671 class SmPolyLineNode final : public SmGraphicNode
673 tools::Polygon maPoly;
674 Size maToSize;
675 tools::Long mnWidth;
677 public:
678 explicit SmPolyLineNode(const SmToken &rNodeToken);
681 * Gets the width of the rect.
682 * @return width
684 tools::Long GetWidth() const { return mnWidth; }
687 * Gets the polygon to draw the node.
688 * @return polygon
690 tools::Polygon &GetPolygon() { return maPoly; }
692 //visual stuff TODO comment
693 virtual void AdaptToX(OutputDevice &rDev, sal_uLong nWidth) override;
694 virtual void AdaptToY(OutputDevice &rDev, sal_uLong nHeight) override;
697 * Prepares the SmRect to render.
698 * @param rDev
699 * @param rFormat
700 * @return
702 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
705 * Accept a visitor.
706 * Calls the method for this class on the visitor.
707 * @param pVisitor
708 * @return
710 void Accept(SmVisitor* pVisitor) override;
714 /** Text node
716 * @remarks This class also serves as baseclass for all nodes that contains text.
718 class SmTextNode : public SmVisibleNode
721 protected:
722 OUString maText;
723 sal_uInt16 mnFontDesc;
724 /** Index within text where the selection starts
725 * @remarks Only valid if SmNode::IsSelected() is true
727 sal_Int32 mnSelectionStart;
728 /** Index within text where the selection ends
729 * @remarks Only valid if SmNode::IsSelected() is true
731 sal_Int32 mnSelectionEnd;
733 protected:
734 SmTextNode(SmNodeType eNodeType, const SmToken &rNodeToken, sal_uInt16 nFontDescP );
736 public:
737 SmTextNode(const SmToken &rNodeToken, sal_uInt16 nFontDescP );
740 * Returns the font type being used (text, variable, symbol, ...).
741 * @return font type
743 sal_uInt16 GetFontDesc() const { return mnFontDesc; }
746 * Sets the node text to rText.
747 * @param rText
748 * @return
750 void SetText(const OUString &rText) { maText = rText; }
753 * Gets the node text.
754 * @return node text
756 const OUString & GetText() const { return maText; }
757 OUString & GetText() { return maText; }
760 * Change the text of this node, including the underlying token to rText.
761 * @param rText
762 * @return
764 void ChangeText(const OUString &rText);
767 * Try to guess the correct FontDesc, used during visual editing
768 * @return
770 void AdjustFontDesc();
773 * Index within GetText() where the selection starts.
774 * @remarks Only valid of SmNode::IsSelected() is true.
775 * @return index.
777 sal_Int32 GetSelectionStart() const { return mnSelectionStart; }
780 * Index within GetText() where the selection ends.
781 * @remarks Only valid of SmNode::IsSelected() is true.
782 * @return index.
784 sal_Int32 GetSelectionEnd() const {return mnSelectionEnd; }
787 * Sets the index within GetText() where the selection starts to index.
788 * @param index
789 * @return
791 void SetSelectionStart(sal_Int32 index) {mnSelectionStart = index;}
794 * Sets the index within GetText() where the selection ends to index.
795 * @param index
796 * @return
798 void SetSelectionEnd(sal_Int32 index) {mnSelectionEnd = index;}
801 * Prepare preliminary settings about font and text
802 * (e.g. maFace, meRectHorAlign, mnFlags, mnAttributes, etc.)
803 * @param rFormat
804 * @param rDocShell
805 * @param nDepth
806 * @return
808 virtual void Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell,
809 int nDepth) override;
812 * Prepares the SmRect to render.
813 * @param rDev
814 * @param rFormat
815 * @return
817 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
820 * Appends to rText the node text.
821 * @param rText
822 * @return
824 virtual void GetAccessibleText( OUStringBuffer &rText ) const override;
827 * Accept a visitor.
828 * Calls the method for this class on the visitor.
829 * @param pVisitor
830 * @return
832 void Accept(SmVisitor* pVisitor) override;
835 * Converts the character from StarMath's private area symbols to a matching Unicode
836 * character, if necessary. To be used when converting GetText() to a normal text.
837 * @param nIn
838 * @return unicode char
840 static sal_Unicode ConvertSymbolToUnicode(sal_Unicode nIn);
844 /** Special node for user defined characters
846 * Node used for pre- and user-defined characters from:
847 * officecfg/registry/data/org/openoffice/Office/Math.xcu
849 * This is just single characters, I think.
851 class SmSpecialNode : public SmTextNode
853 bool mbIsFromGreekSymbolSet;
855 protected:
856 SmSpecialNode(SmNodeType eNodeType, const SmToken &rNodeToken, sal_uInt16 _nFontDesc);
858 public:
859 explicit SmSpecialNode(const SmToken &rNodeToken);
862 * Prepare preliminary settings about font and text
863 * (e.g. maFace, meRectHorAlign, mnFlags, mnAttributes, etc.)
864 * @param rFormat
865 * @param rDocShell
866 * @param nDepth
867 * @return
869 virtual void Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell,
870 int nDepth) override;
873 * Prepares the SmRect to render.
874 * @param rDev
875 * @param rFormat
876 * @return
878 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
881 * Accept a visitor.
882 * Calls the method for this class on the visitor.
883 * @param pVisitor
884 * @return
886 void Accept(SmVisitor* pVisitor) override;
890 /** Glyph node for custom operators
892 * This node is used with commands: oper, uoper and boper.
893 * E.g. in "A boper op B", "op" will be an instance of SmGlyphSpecialNode.
894 * "boper" simply interprets "op", the following token, as a binary operator.
895 * The command "uoper" interprets the following token as unary operator.
896 * For these commands an instance of SmGlyphSpecialNode is used for the
897 * operator token, following the command.
899 class SmGlyphSpecialNode final : public SmSpecialNode
901 public:
902 explicit SmGlyphSpecialNode(const SmToken &rNodeToken)
903 : SmSpecialNode(SmNodeType::GlyphSpecial, rNodeToken, FNT_MATH)
907 * Prepares the SmRect to render.
908 * @param rDev
909 * @param rFormat
910 * @return
912 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
915 * Accept a visitor.
916 * Calls the method for this class on the visitor.
917 * @param pVisitor
918 * @return
920 void Accept(SmVisitor* pVisitor) override;
924 /** Math symbol node
926 * Use for math symbols such as plus, minus and integral in the INT command.
928 class SmMathSymbolNode : public SmSpecialNode
930 protected:
931 SmMathSymbolNode(SmNodeType eNodeType, const SmToken &rNodeToken)
932 : SmSpecialNode(eNodeType, rNodeToken, FNT_MATH)
934 sal_Unicode cChar = GetToken().cMathChar;
935 if (u'\0' != cChar) SetText(OUString(cChar));
938 public:
939 explicit SmMathSymbolNode(const SmToken &rNodeToken);
941 //visual stuff TODO comment
942 virtual void AdaptToX(OutputDevice &rDev, sal_uLong nWidth) override;
943 virtual void AdaptToY(OutputDevice &rDev, sal_uLong nHeight) override;
946 * Prepare preliminary settings about font and text
947 * (e.g. maFace, meRectHorAlign, mnFlags, mnAttributes, etc.)
948 * @param rFormat
949 * @param rDocShell
950 * @param nDepth
951 * @return
953 virtual void Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell,
954 int nDepth) override;
957 * Prepares the SmRect to render.
958 * @param rDev
959 * @param rFormat
960 * @return
962 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
965 * Accept a visitor.
966 * Calls the method for this class on the visitor.
967 * @param pVisitor
968 * @return
970 void Accept(SmVisitor* pVisitor) override;
974 /** Math Identifier
976 * This behaves essentially the same as SmMathSymbolNode and is only used to
977 * represent math symbols that should be exported as <mi> elements rather than
978 * <mo> elements.
980 class SmMathIdentifierNode final : public SmMathSymbolNode
982 public:
983 explicit SmMathIdentifierNode(const SmToken &rNodeToken)
984 : SmMathSymbolNode(SmNodeType::MathIdent, rNodeToken) {}
988 /** Root symbol node
990 * Root symbol node used by SmRootNode to create the root symbol, in front of
991 * the line with the line above. I don't think this node should be used for
992 * anything else.
994 class SmRootSymbolNode final : public SmMathSymbolNode
996 sal_uLong mnBodyWidth; // width of body (argument) of root sign
998 public:
999 explicit SmRootSymbolNode(const SmToken &rNodeToken)
1000 : SmMathSymbolNode(SmNodeType::RootSymbol, rNodeToken)
1001 , mnBodyWidth(0) { }
1004 * Gets the body width.
1005 * Allows to know how long is the root and paint it.
1006 * @return body width
1008 sal_uLong GetBodyWidth() const {return mnBodyWidth;};
1010 //visual stuff TODO comment
1011 virtual void AdaptToX(OutputDevice &rDev, sal_uLong nHeight) override;
1012 virtual void AdaptToY(OutputDevice &rDev, sal_uLong nHeight) override;
1015 * Accept a visitor.
1016 * Calls the method for this class on the visitor.
1017 * @param pVisitor
1018 * @return
1020 void Accept(SmVisitor* pVisitor) override;
1024 /** Place node
1026 * Used to create the <?> command, that denotes place where something can be
1027 * written.
1028 * It is drawn as a square with a shadow.
1030 class SmPlaceNode final : public SmMathSymbolNode
1032 public:
1033 explicit SmPlaceNode(const SmToken &rNodeToken)
1034 : SmMathSymbolNode(SmNodeType::Place, rNodeToken) { }
1035 SmPlaceNode() : SmMathSymbolNode(SmNodeType::Place, SmToken(TPLACE, MS_PLACE, "<?>")) { };
1038 * Prepare preliminary settings about font and text
1039 * (e.g. maFace, meRectHorAlign, mnFlags, mnAttributes, etc.)
1040 * @param rFormat
1041 * @param rDocShell
1042 * @param nDepth
1043 * @return
1045 virtual void Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell,
1046 int nDepth) override;
1049 * Prepares the SmRect to render.
1050 * @param rDev
1051 * @param rFormat
1052 * @return
1054 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1057 * Accept a visitor.
1058 * Calls the method for this class on the visitor.
1059 * @param pVisitor
1060 * @return
1062 void Accept(SmVisitor* pVisitor) override;
1066 /** Error node, for parsing errors
1068 * This node is used for parsing errors and draws a questionmark turned upside
1069 * down (inverted question mark).
1071 class SmErrorNode final : public SmMathSymbolNode
1073 public:
1074 explicit SmErrorNode(const SmToken &rNodeToken)
1075 : SmMathSymbolNode(SmNodeType::Error, rNodeToken) { SetText(OUString(MS_ERROR)); }
1078 * Prepare preliminary settings about font and text
1079 * (e.g. maFace, meRectHorAlign, mnFlags, mnAttributes, etc.)
1080 * @param rFormat
1081 * @param rDocShell
1082 * @param nDepth
1083 * @return
1085 virtual void Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell,
1086 int nDepth) override;
1089 * Prepares the SmRect to render.
1090 * @param rDev
1091 * @param rFormat
1092 * @return
1094 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1097 * Accept a visitor.
1098 * Calls the method for this class on the visitor.
1099 * @param pVisitor
1100 * @return
1102 void Accept(SmVisitor* pVisitor) override;
1106 /** Table node
1108 * This is the root node for the formula tree. This node is also used for the
1109 * STACK and BINOM commands. When used for root node, its
1110 * children are instances of SmLineNode, and in some obscure cases the child
1111 * can be an instance of SmExpressionNode, mainly when errors occur.
1113 class SmTableNode final : public SmStructureNode
1115 tools::Long mnFormulaBaseline;
1116 public:
1117 explicit SmTableNode(const SmToken &rNodeToken)
1118 : SmStructureNode(SmNodeType::Table, rNodeToken)
1119 , mnFormulaBaseline(0) { }
1121 virtual const SmNode * GetLeftMost() const override;
1124 * Prepares the SmRect to render.
1125 * @param rDev
1126 * @param rFormat
1127 * @return
1129 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1132 * Gets the formula baseline.
1133 * @return formula baseline
1135 tools::Long GetFormulaBaseline() const;
1138 * Accept a visitor.
1139 * Calls the method for this class on the visitor.
1140 * @param pVisitor
1141 * @return
1143 void Accept(SmVisitor* pVisitor) override;
1147 /** A line
1149 * Used as child of SmTableNode when the SmTableNode is the root node of the
1150 * formula tree.
1152 class SmLineNode : public SmStructureNode
1154 bool mbUseExtraSpaces;
1156 protected:
1157 SmLineNode(SmNodeType eNodeType, const SmToken &rNodeToken)
1158 : SmStructureNode(eNodeType, rNodeToken)
1159 , mbUseExtraSpaces(true) { }
1161 public:
1162 explicit SmLineNode(const SmToken &rNodeToken)
1163 : SmStructureNode(SmNodeType::Line, rNodeToken)
1164 , mbUseExtraSpaces(true) { }
1167 * Sets if it going to use extra spaces.
1168 * It is used to set if there has to be space between node while rendering.
1169 * By default it is true.
1170 * @param bVal
1171 * @return
1173 void SetUseExtraSpaces(bool bVal) { mbUseExtraSpaces = bVal; }
1176 * Checks if it is using extra spaces.
1177 * It is used for calculating space between nodes when rendering.
1178 * By default it is true.
1179 * @return is using extra spaces
1181 bool IsUseExtraSpaces() const { return mbUseExtraSpaces; };
1184 * Prepare preliminary settings about font and text
1185 * (e.g. maFace, meRectHorAlign, mnFlags, mnAttributes, etc.)
1186 * @param rFormat
1187 * @param rDocShell
1188 * @param nDepth
1189 * @return
1191 virtual void Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell,
1192 int nDepth) override;
1195 * Prepares the SmRect to render.
1196 * @param rDev
1197 * @param rFormat
1198 * @return
1200 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1203 * Accept a visitor.
1204 * Calls the method for this class on the visitor.
1205 * @param pVisitor
1206 * @return
1208 void Accept(SmVisitor* pVisitor) override;
1212 /** Expression node
1214 * Used whenever you have an expression such as "A OVER {B + C}", here there is
1215 * an expression node that allows "B + C" to be the denominator of the
1216 * SmBinVerNode, that the OVER command creates.
1218 class SmExpressionNode final : public SmLineNode
1220 public:
1221 explicit SmExpressionNode(const SmToken &rNodeToken)
1222 : SmLineNode(SmNodeType::Expression, rNodeToken) { }
1225 * Prepares the SmRect to render.
1226 * @param rDev
1227 * @param rFormat
1228 * @return
1230 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1233 * Accept a visitor.
1234 * Calls the method for this class on the visitor.
1235 * @param pVisitor
1236 * @return
1238 void Accept(SmVisitor* pVisitor) override;
1242 /** Unary horizontal node
1244 * The same as SmBinHorNode except this is for unary operators.
1246 class SmUnHorNode final : public SmStructureNode
1248 public:
1249 explicit SmUnHorNode(const SmToken &rNodeToken)
1250 : SmStructureNode(SmNodeType::UnHor, rNodeToken, 2) { }
1253 * Prepares the SmRect to render.
1254 * @param rDev
1255 * @param rFormat
1256 * @return
1258 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1261 * Accept a visitor.
1262 * Calls the method for this class on the visitor.
1263 * @param pVisitor
1264 * @return
1266 void Accept(SmVisitor* pVisitor) override;
1270 /** Root node
1272 * Used for create square roots and other roots, example:
1273 * \f$ \sqrt[\mbox{[Argument]}]{\mbox{[Body]}} \f$.
1275 * Children:<BR>
1276 * 0: Argument (optional)<BR>
1277 * 1: Symbol (instance of SmRootSymbolNode)<BR>
1278 * 2: Body<BR>
1279 * Where argument is optional and may be NULL.
1281 class SmRootNode final : public SmStructureNode
1283 public:
1284 explicit SmRootNode(const SmToken &rNodeToken)
1285 : SmStructureNode(SmNodeType::Root, rNodeToken, 3) { }
1288 * Prepares the SmRect to render.
1289 * @param rDev
1290 * @param rFormat
1291 * @return
1293 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1296 * Accept a visitor.
1297 * Calls the method for this class on the visitor.
1298 * @param pVisitor
1299 * @return
1301 void Accept(SmVisitor* pVisitor) override;
1304 * Returns the node containing the data of the order of the root.
1305 * @return order data
1307 const SmNode* Argument() const { return const_cast<SmRootNode *>(this)->Argument(); }
1308 SmNode* Argument() { assert( GetNumSubNodes() == 3 ); return GetSubNode( 0 ); }
1311 * Returns the node containing the data of the character used for the root.
1312 * @return symbol data
1314 const SmRootSymbolNode* Symbol() const { return const_cast<SmRootNode *>(this)->Symbol(); }
1315 SmRootSymbolNode* Symbol() { assert( GetNumSubNodes() == 3 );
1316 assert( GetSubNode( 1 )->GetType()
1317 == SmNodeType::RootSymbol );
1318 return static_cast< SmRootSymbolNode* >
1319 ( GetSubNode( 1 )); }
1322 * Returns the node containing the data inside the root.
1323 * @return body data
1325 const SmNode* Body() const { return const_cast<SmRootNode *>(this)->Body(); }
1326 SmNode* Body() { assert( GetNumSubNodes() == 3 ); return GetSubNode( 2 ); }
1331 /** Binary horizontal node
1333 * This node is used for binary operators. In a formula such as "A + B".
1335 * Children:<BR>
1336 * 0: Left operand<BR>
1337 * 1: Binary operator<BR>
1338 * 2: Right operand<BR>
1340 * None of the children may be NULL.
1342 class SmBinHorNode final : public SmStructureNode
1344 public:
1345 explicit SmBinHorNode(const SmToken &rNodeToken)
1346 : SmStructureNode(SmNodeType::BinHor, rNodeToken, 3) { }
1349 * Prepares the SmRect to render.
1350 * @param rDev
1351 * @param rFormat
1352 * @return
1354 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1357 * Accept a visitor.
1358 * Calls the method for this class on the visitor.
1359 * @param pVisitor
1360 * @return
1362 void Accept(SmVisitor* pVisitor) override;
1365 * Returns the node containing the data of the binary operator.
1366 * @return symbol data
1368 const SmNode* Symbol() const { return const_cast<SmBinHorNode *>(this)->Symbol(); }
1369 SmNode* Symbol() { assert( GetNumSubNodes() == 3 ); return GetSubNode( 1 ); }
1372 * Returns the node containing the data of the left operand.
1373 * @return left operand data
1375 const SmNode* LeftOperand() const { return const_cast<SmBinHorNode *>(this)->LeftOperand(); }
1376 SmNode* LeftOperand() { assert( GetNumSubNodes() == 3 ); return GetSubNode( 0 ); }
1379 * Returns the node containing the data of the right operand.
1380 * @return right operand data
1382 const SmNode* RightOperand() const { return const_cast<SmBinHorNode *>(this)->RightOperand(); }
1383 SmNode* RightOperand() { assert( GetNumSubNodes() == 3 ); return GetSubNode( 2 ); }
1387 /** Binary horizontal node
1389 * This node is used for creating the OVER command, consider the formula:
1390 * "numerator OVER denominator", which looks like
1391 * \f$ \frac{\mbox{numerator}}{\mbox{denominator}} \f$
1393 * Children:<BR>
1394 * 0: Numerator<BR>
1395 * 1: Line (instance of SmRectangleNode)<BR>
1396 * 2: Denominator<BR>
1397 * None of the children may be NULL.
1399 class SmBinVerNode final : public SmStructureNode
1401 public:
1402 explicit SmBinVerNode(const SmToken &rNodeToken)
1403 : SmStructureNode(SmNodeType::BinVer, rNodeToken, 3) { }
1405 virtual const SmNode * GetLeftMost() const override;
1408 * Prepares the SmRect to render.
1409 * @param rDev
1410 * @param rFormat
1411 * @return
1413 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1416 * Accept a visitor.
1417 * Calls the method for this class on the visitor.
1418 * @param pVisitor
1419 * @return
1421 void Accept(SmVisitor* pVisitor) override;
1425 /** Binary diagonal node
1427 * Used for implementing the WIDESLASH command, example: "A WIDESLASH B".
1429 * Children:<BR>
1430 * 0: Left operand<BR>
1431 * 1: right operand<BR>
1432 * 2: Line (instance of SmPolyLineNode).<BR>
1433 * None of the children may be NULL.
1435 class SmBinDiagonalNode final : public SmStructureNode
1437 bool mbAscending;
1440 * Returns the position and size of the diagonal line by reference.
1441 * @param rPos
1442 * @param rSize
1443 * @param rDiagPoint
1444 * @param fAngleDeg
1445 * @return position and size of the diagonal line
1447 void GetOperPosSize(Point &rPos, Size &rSize, const Point &rDiagPoint, double fAngleDeg) const;
1449 public:
1450 explicit SmBinDiagonalNode(const SmToken &rNodeToken)
1451 : SmStructureNode(SmNodeType::BinDiagonal, rNodeToken, 3)
1452 , mbAscending(false) { }
1455 * Checks if it is of ascending type.
1456 * Ascending:
1457 * / b
1459 * a /
1460 * Descending:
1461 * a \
1463 * \ b
1464 * @return ascending.
1466 bool IsAscending() const { return mbAscending; }
1469 * Sets if the wideslash is ascending to bVal.
1470 * @param bVal
1471 * @return
1473 void SetAscending(bool bVal) { mbAscending = bVal; }
1476 * Prepares the SmRect to render.
1477 * @param rDev
1478 * @param rFormat
1479 * @return
1481 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1484 * Accept a visitor.
1485 * Calls the method for this class on the visitor.
1486 * @param pVisitor
1487 * @return
1489 void Accept(SmVisitor* pVisitor) override;
1493 /** Enum used to index sub-/supscripts in the 'maSubNodes' array
1494 * in 'SmSubSupNode'
1496 * See graphic for positions at char:
1498 * \code
1499 * CSUP
1501 * LSUP H H RSUP
1502 * H H
1503 * HHHH
1504 * H H
1505 * LSUB H H RSUB
1507 * CSUB
1508 * \endcode
1510 enum SmSubSup
1511 { CSUB, CSUP, RSUB, RSUP, LSUB, LSUP
1514 /** numbers of entries in the above enum (that is: the number of possible
1515 * sub-/supscripts)
1517 #define SUBSUP_NUM_ENTRIES 6
1519 /** Super- and subscript node
1521 * Used for creating super- and subscripts for commands such as:
1522 * "^", "_", "lsup", "lsub", "csup" and "csub".
1523 * Example: "A^2" which looks like: \f$ A^2 \f$
1525 * This node is also used for creating limits on SmOperNode, when
1526 * "FROM" and "TO" commands are used with "INT", "SUM" or similar.
1528 * Children of this node can be enumerated using the SmSubSup enum.
1529 * Please note that children may be NULL, except for the body.
1530 * It is recommended that you access children using GetBody() and
1531 * GetSubSup().
1533 class SmSubSupNode final : public SmStructureNode
1535 bool mbUseLimits;
1537 public:
1538 explicit SmSubSupNode(const SmToken &rNodeToken)
1539 : SmStructureNode(SmNodeType::SubSup, rNodeToken, 1 + SUBSUP_NUM_ENTRIES)
1540 , mbUseLimits(false) { }
1543 * Returns the node with the data of what has to be superindex or subindex.
1544 * @return body data
1546 const SmNode * GetBody() const { return const_cast<SmSubSupNode *>(this)->GetBody(); }
1547 SmNode * GetBody() { return GetSubNode(0); }
1550 * Checks if it is going to be used for a limit.
1551 * Example lim from { x toward 0 } { {sin x}over x } = 1
1552 * @return is a limit
1554 bool IsUseLimits() const { return mbUseLimits; };
1557 * Sets if it is going to be used for a limit to bVal.
1558 * @param bVal
1559 * @return
1561 void SetUseLimits(bool bVal) { mbUseLimits = bVal; }
1564 * Gets the node with the data of what has to be superindex or subindex.
1565 * The position to check is given by eSubSup.
1566 * @remarks this method may return NULL.
1567 * @param eSubSup
1568 * @return body data
1570 const SmNode * GetSubSup(SmSubSup eSubSup) const { return const_cast< SmSubSupNode* >
1571 ( this )->GetSubSup( eSubSup ); }
1572 SmNode * GetSubSup(SmSubSup eSubSup) { return GetSubNode(1 + eSubSup); };
1575 * Sets the node with the data of what has to be superindex or subindex.
1576 * @param pScript
1578 void SetBody(SmNode* pBody) { SetSubNode(0, pBody); }
1581 * Sets the node with the data of what has to be superindex or subindex.
1582 * The position to check is given by eSubSup.
1583 * @param eSubSup
1584 * @param pScript
1586 void SetSubSup(SmSubSup eSubSup, SmNode* pScript) { SetSubNode( 1 + eSubSup, pScript); }
1589 * Prepares the SmRect to render.
1590 * @param rDev
1591 * @param rFormat
1592 * @return
1594 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1597 * Accept a visitor.
1598 * Calls the method for this class on the visitor.
1599 * @param pVisitor
1600 * @return
1602 void Accept(SmVisitor* pVisitor) override;
1607 /** Node for brace construction
1609 * Used for "lbrace [body] rbrace" and similar constructions.
1610 * Should look like \f$ \{\mbox{[body]}\} \f$
1612 * Children:<BR>
1613 * 0: Opening brace<BR>
1614 * 1: Body (usually SmBracebodyNode)<BR>
1615 * 2: Closing brace<BR>
1616 * None of the children can be NULL.
1618 * Note that child 1 (Body) is usually SmBracebodyNode, but it can also be e.g. SmExpressionNode.
1620 class SmBraceNode final : public SmStructureNode
1622 public:
1623 explicit SmBraceNode(const SmToken &rNodeToken)
1624 : SmStructureNode(SmNodeType::Brace, rNodeToken, 3) { }
1627 * Returns the node containing the data of the opening brace.
1628 * @return opening brace data
1630 const SmMathSymbolNode* OpeningBrace() const { return const_cast<SmBraceNode *>
1631 (this)->OpeningBrace(); }
1632 SmMathSymbolNode* OpeningBrace() { assert( GetNumSubNodes() == 3 );
1633 assert( GetSubNode( 0 )->GetType()
1634 == SmNodeType::Math );
1635 return static_cast< SmMathSymbolNode* >
1636 ( GetSubNode( 0 )); }
1639 * Returns the node containing the data of what is between braces.
1640 * @return body data
1642 const SmNode* Body() const { return const_cast<SmBraceNode *>(this)->Body(); }
1643 SmNode* Body() { assert( GetNumSubNodes() == 3 ); return GetSubNode( 1 ); }
1646 * Returns the node containing the data of the closing brace.
1647 * @return closing brace data
1649 const SmMathSymbolNode* ClosingBrace() const { return const_cast<SmBraceNode *>
1650 (this)->ClosingBrace(); }
1651 SmMathSymbolNode* ClosingBrace() { assert( GetNumSubNodes() == 3 );
1652 assert( GetSubNode( 2 )->GetType()
1653 == SmNodeType::Math );
1654 return static_cast< SmMathSymbolNode* >
1655 ( GetSubNode( 2 )); }
1658 * Prepares the SmRect to render.
1659 * @param rDev
1660 * @param rFormat
1661 * @return
1663 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1666 * Accept a visitor.
1667 * Calls the method for this class on the visitor.
1668 * @param pVisitor
1669 * @return
1671 void Accept(SmVisitor* pVisitor) override;
1675 /** Body of an SmBraceNode
1677 * This usually only has one child an SmExpressionNode, however, it can also
1678 * have other children.
1679 * Consider the formula "lbrace [body1] mline [body2] rbrace", looks like:
1680 * \f$ \{\mbox{[body1] | [body2]}\} \f$.
1681 * In this case SmBracebodyNode will have three children, "[body1]", "|" and
1682 * [body2].
1684 class SmBracebodyNode final : public SmStructureNode
1686 tools::Long mnBodyHeight;
1688 public:
1689 explicit SmBracebodyNode(const SmToken &rNodeToken)
1690 : SmStructureNode(SmNodeType::Bracebody, rNodeToken)
1691 , mnBodyHeight(0) { }
1694 * Prepares the SmRect to render.
1695 * @param rDev
1696 * @param rFormat
1697 * @return
1699 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1700 tools::Long GetBodyHeight() const { return mnBodyHeight; }
1703 * Accept a visitor.
1704 * Calls the method for this class on the visitor.
1705 * @param pVisitor
1706 * @return
1708 void Accept(SmVisitor* pVisitor) override;
1712 /** Node for vertical brace construction
1714 * Used to implement commands "[body] underbrace [script]" and
1715 * "[body] overbrace [script]".
1716 * Underbrace should look like this \f$ \underbrace{\mbox{body}}_{\mbox{script}}\f$.
1718 * Children:<BR>
1719 * 0: body<BR>
1720 * 1: brace<BR>
1721 * 2: script<BR>
1722 * (None of these children are optional, e.g. they must all be not NULL).
1724 class SmVerticalBraceNode final : public SmStructureNode
1726 public:
1727 explicit SmVerticalBraceNode(const SmToken &rNodeToken)
1728 : SmStructureNode(SmNodeType::VerticalBrace, rNodeToken, 3) { }
1731 * Returns the node containing the data of what the brace is pointing for.
1732 * body { script }
1733 * @return body data
1735 const SmNode* Body() const { return const_cast<SmVerticalBraceNode *>(this)->Body(); }
1736 SmNode* Body() { assert( GetNumSubNodes() == 3 ); return GetSubNode( 0 ); }
1739 * Returns the node containing the data of the brace.
1740 * @return brace data
1742 const SmMathSymbolNode* Brace() const { return const_cast<SmVerticalBraceNode *>
1743 (this)->Brace(); }
1744 SmMathSymbolNode* Brace() { assert( GetNumSubNodes() == 3 );
1745 assert( GetSubNode( 1 )->GetType()
1746 == SmNodeType::Math );
1747 return static_cast< SmMathSymbolNode* >
1748 ( GetSubNode( 1 )); }
1751 * Returns the node containing the data of what is in the brace.
1752 * body { script }
1753 * @return opening brace data
1755 const SmNode* Script() const { return const_cast<SmVerticalBraceNode *>(this)->Script(); }
1756 SmNode* Script() { assert( GetNumSubNodes() == 3 ); return GetSubNode( 2 ); }
1759 * Prepares the SmRect to render.
1760 * @param rDev
1761 * @param rFormat
1762 * @return
1764 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1767 * Accept a visitor.
1768 * Calls the method for this class on the visitor.
1769 * @param pVisitor
1770 * @return
1772 void Accept(SmVisitor* pVisitor) override;
1775 /** Operation Node
1777 * Used for commands like SUM, INT and similar.
1779 * Children:<BR>
1780 * 0: Operation (instance of SmMathSymbolNode or SmSubSupNode)<BR>
1781 * 1: Body<BR>
1782 * None of the children may be NULL.
1785 class SmOperNode final : public SmStructureNode
1787 public:
1788 explicit SmOperNode(const SmToken &rNodeToken)
1789 : SmStructureNode(SmNodeType::Oper, rNodeToken, 2) { }
1792 * Returns the node with the operator data
1793 * @return operator data
1795 const SmNode * GetSymbol() const { return const_cast<SmOperNode *>(this)->GetSymbol(); }
1796 SmNode * GetSymbol();
1799 * Returns the height of the node in base to the symbol
1800 * ( rSymbol contains the operator data )
1801 * and the font format ( rFormat ).
1802 * @param rSymbol
1803 * @param rFormat
1804 * @return node's height
1806 tools::Long CalcSymbolHeight(const SmNode &rSymbol, const SmFormat &rFormat) const;
1809 * Prepares the SmRect to render.
1810 * @param rDev
1811 * @param rFormat
1812 * @return
1814 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1817 * Accept a visitor.
1818 * Calls the method for this class on the visitor.
1819 * @param pVisitor
1820 * @return
1822 void Accept(SmVisitor* pVisitor) override;
1826 /** Node used for alignment
1828 * This node has exactly one child at index 0.
1830 class SmAlignNode final : public SmStructureNode
1832 public:
1833 explicit SmAlignNode(const SmToken &rNodeToken)
1834 : SmStructureNode(SmNodeType::Align, rNodeToken) { }
1837 * Prepares the SmRect to render.
1838 * @param rDev
1839 * @param rFormat
1840 * @return
1842 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1845 * Accept a visitor.
1846 * Calls the method for this class on the visitor.
1847 * @param pVisitor
1848 * @return
1850 void Accept(SmVisitor* pVisitor) override;
1854 /** Attribute node
1856 * Used to give an attribute to another node. Used for commands such as:
1857 * UNDERLINE, OVERLINE, OVERSTRIKE, WIDEVEC, WIDEHARPOON, WIDEHAT and WIDETILDE.
1859 * Children:<BR>
1860 * 0: Attribute<BR>
1861 * 1: Body<BR>
1862 * None of these may be NULL.
1864 class SmAttributNode final : public SmStructureNode
1866 public:
1867 explicit SmAttributNode(const SmToken &rNodeToken)
1868 : SmStructureNode(SmNodeType::Attribut, rNodeToken, 2) {}
1871 * Prepares the SmRect to render.
1872 * @param rDev
1873 * @param rFormat
1874 * @return
1876 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1879 * Accept a visitor.
1880 * Calls the method for this class on the visitor.
1881 * @param pVisitor
1882 * @return
1884 void Accept(SmVisitor* pVisitor) override;
1887 * Gets the attribute data.
1888 * @return attribute data
1890 const SmNode* Attribute() const { return const_cast<SmAttributNode *>(this)->Attribute(); }
1891 SmNode* Attribute() { assert( GetNumSubNodes() == 2 ); return GetSubNode( 0 ); }
1894 * Gets the body data ( the nodes affected by the attribute ).
1895 * @return body data
1897 const SmNode* Body() const { return const_cast<SmAttributNode *>(this)->Body(); }
1898 SmNode* Body() { assert( GetNumSubNodes() == 2 ); return GetSubNode( 1 ); }
1902 /** Font node
1904 * Used to change the font of its children.
1906 class SmFontNode final : public SmStructureNode
1908 FontSizeType meSizeType;
1909 Fraction maFontSize;
1911 public:
1912 explicit SmFontNode(const SmToken &rNodeToken)
1913 : SmStructureNode(SmNodeType::Font, rNodeToken)
1914 , meSizeType(FontSizeType::MULTIPLY)
1915 , maFontSize(1) { }
1918 * Sets font size to rValue in nType mode.
1919 * Check FontSizeType for details.
1920 * @param rValue
1921 * @param nType
1922 * @return
1924 void SetSizeParameter(const Fraction &rValue, FontSizeType nType)
1925 { meSizeType = nType; maFontSize = rValue; }
1928 * Returns the font size.
1929 * @return font size.
1931 const Fraction & GetSizeParameter() const {return maFontSize;}
1934 * Returns the font size type.
1935 * Check FontSizeType for details.
1936 * @return font size type.
1938 FontSizeType GetSizeType() const {return meSizeType;}
1941 * Prepare preliminary settings about font and text
1942 * (e.g. maFace, meRectHorAlign, mnFlags, mnAttributes, etc.)
1943 * @param rFormat
1944 * @param rDocShell
1945 * @param nDepth
1946 * @return
1948 virtual void Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell,
1949 int nDepth) override;
1952 * Prepares the SmRect to render.
1953 * @param rDev
1954 * @param rFormat
1955 * @return
1957 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1960 * Accept a visitor.
1961 * Calls the method for this class on the visitor.
1962 * @param pVisitor
1963 * @return
1965 void Accept(SmVisitor* pVisitor) override;
1969 /** Matrix node
1971 * Used to implement the MATRIX command, example:
1972 * "matrix{ 1 # 2 ## 3 # 4}".
1974 class SmMatrixNode final : public SmStructureNode
1976 sal_uInt16 mnNumRows,
1977 mnNumCols;
1979 public:
1980 explicit SmMatrixNode(const SmToken &rNodeToken)
1981 : SmStructureNode(SmNodeType::Matrix, rNodeToken)
1982 , mnNumRows(0)
1983 , mnNumCols(0) { }
1986 * Gets the number of rows of the matrix.
1987 * @return rows number
1989 sal_uInt16 GetNumRows() const {return mnNumRows;}
1992 * Gets the number of columns of the matrix.
1993 * @return columns number
1995 sal_uInt16 GetNumCols() const {return mnNumCols;}
1998 * Sets the dimensions of the matrix.
1999 * @param nMatrixRows
2000 * @param nMatrixCols
2001 * @return
2003 void SetRowCol(sal_uInt16 nMatrixRows, sal_uInt16 nMatrixCols)
2004 { mnNumRows = nMatrixRows; mnNumCols = nMatrixCols; }
2006 virtual const SmNode * GetLeftMost() const override;
2009 * Prepares the SmRect to render.
2010 * @param rDev
2011 * @param rFormat
2012 * @return
2014 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
2017 * Accept a visitor.
2018 * Calls the method for this class on the visitor.
2019 * @param pVisitor
2020 * @return
2022 void Accept(SmVisitor* pVisitor) override;
2026 /** Node for whitespace
2028 * Used to implement the commands "~" and "`". This node is just a blank space.
2030 class SmBlankNode final : public SmGraphicNode
2032 sal_uInt16 mnNum;
2034 public:
2035 explicit SmBlankNode(const SmToken &rNodeToken)
2036 : SmGraphicNode(SmNodeType::Blank, rNodeToken)
2037 , mnNum(0) { }
2039 void IncreaseBy(const SmToken &rToken, sal_uInt32 nMultiplyBy = 1);
2040 void Clear() { mnNum = 0; }
2041 sal_uInt16 GetBlankNum() const { return mnNum; }
2042 void SetBlankNum(sal_uInt16 nNumber) { mnNum = nNumber; }
2045 * Prepare preliminary settings about font and text
2046 * (e.g. maFace, meRectHorAlign, mnFlags, mnAttributes, etc.)
2047 * @param rFormat
2048 * @param rDocShell
2049 * @param nDepth
2050 * @return
2052 virtual void Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell,
2053 int nDepth) override;
2056 * Prepares the SmRect to render.
2057 * @param rDev
2058 * @param rFormat
2059 * @return
2061 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
2064 * Accept a visitor.
2065 * Calls the method for this class on the visitor.
2066 * @param pVisitor
2067 * @return
2069 void Accept(SmVisitor* pVisitor) override;
2073 #endif
2076 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */