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 /javax/swing/text/html/StyleSheet.java | |
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 'javax/swing/text/html/StyleSheet.java')
-rw-r--r-- | javax/swing/text/html/StyleSheet.java | 82 |
1 files changed, 70 insertions, 12 deletions
diff --git a/javax/swing/text/html/StyleSheet.java b/javax/swing/text/html/StyleSheet.java index 27d69bf4b..1f3d14b5e 100644 --- a/javax/swing/text/html/StyleSheet.java +++ b/javax/swing/text/html/StyleSheet.java @@ -52,6 +52,8 @@ import java.awt.Font; import java.awt.Graphics; import java.awt.Rectangle; import java.awt.Shape; +import java.awt.font.FontRenderContext; +import java.awt.geom.Rectangle2D; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -882,7 +884,37 @@ public class StyleSheet extends StyleContext style |= fStyle.getValue(); return new Font(family, style, realSize); } - + + /** + * Determines the EM base value based on the specified attributes. + * + * @param atts the attibutes + * + * @return the EM base value + */ + float getEMBase(AttributeSet atts) + { + Font font = getFont(atts); + FontRenderContext ctx = new FontRenderContext(null, false, false); + Rectangle2D bounds = font.getStringBounds("M", ctx); + return (float) bounds.getWidth(); + } + + /** + * Determines the EX base value based on the specified attributes. + * + * @param atts the attibutes + * + * @return the EX base value + */ + float getEXBase(AttributeSet atts) + { + Font font = getFont(atts); + FontRenderContext ctx = new FontRenderContext(null, false, false); + Rectangle2D bounds = font.getStringBounds("x", ctx); + return (float) bounds.getHeight(); + } + /** * Resolves the fontsize for a given set of attributes. * @@ -1120,49 +1152,75 @@ public class StyleSheet extends StyleContext */ BoxPainter(AttributeSet as, StyleSheet ss) { + float emBase = ss.getEMBase(as); + float exBase = ss.getEXBase(as); // Fetch margins. Length l = (Length) as.getAttribute(CSS.Attribute.MARGIN); if (l != null) { + l.setFontBases(emBase, exBase); topInset = bottomInset = leftInset = rightInset = l.getValue(); } l = (Length) as.getAttribute(CSS.Attribute.MARGIN_LEFT); if (l != null) - leftInset = l.getValue(); - else if (as.getAttribute(StyleConstants.NameAttribute) == HTML.Tag.UL) - System.err.println("UL margin left value: " + l + " atts: " + as); + { + l.setFontBases(emBase, exBase); + leftInset = l.getValue(); + } l = (Length) as.getAttribute(CSS.Attribute.MARGIN_RIGHT); if (l != null) - rightInset = l.getValue(); + { + l.setFontBases(emBase, exBase); + rightInset = l.getValue(); + } l = (Length) as.getAttribute(CSS.Attribute.MARGIN_TOP); if (l != null) - topInset = l.getValue(); + { + l.setFontBases(emBase, exBase); + topInset = l.getValue(); + } l = (Length) as.getAttribute(CSS.Attribute.MARGIN_BOTTOM); if (l != null) - bottomInset = l.getValue(); + { + l.setFontBases(emBase, exBase); + bottomInset = l.getValue(); + } // Fetch padding. l = (Length) as.getAttribute(CSS.Attribute.PADDING); if (l != null) { + l.setFontBases(emBase, exBase); leftPadding = rightPadding = topPadding = bottomPadding = l.getValue(); } l = (Length) as.getAttribute(CSS.Attribute.PADDING_LEFT); if (l != null) - leftPadding = l.getValue(); + { + l.setFontBases(emBase, exBase); + leftPadding = l.getValue(); + } l = (Length) as.getAttribute(CSS.Attribute.PADDING_RIGHT); if (l != null) - rightPadding = l.getValue(); + { + l.setFontBases(emBase, exBase); + rightPadding = l.getValue(); + } l = (Length) as.getAttribute(CSS.Attribute.PADDING_TOP); if (l != null) - topPadding = l.getValue(); + { + l.setFontBases(emBase, exBase); + topPadding = l.getValue(); + } l = (Length) as.getAttribute(CSS.Attribute.PADDING_BOTTOM); if (l != null) - bottomPadding = l.getValue(); + { + l.setFontBases(emBase, exBase); + bottomPadding = l.getValue(); + } // Determine border. - border = new CSSBorder(as); + border = new CSSBorder(as, ss); // Determine background. background = ss.getBackground(as); |