KOffice – TDE office suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DESIGN 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. The design of kformula
  2. (as we imagine it)
  3. The core of kformula is a tree of element objects that make up the
  4. formula which is beeing edited.
  5. The element tree itself
  6. #######################
  7. BasicElement
  8. ------------
  9. All element classes are derived from this one.
  10. So it provides the interface that is common to all elements.
  11. BasicElement itself is an abstract class. You never want to create
  12. objects from it.
  13. Responsebilities
  14. (This goes for every derived element and therefore for each one.)
  15. - knows its children. Actually BasicElement doesn't have any. But it
  16. already defines that children must be known by their parent.
  17. - knows its bounding rectangle (its size.) The children are included
  18. in this rect. (Only width and height are needed. Positions are
  19. handled by the parent)
  20. //- knows its middle line. (for alignment)
  21. - knows it's zero point for midline (vertical alignment) and
  22. keep open the possibility of negative positions (out of bounding rect)
  23. - draws itself (given a painter); children are drawn, too
  24. - knows all positions where the cursor is allowed to be. (see below)
  25. - knows its parent; The topmost element has no parent; there is a
  26. implicit garantie that the topmost element is always a
  27. SequenceElement.
  28. - can save and load itself. different formates. (see below)
  29. - all children must be a SequenceElement. Except for SequenceElement's
  30. children that might be of any type.
  31. - might have its own color.
  32. - might have its own font size (see below).
  33. SequenceElement from BasicElement
  34. ---------------
  35. Manages a list of children. The children are aligned horizontally at
  36. one middle line. No gaps, no overlaps.
  37. Has no own look. It just draws all its children and is done. Except if
  38. its empty. It looks like an empty space then (i.e. a little square)
  39. Has n+1 valid cursor positions where n is the number of
  40. children. These are before, between and after the children.
  41. May contain any (type of) element as child
  42. except SequenceElements if they contains a SequenceElement they merge
  43. it in the list
  44. They can handle splitting of the sequence to allow "select an put selected item
  45. between parenthesis" i.e. as content child of a delimiterelement)
  46. FormulaElement from SequenceElement
  47. --------------
  48. The only element those parent is null. The root of the element object
  49. tree.
  50. This is the element that is created by the KFormulaDoc and that knows
  51. about it. As every other element knows its parent and therefore the
  52. FormulaElement we get a chance to pass messages to the outside world.
  53. RootElement from BasicElement
  54. -----------
  55. contains two children. content and index. index is optional.
  56. IndexElement from BasicElement
  57. ------------
  58. contains five children. content and four indexes. all indexes are
  59. optional. If there is no index the element might be replaced by its content.
  60. TextElement from BasicElement
  61. -----------
  62. contains one char and no children at all.
  63. Might have its own font and size. But preferes to use a reasonalbe
  64. font and size that are calculated from its parents font and a given
  65. scheme (see below).
  66. DelimiterElement from BasicElement
  67. ----------------
  68. contains one child and draws delimiters around it. You are free to
  69. choose with.
  70. FractionElement from BasicElement
  71. ---------------
  72. 2 children: numerator, denominator
  73. DecorationElement from BasicElement
  74. -----------------
  75. A piece of art. It has one child and decorates it above (or below or
  76. both) with some nice decor. Some decor might be required to be as
  77. width as the content. There is a way to guarantee this.
  78. We could even add yet another child that can optionally be shown at
  79. the other side of the decoration.
  80. SumIntegralElement from BasicElement //PrefixedElement
  81. ------------------
  82. draws all sorts of mathematical symbols with three children. Above,
  83. below (or whereever the indices and limits go)and to the right.
  84. GeometryElement from BasicElement
  85. ---------------
  86. One child.
  87. Draw it at a fixed position relative to parent or absolute.
  88. This is to do dirty things.
  89. This element must not be used, kformula will provide you everything
  90. without the use of this kind of element, any way for strange reasons
  91. you want to do things that are not usually allowed and that are not
  92. typical of a math formula.
  93. [We will decide if implement this element or not]
  94. MatrixElement from BasicElement
  95. -------------
  96. A matrix of children.
  97. With all align stuff, internal borders etc, matrix dots handling (i.e.
  98. those dots or lines that complete the matrix, not well handled in TeX),
  99. etc..
  100. SpaceElement from BasicElement
  101. ------------
  102. No children at all. Provides the facility to insert horizontal spaces
  103. in the formula. (therefore it is similar to TextElement.)
  104. OperatorElement from TextElement
  105. ---------------
  106. The element to be used for all kinds of operators. It needed because
  107. operators require some space before and after and are therefore no
  108. simple text.
  109. They can you pixamps inestead of fonts, the use of pixmaps is needed only
  110. to give the user the possibilty of introduce its strange operator that we
  111. do not provide as a font. There problems with the scalability but we will
  112. include as fonts (or vectorial images) in kformula all TeX operators so we
  113. hope there is no need to use pixamps for a standard use of KFormula
  114. Navigation
  115. ##########
  116. There is a class Cursor that implements a pointer to a valid cursor
  117. position inside the formula structure. Each kformula view needs to
  118. have its own object of this class.
  119. The Cursor class uses the elements facility to travel throught the
  120. structure. (It gives the key to the current element and asks for the
  121. new position.)
  122. If the cursor points into an element this element is said to own the
  123. cursor. There are a few rules that describe how new cursor positions
  124. are calculated given the current key:
  125. - An elements cursor positions are its children. The element might not
  126. own the cursor except when it is owned by one of its children. The
  127. only exception is SequenceElement which has valid cursor positions
  128. before, between and after its children, too.
  129. (Therefore the cursor is always owned by a SequenceElement.)
  130. - Each element's children are ordered. If the cursor leaves one child
  131. the next child it. The direction depends on the key that moved the
  132. cursor. If there is child left the cursor is passed to the parent.
  133. - If the cursor comes from our parent the first or the last child gets
  134. it. Depending on the direction in which the cursor moved.
  135. Please note that because each element knows its own cursor positions
  136. and how to behave, it is possible for each combination of elements to
  137. work together correctly.
  138. Save and Load (Import/Export)
  139. #############################
  140. there are quite a few formats we want to read and write:
  141. Built in:
  142. - native koffice xml
  143. Import/Export filters
  144. - MathML
  145. - C like math strings
  146. - LaTeX
  147. Element templates
  148. #################
  149. example: you can create a template to write limits:
  150. it is a "lim ( )" string over 2 empty elements with an arrows that separe
  151. them
  152. "Look" templates
  153. ################
  154. There need to be templates that tell which font to use, how the sizes
  155. differ among different elements and what spaces are to be
  156. included. (And much more.)
  157. Your only need to choose one of them to get a reasonable good look.
  158. Interface templates
  159. ###################
  160. Decide what TDEAction have to be toolbars,
  161. what element templates must be loaded, what toolbar display....
  162. There will be predefined (sorry for the spelling error) templates for
  163. -General...
  164. -Physics (Vectors , integral, partial derivative etc are preferred..)
  165. -Analysis (Integral and diff equation stuff)
  166. -Geometry (Tensor product etc)
  167. -Chemistry (Arrows, Periodic table external toolbar)
  168. -Computer science (...)
  169. -????
  170. Context sensibility
  171. ###################
  172. We want a formula to look different according to its
  173. surroundings. (Most obviosly according to the available height and/or width.)
  174. It would be great to get something like automatic operator
  175. alignment. So if you type some formulas each on its own line the
  176. assigment operators should be automatically in a column. (If the user
  177. turns this on.)
  178. Fonts and font size (2 ideas)
  179. ###################
  180. 1)
  181. Each element know its font family (also if it is not a text element) so that it
  182. can give this font to its children.
  183. The font size is calculated starting from a global scale factor and appling to it
  184. a local size modifier (like HTML -2, -1,+3,etc..), this also calculate the
  185. QPen width for vector drawn stuff (like root symbol etc) and it gives a scale
  186. factor for pixmap.
  187. 2)
  188. When it comes to drawing we pass a StyleContext to the
  189. FormulaElement. The StyleContext contains the font family to use, the
  190. normal font size, the spaces to include between certain elements and
  191. all sorts of context information that is needed to draw the
  192. formula. As it is passed down the tree it also counts the current level
  193. so it can tell each element the font size it is supposed to use.
  194. The elements use this information to calculate their sizes and to draw
  195. themselves. Each element is allowed to choose different settings for
  196. whatever reason. But if the formula looks ugly then its the elements
  197. blame.
  198. Andrea Rizzi <rizzi@kde.org>
  199. Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>