PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/library/dompdf/include/text_renderer.cls.php

https://code.google.com/p/ecartcommerce/
PHP | 136 lines | 58 code | 29 blank | 49 comment | 18 complexity | 97feaf787762d1d8211e1ae69d0bb314 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1
  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. /* $Id: text_renderer.cls.php,v 1.5 2006/07/07 21:31:05 benjcarson Exp $ */
  40. /**
  41. * Renders text frames
  42. *
  43. * @access private
  44. * @package dompdf
  45. */
  46. class Text_Renderer extends Abstract_Renderer {
  47. const UNDERLINE_OFFSET = 0.1; // Relative to bottom of text, as fraction of height
  48. const OVERLINE_OFFSET = 0.25; // Relative to top of text, "
  49. const LINETHROUGH_OFFSET = 0.0; // Relative to centre of text, "
  50. const DECO_EXTENSION = 0.75; // How far to extend lines past either end, in pt
  51. //........................................................................
  52. function render(Frame $frame) {
  53. $style = $frame->get_style();
  54. list($x, $y) = $frame->get_position();
  55. $cb = $frame->get_containing_block();
  56. if ( ($ml = $style->margin_left) == "auto" || $ml == "none" )
  57. $ml = 0;
  58. if ( ($pl = $style->padding_left) == "auto" || $pl == "none" )
  59. $pl = 0;
  60. if ( ($bl = $style->border_left_width) == "auto" || $bl == "none" )
  61. $bl = 0;
  62. $x += $style->length_in_pt( array($ml, $pl, $bl), $cb["w"] );
  63. $text = $frame->get_text();
  64. $font = $style->font_family;
  65. $size = $style->font_size;
  66. $height = $style->height;
  67. $spacing = $frame->get_text_spacing() + $style->word_spacing;
  68. if ( preg_replace("/[\s]+/", "", $text) == "" )
  69. return;
  70. $this->_canvas->text($x, $y, $text,
  71. $font, $size,
  72. $style->color, $spacing);
  73. // Handle text decoration:
  74. // http://www.w3.org/TR/CSS21/text.html#propdef-text-decoration
  75. // Draw all applicable text-decorations. Start with the root and work
  76. // our way down.
  77. $p = $frame;
  78. $stack = array();
  79. while ( $p = $p->get_parent() )
  80. $stack[] = $p;
  81. while ( count($stack) > 0 ) {
  82. $f = array_pop($stack);
  83. $deco_y = $y;
  84. if ( ($text_deco = $f->get_style()->text_decoration) === "none" )
  85. continue;
  86. $color = $f->get_style()->color;
  87. switch ($text_deco) {
  88. default:
  89. continue;
  90. case "underline":
  91. $deco_y += $height * (1 + self::UNDERLINE_OFFSET);
  92. break;
  93. case "overline":
  94. $deco_y += $height * self::OVERLINE_OFFSET;
  95. break;
  96. case "line-through":
  97. $deco_y -= $height * ( 0.25 + self::LINETHROUGH_OFFSET);
  98. break;
  99. }
  100. $dx = 0;
  101. $x1 = $x - self::DECO_EXTENSION;
  102. $x2 = $x + $style->width + $dx + self::DECO_EXTENSION;
  103. $this->_canvas->line($x1, $deco_y, $x2, $deco_y, $color, 0.5);
  104. }
  105. }
  106. }
  107. ?>