Version 5 (modified by diana, 15 years ago) (diff) |
---|
Analysis
Overview
This task is result from the merge of #2370 (HOT_TEXT_INTERNAL) and #2344 (TEXT_LAYOUT_COMMONS). This is needed because the tasks are too connected to each other.
- The existing stable poses in the sophie text are not easy to work with and require working with text history which is not cheap and fast enough. This task should remove the stable poses from the text.
- The current Hot Layout has several important issues:
- It is not known how will hyphenation be integrated with it;
- Spell check underlining is not currently possible;
- Text links cannot have foreground color;
- Pressing "Tab" inserts 4 spaces, instead of a real tab;
- Performance issues - Segment layouts could not be cached, which means that their redrawing is very slow.
Task requirements
- Remove the HotPos class
- Remove most of the ImmHotText existing code. Keep the recent text functionality and improve the code quality.
- Modify the layout basics, so that
- Tab will be functional;
- Future features (hyphenation, spell check, links foreground) will be achievable;
- Performance will not degrade. If possible, it should be improved.
- In the design section, describe:
- What changes will be made to the layout mechanism;
- What causes theses changes, what will the effect be;
- In the implementation, describe:
- Implementation idea for hyphenation;
- Implementation idea for spell check and foreground highlighting.
Task result
The result should be code.
Implementation idea
- Remove HotPos class(the stable poses) and replace them with unstable text indexes.
- Keep the text styles in every text unit.
- Drop TextLayout, LineBreakMeasurer and AttributedCharacterIterator - use Font instead. This will allow deleting of most of the HotSegmentLayout contents. Several utility methods will also be deleted. Hooray :)
Related
(Add links to related tasks that could be useful or helpful.)
How to demo
- Run all the text related tests in sophie.
- Play around with a text frame - show affine transforms, wrapping modes, chaining, navigation, etc.
Design
-TEXT MODEL PART-
The idea of the new text design is to remove the existing stable poses with unstable indexes. In order to achieve this functionality the following changes have been made:
- Rename HotIndexInterval in org.sophie2.base.model.text.smart.position package with HotTextInterval.
- From org.sophie2.base.model.text.smart.position remove HotInterval and replace all of its usage in Sophie with HotTextInterval.
- Remove HotPos class.
- Remove HotPos persister class.
- In HotTextInterval add a comparator for intervals.
- In org.sophie2.base.model.text.smart package add new class named TextUnit - this class represents a
single text unit in sophie text. This class is needed mostly to hold the styled value of every single text
unit in the whole text.
- Every text unit holds a char value and HotStyleDef value(only reference to a text style).
- Add getUnitStyle function in the class to get the unit style.
- Add getUnitChar function to get the char.
- In org.sophie2.base.model.text.smart add ImmText interface - the interface of the new sophie text.
- Hash getStyledHash() - Returns the styled hash of the text.
- HotTextInterval getLastChangedInterval() - Returns interval from the last change of the text(applying styles or replacing
text).
- CharSequence toSequence() - Gets the chars of the text as CharSequence.
- char getCharAt(int index) - Method for getting the char at a specific text's index.
- TextUnit getAt(int index) - Method for getting a text unit at a specific index.
- ImmText replace(HotTextInterval interval, ImmText text) - Method for replacing interval of the given text with another text. Replaces form the begin index inclusive to the end index exclusive. Applies the styles from the first replaced text to the replacing text.
- T getStyleValue(HotAttr<T> attr, HotTextInterval interval) - Gets the style value for a given attribute and given interval. If not all interval has the same value for the given attribute - the default value is returned.
- ImmText applyStyle(HotStyleDef style, HotTextInterval interval) - Applies style to the text for a given interval.
- int getBegin() - Gets the begin of the text.
- int getEnd() - Gets the end of the text.
- In ImmHotText class remove all the existing fields and add ImmList<TextUnit> textUnits and HotTextInterval lastChangedInterval(the first one holds the units of the sophie2 text and the second one holds the interval that has been most recently changed by some of the functions of the text(applyStyle or replace)).
- Make the ImmHotText class implement the ImmText interface and implement the functions of the interface.
- Make HotStyleDef class implement Hashable and intern the HotStyleDef's values(add field with the used styles till now and when creating a new HotStyleDef object if the map contains the object take the containing object else add the object in the map).
- In HotStyleDef class add replaceDerive function that concatenates only the non default values from this style and the given one and constructs a new HotStyleDef with this values.
- In HotStyleDef class add getAllAttr function that returns list of all the CommonAttr's values.
- In CommonAttr add two new values: HotAttr<String> LINK_ATTRIBUTE - represents the link id's for the text and HotAttr<ImmList<String>> ATTACHMENT_ATTRIBUTE - represents the text attachments
(without text links(anchors and so on)).
- In LinkAttachment class add String linkId attribute - this is a random final value that is unique for every link in the text and is genetared in the constructor of the class. Add a getter method for the value.
- In HotTextResourceR4 class add Key<ImmMap<String, LinkAttachment>> KEY_TEXT_LINK_MAP key that holds all the the text link attachments' ids to the link attachment itself(this is used in the ligics for adding and removing text links).
- The new logic for adding/removing link is as follows:first applying style to the text with the map consisting of LINK_ATTRIBUTE with value equal to the added link id's(the default LINK_ATTRIBUTE's value if removed), second we change the map of the current hottextresource to a new one(with one added or removed value).
- In TextViewFlow add abstract Prop<ImmMap<HotTextInterval, Attachment>> attachmentMap() - Property, holding map of intervals to link attachments. it holds all the links that are not none-refs(it is called attachmentMap not linkAttachmentMap because it will hold all the link attachments and the other attachments in the future).
- In org.sophie2.base.model.text.smart add new utility class ImmTextUtils that has:
- ImmText empty() - Creates an empty text.
- int advance(ImmText text, int index, int offset) - navigates in text(if negative offset - navigate backwards else advande forwards).
- HotTextInterval getNextAttrInterval - Returns interval from the given position to the last position in the given text
before which the value of the given attribute in this position is the same as the value of the attribute in the given position.
- boolean checkBounds - Checks if the given index is in the bounds of the given text.
- ImmText subText(HotTextInterval interval, ImmText text) - Creates a new sub text of the given text.
- ImmText addLinkAttachment - Adds LINK_ATTRIBUTE to the given text with given link id.
- ImmText removeLinkAttachment - Removes LINK_ATTRIBUTE from the given text.This method only applies style to the given interval that has link attribute set to it's default value. Does not check if the interval has consistent link attribute.
- getStyleValue - Retrieves a specific text attribute's value at a specific position of the given text.
- TextViewState??????????????????????????????
-TEXT LAYOUT PART-
Implementation
(Describe and link the implementation results here (from the wiki or the repository).)
Testing
(Place the testing results here.)
Comments
(Write comments for this or later revisions here.)