You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by de...@apache.org on 2003/05/28 16:40:58 UTC
cvs commit: xml-batik/sources/org/apache/batik/extension/svg BatikExtConstants.java BatikMultiImageElementBridge.java MultiResGraphicsNode.java
deweese 2003/05/28 07:40:57
Modified: samples/extensions multi.svg
samples/extensions/opera opera-1-0-0.svg opera-1-0-2.svg
opera-2-0-0.svg opera-3-0-0.svg
sources/org/apache/batik/bridge BridgeContext.java
SVGUtilities.java
sources/org/apache/batik/extension/svg
BatikExtConstants.java
BatikMultiImageElementBridge.java
MultiResGraphicsNode.java
Added: samples/extensions/opera opera.svg
Log:
Updated multiImage element to match 1.2 specification for external
file references (uses subImageRef instead of subImage and
min/max-pixel-size instead of pixel-width/height.
extensions/multi.svg and extensions/opera have been updated and I
added a 'top-level' svg for opera.
Revision Changes Path
1.4 +13 -13 xml-batik/samples/extensions/multi.svg
Index: multi.svg
===================================================================
RCS file: /home/cvs/xml-batik/samples/extensions/multi.svg,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- multi.svg 3 Oct 2002 18:57:13 -0000 1.3
+++ multi.svg 28 May 2003 14:40:57 -0000 1.4
@@ -22,23 +22,23 @@
<svg width="450" height="500" xml:space="preserve"
viewBox="0 0 450 500"
xmlns="http://www.w3.org/2000/svg"
- xmlns:xlink="http://www.w3.org/1999/xlink"
- xmlns:batikExt="http://xml.apache.org/batik/ext">
+ xmlns:xlink="http://www.w3.org/1999/xlink">
<title>MultiImage Extension Tag</title>
<defs>
<g id="sample">
<rect fill="#ADA" x="0" y="0" width="280" height="400"/>
- <batikExt:multiImage id="img" xlink:href="multi1.jpg"
- x="20" y="20" width="240" height="360"
- pixel-width="480" pixel-height="720">
- <batikExt:subImage xlink:href="multi2.jpg"
- pixel-width="240" pixel-height="360"/>
- <batikExt:subImage xlink:href="multi3.jpg"
- pixel-width="120" pixel-height="180"/>
- <batikExt:subImage xlink:href="multi4.jpg"
- pixel-width="60" pixel-height="90"/>
- </batikExt:multiImage>
+ <multiImage id="img" x="20" y="20" width="240" height="360"
+ xmlns="http://xml.apache.org/batik/ext">
+ <subImageRef xlink:href="multi1.jpg"
+ max-pixel-size="1"/>
+ <subImageRef xlink:href="multi2.jpg"
+ min-pixel-size="1" max-pixel-size="2"/>
+ <subImageRef xlink:href="multi3.jpg"
+ min-pixel-size="2" max-pixel-size="4"/>
+ <subImageRef xlink:href="multi4.jpg"
+ min-pixel-size="4"/>
+ </multiImage>
</g>
</defs>
1.2 +39 -29 xml-batik/samples/extensions/opera/opera-1-0-0.svg
Index: opera-1-0-0.svg
===================================================================
RCS file: /home/cvs/xml-batik/samples/extensions/opera/opera-1-0-0.svg,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- opera-1-0-0.svg 3 Oct 2002 18:57:13 -0000 1.1
+++ opera-1-0-0.svg 28 May 2003 14:40:57 -0000 1.2
@@ -2,33 +2,43 @@
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg width="360" height="360" viewBox="0 0 360 360"
-xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:batikExt="http://xml.apache.org/batik/ext">
- <batikExt:multiImage x="0" y="0" width="180" height="180"
- xlink:href="multires/opera-1-0-0.jpg"
- pixel-width="180" pixel-height="180">
- <batikExt:subImage xlink:href="opera-0-0-0.svg"
- pixel-width="360" pixel-height="360"/>
- </batikExt:multiImage>
- <rect class="overlay" fill="none" stroke="#FF0" stroke-width="4" x="0" y="0" width="180" height="180"/>
- <batikExt:multiImage x="180" y="0" width="180" height="180"
- xlink:href="multires/opera-1-1-0.jpg"
- pixel-width="180" pixel-height="180">
- <batikExt:subImage xlink:href="opera-0-2-0.svg"
- pixel-width="360" pixel-height="360"/>
- </batikExt:multiImage>
- <rect class="overlay" fill="none" stroke="#FF0" stroke-width="4" x="180" y="0" width="180" height="180"/>
- <batikExt:multiImage x="0" y="180" width="180" height="180"
- xlink:href="multires/opera-1-0-1.jpg"
- pixel-width="180" pixel-height="180">
- <batikExt:subImage xlink:href="opera-0-0-2.svg"
- pixel-width="360" pixel-height="360"/>
- </batikExt:multiImage>
- <rect class="overlay" fill="none" stroke="#FF0" stroke-width="4" x="0" y="180" width="180" height="180"/>
- <batikExt:multiImage x="180" y="180" width="180" height="180"
- xlink:href="multires/opera-1-1-1.jpg"
- pixel-width="180" pixel-height="180">
- <batikExt:subImage xlink:href="opera-0-2-2.svg"
- pixel-width="360" pixel-height="360"/>
- </batikExt:multiImage>
- <rect class="overlay" fill="none" stroke="#FF0" stroke-width="4" x="180" y="180" width="180" height="180"/>
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink">
+ <multiImage x="0" y="0" width="180" height="180"
+ xmlns="http://xml.apache.org/batik/ext">
+ <subImageRef xlink:href="multires/opera-1-0-0.jpg"
+ min-pixel-size="1"/>
+ <subImageRef xlink:href="opera-0-0-0.svg"
+ max-pixel-size="1"/>
+ </multiImage>
+ <multiImage x="180" y="0" width="180" height="180"
+ xmlns="http://xml.apache.org/batik/ext">
+ <subImageRef xlink:href="multires/opera-1-1-0.jpg"
+ min-pixel-size="1"/>
+ <subImageRef xlink:href="opera-0-2-0.svg"
+ max-pixel-size="1"/>
+ </multiImage>
+ <multiImage x="0" y="180" width="180" height="180"
+ xmlns="http://xml.apache.org/batik/ext">
+ <subImageRef xlink:href="multires/opera-1-0-1.jpg"
+ min-pixel-size="1"/>
+ <subImageRef xlink:href="opera-0-0-2.svg"
+ max-pixel-size="1"/>
+ </multiImage>
+ <multiImage x="180" y="180" width="180" height="180"
+ xmlns="http://xml.apache.org/batik/ext">
+ <subImageRef xlink:href="multires/opera-1-1-1.jpg"
+ min-pixel-size="1"/>
+ <subImageRef xlink:href="opera-0-2-2.svg"
+ max-pixel-size="1"/>
+ </multiImage>
+
+ <rect class="overlay" fill="none" stroke="#FF0" stroke-width="4"
+ x="0" y="0" width="180" height="180"/>
+ <rect class="overlay" fill="none" stroke="#FF0" stroke-width="4"
+ x="180" y="0" width="180" height="180"/>
+ <rect class="overlay" fill="none" stroke="#FF0" stroke-width="4"
+ x="0" y="180" width="180" height="180"/>
+ <rect class="overlay" fill="none" stroke="#FF0" stroke-width="4"
+ x="180" y="180" width="180" height="180"/>
</svg>
1.2 +21 -15 xml-batik/samples/extensions/opera/opera-1-0-2.svg
Index: opera-1-0-2.svg
===================================================================
RCS file: /home/cvs/xml-batik/samples/extensions/opera/opera-1-0-2.svg,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- opera-1-0-2.svg 3 Oct 2002 18:57:13 -0000 1.1
+++ opera-1-0-2.svg 28 May 2003 14:40:57 -0000 1.2
@@ -2,19 +2,25 @@
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg width="360" height="180" viewBox="0 0 360 180"
-xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:batikExt="http://xml.apache.org/batik/ext">
- <batikExt:multiImage x="0" y="0" width="180" height="180"
- xlink:href="multires/opera-1-0-2.jpg"
- pixel-width="180" pixel-height="180">
- <batikExt:subImage xlink:href="opera-0-0-4.svg"
- pixel-width="360" pixel-height="360"/>
- </batikExt:multiImage>
- <rect class="overlay" fill="none" stroke="#FF0" stroke-width="4" x="0" y="0" width="180" height="180"/>
- <batikExt:multiImage x="180" y="0" width="180" height="180"
- xlink:href="multires/opera-1-1-2.jpg"
- pixel-width="180" pixel-height="180">
- <batikExt:subImage xlink:href="opera-0-2-4.svg"
- pixel-width="360" pixel-height="360"/>
- </batikExt:multiImage>
- <rect class="overlay" fill="none" stroke="#FF0" stroke-width="4" x="180" y="0" width="180" height="180"/>
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink">
+ <multiImage x="0" y="0" width="180" height="180"
+ xmlns="http://xml.apache.org/batik/ext">
+ <subImageRef xlink:href="multires/opera-1-0-2.jpg"
+ min-pixel-size="1"/>
+ <subImageRef xlink:href="opera-0-0-4.svg"
+ max-pixel-size="1"/>
+ </multiImage>
+ <multiImage x="180" y="0" width="180" height="180"
+ xmlns="http://xml.apache.org/batik/ext">
+ <subImageRef xlink:href="multires/opera-1-1-2.jpg"
+ min-pixel-size="1"/>
+ <subImageRef xlink:href="opera-0-2-4.svg"
+ max-pixel-size="1"/>
+ </multiImage>
+
+ <rect class="overlay" fill="none" stroke="#FF0" stroke-width="4"
+ x="0" y="0" width="180" height="180"/>
+ <rect class="overlay" fill="none" stroke="#FF0" stroke-width="4"
+ x="180" y="0" width="180" height="180"/>
</svg>
1.2 +22 -15 xml-batik/samples/extensions/opera/opera-2-0-0.svg
Index: opera-2-0-0.svg
===================================================================
RCS file: /home/cvs/xml-batik/samples/extensions/opera/opera-2-0-0.svg,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- opera-2-0-0.svg 3 Oct 2002 18:57:13 -0000 1.1
+++ opera-2-0-0.svg 28 May 2003 14:40:57 -0000 1.2
@@ -2,19 +2,26 @@
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg width="180" height="270" viewBox="0 0 180 270"
-xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:batikExt="http://xml.apache.org/batik/ext">
- <batikExt:multiImage x="0" y="0" width="180" height="180"
- xlink:href="multires/opera-2-0-0.jpg"
- pixel-width="180" pixel-height="180">
- <batikExt:subImage xlink:href="opera-1-0-0.svg"
- pixel-width="360" pixel-height="360"/>
- </batikExt:multiImage>
- <rect class="overlay" fill="none" stroke="#0F0" stroke-width="4" x="0" y="0" width="180" height="180"/>
- <batikExt:multiImage x="0" y="180" width="180" height="90"
- xlink:href="multires/opera-2-0-1.jpg"
- pixel-width="180" pixel-height="90">
- <batikExt:subImage xlink:href="opera-1-0-2.svg"
- pixel-width="360" pixel-height="180"/>
- </batikExt:multiImage>
- <rect class="overlay" fill="none" stroke="#0F0" stroke-width="4" x="0" y="180" width="180" height="90"/>
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink">
+ <multiImage x="0" y="0" width="180" height="180"
+ xmlns="http://xml.apache.org/batik/ext">
+ <subImageRef xlink:href="multires/opera-2-0-0.jpg"
+ min-pixel-size="1"/>
+ <subImageRef xlink:href="opera-1-0-0.svg"
+ max-pixel-size="1"/>
+ </multiImage>
+
+ <multiImage x="0" y="180" width="180" height="90"
+ xmlns="http://xml.apache.org/batik/ext">
+ <subImageRef xlink:href="multires/opera-2-0-1.jpg"
+ min-pixel-size="1"/>
+ <subImageRef xlink:href="opera-1-0-2.svg"
+ max-pixel-size="1"/>
+ </multiImage>
+
+ <rect class="overlay" fill="none" stroke="#0F0" stroke-width="4"
+ x="0" y="0" width="180" height="180"/>
+ <rect class="overlay" fill="none" stroke="#0F0" stroke-width="4"
+ x="0" y="180" width="180" height="90"/>
</svg>
1.2 +11 -8 xml-batik/samples/extensions/opera/opera-3-0-0.svg
Index: opera-3-0-0.svg
===================================================================
RCS file: /home/cvs/xml-batik/samples/extensions/opera/opera-3-0-0.svg,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- opera-3-0-0.svg 3 Oct 2002 18:57:13 -0000 1.1
+++ opera-3-0-0.svg 28 May 2003 14:40:57 -0000 1.2
@@ -2,12 +2,15 @@
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg width="90" height="135" viewBox="0 0 90 135"
-xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:batikExt="http://xml.apache.org/batik/ext">
- <batikExt:multiImage x="0" y="0" width="90" height="135"
- xlink:href="multires/opera-3-0-0.jpg"
- pixel-width="90" pixel-height="135">
- <batikExt:subImage xlink:href="opera-2-0-0.svg"
- pixel-width="180" pixel-height="270"/>
- </batikExt:multiImage>
- <rect class="overlay" fill="none" stroke="#00F" stroke-width="4" x="0" y="0" width="90" height="135"/>
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink">
+ <multiImage x="0" y="0" width="90" height="135"
+ xmlns="http://xml.apache.org/batik/ext">
+ <subImageRef xlink:href="multires/opera-3-0-0.jpg"
+ min-pixel-size="1"/>
+ <subImageRef xlink:href="opera-2-0-0.svg"
+ max-pixel-size="1"/>
+ </multiImage>
+ <rect class="overlay" fill="none" stroke="#00F" stroke-width="4"
+ x="0" y="0" width="90" height="135"/>
</svg>
1.1 xml-batik/samples/extensions/opera/opera.svg
Index: opera.svg
===================================================================
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg width="640" height="480" viewBox="0 0 640 480"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<image x="165" y="50" width="270" height="405"
xlink:href="opera-3-0-0.svg" />
<image x="10" y="50" width="135" height="202.5"
xlink:href="opera-3-0-0.svg" />
<image x="43.75" y="272.5" width="67.5" height="101.25"
xlink:href="opera-3-0-0.svg" />
</svg>
1.61 +13 -22 xml-batik/sources/org/apache/batik/bridge/BridgeContext.java
Index: BridgeContext.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/BridgeContext.java,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -r1.60 -r1.61
--- BridgeContext.java 24 Apr 2003 00:31:36 -0000 1.60
+++ BridgeContext.java 28 May 2003 14:40:57 -0000 1.61
@@ -589,47 +589,38 @@
// Bridge management /////////////////////////////////////////////////////
/**
- * Returns the bridge associated with the specified element.
+ * Returns true if the specified element has a GraphicsNodeBridge
+ * associated to it, false otherwise.
*
* @param element the element
*/
- public Bridge getBridge(Element element) {
+ public boolean hasGraphicsNodeBridge(Element element) {
if (namespaceURIMap == null || element == null) {
- return null;
+ return false;
}
- String namespaceURI = element.getNamespaceURI();
String localName = element.getLocalName();
+ String namespaceURI = element.getNamespaceURI();
namespaceURI = ((namespaceURI == null)? "" : namespaceURI);
HashMap localNameMap = (HashMap) namespaceURIMap.get(namespaceURI);
if (localNameMap == null) {
- return null;
- }
- Bridge bridge = (Bridge)localNameMap.get(localName);
- if (dynamic) {
- return bridge == null ? null : bridge.getInstance();
- } else {
- return bridge;
+ return false;
}
+ return (localNameMap.get(localName) instanceof GraphicsNodeBridge);
}
/**
- * Returns true if the specified element has a GraphicsNodeBridge
- * associated to it, false otherwise.
+ * Returns the bridge associated with the specified element.
*
* @param element the element
*/
- public boolean hasGraphicsNodeBridge(Element element) {
+ public Bridge getBridge(Element element) {
if (namespaceURIMap == null || element == null) {
- return false;
+ return null;
}
- String namespaceURI = element.getNamespaceURI();
String localName = element.getLocalName();
+ String namespaceURI = element.getNamespaceURI();
namespaceURI = ((namespaceURI == null)? "" : namespaceURI);
- HashMap localNameMap = (HashMap) namespaceURIMap.get(namespaceURI);
- if (localNameMap == null) {
- return false;
- }
- return (localNameMap.get(localName) instanceof GraphicsNodeBridge);
+ return getBridge(namespaceURI, localName);
}
/**
1.24 +57 -25 xml-batik/sources/org/apache/batik/bridge/SVGUtilities.java
Index: SVGUtilities.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGUtilities.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- SVGUtilities.java 11 Apr 2003 13:54:56 -0000 1.23
+++ SVGUtilities.java 28 May 2003 14:40:57 -0000 1.24
@@ -487,39 +487,71 @@
float [] filterRes = new float[2];
String s = getChainableAttributeNS
(filterElement, null, SVG_FILTER_RES_ATTRIBUTE, ctx);
- if (s.length() == 0) {
- filterRes[0] = -1;
- filterRes[1] = -1;
+ Float [] vals = convertSVGNumberOptionalNumber
+ (filterElement, SVG_FILTER_RES_ATTRIBUTE, s);
- } else {
- try {
- filterRes[0] = -1; // -1 means unspecified
- StringTokenizer tokens = new StringTokenizer(s, " ");
- filterRes[0] = Float.parseFloat(tokens.nextToken());
- if (tokens.hasMoreTokens()) {
- filterRes[1] = Float.parseFloat(tokens.nextToken());
- } else {
- // if only one value is specified, resY = resX
- filterRes[1] = filterRes[0];
- }
- if (tokens.hasMoreTokens()) {
- throw new BridgeException
- (filterElement, ERR_ATTRIBUTE_VALUE_MALFORMED,
- new Object[] {SVG_FILTER_RES_ATTRIBUTE, s});
- }
- } catch (NumberFormatException ex) {
+ if (filterRes[0] < 0 || filterRes[1] < 0) {
+ throw new BridgeException
+ (filterElement, ERR_ATTRIBUTE_VALUE_MALFORMED,
+ new Object[] {SVG_FILTER_RES_ATTRIBUTE, s});
+ }
+
+ if (vals[0] == null)
+ filterRes[0] = -1;
+ else {
+ filterRes[0] = vals[0].floatValue();
+ if (filterRes[0] < 0)
throw new BridgeException
(filterElement, ERR_ATTRIBUTE_VALUE_MALFORMED,
- new Object[] {SVG_FILTER_RES_ATTRIBUTE, s, ex});
- }
- if (filterRes[0] < 0 || filterRes[1] < 0) {
+ new Object[] {SVG_FILTER_RES_ATTRIBUTE, s});
+ }
+
+ if (vals[1] == null)
+ filterRes[1] = filterRes[0];
+ else {
+ filterRes[1] = vals[1].floatValue();
+ if (filterRes[1] < 0)
throw new BridgeException
(filterElement, ERR_ATTRIBUTE_VALUE_MALFORMED,
new Object[] {SVG_FILTER_RES_ATTRIBUTE, s});
- }
}
return filterRes;
}
+
+ /**
+ * This function parses attrValue for a number followed by an optional
+ * second Number. It always returns an array of two Floats. If either
+ * or both values are not provided the entries are set to null
+ */
+ public static Float []
+ convertSVGNumberOptionalNumber(Element elem,
+ String attrName,
+ String attrValue) {
+
+ Float [] ret = new Float[2];
+ if (attrValue.length() == 0)
+ return ret;
+
+ try {
+ StringTokenizer tokens = new StringTokenizer(attrValue, " ");
+ ret[0] = new Float(Float.parseFloat(tokens.nextToken()));
+ if (tokens.hasMoreTokens()) {
+ ret[1] = new Float(Float.parseFloat(tokens.nextToken()));
+ }
+
+ if (tokens.hasMoreTokens()) {
+ throw new BridgeException
+ (elem, ERR_ATTRIBUTE_VALUE_MALFORMED,
+ new Object[] {attrName, attrValue});
+ }
+ } catch (NumberFormatException ex) {
+ throw new BridgeException
+ (elem, ERR_ATTRIBUTE_VALUE_MALFORMED,
+ new Object[] {attrName, attrValue, ex});
+ }
+ return ret;
+ }
+
/**
* Returns the filter region according to the x, y, width, height,
1.16 +7 -4 xml-batik/sources/org/apache/batik/extension/svg/BatikExtConstants.java
Index: BatikExtConstants.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/extension/svg/BatikExtConstants.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- BatikExtConstants.java 20 Feb 2003 11:15:47 -0000 1.15
+++ BatikExtConstants.java 28 May 2003 14:40:57 -0000 1.16
@@ -75,6 +75,9 @@
/** Tag name for Batik's subImage multiImage extension. */
public static final String BATIK_EXT_SUB_IMAGE_TAG =
"subImage";
+ /** Tag name for Batik's subImageRef multiImage extension. */
+ public static final String BATIK_EXT_SUB_IMAGE_REF_TAG =
+ "subImageRef";
/** Attribute name for dx attribute */
public static final String BATIK_EXT_DX_ATRIBUTE =
@@ -172,12 +175,12 @@
"trim";
/** Attribute name for pixel-width attribute */
- public static final String BATIK_EXT_PIXEL_WIDTH_ATTRIBUTE =
- "pixel-width";
+ public static final String BATIK_EXT_MIN_PIXEL_SIZE_ATTRIBUTE =
+ "min-pixel-size";
/** Attribute name for pixel-height attribute */
- public static final String BATIK_EXT_PIXEL_HEIGHT_ATTRIBUTE =
- "pixel-height";
+ public static final String BATIK_EXT_MAX_PIXEL_SIZE_ATTRIBUTE =
+ "max-pixel-size";
/** Attribute name for color attribute */
public static final String BATIK_EXT_SOLID_COLOR_PROPERTY =
1.9 +64 -51 xml-batik/sources/org/apache/batik/extension/svg/BatikMultiImageElementBridge.java
Index: BatikMultiImageElementBridge.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/extension/svg/BatikMultiImageElementBridge.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- BatikMultiImageElementBridge.java 11 Apr 2003 13:58:18 -0000 1.8
+++ BatikMultiImageElementBridge.java 28 May 2003 14:40:57 -0000 1.9
@@ -97,9 +97,11 @@
return null;
}
- List dims = new LinkedList();
- List uris = new LinkedList();
- addInfo(e, dims, uris);
+ Rectangle2D b = getImageBounds(ctx, e);
+
+ List uris = new LinkedList();
+ List minDim = new LinkedList();
+ List maxDim = new LinkedList();
for (Node n = e.getFirstChild(); n != null; n = n.getNextSibling()) {
if (n.getNodeType() != Node.ELEMENT_NODE)
@@ -107,39 +109,49 @@
Element se = (Element)n;
if (!(se.getNamespaceURI().equals(BATIK_EXT_NAMESPACE_URI)) ||
- !(se.getLocalName().equals(BATIK_EXT_SUB_IMAGE_TAG)))
+ !(se.getLocalName().equals(BATIK_EXT_SUB_IMAGE_REF_TAG)))
continue;
- addInfo(se, dims, uris);
+ addInfo(se, uris, minDim, maxDim, b);
}
- Dimension [] dary = new Dimension[uris.size()];
+ Dimension [] mindary = new Dimension[uris.size()];
+ Dimension [] maxdary = new Dimension[uris.size()];
ParsedURL [] uary = new ParsedURL[uris.size()];
- Iterator di = dims.iterator();
+ Iterator mindi = minDim.iterator();
+ Iterator maxdi = maxDim.iterator();
Iterator ui = uris.iterator();
int n=0;
- while (di.hasNext()) {
- int i;
- Dimension d = (Dimension)di.next();
- for (i=0; i<n; i++) {
- if (d.width > dary[i].width) break;
+ while (mindi.hasNext()) {
+ Dimension minD = (Dimension)mindi.next();
+ Dimension maxD = (Dimension)maxdi.next();
+ int i =0;
+ if (minD != null) {
+ for (; i<n; i++) {
+ if ((mindary[i] != null) &&
+ (minD.width < mindary[i].width)) {
+ break;
+ }
+ }
}
for (int j=n; j>i; j--) {
- dary[j] = dary[j-1];
- uary[j] = uary[j-1];
+ uary[j] = uary[j-1];
+ mindary[j] = mindary[j-1];
+ maxdary[j] = maxdary[j-1];
}
- dary[i] = d;
- uary[i] = (ParsedURL)ui.next();
+
+ uary [i] = (ParsedURL)ui.next();
+ mindary[i] = minD;
+ maxdary[i] = maxD;
n++;
}
- Rectangle2D b = getImageBounds(ctx, e);
-
// System.out.println("Bounds: " + bounds);
// System.out.println("ImgB: " + imgBounds);
- GraphicsNode node = new MultiResGraphicsNode(e, b, uary, dary);
+ GraphicsNode node = new MultiResGraphicsNode(e, b, uary,
+ mindary, maxdary);
// 'transform'
String s = e.getAttributeNS(null, SVG_TRANSFORM_ATTRIBUTE);
@@ -180,8 +192,9 @@
((SVGOMElement)e).setSVGContext(this);
}
- protected void addInfo(Element e, Collection dims, Collection uris) {
- Dimension d = getElementPixelSize(e);
+ protected void addInfo(Element e, Collection uris,
+ Collection minDim, Collection maxDim,
+ Rectangle2D bounds) {
String uriStr = XLinkSupport.getXLinkHref(e);
if (uriStr.length() == 0) {
throw new BridgeException(e, ERR_ATTRIBUTE_MISSING,
@@ -192,40 +205,40 @@
ParsedURL purl;
if (baseURI == null) purl = new ParsedURL(uriStr);
else purl = new ParsedURL(baseURI, uriStr);
-
- dims.add(d);
uris.add(purl);
+
+
+ minDim.add(getElementMinPixel(e, bounds));
+ maxDim.add(getElementMaxPixel(e, bounds));
+ }
+
+ protected Dimension getElementMinPixel(Element e, Rectangle2D bounds) {
+ return getElementPixelSize
+ (e, BATIK_EXT_MAX_PIXEL_SIZE_ATTRIBUTE, bounds);
+ }
+ protected Dimension getElementMaxPixel(Element e, Rectangle2D bounds) {
+ return getElementPixelSize
+ (e, BATIK_EXT_MIN_PIXEL_SIZE_ATTRIBUTE, bounds);
}
- protected Dimension getElementPixelSize(Element e) {
- int w=0, h=0;
+ protected Dimension getElementPixelSize(Element e,
+ String attr,
+ Rectangle2D bounds) {
String s;
+ s = e.getAttribute(attr);
+ if (s.length() == 0) return null;
- s = e.getAttributeNS(null,BATIK_EXT_PIXEL_WIDTH_ATTRIBUTE);
- if (s.length() == 0) throw new BridgeException
- (e, ERR_ATTRIBUTE_MISSING,
- new Object[] {BATIK_EXT_PIXEL_WIDTH_ATTRIBUTE});
-
- try {
- w = (int)SVGUtilities.convertSVGNumber(s);
- } catch (NumberFormatException ex) {
- throw new BridgeException
- (e, ERR_ATTRIBUTE_VALUE_MALFORMED,
- new Object[] {BATIK_EXT_PIXEL_WIDTH_ATTRIBUTE, s});
- }
+ Float [] vals = SVGUtilities.convertSVGNumberOptionalNumber
+ (e, attr, s);
- s = e.getAttributeNS(null,BATIK_EXT_PIXEL_HEIGHT_ATTRIBUTE);
- if (s.length() == 0) throw new BridgeException
- (e, ERR_ATTRIBUTE_MISSING,
- new Object[] {BATIK_EXT_PIXEL_HEIGHT_ATTRIBUTE});
- try {
- h = (int)SVGUtilities.convertSVGNumber(s);
- } catch (NumberFormatException ex) {
- throw new BridgeException
- (e, ERR_ATTRIBUTE_VALUE_MALFORMED,
- new Object[] {BATIK_EXT_PIXEL_HEIGHT_ATTRIBUTE, s});
- }
+ if (vals[0] == null) return null;
- return new Dimension(w, h);
+ float xPixSz = vals[0].floatValue();
+ float yPixSz = xPixSz;
+ if (vals[1] != null)
+ yPixSz = vals[1].floatValue();
+
+ return new Dimension((int)(bounds.getWidth()/xPixSz+0.5),
+ (int)(bounds.getHeight()/yPixSz+0.5));
}
}
1.5 +71 -26 xml-batik/sources/org/apache/batik/extension/svg/MultiResGraphicsNode.java
Index: MultiResGraphicsNode.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/extension/svg/MultiResGraphicsNode.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- MultiResGraphicsNode.java 11 Apr 2003 13:58:20 -0000 1.4
+++ MultiResGraphicsNode.java 28 May 2003 14:40:57 -0000 1.5
@@ -48,7 +48,8 @@
SoftReference [] srcs;
ParsedURL [] srcURLs;
- Dimension [] sizes;
+ Dimension [] minSz;
+ Dimension [] maxSz;
Rectangle2D bounds;
UserAgent userAgent;
@@ -66,17 +67,19 @@
public MultiResGraphicsNode(Element multiImgElem,
- Rectangle2D bounds,
- ParsedURL []srcURLs,
- Dimension [] sizes) {
+ Rectangle2D bounds,
+ ParsedURL [] srcURLs,
+ Dimension [] minSz,
+ Dimension [] maxSz) {
this.multiImgElem = multiImgElem;
this.srcURLs = new ParsedURL[srcURLs.length];
- this.sizes = new Dimension[srcURLs.length];
+ this.minSz = new Dimension[srcURLs.length];
+ this.maxSz = new Dimension[srcURLs.length];
for (int i=0; i<srcURLs.length; i++) {
this.srcURLs[i] = srcURLs[i];
- if (i < sizes.length)
- this.sizes[i] = sizes[i];
+ this.minSz[i] = minSz[i];
+ this.maxSz[i] = maxSz[i];
}
this.srcs = new SoftReference[srcURLs.length];
@@ -92,7 +95,7 @@
* @param g2d the Graphics2D to use
*/
public void primitivePaint(Graphics2D g2d) {
- // System.out.println("PrimPaint: " + this);
+ // System.err.println("PrimPaint: " + this);
// get the current affine transform
AffineTransform at = g2d.getTransform();
@@ -102,27 +105,69 @@
GraphicsNode gn = null;
int idx =-1;
double w = bounds.getWidth()*scx;
- for (int i=1; i<sizes.length; i++) {
- if (w > sizes[i].width) {
- idx = i-1;
- break;
+ double minDist = calcDist(w, minSz[0], maxSz[0]);
+ int minIdx = 0;
+ // System.err.println("Width: " + w);
+ for (int i=0; i<minSz.length; i++) {
+ double dist = calcDist(w, minSz[i], maxSz[i]);
+ // System.err.println("Dist: " + dist);
+ if (dist < minDist) {
+ minDist = dist;
+ minIdx = i;
+ }
+
+ if (((minSz[i] == null) || (w >= minSz[i].width)) &&
+ ((maxSz[i] == null) || (w <= maxSz[i].width))) {
+ // We have a range match
+ // System.err.println("Match: " + i + " " +
+ // minSz[i] + " -> " + maxSz[i]);
+ if ((idx == -1) || (minIdx == i)) {
+ idx = i;
+ }
}
}
+
if (idx == -1)
- idx = srcURLs.length-1;
+ idx = minIdx;
gn = getGraphicsNode(idx);
if (gn == null) return;
- Rectangle2D gnBounds = gn.getBounds();
- double sx = bounds.getWidth()/sizes[idx].getWidth();
- double sy = bounds.getHeight()/sizes[idx].getHeight();
-
- // System.out.println("Scale: [" + sx + ", " + sy + "]");
- // g2d.scale(sx, sy);
+ // Rectangle2D gnBounds = gn.getBounds();
+ // double sx = bounds.getWidth()/sizes[idx].getWidth();
+ // double sy = bounds.getHeight()/sizes[idx].getHeight();
+ // System.err.println("Scale: [" + sx + ", " + sy + "]");
+
gn.paint(g2d);
}
+ // This function can be tweaked to any extent. This is a very
+ // simple measure of 'goodness'. It has two main flaws as is,
+ // mostly in regards to distance calc with 'unbounded' ranges.
+ // First it doesn't punish if the distance is the wrong way on the
+ // unbounded range (so over a max by 10 is the same as under a max
+ // by 10) this is compensated by the absolute preference for
+ // matches 'in range' above. The other issue is that unbounded
+ // ranages tend to 'win' when the value is near the boundry point
+ // since they use distance from the boundry point rather than the
+ // middle of the range. As it is this seems to meet all the
+ // requirements of the SVG specification however.
+ public double calcDist(double loc, Dimension min, Dimension max) {
+ if (min == null) {
+ if (max == null)
+ return 10E10; // very large number.
+ else
+ return Math.abs(loc-max.width);
+ } else {
+ if (max == null)
+ return Math.abs(loc-min.width);
+ else {
+ double mid = (max.width+min.width)/2.0;
+ return Math.abs(loc-mid);
+ }
+ }
+ }
+
/**
* Returns the bounds of the area covered by this node's primitive paint.
*/
@@ -142,7 +187,7 @@
}
public GraphicsNode getGraphicsNode(int idx) {
- // System.out.println("Getting: " + idx);
+ // System.err.println("Getting: " + idx);
if (srcs[idx] != null) {
Object o = srcs[idx].get();
if (o != null)
@@ -206,8 +251,8 @@
vb[2] = (float)imgBounds.getWidth(); // width
vb[3] = (float)imgBounds.getHeight(); // height
- // System.out.println("Bounds: " + bounds);
- // System.out.println("ImgB: " + imgBounds);
+ // System.err.println("Bounds: " + bounds);
+ // System.err.println("ImgB: " + imgBounds);
// handles the 'preserveAspectRatio', 'overflow' and 'clip' and
// sets the appropriate AffineTransform to the image node
initializeViewport(e, node, vb, bounds);
@@ -254,8 +299,8 @@
// handles the 'preserveAspectRatio', 'overflow' and 'clip' and sets
// the appropriate AffineTransform to the image node
- // System.out.println("Bounds: " + bounds);
- // System.out.println("ViewBox: " + viewBox);
+ // System.err.println("Bounds: " + bounds);
+ // System.err.println("ViewBox: " + viewBox);
initializeViewport(e, result, vb, bounds);
return result;
@@ -284,7 +329,7 @@
AffineTransform at
= ViewBox.getPreserveAspectRatioTransform(e, vb, w, h);
- // System.out.println("VP Affine: " + at);
+ // System.err.println("VP Affine: " + at);
at.preConcatenate(AffineTransform.getTranslateInstance(x, y));
node.setTransform(at);
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org