[PATCH] Changed GfxFont to accept non-standard font sizes.

Stefan Thomas thomas at txtbear.com
Thu Apr 29 04:59:04 PDT 2010


Only certain font sizes are allowed according to the PDF Specification. However, other sizes do appear in the wild and there is no reason not to handle them gracefully, by falling back to the nearest valid value.
---
 poppler/GfxFont.cc |   19 +++++++++----------
 1 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc
index f823faf..8787a3b 100644
--- a/poppler/GfxFont.cc
+++ b/poppler/GfxFont.cc
@@ -264,16 +264,15 @@ void GfxFont::readFontDescriptor(XRef *xref, Dict *fontDict) {
     // 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");
+      if (obj2.getNum() <= 150) weight = W100;
+      else if (obj2.getNum() <= 250) weight = W200;
+      else if (obj2.getNum() <= 350) weight = W300;
+      else if (obj2.getNum() <= 450) weight = W400;
+      else if (obj2.getNum() <= 550) weight = W500;
+      else if (obj2.getNum() <= 650) weight = W600;
+      else if (obj2.getNum() <= 750) weight = W700;
+      else if (obj2.getNum() <= 850) weight = W800;
+      else weight = W900;
     }
     obj2.free();
 
-- 
1.6.3.3


--------------090002060809000209090806--


More information about the poppler mailing list