xref: /core/starmath/inc/node.hxx (revision b56ca52c)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 /** The SmNode is the basic structure of formula data.
21   *
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:
25   *
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
59   *
60   */
61 
62 #pragma once
63 
64 #include "types.hxx"
65 #include "token.hxx"
66 #include "rect.hxx"
67 #include "format.hxx"
68 #include "nodetype.hxx"
69 
70 #include <editeng/editdata.hxx>
71 #include <rtl/ustrbuf.hxx>
72 
73 enum class FontAttribute {
74     None   = 0x0000,
75     Bold   = 0x0001,
76     Italic = 0x0002
77 };
78 
79 namespace o3tl
80 {
81     template<> struct typed_flags<FontAttribute> : is_typed_flags<FontAttribute, 0x0003> {};
82 }
83 
84 
85 enum class FontSizeType {
86   ABSOLUT  = 1,
87   PLUS     = 2,
88   MINUS    = 3,
89   MULTIPLY = 4,
90   DIVIDE   = 5
91 };
92 
93 // flags to interdict respective status changes
94 enum class FontChangeMask {
95     None     = 0x0000,
96     Face     = 0x0001,
97     Size     = 0x0002,
98     Bold     = 0x0004,
99     Italic   = 0x0008,
100     Color    = 0x0010,
101     Phantom  = 0x0020
102 };
103 
104 namespace o3tl
105 {
106     template<> struct typed_flags<FontChangeMask> : is_typed_flags<FontChangeMask, 0x003f> {};
107 }
108 
109 
110 class SmVisitor;
111 class SmDocShell;
112 class SmNode;
113 class SmStructureNode;
114 
115 typedef std::vector< SmNode * > SmNodeArray;
116 
117 enum class SmScaleMode
118 {
119     None,
120     Width,
121     Height
122 };
123 
124 class SmNode : public SmRect
125 {
126     // Rendering info for SmRect
127     SmFace          maFace;
128     // Anclage to the code
129     SmToken         maNodeToken;
130     ESelection      m_aESelection;
131     // Node information
132     SmNodeType      meType;
133     SmScaleMode     meScaleMode;
134     RectHorAlign    meRectHorAlign;
135     FontChangeMask  mnFlags;
136     FontAttribute   mnAttributes;
137     bool            mbIsPhantom;
138     bool            mbIsSelected;
139     // index in accessible text; -1 if not (yet) applicable
140     sal_Int32       mnAccIndex;
141 
142 protected:
143     SmNode(SmNodeType eNodeType, SmToken aNodeToken);
144 
145 public:
146     SmNode(const SmNode&) = delete;
147     SmNode& operator=(const SmNode&) = delete;
148 
149     virtual ~SmNode();
150 
151     /**
152      * Checks node visibility.
153      * Returns true if this is an instance of SmVisibleNode's subclass, false otherwise.
154      * @return node visibility
155      */
156     virtual bool IsVisible() const = 0;
157 
158     /**
159      * Gets the number of subnodes.
160      * @return number of subnodes
161      */
162     virtual size_t GetNumSubNodes() const = 0;
163 
164     /**
165      * Gets the subnode of index nIndex.
166      * @param nIndex
167      * @return subnode of index nIndex
168      */
169     virtual SmNode * GetSubNode(size_t nIndex) = 0;
GetSubNode(size_t nIndex) const170     const   SmNode * GetSubNode(size_t nIndex) const
171                      { return const_cast<SmNode *>(this)->GetSubNode(nIndex); }
172 
173     virtual const SmNode * GetLeftMost() const;
174 
175     /**
176      * Gets the FontChangeMask flags.
177      * @return FontChangeMask flags
178      */
Flags()179     FontChangeMask &Flags() { return mnFlags; }
180 
181     /**
182      * Gets the font attributes.
183      * @return font attributes
184      */
Attributes()185     FontAttribute &Attributes() { return mnAttributes; }
186 
187     /**
188      * Checks if it is a visible node rendered invisible.
189      * @return rendered visibility
190      */
IsPhantom() const191     bool IsPhantom() const { return mbIsPhantom; }
192 
193     /**
194      * Sets the render visibility of a visible node to bIsPhantom.
195      * @param bIsPhantom
196      * @return
197      */
198     void SetPhantom(bool bIsPhantom);
199 
200     /**
201      * Sets the font color.
202      * @param rColor
203      * @return
204      */
205     void SetColor(const Color &rColor);
206 
207     /**
208      * Sets the font attribute nAttrib.
209      * Check FontAttribute class.
210      * @param nAttrib
211      * @return
212      */
213     void SetAttribute(FontAttribute nAttrib);
214 
215     /**
216      * Clears the font attribute nAttrib.
217      * Check FontAttribute class.
218      * @param nAttrib
219      * @return
220      */
221     void ClearAttribute(FontAttribute nAttrib);
222 
223     /**
224      * Gets the font.
225      * @return font
226      */
GetFont() const227     const SmFace & GetFont() const { return maFace; };
GetFont()228           SmFace & GetFont()       { return maFace; };
229 
230     /**
231      * Sets the font to rFace.
232      * @param rFace
233      * @return
234      */
235     void SetFont(const SmFace &rFace);
236 
237     /**
238      * Sets the font size to rRelSize with type nType.
239      * Check FontSizeType for details.
240      * @param rRelSize
241      * @param nType
242      * @return
243      */
244     void SetFontSize(const Fraction &rRelSize, FontSizeType nType);
245 
246     /**
247      * Sets the font size to rRelSize with type FontSizeType::ABSOLUT.
248      * @param rScale
249      * @return
250      */
251     void SetSize(const Fraction &rScale);
252 
253     /**
254      * Prepare preliminary settings about font and text
255      * (e.g. maFace, meRectHorAlign, mnFlags, mnAttributes, etc.)
256      * @param rFormat
257      * @param rDocShell
258      * @param nDepth
259      * @return
260      */
261     virtual void Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell, int nDepth);
262 
263     /**
264      * Prepare preliminary font attributes
265      * Called on Prepare(...).
266      * @return
267      */
268     void PrepareAttributes();
269 
270     /**
271      * Sets the alignment of the text.
272      * Check RectHorAlign class for details.
273      * The subtrees will be affected if bApplyToSubTree.
274      * @param eHorAlign
275      * @param bApplyToSubTree
276      * @return
277      */
278     void SetRectHorAlign(RectHorAlign eHorAlign, bool bApplyToSubTree = true );
279 
280     /**
281      * Gets the alignment of the text.
282      * @return alignment of the text
283      */
GetRectHorAlign() const284     RectHorAlign GetRectHorAlign() const { return meRectHorAlign; }
285 
286     /**
287      * Parses itself to SmRect.
288      * @return this
289      */
GetRect() const290     const SmRect & GetRect() const { return *this; }
291 
292     /**
293      * Moves the rectangle by rVector.
294      * @param rVector
295      * @return
296      */
297     void Move(const Point &rVector);
298 
299     /**
300      * Moves the rectangle to rPoint, being the top left corner the origin.
301      * @param rPoint
302      * @return
303      */
MoveTo(const Point & rPoint)304     void MoveTo(const Point &rPoint) { Move(rPoint - GetTopLeft()); }
305 
306     /**
307      * Prepares the SmRect to render.
308      * @param rDev
309      * @param rFormat
310      * @return
311      */
312     virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) = 0;
313 
314     /**
315      * Appends to rText the node text.
316      * @param rText
317      * @return
318      */
319     virtual void GetAccessibleText( OUStringBuffer &rText ) const = 0;
320 
321     /**
322      * Gets the node accessible index.
323      * Used for visual editing.
324      * @return node accessible index
325      */
GetAccessibleIndex() const326     sal_Int32 GetAccessibleIndex() const { return mnAccIndex; }
327 
328     /**
329      * Sets the node accessible index to nAccIndex.
330      * Used for visual editing.
331      * @param nAccIndex
332      * @return
333      */
SetAccessibleIndex(sal_Int32 nAccIndex)334     void SetAccessibleIndex(sal_Int32 nAccIndex) { mnAccIndex = nAccIndex; }
335 
336     /**
337      * Finds the node with accessible index nAccIndex.
338      * Used for visual editing.
339      * @param nAccIndex
340      * @return node with accessible index nAccIndex
341      */
342     const SmNode * FindNodeWithAccessibleIndex(sal_Int32 nAccIndex) const;
343 
344     /**
345      * Gets the line in the text where the node is located.
346      * It is used to do the visual <-> text correspondence.
347      * @return line
348      */
GetRow() const349     sal_uInt16 GetRow() const { return sal::static_int_cast<sal_uInt16>(m_aESelection.nStartPara); }
350 
351     /**
352      * Gets the column of the line in the text where the node is located.
353      * It is used to do the visual <-> text correspondence.
354      * @return column
355      */
GetColumn() const356     sal_uInt16 GetColumn() const { return sal::static_int_cast<sal_uInt16>(m_aESelection.nStartPos); }
357 
358     /**
359      * Gets the scale mode.
360      * @return scale mode
361      */
GetScaleMode() const362     SmScaleMode GetScaleMode() const { return meScaleMode; }
363 
364     /**
365      * Sets the scale mode to eMode.
366      * @param eMode
367      * @return
368      */
SetScaleMode(SmScaleMode eMode)369     void SetScaleMode(SmScaleMode eMode) { meScaleMode = eMode; }
370 
371     //visual stuff TODO comment
372     virtual void AdaptToX(OutputDevice &rDev, sal_uLong nWidth);
373     virtual void AdaptToY(OutputDevice &rDev, sal_uLong nHeight);
374 
375     /**
376      * Gets the node type.
377      * @return node type
378      */
GetType() const379     SmNodeType GetType() const  { return meType; }
380 
381     /**
382      * Gets the token.
383      * The token contains the data extracted from the text mode.
384      * Ej: text, type (sub, sup, int,...), row and column,...
385      * @return node type
386      */
GetToken() const387     const SmToken & GetToken() const { return maNodeToken; }
GetToken()388           SmToken & GetToken()       { return maNodeToken; }
389 
390     /**
391      * Gets node position in input text.
392      * @return node position in input text
393      */
GetSelection() const394     const ESelection& GetSelection() const { return m_aESelection; }
395 
396     /**
397      * Gets node position in input text.
398      * @param aESelection
399      */
SetSelection(ESelection aESelection)400     void SetSelection(ESelection aESelection) { m_aESelection = aESelection; }
401 
402     /**
403      * Finds the node from the position in the text.
404      * It is used to do the visual <-> text correspondence.
405      * @param nRow
406      * @param nCol
407      * @return the given node
408      */
409     const SmNode *  FindTokenAt(sal_uInt16 nRow, sal_uInt16 nCol) const;
410 
411     /**
412      * Finds the closest rectangle in the screen.
413      * @param rPoint
414      * @return the given node
415      */
416     const SmNode *  FindRectClosestTo(const Point &rPoint) const;
417 
418     /**
419      * Accept a visitor.
420      * Calls the method for this class on the visitor.
421      * @param pVisitor
422      * @return
423      */
424     virtual void Accept(SmVisitor* pVisitor) = 0;
425 
426     /**
427      * Checks if the node is selected.
428      * @return the node is selected
429      */
IsSelected() const430     bool IsSelected() const {return mbIsSelected;}
431 
432     /**
433      * Sets the node to Selected.
434      * @param Selected
435      * @return
436      */
SetSelected(bool Selected)437     void SetSelected(bool Selected) {mbIsSelected = Selected;}
438 
439     /**
440      * Gets the parent node of this node.
441      * @return parent node
442      */
GetParent() const443     const SmStructureNode* GetParent() const { return mpParentNode; }
GetParent()444           SmStructureNode* GetParent()       { return mpParentNode; }
445 
446     /**
447      * Sets the parent node.
448      * @param parent
449      * @return
450      */
SetParent(SmStructureNode * parent)451     void SetParent(SmStructureNode* parent){ mpParentNode = parent; }
452 
453     /**
454      * Sets the token for this node.
455      * @param token
456      * @return
457      */
SetToken(SmToken const & token)458     void SetToken(SmToken const & token){ maNodeToken = token; }
459 
460 private:
461     SmStructureNode* mpParentNode;
462 };
463 
464 
465 /** Abstract baseclass for all composite node
466  *
467  * Subclasses of this class can have subnodes. Nodes that doesn't derivate from
468  * this class does not have subnodes.
469  */
470 class SmStructureNode : public SmNode
471 {
472     SmNodeArray maSubNodes;
473 
474 protected:
SmStructureNode(SmNodeType eNodeType,const SmToken & rNodeToken,size_t nSize=0)475     SmStructureNode(SmNodeType eNodeType, const SmToken &rNodeToken, size_t nSize = 0)
476         : SmNode(eNodeType, rNodeToken)
477         , maSubNodes(nSize) {}
478 
479 public:
480     virtual ~SmStructureNode() override;
481 
482     /**
483      * Checks node visibility.
484      * Returns true if this is an instance of SmVisibleNode's subclass, false otherwise.
485      * @return node visibility
486      */
487     virtual bool IsVisible() const override;
488 
489     /**
490      * Gets the number of subnodes.
491      * @return number of subnodes
492      */
493     virtual size_t GetNumSubNodes() const override;
494 
495     /**
496      * Gets the subnode of index nIndex.
497      * @param nIndex
498      * @return subnode of index nIndex
499      */
500     using   SmNode::GetSubNode;
501     virtual SmNode * GetSubNode(size_t nIndex) override;
502 
503     /**
504      * Gets the subnode of index nIndex, used for operators.
505      * @param nIndex
506      * @return subnode of index nIndex
507      */
508     SmNode * GetSubNodeBinMo(size_t nIndex) const;
509 
510     /**
511      * Does the cleaning of the subnodes.
512      * @return
513      */
514     void ClearSubNodes();
515 
516     /**
517      * Sets subnodes, used for operators.
518      * @param pFirst
519      * @param pSecond
520      * @param pThird
521      * @return
522      */
523     void SetSubNodes(std::unique_ptr<SmNode> pFirst, std::unique_ptr<SmNode> pSecond,
524                      std::unique_ptr<SmNode> pThird = nullptr);
525 
526     /**
527      * Sets subnodes.
528      * @param pFirst
529      * @param pSecond
530      * @param pThird
531      * @return
532      */
533     void SetSubNodes(SmNode* pFirst, SmNode* pSecond, SmNode* pThird);
534 
535     /**
536      * Sets subnodes, used for operators.
537      * The data is reordered so the items are correctly ordered.
538      * @param pFirst
539      * @param pSecond
540      * @param pThird
541      * @return
542      */
543     void SetSubNodesBinMo(std::unique_ptr<SmNode> pFirst, std::unique_ptr<SmNode> pSecond,
544                           std::unique_ptr<SmNode> pThird = nullptr);
545 
546     /**
547      * Sets subnodes.
548      * @param rNodeArray
549      * @return
550      */
551     void SetSubNodes(SmNodeArray&& rNodeArray);
552 
553     /**
554      * Appends to rText the node text.
555      * @param rText
556      * @return
557      */
558     virtual void  GetAccessibleText( OUStringBuffer &rText ) const override;
559 
560     /**
561      * Gets the first subnode.
562      * @return first subnode
563      */
begin()564     SmNodeArray::iterator begin() {return maSubNodes.begin();}
565 
566     /**
567      * Gets the last subnode.
568      * @return last subnode
569      */
end()570     SmNodeArray::iterator end() {return maSubNodes.end();}
571 
572     /**
573      * Gets the last subnode.
574      * @return last subnode
575      */
rbegin()576     SmNodeArray::reverse_iterator rbegin() {return maSubNodes.rbegin();}
577 
578     /**
579      * Gets the first subnode.
580      * @return first subnode
581      */
rend()582     SmNodeArray::reverse_iterator rend() {return maSubNodes.rend();}
583 
584     /**
585      * Get the index of the child node pSubNode.
586      * Returns -1, if pSubNode isn't a subnode of this.
587      * @param pSubNode
588      * @return index of the child node
589      */
590     int IndexOfSubNode(SmNode const * pSubNode);
591 
592     /**
593      * Sets the subnode pNode at nIndex.
594      * If necessary increases the subnodes length.
595      * @param nIndex
596      * @param pNode
597      * @return
598      */
599     void SetSubNode(size_t nIndex, SmNode* pNode);
600 
601 private:
602     /** Sets parent on children of this node */
603     void ClaimPaternity();
604 };
605 
606 
607 /** Abstract base class for all visible node
608  *
609  * Nodes that doesn't derivate from this class doesn't draw anything, but their
610  * children.
611  */
612 class SmVisibleNode : public SmNode
613 {
614 protected:
SmVisibleNode(SmNodeType eNodeType,const SmToken & rNodeToken)615     SmVisibleNode(SmNodeType eNodeType, const SmToken &rNodeToken)
616     :   SmNode(eNodeType, rNodeToken) {}
617 
618 public:
619 
620     /**
621      * Checks node visibility.
622      * Returns true if this is an instance of SmVisibleNode's subclass, false otherwise.
623      * @return node visibility
624      */
625     virtual bool        IsVisible() const override;
626 
627     /**
628      * Gets the number of subnodes.
629      * @return number of subnodes
630      */
631     virtual size_t      GetNumSubNodes() const override;
632 
633     /**
634      * Gets the subnode of index nIndex.
635      * @param nIndex
636      * @return subnode of index nIndex
637      */
638     using   SmNode::GetSubNode;
639     virtual SmNode *    GetSubNode(size_t nIndex) override;
640 };
641 
642 
643 class SmGraphicNode : public SmVisibleNode
644 {
645 protected:
SmGraphicNode(SmNodeType eNodeType,const SmToken & rNodeToken)646     SmGraphicNode(SmNodeType eNodeType, const SmToken &rNodeToken)
647     :   SmVisibleNode(eNodeType, rNodeToken) {}
648 
649 public:
650 
651     /**
652      * Appends to rText the node text.
653      * @param rText
654      * @return
655      */
656     virtual void  GetAccessibleText( OUStringBuffer &rText ) const override;
657 };
658 
659 
660 /** Draws a rectangle
661  *
662  * Used for drawing the line in the OVER and OVERSTRIKE commands.
663  */
664 class SmRectangleNode final : public SmGraphicNode
665 {
666     Size maToSize;
667 
668 public:
SmRectangleNode(const SmToken & rNodeToken)669     explicit SmRectangleNode(const SmToken &rNodeToken)
670         : SmGraphicNode(SmNodeType::Rectangle, rNodeToken)
671     {}
672 
673     //visual stuff TODO comment
674     virtual void AdaptToX(OutputDevice &rDev, sal_uLong nWidth) override;
675     virtual void AdaptToY(OutputDevice &rDev, sal_uLong nHeight) override;
676 
677     /**
678      * Prepares the SmRect to render.
679      * @param rDev
680      * @param rFormat
681      * @return
682      */
683     virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
684 
685     /**
686      * Accept a visitor.
687      * Calls the method for this class on the visitor.
688      * @param pVisitor
689      * @return
690      */
691     void Accept(SmVisitor* pVisitor) override;
692 };
693 
694 
695 /** Polygon line node
696  *
697  * Used to draw the slash of the WIDESLASH command by SmBinDiagonalNode.
698  */
699 class SmPolyLineNode final : public SmGraphicNode
700 {
701     tools::Polygon maPoly;
702     Size maToSize;
703     tools::Long mnWidth;
704 
705 public:
706     explicit SmPolyLineNode(const SmToken &rNodeToken);
707 
708     /**
709      * Gets the width of the rect.
710      * @return width
711      */
GetWidth() const712     tools::Long GetWidth() const { return mnWidth; }
713 
714     /**
715      * Gets the polygon to draw the node.
716      * @return polygon
717      */
GetPolygon()718     tools::Polygon &GetPolygon()  { return maPoly; }
719 
720     //visual stuff TODO comment
721     virtual void AdaptToX(OutputDevice &rDev, sal_uLong nWidth) override;
722     virtual void AdaptToY(OutputDevice &rDev, sal_uLong nHeight) override;
723 
724     /**
725      * Prepares the SmRect to render.
726      * @param rDev
727      * @param rFormat
728      * @return
729      */
730     virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
731 
732     /**
733      * Accept a visitor.
734      * Calls the method for this class on the visitor.
735      * @param pVisitor
736      * @return
737      */
738     void Accept(SmVisitor* pVisitor) override;
739 };
740 
741 
742 /** Text node
743  *
744  * @remarks This class also serves as baseclass for all nodes that contains text.
745  */
746 class SmTextNode : public SmVisibleNode
747 {
748     OUString   maText;
749     sal_uInt16 mnFontDesc;
750     /** Index within text where the selection starts
751      * @remarks Only valid if SmNode::IsSelected() is true
752      */
753     sal_Int32  mnSelectionStart;
754     /** Index within text where the selection ends
755      * @remarks Only valid if SmNode::IsSelected() is true
756      */
757     sal_Int32  mnSelectionEnd;
758 
759 protected:
760     SmTextNode(SmNodeType eNodeType, const SmToken &rNodeToken, sal_uInt16 nFontDescP );
761 
762 public:
763     SmTextNode(const SmToken &rNodeToken, sal_uInt16 nFontDescP );
764 
765     /**
766      * Returns the font type being used (text, variable, symbol, ...).
767      * @return font type
768      */
GetFontDesc() const769     sal_uInt16 GetFontDesc() const { return mnFontDesc; }
770 
771     /**
772      * Sets the node text to rText.
773      * @param rText
774      * @return
775      */
SetText(const OUString & rText)776     void SetText(const OUString &rText) { maText = rText; }
777 
778     /**
779      * Gets the node text.
780      * @return node text
781      */
GetText() const782     const OUString & GetText() const { return maText; }
GetText()783           OUString & GetText()       { return maText; }
784 
785     /**
786      * Change the text of this node, including the underlying token to rText.
787      * @param rText
788      * @return
789      */
790     void ChangeText(const OUString &rText);
791 
792     /**
793      * Try to guess the correct FontDesc, used during visual editing
794      * @return
795      */
796     void AdjustFontDesc();
797 
798     /**
799      * Index within GetText() where the selection starts.
800      * @remarks Only valid of SmNode::IsSelected() is true.
801      * @return index.
802      */
GetSelectionStart() const803     sal_Int32 GetSelectionStart() const { return mnSelectionStart; }
804 
805     /**
806      * Index within GetText() where the selection ends.
807      * @remarks Only valid of SmNode::IsSelected() is true.
808      * @return index.
809      */
GetSelectionEnd() const810     sal_Int32 GetSelectionEnd() const  {return mnSelectionEnd; }
811 
812     /**
813      * Sets the index within GetText() where the selection starts to index.
814      * @param index
815      * @return
816      */
SetSelectionStart(sal_Int32 index)817     void SetSelectionStart(sal_Int32 index) {mnSelectionStart = index;}
818 
819     /**
820      * Sets the index within GetText() where the selection ends to index.
821      * @param index
822      * @return
823      */
SetSelectionEnd(sal_Int32 index)824     void SetSelectionEnd(sal_Int32 index) {mnSelectionEnd = index;}
825 
826     /**
827      * Prepare preliminary settings about font and text
828      * (e.g. maFace, meRectHorAlign, mnFlags, mnAttributes, etc.)
829      * @param rFormat
830      * @param rDocShell
831      * @param nDepth
832      * @return
833      */
834     virtual void Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell,
835                          int nDepth) override;
836 
837     /**
838      * Prepares the SmRect to render.
839      * @param rDev
840      * @param rFormat
841      * @return
842      */
843     virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
844 
845     /**
846      * Appends to rText the node text.
847      * @param rText
848      * @return
849      */
850     virtual void  GetAccessibleText( OUStringBuffer &rText ) const override;
851 
852     /**
853      * Accept a visitor.
854      * Calls the method for this class on the visitor.
855      * @param pVisitor
856      * @return
857      */
858     void Accept(SmVisitor* pVisitor) override;
859 
860     /**
861      * Converts the character from StarMath's private area symbols to a matching Unicode
862      * character, if necessary. To be used when converting GetText() to a normal text.
863      * @param nIn
864      * @return unicode char
865      */
866     static sal_Unicode ConvertSymbolToUnicode(sal_Unicode nIn);
867 };
868 
869 
870 /** Special node for user defined characters
871  *
872  * Node used for pre- and user-defined characters from:
873  * officecfg/registry/data/org/openoffice/Office/Math.xcu
874  *
875  * This is just single characters, I think.
876  */
877 class SmSpecialNode : public SmTextNode
878 {
879 protected:
880     SmSpecialNode(SmNodeType eNodeType, const SmToken &rNodeToken, sal_uInt16 _nFontDesc);
881 
882 public:
883     explicit SmSpecialNode(const SmToken &rNodeToken);
884 
885     /**
886      * Prepare preliminary settings about font and text
887      * (e.g. maFace, meRectHorAlign, mnFlags, mnAttributes, etc.)
888      * @param rFormat
889      * @param rDocShell
890      * @param nDepth
891      * @return
892      */
893     virtual void Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell,
894                          int nDepth) override;
895 
896     /**
897      * Prepares the SmRect to render.
898      * @param rDev
899      * @param rFormat
900      * @return
901      */
902     virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
903 
904     /**
905      * Accept a visitor.
906      * Calls the method for this class on the visitor.
907      * @param pVisitor
908      * @return
909      */
910     void Accept(SmVisitor* pVisitor) override;
911 };
912 
913 
914 /** Glyph node for custom operators
915  *
916  * This node is used with commands: oper, uoper and boper.
917  * E.g. in "A boper op B", "op" will be an instance of SmGlyphSpecialNode.
918  * "boper" simply interprets "op", the following token, as a binary operator.
919  * The command "uoper" interprets the following token as unary operator.
920  * For these commands an instance of SmGlyphSpecialNode is used for the
921  * operator token, following the command.
922  */
923 class SmGlyphSpecialNode final : public SmSpecialNode
924 {
925 public:
SmGlyphSpecialNode(const SmToken & rNodeToken)926     explicit SmGlyphSpecialNode(const SmToken &rNodeToken)
927         : SmSpecialNode(SmNodeType::GlyphSpecial, rNodeToken, FNT_MATH)
928     {}
929 
930     /**
931      * Prepares the SmRect to render.
932      * @param rDev
933      * @param rFormat
934      * @return
935      */
936     virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
937 
938     /**
939      * Accept a visitor.
940      * Calls the method for this class on the visitor.
941      * @param pVisitor
942      * @return
943      */
944     void Accept(SmVisitor* pVisitor) override;
945 };
946 
947 
948 /** Math symbol node
949  *
950  * Use for math symbols such as plus, minus and integral in the INT command.
951  */
952 class SmMathSymbolNode : public SmSpecialNode
953 {
954 protected:
SmMathSymbolNode(SmNodeType eNodeType,const SmToken & rNodeToken)955     SmMathSymbolNode(SmNodeType eNodeType, const SmToken &rNodeToken)
956     :   SmSpecialNode(eNodeType, rNodeToken, FNT_MATH)
957     {
958         SetText(GetToken().cMathChar);
959     }
960 
961 public:
962     explicit SmMathSymbolNode(const SmToken &rNodeToken);
963 
964     //visual stuff TODO comment
965     virtual void AdaptToX(OutputDevice &rDev, sal_uLong nWidth) override;
966     virtual void AdaptToY(OutputDevice &rDev, sal_uLong nHeight) override;
967 
968     /**
969      * Prepare preliminary settings about font and text
970      * (e.g. maFace, meRectHorAlign, mnFlags, mnAttributes, etc.)
971      * @param rFormat
972      * @param rDocShell
973      * @param nDepth
974      * @return
975      */
976     virtual void Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell,
977                          int nDepth) override;
978 
979     /**
980      * Prepares the SmRect to render.
981      * @param rDev
982      * @param rFormat
983      * @return
984      */
985     virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
986 
987     /**
988      * Accept a visitor.
989      * Calls the method for this class on the visitor.
990      * @param pVisitor
991      * @return
992      */
993     void Accept(SmVisitor* pVisitor) override;
994 };
995 
996 
997 /** Math Identifier
998  *
999  * This behaves essentially the same as SmMathSymbolNode and is only used to
1000  * represent math symbols that should be exported as <mi> elements rather than
1001  * <mo> elements.
1002  */
1003 class SmMathIdentifierNode final : public SmMathSymbolNode
1004 {
1005 public:
SmMathIdentifierNode(const SmToken & rNodeToken)1006     explicit SmMathIdentifierNode(const SmToken &rNodeToken)
1007         : SmMathSymbolNode(SmNodeType::MathIdent, rNodeToken) {}
1008 };
1009 
1010 
1011 /** Root symbol node
1012  *
1013  * Root symbol node used by SmRootNode to create the root symbol, in front of
1014  * the line with the line above. I don't think this node should be used for
1015  * anything else.
1016  */
1017 class SmRootSymbolNode final : public SmMathSymbolNode
1018 {
1019     sal_uLong mnBodyWidth;  // width of body (argument) of root sign
1020 
1021 public:
SmRootSymbolNode(const SmToken & rNodeToken)1022     explicit SmRootSymbolNode(const SmToken &rNodeToken)
1023         : SmMathSymbolNode(SmNodeType::RootSymbol, rNodeToken)
1024         , mnBodyWidth(0) { }
1025 
1026     /**
1027      * Gets the body width.
1028      * Allows to know how long is the root and paint it.
1029      * @return body width
1030      */
GetBodyWidth() const1031     sal_uLong GetBodyWidth() const {return mnBodyWidth;};
1032 
1033     //visual stuff TODO comment
1034     virtual void AdaptToX(OutputDevice &rDev, sal_uLong nHeight) override;
1035     virtual void AdaptToY(OutputDevice &rDev, sal_uLong nHeight) override;
1036 
1037     /**
1038      * Accept a visitor.
1039      * Calls the method for this class on the visitor.
1040      * @param pVisitor
1041      * @return
1042      */
1043     void Accept(SmVisitor* pVisitor) override;
1044 };
1045 
1046 
1047 /** Place node
1048  *
1049  * Used to create the <?> command, that denotes place where something can be
1050  * written.
1051  * It is drawn as a square with a shadow.
1052  */
1053 class SmPlaceNode final : public SmMathSymbolNode
1054 {
1055 public:
SmPlaceNode(const SmToken & rNodeToken)1056     explicit SmPlaceNode(const SmToken &rNodeToken)
1057         : SmMathSymbolNode(SmNodeType::Place, rNodeToken) { }
SmPlaceNode()1058     SmPlaceNode() : SmMathSymbolNode(SmNodeType::Place, SmToken(TPLACE, MS_PLACE, u"<?>"_ustr)) { };
1059 
1060     /**
1061      * Prepare preliminary settings about font and text
1062      * (e.g. maFace, meRectHorAlign, mnFlags, mnAttributes, etc.)
1063      * @param rFormat
1064      * @param rDocShell
1065      * @param nDepth
1066      * @return
1067      */
1068     virtual void Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell,
1069                          int nDepth) override;
1070 
1071     /**
1072      * Prepares the SmRect to render.
1073      * @param rDev
1074      * @param rFormat
1075      * @return
1076      */
1077     virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1078 
1079     /**
1080      * Accept a visitor.
1081      * Calls the method for this class on the visitor.
1082      * @param pVisitor
1083      * @return
1084      */
1085     void Accept(SmVisitor* pVisitor) override;
1086 };
1087 
1088 
1089 /** Error node, for parsing errors
1090  *
1091  * This node is used for parsing errors and draws a questionmark turned upside
1092  * down (inverted question mark).
1093  */
1094 class SmErrorNode final : public SmMathSymbolNode
1095 {
1096 public:
SmErrorNode(const SmToken & rNodeToken)1097     explicit SmErrorNode(const SmToken &rNodeToken)
1098                 : SmMathSymbolNode(SmNodeType::Error, rNodeToken) { SetText(OUString(MS_ERROR)); }
1099 
1100     /**
1101      * Prepare preliminary settings about font and text
1102      * (e.g. maFace, meRectHorAlign, mnFlags, mnAttributes, etc.)
1103      * @param rFormat
1104      * @param rDocShell
1105      * @param nDepth
1106      * @return
1107      */
1108     virtual void Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell,
1109                          int nDepth) override;
1110 
1111     /**
1112      * Prepares the SmRect to render.
1113      * @param rDev
1114      * @param rFormat
1115      * @return
1116      */
1117     virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1118 
1119     /**
1120      * Accept a visitor.
1121      * Calls the method for this class on the visitor.
1122      * @param pVisitor
1123      * @return
1124      */
1125     void Accept(SmVisitor* pVisitor) override;
1126 };
1127 
1128 
1129 /** Table node
1130  *
1131  * This is the root node for the formula tree. This node is also used for the
1132  * STACK and BINOM commands. When used for root node, its
1133  * children are instances of SmLineNode, and in some obscure cases the child
1134  * can be an instance of SmExpressionNode, mainly when errors occur.
1135  */
1136 class SmTableNode final : public SmStructureNode
1137 {
1138     tools::Long mnFormulaBaseline;
1139 public:
SmTableNode(const SmToken & rNodeToken)1140     explicit SmTableNode(const SmToken &rNodeToken)
1141         : SmStructureNode(SmNodeType::Table, rNodeToken)
1142         , mnFormulaBaseline(0) { }
1143 
1144     virtual const SmNode * GetLeftMost() const override;
1145 
1146     /**
1147      * Prepares the SmRect to render.
1148      * @param rDev
1149      * @param rFormat
1150      * @return
1151      */
1152     virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1153 
1154     /**
1155      * Gets the formula baseline.
1156      * @return formula baseline
1157      */
1158     tools::Long GetFormulaBaseline() const;
1159 
1160     /**
1161      * Accept a visitor.
1162      * Calls the method for this class on the visitor.
1163      * @param pVisitor
1164      * @return
1165      */
1166     void Accept(SmVisitor* pVisitor) override;
1167 };
1168 
1169 
1170 /** A line
1171  *
1172  * Used as child of SmTableNode when the SmTableNode is the root node of the
1173  * formula tree.
1174  */
1175 class SmLineNode : public SmStructureNode
1176 {
1177     bool mbUseExtraSpaces;
1178 
1179 protected:
SmLineNode(SmNodeType eNodeType,const SmToken & rNodeToken)1180     SmLineNode(SmNodeType eNodeType, const SmToken &rNodeToken)
1181         : SmStructureNode(eNodeType, rNodeToken)
1182         , mbUseExtraSpaces(true) { }
1183 
1184 public:
SmLineNode(const SmToken & rNodeToken)1185     explicit SmLineNode(const SmToken &rNodeToken)
1186         : SmStructureNode(SmNodeType::Line, rNodeToken)
1187         , mbUseExtraSpaces(true) { }
1188 
1189     /**
1190      * Sets if it going to use extra spaces.
1191      * It is used to set if there has to be space between node while rendering.
1192      * By default it is true.
1193      * @param bVal
1194      * @return
1195      */
SetUseExtraSpaces(bool bVal)1196     void  SetUseExtraSpaces(bool bVal) { mbUseExtraSpaces = bVal; }
1197 
1198     /**
1199      * Checks if it is using extra spaces.
1200      * It is used for calculating space between nodes when rendering.
1201      * By default it is true.
1202      * @return is using extra spaces
1203      */
IsUseExtraSpaces() const1204     bool  IsUseExtraSpaces() const { return mbUseExtraSpaces; };
1205 
1206     /**
1207      * Prepare preliminary settings about font and text
1208      * (e.g. maFace, meRectHorAlign, mnFlags, mnAttributes, etc.)
1209      * @param rFormat
1210      * @param rDocShell
1211      * @param nDepth
1212      * @return
1213      */
1214     virtual void Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell,
1215                          int nDepth) override;
1216 
1217     /**
1218      * Prepares the SmRect to render.
1219      * @param rDev
1220      * @param rFormat
1221      * @return
1222      */
1223     virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1224 
1225     /**
1226      * Accept a visitor.
1227      * Calls the method for this class on the visitor.
1228      * @param pVisitor
1229      * @return
1230      */
1231     void Accept(SmVisitor* pVisitor) override;
1232 };
1233 
1234 
1235 /** Expression node
1236  *
1237  * Used whenever you have an expression such as "A OVER {B + C}", here there is
1238  * an expression node that allows "B + C" to be the denominator of the
1239  * SmBinVerNode, that the OVER command creates.
1240  */
1241 class SmExpressionNode final : public SmLineNode
1242 {
1243 public:
SmExpressionNode(const SmToken & rNodeToken)1244     explicit SmExpressionNode(const SmToken &rNodeToken)
1245         : SmLineNode(SmNodeType::Expression, rNodeToken) { }
1246 
1247     /**
1248      * Prepares the SmRect to render.
1249      * @param rDev
1250      * @param rFormat
1251      * @return
1252      */
1253     virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1254 
1255     /**
1256      * Accept a visitor.
1257      * Calls the method for this class on the visitor.
1258      * @param pVisitor
1259      * @return
1260      */
1261     void Accept(SmVisitor* pVisitor) override;
1262 };
1263 
1264 
1265 /** Unary horizontal node
1266  *
1267  * The same as SmBinHorNode except this is for unary operators.
1268  */
1269 class SmUnHorNode final : public SmStructureNode
1270 {
1271 public:
SmUnHorNode(const SmToken & rNodeToken)1272     explicit SmUnHorNode(const SmToken &rNodeToken)
1273         : SmStructureNode(SmNodeType::UnHor, rNodeToken, 2) { }
1274 
1275     /**
1276      * Prepares the SmRect to render.
1277      * @param rDev
1278      * @param rFormat
1279      * @return
1280      */
1281     virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1282 
1283     /**
1284      * Accept a visitor.
1285      * Calls the method for this class on the visitor.
1286      * @param pVisitor
1287      * @return
1288      */
1289     void Accept(SmVisitor* pVisitor) override;
1290 };
1291 
1292 
1293 /** Root node
1294  *
1295  * Used for create square roots and other roots, example:
1296  * \f$ \sqrt[\mbox{[Argument]}]{\mbox{[Body]}} \f$.
1297  *
1298  * Children:<BR>
1299  * 0: Argument (optional)<BR>
1300  * 1: Symbol (instance of SmRootSymbolNode)<BR>
1301  * 2: Body<BR>
1302  * Where argument is optional and may be NULL.
1303  */
1304 class SmRootNode final : public SmStructureNode
1305 {
1306 public:
SmRootNode(const SmToken & rNodeToken)1307     explicit SmRootNode(const SmToken &rNodeToken)
1308         : SmStructureNode(SmNodeType::Root, rNodeToken, 3) { }
1309 
1310     /**
1311      * Prepares the SmRect to render.
1312      * @param rDev
1313      * @param rFormat
1314      * @return
1315      */
1316     virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1317 
1318     /**
1319      * Accept a visitor.
1320      * Calls the method for this class on the visitor.
1321      * @param pVisitor
1322      * @return
1323      */
1324     void Accept(SmVisitor* pVisitor) override;
1325 
1326     /**
1327      * Returns the node containing the data of the order of the root.
1328      * @return order data
1329      */
Argument() const1330     const SmNode* Argument() const { return const_cast<SmRootNode *>(this)->Argument(); }
Argument()1331           SmNode* Argument()       { assert( GetNumSubNodes() == 3 ); return GetSubNode( 0 ); }
1332 
1333     /**
1334      * Returns the node containing the data of the character used for the root.
1335      * @return symbol data
1336      */
Symbol() const1337     const SmRootSymbolNode* Symbol() const { return const_cast<SmRootNode *>(this)->Symbol(); }
Symbol()1338           SmRootSymbolNode* Symbol()       { assert( GetNumSubNodes() == 3 );
1339                                              assert( GetSubNode( 1 )->GetType()
1340                                                         == SmNodeType::RootSymbol );
1341                                              return static_cast< SmRootSymbolNode* >
1342                                                 ( GetSubNode( 1 )); }
1343 
1344     /**
1345      * Returns the node containing the data inside the root.
1346      * @return body data
1347      */
Body() const1348     const SmNode* Body() const { return const_cast<SmRootNode *>(this)->Body(); }
Body()1349           SmNode* Body()       { assert( GetNumSubNodes() == 3 ); return GetSubNode( 2 ); }
1350 
1351 };
1352 
1353 
1354 /** Binary horizontal node
1355  *
1356  * This node is used for binary operators. In a formula such as "A + B".
1357  *
1358  * Children:<BR>
1359  * 0: Left operand<BR>
1360  * 1: Binary operator<BR>
1361  * 2: Right operand<BR>
1362  *
1363  * None of the children may be NULL.
1364  */
1365 class SmBinHorNode final : public SmStructureNode
1366 {
1367 public:
SmBinHorNode(const SmToken & rNodeToken)1368     explicit SmBinHorNode(const SmToken &rNodeToken)
1369         : SmStructureNode(SmNodeType::BinHor, rNodeToken, 3) { }
1370 
1371     /**
1372      * Prepares the SmRect to render.
1373      * @param rDev
1374      * @param rFormat
1375      * @return
1376      */
1377     virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1378 
1379     /**
1380      * Accept a visitor.
1381      * Calls the method for this class on the visitor.
1382      * @param pVisitor
1383      * @return
1384      */
1385     void Accept(SmVisitor* pVisitor) override;
1386 
1387     /**
1388      * Returns the node containing the data of the binary operator.
1389      * @return symbol data
1390      */
Symbol() const1391     const SmNode* Symbol() const { return const_cast<SmBinHorNode *>(this)->Symbol(); }
Symbol()1392           SmNode* Symbol()       { assert( GetNumSubNodes() == 3 ); return GetSubNode( 1 ); }
1393 
1394     /**
1395      * Returns the node containing the data of the left operand.
1396      * @return left operand data
1397      */
LeftOperand() const1398     const SmNode* LeftOperand() const { return const_cast<SmBinHorNode *>(this)->LeftOperand(); }
LeftOperand()1399           SmNode* LeftOperand()       { assert( GetNumSubNodes() == 3 ); return GetSubNode( 0 ); }
1400 
1401     /**
1402      * Returns the node containing the data of the right operand.
1403      * @return right operand data
1404      */
RightOperand() const1405     const SmNode* RightOperand() const { return const_cast<SmBinHorNode *>(this)->RightOperand(); }
RightOperand()1406           SmNode* RightOperand()       { assert( GetNumSubNodes() == 3 ); return GetSubNode( 2 ); }
1407 };
1408 
1409 
1410 /** Binary horizontal node
1411  *
1412  * This node is used for creating the OVER command, consider the formula:
1413  * "numerator OVER denominator", which looks like
1414  * \f$ \frac{\mbox{numerator}}{\mbox{denominator}} \f$
1415  *
1416  * Children:<BR>
1417  * 0: Numerator<BR>
1418  * 1: Line (instance of SmRectangleNode)<BR>
1419  * 2: Denominator<BR>
1420  * None of the children may be NULL.
1421  */
1422 class SmBinVerNode final : public SmStructureNode
1423 {
1424 public:
SmBinVerNode(const SmToken & rNodeToken)1425     explicit SmBinVerNode(const SmToken &rNodeToken)
1426         : SmStructureNode(SmNodeType::BinVer, rNodeToken, 3) { }
1427 
1428     virtual const SmNode * GetLeftMost() const override;
1429 
1430     /**
1431      * Prepares the SmRect to render.
1432      * @param rDev
1433      * @param rFormat
1434      * @return
1435      */
1436     virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1437 
1438     /**
1439      * Accept a visitor.
1440      * Calls the method for this class on the visitor.
1441      * @param pVisitor
1442      * @return
1443      */
1444     void Accept(SmVisitor* pVisitor) override;
1445 };
1446 
1447 
1448 /** Binary diagonal node
1449  *
1450  * Used for implementing the WIDESLASH command, example: "A WIDESLASH B".
1451  *
1452  * Children:<BR>
1453  * 0: Left operand<BR>
1454  * 1: right operand<BR>
1455  * 2: Line (instance of SmPolyLineNode).<BR>
1456  * None of the children may be NULL.
1457  */
1458 class SmBinDiagonalNode final : public SmStructureNode
1459 {
1460     bool mbAscending;
1461 
1462     /**
1463      * Returns the position and size of the diagonal line by reference.
1464      * @param rPos
1465      * @param rSize
1466      * @param rDiagPoint
1467      * @param fAngleDeg
1468      * @return position and size of the diagonal line
1469      */
1470     void GetOperPosSize(Point &rPos, Size &rSize, const Point &rDiagPoint, double fAngleDeg) const;
1471 
1472 public:
SmBinDiagonalNode(const SmToken & rNodeToken)1473     explicit SmBinDiagonalNode(const SmToken &rNodeToken)
1474         : SmStructureNode(SmNodeType::BinDiagonal, rNodeToken, 3)
1475         , mbAscending(false) { }
1476 
1477     /**
1478      * Checks if it is of ascending type.
1479      * Ascending:
1480      *     / b
1481      *    /
1482      * a /
1483      * Descending:
1484      * a \
1485      *    \
1486      *     \ b
1487      * @return ascending.
1488      */
IsAscending() const1489     bool    IsAscending() const { return mbAscending; }
1490 
1491     /**
1492      * Sets if the wideslash is ascending to bVal.
1493      * @param bVal
1494      * @return
1495      */
SetAscending(bool bVal)1496     void    SetAscending(bool bVal)  { mbAscending = bVal; }
1497 
1498     /**
1499      * Prepares the SmRect to render.
1500      * @param rDev
1501      * @param rFormat
1502      * @return
1503      */
1504     virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1505 
1506     /**
1507      * Accept a visitor.
1508      * Calls the method for this class on the visitor.
1509      * @param pVisitor
1510      * @return
1511      */
1512     void Accept(SmVisitor* pVisitor) override;
1513 };
1514 
1515 
1516 /** Enum used to index sub-/supscripts in the 'maSubNodes' array
1517  * in 'SmSubSupNode'
1518  *
1519  * See graphic for positions at char:
1520  *
1521  * \code
1522  *      CSUP
1523  *
1524  * LSUP H  H RSUP
1525  *      H  H
1526  *      HHHH
1527  *      H  H
1528  * LSUB H  H RSUB
1529  *
1530  *      CSUB
1531  * \endcode
1532  */
1533 enum SmSubSup
1534 {   CSUB, CSUP, RSUB, RSUP, LSUB, LSUP
1535 };
1536 
1537 /** numbers of entries in the above enum (that is: the number of possible
1538  * sub-/supscripts)
1539  */
1540 #define SUBSUP_NUM_ENTRIES 6
1541 
1542 /** Super- and subscript node
1543  *
1544  * Used for creating super- and subscripts for commands such as:
1545  * "^", "_", "lsup", "lsub", "csup" and "csub".
1546  * Example: "A^2" which looks like: \f$ A^2 \f$
1547  *
1548  * This node is also used for creating limits on SmOperNode, when
1549  * "FROM" and "TO" commands are used with "INT", "SUM" or similar.
1550  *
1551  * Children of this node can be enumerated using the SmSubSup enum.
1552  * Please note that children may be NULL, except for the body.
1553  * It is recommended that you access children using GetBody() and
1554  * GetSubSup().
1555  */
1556 class SmSubSupNode final : public SmStructureNode
1557 {
1558     bool mbUseLimits;
1559 
1560 public:
SmSubSupNode(const SmToken & rNodeToken)1561     explicit SmSubSupNode(const SmToken &rNodeToken)
1562         : SmStructureNode(SmNodeType::SubSup, rNodeToken, 1 + SUBSUP_NUM_ENTRIES)
1563         , mbUseLimits(false) { }
1564 
1565     /**
1566      * Returns the node with the data of what has to be superindex or subindex.
1567      * @return body data
1568      */
GetBody() const1569     const SmNode * GetBody() const { return const_cast<SmSubSupNode *>(this)->GetBody(); }
GetBody()1570           SmNode * GetBody()       { return GetSubNode(0); }
1571 
1572     /**
1573      * Checks if it is going to be used for a limit.
1574      * Example lim from { x toward 0 } { {sin x}over x } = 1
1575      * @return is a limit
1576      */
IsUseLimits() const1577     bool  IsUseLimits() const { return mbUseLimits; };
1578 
1579     /**
1580      * Sets if it is going to be used for a limit to bVal.
1581      * @param bVal
1582      * @return
1583      */
SetUseLimits(bool bVal)1584     void  SetUseLimits(bool bVal) { mbUseLimits = bVal; }
1585 
1586     /**
1587      * Gets the node with the data of what has to be superindex or subindex.
1588      * The position to check is given by eSubSup.
1589      * @remarks this method may return NULL.
1590      * @param eSubSup
1591      * @return body data
1592      */
GetSubSup(SmSubSup eSubSup) const1593      const SmNode * GetSubSup(SmSubSup eSubSup) const { return const_cast< SmSubSupNode* >
1594                                                             ( this )->GetSubSup( eSubSup ); }
GetSubSup(SmSubSup eSubSup)1595            SmNode * GetSubSup(SmSubSup eSubSup)       { return GetSubNode(1 + eSubSup); };
1596 
1597     /**
1598      * Sets the node with the data of what has to be superindex or subindex.
1599      * @param pScript
1600      */
SetBody(SmNode * pBody)1601     void SetBody(SmNode* pBody) { SetSubNode(0, pBody); }
1602 
1603      /**
1604      * Sets the node with the data of what has to be superindex or subindex.
1605      * The position to check is given by eSubSup.
1606      * @param eSubSup
1607      * @param pScript
1608      */
SetSubSup(SmSubSup eSubSup,SmNode * pScript)1609     void SetSubSup(SmSubSup eSubSup, SmNode* pScript) { SetSubNode( 1 + eSubSup, pScript); }
1610 
1611     /**
1612      * Prepares the SmRect to render.
1613      * @param rDev
1614      * @param rFormat
1615      * @return
1616      */
1617     virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1618 
1619     /**
1620      * Accept a visitor.
1621      * Calls the method for this class on the visitor.
1622      * @param pVisitor
1623      * @return
1624      */
1625     void Accept(SmVisitor* pVisitor) override;
1626 
1627 };
1628 
1629 
1630 /** Node for brace construction
1631  *
1632  * Used for "lbrace [body] rbrace" and similar constructions.
1633  * Should look like \f$ \{\mbox{[body]}\} \f$
1634  *
1635  * Children:<BR>
1636  * 0: Opening brace<BR>
1637  * 1: Body (usually SmBracebodyNode)<BR>
1638  * 2: Closing brace<BR>
1639  * None of the children can be NULL.
1640  *
1641  * Note that child 1 (Body) is usually SmBracebodyNode, but it can also be e.g. SmExpressionNode.
1642  */
1643 class SmBraceNode final : public SmStructureNode
1644 {
1645 public:
SmBraceNode(const SmToken & rNodeToken)1646     explicit SmBraceNode(const SmToken &rNodeToken)
1647         : SmStructureNode(SmNodeType::Brace, rNodeToken, 3) { }
1648 
1649     /**
1650      * Returns the node containing the data of the opening brace.
1651      * @return opening brace data
1652      */
OpeningBrace() const1653     const SmMathSymbolNode* OpeningBrace() const { return const_cast<SmBraceNode *>
1654                                                        (this)->OpeningBrace(); }
OpeningBrace()1655     SmMathSymbolNode* OpeningBrace()             { assert( GetNumSubNodes() == 3 );
1656                                                    assert( GetSubNode( 0 )->GetType()
1657                                                                == SmNodeType::Math );
1658                                                    return static_cast< SmMathSymbolNode* >
1659                                                        ( GetSubNode( 0 )); }
1660 
1661     /**
1662      * Returns the node containing the data of what is between braces.
1663      * @return body data
1664      */
Body() const1665     const SmNode* Body() const { return const_cast<SmBraceNode *>(this)->Body(); }
Body()1666     SmNode* Body()             { assert( GetNumSubNodes() == 3 ); return GetSubNode( 1 ); }
1667 
1668     /**
1669      * Returns the node containing the data of the closing brace.
1670      * @return closing brace data
1671      */
ClosingBrace() const1672     const SmMathSymbolNode* ClosingBrace() const { return const_cast<SmBraceNode *>
1673                                                        (this)->ClosingBrace(); }
ClosingBrace()1674     SmMathSymbolNode* ClosingBrace()             { assert( GetNumSubNodes() == 3 );
1675                                                    assert( GetSubNode( 2 )->GetType()
1676                                                                == SmNodeType::Math );
1677                                                    return static_cast< SmMathSymbolNode* >
1678                                                        ( GetSubNode( 2 )); }
1679 
1680     /**
1681      * Prepares the SmRect to render.
1682      * @param rDev
1683      * @param rFormat
1684      * @return
1685      */
1686     virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1687 
1688     /**
1689      * Accept a visitor.
1690      * Calls the method for this class on the visitor.
1691      * @param pVisitor
1692      * @return
1693      */
1694     void Accept(SmVisitor* pVisitor) override;
1695 };
1696 
1697 
1698 /** Body of an SmBraceNode
1699  *
1700  * This usually only has one child an SmExpressionNode, however, it can also
1701  * have other children.
1702  * Consider the formula "lbrace [body1] mline [body2] rbrace", looks like:
1703  * \f$ \{\mbox{[body1] | [body2]}\} \f$.
1704  * In this case SmBracebodyNode will have three children, "[body1]", "|" and
1705  * [body2].
1706  */
1707 class SmBracebodyNode final : public SmStructureNode
1708 {
1709     tools::Long mnBodyHeight;
1710 
1711 public:
SmBracebodyNode(const SmToken & rNodeToken)1712     explicit SmBracebodyNode(const SmToken &rNodeToken)
1713         : SmStructureNode(SmNodeType::Bracebody, rNodeToken)
1714         , mnBodyHeight(0) { }
1715 
1716     /**
1717      * Prepares the SmRect to render.
1718      * @param rDev
1719      * @param rFormat
1720      * @return
1721      */
1722     virtual void    Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
GetBodyHeight() const1723     tools::Long GetBodyHeight() const { return mnBodyHeight; }
1724 
1725     /**
1726      * Accept a visitor.
1727      * Calls the method for this class on the visitor.
1728      * @param pVisitor
1729      * @return
1730      */
1731     void Accept(SmVisitor* pVisitor) override;
1732 };
1733 
1734 
1735 /** Node for vertical brace construction
1736  *
1737  * Used to implement commands "[body] underbrace [script]" and
1738  * "[body] overbrace [script]".
1739  * Underbrace should look like this \f$ \underbrace{\mbox{body}}_{\mbox{script}}\f$.
1740  *
1741  * Children:<BR>
1742  * 0: body<BR>
1743  * 1: brace<BR>
1744  * 2: script<BR>
1745  * (None of these children are optional, e.g. they must all be not NULL).
1746  */
1747 class SmVerticalBraceNode final : public SmStructureNode
1748 {
1749 public:
SmVerticalBraceNode(const SmToken & rNodeToken)1750     explicit SmVerticalBraceNode(const SmToken &rNodeToken)
1751     : SmStructureNode(SmNodeType::VerticalBrace, rNodeToken, 3) { }
1752 
1753     /**
1754      * Returns the node containing the data of what the brace is pointing for.
1755      * body { script }
1756      * @return body data
1757      */
Body() const1758     const SmNode* Body() const { return const_cast<SmVerticalBraceNode *>(this)->Body(); }
Body()1759     SmNode* Body()             { assert( GetNumSubNodes() == 3 ); return GetSubNode( 0 ); }
1760 
1761     /**
1762      * Returns the node containing the data of the brace.
1763      * @return brace data
1764      */
Brace() const1765     const SmMathSymbolNode* Brace() const { return const_cast<SmVerticalBraceNode *>
1766                                                 (this)->Brace(); }
Brace()1767           SmMathSymbolNode* Brace()       { assert( GetNumSubNodes() == 3 );
1768                                             assert( GetSubNode( 1 )->GetType()
1769                                                         == SmNodeType::Math );
1770                                             return static_cast< SmMathSymbolNode* >
1771                                                 ( GetSubNode( 1 )); }
1772 
1773     /**
1774      * Returns the node containing the data of what is in the brace.
1775      * body { script }
1776      * @return opening brace data
1777      */
Script() const1778     const SmNode* Script() const { return const_cast<SmVerticalBraceNode *>(this)->Script(); }
Script()1779           SmNode* Script()       { assert( GetNumSubNodes() == 3 ); return GetSubNode( 2 ); }
1780 
1781     /**
1782      * Prepares the SmRect to render.
1783      * @param rDev
1784      * @param rFormat
1785      * @return
1786      */
1787     virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1788 
1789     /**
1790      * Accept a visitor.
1791      * Calls the method for this class on the visitor.
1792      * @param pVisitor
1793      * @return
1794      */
1795     void Accept(SmVisitor* pVisitor) override;
1796 };
1797 
1798 /** Operation Node
1799  *
1800  * Used for commands like SUM, INT and similar.
1801  *
1802  * Children:<BR>
1803  * 0: Operation (instance of SmMathSymbolNode or SmSubSupNode)<BR>
1804  * 1: Body<BR>
1805  * None of the children may be NULL.
1806  *
1807  */
1808 class SmOperNode final : public SmStructureNode
1809 {
1810 public:
SmOperNode(const SmToken & rNodeToken)1811     explicit SmOperNode(const SmToken &rNodeToken)
1812         : SmStructureNode(SmNodeType::Oper, rNodeToken, 2) { }
1813 
1814     /**
1815      * Returns the node with the operator data
1816      * @return operator data
1817      */
GetSymbol() const1818     const SmNode * GetSymbol() const { return const_cast<SmOperNode *>(this)->GetSymbol(); }
1819           SmNode * GetSymbol();
1820 
1821     /**
1822      * Returns the height of the node in base to the symbol
1823      * ( rSymbol contains the operator data )
1824      * and the font format ( rFormat ).
1825      * @param rSymbol
1826      * @param rFormat
1827      * @return node's height
1828      */
1829     tools::Long CalcSymbolHeight(const SmNode &rSymbol, const SmFormat &rFormat) const;
1830 
1831     /**
1832      * Prepares the SmRect to render.
1833      * @param rDev
1834      * @param rFormat
1835      * @return
1836      */
1837     virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1838 
1839     /**
1840      * Accept a visitor.
1841      * Calls the method for this class on the visitor.
1842      * @param pVisitor
1843      * @return
1844      */
1845     void Accept(SmVisitor* pVisitor) override;
1846 };
1847 
1848 
1849 /** Node used for alignment
1850  *
1851  * This node has exactly one child at index 0.
1852  */
1853 class SmAlignNode final : public SmStructureNode
1854 {
1855 public:
SmAlignNode(const SmToken & rNodeToken)1856     explicit SmAlignNode(const SmToken &rNodeToken)
1857         : SmStructureNode(SmNodeType::Align, rNodeToken) { }
1858 
1859     /**
1860      * Prepares the SmRect to render.
1861      * @param rDev
1862      * @param rFormat
1863      * @return
1864      */
1865     virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1866 
1867     /**
1868      * Accept a visitor.
1869      * Calls the method for this class on the visitor.
1870      * @param pVisitor
1871      * @return
1872      */
1873     void Accept(SmVisitor* pVisitor) override;
1874 };
1875 
1876 
1877 /** Attribute node
1878  *
1879  * Used to give an attribute to another node. Used for commands such as:
1880  * UNDERLINE, OVERLINE, OVERSTRIKE, WIDEVEC, WIDEHARPOON, WIDEHAT and WIDETILDE.
1881  *
1882  * Children:<BR>
1883  * 0: Attribute<BR>
1884  * 1: Body<BR>
1885  * None of these may be NULL.
1886  */
1887 class SmAttributeNode final : public SmStructureNode
1888 {
1889 public:
SmAttributeNode(const SmToken & rNodeToken)1890     explicit SmAttributeNode(const SmToken &rNodeToken)
1891         : SmStructureNode(SmNodeType::Attribute, rNodeToken, 2) {}
1892 
1893     /**
1894      * Prepares the SmRect to render.
1895      * @param rDev
1896      * @param rFormat
1897      * @return
1898      */
1899     virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1900 
1901     /**
1902      * Accept a visitor.
1903      * Calls the method for this class on the visitor.
1904      * @param pVisitor
1905      * @return
1906      */
1907     void Accept(SmVisitor* pVisitor) override;
1908 
1909     /**
1910      * Gets the attribute data.
1911      * @return attribute data
1912      */
Attribute() const1913     const SmNode* Attribute() const { return const_cast<SmAttributeNode *>(this)->Attribute(); }
Attribute()1914           SmNode* Attribute()       { assert( GetNumSubNodes() == 2 ); return GetSubNode( 0 ); }
1915 
1916     /**
1917      * Gets the body data ( the nodes affected by the attribute ).
1918      * @return body data
1919      */
Body() const1920     const SmNode* Body() const { return const_cast<SmAttributeNode *>(this)->Body(); }
Body()1921           SmNode* Body()      { assert( GetNumSubNodes() == 2 ); return GetSubNode( 1 ); }
1922 };
1923 
1924 
1925 /** Font node
1926  *
1927  * Used to change the font of its children.
1928  */
1929 class SmFontNode final : public SmStructureNode
1930 {
1931     FontSizeType meSizeType;
1932     Fraction     maFontSize;
1933 
1934 public:
SmFontNode(const SmToken & rNodeToken)1935     explicit SmFontNode(const SmToken &rNodeToken)
1936         : SmStructureNode(SmNodeType::Font, rNodeToken)
1937         , meSizeType(FontSizeType::MULTIPLY)
1938         , maFontSize(1) { }
1939 
1940     /**
1941      * Sets font size to rValue in nType mode.
1942      * Check FontSizeType for details.
1943      * @param rValue
1944      * @param nType
1945      * @return
1946      */
SetSizeParameter(const Fraction & rValue,FontSizeType nType)1947     void SetSizeParameter(const Fraction &rValue, FontSizeType nType)
1948                             { meSizeType = nType; maFontSize = rValue; }
1949 
1950     /**
1951      * Returns the font size.
1952      * @return font size.
1953      */
GetSizeParameter() const1954     const Fraction & GetSizeParameter() const {return maFontSize;}
1955 
1956     /**
1957      * Returns the font size type.
1958      * Check FontSizeType for details.
1959      * @return font size type.
1960      */
GetSizeType() const1961     FontSizeType GetSizeType() const {return meSizeType;}
1962 
1963     /**
1964      * Prepare preliminary settings about font and text
1965      * (e.g. maFace, meRectHorAlign, mnFlags, mnAttributes, etc.)
1966      * @param rFormat
1967      * @param rDocShell
1968      * @param nDepth
1969      * @return
1970      */
1971     virtual void Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell,
1972                          int nDepth) override;
1973 
1974     /**
1975      * Prepares the SmRect to render.
1976      * @param rDev
1977      * @param rFormat
1978      * @return
1979      */
1980     virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
1981 
1982     /**
1983      * Accept a visitor.
1984      * Calls the method for this class on the visitor.
1985      * @param pVisitor
1986      * @return
1987      */
1988     void Accept(SmVisitor* pVisitor) override;
1989 };
1990 
1991 
1992 /** Matrix node
1993  *
1994  * Used to implement the MATRIX command, example:
1995  * "matrix{ 1 # 2 ## 3 # 4}".
1996  */
1997 class SmMatrixNode final : public SmStructureNode
1998 {
1999     sal_uInt16 mnNumRows,
2000                mnNumCols;
2001 
2002 public:
SmMatrixNode(const SmToken & rNodeToken)2003     explicit SmMatrixNode(const SmToken &rNodeToken)
2004         : SmStructureNode(SmNodeType::Matrix, rNodeToken)
2005         , mnNumRows(0)
2006         , mnNumCols(0) { }
2007 
2008     /**
2009      * Gets the number of rows of the matrix.
2010      * @return rows number
2011      */
GetNumRows() const2012     sal_uInt16 GetNumRows() const {return mnNumRows;}
2013 
2014     /**
2015      * Gets the number of columns of the matrix.
2016      * @return columns number
2017      */
GetNumCols() const2018     sal_uInt16 GetNumCols() const {return mnNumCols;}
2019 
2020     /**
2021      * Sets the dimensions of the matrix.
2022      * @param nMatrixRows
2023      * @param nMatrixCols
2024      * @return
2025      */
SetRowCol(sal_uInt16 nMatrixRows,sal_uInt16 nMatrixCols)2026     void SetRowCol(sal_uInt16 nMatrixRows, sal_uInt16 nMatrixCols)
2027                      { mnNumRows = nMatrixRows; mnNumCols = nMatrixCols; }
2028 
2029     virtual const SmNode * GetLeftMost() const override;
2030 
2031     /**
2032      * Prepares the SmRect to render.
2033      * @param rDev
2034      * @param rFormat
2035      * @return
2036      */
2037     virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
2038 
2039     /**
2040      * Accept a visitor.
2041      * Calls the method for this class on the visitor.
2042      * @param pVisitor
2043      * @return
2044      */
2045     void Accept(SmVisitor* pVisitor) override;
2046 };
2047 
2048 
2049 /** Node for whitespace
2050  *
2051  * Used to implement the commands "~" and "`". This node is just a blank space.
2052  */
2053 class SmBlankNode final : public SmGraphicNode
2054 {
2055     sal_uInt16 mnNum;
2056 
2057 public:
SmBlankNode(const SmToken & rNodeToken)2058     explicit SmBlankNode(const SmToken &rNodeToken)
2059         : SmGraphicNode(SmNodeType::Blank, rNodeToken)
2060         , mnNum(0) { }
2061 
2062     void         IncreaseBy(const SmToken &rToken, sal_uInt32 nMultiplyBy = 1);
Clear()2063     void         Clear() { mnNum = 0; }
GetBlankNum() const2064     sal_uInt16   GetBlankNum() const { return mnNum; }
SetBlankNum(sal_uInt16 nNumber)2065     void         SetBlankNum(sal_uInt16 nNumber) { mnNum = nNumber; }
2066 
2067     /**
2068      * Prepare preliminary settings about font and text
2069      * (e.g. maFace, meRectHorAlign, mnFlags, mnAttributes, etc.)
2070      * @param rFormat
2071      * @param rDocShell
2072      * @param nDepth
2073      * @return
2074      */
2075     virtual void Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell,
2076                          int nDepth) override;
2077 
2078     /**
2079      * Prepares the SmRect to render.
2080      * @param rDev
2081      * @param rFormat
2082      * @return
2083      */
2084     virtual void Arrange(OutputDevice &rDev, const SmFormat &rFormat) override;
2085 
2086     /**
2087      * Accept a visitor.
2088      * Calls the method for this class on the visitor.
2089      * @param pVisitor
2090      * @return
2091      */
2092     void Accept(SmVisitor* pVisitor) override;
2093 
2094 };
2095 
2096 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
2097