if (hints.containsKey(KEY_AOI)) { Rectangle2D aoi = (Rectangle2D) hints.get(KEY_AOI); if (hints.containsKey(ImageTranscoder.KEY_BACKGROUND_COLOR)) { Paint bgcolor = (Paint) hints.get(ImageTranscoder.KEY_BACKGROUND_COLOR); g2d.setComposite(AlphaComposite.SrcOver);
(hints.containsKey(KEY_EXECUTE_ONLOAD) && (Boolean) hints.get(KEY_EXECUTE_ONLOAD) && BaseScriptingEnvironment.isDynamicDocument(ctx, svgDoc));
/** * Returns the device resolution that has been set up. * @return the device resolution (in dpi) */ protected float getDeviceResolution() { if (hints.containsKey(KEY_DEVICE_RESOLUTION)) { return (Float) hints.get(KEY_DEVICE_RESOLUTION); } else { return GraphicsConstants.DEFAULT_DPI; } }
/** * Indicates whether text should be stroked rather than painted using text operators. Stroking * text (also referred to as "painting as shapes") can used in situations where the quality of * text output is not satisfying. The downside of the work-around: The generated file will * likely become bigger and you will lose copy/paste functionality for certain output formats * such as PDF. * @return true if text should be stroked rather than painted using text operators */ protected boolean isTextStroked() { boolean stroke = false; if (hints.containsKey(KEY_STROKE_TEXT)) { stroke = (Boolean) hints.get(KEY_STROKE_TEXT); } return stroke; }
/** * Helper method. Builds a Vector containing the allowed * values for the <script> element's type attribute. */ protected void computeAllowedScripts(){ scripts = new LinkedList(); if (!SVGAbstractTranscoder.this.hints.containsKey (KEY_ALLOWED_SCRIPT_TYPES)) { return; } String allowedScripts = (String)SVGAbstractTranscoder.this.hints.get (KEY_ALLOWED_SCRIPT_TYPES); StringTokenizer st = new StringTokenizer(allowedScripts, ","); while (st.hasMoreTokens()) { scripts.add(st.nextToken()); } }
/** * Helper method. Builds a Vector containing the allowed * values for the <script> element's type attribute. */ protected void computeAllowedScripts(){ scripts = new LinkedList(); if (!SVGAbstractTranscoder.this.hints.containsKey (KEY_ALLOWED_SCRIPT_TYPES)) { return; } String allowedScripts = (String)SVGAbstractTranscoder.this.hints.get (KEY_ALLOWED_SCRIPT_TYPES); StringTokenizer st = new StringTokenizer(allowedScripts, ","); while (st.hasMoreTokens()) { scripts.add(st.nextToken()); } }
/** * Returns the user language specified in the * <code>TranscodingHints</code> or "en" (english) if any. */ public String getLanguages() { if (SVGAbstractTranscoder.this.hints.containsKey(KEY_LANGUAGE)) { return (String)SVGAbstractTranscoder.this.hints.get (KEY_LANGUAGE); } return super.getLanguages(); }
/** * Returns the user language specified in the * <code>TranscodingHints</code> or "en" (english) if any. */ public String getLanguages() { if (SVGAbstractTranscoder.this.hints.containsKey(KEY_LANGUAGE)) { return (String)SVGAbstractTranscoder.this.hints.get (KEY_LANGUAGE); } return super.getLanguages(); }
/** * Sets document size according to the hints. * Global variables width and height are modified. * * @param docWidth Width of the document. * @param docHeight Height of the document. */ protected void setImageSize(float docWidth, float docHeight) { // Check hint to know if scaling is really needed Boolean scaleToPage = (Boolean)hints.get(KEY_SCALE_TO_PAGE); if(scaleToPage != null && !scaleToPage.booleanValue()) { float w = docWidth; float h = docHeight; if (hints.containsKey(KEY_AOI)) { Rectangle2D aoi = (Rectangle2D)hints.get(KEY_AOI); w = (float)aoi.getWidth(); h = (float)aoi.getHeight(); } super.setImageSize(w, h); } }
/** * Sets document size according to the hints. * Global variables width and height are modified. * * @param docWidth Width of the document. * @param docHeight Height of the document. */ protected void setImageSize(float docWidth, float docHeight) { // Check hint to know if scaling is really needed Boolean scaleToPage = (Boolean)hints.get(KEY_SCALE_TO_PAGE); if(scaleToPage != null && !scaleToPage) { float w = docWidth; float h = docHeight; if (hints.containsKey(KEY_AOI)) { Rectangle2D aoi = (Rectangle2D)hints.get(KEY_AOI); w = (float)aoi.getWidth(); h = (float)aoi.getHeight(); } super.setImageSize(w, h); } }
/** * Returns the pixel to millimeter conversion factor specified in the * {@link TranscodingHints} or 0.3528 if any. * @return the pixel unit to millimeter factor */ public float getPixelUnitToMillimeter() { Object key = ImageTranscoder.KEY_PIXEL_UNIT_TO_MILLIMETER; if (getTranscodingHints().containsKey(key)) { return (Float) getTranscodingHints().get(key); } else { // return 0.3528f; // 72 dpi return UnitConv.IN2MM / 96; //96dpi = 0.2645833333333333333f; } }
if (SVGAbstractTranscoder.this.hints.containsKey (KEY_CONSTRAIN_SCRIPT_ORIGIN)) { constrainOrigin =
public void transcode(TranscoderOutput output) throws Exception { OutputStream out = output.getOutputStream(); if (!(out instanceof BufferedOutputStream)) { out = new BufferedOutputStream(out); } graphics.setupDocument(out, 800, 1000); graphics.setSVGDimension(width, height); if (hints.containsKey(ImageTranscoder.KEY_BACKGROUND_COLOR)) { graphics.setBackgroundColor( (Color) hints.get(ImageTranscoder.KEY_BACKGROUND_COLOR)); } graphics.setGraphicContext( new org.apache.xmlgraphics.java2d.GraphicContext()); graphics.setRenderingHint( RenderingHintsKeyExt.KEY_TRANSCODING, RenderingHintsKeyExt.VALUE_TRANSCODING_VECTOR); for (String s : svg) { transcode(new TranscoderInput(new StringReader(s)), output); graphics.nextPage(); } graphics.finish(); }
if (hints.containsKey(PNGTranscoder.KEY_FORCE_TRANSPARENT_WHITE)) { forceTransparentWhite = ((Boolean)hints.get
/** * Returns the effective configuration for the transcoder. * @return the effective configuration */ protected Configuration getEffectiveConfiguration() { Configuration effCfg = this.cfg; if (effCfg == null) { //By default, enable font auto-detection if no cfg is given boolean autoFonts = getAutoFontsDefault(); if (hints.containsKey(KEY_AUTO_FONTS)) { autoFonts = (Boolean) hints.get(KEY_AUTO_FONTS); } if (autoFonts) { DefaultConfiguration c = new DefaultConfiguration("cfg"); DefaultConfiguration fonts = new DefaultConfiguration("fonts"); c.addChild(fonts); DefaultConfiguration autodetect = new DefaultConfiguration("auto-detect"); fonts.addChild(autodetect); effCfg = c; } } return effCfg; }
if (hints.containsKey(PNGTranscoder.KEY_FORCE_TRANSPARENT_WHITE)) { forceTransparentWhite = (Boolean) hints.get
if (hints.containsKey(PNGTranscoder.KEY_FORCE_TRANSPARENT_WHITE)) { forceTransparentWhite = ((Boolean)hints.get
if (hints.containsKey(KEY_QUALITY)) { quality = ((Float)hints.get(KEY_QUALITY)).floatValue(); } else {
if (hints.containsKey(PNGTranscoder.KEY_FORCE_TRANSPARENT_WHITE)) { forceTransparentWhite = (Boolean) hints.get
public PDFPrinter(List<String> svg) throws TranscoderException { this.svg = svg; graphics = new PDFDocumentGraphics2D(isTextStroked()); graphics.getPDFDocument().getInfo().setProducer("Apache FOP Version " + Version.getVersion() + ": PDF Transcoder for Batik"); if (hints.containsKey(KEY_DEVICE_RESOLUTION)) { graphics.setDeviceDPI(getDeviceResolution()); } try { Configuration effCfg = getEffectiveConfiguration(); if (effCfg != null) { PDFDocumentGraphics2DConfigurator configurator = new PDFDocumentGraphics2DConfigurator(); boolean useComplexScriptFeatures = false; //TODO - FIX ME configurator.configure(graphics, effCfg, useComplexScriptFeatures); } else { graphics.setupDefaultFontInfo(); } ((FOPTranscoderUserAgent) userAgent).setFontFamilyResolver( new FOPFontFamilyResolverImpl(graphics.getFontInfo())); } catch (Exception e) { throw new TranscoderException( "Error while setting up PDFDocumentGraphics2D", e); } }