throw new BridgeException(cursorElement, ERR_ATTRIBUTE_MISSING,
new Object[] {"xlink:href"});
}
String baseURI = XMLBaseSupport.getCascadedXMLBase(cursorElement);
ParsedURL purl;
if (baseURI == null) {
purl = new ParsedURL(uriStr);
} else {
purl = new ParsedURL(baseURI, uriStr);
}
//
// Convert the cursor's hot spot
//
UnitProcessor.Context uctx
= UnitProcessor.createContext(ctx, cursorElement);
String s = cursorElement.getAttributeNS(null, SVG_X_ATTRIBUTE);
float x = 0;
if (s.length() != 0) {
x = UnitProcessor.svgHorizontalCoordinateToUserSpace
(s, SVG_X_ATTRIBUTE, uctx);
}
s = cursorElement.getAttributeNS(null, SVG_Y_ATTRIBUTE);
float y = 0;
if (s.length() != 0) {
y = UnitProcessor.svgVerticalCoordinateToUserSpace
(s, SVG_Y_ATTRIBUTE, uctx);
}
CursorDescriptor desc = new CursorDescriptor(purl, x, y);
//
// Check if there is a cursor in the cache for this url
//
Cursor cachedCursor = cursorCache.getCursor(desc);
if (cachedCursor != null) {
return cachedCursor;
}
//
// Load image into Filter f and transform hotSpot to
// cursor space.
//
Point2D.Float hotSpot = new Point2D.Float(x, y);
Filter f = cursorHrefToFilter(cursorElement,
purl,
hotSpot);
if (f == null) {
cursorCache.clearCursor(desc);
return null;
}
// The returned Filter is guaranteed to create a
// default rendering of the desired size
Rectangle cursorSize = f.getBounds2D().getBounds();
RenderedImage ri = f.createScaledRendering(cursorSize.width,
cursorSize.height,
null);
Image img = null;
if (ri instanceof Image) {
img = (Image)ri;
} else {
img = renderedImageToImage(ri);
}
// Make sure the not spot does not fall out of the cursor area. If it
// does, then clamp the coordinates to the image space.
hotSpot.x = hotSpot.x < 0 ? 0 : hotSpot.x;
hotSpot.y = hotSpot.y < 0 ? 0 : hotSpot.y;
hotSpot.x = hotSpot.x > (cursorSize.width-1) ? cursorSize.width - 1 : hotSpot.x;
hotSpot.y = hotSpot.y > (cursorSize.height-1) ? cursorSize.height - 1: hotSpot.y;
//
// The cursor image is now into 'img'
//
Cursor c = Toolkit.getDefaultToolkit()
.createCustomCursor(img,
new Point((int)Math.round(hotSpot.x),
(int)Math.round(hotSpot.y)),
purl.toString());
cursorCache.putCursor(desc, c);
return c;
}