diff options
author | Roman Kennke <roman@kennke.org> | 2006-11-16 13:03:04 +0000 |
---|---|---|
committer | Roman Kennke <roman@kennke.org> | 2006-11-16 13:03:04 +0000 |
commit | 63cd013ae30b6b4db963ae282e484b7edaa97f63 (patch) | |
tree | 0ee04574919ef8f2949b0c585999aee46d5266ec | |
parent | 231081816fd6f60043b8372914a23bae744ed992 (diff) | |
download | classpath-63cd013ae30b6b4db963ae282e484b7edaa97f63.tar.gz |
2006-11-16 Roman Kennke <kennke@aicas.com>
* javax/swing/text/FlowView.java
(LogicalView.getPreferredSpan): Calculate maximum correctly.
* javax/swing/text/GlyphView.java
(tabExpander): New field.
(tabX): New field.
(breakView): Set tabX on broken view.
(getPartialSpan): Let the painter fetch the span.
(getTabbedSpan): Update the tab expander field. Maybe trigger
relayout.
(getTabExpander): Simply return the stored expander.
* javax/swing/text/Utilities.java
(getTabbedTextOffset): Made algoritm a little smarter and more
efficient.
(getTabbedTextWidth): Don't add single char widths, instead add
chunks of characters.
* javax/swing/text/html/ParagraphView.java
(calculateMinorAxisRequirements): Adjust margin only when the
CSS span is not fixed.
-rw-r--r-- | ChangeLog | 21 | ||||
-rw-r--r-- | javax/swing/text/FlowView.java | 2 | ||||
-rw-r--r-- | javax/swing/text/GlyphView.java | 49 | ||||
-rw-r--r-- | javax/swing/text/Utilities.java | 65 | ||||
-rw-r--r-- | javax/swing/text/html/ParagraphView.java | 16 |
5 files changed, 78 insertions, 75 deletions
@@ -1,3 +1,24 @@ +2006-11-16 Roman Kennke <kennke@aicas.com> + + * javax/swing/text/FlowView.java + (LogicalView.getPreferredSpan): Calculate maximum correctly. + * javax/swing/text/GlyphView.java + (tabExpander): New field. + (tabX): New field. + (breakView): Set tabX on broken view. + (getPartialSpan): Let the painter fetch the span. + (getTabbedSpan): Update the tab expander field. Maybe trigger + relayout. + (getTabExpander): Simply return the stored expander. + * javax/swing/text/Utilities.java + (getTabbedTextOffset): Made algoritm a little smarter and more + efficient. + (getTabbedTextWidth): Don't add single char widths, instead add + chunks of characters. + * javax/swing/text/html/ParagraphView.java + (calculateMinorAxisRequirements): Adjust margin only when the + CSS span is not fixed. + 2006-11-16 David Gilbert <david.gilbert@object-refinery.com> * java/beans/beancontext/BeanContextSupport.java diff --git a/javax/swing/text/FlowView.java b/javax/swing/text/FlowView.java index 9609f3fc8..c2bed399f 100644 --- a/javax/swing/text/FlowView.java +++ b/javax/swing/text/FlowView.java @@ -488,7 +488,7 @@ public abstract class FlowView extends BoxView if (v.getBreakWeight(axis, 0, Integer.MAX_VALUE) >= ForcedBreakWeight) { - max = Math.max(pref, pref); + max = Math.max(max, pref); pref = 0; } } diff --git a/javax/swing/text/GlyphView.java b/javax/swing/text/GlyphView.java index 35c8dd5d7..c654cee46 100644 --- a/javax/swing/text/GlyphView.java +++ b/javax/swing/text/GlyphView.java @@ -497,6 +497,16 @@ public class GlyphView extends View implements TabableView, Cloneable private int length; /** + * The x location against which the tab expansion is done. + */ + private float tabX; + + /** + * The tab expander that is used in this view. + */ + private TabExpander tabExpander; + + /** * Creates a new <code>GlyphView</code> for the given <code>Element</code>. * * @param element the element that is rendered by this GlyphView @@ -658,13 +668,7 @@ public class GlyphView extends View implements TabableView, Cloneable */ public TabExpander getTabExpander() { - TabExpander te = null; - View parent = getParent(); - - if (parent instanceof TabExpander) - te = (TabExpander) parent; - - return te; + return tabExpander; } /** @@ -678,8 +682,16 @@ public class GlyphView extends View implements TabableView, Cloneable public float getTabbedSpan(float x, TabExpander te) { checkPainter(); + TabExpander old = tabExpander; + tabExpander = te; + if (tabExpander != old) + { + // Changing the tab expander will lead to a relayout in the X_AXIS. + preferenceChanged(null, true, false); + } + tabX = x; return getGlyphPainter().getSpan(this, getStartOffset(), - getEndOffset(), te, x); + getEndOffset(), tabExpander, x); } /** @@ -693,23 +705,8 @@ public class GlyphView extends View implements TabableView, Cloneable */ public float getPartialSpan(int p0, int p1) { - Element el = getElement(); - Document doc = el.getDocument(); - Segment seg = new Segment(); - try - { - doc.getText(p0, p1 - p0, seg); - } - catch (BadLocationException ex) - { - AssertionError ae; - ae = new AssertionError("BadLocationException must not be thrown " - + "here"); - ae.initCause(ex); - throw ae; - } - FontMetrics fm = null; // Fetch font metrics somewhere. - return Utilities.getTabbedTextWidth(seg, fm, 0, null, p0); + checkPainter(); + return glyphPainter.getSpan(this, p0, p1, tabExpander, tabX); } /** @@ -938,6 +935,8 @@ public class GlyphView extends View implements TabableView, Cloneable if (p0 != getStartOffset() || end != getEndOffset()) { brokenView = createFragment(p0, end); + if (brokenView instanceof GlyphView) + ((GlyphView) brokenView).tabX = pos; } } return brokenView; diff --git a/javax/swing/text/Utilities.java b/javax/swing/text/Utilities.java index fa2d1ab52..e1243f640 100644 --- a/javax/swing/text/Utilities.java +++ b/javax/swing/text/Utilities.java @@ -163,7 +163,9 @@ public class Utilities // The current maximum width. int maxWidth = 0; - for (int offset = s.offset; offset < (s.offset + s.count); ++offset) + int end = s.offset + s.count; + int count = 0; + for (int offset = s.offset; offset < end; offset++) { switch (buffer[offset]) { @@ -179,21 +181,18 @@ public class Utilities case '\n': // In case we have a newline, we must 'draw' // the buffer and jump on the next line. - pixelX += metrics.charWidth(buffer[offset]); - maxWidth = Math.max(maxWidth, pixelX - x); - pixelX = x; - break; - default: - // Here we draw the char. - pixelX += metrics.charWidth(buffer[offset]); - break; - } + pixelX += metrics.charsWidth(buffer, offset - count, count); + count = 0; + break; + default: + count++; + } } // Take the last line into account. - maxWidth = Math.max(maxWidth, pixelX - x); + pixelX += metrics.charsWidth(buffer, end - count, count); - return maxWidth; + return pixelX - x; } /** @@ -228,43 +227,41 @@ public class Utilities int x, TabExpander te, int p0, boolean round) { - // At the end of the for loop, this holds the requested model location - int pos; + int found = s.count; int currentX = x0; - int width = 0; + int nextX = currentX; - for (pos = 0; pos < s.count; pos++) + int end = s.offset + s.count; + for (int pos = s.offset; pos < end && found == s.count; pos++) { - char nextChar = s.array[s.offset+pos]; - - if (nextChar == 0) - break; + char nextChar = s.array[pos]; if (nextChar != '\t') - width = fm.charWidth(nextChar); + nextX += fm.charWidth(nextChar); else { if (te == null) - width = fm.charWidth(' '); + nextX += fm.charWidth(' '); else - width = ((int) te.nextTabStop(currentX, pos)) - currentX; + nextX += ((int) te.nextTabStop(nextX, p0 + pos - s.offset)); } - if (round) + if (x >= currentX && x < nextX) { - if (currentX + (width>>1) > x) - break; - } - else - { - if (currentX + width > x) - break; + // Found position. + if ((! round) || ((x - currentX) < (nextX - x))) + { + found = pos - s.offset; + } + else + { + found = pos + 1 - s.offset; + } } - - currentX += width; + currentX = nextX; } - return pos; + return found; } /** diff --git a/javax/swing/text/html/ParagraphView.java b/javax/swing/text/html/ParagraphView.java index e3f2817be..8443515d3 100644 --- a/javax/swing/text/html/ParagraphView.java +++ b/javax/swing/text/html/ParagraphView.java @@ -187,28 +187,14 @@ public class ParagraphView SizeRequirements r) { r = super.calculateMinorAxisRequirements(axis, r); - if (setCSSSpan(r, axis)) + if (! setCSSSpan(r, axis)) { - // If we have set the span from CSS, then we need to adjust - // the margins. - SizeRequirements parent = super.calculateMinorAxisRequirements(axis, - null); int margin = axis == X_AXIS ? getLeftInset() + getRightInset() : getTopInset() + getBottomInset(); r.minimum -= margin; r.preferred -= margin; r.maximum -= margin; } - else - { - float min = 0; - int n = getLayoutViewCount(); - for (int i = 0; i < n; i++) - min = Math.max(getLayoutView(i).getMinimumSpan(axis), min); - r.minimum = (int) min; - r.preferred = Math.max(r.preferred, r.minimum); - r.maximum = Math.max(r.maximum, r.preferred); - } return r; } |