Search in sources :

Example 6 with PreviewProperties

use of org.gephi.preview.api.PreviewProperties in project gephi by gephi.

the class SVGExporter method execute.

@Override
public boolean execute() {
    PreviewController controller = Lookup.getDefault().lookup(PreviewController.class);
    controller.getModel(workspace).getProperties().putValue(PreviewProperty.VISIBILITY_RATIO, 1.0);
    controller.refreshPreview(workspace);
    PreviewProperties props = controller.getModel(workspace).getProperties();
    props.putValue(SVGTarget.SCALE_STROKES, scaleStrokes);
    props.putValue(PreviewProperty.MARGIN, new Float((float) margin));
    target = (SVGTarget) controller.getRenderTarget(RenderTarget.SVG_TARGET, workspace);
    if (target instanceof LongTask) {
        ((LongTask) target).setProgressTicket(progress);
    }
    try {
        controller.render(target, workspace);
        // creates SVG-to-SVG transcoder
        SVGTranscoder t = new SVGTranscoder();
        t.addTranscodingHint(SVGTranscoder.KEY_XML_DECLARATION, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        // sets transcoder input and output
        TranscoderInput input = new TranscoderInput(target.getDocument());
        // performs transcoding
        try {
            TranscoderOutput output = new TranscoderOutput(writer);
            t.transcode(input, output);
        } finally {
            writer.close();
            props.removeSimpleValue(PreviewProperty.MARGIN);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    Progress.finish(progress);
    return !cancel;
}
Also used : PreviewProperties(org.gephi.preview.api.PreviewProperties) TranscoderOutput(org.apache.batik.transcoder.TranscoderOutput) LongTask(org.gephi.utils.longtask.spi.LongTask) TranscoderInput(org.apache.batik.transcoder.TranscoderInput) PreviewController(org.gephi.preview.api.PreviewController) SVGTranscoder(org.apache.batik.transcoder.svg2svg.SVGTranscoder)

Example 7 with PreviewProperties

use of org.gephi.preview.api.PreviewProperties in project gephi by gephi.

the class PDFRenderTargetBuilder method buildRenderTarget.

@Override
public RenderTarget buildRenderTarget(PreviewModel previewModel) {
    CanvasSize cs = previewModel.getGraphicsCanvasSize();
    PreviewProperties properties = previewModel.getProperties();
    float marginBottom = properties.getFloatValue(PDFTarget.MARGIN_BOTTOM);
    float marginLeft = properties.getFloatValue(PDFTarget.MARGIN_LEFT);
    float marginRight = properties.getFloatValue(PDFTarget.MARGIN_RIGHT);
    float marginTop = properties.getFloatValue(PDFTarget.MARGIN_TOP);
    com.itextpdf.text.Rectangle pageSize = properties.getValue(PDFTarget.PAGESIZE);
    boolean landscape = properties.getBooleanValue(PDFTarget.LANDSCAPE);
    PdfContentByte cb = properties.getValue(PDFTarget.PDF_CONTENT_BYTE);
    PDFRenderTargetImpl renderTarget = new PDFRenderTargetImpl(cb, cs, pageSize, marginLeft, marginRight, marginTop, marginBottom, landscape);
    return renderTarget;
}
Also used : CanvasSize(org.gephi.preview.api.CanvasSize) PreviewProperties(org.gephi.preview.api.PreviewProperties) PdfContentByte(com.itextpdf.text.pdf.PdfContentByte)

Aggregations

PreviewProperties (org.gephi.preview.api.PreviewProperties)7 PreviewController (org.gephi.preview.api.PreviewController)4 PdfContentByte (com.itextpdf.text.pdf.PdfContentByte)2 LongTask (org.gephi.utils.longtask.spi.LongTask)2 BaseColor (com.itextpdf.text.BaseColor)1 Document (com.itextpdf.text.Document)1 DocumentException (com.itextpdf.text.DocumentException)1 Rectangle (com.itextpdf.text.Rectangle)1 PdfWriter (com.itextpdf.text.pdf.PdfWriter)1 Color (java.awt.Color)1 Graphics2D (java.awt.Graphics2D)1 BufferedImage (java.awt.image.BufferedImage)1 TranscoderInput (org.apache.batik.transcoder.TranscoderInput)1 TranscoderOutput (org.apache.batik.transcoder.TranscoderOutput)1 SVGTranscoder (org.apache.batik.transcoder.svg2svg.SVGTranscoder)1 Column (org.gephi.graph.api.Column)1 Node (org.gephi.graph.api.Node)1 CanvasSize (org.gephi.preview.api.CanvasSize)1 Item (org.gephi.preview.api.Item)1 PreviewModel (org.gephi.preview.api.PreviewModel)1