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


Java FontRenderContext类代码示例

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


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

示例1: updateIcons

import java.awt.font.FontRenderContext; //导入依赖的package包/类
public static void updateIcons(JTree tree) {
    Font defaultFont = UIManager.getFont("Tree.font");
    Font currentFont = tree.getFont();

    double newScale = (double)
            currentFont.getSize2D() / defaultFont.getSize2D();

    DefaultTreeCellRenderer renderer =
            (DefaultTreeCellRenderer) tree.getCellRenderer();
    renderer.setOpenIcon(
            scale(UIManager.getIcon("Tree.openIcon"), newScale, tree));
    renderer.setClosedIcon(
            scale(UIManager.getIcon("Tree.closedIcon"), newScale, tree));
    renderer.setLeafIcon(
            scale(UIManager.getIcon("Tree.leafIcon"), newScale, tree));

    Collection<Integer> iconSizes = Arrays.asList(
            renderer.getOpenIcon().getIconHeight(),
            renderer.getClosedIcon().getIconHeight(),
            renderer.getLeafIcon().getIconHeight());

    // Convert points to pixels
    Point2D p = new Point2D.Float(0, currentFont.getSize2D());
    FontRenderContext context =
            tree.getFontMetrics(currentFont).getFontRenderContext();
    context.getTransform().transform(p, p);
    int fontSizeInPixels = (int) Math.ceil(p.getY());

    tree.setRowHeight(
            Math.max(fontSizeInPixels, Collections.max(iconSizes) + 2));
}
 
开发者ID:phweda,项目名称:MFM,代码行数:32,代码来源:SwingUtils.java

示例2: main

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

示例3: paintComponent

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

示例4: createImage

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

示例5: getSizeForString

import java.awt.font.FontRenderContext; //导入依赖的package包/类
/**
 * Returns an <mxRectangle> with the size (width and height in pixels) of the given string.
 * 
 * @param text String whose size should be returned.
 * @param font Font to be used for the computation.
 */
