File: infrastructure.lisp

package info (click to toggle)
cl-typesetting 157-3
  • links: PTS
  • area: non-free
  • in suites: lenny
  • size: 836 kB
  • ctags: 537
  • sloc: lisp: 4,534; makefile: 33; sh: 22
file content (126 lines) | stat: -rw-r--r-- 4,932 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
(in-package :cl-pdf-doc)
;;; cl-pdf-doc copyright 2007 Brian Sorg see license.txt for the details
;;; You can reach me at brian.sorg@liberatinginsight.com
;;; The homepage of cl-pdf-doc is here: http://www.liberatinginsight.com/open-projects.html"

(defmacro chapter ((title &key (outline-name title)) &body body)
  "Sets up a block of code that will represent a chapter in the documentation. 
Title - Is the title of the chapter
Outline-name - is the pdf bookmark name
Body - Chapter Contents"
  `(let ((content (tt:compile-text 
		      ()
		    (pdf:with-outline-level (,outline-name (pdf:register-page-reference))
		      (header ,title 1)
		      ,@body)
		    (tt:new-page))))
    (tt:draw-pages  content :margins *doc-margins* :header (generate-header) :footer (generate-footer)
     :size (rest (assoc :letter tt::+paper-sizes+)))))

(defmacro outline-header ((header-string &key (header-size 1) (outline-name header-string)) &body body)
  "Header for the text that will be registered in the pdf bookmarks outline section"
  `(pdf:with-outline-level (,outline-name (pdf:register-page-reference))
    (header ,header-string ,header-size)
    ,@body))

(defmacro header (header-string header-size)
  "Header Block of Text
Header-Size - Relates to the importance of the header. 1 Signals the most important, larger numbers drop in significance"
  `(tt:paragraph (:font "Helvetica-Bold" :font-size (get-header-font ,header-size))
    (tt:vspace 5)
    ,header-string 
    (tt:vspace 5)))

(defmacro body-text (&body body)
  "Normal Body Text"
  `(tt:paragraph (:font "Helvetica" :font-size 10 :top-margin 3 :bottom-margin 3)
    ,@body))

(defmacro code-text ((&optional (title "Code Example")) &body body)
  "Verbatim Lisp code text"
  `(progn 
    (tt:paragraph (:font "Helvetica" :font-size 10 :top-margin 10  :left-margin 36 :right-margin 36)
      (tt:verbatim ,@body))
    (tt:paragraph (:font "Helvetica-Bold" :font-size 10 :h-align :center :left-margin 36 :right-margin 36 :bottom-margin 10)
      ,title)))

(defmacro quote-block (&body body)
  "Block of text which is set apart by font type and extra indentation"
  `(tt:paragraph (:font "Times-Roman" :font-size 10 :top-margin 5 :bottom-margin 5 :left-margin 36 :right-margin 36)
    ,@body))

(defmacro highlight (&body body)
  "Place body text inline in bold"
  `(tt:with-style (:font "Helvetica-Bold" :font-size 10)
    ,@body))

(defmacro emphasize (&body body)
  "Place body test inline in italics"
  `(tt:with-style (:font "Helvetica-Oblique" :font-size 10)
    ,@body))

(defun definition-table (definition-lists)

  (tt:table (:col-widths '(36 150 300) :border 0 :splittable-p t)
    (dolist (def definition-lists)
      (tt:row ()
	(tt:cell () (tt:put-string ""))
	(tt:cell () (highlight (tt:put-string (first def))))
	(tt:cell () (body-text (tt:put-string (second def))))))))

(defun get-header-font (size)
  "Given a default size return the documents font size"
  (case size
    (1 18)
    (2 16)
    (3 14)
    (4 12)
    (5 10)))

(defun generate-header ()
  "Page Header Code"
  (tt:compile-text 
      ()
    (tt:paragraph (:h-align :center
				 :font "Helvetica-BoldOblique" :font-size 14)
      "Cl-Pdf Documentation - Version 0.1" :eol
      (tt:vspace 2)
      (tt:hrule :dy 1))))

(defun generate-footer ()
  "Page Footer Code"
  (let* ((print-stamp (multiple-value-bind (second minute hour date month year)
			  (get-decoded-time)
			(declare (ignore second minute hour))
			(format nil "Generated on ~4D-~2,'0D-~2,'0D" 
				year month date))))
    (lambda (pdf:*page*)
      (tt:compile-text 
	  (:font "Helvetica" :font-size 10)
	(tt:paragraph (:h-align :center  :font "Helvetica" :font-size 10)
	  (tt:hrule :dy 1)
	  (tt:vspace 2)
	  (tt:put-string "Brian Sorg, Founder Liberating Insight LLC") :eol
	  (tt:put-string "Copyright Fort Wayne IN USA 2007"):eol
	  (tt:verbatim print-stamp)
	  (tt:verbatim 
	   (format nil "   Page ~a" pdf:*page-number*)))))))


(defmacro function-description ((name &key (type "function") (spec "()") (return-value "nil") (args nil)) &body description)
  "Macro to set up a macro or function description"
  (let ((line (gensym)))
    `(pdf:with-outline-level (,name (pdf:register-page-reference))
      (header (tt:put-string (string-upcase ,name)) 4)
      (header "Syntax" 5)
      (body-text ,type " " (highlight ,name) " " (emphasize ,spec) " ==> " ,return-value)
      (when ,args
	(header "Arguments" 5)
	(dolist (,line ,args)
	  (if (listp ,line)
	      (tt:paragraph (:font "Helvetica" :font-size 10 :left-margin 40)
		(emphasize (tt:put-string (first ,line))) (tt:put-string (format nil ": ~a" (second ,line))))
	      (tt:paragraph (:font "Helvetica" :font-size 10 :left-margin 20)
		(highlight (tt:put-string ,line))))))
      (header "Description" 5)
      ,@description)))