}
// get 3d annotation links
List links = DOMUtil.getChildElementsByTagName(el, "link");
if (links.size() > 0) {
PDF3DStream stream = annot.getStreamSafely();
FO3DPDFRenderer renderer = (FO3DPDFRenderer) context.getRenderer();
PDFObject resource = renderer.add3DResourceStream(getClass()
.getResource(ANNOT_MODEL_FILE).toExternalForm());
stream.addResource(ANNOT_RESOURCE_NAME, resource);
// load JavaScript library code once (per 3D stream)
// this is because the DOM element could exist multiple times within
// the extension section.
if (!libLoadedList.contains(stream.referencePDF())) {
stream.addJSCode(getLibJSCode());
libLoadedList.add(stream.referencePDF());
}
Double scale;
Color color;
Vector3 pos;
String destination;
for (Iterator it = links.iterator(); it.hasNext();) {
Element link = (Element) it.next();
// Link destination
destination = DOMUtil.getAttribute(link, "href", true);
// Link position
pos = DOMUtil.get3DVectorAttribute(link, "at", true);
// Link color
color = defColor;
arg = DOMUtil.getAttribute(link, "color");
if (arg.length() > 0) {
color = ColorUtil.parseColorString(context.getUserAgent(),
arg);
}
// Link scale
scale = defScale;
arg = DOMUtil.getAttribute(link, "scale");
if (arg.length() > 0) {
scale = new Double(arg);
}
// add JavaScript code for initializing the 3d link annotation
stream.addJSCode("\nadd3DLinkAnnotation('"
+ ANNOT_RESOURCE_NAME + "'," + pos.toPDF3DJSString()
+ ",'" + destination + "'," + scale + ",new Color("
+ (color.getRed() / 255d) + ","
+ (color.getGreen() / 255d) + ","
+ (color.getBlue() / 255d) + "));");
}
// This is a workaround, because Acrobat changes the scene and
// view settings when we add a new model resource.
// This should be removed if we have another solution within the
// JavaScript file.
stream.addJSCode("\nreInitView(" + stream.getDefaultViewIndex()
+ ");");
}
}