Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
/add-child {
2
  1 index /add-child call-method
3
} def
4
 
5
/box-container-add-child {         % => Child This
6
  dup 2 index put-parent           % => Child This
7
 
8
  1 index
9
  1 index get-content              % => Child This Child Content
10
  array-prepend                    % => Child This Content'
11
  1 index put-content
12
 
13
  pop pop
14
} def
15
 
16
/box-container-add-deferred-float {% => Float This
17
  dup /DeferredFloats get          % => Float This DeferredFloats
18
  2 index exch array-prepend       % => Float This Floats
19
  1 index exch
20
  /DeferredFloats exch
21
  put                              % => Float This
22
  pop pop
23
} def
24
 
25
/box-container-append-line {       % => Child This
26
  exch
27
  1 index get-line                 % => Parent Child PLine
28
  array-prepend
29
  exch put-line
30
} def
31
 
32
/box-container-calculate-text-indent {
33
                                   % => This
34
  dup /text-indent get-css-value   % => This TextIndent
35
 
36
  dup /Percentage get {
37
    /Value get
38
    1 index /get-width call-method mul 100 div
39
  } {
40
    /Value get
41
  } ifelse                         % => This Value
42
 
43
  exch pop
44
} def
45
 
46
/box-container-clear-deferred-floats {
47
  get-box-dict [] /DeferredFloats put
48
} def
49
 
50
/box-container-clear-line {        % => Box
51
  [] exch put-line
52
} def
53
 
54
/box-container-close-line {        % => Context This
55
  false 2 index 2 index
56
  box-container-close-line-common  % => Context This
57
  pop pop
58
} def
59
 
60
/box-container-close-last-line {   % => Context This
61
  true 2 index 2 index
62
  box-container-close-line-common  % => Context This
63
  pop pop
64
} def
65
 
66
/box-container-close-line-common { % => IsLastLine Context This
67
% Align line-box using 'text-align' property
68
 
69
% Note that text-align should not be applied to the block boxes!
70
% As block boxes will be alone in the line-box, we can check
71
% if the very first box in the line is inline; if not - no justification should be made
72
  dup get-line dup length 0 gt {   % => IsLastLine Context This Line
73
 
74
      dup /text-align get-css-value
75
      3 index exch                 % => IsLastLine Context This IsLastLine AlignFun
76
      3 index exch                 % => IsLastLine Context This IsLastLine Context AlignFun
77
      3 index exch                 % => IsLastLine Context This IsLastLine Context This AlignFun
78
      cvx exec                     % => IsLastLine Context This
79
    } {                            % => IsLastLine Context This
80
% Nevertheless, CENTER tag and P/DIV with ALIGN attribute set should affect the
81
% position of non-inline children.
82
      dup /pseudo-align get-css-value
83
      3 index exch                 % => IsLastLine Context This IsLastLine AlignFun
84
      3 index exch                 % => IsLastLine Context This IsLastLine Context AlignFun
85
      3 index exch                 % => IsLastLine Context This IsLastLine Context This AlignFun
86
      cvx exec
87
    } ifelse                       % => IsLastLine Context This
88
  } {
89
    pop
90
  } ifelse                         % => IsLastLine Context This
91
 
92
% Apply vertical align to all of the line content
93
% first, we need to aling all baseline-aligned boxes to determine the basic line-box height, top and bottom edges
94
% then, SUP and SUP positioned boxes (as they can extend the top and bottom edges, but not affected themselves)
95
% then, MIDDLE, BOTTOM and TOP positioned boxes in the given order
96
 
97
 
98
  2 index get-line {               % => IsLastLine Context This 0(Baseline) 0(Height) Child
99
    dup /vertical-align get-css-value
100
    /baseline eq {                 % => IsLastLine Context This Baseline Height Child
101
      dup get-default-baseline     % => IsLastLine Context This Baseline Height Child DefaultDaseline
102
      4 3 roll                     % => IsLastLine Context This Height Child DefaultDaseline Baseline
103
      max                          % => IsLastLine Context This Height Child Baseline'
104
      3 1 roll                     % => IsLastLine Context This Baseline' Height Child
105
    } if
106
    pop
107
  } forall                         % => IsLastLine Context This Baseline' Height
108
 
109
  2 index get-line {               % => IsLastLine Context This Baseline' Height Child
110
    dup /vertical-align get-css-value
111
    /baseline eq {                 % => IsLastLine Context This Baseline Height Child
112
      2 index 1 index put-baseline % => IsLastLine Context This Baseline Height Child
113
 
114
      dup get-baseline-offset
115
      1 index get-full-height add  % => IsLastLine Context This Baseline Height Child H+BO
116
      3 2 roll                     % => IsLastLine Context This Baseline Child Height H+BO
117
      max                          % => IsLastLine Context This Baseline Child Height'
118
      exch                         % => IsLastLine Context This Baseline Height' Child
119
    } if
120
    pop
121
  } forall                         % => IsLastLine Context This Baseline Height
