fontmetrics

Java - FontMetrics without Graphics

与世无争的帅哥 提交于 2019-11-30 11:05:18
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 = fm.stringWidth(pattern); int height = fm.getHeight(); Hmm... It is quite logical that you need graphics to get FontMetrics. Font height, width etc. can differ on various displays. If you have some Component, you can use it for getting FontMetrics: component.getFontMetrics(font); No you do not necessarily need to get/use the graphics object: Font font

Java: FontMetrics ascent incorrect?

允我心安 提交于 2019-11-29 16:55:20
问题 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 quick demo program and I see this: where the 4 horizontal lines for each row of text are: baseline position lowered by getDescent() baseline position baseline position raised by getAscent() baseline position raised by getHeight() Notice the space

Java: Friendlier way to get an instance of FontMetrics

ε祈祈猫儿з 提交于 2019-11-29 08:02:18
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 of the screen you need fontmetrics. But, mostly, menuitems are clickable. So I create an array of Rectangles and all the rectangles fits around the items, so when the mouse is pressed, I can simply use for (int i = 0; i < rects.length; i++) if (rects[i].contains(mouseX, mouseY)) { ... } But to create the rects I also need FontMetrics for their

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

天涯浪子 提交于 2019-11-28 11:22:07
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 because the font metrics were wrong. The chart was originally configured to use the Source Sans Pro Regular font for that text, which supports only Latin character sets. The obvious solution is to bundle an actual Japanese .TTF font and ask JFreeChart to use it. This works fine, in that the output text uses the correct glyphs and it is also laid out

What does font-size really correspond to?

别等时光非礼了梦想. 提交于 2019-11-28 09:45:13
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 metrics. The em unit is relative to the given font-size and the OS/2 metrics are relative to the em-square. What I expect My expectations are based on the following references. I did not found anything more clear or precise. According to the W3C reference for font-size in CSS2.1 , and as quoted in all the Stack Overflow questions I found on the topic (

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

两盒软妹~` 提交于 2019-11-27 06:07:59
问题 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 because the font metrics were wrong. The chart was originally configured to use the Source Sans Pro Regular font for that text, which supports only Latin character sets. The obvious solution is to bundle an actual Japanese .TTF font and ask JFreeChart to

What does font-size really correspond to?

旧巷老猫 提交于 2019-11-26 16:49:43
问题 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 metrics. The em unit is relative to the given font-size and the OS/2 metrics are relative to the em-square. What I expect My expectations are based on the following references. I did not found anything more clear or precise. According to the W3C

Meaning of top, ascent, baseline, descent, bottom, and leading in Android&#39;s FontMetrics

試著忘記壹切 提交于 2019-11-26 12:39:53
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 . And where exactly is the baseline? Do you have a diagram to help me visualize it? Let's first review what the documentation says : Top - The maximum distance above the baseline for the tallest glyph in the font at a given text size. Ascent - The recommended distance above the baseline for singled spaced text. Descent - The recommended distance

Meaning of top, ascent, baseline, descent, bottom, and leading in Android&#39;s FontMetrics

我们两清 提交于 2019-11-26 03:01:54
问题 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 . And where exactly is the baseline? Do you have a diagram to help me visualize it? 回答1: Let's first review what the documentation says: Top - The maximum distance above the baseline for the tallest glyph in the font at a given text size. Ascent -