Hey folks,
Got a quick patch. The GfxFont parses the FontWeight as per the PDF
Specification, allowing only certain discrete values and raising an
error otherwise. We've encountered PDFs in the wild that don't adhere to
the standard. Acroread seems to handle the case gracefully, falling back
to the nearest valid font weight. Poppler raises an error and ignores
the FontWeight property altogether.
This patch adds the same graceful handling to Poppler. I don't see a
reason not to allow non-standard font weights. Poppler is a renderer,
not a validator. If we can handle this case gracefully and transparently
to the user, we should.
However, one could make an argument for adding a basic bounds check for
values outside of 50-950 or so. Personally I'm from the school of trying
to handle problems as locally as possible, but if a PDF has a font
weight with nonsensical values, perhaps that would be better handled
with an error. We opted to go without the bounds check for simplicity,
but it would be easy enough to add:
if (obj2.getNum() < 50 || obj2.getNum() > 950) error(-1, "Invalid Font
Weight");
else if (obj2.getNum() <= 150) weight = W100;
[..etc..]
Cheers,
Stefan Thomas
CTO
TxtBear AG Switzerland | www.txtbear.com | [email protected]
>From 6fefb3d5396c56d11f2936f8da280e30b949380b Mon Sep 17 00:00:00 2001
From: Stefan Thomas <[email protected]>
Date: Thu, 29 Apr 2010 12:59:04 +0100
Subject: [PATCH] Changed GfxFont to accept non-standard font sizes.
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
_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler