dotted hfill (was: [cl-typesetting-devel] HTML rendering)
Klaus Weidner
kw at w-m-p.com
Wed Apr 21 05:25:48 UTC 2004
On Wed, Apr 21, 2004 at 12:28:39AM +0200, Marc Battyani wrote:
> Tomorrow I will try to find some time to look at the margin change for
> multiline entries.
I've only gotten it to do what I want with a really ugly hack - the hfill
added at the end of each left-justified line needed to be left out on the
last line, otherwise the leader at that place didn't reach to the right
margin. I didn't see an obvious way to prevent the hfill from being
attached, so I got violent and added an extraction routine ;-)
Also, I've hacked the enumerate function to be a bit smarter, so that it
lines up the margins properly. To support that, I added a
put-filled-string function which aligns a string within a predefined
horizontal area. That also took some hacking - I may have missed some
obvious solution. Putting real boxes inline messed up the formatting...
Lastly, I've experimented with tables a bit - is it currently really
required to explicitly specify column widths? If so, making that dynamic
would be a fairly important project.
I've attached the current output of the XHTML converter, which is
starting to look promising. Still missing are strikethrough and
underline, which I'm too tired to figure out how to implement.
One more thing, is there some easy way to handle widow/orphan prevention
automatically, i.e. by specifying a 'badness' in the interline vspace?
-Klaus
-------------- next part --------------
diff -urN orig/cl-typesetting/layout.lisp cl-typesetting/layout.lisp
--- orig/cl-typesetting/layout.lisp Tue Apr 20 17:16:58 2004
+++ cl-typesetting/layout.lisp Tue Apr 20 19:42:51 2004
@@ -90,7 +90,7 @@
(if line-boxes
(let ((text-line (make-instance 'text-line :dx dx :adjustable-p t)))
(setf line-boxes (boxes-left-trim line-boxes))
- (when (member *h-align* '(:center :left))
+ (when (member *h-align* '(:center :left :left-not-last))
(push (make-hfill-glue) line-boxes))
(unless (zerop *right-margin*)
(push (make-instance 'h-spacing :dx *right-margin*) line-boxes))
@@ -130,7 +130,15 @@
(push box text-lines))
((and trimming (trimmable-p box)) nil)
((eq box :eol)
- #+nil(when (eq *h-align* :justified)
+ (when (eq *h-align* :left-not-last)
+ ;; incredibly ugly hack - need to get rid of the
+ ;; superfluous box added on the last line.
+ (let ((fbox (find-if (lambda (box)
+ (and (typep box 'h-spacing)
+ (eql (expansibility box) +huge-number+)))
+ line-boxes)))
+ (if fbox (setq line-boxes (remove fbox line-boxes)))))
+ (when (eq *h-align* :justified)
(push (make-hfill-glue) line-boxes))
(next-line line-boxes))
((eq box :fresh-page)
diff -urN orig/cl-typesetting/typo.lisp cl-typesetting/typo.lisp
--- orig/cl-typesetting/typo.lisp Tue Apr 20 17:16:58 2004
+++ cl-typesetting/typo.lisp Tue Apr 20 23:20:28 2004
@@ -216,8 +216,8 @@
(add-box (make-char-box char))
(add-box (make-inter-char-glue))))))))
-;;; put a string in a 'verbatim' way: no kerning, no hyphenation, significant whitespaces, significant newlines
(defun verbatim (string)
+ "put a string in a 'verbatim' way: no kerning, no hyphenation, significant whitespaces, significant newlines"
(when (stringp string)
(loop for char across string
for i from 0
@@ -228,6 +228,18 @@
(t (add-box (make-char-box char))
(add-box (make-inter-char-glue)))))))
+(defun put-filled-string (string width &key (align :left))
+ "place aligned string in fixed-width space"
+ (let* ((string-width
+ (loop for char across string
+ summing (pdf:get-char-width char *font* *font-size*)))
+ (blank (- width string-width)))
+ (case align
+ ((:left) (verbatim string) (hspace blank))
+ ((:center)
+ (hspace (* 0.5 blank)) (verbatim string) (hspace (* 0.5 blank)))
+ ((:right) (hspace blank) (verbatim string)))))
+
(defun new-line ()
(add-box :eol))
@@ -363,13 +375,19 @@
(defvar %enumerate-indents% nil)
-(defmacro enumerate ((&key (indent 20) (item-fmt "~D. "))
+(defmacro enumerate ((&key (indent 20)
+ text-style
+ (item-fmt "~D. ")
+ (start-from 1)
+ item-style)
&body body)
`(let ((%enumerate-indents% (cons ,indent %enumerate-indents%)))
,@(loop for item in body
- for i from 1 collect
+ for i from start-from collect
`(paragraph (:left-margin (reduce #'+ %enumerate-indents%)
- :first-line-indent (- 4)
- ,@(cadr item))
- ,(format nil item-fmt i)
- ,@(cddr item)))))
+ :first-line-indent (- ,indent)
+ , at text-style)
+ (with-style ,item-style
+ (put-filled-string ,(format nil item-fmt i)
+ ,indent :align :right))
+ ,item))))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: output.pdf
Type: application/pdf
Size: 19499 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/cl-typesetting-devel/attachments/20040421/6c230aa2/attachment.pdf>
More information about the cl-typesetting-devel
mailing list