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:
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);
...
It makes me intuitive, but I wonder if it really works with GDI font drivers and printer drivers.
source
share