You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Esteban R <er...@hotmail.com> on 2017/06/29 14:20:32 UTC

Box issue with type3 font

Hello. I'm using DrawPrintTextLocations.java (from http://svn.apache.org/repos/asf/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/DrawPrintTextLocations.java)

to find the boxes for a character in the following pdf (a simplified version of a real life pdf):

http://wikisend.com/download/727732/boxissue_type3_font.pdf

but none of the boxes matches the printed character (see near the bottom of the page).

This is the output that I get:

http://wikisend.com/download/129910/boxissue_type3_font-marked-1.png


I have noticed that some values in the font have negative values... so I don't know if the file (or font) is corrupted or there is an issue in pdfbox (or in DrawPrintTextLocations). How can I get a tightly enclosing box for the character?


Esteban

Re: Box issue with type3 font

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 30.06.2017 um 15:43 schrieb Esteban R:
> Tilman: thanks for your answer! (https://lists.apache.org/thread.html/a6f20d16b76acbfe4c292bc2d0e7111de9173c7cd63aae330df3886a@%3Cusers.pdfbox.apache.org%3E) .
>
> For some reason your answer didn't arrive to my e-mail account although other e-mails from users@pdfbox.apache.org arrive ok :s .
>
>> To get a perfect bounding box for the cyan rectangle, the only thing one
>> could do would be to evaluate the content stream in the charproc:
>
> We will ignore the issue by now, but in case we decide to implement a solution in the future... maybe we can just create a "mock" document with the content stream, render it with PDFImageWriter.writeImage and then find the bounding box in the resulting image?

Yeah, but how find it? There is some code in PDFDebugger in the trunk 
(Type3Font.java) that does create a mock document. But it's just an 
image. One would have to look at black pixels. What if (just in theory) 
the font is white? What might be tried is to process only the path 
commands and see what happens. But there's also the problem of some 
fonts that use tiny images.

I'll do something re: the example, i.e. add a comment that 
charProc.getGlyphBBox() is sometimes unreliable, and certainly not as 
good as the individual glyph bounds on vector fonts. And add some code 
to compensate for a glyph bbox that is larger than the font bbox.

Tilman

>
>
> Esteban
>
>
>
>
> ________________________________
> De: Esteban R <er...@hotmail.com>
> Enviado: jueves, 29 de junio de 2017 02:20 p.m.
> Para: users@pdfbox.apache.org
> Asunto: Box issue with type3 font
>
>
> Hello. I'm using DrawPrintTextLocations.java (from http://svn.apache.org/repos/asf/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/DrawPrintTextLocations.java)
>
> to find the boxes for a character in the following pdf (a simplified version of a real life pdf):
>
> http://wikisend.com/download/727732/boxissue_type3_font.pdf
>
> but none of the boxes matches the printed character (see near the bottom of the page).
>
> This is the output that I get:
>
> http://wikisend.com/download/129910/boxissue_type3_font-marked-1.png
>
>
> I have noticed that some values in the font have negative values... so I don't know if the file (or font) is corrupted or there is an issue in pdfbox (or in DrawPrintTextLocations). How can I get a tightly enclosing box for the character?
>
>
> Esteban
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Box issue with type3 font

Posted by Esteban R <er...@hotmail.com>.
Thanks for your answers.


I have tried the changes in DrawTextLocations and the box is better. Of course, possibly due to the negative bbox and wrong font information, the cyan box  is still different than the real bbox but I understand that this is the best approach by now.


Esteban






________________________________
De: Tilman Hausherr <TH...@t-online.de>
Enviado: sábado, 01 de julio de 2017 09:21 a.m.
Para: users@pdfbox.apache.org
Asunto: Re: Box issue with type3 font

Done
https://issues.apache.org/jira/browse/PDFBOX-3850

And yes, the negative bbox is also a problem... this font is completely
wrong.

Tilman

Am 30.06.2017 um 15:43 schrieb Esteban R:
> Tilman: thanks for your answer! (https://lists.apache.org/thread.html/a6f20d16b76acbfe4c292bc2d0e7111de9173c7cd63aae330df3886a@%3Cusers.pdfbox.apache.org%3E) .
>
> For some reason your answer didn't arrive to my e-mail account although other e-mails from users@pdfbox.apache.org arrive ok :s .
>
>> To get a perfect bounding box for the cyan rectangle, the only thing one
>> could do would be to evaluate the content stream in the charproc:
>
> We will ignore the issue by now, but in case we decide to implement a solution in the future... maybe we can just create a "mock" document with the content stream, render it with PDFImageWriter.writeImage and then find the bounding box in the resulting image?
>
>
> Esteban
>
>
>
>
> ________________________________
> De: Esteban R <er...@hotmail.com>
> Enviado: jueves, 29 de junio de 2017 02:20 p.m.
> Para: users@pdfbox.apache.org
> Asunto: Box issue with type3 font
>
>
> Hello. I'm using DrawPrintTextLocations.java (from http://svn.apache.org/repos/asf/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/DrawPrintTextLocations.java)
>
> to find the boxes for a character in the following pdf (a simplified version of a real life pdf):
>
> http://wikisend.com/download/727732/boxissue_type3_font.pdf
>
> but none of the boxes matches the printed character (see near the bottom of the page).
>
> This is the output that I get:
>
> http://wikisend.com/download/129910/boxissue_type3_font-marked-1.png

>
>
> I have noticed that some values in the font have negative values... so I don't know if the file (or font) is corrupted or there is an issue in pdfbox (or in DrawPrintTextLocations). How can I get a tightly enclosing box for the character?
>
>
> Esteban
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Box issue with type3 font

Posted by Tilman Hausherr <TH...@t-online.de>.
Done
https://issues.apache.org/jira/browse/PDFBOX-3850

And yes, the negative bbox is also a problem... this font is completely 
wrong.

Tilman

Am 30.06.2017 um 15:43 schrieb Esteban R:
> Tilman: thanks for your answer! (https://lists.apache.org/thread.html/a6f20d16b76acbfe4c292bc2d0e7111de9173c7cd63aae330df3886a@%3Cusers.pdfbox.apache.org%3E) .
>
> For some reason your answer didn't arrive to my e-mail account although other e-mails from users@pdfbox.apache.org arrive ok :s .
>
>> To get a perfect bounding box for the cyan rectangle, the only thing one
>> could do would be to evaluate the content stream in the charproc:
>
> We will ignore the issue by now, but in case we decide to implement a solution in the future... maybe we can just create a "mock" document with the content stream, render it with PDFImageWriter.writeImage and then find the bounding box in the resulting image?
>
>
> Esteban
>
>
>
>
> ________________________________
> De: Esteban R <er...@hotmail.com>
> Enviado: jueves, 29 de junio de 2017 02:20 p.m.
> Para: users@pdfbox.apache.org
> Asunto: Box issue with type3 font
>
>
> Hello. I'm using DrawPrintTextLocations.java (from http://svn.apache.org/repos/asf/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/DrawPrintTextLocations.java)
>
> to find the boxes for a character in the following pdf (a simplified version of a real life pdf):
>
> http://wikisend.com/download/727732/boxissue_type3_font.pdf
>
> but none of the boxes matches the printed character (see near the bottom of the page).
>
> This is the output that I get:
>
> http://wikisend.com/download/129910/boxissue_type3_font-marked-1.png
>
>
> I have noticed that some values in the font have negative values... so I don't know if the file (or font) is corrupted or there is an issue in pdfbox (or in DrawPrintTextLocations). How can I get a tightly enclosing box for the character?
>
>
> Esteban
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Box issue with type3 font

Posted by Esteban R <er...@hotmail.com>.
Tilman: thanks for your answer! (https://lists.apache.org/thread.html/a6f20d16b76acbfe4c292bc2d0e7111de9173c7cd63aae330df3886a@%3Cusers.pdfbox.apache.org%3E) .

For some reason your answer didn't arrive to my e-mail account although other e-mails from users@pdfbox.apache.org arrive ok :s .

>To get a perfect bounding box for the cyan rectangle, the only thing one
>could do would be to evaluate the content stream in the charproc:


We will ignore the issue by now, but in case we decide to implement a solution in the future... maybe we can just create a "mock" document with the content stream, render it with PDFImageWriter.writeImage and then find the bounding box in the resulting image?


Esteban




________________________________
De: Esteban R <er...@hotmail.com>
Enviado: jueves, 29 de junio de 2017 02:20 p.m.
Para: users@pdfbox.apache.org
Asunto: Box issue with type3 font


Hello. I'm using DrawPrintTextLocations.java (from http://svn.apache.org/repos/asf/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/DrawPrintTextLocations.java)

to find the boxes for a character in the following pdf (a simplified version of a real life pdf):

http://wikisend.com/download/727732/boxissue_type3_font.pdf

but none of the boxes matches the printed character (see near the bottom of the page).

This is the output that I get:

http://wikisend.com/download/129910/boxissue_type3_font-marked-1.png


I have noticed that some values in the font have negative values... so I don't know if the file (or font) is corrupted or there is an issue in pdfbox (or in DrawPrintTextLocations). How can I get a tightly enclosing box for the character?


Esteban

Re: Box issue with type3 font

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 29.06.2017 um 16:20 schrieb Esteban R:
> Hello. I'm using DrawPrintTextLocations.java (from http://svn.apache.org/repos/asf/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/DrawPrintTextLocations.java)
>
> to find the boxes for a character in the following pdf (a simplified version of a real life pdf):
>
> http://wikisend.com/download/727732/boxissue_type3_font.pdf
>
> but none of the boxes matches the printed character (see near the bottom of the page).
>
> This is the output that I get:
>
> http://wikisend.com/download/129910/boxissue_type3_font-marked-1.png
>
>
> I have noticed that some values in the font have negative values... so I don't know if the file (or font) is corrupted or there is an issue in pdfbox (or in DrawPrintTextLocations). How can I get a tightly enclosing box for the character?
>
>
> Esteban
>

The charproc has this in the first line:

1 0 -10 -10 10 10 d1


PDF specification:

====

wx wy llx lly urx ury

Set width and bounding box information for the glyph and declare that 
the glyph description specifies only shape, not colour.

wx denotes the horizontal displacement in the glyph coordinate system; 
it shall be consistent with the corresponding width in the font’s Widths 
array. wy shall be 0 (see 9.2.4, "Glyph Positioning and Metrics").
llx and lly denote the coordinates of the lower-left corner, and urx and 
ury denote the upper-right corner, of the glyph bounding box. The glyph 
bounding box is the smallest rectangle, oriented with the axes of the 
glyph coordinate system, that completely encloses all marks placed on 
the page as a result of executing the glyph’s description. The declared 
bounding box shall be correct—in other words, sufficiently large to 
enclose the entire glyph. If any marks fall outside this bounding box, 
the result is unpredictable.

====

So the bounding box here is too large. It is even larger than the total 
bounding box that can be found at

Root/Pages/Kids/[0]/Resources/XObject/TPL1/Resources/Font/R20/FontBBox

To get a perfect bounding box for the cyan rectangle, the only thing one 
could do would be to evaluate the content stream in the charproc:

1 0 -10 -10 10 10 d1
0.01 0 0 0.01 0 0 cm
11.7188 0 m
2.05078 58.4961 l
8.44922 58.4961 l
16.1602 8.59375 l
24.5117 58.4961 l
32.3242 58.4961 l
41.3086 8.59375 l
48.3398 58.4961 l
54.6406 58.4961 l
45.0703 0 l
37.9883 0 l
28.5664 48.2422 l
19.4805 0 l
11.7188 0 l
f

This would be quite tricky... I don't know how Adobe and PDF.js do it. 
Maybe they drop the individual bounding box and just use the width as 
height.

Tilman



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org