ImproveMathEquationEditor/SourcesDescription

From Wiki.ooo4kids.org

Jump to: navigation, search

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 ;-)

A Formula is like rectangles, every containing one part of the equation. We'll have to calculate the height of every rectangle, connect each other from the first to the last one, without error (what is not the case yet)

Dependencies

prj/build.lst : first line, starmath depends on svx. svx depends on vcl, but svtools and tools too.

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

Equation debug mode.jpg

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

Inheritance diagram for SmNode (click to enlarge)

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


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)

Positions at char : enums are used to index sub-/supscripts in the 'aSubNodes' array in 'SmSubSupNode'

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 :

There are parsing descriptors too.

There are maybe conversion needed

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).

There are several methods of copying baselines and mid's in ExtendBy function.

Possibilities are :

The class SmRect :

Important methods :

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

Suggestion: add a shortcut for undo/redo (seems to not exist) ?

For instance this part does define the interface for init, deinit, error handling.

IMPORTANT : ArrangeFormula and IsFormulaArranged

IMPORTANT : GetHorAlign, SetHorAlign might play a role in our issue


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, ...

Links

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox