[cl-pdf-devel] Simple patch for draw-...-text
Andrey Moskvitin
archimag at gmail.com
Thu Mar 26 10:11:47 UTC 2009
Hi,
I need to draw text in bounded rect. However, functions of draw-...- text
does not allow it. So, I made minor changes in this functions.
Here is my patch:
diff --git a/text.lisp b/text.lisp
index 8fbddf3..30736bd 100644
--- a/text.lisp
+++ b/text.lisp
@@ -36,36 +36,39 @@ with Lisps that read source files in UTF-8 encoding.")
finally (push (string-trim *delimiter-chars* (subseq string
start)) result))
(nreverse result))))
-(defun draw-centered-text (x y string font font-size &optional max-width)
+(defun draw-centered-text (x y string font font-size &optional max-width
max-height)
(pdf:in-text-mode
(pdf:move-text x y)
(pdf:set-font font font-size)
(loop with dy = (* -1.2 font-size)
for (str . rest) on (if max-width (split-text string font font-size
max-width) (list string))
+ for line-count from 0 while (if max-height (> max-height (* -1 dy
line-count)) t)
for last-x = 0 then offset
for offset = (* -0.5 (text-width str font font-size)) do
(move-text (- offset last-x) 0)
(show-text str)
(when rest (pdf:move-text 0 dy)))))
-(defun draw-left-text (x y string font font-size &optional max-width)
+(defun draw-left-text (x y string font font-size &optional max-width
max-height)
(pdf:in-text-mode
(pdf:move-text x y)
(pdf:set-font font font-size)
(loop with dy = (* -1.2 font-size)
for (str . rest) on (if max-width (split-text string font font-size
max-width) (list string))
+ for line-count from 0 while (if max-height (> max-height (* -1 dy
line-count)) t)
for last-x = 0 then offset
for offset = (- (text-width str font font-size)) do
(move-text (- offset last-x) 0)
(show-text str)
(when rest (pdf:move-text 0 dy)))))
-(defun draw-right-text (x y string font font-size &optional max-width)
+(defun draw-right-text (x y string font font-size &optional max-width
max-height)
(pdf:in-text-mode
(pdf:move-text x y)
(pdf:set-font font font-size)
(loop with dy = (* -1.2 font-size)
for (str . rest) on (if max-width (split-text string font font-size
max-width) (list string))
+ for line-count from 0 while (if max-height (> max-height (* -1 dy
line-count)) t)
do
(show-text str)
(when rest (move-text 0 dy)))))
Moskvitin Andrey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cl-pdf-devel/attachments/20090326/aa474869/attachment.html>
More information about the cl-pdf-devel
mailing list