Search in sources :

Example 16 with FontRenderContext

use of java.awt.font.FontRenderContext in project bytecode-viewer by Konloch.

the class CodeSequenceDiagram method execute.

@Override
public void execute(ArrayList<ClassNode> classNodeList) {
    if (BytecodeViewer.viewer.workPane.getCurrentViewer() == null || !(BytecodeViewer.viewer.workPane.getCurrentViewer() instanceof ClassViewer)) {
        BytecodeViewer.showMessage("First open a class file.");
        return;
    }
    ClassNode c = BytecodeViewer.viewer.workPane.getCurrentViewer().cn;
    if (c == null) {
        BytecodeViewer.showMessage("ClassNode is null for CodeSequenceDiagram. Please report to @Konloch");
        return;
    }
    JFrame frame = null;
    if (c.name != null)
        frame = new JFrame("Code Sequence Diagram - " + c.name);
    else
        frame = new JFrame("Code Sequence Diagram - Unknown Name");
    frame.setIconImages(Resources.iconList);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.setSize(400, 320);
    mxGraph graph = new mxGraph();
    graph.setVertexLabelsMovable(false);
    graph.setGridEnabled(true);
    graph.setEnabled(false);
    graph.setCellsEditable(false);
    graph.setCellsSelectable(false);
    graph.setCellsMovable(false);
    graph.setCellsLocked(true);
    Object parent = graph.getDefaultParent();
    Font font = UIManager.getDefaults().getFont("TabbedPane.font");
    AffineTransform affinetransform = new AffineTransform();
    FontRenderContext frc = new FontRenderContext(affinetransform, true, true);
    graph.getModel().beginUpdate();
    try {
        int testX = 10;
        int testY = 0;
        double magicNumber = 5.8;
        for (MethodNode m : (ArrayList<MethodNode>) c.methods) {
            String mIdentifier = c.name + "." + m.name + m.desc;
            Object node = graph.insertVertex(parent, null, mIdentifier, testX, testY, mIdentifier.length() * magicNumber, 30);
            Object attach = node;
            testX += (int) (font.getStringBounds(mIdentifier, frc).getWidth()) + 60;
            for (AbstractInsnNode i : m.instructions.toArray()) {
                if (i instanceof MethodInsnNode) {
                    MethodInsnNode mi = (MethodInsnNode) i;
                    String identifier = mi.owner + "." + mi.name + mi.desc;
                    Object node2 = graph.insertVertex(parent, null, identifier, testX, testY, identifier.length() * 5, 30);
                    testX += (int) (font.getStringBounds(identifier, frc).getWidth()) + 60;
                    graph.insertEdge(parent, null, null, attach, node2);
                    attach = node2;
                }
            }
            testY += 60;
            testX = 10;
        }
    } finally {
        graph.getModel().endUpdate();
    }
    mxGraphComponent graphComponent = new mxGraphComponent(graph);
    frame.getContentPane().add(graphComponent);
    frame.setVisible(true);
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) ArrayList(java.util.ArrayList) com.mxgraph.view.mxGraph(com.mxgraph.view.mxGraph) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) MethodNode(org.objectweb.asm.tree.MethodNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) AffineTransform(java.awt.geom.AffineTransform) ClassViewer(the.bytecode.club.bytecodeviewer.gui.ClassViewer) FontRenderContext(java.awt.font.FontRenderContext) com.mxgraph.swing.mxGraphComponent(com.mxgraph.swing.mxGraphComponent)

Example 17 with FontRenderContext

use of java.awt.font.FontRenderContext in project poi by apache.

the class SLGraphics method getFontRenderContext.

/**
     * Get the rendering context of the <code>Font</code> within this
     * <code>Graphics2D</code> context.
     * The {@link FontRenderContext}
     * encapsulates application hints such as anti-aliasing and
     * fractional metrics, as well as target device specific information
     * such as dots-per-inch.  This information should be provided by the
     * application when using objects that perform typographical
     * formatting, such as <code>Font</code> and
     * <code>TextLayout</code>.  This information should also be provided
     * by applications that perform their own layout and need accurate
     * measurements of various characteristics of glyphs such as advance
     * and line height when various rendering hints have been applied to
     * the text rendering.
     *
     * @return a reference to an instance of FontRenderContext.
     * @see java.awt.font.FontRenderContext
     * @see java.awt.Font#createGlyphVector(FontRenderContext,char[])
     * @see java.awt.font.TextLayout
     * @since     JDK1.2
     */
public FontRenderContext getFontRenderContext() {
    boolean isAntiAliased = RenderingHints.VALUE_TEXT_ANTIALIAS_ON.equals(getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING));
    boolean usesFractionalMetrics = RenderingHints.VALUE_FRACTIONALMETRICS_ON.equals(getRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS));
    return new FontRenderContext(new AffineTransform(), isAntiAliased, usesFractionalMetrics);
}
Also used : AffineTransform(java.awt.geom.AffineTransform) FontRenderContext(java.awt.font.FontRenderContext)

