wiki:TEXT_LAYOUT_COMMONS

Version 4 (modified by kyli, 15 years ago) (diff)

--

Error: Macro BackLinksMenu(None) failed
compressed data is corrupt

Error: Macro TicketQuery(summary=TEXT_LAYOUT_COMMONS, format=table, col=summary|owner|status|type|component|priority|effort|importance, rows=description|analysis_owners|analysis_reviewers|analysis_score|design_owners|design_reviewers|design_score|implementation_owners|implementation_reviewers|implementation_score|test_owners|test_reviewers|test_score|) failed
current transaction is aborted, commands ignored until end of transaction block

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

TEXT_LAYOUT_LAZY.

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

}}} with {{{

TextRunIterator runIterator = new TextRunIterator(textLine); float lineHeight = runIterator.getLineHeight();

}}}

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