This patch makes working the HR tag as expected, drawing the horizontal
dash.
The patch makes change in FlowView.layoutRow, passing the row with the
view, having forced break weigth (on the end) to the adjustRow. The
adjustRow finally calls the breakView on such view, resulting the
correct rendering. Without this change, the breakView seems never called
on the views with the forced break weigth. Seems no Mauve regressions.
2006-07-08 Audrius Meskauskas <[EMAIL PROTECTED]>
* javax/swing/text/FlowView.java (FlowStrategy.layoutRow):
Handle the forced break in the same way as exceeding the
available row space.
* javax/swing/text/html/HRuleView.java: Rewritten.
* javax/swing/text/html/HTMLDocument.java
(HTMLReader.addSpecialElement):Reserve two characters for
the special elements.
* examples/gnu/classpath/examples/swing/HtmlDemo.java
(text): Extended tht HTML example to parse.
Index: examples/gnu/classpath/examples/swing/HtmlDemo.java
===================================================================
RCS file: /sources/classpath/classpath/examples/gnu/classpath/examples/swing/HtmlDemo.java,v
retrieving revision 1.1
diff -u -r1.1 HtmlDemo.java
--- examples/gnu/classpath/examples/swing/HtmlDemo.java 9 Jun 2006 12:51:24 -0000 1.1
+++ examples/gnu/classpath/examples/swing/HtmlDemo.java 8 Jul 2006 19:29:32 -0000
@@ -63,8 +63,12 @@
JTextPane html = new JTextPane();
- //JTextArea text = new JTextArea("<html><body><p><img src='' alt='alt txt'></p></body></html>");
- JTextArea text = new JTextArea("<html><body><p>nor<font color=red>ma</font>l<sup>sup</sup>normal<sub>sub</sub>normal</p></body></html>");
+ JTextArea text = new JTextArea("<html><body><p>" +
+ "123456789HR!<hr>987654321"+
+ "123456789BR!<br>987654321"+
+ "<font color=red>ma</font>"+
+ "<sup>sup</sup>normal<sub>sub</sub>normal</p><p>Table:"+
+ "<table><tr>a<td>b<td>c<tr>x<td>y<td>z</table></body></html>");
JPanel buttons;
Index: javax/swing/text/FlowView.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/text/FlowView.java,v
retrieving revision 1.12
diff -u -r1.12 FlowView.java
--- javax/swing/text/FlowView.java 7 Jul 2006 13:34:36 -0000 1.12
+++ javax/swing/text/FlowView.java 8 Jul 2006 19:29:55 -0000
@@ -159,20 +159,18 @@
}
/**
- * Lays out one row of the flow view. This is called by [EMAIL PROTECTED] #layout}
- * to fill one row with child views until the available span is exhausted.
- *
- * The default implementation fills the row by calling
- * [EMAIL PROTECTED] #createView(FlowView, int, int, int)} until the available space
- * is exhausted, a forced break is encountered or there are no more views
- * in the logical view. If the available space is exhausted,
- * [EMAIL PROTECTED] #adjustRow(FlowView, int, int, int)} is called to fit the row
- * into the available span.
- *
+ * Lays out one row of the flow view. This is called by [EMAIL PROTECTED] #layout} to
+ * fill one row with child views until the available span is exhausted. The
+ * default implementation fills the row by calling
+ * [EMAIL PROTECTED] #createView(FlowView, int, int, int)} until the available space is
+ * exhausted, a forced break is encountered or there are no more views in
+ * the logical view. If the available space is exhausted,
+ * [EMAIL PROTECTED] #adjustRow(FlowView, int, int, int)} is called to fit the row into
+ * the available span.
+ *
* @param fv the flow view for which we perform the layout
* @param rowIndex the index of the row
* @param pos the model position for the beginning of the row
- *
* @return the start position of the next row
*/
protected int layoutRow(FlowView fv, int rowIndex, int pos)
@@ -188,36 +186,39 @@
if (span == 0)
span = Integer.MAX_VALUE;
- while (span > 0)
+ Row: while (span > 0)
{
- if (logicalView.getViewIndex(offset, Position.Bias.Forward) == -1)
+ if (logicalView.getViewIndex(offset, Position.Bias.Forward) == - 1)
break;
View view = createView(fv, offset, span, rowIndex);
if (view == null)
break;
+
int viewSpan = (int) view.getPreferredSpan(axis);
- row.append(view);
int breakWeight = view.getBreakWeight(axis, x, span);
-
- offset += (view.getEndOffset() - view.getStartOffset());
- if (breakWeight >= View.ForcedBreakWeight)
- break;
+ row.append(view);
+ offset += (view.getEndOffset() - view.getStartOffset());
x += viewSpan;
span -= viewSpan;
+
+ // Break if the line if the view does not fit in this row or the
+ // line just must be broken.
+ if (span < 0 || breakWeight >= View.ForcedBreakWeight)
+ {
+ int flowStart = fv.getFlowStart(axis);
+ int flowSpan = fv.getFlowSpan(axis);
+ adjustRow(fv, rowIndex, flowSpan, flowStart);
+ int rowViewCount = row.getViewCount();
+ if (rowViewCount > 0)
+ offset = row.getView(rowViewCount - 1).getEndOffset();
+ else
+ offset = - 1;
+ break Row;
+ }
}
- if (span < 0)
- {
- int flowStart = fv.getFlowStart(axis);
- int flowSpan = fv.getFlowSpan(axis);
- adjustRow(fv, rowIndex, flowSpan, flowStart);
- int rowViewCount = row.getViewCount();
- if (rowViewCount > 0)
- offset = row.getView(rowViewCount - 1).getEndOffset();
- else
- offset = -1;
- }
- return offset != pos ? offset : -1;
+
+ return offset != pos ? offset : - 1;
}
/**
Index: javax/swing/text/html/HRuleView.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/text/html/HRuleView.java,v
retrieving revision 1.1
diff -u -r1.1 HRuleView.java
--- javax/swing/text/html/HRuleView.java 6 Jul 2006 09:04:38 -0000 1.1
+++ javax/swing/text/html/HRuleView.java 8 Jul 2006 19:29:56 -0000
@@ -59,9 +59,52 @@
*/
View nullView;
+ /**
+ * The height of the horizontal dash area.
+ */
static int HEIGHT = 4;
/**
+ * The imaginary invisible view that stays after end of line after the
+ * breaking procedure. It occupies on character.
+ */
+ class Beginning extends NullView
+ {
+ /**
+ * The break offset that becomes the views start offset.
+ */
+ int breakOffset;
+
+ /**
+ * Return the end offset that is always one char after the break offset.
+ */
+ public int getEndOffset()
+ {
+ return breakOffset + 1;
+ }
+
+ /**
+ * Return the start offset that has been passed in a constructor.
+ */
+ public int getStartOffset()
+ {
+ return breakOffset;
+ }
+
+ /**
+ * Create the new instance of this view.
+ *
+ * @param element the element (inherited from the HR view)
+ * @param offset the position where the HR view has been broken
+ */
+ public Beginning(Element element, int offset)
+ {
+ super(element);
+ breakOffset = offset;
+ }
+ }
+
+ /**
* Creates the new HR view.
*/
public HRuleView(Element element)
@@ -76,7 +119,7 @@
*/
public int getBreakWeight(int axis, float pos, float len)
{
- if (axis == X_AXIS)
+ if (axis == X_AXIS && ((getEndOffset() - getStartOffset()) > 1))
return ForcedBreakWeight;
else
return BadBreakWeight;
@@ -105,14 +148,17 @@
}
/**
- * Always returns the null view, indicating that the dash must be painted
- * below the breaking point.
+ * Break the view into this view and the invisible imaginary view that
+ * stays on the end of line that is broken by HR dash. The view is broken
+ * only if its length is longer than one (the two characters are expected
+ * in the initial length).
*/
public View breakView(int axis, int offset, float pos, float len)
{
- if (nullView == null)
- nullView = new NullView(getElement());
- return nullView;
+ if (getEndOffset() - getStartOffset() > 1)
+ return new Beginning(getElement(), offset);
+ else
+ return this;
}
/**
@@ -132,15 +178,7 @@
else
return HEIGHT;
}
-
- /**
- * Returns the same values as [EMAIL PROTECTED] #getMaximumSpan(int)}
- */
- public float getMinimumSpan(int axis)
- {
- return getMaximumSpan(axis);
- }
-
+
/**
* Returns the same values as [EMAIL PROTECTED] #getMaximumSpan(int)}
*/
Index: javax/swing/text/html/HTMLDocument.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/text/html/HTMLDocument.java,v
retrieving revision 1.34
diff -u -r1.34 HTMLDocument.java
--- javax/swing/text/html/HTMLDocument.java 10 Jun 2006 11:39:58 -0000 1.34
+++ javax/swing/text/html/HTMLDocument.java 8 Jul 2006 19:30:00 -0000
@@ -1433,14 +1433,14 @@
// Migrate from the rather htmlAttributeSet to the faster, lighter and
// unchangeable alternative implementation.
AttributeSet copy = a.copyAttributes();
-
- // TODO: Figure out why we must always insert this single character
- // (otherwise the element does not appear). Either fix or add explaining
- // comment or at least report a normal bug.
- DefaultStyledDocument.ElementSpec spec;
- spec = new DefaultStyledDocument.ElementSpec(copy,
- DefaultStyledDocument.ElementSpec.ContentType,
- new char[] {' '}, 0, 1 );
+
+ // The two spaces are required because some special elements like HR
+ // must be broken. At least two characters are needed to break into the
+ // two parts.
+ DefaultStyledDocument.ElementSpec spec =
+ new DefaultStyledDocument.ElementSpec(copy,
+ DefaultStyledDocument.ElementSpec.ContentType,
+ new char[] {' ', ' '}, 0, 2 );
parseBuffer.add(spec);
}