类java.awt.font.FontRenderContext源码实例Demo

下面列出了怎么用java.awt.font.FontRenderContext的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: Autumn   文件: HeadIconUtil.java
/**
 * 创建图片
 * @param content 内容
 * @param font  字体
 * @param width 宽
 * @param height 高
 * @return
 */
private static BufferedImage createImage(String content, Font font, Integer width, Integer height){
    BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = (Graphics2D)bi.getGraphics();
    g2.setBackground(Color.blue);
    g2.clearRect(0, 0, width, height);
    g2.setPaint(Color.BLACK);

    FontRenderContext context = g2.getFontRenderContext();
    Rectangle2D bounds = font.getStringBounds(content, context);
    double x = (width - bounds.getWidth()) / 2;
    double y = (height - bounds.getHeight()) / 2;
    double ascent = - bounds.getY();
    double baseY = y + ascent;

    g2.drawString(content, (int)x, (int)baseY);

    return bi;
}
 
源代码2 项目: pumpernickel   文件: TextBlock.java
@Override
public synchronized void paint(Graphics2D g) {
	if (dirty)
		revalidate();
	FontRenderContext frc = createFontRenderContext();
	if (frc.isAntiAliased()) {
		g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
				RenderingHints.VALUE_ANTIALIAS_ON);
	} else {
		g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
				RenderingHints.VALUE_ANTIALIAS_OFF);
	}
	if (frc.usesFractionalMetrics()) {
		g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
				RenderingHints.VALUE_FRACTIONALMETRICS_ON);
	} else {
		g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
				RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
	}

	paintBackground(g, body);
	paintBorder(g, body);
	paintText(g, body);
}
 
源代码3 项目: jdk8u-dev-jdk   文件: GlyphListPipe.java
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();
}
 
源代码4 项目: jdk8u-jdk   文件: HelvLtOblTest.java
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);
}
 
源代码5 项目: Bytecoder   文件: StandardGlyphVector.java
public StandardGlyphVector(Font font, CharacterIterator iter, FontRenderContext frc) {
    int offset = iter.getBeginIndex();
    char[] text = new char [iter.getEndIndex() - offset];
    for(char c = iter.first();
        c != CharacterIterator.DONE;
        c = iter.next()) {
        text[iter.getIndex() - offset] = c;
    }
    init(font, text, 0, text.length, frc, UNINITIALIZED_FLAGS);
}
 
源代码6 项目: jdk8u-jdk   文件: TextConstructionTests.java
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);
}
 
源代码7 项目: openjdk-8-source   文件: StandardGlyphVector.java
public StandardGlyphVector(Font font, FontRenderContext frc, int[] glyphs, float[] positions,
                           int[] indices, int flags) {
    initGlyphVector(font, frc, glyphs, positions, indices, flags);

    // this code should go into layout
    float track = getTracking(font);
    if (track != 0) {
        track *= font.getSize2D();
        Point2D.Float trackPt = new Point2D.Float(track, 0); // advance delta
        if (font.isTransformed()) {
            AffineTransform at = font.getTransform();
            at.deltaTransform(trackPt, trackPt);
        }

        // how do we know its a base glyph
        // for now, it is if the natural advance of the glyph is non-zero
        Font2D f2d = FontUtilities.getFont2D(font);
        FontStrike strike = f2d.getStrike(font, frc);

        float[] deltas = { trackPt.x, trackPt.y };
        for (int j = 0; j < deltas.length; ++j) {
            float inc = deltas[j];
            if (inc != 0) {
                float delta = 0;
                for (int i = j, n = 0; n < glyphs.length; i += 2) {
                    if (strike.getGlyphAdvance(glyphs[n++]) != 0) { // might be an inadequate test
                        positions[i] += delta;
                        delta += inc;
                    }
                }
                positions[positions.length-2+j] += delta;
            }
        }
    }
}
 
源代码8 项目: TencentKona-8   文件: TextSourceLabel.java
protected GlyphVector createGV() {
  Font font = source.getFont();
  FontRenderContext frc = source.getFRC();
  int flags = source.getLayoutFlags();
  char[] context = source.getChars();
  int start = source.getStart();
  int length = source.getLength();

  GlyphLayout gl = GlyphLayout.get(null); // !!! no custom layout engines
  StandardGlyphVector gv = gl.layout(font, frc, context, start, length,
                                     flags, null); // ??? use textsource
  GlyphLayout.done(gl);

  return gv;
}
 
