FileDocCategorySizeDatePackage
Scale.javaAPI DocApache Ant 1.705680Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.types.optional.image

Scale

public class Scale extends TransformOperation implements DrawOperation
see
org.apache.tools.ant.taskdefs.optional.image.Image

Fields Summary
private static final int
HUNDRED
private String
widthStr
private String
heightStr
private boolean
xPercent
private boolean
yPercent
private String
proportions
Constructors Summary
Methods Summary
public javax.media.jai.PlanarImageexecuteDrawOperation()
{@inheritDoc}.

        for (int i = 0; i < instructions.size(); i++) {
            ImageOperation instr = ((ImageOperation) instructions.elementAt(i));
            if (instr instanceof DrawOperation) {
                PlanarImage image = null;
                // If this TransformOperation has DrawOperation children
                // then Rotate the first child and return.
                performScale(image);
                return image;
            }
        }
        return null;
    
public javax.media.jai.PlanarImageexecuteTransformOperation(javax.media.jai.PlanarImage image)
{@inheritDoc}.

        BufferedImage bi = null;
        for (int i = 0; i < instructions.size(); i++) {
            ImageOperation instr = ((ImageOperation) instructions.elementAt(i));
            if (instr instanceof DrawOperation) {
                return performScale(image);
            } else if (instr instanceof TransformOperation) {
                bi = image.getAsBufferedImage();
                image = ((TransformOperation) instr)
                    .executeTransformOperation(PlanarImage.wrapRenderedImage(bi));
                bi = image.getAsBufferedImage();
            }
        }
        return performScale(image);
    
public floatgetHeight()
Get the height.

return
the value converted from the height string.

        int percIndex = heightStr.indexOf('%");
        if (percIndex > 0) {
            float height = Float.parseFloat(heightStr.substring(0, percIndex));
            yPercent = true;
            return height / HUNDRED;
        } else {
            yPercent = false;
            return Float.parseFloat(heightStr);
        }
    
public floatgetWidth()
Get the width.

return
the value converted from the width string.

        float width = 0.0F;
        int percIndex = widthStr.indexOf('%");
        if (percIndex > 0) {
            width = Float.parseFloat(widthStr.substring(0, percIndex));
            xPercent = true;
            return width / HUNDRED;
        } else {
            xPercent = false;
            return Float.parseFloat(widthStr);
        }
    
public javax.media.jai.PlanarImageperformScale(javax.media.jai.PlanarImage image)
Scale an image.

param
image the image to scale.
return
the scaled image.

        ParameterBlock pb = new ParameterBlock();
        pb.addSource(image);
        float xFl = getWidth();
        float yFl = getHeight();

        if (!xPercent) {
            xFl = (xFl / image.getWidth());
        }
        if (!yPercent) {
            yFl = (yFl / image.getHeight());
        }

        if ("width".equals(proportions)) {
            yFl = xFl;
        } else if ("height".equals(proportions)) {
            xFl = yFl;
        } else if ("fit".equals(proportions)) {
            yFl = Math.min(xFl, yFl);
            xFl = yFl;
        } else if ("cover".equals(proportions)) {
            yFl = Math.max(xFl, yFl);
            xFl = yFl;
        }

        pb.add(new Float(xFl));
        pb.add(new Float(yFl));

        log("\tScaling to " + (xFl * HUNDRED) + "% x "
            + (yFl * HUNDRED) + "%");

        return JAI.create("scale", pb);
    
public voidsetHeight(java.lang.String height)
Sets the height of the image, either as an integer or a %. Defaults to 100%.

param
height the value to use.

        heightStr = height;
    
public voidsetProportions(org.apache.tools.ant.types.optional.image.Scale$ProportionsAttribute pa)
Sets the behaviour regarding the image proportions.

param
pa the enumerated value.

        proportions = pa.getValue();
    
public voidsetWidth(java.lang.String width)
Sets the width of the image, either as an integer or a %. Defaults to 100%.

param
width the value to use.

        widthStr = width;