ImproveMathEquationEditor/SourcesDescription
From Wiki.ooo4kids.org
Back to Improve Math Equation Editor
Important: If you use this information, don't forget everything you'll find here is under CC by-sa License, and you must mention your sources in what you write ...
Contents |
Starmath sources (introduction)
Starmath is the only module who has an "human" size in OOo and OOo4Kids source code. That's a good reason to document it ;-)
Dependencies
prj/build.lst : first line, starmath depends on svx. svx depends on vcl, but svtools and tools too.
- svx : the editeng (parsing)
- vcl : for the fonts, the Windows, the frames, the controls, menus, keyboard events, the mouse events, the toolbox (svx itself depends onn drawinglayer ... depending on vcl .. and so on)
- sfx2 (for the shell)
- tools, svtools : other OS agnostic dialog things
Starmath does not depend on Star Writer, but any equation is considered as an abstracted object for sw.
The sources
Headers : starmath/inc : contains the headers ( .hxx ) and the constants declarations ( .hrc )
starmath/source : contains the implementation (.cxx) , and the UI resource files (.src)
Analyze of headers content
As shown in the image above, in a Math formula, everything looks like rectangles unaligned, containing everything. For us, a node will be a point connecting two rectangles, and we will parse the text the user entered, to calculate the rectangles positions.
Essential headers
For our study, those essential headers are: node.hxx, parse.hxx and rect.hxx.
node.hxx
In node.hxx is defined the interface for 27 types of nodes (see the SmNodeType enumeration).
A node can be scaled or not (see enum SmScaleMode)
enum SmNodeType
{
NTABLE, NBRACE, NBRACEBODY, NOPER, NALIGN,
NATTRIBUT, NFONT, NUNHOR, NBINHOR, NBINVER,
NBINDIAGONAL, NSUBSUP, NMATRIX, NPLACE, NTEXT,
NSPECIAL, NGLYPH_SPECIAL, NMATH, NBLANK, NERROR,
NLINE, NEXPRESSION, NPOLYLINE, NROOT, NROOTSYMBOL,
NRECTANGLE, NVERTICAL_BRACE
};
Comments about the inheritance diagram
- class SmNode : inherits of SmRect.
- class SmNodeStructure : inherits of SmNode.
- class SmVisibleNode : inherits of SmNode.
- 16 classes define all the possible structures (see the diagram on left, created with Doxygen).
- a node can be SmVisibleNode or SmNodeStructure.
- an SmVisibleNode can be SmGraphicNode or SmTextNode
As example, a case (letter upper K) where wa added all possibilities, with the name for each (see figure below). The ruls is very simple : c for "center", r for "right", and l for "left". You can add all the possibilities you want, and one csup script, can contain the same scheme recusrively (at some level, the font should become unreadable though)
Some words about debug mode : rebuilding in starmath with the option "debug=not_empty" (e.g. debug=t), and replacing the old stripped libsmm with the brand new fat one, the shapes of the rectangles are all drawn, same for the green lines, providing a "visible" and colored baseline, and mid lines too, for one rectangle, or one character
parse.hxx
The mathematical expression is parsed. Thus, in parse.hxx, we define :
- TokenGroups ( as constants )
- Token types ( as enumeration SmTokenType ) // could be an interesting place to add your own new token ..."
- Token itselves : structure containing all the mandatory information collected/used for the parsing.
There are parsing descriptors too.
- enum SmParseError
- structures containing the Error description ( struct SmErrorDesc )
There are maybe conversion needed
- enumeration SmConvert, with the choice, no conversion, convert Star Office format 4 to Star Office format 5 ... and so on
Class SmParser : contains methods to handle a string, parse it and do something. This class includes a grammar, a get /set Language and some inline methods (probably for performance reasons).
rect.hxx
A file who really desserves to be printed, after a better indentation (to make it readable).
- a rectangle can be either core, italic, lines or middle
- its position can either be (respectively) Left, Right, Top, Bottom, Attribut ( see enum RectPos )
- its horizontal alignment can either be Left, Center or Right ( see enum RectHorAlign )
- its vertical alignment can either be Top, Mid, Bottom, Baseline, Centery, Attribut_hi Attribut_mid or Attribut_lo ( see enum RectVerAlign )
There are several methods of copying baselines and mid's in ExtendBy function.
Possibilities are :
- This (object) ,
- Arg (its argument) => no change for both)
- None (no baseline
- Xor use baseline if existing or copy the argument one if empty ( see enum RectCopyMBL for all)
The class SmRect :
- counts a lot of members, and methods for alignement,
- counts several ctors (several possibilities with SmRect)
- several setters and getters for : (Set/Get)Top, Left Bottom, Right, Center, Width and Height
- several Baseline dedicated functions :
- HasBaseline
- GetBaselineOffset
- Set AlignTop
- (lot of similar methods).
Important methods :
- Point AlignTo
- boolean/setters/getters for baseline
- overloaded ExtendBy methods (no alignment, new alignment, bKeepVertAlignment)
- Inlined new rectangle creation(dedicated operator, for performance reasons, probably)
inline SmRect & SmRect::operator = (const SmRect &rRect)
{
new (this) SmRect(rRect); // placement new
return *this;
}
The above method allows to create a new rectangle attached to the previous one -> tree of rectangles
Second role headers
- action.hxx : SmFormatAction (undo, redo, repeat action)
Suggestion: add a shortcut for undo/redo (seems to not exist) ?
- application.hxx : Math is a whole application itself, including it's own graphic shell. So it is managed as an application.
For instance this part does define the interface for init, deinit, error handling.
- config.hxx : set / get fontname as config property for the font from a fontlist
- dialog.hxx : everything for the dialog, including the UI (checkbox, fixedline ..and so on)
- document.hxx : class SmDocShell + defines the interface for the edited math document itself : InitNew, SaveAs, Load, Draw, GetSize, GetEditEngine, Parse, SetFormat, LoadSymbols, SetEditEngineDefaultFonts ... and so on
IMPORTANT : ArrangeFormula and IsFormulaArranged
- edit.hxx : defines the interface for the edited window ( GetDoc, GetView, GetEditView, GetFocus, LoseFocus, Copy, Paste .. and so on)
- format.hxx : (if I'm not wrong) should calculate the fot size, and the size of brackets, parenthesis ..and everything in the formula
IMPORTANT : GetHorAlign, SetHorAlign might play a role in our issue
- smdll.hxx : Init, Exit, DetectFilter interface when an instance of SmModule is created.
- smmod.hxx : defines SmModule interface for the Starmath application.
SmModule is like to be compared with the <SfxApplication>-subclass ( the one checked by the application framework e.g. rApplication.IsModule() .. ).
Contains the SmLocalizedSymbolData class too. This is the place where the localized symbols are instanciated.
Important methods in this class are : GetState, GetDefaultVirtualDev, GetAppData
The selection toolbox is one of the most visible element ( "Elements of Formula" ) : SmToolboxWindow inherits of SfxFloatingWindow
The SmViewShell inherits of the SfxShell and the
The class SmDocShell inherits of SfxObjectShell, and SfxListener (to add, remove events listeners)
(class SmDocShell : public SfxObjectShell, public SfxListener )
The OutputDevice is a reference (can be a pointer too) to any device for rendering or drawing something : can be a Window, a Printer, ...