public void runTest(Object ctx, int numReps) {
    TCContext tcctx = (TCContext)ctx;
    final Font font = tcctx.font;
    final char[] chars = tcctx.chars1;
    final int start = 1;
    final int limit = chars.length - 1;
    final FontRenderContext frc = tcctx.frc;
    final int flags = tcctx.flags;
    GlyphVector gv;
    do {
        gv = font.layoutGlyphVector(frc, chars, start, limit, flags);
    } while (--numReps >= 0);
}
 
源代码10 项目: java-swing-tips   文件: MainPanel.java
@Override protected void paintComponent(Graphics g) {
  Graphics2D g2 = (Graphics2D) g.create();
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  g2.setPaint(Color.WHITE);
  g2.fillRect(0, 0, getWidth(), getHeight());

  String str = getCharacterString();

  FontRenderContext frc = g2.getFontRenderContext();
  Shape exShape = new TextLayout(str, ipaEx, frc).getOutline(null);
  Shape mjShape = new TextLayout(str, ipaMj, frc).getOutline(null);

  Rectangle2D b = exShape.getBounds2D();
  double cx = getWidth() / 2d - b.getCenterX();
  double cy = getHeight() / 2d - b.getCenterY();
  AffineTransform toCenterAtf = AffineTransform.getTranslateInstance(cx, cy);

  g2.setPaint(Color.YELLOW);
  g2.draw(toCenterAtf.createTransformedShape(b));

  Shape s1 = toCenterAtf.createTransformedShape(exShape);
  Shape s2 = toCenterAtf.createTransformedShape(mjShape);

  if (fontPaintFlag.contains(FontPaint.IPA_EX_MINCHO)) {
    g2.setPaint(Color.CYAN);
    g2.fill(s1);
  }
  if (fontPaintFlag.contains(FontPaint.IPA_MJ_MINCHO)) {
    g2.setPaint(Color.MAGENTA);
    g2.fill(s2);
  }
  if (fontPaintFlag.containsAll(EnumSet.allOf(FontPaint.class))) {
    g2.setClip(s1);
    g2.setPaint(Color.BLACK);
    g2.fill(s2);
  }
  g2.dispose();
}
 
源代码11 项目: openjdk-8-source   文件: StandardGlyphVector.java
/**
 * Utility used by getStandardGV.
 * Constructs a StandardGlyphVector from a generic glyph vector.
 * Do not call this from new contexts without considering the comment
 * about "userGlyphs".
 */
private StandardGlyphVector(GlyphVector gv, FontRenderContext frc) {
    this.font = gv.getFont();
    this.frc = frc;
    initFontData();

    int nGlyphs = gv.getNumGlyphs();
    this.userGlyphs = gv.getGlyphCodes(0, nGlyphs, null);
    if (gv instanceof StandardGlyphVector) {
        /* userGlyphs will be OK because this is a private constructor
         * and the returned instance is used only for rendering.
         * It's not constructable by user code, nor returned to the
         * application. So we know "userGlyphs" are valid as having
         * been either already validated or are the result of layout.
         */
        this.glyphs = userGlyphs;
    } else {
        this.glyphs = getValidatedGlyphs(this.userGlyphs);
    }
    this.flags = gv.getLayoutFlags() & FLAG_MASK;

    if ((flags & FLAG_HAS_POSITION_ADJUSTMENTS) != 0) {
        this.positions = gv.getGlyphPositions(0, nGlyphs + 1, null);
    }

    if ((flags & FLAG_COMPLEX_GLYPHS) != 0) {
        this.charIndices = gv.getGlyphCharIndices(0, nGlyphs, null);
    }

    if ((flags & FLAG_HAS_TRANSFORMS) != 0) {
        AffineTransform[] txs = new AffineTransform[nGlyphs]; // worst case
        for (int i = 0; i < nGlyphs; ++i) {
            txs[i] = gv.getGlyphTransform(i); // gv doesn't have getGlyphsTransforms
        }

        setGlyphTransforms(txs);
    }
}
 
源代码12 项目: openjdk-8   文件: TextConstructionTests.java
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);
}
 
源代码13 项目: openjdk-jdk9   文件: bug6302464.java
private static void testFontRenderingContext(Object aaHint) {

        JLabel label = new JLabel("Test");
        label.putClientProperty(KEY_TEXT_ANTIALIASING, aaHint);
        FontRenderContext frc = label.getFontMetrics(
                label.getFont()).getFontRenderContext();

        if (!aaHint.equals(frc.getAntiAliasingHint())) {
            throw new RuntimeException("Wrong aa hint in FontRenderContext");
        }
    }
 
