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


Java GlyphVector类代码示例

本文整理汇总了Java中java.awt.font.GlyphVector的典型用法代码示例。如果您正苦于以下问题:Java GlyphVector类的具体用法?Java GlyphVector怎么用?Java GlyphVector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: initializeFont

import java.awt.font.GlyphVector; //导入依赖的package包/类
/**
 * Initialise the font to be used based on configuration
 * 
 * @param baseFont The AWT font to render
 * @param size The point size of the font to generated
 * @param bold True if the font should be rendered in bold typeface
 * @param italic True if the font should be rendered in bold typeface
 */
private void initializeFont(Font baseFont, int size, boolean bold, boolean italic) {
	Map attributes = baseFont.getAttributes();
	attributes.put(TextAttribute.SIZE, new Float(size));
	attributes.put(TextAttribute.WEIGHT, bold ? TextAttribute.WEIGHT_BOLD : TextAttribute.WEIGHT_REGULAR);
	attributes.put(TextAttribute.POSTURE, italic ? TextAttribute.POSTURE_OBLIQUE : TextAttribute.POSTURE_REGULAR);
	try {
		attributes.put(TextAttribute.class.getDeclaredField("KERNING").get(null), TextAttribute.class.getDeclaredField(
			"KERNING_ON").get(null));
	} catch (Exception ignored) {
	}
	font = baseFont.deriveFont(attributes);

	FontMetrics metrics = GlyphPage.getScratchGraphics().getFontMetrics(font);
	ascent = metrics.getAscent();
	descent = metrics.getDescent();
	leading = metrics.getLeading();
	
	// Determine width of space glyph (getGlyphPixelBounds gives a width of zero).
	char[] chars = " ".toCharArray();
	GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
	spaceWidth = vector.getGlyphLogicalBounds(0).getBounds().width;
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:31,代码来源:UnicodeFont.java

示例2: getGlyph

import java.awt.font.GlyphVector; //导入依赖的package包/类
/**
 * Returns the glyph for the specified codePoint. If the glyph does not exist yet, 
 * it is created and queued to be loaded.
 * 
 * @param glyphCode The code of the glyph to locate
 * @param codePoint The code point associated with the glyph
 * @param bounds The bounds of the glyph on the page
 * @param vector The vector the glyph is part of  
 * @param index The index of the glyph within the vector
 * @return The glyph requested
 */
private Glyph getGlyph (int glyphCode, int codePoint, Rectangle bounds, GlyphVector vector, int index) {
	if (glyphCode < 0 || glyphCode >= MAX_GLYPH_CODE) {
		// GlyphVector#getGlyphCode sometimes returns negative numbers on OS X.
		return new Glyph(codePoint, bounds, vector, index, this) {
			public boolean isMissing () {
				return true;
			}
		};
	}
	int pageIndex = glyphCode / PAGE_SIZE;
	int glyphIndex = glyphCode & (PAGE_SIZE - 1);
	Glyph glyph = null;
	Glyph[] page = glyphs[pageIndex];
	if (page != null) {
		glyph = page[glyphIndex];
		if (glyph != null) return glyph;
	} else
		page = glyphs[pageIndex] = new Glyph[PAGE_SIZE];
	// Add glyph so size information is available and queue it so its image can be loaded later.
	glyph = page[glyphIndex] = new Glyph(codePoint, bounds, vector, index, this);
	queuedGlyphs.add(glyph);
	return glyph;
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:35,代码来源:UnicodeFont.java

示例3: main

import java.awt.font.GlyphVector; //导入依赖的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

示例4: paintComponent

import java.awt.font.GlyphVector; //导入依赖的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:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:HelvLtOblTest.java

示例5: cacheVector

import java.awt.font.GlyphVector; //导入依赖的package包/类
private Rectangle cacheVector(GlyphVector vector) {
	/*
        * Compute the exact area that the rendered string will take up in the image buffer. Note that
        * the string will actually be drawn at a positive (x,y) offset from (0,0) to leave enough room
        * for the ascent above the baseline and to correct for a few glyphs that appear to have negative
        * horizontal bearing (e.g. U+0423 Cyrillic uppercase letter U on Windows 7).
        */
	final Rectangle vectorBounds = vector.getPixelBounds(fontContext, 0, 0);

	/* Enlage the stringImage if it is too small to store the entire rendered string */
	if (vectorBounds.width > stringImage.getWidth() || vectorBounds.height > stringImage.getHeight())
		allocateStringImage(Math.max(vectorBounds.width, stringImage.getWidth()),
				Math.max(vectorBounds.height, stringImage.getHeight()));

	/* Erase the upper-left corner where the string will get drawn*/
	stringGraphics.clearRect(0, 0, vectorBounds.width, vectorBounds.height);

	/* Draw string with opaque white color and baseline adjustment so the upper-left corner of the image is at (0,0) */
	stringGraphics.drawGlyphVector(vector, -vectorBounds.x, -vectorBounds.y);

	return vectorBounds;
}
 
开发者ID:ImpactDevelopment,项目名称:ClientAPI,代码行数:23,代码来源:FontCache.java

示例6: 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);
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:37,代码来源:ImageProducer.java

示例7: 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;
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:28,代码来源:UnicodeFont.java

示例8: drawGlyphVector

import java.awt.font.GlyphVector; //导入依赖的package包/类
public void drawGlyphVector(SunGraphics2D sg2d, GlyphVector g,
                            float x, float y)
{
    FontRenderContext frc = g.getFontRenderContext();
    FontInfo info = sg2d.getGVFontInfo(g.getFont(), frc);
    switch (info.aaHint) {
    case SunHints.INTVAL_TEXT_ANTIALIAS_OFF:
        super.drawGlyphVector(sg2d, g, x, y);
        return;
    case SunHints.INTVAL_TEXT_ANTIALIAS_ON:
         SurfaceData.aaTextRenderer.drawGlyphVector(sg2d, g, x, y);
        return;
    case SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HRGB:
    case SunHints.INTVAL_TEXT_ANTIALIAS_LCD_VRGB:
         SurfaceData.lcdTextRenderer.drawGlyphVector(sg2d, g, x, y);
        return;
    default:
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:X11TextRenderer.java

示例9: setFromGlyphVector

import java.awt.font.GlyphVector; //导入依赖的package包/类
public void setFromGlyphVector(FontInfo info, GlyphVector gv,
                               float x, float y) {
    this.x = x;
    this.y = y;
    this.lcdRGBOrder = info.lcdRGBOrder;
    this.lcdSubPixPos = info.lcdSubPixPos;
    /* A GV may be rendered in different Graphics. It is possible it is
     * used for one case where LCD text is available, and another where
     * it is not. Pass in the "info". to ensure get a suitable one.
     */
    StandardGlyphVector sgv = StandardGlyphVector.getStandardGV(gv, info);
    // call before ensureCapacity :-
    usePositions = sgv.needsPositions(info.devTx);
    len = sgv.getNumGlyphs();
    ensureCapacity(len);
    strikelist = sgv.setupGlyphImages(images,
                                      usePositions ? positions : null,
                                      info.devTx);
    glyphindex = -1;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:GlyphList.java

示例10: drawGlyphVector

import java.awt.font.GlyphVector; //导入依赖的package包/类
public void drawGlyphVector(SunGraphics2D sg2d, GlyphVector gv,
                            float x, float y)
{
    FontRenderContext frc = gv.getFontRenderContext();
    FontInfo info = sg2d.getGVFontInfo(gv.getFont(), frc);
    if (info.pixelHeight > OutlineTextRenderer.THRESHHOLD) {
        SurfaceData.outlineTextRenderer.drawGlyphVector(sg2d, gv, x, y);
        return;
    }
    if (sg2d.transformState >= SunGraphics2D.TRANSFORM_TRANSLATESCALE) {
        double origin[] = {x, y};
        sg2d.transform.transform(origin, 0, origin, 0, 1);
        x = (float) origin[0];
        y = (float) origin[1];
    } else {
        x += sg2d.transX; // don't use the glyph info origin, already in gv.
        y += sg2d.transY;
    }

    GlyphList gl = GlyphList.getInstance();
    gl.setFromGlyphVector(info, gv, x, y);
    drawGlyphList(sg2d, gl, info.aaHint);
    gl.dispose();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:GlyphListPipe.java

示例11: drawGlyphVector

import java.awt.font.GlyphVector; //导入依赖的package包/类
public void drawGlyphVector(GlyphVector gv, float x, float y)
{
    if (gv == null) {
        throw new NullPointerException("GlyphVector is null");
    }

    try {
        textpipe.drawGlyphVector(this, gv, x, y);
    } catch (InvalidPipeException e) {
        try {
            revalidateAll();
            textpipe.drawGlyphVector(this, gv, x, y);
        } catch (InvalidPipeException e2) {
            // Still catching the exception; we are not yet ready to
            // validate the surfaceData correctly.  Fail for now and
            // try again next time around.
        }
    } finally {
        surfaceData.markDirty();
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:SunGraphics2D.java

示例12: drawGlyphVector

import java.awt.font.GlyphVector; //导入依赖的package包/类
/**
 * Draws a GlyphVector.
 * The rendering attributes applied include the clip, transform,
 * paint or color, and composite attributes.  The GlyphVector specifies
 * individual glyphs from a Font.
 * @param g The GlyphVector to be drawn.
 * @param x,y The coordinates where the glyphs should be drawn.
 * @see #setPaint
 * @see java.awt.Graphics#setColor
 * @see #transform
 * @see #setTransform
 * @see #setComposite
 * @see #clip
 * @see #setClip
 */
public void drawGlyphVector(GlyphVector g,
                            float x,
                            float y) {

    /* We should not reach here if printingGlyphVector is already true.
     * Add an assert so this can be tested if need be.
     * But also ensure that we do at least render properly by filling
     * the outline.
     */
    if (printingGlyphVector) {
        assert !printingGlyphVector; // ie false.
        fill(g.getOutline(x, y));
        return;
    }

    try {
        printingGlyphVector = true;
        if (RasterPrinterJob.shapeTextProp ||
            !printedSimpleGlyphVector(g, x, y)) {
            fill(g.getOutline(x, y));
        }
    } finally {
        printingGlyphVector = false;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:41,代码来源:PathGraphics.java

示例13: 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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:PathGraphics.java

示例14: drawGlyphVector

import java.awt.font.GlyphVector; //导入依赖的package包/类
public void drawGlyphVector(SunGraphics2D sg2d, GlyphVector g,
                            float x, float y)
{
    FontRenderContext frc = g.getFontRenderContext();
    FontInfo info = sg2d.getGVFontInfo(g.getFont(), frc);
    switch (info.aaHint) {
    case SunHints.INTVAL_TEXT_ANTIALIAS_OFF:
        super.drawGlyphVector(sg2d, g, x, y);
        return;
    case SunHints.INTVAL_TEXT_ANTIALIAS_ON:
         sg2d.surfaceData.aaTextRenderer.drawGlyphVector(sg2d, g, x, y);
        return;
    case SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HRGB:
    case SunHints.INTVAL_TEXT_ANTIALIAS_LCD_VRGB:
         sg2d.surfaceData.lcdTextRenderer.drawGlyphVector(sg2d, g, x, y);
        return;
    default:
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:X11TextRenderer.java

示例15: runTest

import java.awt.font.GlyphVector; //导入依赖的package包/类
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    GlyphMetrics gm;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            gm = gv.getGlyphMetrics(i);
        }
    } while (--numReps >= 0);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:TextMeasureTests.java


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