*/
protected Filter cursorHrefToFilter(Element cursorElement,
ParsedURL purl,
Point2D hotSpot) {
AffineRable8Bit f = null;
String uriStr = purl.toString();
Dimension cursorSize = null;
// Try to load as an SVG Document
DocumentLoader loader = ctx.getDocumentLoader();
SVGDocument svgDoc = (SVGDocument)cursorElement.getOwnerDocument();
URIResolver resolver = ctx.createURIResolver(svgDoc, loader);
try {
Element rootElement = null;
Node n = resolver.getNode(uriStr, cursorElement);
if (n.getNodeType() == Node.DOCUMENT_NODE) {
SVGDocument doc = (SVGDocument)n;
// FIXX: really should be subCtx here.
ctx.initializeDocument(doc);
rootElement = doc.getRootElement();
} else {
throw new BridgeException
(ctx, cursorElement, ERR_URI_IMAGE_INVALID,
new Object[] {uriStr});
}
GraphicsNode node = ctx.getGVTBuilder().build(ctx, rootElement);
//
// The cursorSize define the viewport into which the
// cursor is displayed. That viewport is platform
// dependant and is not defined by the SVG content.
//
float width = DEFAULT_PREFERRED_WIDTH;
float height = DEFAULT_PREFERRED_HEIGHT;
UnitProcessor.Context uctx
= UnitProcessor.createContext(ctx, rootElement);
String s = rootElement.getAttribute(SVG_WIDTH_ATTRIBUTE);
if (s.length() != 0) {
width = UnitProcessor.svgHorizontalLengthToUserSpace
(s, SVG_WIDTH_ATTRIBUTE, uctx);
}
s = rootElement.getAttribute(SVG_HEIGHT_ATTRIBUTE);
if (s.length() != 0) {
height = UnitProcessor.svgVerticalLengthToUserSpace
(s, SVG_HEIGHT_ATTRIBUTE, uctx);
}
cursorSize
= Toolkit.getDefaultToolkit().getBestCursorSize
(Math.round(width), Math.round(height));
// Handle the viewBox transform
AffineTransform at = ViewBox.getPreserveAspectRatioTransform
(rootElement, cursorSize.width, cursorSize.height, ctx);
Filter filter = node.getGraphicsNodeRable(true);
f = new AffineRable8Bit(filter, at);
} catch (BridgeException ex) {
throw ex;
} catch (SecurityException ex) {
throw new BridgeException(ctx, cursorElement, ex, ERR_URI_UNSECURE,
new Object[] {uriStr});
} catch (Exception ex) {
/* Nothing to do */
}
// If f is null, it means that we are not dealing with
// an SVG image. Try as a raster image.
if (f == null) {
ImageTagRegistry reg = ImageTagRegistry.getRegistry();
Filter filter = reg.readURL(purl);
if (filter == null) {
return null;
}
// Check if we got a broken image
if (BrokenLinkProvider.hasBrokenLinkProperty(filter)) {
return null;
}
Rectangle preferredSize = filter.getBounds2D().getBounds();
cursorSize = Toolkit.getDefaultToolkit().getBestCursorSize
(preferredSize.width, preferredSize.height);
if (preferredSize != null && preferredSize.width >0
&& preferredSize.height > 0 ) {
AffineTransform at = new AffineTransform();
if (preferredSize.width > cursorSize.width
||
preferredSize.height > cursorSize.height) {
at = ViewBox.getPreserveAspectRatioTransform
(new float[] {0, 0, preferredSize.width, preferredSize.height},
SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMIN,
true,
cursorSize.width,
cursorSize.height);
}
f = new AffineRable8Bit(filter, at);
} else {
// Invalid Size
return null;
}
}
//
// Transform the hot spot from image space to cursor space
//
AffineTransform at = f.getAffine();
at.transform(hotSpot, hotSpot);
//
// In all cases, clip to the cursor boundaries
//