Hi,<br>
<br>
<div style="text-align: left;" dir="ltr">I apologize for the long silence, was strongly engaged.<div class="im"><br><br><font size="-1"><font face="Helvetica, Arial, sans-serif">> Anyway, it's an interesting feature so could you rework its
implementation?</font></font><br></div></div>
Well, I agree, this is a new version.<br>
<br>
Andrey<br>
<br>
---<br><div class="im"><br><span style="font-family: courier new,monospace;">diff --git a/text.lisp b/text.lisp</span><br style="font-family: courier new,monospace;">
</div>
<span style="font-family: courier new,monospace;">index 8fbddf3..4c695d4 100644</span>
<div class="im"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">--- a/text.lisp</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+++ b/text.lisp</span><br style="font-family: courier new,monospace;"></div>
<span style="font-family: courier new,monospace;">@@ -16,56 +16,71 @@ with Lisps that read source files in UTF-8 encoding.")</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">
(loop for c across string</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> summing (get-char-width c font font-size)))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">-(defun split-text (string font font-size max-width)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">- (if (> (* 2 (get-char-width #\M font font-size)) max-width)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">- (loop for c across string</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">
- collect (make-string 1 :initial-element c))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">- (let ((width 0)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">- (start 0)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">- (result ()))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">- (loop for i from 0</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">- for c across string</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">- for d = (get-char-width c font font-size) do</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">
- (if (or (char= c #\Newline)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">- (char= c +section-char+)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">- (> (+ width d) max-width))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">- (progn </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">- (push (string-trim *delimiter-chars* (subseq string start i)) result)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">
- (setf start i width 0))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">- (incf width d))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">- finally (push (string-trim *delimiter-chars* (subseq string start)) result))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">- (nreverse result))))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+(defun split-text (string font font-size max-width &optional max-height)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">
+ (let ((max-line-number (if max-height </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+ (floor (+ max-height (* 0.2 font-size))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+ </span><span style="font-family: courier new,monospace;"> (* 1.2 font-size))))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+ (current-line-number 1))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+ (flet ((check-max-number-of-lines ()</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">
+ (and max-line-number</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+ (< max-line-number</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+ (prog1</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+ current-line-number</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+ (incf current-line-number))))))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">
+ (if (> (* 2 (get-char-width #\M font font-size)) max-width)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+ (loop for c across string</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+ until (check-max-number-of-lines)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+ collect (string c))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+ (let ((width 0)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">
+ (start 0)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+ (result ()))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+ (loop with max-number-of-lines = (and max-line-number (< max-line-number current-line-number))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+ until max-number-of-lines</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">
+ for i from 0</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+ for c across string</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+ for d = (get-char-width c font font-size) do </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+ (if (or (char= c #\Newline)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+ (char= c +section-char+)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">
+ (> (+ width d) max-width))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+ (progn </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+ (push (string-trim *delimiter-chars* (subseq string start i)) result)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+ (setf start i width 0)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">
+ (setf max-number-of-lines (check-max-number-of-lines)))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+ (incf width d))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+ finally (unless max-number-of-lines</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+ (push (string-trim *delimiter-chars* (subseq string start)) result)))</span>
<div class="im"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">
+ (nreverse result))))))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">-(defun draw-centered-text (x y string font font-size &optional max-width)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+(defun draw-centered-text (x y string font font-size &optional max-width max-height)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (pdf:in-text-mode</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">
(pdf:move-text x y)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (pdf:set-font font font-size)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (loop with dy = (* -1.2 font-size)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">- for (str . rest) on (if max-width (split-text string font font-size max-width) (list string))</span><br style="font-family: courier new,monospace;"></div>
<span style="font-family: courier new,monospace;">+ for (str . rest) on (if max-width (split-text string font font-size max-width max-height) (list string))</span>
<div class="im"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">
for last-x = 0 then offset</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> for offset = (* -0.5 (text-width str font font-size)) do</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (move-text (- offset last-x) 0)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (show-text str)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (when rest (pdf:move-text 0 dy)))))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">-(defun draw-left-text (x y string font font-size &optional max-width)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
+(defun draw-left-text (x y string font font-size &optional max-width max-height)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (pdf:in-text-mode</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (pdf:move-text x y)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (pdf:set-font font font-size)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (loop with dy = (* -1.2 font-size)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">- for (str . rest) on (if max-width (split-text string font font-size max-width) (list string))</span><br style="font-family: courier new,monospace;">
</div>
<span style="font-family: courier new,monospace;">
+ for (str . rest) on (if max-width (split-text string font font-size max-width max-height) (list string))</span>
<div class="im"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> for last-x = 0 then offset</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> for offset = (- (text-width str font font-size)) do</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (move-text (- offset last-x) 0)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">
(show-text str)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (when rest (pdf:move-text 0 dy)))))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">-(defun draw-right-text (x y string font font-size &optional max-width)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+(defun draw-right-text (x y string font font-size &optional max-width max-height)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
(pdf:in-text-mode</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (pdf:move-text x y)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (pdf:set-font font font-size)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (loop with dy = (* -1.2 font-size)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">- for (str . rest) on (if max-width (split-text string font font-size max-width) (list string))</span><br style="font-family: courier new,monospace;">
</div>
<span style="font-family: courier new,monospace;">
+ for (str . rest) on (if max-width (split-text string font font-size max-width max-height) (list string))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> do</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (show-text str)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (when rest (move-text 0 dy)))))</span><br><br><br><div class="gmail_quote">2009/3/29 Marc Battyani <span dir="ltr"><<a href="mailto:marc.battyani@fractalconcept.com">marc.battyani@fractalconcept.com</a>></span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div bgcolor="#ffffff" text="#000000">
<font size="-1"><font face="Helvetica, Arial, sans-serif">Hi Andrey,<br>
<br>
This is a very good idea but I think it needs some polish. :)<br>
<br>
Having a while clause before for clauses is not compliant even if most
loop implementations are OK with this.<br>
<br>
Using a line count and then multiplying by dy at each iteration is not
very efficient, it would be better to have a current-height and add dy
at each iteration or even simply to substract dy from max-height until
it goes negative (with a default huge value for max-height)<br>
<br>
BTW as the draw-...-text functions all call split text, in fact it
would be much more efficient to limit the number of lines directly in
split-text. After all what is the point of splitting a text in n lines
if we only want 2 lines for instance.<br>
<br>
Anyway, it's an interesting feature so could you rework its
implementation?<br>
<br>
Thanks,<br>
<br>
Marc </font></font><br></div></blockquote></div><br>