Skip to content

Commit 09f86ad

Browse files
Implement ListItem.setListSymbol
DEVSIX-443
1 parent 14612e2 commit 09f86ad

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public enum Property {
4747
LEFT,
4848
LINE_DRAWER,
4949
LIST_START,
50-
LIST_SYMBOL,
50+
LIST_SYMBOL(true),
5151
LIST_SYMBOL_INDENT,
5252
MARGIN_BOTTOM,
5353
MARGIN_LEFT,

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.itextpdf.layout.element;
22

33
import com.itextpdf.kernel.pdf.PdfName;
4+
import com.itextpdf.layout.Property;
45
import com.itextpdf.layout.renderer.ListItemRenderer;
56

67
/**
@@ -37,6 +38,46 @@ public ListItem(Image image) {
3738
add(image);
3839
}
3940

41+
/**
42+
* Sets the list item symbol to be used.
43+
* @param symbol the textual symbol to be used for the item.
44+
* @return this list item.
45+
*/
46+
public ListItem setListSymbol(String symbol) {
47+
return setListSymbol(new Text(symbol));
48+
}
49+
50+
/**
51+
* Sets the list item symbol to be used.
52+
* @param text the {@link Text} object to be used for the item.
53+
* @return this list item.
54+
*/
55+
public ListItem setListSymbol(Text text) {
56+
return setProperty(Property.LIST_SYMBOL, text);
57+
}
58+
59+
/**
60+
* Sets the list item symbol to be used.
61+
* @param image the {@link Image} object to be used for the item.
62+
* @return this list.
63+
*/
64+
public ListItem setListSymbol(Image image) {
65+
return setProperty(Property.LIST_SYMBOL, image);
66+
}
67+
68+
/**
69+
* Sets the list item numbering type to be used.
70+
* @param listNumberingType the {@link Property#ListNumberingType} that will generate appropriate prefixes for the {@link ListItem}.
71+
* @return this list item.
72+
*/
73+
public ListItem setListSymbol(Property.ListNumberingType listNumberingType) {
74+
// Do not draw any points after ZapfDingbats special number symbol
75+
if (listNumberingType == Property.ListNumberingType.ZAPF_DINGBATS_1 || listNumberingType == Property.ListNumberingType.ZAPF_DINGBATS_2 ||
76+
listNumberingType == Property.ListNumberingType.ZAPF_DINGBATS_3 || listNumberingType == Property.ListNumberingType.ZAPF_DINGBATS_4) {
77+
}
78+
return setProperty(Property.LIST_SYMBOL, listNumberingType);
79+
}
80+
4081
@Override
4182
protected ListItemRenderer makeNewRenderer() {
4283
return new ListItemRenderer(this);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public LayoutResult layout(LayoutContext layoutContext) {
3131
int listItemNum = getProperty(Property.LIST_START, 1);
3232
for (int i = 0; i < childRenderers.size(); i++) {
3333
if (childRenderers.get(i).getModelElement() instanceof ListItem) {
34-
IRenderer currentSymbolRenderer = makeListSymbolRenderer(listItemNum++);
34+
IRenderer currentSymbolRenderer = makeListSymbolRenderer(listItemNum++, childRenderers.get(i));
3535
symbolRenderers.add(currentSymbolRenderer);
3636
LayoutResult listSymbolLayoutResult = currentSymbolRenderer.layout(layoutContext);
3737
if (listSymbolLayoutResult.getStatus() != LayoutResult.FULL) {
@@ -57,8 +57,8 @@ public LayoutResult layout(LayoutContext layoutContext) {
5757
return super.layout(layoutContext);
5858
}
5959

60-
protected IRenderer makeListSymbolRenderer(int index) {
61-
Object defaultListSymbol = modelElement.getProperty(Property.LIST_SYMBOL);
60+
protected IRenderer makeListSymbolRenderer(int index, IRenderer renderer) {
61+
Object defaultListSymbol = renderer.getProperty(Property.LIST_SYMBOL);
6262
if (defaultListSymbol instanceof Text) {
6363
return new TextRenderer((Text) defaultListSymbol).setParent(this);
6464
} else if (defaultListSymbol instanceof Image) {

0 commit comments

Comments
 (0)