122
 
123
% SUB vertical align
124
  2 index get-line {               % => IsLastLine Context This Baseline' Height Child
125
    dup /vertical-align get-css-value
126
    /sub eq {                      % => IsLastLine Context This Baseline Height Child
127
      2 index
128
      1 index get-full-height
129
      2 div                        % => IsLastLine Context This Baseline Height Child
130
      add
131
      1 index put-baseline
132
    } if
133
    pop
134
  } forall                         % => IsLastLine Context This Baseline Height
135
 
136
% SUPER vertical align
137
  2 index get-line {               % => IsLastLine Context This Baseline' Height Child
138
    dup /vertical-align get-css-value
139
    /super eq {                    % => IsLastLine Context This Baseline Height Child
140
      dup get-full-height 2 div    % => IsLastLine Context This Baseline Height Child BL
141
      1 index put-baseline
142
    } if
143
    pop
144
  } forall                         % => IsLastLine Context This Baseline Height
145
 
146
% MIDDLE vertical align
147
 
148
  3 index get-line {               % => IsLastLine Context This Baseline Height Middle Child
149
    dup /vertical-align get-css-value
150
    /middle eq {                   % => IsLastLine Context This Baseline Height Middle Child
151
      dup get-full-height 2 div    % => IsLastLine Context This Baseline Height Middle Child Middle
152
      3 2 roll                     % => IsLastLine Context This Baseline Height Child Middle Middle2
153
      max                          % => IsLastLine Context This Baseline Height Child Middle'
154
      exch                         % => IsLastLine Context This Baseline Height Middle Child
155
    } if
156
    pop
157
  } forall                         % => IsLastLine Context This Baseline Height Middle
158
 
159
  dup 2 mul 2 index gt {           % => IsLastLine Context This Baseline Height Middle
160
    dup 2 index 2 div sub          % => IsLastLine Context This Baseline Height Middle Delta
161
% offset already aligned items
162
    4 index get-line {             % => IsLastLine Context This Baseline Height Middle Delta Child
163
      dup get-baseline
164
      2 index add
165
      1 index put-baseline
166
      pop
167
    } forall                       % => IsLastLine Context This Baseline Height Middle Delta
168
    pop                            % => IsLastLine Context This Baseline Height Middle
169
    2 mul exch pop
170
  } {
171
    pop
172
  } ifelse                         % => IsLastLine Context This Baseline Height
173
 
174
  2 index get-line {               % => IsLastLine Context This Baseline Height Child
175
    dup /vertical-align get-css-value
176
    /middle eq {                   % => IsLastLine Context This Baseline Height Child
177
      dup get-default-baseline
178
      1 index get-full-height 2 div
179
      sub
180
      2 index 2 div
181
      add
182
      1 index put-baseline         % => IsLastLine Context This Baseline Height Child
183
    } if
184
    pop
185
  } forall
186
 
187
% BOTTOM vertical align
188
 
189
  3 index get-line {               % => IsLastLine Context This Baseline Height Bottom Child
190
    dup /vertical-align get-css-value
191
    /bottom eq {                   % => IsLastLine Context This Baseline Height Bottom Child
192
      dup get-full-height          % => IsLastLine Context This Baseline Height Bottom Child Bottom
193
      3 2 roll                     % => IsLastLine Context This Baseline Height Child Bottom Bottom2
194
      max                          % => IsLastLine Context This Baseline Height Child Bottom'
195
      exch                         % => IsLastLine Context This Baseline Height Bottom Child
196
    } if
197
    pop
198
  } forall                         % => IsLastLine Context This Baseline Height Bottom
199
 
200
  dup 2 index gt       {           % => IsLastLine Context This Baseline Height Bottom
201
    dup 2 index sub                % => IsLastLine Context This Baseline Height Bottom Delta
202
% offset already aligned items
203
    4 index get-line {             % => IsLastLine Context This Baseline Height Bottom Delta Child
204
      dup get-baseline
205
      2 index add
206
      1 index put-baseline
207
      pop
208
    } forall                       % => IsLastLine Context This Baseline Height Bottom Delta
209
    pop                            % => IsLastLine Context This Baseline Height Bottom
210
    exch pop
211
  } {
212
    pop
213
  } ifelse                         % => IsLastLine Context This Baseline Height
214
 
