Font sizes with Polybios

Discuss PDF file handling with the Polybios plugin here
Post Reply
User avatar
jPV
Posts: 365
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Font sizes with Polybios

Post by jPV »

I'd like to render a preview of contents that would be written to a PDF file by Hollywood functions to a Hollywood display, but texts that I render to the Hollywood display seem to appear in different size in the actual PDF file, even though I use same fonts and sizes.

Here's an example code what I've tried now (on MorphOS):

Code: Select all

@REQUIRE "polybios"
@DISPLAY {Width=595, Height=842, Color=#WHITE}

font$ = "Arial"
;font$ = "System:Fonts/_ttf/Arial.TTF"
size = 24
text$ = "This is a text line!!1 gjyq"

OpenFont(1, font$, size, {Engine = #FONTENGINE_INBUILT})
UseFont(1)
SetFontColor(#BLACK)
SetFontStyle(#ANTIALIAS)
TextOut(0, 0, text$)

doc=pdf.CreateDocument()
page = doc:AddPage()
page:SetSize(#HPDF_PAGE_SIZE_A4, #HPDF_PAGE_PORTRAIT)
font = doc:LoadFont(font$)
;font = doc:LoadTTFont(font$, True)
font = doc:GetFont(font)
page:SetFontAndSize(font, size)
page:BeginText()
page:TextOut(0, 842 - size, text$)
page:EndText()
doc:SaveToFile("ram:test.pdf")

WaitLeftMouse() 
As you can see, I've tried to load fonts though Hollywood/system, but also directly as TTF files. It's the same result in both cases and looks like this.

Rendered in the Hollywood display it looks like this:
Image

But in the PDF file it looks like this (even when loaded with Polybos itself):
Image

So why it's much bigger in the PDF? Should I scale something according something or how could I get them closer to the same sizes? :)

Page sizes are same for the display (595x842) and PDF (A4 = 595x842), and font sizes are defined to same 24 for both. PDF coordinates seem to match with Hollywood display with other operations, but only the text looks different.

Any advice or suggestions would be very welcome!

User avatar
airsoftsoftwair
Posts: 4392
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Font sizes with Polybios

Post by airsoftsoftwair »

For compatibility reasons Hollywood uses a font size in pixels by default whereas PDF uses points. So you can either manually convert pixels into points or try setting the "UsePoints" tag to TRUE in SetFont() to have Hollywood do that for you.

User avatar
jPV
Posts: 365
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Font sizes with Polybios

Post by jPV »

With that UsePoints it becomes about the same in height (there might be small 1 pixel or so differnce, which shows if you print many lines), but text in PDF is still noticeably wider. Any ideas why?

In Hollywood:
Image

In PDF:
Image

It's look even worse with capital letters and longer lines...

With page:SetCharSpace you can finetune a fixed content line, but if contents change, it doesn't help...

User avatar
airsoftsoftwair
Posts: 4392
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Font sizes with Polybios

Post by airsoftsoftwair »

I'm afraid there's not much you can do here. Polybios uses a different vector rasterization and text layouting technique than Hollywood. This makes it impossible to get the same layout with Hollywood and Polybios because the two engines are completely different. Hollywood uses a rather old version of freetype and a basic layouter whereas Polybios uses much more sophisticated tools. Might be an idea to do an advanced text rendering plugin based on pango but even this wouldn't give you exact results because text rendering results always deviate based on the renderer. When rendering the same text in the same size with the same font on macOS, Linux, and Windows you'll also get different results when using the OS-native renderers. That's why Hollywood offers its inbuilt renderer. This might not give you the most sophisticated layouting tools but at least its pixel-perfectly consistent between all platforms. But of course it can't be consistent to Polybios.

Post Reply