當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。