diff options
author | Roman Kennke <roman@kennke.org> | 2006-12-01 14:43:42 +0000 |
---|---|---|
committer | Roman Kennke <roman@kennke.org> | 2006-12-01 14:43:42 +0000 |
commit | 5bce0abfef6817e4299bc0640baf46b5f873d530 (patch) | |
tree | 07707896fdf219b9fac9903a491fd67beaa0e22f /gnu/javax | |
parent | 73ee7fab7219cb0edb4ded57f73dea804846d6b2 (diff) | |
download | classpath-5bce0abfef6817e4299bc0640baf46b5f873d530.tar.gz |
2006-11-30 Roman Kennke <kennke@aicas.com>
* gnu/javax/swing/text/html/css/Length.java
(emBase): New field.
(exBase): New field.
(isFontEMRelative): New field.
(isFontEXRelative): New field.
(Length): Recognize and setup EM and EX relative values.
(getValue): Handle EM and EX relative values.
(isEMRelative): New method.
(isEXRelative): New method.
(setEMBase): New method.
(setEXBase): New method.
(setFontBases): New method.
* gnu/javax/swing/text/html/parser/support/Parser.java
(_handleEmptyTag): Use new isBlock() helper method.
(_handleEndTag_remaining): Use new isBlock() helper method.
(_handleStartTag): Consume whitespace after block start tag.
(Comment): Consume whitespace after a comment.
(isBlock): New helper method.
(readAttributes): Consider all characters in unquoted attribute
values.
* javax/swing/text/html/BlockView.java
(layoutMinorAxis): Use cached span value.
(paint): Added debug code (commented out).
(setPropertiesFromAttributes): Set the EM and EX base on lengths.
* javax/swing/text/html/CSSBorder.java
(CSSBorder): Take StyleSheet as argument. Call getBorderWidth()
with stylesheet.
(getBorderWidth): Set the EM and EX base on the length values.
* javax/swing/text/html/HTMLDocument.java
(HTMLReader.ParagraphAction.end): Do not set the inParagraph field.
(HTMLReader.ParagraphAction.start): Do not set the inParagraph field.
(HTMLReader.inImpliedParagraph): Removed.
(HTMLReader.inParagraph): Removed.
(HTMLReader.parseStack): New field.
(HTMLReader.addContent): Use new paragraph handling.
(HTMLReader.addSpecialElement): Use new paragraph handling.
(HTMLReader.blockClose): Use new paragraph handling.
(HTMLReader.blockOpen): Use new paragraph handling.
(HTMLReader.inImpliedParagraph): New helper method.
(HTMLReader.inParagraph): New helper method.
* javax/swing/text/html/ImageView.java
(attributes): New field. Caches view attributes.
(spans): New field. Caches CSS spans.
(getAttributes): Correctly setup CSS view attributes.
(getPreferredSpan): Use caches spans.
(getStyleSheet): Use the view's getDocument() method.
(setPropertiesFromAttributes): Cache spans and setup EM and EX.
(updateSize): Use cached spans.
* javax/swing/text/html/ParagraphView.java
(setPropertiesFromAttributes): Setup EM and EX.
* javax/swing/text/html/StyleSheet.java
(BoxPainter.BoxPainter): Setup EM and EX correctly.
(getEMBase): New helper method.
(getEXBase): New helper method.
* javax/swing/text/html/TableView.java
(width): New field. Caches the table width.
(calculateMinorAxisRequirements): Use caches span.
(setPropertiesFromAttributes): Cache span and setup EM/EX.
(updateGrid): Correctly setup EM/EX.
Diffstat (limited to 'gnu/javax')
-rw-r--r-- | gnu/javax/swing/text/html/css/Length.java | 106 | ||||
-rw-r--r-- | gnu/javax/swing/text/html/parser/support/Parser.java | 35 |
2 files changed, 130 insertions, 11 deletions
diff --git a/gnu/javax/swing/text/html/css/Length.java b/gnu/javax/swing/text/html/css/Length.java index 339e2a2e0..06e1ce1ac 100644 --- a/gnu/javax/swing/text/html/css/Length.java +++ b/gnu/javax/swing/text/html/css/Length.java @@ -62,15 +62,40 @@ public class Length private boolean isPercentage; /** + * Indicates a length value that is relative to the font size (em). + */ + private boolean isFontEMRelative; + + /** + * Indicates a length value that is relative to the font size (ex). + */ + private boolean isFontEXRelative; + + /** + * The EM base size. + */ + private float emBase; + + /** + * The EX base size. + */ + private float exBase; + + /** * Creates a new length converter instance. * * @param val the CSS value */ public Length(String val) { + isFontEMRelative = false; + isFontEXRelative = false; + isPercentage = false; value = val; int i = value.indexOf("px"); int percent = value.indexOf("%"); + int em = value.indexOf("em"); + int ex = value.indexOf("ex"); try { floatValue = 0.0F; @@ -85,13 +110,24 @@ public class Length String sub = value.substring(0, percent); floatValue = Float.parseFloat(sub) / 100; } + else if (em != -1) + { + isFontEMRelative = true; + String sub = value.substring(0, em); + floatValue = Float.parseFloat(sub); + } + else if (ex != -1) + { + isFontEXRelative = true; + String sub = value.substring(0, ex); + floatValue = Float.parseFloat(sub); + } else { - // TODO: Implement other length options. floatValue = Float.parseFloat(value); } } - catch (NumberFormatException ex) + catch (NumberFormatException exc) { // Don't let such small problems interrupt CSS parsing. System.err.println("couldn't parse: " + val); @@ -112,19 +148,79 @@ public class Length * Returns the absolute span for the case when this length value is * a relative value. * - * @param available the target span + * @param base the base span * * @return the absolute span */ - public float getValue(float available) + public float getValue(float base) { float span = floatValue; if (isPercentage) - span *= available; + span *= base; + else if (isFontEMRelative) + span *= emBase; + else if (isFontEXRelative) + span *= exBase; return span; } /** + * Sets the font relative EM base. + * + * @param base the font relative EM base + */ + public void setEMBase(float base) + { + emBase = base; + } + + /** + * Sets the font relative EX base. + * + * @param base the font relative EX base + */ + public void setEXBase(float base) + { + exBase = base; + } + + /** + * Sets the font relative base values. + * + * @param emBase the EM base + * @param exBase the EX base + */ + public void setFontBases(float emBase, float exBase) + { + setEMBase(emBase); + setEXBase(exBase); + } + + /** + * Returns true when this length value is an em font relative value. In + * order to get correct results, you need the exBase property set up + * correctly. + * + * @return true when this length value is an ex font relative value + */ + public boolean isFontEMRelative() + { + return isFontEMRelative; + } + + /** + * Returns true when this length value is an ex font relative value. In + * order to get correct results, you need the emBase property set up + * correctly. + * + * @return true when this length value is an ex font relative value + */ + public boolean isFontEXRelative() + { + return isFontEXRelative; + } + + /** * Returns <code>true</code> when the length value is a percentage * value, <code>false</code> otherwise. * diff --git a/gnu/javax/swing/text/html/parser/support/Parser.java b/gnu/javax/swing/text/html/parser/support/Parser.java index f6747ef84..f04c58138 100644 --- a/gnu/javax/swing/text/html/parser/support/Parser.java +++ b/gnu/javax/swing/text/html/parser/support/Parser.java @@ -498,6 +498,9 @@ public class Parser mustBe(t.kind); } hTag = new Token(start, last); + + // Consume any whitespace immediately following a comment. + optional(WS); handleComment(); } @@ -983,13 +986,15 @@ public class Parser + next.getImage() + "'"); attrValue = value.getImage(); } - else if (next.kind == SLASH) - // The slash in this context is treated as the ordinary - // character, not as a token. The slash may be part of + else if (next.kind == SLASH || next.kind == OTHER) + // The slash and other characters (like %) in this context is + // treated as the ordinary + // character, not as a token. The character may be part of // the unquoted URL. { StringBuffer image = new StringBuffer(value.getImage()); - while (next.kind == NUMTOKEN || next.kind == SLASH) + while (next.kind == NUMTOKEN || next.kind == SLASH + || next.kind == OTHER) { image.append(getNextToken().getImage()); next = getTokenAhead(); @@ -1186,7 +1191,7 @@ public class Parser // it. // For some unknown reason a FRAME tag is not treated as block element. // However in this case it should be treated as such. - if (h.isBlock() || h == HTML.Tag.FRAME) + if (isBlock(h)) optional(WS); } catch (ChangedCharSetException ex) @@ -1226,7 +1231,7 @@ public class Parser // When a block tag is closed, consume whitespace that follows after // it. - if (h.isBlock()) + if (isBlock(h)) optional(WS); if (h == HTML.Tag.TITLE) @@ -1255,6 +1260,9 @@ public class Parser HTML.Tag h = tag.getHTMLTag(); + if (isBlock(h)) + optional(WS); + if (h.isPreformatted()) preformatted++; @@ -1502,4 +1510,19 @@ public class Parser { error("Whitespace here is not permitted"); } + + /** + * Returns true when the specified tag should be considered a block tag + * wrt whitespace handling. We need this special handling, since there + * are a couple of tags that we must treat as block tags but which aren't + * officially block tags. + * + * @param tag the tag to check + * @return true when the specified tag should be considered a block tag + * wrt whitespace handling + */ + private boolean isBlock(HTML.Tag tag) + { + return tag.isBlock() || tag == HTML.Tag.STYLE || tag == HTML.Tag.FRAME; + } } |