本文整理匯總了Java中java.awt.font.GlyphVector.getNumGlyphs方法的典型用法代碼示例。如果您正苦於以下問題:Java GlyphVector.getNumGlyphs方法的具體用法?Java GlyphVector.getNumGlyphs怎麽用?Java GlyphVector.getNumGlyphs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.font.GlyphVector
的用法示例。
在下文中一共展示了GlyphVector.getNumGlyphs方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createImage
import java.awt.font.GlyphVector; //導入方法依賴的package包/類
protected BufferedImage createImage(Color bgColor) {
BufferedImage bufferedImage = new BufferedImage(END_X, END_Y,
BufferedImage.TYPE_INT_RGB);
// create graphics and graphics2d
final Graphics graphics = bufferedImage.getGraphics();
final Graphics2D g2d = (Graphics2D) graphics;
// set the background color
g2d.setBackground(bgColor == null ? Color.gray : bgColor);
g2d.clearRect(START_X, START_Y, END_X, END_Y);
// create a pattern for the background
createPattern(g2d);
// set the fonts and font rendering hints
Font font = new Font("Helvetica", Font.ITALIC, 30);
g2d.setFont(font);
FontRenderContext frc = g2d.getFontRenderContext();
g2d.translate(10, 24);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setStroke(new BasicStroke(3));
// sets the foreground color
g2d.setPaint(Color.DARK_GRAY);
GlyphVector gv = font.createGlyphVector(frc, message);
int numGlyphs = gv.getNumGlyphs();
for (int ii = 0; ii < numGlyphs; ii++) {
AffineTransform at;
Point2D p = gv.getGlyphPosition(ii);
at = AffineTransform.getTranslateInstance(p.getX(), p.getY());
at.rotate(Math.PI / 8);
Shape shape = gv.getGlyphOutline(ii);
Shape sss = at.createTransformedShape(shape);
g2d.fill(sss);
}
return blurImage(bufferedImage);
}
示例2: findWidth
import java.awt.font.GlyphVector; //導入方法依賴的package包/類
/**
* @param text the string to find the width of
* @param logical whether to add the space the letters should occupy on the end
* @return width of string.
*/
private int findWidth(String text,boolean logical) {
char[] chars = text.toCharArray();
GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
int width = 0;
int extraX = 0;
boolean startNewLine = false;
for (int glyphIndex = 0, n = vector.getNumGlyphs(); glyphIndex < n; glyphIndex++) {
int charIndex = vector.getGlyphCharIndex(glyphIndex);
int codePoint = text.codePointAt(charIndex);
Rectangle bounds = logical ? vector.getLogicalBounds().getBounds() : getGlyphBounds(vector, glyphIndex, codePoint);
if (startNewLine && codePoint != '\n') extraX = -bounds.x;
if (glyphIndex > 0) extraX += paddingLeft + paddingRight + paddingAdvanceX;
width = Math.max(width, bounds.x + extraX + bounds.width);
if (codePoint == '\n') startNewLine = true;
}
return width;
}
示例3: samePositions
import java.awt.font.GlyphVector; //導入方法依賴的package包/類
private boolean samePositions(GlyphVector gv, int[] gvcodes,
int[] origCodes, float[] origPositions) {
int numGlyphs = gv.getNumGlyphs();
float[] gvpos = gv.getGlyphPositions(0, numGlyphs, null);
/* this shouldn't happen here, but just in case */
if (numGlyphs != gvcodes.length || /* real paranoia here */
origCodes.length != gvcodes.length ||
origPositions.length != gvpos.length) {
return false;
}
for (int i=0; i<numGlyphs; i++) {
if (gvcodes[i] != origCodes[i] || gvpos[i] != origPositions[i]) {
return false;
}
}
return true;
}
示例4: addGlyphs
import java.awt.font.GlyphVector; //導入方法依賴的package包/類
/**
* Queues the glyphs in the specified text to be loaded. Note that the glyphs are not actually loaded until
* {@link #loadGlyphs()} is called.
*
* @param text The text containing the glyphs to be added
*/
public void addGlyphs(String text) {
if (text == null) throw new IllegalArgumentException("text cannot be null.");
char[] chars = text.toCharArray();
GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
for (int i = 0, n = vector.getNumGlyphs(); i < n; i++) {
int codePoint = text.codePointAt(vector.getGlyphCharIndex(i));
Rectangle bounds = getGlyphBounds(vector, i, codePoint);
getGlyph(vector.getGlyphCode(i), codePoint, bounds, vector, i);
}
}
示例5: getHeight
import java.awt.font.GlyphVector; //導入方法依賴的package包/類
/**
* @see org.newdawn.slick.Font#getHeight(java.lang.String)
*/
public int getHeight (String text) {
if (text == null) throw new IllegalArgumentException("text cannot be null.");
if (text.length() == 0) return 0;
if (displayListCaching) {
DisplayList displayList = (DisplayList)displayLists.get(text);
if (displayList != null) return displayList.height;
}
char[] chars = text.toCharArray();
GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
int lines = 0, height = 0;
for (int i = 0, n = vector.getNumGlyphs(); i < n; i++) {
int charIndex = vector.getGlyphCharIndex(i);
int codePoint = text.codePointAt(charIndex);
if (codePoint == ' ') continue;
Rectangle bounds = getGlyphBounds(vector, i, codePoint);
height = Math.max(height, ascent + bounds.y + bounds.height);
if (codePoint == '\n') {
lines++;
height = 0;
}
}
return lines * getLineHeight() + height;
}
示例6: runTest
import java.awt.font.GlyphVector; //導入方法依賴的package包/類
public void runTest(Object ctx, int numReps) {
GVContext gvctx = (GVContext)ctx;
GlyphVector gv = gvctx.gv;
Shape s;
do {
for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
s = gv.getGlyphOutline(i);
}
} while (--numReps >= 0);
}
示例7: runTest
import java.awt.font.GlyphVector; //導入方法依賴的package包/類
public void runTest(Object ctx, int numReps) {
GVContext gvctx = (GVContext)ctx;
GlyphVector gv = gvctx.gv;
Shape s;
do {
for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
s = gv.getGlyphLogicalBounds(i);
}
} while (--numReps >= 0);
}
示例8: StandardGlyphVector
import java.awt.font.GlyphVector; //導入方法依賴的package包/類
/**
* Utility used by getStandardGV.
* Constructs a StandardGlyphVector from a generic glyph vector.
* Do not call this from new contexts without considering the comment
* about "userGlyphs".
*/
private StandardGlyphVector(GlyphVector gv, FontRenderContext frc) {
this.font = gv.getFont();
this.frc = frc;
initFontData();
int nGlyphs = gv.getNumGlyphs();
this.userGlyphs = gv.getGlyphCodes(0, nGlyphs, null);
if (gv instanceof StandardGlyphVector) {
/* userGlyphs will be OK because this is a private constructor
* and the returned instance is used only for rendering.
* It's not constructable by user code, nor returned to the
* application. So we know "userGlyphs" are valid as having
* been either already validated or are the result of layout.
*/
this.glyphs = userGlyphs;
} else {
this.glyphs = getValidatedGlyphs(this.userGlyphs);
}
this.flags = gv.getLayoutFlags() & FLAG_MASK;
if ((flags & FLAG_HAS_POSITION_ADJUSTMENTS) != 0) {
this.positions = gv.getGlyphPositions(0, nGlyphs + 1, null);
}
if ((flags & FLAG_COMPLEX_GLYPHS) != 0) {
this.charIndices = gv.getGlyphCharIndices(0, nGlyphs, null);
}
if ((flags & FLAG_HAS_TRANSFORMS) != 0) {
AffineTransform[] txs = new AffineTransform[nGlyphs]; // worst case
for (int i = 0; i < nGlyphs; ++i) {
txs[i] = gv.getGlyphTransform(i); // gv doesn't have getGlyphsTransforms
}
setGlyphTransforms(txs);
}
}
示例9: runTest
import java.awt.font.GlyphVector; //導入方法依賴的package包/類
public void runTest(Object ctx, int numReps) {
GVContext gvctx = (GVContext)ctx;
GlyphVector gv = gvctx.gv;
Shape s;
do {
for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
s = gv.getGlyphVisualBounds(i);
}
} while (--numReps >= 0);
}