File: test-table.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 (101 lines) | stat: -rw-r--r-- 4,188 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
(in-package :cl-user)

(defun test-table (&optional (file (lw:current-pathname "test-table.pdf"))
                   &aux content table (margins '(72 72 72 50)))
  (let* ((tt:*default-font* (pdf:get-font "Helvetica"))
         (tt:*default-font-size* 10)
         (row-height nil))
   (tt:with-document ()
    (setq content (tt:compile-text (:font tt:*default-font*
                                    :font-size tt:*default-font-size*)
     (tt:paragraph () "Test table spans and borders")
     (tt:table (:col-widths '(20 40 60 80 120) :background-color :yellow :border 1)
       (tt:header-row ()
         (tt:cell (:col-span 5)
           (tt:paragraph (:h-align :center :font-size 12)
             "Table with cells spanning more then one row or column")))
       (tt:row (:background-color :green)
         (tt:cell (:row-span 2 :background-color :blue)
           "1,1 2,1  row-span 2")
         (tt:cell () "1,2")
         (tt:cell (:col-span 2 :row-span 3 :background-color :red)
           "1,3 1,4 - 3,3 3,4  col-span 2 row-span 3")
         (tt:cell () "1,5"))
       (tt::row ()
         (tt:cell () "2,2")
         (tt:cell (:row-span 2 :background-color :blue) "2,5 3,5  row-span 2"))
       (tt:row (:background-color :green)
         (tt:cell (:col-span 2) "3,1 3,2  col-span 2"))
       (tt::row ()
         (tt:cell () "4,1")
         (tt:cell () "4,2")
         (tt:cell () "4,3")
         (tt:cell () "4,4")
         (tt:cell () "4,5")))

    (setq table
     (tt:table (:col-widths '(50 40 60 80 120) :border 0)
       (tt:header-row ()
         (tt:cell (:col-span 0 :border 1)
           (tt:paragraph (:h-align :centered :font-size 12)
             "Cells with borders. Header row cell  col-span 0")))
       (tt:row (:background-color :green)
         (tt:cell (:row-span 2 :background-color :blue)
           "1,1 2,1  row-span 2")
         (tt:cell () "1,2")
         (tt:cell (:col-span 2 :row-span 3 :background-color :red)
           "1,3 1,4 - 3,3 3,4  col-span 2 row-span 3")
         (tt:cell () "1,5"))
       (tt:row ()
         (tt:cell (:border 2) "2,2")
         (tt:cell (:row-span 2 :background-color :blue) "2,5 3,5  row-span 2"))
       (tt:row (:background-color :green)
         (tt:cell (:col-span 2 :border 2) "3,1 3,2  col-span 2"))
       (tt:row ()
         (tt:cell (:border #(3 0 0 0)) "4,1 left-border 3")
         (tt:cell (:border #(0 3 0 0)) "4,2 top-border 3")
         (tt:cell (:border #(2 2 2 2)) "4,3 border #(2 2 2 2)")
         (tt:cell (:border #(0 0 3 0)) "4,4 right-border 3")
         (tt:cell (:border #(0 0 0 3)) "4,5 bottom-border 3"))
       (tt:footer-row ()
         (tt:cell (:col-span 5 :border '(0 1/4))
           (tt:paragraph (:h-align :justified :font-size 12)
             "footer" :hfill "cell" :hfill "spanning" :hfill "several" :hfill "columns")))))
   
     (tt:table (:col-widths '(60 60 60 60 60) :border 1)
       (tt:row (:height row-height)
         (tt:cell (:row-span 2) "1,1 2,1  row-span 2")
         (tt:cell () "1,2")
         (tt:cell () "1,3")
         (tt:cell (:col-span 0) "1,4 1,5  col-span 0"))
       (tt::row (:height row-height)
         (tt:cell (:row-span 3) "2,2 3,2 4,2  row-span 3")
         (tt:cell () "2,3")
         (tt:cell (:col-span 0 :row-span 0) "2,4 - 4,5  col-span 0 row-span 0"))
       (tt:row (:height row-height)
         (tt:cell (:row-span 0) "3,1 4,1  row-span 0")
         (tt:cell () "3,3"))
       (tt:row (:height row-height)
         (tt:cell () "4,3")))

     (tt:table (:col-widths '(60 60 60) :border 1)
       (tt:row (:height row-height)
         (tt:cell (:row-span 2) "1,1 2,1  row-span 2")
         (tt:cell () "1,2")
         (tt:cell () "1,3"))
       (tt::row (:height row-height)
         (tt:cell (:row-span 3) "2,2 3,2 4,2  row-span 3")
         (tt:cell () "2,3"))
       (tt:row (:height row-height)
         (tt:cell (:row-span 2) "3,1 4,1  row-span 2")
         (tt:cell () "3,3"))
       (tt:row (:height row-height)
         (tt:cell () "4,3")))
    ))
    (tt::draw-pages content :margins margins :break :after)
    (pdf:write-document file)))
 table)

;(pdf:load-fonts)
;(setq pdf:*compress-streams* nil)
;(setq table (test-table))