bug 257806: show comment markers before and after comments
Currently the markers <!-- and --> are used.
Signed-off-by: Florian Thienel <florian@thienel.org>
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/BlockElementBox.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/BlockElementBox.java
index c4f7301..919ea9f 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/BlockElementBox.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/BlockElementBox.java
@@ -53,8 +53,7 @@
* @param element
* Element to which this box corresponds.
*/
- public BlockElementBox(LayoutContext context, BlockBox parent,
- Element element) {
+ public BlockElementBox(LayoutContext context, BlockBox parent, Element element) {
super(context, parent, element);
}
@@ -82,8 +81,7 @@
super.paint(context, x, y);
if (this.beforeMarker != null) {
- this.beforeMarker.paint(context, x + this.beforeMarker.getX(), y
- + this.beforeMarker.getY());
+ this.beforeMarker.paint(context, x + this.beforeMarker.getX(), y + this.beforeMarker.getY());
}
}
@@ -93,13 +91,11 @@
Styles styles = context.getStyleSheet().getStyles(this.getElement());
if (this.beforeMarker != null) {
- int x = -this.beforeMarker.getWidth()
- - Math.round(BULLET_SPACE * styles.getFontSize());
+ int x = -this.beforeMarker.getWidth() - Math.round(BULLET_SPACE * styles.getFontSize());
int y = this.getFirstLineTop(context);
LineBox firstLine = this.getFirstLine();
if (firstLine != null) {
- y += firstLine.getBaseline()
- - this.beforeMarker.getFirstLine().getBaseline();
+ y += firstLine.getBaseline() - this.beforeMarker.getFirstLine().getBaseline();
}
this.beforeMarker.setX(x);
@@ -110,9 +106,8 @@
}
public String toString() {
- return "BlockElementBox: <" + this.getElement().getPrefixedName() + ">" + "[x="
- + this.getX() + ",y=" + this.getY() + ",width="
- + this.getWidth() + ",height=" + this.getHeight() + "]";
+ return "BlockElementBox: <" + this.getElement().getPrefixedName() + ">" + "[x=" + this.getX() + ",y=" + this.getY() + ",width=" + this.getWidth()
+ + ",height=" + this.getHeight() + "]";
}
// ===================================================== PRIVATE
@@ -129,9 +124,9 @@
final Element element = this.getElement();
int width = this.getWidth();
- List<Box> childList = new ArrayList<Box>();
+ final List<Box> childList = new ArrayList<Box>();
- StyleSheet styleSheet = context.getStyleSheet();
+ final StyleSheet styleSheet = context.getStyleSheet();
// element and styles for generated boxes
Element genElement;
@@ -139,17 +134,14 @@
// :before content
List<InlineBox> beforeInlines = null;
- genElement = context.getStyleSheet()
- .getBeforeElement(this.getElement());
+ genElement = context.getStyleSheet().getBeforeElement(this.getElement());
if (genElement != null) {
genStyles = styleSheet.getStyles(genElement);
if (genStyles.getDisplay().equals(CSS.INLINE)) {
beforeInlines = new ArrayList<InlineBox>();
- beforeInlines.addAll(LayoutUtils.createGeneratedInlines(
- context, genElement));
+ beforeInlines.addAll(LayoutUtils.createGeneratedInlines(context, genElement));
} else {
- childList.add(new BlockPseudoElementBox(context, genElement,
- this, width));
+ childList.add(new BlockPseudoElementBox(context, genElement, this, width));
}
}
@@ -163,7 +155,7 @@
beforeInlines.add(imageBox);
}
}
-
+
// :after content
Box afterBlock = null;
List<InlineBox> afterInlines = null;
@@ -172,40 +164,34 @@
genStyles = context.getStyleSheet().getStyles(genElement);
if (genStyles.getDisplay().equals(CSS.INLINE)) {
afterInlines = new ArrayList<InlineBox>();
- afterInlines.addAll(LayoutUtils.createGeneratedInlines(context,
- genElement));
+ afterInlines.addAll(LayoutUtils.createGeneratedInlines(context, genElement));
} else {
- afterBlock = new BlockPseudoElementBox(context, genElement,
- this, width);
+ afterBlock = new BlockPseudoElementBox(context, genElement, this, width);
}
}
final int startOffset = element.getStartOffset() + 1;
final int endOffset = element.getEndOffset();
- List<Box> blockBoxes = createBlockBoxes(context, startOffset, endOffset,
- width, beforeInlines, afterInlines);
+ List<Box> blockBoxes = createBlockBoxes(context, startOffset, endOffset, width, beforeInlines, afterInlines);
childList.addAll(blockBoxes);
if (afterBlock != null)
childList.add(afterBlock);
- if (styles.getDisplay().equals(CSS.LIST_ITEM)
- && !styles.getListStyleType().equals(CSS.NONE)) {
+ if (styles.getDisplay().equals(CSS.LIST_ITEM) && !styles.getListStyleType().equals(CSS.NONE)) {
this.createListMarker(context);
}
if (VEXCorePlugin.getInstance().isDebugging()) {
long end = System.currentTimeMillis();
if (end - start > 10) {
- System.out.println("BEB.layout for "
- + this.getElement().getPrefixedName() + " took "
- + (end - start) + "ms");
+ System.out.println("BEB.layout for " + this.getElement().getPrefixedName() + " took " + (end - start) + "ms");
}
}
return childList;
}
-
+
/**
* Creates a marker box for this primary box and puts it in the beforeMarker
* field.
@@ -224,14 +210,12 @@
markerInline = createSquareBullet(this.getElement(), styles);
} else if (isEnumeratedListStyleType(type)) {
String item = this.getItemNumberString(type);
- markerInline = new StaticTextBox(context, this.getElement(), item
- + ".");
+ markerInline = new StaticTextBox(context, this.getElement(), item + ".");
} else {
markerInline = createDiscBullet(this.getElement(), styles);
}
- this.beforeMarker = ParagraphBox.create(context, this.getElement(),
- new InlineBox[] { markerInline }, Integer.MAX_VALUE);
+ this.beforeMarker = ParagraphBox.create(context, this.getElement(), new InlineBox[] { markerInline }, Integer.MAX_VALUE);
}
@@ -301,10 +285,8 @@
Styles styles = context.getStyleSheet().getStyles(this.getElement());
int top = styles.getBorderTopWidth() + styles.getPaddingTop().get(0);
Box[] children = this.getChildren();
- if (children != null && children.length > 0
- && children[0] instanceof BlockElementBox) {
- return top
- + ((BlockElementBox) children[0]).getFirstLineTop(context);
+ if (children != null && children.length > 0 && children[0] instanceof BlockElementBox) {
+ return top + ((BlockElementBox) children[0]).getFirstLineTop(context);
} else {
return top;
}
@@ -345,13 +327,11 @@
} else {
return Integer.toString(item);
}
- } else if (style.equals(CSS.LOWER_ALPHA)
- || style.equals(CSS.LOWER_LATIN)) {
+ } else if (style.equals(CSS.LOWER_ALPHA) || style.equals(CSS.LOWER_LATIN)) {
return this.getAlpha(item);
} else if (style.equals(CSS.LOWER_ROMAN)) {
return this.getRoman(item);
- } else if (style.equals(CSS.UPPER_ALPHA)
- || style.equals(CSS.UPPER_LATIN)) {
+ } else if (style.equals(CSS.UPPER_ALPHA) || style.equals(CSS.UPPER_LATIN)) {
return this.getAlpha(item).toUpperCase();
} else if (style.equals(CSS.UPPER_ROMAN)) {
return this.getRoman(item).toUpperCase();
@@ -366,12 +346,9 @@
}
private String getRoman(int n) {
- final String[] ones = { "", "i", "ii", "iii", "iv", "v", "vi", "vii",
- "viii", "ix" };
- final String[] tens = { "", "x", "xx", "xxx", "xl", "l", "lx", "lxx",
- "lxxx", "xc" };
- final String[] hundreds = { "", "c", "cc", "ccc", "cd", "d", "dc",
- "dcc", "dccc", "cm" };
+ final String[] ones = { "", "i", "ii", "iii", "iv", "v", "vi", "vii", "viii", "ix" };
+ final String[] tens = { "", "x", "xx", "xxx", "xl", "l", "lx", "lxx", "lxxx", "xc" };
+ final String[] hundreds = { "", "c", "cc", "ccc", "cd", "d", "dc", "dcc", "dccc", "cm" };
StringBuffer sb = new StringBuffer();
for (int i = 0; i < n / 1000; i++) {
sb.append("m");
@@ -383,15 +360,10 @@
}
private static boolean isEnumeratedListStyleType(String s) {
- return s.equals(CSS.ARMENIAN) || s.equals(CSS.CJK_IDEOGRAPHIC)
- || s.equals(CSS.DECIMAL) || s.equals(CSS.DECIMAL_LEADING_ZERO)
- || s.equals(CSS.GEORGIAN) || s.equals(CSS.HEBREW)
- || s.equals(CSS.HIRAGANA) || s.equals(CSS.HIRAGANA_IROHA)
- || s.equals(CSS.KATAKANA) || s.equals(CSS.KATAKANA_IROHA)
- || s.equals(CSS.LOWER_ALPHA) || s.equals(CSS.LOWER_GREEK)
- || s.equals(CSS.LOWER_LATIN) || s.equals(CSS.LOWER_ROMAN)
- || s.equals(CSS.UPPER_ALPHA) || s.equals(CSS.UPPER_LATIN)
- || s.equals(CSS.UPPER_ROMAN);
+ return s.equals(CSS.ARMENIAN) || s.equals(CSS.CJK_IDEOGRAPHIC) || s.equals(CSS.DECIMAL) || s.equals(CSS.DECIMAL_LEADING_ZERO) || s.equals(CSS.GEORGIAN)
+ || s.equals(CSS.HEBREW) || s.equals(CSS.HIRAGANA) || s.equals(CSS.HIRAGANA_IROHA) || s.equals(CSS.KATAKANA) || s.equals(CSS.KATAKANA_IROHA)
+ || s.equals(CSS.LOWER_ALPHA) || s.equals(CSS.LOWER_GREEK) || s.equals(CSS.LOWER_LATIN) || s.equals(CSS.LOWER_ROMAN)
+ || s.equals(CSS.UPPER_ALPHA) || s.equals(CSS.UPPER_LATIN) || s.equals(CSS.UPPER_ROMAN);
}
}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/CommentBlockElementBox.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/CommentBlockElementBox.java
new file mode 100644
index 0000000..cf4e5b6
--- /dev/null
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/CommentBlockElementBox.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Florian Thienel and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Florian Thienel - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.vex.core.internal.layout;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.vex.core.internal.VEXCorePlugin;
+import org.eclipse.vex.core.internal.dom.Element;
+
+/**
+ * @author Florian Thienel
+ */
+public class CommentBlockElementBox extends BlockElementBox {
+
+ private static final String AFTER_TEXT = "-->";
+ private static final String BEFORE_TEXT = "<!--";
+
+ public CommentBlockElementBox(final LayoutContext context, final BlockBox parent, final Element element) {
+ super(context, parent, element);
+ }
+
+ @Override
+ public List<Box> createChildren(final LayoutContext context) {
+ long start = 0;
+ if (VEXCorePlugin.getInstance().isDebugging())
+ start = System.currentTimeMillis();
+
+ final Element element = getElement();
+ final int width = getWidth();
+
+ final List<Box> childList = new ArrayList<Box>();
+
+ // :before content
+ final List<InlineBox> beforeInlines = new ArrayList<InlineBox>();
+ beforeInlines.add(new StaticTextBox(context, element, BEFORE_TEXT));
+
+ // :after content
+ final List<InlineBox> afterInlines = new ArrayList<InlineBox>();
+ afterInlines.add(new StaticTextBox(context, element, AFTER_TEXT));
+
+ final int startOffset = element.getStartOffset() + 1;
+ final int endOffset = element.getEndOffset();
+ final List<Box> blockBoxes = createBlockBoxes(context, startOffset, endOffset, width, beforeInlines, afterInlines);
+ childList.addAll(blockBoxes);
+
+ if (VEXCorePlugin.getInstance().isDebugging()) {
+ final long end = System.currentTimeMillis();
+ if (end - start > 10)
+ System.out.println("CommentBlockElementBox.layout for " + getElement().getPrefixedName() + " took " + (end - start) + "ms");
+ }
+
+ return childList;
+ }
+}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/CssBoxFactory.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/CssBoxFactory.java
index d3fafc3..8934b64 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/CssBoxFactory.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/CssBoxFactory.java
@@ -12,6 +12,7 @@
import org.eclipse.vex.core.internal.css.CSS;
import org.eclipse.vex.core.internal.css.Styles;
+import org.eclipse.vex.core.internal.dom.CommentElement;
import org.eclipse.vex.core.internal.dom.Element;
/**
@@ -22,23 +23,16 @@
private static final long serialVersionUID = -6882526795866485074L;
- /**
- * Class constructor.
- */
- public CssBoxFactory() {
- }
-
- public Box createBox(LayoutContext context, Element element,
- BlockBox parent, int containerWidth) {
- Styles styles = context.getStyleSheet().getStyles(element);
- if (styles.getDisplay().equals(CSS.TABLE)) {
+ public Box createBox(final LayoutContext context, final Element element, final BlockBox parent, final int containerWidth) {
+ final Styles styles = context.getStyleSheet().getStyles(element);
+ if (element instanceof CommentElement)
+ return new CommentBlockElementBox(context, parent, element);
+ else if (styles.getDisplay().equals(CSS.TABLE))
return new TableBox(context, parent, element);
- } else if (styles.isBlock()) {
+ else if (styles.isBlock())
return new BlockElementBox(context, parent, element);
- } else {
- throw new RuntimeException("Unexpected display property: "
- + styles.getDisplay());
- }
+ else
+ throw new RuntimeException("Unexpected display property: " + styles.getDisplay());
}
}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/InlineElementBox.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/InlineElementBox.java
index 15821a1..dece41d 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/InlineElementBox.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/InlineElementBox.java
@@ -21,6 +21,7 @@
import org.eclipse.vex.core.internal.core.Rectangle;
import org.eclipse.vex.core.internal.css.CSS;
import org.eclipse.vex.core.internal.css.Styles;
+import org.eclipse.vex.core.internal.dom.CommentElement;
import org.eclipse.vex.core.internal.dom.Element;
import org.eclipse.vex.core.internal.dom.Node;
import org.eclipse.vex.core.internal.dom.Text;
@@ -31,8 +32,10 @@
*/
public class InlineElementBox extends CompositeInlineBox {
- private Element element;
- private InlineBox[] children;
+ private static final String COMMENT_AFTER_TEXT = "-->";
+ private static final String COMMENT_BEFORE_TEXT = "<!--";
+ private final Element element;
+ private final InlineBox[] children;
private InlineBox firstContentChild = null;
private InlineBox lastContentChild = null;
private int baseline;
@@ -52,36 +55,34 @@
* End offset of the range being rendered, which may be
* arbitrarily after or inside the element.
*/
- private InlineElementBox(LayoutContext context, Element element,
- int startOffset, int endOffset) {
+ private InlineElementBox(final LayoutContext context, final Element element, final int startOffset, final int endOffset) {
this.element = element;
- List<InlineBox> childList = new ArrayList<InlineBox>();
+ final List<InlineBox> childList = new ArrayList<InlineBox>();
final Styles styles = context.getStyleSheet().getStyles(element);
if (startOffset <= element.getStartOffset()) {
// space for the left margin/border/padding
- int space = styles.getMarginLeft().get(0)
- + styles.getBorderLeftWidth()
- + styles.getPaddingLeft().get(0);
+ final int space = styles.getMarginLeft().get(0) + styles.getBorderLeftWidth() + styles.getPaddingLeft().get(0);
- if (space > 0) {
+ if (space > 0)
childList.add(new SpaceBox(space, 1));
+
+ if (element instanceof CommentElement)
+ childList.add(new StaticTextBox(context, element, COMMENT_BEFORE_TEXT));
+ else {
+ // :before content
+ final Element beforeElement;
+ beforeElement = context.getStyleSheet().getBeforeElement(element);
+ if (beforeElement != null)
+ childList.addAll(LayoutUtils.createGeneratedInlines(context, beforeElement));
+ // left marker
+ childList.add(createLeftMarker(element, styles));
}
- // :before content
- Element beforeElement = context.getStyleSheet().getBeforeElement(
- element);
- if (beforeElement != null) {
- childList.addAll(LayoutUtils.createGeneratedInlines(context,
- beforeElement));
- }
-
- // left marker
- childList.add(createLeftMarker(element, styles));
}
// background image
@@ -91,40 +92,35 @@
childList.add(imageBox);
}
- InlineBoxes inlines = createInlineBoxes(context, element, startOffset,
- endOffset);
+ final InlineBoxes inlines = createInlineBoxes(context, element, startOffset, endOffset);
childList.addAll(inlines.boxes);
- this.firstContentChild = inlines.firstContentBox;
- this.lastContentChild = inlines.lastContentBox;
+ firstContentChild = inlines.firstContentBox;
+ lastContentChild = inlines.lastContentBox;
if (endOffset > element.getEndOffset()) {
- childList.add(new PlaceholderBox(context, element, element
- .getEndOffset()
- - element.getStartOffset()));
+ childList.add(new PlaceholderBox(context, element, element.getEndOffset() - element.getStartOffset()));
- // trailing marker
- childList.add(createRightMarker(element, styles));
+ if (element instanceof CommentElement)
+ childList.add(new StaticTextBox(context, element, COMMENT_AFTER_TEXT));
+ else {
+ // trailing marker
+ childList.add(createRightMarker(element, styles));
- // :after content
- Element afterElement = context.getStyleSheet().getAfterElement(
- element);
- if (afterElement != null) {
- childList.addAll(LayoutUtils.createGeneratedInlines(context,
- afterElement));
+ // :after content
+ final Element afterElement = context.getStyleSheet().getAfterElement(element);
+ if (afterElement != null)
+ childList.addAll(LayoutUtils.createGeneratedInlines(context, afterElement));
}
// space for the right margin/border/padding
- int space = styles.getMarginRight().get(0)
- + styles.getBorderRightWidth()
- + styles.getPaddingRight().get(0);
+ final int space = styles.getMarginRight().get(0) + styles.getBorderRightWidth() + styles.getPaddingRight().get(0);
- if (space > 0) {
+ if (space > 0)
childList.add(new SpaceBox(space, 1));
- }
}
- this.children = childList.toArray(new InlineBox[childList.size()]);
+ children = childList.toArray(new InlineBox[childList.size()]);
layout(context);
}
@@ -138,63 +134,61 @@
* @param children
* Child boxes.
*/
- private InlineElementBox(LayoutContext context, Element element,
- InlineBox[] children) {
+ private InlineElementBox(final LayoutContext context, final Element element, final InlineBox[] children) {
this.element = element;
this.children = children;
layout(context);
- for (int i = 0; i < children.length; i++) {
- InlineBox child = children[i];
+ for (final InlineBox child : children)
if (child.hasContent()) {
- if (this.firstContentChild == null) {
- this.firstContentChild = child;
- }
- this.lastContentChild = child;
+ if (firstContentChild == null)
+ firstContentChild = child;
+ lastContentChild = child;
}
- }
}
/**
* @see org.eclipse.vex.core.internal.layout.InlineBox#getBaseline()
*/
public int getBaseline() {
- return this.baseline;
+ return baseline;
}
/**
* @see org.eclipse.vex.core.internal.layout.Box#getChildren()
*/
+ @Override
public Box[] getChildren() {
- return this.children;
+ return children;
}
/**
* Returns the element associated with this box.
*/
+ @Override
public Element getElement() {
- return this.element;
+ return element;
}
/**
* @see org.eclipse.vex.core.internal.layout.Box#getEndOffset()
*/
+ @Override
public int getEndOffset() {
- if (this.lastContentChild == null) {
- return this.getElement().getEndOffset();
- } else {
- return this.lastContentChild.getEndOffset();
- }
+ if (lastContentChild == null)
+ return getElement().getEndOffset();
+ else
+ return lastContentChild.getEndOffset();
}
/**
* @see org.eclipse.vex.core.internal.layout.Box#getStartOffset()
*/
+ @Override
public int getStartOffset() {
- if (this.firstContentChild == null) {
- return this.getElement().getStartOffset();
- } else {
- return this.firstContentChild.getStartOffset();
- }
+ if (firstContentChild == null)
+ return getElement().getStartOffset();
+ else
+ return firstContentChild.getStartOffset();
}
/**
@@ -203,42 +197,41 @@
* @see org.eclipse.vex.core.internal.layout.AbstractBox#paint(org.eclipse.vex.core.internal.layout.LayoutContext,
* int, int)
*/
- public void paint(LayoutContext context, int x, int y) {
+ @Override
+ public void paint(final LayoutContext context, final int x, final int y) {
this.drawBox(context, x, y, 0, true); // TODO CSS violation
super.paint(context, x, y);
}
- public Pair split(LayoutContext context, InlineBox[] lefts,
- InlineBox[] rights) {
+ @Override
+ public Pair split(final LayoutContext context, final InlineBox[] lefts, final InlineBox[] rights) {
InlineElementBox left = null;
InlineElementBox right = null;
- if (lefts.length > 0 || rights.length == 0) {
- left = new InlineElementBox(context, this.getElement(), lefts);
- }
+ if (lefts.length > 0 || rights.length == 0)
+ left = new InlineElementBox(context, getElement(), lefts);
- if (rights.length > 0) {
- right = new InlineElementBox(context, this.getElement(), rights);
- }
+ if (rights.length > 0)
+ right = new InlineElementBox(context, getElement(), rights);
return new Pair(left, right);
}
+ @Override
public String toString() {
- StringBuffer sb = new StringBuffer();
- if (this.getStartOffset() == this.getElement().getStartOffset() + 1) {
+ final StringBuffer sb = new StringBuffer();
+ if (getStartOffset() == getElement().getStartOffset() + 1) {
sb.append("<");
- sb.append(this.getElement().getPrefixedName());
+ sb.append(getElement().getPrefixedName());
sb.append(">");
}
- Box[] children = this.getChildren();
- for (int i = 0; i < children.length; i++) {
- sb.append(children[i]);
- }
- if (this.getEndOffset() == this.getElement().getEndOffset()) {
+ final Box[] children = getChildren();
+ for (final Box element2 : children)
+ sb.append(element2);
+ if (getEndOffset() == getElement().getEndOffset()) {
sb.append("</");
- sb.append(this.getElement().getPrefixedName());
+ sb.append(getElement().getPrefixedName());
sb.append(">");
}
return sb.toString();
@@ -273,53 +266,44 @@
* The end of the range to convert to inline boxes.
* @return
*/
- static InlineBoxes createInlineBoxes(LayoutContext context,
- Element element2, int startOffset, int endOffset) {
+ static InlineBoxes createInlineBoxes(final LayoutContext context, final Element element2, final int startOffset, final int endOffset) {
- InlineBoxes result = new InlineBoxes();
+ final InlineBoxes result = new InlineBoxes();
- List<Node> nodes = element2.getChildNodes();
+ final List<Node> nodes = element2.getChildNodes();
for (int i = 0; i < nodes.size(); i++) {
- Node node = nodes.get(i);
+ final Node node = nodes.get(i);
InlineBox child;
-
- if (node.getStartOffset() >= endOffset) {
+
+ if (node.getStartOffset() >= endOffset)
break;
- } else if (node instanceof Text) {
+ else if (node instanceof Text) {
// This check is different for Text and Element, so we have to
// do it here and below, too.
- if (node.getEndOffset() <= startOffset) {
+ if (node.getEndOffset() <= startOffset)
continue;
- }
- int start = Math.max(startOffset, node.getStartOffset());
- int end = Math.min(endOffset, node.getEndOffset());
- child = new DocumentTextBox(context, element2, start,
- end);
+ final int start = Math.max(startOffset, node.getStartOffset());
+ final int end = Math.min(endOffset, node.getEndOffset());
+ child = new DocumentTextBox(context, element2, start, end);
} else {
- if (node.getEndOffset() < startOffset) {
+ if (node.getEndOffset() < startOffset)
continue;
- }
- Element childElement = (Element) node;
- InlineBox placeholder = new PlaceholderBox(context,
- element2, childElement.getStartOffset()
- - element2.getStartOffset());
+ final Element childElement = (Element) node;
+ final InlineBox placeholder = new PlaceholderBox(context, element2, childElement.getStartOffset() - element2.getStartOffset());
result.boxes.add(placeholder);
- if (result.firstContentBox == null) {
+ if (result.firstContentBox == null)
result.firstContentBox = placeholder;
- }
- child = new InlineElementBox(context, childElement,
- startOffset, endOffset);
+ child = new InlineElementBox(context, childElement, startOffset, endOffset);
}
- if (result.firstContentBox == null) {
+ if (result.firstContentBox == null)
result.firstContentBox = child;
- }
result.lastContentBox = child;
@@ -331,11 +315,11 @@
// ========================================================== PRIVATE
- private static InlineBox createLeftMarker(Element element, Styles styles) {
+ private static InlineBox createLeftMarker(final Element element, final Styles styles) {
final int size = Math.round(0.5f * styles.getFontSize());
final int lift = Math.round(0.1f * styles.getFontSize());
- Drawable drawable = new Drawable() {
- public void draw(Graphics g, int x, int y) {
+ final Drawable drawable = new Drawable() {
+ public void draw(final Graphics g, final int x, int y) {
g.setLineStyle(Graphics.LINE_SOLID);
g.setLineWidth(1);
y -= lift;
@@ -351,11 +335,11 @@
return new DrawableBox(drawable, element, DrawableBox.START_MARKER);
}
- private static InlineBox createRightMarker(Element element, Styles styles) {
+ private static InlineBox createRightMarker(final Element element, final Styles styles) {
final int size = Math.round(0.5f * styles.getFontSize());
final int lift = Math.round(0.1f * styles.getFontSize());
- Drawable drawable = new Drawable() {
- public void draw(Graphics g, int x, int y) {
+ final Drawable drawable = new Drawable() {
+ public void draw(final Graphics g, final int x, int y) {
g.setLineStyle(Graphics.LINE_SOLID);
g.setLineWidth(1);
y -= lift;
@@ -371,29 +355,27 @@
return new DrawableBox(drawable, element, DrawableBox.END_MARKER);
}
- private void layout(LayoutContext context) {
- Graphics g = context.getGraphics();
- Styles styles = context.getStyleSheet().getStyles(element);
- FontResource font = g.createFont(styles.getFont());
- FontResource oldFont = g.setFont(font);
- FontMetrics fm = g.getFontMetrics();
- this.setHeight(styles.getLineHeight());
- this.halfLeading = (styles.getLineHeight() - fm.getAscent() - fm
- .getDescent()) / 2;
- this.baseline = this.halfLeading + fm.getAscent();
+ private void layout(final LayoutContext context) {
+ final Graphics g = context.getGraphics();
+ final Styles styles = context.getStyleSheet().getStyles(element);
+ final FontResource font = g.createFont(styles.getFont());
+ final FontResource oldFont = g.setFont(font);
+ final FontMetrics fm = g.getFontMetrics();
+ setHeight(styles.getLineHeight());
+ halfLeading = (styles.getLineHeight() - fm.getAscent() - fm.getDescent()) / 2;
+ baseline = halfLeading + fm.getAscent();
g.setFont(oldFont);
font.dispose();
int x = 0;
- for (int i = 0; i < this.children.length; i++) {
- InlineBox child = this.children[i];
+ for (final InlineBox child : children) {
// TODO: honour the child's vertical-align property
child.setX(x);
child.alignOnBaseline(baseline);
x += child.getWidth();
}
- this.setWidth(x);
+ setWidth(x);
}
}