源代码14 项目: astor   文件: NumberAxis.java
/**
 * Estimates the maximum width of the tick labels, assuming the specified
 * tick unit is used.
 * <P>
 * Rather than computing the string bounds of every tick on the axis, we
 * just look at two values: the lower bound and the upper bound for the
 * axis.  These two values will usually be representative.
 *
 * @param g2  the graphics device.
 * @param unit  the tick unit to use for calculation.
 *
 * @return The estimated maximum width of the tick labels.
 */
protected double estimateMaximumTickLabelWidth(Graphics2D g2,
                                               TickUnit unit) {

    RectangleInsets tickLabelInsets = getTickLabelInsets();
    double result = tickLabelInsets.getLeft() + tickLabelInsets.getRight();

    if (isVerticalTickLabels()) {
        // all tick labels have the same width (equal to the height of the
        // font)...
        FontRenderContext frc = g2.getFontRenderContext();
        LineMetrics lm = getTickLabelFont().getLineMetrics("0", frc);
        result += lm.getHeight();
    }
    else {
        // look at lower and upper bounds...
        FontMetrics fm = g2.getFontMetrics(getTickLabelFont());
        Range range = getRange();
        double lower = range.getLowerBound();
        double upper = range.getUpperBound();
        String lowerStr = "";
        String upperStr = "";
        NumberFormat formatter = getNumberFormatOverride();
        if (formatter != null) {
            lowerStr = formatter.format(lower);
            upperStr = formatter.format(upper);
        }
        else {
            lowerStr = unit.valueToString(lower);
            upperStr = unit.valueToString(upper);
        }
        double w1 = fm.stringWidth(lowerStr);
        double w2 = fm.stringWidth(upperStr);
        result += Math.max(w1, w2);
    }

    return result;

}
 
源代码15 项目: openjdk-jdk8u-backup   文件: FontDesignMetrics.java
private FontDesignMetrics(Font font, FontRenderContext frc) {
  super(font);
  this.font = font;
  this.frc = frc;

  this.isAntiAliased = frc.isAntiAliased();
  this.usesFractionalMetrics = frc.usesFractionalMetrics();

  frcTx = frc.getTransform();

  matrix = new double[4];
  initMatrixAndMetrics();

  initAdvCache();
}
 
源代码16 项目: ECG-Viewer   文件: NumberAxis.java
/**
 * Estimates the maximum width of the tick labels, assuming the specified
 * tick unit is used.
 * <P>
 * Rather than computing the string bounds of every tick on the axis, we
 * just look at two values: the lower bound and the upper bound for the
 * axis.  These two values will usually be representative.
 *
 * @param g2  the graphics device.
 * @param unit  the tick unit to use for calculation.
 *
 * @return The estimated maximum width of the tick labels.
 */
protected double estimateMaximumTickLabelWidth(Graphics2D g2,
                                               TickUnit unit) {

    RectangleInsets tickLabelInsets = getTickLabelInsets();
    double result = tickLabelInsets.getLeft() + tickLabelInsets.getRight();

    if (isVerticalTickLabels()) {
        // all tick labels have the same width (equal to the height of the
        // font)...
        FontRenderContext frc = g2.getFontRenderContext();
        LineMetrics lm = getTickLabelFont().getLineMetrics("0", frc);
        result += lm.getHeight();
    }
    else {
        // look at lower and upper bounds...
        FontMetrics fm = g2.getFontMetrics(getTickLabelFont());
        Range range = getRange();
        double lower = range.getLowerBound();
        double upper = range.getUpperBound();
        String lowerStr, upperStr;
        NumberFormat formatter = getNumberFormatOverride();
        if (formatter != null) {
            lowerStr = formatter.format(lower);
            upperStr = formatter.format(upper);
        }
        else {
            lowerStr = unit.valueToString(lower);
            upperStr = unit.valueToString(upper);
        }
        double w1 = fm.stringWidth(lowerStr);
        double w2 = fm.stringWidth(upperStr);
        result += Math.max(w1, w2);
    }

    return result;

}
 
源代码17 项目: openjdk-8   文件: StandardGlyphVector.java
/**
 * Utility used by getStandardGV.
 * Constructs a StandardGlyphVector from a generic glyph vector.
 * Do not call this from new contexts without considering the comment
 * about "userGlyphs".
 */
