@@ -44,12 +44,16 @@ This file is part of the iText (R) project.
44
44
package com .itextpdf .layout .renderer ;
45
45
46
46
import com .itextpdf .io .LogMessageConstant ;
47
+ import com .itextpdf .kernel .colors .ColorConstants ;
47
48
import com .itextpdf .kernel .font .PdfFont ;
49
+ import com .itextpdf .kernel .geom .Line ;
48
50
import com .itextpdf .kernel .pdf .tagging .StandardRoles ;
51
+ import com .itextpdf .layout .borders .SolidBorder ;
49
52
import com .itextpdf .layout .element .ListItem ;
50
53
import com .itextpdf .layout .element .Paragraph ;
51
54
import com .itextpdf .layout .layout .LayoutContext ;
52
55
import com .itextpdf .layout .layout .LayoutResult ;
56
+ import com .itextpdf .layout .property .BaseDirection ;
53
57
import com .itextpdf .layout .property .ListSymbolAlignment ;
54
58
import com .itextpdf .layout .property .ListSymbolPosition ;
55
59
import com .itextpdf .layout .property .Property ;
@@ -133,19 +137,33 @@ public void draw(DrawContext drawContext) {
133
137
134
138
// It will be null in case of overflow (only the "split" part will contain symbol renderer.
135
139
if (symbolRenderer != null && !symbolAddedInside ) {
140
+ boolean isRtl = BaseDirection .RIGHT_TO_LEFT .equals (this .<BaseDirection >getProperty (Property .BASE_DIRECTION ));
136
141
symbolRenderer .setParent (this );
137
- float x = occupiedArea .getBBox ().getX ();
142
+ float x = isRtl ? occupiedArea .getBBox ().getRight () : occupiedArea . getBBox (). getLeft ();
138
143
ListSymbolPosition symbolPosition = (ListSymbolPosition ) ListRenderer .getListItemOrListProperty (this , parent , Property .LIST_SYMBOL_POSITION );
139
144
if (symbolPosition != ListSymbolPosition .DEFAULT ) {
140
145
Float symbolIndent = this .getPropertyAsFloat (Property .LIST_SYMBOL_INDENT );
141
- x -= symbolAreaWidth + (float ) (symbolIndent == null ? 0 : symbolIndent );
146
+ if (isRtl ) {
147
+ x += (symbolAreaWidth + (float ) (symbolIndent == null ? 0 : symbolIndent ));
148
+ } else {
149
+ x -= (symbolAreaWidth + (float ) (symbolIndent == null ? 0 : symbolIndent ));
150
+ }
142
151
if (symbolPosition == ListSymbolPosition .OUTSIDE ) {
143
- UnitValue marginLeftUV = this .getPropertyAsUnitValue (Property .MARGIN_LEFT );
144
- if (!marginLeftUV .isPointValue ()) {
145
- Logger logger = LoggerFactory .getLogger (ListItemRenderer .class );
146
- logger .error (MessageFormatUtil .format (LogMessageConstant .PROPERTY_IN_PERCENTS_NOT_SUPPORTED , Property .MARGIN_LEFT ));
152
+ if (isRtl ) {
153
+ UnitValue marginRightUV = this .getPropertyAsUnitValue (Property .MARGIN_RIGHT );
154
+ if (!marginRightUV .isPointValue ()) {
155
+ Logger logger = LoggerFactory .getLogger (ListItemRenderer .class );
156
+ logger .error (MessageFormatUtil .format (LogMessageConstant .PROPERTY_IN_PERCENTS_NOT_SUPPORTED , Property .MARGIN_RIGHT ));
157
+ }
158
+ x -= marginRightUV .getValue ();
159
+ } else {
160
+ UnitValue marginLeftUV = this .getPropertyAsUnitValue (Property .MARGIN_LEFT );
161
+ if (!marginLeftUV .isPointValue ()) {
162
+ Logger logger = LoggerFactory .getLogger (ListItemRenderer .class );
163
+ logger .error (MessageFormatUtil .format (LogMessageConstant .PROPERTY_IN_PERCENTS_NOT_SUPPORTED , Property .MARGIN_LEFT ));
164
+ }
165
+ x += marginLeftUV .getValue ();
147
166
}
148
- x += marginLeftUV .getValue ();
149
167
}
150
168
}
151
169
applyMargins (occupiedArea .getBBox (), false );
@@ -161,8 +179,8 @@ public void draw(DrawContext drawContext) {
161
179
}
162
180
}
163
181
if (yLine != null ) {
164
- if (symbolRenderer instanceof TextRenderer ) {
165
- (( TextRenderer ) symbolRenderer ).moveYLineTo (( float ) yLine );
182
+ if (symbolRenderer instanceof LineRenderer ) {
183
+ symbolRenderer . move ( 0 , ( float ) yLine - (( LineRenderer ) symbolRenderer ).getYLine () );
166
184
} else {
167
185
symbolRenderer .move (0 , (float ) yLine - symbolRenderer .getOccupiedArea ().getBBox ().getY ());
168
186
}
@@ -182,12 +200,26 @@ public void draw(DrawContext drawContext) {
182
200
applyMargins (occupiedArea .getBBox (), true );
183
201
184
202
ListSymbolAlignment listSymbolAlignment = (ListSymbolAlignment )parent .<ListSymbolAlignment >getProperty (Property .LIST_SYMBOL_ALIGNMENT ,
185
- ListSymbolAlignment .RIGHT );
186
- float xPosition = x - symbolRenderer .getOccupiedArea ().getBBox ().getX ();
203
+ isRtl ? ListSymbolAlignment . LEFT : ListSymbolAlignment .RIGHT );
204
+ float dxPosition = x - symbolRenderer .getOccupiedArea ().getBBox ().getX ();
187
205
if (listSymbolAlignment == ListSymbolAlignment .RIGHT ) {
188
- xPosition += symbolAreaWidth - symbolRenderer .getOccupiedArea ().getBBox ().getWidth ();
206
+ if (!isRtl ) {
207
+ dxPosition += symbolAreaWidth - symbolRenderer .getOccupiedArea ().getBBox ().getWidth ();
208
+ }
209
+ } else if (listSymbolAlignment == ListSymbolAlignment .LEFT ) {
210
+ if (isRtl ) {
211
+ dxPosition -= (symbolAreaWidth - symbolRenderer .getOccupiedArea ().getBBox ().getWidth ());
212
+ }
213
+ }
214
+ if (symbolRenderer instanceof LineRenderer ) {
215
+ if (isRtl ) {
216
+ symbolRenderer .move (dxPosition - symbolRenderer .getOccupiedArea ().getBBox ().getWidth (), 0 );
217
+ } else {
218
+ symbolRenderer .move (dxPosition , 0 );
219
+ }
220
+ } else {
221
+ symbolRenderer .move (dxPosition , 0 );
189
222
}
190
- symbolRenderer .move (xPosition , 0 );
191
223
192
224
if (symbolRenderer .getOccupiedArea ().getBBox ().getRight () > parent .getOccupiedArea ().getBBox ().getLeft ()) {
193
225
beginElementOpacityApplying (drawContext );
@@ -234,13 +266,24 @@ private void applyListSymbolPosition() {
234
266
if (symbolRenderer != null ) {
235
267
ListSymbolPosition symbolPosition = (ListSymbolPosition ) ListRenderer .getListItemOrListProperty (this , parent , Property .LIST_SYMBOL_POSITION );
236
268
if (symbolPosition == ListSymbolPosition .INSIDE ) {
269
+ boolean isRtl = BaseDirection .RIGHT_TO_LEFT .equals (this .<BaseDirection >getProperty (Property .BASE_DIRECTION ));
237
270
if (childRenderers .size () > 0 && childRenderers .get (0 ) instanceof ParagraphRenderer ) {
238
271
ParagraphRenderer paragraphRenderer = (ParagraphRenderer ) childRenderers .get (0 );
239
272
Float symbolIndent = this .getPropertyAsFloat (Property .LIST_SYMBOL_INDENT );
240
- if (symbolIndent != null ) {
241
- symbolRenderer .setProperty (Property .MARGIN_RIGHT , UnitValue .createPointValue ((float ) symbolIndent ));
242
- }
243
- paragraphRenderer .childRenderers .add (0 , symbolRenderer );
273
+
274
+ if (symbolRenderer instanceof LineRenderer ) {
275
+ if (symbolIndent != null ) {
276
+ symbolRenderer .getChildRenderers ().get (1 ).setProperty (isRtl ? Property .MARGIN_LEFT : Property .MARGIN_RIGHT , UnitValue .createPointValue ((float ) symbolIndent ));
277
+ }
278
+ for (IRenderer childRenderer : symbolRenderer .getChildRenderers ()) {
279
+ paragraphRenderer .childRenderers .add (0 , childRenderer );
280
+ }
281
+ } else {
282
+ if (symbolIndent != null ) {
283
+ symbolRenderer .setProperty (isRtl ? Property .MARGIN_LEFT : Property .MARGIN_RIGHT , UnitValue .createPointValue ((float ) symbolIndent ));
284
+ }
285
+ paragraphRenderer .childRenderers .add (0 , symbolRenderer );
286
+ }
244
287
symbolAddedInside = true ;
245
288
} else if (childRenderers .size () > 0 && childRenderers .get (0 ) instanceof ImageRenderer ) {
246
289
Paragraph p = new Paragraph ();
@@ -272,7 +315,12 @@ private void applyListSymbolPosition() {
272
315
}
273
316
274
317
private boolean isListSymbolEmpty (IRenderer listSymbolRenderer ) {
275
- return listSymbolRenderer instanceof TextRenderer && ((TextRenderer ) listSymbolRenderer ).getText ().toString ().length () == 0 ;
318
+ if (listSymbolRenderer instanceof TextRenderer ) {
319
+ return ((TextRenderer ) listSymbolRenderer ).getText ().toString ().length () == 0 ;
320
+ } else if (listSymbolRenderer instanceof LineRenderer ) {
321
+ return ((TextRenderer ) listSymbolRenderer .getChildRenderers ().get (1 )).getText ().toString ().length () == 0 ;
322
+ }
323
+ return false ;
276
324
}
277
325
278
326
private float [] calculateAscenderDescender () {
0 commit comments