xournalpp / xournalpp

Xournal++ is a handwriting notetaking software with PDF annotation support. Written in C++ with GTK3, supporting Linux (e.g. Ubuntu, Debian, Arch, SUSE), macOS and Windows 10. Supports pen input from devices such as Wacom Tablets.
https://xournalpp.github.io
GNU General Public License v2.0
11.27k stars 803 forks source link

The font in the exported PDF is offset #5405

Open moriro opened 11 months ago

moriro commented 11 months ago

Operating System

Windows

(Linux only) Distribution

No response

(Linux only) Desktop Environment

No response

(Linux Only) Display Server

None

Installation Method

Official release

Xournal++ Version

1.2.2

libgtk Version

GTK: 3.24.39

Bug Description

The font size(or style? or line spacing?) will be changed in multi-line texts. I have experimented with various fonts, and it appears to be a consistent issue. This results in an offset between the text and the ink.

image

However, this issue does not occur when exporting to PNG/SVG or input the text via LaTeX. The problem seems to be associated with the system's PDF export method, and I have been unable to find a solution online.

Expected Behaviour

The font size(or style? or line spacing?) will be changed and offset.

Steps to Reproduce

  1. Enter multiple lines of text, draw some underline by ink or add a background
  2. Export to PDF, PNG
  3. Compare the PDF and PNG/.xopp, it will happen

Additional Context

Windows11 23H2 22631.2861

tmoerschell commented 10 months ago

Hi, thanks for reporting ! I have dug a little bit into this...

I found the issue to be that the baseline of the pango layout is slightly different when exporting to PDF (why, I do not know). Xournal++ does not align text on the baseline, so it is shifted up when the baseline is lower (lower pango y = closer to the top) than usual.

https://github.com/xournalpp/xournalpp/blob/0abf8a8f26d008299f9d06ed48a78894400a54aa/src/core/view/TextView.cpp#L21-L27 This is where the change to the baseline happens: calling pango_layout_get_baseline(layout.get()) before and after pango_cairo_update_layout(cr, layout.get()) will return different results.

Now simply removing this call to pango_cairo_update_layout() works and resolves the issue, but doesn't feel like the correct way to do it. I think it could lead to imperfections in the rendering, but I do not know much about this.

Ideally, the font would be aligned on the baseline, such that we would always subtract the baseline from the translation, but that would move existing text. Instead we can correct for the baseline change we observe.