Questions tagged [fontmetrics]

115 questions
113
votes
2 answers

Meaning of top, ascent, baseline, descent, bottom, and leading in Android's FontMetrics

This seems like a basic question, but I couldn't find a similar one on SO. While reading the documentation, I was having trouble grasping the concepts. I want to understand what the difference is between top and ascent and also bottom and descent.…
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
37
votes
2 answers

Java - FontMetrics without Graphics

How to get FontMetrics without use Graphics ? I want to get FontMetrics in constructor, now I do this way: BufferedImage bi = new BufferedImage(5, 5, BufferedImage.TYPE_INT_RGB); FontMetrics fm = bi.getGraphics().getFontMetrics(font); int width =…
piotrek
  • 1,333
  • 4
  • 17
  • 35
30
votes
2 answers

What does font-size really correspond to?

I am trying to find what the value set in the font-size CSS property is corresponding to. To give the context, I want to get in CSS the size in em of parts of the font (above the capital height and under the baseline) that I know from its OS/2…
ncoden
  • 869
  • 9
  • 24
20
votes
3 answers

Java: FontMetrics ascent incorrect?

When I look at the javadoc for FontMetric.getAscent() I see: The font ascent is the distance from the font's baseline to the top of most alphanumeric characters. Some characters in the Font might extend above the font ascent line. But I wrote a…
Jason S
  • 184,598
  • 164
  • 608
  • 970
17
votes
1 answer

Programmatically measure text string in pixels for Silverlight

In WPF there is the FormattedText in the System.Windows.Media namespace MSDN FormattedText that I can use like so: private static Size GetTextSize(string txt, string font, int size, bool isBold) { Typeface tf = new Typeface(new…
AlignedDev
  • 8,102
  • 9
  • 56
  • 91
14
votes
4 answers

String width via fontmetrics calculation is very slow if there are arabic or persian letters in text

I have a problem. My application interface works much slower if i use eastern languages there. Especially i felt it in components such as JList, JCombobox, JTable. How i found the performance of FontMetrics.stringWidth method is very slow (500+…
Eugene Popovich
  • 3,343
  • 2
  • 30
  • 33
13
votes
4 answers

String length in pixels in Java

Is there a way to calculate the length of a string in pixels, given a certain java.awt.Font object, that does not use any GUI components?
APerson
  • 8,140
  • 8
  • 35
  • 49
12
votes
4 answers

Java: how do you find out the cap height and x-height of a font?

FontMetrics doesn't have getters for cap height and x-height of a font. How can I obtain these values? As far as cap height goes, there's no guarantee for a particular capital letter that the letter's ascent is the same as the cap height. (e.g. a…
Jason S
  • 184,598
  • 164
  • 608
  • 970
12
votes
1 answer

What is the difference between alphabetic and ideographic in Flutter's TextBaseline enum

The TextBaseline enum in Flutter has two options: alphabetic ideographic How do these values actually change the baseline?
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
11
votes
3 answers

Android: How to determine character index of a touch event's position in TextView?

I have a TextView with an OnTouchListener. What I want is the character index the user is pointing to when I get the MotionEvent. Is there any way to get to the underlying font metrics of the TextView?
Epaga
  • 38,231
  • 58
  • 157
  • 245
10
votes
2 answers

How to get ascender/descender and x height for a given font

I need to get a ascender/descender and x-height.. By using following code I can find the descender and the total height: descender_height = paint.descent(); total_height = descender_height - paint.ascent(); //ascender = ?; is this always equal to…
sinek
  • 2,458
  • 3
  • 33
  • 55
9
votes
2 answers

Get single glyph metrics (.net)

How can I get full information about single glyph from choosen font (for example Arial -> symbol "A") This picture describe what variables I need to find:
leavelllusion
  • 329
  • 5
  • 11
9
votes
4 answers

Java: Getting a font with a specific height in pixels

It’s easy to determine the rendered height of a font using FontMetrics, but what about the other way around? How can I obtain a font that will fit into a specific height in pixels? "Give me Verdana in a size that is 30 pixels high from ascender to…
Tony the Pony
  • 40,327
  • 71
  • 187
  • 281
9
votes
3 answers

Getting font metrics without GUI (console mode)

Let's say some images have to be generated by a Qt console program and that font metrics are needed by internal algorithms (they use the text width/height as input to compute the position where the drawing should occur). This program has to be…
gpalex
  • 826
  • 1
  • 11
  • 27
7
votes
2 answers

QFont doens't allow line spacing or leading to be set manually

I've been trying to find a way to change a font file's line spacing default value, using QFont, QFontMetrics or something like that. I'm using QPainter::drawText to draw some text in a bounding rectangle. It's strange that QFont allows for font…
Pedro Leal
  • 183
  • 1
  • 10
1
2 3 4 5 6 7 8