source: trunk/filemanager/tp/dompdf/include/list_bullet_image_frame_decorator.cls.php @ 2000

Revision 2000, 6.1 KB checked in by amuller, 14 years ago (diff)

Ticket #597 - Implementação do módulo gerenciador de arquivos

Line 
1<?php
2/**
3 * DOMPDF - PHP5 HTML to PDF renderer
4 *
5 * File: $RCSfile: list_bullet_image_frame_decorator.cls.php,v $
6 * Created on: 2005-06-28
7 *
8 * Copyright (c) 2004 - Benj Carson <benjcarson@digitaljunkies.ca>
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this library in the file LICENSE.LGPL; if not, write to the
22 * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 * 02111-1307 USA
24 *
25 * Alternatively, you may distribute this software under the terms of the
26 * PHP License, version 3.0 or later.  A copy of this license should have
27 * been distributed with this file in the file LICENSE.PHP .  If this is not
28 * the case, you can obtain a copy at http://www.php.net/license/3_0.txt.
29 *
30 * The latest version of DOMPDF might be available at:
31 * http://www.digitaljunkies.ca/dompdf
32 *
33 * @link http://www.digitaljunkies.ca/dompdf
34 * @copyright 2004 Benj Carson
35 * @author Benj Carson <benjcarson@digitaljunkies.ca>
36 * @contributor Helmut Tischer <htischer@weihenstephan.org>
37 * @package dompdf
38 * @version 0.5.1
39 *
40 * Changes
41 * @contributor Helmut Tischer <htischer@weihenstephan.org>
42 * @version 0.5.1.htischer.20090507
43 * - added comment
44 */
45
46/* $Id: list_bullet_image_frame_decorator.cls.php 186 2009-10-19 22:42:06Z eclecticgeek@gmail.com $ */
47
48/**
49 * Decorates frames for list bullets with custom images
50 *
51 * @access private
52 * @package dompdf
53 */
54class List_Bullet_Image_Frame_Decorator extends Frame_Decorator {
55
56  /**
57   * The underlying image frame
58   *
59   * @var Image_Frame_Decorator
60   */
61  protected $_img;
62
63  /**
64   * The image's width in pixels
65   *
66   * @var int
67   */
68  protected $_width;
69 
70  /**
71   * The image's height in pixels
72   *
73   * @var int
74   */
75  protected $_height;
76
77  /**
78   * Class constructor
79   *
80   * @param Frame $frame the bullet frame to decorate
81   * @param DOMPDF $dompdf the document's dompdf object
82   */
83  function __construct(Frame $frame, DOMPDF $dompdf) {
84    $style = $frame->get_style();
85    $url = $style->list_style_image;
86    $frame->get_node()->setAttribute("src", $url);
87    $this->_img = new Image_Frame_Decorator($frame, $dompdf);
88    parent::__construct($this->_img, $dompdf);
89    list($width, $height) = getimagesize($this->_img->get_image_url());
90
91    // Resample the bullet image to be consistent with 'auto' sized images
92    // See also Image_Frame_Reflower::get_min_max_width
93    // Tested php ver: value measured in px, suffix "px" not in value: rtrim unnecessary.
94    $this->_width = (((float)rtrim($width, "px")) * 72) / DOMPDF_DPI;
95    $this->_height = (((float)rtrim($height, "px")) * 72) / DOMPDF_DPI;
96 
97    //If an image is taller as the containing block/box, the box should be extended.
98    //Neighbour elements are overwriting the overlapping image areas.
99    //Todo: Where can the box size be extended?   
100    //Code below has no effect.
101    //See block_frame_reflower _calculate_restricted_height
102    //See generated_frame_reflower, Dompdf:render() "list-item", "-dompdf-list-bullet"S.
103    //Leave for now   
104    //if ($style->min_height < $this->_height ) {
105    //  $style->min_height = $this->_height;
106    //}
107    //$style->height = "auto";   
108  }
109
110  /**
111   * Return the bullet's width
112   *
113   * @return int
114   */
115  function get_width() {
116    //ignore image width, use same width as on predefined bullet List_Bullet_Frame_Decorator
117    //for proper alignment of bullet image and text. Allow image to not fitting on left border.
118    //This controls the distance between bullet image and text
119    //return $this->_width;
120    return $this->_frame->get_style()->get_font_size()*List_Bullet_Frame_Decorator::BULLET_SIZE +
121      2 * List_Bullet_Frame_Decorator::BULLET_PADDING;
122  }
123
124  /**
125   * Return the bullet's height
126   *
127   * @return int
128   */
129  function get_height() {
130    //based on image height
131    return $this->_height;
132  }
133 
134  /**
135   * Override get_margin_width
136   *
137   * @return int
138   */
139  function get_margin_width() {
140    //ignore image width, use same width as on predefined bullet List_Bullet_Frame_Decorator
141    //for proper alignment of bullet image and text. Allow image to not fitting on left border.
142    //This controls the extra indentation of text to make room for the bullet image.
143    //Here use actual image size, not predefined bullet size
144    //return $this->_frame->get_style()->get_font_size()*List_Bullet_Frame_Decorator::BULLET_SIZE +
145    //  2 * List_Bullet_Frame_Decorator::BULLET_PADDING;
146
147    // Small hack to prevent indenting of list text
148    // Image Might not exist, then position like on list_bullet_frame_decorator fallback to none.
149    if ( $this->_frame->get_style()->list_style_position == "outside" ||
150         $this->_width == 0)
151      return 0;
152    //This aligns the "inside" image position with the text.
153    //The text starts to the right of the image.
154    //Between the image and the text there is an added margin of image width.
155    //Where this comes from is unknown.
156    //The corresponding List_Bullet_Frame_Decorator sets a smaller margin. bullet size?
157    return $this->_width + 2 * List_Bullet_Frame_Decorator::BULLET_PADDING;
158  }
159
160  /**
161   * Override get_margin_height()
162   *
163   * @return int
164   */
165  function get_margin_height() {
166    //Hits only on "inset" lists items, to increase height of box
167    //based on image height
168    return $this->_height + 2 * List_Bullet_Frame_Decorator::BULLET_PADDING;
169  }
170
171  /**
172   * Return image url
173   *
174   * @return string
175   */
176  function get_image_url() {
177    return $this->_img->get_image_url();
178  }
179
180  /**
181   * Return the image extension
182   *
183   * @return string
184   */
185  function get_image_ext() {
186    return $this->_img->get_image_ext();
187  }
188 
189}
190
191?>
Note: See TracBrowser for help on using the repository browser.