Questions tagged [fontmetrics]

115 questions
7
votes
1 answer

QFontMetrics returns inaccurate results

I have a custom delegate in my QTableWidget to hightlight matches if a user searches something. Unfortunately the rectangle position does often not really fit This happens on some characters or phrases or depending on the number of matches or the…
Bowdzone
  • 3,827
  • 11
  • 39
  • 52
7
votes
2 answers

Why does a Latin-characters-only Java font claim to support Asian characters, even though it does not?

When rendering a chart with JFreeChart, I noticed a layout problem when the chart's category labels included Japanese characters. Although the text is rendered with the correct glyphs, the text was positioned in the wrong location, presumably…
Scott Dudley
  • 3,256
  • 1
  • 18
  • 30
6
votes
2 answers

Measure the width of an AttributedString in J2ME

I'm writing code against the Java Personal Basis Profile in J2ME. I need to measure the width of an AttributedString in pixels. In Java SE, I'd get an AttributedCharacterIterator from my AttributedString and pass it to FontMetrics#getStringBounds,…
Dan Fabulich
  • 37,506
  • 41
  • 139
  • 175
5
votes
2 answers

What is the difference between FontMetrics.stringWidth() and FontMetrics.getStringBounds()?

I need to find the width of the text that is drawn on the screen. This thread suggests that the FontMetrics.stringWidth() will sometimes not be as accurate as FontMetrics.getStringBounds(). Does anyone know if this is correct, and if it is, in which…
Domchi
  • 10,705
  • 6
  • 54
  • 64
5
votes
3 answers

Getting FontMetrics StackOverflowError

Running the following code: import java.awt.Font; import java.awt.FontMetrics; public class MetricsTest { public static void main(String[] args) { Font myFontTest=new Font("Arial", Font.PLAIN, 11); FontMetrics…
geo
  • 517
  • 1
  • 9
  • 28
5
votes
1 answer

Glyph width in Open Type font

I have MinionPro-Regular.otf file. I working with it's structure. I have found it have: Table 'hhea': reference on 1668 metrics in 'hmtx' table. Table 'hmtx': 1668 pairs of hMetrics('advanceWidth', 'leftSideBearing'). Table 'CFF ': 1429 glyph…
Ruben Kazumov
  • 3,803
  • 2
  • 26
  • 39
4
votes
3 answers

Java get font size given height

Is there a (neat) way, instead of getting the height of a particular font size, getting a font size of a particular font (SansSerif in this case) that produces a given height? I could of course loop through font sizes or use some form of binary…
Michael Berry
  • 70,193
  • 21
  • 157
  • 216
4
votes
1 answer

FontMetrics not correct when run on android device. Simulator fine

I have an Android App that dynamically scales text depending on the resolution of the android device. I have tested this code on all the predefined resolutions in the Android Simulator and my code works fine. (This includes the same resolutions as…
Sprooose
  • 504
  • 1
  • 6
  • 17
4
votes
0 answers

Strange behaviour calculating bounding box of text with degrees symbol

I am using matplotlib's Adobe Font Metrics interface to calculate the bounding box of various strings. Calculating the bounding boxes for '12' and '°' works well, but when calculating the bounding box for '12°' the size of the box seems far too…
tim-mccurrach
  • 6,395
  • 4
  • 23
  • 41
4
votes
7 answers

Java: Friendlier way to get an instance of FontMetrics

Is there a friendlier way to get an instance of FontMetrics than FontMetrics fm = Graphics.getFontMetrics(Font); I hate this way because of the following example: If you want to create in a game a menu and you want all the menuitems in the center…
Martijn Courteaux
  • 67,591
  • 47
  • 198
  • 287
4
votes
0 answers

List of possible causes / workarounds for broken font metrics in Java? Or do I have to switch to LaTeX?

I'm working on an application that I thought would be fairly simple / straightforward. All it does is render a string into a BufferedImage in a particular font (from a file, not installed on the system). I'm making some progress, but after several…
Samuel Dealey
  • 263
  • 1
  • 7
4
votes
1 answer

Drawing strings inscribed in a circle

I am aware of Java's drawString(String str, int x, int y) method; however, sometimes all I want is to label a circle with an appropriate string in the middle of it, given a font size (either in pts or in accordance to the circle's size). Is there an…
4
votes
1 answer

How to get line height for a font, like in JTextArea?

I need to get distance from baseline of one line to baseline to next text line, the same as it is laid out in JTextArea. For that, I have only a font with specified font size. My problem is that on font, I can only get LineMetrics or FontMetrics,…
Rogach
  • 26,050
  • 21
  • 93
  • 172
3
votes
2 answers

MFC string width without CDC

Is there any way to get the width of a string in pixels without using CDC or using a CDC not linked with a display. The class that needs to retrieve the string width does not inherit from CWnd in order to use CWnd::GetDC() and there is no way to…
cdyer
  • 1,220
  • 1
  • 12
  • 21
3
votes
3 answers

Which API returns the right font width in Java?

Which Font API of Java returns the right width? We use currently font.getStringBounds( "the string", frc ).getWidth(); This return the right values on images and display. But it is wrong on printing with Java SE 6. With Java 7 all is correct. The…
Horcrux7
  • 23,758
  • 21
  • 98
  • 156