Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
% $Header: /cvsroot/html2ps/postscript/box.text.ps,v 1.1 2005/12/18 07:21:37 Konstantin Exp $
2
 
3
/box-text-create {                 % =>
4
  box-generic-inline-create
5
 
6
% setup box-specific properties
7
  dup /Text () put
8
  dup /Encoding ISOLatin1Encoding put
9
 
10
% setup inherited method references
11
  dup box-text-setup-methods
12
  dup /box-text add-type
13
} def
14
 
15
/box-text-draw-overline {         % => Text Box
16
  newpath
17
 
18
% Get the thickness of the font underline
19
 
20
  currentfont
21
  font-underline-thick             % => Text Box UThick
22
  setlinewidth                     % => Text Box
23
 
24
% Get the position of the font underline
25
  currentfont
26
  font-overline-pos               % => Text Box UPos
27
 
28
  1 index get-left
29
  2 index get-top
30
  3 index get-default-baseline
31
  sub                              % => Text Box UPos X Y'
32
% Note that UPos is negative
33
  2 index add                      % => Text Box UPos X Y'
34
 
35
  moveto
36
 
37
  1 index /get-width call-method
38
 
39
  rlineto
40
  stroke                           % => Text Box UPos
41
 
42
  pop pop pop
43
} def
44
 
45
/box-text-draw-line-through {      % => Text Box
46
  newpath
47
 
48
% Get the line thickness
49
 
50
  currentfont
51
  font-underline-thick             % => Text Box UThick
52
  setlinewidth                     % => Text Box
53
 
54
% Get the position of the font underline
55
  currentfont
56
  font-line-through-pos            % => Text Box UPos
57
 
58
  1 index get-left
59
  2 index get-top
60
  3 index get-default-baseline
61
  sub                              % => Text Box UPos X Y'
62
% Note that UPos is negative
63
  2 index add                      % => Text Box UPos X Y'
64
 
65
  moveto
66
 
67
  1 index /get-width call-method
68
 
69
  rlineto
70
  stroke                           % => Text Box UPos
71
 
72
  pop pop pop
73
} def
74
 
75
/box-text-draw-underline {         % => Text Box
76
  newpath
77
 
78
% Get the line thickness
79
 
80
  currentfont
81
  font-underline-thick             % => Text Box UThick
82
  setlinewidth                     % => Text Box
83
 
84
% Get the position of the font underline
85
  currentfont
86
  font-underline-pos               % => Text Box UPos
87
 
88
  1 index get-left
89
  2 index get-top
90
  3 index get-default-baseline
91
  sub                              % => Text Box UPos X Y'
92
% Note that UPos is negative
93
  2 index add                      % => Text Box UPos X Y'
94
 
95
  moveto
96
 
97
  1 index /get-width call-method
98
 
99
  rlineto
100
  stroke                           % => Text Box UPos
101
 
102
  pop pop pop
103
} def
104
 
105
/box-text-find-font {              % => Box
106
  dup /font-size get-css-value
107
 
108
  1 index
109
  /font-family get-css-value       % => Box FontSize FontFamily
110
  exch scalefont                   % => Box <<Font>>
111
 
112
  exch pop                         % => <<Font>>
113
} def
114
 
115
/box-text-get-min-width {          % => Context This
116
  dup get-full-width
117
  exch pop
118
  exch pop
119
} def
120
 
121
/box-text-get-max-width {          % => Context This
122
  dup get-full-width
123
  exch pop
124
  exch pop
125
} def
126
 
