How to specify font height in different orientations?

A common way to create a font with GDI is to use the desired dot size and vertical resolution of the target device (DPI) as follows:

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

Assuming a default display mode MM_TEXT, it converts point_size to pixel height for the desired device. (This is a common approximation: in fact, 72.27 dots per inch, not 72.) (A minus sign means that I want to indicate the actual height of the character, not the height of the cell.)

If I want to create a side font, that is, one with orientation and 90 degree descents, do I use LOGPIXELSXinstead LOGPIXELSY? For some printers I'm aiming at, the horizontal and vertical resolutions are different.

Generally, if I need an angle theta, can I combine LOGPIXELSXand LOGPIXELSY? I am 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);
...

It makes me intuitive, but I wonder if it really works with GDI font drivers and printer drivers.

+3
source share
1 answer

1) There are 72 dpi. (previously it was 72.27, but has been changed). 2) Combining LOGPIXELSX and LOGPIXELSY in the way you do is fine, but 3) The font manager does not look at the descent and orientation when displaying fonts. LOGPIXELS values ​​will only be used as part of the coordinate transformation.

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

, " ", .

, . . - .

0

Source: https://habr.com/ru/post/1709440/


All Articles