Search in sources :

Example 1 with Shape

use of java.awt.Shape in project WordCram by danbernier.

the class AWordCramEngine method willSkipWordsWhoseShapesAreTooSmallEvenWhenMinShapeSizeIsZero.

@Test
public void willSkipWordsWhoseShapesAreTooSmallEvenWhenMinShapeSizeIsZero() {
    Word big = new Word("big", 10);
    Word small = new Word("small", 1);
    Shape bigShape = new Rectangle(0, 0, 20, 20);
    Shape smallShape = new Rectangle(0, 0, 0, 1);
    renderOptions.minShapeSize = 0;
    when(shaper.getShapeFor(eq(big.word), any(PFont.class), anyFloat(), anyFloat())).thenReturn(bigShape);
    when(shaper.getShapeFor(eq(small.word), any(PFont.class), anyFloat(), anyFloat())).thenReturn(smallShape);
    WordCramEngine engine = getEngine(big, small);
    Word[] skippedWords = engine.getSkippedWords();
    Assert.assertEquals(1, skippedWords.length);
    Assert.assertSame(small, skippedWords[0]);
    Assert.assertEquals(WordSkipReason.SHAPE_WAS_TOO_SMALL, small.wasSkippedBecause());
    Assert.assertNull(big.wasSkippedBecause());
}
Also used : Shape(java.awt.Shape) PFont(processing.core.PFont) Rectangle(java.awt.Rectangle) Test(org.junit.Test)

Example 2 with Shape

use of java.awt.Shape in project WordCram by danbernier.

the class PlacerHeatMap method draw.

public void draw(PApplet sketch) {
    RectStack rectStack = new RectStack();
    for (int i = 0; i < words.length; i++) {
        Word word = words[i];
        PFont wordFont = word.getFont(fonter);
        float wordSize = word.getSize(sizer, i, words.length);
        float wordAngle = word.getAngle(angler);
        Shape shape = shaper.getShapeFor(word.word, wordFont, wordSize, wordAngle);
        Rectangle2D rect = shape.getBounds2D();
        //return r.getHeight() < minShapeSize || r.getWidth() < minShapeSize;
        int wordImageWidth = (int) rect.getWidth();
        int wordImageHeight = (int) rect.getHeight();
        PVector desiredLocation = word.getTargetPlace(placer, i, words.length, wordImageWidth, wordImageHeight, sketch.width, sketch.height);
        //sketch.rect(desiredLocation.x, desiredLocation.y, wordImageWidth, wordImageHeight);
        rectStack.add((int) desiredLocation.x, (int) desiredLocation.y, wordImageWidth, wordImageHeight);
    }
    RectGrid grid = new RectGrid(rectStack);
    grid.draw(sketch);
}
Also used : PVector(processing.core.PVector) Shape(java.awt.Shape) PFont(processing.core.PFont) Rectangle2D(java.awt.geom.Rectangle2D)

Example 3 with Shape

use of java.awt.Shape in project WordCram by danbernier.

the class AWordCramEngine method willSkipWordsWhoseShapesAreTooSmall.

@Test
public void willSkipWordsWhoseShapesAreTooSmall() {
    Word big = new Word("big", 10);
    Word small = new Word("small", 1);
    Shape bigShape = new Rectangle(0, 0, 20, 20);
    Shape smallShape = new Rectangle(0, 0, 1, 1);
    when(shaper.getShapeFor(eq(big.word), any(PFont.class), anyFloat(), anyFloat())).thenReturn(bigShape);
    when(shaper.getShapeFor(eq(small.word), any(PFont.class), anyFloat(), anyFloat())).thenReturn(smallShape);
    WordCramEngine engine = getEngine(big, small);
    Word[] skippedWords = engine.getSkippedWords();
    Assert.assertEquals(1, skippedWords.length);
    Assert.assertSame(small, skippedWords[0]);
    Assert.assertEquals(WordSkipReason.SHAPE_WAS_TOO_SMALL, small.wasSkippedBecause());
    Assert.assertNull(big.wasSkippedBecause());
}
Also used : Shape(java.awt.Shape) PFont(processing.core.PFont) Rectangle(java.awt.Rectangle) Test(org.junit.Test)

Example 4 with Shape

use of java.awt.Shape in project android_frameworks_base by ParanoidAndroid.

the class GcSnapshot method doRestore.

private GcSnapshot doRestore() {
    if (mPrevious != null) {
        if (mLocalLayer != null) {
            // prepare to blit the layers in which we have draw, in the layer beneath
            // them, starting with the top one (which is the current local layer).
            int i = mLayers.size() - 1;
            int flags;
            do {
                Layer dstLayer = mLayers.get(i - 1);
                restoreLayer(dstLayer);
                flags = dstLayer.getFlags();
                i--;
            } while (i > 0 && (flags & Canvas.CLIP_TO_LAYER_SAVE_FLAG) == 0);
        }
        // didn't save the matrix? set the current matrix on the previous snapshot
        if ((mFlags & Canvas.MATRIX_SAVE_FLAG) == 0) {
            AffineTransform mtx = getTransform();
            for (Layer layer : mPrevious.mLayers) {
                layer.getGraphics().setTransform(mtx);
            }
        }
        // didn't save the clip? set the current clip on the previous snapshot
        if ((mFlags & Canvas.CLIP_SAVE_FLAG) == 0) {
            Shape clip = getClip();
            for (Layer layer : mPrevious.mLayers) {
                layer.setClip(clip);
            }
        }
    }
    for (Layer layer : mLayers) {
        layer.getGraphics().dispose();
    }
    return mPrevious;
}
Also used : Shape(java.awt.Shape) AffineTransform(java.awt.geom.AffineTransform) Paint(android.graphics.Paint)

Example 5 with Shape

use of java.awt.Shape in project LuaViewSDK by alibaba.

the class EclipseTabbedPaneUI method paintTabBorder.

@Override
protected void paintTabBorder(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) {
    if (tabPlacement == BOTTOM) {
        g.setColor(LINE_COLOR);
        g.drawLine(x, y + h - 1, x + w, y + h - 1);
    }
    if (tabPlacement == TOP && isSelected) {
        g.setColor(LINE_COLOR);
        Shape shape = g.getClip();
        g.setClip(x, y, w + 2, h);
        g.drawRoundRect(x, y, w, h + R + R, R, R);
        g.setClip(shape);
    }
}
Also used : Shape(java.awt.Shape)

Aggregations

Shape (java.awt.Shape)85 AffineTransform (java.awt.geom.AffineTransform)21 BasicStroke (java.awt.BasicStroke)20 Graphics2D (java.awt.Graphics2D)19 Rectangle (java.awt.Rectangle)13 Stroke (java.awt.Stroke)11 Color (java.awt.Color)10 Rectangle2D (java.awt.geom.Rectangle2D)10 BufferedImage (java.awt.image.BufferedImage)9 Paint (android.graphics.Paint)6 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)6 Composite (java.awt.Composite)6 TextLayout (java.awt.font.TextLayout)6 Area (java.awt.geom.Area)6 Point2D (java.awt.geom.Point2D)6 Font (java.awt.Font)5 FontMetrics (java.awt.FontMetrics)5 Paint (java.awt.Paint)5 Point (java.awt.Point)5 Test (org.junit.Test)5