Check if font supports bold

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2409
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Check if font supports bold

Post by evstevemd »

Hi,
Does wxWidget wxFont (or anything else) provide platform reliable way to check if font have/supports bold and italic? Checking wxFont it have only a way to make bold and italic but provide no way for checking. Some fonts don't support Bold and Italic making my app weird when user selects such fonts

TIA
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: Check if font supports bold

Post by eranon »

Hello evstevemd, The MFC's CFontDialog class has a IsBold() method: https://msdn.microsoft.com/en-us/librar ... og__isbold. So, if your code is Windows only, you could maybe look at the implementation of this MFC function (source should be installed with Visual Studio -- not checked) and reproduce it w/o MFC.

Also, adding the bold style to a font in wxWidgets should change the font weight. So, maybe (but, again, not checked anything, it's pure theory) using wxNativeFontInfo::GetWeight() afterward could help figure out if the weight changed or not... Well, knowing Windows has a mechanism doing it may switch to another font when it exists a bold-specific version, and in this case I don't know if the weight property is impacted or not.

--
EDIT: Another way (tip level LOL), could be to measure the length of the text in pixels (GetTextExtent) with the given font before changing to bold, then compare with the length after. The bold one should be a little longer.
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2409
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Re: Check if font supports bold

Post by evstevemd »

Hi eranon,
thanks for suggestions. I give them a try (the wx's ones).
As of Windows only solution, I'll skip it as my is is required to work the same cross platform
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Post Reply