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


Java GlyphVector.getLogicalBounds方法代码示例

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


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

示例1: runTest

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

示例2: getStringBounds

import java.awt.font.GlyphVector; //导入方法依赖的package包/类
/**
 * Returns the logical bounds of the specified array of characters
 * in the specified <code>FontRenderContext</code>.  The logical
 * bounds contains the origin, ascent, advance, and height, which
 * includes the leading.  The logical bounds does not always enclose
 * all the text.  For example, in some languages and in some fonts,
 * accent marks can be positioned above the ascent or below the
 * descent.  To obtain a visual bounding box, which encloses all the
 * text, use the {@link TextLayout#getBounds() getBounds} method of
 * <code>TextLayout</code>.
 * <p>Note: The returned bounds is in baseline-relative coordinates
 * (see {@link java.awt.Font class notes}).
 * @param chars an array of characters
 * @param beginIndex the initial offset in the array of
 * characters
 * @param limit the end offset in the array of characters
 * @param frc the specified <code>FontRenderContext</code>
 * @return a <code>Rectangle2D</code> that is the bounding box of the
 * specified array of characters in the specified
 * <code>FontRenderContext</code>.
 * @throws IndexOutOfBoundsException if <code>beginIndex</code> is
 *         less than zero, or <code>limit</code> is greater than the
 *         length of <code>chars</code>, or <code>beginIndex</code>
 *         is greater than <code>limit</code>.
 * @see FontRenderContext
 * @see Font#createGlyphVector
 * @since 1.2
 */
