Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
require_once(HTML2PS_DIR.'box.generic.inline.php');
4
 
5
/**
6
 * @TODO: constructor required font properties to be known for the
7
 * "content" element; on the other side, "content" element may be one
8
 * without font properties defined/used. Currently, it is solved by
9
 * adding CSS_FONT and CSS_LETTER_SPACING to GenericFormattedBox::readCSS
10
 */
11
class BoxNoteCall extends GenericInlineBox {
12
  var $_note_number;
13
  var $_note_content;
14
  var $_note_marker_box;
15
  var $_note_call_box;
16
 
17
  function offset($dx, $dy) {
18
    parent::offset($dx, $dy);
19
    $this->_note_call_box->offset($dx, $dy);
20
  }
21
 
22
  function BoxNoteCall(&$content, &$pipeline) {
23
    $this->GenericInlineBox();
24
 
25
    $this->_note_content =& $content;
26
 
27
    $this->copy_style($content);
28
    $this->put_height_constraint(new HCConstraint(null, null, null));
29
 
30
    /**
31
     * Prepare ::note-call box
32
     */
33
 
34
    $this->_note_call_box = InlineBox::create_from_text(CSSListStyleType::format_number(LST_DECIMAL, 99),
35
                                                        WHITESPACE_NORMAL,
36
                                                        $pipeline);
37
 
38
    $this->_note_call_box->copy_style($content);
39
    $this->_note_call_box->content[0]->copy_style($content);
40
 
41
    $font = $this->_note_call_box->content[0]->get_css_property(CSS_FONT);
42
    $font = $font->copy();
43
    $font->size->scale(0.75);
44
    $this->_note_call_box->content[0]->setCSSProperty(CSS_FONT, $font);
45
 
46
    $this->_note_call_box->content[0]->setCSSProperty(CSS_VERTICAL_ALIGN, VA_SUPER);
47
    $this->_note_call_box->content[0]->setCSSProperty(CSS_LINE_HEIGHT, CSS::getDefaultValue(CSS_LINE_HEIGHT));
48
 
49
    /**
50
     * Prepare ::marker box
51
     */
52
 
53
    $this->_note_marker_box = InlineBox::create_from_text(CSSListStyleType::format_number(LST_DECIMAL, 99),
54
                                                          WHITESPACE_NORMAL,
55
                                                          $pipeline);
56
 
57
    $this->_note_marker_box->copy_style($content);
58
    $this->_note_marker_box->content[0]->copy_style($content);
59
 
60
    $font = $this->_note_marker_box->content[0]->get_css_property(CSS_FONT);
61
    $font = $font->copy();
62
    $font->size->scale(0.5);
63
    $this->_note_marker_box->content[0]->setCSSProperty(CSS_FONT, $font);
64
 
65
    $margin = $this->_note_marker_box->content[0]->get_css_property(CSS_MARGIN);
66
    $margin = $margin->copy();
67
    $margin->right = Value::fromData(FOOTNOTE_MARKER_MARGIN, UNIT_PT);
68
    $this->_note_marker_box->content[0]->setCSSProperty(CSS_MARGIN, $margin);
69
 
70
 
71
    $this->_note_marker_box->content[0]->setCSSProperty(CSS_VERTICAL_ALIGN, VA_SUPER);
72
    $this->_note_marker_box->content[0]->setCSSProperty(CSS_LINE_HEIGHT, CSS::getDefaultValue(CSS_LINE_HEIGHT));
73
  }
74
 
75
  function &create(&$content, &$pipeline) {
76
    $box = new BoxNoteCall($content, $pipeline);
77
 
78
    return $box;
79
  }
80
 
81
  function reflow(&$parent, &$context) {
82
    $parent->append_line($this->_note_call_box);
83
 
84
    $body = $parent;
85
    while ($body->parent) {
86
      $body = $body->parent;
87
    };
88
 
89
    /**
90
     * Reflow note content
91
     */
92
    $this->put_full_height(1000);
93
    $this->put_full_width($body->get_width());
94
 
95
    $this->_current_x = $this->get_left();
96
    $this->_current_y = $this->get_top();
97
    $this->_note_content->reflow($this, $context);
98
 
99
    $this->_current_x = $this->get_left();
100
    $this->_current_y = $this->get_top();
101
    $this->_note_marker_box->reflow($this, $context);
102
 
103
    $this->_current_x = $this->get_left();
104
    $this->_current_y = $this->get_top();
105
    $this->_note_call_box->reflow($this, $context);
106
    // This prevents note-call box from affecting line height
107
    $this->_note_call_box->put_full_height(0);
108
 
109
    /**
110
     * Reflow note-call itself
111
     */
112
    $this->put_full_height(0);
113
    $this->put_full_width(0);
114
    $this->guess_corner($parent);
115
    $parent->_current_x += $this->_note_call_box->content[0]->get_width();
116
    $this->_note_call_box->put_full_width($this->_note_call_box->content[0]->get_width());
117
 
118
    $this->_note_call_box->moveto($this->get_left(), $this->get_top());
119
 
120
//     $last =& $parent->last_in_line();
121
//     $last->note_call = true;
122
 
123
    return true;
124
  }
125
 
126
  function reflow_whitespace(&$linebox_started, &$previous_whitespace) {
127
    $ls = false;
128
    $pw = false;
129
    $this->_note_content->reflow_whitespace($ls, $pw);
130
  }
131
 
132
  function reflow_text(&$driver) {
133
    $this->_note_content->reflow_text($driver);
134
    $this->_note_marker_box->reflow_text($driver);
135
    $this->_note_call_box->reflow_text($driver);
136
    return true;
137
  }
138
 
139
  function _getFootnoteHeight(&$driver) {
140
    if ($driver->getFootnoteCount() == 0) {
141
      $footnote_height =
142
        $this->_note_content->get_full_height() +
143
        FOOTNOTE_LINE_TOP_GAP +
144
        FOOTNOTE_LINE_BOTTOM_GAP;
145
    } else {
146
      $footnote_height =
147
        $this->_note_content->get_full_height() +
148
        FOOTNOTE_GAP;
149
    };
150
 
151
    return $footnote_height;
152
  }
153
 
154
  function show(&$driver) {
155
    $footnote_height = $this->_getFootnoteHeight($driver);
156
    if (!$driver->willContain($this, $footnote_height)) {
157
      return true;
158
    };
159
 
160
    $driver->setFootnoteAreaHeight($driver->getFootnoteAreaHeight() + $footnote_height);
161
    $driver->setFootnoteCount($driver->getFootnoteCount() + 1);
162
 
163
    /**
164
     * Prepare box containing note number
165
     */
166
    $this->_note_number = $driver->getFootnoteCount();
167
 
168
    /**
169
     * Render reference number
170
     */
171
    $this->_note_call_box->content[0]->words[0] = CSSListStyleType::format_number(LST_DECIMAL,
172
                                                                                  $this->_note_number);
173
    $this->_note_call_box->show_fixed($driver);
174
 
175
    return true;
176
  }
177
 
178
  function show_footnote(&$driver, $x, $y) {
179
    /**
180
     * Render note reference number
181
     */
182
    $this->_note_marker_box->content[0]->words[0] = CSSListStyleType::format_number(LST_DECIMAL,
183
                                                                                    $this->_note_number);
184
    $this->_note_marker_box->moveto($x, $y);
185
    $this->_note_marker_box->show_fixed($driver);
186
 
187
    /**
188
     * Render note content
189
     */
190
    $this->_note_content->moveto($x + $this->_note_marker_box->content[0]->get_width()*0.75,
191
                                 $y);
192
    $this->_note_content->show_fixed($driver);
193
 
194
 
195
    return $y - $this->_note_content->get_full_height();
196
  }
197
}
198
 
199
?>