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


Java Font.createGlyphVector方法代码示例

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


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

示例1: createImage

import java.awt.Font; //导入方法依赖的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);
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:37,代码来源:ImageProducer.java

示例2: paintComponent

import java.awt.Font; //导入方法依赖的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

示例3: drawText

import java.awt.Font; //导入方法依赖的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

示例4: main

import java.awt.Font; //导入方法依赖的package包/类
public static void main(String[] args)
{
    Font defaultFont = new Font(null);
    FontRenderContext defaultFrc = new FontRenderContext(new AffineTransform(),
                                                         true, true);
    GlyphVector gv = defaultFont.createGlyphVector(defaultFrc, "test");

    //this causes the bounds to be cached
    //which is necessary to trigger the bug
    gv.getGlyphLogicalBounds(0);

    //this correctly gets the position of the overall advance
    Point2D glyphPosition = gv.getGlyphPosition(gv.getNumGlyphs());

    // this sets the position of the overall advance,
    // but also incorrectly tries to clear the bounds cache
    // of a specific glyph indexed by the glyphIndex parameter
    // even if the glyphIndex represents the overall advance
    // (i.e. if glyphIndex == getNumGlyphs())
    gv.setGlyphPosition(gv.getNumGlyphs(), glyphPosition);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:TestStandardGlyphVectorBug.java

示例5: drawString

import java.awt.Font; //导入方法依赖的package包/类
/** Draws the given string at (x,y) */
public void drawString(String text, int x, int y) {
	if (text.length() == 0)
		return;
	if (gr != null) {
		gr.drawString(text, x, y);
		return;
	}
	calc();
	Font font = (fontBoldness ? cachedBoldFont : cachedPlainFont);
	GlyphVector gv = font.createGlyphVector(new FontRenderContext(null, false, false), text);
	translate(x, y);
	draw(gv.getOutline(), true);
	translate(-x, -y);
}
 
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:16,代码来源:Artist.java

示例6: runTest

import java.awt.Font; //导入方法依赖的package包/类
public void runTest(Object ctx, int numReps) {
    TCContext tcctx = (TCContext)ctx;
    final Font font = tcctx.font;
    final String text = tcctx.text;
    final FontRenderContext frc = tcctx.frc;
    GlyphVector gv;
    do {
        gv = font.createGlyphVector(frc, text);
    } while (--numReps >= 0);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:11,代码来源:TextConstructionTests.java

示例7: drawString

import java.awt.Font; //导入方法依赖的package包/类
/** Draws the given string at (x,y) */
public void drawString(String text, int x, int y) {
    if (text.length()==0) return;
    if (gr!=null) { gr.drawString(text,x,y); return; }
    calc();
    Font font = (fontBoldness ? cachedBoldFont : cachedPlainFont);
    GlyphVector gv = font.createGlyphVector(new FontRenderContext(null,false,false), text);
    translate(x,y);
    draw(gv.getOutline(), true);
    translate(-x,-y);
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:12,代码来源:Artist.java

示例8: writeImage

import java.awt.Font; //导入方法依赖的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

示例9: runTest

import java.awt.Font; //导入方法依赖的package包/类
public void runTest(Object ctx, int numReps) {
    TCContext tcctx = (TCContext)ctx;
    final Font font = tcctx.font;
    final CharacterIterator ci = tcctx.ci;
    final FontRenderContext frc = tcctx.frc;
    GlyphVector gv;
    do {
        gv = font.createGlyphVector(frc, ci);
    } while (--numReps >= 0);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:TextConstructionTests.java

示例10: textOut

import java.awt.Font; //导入方法依赖的package包/类
private void textOut(String str,
                     Font font, PhysicalFont font2D,
                     FontRenderContext frc,
                     float deviceSize, int rotation, float awScale,
                     AffineTransform deviceTransform,
                     double scaleFactorX,
                     float userx, float usery,
                     float devx, float devy, float targetW) {

    String family = font2D.getFamilyName(null);
    int style = font.getStyle() | font2D.getStyle();
    WPrinterJob wPrinterJob = (WPrinterJob)getPrinterJob();
    boolean setFont = wPrinterJob.setFont(family, deviceSize, style,
                                          rotation, awScale);
    if (!setFont) {
        super.drawString(str, userx, usery, font, frc, targetW);
        return;
    }

    float[] glyphPos = null;
    if (!okGDIMetrics(str, font, frc, scaleFactorX)) {
        /* If there is a 1:1 char->glyph mapping then char positions
         * are the same as glyph positions and we can tell GDI
         * where to place the glyphs.
         * On drawing we remove control chars so these need to be
         * removed now so the string and positions are the same length.
         * For other cases we need to pass glyph codes to GDI.
         */
        str = wPrinterJob.removeControlChars(str);
        char[] chars = str.toCharArray();
        int len = chars.length;
        GlyphVector gv = null;
        if (!FontUtilities.isComplexText(chars, 0, len)) {
            gv = font.createGlyphVector(frc, str);
        }
        if (gv == null) {
            super.drawString(str, userx, usery, font, frc, targetW);
            return;
        }
        glyphPos = gv.getGlyphPositions(0, len, null);
        Point2D gvAdvPt = gv.getGlyphPosition(gv.getNumGlyphs());

        /* GDI advances must not include device space rotation.
         * See earlier comment in printGlyphVector() for details.
         */
        AffineTransform advanceTransform =
          new AffineTransform(deviceTransform);
        advanceTransform.rotate(rotation*Math.PI/1800.0);
        float[] glyphAdvPos = new float[glyphPos.length];

        advanceTransform.transform(glyphPos, 0,         //source
                                   glyphAdvPos, 0,      //destination
                                   glyphPos.length/2);  //num points
        glyphPos = glyphAdvPos;
    }
    wPrinterJob.textOut(str, devx, devy, glyphPos);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:58,代码来源:WPathGraphics.java

示例11: main

import java.awt.Font; //导入方法依赖的package包/类
public static void main(String[] args) {
    Locale.setDefault(Locale.US);

    // initialize j.u.l Looger:
    final Logger log = Logger.getLogger("sun.java2d.marlin");
    log.addHandler(new Handler() {
        @Override
        public void publish(LogRecord record) {
            Throwable th = record.getThrown();
            // detect any Throwable:
            if (th != null) {
                System.out.println("Test failed:\n" + record.getMessage());
                th.printStackTrace(System.out);

                throw new RuntimeException("Test failed: ", th);
            }
        }

        @Override
        public void flush() {
        }

        @Override
        public void close() throws SecurityException {
        }
    });

    log.info("TextClipErrorTest: start");

    // enable Marlin logging & internal checks:
    System.setProperty("sun.java2d.renderer.log", "true");
    System.setProperty("sun.java2d.renderer.useLogger", "true");
    System.setProperty("sun.java2d.renderer.doChecks", "true");

    BufferedImage image = new BufferedImage(256, 256,
                                            BufferedImage.TYPE_INT_ARGB);

    Graphics2D g2d = image.createGraphics();
    g2d.setColor(Color.red);
    try {
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                             RenderingHints.VALUE_ANTIALIAS_ON);

        Font font = g2d.getFont();
        FontRenderContext frc = new FontRenderContext(
            new AffineTransform(), true, true);

        g2d.setStroke(new BasicStroke(4.0f,
                                      BasicStroke.CAP_ROUND,
                                      BasicStroke.JOIN_ROUND));

        final Shape badShape;
        if (SERIALIZE) {
            final GlyphVector gv1 = font.createGlyphVector(frc, "\u00d6");
            final Shape textShape = gv1.getOutline();

            final AffineTransform at1 = AffineTransform.getTranslateInstance(
                -2091202.554154681, 5548.601436981691);
            badShape = at1.createTransformedShape(textShape);
            serializeShape(badShape);
        } else {
            badShape = deserializeShape();
        }

        g2d.draw(badShape);

        // Draw anything within bounds and it fails:
        g2d.draw(new Line2D.Double(10, 20, 30, 40));

        if (SAVE_IMAGE) {
            final File file = new File("TextClipErrorTest.png");
            System.out.println("Writing file: " + file.getAbsolutePath());
            ImageIO.write(image, "PNG", file);
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        g2d.dispose();
        log.info("TextClipErrorTest: end");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:82,代码来源:TextClipErrorTest.java

示例12: textOut

import java.awt.Font; //导入方法依赖的package包/类
private void textOut(String str,
                     Font font, PhysicalFont font2D,
                     FontRenderContext frc,
                     float deviceSize, int rotation, float awScale,
                     double scaleFactorX, double scaleFactorY,
                     float userx, float usery,
                     float devx, float devy, float targetW) {

    String family = font2D.getFamilyName(null);
    int style = font.getStyle() | font2D.getStyle();
    WPrinterJob wPrinterJob = (WPrinterJob)getPrinterJob();
    boolean setFont = wPrinterJob.setFont(family, deviceSize, style,
                                          rotation, awScale);
    if (!setFont) {
        super.drawString(str, userx, usery, font, frc, targetW);
        return;
    }

    float[] glyphPos = null;
    if (!okGDIMetrics(str, font, frc, scaleFactorX)) {
        /* If there is a 1:1 char->glyph mapping then char positions
         * are the same as glyph positions and we can tell GDI
         * where to place the glyphs.
         * On drawing we remove control chars so these need to be
         * removed now so the string and positions are the same length.
         * For other cases we need to pass glyph codes to GDI.
         */
        str = wPrinterJob.removeControlChars(str);
        char[] chars = str.toCharArray();
        int len = chars.length;
        GlyphVector gv = null;
        if (!FontUtilities.isComplexText(chars, 0, len)) {
            gv = font.createGlyphVector(frc, str);
        }
        if (gv == null) {
            super.drawString(str, userx, usery, font, frc, targetW);
            return;
        }
        glyphPos = gv.getGlyphPositions(0, len, null);
        Point2D gvAdvPt = gv.getGlyphPosition(gv.getNumGlyphs());

        /* GDI advances must not include device space rotation.
         * See earlier comment in printGlyphVector() for details.
         */
        AffineTransform advanceTransform =
           AffineTransform.getScaleInstance(scaleFactorX, scaleFactorY);
        float[] glyphAdvPos = new float[glyphPos.length];

        advanceTransform.transform(glyphPos, 0,         //source
                                   glyphAdvPos, 0,      //destination
                                   glyphPos.length/2);  //num points
        glyphPos = glyphAdvPos;
    }
    wPrinterJob.textOut(str, devx, devy, glyphPos);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:56,代码来源:WPathGraphics.java


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