【发布时间】:2021-12-21 02:42:20
【问题描述】:
我有简单的代码(iTextShar 库)用 Phrase 生成 PdfCell:
//I create new Phrase
Phrase p = new("Lorem ipsum", myFont);
//I set leading for Phrase
p.setFixedLeading(10f);
//I create new Table Cell end insert Phrase
PdfPCell cell = new(p);
为什么我不能直接在 PdfPCell 上生成 Phrase 并同时运行方法 .setFixedLeading。有这样的想法吗?
PdfPCell cell = new(Phrase p("Lorem ipsum", myFont).setFixedLeading(10f));
在创建新的 Phrase 对象时,有没有办法使用 .setFixedLeading 方法设置Leading?
【问题讨论】:
-
你不能这样做,因为
setFixedLeading不会返回任何东西。有没有类似于WithFixedLeading的方法返回this,你可以。这被称为流畅的界面。如果FixedLeading是一个属性,您还可以使用对象初始化器形式的一个表达式 (new Phrase("Lorem ipsum", myFont) { FixedLeading = 10f })。