215
  2 index get-line {               % => IsLastLine Context This Baseline Height Child
216
    dup /vertical-align get-css-value
217
    /bottom eq {                   % => IsLastLine Context This Baseline Height Child
218
      dup get-default-baseline
219
      1 index get-full-height
220
      sub
221
      2 index
222
      add
223
      1 index put-baseline         % => IsLastLine Context This Baseline Height Child
224
    } if
225
    pop
226
  } forall
227
 
228
% TOP vertical align
229
 
230
  3 index get-line {               % => IsLastLine Context This Baseline Height Bottom Child
231
    dup /vertical-align get-css-value
232
    /top eq {                      % => IsLastLine Context This Baseline Height Bottom Child
233
      dup get-full-height          % => IsLastLine Context This Baseline Height Bottom Child Bottom
234
      3 2 roll                     % => IsLastLine Context This Baseline Height Child Bottom Bottom2
235
      max                          % => IsLastLine Context This Baseline Height Child Bottom'
236
      exch                         % => IsLastLine Context This Baseline Height Bottom Child
237
    } if
238
    pop
239
  } forall                         % => IsLastLine Context This Baseline Height Bottom
240
 
241
  dup 2 index gt       {           % => IsLastLine Context This Baseline Height Bottom
242
    dup 2 index sub                % => IsLastLine Context This Baseline Height Bottom Delta
243
% offset already aligned items
244
    4 index get-line {             % => IsLastLine Context This Baseline Height Bottom Delta Child
245
      dup get-baseline
246
      2 index add
247
      1 index put-baseline
248
      pop
249
    } forall                       % => IsLastLine Context This Baseline Height Bottom Delta
250
    pop                            % => IsLastLine Context This Baseline Height Bottom
251
    exch pop
252
  } {
253
    pop
254
  } ifelse                         % => IsLastLine Context This Baseline Height
255
 
256
  2 index get-line {               % => IsLastLine Context This Baseline Height Child
257
    dup /vertical-align get-css-value
258
    /top eq {                      % => IsLastLine Context This Baseline Height Child
259
      dup get-default-baseline
260
      1 index put-baseline         % => IsLastLine Context This Baseline Height Child
261
    } if
262
    pop
263
  } forall                         % => IsLastLine Context This Baseline Height
264
 
265
  pop pop                          % => IsLastLine Context This
266
 
267
% Calculate the bottom Y coordinate of last line box
268
 
269
  dup get-current-y                % => IsLastLine Context This BY
270
  1 index get-line {               % => IsLastLine Context This BY Child
271
% This line is required; say, we have sequence of text and image inside the container,
272
% AND image have greater baseline than text; in out case, text will be offset to the bottom
273
% of the page and we lose the gap between text and container bottom edge, unless we'll re-extend
274
% containier height
275
 
276
% Note that we're using the colapsed margin value to get the Y coordinate to extend height to,
277
% as bottom margin may be collapsed with parent
278
 
279
    dup get-bottom-margin
280
    4 index context-get-collapsed-margin add
281
    3 index box-generic-extend-height
282
 
283
    get-bottom-margin              % => IsLastLine Context This BY BM
284
    min                            % => IsLastLine Context This BY'
285
  } forall
286
 
287
% Clear the line box
288
  1 index box-container-clear-line
289
 
290
% Reset current X coordinate to the far left
291
  1 index get-left
292
  2 index put-current-x
293
 
294
% Extend Y coordinate
295
  1 index put-current-y            % => IsLastLine Context This
296
 
297
% Render the deferred floats
298
  dup box-container-get-deferred-floats {
299
                                   % => IsLastLine Context This Float
300
    3 copy                         % => IsLastLine Context This Float Context This Float
301
    box-container-reflow-static-float
302
    pop
303
  } forall                         % => IsLastLine Context This
304
  dup box-container-clear-deferred-floats
305
 
306
%  modify the current-x value, so that next inline box will not intersect any floating boxes
307
  dup get-current-y
308
  1 index get-current-x            % => IsLastLine Context This Y X
309
  3 index context-float-left-x     % => IsLastLine Context This X
310
 
311
  1 index put-current-x            % => IsLastLine Context This
312
 
313
% clear the stack
314
  pop pop pop
315
} def
316
 
317
/box-container-create {            % =>
318
  box-generic-create
319
 
320
  dup /Content [] put
321
  dup /Line [] put
322
 
323
  dup box-container-setup-methods
324
  dup /box-container add-type
325
} def
326
 
327
% Calculate the available widths - e.g. content width minus space occupied by floats;
328
% as floats may not fill the whole height of this box, this value depends on Y-coordinate.
329
% We use current_Y in calculations
330
%
331
/box-container-get-available-width { % => Context Box
332
  dup get-current-y
333
  1 index get-left
334
  3 index context-float-left-x     % => Context Box FL
335
  1 index get-left sub             % => Context Box FloatLeftWidth
336
 
337
  1 index get-right
338
  2 index get-current-y
339
  3 index get-right
340
  5 index context-float-right-x
341
  sub                              % => Context Box FloatLeftWidth FloatRightWidth
342
 
343
  2 index /get-width call-method
344
  exch sub
345
  exch sub
346
 
347
  exch pop
348
  exch pop
349
} def
350
 
351
% Get a list of floating boxes which shold be rendered
352
% at the end of current line box
353
%
354
/box-container-get-deferred-floats {
355
  get-box-dict /DeferredFloats get
356
} def
357
 
358
% Get first child of current box which actually will be drawn
359
% on the page. So, whitespace and null boxes will be ignored
360
%
361
% See description of is_null for null box definition.
362
% (not only NullBoxPDF is treated as null box)
363
%
364
% @return reference to the first visible child of current box
365
/box-container-get-first {         % => This
366
  /null
367
  1 index get-content {            % => This /null Child
368
    dup /is-whitespace call-method not
369
    1 index /is-null call-method not
370
    and {                          % => This FC Child
371
      exch pop                     % => This Child
372
      exit
373
    } if                           % => This FC Child
374
    pop
375
  } forall                         % => This FC
376
 
377
  exch pop                         % => FC
378
} def
379
 
380
% Get first text or image child of current box which actually will be drawn
381
% on the page. So, whitespace and null boxes will be ignored
382
%
383
% See description of is_null for null box definition.
384
% (not only NullBoxPDF is treated as null box)
385
%
386
% @return reference to the first visible child of current box
387
/box-container-get-first-data {    % => This
388
  /null
389
  1 index get-content {            % => This /null Child
390
    dup /is-whitespace call-method not
391
    1 index /is-null call-method not
392
    and {                          % => This FC Child
393
      dup is-container {
394
        box-container-get-first-data
395
        dup /null ne {
396
          exch pop exit
397
        } if
398
      } {
399
        exch pop exit
400
      } ifelse                     % => This FC Child
401
    } if                           % => This FC Child
402
    pop
403
  } forall                         % => This FC
404
 
405
  exch pop                         % => FC
406
} def
407
 
408
% Get last child of current box which actually will be drawn
409
% on the page. So, whitespace and null boxes will be ignored
410
%
411
% See description of is_null for null box definition.
412
% (not only NullBoxPDF is treated as null box)
413
%
414
% @return reference to the first visible child of current box
415
/box-container-get-last {          % => This
416
  /null
417
  1 index get-content              % => This /null Content
418
  dup length 1 sub -1 0 {          % => This /null Content I
419
    2 copy get                     % => This /null Context I Element
420
 
421
    dup /is-whitespace call-method not
422
    1 index /is-null call-method not
423
    and
424
    {
425
      4 3 roll pop 3 1 roll        % => This /null Context I
426
      pop
427
      exit
428
    } {
429
      pop
430
    } ifelse                       % => This /null Context I
431
    pop
432
  } for                            % => This Last Content
433
  pop exch pop
434
} def
435
 
436
 
437
/box-container-get-max-width {     % => Context This
438
 
439
 
440
% We need to add text indent to the max width
441
  1 index
442
  box-generic-calc-text-indent     % => Context This MaxW CMaxW
443
 
444
  2 index get-content {            % => Context This MaxW CMaxW Item
445
    dup is-inline
446
    1 index /float get-css-value
447
    /none ne or {                  % => Context This MaxW CMaxW Item
448
      4 index
449
      1 index
450
      /get-max-width call-method   % => Context This MaxW CMaxW Item W
451
      3 2 roll add exch            % => Context This MaxW CMaxW' Item
452
    } {                            % => Context This MaxW CMaxW Item
453
      2 index 2 index max          % => Context This MaxW CMaxW Item MaxW'
454
      4 3 roll pop                 % => Context This CMaxW Item MaxW'
455
      3 1 roll                     % => Context This MaxW CMaxW Item
456
 
457
      4 index
458
      1 index /get-max-width
459
      call-method                  % => Context This MaxW CMaxW Item CMaxW'
460
      3 2 roll pop exch            % => Context This MaxW CMaxW' Item
461
 
462
% Process special case with percentage constrained table
463
 
464
      dup get-width-constraint     % => Context This MaxW CMaxW Item WC
465
 
466
      1 index /box-table is-a
467
      1 index /type get
468
      /fraction eq and {           % => Context This MaxW CMaxW Item WC
469
        4 index
470
        box-generic-get-expandable-width % => Context This MaxW CMaxW Item WC ExpandableWidth
471
 
472
        5 index
473
        /get-width call-method     % => Context This MaxW CMaxW Item WC ExpandableWidth Width
474
 
475
        2 index
476
        dup /apply get exec        % => Context This MaxW CMaxW Item WC CWidth
477
 
478
        3 index max                % => Context This MaxW CMaxW Item WC CMaxW'
479
 
480
        4 3 roll pop 3 1 roll      % => Context This MaxW CMaxW' Item WC
481
      } if                         % => Context This MaxW CMaxW Item WC
482
      pop                          % => Context This MaxW CMaxW Item
483
    } ifelse                       % => Context This MaxW CMaxW Item
484
 
485
    pop
486
  } forall                         % => Context This MaxW CMaxW
487
 
488
% Check if last line have maximal width
489
 
490
  max                              % => Context This MaxW
491
 
492
% Note that max width cannot differ drom constrained width,
493
% if any width constraints apply
494
 
495
  1 index get-width-constraint     % => Context This MaxW WC
496
  dup /type get /none ne {
497
    2 index get-parent
498
    /get-width call-method         % => Context This MaxW WC PWidth
499
    2 index                        % => Context This MaxW WC PWidth MaxW
500
    2 index dup  /apply get exec   % => Context This MaxW WC MaxW'
501
    exch pop                       % => Context This MaxW MaxW'
502
    exch pop
503
  } {
504
    pop
505
  } ifelse                         % => Context This MaxW
506
 
507
  1 index get-hor-extra
508
  add
509
 
510
  exch pop
511
  exch pop
512
} def
513
 
