Skip to content

Commit 9dc56a7

Browse files
committed
Add support to li value property of ordered list ol
DEVSIX-2455
1 parent 0965f96 commit 9dc56a7

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

layout/src/main/java/com/itextpdf/layout/element/ListItem.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ This file is part of the iText (R) project.
4444
package com.itextpdf.layout.element;
4545

4646
import com.itextpdf.kernel.pdf.tagging.StandardRoles;
47-
import com.itextpdf.kernel.pdf.tagutils.DefaultAccessibilityProperties;
4847
import com.itextpdf.kernel.pdf.tagutils.AccessibilityProperties;
48+
import com.itextpdf.kernel.pdf.tagutils.DefaultAccessibilityProperties;
4949
import com.itextpdf.layout.property.ListNumberingType;
5050
import com.itextpdf.layout.property.ListSymbolPosition;
5151
import com.itextpdf.layout.property.Property;
@@ -75,6 +75,17 @@ public ListItem(String text) {
7575
add(new Paragraph(text).setMarginTop(0).setMarginBottom(0));
7676
}
7777

78+
/**
79+
* Customizes the index of the item in the list.
80+
*
81+
* @param ordinalValue the custom value property of an ordered list's list item.
82+
* @return this listItem.
83+
*/
84+
public ListItem setListSymbolOrdinalValue(int ordinalValue) {
85+
setProperty(Property.LIST_SYMBOL_ORDINAL_VALUE, ordinalValue);
86+
return this;
87+
}
88+
7889
/**
7990
* Creates a list item with an image.
8091
*
@@ -97,6 +108,7 @@ public <T1> T1 getDefaultProperty(int property) {
97108

98109
/**
99110
* Sets the list item symbol to be used.
111+
*
100112
* @param symbol the textual symbol to be used for the item.
101113
* @return this list item.
102114
*/
@@ -106,6 +118,7 @@ public ListItem setListSymbol(String symbol) {
106118

107119
/**
108120
* Sets the list item symbol to be used.
121+
*
109122
* @param text the {@link Text} object to be used for the item.
110123
* @return this list item.
111124
*/
@@ -116,6 +129,7 @@ public ListItem setListSymbol(Text text) {
116129

117130
/**
118131
* Sets the list item symbol to be used.
132+
*
119133
* @param image the {@link Image} object to be used for the item.
120134
* @return this list.
121135
*/
@@ -126,6 +140,7 @@ public ListItem setListSymbol(Image image) {
126140

127141
/**
128142
* Sets the list item numbering type to be used.
143+
*
129144
* @param listNumberingType the {@link ListNumberingType} that will generate appropriate prefixes for the {@link ListItem}.
130145
* @return this list item.
131146
*/

layout/src/main/java/com/itextpdf/layout/property/Property.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ private Property() {
8989
public static final int FIRST_LINE_INDENT = 18;
9090
public static final int FLOAT = 99;
9191
public static final int FLUSH_ON_DRAW = 19;
92+
9293
/**
9394
* Font family as String or PdfFont shall be set.
95+
*
9496
* @see com.itextpdf.io.font.constants.StandardFontFamilies
9597
*/
9698
public static final int FONT = 20;
@@ -139,6 +141,7 @@ private Property() {
139141
public static final int LIST_SYMBOL = 37;
140142
public static final int LIST_SYMBOL_ALIGNMENT = 38;
141143
public static final int LIST_SYMBOL_INDENT = 39;
144+
public static final int LIST_SYMBOL_ORDINAL_VALUE = 120;
142145
public static final int LIST_SYMBOL_PRE_TEXT = 41;
143146
public static final int LIST_SYMBOL_POSITION = 83;
144147
public static final int LIST_SYMBOL_POST_TEXT = 42;

layout/src/main/java/com/itextpdf/layout/renderer/ListRenderer.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ This file is part of the iText (R) project.
4545

4646

4747
import com.itextpdf.io.LogMessageConstant;
48-
import com.itextpdf.io.util.MessageFormatUtil;
4948
import com.itextpdf.io.font.constants.StandardFonts;
49+
import com.itextpdf.io.util.MessageFormatUtil;
5050
import com.itextpdf.io.util.TextUtil;
5151
import com.itextpdf.kernel.font.PdfFont;
5252
import com.itextpdf.kernel.font.PdfFontFactory;
@@ -67,13 +67,12 @@ This file is part of the iText (R) project.
6767
import com.itextpdf.layout.property.ListSymbolPosition;
6868
import com.itextpdf.layout.property.Property;
6969
import com.itextpdf.layout.property.UnitValue;
70-
import org.slf4j.Logger;
71-
import org.slf4j.LoggerFactory;
7270
import com.itextpdf.layout.tagging.LayoutTaggingHelper;
73-
7471
import java.io.IOException;
7572
import java.util.ArrayList;
7673
import java.util.List;
74+
import org.slf4j.Logger;
75+
import org.slf4j.LoggerFactory;
7776

7877
public class ListRenderer extends BlockRenderer {
7978

@@ -271,7 +270,7 @@ private LayoutResult correctListSplitting(IRenderer splitRenderer, IRenderer ove
271270
ListRenderer newOverflowRenderer = (ListRenderer) createOverflowRenderer(LayoutResult.PARTIAL);
272271
newOverflowRenderer.deleteOwnProperty(Property.FORCED_PLACEMENT);
273272
// ListItemRenderer for not rendered children of firstListItemRenderer
274-
newOverflowRenderer.childRenderers.add(((ListItemRenderer)firstListItemRenderer).createOverflowRenderer(LayoutResult.PARTIAL));
273+
newOverflowRenderer.childRenderers.add(((ListItemRenderer) firstListItemRenderer).createOverflowRenderer(LayoutResult.PARTIAL));
275274
newOverflowRenderer.childRenderers.addAll(splitRenderer.getChildRenderers().subList(1, splitRenderer.getChildRenderers().size()));
276275

277276
List<IRenderer> childrenStillRemainingToRender =
@@ -302,9 +301,10 @@ private LayoutResult correctListSplitting(IRenderer splitRenderer, IRenderer ove
302301
private LayoutResult initializeListSymbols(LayoutContext layoutContext) {
303302
if (!hasOwnProperty(Property.LIST_SYMBOLS_INITIALIZED)) {
304303
List<IRenderer> symbolRenderers = new ArrayList<>();
305-
int listItemNum = (int) this.<Integer>getProperty(Property.LIST_START, 1);
304+
int listItemNum = (int)this.<Integer>getProperty(Property.LIST_START, 1);
306305
for (int i = 0; i < childRenderers.size(); i++) {
307306
childRenderers.get(i).setParent(this);
307+
listItemNum = (childRenderers.get(i).<Integer>getProperty(Property.LIST_SYMBOL_ORDINAL_VALUE) != null) ? (int) childRenderers.get(i).<Integer>getProperty(Property.LIST_SYMBOL_ORDINAL_VALUE) : listItemNum;
308308
IRenderer currentSymbolRenderer = makeListSymbolRenderer(listItemNum, childRenderers.get(i));
309309
LayoutResult listSymbolLayoutResult = null;
310310
if (currentSymbolRenderer != null) {

0 commit comments

Comments
 (0)