summaryrefslogtreecommitdiff
path: root/javax
diff options
context:
space:
mode:
authorRoman Kennke <roman@kennke.org>2006-11-17 22:12:11 +0000
committerRoman Kennke <roman@kennke.org>2006-11-17 22:12:11 +0000
commitca2c85b24355b815db4e1b11c97d1112c6413414 (patch)
tree146ad8e3d63f4807f979a27b959475cf6e5d55ee /javax
parent38c0e491cd82d1cbe3845586e5f893083fdfbce3 (diff)
downloadclasspath-ca2c85b24355b815db4e1b11c97d1112c6413414.tar.gz
2006-11-17 Roman Kennke <kennke@aicas.com>
* gnu/javax/swing/text/html/css/CSSParser.java (parseDeclaration): Trim string before reporting. * gnu/javax/swing/text/html/css/FontSize.java (size): New field. (isRelative): New field. (sizeIndex): New field. (FontSize): Initialize new fields. (getValue): Changed to call getValue(int). (getValue(int)): New method. Implements relative font sizes. (isRelative): New method. (mapAbsolute): Store index. (mapEM): New helper method. (mapLarger): New helper method. (mapPercent): New helper method. (mapRelative): New helper method. (mapSmaller): New helper method. (mapValue): New helper method. * javax/swing/text/html/CSS.java (parseBackgroundShorthand): Create CSSColor directly. * javax/swing/text/html/StyleSheet.java (addRule): Invalidate resolved styles. (getFont): Call new getFontSize() method to resolve relative font sizes. (getFontSize): New helper method. Resolves relative font sizes. (translateHTMLToCSS): Create CSS objects directly.
Diffstat (limited to 'javax')
-rw-r--r--javax/swing/text/html/CSS.java2
-rw-r--r--javax/swing/text/html/StyleSheet.java47
2 files changed, 42 insertions, 7 deletions
diff --git a/javax/swing/text/html/CSS.java b/javax/swing/text/html/CSS.java
index 2068076e2..c82b6c537 100644
--- a/javax/swing/text/html/CSS.java
+++ b/javax/swing/text/html/CSS.java
@@ -548,7 +548,7 @@ public class CSS implements Serializable
String token = tokens.nextToken();
if (CSSColor.isValidColor(token))
atts.addAttribute(Attribute.BACKGROUND_COLOR,
- getValue(Attribute.BACKGROUND_COLOR, token));
+ new CSSColor(token));
}
}
}
diff --git a/javax/swing/text/html/StyleSheet.java b/javax/swing/text/html/StyleSheet.java
index 150b27426..aa2590464 100644
--- a/javax/swing/text/html/StyleSheet.java
+++ b/javax/swing/text/html/StyleSheet.java
@@ -484,6 +484,9 @@ public class StyleSheet extends StyleContext
// Shouldn't happen. And if, then we
System.err.println("IOException while parsing stylesheet: " + ex.getMessage());
}
+ // Clean up resolved styles cache so that the new styles are recognized
+ // on next stylesheet request.
+ resolvedStyles.clear();
}
/**
@@ -704,13 +707,13 @@ public class StyleSheet extends StyleContext
o = htmlAttrSet.getAttribute(HTML.Attribute.WIDTH);
if (o != null)
cssAttr = addAttribute(cssAttr, CSS.Attribute.WIDTH,
- CSS.getValue(CSS.Attribute.WIDTH, o.toString()));
+ new Length(o.toString()));
// The HTML height attribute maps directly to CSS height.
o = htmlAttrSet.getAttribute(HTML.Attribute.HEIGHT);
if (o != null)
cssAttr = addAttribute(cssAttr, CSS.Attribute.HEIGHT,
- CSS.getValue(CSS.Attribute.HEIGHT, o.toString()));
+ new Length(o.toString()));
o = htmlAttrSet.getAttribute(HTML.Attribute.NOWRAP);
if (o != null)
@@ -852,10 +855,7 @@ public class StyleSheet extends StyleContext
*/
public Font getFont(AttributeSet a)
{
- FontSize size = (FontSize) a.getAttribute(CSS.Attribute.FONT_SIZE);
- int realSize = 12;
- if (size != null)
- realSize = size.getValue();
+ int realSize = getFontSize(a);
// Decrement size for subscript and superscript.
Object valign = a.getAttribute(CSS.Attribute.VERTICAL_ALIGN);
@@ -880,6 +880,41 @@ public class StyleSheet extends StyleContext
}
/**
+ * Resolves the fontsize for a given set of attributes.
+ *
+ * @param atts the attributes
+ *
+ * @return the resolved font size
+ */
+ private int getFontSize(AttributeSet atts)
+ {
+ int size = 12;
+ if (atts.isDefined(CSS.Attribute.FONT_SIZE))
+ {
+ FontSize fs = (FontSize) atts.getAttribute(CSS.Attribute.FONT_SIZE);
+ if (fs.isRelative())
+ {
+ int parSize = 12;
+ AttributeSet resolver = atts.getResolveParent();
+ if (resolver != null) {
+ parSize = getFontSize(resolver);System.err.println("parent size: " + parSize); }
+ size = fs.getValue(parSize);
+ }
+ else
+ {
+ size = fs.getValue();
+ }
+ }
+ else
+ {
+ AttributeSet resolver = atts.getResolveParent();
+ if (resolver != null)
+ size = getFontSize(resolver);
+ }
+ return size;
+ }
+
+ /**
* Takes a set of attributes and turns it into a foreground
* color specification. This is used to specify things like, brigher, more hue
* etc.