赞
踩
这是一个在屏幕上打印字符串的例子,但是例子整体结构有些变化,我们采用 while 是循环的方式来判断是否退出,而不是采用定时的方式,有个好处是,在while中重绘,可以在屏幕发生变化时,让我们的内容任然在屏幕上。
接下来看看这个循环怎么回事:
Atom wm_delete_window;
wm_delete_window =
XInternAtom (text_box.display, "WM_DELETE_WINDOW", False);
XSetWMProtocols (text_box.display, text_box.window, &wm_delete_window, 1);
while (1) { XEvent e; XNextEvent (text_box.display, & e); if (e.type == Expose) { draw_screen (); } /* Deal with a client message from the window manager telling us to delete the window. */ else if (e.type == ClientMessage) { printf ("Closed by the window manager.\n"); if ((Atom)e.xclient.data.l[0] == wm_delete_window) { break; } } }
恩恩,来看看具体打印字符串的步骤吧:
const char * fontname = "-*-helvetica-*-r-*-*-14-*-*-*-*-*-*-*";
text_box.font = XLoadQueryFont (text_box.display, fontname);
/* If the font could not be loaded, revert to the "fixed" font. */
if (! text_box.font) {
fprintf (stderr, "unable to load font %s: using fixed\n", fontname);
text_box.font = XLoadQueryFont (text_box.display, "fixed");
}
XSetFont (text_box.display, text_box.gc, text_box.font->fid);
3.获得8-bit 字符的打印信息。
XTextExtents (text_box.font, text_box.text, text_box.text_len,
& direction, & ascent, & descent, & overall);
参数中有 & 返回的信息,分别是:
参数 | 说明 |
---|---|
direction | 方向,有 FontLeftToRight 或者 FontRightToLeft |
ascent | 上升高度 |
descent | 下降高度,ascent - descent 应该就是该行 字高 |
overall | 一个 XCharStruct 的结构体,内部有该字符串的一些参数 |
另外16-bit的打印信息使用 XTextExtents16。
清空窗口,一般绘画都需要先清空。
XClearWindow (text_box.display, text_box.window);
绘画字符串
XDrawString (text_box.display, text_box.window, text_box.gc,
x, y, text_box.text, text_box.text_len);
XLoadQueryFont 采用的是 XLFD 格式
"-Foundry-FamilyName-WeightName- Slant-SetwidthName-AddStyleName- PixelSize- PointSize-ResolutionX-ResolutionY-Spacing- AverageWidth-CharSetRegistry- CharSetCoding"
一共有14个字段,看起来很复杂,其实就是描述字体的样式,下面看看每个字段的含义
特性字符串 | 定义 |
---|---|
Foundry | 标识字体设计者的字符串 |
FamilyName | 标识字体的注册商标名称的字符串 |
WeightName | 给出字体的相对磅值 (例如粗体) 的字符串 |
Slant | R (Roman-无倾斜) I (斜体-向右倾斜) O (倾斜-向右倾斜) RI (反转斜体-向左倾斜) RO (反转倾斜-向左倾斜) |
SetwidthName | 描述宽度 (例如压缩或扩展) 的字符串 |
AddStyleName | 提供唯一标识字体所需要的任何附加信息的字符串 |
PixelSize | 以像素为单位,给出 em-square 大小的整数 |
PointSize | 以小数点为单位,给出 em-square 大小的整数 |
ResolutionX | 以像素为单位,给出水平分辨率的整数 |
ResolutionY | 以像素为单位,给出垂直分辨率的整数 |
Spacing | 指定单元间的间隔的代码: M (等间隔–固定间距) P (比例间隔–变化间距) C (字符单元) |
AverageWidth | 以 1/10 个像素为单位,给出平均宽度的整数 |
CharSetRegistry | 标识已注册了字体编码的注册授权的字符串 |
CharSetEncoding | 在指定注册中标识字符集的字符串 |
参考:X 逻辑字体描述 (XLFD)
X logical font description
每个参数具体怎么得来的,目前还没有发现规律,插眼!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。