@Override public void paint(@NotNull Inlay inlay, @NotNull Graphics g, @NotNull Rectangle targetRegion, @NotNull TextAttributes textAttributes) { Editor editor = inlay.getEditor(); FontMetrics fontMetrics = getFontMetrics(editor).metrics; LineMetrics lineMetrics = fontMetrics.getLineMetrics(text, g); g.setColor(JBColor.GRAY); g.setFont(fontMetrics.getFont()); g.drawString(text, 0, targetRegion.y + (int)(lineMetrics.getHeight() - lineMetrics.getDescent())); g.setColor(JBColor.LIGHT_GRAY); g.drawRect(targetRegion.x, targetRegion.y, targetRegion.width, targetRegion.height); }
/** * Vertical centering is not trivial, because visually we want centering on characters such as * a,m,e, and not centering on d,g whose center is affected by the full ascent or the full * descent. This method tries to computes the y anchor taking into account those. */ public double getLinePlacementYAnchor() { TextStyle2D textStyle = getLabel().getTextStyle(); LineMetrics lm = textStyle .getFont() .getLineMetrics(textStyle.getLabel(), graphics.getFontRenderContext()); // gracefully handle font size = 0 if (lm.getHeight() > 0) { return (Math.abs(lm.getStrikethroughOffset()) + lm.getDescent() + lm.getLeading()) / lm.getHeight(); } else { return 0; } }
@Override public double getLineHeight() { return lineMetrics().getHeight(); }
/** * Returns the height of the band. * * @param g2 the graphics device. * * @return The height of the band. */ public double getHeight(Graphics2D g2) { double result = 0.0; if (this.markers.size() > 0) { LineMetrics metrics = this.font.getLineMetrics( "123g", g2.getFontRenderContext() ); result = this.topOuterGap + this.topInnerGap + metrics.getHeight() + this.bottomInnerGap + this.bottomOuterGap; } return result; }
/** * Returns the height of the band. * * @param g2 the graphics device. * * @return The height of the band. */ public double getHeight(Graphics2D g2) { double result = 0.0; if (this.markers.size() > 0) { LineMetrics metrics = this.font.getLineMetrics( "123g", g2.getFontRenderContext() ); result = this.topOuterGap + this.topInnerGap + metrics.getHeight() + this.bottomInnerGap + this.bottomOuterGap; } return result; }
@Override protected final void paintComponent(Graphics g) { Graphics2D graphics = (Graphics2D) g; // paint the background of this item with lightGray color graphics.setColor(background); graphics.fillRect(0, 0, getWidth(), getHeight()); // draw message: graphics.setFont(FONT); graphics.setColor(foreground); graphics.drawString(getText(), X_AXIS_OFFSET, (int) graphics.getFontMetrics().getLineMetrics(this.getText(), graphics).getHeight()); }
/** * @param text * @param font * @param linePlacement */ public TextStroke( String text, Font font, LinePlacement linePlacement ) { this.text = text; this.font = font; this.linePlacement = linePlacement; frc = new FontRenderContext( null, false, false ); lineHeight = font.getLineMetrics( text, frc ).getHeight(); }
@Override protected final void paintComponent(Graphics g) { Graphics2D graphics = (Graphics2D) g; graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); // paint background image graphics.drawImage(getBackgroundImage(getWidth(), getHeight(), graphics, background, secondaryBackground), 0, 0, null); // draw text: graphics.setFont(FONT); graphics.setColor(foreground); graphics.drawString(getText(), X_AXIS_OFFSET, (int) graphics.getFontMetrics().getLineMetrics(this.getText(), graphics).getHeight()); }
@Override public void paintLabels(Graphics g) { Font oldFont = g.getFont(); Font font = NapkinUtil.currentTheme(slider).getTextFont(); g.setFont(font); textHeight = (int) (0.5f * font.getLineMetrics("0123456789", ((Graphics2D) g).getFontRenderContext()).getHeight() + 0.5f); super.paintLabels(g); g.setFont(oldFont); } }
@Override public Dimensions getPreferredSize() { Label label = (Label)getComponent(); String text = label.getText(); FontRenderContext fontRenderContext = Platform.getFontRenderContext(); int preferredWidth; if (text != null && text.length() > 0) { Rectangle2D stringBounds = font.getStringBounds(text, fontRenderContext); preferredWidth = (int)Math.ceil(stringBounds.getWidth()); } else { preferredWidth = 0; } preferredWidth += (padding.left + padding.right); LineMetrics lm = font.getLineMetrics("", fontRenderContext); int preferredHeight = (int)Math.ceil(lm.getHeight()) + (padding.top + padding.bottom); return new Dimensions(preferredWidth, preferredHeight); }
/** * Vertical centering is not trivial, because visually we want centering on * characters such as a,m,e, and not centering on d,g whose center is * affected by the full ascent or the full descent. This method tries to * computes the y anchor taking into account those. */ public double getLinePlacementYAnchor() { TextStyle2D textStyle = getLabel().getTextStyle(); LineMetrics lm = textStyle.getFont().getLineMetrics(textStyle.getLabel(), graphics.getFontRenderContext()); // gracefully handle font size = 0 if(lm.getHeight() > 0) return (Math.abs(lm.getStrikethroughOffset()) + lm.getDescent() + lm.getLeading()) / lm.getHeight(); else return 0; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
public RotatedTextIcon(int rotate, Font font, String text) { this.rotate = rotate; this.font = font; FontRenderContext fontRenderContext = new FontRenderContext(null,true,true); glyphs = font.createGlyphVector(fontRenderContext,text); width = (int)glyphs.getLogicalBounds().getWidth() + 4; //height = (int)glyphs.getLogicalBounds().getHeight(); LineMetrics lineMetrics = font.getLineMetrics(text,fontRenderContext); ascent = lineMetrics.getAscent(); height = (int)lineMetrics.getHeight(); renderHints = new RenderingHints( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); renderHints.put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); renderHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); } //}}}
public JavaFont(String fontName, int fontStyle, int fontSize) { super(fontName, fontStyle, fontSize); myFont = UIManager.getCachedJavaFont(fontName, fontStyle, fontSize); frc = new java.awt.font.FontRenderContext(null, true, false); java.awt.font.LineMetrics metrics = myFont.getLineMetrics("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopwrstuvwxyz0123456789", frc); height = metrics.getHeight(); ascent = metrics.getAscent(); leading = metrics.getLeading(); descent = metrics.getDescent(); } public MetaFont deriveFontSize(int newSize, UIManager uiLoader)
/** * Constructs a GVTLineMetrics object based on the specified line metrics. * * @param lineMetrics The lineMetrics object that this metrics object will * be based upon. */ public GVTLineMetrics(LineMetrics lineMetrics) { this.ascent = lineMetrics.getAscent(); this.baselineIndex = lineMetrics.getBaselineIndex(); this.baselineOffsets = lineMetrics.getBaselineOffsets(); this.descent = lineMetrics.getDescent(); this.height = lineMetrics.getHeight(); this.leading = lineMetrics.getLeading(); this.numChars = lineMetrics.getNumChars(); this.strikethroughOffset = lineMetrics.getStrikethroughOffset(); this.strikethroughThickness = lineMetrics.getStrikethroughThickness(); this.underlineOffset = lineMetrics.getUnderlineOffset(); this.underlineThickness = lineMetrics.getUnderlineThickness(); this.overlineOffset = -this.ascent; this.overlineThickness = this.underlineThickness; }
/** * Constructs a GVTLineMetrics object based on the specified line metrics. * * @param lineMetrics The lineMetrics object that this metrics object will * be based upon. */ public GVTLineMetrics(LineMetrics lineMetrics) { this.ascent = lineMetrics.getAscent(); this.baselineIndex = lineMetrics.getBaselineIndex(); this.baselineOffsets = lineMetrics.getBaselineOffsets(); this.descent = lineMetrics.getDescent(); this.height = lineMetrics.getHeight(); this.leading = lineMetrics.getLeading(); this.numChars = lineMetrics.getNumChars(); this.strikethroughOffset = lineMetrics.getStrikethroughOffset(); this.strikethroughThickness = lineMetrics.getStrikethroughThickness(); this.underlineOffset = lineMetrics.getUnderlineOffset(); this.underlineThickness = lineMetrics.getUnderlineThickness(); this.overlineOffset = -this.ascent; this.overlineThickness = this.underlineThickness; }
/** * Constructs a GVTLineMetrics object based on the specified line metrics. * * @param lineMetrics The lineMetrics object that this metrics object will * be based upon. */ public GVTLineMetrics(LineMetrics lineMetrics) { this.ascent = lineMetrics.getAscent(); this.baselineIndex = lineMetrics.getBaselineIndex(); this.baselineOffsets = lineMetrics.getBaselineOffsets(); this.descent = lineMetrics.getDescent(); this.height = lineMetrics.getHeight(); this.leading = lineMetrics.getLeading(); this.numChars = lineMetrics.getNumChars(); this.strikethroughOffset = lineMetrics.getStrikethroughOffset(); this.strikethroughThickness = lineMetrics.getStrikethroughThickness(); this.underlineOffset = lineMetrics.getUnderlineOffset(); this.underlineThickness = lineMetrics.getUnderlineThickness(); this.overlineOffset = -this.ascent; this.overlineThickness = this.underlineThickness; }