-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reverse lines order in Persian and Arabic text wrap #53
Comments
Unless the Class was refactored, this following change must be in the
|
Until this issue is resolved you can implement these changes in your code by extending the <?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)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
The text was updated successfully, but these errors were encountered: