File: boxes.lisp

package info (click to toggle)
cl-typesetting 117-3
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 808 kB
  • ctags: 508
  • sloc: lisp: 4,073; makefile: 33; sh: 22
file content (189 lines) | stat: -rw-r--r-- 4,122 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
;;; cl-typesetting copyright 2003-2004 Marc Battyani see license.txt for the details
;;; You can reach me at marc.battyani@fractalconcept.com or marc@battyani.net
;;; The homepage of cl-typesetting is here: http://www.fractalconcept.com/asp/html/cl-typesetting.html

(in-package typeset)

(defclass box ()
  ((dx :accessor dx :initform 0 :initarg :dx)
   (dy :accessor dy :initform 0 :initarg :dy)
   (baseline :accessor baseline :initform 0 :initarg :baseline)
   (offset :accessor offset :initform *offset* :initarg :offset)
   ))

(defmethod dx (box)
  0)

(defmethod (setf dx) (value box)
  value)

(defmethod dy (box)
  0)

(defmethod (setf dy) (value box)
  value)

(defmethod baseline (box)
  0)

(defmethod (setf baseline) (value box)
  value)

(defmethod offset (box)
  0)

(defmethod (setf offset) (value box)
  value)

(defclass h-mode-mixin ()
  ())

(defclass v-mode-mixin ()
  ())

(defmethod delta-size (obj)
  0)

(defmethod max-expansion (obj)
  0)

(defmethod expansibility (obj)
  0)

(defmethod max-compression (obj)
  0)

(defmethod compressibility (obj)
  0)

(defclass soft-box (box)
  ((delta-size :accessor delta-size :initform 0)
   (max-expansion :accessor max-expansion :initform 0 :initarg :max-expansion)
   (expansibility :accessor expansibility :initform 0 :initarg :expansibility)
   (max-compression :accessor max-compression :initform 0 :initarg :max-compression)
   (compressibility :accessor compressibility :initform 0 :initarg :compressibility)
   (locked :accessor locked :initform nil :initarg :locked)))

(defmethod locked (box)
  t)

(defmethod (setf locked) (value box)
  value)

(defclass container-box (soft-box)
  ((boxes :accessor boxes :initform nil :initarg :boxes)
   (adjustable-p :accessor adjustable-p :initform nil :initarg :adjustable-p)
   (internal-baseline :accessor internal-baseline :initform 0)))

(defclass vbox (container-box h-mode-mixin)
  ())

(defclass hbox (container-box v-mode-mixin)
  ())

(defclass glue (soft-box)
  ())

(defclass hglue (glue h-mode-mixin)
  ())

(defclass vglue (glue v-mode-mixin)
  ())

(defclass spacing (soft-box) ;; non trimmable white space
  ())

(defclass h-spacing (spacing h-mode-mixin) 
  ())

(defclass v-spacing (spacing v-mode-mixin)
  ())

(defclass char-box (box h-mode-mixin)
  ((boxed-char :accessor boxed-char :initform nil :initarg :boxed-char)))

(defclass white-char-box (hglue)
  ((trimmable-p :accessor trimmable-p :initform nil :initarg :trimmable-p)))

(defmethod soft-box-p (box)
  nil)

(defmethod soft-box-p ((box soft-box))
  t)

(defmethod char-box-p (box)
  nil)

(defmethod char-box-p ((box char-box))
  t)

(defmethod white-char-box-p (box)
  nil)

(defmethod white-char-box-p ((box white-char-box))
  t)

(defmethod trimmable-p (box)
  nil)

(defmethod trimmable-p ((box glue))
  t)

(defmethod white-space-p (box)
  nil)

(defmethod white-space-p ((box glue))
  t)

(defmethod white-space-p ((box spacing))
  t)

(defmethod hmode-p (box)
  nil)

(defmethod hmode-p ((box h-mode-mixin))
  t)

(defmethod vmode-p (box)
  nil)

(defmethod vmode-p ((box v-mode-mixin))
  t)

(defmethod adjust-box-dx (box dx baseline)
  nil)

(defmethod adjust-box-dx ((box hbox) dx baseline)
  (when (adjustable-p box)
    (setf (dx box) dx
	  (baseline box) baseline)))

(defmethod adjust-box-dy ((box vbox) dy baseline)
  (when (adjustable-p box)
    (setf (dy box) dy
	  (baseline box) baseline)))

(defmethod adjust-box-dy (box dy baseline)
  nil)

(defgeneric v-split (box dx dy)
 ;;; Split a v-mode box vertically into two parts
  ;; Args: dx - area width, dy - area height
  ;; Values: box-fitted, box-left, dy-left
 (:method ((box v-mode-mixin) dx dy)
  (declare (ignore dx))
  (if (> (dy box) dy)
      (values nil box dy)
      (values box nil (- dy (dy box))))))

(defgeneric boxes-left (content))

(defgeneric (setf boxes-left) (value content)
 (:method (value content)	; Do nothing if has already been adjusted by v-split.
  (declare (ignore content))
  value))

(defmethod print-object ((self char-box) stream)
  (print-unreadable-object (self stream :type t)
    (prin1 (boxed-char self) stream)))