private StandardGlyphVector(GlyphVector gv, FontRenderContext frc) {
    this.font = gv.getFont();
    this.frc = frc;
    initFontData();

    int nGlyphs = gv.getNumGlyphs();
    this.userGlyphs = gv.getGlyphCodes(0, nGlyphs, null);
    if (gv instanceof StandardGlyphVector) {
        /* userGlyphs will be OK because this is a private constructor
         * and the returned instance is used only for rendering.
         * It's not constructable by user code, nor returned to the
         * application. So we know "userGlyphs" are valid as having
         * been either already validated or are the result of layout.
         */
        this.glyphs = userGlyphs;
    } else {
        this.glyphs = getValidatedGlyphs(this.userGlyphs);
    }
    this.flags = gv.getLayoutFlags() & FLAG_MASK;

    if ((flags & FLAG_HAS_POSITION_ADJUSTMENTS) != 0) {
        this.positions = gv.getGlyphPositions(0, nGlyphs + 1, null);
    }

    if ((flags & FLAG_COMPLEX_GLYPHS) != 0) {
        this.charIndices = gv.getGlyphCharIndices(0, nGlyphs, null);
    }

    if ((flags & FLAG_HAS_TRANSFORMS) != 0) {
        AffineTransform[] txs = new AffineTransform[nGlyphs]; // worst case
        for (int i = 0; i < nGlyphs; ++i) {
            txs[i] = gv.getGlyphTransform(i); // gv doesn't have getGlyphsTransforms
        }

        setGlyphTransforms(txs);
    }
}
 
源代码18 项目: jdk8u-jdk   文件: TextSourceLabel.java
protected GlyphVector createGV() {
  Font font = source.getFont();
  FontRenderContext frc = source.getFRC();
  int flags = source.getLayoutFlags();
  char[] context = source.getChars();
  int start = source.getStart();
  int length = source.getLength();

  GlyphLayout gl = GlyphLayout.get(null); // !!! no custom layout engines
  StandardGlyphVector gv = gl.layout(font, frc, context, start, length,
                                     flags, null); // ??? use textsource
  GlyphLayout.done(gl);

  return gv;
}
 
源代码19 项目: opensim-gui   文件: NumberAxis.java
/**
 * Estimates the maximum tick label height.
 * 
 * @param g2  the graphics device.
 * 
 * @return The maximum height.
 */
protected double estimateMaximumTickLabelHeight(Graphics2D g2) {

    RectangleInsets tickLabelInsets = getTickLabelInsets();
    double result = tickLabelInsets.getTop() + tickLabelInsets.getBottom();
    
    Font tickLabelFont = getTickLabelFont();
    FontRenderContext frc = g2.getFontRenderContext();
    result += tickLabelFont.getLineMetrics("123", frc).getHeight();
    return result;
    
}
 
源代码20 项目: openjdk-8   文件: OutlineTextRenderer.java
public void drawGlyphVector(SunGraphics2D g2d, GlyphVector gv,
                            float x, float y) {


    Shape s = gv.getOutline(x, y);
    int prevaaHint = - 1;
    FontRenderContext frc = gv.getFontRenderContext();
    boolean aa = frc.isAntiAliased();

    /* aa will be true if any AA mode has been specified.
     * ie for LCD and 'gasp' modes too.
     * We will check if 'gasp' has resolved AA to be "OFF", and
     * in all other cases (ie AA ON and all LCD modes) use AA outlines.
     */
    if (aa) {
        if (g2d.getGVFontInfo(gv.getFont(), frc).aaHint ==
            SunHints.INTVAL_TEXT_ANTIALIAS_OFF) {
            aa = false;
        }
    }

    if (aa && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) {
        prevaaHint = g2d.antialiasHint;
        g2d.antialiasHint =  SunHints.INTVAL_ANTIALIAS_ON;
        g2d.validatePipe();
    } else if (!aa && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_OFF) {
        prevaaHint = g2d.antialiasHint;
        g2d.antialiasHint =  SunHints.INTVAL_ANTIALIAS_OFF;
        g2d.validatePipe();
    }

    g2d.fill(s);

    if (prevaaHint != -1) {
         g2d.antialiasHint = prevaaHint;
         g2d.validatePipe();
    }
}
 
源代码21 项目: swcv   文件: FontTests.java
private void drawTextInBox(Graphics2D g2, String text, Rectangle2D positionOnScreen)
{
    Font font = FontUtils.getFont();
    FontRenderContext frc = g2.getFontRenderContext();

    //bounding box of the word
    GlyphVector gv2 = font.layoutGlyphVector(frc, text.toCharArray(), 0, text.length(), Font.LAYOUT_LEFT_TO_RIGHT);
    Rectangle bb = gv2.getPixelBounds(frc, 0.0f, 0.0f);

    //find correct font size
    float scaleX = (float)(positionOnScreen.getWidth() / bb.getWidth());
    float scaleY = (float)(positionOnScreen.getHeight() / bb.getHeight());

    //get a new position for the text
    float x = (float)(positionOnScreen.getX() - bb.getX() * scaleX);
    float y = (float)(positionOnScreen.getY() - bb.getY() * scaleY);

    //preparing font
    AffineTransform at = new AffineTransform(scaleX, 0, 0, scaleY, 0, 0);
    Font deriveFont = font.deriveFont(at);
    g2.setFont(deriveFont);
    g2.setColor(Color.black);

    //draw the label
    GlyphVector gv = deriveFont.layoutGlyphVector(frc, text.toCharArray(), 0, text.length(), Font.LAYOUT_LEFT_TO_RIGHT);
    g2.drawGlyphVector(gv, x, y);
    g2.draw(positionOnScreen);
}
 
源代码22 项目: ccu-historian   文件: DateAxis.java
/**
 * Estimates the maximum width of the tick labels, assuming the specified
 * tick unit is used.
 * <P>
 * Rather than computing the string bounds of every tick on the axis, we
 * just look at two values: the lower bound and the upper bound for the
 * axis.  These two values will usually be representative.
 *
 * @param g2  the graphics device.
 * @param unit  the tick unit to use for calculation.
 *
 * @return The estimated maximum width of the tick labels.
 */
private double estimateMaximumTickLabelWidth(Graphics2D g2, 
        DateTickUnit unit) {

    RectangleInsets tickLabelInsets = getTickLabelInsets();
    double result = tickLabelInsets.getLeft() + tickLabelInsets.getRight();

    Font tickLabelFont = getTickLabelFont();
    FontRenderContext frc = g2.getFontRenderContext();
    LineMetrics lm = tickLabelFont.getLineMetrics("ABCxyz", frc);
    if (isVerticalTickLabels()) {
        // all tick labels have the same width (equal to the height of
        // the font)...
        result += lm.getHeight();
    }
    else {
        // look at lower and upper bounds...
        DateRange range = (DateRange) getRange();
        Date lower = range.getLowerDate();
        Date upper = range.getUpperDate();
        String lowerStr, upperStr;
        DateFormat formatter = getDateFormatOverride();
        if (formatter != null) {
            lowerStr = formatter.format(lower);
            upperStr = formatter.format(upper);
        }
        else {
            lowerStr = unit.dateToString(lower);
            upperStr = unit.dateToString(upper);
        }
        FontMetrics fm = g2.getFontMetrics(tickLabelFont);
        double w1 = fm.stringWidth(lowerStr);
        double w2 = fm.stringWidth(upperStr);
        result += Math.max(w1, w2);
    }

    return result;

}
 
源代码23 项目: jdk8u60   文件: TextLabelFactory.java
/**
 * Initialize a factory to produce glyph arrays.
 * @param frc the FontRenderContext to use for the arrays to be produced.
 * @param text the text of the paragraph.
 * @param bidi the bidi information for the paragraph text, or null if the
 * entire text is left-to-right text.
 */
public TextLabelFactory(FontRenderContext frc,
                        char[] text,
                        Bidi bidi,
                        int flags) {
  this.frc = frc;
  this.text = text.clone();
  this.bidi = bidi;
  this.flags = flags;
  this.lineBidi = bidi;
  this.lineStart = 0;
  this.lineLimit = text.length;
}
 
源代码24 项目: jdk8u-dev-jdk   文件: StandardTextSource.java
/** Create a StandardTextSource whose context and source are all the text in the String. */
public StandardTextSource(String str,
                          int level,
                          int flags,
                          Font font,
                          FontRenderContext frc) {
  this(str.toCharArray(), 0, str.length(), 0, str.length(), level, flags, font, frc, null);
}
 
