Skip to content
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

Right to left paragraph direction support (rtl dir) #331

Open
alimo2 opened this issue Aug 10, 2014 · 39 comments
Open

Right to left paragraph direction support (rtl dir) #331

alimo2 opened this issue Aug 10, 2014 · 39 comments

Comments

@alimo2
Copy link

alimo2 commented Aug 10, 2014

Hi;

I'm using the last version 3, but it doesn't support right to left language such as Farsi, Arabic in paragraph style & make words cluttered & not in right order!
is there any way fix this?


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@alimo2 alimo2 changed the title rtl direction support Right to left paragraph direction support (rtl dir) Aug 10, 2014
@alimo2
Copy link
Author

alimo2 commented Aug 11, 2014

any solution? :(

@Progi1984
Copy link
Member

I believe no implementation has been done in PHPWord. I change the label Question to Feature Request.

@alimo2
Copy link
Author

alimo2 commented Aug 12, 2014

Thank you, but if anyone know any temp solution plz help me.

@Progi1984
Copy link
Member

@alimo2 Have you some DOCX / ODT files for sample and reference for reverse engineering ? Thx

@alimo2
Copy link
Author

alimo2 commented Aug 12, 2014

docx file generated by PHPWord ?

@Progi1984
Copy link
Member

@alimo2 No DOCX with Word ou LibreOffice, but with RTL paragraph.

@alimo2
Copy link
Author

alimo2 commented Aug 12, 2014

@alimo2
Copy link
Author

alimo2 commented Aug 12, 2014

i check the parsed xml & i think the problem is extra tags that word add to file!

@Progi1984
Copy link
Member

@Progi1984 Progi1984 added this to the 0.12.0 milestone Aug 12, 2014
@Progi1984 Progi1984 self-assigned this Aug 12, 2014
@alimo2
Copy link
Author

alimo2 commented Aug 12, 2014

so what shall i do with PHPWord classes? i know about word rtl xml tags

@Progi1984
Copy link
Member

@alimo2 I just commited (to the develop branch) an implementation to RTL in textrun. Please could you test and give us your feedback ?

@alimo2
Copy link
Author

alimo2 commented Aug 13, 2014

yes for sure, tnx

@Progi1984
Copy link
Member

@alimo2 So is it working for you ?

@alimo2
Copy link
Author

alimo2 commented Aug 13, 2014

yes that is working! tnx a lot. When you commit it in master code?

@Progi1984
Copy link
Member

In the next release :)
Thanks for your tests.

@khosro
Copy link

khosro commented Aug 19, 2014

@Progi1984 thanks for adding support for right to left.
I have downloaded development branch and test "Sample_36_RTL.php".
First of all ,i have encounter following exception :

Fatal error: Uncaught exception 'PhpOffice\PhpWord\Exception\Exception' with message '"HTML" is not a valid writer.' in D:\Projects\PHPWord\PHPWord-develop\src\PhpWord\IOFactory.php on line 32

Then i have removed html writer from "Sample_Header.php" file.
The sample only sets Text Align to right but does not set "Text direction" to "Right To Left"!!!
It must also set text direction to "Right To Left".

@Progi1984 Progi1984 reopened this Aug 19, 2014
@Progi1984
Copy link
Member

@khosro Actually, that sets the direction for the textrun and not for the paragraph. It may be your problem. For the fatal error, could you open a new issue, please ?

@khosro
Copy link

khosro commented Aug 19, 2014

@Progi1984 ,what actually " array('rtl' => true)" does? I think it must set text direction to Right to Left.

@Progi1984
Copy link
Member

