This is an automated email from the ASF dual-hosted git repository.

jaragunde pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 1a3a7897b3 Implement XWPFRun.isRtl() getter. (#1172)
1a3a7897b3 is described below

commit 1a3a7897b35752cb2ba54ad763571c8698b04bac
Author: Jacobo Aragunde PĂ©rez <[email protected]>
AuthorDate: Thu Jul 2 12:49:20 2026 +0200

    Implement XWPFRun.isRtl() getter. (#1172)
    
    Reflects the value of the <w:rtl> attribute inside the run properties,
    specified by section "17.3.2.30 rtl (Right To Left Text)".
---
 .../main/java/org/apache/poi/xwpf/usermodel/XWPFRun.java |  12 ++++++++++++
 .../java/org/apache/poi/xwpf/usermodel/TestXWPFRun.java  |  12 ++++++++++++
 test-data/document/rtl.docx                              | Bin 0 -> 6918 bytes
 3 files changed, 24 insertions(+)

diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFRun.java 
b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
index 6d85aaa320..6049606509 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
@@ -1847,4 +1847,16 @@ public class XWPFRun implements ISDTContents, 
IRunElement, CharacterRun {
     public List<XWPFChart> getEmbeddedCharts() {
         return Collections.unmodifiableList(charts);
     }
+
+    /**
+     * Specifies if the reading order is set to right-to-left in the current 
run
+     * properties.
+     * @return The value of the right-to-left flag for the run. Defaults to 
false if not present
+     * in the document.
+     * @since 6.0.0
+     */
+    public boolean isRtl() {
+        CTRPr pr = getRunProperties(false);
+        return pr != null && pr.sizeOfRtlArray() > 0 && 
isCTOnOff(pr.getRtlArray(0));
+    }
 }
diff --git 
a/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFRun.java 
b/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFRun.java
index c3489891c7..7eae76845c 100644
--- a/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFRun.java
+++ b/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFRun.java
@@ -958,4 +958,16 @@ class TestXWPFRun {
             }
         }
     }
+
+    @Test
+    void testIsRtl() throws IOException {
+        try (XWPFDocument doc = 
XWPFTestDataSamples.openSampleDocument("rtl.docx")) {
+            XWPFParagraph p = doc.getParagraphArray(0);
+
+            assertTrue(p.getRuns().get(0).isRtl());   // contains: <w:rtl/>
+            assertTrue(p.getRuns().get(1).isRtl());   // contains: <w:rtl 
w:val="true"/>
+            assertFalse(p.getRuns().get(5).isRtl());  // no rtl element
+            assertFalse(p.getRuns().get(13).isRtl()); // contains: <w:rtl 
w:val="false"/>
+        }
+    }
 }
diff --git a/test-data/document/rtl.docx b/test-data/document/rtl.docx
new file mode 100755
index 0000000000..efb62584fc
Binary files /dev/null and b/test-data/document/rtl.docx differ


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to