Changeset 873


Ignore:
Timestamp:
02/10/14 00:57:44 (10 years ago)
Author:
ngw8
Message:

Changed the way anchoring top and anchoring bottom works for text.

Summary since this is an insanely long commit message for a only few lines of changes:
Change to text top anchoring is essentially a bug fix, change to text bottom anchoring is a slight change in behaviour to make it consistent with all other anchoring.

Since text is positioned relative to the baseline of the first line, in order to have the top of the text against the top of the frame, its y-position should equal the distance from the top of the text to the baseline of the first line (i.e. getAscent()). Previously anchoring top was setting the y-position to [anchor] + [bounds height], which sort of worked for a single line of text, but didn't work well for multi-line text (since the text y-position was being offset by the text's entire height, not just the height of the first line).

Anchoring text to the bottom was previously setting the y-position to [FrameHeight] - [anchor], which meant the baseline of the first line of text was always positioned at [anchor] from the bottom (so setting anchorBottom to 0 with multi-line text caused all but the first line to be below the bottom of the frame). This didn't really seem like the expected behaviour for anything apart from single-line text, given that bottom-anchoring an image at 0 places its bottom edge (rather than its top edge, where it is positioned relative to) against the bottom edge of the frame, and right-anchoring a text item positions it so that the text _ends_ at [offset] from the right edge. To be consistent with all the other anchoring, bottom anchoring of text now positions the text so that the text ends at [offset] from the bottom of the frame.

Also had to change DefaultFrameWriter to write the text tag before the anchor tags, otherwise when reading in a frame setAnchorTop/Bottom would have no text to get the ascent/descent for. Frames saved before this commit that use anchor bottom/top will probably still throw an exception (that gets caught), but the frame should load and display fine.

This shouldn't break any functionality or default frames (only Exploratory Search overlays which I still need to update anyway), but may require existing frames that were using anchor top/bottom to be adjusted slightly. Feel free to revert if it does break significant stuff, although this does seem to be how anchoring text is intended to work.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/items/Text.java

    r836 r873  
    25312531                        super.setAnchorTop(anchor);
    25322532                        if (anchor != null) {
    2533                                 setY(anchor + getBoundsHeight());
     2533                                setY(anchor + _textLayouts.get(0).getAscent());
    25342534                        }
    25352535                        return;
     
    25552555                if (!isLineEnd()) {
    25562556                        super.setAnchorBottom(anchor);
     2557                        if (anchor != null) {
     2558                                setY(FrameGraphics.getMaxFrameSize().height - (anchor + this.getBoundsHeight() - _textLayouts.get(0).getAscent() - _textLayouts.get(0).getDescent()));
     2559                        }
    25572560                        return;
    25582561                }
     
    25662569                if (anchor != null) {
    25672570
    2568                         float deltaY = FrameGraphics.getMaxFrameSize().height - anchor
    2569                                         - oldY;
     2571                        float deltaY = FrameGraphics.getMaxFrameSize().height - anchor - oldY;
    25702572                        anchorConnected(AnchorEdgeType.Bottom, deltaY);
    25712573                }
Note: See TracChangeset for help on using the changeset viewer.