How to detect if a font has certain properties eg. Bold, Underline

There was one case when Windows did not synthesize styles, it was with PostScript ATM Type 1 fonts. But that was before the current OpenType standard.

All TrueType fonts synthesized Bold, Italic and BoldItalic.

I will run a test tomorrow with a PostScript OpenType font.

BTW, Underline is not exactly a stylistic variation. Any font contains instructions for underline that the font imager will apply : position relative to baseline, weight. So typically, all fonts are able to do underline.

OK. I tried with the basic font in a collection of PostScript Open Type fonts (.OTF).

When I launch WordPad, and select that font which has no stylistic variation, the system synthesizes Bold, Italic, and Bold Italic as expected.

But if I use the Font() function in Xojo Windows, these styles won’t appear. Only the fonts with unusual style, like Condensed or Black will show.

So, it is necessary to use an additional plugin to actually see which styles are actually available. I am sure MBS has that.

Note that a Xojo application will show the synthesized styles just as well as WordPad, even if they don’t show in the list of fonts.

I know, its dirty, but it should work on all systems (can’t try all), if you want ‘normal’, ‘bold’, italic’ and ‘bolditalic’.
Usually a popupMenu is not time critical.

Public Function hasBoldAndItalic(font_ as string) as Boolean
Var pBold as Picture
Var pItalic as Picture
Var pBoldItalic as Picture
Var p as Picture
var col as color = &c123456
var s as string = “S”

pBold = new picture(30, 30)
pBold.Graphics.AntiAliased = false
pbold.Graphics.Bold = True
pbold.Graphics.Italic = False
pBold.Graphics.FontName = font_
pBold.Graphics.FontSize = 60
pBold.Graphics.DrawingColor = col
pBold.Graphics.DrawText(s,0,30)

pItalic = new picture(30, 30)
pitalic.Graphics.AntiAliased = false
pItalic.Graphics.Italic = True
pItalic.Graphics.Bold = False
pItalic.Graphics.FontName = font_
pItalic.Graphics.FontSize = 60
pItalic.Graphics.DrawingColor = col
pItalic.Graphics.DrawText(s,0,30)

pBoldItalic = new picture(30, 30)
pBoldItalic.Graphics.AntiAliased = false
pBoldItalic.Graphics.Italic = True
pBoldItalic.Graphics.Bold = True
pBoldItalic.Graphics.FontName = font_
pBoldItalic.Graphics.FontSize = 60
pBoldItalic.Graphics.DrawingColor = col
pBoldItalic.Graphics.DrawText(s,0,30)

p = new picture(30, 30)
p.Graphics.AntiAliased = false
p.Graphics.Bold = False
p.Graphics.Italic = False
p.Graphics.FontName = font_
p.Graphics.FontSize = 60
p.Graphics.DrawingColor = col
p.Graphics.DrawText(s,0,30)

Var rgb(3) as RGBSurface
rgb(0) = p.RGBSurface
rgb(1) = pBold.RGBSurface
rgb(2) = pItalic.RGBSurface
rgb(3) = pBoldItalic.RGBSurface

Var count(3) as Integer
count(0) = 0
count(1) = 0
count(2) = 0
count(3) = 0

for x as Integer = 0 to 29
For y as Integer = 0 to 29
if rgb(0).Pixel(x,y) = col then count(0) = count(0) + 1
if rgb(1).Pixel(x,y) = col then count(1) = count(1) + 1
if rgb(2).Pixel(x,y) = col then count(2) = count(2) + 1
if rgb(3).Pixel(x,y) = col then count(3) = count(2) + 1
next
next
if count(0) <> count(1) And _
count(0) <> count(2) And _
count(0) <> count(3) And _
count(1) <> count(2) And _
count(1) <> count(3) And _
count(2) <> count(3) then
return true
else
return false
end if

End Function

There is a error in my code:

Should be:


for x as Integer = 0 to 29
For y as Integer = 0 to 29
if rgb(0).Pixel(x,y) = col then count(0) = count(0) + 1
if rgb(1).Pixel(x,y) = col then count(1) = count(1) + 1
if rgb(2).Pixel(x,y) = col then count(2) = count(2) + 1
if rgb(3).Pixel(x,y) = col then count(3) = count(3) + 1. <—
next
next

Sorry Karl