Last active
September 14, 2015 05:10
-
-
Save pederkl/8ecd27034967f7a88de1 to your computer and use it in GitHub Desktop.
Example code showing weird word spacing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(in-package :cl-user) | |
(asdf:load-system "cl-pdf") | |
(asdf:load-system "cl-typesetting") | |
(defun test-linebreaks (&optional (data '("Here is a line with some descriptive text, enough that it needs to linewrap. Which means lots of text if we let it use the entire page width." | |
"Line with less text, but still seeing weird spacing."))) | |
(pdf:with-document () | |
(pdf:with-page () | |
(let* ((lines (tt:compile-text (:font-size 8) | |
(loop for line in data | |
do | |
(tt:format-string line) | |
(tt:new-line)))) | |
(lines-position '(36 557))) | |
; (break) | |
(tt::draw-block lines | |
(first lines-position) | |
(second lines-position) | |
(- (aref (pdf::bounds pdf::*page*) 2) | |
(first lines-position)) | |
(- (aref (pdf::bounds pdf::*page*) 3) | |
(second lines-position))))) | |
(pdf:write-document "/tmp/test-linebreaks.pdf"))) |
I think it's because there is no paragraph style specified. Wrapping the lines in a paragraph fixes the issue as text settings like justified, centered, etc. are paragraph settings.
So the following works for me:
(defun test-linebreaks (&optional (data '("Here is a line with some descriptive text, enough that it needs to linewrap. Which means lots of text if we let it use the entire page width."
"Line with less text, but still seeing weird spacing.")))
(pdf:with-document ()
(pdf:with-page ()
(let* ((lines (tt:compile-text ()
(tt:paragraph (:h-align :center :font-size 16)
(loop for line in data
do
(tt:format-string line)
(tt:new-line)))))
(lines-position '(36 557)))
; (break)
(tt::draw-block lines
(first lines-position)
(second lines-position)
(- (aref (pdf::bounds pdf::*page*) 2)
(first lines-position))
(- (aref (pdf::bounds pdf::*page*) 3)
(second lines-position)))))
(pdf:write-document "/tmp/test-linebreaks.pdf")))
I had to move the :font-size to the paragraph but it should have worked as a default setting as you wrote initially.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In the PDF file, it looks like
This, I have noe clue wether is correct or not, and I don't know cl-pdf or the PDF spec well enough to find out how this is generated and what it should have generated instead.