1 18 package org.apache.batik.svggen; 19 20 import java.awt.RenderingHints ; 21 22 import org.apache.batik.ext.awt.g2d.GraphicContext; 23 24 42 public class SVGRenderingHints extends AbstractSVGConverter{ 43 47 public SVGRenderingHints(SVGGeneratorContext generatorContext) { 48 super(generatorContext); 49 } 50 51 61 public SVGDescriptor toSVG(GraphicContext gc){ 62 return toSVG(gc.getRenderingHints()); 63 } 64 65 70 public static SVGHintsDescriptor toSVG(RenderingHints hints){ 71 String colorInterpolation = SVG_AUTO_VALUE; 73 String colorRendering = SVG_AUTO_VALUE; 74 String textRendering = SVG_AUTO_VALUE; 75 String shapeRendering = SVG_AUTO_VALUE; 76 String imageRendering = SVG_AUTO_VALUE; 77 78 if(hints != null){ 82 Object rendering = hints.get(RenderingHints.KEY_RENDERING); 83 if(rendering == RenderingHints.VALUE_RENDER_DEFAULT){ 84 colorInterpolation = SVG_AUTO_VALUE; 85 colorRendering = SVG_AUTO_VALUE; 86 textRendering = SVG_AUTO_VALUE; 87 shapeRendering = SVG_AUTO_VALUE; 88 imageRendering = SVG_AUTO_VALUE; 89 } 90 else if(rendering == RenderingHints.VALUE_RENDER_SPEED){ 91 colorInterpolation = SVG_SRGB_VALUE; 92 colorRendering = SVG_OPTIMIZE_SPEED_VALUE; 93 textRendering = SVG_OPTIMIZE_SPEED_VALUE; 94 shapeRendering = SVG_GEOMETRIC_PRECISION_VALUE; 95 imageRendering = SVG_OPTIMIZE_SPEED_VALUE; 96 } 97 else if(rendering == RenderingHints.VALUE_RENDER_QUALITY){ 98 colorInterpolation = SVG_LINEAR_RGB_VALUE; 99 colorRendering = SVG_OPTIMIZE_QUALITY_VALUE; 100 textRendering = SVG_OPTIMIZE_QUALITY_VALUE; 101 shapeRendering = SVG_GEOMETRIC_PRECISION_VALUE; 102 imageRendering = SVG_OPTIMIZE_QUALITY_VALUE; 103 } 104 105 Object fractionalMetrics = hints.get(RenderingHints.KEY_FRACTIONALMETRICS); 109 if(fractionalMetrics == RenderingHints.VALUE_FRACTIONALMETRICS_ON){ 110 textRendering = SVG_OPTIMIZE_QUALITY_VALUE; 111 shapeRendering = SVG_GEOMETRIC_PRECISION_VALUE; 112 } 113 else if(fractionalMetrics == RenderingHints.VALUE_FRACTIONALMETRICS_OFF){ 114 textRendering = SVG_OPTIMIZE_SPEED_VALUE; 115 shapeRendering = SVG_OPTIMIZE_SPEED_VALUE; 116 } 117 else if(fractionalMetrics == RenderingHints.VALUE_FRACTIONALMETRICS_DEFAULT){ 118 textRendering = SVG_AUTO_VALUE; 119 shapeRendering = SVG_AUTO_VALUE; 120 } 121 122 Object antialiasing = hints.get(RenderingHints.KEY_ANTIALIASING); 126 if(antialiasing == RenderingHints.VALUE_ANTIALIAS_ON){ 127 textRendering = SVG_OPTIMIZE_LEGIBILITY_VALUE; 128 shapeRendering = SVG_AUTO_VALUE; 129 } 130 else if(antialiasing == RenderingHints.VALUE_ANTIALIAS_OFF){ 131 textRendering = SVG_GEOMETRIC_PRECISION_VALUE; 132 shapeRendering = SVG_CRISP_EDGES_VALUE; 133 } 134 else if(antialiasing == RenderingHints.VALUE_ANTIALIAS_DEFAULT){ 135 textRendering = SVG_AUTO_VALUE; 136 shapeRendering = SVG_AUTO_VALUE; 137 } 138 139 Object textAntialiasing = hints.get(RenderingHints.KEY_TEXT_ANTIALIASING); 143 if(textAntialiasing == RenderingHints.VALUE_TEXT_ANTIALIAS_ON) 144 textRendering = SVG_GEOMETRIC_PRECISION_VALUE; 145 else if(textAntialiasing == RenderingHints.VALUE_TEXT_ANTIALIAS_OFF) 146 textRendering = SVG_OPTIMIZE_SPEED_VALUE; 147 else if(textAntialiasing == RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT) 148 textRendering = SVG_AUTO_VALUE; 149 150 Object colorRenderingHint = hints.get(RenderingHints.KEY_COLOR_RENDERING); 154 if(colorRenderingHint == RenderingHints.VALUE_COLOR_RENDER_DEFAULT) 155 colorRendering = SVG_AUTO_VALUE; 156 else if(colorRenderingHint == RenderingHints.VALUE_COLOR_RENDER_QUALITY) 157 colorRendering = SVG_OPTIMIZE_QUALITY_VALUE; 158 else if(colorRenderingHint == RenderingHints.VALUE_COLOR_RENDER_SPEED) 159 colorRendering = SVG_OPTIMIZE_SPEED_VALUE; 160 161 Object interpolation = hints.get(RenderingHints.KEY_INTERPOLATION); 165 if(interpolation == RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR) 166 imageRendering = SVG_OPTIMIZE_SPEED_VALUE; 167 else if(interpolation == RenderingHints.VALUE_INTERPOLATION_BICUBIC 168 || 169 interpolation == RenderingHints.VALUE_INTERPOLATION_BILINEAR) 170 imageRendering = SVG_OPTIMIZE_QUALITY_VALUE; 171 } 173 return new SVGHintsDescriptor(colorInterpolation, 174 colorRendering, 175 textRendering, 176 shapeRendering, 177 imageRendering); 178 } 179 } 180 | Popular Tags |