本文整理汇总了Java中org.apache.harmony.awt.gl.font.CompositeFont.getCharFontIndex方法的典型用法代码示例。如果您正苦于以下问题:Java CompositeFont.getCharFontIndex方法的具体用法?Java CompositeFont.getCharFontIndex怎么用?Java CompositeFont.getCharFontIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.harmony.awt.gl.font.CompositeFont
的用法示例。
在下文中一共展示了CompositeFont.getCharFontIndex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawCompositeString
import org.apache.harmony.awt.gl.font.CompositeFont; //导入方法依赖的package包/类
/**
* Method to draw string with graphics that has composite font
* at desired coordinates.
*
* @param g Graphics to draw onto
* @param str String to draw
* @param x starting X coordinate to draw at
* @param y starting Y coordinate to draw at
*/
@SuppressWarnings("deprecation")
public void drawCompositeString(Graphics2D g, String str, int x, int y) {
int len = str.length();
if (len == 0){
return;
}
AffineTransform trans = ((WinGDIGraphics2D)g).getTransform();
long gi = ((WinGDIGraphics2D)g).getGraphicsInfo();
long hdc = ((WinGDIGraphics2D)g).getDC();
x += (int)Math.round(trans.getTranslateX());
y += (int)Math.round(trans.getTranslateY());
win32.SetTextColor(hdc, getGDIColor(g.getColor().getRGB()));
win32.SetBkMode(hdc, WindowsDefs.TRANSPARENT);
CompositeFont wcf = (CompositeFont)(g.getFont().getPeer());
int charFontIndex = wcf.getCharFontIndex(str.charAt(0), 0);
int fontIndex = charFontIndex;
WindowsFont physFont = (WindowsFont)wcf.fPhysicalFonts[charFontIndex];
long font = physFont.getFontHandle();
win32.SelectObject(hdc, font);
int ascent = physFont.getAscent(); // Font ascent
int offs = 0; // width of substring with the same font header
int yOffset = y - ascent; // Y offset to draw (y - font.ascent)
int xOffset = x; // X offset to draw
int start = 0;
int count = 0;
for (int i=0; i < len; i++){
char c = str.charAt(i);
Glyph gl = wcf.getGlyph(c);
int glWidth = Math.round(gl.getGlyphPointMetrics().getAdvance());
if (glWidth ==0){
continue;
}
fontIndex = wcf.getCharFontIndex(c, 0);
if (fontIndex != charFontIndex){
charFontIndex = fontIndex;
win32.TextOutW(hdc, xOffset, yOffset,
str.substring(start, start + count), count);
xOffset += offs;
offs = 0;
count = 1;
start = i;
physFont = (WindowsFont)wcf.fPhysicalFonts[charFontIndex];
font = physFont.getFontHandle();
win32.SelectObject(hdc, font);
yOffset = y - physFont.getAscent();
} else {
count++;
}
offs += glWidth;
}
win32.TextOutW(hdc, xOffset, yOffset,
str.substring(start, start + count), count);
}
示例2: drawCompositeString
import org.apache.harmony.awt.gl.font.CompositeFont; //导入方法依赖的package包/类
/**
* Method to draw string with graphics that has composite font
* at desired coordinates.
*
* @param g Graphics to draw onto
* @param str String to draw
* @param x starting X coordinate to draw at
* @param y starting Y coordinate to draw at
*/
@SuppressWarnings("deprecation")
public void drawCompositeString(Graphics2D g, String str, int x, int y) {
int len = str.length();
if (len == 0){
return;
}
AffineTransform trans = ((WinGDIPGraphics2D)g).getTransform();
long gi = ((WinGDIPGraphics2D)g).getGraphicsInfo();
long hdc = NativeFont.gdiPlusGetHDC(gi);
x += (int)Math.round(trans.getTranslateX());
y += (int)Math.round(trans.getTranslateY());
win32.SetTextColor(hdc, getGDIColor(g.getColor().getRGB()));
win32.SetBkMode(hdc, WindowsDefs.TRANSPARENT);
CompositeFont wcf = (CompositeFont)(g.getFont().getPeer());
int charFontIndex = wcf.getCharFontIndex(str.charAt(0), 0);
int fontIndex = charFontIndex;
WindowsFont physFont = (WindowsFont)wcf.fPhysicalFonts[charFontIndex];
long font = physFont.getFontHandle();
win32.SelectObject(hdc, font);
int ascent = physFont.getAscent(); // Font ascent
int offs = 0; // width of substring with the same font header
int yOffset = y - ascent; // Y offset to draw (y - font.ascent)
int xOffset = x; // X offset to draw
int start = 0;
int count = 0;
for (int i=0; i < len; i++){
char c = str.charAt(i);
Glyph gl = wcf.getGlyph(c);
int glWidth = Math.round(gl.getGlyphPointMetrics().getAdvance());
if (glWidth ==0){
continue;
}
fontIndex = wcf.getCharFontIndex(c, 0);
if (fontIndex != charFontIndex){
charFontIndex = fontIndex;
win32.TextOutW(hdc, xOffset, yOffset,
str.substring(start, start + count), count);
xOffset += offs;
offs = 0;
count = 1;
start = i;
physFont = (WindowsFont)wcf.fPhysicalFonts[charFontIndex];
font = physFont.getFontHandle();
win32.SelectObject(hdc, font);
yOffset = y - physFont.getAscent();
} else {
count++;
}
offs += glWidth;
}
win32.TextOutW(hdc, xOffset, yOffset,
str.substring(start, start + count), count);
NativeFont.gdiPlusReleaseHDC(gi, hdc);
}