Changes between Version 7 and Version 8 of TEXT_MODEL_REDESIGN


Ignore:
Timestamp:
03/24/10 15:29:46 (15 years ago)
Author:
kyli
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TEXT_MODEL_REDESIGN

    v7 v8  
    4747 
    4848= Design = 
    49 -TEXT MODEL PART- 
    5049 
    51 The idea of the new text design is to remove the existing stable poses with unstable indexes. 
     50== TEXT MODEL PART == 
     51 
     52 The idea of the new text design is to remove the existing stable poses with unstable indexes. 
     53  
    5254In order to achieve this functionality the following changes have been made: 
    53  * Rename HotIndexInterval in org.sophie2.base.model.text.smart.position package with HotTextInterval. 
    54  *  From org.sophie2.base.model.text.smart.position remove HotInterval and replace all of its usage 
    55  in Sophie with HotTextInterval. 
    56  * Remove HotPos class. 
    57  * Remove HotPos persister class.  
     55 
     56 * Rename HotIndexInterval in org.sophie2.base.model.text.smart.position package to HotTextInterval. 
     57 
     58 *  From org.sophie2.base.model.text.smart.position remove HotInterval and replace its usage with HotTextInterval. 
     59 
     60 * Remove the HotPos class. 
     61 
     62 * Remove the HotPos persister class.  
     63 
    5864 * In HotTextInterval add a comparator for intervals. 
     65 
    5966 * In org.sophie2.base.model.text.smart package add new class named TextUnit - this class represents a 
    6067 single text unit in sophie text. This class is needed mostly to hold the styled value of every single text 
     
    6370   * Add getUnitStyle function in the class to get the unit style. 
    6471   * Add getUnitChar function to get the char. 
     72 
    6573 * In org.sophie2.base.model.text.smart add ImmText interface - the interface of the new sophie text. 
    6674  * Hash getStyledHash() - Returns the styled hash of the text. 
     
    7785  * int getEnd() - Gets the end of the text.  
    7886  * ImmText subText(HotTextInterval interval) - Creates a new sub text of the given text.  
    79  * In ImmHotText class remove all the existing fields and add ImmList<TextUnit> textUnits . 
     87 
     88 * In ImmHotText class remove all the existing fields and add ImmList<TextUnit> textUnits. 
     89 
    8090 * Make the ImmHotText class implement the ImmText interface and implement the functions of the interface. 
    81  * Make HotStyleDef class implement Hashable and intern the HotStyleDef's values(add field with the used styles 
     91 
     92 * Make HotStyleDef class implement Hashable and intern the HotStyleDef's values(add static field with the used styles 
    8293 till now and when creating a new HotStyleDef object if the map contains the object take the containing object 
    8394 else add the object in the map). 
     95 
    8496 * In HotStyleDef class add replaceDerive function that concatenates only the non default values from this  
    8597 style and the given one and constructs a new HotStyleDef with this values. 
     98 
    8699 * In HotStyleDef class add getAllAttr function that returns list of all the CommonAttr's values. 
     100 
    87101 * In CommonAttr add two new values: HotAttr<String> LINK_ATTRIBUTE - represents the link id's for the text and 
    88102 HotAttr<ImmList<String>> ATTACHMENT_ATTRIBUTE - represents the text attachments 
    89103(without text links(anchors and so on)). 
     104 
    90105 * In LinkAttachment class add String linkId attribute - this is a random final value that is unique for every 
    91106 link in the text and is genetared in the constructor of the class. Add a getter method for the value. 
     107 
    92108 * In HotTextResourceR4 class add Key<ImmMap<String, LinkAttachment>> KEY_TEXT_LINK_MAP key that 
    93109 holds all the the text link attachments' ids to the link attachment itself(this is used in the ligics for adding 
    94110 and removing text links). 
    95  * The new logic for adding/removing link is as follows:first applying style to the text with the map consisting 
     111 
     112 * The new logic for adding/removing link is as follows: first applying style to the text with the map consisting 
    96113 of LINK_ATTRIBUTE with value equal to the added link id's(the default LINK_ATTRIBUTE's value if removed), 
    97114 second we change the map of the current hottextresource to a new one(with one added or removed value). 
     115 
    98116 * In TextViewFlow add abstract Prop<ImmMap<HotTextInterval, Attachment>> attachmentMap() - Property, holding map 
    99  of intervals to link attachments. it holds all the links that are not none-refs(it is called attachmentMap 
     117 of intervals to link attachments. It holds all the links that are not none-refs(it is called attachmentMap 
    100118 not linkAttachmentMap because it will hold all the link attachments and the other attachments  in the future). 
     119 
    101120 * In org.sophie2.base.model.text.smart add new utility class ImmTextUtils that has: 
    102121  * ImmText empty() - Creates an empty text. 
     
    111130  * getStyleValue - Retrieves a specific text attribute's value at a specific position of the given text. 
    112131  
    113 -TEXT LAYOUT PART- 
     132== TEXT LAYOUT PART == 
    114133 
     134=== Text Layout === 
     135 
     136 Why should TextLayout be removed from our code: 
     137 
     138 * We only use the nextLayout() method,  get the line metrics and get the text hit info (determine which char hits a concrete Point2D) from it. Drawing with TextLayout is actually problematic, since it causes the baseline zig-zagging problem. Thus we use tons of reflection, which I suppose is not good. 
     139 
     140 * TextLayout is constructed by a LineBreakMeasurer, which demands AttributedCharacterIterator to be made out of the HotText. In the current situation, this could cause some performance problems with large texts and many styles. On the other hand, LineBreakMeasurers need to be cached in order to have better performance (so says the JavaDoc), but they are statefull. So, simultaneous usage is quite undetermined (this could happen with the backgound thread which is used by the lazy layout). 
     141 
     142 What to use instead: 
     143 
     144 * '''Definition''': a TextRun is a sequence of characters with equal styles.  
     145 
     146 * :) 
     147  
     148 * The HotText will provide us the longest possible TextRun, starting from a concrete position. The method would look like this: TextRun getRun(int charIndex); This method will be fast enough with the new HotText design. 
     149 
     150 * TextRuns can be cached, because they are immutable. They hold enough information for creating a Font object (it needs CharSequence and AttributeMap), which can create a GlyphVector. The font can also create FontMetrics, which gives additional information. 
     151 
     152 * For calculating the line height of a paragraph, we get all the text runs from it, retrieve their font metrics and sum the ascent and descent values. Then we return the largest value from these. 
     153 
     154 * For laying out a paragraph text, we get the words one by one and create glyph vectors subsequently, then using their getLogicalBounds methods, we determine the sum of the widths of the vectors. If a vector does not fit in the space left, the whole word will be removed from the segment. If no words are laid out in the current segment, we try to lay out as many text runs as possible. If no runs can be laid out, we split the current TextRun and try again. This logic implements the common line-breaking policy in LineBreakMeasurer, which we currently use. 
     155 
     156 * Drawing a TextRun: the vector generated from the run has getOutline() method, which returns a shape. The run attributes hold the foreground and backgound colors, so we fill the shape with the first and the rest with the second. Note: all the glyph vectors in a paragraph must be drawn on the same baseline offset. The baseline offset for a paragraph can be calculated together with the line height. 
     157 
     158 * Decoration: the Font class can work with Font Family, Font Size, Bold and Italics attributes. Underline and Strikethrough will be implemented by drawing lines respectively on the underline and strikethrough offsets (retrieved from the font metrics). Other decorations (highlights, caret, spellcheck undrelining and others) will be implemented in another task.  
     159 
     160 * Tabbed text: tabs can be calculated when creating the segment layouts. First of all, we must ensure that if the HotText breaks the text runs if a tab is met (e.g. a tab can only be in the end of a run). Next, put a constant in SegmentLayout which defines the max tab width (the logical width). Then we determine the actual tab width with the formula ''tabSize = MAX_TAB_WIDTH - tabXPos % MAX_TAB_WIDTH''. We add the calculated value as an offset between the current glyph vector and the next one. This way, in a rectangular area, the tabbed text will be aligned and will look cool.  
     161 
     162=== Positioning === 
     163 
     164 * Since the HotPos will be removed, HotLayout should not use it. So simply replace all the HotPos-related methods with int-related ones. 
     165 
     166 
     167 
     168== Tests == 
     169 
     170 * We should make all the current text and layout-related tests to work again. 
     171 * New tests: [branches/private/kyli/2344/modules/org.sophie2.base.model.text/src/test/java/org/sophie2/base/model/text/smart/TextPerformanceTest.java Performance test], [branches/private/kyli/2344/modules/org.sophie2.base.model.text/src/test/java/org/sophie2/base/model/text/smart/ImmTextTest.java] 
    115172 
    116173= Implementation =