fontmetrics

Getting font metrics without GUI (console mode)

血红的双手。 提交于 2020-08-27 04:19:37
问题 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 runable on a Linux without any GUI (runlevel-3, basically a cluster without any display server). Problem: QFontMetrics are only available when running a Qt application in GUI mode. Any workaround to get string metrics without any display server ? 回答1:

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

允我心安 提交于 2020-03-05 03:22:05
问题 The TextBaseline enum in Flutter has two options: alphabetic ideographic How do these values actually change the baseline? I'm adding my answer below. 回答1: TextBaseline.alphabetic The alphabetic baseline is the line that the letters in alphabets like English sit on. Here is an example: You can see that the English letters sit nicely on the line, but it cuts through the Chinese characters. TextBaseline.ideographic When you use the ideographic option, though, the baseline is at the bottom of

Java: Friendlier way to get an instance of FontMetrics

半世苍凉 提交于 2019-12-29 07:15:11
问题 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

How to get linespacing of a TextView?

泄露秘密 提交于 2019-12-23 16:56:49
问题 Is there any way to get the linespacing of a TextView in Android ? I try to find fontMetrics of the Paint of the TextView and do like this: tv1.getPaint().getFontMetrics(pfm); float fontTop = pfm.top; float fontBottom = pfm.bottom; System.out.println("Line Space >> " + (fontBottom - fontTop)); But it seems that result is the same until I change font size of the TextView . So how can I get the linespacing of a TextView ? 回答1: Linespacing of TextView is textView.getPaint().getFontSpacing() *

FontMetrics not correct when run on android device. Simulator fine

岁酱吖の 提交于 2019-12-23 12:56:23
问题 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 on HTC Desire and Motorola Droid) It also works fine on my HTC Wildfire. Here are some screen shots from the simulators: However... I have tried this on HTC Desire, and I have had reports from users using Motorola Droid that the fonts are not

QFontMetrics returns inaccurate results

只谈情不闲聊 提交于 2019-12-23 10:52:57
问题 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 size of the leading string. I can't find something specific causing this. Here is one example: . This is my paint routine (a bit messy from all the trial and error trying to fix the issue): void custom_delegate::paint(QPainter* painter, const

QFontMetrics returns inaccurate results

≡放荡痞女 提交于 2019-12-23 10:52:26
问题 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 size of the leading string. I can't find something specific causing this. Here is one example: . This is my paint routine (a bit messy from all the trial and error trying to fix the issue): void custom_delegate::paint(QPainter* painter, const

Java: Getting a font with a specific height in pixels

烈酒焚心 提交于 2019-12-19 17:45:49
问题 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 descender." How do I ask Java for this? 回答1: Jen, I don't think there's a "direct" way to find a font by height; only an indirect way... by looping through the sizes, and testing the height of each is <= required height. If you're doing this once,

Java Graphics: Constructing FontMetrics from Font, without a Graphics2D

瘦欲@ 提交于 2019-12-19 10:53:06
问题 Known Given FontMetrics There is a protected constructor for FontMetrics from Font . Question: Given a Font object, is there a way to construct a FontMetrics object without going through Graphics2D.setFont , Graphics2D.getFontMetric() ? Context I'm playing with a TeX like rendering algorithm. I need to calculate bounding boxes & the such for various characters from a *.pfb file. I can construct a Font object from the *.pfb file. I need a FontMetrics object to get the ascent, descent, width.

String length in pixels in Java

巧了我就是萌 提交于 2019-12-19 05:17:06
问题 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? 回答1: that does not use any GUI components? It depends on what you mean here. I'm assuming you mean you want to do it without receiving a HeadlessException . The best way is with a BufferedImage . AFAIK, this won't throw a HeadlessException : Font font = ... ; BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); FontMetrics fm = img