@@ -34,6 +34,7 @@ This file is part of the iText (R) project.
34
34
import com .itextpdf .layout .font .FontProvider ;
35
35
import com .itextpdf .layout .font .FontSet ;
36
36
import com .itextpdf .layout .layout .LayoutPosition ;
37
+ import com .itextpdf .layout .properties .BaseDirection ;
37
38
import com .itextpdf .layout .properties .IBeforeTextRestoreExecutor ;
38
39
import com .itextpdf .layout .properties .Property ;
39
40
import com .itextpdf .layout .properties .RenderingMode ;
@@ -246,6 +247,13 @@ protected void doDraw(SvgDrawContext context) {
246
247
new ClippedElementDrawer (getParentClipPath (), context ));
247
248
}
248
249
this .paragraph .setMargin (0 );
250
+ String direction = this .attributesAndStyles .get (SvgConstants .Attributes .DIRECTION );
251
+ boolean isRtl = "rtl" .equals (direction );
252
+ if (isRtl ) {
253
+ paragraph .setProperty (Property .BASE_DIRECTION , BaseDirection .RIGHT_TO_LEFT );
254
+ } else {
255
+ paragraph .setProperty (Property .BASE_DIRECTION , BaseDirection .LEFT_TO_RIGHT );
256
+ }
249
257
applyTextRenderingMode (paragraph );
250
258
applyFontProperties (paragraph , context );
251
259
// We resolve and draw absolutely positioned text chunks similar to getTextRectangle method. We are interested
@@ -473,22 +481,27 @@ private void deepCopyChildren(TextSvgBranchRenderer deepCopy) {
473
481
474
482
private void applyTextAnchor () {
475
483
if (this .attributesAndStyles != null &&
476
- this .attributesAndStyles .containsKey (SvgConstants .Attributes .TEXT_ANCHOR )) {
477
- String textAnchorValue = this .getAttribute (SvgConstants .Attributes .TEXT_ANCHOR );
478
- applyTextAnchor (textAnchorValue );
484
+ (this .attributesAndStyles .containsKey (SvgConstants .Attributes .TEXT_ANCHOR ) ||
485
+ this .attributesAndStyles .containsKey (SvgConstants .Attributes .DIRECTION ))) {
486
+ String textAnchorValue = getAttributeOrDefault (SvgConstants .Attributes .TEXT_ANCHOR ,
487
+ SvgConstants .Values .TEXT_ANCHOR_START );
488
+ String direction = this .attributesAndStyles .get (SvgConstants .Attributes .DIRECTION );
489
+ boolean isRtl = "rtl" .equals (direction );
490
+ applyTextAnchor (textAnchorValue , isRtl );
479
491
}
480
492
}
481
493
482
- private void applyTextAnchor (String textAnchorValue ) {
494
+ private void applyTextAnchor (String textAnchorValue , boolean isRtl ) {
483
495
if (getParent () instanceof TextSvgBranchRenderer ) {
484
- ((TextSvgBranchRenderer ) getParent ()).applyTextAnchor (textAnchorValue );
496
+ ((TextSvgBranchRenderer ) getParent ()).applyTextAnchor (textAnchorValue , isRtl );
485
497
return ;
486
498
}
487
499
if (SvgConstants .Values .TEXT_ANCHOR_MIDDLE .equals (textAnchorValue )) {
488
500
paragraph .setProperty (Property .TEXT_ANCHOR , TextAnchor .MIDDLE );
489
501
return ;
490
502
}
491
- if (SvgConstants .Values .TEXT_ANCHOR_END .equals (textAnchorValue )) {
503
+ if (SvgConstants .Values .TEXT_ANCHOR_END .equals (textAnchorValue ) && !isRtl ||
504
+ !SvgConstants .Values .TEXT_ANCHOR_END .equals (textAnchorValue ) && isRtl ) {
492
505
paragraph .setProperty (Property .TEXT_ANCHOR , TextAnchor .END );
493
506
return ;
494
507
}
0 commit comments