Q: I am trying to get the bounding box for Text element, but I
encountered one PDF where bool pdftron::PDF::Element::GetBBox ( Rect
& out_bbox ) returns false.
The same code works fine for other PDFs. Is there any other way to get
the bounding box when GetBBox fails?
----------------------------------
A: The problem is that the file is using a Type3 font which has
corrupt font bounding box [0, 0, 0, 0]. You could open Type3 font
display list and find the bounding box for all element in the glyph
stream using Type3FontBegin.
Perhaps something along the following lines:
CharIterator itr = text_element.GetCharIterator();
if (font.GetType() == Font.Type.e_Type3) {
for (; itr.HasNext(); itr.Next()) {
Obj font_stm = font.GetType3GlyphStream(itr.Current().char_code);
Matrix2D pos(1, 0, 0, 1, itr.Current().x, itr.Current().y);
element_reader.Type3FontBegin(font_stm, font.GetSDFObj(), 0);
ProcessElements(mtx * pos * font_mtx); << Here find the bbox for
all elements (this is the bbox for the glyph).
element_reader.End();
}
}