Tabnine Logo
LineMetrics
Code IndexAdd Tabnine to your IDE (free)

How to use
LineMetrics
in
java.awt.font

Best Java code snippets using java.awt.font.LineMetrics (Showing top 20 results out of 540)

Refine searchRefine arrow

  • Font
  • Graphics2D
  • Rectangle2D
  • FontMetrics
origin: i2p/i2p.i2p

double getFontHeight(Font font) {
  LineMetrics lm = font.getLineMetrics(DUMMY_TEXT, gd.getFontRenderContext());
  return lm.getAscent() + lm.getDescent();
}
origin: geotools/geotools

/**
 * 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;
  }
}
origin: geotools/geotools

/**
 * Helper method that will draw the underline of a curved label using the context of the cursor.
 */
private void drawCurvedUnderline(
    LineInfo line,
    LineStringCursor cursor,
    double startOrdinate,
    boolean drawingHalo,
    LineMetrics metrics) {
  final float lineOffset = metrics.getUnderlineOffset() * 2;
  final float lineThickness = metrics.getUnderlineThickness();
  drawCurvedLine(line, cursor, startOrdinate, drawingHalo, lineOffset, lineThickness);
}
origin: JetBrains/ideavim

@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);
}
origin: geotools/geotools

/**
 * Helper method that will draw the underline of a curved label using the context of the cursor.
 */
private void drawCurvedStrikethrough(
    LineInfo line,
    LineStringCursor cursor,
    double startOrdinate,
    boolean drawingHalo,
    LineMetrics metrics) {
  final float lineOffset = metrics.getStrikethroughOffset();
  final float lineThickness = metrics.getStrikethroughThickness();
  drawCurvedLine(line, cursor, startOrdinate, drawingHalo, lineOffset, lineThickness);
}
origin: com.github.insubstantial/flamingo

Graphics2D g2d = (Graphics2D) g.create();
g2d.setComposite(AlphaComposite.SrcOver.derive(toPaintEnabled ? 1.0f
    : 0.5f));
Shape clip = g2d.getClip();
RoundRectangle2D.Double roundRect = new RoundRectangle2D.Double(rect.x,
    rect.y, rect.width - 1, rect.height - 1, 6, 6);
g2d.clip(roundRect);
buttonRendererPane.paintComponent(g2d, rendererButton, c, rect.x
    - rect.width / 2, rect.y - rect.height / 2, 2 * rect.width,
    "Button.foreground"));
Font font = UIManager.getFont("Button.font");
font = font.deriveFont(font.getSize() + 1.0f);
g2d.setFont(font);
int strWidth = g2d.getFontMetrics().stringWidth(keyTip);
g2d.translate(rect.x, rect.y);
LineMetrics lineMetrics = g2d.getFontMetrics().getLineMetrics(keyTip, g2d);
int strHeight = (int)lineMetrics.getHeight();
g2d.drawString(keyTip, (rect.width - strWidth + 1) / 2,
    (rect.height + strHeight) / 2
        - g2d.getFontMetrics().getDescent() + 1);
g2d.dispose();
origin: jfree/jfreechart

bounds = fm.getStringBounds(text, g2);
LineMetrics lm = fm.getFont().getLineMetrics(text,
    g2.getFontRenderContext());
bounds.setRect(bounds.getX(), bounds.getY(), bounds.getWidth(),
    lm.getHeight());
double width = fm.stringWidth(text);
double height = fm.getHeight();
bounds = new Rectangle2D.Double(0.0, -fm.getAscent(), width,
origin: com.synaptix/SynaptixWidget

private void paintNodeText(Graphics2D g2, String text, Font font, Color color, int x, int y, int height, int width, int widthMax) {
  String[] lignes = text.split("\\n");
  g2.setFont(font);
  g2.setColor(color);
  String text1 = widthMax != -1 ? Utils.getClippedText(lignes[0], g2.getFontMetrics(), widthMax) : lignes[0];
  Rectangle2D rectHaut = font.getStringBounds(text1, g2.getFontRenderContext());
  LineMetrics lmHaut = font.getLineMetrics(text1, g2.getFontRenderContext());
  g2.drawString(text1, (int) (x - rectHaut.getWidth() / 2), y - lmHaut.getDescent() - width / 2);
  if (lignes.length > 1) {
    String text2 = widthMax != -1 ? Utils.getClippedText(lignes[1], g2.getFontMetrics(), widthMax) : lignes[1];
    Rectangle2D rectBas = font.getStringBounds(text2, g2.getFontRenderContext());
    LineMetrics lmBas = font.getLineMetrics(text2, g2.getFontRenderContext());
    g2.drawString(text2, (int) (x - rectBas.getWidth() / 2), y + lmBas.getAscent() + width / 2);
  }
}
origin: stackoverflow.com

f = f.deriveFont(Size);
LineMetrics lm = f.getLineMetrics(Text, frc);
Rectangle2D r2d = f.getStringBounds(Text, frc);
BufferedImage img = new BufferedImage((int)Math.ceil(r2d.getWidth()), (int)Math.ceil(r2d.getHeight()), BufferedImage.TYPE_INT_ARGB);
g2d.setRenderingHints(RenderingProperties);
g2d.setBackground(Color.WHITE);
g2d.setColor(Color.BLACK);
g2d.clearRect(0, 0, img.getWidth(), img.getHeight());
g2d.setFont(f);
g2d.drawString(Text, 0, lm.getAscent());
g2d.dispose();
origin: org.bitbucket.goalhub.simpleide/jedit

private double paintFooter(Graphics2D gfx, double pageX, double pageY,
  double pageWidth, double pageHeight, int pageIndex,
  boolean actuallyPaint)
{
  String footerText = jEdit.getProperty("print.footerText",
    new Object[] { new Date(), Integer.valueOf(pageIndex + 1)});
  FontRenderContext frc = gfx.getFontRenderContext();
  lm = font.getLineMetrics(footerText,frc);
  Rectangle2D bounds = font.getStringBounds(footerText,frc);
  Rectangle2D footerBounds = new Rectangle2D.Double(
    pageX,pageY + pageHeight - bounds.getHeight(),
    pageWidth,bounds.getHeight());
  if(actuallyPaint)
  {
    gfx.setColor(footerColor);
    gfx.fill(footerBounds);
    gfx.setColor(footerTextColor);
    gfx.drawString(footerText,
      (float)(pageX + (pageWidth - bounds.getWidth()) / 2),
      (float)(pageY + pageHeight - bounds.getHeight()
      + lm.getAscent()));
  }
  return footerBounds.getHeight();
} //}}}
origin: pentaho/pentaho-reporting

protected void drawScaleValues( final Graphics2D g2, final Rectangle2D area ) {
 g2.setPaint( getScaleValuePaint() );
 final Font valueFont = getScaleValueFont();
 if ( valueFont != null ) {
  g2.setFont( valueFont );
 } else if ( styleSheet != null ) {
  final String fontName = (String) styleSheet.getStyleProperty( TextStyleKeys.FONT );
   style |= Font.ITALIC;
  g2.setFont( new Font( fontName, style, fontSize ) );
 final FontMetrics fm = g2.getFontMetrics( f );
 final FontRenderContext frc = g2.getFontRenderContext();
 final double y = area.getCenterY();
   final Rectangle2D bounds = fm.getStringBounds( text, g2 );
   width = (float) bounds.getWidth();
  } else {
   width = fm.stringWidth( text );
  final LineMetrics metrics = f.getLineMetrics( text, frc );
  final float descent = metrics.getDescent();
  final float leading = metrics.getLeading();
  final float yAdj = -descent - leading + (float) ( metrics.getHeight() / 2.0 );
  final float xAdj = -width / 2.0f;
  g2.drawString( text, (float) ( x + xAdj ), (float) ( y + yAdj ) );
origin: com.synaptix/SynaptixWidget

  private void paintCenterString(Graphics g, String text, Font font, int x, int y, int width, int height) {
    if (text != null && !text.isEmpty()) {
      Graphics2D g2 = (Graphics2D) g.create(x, y, width, height);
      g2.setFont(font);
      String t = Utils.getClippedText(text, g2.getFontMetrics(), width);
      Rectangle2D rect2 = font.getStringBounds(t, g2.getFontRenderContext());
      LineMetrics lm = font.getLineMetrics(t, g2.getFontRenderContext());
      final int x2 = (int) (width - rect2.getWidth()) / 2;
      final float y2 = height / 2 + lm.getAscent() / 2;
      g2.drawString(t, x2, y2);
      g2.dispose();
    }
  }
}
origin: edu.toronto.cs.medsavant/medsavant-client

Font font = new Font(FontFactory.getGeneralFont().getFamily(),Font.PLAIN, 1);
g2.setFont(font);
FontMetrics fm = g2.getFontMetrics();
FontRenderContext frc = g2.getFontRenderContext();
float height = font.getLineMetrics(hid, frc).getHeight();
float width = fm.stringWidth(hid);
float startX = (float) position.x - width/2;
float startY = (float) (position.y + size/2 + gap);
origin: mucommander/mucommander

@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());
}

origin: jfree/jfreechart

/**
 * A utility method that draws a string inside a rectangle.
 *
 * @param g2  the graphics device.
 * @param bounds  the rectangle.
 * @param font  the font.
 * @param text  the text.
 */
private void drawStringInRect(Graphics2D g2, Rectangle2D bounds, Font font,
               String text) {
  g2.setFont(font);
  FontMetrics fm = g2.getFontMetrics(font);
  Rectangle2D r = TextUtils.getTextBounds(text, g2, fm);
  double x = bounds.getX();
  if (r.getWidth() < bounds.getWidth()) {
    x = x + (bounds.getWidth() - r.getWidth()) / 2;
  }
  LineMetrics metrics = font.getLineMetrics(
    text, g2.getFontRenderContext()
  );
  g2.drawString(
    text, (float) x, (float) (bounds.getMaxY()
      - this.bottomInnerGap - metrics.getDescent())
  );
}
origin: org.netbeans.api/org-openide-awt

  f = new Font("Dialog", Font.PLAIN, fs); //NOI18N
dotWidth = g.getFontMetrics().charWidth('.'); //NOI18N
          x = origX;
          int lineHeight = g.getFontMetrics().getHeight();
          y += lineHeight;
          heightPainted += lineHeight;
        x = origX;
        int lineHeight = g.getFontMetrics().getHeight();
        y += (lineHeight + (lineHeight / 2));
        heightPainted = y + lineHeight;
  if (Utilities.isMac()) {
    r.setRect(r.getX(), r.getY(), (double)fm.stringWidth(new String(chars, pos, nextTag - pos + 1)), r.getHeight());
          int stPos = Math.round(lm.getStrikethroughOffset()) +
            g.getFont().getBaselineFor(chars[pos]) + 1;
          int stPos = Math.round(lm.getUnderlineOffset()) +
            g.getFont().getBaselineFor(chars[pos]) + 1;
origin: de.sciss/abc4j

public double render(Graphics2D g2) {
  double labelSize = (double)getMetrics().getTextFontWidth(ScoreElements.PART_LABEL, getText());
  Font previousFont = g2.getFont();
  Color previousColor = g2.getColor();
  setColor(g2, ScoreElements.PART_LABEL);
  Rectangle2D bb = getBoundingBox();
  g2.setFont(getTemplate().getTextFont(ScoreElements.PART_LABEL));
  float descent = g2.getFont().getLineMetrics(getText(), g2.getFontRenderContext())
    .getDescent();
  g2.drawString(getText(), (int)(bb.getCenterX() - labelSize/2),
      (int)(bb.getY() + bb.getHeight() - descent));
  g2.setFont(previousFont);
  g2.draw(bb);
  g2.setColor(previousColor);
  return getWidth();
}
origin: com.googlecode.blaisemath/blaise-graphics

@Override
public void render(AnchoredText text, AttributeSet style, Graphics2D canvas) {
  if (Strings.isNullOrEmpty(text.getText())) {
    return;
  }
  Font font = Styles.fontOf(style);       
  canvas.setFont(font);
  canvas.setColor(style.getColor(Styles.FILL));
  canvas.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
  FontRenderContext frc = canvas.getFontRenderContext();
  Anchor textAnchor = Styles.anchorOf(style, Anchor.SOUTHWEST);
  
  double lineHeight = font.getLineMetrics("", frc).getHeight();
  Rectangle2D bounds = boundingBox(text, style);  
  Point2D offset = style.getPoint(Styles.OFFSET, new Point());
  assert offset != null;
  double x0 = text.getX() + offset.getX();
  double y0 = bounds.getMaxY();
  for (String line : Lists.reverse(Arrays.asList(lines(text)))) {
    double wid = font.getStringBounds(line, frc).getWidth();
    double dx = textAnchor.getRectOffset(wid, 0).getX();
    canvas.drawString(line, (float)(x0+dx), (float) y0);
    y0 -= lineHeight;
  }
}
origin: dhale/jtk

public void paintToRect(Graphics2D g2d, int x, int y, int w, int h) {
 g2d = createGraphics(g2d,x,y,w,h);
 g2d.setRenderingHint(
  RenderingHints.KEY_ANTIALIASING,
  RenderingHints.VALUE_ANTIALIAS_ON);
 Font font = g2d.getFont();
 FontMetrics fm = g2d.getFontMetrics();
 FontRenderContext frc = g2d.getFontRenderContext();
 LineMetrics lm = font.getLineMetrics(text,frc);
 //int fh = round(lm.getHeight());
 //int fa = round(lm.getAscent());
 int fd = round(lm.getDescent());
 int wt = fm.stringWidth(text);
 int xt = max(0,(w-wt)/2);
 int yt = h-1-2*fd;
 g2d.drawString(text,xt,yt);
 g2d.dispose();
}
origin: mucommander/mucommander

@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());
}
java.awt.fontLineMetrics

Most used methods

  • getAscent
  • getDescent
  • getHeight
  • getLeading
  • getStrikethroughOffset
  • getUnderlineOffset
  • getStrikethroughThickness
  • getUnderlineThickness
  • getBaselineIndex
  • getBaselineOffsets
  • getNumChars
  • getNumChars

Popular in Java

  • Updating database using SQL prepared statement
  • getApplicationContext (Context)
  • setRequestProperty (URLConnection)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • TreeSet (java.util)
    TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support
  • BlockingQueue (java.util.concurrent)
    A java.util.Queue that additionally supports operations that wait for the queue to become non-empty
  • ConcurrentHashMap (java.util.concurrent)
    A plug-in replacement for JDK1.5 java.util.concurrent.ConcurrentHashMap. This version is based on or
  • ServletException (javax.servlet)
    Defines a general exception a servlet can throw when it encounters difficulty.
  • JOptionPane (javax.swing)
  • Get (org.apache.hadoop.hbase.client)
    Used to perform Get operations on a single row. To get everything for a row, instantiate a Get objec
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now