@khosro it writes a "w:rtl" tag in the text run (Source : 8d9e85b#diff-3c77dc4e950fb7b3faece7ad6fe4bc19R134)

@khosro
Copy link

khosro commented Aug 19, 2014

@Progi1984 .OK.
I am newbie in PHP. Maybe this is silly question:
Is there any way to set text direction of paragraph ?

@Progi1984
Copy link
Member

@khosro See this link about RTL Text in OpenXML files. Normally, that could help you.

@khosro
Copy link

khosro commented Aug 19, 2014

Thanks.
I think we can not set Right to Left text direction to a paragraph in PHPWord.Am i right?

@Progi1984
Copy link
Member

@khosro At the moment, no. May be with a PR ? An idea, @ivanlanin ?

@khosro
Copy link

khosro commented Aug 20, 2014

@Progi1984 I found a problem
In sample "Sample_36_RTL" if i change string to "سلام این یک پاراگراف Hello راست به چپ است" the generated word render "سلام این یک پاراگراف olleH راست به چپ است"!!!
I mean english word render in reverse.

@Progi1984
Copy link
Member

@khosro Are you sure it's an error ? For me, Word reverses text which is in ASCII. Sorry, I haven't got Word for testing, only Libreoffice & Word Online.

@khosro
Copy link

khosro commented Aug 20, 2014

@Progi1984 Yes.I am sure.I tested it with Microsoft word.

@Progi1984
Copy link
Member

@khosro Could you send me a DOCX with the good render for this string, plz ? I have to analyze the file.

@khosro
Copy link

khosro commented Aug 20, 2014

@Progi1984
Excuse me.I was out of office.In our office we have installed MS Word 2013,when i embed english word in Arabic or Farsi paragraph it renders english word in reverse.
But also i test it with MS Word 2010.In MS Word 2010 it is OK.
I uploaded DOCX with the good render and also changed RTL sample here https://www.dropbox.com/s/pqxyha621btgyn1/Sample_36_RTL.zip

@khosro
Copy link

khosro commented Aug 21, 2014

@Progi1984
The uploaded DOCX file in previous comment generated from "Sample_36_RTL".
There some problems with that file :

  1. As i said this ,english word renders in reverse in MS Word 2013.
    2.In either MS 2010 or MS 2013 if i type english word among "Right to left " language paragraph ,the order of words changed in sentence ,then the meaning of sentence changes.
    In order to solve this problem(mixing english word and "Right to left " language words such as Arabic and Farsi) in MS Word we change the text direction to "Right to Left"(The "Sample_36_RTL" does not do that).

I uploaded the new correct version and also change text direction in it.
https://www.dropbox.com/s/qfe5bjcenxf0yki/Sample_36_RTL-New.zip

@khosro
Copy link

khosro commented Aug 23, 2014

@Progi1984
Excuse me.I am really confused.The uploaded file in previouse comment was generated by PHPWord and then in Word 2010 i set direction to Farsi paragraph.I thought it also does work in MS Word 2013,but it does not .So that i again created another file by PHPWord and then open it by MS Word 2013 and then set direction and uploaded here.

@amirush2001
Copy link

In addition to the ltr, the <bidi/> (bidirectional) element should be added.
Writer/Word2007/Style/Font.php (in the write function, after the rtl code):

$xmlWriter->startElement('w:bidi');
$xmlWriter->endElement();

Writer/Word2007/Element/Text.php (in the write function, after $this->startElementP();):

$xmlWriter->startElement('w:pPr');
$xmlWriter->startElement('w:bidi');
$xmlWriter->endElement();
$xmlWriter->endElement();

@amirush2001
Copy link

And also the xml:space should have <w:rtl> element(Writer/Word2007/Element/Text.php):

$xmlWriter->startElement('w:r');
$xmlWriter->startElement('w:rPr'); //Added
$xmlWriter->startElement('w:rtl'); //Added
$xmlWriter->endElement(); //Added
$xmlWriter->endElement(); //Added
$xmlWriter->startElement('w:t');        
$xmlWriter->writeAttribute('xml:space', 'preserve');
$xmlWriter->writeRaw($this->getText($element->getText()));
$xmlWriter->endElement();
$xmlWriter->endElement(); // w:r

@salehi-nawroz
Copy link

@amirush2001,
thanks for helping us , i have the same problem as khosro,but in my phpword library i could not found the following link as u mentioned in your comment
Writer/Word2007/Style/Font.php
Writer/Word2007/Element/Text.php
can u help me plz?

@ghost ghost modified the milestones: 0.13.0, 0.12.0 Jan 3, 2015
@ghost ghost removed this from the v0.13.0 milestone Jul 30, 2016
@falahatiali
Copy link

is there any way to set Table of content as right to left?

@falahatiali
Copy link

@alimo2
Could you insert an RTL table of content? I can't find additional setting for TOC.

@alimo2
Copy link
Author

alimo2 commented Sep 8, 2020

I still have problem with latest version of phpword (0.17.0). Arabic letters in template become separated & also with wrong direction.
What shal i do ?

@Progi1984

@alimo2
Copy link
Author

alimo2 commented Sep 8, 2020

Screenshot from 2020-09-08 15-35-55

correct is:
رضا مرادی

@alimo2
Copy link
Author

alimo2 commented Sep 8, 2020

is there any way to set Table of content as right to left?

i've never use table of content. sry.

@github-actions github-actions bot added the Stale label Nov 18, 2022
@Progi1984 Progi1984 removed the Stale label Nov 18, 2022
@PHPOffice PHPOffice deleted a comment from github-actions bot Dec 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

6 participants