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