summaryrefslogtreecommitdiff
path: root/gnu
diff options
context:
space:
mode:
authorAndrew John Hughes <gnu_andrew@member.fsf.org>2006-12-03 17:06:05 +0000
committerAndrew John Hughes <gnu_andrew@member.fsf.org>2006-12-03 17:06:05 +0000
commit995a16ee911442342a73cce6a4e1761cc8bd1f81 (patch)
tree9eb07e047ec678c09034c38c2ff728b622774a9b /gnu
parent306a965fe7e642bfb08eeeecfed9bd61ed857db9 (diff)
downloadclasspath-995a16ee911442342a73cce6a4e1761cc8bd1f81.tar.gz
2006-12-03 Andrew John Hughes <gnu_andrew@member.fsf.org>
* Merge of HEAD-->generics-branch for 2006/11/29 to 0.93 branch point.
Diffstat (limited to 'gnu')
-rw-r--r--gnu/java/awt/peer/gtk/BufferedImageGraphics.java72
-rw-r--r--gnu/java/awt/peer/gtk/CairoGraphics2D.java11
-rw-r--r--gnu/javax/swing/text/html/css/BorderStyle.java64
-rw-r--r--gnu/javax/swing/text/html/css/BorderWidth.java12
-rw-r--r--gnu/javax/swing/text/html/css/FontSize.java8
-rw-r--r--gnu/javax/swing/text/html/css/Length.java155
-rw-r--r--gnu/javax/swing/text/html/css/Selector.java17
-rw-r--r--gnu/javax/swing/text/html/parser/support/Parser.java40
8 files changed, 334 insertions, 45 deletions
diff --git a/gnu/java/awt/peer/gtk/BufferedImageGraphics.java b/gnu/java/awt/peer/gtk/BufferedImageGraphics.java
index 7de9c057e..37ae498ad 100644
--- a/gnu/java/awt/peer/gtk/BufferedImageGraphics.java
+++ b/gnu/java/awt/peer/gtk/BufferedImageGraphics.java
@@ -248,13 +248,13 @@ public class BufferedImageGraphics extends CairoGraphics2D
if (sm.getScanlineStride() == imageWidth && minX == 0)
{
System.arraycopy(pixels, y * imageWidth,
- db, y * imageWidth - minY,
+ db, (y - minY) * imageWidth,
height * imageWidth);
}
else
{
int scanline = sm.getScanlineStride();
- for (int i = y; i < height; i++)
+ for (int i = y; i < (height + y); i++)
System.arraycopy(pixels, i * imageWidth + x, db,
(i - minY) * scanline + x - minX, width);
@@ -313,6 +313,7 @@ public class BufferedImageGraphics extends CairoGraphics2D
Graphics2D g2d = (Graphics2D)buffer.getGraphics();
g2d.setStroke(this.getStroke());
g2d.setColor(this.getColor());
+ g2d.setTransform(transform);
g2d.draw(s);
drawComposite(r.getBounds2D(), null);
@@ -334,6 +335,7 @@ public class BufferedImageGraphics extends CairoGraphics2D
Graphics2D g2d = (Graphics2D)buffer.getGraphics();
g2d.setPaint(this.getPaint());
g2d.setColor(this.getColor());
+ g2d.setTransform(transform);
g2d.fill(s);
drawComposite(s.getBounds2D(), null);
@@ -353,6 +355,7 @@ public class BufferedImageGraphics extends CairoGraphics2D
Graphics2D g2d = (Graphics2D)buffer.getGraphics();
g2d.setRenderingHints(this.getRenderingHints());
+ g2d.setTransform(transform);
g2d.drawRenderedImage(image, xform);
drawComposite(buffer.getRaster().getBounds(), null);
@@ -427,43 +430,64 @@ public class BufferedImageGraphics extends CairoGraphics2D
Graphics2D g2d = (Graphics2D)buffer.getGraphics();
g2d.setPaint(this.getPaint());
g2d.setStroke(this.getStroke());
+ g2d.setTransform(transform);
g2d.drawGlyphVector(gv, x, y);
drawComposite(bounds, null);
}
}
+ /**
+ * Perform composite drawing from the buffer onto the main image.
+ *
+ * The image to be composited should already be drawn into the buffer, in the
+ * proper place, after all necessary transforms have been applied.
+ *
+ * @param bounds The bounds to draw, in user-space.
+ * @param observer The image observer, if any (may be null).
+ * @return True on success, false on failure.
+ */
private boolean drawComposite(Rectangle2D bounds, ImageObserver observer)
{
- // Clip source to visible areas that need updating
- Rectangle2D clip = this.getClipBounds();
- Rectangle2D.intersect(bounds, clip, bounds);
- clip = new Rectangle(buffer.getMinX(), buffer.getMinY(),
- buffer.getWidth(), buffer.getHeight());
- Rectangle2D.intersect(bounds, clip, bounds);
+ // Find bounds in device space
+ double[] points = new double[] {bounds.getX(), bounds.getY(),
+ bounds.getMaxX(), bounds.getMaxY()};
+ transform.transform(points, 0, points, 0, 2);
+ bounds = new Rectangle2D.Double(points[0], points[1],
+ (points[2] - points[0]),
+ (points[3] - points[1]));
+
+ // Clip bounds by the stored clip, and by the internal buffer
+ Rectangle2D devClip = this.getClipInDevSpace();
+ Rectangle2D.intersect(bounds, devClip, bounds);
+ devClip = new Rectangle(buffer.getMinX(), buffer.getMinY(),
+ buffer.getWidth(), buffer.getHeight());
+ Rectangle2D.intersect(bounds, devClip, bounds);
+
+ // Round bounds as needed, but be conservative in our rounding
+ // (otherwise it may leave unpainted stripes)
+ double x = bounds.getX();
+ double y = bounds.getY();
+ double w = bounds.getWidth();
+ double h = bounds.getHeight();
+ if (Math.floor(x) != x)
+ w--;
+ if (Math.floor(y) != y)
+ h--;
+ bounds.setRect(Math.ceil(x), Math.ceil(y), Math.floor(w), Math.floor(h));
+ // Find subimage of internal buffer for updating
BufferedImage buffer2 = buffer;
if (!bounds.equals(buffer2.getRaster().getBounds()))
buffer2 = buffer2.getSubimage((int)bounds.getX(), (int)bounds.getY(),
(int)bounds.getWidth(),
(int)bounds.getHeight());
-
- // Get destination clip to bounds
- double[] points = new double[] {bounds.getX(), bounds.getY(),
- bounds.getMaxX(), bounds.getMaxY()};
- transform.transform(points, 0, points, 0, 2);
-
- Rectangle2D deviceBounds = new Rectangle2D.Double(points[0], points[1],
- points[2] - points[0],
- points[3] - points[1]);
-
- Rectangle2D.intersect(deviceBounds, this.getClipInDevSpace(), deviceBounds);
-
+
+ // Find subimage of main image for updating
BufferedImage current = image;
- current = current.getSubimage((int)deviceBounds.getX(),
- (int)deviceBounds.getY(),
- (int)deviceBounds.getWidth(),
- (int)deviceBounds.getHeight());
+ current = current.getSubimage((int)bounds.getX(), (int)bounds.getY(),
+ (int)bounds.getWidth(),
+ (int)bounds.getHeight());
// Perform actual composite operation
compCtx.compose(buffer2.getRaster(), current.getRaster(),
diff --git a/gnu/java/awt/peer/gtk/CairoGraphics2D.java b/gnu/java/awt/peer/gtk/CairoGraphics2D.java
index 16de95185..ec9890524 100644
--- a/gnu/java/awt/peer/gtk/CairoGraphics2D.java
+++ b/gnu/java/awt/peer/gtk/CairoGraphics2D.java
@@ -1153,8 +1153,8 @@ public abstract class CairoGraphics2D extends Graphics2D
// does not get distorted by this shifting operation
double x = shiftX(r.getX(),shiftDrawCalls && isDraw);
double y = shiftY(r.getY(), shiftDrawCalls && isDraw);
- double w = shiftX(r.getWidth() + r.getX(), shiftDrawCalls && isDraw) - x;
- double h = shiftY(r.getHeight() + r.getY(), shiftDrawCalls && isDraw) - y;
+ double w = Math.round(r.getWidth());
+ double h = Math.round(r.getHeight());
cairoRectangle(nativePointer, x, y, w, h);
}
@@ -1506,8 +1506,11 @@ public abstract class CairoGraphics2D extends Graphics2D
setBackground(bgcolor);
double[] origin = new double[] {0,0};
+ double[] dimensions = new double[] {width, height};
xform.transform(origin, 0, origin, 0, 1);
- clearRect((int)origin[0], (int)origin[1], width, height);
+ xform.deltaTransform(dimensions, 0, dimensions, 0, 1);
+ clearRect((int)origin[0], (int)origin[1],
+ (int)dimensions[0], (int)dimensions[1]);
setBackground(oldColor);
}
@@ -2051,4 +2054,4 @@ public abstract class CairoGraphics2D extends Graphics2D
return rect;
}
-}
+} \ No newline at end of file
diff --git a/gnu/javax/swing/text/html/css/BorderStyle.java b/gnu/javax/swing/text/html/css/BorderStyle.java
new file mode 100644
index 000000000..d75beea52
--- /dev/null
+++ b/gnu/javax/swing/text/html/css/BorderStyle.java
@@ -0,0 +1,64 @@
+/* BorderStyle.java -- Utility for dealing with border styles
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.javax.swing.text.html.css;
+
+/**
+ * Utility class for handling border styles.
+ */
+public class BorderStyle
+{
+
+ /**
+ * Determines if a given value makes up a valid border style value.
+ *
+ * @param value the value to check
+ *
+ * @return <code>true</code> when this is a valid border style,
+ * <code>false</code> otherwise
+ */
+ public static boolean isValidStyle(String value)
+ {
+ return value.equals("none") || value.equals("hidden")
+ || value.equals("dotted") || value.equals("dashed")
+ || value.equals("solid") || value.equals("double")
+ || value.equals("groove") || value.equals("ridge")
+ || value.equals("inset") || value.equals("outset");
+
+ }
+}
diff --git a/gnu/javax/swing/text/html/css/BorderWidth.java b/gnu/javax/swing/text/html/css/BorderWidth.java
index b717020e3..ae64c2110 100644
--- a/gnu/javax/swing/text/html/css/BorderWidth.java
+++ b/gnu/javax/swing/text/html/css/BorderWidth.java
@@ -63,4 +63,16 @@ public class BorderWidth
floatValue = 3.F;
}
+ /**
+ * Checks if the specified value makes up a valid border-width value.
+ *
+ * @param value the value to check
+ *
+ * @return <code>true</code> if the value is a valid border-width
+ */
+ public static boolean isValid(String value)
+ {
+ return value.equals("thin") || value.equals("medium")
+ || value.equals("thick") || Length.isValid(value);
+ }
}
diff --git a/gnu/javax/swing/text/html/css/FontSize.java b/gnu/javax/swing/text/html/css/FontSize.java
index 7dc8d46c6..2795b6784 100644
--- a/gnu/javax/swing/text/html/css/FontSize.java
+++ b/gnu/javax/swing/text/html/css/FontSize.java
@@ -255,13 +255,13 @@ public class FontSize
private int mapRelative(int par)
{
- if (value.contains("%"))
+ if (value.indexOf('%') != -1)
size = mapPercent(par);
- else if (value.contains("em"))
+ else if (value.indexOf("em") != -1)
size = mapEM(par);
- else if (value.contains("larger"))
+ else if (value.indexOf("larger") != -1)
size = mapLarger(par);
- else if (value.contains("smaller"))
+ else if (value.indexOf("smaller") != -1)
size = mapSmaller(par);
return size;
}
diff --git a/gnu/javax/swing/text/html/css/Length.java b/gnu/javax/swing/text/html/css/Length.java
index 339e2a2e0..06fa36e3d 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.
*
@@ -135,4 +231,53 @@ public class Length
{
return isPercentage;
}
+
+ /**
+ * Checks if the specified value makes up a valid length value.
+ *
+ * @param value the value to check
+ *
+ * @return <code>true</code> if the value is a valid length
+ */
+ public static boolean isValid(String value)
+ {
+ boolean isValid = true;
+ int px = value.indexOf("px");
+ int em = value.indexOf("em");
+ int ex = value.indexOf("ex");
+ int pc = value.indexOf('%');
+ try
+ {
+ if (px != -1)
+ {
+ Integer.parseInt(value.substring(0, px));
+ }
+ else if (em != -1)
+ {
+ Integer.parseInt(value.substring(0, em));
+ }
+ else if (ex != -1)
+ {
+ Integer.parseInt(value.substring(0, ex));
+ }
+ else if (pc != -1)
+ {
+ Integer.parseInt(value.substring(0, ex));
+ }
+ else
+ {
+ Integer.parseInt(value);
+ }
+ }
+ catch (NumberFormatException nfe)
+ {
+ isValid = false;
+ }
+ return isValid;
+ }
+
+ public String toString()
+ {
+ return value;
+ }
}
diff --git a/gnu/javax/swing/text/html/css/Selector.java b/gnu/javax/swing/text/html/css/Selector.java
index b8128233b..210df3a7b 100644
--- a/gnu/javax/swing/text/html/css/Selector.java
+++ b/gnu/javax/swing/text/html/css/Selector.java
@@ -38,6 +38,7 @@ exception statement from your version. */
package gnu.javax.swing.text.html.css;
+import java.util.Map;
import java.util.StringTokenizer;
/**
@@ -98,7 +99,7 @@ public class Selector
* @return <code>true</code> when this selector matches the element path,
* <code>false</code> otherwise
*/
- public boolean matches(String[] tags, String[] pathClasses, String[] pathIds)
+ public boolean matches(String[] tags, Map[] attributes)
{
// TODO: This implements class, id and descendent matching. These are
// the most commonly used selector matchers in CSS together with HTML.
@@ -119,15 +120,22 @@ public class Selector
boolean tagMatch = false;
for (; tagIndex < numTags && tagMatch == false; tagIndex++)
{
+ Object pathClass = attributes[tagIndex].get("class");
+ // Try pseudo class too.
+ Object pseudoClass = attributes[tagIndex].get("_pseudo");
+ Object dynClass = attributes[tagIndex].get("_dynamic");
+ Object pathId = attributes[tagIndex].get("id");
String tag = elements[j];
String clazz = classes[j];
String id = ids[j];
tagMatch = tag.equals("") || tag.equals("*")
|| tag.equals(tags[tagIndex]);
tagMatch = tagMatch && (clazz.equals("*")
- || clazz.equals(pathClasses[tagIndex]));
+ || clazz.equals(dynClass)
+ || clazz.equals(pseudoClass)
+ || clazz.equals(pathClass));
tagMatch = tagMatch && (id.equals("*")
- || id.equals(pathIds[tagIndex]));
+ || id.equals(pathId));
// For the last element in the selector we must not look
// further.
if (j == 0)
@@ -190,6 +198,9 @@ public class Selector
{
String sel = selector[i];
int clazzIndex = sel.indexOf('.');
+ // Try pseudo class too.
+ if (clazzIndex == -1)
+ clazzIndex = sel.indexOf(':');
int idIndex = sel.indexOf('#');
String clazz;
if (clazzIndex == -1)
diff --git a/gnu/javax/swing/text/html/parser/support/Parser.java b/gnu/javax/swing/text/html/parser/support/Parser.java
index 98058e503..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();
@@ -1181,6 +1186,13 @@ public class Parser
{
validator.validateTag(tag, attributes);
handleEmptyTag(tag);
+ HTML.Tag h = tag.getHTMLTag();
+ // When a block tag is closed, consume whitespace that follows after
+ // 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 (isBlock(h))
+ optional(WS);
}
catch (ChangedCharSetException ex)
{
@@ -1219,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)
@@ -1248,6 +1260,9 @@ public class Parser
HTML.Tag h = tag.getHTMLTag();
+ if (isBlock(h))
+ optional(WS);
+
if (h.isPreformatted())
preformatted++;
@@ -1495,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;
+ }
}