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


Java Graphics2D.drawGlyphVector方法代码示例

本文整理汇总了Java中java.awt.Graphics2D.drawGlyphVector方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics2D.drawGlyphVector方法的具体用法?Java Graphics2D.drawGlyphVector怎么用?Java Graphics2D.drawGlyphVector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.Graphics2D的用法示例。


在下文中一共展示了Graphics2D.drawGlyphVector方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: paintComponent

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void paintComponent(Graphics g) {
     super.paintComponent(g);
     Graphics2D g2 = (Graphics2D)g;
     FontRenderContext frc = new FontRenderContext(null, true, true);
     Font f = helvFont.deriveFont(Font.PLAIN, 40);
     System.out.println("font = " +f.getFontName());
     GlyphVector gv = f.createGlyphVector(frc, codes);
     g.setFont(f);
     g.setColor(Color.white);
     g.fillRect(0,0,400,400);
     g.setColor(Color.black);
     g2.drawGlyphVector(gv, 5,200);
     g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                         RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
     g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
                         RenderingHints.VALUE_FRACTIONALMETRICS_ON);
     g2.drawString(str, 5, 250);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:HelvLtOblTest.java

示例2: drawText

import java.awt.Graphics2D; //导入方法依赖的package包/类
BufferedImage drawText(boolean doGV) {
    int w = 400;
    int h = 50;
    BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = bi.createGraphics();
    g.setColor(Color.white);
    g.fillRect(0,0,w,h);
    g.setColor(Color.black);
    Font f = helvFont.deriveFont(Font.PLAIN, 40);
    g.setFont(f);
    int x = 5;
    int y = h - 10;
    if (doGV) {
        FontRenderContext frc = new FontRenderContext(null, true, true);
        GlyphVector gv = f.createGlyphVector(frc, codes);
        g.drawGlyphVector(gv, 5, y);
   } else {
       g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                          RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
       g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
                          RenderingHints.VALUE_FRACTIONALMETRICS_ON);
       g.drawString(str, x, y);
   }
   return bi;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:26,代码来源:HelvLtOblTest.java

示例3: runTest

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    Graphics2D g2d = gvctx.g2d;
    GlyphVector gv = gvctx.gv;
    do {
        g2d.drawGlyphVector(gv, 40, 40);
    } while (--numReps >= 0);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:9,代码来源:TextRenderTests.java

示例4: writeImage

import java.awt.Graphics2D; //导入方法依赖的package包/类
public static void writeImage(File fontFile, File outputFile, String value) throws Exception {
    BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = image.createGraphics();
    g.setColor(Color.WHITE);
    g.fillRect(0, 0, image.getWidth(), image.getHeight());
    g.setColor(Color.BLACK);

    Font font = Font.createFont(Font.TRUETYPE_FONT, fontFile);
    font = font.deriveFont(Font.PLAIN, 72f);
    FontRenderContext frc = new FontRenderContext(null, false, false);
    GlyphVector gv = font.createGlyphVector(frc, value);
    g.drawGlyphVector(gv, 10, 80);
    g.fill(gv.getOutline(10, 180));
    ImageIO.write(image, "png", outputFile);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:GlyphVectorOutline.java

示例5: modeSpecificDrawLine

import java.awt.Graphics2D; //导入方法依赖的package包/类
private void modeSpecificDrawLine( Graphics2D g2, String line,
                                   int baseX, int baseY ) {
    /// ABP - keep track of old tform, restore it later
    AffineTransform oldTx = null;
    oldTx = g2.getTransform();
    g2.translate( baseX, baseY );
    g2.transform( getAffineTransform( g2Transform ) );

    switch ( drawMethod ) {
      case DRAW_STRING:
        g2.drawString( line, 0, 0 );
        break;
      case DRAW_CHARS:
        g2.drawChars( line.toCharArray(), 0, line.length(), 0, 0 );
        break;
      case DRAW_BYTES:
        try {
            byte lineBytes[] = line.getBytes( "ISO-8859-1" );
            g2.drawBytes( lineBytes, 0, lineBytes.length, 0, 0 );
        }
        catch ( Exception e ) {
            e.printStackTrace();
        }
        break;
      case DRAW_GLYPHV:
        GlyphVector gv =
          testFont.createGlyphVector( g2.getFontRenderContext(), line );
        g2.drawGlyphVector( gv, (float) 0, (float) 0 );
        break;
      case TL_DRAW:
        TextLayout tl = new TextLayout( line, testFont,
                                        g2.getFontRenderContext() );
        tl.draw( g2, (float) 0, (float) 0 );
        break;
      case GV_OUTLINE:
        GlyphVector gvo =
          testFont.createGlyphVector( g2.getFontRenderContext(), line );
        g2.draw( gvo.getOutline( (float) 0, (float) 0 ));
        break;
      case TL_OUTLINE:
        TextLayout tlo =
          new TextLayout( line, testFont,
                          g2.getFontRenderContext() );
        AffineTransform at = new AffineTransform();
        g2.draw( tlo.getOutline( at ));
    }

    /// ABP - restore old tform
    g2.setTransform ( oldTx );

}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:52,代码来源:FontPanel.java

示例6: handleDraw

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void handleDraw(Graphics2D g, float x, float y) {
  g.drawGlyphVector(getGV(), x, y);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:4,代码来源:ExtendedTextSourceLabel.java

示例7: draw

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void draw(Graphics2D g, float x, float y) {
  g.drawGlyphVector(getGV(), x, y);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:4,代码来源:TextSourceLabel.java

示例8: runTest

import java.awt.Graphics2D; //导入方法依赖的package包/类
private static void runTest() {
    im = new BufferedImage(W, H, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = im.createGraphics();
    g2d.setColor(Color.white);
    g2d.fillRect(0, 0, W, H);
    g2d.setColor(Color.black);
    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                         RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    char[] chs = "Sample Text.".toCharArray();
    int len = chs.length;

    int x = 50, y = 100;

    FontRenderContext frc = g2d.getFontRenderContext();
    Font plain = new Font("Serif", Font.PLAIN, 48);
    GlyphVector pgv = plain.layoutGlyphVector(frc, chs, 0, len, 0);
    g2d.setFont(plain);
    g2d.drawChars(chs, 0, len, x, y); y +=50;

    g2d.drawGlyphVector(pgv, x, y); y += 50;
    Rectangle2D plainStrBounds = plain.getStringBounds(chs, 0, len, frc);
    Rectangle2D plainGVBounds = pgv.getLogicalBounds();
    Font bold = new Font("Serif", Font.BOLD, 48);
    GlyphVector bgv = bold.layoutGlyphVector(frc, chs, 0, len, 0);
    Rectangle2D boldStrBounds = bold.getStringBounds(chs, 0, len, frc);
    Rectangle2D boldGVBounds = bgv.getLogicalBounds();
    g2d.setFont(bold);
    g2d.drawChars(chs, 0, len, x, y); y +=50;
    g2d.drawGlyphVector(bgv, x, y);
    System.out.println("Plain String Bounds = " + plainStrBounds);
    System.out.println("Bold String Bounds = " + boldStrBounds);
    System.out.println("Plain GlyphVector Bounds = " + plainGVBounds);
    System.out.println("Bold GlyphVector Bounds = " + boldGVBounds);
    if (!plainStrBounds.equals(boldStrBounds) &&
         plainGVBounds.equals(boldGVBounds))
    {
        System.out.println("Test failed: Plain GV bounds same as Bold");
        if (!interactive) {
            throw new RuntimeException("Plain GV bounds same as Bold");
        }
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:44,代码来源:StyledFontLayoutTest.java


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