Skip to content

Commit

Permalink
Add inravina-examples system
Browse files Browse the repository at this point in the history
  • Loading branch information
yitzchak committed Jul 5, 2023
1 parent aa13985 commit 83409c0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
3 changes: 3 additions & 0 deletions code/examples/packages.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(defpackage #:inravina-examples
(:use #:common-lisp)
(:export #:pprint-pdf))
35 changes: 13 additions & 22 deletions examples/pdf.lisp → code/examples/pdf.lisp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
(ql:quickload :cl-pdf)
(ql:quickload :inravina/intrinsic)
(in-package #:inravina-examples)

(defclass pdf-stream (trivial-gray-streams:fundamental-character-output-stream)
((line :accessor line
Expand All @@ -22,24 +21,20 @@

(defmethod trivial-stream-column:stream-measure-string ((stream pdf-stream) string &optional start end style)
(declare (ignore stream style))
(print "d")
(measure-string (subseq string (or start 0) end)))

(defmethod trivial-stream-column:stream-measure-char ((stream pdf-stream) char &optional style)
(declare (ignore stream style))
(print "c")
(measure-char char))

(defmethod trivial-gray-streams:stream-terpri ((stream pdf-stream))
(print "b")
(pdf:move-text (* (- (indent stream)) (em-size))
(* pdf::*font-size* -1.2))
(incf (line stream))
(setf (column stream) 0
(indent stream) 0))

(defmethod trivial-gray-streams:stream-advance-to-column ((stream pdf-stream) column)
(print "a")
(unless (zerop column)
(pdf:move-text (* column (em-size))
0)
Expand All @@ -57,21 +52,17 @@
string)

(defmethod trivial-gray-streams:stream-line-column ((stream pdf-stream))
(print "e")
(column stream))

(pdf:with-document ()
(pdf:with-page ()
(pdf:with-outline-level ("Example" (pdf:register-page-reference))
(let ((helvetica (pdf:get-font "Helvetica"))
(*print-pretty* t))
(pdf:in-text-mode
(pdf:move-text 100 800)
(pdf:set-font helvetica 12.0)
(pdf:set-text-leading (* 1.2 12.0))
(pprint '(when (quux 'a)
(loop for i in '(1 2 3)
do (print i) (wibble i) collect i)
(write-line "gronk"))
(make-instance 'pdf-stream))))))
(pdf:write-document #P"t.pdf"))
(defun pprint-pdf (form path &key (font "Helvetica"))
(pdf:with-document ()
(pdf:with-page ()
(pdf:with-outline-level ("Example" (pdf:register-page-reference))
(let ((helvetica (pdf:get-font font))
(*print-pretty* t))
(pdf:in-text-mode
(pdf:move-text 100 800)
(pdf:set-font helvetica 12.0)
(pdf:set-text-leading (* 1.2 12.0))
(incless-extrinsic:pprint form (make-instance 'pdf-stream))))))
(pdf:write-document path)))
13 changes: 13 additions & 0 deletions inravina-examples.asd
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(in-package #:asdf-user)

(defsystem "inravina-examples"
:description "Inravina Examples"
:author "Tarn W. Burton"
:license "MIT"
:depends-on ("cl-pdf"
"inravina-extrinsic")
:components ((:module "code"
:pathname "code/examples/"
:serial t
:components ((:file "packages")
(:file "pdf")))))

0 comments on commit 83409c0

Please sign in to comment.