How can I detect if a font is bold?

Q:

How can I detect if a font is bold? Is there any way to do it? Is
there a nice and convenient way to do it (like calling font.isItalic()
for italics)?
-------------
A:

For bold and italics you could sometimes rely on 'ItalicAngle' and
'FontWeight' parameters in the Font dictionary (but in some cases
this information is not correct). You can also obtain other properties
from font descriptor dictionary (see section 5.7 'Font Descriptors' in
PDF Reference Manual).

For example,

// In C# ---------------
Obj fd = font.GetFontDescriptor();
if (fd == null) return; // If null, the font is not embedded

double italic_angle = 0, weight=400;
Obj o = fd.FindObj("ItalicAngle");
if (o != null) {
   italic_angle = o.GetNumber();
}

o = fd.Find("FontWeight");
if (o != null) {
   // A value of 400 indicates a normal weight; 700 indicates bold.
   weight = o.GetNumber();
}

// In C++ ----------------

Obj* fd = font.GetFontDescriptor();
if (!fd) return; // If null, the font is not embedded

double italic_angle = 0, weight=400;
Obj* o;
if (o = fd->FindObj("ItalicAngle")) {
   italic_angle = o->GetNumber();
}

if (o = fd->Find("FontWeight")) {
   // A value of 400 indicates a normal weight; 700 indicates bold.
   weight = o->GetNumber();
}