简体   繁体   English

Motif 如何计算或检索字体像素大小?

[英]Motif How to calculate or retrieve the font pixel size?

I am trying to write code in Motif to change a dialog warning box to resize size it if the box is not wide enough.我正在尝试在 Motif 中编写代码来更改对话框警告框以调整其大小,如果框不够宽。 The width and height is always being set by the calling classes and its not always wide enough for the message being displayed and the end of the line is truncated off.宽度和高度始终由调用类设置,并且它并不总是足够宽以显示消息并且行尾被截断。 Instead of fixing everywhere to use auto sizing (ie width is 0 or not set at all) they want to figure out what the pixel width size is for a character in the dialog.他们不想到处固定以使用自动调整大小(即宽度为 0 或根本不设置),而是想弄清楚对话框中字符的像素宽度大小是多少。 They can then multiple the longest line X pixels width to get the lines length in pixels.然后,他们可以乘以最长的线 X 像素宽度来获得以像素为单位的线长度。 Then we would see if the dialog declared width needs to be reset to stop the truncation.然后我们将查看是否需要重置对话框声明的宽度以停止截断。 Only dialogs that are too short will be changed (dialogs too wide are not to be changed).只有太短的对话框才会被更改(太宽的对话框不会被更改)。

However;然而; I can't find any example on how get the character width in pixels anywhere.我找不到任何关于如何在任何地方获取以像素为单位的字符宽度的示例。 I remember years ago I was on a project where they created some type of widget, inserted a character into it, and then did a XtGetValues to get the width and height so I think it can be done.我记得几年前我在一个项目中,他们创建了某种类型的小部件,在其中插入一个字符,然后执行 XtGetValues 来获取宽度和高度,所以我认为可以完成。 So does anyone know how to do this?那么有人知道该怎么做吗?

That was a long time ago, but if memory serves, Xt doesn't have any specific support for fonts, it relies on plain libx11.那是很久以前的事了,但是如果 memory 服务,Xt 对 fonts 没有任何具体的支持,它依赖于普通的 libx11。 You will need to call XQueryFont or XLoadQueryFont to get the XFontStruct describing your font, then grovel through the per_char array to find the extents of individual glyphs.您将需要调用XQueryFontXLoadQueryFont来获取描述字体的XFontStruct ,然后通过per_char数组查找单个字形的范围。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM