Java Code Examples for java.awt.font.GlyphVector#getGlyphPixelBounds()

The following examples show how to use java.awt.font.GlyphVector#getGlyphPixelBounds() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextMeasureTests.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    Rectangle2D r;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            r = gv.getGlyphPixelBounds(i, null, 0, 0); // !!! add opt to provide different frc?
        }
    } while (--numReps >= 0);
}
 
Example 2
Source File: BMFontUtil.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private int[] getGlyphMetrics (Font font, int codePoint) {
	// xOffset and xAdvance will be incorrect for unicode characters such as combining marks or non-spacing characters
	// (eg Pnujabi's "\u0A1C\u0A47") that require the context of surrounding glyphs to determine spacing, but thisis the
	// best we can do with the BMFont format.
	char[] chars = Character.toChars(codePoint);
	GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
	GlyphMetrics metrics = vector.getGlyphMetrics(0);
	int xOffset = vector.getGlyphPixelBounds(0, null, 0, 0).x - unicodeFont.getPaddingLeft();
	int xAdvance = (int)(metrics.getAdvanceX() + unicodeFont.getPaddingAdvanceX() + unicodeFont.getPaddingLeft() + unicodeFont
		.getPaddingRight());
	return new int[] {xOffset, xAdvance};
}
 
Example 3
Source File: BMFontUtil.java    From gdx-skineditor with Apache License 2.0 5 votes vote down vote up
private int[] getGlyphMetrics (Font font, int codePoint) {
	// xOffset and xAdvance will be incorrect for unicode characters such as combining marks or non-spacing characters
	// (eg Pnujabi's "\u0A1C\u0A47") that require the context of surrounding glyphs to determine spacing, but thisis the
	// best we can do with the BMFont format.
	char[] chars = Character.toChars(codePoint);
	GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
	GlyphMetrics metrics = vector.getGlyphMetrics(0);
	int xOffset = vector.getGlyphPixelBounds(0, GlyphPage.renderContext, 0.5f, 0).x - unicodeFont.getPaddingLeft();
	int xAdvance = (int)(metrics.getAdvanceX() + unicodeFont.getPaddingAdvanceX() + unicodeFont.getPaddingLeft() + unicodeFont
		.getPaddingRight());
	return new int[] {xOffset, xAdvance};
}
 
Example 4
Source File: TextMeasureTests.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    Rectangle2D r;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            r = gv.getGlyphPixelBounds(i, null, 0, 0); // !!! add opt to provide different frc?
        }
    } while (--numReps >= 0);
}
 
Example 5
Source File: TextMeasureTests.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    Rectangle2D r;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            r = gv.getGlyphPixelBounds(i, null, 0, 0); // !!! add opt to provide different frc?
        }
    } while (--numReps >= 0);
}
 
Example 6
Source File: TextMeasureTests.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    Rectangle2D r;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            r = gv.getGlyphPixelBounds(i, null, 0, 0); // !!! add opt to provide different frc?
        }
    } while (--numReps >= 0);
}
 
Example 7
Source File: TextMeasureTests.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    Rectangle2D r;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            r = gv.getGlyphPixelBounds(i, null, 0, 0); // !!! add opt to provide different frc?
        }
    } while (--numReps >= 0);
}
 
Example 8
Source File: TextMeasureTests.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    Rectangle2D r;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            r = gv.getGlyphPixelBounds(i, null, 0, 0); // !!! add opt to provide different frc?
        }
    } while (--numReps >= 0);
}
 
Example 9
Source File: TextMeasureTests.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    Rectangle2D r;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            r = gv.getGlyphPixelBounds(i, null, 0, 0); // !!! add opt to provide different frc?
        }
    } while (--numReps >= 0);
}
 
Example 10
Source File: TextMeasureTests.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    Rectangle2D r;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            r = gv.getGlyphPixelBounds(i, null, 0, 0); // !!! add opt to provide different frc?
        }
    } while (--numReps >= 0);
}
 
Example 11
Source File: TextMeasureTests.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    Rectangle2D r;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            r = gv.getGlyphPixelBounds(i, null, 0, 0); // !!! add opt to provide different frc?
        }
    } while (--numReps >= 0);
}
 
Example 12
Source File: SwingUtilities2.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public int getLeftSideBearing(char aChar) {
    int index = aChar - MIN_CHAR_INDEX;
    assert (index >= 0 && index < (MAX_CHAR_INDEX - MIN_CHAR_INDEX));
    byte lsb = lsbCache[index];
    if (lsb == UNSET) {
        oneChar[0] = aChar;
        GlyphVector gv = font.createGlyphVector(frc, oneChar);
        lsb = (byte) gv.getGlyphPixelBounds(0, frc, 0f, 0f).x;
        if (lsb < 0) {
            /* HRGB/HBGR LCD glyph images will always have a pixel
             * on the left used in colour fringe reduction.
             * Text rendering positions this correctly but here
             * we are using the glyph image to adjust that position
             * so must account for it.
             */
            Object aaHint = frc.getAntiAliasingHint();
            if (aaHint == VALUE_TEXT_ANTIALIAS_LCD_HRGB ||
                    aaHint == VALUE_TEXT_ANTIALIAS_LCD_HBGR) {
                lsb++;
            }
        }
        lsbCache[index] = lsb;
    }
    return lsb;


}
 
Example 13
Source File: TextMeasureTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    Rectangle2D r;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            r = gv.getGlyphPixelBounds(i, null, 0, 0); // !!! add opt to provide different frc?
        }
    } while (--numReps >= 0);
}
 
Example 14
Source File: TextMeasureTests.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    Rectangle2D r;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            r = gv.getGlyphPixelBounds(i, null, 0, 0); // !!! add opt to provide different frc?
        }
    } while (--numReps >= 0);
}
 
Example 15
Source File: TextMeasureTests.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    Rectangle2D r;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            r = gv.getGlyphPixelBounds(i, null, 0, 0); // !!! add opt to provide different frc?
        }
    } while (--numReps >= 0);
}
 
Example 16
Source File: TextMeasureTests.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    Rectangle2D r;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            r = gv.getGlyphPixelBounds(i, null, 0, 0); // !!! add opt to provide different frc?
        }
    } while (--numReps >= 0);
}
 
Example 17
Source File: UnicodeFont.java    From opsu with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Returns the bounds of the specified glyph.
 * 
 * @param vector The vector the glyph is part of
 * @param index The index of the glyph within the vector
 * @param codePoint The code point associated with the glyph
 */
private Rectangle getGlyphBounds (GlyphVector vector, int index, int codePoint) {
	Rectangle bounds = vector.getGlyphPixelBounds(index, GlyphPage.renderContext, 0, 0);
	if (codePoint == ' ') bounds.width = spaceWidth;
	return bounds;
}
 
Example 18
Source File: UnicodeFont.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Returns the bounds of the specified glyph.\
 * 
 * @param vector The vector the glyph is part of
 * @param index The index of the glyph within the vector
 * @param codePoint The code point associated with the glyph
 */
private Rectangle getGlyphBounds (GlyphVector vector, int index, int codePoint) {
	Rectangle bounds = vector.getGlyphPixelBounds(index, GlyphPage.renderContext, 0, 0);
	if (codePoint == ' ') bounds.width = spaceWidth;
	return bounds;
}