514
/box-container-get-min-nowrap-width { % => Context This
515
 
516
 
517
% We need to add text indent to the width
518
 
519
  1 index
520
  box-generic-calc-text-indent     % => Context This MaxW CMaxW
521
 
522
  2 index get-content {            % => Context This MaxW CMaxW Child
523
    dup is-inline {
524
% Inline boxes content will not be wrapped, so we may calculate its max width
525
      4 index exch
526
      /get-max-width call-method   % => Context This MaxW CMaxW CMW
527
      add                          % => Context This MaxW CMaxW
528
    } {                            % => Context This MaxW CMaxW Child
529
      3 1 roll                     % => Context This Child MaxW CMaxW
530
      max                          % => Context This Child MaxW'
531
      exch                         % => Context This MaxW' Child
532
      3 index exch                 % => Context This MaxW' Context Child
533
      /get-min-width call-method   % => Context This MaxW' CMaxW'
534
    } ifelse                       % => Context This MaxW CMaxW
535
  } forall                         % => Context This MaxW CMaxW
536
 
537
% Check if last line have maximal width
538
  max                              % => Context This MaxW
539
 
540
% Apply width constraint to min width. Return maximal value
541
  1 index get-parent
542
  /get-width call-method           % => Context This MaxW ParentW
543
  1 index                          % => Context This MaxW ParentW W
544
  3 index get-width-constraint     % => Context This MaxW ParentW W WC
545
  dup /apply get exec              % => Context This MaxW MaxW'
546
  max                              % => Context This MaxW
547
 
548
  1 index get-hor-extra add        % => Context This MaxW
549
  exch pop
550
  exch pop
551
} def
552
 
553
/box-container-get-min-width {     % => Context This
554
% If box does not have any context, its minimal width is determined by extra horizontal space
555
  dup get-content length 0 eq {    % => Context This
556
    dup get-hor-extra
557
  } {                              % => Context This
558
% If we're in 'nowrap' mode, minimal and maximal width will be equal
559
    dup /white-space get-css-value /nowrap eq
560
    1 index
561
    /pseudo-nowrap get-css-value
562
    /nowrap eq or {                % => Context This
563
      2 copy box-container-get-min-nowrap-width
564
    } {                            % => Context This
565
% We need to add text indent size to the with of the first item
566
      dup
567
      box-generic-calc-text-indent % => Context This TI
568
      2 index
569
      2 index                      % => Context This TI Context This
570
      get-content 0 get
571
%      box-container-get-first-data % => Context This TI Context First
572
      /get-min-width call-method   % => Context This TI WFirst
573
      add                          % => Context This MinW
574
 
575
      1 index get-content {        % => Context This MinW Child
576
        3 index exch
577
        /get-min-width call-method % => Context This MinW CMinW
578
        max                        % => Context This MinW
579
      } forall                     % => Context This MinW
580
 
581
      1 index get-parent
582
      /get-width call-method       % => Context This MinW ParentW
583
      1 index                      % => Context This MinW ParentW MinW
584
      3 index get-width-constraint % => Context This MinW ParentW MinW WC
585
      dup /apply get exec          % => Context This MinW MinW'
586
      max
587
 
588
      1 index get-hor-extra add    % => Context This MinW'
589
    } ifelse                       % => Context This Width
590
  } ifelse                         % => Context This Width
591
 
592
  exch pop
593
  exch pop
594
} def
595
 
