设置目录样式
示例代码
package test.create.c10;
import iofd.kernel.colors.OfdRgbColor;
import iofd.layout.DefaultPageProperty;
import iofd.layout.OfdDocument;
import iofd.layout.block.PageSeparator;
import iofd.layout.block.Paragraph;
import iofd.layout.block.paragraph.Text;
import iofd.layout.physcial.page.menu.MenuCreator;
import java.util.HashMap;
import java.util.Map;
import test.create.TestDocUtil;
public class C1006CustomizeStyleMultLevelMenuWithFrontCover {
public static void main(String[] args) throws Throwable {
C1006CustomizeStyleMultLevelMenuWithFrontCover o = new C1006CustomizeStyleMultLevelMenuWithFrontCover();
o.done();
}
private void done() throws Throwable {
String clzName = this.getClass().getSimpleName();
System.out.println(clzName + " begin");
OfdDocument doc = new OfdDocument();
DefaultPageProperty prop = DefaultPageProperty.createDefaultPageProperty();
prop.setDebug(true);
prop.setLogDebug(true);
doc.setDefaultPageProperty(prop);
doc.setSetFrontCoverPage(true);
MenuCreator menuCreator = new MenuCreator("Index");
menuCreator.setMaxPaintLevel(3);
menuCreator.setMaxOpenLevel(2);
Map defaultStyle = createDefaultStyle();
menuCreator.setDefaultStyle(defaultStyle);
doc.setMenuCreator(menuCreator);
Paragraph p = new Paragraph();
String s = "该文本展示如何设置多级目录,并且带封面[本页为封面],这里自定义了目录列表各级采用不同的显示样式";
p.add(new Text(s));
doc.add(p);
doc.add(new PageSeparator());
p = new Paragraph();
s = "1 测试目录第1级";
p.add(new Text(s));
p.createCurrentLevelMenuInfo(null, s);
doc.add(p);
doc.add(new PageSeparator());
p = new Paragraph();
s = "1.1 测试目录第2级";
p.add(new Text(s));
p.createSubLevelMenuInfo(null, s);
doc.add(p);
doc.add(new PageSeparator());
p = new Paragraph();
s = "1.1.1 测试目录第3级";
p.add(new Text(s));
p.createSubLevelMenuInfo(null, s);
doc.add(p);
doc.add(new PageSeparator());
p = new Paragraph();
s = "1.1.1.1 测试目录第4级";
p.add(new Text(s));
p.createSubLevelMenuInfo(null, s);
doc.add(p);
doc.add(new PageSeparator());
p = new Paragraph();
s = "1.1.2 测试目录第3级";
p.add(new Text(s));
p.createManualMenuInfo(null, s, 3);
doc.add(p);
doc.add(new PageSeparator());
p = new Paragraph();
s = "1.1.2.1 测试目录第4级";
p.add(new Text(s));
p.createSubLevelMenuInfo(null, s);
doc.add(p);
doc.add(new PageSeparator());
p = new Paragraph();
s = "1.1.2.2 测试目录第4级";
p.add(new Text(s));
p.createCurrentLevelMenuInfo(null, s);
doc.add(p);
doc.add(new PageSeparator());
p = new Paragraph();
s = "2 测试目录第1级";
p.add(new Text(s));
p.createManualMenuInfo(null, s, 1);
doc.add(p);
doc.add(new PageSeparator());
p = new Paragraph();
s = "2.1 测试目录第2级";
p.add(new Text(s));
p.createSubLevelMenuInfo(null, s);
doc.add(p);
doc.add(new PageSeparator());
p = new Paragraph();
s = "2.1.1 测试目录第3级";
p.add(new Text(s));
p.createSubLevelMenuInfo(null, s);
doc.add(p);
doc.add(new PageSeparator());
p = new Paragraph();
s = "2.1.1.1 测试目录第4级";
p.add(new Text(s));
p.createSubLevelMenuInfo(null, s);
doc.add(p);
String fileName = TestDocUtil.getOfdFilePath(this.getClass());
doc.save(fileName);
System.out.println(clzName + " end");
}
private Map createDefaultStyle(){
Map ret = new HashMap<>();
Text t2 = new Text("");
t2.setColor(OfdRgbColor.RED);
ret.put("2", t2);
Text t3 = new Text("");
t3.setItalic(true);
ret.put("3", t3);
return ret;
}
}