HPDF_Page_TextRect() corrections and improvements

755 views
Skip to first unread message

Ralf Junker

unread,
Jan 29, 2010, 1:37:01 PM1/29/10
to lib...@googlegroups.com
The attached patch fixes a few issues in HPDF_Page_TextRect():

* With HPDF_TALIGN_JUSTIFY, last lines of paragraphs were justified
whereas the last line of the text was not. This is now fixed so that
last lines in paragraphs are left aligned.

* Trim text lines so that trailing white space and line break characters
are not written out, resulting in smaller PDF files.

* For HPDF_TALIGN_RIGHT and HPDF_TALIGN_CENTER, an extra, unnecessary
"Td" operator was written after each line acting as a "carriage return".
This is now spared and calculated into the the "Td" offsets of the
following line, resulting in smaller PDF output.

* In the same context, added a new static TextPos_AbsToRel() function to
calculate coordinates for HPDF_Page_MoveTextPos(). Also used this to
replace extended code in HPDF_Page_TextOut().

* For all alignment types, do not output two leading "Td" operators
where a combined single one can do the job just as well.

The patch is against the current GIT head. A simple demo application
attached as well.

Ralf

HPDF_Page_TextRect.patch
main.c

Franco Marchesini

unread,
Feb 1, 2010, 5:17:07 AM2/1/10
to lib...@googlegroups.com
Thanks!!
It's work fine.

Franco

2010/1/29 Ralf Junker <ralfj...@gmx.de>:

> --
> ---
> libHaru.org development mailing list
> To unsubscribe, send email to libharu-u...@googlegroups.com

Antony Dovgal

unread,
Feb 1, 2010, 5:28:57 AM2/1/10
to lib...@googlegroups.com
Committed, thanks!


--
Wbr,
Antony Dovgal
---
http://pinba.org - realtime statistics for PHP

Franco Marchesini

unread,
Feb 1, 2010, 8:37:59 AM2/1/10
to lib...@googlegroups.com
Hello,
I work with MAcBook Pro and Snow Leopard.
This morning I downloaded the git version of the library and I applied
the patch.
Now I realized that the strings printed with HPDF_Page_TextRect () are
not displayed by Adobe Acrobat Reader version 9.2.0, even if they are
printed correctly and are visible in the preview system utility.

Is a problem, any idea?
Best regards

Franco

2010/2/1 Antony Dovgal <to...@daylessday.org>:

Ralf Junker

unread,
Feb 1, 2010, 9:47:42 AM2/1/10
to lib...@googlegroups.com
On 01.02.2010 14:37, Franco Marchesini wrote:

> This morning I downloaded the git version of the library and I applied
> the patch.
> Now I realized that the strings printed with HPDF_Page_TextRect () are
> not displayed by Adobe Acrobat Reader version 9.2.0, even if they are
> printed correctly and are visible in the preview system utility.

Does your problem show with the example application I attached next to
the patch to my original message? Or does it happen with your custom
code? For the latter, can you provide C code to reproduce the problem?

Could it be related to my posting "Patch: Fix missing parentheses from
empty string object" from 2010-01-04?

Ralf

Franco Marchesini

unread,
Feb 1, 2010, 10:06:18 AM2/1/10
to lib...@googlegroups.com
Hi Ralf,
the problem is also with your example.
I attach the pdf file generated (_test.pdf).
The strange thing is that with the safari browser plugin (from adobe)
I can see and print correctly the file.

> Could it be related to my posting "Patch: Fix missing parentheses from empty
> string object" from 2010-01-04?

Yes, I had the problem after apply your patch to git version this morning.
I honestly do not know if the problem is in the patch or version of the library.
Earlier works with version 2.10 without this problem.

Franco

2010/2/1 Ralf Junker <ralfj...@gmx.de>:

_test.pdf

Franco Marchesini

unread,
Feb 2, 2010, 3:36:54 AM2/2/10
to lib...@googlegroups.com
Hello Ralf,
I think the problem is in the patch.
This morning I installed the libharu 2.1.0, I applied the patch and I
ran your test.
_test.pdf output file has the same problems.
It's ok with pdf safari plugin.
It's ok with mac osx preview utility.
It's no ok with Adobe Acrobat reader 9.2.0.

Ciao
Franco

2010/2/1 Franco Marchesini <franco.m...@gmail.com>:

Ralf Junker

unread,
Feb 2, 2010, 4:18:19 AM2/2/10
to lib...@googlegroups.com
On 01.02.2010 16:06, Franco Marchesini wrote:

>> Could it be related to my posting "Patch: Fix missing parentheses
>> from empty string object" from 2010-01-04?
>
> Yes, I had the problem after apply your patch to git version this
> morning. I honestly do not know if the problem is in the patch or
> version of the library. Earlier works with version 2.10 without this
> problem.

I can confirm that your _test.pdf file does not display with Adobe
Reader 8.1.3 either.

However, a closer look shows that it was generated without my patch from
2010-01-04 which fixes the missing parenthesis problem for empty strings.

Below is copy of my original message and the patch. It merely comments
out these two lines in hpdf_streams.c, HPDF_Stream_WriteEscapeText2():

if (!len)
return HPDF_OK;

I believe that it should be pushed to GIT for the reasons given as well
as the example you presented.

Ralf

------------------

Copy of message from 2010-01-04:

libharu does not output parenthesis for empty string objects. Without,
WinXP Adobe Reader 8.1.3 fails to open the Properties dialog if the
PDF producer is set to an empty string with

HPDF_SetInfoAttr (pdf, HPDF_INFO_PRODUCER, "");

See PDF Specification, "7.3.4.2 Literal Strings" for details. The empty
string WITH parenthesis is explicitly mentioned as an example.


--- hpdf_streams.c Thu Jan 15 10:14:12 1970
+++ hpdf_streams.c Thu Jan 15 10:14:12 1970
@@ -421,8 +421,13 @@

HPDF_PTRACE((" HPDF_Stream_WriteEscapeText2\n"));

+ /* The following block is commented out because it violates "PDF Spec
+ 7.3.4.2 Literal Strings". It states that the two matching
parentheses
+ must still be present to represent an empty string of zero
length. */
+ /*
if (!len)
return HPDF_OK;
+ */

buf[idx++] = '(';


Franco Marchesini

unread,
Feb 2, 2010, 4:36:30 AM2/2/10
to lib...@googlegroups.com
Good!!
I confirm that with the 2010-01-04 patch all work fine

Thanks
Franco

2010/2/2 Ralf Junker <ralfj...@gmx.de>:

Antony Dovgal

unread,
Feb 2, 2010, 5:14:05 AM2/2/10
to lib...@googlegroups.com
On 02/02/2010 12:18 PM, Ralf Junker wrote:
> I believe that it should be pushed to GIT for the reasons given as well
> as the example you presented.

Oops! Missed that patch in the list.
Committed, thanks a lot.

Reply all
Reply to author
Forward
0 new messages