源代码25 项目: jdk8u-jdk   文件: StandardGlyphVector.java
public StandardGlyphVector(Font font, FontRenderContext frc, int[] glyphs, float[] positions,
                           int[] indices, int flags) {
    initGlyphVector(font, frc, glyphs, positions, indices, flags);

    // this code should go into layout
    float track = getTracking(font);
    if (track != 0) {
        track *= font.getSize2D();
        Point2D.Float trackPt = new Point2D.Float(track, 0); // advance delta
        if (font.isTransformed()) {
            AffineTransform at = font.getTransform();
            at.deltaTransform(trackPt, trackPt);
        }

        // how do we know its a base glyph
        // for now, it is if the natural advance of the glyph is non-zero
        Font2D f2d = FontUtilities.getFont2D(font);
        FontStrike strike = f2d.getStrike(font, frc);

        float[] deltas = { trackPt.x, trackPt.y };
        for (int j = 0; j < deltas.length; ++j) {
            float inc = deltas[j];
            if (inc != 0) {
                float delta = 0;
                for (int i = j, n = 0; n < glyphs.length; i += 2) {
                    if (strike.getGlyphAdvance(glyphs[n++]) != 0) { // might be an inadequate test
                        positions[i] += delta;
                        delta += inc;
                    }
                }
                positions[positions.length-2+j] += delta;
            }
        }
    }
}
 
public void runTest(Object ctx, int numReps) {
    TCContext tcctx = (TCContext)ctx;
    final Font font = tcctx.font;
    final char[] chars = tcctx.chars;
    final FontRenderContext frc = tcctx.frc;
    GlyphVector gv;
    do {
        gv = font.createGlyphVector(frc, chars);
    } while (--numReps >= 0);
}
 
源代码27 项目: jdk8u-dev-jdk   文件: Font2D.java
/**
 * The length of the metrics array must be >= 4.  This method will
 * store the following elements in that array before returning:
 *    metrics[0]: ascent
 *    metrics[1]: descent
 *    metrics[2]: leading
 *    metrics[3]: max advance
 */
public void getFontMetrics(Font font, FontRenderContext frc,
                           float metrics[]) {
    StrikeMetrics strikeMetrics = getStrike(font, frc).getFontMetrics();
    metrics[0] = strikeMetrics.getAscent();
    metrics[1] = strikeMetrics.getDescent();
    metrics[2] = strikeMetrics.getLeading();
    metrics[3] = strikeMetrics.getMaxAdvance();
}
 
private float computeStringWidth(int fragmentIndex, Font font) {
  String text = myFragments.get(fragmentIndex);
  if (StringUtil.isEmpty(text)) return 0;
  FontRenderContext fontRenderContext = getFontMetrics(font).getFontRenderContext();
  TextLayout layout = getTextLayout(fragmentIndex, font, fontRenderContext);
  if (layout != null) {
    return layout.getAdvance();
  }
  else {
    return (float)font.getStringBounds(text, fontRenderContext).getWidth();
  }
}
 
源代码29 项目: astor   文件: LogAxis.java
/**
 * Estimates the maximum tick label height.
 *
 * @param g2  the graphics device.
 *
 * @return The maximum height.
 *
 * @since 1.0.7
 */
protected double estimateMaximumTickLabelHeight(Graphics2D g2) {

    RectangleInsets tickLabelInsets = getTickLabelInsets();
    double result = tickLabelInsets.getTop() + tickLabelInsets.getBottom();

    Font tickLabelFont = getTickLabelFont();
    FontRenderContext frc = g2.getFontRenderContext();
    result += tickLabelFont.getLineMetrics("123", frc).getHeight();
    return result;

}
 
源代码30 项目: TencentKona-8   文件: StandardGlyphVector.java
private void init(Font font, char[] text, int start, int count,
                  FontRenderContext frc, int flags) {

    if (start < 0 || count < 0 || start + count > text.length) {
        throw new ArrayIndexOutOfBoundsException("start or count out of bounds");
    }

    this.font = font;
    this.frc = frc;
    this.flags = flags;

    if (getTracking(font) != 0) {
        addFlags(FLAG_HAS_POSITION_ADJUSTMENTS);
    }

    // !!! change mapper interface?
    if (start != 0) {
        char[] temp = new char[count];
        System.arraycopy(text, start, temp, 0, count);
        text = temp;
    }

    initFontData(); // sets up font2D

    // !!! no layout for now, should add checks
    // !!! need to support creating a StandardGlyphVector from a TextMeasurer's info...
    glyphs = new int[count]; // hmmm
    /* Glyphs obtained here are already validated by the font */
    userGlyphs = glyphs;
    font2D.getMapper().charsToGlyphs(count, text, glyphs);
}
 
 类所在包
 同包方法