LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / starmath / inc / node.hxx
blob427966279dd67b987f45792aa17fac1ee6eb5a20
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 * SmAttributeNode 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 #pragma once
64 #include "types.hxx"
65 #include "token.hxx"
66 #include "rect.hxx"
67 #include "format.hxx"
68 #include "nodetype.hxx"
70 #include <editeng/editdata.hxx>
72 enum class FontAttribute {
73 None = 0x0000,
74 Bold = 0x0001,
75 Italic = 0x0002
78 namespace o3tl
80 template<> struct typed_flags<FontAttribute> : is_typed_flags<FontAttribute, 0x0003> {};
84 enum class FontSizeType {
85 ABSOLUT = 1,
86 PLUS = 2,
87 MINUS = 3,
88 MULTIPLY = 4,
89 DIVIDE = 5
92 // flags to interdict respective status changes
93 enum class FontChangeMask {
94 None = 0x0000,
95 Face = 0x0001,
96 Size = 0x0002,
97 Bold = 0x0004,
98 Italic = 0x0008,
99 Color = 0x0010,
100 Phantom = 0x0020
103 namespace o3tl
105 template<> struct typed_flags<FontChangeMask> : is_typed_flags<FontChangeMask, 0x003f> {};
109 class SmVisitor;
110 class SmDocShell;
111 class SmNode;
112 class SmStructureNode;
114 typedef std::vector< SmNode * > SmNodeArray;
116 enum class SmScaleMode
118 None,
119 Width,
120 Height
123 class SmNode : public SmRect
125 // Rendering info for SmRect
126 SmFace maFace;
127 // Anclage to the code
128 SmToken maNodeToken;
129 ESelection m_aESelection;
130 // Node information
131 SmNodeType meType;
132 SmScaleMode meScaleMode;
133 RectHorAlign meRectHorAlign;
134 FontChangeMask mnFlags;
135 FontAttribute mnAttributes;
136 bool mbIsPhantom;
137 bool mbIsSelected;
138 // index in accessible text; -1 if not (yet) applicable
139 sal_Int32 mnAccIndex;
141 protected:
142 SmNode(SmNodeType eNodeType, const SmToken &rNodeToken);
144 public:
145 SmNode(const SmNode&) = delete;
146 SmNode& operator=(const SmNode&) = delete;
148 virtual ~SmNode();
151 * Checks node visibility.
152 * Returns true if this is an instance of SmVisibleNode's subclass, false otherwise.
153 * @return node visibility
155 virtual bool IsVisible() const = 0;
158 * Gets the number of subnodes.
159 * @return number of subnodes
161 virtual size_t GetNumSubNodes() const = 0;
164 * Gets the subnode of index nIndex.
165 * @param nIndex
166 * @return subnode of index nIndex
168 virtual SmNode * GetSubNode(size_t nIndex) = 0;
169 const SmNode * GetSubNode(size_t nIndex) const
170 { return const_cast<SmNode *>(this)->GetSubNode(nIndex); }
172 virtual const SmNode * GetLeftMost() const;
175 * Gets the FontChangeMask flags.
176 * @return FontChangeMask flags
178 FontChangeMask &Flags() { return mnFlags; }
181 * Gets the font attributes.
182 * @return font attributes
184 FontAttribute &Attributes() { return mnAttributes; }
187 * Checks if it is a visible node rendered invisible.
188 * @return rendered visibility
190 bool IsPhantom() const { return mbIsPhantom; }
193 * Sets the render visibility of a visible node to bIsPhantom.
194 * @param bIsPhantom
195 * @return
197 void SetPhantom(bool bIsPhantom);
200 * Sets the font color.
201 * @param rColor
202 * @return
204 void SetColor(const Color &rColor);
207 * Sets the font attribute nAttrib.
208 * Check FontAttribute class.
209 * @param nAttrib
210 * @return
212 void SetAttribute(FontAttribute nAttrib);
215 * Clears the font attribute nAttrib.
216 * Check FontAttribute class.
217 * @param nAttrib
218 * @return
220 void ClearAttribute(FontAttribute nAttrib);
223 * Gets the font.
224 * @return font
226 const SmFace & GetFont() const { return maFace; };
227 SmFace & GetFont() { return maFace; };
230 * Sets the font to rFace.
231 * @param rFace
232 * @return
234 void SetFont(const SmFace &rFace);
237 * Sets the font size to rRelSize with type nType.
238 * Check FontSizeType for details.
239 * @param rRelSize
240 * @param nType
241 * @return
243 void SetFontSize(const Fraction &rRelSize, FontSizeType nType);
246 * Sets the font size to rRelSize with type FontSizeType::ABSOLUT.
247 * @param rScale
248 * @return
250 void SetSize(const Fraction &rScale);
253 * Prepare preliminary settings about font and text
254 * (e.g. maFace, meRectHorAlign, mnFlags, mnAttributes, etc.)
255 * @param rFormat
256 * @param rDocShell
257 * @param nDepth
258 * @return
260 virtual void Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell, int nDepth);
263 * Prepare preliminary font attributes
264 * Called on Prepare(...).
265 * @return
267 void PrepareAttributes();
270 * Sets the alignment of the text.
271 * Check RectHorAlign class for details.
272 * The subtrees will be affected if bApplyToSubTree.
273 * @param eHorAlign
274 * @param bApplyToSubTree
275 * @return
277 void SetRectHorAlign(RectHorAlign eHorAlign, bool bApplyToSubTree = true );
280 * Gets the alignment of the text.
281 * @return alignment of the text
283 RectHorAlign GetRectHorAlign() const { return meRectHorAlign; }
286 * Parses itself to SmRect.
287 * @return this
289 const SmRect & GetRect() const { return *this; }
292 * Moves the rectangle by rVector.
293 * @param rVector
294 * @return
296 void Move(const Point &rVector);
299 * Moves the rectangle to rPoint, being the top left corner the origin.
300 * @param rPoint
301 * @return
303 void MoveTo(const Point &rPoint) { Move(rPoint - GetTopLeft()); }
306 * Prepares the SmRect to render.
307 * @param rDev
308 * @param rFormat
309 * @return
311 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) = 0;
314 * Appends to rText the node text.
315 * @param rText
316 * @return
318 virtual void GetAccessibleText( OUStringBuffer &rText ) const = 0;
321 * Gets the node accessible index.
322 * Used for visual editing.
323 * @return node accessible index
325 sal_Int32 GetAccessibleIndex() const { return mnAccIndex; }
328 * Sets the node accessible index to nAccIndex.
329 * Used for visual editing.
330 * @param nAccIndex
331 * @return
333 void SetAccessibleIndex(sal_Int32 nAccIndex) { mnAccIndex = nAccIndex; }
336 * Finds the node with accessible index nAccIndex.
337 * Used for visual editing.
338 * @param nAccIndex
339 * @return node with accessible index nAccIndex
341 const SmNode * FindNodeWithAccessibleIndex(sal_Int32 nAccIndex) const;
344 * Gets the line in the text where the node is located.
345 * It is used to do the visual <-> text correspondence.
346 * @return line
348 sal_uInt16 GetRow() const { return sal::static_int_cast<sal_uInt16>(m_aESelection.nStartPara); }
351 * Gets the column of the line in the text where the node is located.
352 * It is used to do the visual <-> text correspondence.
353 * @return column
355 sal_uInt16 GetColumn() const { return sal::static_int_cast<sal_uInt16>(m_aESelection.nStartPos); }
358 * Gets the scale mode.
359 * @return scale mode
361 SmScaleMode GetScaleMode() const { return meScaleMode; }
364 * Sets the scale mode to eMode.
365 * @param eMode
366 * @return
368 void SetScaleMode(SmScaleMode eMode) { meScaleMode = eMode; }
370 //visual stuff TODO comment
371 virtual void AdaptToX(OutputDevice &rDev, sal_uLong nWidth);
372 virtual void AdaptToY(OutputDevice &rDev, sal_uLong nHeight);
375 * Gets the node type.
376 * @return node type
378 SmNodeType GetType() const { return meType; }
381 * Gets the token.
382 * The token contains the data extracted from the text mode.
383 * Ej: text, type (sub, sup, int,...), row and column,...
384 * @return node type
386 const SmToken & GetToken() const { return maNodeToken; }
387 SmToken & GetToken() { return maNodeToken; }
390 * Gets node position in input text.
391 * @return node position in input text
393 const ESelection& GetSelection() const { return m_aESelection; }
396 * Gets node position in input text.
397 * @param aESelection
399 void SetSelection(ESelection aESelection) { m_aESelection = aESelection; }
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 * Gets the subnode of index nIndex, used for operators.
504 * @param nIndex
505 * @return subnode of index nIndex
507 SmNode * GetSubNodeBinMo(size_t nIndex) const;
510 * Does the cleaning of the subnodes.
511 * @return
513 void ClearSubNodes();
516 * Sets subnodes, used for operators.
517 * @param pFirst
518 * @param pSecond
519 * @param pThird
520 * @return
522 void SetSubNodes(std::unique_ptr<SmNode> pFirst, std::unique_ptr<SmNode> pSecond,
523 std::unique_ptr<SmNode> pThird = nullptr);
526 * Sets subnodes.
527 * @param pFirst
528 * @param pSecond
529 * @param pThird
530 * @return
532 void SetSubNodes(SmNode* pFirst, SmNode* pSecond, SmNode* pThird);
535 * Sets subnodes, used for operators.
536 * The data is reordered so the items are correctly ordered.
537 * @param pFirst
538 * @param pSecond
539 * @param pThird
540 * @return
542 void SetSubNodesBinMo(std::unique_ptr<SmNode> pFirst, std::unique_ptr<SmNode> pSecond,
543 std::unique_ptr<SmNode> pThird = nullptr);
546 * Sets subnodes, used for operators.
547 * The data is reordered so the items are correctly ordered.
548 * @param pFirst
549 * @param pSecond
550 * @param pThird
551 * @return
553 void SetSubNodesBinMo(SmNode* pFirst, SmNode* pSecond, SmNode* pThird);
556 * Sets subnodes.
557 * @param rNodeArray
558 * @return
560 void SetSubNodes(SmNodeArray&& rNodeArray);
563 * Appends to rText the node text.
564 * @param rText
565 * @return
567 virtual void GetAccessibleText( OUStringBuffer &rText ) const override;
570 * Gets the first subnode.
571 * @return first subnode
573 SmNodeArray::iterator begin() {return maSubNodes.begin();}
576 * Gets the last subnode.
577 * @return last subnode
579 SmNodeArray::iterator end() {return maSubNodes.end();}
582 * Gets the last subnode.
583 * @return last subnode
585 SmNodeArray::reverse_iterator rbegin() {return maSubNodes.rbegin();}
588 * Gets the first subnode.
589 * @return first subnode
591 SmNodeArray::reverse_iterator rend() {return maSubNodes.rend();}
594 * Get the index of the child node pSubNode.
595 * Returns -1, if pSubNode isn't a subnode of this.
596 * @param pSubNode
597 * @return index of the child node
599 int IndexOfSubNode(SmNode const * pSubNode);
602 * Sets the subnode pNode at nIndex.
603 * If necessary increases the subnodes length.
604 * @param nIndex
605 * @param pNode
606 * @return
608 void SetSubNode(size_t nIndex, SmNode* pNode);
610 private:
611 /** Sets parent on children of this node */
612 void ClaimPaternity();
616 /** Abstract base class for all visible node
618 * Nodes that doesn't derivate from this class doesn't draw anything, but their
619 * children.
621 class SmVisibleNode : public SmNode
623 protected:
624 SmVisibleNode(SmNodeType eNodeType, const SmToken &rNodeToken)
625 : SmNode(eNodeType, rNodeToken) {}
627 public:
630 * Checks node visibility.
631 * Returns true if this is an instance of SmVisibleNode's subclass, false otherwise.
632 * @return node visibility
634 virtual bool IsVisible() const override;
637 * Gets the number of subnodes.
638 * @return number of subnodes
640 virtual size_t GetNumSubNodes() const override;
643 * Gets the subnode of index nIndex.
644 * @param nIndex
645 * @return subnode of index nIndex
647 using SmNode::GetSubNode;
648 virtual SmNode * GetSubNode(size_t nIndex) override;
652 class SmGraphicNode : public SmVisibleNode
654 protected:
655 SmGraphicNode(SmNodeType eNodeType, const SmToken &rNodeToken)
656 : SmVisibleNode(eNodeType, rNodeToken) {}
658 public:
661 * Appends to rText the node text.
662 * @param rText
663 * @return
665 virtual void GetAccessibleText( OUStringBuffer &rText ) const override;
669 /** Draws a rectangle
671 * Used for drawing the line in the OVER and OVERSTRIKE commands.
673 class SmRectangleNode final : public SmGraphicNode
675 Size maToSize;
677 public:
678 explicit SmRectangleNode(const SmToken &rNodeToken)
679 : SmGraphicNode(SmNodeType::Rectangle, rNodeToken)
682 //visual stuff TODO comment
683 virtual void AdaptToX(OutputDevice &rDev, sal_uLong nWidth) override;
684 virtual void AdaptToY(OutputDevice &rDev, sal_uLong nHeight) override;
687 * Prepares the SmRect to render.
688 * @param rDev
689 * @param rFormat
690 * @return
692 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
695 * Accept a visitor.
696 * Calls the method for this class on the visitor.
697 * @param pVisitor
698 * @return
700 void Accept(SmVisitor* pVisitor) override;
704 /** Polygon line node
706 * Used to draw the slash of the WIDESLASH command by SmBinDiagonalNode.
708 class SmPolyLineNode final : public SmGraphicNode
710 tools::Polygon maPoly;
711 Size maToSize;
712 tools::Long mnWidth;
714 public:
715 explicit SmPolyLineNode(const SmToken &rNodeToken);
718 * Gets the width of the rect.
719 * @return width
721 tools::Long GetWidth() const { return mnWidth; }
724 * Gets the polygon to draw the node.
725 * @return polygon
727 tools::Polygon &GetPolygon() { return maPoly; }
729 //visual stuff TODO comment
730 virtual void AdaptToX(OutputDevice &rDev, sal_uLong nWidth) override;
731 virtual void AdaptToY(OutputDevice &rDev, sal_uLong nHeight) override;
734 * Prepares the SmRect to render.
735 * @param rDev
736 * @param rFormat
737 * @return
739 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
742 * Accept a visitor.
743 * Calls the method for this class on the visitor.
744 * @param pVisitor
745 * @return
747 void Accept(SmVisitor* pVisitor) override;
751 /** Text node
753 * @remarks This class also serves as baseclass for all nodes that contains text.
755 class SmTextNode : public SmVisibleNode
758 protected:
759 OUString maText;
760 sal_uInt16 mnFontDesc;
761 /** Index within text where the selection starts
762 * @remarks Only valid if SmNode::IsSelected() is true
764 sal_Int32 mnSelectionStart;
765 /** Index within text where the selection ends
766 * @remarks Only valid if SmNode::IsSelected() is true
768 sal_Int32 mnSelectionEnd;
770 protected:
771 SmTextNode(SmNodeType eNodeType, const SmToken &rNodeToken, sal_uInt16 nFontDescP );
773 public:
774 SmTextNode(const SmToken &rNodeToken, sal_uInt16 nFontDescP );
777 * Returns the font type being used (text, variable, symbol, ...).
778 * @return font type
780 sal_uInt16 GetFontDesc() const { return mnFontDesc; }
783 * Sets the node text to rText.
784 * @param rText
785 * @return
787 void SetText(const OUString &rText) { maText = rText; }
790 * Gets the node text.
791 * @return node text
793 const OUString & GetText() const { return maText; }
794 OUString & GetText() { return maText; }
797 * Change the text of this node, including the underlying token to rText.
798 * @param rText
799 * @return
801 void ChangeText(const OUString &rText);
804 * Try to guess the correct FontDesc, used during visual editing
805 * @return
807 void AdjustFontDesc();
810 * Index within GetText() where the selection starts.
811 * @remarks Only valid of SmNode::IsSelected() is true.
812 * @return index.
814 sal_Int32 GetSelectionStart() const { return mnSelectionStart; }
817 * Index within GetText() where the selection ends.
818 * @remarks Only valid of SmNode::IsSelected() is true.
819 * @return index.
821 sal_Int32 GetSelectionEnd() const {return mnSelectionEnd; }
824 * Sets the index within GetText() where the selection starts to index.
825 * @param index
826 * @return
828 void SetSelectionStart(sal_Int32 index) {mnSelectionStart = index;}
831 * Sets the index within GetText() where the selection ends to index.
832 * @param index
833 * @return
835 void SetSelectionEnd(sal_Int32 index) {mnSelectionEnd = index;}
838 * Prepare preliminary settings about font and text
839 * (e.g. maFace, meRectHorAlign, mnFlags, mnAttributes, etc.)
840 * @param rFormat
841 * @param rDocShell
842 * @param nDepth
843 * @return
845 virtual void Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell,
846 int nDepth) override;
849 * Prepares the SmRect to render.
850 * @param rDev
851 * @param rFormat
852 * @return
854 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
857 * Appends to rText the node text.
858 * @param rText
859 * @return
861 virtual void GetAccessibleText( OUStringBuffer &rText ) const override;
864 * Accept a visitor.
865 * Calls the method for this class on the visitor.
866 * @param pVisitor
867 * @return
869 void Accept(SmVisitor* pVisitor) override;
872 * Converts the character from StarMath's private area symbols to a matching Unicode
873 * character, if necessary. To be used when converting GetText() to a normal text.
874 * @param nIn
875 * @return unicode char
877 static sal_Unicode ConvertSymbolToUnicode(sal_Unicode nIn);
881 /** Special node for user defined characters
883 * Node used for pre- and user-defined characters from:
884 * officecfg/registry/data/org/openoffice/Office/Math.xcu
886 * This is just single characters, I think.
888 class SmSpecialNode : public SmTextNode
890 bool mbIsFromGreekSymbolSet;
892 protected:
893 SmSpecialNode(SmNodeType eNodeType, const SmToken &rNodeToken, sal_uInt16 _nFontDesc);
895 public:
896 explicit SmSpecialNode(const SmToken &rNodeToken);
899 * Prepare preliminary settings about font and text
900 * (e.g. maFace, meRectHorAlign, mnFlags, mnAttributes, etc.)
901 * @param rFormat
902 * @param rDocShell
903 * @param nDepth
904 * @return
906 virtual void Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell,
907 int nDepth) override;
910 * Prepares the SmRect to render.
911 * @param rDev
912 * @param rFormat
913 * @return
915 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
918 * Accept a visitor.
919 * Calls the method for this class on the visitor.
920 * @param pVisitor
921 * @return
923 void Accept(SmVisitor* pVisitor) override;
927 /** Glyph node for custom operators
929 * This node is used with commands: oper, uoper and boper.
930 * E.g. in "A boper op B", "op" will be an instance of SmGlyphSpecialNode.
931 * "boper" simply interprets "op", the following token, as a binary operator.
932 * The command "uoper" interprets the following token as unary operator.
933 * For these commands an instance of SmGlyphSpecialNode is used for the
934 * operator token, following the command.
936 class SmGlyphSpecialNode final : public SmSpecialNode
938 public:
939 explicit SmGlyphSpecialNode(const SmToken &rNodeToken)
940 : SmSpecialNode(SmNodeType::GlyphSpecial, rNodeToken, FNT_MATH)
944 * Prepares the SmRect to render.
945 * @param rDev
946 * @param rFormat
947 * @return
949 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
952 * Accept a visitor.
953 * Calls the method for this class on the visitor.
954 * @param pVisitor
955 * @return
957 void Accept(SmVisitor* pVisitor) override;
961 /** Math symbol node
963 * Use for math symbols such as plus, minus and integral in the INT command.
965 class SmMathSymbolNode : public SmSpecialNode
967 protected:
968 SmMathSymbolNode(SmNodeType eNodeType, const SmToken &rNodeToken)
969 : SmSpecialNode(eNodeType, rNodeToken, FNT_MATH)
971 SetText(GetToken().cMathChar);
974 public:
975 explicit SmMathSymbolNode(const SmToken &rNodeToken);
977 //visual stuff TODO comment
978 virtual void AdaptToX(OutputDevice &rDev, sal_uLong nWidth) override;
979 virtual void AdaptToY(OutputDevice &rDev, sal_uLong nHeight) override;
982 * Prepare preliminary settings about font and text
983 * (e.g. maFace, meRectHorAlign, mnFlags, mnAttributes, etc.)
984 * @param rFormat
985 * @param rDocShell
986 * @param nDepth
987 * @return
989 virtual void Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell,
990 int nDepth) override;
993 * Prepares the SmRect to render.
994 * @param rDev
995 * @param rFormat
996 * @return
998 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1001 * Accept a visitor.
1002 * Calls the method for this class on the visitor.
1003 * @param pVisitor
1004 * @return
1006 void Accept(SmVisitor* pVisitor) override;
1010 /** Math Identifier
1012 * This behaves essentially the same as SmMathSymbolNode and is only used to
1013 * represent math symbols that should be exported as <mi> elements rather than
1014 * <mo> elements.
1016 class SmMathIdentifierNode final : public SmMathSymbolNode
1018 public:
1019 explicit SmMathIdentifierNode(const SmToken &rNodeToken)
1020 : SmMathSymbolNode(SmNodeType::MathIdent, rNodeToken) {}
1024 /** Root symbol node
1026 * Root symbol node used by SmRootNode to create the root symbol, in front of
1027 * the line with the line above. I don't think this node should be used for
1028 * anything else.
1030 class SmRootSymbolNode final : public SmMathSymbolNode
1032 sal_uLong mnBodyWidth; // width of body (argument) of root sign
1034 public:
1035 explicit SmRootSymbolNode(const SmToken &rNodeToken)
1036 : SmMathSymbolNode(SmNodeType::RootSymbol, rNodeToken)
1037 , mnBodyWidth(0) { }
1040 * Gets the body width.
1041 * Allows to know how long is the root and paint it.
1042 * @return body width
1044 sal_uLong GetBodyWidth() const {return mnBodyWidth;};
1046 //visual stuff TODO comment
1047 virtual void AdaptToX(OutputDevice &rDev, sal_uLong nHeight) override;
1048 virtual void AdaptToY(OutputDevice &rDev, sal_uLong nHeight) override;
1051 * Accept a visitor.
1052 * Calls the method for this class on the visitor.
1053 * @param pVisitor
1054 * @return
1056 void Accept(SmVisitor* pVisitor) override;
1060 /** Place node
1062 * Used to create the <?> command, that denotes place where something can be
1063 * written.
1064 * It is drawn as a square with a shadow.
1066 class SmPlaceNode final : public SmMathSymbolNode
1068 public:
1069 explicit SmPlaceNode(const SmToken &rNodeToken)
1070 : SmMathSymbolNode(SmNodeType::Place, rNodeToken) { }
1071 SmPlaceNode() : SmMathSymbolNode(SmNodeType::Place, SmToken(TPLACE, MS_PLACE, "<?>")) { };
1074 * Prepare preliminary settings about font and text
1075 * (e.g. maFace, meRectHorAlign, mnFlags, mnAttributes, etc.)
1076 * @param rFormat
1077 * @param rDocShell
1078 * @param nDepth
1079 * @return
1081 virtual void Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell,
1082 int nDepth) override;
1085 * Prepares the SmRect to render.
1086 * @param rDev
1087 * @param rFormat
1088 * @return
1090 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1093 * Accept a visitor.
1094 * Calls the method for this class on the visitor.
1095 * @param pVisitor
1096 * @return
1098 void Accept(SmVisitor* pVisitor) override;
1102 /** Error node, for parsing errors
1104 * This node is used for parsing errors and draws a questionmark turned upside
1105 * down (inverted question mark).
1107 class SmErrorNode final : public SmMathSymbolNode
1109 public:
1110 explicit SmErrorNode(const SmToken &rNodeToken)
1111 : SmMathSymbolNode(SmNodeType::Error, rNodeToken) { SetText(OUString(MS_ERROR)); }
1114 * Prepare preliminary settings about font and text
1115 * (e.g. maFace, meRectHorAlign, mnFlags, mnAttributes, etc.)
1116 * @param rFormat
1117 * @param rDocShell
1118 * @param nDepth
1119 * @return
1121 virtual void Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell,
1122 int nDepth) override;
1125 * Prepares the SmRect to render.
1126 * @param rDev
1127 * @param rFormat
1128 * @return
1130 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1133 * Accept a visitor.
1134 * Calls the method for this class on the visitor.
1135 * @param pVisitor
1136 * @return
1138 void Accept(SmVisitor* pVisitor) override;
1142 /** Table node
1144 * This is the root node for the formula tree. This node is also used for the
1145 * STACK and BINOM commands. When used for root node, its
1146 * children are instances of SmLineNode, and in some obscure cases the child
1147 * can be an instance of SmExpressionNode, mainly when errors occur.
1149 class SmTableNode final : public SmStructureNode
1151 tools::Long mnFormulaBaseline;
1152 public:
1153 explicit SmTableNode(const SmToken &rNodeToken)
1154 : SmStructureNode(SmNodeType::Table, rNodeToken)
1155 , mnFormulaBaseline(0) { }
1157 virtual const SmNode * GetLeftMost() const override;
1160 * Prepares the SmRect to render.
1161 * @param rDev
1162 * @param rFormat
1163 * @return
1165 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1168 * Gets the formula baseline.
1169 * @return formula baseline
1171 tools::Long GetFormulaBaseline() const;
1174 * Accept a visitor.
1175 * Calls the method for this class on the visitor.
1176 * @param pVisitor
1177 * @return
1179 void Accept(SmVisitor* pVisitor) override;
1183 /** A line
1185 * Used as child of SmTableNode when the SmTableNode is the root node of the
1186 * formula tree.
1188 class SmLineNode : public SmStructureNode
1190 bool mbUseExtraSpaces;
1192 protected:
1193 SmLineNode(SmNodeType eNodeType, const SmToken &rNodeToken)
1194 : SmStructureNode(eNodeType, rNodeToken)
1195 , mbUseExtraSpaces(true) { }
1197 public:
1198 explicit SmLineNode(const SmToken &rNodeToken)
1199 : SmStructureNode(SmNodeType::Line, rNodeToken)
1200 , mbUseExtraSpaces(true) { }
1203 * Sets if it going to use extra spaces.
1204 * It is used to set if there has to be space between node while rendering.
1205 * By default it is true.
1206 * @param bVal
1207 * @return
1209 void SetUseExtraSpaces(bool bVal) { mbUseExtraSpaces = bVal; }
1212 * Checks if it is using extra spaces.
1213 * It is used for calculating space between nodes when rendering.
1214 * By default it is true.
1215 * @return is using extra spaces
1217 bool IsUseExtraSpaces() const { return mbUseExtraSpaces; };
1220 * Prepare preliminary settings about font and text
1221 * (e.g. maFace, meRectHorAlign, mnFlags, mnAttributes, etc.)
1222 * @param rFormat
1223 * @param rDocShell
1224 * @param nDepth
1225 * @return
1227 virtual void Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell,
1228 int nDepth) override;
1231 * Prepares the SmRect to render.
1232 * @param rDev
1233 * @param rFormat
1234 * @return
1236 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1239 * Accept a visitor.
1240 * Calls the method for this class on the visitor.
1241 * @param pVisitor
1242 * @return
1244 void Accept(SmVisitor* pVisitor) override;
1248 /** Expression node
1250 * Used whenever you have an expression such as "A OVER {B + C}", here there is
1251 * an expression node that allows "B + C" to be the denominator of the
1252 * SmBinVerNode, that the OVER command creates.
1254 class SmExpressionNode final : public SmLineNode
1256 public:
1257 explicit SmExpressionNode(const SmToken &rNodeToken)
1258 : SmLineNode(SmNodeType::Expression, rNodeToken) { }
1261 * Prepares the SmRect to render.
1262 * @param rDev
1263 * @param rFormat
1264 * @return
1266 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1269 * Accept a visitor.
1270 * Calls the method for this class on the visitor.
1271 * @param pVisitor
1272 * @return
1274 void Accept(SmVisitor* pVisitor) override;
1278 /** Unary horizontal node
1280 * The same as SmBinHorNode except this is for unary operators.
1282 class SmUnHorNode final : public SmStructureNode
1284 public:
1285 explicit SmUnHorNode(const SmToken &rNodeToken)
1286 : SmStructureNode(SmNodeType::UnHor, rNodeToken, 2) { }
1289 * Prepares the SmRect to render.
1290 * @param rDev
1291 * @param rFormat
1292 * @return
1294 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1297 * Accept a visitor.
1298 * Calls the method for this class on the visitor.
1299 * @param pVisitor
1300 * @return
1302 void Accept(SmVisitor* pVisitor) override;
1306 /** Root node
1308 * Used for create square roots and other roots, example:
1309 * \f$ \sqrt[\mbox{[Argument]}]{\mbox{[Body]}} \f$.
1311 * Children:<BR>
1312 * 0: Argument (optional)<BR>
1313 * 1: Symbol (instance of SmRootSymbolNode)<BR>
1314 * 2: Body<BR>
1315 * Where argument is optional and may be NULL.
1317 class SmRootNode final : public SmStructureNode
1319 public:
1320 explicit SmRootNode(const SmToken &rNodeToken)
1321 : SmStructureNode(SmNodeType::Root, rNodeToken, 3) { }
1324 * Prepares the SmRect to render.
1325 * @param rDev
1326 * @param rFormat
1327 * @return
1329 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1332 * Accept a visitor.
1333 * Calls the method for this class on the visitor.
1334 * @param pVisitor
1335 * @return
1337 void Accept(SmVisitor* pVisitor) override;
1340 * Returns the node containing the data of the order of the root.
1341 * @return order data
1343 const SmNode* Argument() const { return const_cast<SmRootNode *>(this)->Argument(); }
1344 SmNode* Argument() { assert( GetNumSubNodes() == 3 ); return GetSubNode( 0 ); }
1347 * Returns the node containing the data of the character used for the root.
1348 * @return symbol data
1350 const SmRootSymbolNode* Symbol() const { return const_cast<SmRootNode *>(this)->Symbol(); }
1351 SmRootSymbolNode* Symbol() { assert( GetNumSubNodes() == 3 );
1352 assert( GetSubNode( 1 )->GetType()
1353 == SmNodeType::RootSymbol );
1354 return static_cast< SmRootSymbolNode* >
1355 ( GetSubNode( 1 )); }
1358 * Returns the node containing the data inside the root.
1359 * @return body data
1361 const SmNode* Body() const { return const_cast<SmRootNode *>(this)->Body(); }
1362 SmNode* Body() { assert( GetNumSubNodes() == 3 ); return GetSubNode( 2 ); }
1367 /** Binary horizontal node
1369 * This node is used for binary operators. In a formula such as "A + B".
1371 * Children:<BR>
1372 * 0: Left operand<BR>
1373 * 1: Binary operator<BR>
1374 * 2: Right operand<BR>
1376 * None of the children may be NULL.
1378 class SmBinHorNode final : public SmStructureNode
1380 public:
1381 explicit SmBinHorNode(const SmToken &rNodeToken)
1382 : SmStructureNode(SmNodeType::BinHor, rNodeToken, 3) { }
1385 * Prepares the SmRect to render.
1386 * @param rDev
1387 * @param rFormat
1388 * @return
1390 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1393 * Accept a visitor.
1394 * Calls the method for this class on the visitor.
1395 * @param pVisitor
1396 * @return
1398 void Accept(SmVisitor* pVisitor) override;
1401 * Returns the node containing the data of the binary operator.
1402 * @return symbol data
1404 const SmNode* Symbol() const { return const_cast<SmBinHorNode *>(this)->Symbol(); }
1405 SmNode* Symbol() { assert( GetNumSubNodes() == 3 ); return GetSubNode( 1 ); }
1408 * Returns the node containing the data of the left operand.
1409 * @return left operand data
1411 const SmNode* LeftOperand() const { return const_cast<SmBinHorNode *>(this)->LeftOperand(); }
1412 SmNode* LeftOperand() { assert( GetNumSubNodes() == 3 ); return GetSubNode( 0 ); }
1415 * Returns the node containing the data of the right operand.
1416 * @return right operand data
1418 const SmNode* RightOperand() const { return const_cast<SmBinHorNode *>(this)->RightOperand(); }
1419 SmNode* RightOperand() { assert( GetNumSubNodes() == 3 ); return GetSubNode( 2 ); }
1423 /** Binary horizontal node
1425 * This node is used for creating the OVER command, consider the formula:
1426 * "numerator OVER denominator", which looks like
1427 * \f$ \frac{\mbox{numerator}}{\mbox{denominator}} \f$
1429 * Children:<BR>
1430 * 0: Numerator<BR>
1431 * 1: Line (instance of SmRectangleNode)<BR>
1432 * 2: Denominator<BR>
1433 * None of the children may be NULL.
1435 class SmBinVerNode final : public SmStructureNode
1437 public:
1438 explicit SmBinVerNode(const SmToken &rNodeToken)
1439 : SmStructureNode(SmNodeType::BinVer, rNodeToken, 3) { }
1441 virtual const SmNode * GetLeftMost() const override;
1444 * Prepares the SmRect to render.
1445 * @param rDev
1446 * @param rFormat
1447 * @return
1449 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1452 * Accept a visitor.
1453 * Calls the method for this class on the visitor.
1454 * @param pVisitor
1455 * @return
1457 void Accept(SmVisitor* pVisitor) override;
1461 /** Binary diagonal node
1463 * Used for implementing the WIDESLASH command, example: "A WIDESLASH B".
1465 * Children:<BR>
1466 * 0: Left operand<BR>
1467 * 1: right operand<BR>
1468 * 2: Line (instance of SmPolyLineNode).<BR>
1469 * None of the children may be NULL.
1471 class SmBinDiagonalNode final : public SmStructureNode
1473 bool mbAscending;
1476 * Returns the position and size of the diagonal line by reference.
1477 * @param rPos
1478 * @param rSize
1479 * @param rDiagPoint
1480 * @param fAngleDeg
1481 * @return position and size of the diagonal line
1483 void GetOperPosSize(Point &rPos, Size &rSize, const Point &rDiagPoint, double fAngleDeg) const;
1485 public:
1486 explicit SmBinDiagonalNode(const SmToken &rNodeToken)
1487 : SmStructureNode(SmNodeType::BinDiagonal, rNodeToken, 3)
1488 , mbAscending(false) { }
1491 * Checks if it is of ascending type.
1492 * Ascending:
1493 * / b
1495 * a /
1496 * Descending:
1497 * a \
1499 * \ b
1500 * @return ascending.
1502 bool IsAscending() const { return mbAscending; }
1505 * Sets if the wideslash is ascending to bVal.
1506 * @param bVal
1507 * @return
1509 void SetAscending(bool bVal) { mbAscending = bVal; }
1512 * Prepares the SmRect to render.
1513 * @param rDev
1514 * @param rFormat
1515 * @return
1517 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1520 * Accept a visitor.
1521 * Calls the method for this class on the visitor.
1522 * @param pVisitor
1523 * @return
1525 void Accept(SmVisitor* pVisitor) override;
1529 /** Enum used to index sub-/supscripts in the 'maSubNodes' array
1530 * in 'SmSubSupNode'
1532 * See graphic for positions at char:
1534 * \code
1535 * CSUP
1537 * LSUP H H RSUP
1538 * H H
1539 * HHHH
1540 * H H
1541 * LSUB H H RSUB
1543 * CSUB
1544 * \endcode
1546 enum SmSubSup
1547 { CSUB, CSUP, RSUB, RSUP, LSUB, LSUP
1550 /** numbers of entries in the above enum (that is: the number of possible
1551 * sub-/supscripts)
1553 #define SUBSUP_NUM_ENTRIES 6
1555 /** Super- and subscript node
1557 * Used for creating super- and subscripts for commands such as:
1558 * "^", "_", "lsup", "lsub", "csup" and "csub".
1559 * Example: "A^2" which looks like: \f$ A^2 \f$
1561 * This node is also used for creating limits on SmOperNode, when
1562 * "FROM" and "TO" commands are used with "INT", "SUM" or similar.
1564 * Children of this node can be enumerated using the SmSubSup enum.
1565 * Please note that children may be NULL, except for the body.
1566 * It is recommended that you access children using GetBody() and
1567 * GetSubSup().
1569 class SmSubSupNode final : public SmStructureNode
1571 bool mbUseLimits;
1573 public:
1574 explicit SmSubSupNode(const SmToken &rNodeToken)
1575 : SmStructureNode(SmNodeType::SubSup, rNodeToken, 1 + SUBSUP_NUM_ENTRIES)
1576 , mbUseLimits(false) { }
1579 * Returns the node with the data of what has to be superindex or subindex.
1580 * @return body data
1582 const SmNode * GetBody() const { return const_cast<SmSubSupNode *>(this)->GetBody(); }
1583 SmNode * GetBody() { return GetSubNode(0); }
1586 * Checks if it is going to be used for a limit.
1587 * Example lim from { x toward 0 } { {sin x}over x } = 1
1588 * @return is a limit
1590 bool IsUseLimits() const { return mbUseLimits; };
1593 * Sets if it is going to be used for a limit to bVal.
1594 * @param bVal
1595 * @return
1597 void SetUseLimits(bool bVal) { mbUseLimits = bVal; }
1600 * Gets the node with the data of what has to be superindex or subindex.
1601 * The position to check is given by eSubSup.
1602 * @remarks this method may return NULL.
1603 * @param eSubSup
1604 * @return body data
1606 const SmNode * GetSubSup(SmSubSup eSubSup) const { return const_cast< SmSubSupNode* >
1607 ( this )->GetSubSup( eSubSup ); }
1608 SmNode * GetSubSup(SmSubSup eSubSup) { return GetSubNode(1 + eSubSup); };
1611 * Sets the node with the data of what has to be superindex or subindex.
1612 * @param pScript
1614 void SetBody(SmNode* pBody) { SetSubNode(0, pBody); }
1617 * Sets the node with the data of what has to be superindex or subindex.
1618 * The position to check is given by eSubSup.
1619 * @param eSubSup
1620 * @param pScript
1622 void SetSubSup(SmSubSup eSubSup, SmNode* pScript) { SetSubNode( 1 + eSubSup, pScript); }
1625 * Prepares the SmRect to render.
1626 * @param rDev
1627 * @param rFormat
1628 * @return
1630 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1633 * Accept a visitor.
1634 * Calls the method for this class on the visitor.
1635 * @param pVisitor
1636 * @return
1638 void Accept(SmVisitor* pVisitor) override;
1643 /** Node for brace construction
1645 * Used for "lbrace [body] rbrace" and similar constructions.
1646 * Should look like \f$ \{\mbox{[body]}\} \f$
1648 * Children:<BR>
1649 * 0: Opening brace<BR>
1650 * 1: Body (usually SmBracebodyNode)<BR>
1651 * 2: Closing brace<BR>
1652 * None of the children can be NULL.
1654 * Note that child 1 (Body) is usually SmBracebodyNode, but it can also be e.g. SmExpressionNode.
1656 class SmBraceNode final : public SmStructureNode
1658 public:
1659 explicit SmBraceNode(const SmToken &rNodeToken)
1660 : SmStructureNode(SmNodeType::Brace, rNodeToken, 3) { }
1663 * Returns the node containing the data of the opening brace.
1664 * @return opening brace data
1666 const SmMathSymbolNode* OpeningBrace() const { return const_cast<SmBraceNode *>
1667 (this)->OpeningBrace(); }
1668 SmMathSymbolNode* OpeningBrace() { assert( GetNumSubNodes() == 3 );
1669 assert( GetSubNode( 0 )->GetType()
1670 == SmNodeType::Math );
1671 return static_cast< SmMathSymbolNode* >
1672 ( GetSubNode( 0 )); }
1675 * Returns the node containing the data of what is between braces.
1676 * @return body data
1678 const SmNode* Body() const { return const_cast<SmBraceNode *>(this)->Body(); }
1679 SmNode* Body() { assert( GetNumSubNodes() == 3 ); return GetSubNode( 1 ); }
1682 * Returns the node containing the data of the closing brace.
1683 * @return closing brace data
1685 const SmMathSymbolNode* ClosingBrace() const { return const_cast<SmBraceNode *>
1686 (this)->ClosingBrace(); }
1687 SmMathSymbolNode* ClosingBrace() { assert( GetNumSubNodes() == 3 );
1688 assert( GetSubNode( 2 )->GetType()
1689 == SmNodeType::Math );
1690 return static_cast< SmMathSymbolNode* >
1691 ( GetSubNode( 2 )); }
1694 * Prepares the SmRect to render.
1695 * @param rDev
1696 * @param rFormat
1697 * @return
1699 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1702 * Accept a visitor.
1703 * Calls the method for this class on the visitor.
1704 * @param pVisitor
1705 * @return
1707 void Accept(SmVisitor* pVisitor) override;
1711 /** Body of an SmBraceNode
1713 * This usually only has one child an SmExpressionNode, however, it can also
1714 * have other children.
1715 * Consider the formula "lbrace [body1] mline [body2] rbrace", looks like:
1716 * \f$ \{\mbox{[body1] | [body2]}\} \f$.
1717 * In this case SmBracebodyNode will have three children, "[body1]", "|" and
1718 * [body2].
1720 class SmBracebodyNode final : public SmStructureNode
1722 tools::Long mnBodyHeight;
1724 public:
1725 explicit SmBracebodyNode(const SmToken &rNodeToken)
1726 : SmStructureNode(SmNodeType::Bracebody, rNodeToken)
1727 , mnBodyHeight(0) { }
1730 * Prepares the SmRect to render.
1731 * @param rDev
1732 * @param rFormat
1733 * @return
1735 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1736 tools::Long GetBodyHeight() const { return mnBodyHeight; }
1739 * Accept a visitor.
1740 * Calls the method for this class on the visitor.
1741 * @param pVisitor
1742 * @return
1744 void Accept(SmVisitor* pVisitor) override;
1748 /** Node for vertical brace construction
1750 * Used to implement commands "[body] underbrace [script]" and
1751 * "[body] overbrace [script]".
1752 * Underbrace should look like this \f$ \underbrace{\mbox{body}}_{\mbox{script}}\f$.
1754 * Children:<BR>
1755 * 0: body<BR>
1756 * 1: brace<BR>
1757 * 2: script<BR>
1758 * (None of these children are optional, e.g. they must all be not NULL).
1760 class SmVerticalBraceNode final : public SmStructureNode
1762 public:
1763 explicit SmVerticalBraceNode(const SmToken &rNodeToken)
1764 : SmStructureNode(SmNodeType::VerticalBrace, rNodeToken, 3) { }
1767 * Returns the node containing the data of what the brace is pointing for.
1768 * body { script }
1769 * @return body data
1771 const SmNode* Body() const { return const_cast<SmVerticalBraceNode *>(this)->Body(); }
1772 SmNode* Body() { assert( GetNumSubNodes() == 3 ); return GetSubNode( 0 ); }
1775 * Returns the node containing the data of the brace.
1776 * @return brace data
1778 const SmMathSymbolNode* Brace() const { return const_cast<SmVerticalBraceNode *>
1779 (this)->Brace(); }
1780 SmMathSymbolNode* Brace() { assert( GetNumSubNodes() == 3 );
1781 assert( GetSubNode( 1 )->GetType()
1782 == SmNodeType::Math );
1783 return static_cast< SmMathSymbolNode* >
1784 ( GetSubNode( 1 )); }
1787 * Returns the node containing the data of what is in the brace.
1788 * body { script }
1789 * @return opening brace data
1791 const SmNode* Script() const { return const_cast<SmVerticalBraceNode *>(this)->Script(); }
1792 SmNode* Script() { assert( GetNumSubNodes() == 3 ); return GetSubNode( 2 ); }
1795 * Prepares the SmRect to render.
1796 * @param rDev
1797 * @param rFormat
1798 * @return
1800 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1803 * Accept a visitor.
1804 * Calls the method for this class on the visitor.
1805 * @param pVisitor
1806 * @return
1808 void Accept(SmVisitor* pVisitor) override;
1811 /** Operation Node
1813 * Used for commands like SUM, INT and similar.
1815 * Children:<BR>
1816 * 0: Operation (instance of SmMathSymbolNode or SmSubSupNode)<BR>
1817 * 1: Body<BR>
1818 * None of the children may be NULL.
1821 class SmOperNode final : public SmStructureNode
1823 public:
1824 explicit SmOperNode(const SmToken &rNodeToken)
1825 : SmStructureNode(SmNodeType::Oper, rNodeToken, 2) { }
1828 * Returns the node with the operator data
1829 * @return operator data
1831 const SmNode * GetSymbol() const { return const_cast<SmOperNode *>(this)->GetSymbol(); }
1832 SmNode * GetSymbol();
1835 * Returns the height of the node in base to the symbol
1836 * ( rSymbol contains the operator data )
1837 * and the font format ( rFormat ).
1838 * @param rSymbol
1839 * @param rFormat
1840 * @return node's height
1842 tools::Long CalcSymbolHeight(const SmNode &rSymbol, const SmFormat &rFormat) const;
1845 * Prepares the SmRect to render.
1846 * @param rDev
1847 * @param rFormat
1848 * @return
1850 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1853 * Accept a visitor.
1854 * Calls the method for this class on the visitor.
1855 * @param pVisitor
1856 * @return
1858 void Accept(SmVisitor* pVisitor) override;
1862 /** Node used for alignment
1864 * This node has exactly one child at index 0.
1866 class SmAlignNode final : public SmStructureNode
1868 public:
1869 explicit SmAlignNode(const SmToken &rNodeToken)
1870 : SmStructureNode(SmNodeType::Align, rNodeToken) { }
1873 * Prepares the SmRect to render.
1874 * @param rDev
1875 * @param rFormat
1876 * @return
1878 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1881 * Accept a visitor.
1882 * Calls the method for this class on the visitor.
1883 * @param pVisitor
1884 * @return
1886 void Accept(SmVisitor* pVisitor) override;
1890 /** Attribute node
1892 * Used to give an attribute to another node. Used for commands such as:
1893 * UNDERLINE, OVERLINE, OVERSTRIKE, WIDEVEC, WIDEHARPOON, WIDEHAT and WIDETILDE.
1895 * Children:<BR>
1896 * 0: Attribute<BR>
1897 * 1: Body<BR>
1898 * None of these may be NULL.
1900 class SmAttributeNode final : public SmStructureNode
1902 public:
1903 explicit SmAttributeNode(const SmToken &rNodeToken)
1904 : SmStructureNode(SmNodeType::Attribute, rNodeToken, 2) {}
1907 * Prepares the SmRect to render.
1908 * @param rDev
1909 * @param rFormat
1910 * @return
1912 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1915 * Accept a visitor.
1916 * Calls the method for this class on the visitor.
1917 * @param pVisitor
1918 * @return
1920 void Accept(SmVisitor* pVisitor) override;
1923 * Gets the attribute data.
1924 * @return attribute data
1926 const SmNode* Attribute() const { return const_cast<SmAttributeNode *>(this)->Attribute(); }
1927 SmNode* Attribute() { assert( GetNumSubNodes() == 2 ); return GetSubNode( 0 ); }
1930 * Gets the body data ( the nodes affected by the attribute ).
1931 * @return body data
1933 const SmNode* Body() const { return const_cast<SmAttributeNode *>(this)->Body(); }
1934 SmNode* Body() { assert( GetNumSubNodes() == 2 ); return GetSubNode( 1 ); }
1938 /** Font node
1940 * Used to change the font of its children.
1942 class SmFontNode final : public SmStructureNode
1944 FontSizeType meSizeType;
1945 Fraction maFontSize;
1947 public:
1948 explicit SmFontNode(const SmToken &rNodeToken)
1949 : SmStructureNode(SmNodeType::Font, rNodeToken)
1950 , meSizeType(FontSizeType::MULTIPLY)
1951 , maFontSize(1) { }
1954 * Sets font size to rValue in nType mode.
1955 * Check FontSizeType for details.
1956 * @param rValue
1957 * @param nType
1958 * @return
1960 void SetSizeParameter(const Fraction &rValue, FontSizeType nType)
1961 { meSizeType = nType; maFontSize = rValue; }
1964 * Returns the font size.
1965 * @return font size.
1967 const Fraction & GetSizeParameter() const {return maFontSize;}
1970 * Returns the font size type.
1971 * Check FontSizeType for details.
1972 * @return font size type.
1974 FontSizeType GetSizeType() const {return meSizeType;}
1977 * Prepare preliminary settings about font and text
1978 * (e.g. maFace, meRectHorAlign, mnFlags, mnAttributes, etc.)
1979 * @param rFormat
1980 * @param rDocShell
1981 * @param nDepth
1982 * @return
1984 virtual void Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell,
1985 int nDepth) override;
1988 * Prepares the SmRect to render.
1989 * @param rDev
1990 * @param rFormat
1991 * @return
1993 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1996 * Accept a visitor.
1997 * Calls the method for this class on the visitor.
1998 * @param pVisitor
1999 * @return
2001 void Accept(SmVisitor* pVisitor) override;
2005 /** Matrix node
2007 * Used to implement the MATRIX command, example:
2008 * "matrix{ 1 # 2 ## 3 # 4}".
2010 class SmMatrixNode final : public SmStructureNode
2012 sal_uInt16 mnNumRows,
2013 mnNumCols;
2015 public:
2016 explicit SmMatrixNode(const SmToken &rNodeToken)
2017 : SmStructureNode(SmNodeType::Matrix, rNodeToken)
2018 , mnNumRows(0)
2019 , mnNumCols(0) { }
2022 * Gets the number of rows of the matrix.
2023 * @return rows number
2025 sal_uInt16 GetNumRows() const {return mnNumRows;}
2028 * Gets the number of columns of the matrix.
2029 * @return columns number
2031 sal_uInt16 GetNumCols() const {return mnNumCols;}
2034 * Sets the dimensions of the matrix.
2035 * @param nMatrixRows
2036 * @param nMatrixCols
2037 * @return
2039 void SetRowCol(sal_uInt16 nMatrixRows, sal_uInt16 nMatrixCols)
2040 { mnNumRows = nMatrixRows; mnNumCols = nMatrixCols; }
2042 virtual const SmNode * GetLeftMost() const override;
2045 * Prepares the SmRect to render.
2046 * @param rDev
2047 * @param rFormat
2048 * @return
2050 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
2053 * Accept a visitor.
2054 * Calls the method for this class on the visitor.
2055 * @param pVisitor
2056 * @return
2058 void Accept(SmVisitor* pVisitor) override;
2062 /** Node for whitespace
2064 * Used to implement the commands "~" and "`". This node is just a blank space.
2066 class SmBlankNode final : public SmGraphicNode
2068 sal_uInt16 mnNum;
2070 public:
2071 explicit SmBlankNode(const SmToken &rNodeToken)
2072 : SmGraphicNode(SmNodeType::Blank, rNodeToken)
2073 , mnNum(0) { }
2075 void IncreaseBy(const SmToken &rToken, sal_uInt32 nMultiplyBy = 1);
2076 void Clear() { mnNum = 0; }
2077 sal_uInt16 GetBlankNum() const { return mnNum; }
2078 void SetBlankNum(sal_uInt16 nNumber) { mnNum = nNumber; }
2081 * Prepare preliminary settings about font and text
2082 * (e.g. maFace, meRectHorAlign, mnFlags, mnAttributes, etc.)
2083 * @param rFormat
2084 * @param rDocShell
2085 * @param nDepth
2086 * @return
2088 virtual void Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell,
2089 int nDepth) override;
2092 * Prepares the SmRect to render.
2093 * @param rDev
2094 * @param rFormat
2095 * @return
2097 virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
2100 * Accept a visitor.
2101 * Calls the method for this class on the visitor.
2102 * @param pVisitor
2103 * @return
2105 void Accept(SmVisitor* pVisitor) override;
2109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */