Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 705821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:05:47+00:00 2026-05-14T04:05:47+00:00

Question: Is there a way to check if a given font is one of

  • 0

Question:

Is there a way to check if a given font is one of Microsoft’s ClearType-optimized fonts?

I guess I could simply hard-code the list of font names, since it’s a relatively short list, but that seems a bit ugly. Would the font names be the same regardless of Windows’ locale and language settings?

Background:

PuTTY looks really ugly with bold, ClearType-enabled, Consolas text. I decided to play around with the source and see if I could figure out the problem, and I think I tracked it down to the following (abbreviated) code:

font_height = cfg.font.height;
if (font_height > 0) {
    font_height =
        -MulDiv(font_height, GetDeviceCaps(hdc, LOGPIXELSY), 72);
    }
}
font_width = 0;

#define f(i,c,w,u) \
    fonts[i] = CreateFont (font_height, font_width, 0, 0, w, FALSE, u, FALSE, \
                           c, OUT_DEFAULT_PRECIS, \
                           CLIP_DEFAULT_PRECIS, FONT_QUALITY(cfg.font_quality), \
                           FIXED_PITCH | FF_DONTCARE, cfg.font.name)

f(FONT_NORMAL, cfg.font.charset, fw_dontcare, FALSE);

SelectObject(hdc, fonts[FONT_NORMAL]);
GetTextMetrics(hdc, &tm);

font_height = tm.tmHeight;
font_width = tm.tmAveCharWidth;

f(FONT_BOLD, cfg.font.charset, fw_bold, FALSE);

The intent is to pick a bold font that fits the same dimensions as the normal font. I’m assuming that PuTTY’s Consolas text looks ugly because, since Consolas is so heavily optimized to be layed out on specific pixel boundaries, trying to shoehorn it into arbitrary dimensions produces bad results.

So it seems like an appropriate fix would be to detect ClearType-optimized fonts and try and create the bold versions of those fonts using the same width and height as the initial CreateFont call.

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:05:48+00:00Added an answer on May 14, 2026 at 4:05 am

    I am not sure that I follow quite what is meant by “tracked it down to the following (abbreviated) code”, but sure enough Consolas bold looks bad in Putty. Here is putty source of windows/window.c (revision 8914 obtained with subversion “svn co svn://svn.tartarus.org/sgt/putty“, on 5 April 2010).

    
          1386      fonts[i] = CreateFont (font_height, font_width, 0, 0, w, FALSE, u, FALSE, \
          1387                             c, OUT_DEFAULT_PRECIS, \
          1388                             CLIP_DEFAULT_PRECIS, FONT_QUALITY(cfg.font_quality), \
          1389                             FIXED_PITCH | FF_DONTCARE, cfg.font.name)
          1390  
          1391      f(FONT_NORMAL, cfg.font.charset, fw_dontcare, FALSE);
          1392  
          1393      SelectObject(hdc, fonts[FONT_NORMAL]);
          1394      GetTextMetrics(hdc, &tm);
          1395  
          1396      GetObject(fonts[FONT_NORMAL], sizeof(LOGFONT), &lfont);
          1397  
          1398      if (pick_width == 0 || pick_height == 0) {
          1399            font_height = tm.tmHeight;
          1400            font_width = tm.tmAveCharWidth;
          1401      }
          ...
          1477      if (bold_mode == BOLD_FONT) {
          1478      f(FONT_BOLD, cfg.font.charset, fw_bold, FALSE);
          1479      }
    
    

    For 10 pt Consolas, the values of font_height and font_width were -13 and 0 when CreateFont was called for FONT_NORMAL (via the macro f), but 15 and 7 when it was called for FONT_BOLD (the values are changed on lines 1399,1400). Setting the value of width explicitly does not agree well with the Consolas bold font. If window.c is modified so that lines 1477-1479 are moved to come after line 1391 a much nicer bold Consolas font is obtained (I also tried all the other available fonts (Courier, Bitstream, Lucida etc.) and they were not adversely affected. I have sent this suggestion to the Putty team. Here is a figure showing the difference:
    Bold-consolas-example

    ADDED ON JANUARY 16, 2011: The “bug” is still present, and the fix still works. Now the line-numbers in window.c are that lines 1510-1512 should be moved to come after line 1417. Kristjan.

    ADDED ON JAN. 13, 2012: The bug is still in version 0.62 of putty (released on Dec. 10, 2011). The linenumbers to move are now 1532-1534 to come after 1439. For completeness here are the steps I carried out in cygwin:

    $ svn co svn://svn.tartarus.org/sgt/putty2
    $ cd putty
    $ perl mkfiles.pl
    $ cd windows
    $ --- edit window.c and move the 3 lines---
    $ make CC=gcc-3 -f Makefile.cyg
    $ --- move resulting executable files (including putty.exe) to a suitable folder
    $ --- add shortcuts to the executables to Windows start menu
    

    Kristjan

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way in order to check if the page in question is
Question Is there a way to define a method only once in C# (in
Silly question - Is there a way to download the iPhone SDK without Xcode
Possible duplicate question: Is there a way to indefinitely pause a thread? In my
The real question: Is there a way to clear certain attributes for all components
I have a very theoretical question: Is there a way to ban the use
Simple question here: is there any way to convert from a jagged array to
My question is: is there a way with a DataContext/Table mapping to implement some
a simple question here Is there a way to change the text click here
Given two floating-point numbers, I'm looking for an efficient way to check if they

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.