/usr/share/php/dompdf/include/list_bullet_renderer.cls.php is in php-dompdf 0.6.0~beta3+dfsg0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | <?php
/**
* @package dompdf
* @link http://www.dompdf.com/
* @author Benj Carson <benjcarson@digitaljunkies.ca>
* @author Helmut Tischer <htischer@weihenstephan.org>
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @version $Id$
*/
/**
* Renders list bullets
*
* @access private
* @package dompdf
*/
class List_Bullet_Renderer extends Abstract_Renderer {
static function get_counter_chars($type) {
static $cache = array();
if ( isset($cache[$type]) ) {
return $cache[$type];
}
$uppercase = false;
$text = "";
switch ($type) {
case "decimal-leading-zero":
case "decimal":
case "1":
return "0123456789";
case "upper-alpha":
case "upper-latin":
case "A":
$uppercase = true;
case "lower-alpha":
case "lower-latin":
case "a":
$text = "abcdefghijklmnopqrstuvwxyz";
break;
case "upper-roman":
case "I":
$uppercase = true;
case "lower-roman":
case "i":
$text = "ivxlcdm";
break;
case "lower-greek":
for($i = 0; $i < 24; $i++) {
$text .= unichr($i+944);
}
break;
}
if ( $uppercase ) {
$text = strtoupper($text);
}
return $cache[$type] = "$text.";
}
//........................................................................
private function make_counter($n, $type, $pad = null){
$n = intval($n);
$text = "";
$uppercase = false;
switch ($type) {
case "decimal-leading-zero":
case "decimal":
case "1":
if ($pad)
$text = str_pad($n, $pad, "0", STR_PAD_LEFT);
else
$text = $n;
break;
case "upper-alpha":
case "upper-latin":
case "A":
$uppercase = true;
case "lower-alpha":
case "lower-latin":
case "a":
$text = chr( ($n % 26) + ord('a') - 1);
break;
case "upper-roman":
case "I":
$uppercase = true;
case "lower-roman":
case "i":
$text = dec2roman($n);
break;
case "lower-greek":
$text = unichr($n + 944);
break;
}
if ( $uppercase ) {
$text = strtoupper($text);
}
return "$text.";
}
function render(Frame $frame) {
$style = $frame->get_style();
$font_size = $style->get_font_size();
$line_height = $style->length_in_pt($style->line_height, $frame->get_containing_block("w"));
$this->_set_opacity( $frame->get_opacity( $style->opacity ) );
// Handle list-style-image
// If list style image is requested but missing, fall back to predefined types
if ( $style->list_style_image !== "none" &&
!Image_Cache::is_broken($img = $frame->get_image_url())) {
list($x,$y) = $frame->get_position();
//For expected size and aspect, instead of box size, use image natural size scaled to DPI.
// Resample the bullet image to be consistent with 'auto' sized images
// See also Image_Frame_Reflower::get_min_max_width
// Tested php ver: value measured in px, suffix "px" not in value: rtrim unnecessary.
//$w = $frame->get_width();
//$h = $frame->get_height();
list($width, $height) = dompdf_getimagesize($img);
$w = (((float)rtrim($width, "px")) * 72) / DOMPDF_DPI;
$h = (((float)rtrim($height, "px")) * 72) / DOMPDF_DPI;
$x -= $w;
$y -= ($line_height - $font_size)/2; //Reverse hinting of list_bullet_positioner
$this->_canvas->image( $img, $x, $y, $w, $h);
} else {
$bullet_style = $style->list_style_type;
$fill = false;
switch ($bullet_style) {
default:
case "disc":
$fill = true;
case "circle":
list($x,$y) = $frame->get_position();
$r = ($font_size*(List_Bullet_Frame_Decorator::BULLET_SIZE /*-List_Bullet_Frame_Decorator::BULLET_THICKNESS*/ ))/2;
$x -= $font_size*(List_Bullet_Frame_Decorator::BULLET_SIZE/2);
$y += ($font_size*(1-List_Bullet_Frame_Decorator::BULLET_DESCENT))/2;
$o = $font_size*List_Bullet_Frame_Decorator::BULLET_THICKNESS;
$this->_canvas->circle($x, $y, $r, $style->color, $o, null, $fill);
break;
case "square":
list($x, $y) = $frame->get_position();
$w = $font_size*List_Bullet_Frame_Decorator::BULLET_SIZE;
$x -= $w;
$y += ($font_size*(1-List_Bullet_Frame_Decorator::BULLET_DESCENT-List_Bullet_Frame_Decorator::BULLET_SIZE))/2;
$this->_canvas->filled_rectangle($x, $y, $w, $w, $style->color);
break;
case "decimal-leading-zero":
case "decimal":
case "lower-alpha":
case "lower-latin":
case "lower-roman":
case "lower-greek":
case "upper-alpha":
case "upper-latin":
case "upper-roman":
case "1": // HTML 4.0 compatibility
case "a":
case "i":
case "A":
case "I":
$li = $frame->get_parent();
$pad = null;
if ( $bullet_style === "decimal-leading-zero" ) {
$pad = strlen($li->get_parent()->get_node()->getAttribute("dompdf-children-count"));
}
$index = $frame->get_node()->getAttribute("dompdf-counter");
$text = $this->make_counter($index, $bullet_style, $pad);
if ( trim($text) == "" ) {
return;
}
$spacing = 0;
$font_family = $style->font_family;
$line = $li->get_containing_line();
list($x, $y) = array($frame->get_position("x"), $line->y);
$x -= Font_Metrics::get_text_width($text, $font_family, $font_size, $spacing);
// Take line-height into account
$line_height = $style->line_height;
$y += ($line_height - $font_size) / 4; // FIXME I thought it should be 2, but 4 gives better results
$this->_canvas->text($x, $y, $text,
$font_family, $font_size,
$style->color, $spacing);
case "none":
break;
}
}
}
}
|