bernattorras / dompdf

Automatically exported from code.google.com/p/dompdf
0 stars 0 forks source link

split_text function (text_frame_decorator.cls.php) requires PHP > 5.2.6 for multibytes strings #35

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Use UTF-8 strings. 
2. When the line break offset is calculted to be after a word containing a
UTF8 special (like "é"), the strip_text function does not separate the html
tag correctly.

What is the expected output? What do you see instead?
The multibyte symbol is not displayed correctly and the rest of the line
(within the same html tag) is removed.

What version of the product are you using? On what operating system?
Works with PHP 5.2.9, doesn't with PHP <= 5.2.6

Please provide any additional information below.
see PHP Bug http://bugs.php.net/bug.php?id=46335

replace the strip_text function by this one :
function split_text($offset) {
  if ( $offset == 0 )
      return;

    //Bug for PHP <= 5.2.6  : http://bugs.php.net/bug.php?id=46335 
    //$split = $this->_frame->get_node()->splitText($offset);
    $node = $this->_frame->get_node();
    $clone = $node->cloneNode(true);

    //set new content of original $node
    $node->deleteData($offset, mb_strlen($node->textContent));

    //Add Node after with remaining text
    $clone->deleteData(0, $offset);
    $parent = $node->parentNode;
    $parent->appendChild($clone);

    $deco = $this->copy($clone);    

    $p = $this->get_parent();
    $p->insert_child_after($deco, $this, false);
    if ( $p instanceof Inline_Frame_Decorator )
      $p->split($deco);
}

Original issue reported on code.google.com by romuald....@gmail.com on 29 Jun 2009 at 12:12

Attachments:

GoogleCodeExporter commented 8 years ago
Sorry the function name is split_text, not strip_text

Original comment by romuald....@gmail.com on 29 Jun 2009 at 12:52

GoogleCodeExporter commented 8 years ago

Original comment by eclecticgeek on 4 Jan 2010 at 10:39

GoogleCodeExporter commented 8 years ago
Hi, I'm having the same problem, but I have PHP 5.2.9 and also your fix don't 
work.

Any thoughts?

Original comment by glp...@gmail.com on 6 Jan 2010 at 1:31

GoogleCodeExporter commented 8 years ago
Issue 146 has been merged into this issue.

Original comment by eclecticgeek on 24 Apr 2010 at 2:18

GoogleCodeExporter commented 8 years ago
Issue 163 has been merged into this issue.

Original comment by fabien.menager on 20 Jul 2010 at 11:13

GoogleCodeExporter commented 8 years ago
This issue was closed by revision r285.

Original comment by fabien.menager on 20 Jul 2010 at 11:35

GoogleCodeExporter commented 8 years ago
Fixed in r285

Original comment by fabien.menager on 20 Jul 2010 at 11:35

GoogleCodeExporter commented 8 years ago
This solution didn't solve my problem (i use PHP 5.3.2 on Ubuntu), after i 
replace that function DOMPDF continued breaking words very bad.
I tried with something somebody posted on the following link and it solved it 
all:
http://www.dashinteractive.net/dompdf/index.php?v=3153736

What tommylacroix proposes is:

function split_text($offset) {
    if ( $offset == 0 )
      return;

    $text = $this->_frame->get_node()->nodeValue;

    $split = $this->_frame->get_node()->splitText($offset);
    $this->_frame->get_node()->nodeValue = mb_substr($text,0,$offset);
    $split->nodeValue = mb_substr($text,$offset);
    $deco = $this->copy($split);
    $p = $this->get_parent();
    $p->insert_child_after($deco, $this, false);

    if ( $p instanceof Inline_Frame_Decorator )
      $p->split($deco);
}

Best regards from Colombia

Original comment by latinos...@gmail.com on 22 Feb 2011 at 4:08

GoogleCodeExporter commented 8 years ago
PHP 5.3 doesn't have the bug in the splitText() method, so this patch is 
irrelevant.

Original comment by mma...@gmail.com on 22 Feb 2011 at 4:18

GoogleCodeExporter commented 8 years ago
Issue 146 has been merged into this issue.

Original comment by eclecticgeek on 13 Sep 2012 at 6:13

GoogleCodeExporter commented 8 years ago

Original comment by eclecticgeek on 30 May 2013 at 5:15