public Rectangle2D getStringBounds(char [] chars,
                                int beginIndex, int limit,
                                   FontRenderContext frc) {
    if (beginIndex < 0) {
        throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
    }
    if (limit > chars.length) {
        throw new IndexOutOfBoundsException("limit: " + limit);
    }
    if (beginIndex > limit) {
        throw new IndexOutOfBoundsException("range length: " +
                                            (limit - beginIndex));
    }

    // this code should be in textlayout
    // quick check for simple text, assume GV ok to use if simple

    boolean simple = values == null ||
        (values.getKerning() == 0 && values.getLigatures() == 0 &&
          values.getBaselineTransform() == null);
    if (simple) {
        simple = ! FontUtilities.isComplexText(chars, beginIndex, limit);
    }

    if (simple) {
        GlyphVector gv = new StandardGlyphVector(this, chars, beginIndex,
                                                 limit - beginIndex, frc);
        return gv.getLogicalBounds();
    } else {
        // need char array constructor on textlayout
        String str = new String(chars, beginIndex, limit - beginIndex);
        TextLayout tl = new TextLayout(str, this, frc);
        return new Rectangle2D.Float(0, -tl.getAscent(), tl.getAdvance(),
                                     tl.getAscent() + tl.getDescent() +
                                     tl.getLeading());
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:66,代码来源:Font.java

示例3: getStringBounds

import java.awt.font.GlyphVector; //导入方法依赖的package包/类
/**
 * Returns the logical bounds of the specified array of characters
 * in the specified {@code FontRenderContext}.  The logical
 * bounds contains the origin, ascent, advance, and height, which
 * includes the leading.  The logical bounds does not always enclose
 * all the text.  For example, in some languages and in some fonts,
 * accent marks can be positioned above the ascent or below the
 * descent.  To obtain a visual bounding box, which encloses all the
 * text, use the {@link TextLayout#getBounds() getBounds} method of
 * {@code TextLayout}.
 * <p>Note: The returned bounds is in baseline-relative coordinates
 * (see {@link java.awt.Font class notes}).
 * @param chars an array of characters
 * @param beginIndex the initial offset in the array of
 * characters
 * @param limit the end offset in the array of characters
 * @param frc the specified {@code FontRenderContext}
 * @return a {@code Rectangle2D} that is the bounding box of the
 * specified array of characters in the specified
 * {@code FontRenderContext}.
 * @throws IndexOutOfBoundsException if {@code beginIndex} is
 *         less than zero, or {@code limit} is greater than the
 *         length of {@code chars}, or {@code beginIndex}
 *         is greater than {@code limit}.
 * @see FontRenderContext
 * @see Font#createGlyphVector
 * @since 1.2
 */
public Rectangle2D getStringBounds(char [] chars,
                                int beginIndex, int limit,
                                   FontRenderContext frc) {
    if (beginIndex < 0) {
        throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
    }
    if (limit > chars.length) {
        throw new IndexOutOfBoundsException("limit: " + limit);
    }
    if (beginIndex > limit) {
        throw new IndexOutOfBoundsException("range length: " +
                                            (limit - beginIndex));
    }

    // this code should be in textlayout
    // quick check for simple text, assume GV ok to use if simple

    boolean simple = values == null ||
        (values.getKerning() == 0 && values.getLigatures() == 0 &&
          values.getBaselineTransform() == null);
    if (simple) {
        simple = ! FontUtilities.isComplexText(chars, beginIndex, limit);
    }

    if (simple) {
        GlyphVector gv = new StandardGlyphVector(this, chars, beginIndex,
                                                 limit - beginIndex, frc);
        return gv.getLogicalBounds();
    } else {
        // need char array constructor on textlayout
        String str = new String(chars, beginIndex, limit - beginIndex);
        TextLayout tl = new TextLayout(str, this, frc);
        return new Rectangle2D.Float(0, -tl.getAscent(), tl.getAdvance(),
                                     tl.getAscent() + tl.getDescent() +
                                     tl.getLeading());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:66,代码来源:Font.java

示例4: runTest

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

示例5: getSize

import java.awt.font.GlyphVector; //导入方法依赖的package包/类
public Vec2 getSize(String text)
{
    GlyphVector vector = font.createGlyphVector(frc, text);
    Rectangle2D bounds = vector.getLogicalBounds();
    return new Vec2((float)bounds.getWidth(), (float)bounds.getHeight());
}
 
开发者ID:SmashMaster,项目名称:KraftigAudio,代码行数:7,代码来源:VectorFont.java

示例6: render

import java.awt.font.GlyphVector; //导入方法依赖的package包/类
public void render(String text, Vec2 pos, float size, Alignment align)
{
    LineMetrics metrics = font.getLineMetrics(text, frc);
    GlyphVector vector = font.createGlyphVector(frc, text);
    Rectangle2D bounds = vector.getLogicalBounds();
    
    Vec2 rad = new Vec2((float)bounds.getWidth(), (float)bounds.getHeight()).mult(0.5f);
    
    GL11.glPushMatrix();
    GL11.glTranslatef(pos.x, pos.y, 0.0f);
    GL11.glScalef(size, -size, 0.0f);
    GL11.glTranslatef((align.x - 1.0f)*rad.x, (-align.y + 1.0f)*rad.y - metrics.getDescent(), 0.0f);
    
    float[] coords = new float[6];
    float loopX = 0.0f, loopY = 0.0f;
    float px = 0.0f, py = 0.0f;
    
    GL11.glBegin(GL11.GL_LINES);
    for (PathIterator path = vector.getOutline().getPathIterator(identity); !path.isDone(); path.next())
    {
        int code = path.currentSegment(coords);
        float x = coords[0], y = coords[1];
        
        switch (code)
        {
            case PathIterator.SEG_MOVETO: //End segment and move to a new position.
                px = x;
                py = y;
                loopX = x;
                loopY = y;
                break;
            default: //Draw line from previous to current.
                GL11.glVertex2f(px, py);
                GL11.glVertex2f(x, y);
                px = x;
                py = y;
                break;
            case PathIterator.SEG_CLOSE: //Draw line to close loop.
                GL11.glVertex2f(x, y);
                GL11.glVertex2f(loopX, loopY);
                px = 0.0f;
                py = 0.0f;
                loopX = 0.0f;
                loopY = 0.0f;
                break;
        }
    }
    GL11.glEnd();
    
    GL11.glPopMatrix();
}
 
开发者ID:SmashMaster,项目名称:KraftigAudio,代码行数:52,代码来源:VectorFont.java

示例7: 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) {

    Rectangle2D bbox = g.getLogicalBounds();
    addDrawingRect(bbox, x, y);
    mPrintMetrics.drawText(this);

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


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