Example 18 with FontRenderContext

use of java.awt.font.FontRenderContext in project poi by apache.

the class PPGraphics2D method getFontRenderContext.

/**
     * Get the rendering context of the <code>Font</code> within this
     * <code>Graphics2D</code> context.
     * The {@link FontRenderContext}
     * encapsulates application hints such as anti-aliasing and
     * fractional metrics, as well as target device specific information
     * such as dots-per-inch.  This information should be provided by the
     * application when using objects that perform typographical
     * formatting, such as <code>Font</code> and
     * <code>TextLayout</code>.  This information should also be provided
     * by applications that perform their own layout and need accurate
     * measurements of various characteristics of glyphs such as advance
     * and line height when various rendering hints have been applied to
     * the text rendering.
     *
     * @return a reference to an instance of FontRenderContext.
     * @see java.awt.font.FontRenderContext
     * @see java.awt.Font#createGlyphVector(FontRenderContext,char[])
     * @see java.awt.font.TextLayout
     * @since     JDK1.2
     */
public FontRenderContext getFontRenderContext() {
    boolean isAntiAliased = RenderingHints.VALUE_TEXT_ANTIALIAS_ON.equals(getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING));
    boolean usesFractionalMetrics = RenderingHints.VALUE_FRACTIONALMETRICS_ON.equals(getRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS));
    return new FontRenderContext(new AffineTransform(), isAntiAliased, usesFractionalMetrics);
}
Also used : AffineTransform(java.awt.geom.AffineTransform) FontRenderContext(java.awt.font.FontRenderContext)

Example 19 with FontRenderContext

use of java.awt.font.FontRenderContext in project poi by apache.

the class BaseTestBugzillaIssues method computeCellWidthManually.

// FIXME: this function is a self-fulfilling prophecy: this test will always pass as long
// as the code-under-test and the testcase code are written the same way (have the same bugs). 
private double computeCellWidthManually(Cell cell0, Font font) {
    final FontRenderContext fontRenderContext = new FontRenderContext(null, true, true);
    RichTextString rt = cell0.getRichStringCellValue();
    String[] lines = rt.getString().split("\\n");
    assertEquals(1, lines.length);
    String txt = lines[0] + "0";
    AttributedString str = new AttributedString(txt);
    copyAttributes(font, str, txt.length());
    // TODO: support rich text fragments
    /*if (rt.numFormattingRuns() > 0) {
        }*/
    TextLayout layout = new TextLayout(str.getIterator(), fontRenderContext);
    double frameWidth = getFrameWidth(layout);
    return ((frameWidth / 1) / 8);
}
Also used : AttributedString(java.text.AttributedString) FontRenderContext(java.awt.font.FontRenderContext) AttributedString(java.text.AttributedString) TextLayout(java.awt.font.TextLayout)

Example 20 with FontRenderContext

use of java.awt.font.FontRenderContext in project intellij-community by JetBrains.

the class TextPainter method calcNumbersStripWidth.

private double calcNumbersStripWidth(Graphics2D g, Rectangle2D clip) {
    if (!myPrintSettings.PRINT_LINE_NUMBERS) {
        return 0;
    }
    int maxLineNumber = myLineNumber + (int) (clip.getHeight() / getLineHeight(g));
    FontRenderContext fontRenderContext = (g).getFontRenderContext();
    double numbersStripWidth = 0;
    for (int i = myLineNumber; i < maxLineNumber; i++) {
        double width = myPlainFont.getStringBounds(String.valueOf(i), fontRenderContext).getWidth();
        if (numbersStripWidth < width) {
            numbersStripWidth = width;
        }
    }
    return numbersStripWidth;
}
Also used : FontRenderContext(java.awt.font.FontRenderContext)

Aggregations

FontRenderContext (java.awt.font.FontRenderContext)75 Font (java.awt.Font)25 TextLayout (java.awt.font.TextLayout)21 GlyphVector (java.awt.font.GlyphVector)18 Graphics2D (java.awt.Graphics2D)16 Rectangle2D (java.awt.geom.Rectangle2D)15 AttributedString (java.text.AttributedString)14 AffineTransform (java.awt.geom.AffineTransform)13 Paint (java.awt.Paint)8 LineBreakMeasurer (java.awt.font.LineBreakMeasurer)7 AttributedCharacterIterator (java.text.AttributedCharacterIterator)7 LineMetrics (java.awt.font.LineMetrics)5 BufferedImage (java.awt.image.BufferedImage)5 ArrayList (java.util.ArrayList)5 Point (java.awt.Point)4 Shape (java.awt.Shape)4 BasicStroke (java.awt.BasicStroke)3 Color (java.awt.Color)3 FontMetrics (java.awt.FontMetrics)3 RoundRectangle2D (java.awt.geom.RoundRectangle2D)3