public static mxRectangle getSizeForString(String text, Font font, double scale) {
  FontRenderContext frc = new FontRenderContext(null, false, false);
  font = font.deriveFont((float) (font.getSize2D() * scale));
  FontMetrics metrics = null;

  if (fontGraphics != null) {
    metrics = fontGraphics.getFontMetrics(font);
  }

  double lineHeight = mxConstants.LINESPACING;

  if (metrics != null) {
    lineHeight += metrics.getHeight();
  } else {
    lineHeight += font.getSize2D() * 1.27;
  }

  String[] lines = text.split("\n");

  Rectangle2D boundingBox = null;

  if (lines.length == 0) {
    boundingBox = font.getStringBounds("", frc);
  } else {
    for (int i = 0; i < lines.length; i++) {
      Rectangle2D bounds = font.getStringBounds(lines[i], frc);

      if (boundingBox == null) {
        boundingBox = bounds;
      } else {
        boundingBox.setFrame(0, 0, Math.max(boundingBox.getWidth(), bounds.getWidth()),
            boundingBox.getHeight() + lineHeight);
      }
    }
  }

  return new mxRectangle(boundingBox);
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:45,代码来源:mxUtils.java

示例6: test

import java.awt.font.FontRenderContext; //导入依赖的package包/类
static void test(int sz) {
     Font reg = new Font(name, Font.PLAIN, sz);
     Font bold = new Font(name, Font.BOLD, sz);
     //System.out.println("reg="+reg);
     //System.out.println("bold="+bold);
     FontRenderContext frc = new FontRenderContext(null, false, false);
     if (reg.getFontName(Locale.ENGLISH).equals(name) &&
         bold.getFontName(Locale.ENGLISH).equals(name)) {
         Rectangle2D rb = reg.getStringBounds(" ", frc);
         Rectangle2D bb = bold.getStringBounds(" ", frc);
         if (bb.getWidth() > rb.getWidth() + 1.01f) {
             System.err.println("reg="+reg+" bds = " + rb);
             System.err.println("bold="+bold+" bds = " + bb);
             throw new RuntimeException("Advance difference too great.");
         }
     } else {
         System.out.println("Skipping test because fonts aren't as expected");
     }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:StyledSpaceAdvance.java

示例7: pixellate

import java.awt.font.FontRenderContext; //导入依赖的package包/类
/**
 * !!! not used currently, but might be by getPixelbounds?
 */
public void pixellate(FontRenderContext renderFRC, Point2D loc, Point pxResult) {
    if (renderFRC == null) {
        renderFRC = frc;
    }

    // it is a total pain that you have to copy the transform.

    AffineTransform at = renderFRC.getTransform();
    at.transform(loc, loc);
    pxResult.x = (int)loc.getX(); // but must not behave oddly around zero
    pxResult.y = (int)loc.getY();
    loc.setLocation(pxResult.x, pxResult.y);
    try {
        at.inverseTransform(loc, loc);
    }
    catch (NoninvertibleTransformException e) {
        throw new IllegalArgumentException("must be able to invert frc transform");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:StandardGlyphVector.java

示例8: drawGlyphVector

import java.awt.font.FontRenderContext; //导入依赖的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:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:GlyphListPipe.java

示例9: measureText

import java.awt.font.FontRenderContext; //导入依赖的package包/类
static void measureText() {
    Font font = new Font(FONT, Font.PLAIN, 36);
    if (!font.getFamily(Locale.ENGLISH).equals(FONT)) {
        return;
    }
    FontRenderContext frc = new FontRenderContext(null, false, false);
    TextLayout tl1 = new TextLayout(STR1, font, frc);
    TextLayout tl2 = new TextLayout(STR2, font, frc);
    Rectangle r1 = tl1.getPixelBounds(frc, 0f, 0f);
    Rectangle r2 = tl2.getPixelBounds(frc, 0f, 0f);
    if (r1.height > r2.height) {
        System.out.println(font);
        System.out.println(r1);
        System.out.println(r2);
        throw new RuntimeException("BAD BOUNDS");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:ArabicDiacriticTest.java

示例10: drawText

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

示例11: getLineNumberWidth

import java.awt.font.FontRenderContext; //导入依赖的package包/类
protected int getLineNumberWidth() {
    int newWidth = 0;
    EditorUI eui = editorUI;
    if (eui != null) {
        /*
        Insets insets = eui.getLineNumberMargin();
        if (insets != null) {
            newWidth += insets.left + insets.right;
        }
         */
        JTextComponent tc = eui.getComponent();
        if (font != null && tc != null) {
            Graphics g;
            FontRenderContext frc;
            FontMetrics fm;
            if ((g = tc.getGraphics()) != null && (g instanceof Graphics2D) &&
                (frc = ((Graphics2D)g).getFontRenderContext()) != null)
            {
                newWidth += new TextLayout(String.valueOf(highestLineNumber), font, frc).getAdvance();
            } else if ((fm = getFontMetrics(font)) != null) {
                // Use FontMetrics.stringWidth() as best approximation
                newWidth += fm.stringWidth(String.valueOf(highestLineNumber));
            }
        }
    }
    
    return newWidth;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:GlyphGutter.java

示例12: main

import java.awt.font.FontRenderContext; //导入依赖的package包/类
public static void main(String[] args) {
    Font font = new Font("Tahoma", Font.PLAIN, 12);
    String text = "\ude00";
    FontRenderContext frc = new FontRenderContext(null, false, false);
    TextLayout layout = new TextLayout(text, font, frc);
    layout.getCaretShapes(0);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:MissingCodePointLayoutTest.java

示例13: getItalicAngle

import java.awt.font.FontRenderContext; //导入依赖的package包/类
private float getItalicAngle(FontRenderContext frc) {
    Object aa, fm;
    if (frc == null) {
        aa = RenderingHints.VALUE_TEXT_ANTIALIAS_OFF;
        fm = RenderingHints.VALUE_FRACTIONALMETRICS_OFF;
    } else {
        aa = frc.getAntiAliasingHint();
        fm = frc.getFractionalMetricsHint();
    }
    return getFont2D().getItalicAngle(this, identityTx, aa, fm);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:Font.java

示例14: TextLabelFactory

import java.awt.font.FontRenderContext; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:TextLabelFactory.java

示例15: paintComponent

import java.awt.font.FontRenderContext; //导入依赖的package包/类
@Override
protected void paintComponent(Graphics g) {
    atualizar();
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g2.setFont(FONT);
    FontRenderContext frc = g2.getFontRenderContext();
    TextLayout textLayout = new TextLayout(Integer.toString(value), FONT, frc);
    g2.setPaint(textColor);
    Shape outline = textLayout.getOutline(AffineTransform.getTranslateInstance(value < 10 ? 20 : type == SHIELD ? 10 : 14, 30));
    g2.fill(outline);
    g2.setPaint(BLACK);
    g2.draw(outline);
}
 
开发者ID:limagiran,项目名称:hearthstone,代码行数:16,代码来源:JLabelAtributos.java


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