[cl-typesetting-devel] Page n of m?

Peter Seibel peter at javamonkey.com
Fri Oct 1 17:43:33 UTC 2004


"Marc Battyani" <marc.battyani at fractalconcept.com> writes:

> Marc Battyani wrote:
>> Peter Seibel <peter at javamonkey.com> writes:
>> >
>> > Okay, that makes sense. So is my workaround the Right Way or a nasty
>> > kludge?
>>
>> You really want to know ? ;-)
>>
>> I will have a deeper look at all this tomorow.
>
> I've looked at it. the reason why it worked well for me and not for you was
> because I used the reference in the text while you were using it only in the
> footer. It turn out that the footer can be called in a rather out of order
> way relative to the normal flow of the text (at stroking time). So the right
> way is to add a located-p to the ref class as a ref can be defined but not
> yet located when it is seen from a footer.
> I hope I'm clear enough. Anyway now Bob' example works.
>
> The new version is on the repositories.(get cl-pdf also)
> Please tell me if this works in your case now.

I haven't tried your new version yet because I had an idea last night
about what the problem might be. The thing that lead me down the path
to my workaround of yesterday was noticing that while my reference got
correctly located (page-number, x, and y set) in stroke, that on the
second pass it would get replaced by a new, unlocated reference when
mark-ref-point was called. My workaround was a kludge but I think the
idea was right--if mark-ref-point is called because a subsequent pass
is being processed (so the ref is not in *reference-table* but is in
*previous-reference-table*) then instead of making a new ref-point we
should copy the previous ref-point. Then the test in stroke to
determine whether the ref-point has been changed is more
straightforward--if the current values are different than the ones
actually stored in the reference it is changing. Below is a patch.
I'll revert this and try your new code but you can feel free to fold
it in if appropriate.

> Another nice stuff related to references is the contextual variables. Have
> you looked at it ?

Nope. Someday in my copious free time. ;-)

-Peter
-Peter


Index: references.lisp
===================================================================
--- references.lisp	(revision 63)
+++ references.lisp	(working copy)
@@ -18,31 +18,35 @@
    (y :accessor y :initform nil)))
 
 (defmethod stroke ((ref-point ref-point) x y)
-  (let ((previous-ref (and *previous-reference-table*
-			   (gethash (id ref-point) *previous-reference-table*)))
-	(page-number pdf:*page-number*))
-    (when (and previous-ref (/= page-number (page-number previous-ref)))
-      (push (id ref-point) *changed-references*))
-    (setf (page-number ref-point) page-number
-	  (x ref-point) x
-	  (y ref-point) y)))
+  (let ((page-number pdf:*page-number*))
+    (when (or (/= page-number (page-number ref-point))
+              (/= x (x ref-point))
+              (/= y (y ref-point)))
+      (push (id ref-point) *changed-references*)
+      (setf (page-number ref-point) page-number
+            (x ref-point) x
+            (y ref-point) y))))
 
 (defun mark-ref-point (id &rest args &key (type 'ref-point))
   (when (gethash id *reference-table*)
-    (error "Reference ~s redefined" id))
+    (error "Reference ~s redefined within single pass." id))
   (remf args :type)
-  (let* ((ref-point (apply #'make-instance type :id id args)))
+  (let* ((ref-point (or (find-previous-ref-point id)
+                        (apply #'make-instance type :id id args))))
     (setf (gethash id *reference-table*) ref-point)
     (add-box ref-point)))
 
 (defun find-ref-point (id)
   (let ((ref-point (or (gethash id *reference-table*)
-		       (and *previous-reference-table*
-			    (gethash id *previous-reference-table*)))))
+                       (find-previous-ref-point id))))
     (unless ref-point
       (pushnew id *undefined-references*))
     ref-point))
 
+(defun find-previous-ref-point (id)
+  (and *previous-reference-table*
+       (gethash id *previous-reference-table*)))
+
 (defun find-ref-point-page-number (id)
   (let ((ref-point (find-ref-point id)))
     (if ref-point



-- 
Peter Seibel                                      peter at javamonkey.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp




More information about the cl-typesetting-devel mailing list