ListBullet.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * @package dompdf
  4. * @link http://dompdf.github.com/
  5. * @author Benj Carson <benjcarson@digitaljunkies.ca>
  6. * @author Helmut Tischer <htischer@weihenstephan.org>
  7. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  8. */
  9. namespace Dompdf\Positioner;
  10. use Dompdf\FrameDecorator\AbstractFrameDecorator;
  11. /**
  12. * Positions list bullets
  13. *
  14. * @package dompdf
  15. */
  16. class ListBullet extends AbstractPositioner
  17. {
  18. /**
  19. * @param AbstractFrameDecorator $frame
  20. */
  21. function position(AbstractFrameDecorator $frame)
  22. {
  23. // Bullets & friends are positioned an absolute distance to the left of
  24. // the content edge of their parent element
  25. $cb = $frame->get_containing_block();
  26. // Note: this differs from most frames in that we must position
  27. // ourselves after determining our width
  28. $x = $cb["x"] - $frame->get_width();
  29. $p = $frame->find_block_parent();
  30. $y = $p->get_current_line_box()->y;
  31. // This is a bit of a hack...
  32. $n = $frame->get_next_sibling();
  33. if ($n) {
  34. $style = $n->get_style();
  35. $line_height = $style->line_height;
  36. // TODO: should offset take into account the line height of the next sibling (per previous logic)?
  37. // $offset = (float)$style->length_in_pt($line_height, $n->get_containing_block("h")) - $frame->get_height();
  38. $offset = $line_height - $frame->get_height();
  39. $y += $offset / 2;
  40. }
  41. // Now the position is the left top of the block which should be marked with the bullet.
  42. // We tried to find out the y of the start of the first text character within the block.
  43. // But the top margin/padding does not fit, neither from this nor from the next sibling
  44. // The "bit of a hack" above does not work also.
  45. // Instead let's position the bullet vertically centered to the block which should be marked.
  46. // But for get_next_sibling() the get_containing_block is all zero, and for find_block_parent()
  47. // the get_containing_block is paper width and the entire list as height.
  48. // if ($p) {
  49. // //$cb = $n->get_containing_block();
  50. // $cb = $p->get_containing_block();
  51. // $y += $cb["h"]/2;
  52. // print 'cb:'.$cb["x"].':'.$cb["y"].':'.$cb["w"].':'.$cb["h"].':';
  53. // }
  54. // Todo:
  55. // For now give up on the above. Use Guesswork with font y-pos in the middle of the line spacing
  56. /*$style = $p->get_style();
  57. $font_size = $style->font_size;
  58. $line_height = (float)$style->length_in_pt($style->line_height, $font_size);
  59. $y += ($line_height - $font_size) / 2; */
  60. //Position is x-end y-top of character position of the bullet.
  61. $frame->set_position($x, $y);
  62. }
  63. }