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
Check if font supports bold
- evstevemd
- Part Of The Furniture
- Posts: 2409
- Joined: Wed Jan 28, 2009 11:57 am
- Location: United Republic of Tanzania
Check if font supports bold
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?
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
- eranon
- 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
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.
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"]
- evstevemd
- 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
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
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?
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?