Java Code Examples for java.awt.font.LineMetrics#getStrikethroughOffset()
The following examples show how to use
java.awt.font.LineMetrics#getStrikethroughOffset() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextPainter.java From Pixelitor with GNU General Public License v3.0 | 5 votes |
private Area createStrikeThroughShape(FontMetrics metrics, LineMetrics lineMetrics, float ascent) { float strikethroughOffset = lineMetrics.getStrikethroughOffset(); float strikethroughThickness = lineMetrics.getStrikethroughThickness(); Shape strikethroughShape = new Rectangle2D.Float( 0.0f, ascent + strikethroughOffset - strikethroughThickness / 2.0f, metrics.stringWidth(text), strikethroughThickness); return new Area(strikethroughShape); }
Example 2
Source File: FontMetricsCache.java From netbeans with Apache License 2.0 | 4 votes |
private synchronized void initStrikethrough(Graphics g) { LineMetrics lm = font.getLineMetrics("aAyY", ((Graphics2D)g).getFontRenderContext()); // NOI18N strikethroughOffset = lm.getStrikethroughOffset(); strikethroughThickness = lm.getStrikethroughThickness(); inited |= ST_INITED; }
Example 3
Source File: FontInfo.java From netbeans with Apache License 2.0 | 4 votes |
FontInfo(Font origFont, JTextComponent textComponent, FontRenderContext frc, float rowHeightCorrection, int textZoom) { renderFont = (textZoom != 0) ? new Font(origFont.getName(), origFont.getStyle(), Math.max(origFont.getSize() + textZoom, 1)) : origFont; char defaultChar = 'A'; String defaultCharText = String.valueOf(defaultChar); TextLayout defaultCharTextLayout = new TextLayout(defaultCharText, renderFont, frc); // NOI18N TextLayout rowHeightTextLayout = new TextLayout("A_|B", renderFont, frc); // Round the ascent to eliminate long mantissa without any visible effect on rendering. updateRowHeight(rowHeightTextLayout, rowHeightCorrection); /* We originally did Math.ceil() when setting charWidth, but this was the cause of NETBEANS-346, where the end-of-line marker (SimpleValueNames.TEXT_LIMIT_WIDTH) would appear in the wrong position due to rounding errors, and similar misalignments in tabs vs. spaces, on certain editor zoom levels. This was observed on Java 9 or above on both Windows and MacOS. Java 9 saw many changes in font metrics implementations, including a new font shaping engine (HarfBuzz) and fractional HiDPI support. Avoiding Math.ceil fixes the problem. The original Math.ceil was introduced by Miloslav Metelka on 2011-08-18, with a comment "Ceil fractions to whole numbers since this measure may be used for background rendering" in the commit titled "Improve AnnotationView performance" for the similarly titled BugZilla bug #201102. So the Math.ceil was intended to be an optimization rather than fixing a correctness bug, and it seems safe to remove it. */ charWidth = defaultCharTextLayout.getAdvance(); LineMetrics lineMetrics = renderFont.getLineMetrics(defaultCharText, frc); underlineAndStrike[0] = lineMetrics.getUnderlineOffset() * rowHeightCorrection; underlineAndStrike[1] = lineMetrics.getUnderlineThickness(); underlineAndStrike[2] = lineMetrics.getStrikethroughOffset() * rowHeightCorrection; underlineAndStrike[3] = lineMetrics.getStrikethroughThickness(); if (LOG.isLoggable(Level.FINE)) { FontMetrics fm = textComponent.getFontMetrics(origFont); // From original font LOG.fine("Orig Font=" + origFont + // NOI18N "\n " + this + ", charWidth=" + charWidth + ", textZoom=" + textZoom + // NOI18N "\n rowHeightCorrection=" + rowHeightCorrection + // NOI18N ", underlineO/T=" + underlineAndStrike[0] + "/" + underlineAndStrike[1] + // NOI18N ", strikethroughO/T=" + underlineAndStrike[2] + "/" + underlineAndStrike[3] + // NOI18N "\n FontMetrics (for comparison; without-RHC): fm-line-height=" + fm.getHeight() + // NOI18N ", fm-ascent,descent,leading=" + fm.getAscent() + "," + fm.getDescent() + "," + fm.getLeading() + // NOI18N "\n"); // NOI18N if (LOG.isLoggable(Level.FINEST)) { LOG.log(Level.FINEST, "FontInfo creation stacktrace", new Exception()); // NOI18N } } }