如何指定不同方向的字体高度? [英] How do I specify font height at different orientations?

查看:272
本文介绍了如何指定不同方向的字体高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用GDI创建字体的常用方法是使用所需的点大小和目标设备的垂直分辨率(DPI),如下所示:

  LOGFONT lf = {0}; 
lf.lfHeight = -MulDiv(point_size,GetDeviceCaps(hdc,LOGPIXELSY),72);
...
HFONT hfont = CreateFontIndirect(& lf);

假设默认 MM_TEXT 映射模式,将point_size转换为所需设备的像素高度。 (这是一个常见的近似值,实际上一英寸有72.27个点,而不是72个。)(减号表示我想指定实际的字符高度,而不是单元格高度。)

如果我想创建一个横向字体 - 也就是说,一个方向和擒纵角度为90度的字体 - 是否使用 LOGPIXELSX 而不是 LOGPIXELSY ?对于一些我打算使用的打印机来说,水平分辨率和垂直分辨率是不同的。一般来说,如果我想要一个角度 theta code>,结合 LOGPIXELSX LOGPIXELSY ?我想这样的事情:

pre $ //给定以度为单位的theta(例如theta = 45.0)...
double theta_radians = theta * 2.0 * pi / 360.0;
int dpi = static_cast< int>(GetDeviceCaps(hdc,LOGPIXELSX)* sin(theta_radians)+
GetDeviceCaps(hdc,LOGPIXELSY)* cos(theta_radians)+
0.5);
LOGFONT lf = {0};
lf.lfHeight = -MulDiv(point_size,dpi,72);
//设置十分之一度的擒纵机构和方向。
lf.lfEscapement = lf.lfOrientation = static_cast< LONG>(theta * 10.0 + 0.5);
...

这对我来说很直观,但是我想知道是真正的GDI字体映射器和打印机驱动程序的工作方式。

解决方案

1)有72点/英寸。 (它曾经是72.27,但已被改变)
2)以你所做的方式结合LOGPIXELSX和LOGPIXELSY是好的,但是
3)字体映射器在映射时不会看擒纵器和方向字体。 LOGPIXELS值将只用作坐标转换的一部分。



http://msdn.microsoft.com/zh-cn/library/ms969909(loband).aspx

不知道打印机驱动程序如何工作,因为这个语句可能包含许多可能的驱动程序和打印机。他们可以用正方形像素进行光栅化,然后拉伸非正方形。他们可以转换字形曲线。他们可以做别的事情。


The common way to create a font with GDI is to use the desired point size and the target device's vertical resolution (DPI) like this:

LOGFONT lf = {0};
lf.lfHeight = -MulDiv(point_size, GetDeviceCaps(hdc, LOGPIXELSY), 72);
...
HFONT hfont = CreateFontIndirect(&lf);

Assuming the default MM_TEXT mapping mode, this converts point_size into the pixel height for the desired device. (This is a common approximation. There are actually 72.27 points in an inch, not 72.) (The minus sign means I want to specify the actual character height, not the cell height.)

If I want to create a sideways font--that is, one with an orientation and escapement of 90 degrees--do I use LOGPIXELSX rather than LOGPIXELSY? For some of the printers I'm targeting, the horizontal and vertical resolutions are different.

Generally, if I want an angle of theta, do I combine LOGPIXELSX and LOGPIXELSY? I'm thinking of something like this:

// Given theta in degrees (e.g., theta = 45.0) ...
double theta_radians = theta * 2.0 * pi / 360.0;
int dpi = static_cast<int>(GetDeviceCaps(hdc, LOGPIXELSX) * sin(theta_radians) +
                           GetDeviceCaps(hdc, LOGPIXELSY) * cos(theta_radians) +
                           0.5);
LOGFONT lf = {0};
lf.lfHeight = -MulDiv(point_size, dpi, 72);
// Set escapement and orientation to theta in tenths of a degree.
lf.lfEscapement = lf.lfOrientation = static_cast<LONG>(theta * 10.0 + 0.5);
...

This makes intuitive sense to me, but I'm wondering if this is really how the GDI font mapper and printer drivers work.

解决方案

1) There are 72 points/inch. (it used to be 72.27 but was changed.) 2) Combining LOGPIXELSX and LOGPIXELSY in the way that you do is fine, but 3) The font mapper doesn't look at escapement and orientation when mapping fonts. The LOGPIXELS values will only be used as part of the coordinate transformation.

http://msdn.microsoft.com/en-us/library/ms969909(loband).aspx

Not sure about how the "printer drivers work" because the statement could include many possible drivers and printers.

They could rasterize with square pixels, then stretch to non-square. They could transform glyph curves. They could do something else.

这篇关于如何指定不同方向的字体高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