Font-Problem VC6.0 Windows

happymozart

Grünschnabel
Hallo

In meiner Applikation sollte sich die Font-Größe aus der Auflösung und den eingestellen Zeilen/Spalten ergeben.

int main(int argc, char* argv[])
{
HFONT font;
LOGFONT myFont;
HDC testDC;
SIZE fontSize;
UINT i;
BOOL rc;

testDC = CreateCompatibleDC(0);

memset(&myFont, 0, sizeof(myFont));

myFont.lfWeight = FW_MEDIUM;
myFont.lfCharSet = ANSI_CHARSET;
myFont.lfPitchAndFamily = FIXED_PITCH;
myFont.lfQuality = ANTIALIASED_QUALITY;
myFont.lfOutPrecision = OUT_RASTER_PRECIS;
strcpy(myFont.lfFaceName , "Courier New");

for (i = 0; i < 10; i++) {
myFont.lfHeight = 20 + i;
myFont.lfWidth = 16;

font = CreateFontIndirect(&myFont);

SelectObject(testDC, font);
rc = GetTextExtentPoint32(testDC, "X", 1, &fontSize);
if (rc == TRUE) {
dprintf("Font (%d/%d) -> (%d/%d)", myFont.lfWidth, myFont.lfHeight, fontSize.cx, fontSize.cy);
}
}

DeleteDC(testDC);

return 0;
}

Output:
Font (16/20) -> (15/20)
Font (16/21) -> (16/21)
Font (16/22) -> (16/22)
Font (16/23) -> (17/23)
Font (16/24) -> (17/24)
Font (16/25) -> (17/25)
Font (16/26) -> (16/25)
Font (16/27) -> (16/27)
Font (16/28) -> (16/27)
Font (16/29) -> (16/29)

Teilweise ergibt sich nun eine Breite von 17 -> der Text wird zu Breit und wird außerhalb des sichtbaren Bildschirms dargestellt. Die Ursache scheint "Font Hinting" zu sein - derweilen bin ich aber noch nicht so weit dies wirklich zu verstehen.

Heißt das, dass ich diesen Font für meine Anforderungen nicht verwenden kann? "MS Gothic" scheint hier schon eher den Erwartungen zu entsprechen, oder täuscht das?

Danke!
 
Zuletzt bearbeitet:
Zurück