source: sandbox/filemanager/tp/dompdf/include/text_renderer.cls.php @ 1575

Revision 1575, 4.0 KB checked in by amuller, 14 years ago (diff)

Ticket #597 - Implentação, melhorias do modulo gerenciador de arquivos

Line 
1<?php
2/**
3 * DOMPDF - PHP5 HTML to PDF renderer
4 *
5 * File: $RCSfile: text_renderer.cls.php,v $
6 * Created on: 2004-06-01
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 * @package dompdf
37 * @version 0.5.1
38 */
39
40/* $Id: text_renderer.cls.php,v 1.5 2006/07/07 21:31:05 benjcarson Exp $ */
41/**
42 * Renders text frames
43 *
44 * @access private
45 * @package dompdf
46 */
47class Text_Renderer extends Abstract_Renderer {
48
49  const UNDERLINE_OFFSET = 0.1;  // Relative to bottom of text, as fraction of height
50  const OVERLINE_OFFSET = 0.25;    // Relative to top of text,         "
51  const LINETHROUGH_OFFSET = 0.0;  // Relative to centre of text,      "
52  const DECO_EXTENSION = 0.75;        // How far to extend lines past either end, in pt
53   
54  //........................................................................
55
56  function render(Frame $frame) {
57   
58    $style = $frame->get_style();
59    list($x, $y) = $frame->get_position();
60    $cb = $frame->get_containing_block();
61
62    if ( ($ml = $style->margin_left) == "auto" || $ml == "none" )
63      $ml = 0;
64
65    if ( ($pl = $style->padding_left) == "auto" || $pl == "none" )
66      $pl = 0;
67
68    if ( ($bl = $style->border_left_width) == "auto" || $bl == "none" )
69      $bl = 0;
70
71    $x += $style->length_in_pt( array($ml, $pl, $bl), $cb["w"] );
72
73    $text = $frame->get_text();
74    $font = $style->font_family;
75    $size = $style->font_size;
76    $height = $style->height;   
77    $spacing = $frame->get_text_spacing() + $style->word_spacing;
78
79    if ( preg_replace("/[\s]+/", "", $text) == "" )
80      return;
81   
82    $this->_canvas->text($x, $y, $text,
83                         $font, $size,
84                         $style->color, $spacing);
85
86    // Handle text decoration:
87    // http://www.w3.org/TR/CSS21/text.html#propdef-text-decoration
88   
89    // Draw all applicable text-decorations.  Start with the root and work
90    // our way down.
91    $p = $frame;
92    $stack = array();
93    while ( $p = $p->get_parent() )
94      $stack[] = $p;
95   
96    while ( count($stack) > 0 ) {
97      $f = array_pop($stack);
98
99      $deco_y = $y;
100      if ( ($text_deco = $f->get_style()->text_decoration) === "none" )
101        continue;
102
103      $color = $f->get_style()->color;
104
105      switch ($text_deco) {
106
107      default:
108        continue;
109
110      case "underline":
111        $deco_y += $height * (1 + self::UNDERLINE_OFFSET);
112        break;
113
114      case "overline":
115        $deco_y += $height * self::OVERLINE_OFFSET;
116        break;
117
118      case "line-through":
119        $deco_y -= $height * ( 0.25 + self::LINETHROUGH_OFFSET);
120        break;
121
122      }
123
124      $dx = 0;
125     
126      $x1 = $x - self::DECO_EXTENSION;
127      $x2 = $x + $style->width + $dx + self::DECO_EXTENSION;
128      $this->_canvas->line($x1, $deco_y, $x2, $deco_y, $color, 0.5);
129
130    }
131  }
132
133}
134
135?>
Note: See TracBrowser for help on using the repository browser.