List of usage examples for java.awt.geom AffineTransform shear
public void shear(double shx, double shy)
From source file:JXTransformer.java
public void stateChanged(ChangeEvent e) { AffineTransform at = new AffineTransform(); at.rotate(rotationSlider.getValue() * Math.PI / 180); double scale = scalingSlider.getValue() / 100.0; at.scale(scale, scale);/* w ww . ja va2s . c o m*/ double shear = shearingSlider.getValue() / 10.0; at.shear(shear, 0); for (JXTransformer t : transformers) { t.setTransform(at); } }
From source file:org.apache.jetspeed.security.mfa.impl.CaptchaImageResource.java
public void init() { boolean emptyBackground = true; if (config.isUseImageBackground() && background != null) { ByteArrayInputStream is = new ByteArrayInputStream(background); JPEGImgDecoder decoder = new DefaultJPEGImgDecoder(); try {// www . j ava 2s . c o m this.image = decoder.decodeAsBufferedImage(is); this.width = image.getWidth(); this.height = image.getHeight(); emptyBackground = false; } catch (Exception e) { emptyBackground = true; } } if (emptyBackground) { this.width = config.getTextMarginLeft() * 2; this.height = config.getTextMarginBottom() * 6; } char[] chars = challengeId.toCharArray(); charAttsList = new ArrayList(); TextLayout text = null; AffineTransform textAt = null; String[] fontNames = config.getFontNames(); for (int i = 0; i < chars.length; i++) { // font name String fontName = (fontNames.length == 1) ? fontNames[0] : fontNames[randomInt(0, fontNames.length)]; // rise int rise = config.getTextRiseRange(); if (rise > 0) { rise = randomInt(config.getTextMarginBottom(), config.getTextMarginBottom() + config.getTextRiseRange()); } if (config.getTextShear() > 0.0 || config.getTextRotation() > 0) { // rotation double dRotation = 0.0; if (config.getTextRotation() > 0) { dRotation = Math.toRadians(randomInt(-(config.getTextRotation()), config.getTextRotation())); } // shear double shearX = 0.0; double shearY = 0.0; if (config.getTextShear() > 0.0) { Random ran = new Random(); shearX = ran.nextDouble() * config.getTextShear(); shearY = ran.nextDouble() * config.getTextShear(); } CharAttributes cf = new CharAttributes(chars[i], fontName, dRotation, rise, shearX, shearY); charAttsList.add(cf); text = new TextLayout(chars[i] + "", getFont(fontName), new FontRenderContext(null, config.isFontAntialiasing(), false)); textAt = new AffineTransform(); if (config.getTextRotation() > 0) textAt.rotate(dRotation); if (config.getTextShear() > 0.0) textAt.shear(shearX, shearY); } else { CharAttributes cf = new CharAttributes(chars[i], fontName, 0, rise, 0.0, 0.0); charAttsList.add(cf); } if (emptyBackground) { Shape shape = text.getOutline(textAt); // this.width += text.getBounds().getWidth(); this.width += (int) shape.getBounds2D().getWidth(); this.width += config.getTextSpacing() + 1; if (this.height < (int) shape.getBounds2D().getHeight() + rise) { this.height = (int) shape.getBounds2D().getHeight() + rise; } } } if (emptyBackground) { this.image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D gfx = (Graphics2D) this.image.getGraphics(); gfx.setBackground(Color.WHITE); gfx.clearRect(0, 0, width, height); } }
From source file:org.apache.jetspeed.security.mfa.impl.CaptchaImageResource.java
/** * Renders this image/* w w w . j a v a2 s . co m*/ * * @return The image data */ private final byte[] render() throws IOException { Graphics2D gfx = (Graphics2D) this.image.getGraphics(); if (config.isFontAntialiasing()) gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int curWidth = config.getTextMarginLeft(); FontRenderContext ctx = new FontRenderContext(null, config.isFontAntialiasing(), false); for (int i = 0; i < charAttsList.size(); i++) { CharAttributes cf = (CharAttributes) charAttsList.get(i); TextLayout text = new TextLayout(cf.getChar() + "", getFont(cf.getName()), ctx); //gfx.getFontRenderContext()); AffineTransform textAt = new AffineTransform(); textAt.translate(curWidth, this.height - cf.getRise()); if (cf.getRotation() != 0) { textAt.rotate(cf.getRotation()); } if (cf.getShearX() > 0.0) textAt.shear(cf.getShearX(), cf.getShearY()); Shape shape = text.getOutline(textAt); curWidth += shape.getBounds().getWidth() + config.getTextSpacing(); if (config.isUseImageBackground()) gfx.setColor(Color.BLACK); else gfx.setXORMode(Color.BLACK); gfx.fill(shape); } if (config.isEffectsNoise()) { noiseEffects(gfx, image); } if (config.isUseTimestamp()) { if (config.isEffectsNoise()) gfx.setColor(Color.WHITE); else gfx.setColor(Color.BLACK); TimeZone tz = TimeZone.getTimeZone(config.getTimestampTZ()); Calendar cal = new GregorianCalendar(tz); SimpleDateFormat formatter; if (config.isUseTimestamp24hr()) formatter = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z"); else formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a, z"); formatter.setTimeZone(tz); Font font = gfx.getFont(); Font newFont = new Font(font.getName(), font.getStyle(), config.getTimestampFontSize()); gfx.setFont(newFont); gfx.drawString(formatter.format(cal.getTime()), config.getTextMarginLeft() * 4, this.height - 1); } return toImageData(image); }