127
/box-text-reflow {                 % => Context Parent This
128
% Check if we need a line break here (possilble several times in a row, if we
129
% have a long word and a floating box intersecting with this word
130
 
131
% To prevent infinite loop, we'll use a limit of 100 sequental line feeds
132
 
133
 
134
   {
135
     1 add                         % => Context Parent This LFs'
136
 
137
     3 index
138
     3 index
139
     3 index
140
     /maybe-line-break
141
     call-method                   % => Context Parent This LFs Flag
142
 
143
     1 index 100 ge
144
     or {
145
       exit
146
     } if
147
   } loop                          % => Context Parent This LFs
148
   pop                             % => Context Parent This
149
 
150
% Determine the baseline position and height of the text-box using line-height CSS property
151
   dup box-generic-apply-line-height
152
 
153
% set default baseline
154
   dup get-default-baseline
155
   1 index put-baseline
156
 
157
% append current box to parent line box
158
   dup 2 index
159
   box-container-append-line       % => Context Parent This
160
 
161
% Determine coordinates of upper-left _margin_ corner
162
   1 index 1 index
163
   box-generic-guess-corner        % => Context Parent This
164
 
165
% Offset parent current X coordinate
166
   dup get-full-width
167
   2 index get-current-x
168
   add                             % => Context Parent This CX'
169
   2 index put-current-x           % => Context Parent This
170
 
171
% Extends parents height
172
   dup get-bottom-margin           % => Context Parent This BM
173
   2 index
174
   box-generic-extend-height       % => Context Parent This
175
 
176
% Update the value of current collapsed margin; pure text (non-span)
177
% boxes always have zero margin
178
 
179
   2 index context-pop-collapsed-margin
180
 
181
 
182
% Clear the stack
183
  pop pop pop
184
} def
185
 
186
/box-text-setup {                  % => Box
187
% select the font used to render current text box
188
  dup box-text-find-font           % => Box <<Font>>
189
 
190
  dup font-ascender                % => Box <<Font>> Ascender
191
  1 index font-descender           % => Box <<Font>> Ascender Descender
192
 
193
  3 2 roll
194
  setfont                          % => Box Ascender Descender
195
 
196
  1 index 3 index put-default-baseline
197
 
198
  add
199
% 1 index /font-size get-css-value min
200
  1 index put-height               % => Box
201
 
202
% determine the width of the current text box
203
  dup get-text stringwidth         % => Box SX __
204
  pop                              % => Box SX
205
  1 index put-width                % => Box
206
 
207
  pop
208
} def
209
 
210
/box-text-setup-methods {          % => Box
211
% Setup method references
212
  dup get-box-dict /Methods get    % => Box Methods
213
  dup /get-min-width {box-text-get-min-width} put
214
  dup /get-max-width {box-text-get-max-width} put
215
  dup /reflow        {box-text-reflow} put
216
  dup /show          {box-text-show} put
217
  pop pop
218
} def
219
 
220
/box-text-show {                   % => Viewport Box
221
% Check if current text box will be cut-off by the page edge
222
% Get Y coordinate of the top edge of the box
223
  dup get-top-margin               % => Viewport Box Top
224
 
225
% Get Y coordinate of the bottom edge of the box
226
  1 index get-bottom-margin        % => Viewport Box Top Bottom
227
 
228
  1 index
229
  4 index viewport-get-bottom
230
  gt                               % => Viewport Box Top Bottom TopInside
231
 
232
  1 index
233
  5 index viewport-get-bottom
234
  gt                               % => Viewport Box Top Bottom TopInside BottomInside
235
 
236
  2 copy
237
  not and                          % => Viewport Box Top Bottom TopInside BottomInside TopInside&&!BottomInside
238
  {                                % => Viewport Box Top Bottom TopInside BottomInside
239
% If yes, do not draw current text box at all; add an required value
240
% to the viewport page offset to make the text box fully visible on the next page
241
    5 index
242
    viewport-get-offset-delta      % => Viewport Box Top Bottom TopInside BottomInside OD
243
 
244
    4 index
245
    7 index viewport-get-bottom
246
    sub                            % => Viewport Box Top Bottom TopInside BottomInside OD ODNew
247
    max                            % => Viewport Box Top Bottom TopInside BottomInside OD'
248
 
249
    6 index
250
    viewport-put-offset-delta      % => Viewport Box Top Bottom TopInside BottomInside
251
 
252
    pop pop
253
  } {                              % => Viewport Box Top Bottom TopInside BottomInside
254
    or not {                       % => Viewport Box Top Bottom
255
    } {                            % => Viewport Box Top Bottom
256
% draw generic box
257
      3 index 3 index
258
      box-generic-show
259
 
260
      2 index get-left
261
      3 index get-top
262
      4 index get-default-baseline
263
      sub
264
      moveto
265
 
266
      2 index get-text             % => Viewport Box Top Bottom Text
267
 
268
      3 index
269
      box-text-find-font            % => Viewport Box Top Bottom Text <<Font>>
270
      setfont
271
      show                         % => Viewport Box Top Bottom
272
 
273
% draw text decoration
274
      2 index /text-decoration get-css-value
275
      3 index get-text             % => Viewport Box Top Bottom Decoration Text
276
% underline
277
      1 index /underline get {     % => Viewport Box Top Bottom Decoration Text
278
        dup
279
        5 index                    % => Viewport Box Top Bottom Decoration Text Text Box
280
        box-text-draw-underline    % => Viewport Box Top Bottom Decoration Text
281
      } if
282
 
283
% overline
284
      1 index /overline get {      % => Viewport Box Top Bottom Decoration Text
285
        dup
286
        5 index                    % => Viewport Box Top Bottom Decoration Text Text Box
287
        box-text-draw-overline     % => Viewport Box Top Bottom Decoration Text
288
      } if
289
 
290
% line-through
291
      1 index /line-through get {  % => Viewport Box Top Bottom Decoration Text
292
        dup
293
        5 index                    % => Viewport Box Top Bottom Decoration Text Text Box
294
        box-text-draw-line-through % => Viewport Box Top Bottom Decoration Text
295
      } if
296
 
297
      pop pop
298
    } ifelse
299
  } ifelse                         % => Viewport Box Top Bottom
300
 
301
  pop pop pop pop
302
} def
303
 
304
/get-encoding {
305
  /Encoding get
306
} def
307
 
308
/get-text {                        % => Box
309
  /Text get
310
} def
311
 
312
/put-encoding {                    % => Encoding Box
313
  exch
314
  /Encoding
315
  exch
316
  put
317
} def
318
 
319
/put-text {                        % => Text Box
320
  exch
321
  /Text
322
  exch
323
  put
324
} def
325
 
326
%%%%%%%%%%%%%%%%%%%%
327
 
328
/show-enc-text-box {
329
% Check if this box will be cut on the bottom edge of the page (i.e. bottom < 0)
330
  dup get-bottom bmargin gt {
331
    show-enc-text-box-force
332
  } {
333
% do not display this box; also, store the additional offset to show this text on the next page
334
    /vdelta vdelta 2 index get-top bmargin sub max def
335
    pop
336
  } ifelse
337
} def
338
 
339
/show-enc-text-box-force {         % => Box
340
  show-generic-box                 % => Box
341
  currentpoint
342
  2 index get-content              % => Box X Y Content
343
  aload pop
344
  show-enc-text
345
  moveto
346
 
347
  dup get-text-decoration          % => Box Decor
348
  dup /Underline known {
349
    currentpoint
350
    3 index get-content            % => Box Decor X Y [Text <<Font>>]
351
    aload pop pop
352
    draw-underline
353
    moveto
354
  } if
355
 
356
  dup /Overline known {
357
    currentpoint
358
    3 index get-content
359
    aload pop pop
360
    draw-overline
361
    moveto
362
  } if
363
 
364
  dup /Line-Through known {
365
    currentpoint
366
    3 index get-content
367
    aload pop pop
368
    draw-line-through
369
    moveto
370
  } if
371
 
372
  pop                              % => Box
373
 
374
} def
375
 
376
/show-enc-text {                   % => Text <<Font>>
377
  setfont                          % => Text
378
  show                             % =>
379
} def