Last modified 15 years ago
Last modified on 03/09/10 10:54:38
Analysis
Overview
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
- 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
Source code, basics for the tasks mentioned.
Implementation idea
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
How to demo
Play around with a text frame - show affine transforms, wrapping modes, chaining, navigation, etc.
Design
- The current usage of TextLayout in our layout could easily allow tabbed text, but it is not designed to work with hyphenation and spell check. It also needs LineBreakMeasurer usage, which is quite heavy class. According to the java doc, re-using the LBMs makes them quite faster, but changes to a text style (for example) cause a new LBM to be created. On the other side, drawing GlyphVectors is said to be the fastest way of drawing text that java.awt.font provides. So:
- Remove ImmHotText.toAci() ad the private field ImmHotText.attrString;
- Remove TextUtils.createLineBreakMeasurer()
- We define that text run is a piece of text in which all characters have the same style attributes. A TextRun object should have at least the following methods:
- Constructor from hot text;
- public String getText();
- public Map<AttributedCharacterIterator.Attribute, Object> getAttributes(); Note: TextAttribute extends AttributedCharacterIterator.Attribute
- public Object getAttribute(AttributedCharacterIterator.Attribute attribute);
- public int getRunLength();
- TextRunIterator is an object created from a single paragraph of ImmHotText. It contains:
- Public constructor from hot text;
- Private HotPos to the current position in the text given;
- public TextRun nextRun() - creates a new run and updates the internal position (if the end has reached, returns null);
- public int getLineHeight() - locates the largest font size in this text hot text and calculates the line height from it;
- Go to HotAreaLayout. In its create method, replace the segment
LineBreakMeasurer measurer = TextUtils.createLineBreakMeasurer(textLine); int measurerPos = measurer.getPosition(); TextLayout textLayout = measurer.nextLayout(Float.MAX_VALUE, measurerPos + consumedLength + textLine.getLength(), false); if (textLayout == null) { textLayout = HotTextLayout.emptyLayout; } float lineHeight = textLayout.getLeading() + textLayout.getAscent() + textLayout.getDescent();
withTextRunIterator runIterator = new TextRunIterator(textLine); float lineHeight = runIterator.getLineHeight();
- Changes to HotSegmentLayout should be made:
- The create method will accept TextRunIterator and HorizontalInterval, not LBM, ImmHotText and ImmSize. First of all, nothing except the width of the size is used, so it is not necessary. Second, the idea is not to use ImmHotText in segment layouts and not to use LBMs at all, so TextRunIterators let us do this - they provide all the needed information about drawing text.
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.)