git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278353 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * Copyright 2002,2004 The Apache Software Foundation | |||
| * Copyright 2002,2004-2005 The Apache Software Foundation | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| @@ -48,12 +48,12 @@ public class Arc extends BasicShape implements DrawOperation { | |||
| /** | |||
| * @todo refactor using an EnumeratedAttribute | |||
| */ | |||
| public void setType(String str_type) { | |||
| if (str_type.toLowerCase().equals("open")) { | |||
| public void setType(String strType) { | |||
| if (strType.toLowerCase().equals("open")) { | |||
| type = Arc2D.OPEN; | |||
| } else if (str_type.toLowerCase().equals("pie")) { | |||
| } else if (strType.toLowerCase().equals("pie")) { | |||
| type = Arc2D.PIE; | |||
| } else if (str_type.toLowerCase().equals("chord")) { | |||
| } else if (strType.toLowerCase().equals("chord")) { | |||
| type = Arc2D.CHORD; | |||
| } | |||
| } | |||
| @@ -65,9 +65,9 @@ public class Arc extends BasicShape implements DrawOperation { | |||
| Graphics2D graphics = (Graphics2D) bi.getGraphics(); | |||
| if (!stroke.equals("transparent")) { | |||
| BasicStroke b_stroke = new BasicStroke(stroke_width); | |||
| BasicStroke bStroke = new BasicStroke(stroke_width); | |||
| graphics.setColor(ColorMapper.getColorByName(stroke)); | |||
| graphics.setStroke(b_stroke); | |||
| graphics.setStroke(bStroke); | |||
| graphics.draw(new Arc2D.Double(stroke_width, stroke_width, width, | |||
| height, start, stop, type)); | |||
| } | |||
| @@ -86,7 +86,8 @@ public class Arc extends BasicShape implements DrawOperation { | |||
| graphics.drawImage(img.getAsBufferedImage(), null, 0, 0); | |||
| } else if (instr instanceof TransformOperation) { | |||
| graphics = (Graphics2D) bi.getGraphics(); | |||
| PlanarImage image = ((TransformOperation) instr).executeTransformOperation(PlanarImage.wrapRenderedImage(bi)); | |||
| PlanarImage image = ((TransformOperation) instr) | |||
| .executeTransformOperation(PlanarImage.wrapRenderedImage(bi)); | |||
| bi = image.getAsBufferedImage(); | |||
| } | |||
| } | |||
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * Copyright 2002,2004 The Apache Software Foundation | |||
| * Copyright 2002,2004-2005 The Apache Software Foundation | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| @@ -23,55 +23,71 @@ import java.awt.Color; | |||
| * @see org.apache.tools.ant.taskdefs.optional.image.Image | |||
| */ | |||
| public final class ColorMapper { | |||
| /** black string */ | |||
| public static final String COLOR_BLACK = "black"; | |||
| /** blue string */ | |||
| public static final String COLOR_BLUE = "blue"; | |||
| /** cyan string */ | |||
| public static final String COLOR_CYAN = "cyan"; | |||
| /** black string */ | |||
| public static final String COLOR_DARKGRAY = "darkgray"; | |||
| /** gray string */ | |||
| public static final String COLOR_GRAY = "gray"; | |||
| /** lightgray string */ | |||
| public static final String COLOR_LIGHTGRAY = "lightgray"; | |||
| // Gotta atleast put in the proper spelling :-P | |||
| /** darkgrey string */ | |||
| public static final String COLOR_DARKGREY = "darkgrey"; | |||
| /** grey string */ | |||
| public static final String COLOR_GREY = "grey"; | |||
| /** lightgrey string */ | |||
| public static final String COLOR_LIGHTGREY = "lightgrey"; | |||
| /** green string */ | |||
| public static final String COLOR_GREEN = "green"; | |||
| /** magenta string */ | |||
| public static final String COLOR_MAGENTA = "magenta"; | |||
| /** orange string */ | |||
| public static final String COLOR_ORANGE = "orange"; | |||
| /** pink string */ | |||
| public static final String COLOR_PINK = "pink"; | |||
| /** reg string */ | |||
| public static final String COLOR_RED = "red"; | |||
| /** white string */ | |||
| public static final String COLOR_WHITE = "white"; | |||
| /** yellow string */ | |||
| public static final String COLOR_YELLOW = "yellow"; | |||
| /** | |||
| * @todo refactor to use an EnumeratedAttribute (maybe?) | |||
| */ | |||
| public static final Color getColorByName(String color_name) { | |||
| color_name = color_name.toLowerCase(); | |||
| public static Color getColorByName(String colorName) { | |||
| colorName = colorName.toLowerCase(); | |||
| if (color_name.equals(COLOR_BLACK)) { | |||
| if (colorName.equals(COLOR_BLACK)) { | |||
| return Color.black; | |||
| } else if (color_name.equals(COLOR_BLUE)) { | |||
| } else if (colorName.equals(COLOR_BLUE)) { | |||
| return Color.blue; | |||
| } else if (color_name.equals(COLOR_CYAN)) { | |||
| } else if (colorName.equals(COLOR_CYAN)) { | |||
| return Color.cyan; | |||
| } else if (color_name.equals(COLOR_DARKGRAY) || color_name.equals(COLOR_DARKGREY)) { | |||
| } else if (colorName.equals(COLOR_DARKGRAY) || colorName.equals(COLOR_DARKGREY)) { | |||
| return Color.darkGray; | |||
| } else if (color_name.equals(COLOR_GRAY) || color_name.equals(COLOR_GREY)) { | |||
| } else if (colorName.equals(COLOR_GRAY) || colorName.equals(COLOR_GREY)) { | |||
| return Color.gray; | |||
| } else if (color_name.equals(COLOR_LIGHTGRAY) || color_name.equals(COLOR_LIGHTGREY)) { | |||
| } else if (colorName.equals(COLOR_LIGHTGRAY) || colorName.equals(COLOR_LIGHTGREY)) { | |||
| return Color.lightGray; | |||
| } else if (color_name.equals(COLOR_GREEN)) { | |||
| } else if (colorName.equals(COLOR_GREEN)) { | |||
| return Color.green; | |||
| } else if (color_name.equals(COLOR_MAGENTA)) { | |||
| } else if (colorName.equals(COLOR_MAGENTA)) { | |||
| return Color.magenta; | |||
| } else if (color_name.equals(COLOR_ORANGE)) { | |||
| } else if (colorName.equals(COLOR_ORANGE)) { | |||
| return Color.orange; | |||
| } else if (color_name.equals(COLOR_PINK)) { | |||
| } else if (colorName.equals(COLOR_PINK)) { | |||
| return Color.pink; | |||
| } else if (color_name.equals(COLOR_RED)) { | |||
| } else if (colorName.equals(COLOR_RED)) { | |||
| return Color.red; | |||
| } else if (color_name.equals(COLOR_WHITE)) { | |||
| } else if (colorName.equals(COLOR_WHITE)) { | |||
| return Color.white; | |||
| } else if (color_name.equals(COLOR_YELLOW)) { | |||
| } else if (colorName.equals(COLOR_YELLOW)) { | |||
| return Color.yellow; | |||
| } | |||
| return Color.black; | |||
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * Copyright 2002,2004 The Apache Software Foundation | |||
| * Copyright 2002,2004-2005 The Apache Software Foundation | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| @@ -32,6 +32,7 @@ public interface DrawOperation { | |||
| * Abstract method which is intended to create an image buffer | |||
| * and return it so it can be drawn into another object. Use | |||
| * an Alpha channel for a "transparent" background. | |||
| * @return a planar image | |||
| */ | |||
| public PlanarImage executeDrawOperation(); | |||
| PlanarImage executeDrawOperation(); | |||
| } | |||
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * Copyright 2002,2004 The Apache Software Foundation | |||
| * Copyright 2002,2004-2005 The Apache Software Foundation | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| @@ -44,9 +44,9 @@ public class Ellipse extends BasicShape implements DrawOperation { | |||
| Graphics2D graphics = (Graphics2D) bi.getGraphics(); | |||
| if (!stroke.equals("transparent")) { | |||
| BasicStroke b_stroke = new BasicStroke(stroke_width); | |||
| BasicStroke bStroke = new BasicStroke(stroke_width); | |||
| graphics.setColor(ColorMapper.getColorByName(stroke)); | |||
| graphics.setStroke(b_stroke); | |||
| graphics.setStroke(bStroke); | |||
| graphics.draw(new Ellipse2D.Double(0, 0, width, height)); | |||
| } | |||
| @@ -63,7 +63,8 @@ public class Ellipse extends BasicShape implements DrawOperation { | |||
| graphics.drawImage(img.getAsBufferedImage(), null, 0, 0); | |||
| } else if (instr instanceof TransformOperation) { | |||
| graphics = (Graphics2D) bi.getGraphics(); | |||
| PlanarImage image = ((TransformOperation) instr).executeTransformOperation(PlanarImage.wrapRenderedImage(bi)); | |||
| PlanarImage image = ((TransformOperation) instr) | |||
| .executeTransformOperation(PlanarImage.wrapRenderedImage(bi)); | |||
| bi = image.getAsBufferedImage(); | |||
| } | |||
| } | |||
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * Copyright 2002,2004 The Apache Software Foundation | |||
| * Copyright 2002,2004-2005 The Apache Software Foundation | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| @@ -55,9 +55,9 @@ public class Rectangle extends BasicShape implements DrawOperation { | |||
| Graphics2D graphics = (Graphics2D) bi.getGraphics(); | |||
| if (!stroke.equals("transparent")) { | |||
| BasicStroke b_stroke = new BasicStroke(stroke_width); | |||
| BasicStroke bStroke = new BasicStroke(stroke_width); | |||
| graphics.setColor(ColorMapper.getColorByName(stroke)); | |||
| graphics.setStroke(b_stroke); | |||
| graphics.setStroke(bStroke); | |||
| if ((arcwidth != 0) || (archeight != 0)) { | |||
| graphics.drawRoundRect(0, 0, width, height, arcwidth, archeight); | |||
| @@ -87,7 +87,8 @@ public class Rectangle extends BasicShape implements DrawOperation { | |||
| } else if (instr instanceof TransformOperation) { | |||
| graphics = (Graphics2D) bi.getGraphics(); | |||
| PlanarImage image | |||
| = ((TransformOperation) instr).executeTransformOperation(PlanarImage.wrapRenderedImage(bi)); | |||
| = ((TransformOperation) instr) | |||
| .executeTransformOperation(PlanarImage.wrapRenderedImage(bi)); | |||
| bi = image.getAsBufferedImage(); | |||
| } | |||
| } | |||
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * Copyright 2002-2004 The Apache Software Foundation | |||
| * Copyright 2002-2005 The Apache Software Foundation | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| @@ -41,12 +41,12 @@ public class Rotate extends TransformOperation implements DrawOperation { | |||
| public PlanarImage performRotate(PlanarImage image) { | |||
| float t_angle = (float) (angle * (Math.PI / 180.0F)); | |||
| float tAngle = (float) (angle * (Math.PI / 180.0F)); | |||
| ParameterBlock pb = new ParameterBlock(); | |||
| pb.addSource(image); | |||
| pb.add(0.0F); | |||
| pb.add(0.0F); | |||
| pb.add(t_angle); | |||
| pb.add(tAngle); | |||
| pb.add(new InterpolationNearest()); | |||
| return JAI.create("Rotate", pb, null); | |||
| } | |||
| @@ -72,7 +72,8 @@ public class Rotate extends TransformOperation implements DrawOperation { | |||
| bi = image.getAsBufferedImage(); | |||
| graphics = (Graphics2D) bi.getGraphics(); | |||
| System.out.println("Execing Transforms"); | |||
| image = ((TransformOperation) instr).executeTransformOperation(PlanarImage.wrapRenderedImage(bi)); | |||
| image = ((TransformOperation) instr) | |||
| .executeTransformOperation(PlanarImage.wrapRenderedImage(bi)); | |||
| bi = image.getAsBufferedImage(); | |||
| } | |||
| } | |||
| @@ -29,10 +29,10 @@ import java.awt.image.renderable.ParameterBlock; | |||
| */ | |||
| public class Scale extends TransformOperation implements DrawOperation { | |||
| private String width_str = "100%"; | |||
| private String height_str = "100%"; | |||
| private boolean x_percent = true; | |||
| private boolean y_percent = true; | |||
| private String widthStr = "100%"; | |||
| private String heightStr = "100%"; | |||
| private boolean xPercent = true; | |||
| private boolean yPercent = true; | |||
| private String proportions = "ignore"; | |||
| public static class ProportionsAttribute extends EnumeratedAttribute { | |||
| @@ -52,68 +52,70 @@ public class Scale extends TransformOperation implements DrawOperation { | |||
| * Sets the width of the image, either as an integer or a %. Defaults to 100%. | |||
| */ | |||
| public void setWidth(String width) { | |||
| width_str = width; | |||
| widthStr = width; | |||
| } | |||
| /** | |||
| * Sets the height of the image, either as an integer or a %. Defaults to 100%. | |||
| */ | |||
| public void setHeight(String height) { | |||
| height_str = height; | |||
| heightStr = height; | |||
| } | |||
| public float getWidth() { | |||
| float width = 0.0F; | |||
| int perc_index = width_str.indexOf('%'); | |||
| if (perc_index > 0) { | |||
| width = Float.parseFloat(width_str.substring(0, perc_index)); | |||
| x_percent = true; | |||
| int percIndex = widthStr.indexOf('%'); | |||
| if (percIndex > 0) { | |||
| width = Float.parseFloat(widthStr.substring(0, percIndex)); | |||
| xPercent = true; | |||
| return width / 100; | |||
| } else { | |||
| x_percent = false; | |||
| return Float.parseFloat(width_str); | |||
| xPercent = false; | |||
| return Float.parseFloat(widthStr); | |||
| } | |||
| } | |||
| public float getHeight() { | |||
| int perc_index = height_str.indexOf('%'); | |||
| if (perc_index > 0) { | |||
| float height = Float.parseFloat(height_str.substring(0, perc_index)); | |||
| y_percent = true; | |||
| int percIndex = heightStr.indexOf('%'); | |||
| if (percIndex > 0) { | |||
| float height = Float.parseFloat(heightStr.substring(0, percIndex)); | |||
| yPercent = true; | |||
| return height / 100; | |||
| } else { | |||
| y_percent = false; | |||
| return Float.parseFloat(height_str); | |||
| yPercent = false; | |||
| return Float.parseFloat(heightStr); | |||
| } | |||
| } | |||
| public PlanarImage performScale(PlanarImage image) { | |||
| ParameterBlock pb = new ParameterBlock(); | |||
| pb.addSource(image); | |||
| float x_fl = getWidth(); | |||
| float y_fl = getHeight(); | |||
| float xFl = getWidth(); | |||
| float yFl = getHeight(); | |||
| if (!x_percent) { | |||
| x_fl = (x_fl / image.getWidth()); | |||
| if (!xPercent) { | |||
| xFl = (xFl / image.getWidth()); | |||
| } | |||
| if (!y_percent) { | |||
| y_fl = (y_fl / image.getHeight()); | |||
| if (!yPercent) { | |||
| yFl = (yFl / image.getHeight()); | |||
| } | |||
| if ("width".equals(proportions)) { | |||
| y_fl = x_fl; | |||
| yFl = xFl; | |||
| } else if ("height".equals(proportions)) { | |||
| x_fl = y_fl; | |||
| xFl = yFl; | |||
| } else if ("fit".equals(proportions)) { | |||
| x_fl = y_fl = Math.min(x_fl, y_fl); | |||
| yFl = Math.min(xFl, yFl); | |||
| xFl = yFl; | |||
| } else if ("cover".equals(proportions)) { | |||
| x_fl = y_fl = Math.max(x_fl, y_fl); | |||
| yFl = Math.max(xFl, yFl); | |||
| xFl = yFl; | |||
| } | |||
| pb.add(new Float(x_fl)); | |||
| pb.add(new Float(y_fl)); | |||
| pb.add(new Float(xFl)); | |||
| pb.add(new Float(yFl)); | |||
| log("\tScaling to " + (x_fl * 100) + "% x " + (y_fl * 100) + "%"); | |||
| log("\tScaling to " + (xFl * 100) + "% x " + (yFl * 100) + "%"); | |||
| return JAI.create("scale", pb); | |||
| } | |||
| @@ -127,7 +129,8 @@ public class Scale extends TransformOperation implements DrawOperation { | |||
| return performScale(image); | |||
| } else if (instr instanceof TransformOperation) { | |||
| bi = image.getAsBufferedImage(); | |||
| image = ((TransformOperation) instr).executeTransformOperation(PlanarImage.wrapRenderedImage(bi)); | |||
| image = ((TransformOperation) instr) | |||
| .executeTransformOperation(PlanarImage.wrapRenderedImage(bi)); | |||
| bi = image.getAsBufferedImage(); | |||
| } | |||
| } | |||
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * Copyright 2002,2004 The Apache Software Foundation | |||
| * Copyright 2002,2004-2005 The Apache Software Foundation | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| @@ -29,7 +29,7 @@ import java.awt.image.BufferedImage; | |||
| * @see org.apache.tools.ant.taskdefs.optional.image.Image | |||
| */ | |||
| public class Text extends ImageOperation implements DrawOperation { | |||
| private String str_text = ""; | |||
| private String strText = ""; | |||
| private String font = "Arial"; | |||
| private int point = 10; | |||
| private boolean bold = false; | |||
| @@ -37,7 +37,7 @@ public class Text extends ImageOperation implements DrawOperation { | |||
| private String color = "black"; | |||
| public void setString(String str) { | |||
| str_text = str; | |||
| strText = str; | |||
| } | |||
| public void setFont(String f) { | |||
| @@ -67,7 +67,7 @@ public class Text extends ImageOperation implements DrawOperation { | |||
| } | |||
| public PlanarImage executeDrawOperation() { | |||
| log("\tCreating Text \"" + str_text + "\""); | |||
| log("\tCreating Text \"" + strText + "\""); | |||
| Color couloir = ColorMapper.getColorByName(color); | |||
| int width = 1; | |||
| @@ -75,23 +75,27 @@ public class Text extends ImageOperation implements DrawOperation { | |||
| BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR_PRE); | |||
| Graphics2D graphics = (Graphics2D) bi.getGraphics(); | |||
| graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); | |||
| graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); | |||
| graphics.setRenderingHint( | |||
| RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); | |||
| graphics.setRenderingHint( | |||
| RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); | |||
| Font f = new Font(font, Font.PLAIN, point); | |||
| FontMetrics fmetrics = graphics.getFontMetrics(f); | |||
| height = fmetrics.getMaxAscent() + fmetrics.getMaxDescent(); | |||
| width = fmetrics.stringWidth(str_text); | |||
| width = fmetrics.stringWidth(strText); | |||
| bi = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR_PRE); | |||
| graphics = (Graphics2D) bi.getGraphics(); | |||
| graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); | |||
| graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); | |||
| graphics.setRenderingHint( | |||
| RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); | |||
| graphics.setRenderingHint( | |||
| RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); | |||
| graphics.setFont(f); | |||
| graphics.setColor(couloir); | |||
| graphics.drawString(str_text, 0, height - fmetrics.getMaxDescent()); | |||
| graphics.drawString(strText, 0, height - fmetrics.getMaxDescent()); | |||
| PlanarImage image = PlanarImage.wrapRenderedImage(bi); | |||
| return image; | |||
| } | |||