Package net.sourceforge.fo3d.util

Examples of net.sourceforge.fo3d.util.Vector3


    /** {@inheritDoc} */
    public void handleElement(RendererContext context, Element el,
            PDF3DAnnotation annot) throws Exception {

        Vector3 pos = DOMUtil.get3DVectorAttribute(el, "at", true);
        String text = el.getTextContent().trim();
        if (text.length() == 0) {
            return;
        }

        String intDest = DOMUtil.getAttribute(el, "internal-destination");

        String resName = RESOURCE_NAME_PREFIX + textSpriteCount++;

        // Generate text image
        BufferedImage bi = getTextImage(text);

        // Debugging generated images
        // ImageIO.write(bi, "gif", new File("D:\\" + resName + ".gif"));

        // Add generated image to PDF document (as 3D stream resource)
        FO3DPDFDocument pdfDoc = (FO3DPDFDocument) context
            .getProperty(PDFRendererContextConstants.PDF_DOCUMENT);
        PDFResourceContext resContext = (PDFResourceContext) context
            .getProperty(PDFRendererContextConstants.PDF_CONTEXT);

        ImageInfo imgInfo = new ImageInfo(null, null);
        ImageSize imgSize = new ImageSize();
        imgSize.setSizeInPixels(bi.getWidth(), bi.getHeight());
        imgSize.setResolution(72);
        imgInfo.setSize(imgSize);

        ImageBuffered img = new ImageBuffered(imgInfo, bi, null);
        PDFImage pdfimage = new ImageRenderedAdapter(img, resName);
        PDFXObject xobj = pdfDoc.addImage(resContext, pdfimage);

        PDF3DStream stream = annot.getStreamSafely();
        stream.addResource(resName, xobj);

        // 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());
        }

        // Add JavaScript code for initializing a new textsprite
        stream.addJSCode("\naddTextSprite('"
            + JavaScriptUtil.escapeString(resName)
            + "',"
            + pos.toPDF3DJSString()
            + (intDest.length() > 0 ? ",'"
                    + JavaScriptUtil.escapeString(intDest) + "'" : "")
            + ");");
    }
View Full Code Here


                }
            } else {
                // 2.) Camera setup is given by the camera's position, the
                // viewing direction (or a target position) and a so called UP
                // vector to specify the camera's roll
                Vector3 pos = DOMUtil.get3DVectorAttribute(camera, "position");
                Vector3 up = DOMUtil.get3DVectorAttribute(camera, "up");
                Vector3 dir = DOMUtil.get3DVectorAttribute(camera, "direction");

                if (pos != null && up != null) {
                    if (dir == null) {
                        // Fallback solution, we can compute the direction with
                        // a given target vector and the position.
                        dir = DOMUtil.get3DVectorAttribute(camera, "target");
                        if (dir != null) {
                            // compute direction
                            dir.sub(pos);
                            // set distance to center of orbit
                            view.setCameraDistanceFromCenterOfOrbit(dir
                                .length());
                        } else {
                            if (log.isErrorEnabled()) {
                                log.error("Illegal view-camera setup ignored. "
                                        + "Whether the target position or "
View Full Code Here

                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) + "));");
            }
View Full Code Here

TOP

Related Classes of net.sourceforge.fo3d.util.Vector3

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.