Enable ClearType fonts with the winapi

363 Views Asked by At

I'm trying to add ClearType to fonts in the vile editor GUI mode "winvile". I'm not familiar with the code.

I searched for all LOGFONT structs and found some in ntwinio.c and w32cmd.c

I couldn't find any other places with LOGFONT so I just tried adding CLEARTYPE_QUALITY (docs) where the structs are initialized. Ended up with:

diff --git a/ntwinio.c b/ntwinio.c
index 4b73176..c3a9871 100644
--- a/ntwinio.c
+++ b/ntwinio.c
@@ -848,6 +848,7 @@ GetMyFont(VIDEO_ATTR attr)
        LOGFONT logfont = vile_logfont;
        logfont.lfItalic = (BYTE) ((attr & VAITAL) != 0);
        logfont.lfUnderline = (BYTE) ((attr & VAUL) != 0);
+       logfont.lfQuality = CLEARTYPE_QUALITY;
        if (attr & VABOLD)
            logfont.lfWeight = FW_SEMIBOLD;
        if ((MyFonts[n].font = CreateFontIndirect(&logfont)) != 0) {
@@ -1218,6 +1219,7 @@ set_font(void)

     vile_logfont.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
     vile_logfont.lfCharSet = ANSI_CHARSET;
+    vile_logfont.lfQuality = CLEARTYPE_QUALITY;
     TRACE(("LOGFONT Facename:%s\n", vile_logfont.lfFaceName));

     if (ChooseFont(&choose)) {
@@ -1346,6 +1348,7 @@ ntwinio_font_frm_str(const char *fontstr,
        /* Build up LOGFONT data structure. */
        memset(&logfont, 0, sizeof(logfont));
        logfont.lfWeight = (str_rslts.bold) ? FW_BOLD : FW_NORMAL;
+       logfont.lfQuality = CLEARTYPE_QUALITY;
        logfont.lfHeight = -MulDiv(str_rslts.size,
                                   GetDeviceCaps(hdc, LOGPIXELSY),
                                   72);
diff --git a/w32cmd.c b/w32cmd.c
index 50276af..e9223ad 100644
--- a/w32cmd.c
+++ b/w32cmd.c
@@ -1626,6 +1626,7 @@ w32_init_logfont(LOGFONT * logfont, FONTSTR_OPTIONS * str_rslts, int height)

     logfont->lfWeight = (str_rslts->bold) ? FW_BOLD : FW_NORMAL;
     logfont->lfHeight = height;
+    logfont->lfQuality = CLEARTYPE_QUALITY;

     if (str_rslts->italic)
        logfont->lfItalic = TRUE;

That didn't seem to work and fonts still look bad, compared to cmd.exe:

enter image description here

I also tried other quality settings, they all look the same to me. Am I missing something in the winapi calls, or maybe missunderstanding how ClearType works?

I'm building with Visual Studio 2010 Express on Windows 10.

1

There are 1 best solutions below

0
ArthurChamz On BEST ANSWER

Wasn't ClearType but compatibility DPI settings for winvile.exe. Thanks to IInspectable for the pointer.