当前位置: 首页>>代码示例>>Java>>正文


Java CompositeFont.getCharFontIndex方法代码示例

本文整理汇总了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);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:81,代码来源:GDITextRenderer.java

示例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);
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:82,代码来源:GDITextRenderer.java


注:本文中的org.apache.harmony.awt.gl.font.CompositeFont.getCharFontIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。