Article By - Godha G.N, Sonata Software Limited
This article will focus on how right-to-left text content is handled in a Word Document.
“Bi-Directional” is a form where text writing begins at the right-hand side of a page and concludes at the left-hand side of the page. They are also referred to as right-to-left (RTL) text which is different from the left-to-right (LTR) direction in which languages using the Latin alphabet (such as English) are written. The term is often shortened to the jargon term BiDi or bidi. Open XML file formats support bi-directional text.
In Open XML, the following can be set to contain bi-directional text –
· Paragraph Text Flow
· Run Text Flow
· Shapes
· Tables
· Sections
Paragraphs
The most basic unit of block-level content within a WordprocessingML document, paragraphs are stored using the <w:p> element. A paragraph defines a distinct division of content with a WordprocessingML document which begins on a new line. When right-to-left text is present in a paragraph, the text direction property is specified via the <w:pPr> element. The <w:bidi/> element is specified. This property only affects the set of paragraph-level properties, and shall not affect the layout of text within the contents of this paragraph.
Example –
<w:p>
<w:pPr>
<w:bidi/>
</w:pPr>
<w:r>
<w:t>This is a paragraph which is RTL.</w:t>
</w:r>
</w:p>
Runs
A paragraph contains one or more runs, where a run is a container for one or more pieces of text having the same set of properties. Like many collection element types, each run can have associated with it a set of properties. All of the elements inside an r element have their properties controlled by a corresponding optional <w:rPr> run properties element, which must be the first child of the r element. If the run context contains text which is right-to-left, this is specified using the <w:rtl/> (Right To Left Text) element. This element specifies that the alignment and reading order for this run shall be right to left.
Example –
<w:p>
<w:pPr>
<w:rPr>
<w:rFonts w:hint="cs"/>
<w:rtl/>
<w:lang w:bidi="ar-DZ"/>
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:rFonts w:hint="cs"/>
<w:rtl/>
<w:lang w:bidi="ar-DZ"/>
</w:rPr>
<w:t>فخ فثسف هب مشىل فشلس شقث لثففهىل لثىثقشفثي</w:t>
</w:r>
</w:p>
In a right to left language, this would result in the correct placement of the punctuation with respect to each region of right to left text.
Shapes
The Shape element is the basic building block of Vector Markup Language (VML). A shape may exist on its own or within a Group Element. Shape defines many attributes and sub-elements that control the look and behavior of the shape. A shape may contain text data also and this text data can be aligned right-to-left. The placement attribute, mso-position-horizontal (Specifies the horizontal positioning data for objects in WordprocessingML) of the shape element specifies the direction of the text in the Shape. Also the actual text in the shape is considered as a paragraph and hence the <w:bidi/> element is also specified.
Example –
<v:shape id="_x0000_s1028" type="#_x0000_t202" style="position:absolute;margin-left:418.25pt;margin-top:18.05pt;width:91.5pt;height:69pt;z-index:251659264;mso-position-horizontal:right">
<v:textbox>
<w:txbxContent>
<w:p>
<w:pPr>
<w:bidi/>
</w:pPr>
<w:r>
<w:t>This is text box</w:t>
</w:r>
</w:p>
</w:txbxContent>
</v:textbox>
</v:shape>
Tables
A table in WordprocessingML is a set of paragraphs (and other block-level content) arranged in rows and columns. Tables in WordprocessingML are defined via the <w:tbl> element. The <w:tbl> element has <w:tblPr> element which defines the set of table-wide properties, properties which are applied to each row and cell in the table. When the text direction of the table is set right-to-left, the text direction property is specified via the <w:bidiVisual/> element. The bidiVisual element specifies that the cells with this table shall be visually represented in a right to left direction. When this property is specified, then the ordering of all cells in this table are applied to the table assuming that the table is a normal left to right table, but the table cells are displayed in a right to left direction. If the text data which is contained in the cells are also right-to-left, then the <w:bidi/> element is also specified.
Example –
<w:tbl>
<w:tblPr>
<w:tblStyle w:val="TableGrid"/>
<w:bidiVisual/>
<w:tblW w:w="0" w:type="auto"/>
<w:tblLook w:val="04A0"/>
</w:tblPr>
<w:tblGrid>
.....
</w:tblGrid>
<w:tr>
<w:tc>
.....
<w:p>
<w:pPr>
<w:bidi/>
.....
</w:pPr>
<w:r>
<w:t>One</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
.....
</w:tc>
</w:tr>
<w:tr>
<w:tc>
.....
<w:p>
<w:pPr>
<w:bidi/>
.....
</w:pPr>
<w:r>
<w:t>Three</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
.....
</w:tc>
</w:tr>
</w:tbl>
Sections
In order to group large document content, a document can be divided into multiple sections, each of which define a region of content in the document and allow the application of a set of section-level properties. Within the definition of section properties, the properties to be applied to that section (including, but not limited to, page size and orientation, line numbering settings, margins, and columns) are specified. The complete set of section properties is located on the definition for the <w:sectPr> element. If the section contains right-to-left text content, it is specified by the <w:bidi/> element. This property only affects section-level properties, and does not affect the layout of text within the contents of this section.
Example –
<w:p>
<w:pPr>
<w:sectPr>
<w:type w:val="continuous"/>
....
<w:bidi/>
<w:docGrid w:linePitch="360"/>
</w:sectPr>
</w:pPr>
</w:p>