596
% Get total height of this box content (including floats, if any)
597
% Note that floats can be contained inside children, so we'll need to use
598
% this function recusively
599
/box-container-get-real-full-height { % => This
600
% Treat items with overflow: hidden specifically,
601
% as floats flown out of this boxes will not be visible
602
  dup /overflow get-css-value
603
  /hidden eq {                     % => This
604
    dup get-full-height            % => This Height
605
  } {                              % => This
606
% Check if this cell is totally empty
607
    dup get-content length 0 eq {
608
 
609
    } {                            % => This
610
% Initialize the vertical extent taken by content using the
611
% very first child
612
      dup get-content 0 get
613
      dup get-top-margin           % => This C0 Top
614
      1 index get-bottom-margin    % => This C0 Top Bottom
615
      3 2 roll pop                 % => This Top Bottom
616
 
617
      2 index get-content {        % => This Top Bottom Child
618
% Check if top margin of current child is to the up
619
% of vertical extent top margin
620
        dup get-top-margin         % => This Top Bottom Child ChildTop
621
        4 3 roll max 3 1 roll      % => This Top' Bottom Child
622
 
623
% Check if current child bottom margin will extend
624
% the vertical space OR if it contains floats extending
625
% this, unless this child have overflow: hidden, because this
626
% will prevent additional content to be visible
627
        dup /overflow get-css-value
628
        /hidden eq {
629
          dup get-bottom-margin
630
          3 2 roll min
631
          exch                     % => This Top Bottom Child
632
        } {
633
          dup get-bottom-margin
634
          1 index get-top-margin
635
          2 index /get-real-full-height call-method
636
          sub
637
          min                      % => This Top Bottom Child ChildBM
638
          3 2 roll min exch        % => This Top Bottom' Child
639
        } ifelse                   % => This Top Bottom Child
640
        pop
641
      } forall                     % => This Top Bottom
642
      sub 0 max                    % => This RH
643
      1 index get-vert-extra add   % => This Height
644
    } ifelse
645
  } ifelse                         % => This Height
646
  exch pop
647
} def
648
 
649
/box-container-is-first {          % => Box This
650
  dup box-container-get-first      % => Box This First
651
  dup /null eq {
652
    pop false
653
  } {
654
    get-uid
655
    2 index get-uid
656
    eq
657
  } ifelse
658
 
659
  exch pop
660
  exch pop
661
} def
662
 
663
% Line box should be treated as empty in following cases:
664
% 1. It is really empty (so, it contains 0 boxes)
665
% 2. It contains only whitespace boxes
666
%
667
/box-container-line-box-empty {    % => This
668
  dup get-line length 0 eq {
669
    pop true                       % => true
670
  } {
671
    true 1 index get-line          % => This true Line
672
    {                              % => This Flag Child
673
      /is-whitespace call-method
674
      and
675
    } forall
676
 
677
    exch pop
678
  } ifelse
679
} def
680
 
681
/box-container-offset {            % => DY DX This
682
  3 copy box-generic-offset
683
 
684
  dup get-current-x
685
  2 index add
686
  1 index put-current-x
687
 
688
  dup get-current-y
689
  3 index add
690
  1 index put-current-y
691
 
692
  dup get-content {
693
    3 index exch
694
    3 index exch
695
    /offset call-method
696
  } forall
697
 
698
  pop pop pop
699
} def
700
 
701
/box-container-offset-if-first {   % => DY DX Box This
702
  2 copy box-container-is-first {
703
    dup get-parent /null ne {
704
      3 index
705
      3 index
706
      3 index
707
      3 index get-parent          % => DY DX Box This DY DX Box Parent
708
 
709
      box-container-offset-if-first
710
                                  % => DY DX Box This ParentResult
711
 
712
      not {
713
        3 index
714
        3 index
715
        2 index /offset call-method  % => DY DX Box This
716
        true
717
      } { false } ifelse
718
    } { false } ifelse
719
  } { false }ifelse
720
 
721
  exch pop
722
  exch pop
723
  exch pop
724
  exch pop
725
} def
726
 
727
/box-container-pre-reflow-images { % => This
728
  dup get-content {
729
    /pre-reflow-images call-method
730
  } forall
731
  pop
732
} def
733
 
