File size: 3,344 Bytes
07c3cdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/box-generic-inline-create {       % =>
  box-container-create             % => Box
  dup box-generic-inline-setup-methods
  dup /box-generic-inline add-type
} def                              % => Box

/box-generic-inline-setup-methods {% => Box
  dup box-container-setup-methods
    
  dup get-box-dict /Methods get    % => Box Methods
  dup /maybe-line-break {box-generic-inline-maybe-line-break} put
  pop pop
} def

% Checks if current inline box should cause a line break inside the parent box
%
% @param $parent reference to a parent box
% @param $content flow context
% @return true if line break occurred; false otherwise
%
/box-generic-inline-maybe-line-break {
                                   % => Context Parent This
  1 index /line-break-allowed call-method {
% Calculate the x-coordinate of this box right edge
    1 index get-current-x
    1 index get-full-width
    add                            % => Context Parent This RightX

    false                          % => Context Parent This RightX NeedBreak

% Check for right-floating boxes
% If upper-right corner of this inline box is inside of some float, wrap the line
    3 index get-current-y
    2 index                        % => Context Parent This RightX NeedBreak CY X
    6 index
    context-point-in-floats
    /null ne                       % => Context Parent This RightX NeedBreak NeedBreak'
    or                             % => Context Parent This RightX NeedBreak

% No floats; check if we had run out the right edge of container
    3 index get-right
    rounding-epsilon add           % => Context Parent This RightX NeedBreak $parent->get_right()+EPSILON
    2 index le {                   % => Context Parent This RightX NeedBreak
        
% Now check if parent line box contains any other boxes;
% if not, we should draw this box unless we have a floating box to the left

      3 index
      box-container-get-first      % => Context Parent This RightX NeedBreak First

      4 index
      box-generic-calc-text-indent % => Context Parent This RightX NeedBreak First IndentOffset

      5 index get-current-x        % => Context Parent This RightX NeedBreak First IndentOffset CX
      6 index get-left             % => Context Parent This RightX NeedBreak First IndentOffset CX L
      2 index add
      rounding-epsilon add         % => Context Parent This RightX NeedBreak First IndentOffset CX X
      gt                           % => Context Parent This RightX NeedBreak First IndentOffset CX>X
      exch pop
      exch pop                     % => Context Parent This RightX NeedBreak CX>X
      or                           % => Context Parent This RightX NeedBreak'
    } if                           % => Context Parent This RightX NeedBreak

% As close-line will not change the current-Y parent coordinate if no 
% items were in the line box, we need to offset this explicitly in this case

    3 index get-line length 0 eq
    1 index and {                  % => Context Parent This RightX NeedBreak
      3 index get-current-y
      3 index get-height sub
      5 index put-current-y
    } if

    dup {
      4 index
      4 index box-container-close-line 
    } if                           % => Context Pareht This RightX NeedBreak

    exch pop
    exch pop
    exch pop
    exch pop
  } {
    pop pop pop false
  } ifelse
} def