if (intentName.equals(i.toString())) {
intent = i;
}
}
if (intent == null) {
throw new XMLException("Invalid rendering intent: " + intentName);
}
if (root.hasAttribute(PpiTag)) {
// ppi attribute added in LZN version 6
pixelsPerInch = Integer.parseInt(root.getAttribute(PpiTag));
}
else {
// arbitrary but sensible default, mostly backwards compatible
pixelsPerInch = 300;
}
profile = null;
XmlNode profileNode = null;
try {
profileNode = root.getChild(ProfileTag);
}
catch (XMLException e) {
// OK, color profile is optional.
}
if (profileNode != null) {
String profileName = profileNode.getAttribute(ProfileNameTag);
String profilePath = profileNode.getAttribute(ProfilePathTag);
profile = new ColorProfileInfo(profileName, profilePath);
}
XmlNode pageNode = root.getChild(PageTag);
restorePageFormat(pageNode);
XmlNode imageRectNode = root.getChild(ImageRectTag);
try {
double x = Double.valueOf(imageRectNode.getAttribute("x"));
double y = Double.valueOf(imageRectNode.getAttribute("y"));
double w = Double.valueOf(imageRectNode.getAttribute("w"));
double h =
Double.valueOf(imageRectNode.getAttribute("h"));
imageRect = new Rectangle2D.Double(x, y, w, h);
// The restored imageRect may not make sense with the current
// imageWidth and imageHeight.
// If the saved aspect ratio is far off, then we scaleToFit().
// Otherwise we allow a little mismatch, to preserve the printed
// image bounds.
double restoredAspect =
imageRect.getWidth() / imageRect.getHeight();
double currentAspect = (imageWidth > 0 && imageHeight > 0) ?
imageWidth / (double) imageHeight : restoredAspect;
if (Math.abs(restoredAspect / currentAspect - 1) > 0.01) {
scaleToFit();
}
}
catch (NumberFormatException e) {
throw new XMLException(
"Can't interpret image bounds: " + e.getMessage()
);
}
}