734
/box-container-setup-methods {     % => Box
735
  dup get-box-dict /Methods get    % => Box Methods
736
  dup /add-child            { box-container-add-child } put
737
  dup /get-max-width        { box-container-get-max-width } put
738
  dup /get-min-width        { box-container-get-min-width } put
739
  dup /get-real-full-height { box-container-get-real-full-height } put
740
  dup /offset               { box-container-offset } put
741
  dup /pre-reflow-images    { box-container-pre-reflow-images } put
742
  dup /reflow-anchors       { box-container-reflow-anchors } put
743
  dup /reflow-content       { box-container-reflow-content } put
744
  dup /reflow-inline        { box-container-reflow-inline } put
745
  dup /reflow-static-float  { box-container-reflow-static-float } put
746
  dup /show                 { box-container-show } put
747
  pop pop
748
} def
749
 
750
/box-container-show {              % => Viewport Box
751
  2 copy box-generic-show          % => Viewport Box
752
 
753
% Setup clipping path for non 'overflow: visible' boxes
754
  dup /overflow get-css-value
755
  /visible ne {
756
% Save clipping area state (of course, BEFORE the clipping area will be set)
757
    gsave
758
 
759
    newpath
760
    dup get-left-border
761
    1 index get-bottom-border      % => Viewport Box X Y
762
    2 index get-right-border
763
    3 index get-left-border sub    % => Viewport Box X Y W
764
    3 index get-top-border
765
    4 index get-bottom-border sub   % => Viewport Box X Y W H
766
    rectclip
767
 
768
  } if
769
 
770
% draw content
771
  dup get-content {                % => Viewport Box ContentElement
772
% We'll check the visibility property here
773
% Reason: all boxes (except the top-level one) are contained in some other box,
774
% so every box will pass this check. The alternative is to add this check into every
775
% box class show member.
776
 
777
% The only exception of absolute positioned block boxes which are drawn separately;
778
% their show method is called explicitly; the similar check should be performed there
779
 
780
    dup /visibility get-css-value /visible eq {
781
      2 index
782
      1 index
783
      /show call-method
784
    } if                           % => Viewport Box ContentElement
785
    pop
786
  } forall                         % => Viewport Box
787
 
788
  dup /overflow get-css-value /visible ne {
789
% restore previous clipping path
790
    grestore
791
  } if
792
 
793
  pop pop
794
} def                              % =>
795
 
796
/box-container-reflow-anchors {    % => List Viewport Box
797
  3 copy box-generic-reflow-anchors
798
 
799
  dup get-content {                % => List Viewport Box Child
800
    3 index exch
801
    3 index exch                   % => List Viewport Box List Viewport Child
802
    /reflow-anchors call-method    % => List' Viewport Box
803
  } forall
804
 
805
  pop pop pop
806
} def
807
 
808
/box-container-reflow-content {    % => Context This
809
  2 copy box-container-close-line  % => Context This
810
 
811
% If first child is inline - apply text-indent
812
  dup box-container-get-first
813
  dup /null ne {
814
    dup is-inline {                % => Context This First
815
      pop
816
      dup box-container-calculate-text-indent
817
      1 index get-additional-text-indent
818
      add
819
      1 index get-current-x
820
      add
821
      1 index put-current-x        % => Context This
822
    } {
823
      pop
824
    } ifelse
825
  } {
826
    pop
827
  } ifelse
828
 
829
 
830
 
831
% reset current Y value
832
  dup get-top
833
  1 index put-current-y
834
 
835
  dup get-content {                % => Context This Child
836
    2 index exch                   % => Context This Context Child
837
    2 index exch                   % => Context This Context This Child
838
    /reflow call-method            % => Context This
839
  } forall                         % => Context This
840
 
841
  1 index 1 index
842
  box-container-close-last-line    % => Context This
843
 
844
  pop pop                          % =>
845
} def
846
 
847
/box-container-reflow-inline {     % => This
848
  dup get-content {                % => This Child
849
    /reflow-inline call-method     % => This
850
  } forall
851
  pop
852
} def
853
 
854
/box-container-reflow-static-float { % => Context Parent Box
855
% Defer the float rendering till the next line box
856
  1 index get-line length 0 gt {
857
    dup 2 index box-container-add-deferred-float
858
  } {
859
 
860
% Calculate margin values if they have been set as a percentage
861
 
862
    2 copy
863
    box-generic-calc-percentage-margins
864
 
865
% Calculate width value if it have been set as a percentage
866
 
867
    3 copy
868
    box-generic-calc-percentage-width
869
 
870
% Calculate margins and/or width is 'auto' values have been specified
871
 
872
    2 copy
873
    box-generic-calc-auto-width-margins
874
 
875
% Determine the actual width of the floating box
876
% Note that get_max_width returns both content and extra width
877
 
878
    2 index 1 index /get-max-width call-method
879
    1 index put-full-width
880
 
881
% We need to call this function before determining the horizontal coordinate
882
% as after vertical offset the additional space to the left may apperar
883
                                   % => Context Parent Box
884
    2 index
885
    2 index get-current-y
886
    2 index
887
    box-generic-apply-clear        % => Context Parent Box Y
888
 
889
% determine the position of top-left floating box corner
890
    1 index /float get-css-value
891
    /right eq {
892
      2 index
893
      2 index get-full-width
894
      2 index                      % => Context Parent Box Y Parent Width Y
895
      6 index
896
      context-float-right-xy       % => Context Parent Box Y X' Y'
897
 
898
      exch
899
      3 index get-full-width sub
900
      exch
901
    } {
902
      2 index
903
      2 index get-full-width
904
      2 index                      % => Context Parent Box Y Parent Width Y
905
      6 index
906
      context-float-left-xy        % => Context Parent Box Y X' Y'
907
    } ifelse                       % => Context Parent Box Y X' Y'
908
 
909
    3 index get-extra-top sub
910
    exch
911
    3 index get-extra-left add
912
    3 index box-generic-move-to    % => Context Parent Box Y
913
    pop                            % => Context Parent Box
914
 
915
% Reflow contents.
916
% Note that floating box creates a new float flow context for it children.
917
 
918
    2 index context-push-floats
919
 
920
% Floating box create a separate margin collapsing context
921
 
922
 
923
 
924
    2 index 1 index /reflow-content call-method
925
 
926
    2 index context-pop-collapsed-margin
927
 
928
% Float should completely enclose its child floats
929
 
930
    2 index context-float-bottom   % => Context Parent Box FB
931
    dup /null ne {
932
      1 index box-generic-extend-height
933
    } {
934
      pop
935
    } ifelse
936
 
937
    2 index context-float-right    % => Context Parent Box FR
938
    dup /null ne {
939
      1 index box-generic-extend-width
940
    } {
941
      pop
942
    } ifelse
943
 
944
% restore old float flow context
945
 
946
    2 index context-pop-floats
947
 
948
% Add this  box to the list of floats in current context
949
 
950
    dup 3 index context-add-float  % => Context Parent Box
951
 
952
% Now fix the value of _current_x for the parent box; it is required
953
% in the following case:
954
% <body><img align="left">some text
955
% in such situation floating image is flown immediately, but it the close_line call have been made before,
956
% so _current_x value of container box will be still equal to ots left content edge; by calling float_left_x again,
957
% we'll force "some text" to be offset to the right
958
 
959
    1 index get-current-y
960
    2 index get-current-x
961
    4 index
962
    context-float-left-x
963
    2 index put-current-x
964
 
965
  } ifelse                         % => Context Parent Box
966
  pop pop pop
967
} def
968
 
969
/get-content {
970
  /Content get
971
} def
972
 
973
/get-line {
974
  /Line get
975
} def
976
 
977
/line-length {                     % => Box
978
  dup get-line 0 exch              % => Box 0(CurrentLength) Line
979
  {                                % => Box CurrentLength LineElement
980
% Note that the line length should include the inline boxes margin/padding
981
% as inline boxes are not directly included to the parent line box,
982
% we'll need to check the parent of current line box element,
983
% and, if it is an inline box, AND this element is last or first contained element
984
% add correcponsing padding value
985
    dup get-full-width             % => Box CurrentLength LineElement EWidth
986
    3 2 roll add exch              % => Box CurrentLength LineElement
987
 
988
    dup get-parent                 % => Box CurrentLength LineElement EParent
989
    dup /null ne {
990
      dup box-container-get-first  % => Box CurrentLength LineElement EParent First
991
      1 index
992
      box-container-get-last       % => Box CurrentLength LineElement EParent First Last
993
 
994
      1 index /null ne {
995
        1 index get-uid
996
        4 index get-uid eq {
997
          2 index
998
          /get-extra-line-left
999
          call-method              % => Box CurrentLength LineElement EParent First Last ELeft
1000
          6 5 roll add 5 1 roll    % => Box CurrentLength' LineElement EParent First Last
1001
        } if
1002
      } if
1003
 
1004
      dup /null ne {
1005
        dup get-uid
1006
        4 index get-uid eq {
1007
          2 index
1008
          /get-extra-line-right
1009
          call-method              % => Box CurrentLength LineElement EParent First Last ELeft
1010
          6 5 roll add 5 1 roll    % => Box CurrentLength' LineElement EParent First Last
1011
        } if
1012
      } if
1013
 
1014
      pop pop                      % => Box CurrentLength LineELement EParent
1015
    } if                           % => Box CurrentLength LineElement EParent
1016
    pop pop
1017
  } forall                         % => Box CurrentLength
1018
  exch pop                         % => Length
1019
} def
1020
 
1021
/put-line {
1022
  exch /Line exch put
1023
} def