Open tayyebi opened 4 years ago
Unless the Class was refactored, this following change must be in the wrapTextWithOverflow
function not draw
}
$lines[] = $line;
}
+ if ($this->reverse_text_lines_order == true)
+ $lines = array_reverse($lines);
return $lines;
}
Until this issue is resolved you can implement these changes in your code by extending the Box
class:
<?php
class GdBox extends \GDText\Box
{
/**
* @var bool
*/
protected $reverse_text_lines_order = false;
/**
* @param bool $reverse_text_lines_order To Reverse Lines Order
*/
public function setReverseTextLinesOrder($reverse_text_lines_order)
{
$this->reverse_text_lines_order = $reverse_text_lines_order;
}
/**
* Splits overflowing text into array of strings.
* @param string $text
* @return string[]
*/
protected function wrapTextWithOverflow($text)
{
$lines = parent::wrapTextWithOverflow($text);
if ($this->reverse_text_lines_order == true) {
$lines = array_reverse($lines);
}
return $lines;
}
}
// example:
$box = new GdBox($image);
//...
$box->setReverseTextLinesOrder(true);
$box->draw('!وا تشا فييين اعشيري');
Until this issue is resolved you can implement these changes in your code by extending the
Box
class:<?php class GdBox extends \GDText\Box { /** * @var bool */ protected $reverse_text_lines_order = false; /** * @param bool $reverse_text_lines_order To Reverse Lines Order */ public function setReverseTextLinesOrder($reverse_text_lines_order) { $this->reverse_text_lines_order = $reverse_text_lines_order; } /** * Splits overflowing text into array of strings. * @param string $text * @return string[] */ protected function wrapTextWithOverflow($text) { $lines = parent::wrapTextWithOverflow($text); if ($this->reverse_text_lines_order == true) { $lines = array_reverse($lines); } return $lines; } } // example: $box = new GdBox($image); //... $box->setReverseTextLinesOrder(true); $box->draw('!وا تشا فييين اعشيري');
It's better to detect Arabic words to set automatically "setReverseTextLinesOrder(true)"
@eissasoubhi Thanks
Just implemented here: https://github.com/Pressz/Sariab-V2/blob/7d6445d48e366b12d8cb055f42e3b50a5dd3b687/Libs/gd-text-master/src/BoxPatched.php
Maybe this is not an issue but it can be a helpful answer that can save time for programmers who are speaking Persian (Farsi) or Arabic.
As you know, we cannot directly pass Persian (or Arabic) to
$box->draw
which $box is an instance ofGDText::Box
.For example, if we have a text like:
and we directly pass it to the box, it will be like:
So we have to use a library like
persian phpgd
by @slashmili which will return an output like:Natives know that the output is in reverse order.
It should be:
Solution
So changes are required in
Box.php
:Then use the new prop inside
draw
function:In your main class you have to detect Persian (or Arabic) with following regex and then pass a parameter to
$box
:So the output will correctly be: