New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Underline not rendered correctly. #609

Closed
tic2000 opened this Issue Mar 21, 2013 · 7 comments

Comments

Projects
None yet
4 participants
@tic2000
Copy link

tic2000 commented Mar 21, 2013

What steps will reproduce the problem?

Save this font.
Install it in your dompdf.
Try to put some underlined text in a PDF using the new font family.

What is the expected output? What do you see instead?

Expected output
Actual output

What version of dompdf are you using? What version of PHP? On what
operating system?
Latest. 5.3. Tried both on linux and Mac.

Please provide the HTML source code you want to convert, or any additional
information.

Any underlined text will do.

I was using an older version of dompdf and I tried to underline that font. The result was a to thin underline and way below the text. But the text was at top as it should have been.

I updated to the latest version and now the underline is OK, but the text is where the old underline was.

The commit that fixed the underline and broke the text is 17446bc.
Looking at the 2 ufm files I noticed that the one with the text in the correct position had
Ascender 857
Descender -143
FontBBox -25 -332 1078 1144

while the wrong one had
Ascender 1144
Descender -332
FontBBox -25 -332 1078 1144

The same day this was commited, March 25th of last year, a change for php-font-lib was done too. Reverting the change for php-font-lib was how I actually generated the correct pdf. Now both the underline is in the right position and has the right thickness and the text is in the right position too.

But I don't know what that could brake either.

@tic2000

This comment has been minimized.

Copy link

tic2000 commented Mar 27, 2013

Since I got no reply I tried this with a default font, in this case Courier.
I altered the demo file so I could also see a preview which you can see in the first screenshot.
html-preview-3

In the second screenshot you can see the pdf generated. As you can see the text is closer to the top from what it should be which results in an underline that is farther away from the text.
pdf-result

Than I did the change described in my previous comment, and using a Courier.ttf I generated a new ufm file. The pdf result now was:
pdf-result-after

Still not as it should, because if I write something with "p" for example the underline is bellow the text and does't cut the "p" as it should.

p
p1
p2

@bsweeney

This comment has been minimized.

Copy link
Member

bsweeney commented Mar 27, 2013

Thanks for the update. The original problem may be in php-font-lib, so I'll leave that for @PhenX to look at. The underline position may well be due to how dompdf is calculating where to draw the line, so we'll take a closer look at it.

@inbaz

This comment has been minimized.

Copy link

inbaz commented Dec 26, 2017

Hey, I found this issue and I got nearly the same problem. I've inserted Open Sans from the google fonts into my document with this link tag:

The result I get is:
wrong_font_display

In an older version I edited the file OpenSans-Regular.ufm.php to have these values:

'UnderlineThickness' => '50',
'UnderlinePosition' => '-500',

That worked.

How can I change the UnderlinePosition for a font that is inserted via the html document with a font-face statement in the css part?

I'm happy to get some information on how to solve this.

Cheers
Andi

@ethaizone

This comment has been minimized.

Copy link

ethaizone commented Jan 7, 2018

@inbaz I tried edit .ufm.php file in vendor directory and this work for me too.

My font is Garuda and Initial UnderlinePosition value is -32. I need change it to -1100 for make it look good in my pdf.

Thank you for point out this info. It help me a lot. :)

Update: After I use it. This solution is just temporary for underline only. It will not work with line-through.

@ethaizone

This comment has been minimized.

Copy link

ethaizone commented Jan 7, 2018

Maybe this is related issue on PhenX/php-font-lib#7

In this line.

$underline_position = $cpdf_font["UnderlinePosition"] / 1000;

Value will divide by 1000 for use in lib. Maybe this is fail from php-font-lib?

@ethaizone

This comment has been minimized.

Copy link

ethaizone commented Jan 7, 2018

$deco_y = $y; //$line->y;

Currently this line don't have proper value. I think we expect $deco_y should have baseline position but I don't know how we can get that. In php-font-lib they don't provide more infomation such as XHeight value but I don't think it will help us too.

763ed27#diff-47ad25618e24e7cdae67048db5fb13cfL92

For this older commit. Just as you see. These code use Ascender and Decender value to shift $base position for use adjust $deco_y later.

For me I like that lastest implement that make $base stay as it be but I think we need to find they way how we can get baseline and use it as $deco_y. I tried use Ascender and Decender but it don't make good result. Maybe we need to use bouning box position?

Ref: http://www.adobe.com/content/dam/acom/en/devnet/font/pdfs/5004.AFM_Spec.pdf
http://www.washington.edu/perl5man/sitemodules/Font/AFM.html
https://en.wikipedia.org/wiki/Baseline_(typography)

@ethaizone

This comment has been minimized.

Copy link

ethaizone commented Jan 7, 2018

IDK why but this fix for me. Need someone to test it,

#1631

@bsweeney bsweeney added this to the 0.8.3 milestone Jun 27, 2018

bsweeney added a commit that referenced this issue Jun 27, 2018

Calculate text decoration y-pos using font height
Previously both the size and frame_font_size were both being set to the same value. However, some calculations require the actual height of the font, not the specified size. This change updates frame_font_height to represent the calculated height of the font. Since these two variables are no longer interchangeable usage was corrected where necessary.

Addresses #609
Partially Addresses #1557

@bsweeney bsweeney closed this Dec 17, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment