Commit 8a8d57bd authored by Albert Astals Cid's avatar Albert Astals Cid

Extract family, stretch and weight from the font descriptor

parent 3a1646c2
......@@ -2,6 +2,8 @@
* poppler/PDFDoc.[cc|h]: Add checkFooter to check document ends with
%%EOF
* poppler/GfxFont.[cc|h]: Extract family, stretch and weight from the
font descriptor
2005-07-06 Brad Hards <bradh@frogmouth.net>
......
......@@ -144,10 +144,14 @@ GfxFont::GfxFont(char *tagA, Ref idA, GooString *nameA) {
origName = nameA;
embFontName = NULL;
extFontFile = NULL;
family = NULL;
stretch = StretchNotDefined;
weight = WeightNotDefined;
}
GfxFont::~GfxFont() {
delete tag;
delete family;
if (origName && origName != name) {
delete origName;
}
......@@ -189,6 +193,43 @@ void GfxFont::readFontDescriptor(XRef *xref, Dict *fontDict) {
}
obj2.free();
// get family
obj1.dictLookup("FontFamily", &obj2);
if (obj2.isString()) family = new GooString(obj2.getString());
obj2.free();
// get stretch
obj1.dictLookup("FontStretch", &obj2);
if (obj2.isName()) {
if (strcmp(obj2.getName(), "UltraCondensed") == 0) stretch = UltraCondensed;
else if (strcmp(obj2.getName(), "ExtraCondensed") == 0) stretch = ExtraCondensed;
else if (strcmp(obj2.getName(), "Condensed") == 0) stretch = Condensed;
else if (strcmp(obj2.getName(), "SemiCondensed") == 0) stretch = SemiCondensed;
else if (strcmp(obj2.getName(), "Normal") == 0) stretch = Normal;
else if (strcmp(obj2.getName(), "SemiExpanded") == 0) stretch = SemiExpanded;
else if (strcmp(obj2.getName(), "Expanded") == 0) stretch = Expanded;
else if (strcmp(obj2.getName(), "ExtraExpanded") == 0) stretch = ExtraExpanded;
else if (strcmp(obj2.getName(), "UltraExpanded") == 0) stretch = UltraExpanded;
else error(-1, "Invalid Font Stretch");
}
obj2.free();
// get weight
obj1.dictLookup("FontWeight", &obj2);
if (obj2.isNum()) {
if (obj2.getNum() == 100) weight = W100;
else if (obj2.getNum() == 200) weight = W200;
else if (obj2.getNum() == 300) weight = W300;
else if (obj2.getNum() == 400) weight = W400;
else if (obj2.getNum() == 500) weight = W500;
else if (obj2.getNum() == 600) weight = W600;
else if (obj2.getNum() == 700) weight = W700;
else if (obj2.getNum() == 800) weight = W800;
else if (obj2.getNum() == 900) weight = W900;
else error(-1, "Invalid Font Weight");
}
obj2.free();
// look for embedded font file
if (obj1.dictLookupNF("FontFile", &obj2)->isRef()) {
if (type == fontType1) {
......
......@@ -82,6 +82,30 @@ struct GfxFontCIDWidths {
class GfxFont {
public:
enum Stretch {
StretchNotDefined,
UltraCondensed,
ExtraCondensed,
Condensed,
SemiCondensed,
Normal,
SemiExpanded,
Expanded,
ExtraExpanded,
UltraExpanded };
enum Weight {
WeightNotDefined,
W100,
W200,
W300,
W400, // Normal
W500,
W600,
W700, // Bold
W800,
W900 };
// Build a GfxFont object.
static GfxFont *makeFont(XRef *xref, char *tagA, Ref idA, Dict *fontDict);
......@@ -102,6 +126,15 @@ public:
// Get base font name.
GooString *getName() { return name; }
// Get font family name.
GooString *getFamily() { return family; }
// Get font stretch.
Stretch getStretch() { return stretch; }
// Get font weight.
Weight getWeight() { return weight; }
// Get the original font name (ignornig any munging that might have
// been done to map to a canonical Base-14 font name).
......@@ -168,6 +201,9 @@ protected:
GooString *tag; // PDF font tag
Ref id; // reference (used as unique ID)
GooString *name; // font name
GooString *family; // font family
Stretch stretch; // font stretch
Weight weight; // font weight
GooString *origName; // original font name
GfxFontType type; // type of font
int flags; // font descriptor flags
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment