int unitsType;
try {
unitsType = parseCoordinateSystem(units);
} catch (IllegalArgumentException ex) {
throw new IllegalAttributeValueException(
Messages.formatMessage("region.units.invalid",
new Object[] {units,
ATTR_PRIMITIVE_UNITS,
filterPrimitiveElement.getLocalName()}));
}
double x = defaultRegion.getX();
double y = defaultRegion.getY();
double w = defaultRegion.getWidth();
double h = defaultRegion.getHeight();
short hd = UnitProcessor.HORIZONTAL_LENGTH;
short vd = UnitProcessor.VERTICAL_LENGTH;
switch(unitsType) {
case OBJECT_BOUNDING_BOX:
Rectangle2D gnBounds = node.getGeometryBounds();
if (xStr.length() != 0) {
x = svgToObjectBoundingBox(filteredElement,
ATTR_X, xStr,
uctx, hd);
x = gnBounds.getX() + x*gnBounds.getWidth();
}
if (yStr.length() != 0) {
y = svgToObjectBoundingBox(filteredElement,
ATTR_Y, yStr,
uctx, vd);
y = gnBounds.getY() + y*gnBounds.getHeight();
}
if (wStr.length() != 0) {
w = svgToObjectBoundingBox(filteredElement,
ATTR_WIDTH, wStr,
uctx, hd);
w *= gnBounds.getWidth();
}
if (hStr.length() != 0) {
h = svgToObjectBoundingBox(filteredElement,
ATTR_HEIGHT, hStr,
uctx, vd);
h *= gnBounds.getHeight();
}
break;
case USER_SPACE_ON_USE:
if (xStr.length() != 0) {
x = svgToUserSpaceOnUse(filteredElement,
ATTR_X, xStr,
uctx, hd);
}
if (yStr.length() != 0) {
y = svgToUserSpaceOnUse(filteredElement,
ATTR_Y, yStr,
uctx, vd);
}
if (wStr.length() != 0) {
w = svgToUserSpaceOnUse(filteredElement,
ATTR_WIDTH, wStr,
uctx, hd);
}
if (hStr.length() != 0) {
h = svgToUserSpaceOnUse(filteredElement,
ATTR_HEIGHT, hStr,
uctx, vd);
}
break;
default:
/* Never happen: Bad coordinate system is catched previously */
throw new Error();
}
if (w < 0) {
throw new IllegalAttributeValueException(
Messages.formatMessage("region.width.illegal",
new Object[] {filterPrimitiveElement.getLocalName()}));
}
if (h < 0) {
throw new IllegalAttributeValueException(
Messages.formatMessage("region.height.illegal",
new Object[] {filterPrimitiveElement.getLocalName()}));
}
return new Rectangle2D.Double(x, y, w, h);