fix OOB exception, add indent command, plus cosmetic changes
This commit is contained in:
parent
c1f5ebd409
commit
e3386df689
6 changed files with 39 additions and 18 deletions
|
@ -6,6 +6,7 @@ import org.xbib.graphics.pdfbox.layout.element.render.Transform;
|
||||||
import org.xbib.graphics.pdfbox.layout.text.Alignment;
|
import org.xbib.graphics.pdfbox.layout.text.Alignment;
|
||||||
import org.xbib.graphics.pdfbox.layout.text.DrawListener;
|
import org.xbib.graphics.pdfbox.layout.text.DrawListener;
|
||||||
import org.xbib.graphics.pdfbox.layout.position.Position;
|
import org.xbib.graphics.pdfbox.layout.position.Position;
|
||||||
|
import org.xbib.graphics.pdfbox.layout.text.Indent;
|
||||||
import org.xbib.graphics.pdfbox.layout.text.TextFlow;
|
import org.xbib.graphics.pdfbox.layout.text.TextFlow;
|
||||||
import org.xbib.graphics.pdfbox.layout.text.TextSequenceUtil;
|
import org.xbib.graphics.pdfbox.layout.text.TextSequenceUtil;
|
||||||
import org.xbib.graphics.pdfbox.layout.text.WidthRespecting;
|
import org.xbib.graphics.pdfbox.layout.text.WidthRespecting;
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package org.xbib.graphics.pdfbox.layout.element.scripting.command;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import org.xbib.graphics.pdfbox.layout.element.Element;
|
||||||
|
import org.xbib.graphics.pdfbox.layout.element.Paragraph;
|
||||||
|
import org.xbib.graphics.pdfbox.layout.element.scripting.Engine;
|
||||||
|
import org.xbib.graphics.pdfbox.layout.element.scripting.State;
|
||||||
|
import org.xbib.graphics.pdfbox.layout.text.Indent;
|
||||||
|
import org.xbib.graphics.pdfbox.layout.text.SpaceUnit;
|
||||||
|
import org.xbib.settings.Settings;
|
||||||
|
|
||||||
|
import static org.xbib.graphics.pdfbox.layout.util.PdfUtil.mmToPt;
|
||||||
|
|
||||||
|
public class IndentCommand implements Command {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Engine engine, State state, Settings settings) throws IOException {
|
||||||
|
float value = settings.getAsFloat("value", 0.0f);
|
||||||
|
Element element = state.getElements().peek();
|
||||||
|
if (element instanceof Paragraph) {
|
||||||
|
Paragraph paragraph = (Paragraph) element;
|
||||||
|
paragraph.add(new Indent(mmToPt(value), SpaceUnit.pt));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -106,9 +106,7 @@ public class Row {
|
||||||
if (element instanceof Cell) {
|
if (element instanceof Cell) {
|
||||||
cells.add((Cell) element);
|
cells.add((Cell) element);
|
||||||
} else if (element instanceof HorizontalRuler) {
|
} else if (element instanceof HorizontalRuler) {
|
||||||
Cell cell = DrawableCell.builder()
|
Cell cell = DrawableCell.builder().drawable((Drawable) element).build();
|
||||||
.drawable((Drawable) element)
|
|
||||||
.build();
|
|
||||||
cells.add(cell);
|
cells.add(cell);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -308,10 +308,12 @@ public class Table {
|
||||||
while (table.isRowSpanAt(rowIndex, columnIndex)) {
|
while (table.isRowSpanAt(rowIndex, columnIndex)) {
|
||||||
columnIndex++;
|
columnIndex++;
|
||||||
}
|
}
|
||||||
Column column = table.getColumns().get(columnIndex);
|
cell.setColumn(table.getColumns().get(columnIndex));
|
||||||
cell.setColumn(column);
|
|
||||||
cell.setWidth(getAvailableCellWidthRespectingSpan(columnIndex, cell.getColSpan()));
|
cell.setWidth(getAvailableCellWidthRespectingSpan(columnIndex, cell.getColSpan()));
|
||||||
columnIndex += cell.getColSpan();
|
columnIndex += cell.getColSpan();
|
||||||
|
if (columnIndex > table.getNumberOfColumns() - 1) {
|
||||||
|
columnIndex = table.getNumberOfColumns();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < table.getColumns().size(); i++) {
|
for (int i = 0; i < table.getColumns().size(); i++) {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.xbib.graphics.pdfbox.layout.text;
|
package org.xbib.graphics.pdfbox.layout.text;
|
||||||
|
|
||||||
import org.xbib.graphics.pdfbox.layout.font.BaseFont;
|
|
||||||
import org.xbib.graphics.pdfbox.layout.font.FontDescriptor;
|
import org.xbib.graphics.pdfbox.layout.font.FontDescriptor;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
|
||||||
|
|
|
@ -42,17 +42,18 @@ public class IndentCharacters {
|
||||||
try {
|
try {
|
||||||
this.level = level == null ? 0 : level.length() + 1;
|
this.level = level == null ? 0 : level.length() + 1;
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
|
//
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
this.indentUnit = indentUnit == null ? SpaceUnit.em : SpaceUnit
|
this.indentUnit = indentUnit == null ? SpaceUnit.em : SpaceUnit.valueOf(indentUnit);
|
||||||
.valueOf(indentUnit);
|
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
|
//
|
||||||
}
|
}
|
||||||
float defaultIndent = this.indentUnit == SpaceUnit.em ? 4 : 10;
|
float defaultIndent = this.indentUnit == SpaceUnit.em ? 4 : 10;
|
||||||
try {
|
try {
|
||||||
this.indentWidth = indentWidth == null ? defaultIndent
|
this.indentWidth = indentWidth == null ? defaultIndent : Integer.parseInt(indentWidth);
|
||||||
: Integer.parseInt(indentWidth);
|
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -256,8 +257,7 @@ public class IndentCharacters {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class IndentCharacterFactory implements
|
private static class IndentCharacterFactory implements ControlCharacters.ControlCharacterFactory {
|
||||||
ControlCharacters.ControlCharacterFactory {
|
|
||||||
|
|
||||||
private final static Pattern PATTERN = Pattern
|
private final static Pattern PATTERN = Pattern
|
||||||
.compile("^-(!)|^([ ]*)-(-)(\\{(\\d*)(em|pt)?\\})?|^([ ]*)-(\\+)(\\{(.+)?:(\\d*)(em|pt)?\\})?|^([ ]*)-(#)(\\{((?!:).)?(.+)?:((\\d*))((em|pt))?\\})?");
|
.compile("^-(!)|^([ ]*)-(-)(\\{(\\d*)(em|pt)?\\})?|^([ ]*)-(\\+)(\\{(.+)?:(\\d*)(em|pt)?\\})?|^([ ]*)-(#)(\\{((?!:).)?(.+)?:((\\d*))((em|pt))?\\})?");
|
||||||
|
@ -272,23 +272,19 @@ public class IndentCharacters {
|
||||||
if ("!".equals(matcher.group(1))) {
|
if ("!".equals(matcher.group(1))) {
|
||||||
return UNINDENT_CHARACTER;
|
return UNINDENT_CHARACTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("-".equals(matcher.group(3))) {
|
if ("-".equals(matcher.group(3))) {
|
||||||
return new IndentCharacter(matcher.group(2), matcher.group(5),
|
return new IndentCharacter(matcher.group(2), matcher.group(5),
|
||||||
matcher.group(6));
|
matcher.group(6));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("+".equals(matcher.group(8))) {
|
if ("+".equals(matcher.group(8))) {
|
||||||
return new ListCharacter(matcher.group(7), matcher.group(11),
|
return new ListCharacter(matcher.group(7), matcher.group(11),
|
||||||
matcher.group(12), matcher.group(10));
|
matcher.group(12), matcher.group(10));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("#".equals(matcher.group(14))) {
|
if ("#".equals(matcher.group(14))) {
|
||||||
return new EnumerationCharacter(matcher.group(13),
|
return new EnumerationCharacter(matcher.group(13),
|
||||||
matcher.group(18), matcher.group(20),
|
matcher.group(18), matcher.group(20),
|
||||||
matcher.group(16), matcher.group(17));
|
matcher.group(16), matcher.group(17));
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new IllegalArgumentException("unkown indentation " + text);
|
throw new IllegalArgumentException("unkown indentation " + text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,9 +310,9 @@ public class IndentCharacters {
|
||||||
|
|
||||||
private static String getBulletCharacter(final int level) {
|
private static String getBulletCharacter(final int level) {
|
||||||
if (level % 2 == 1) {
|
if (level % 2 == 1) {
|
||||||
return System.getProperty("pdfbox.layout.bullet.odd", BULLET);
|
return System.getProperty("org.xbib.graphics.pdfbox.layout.bullet.odd", BULLET);
|
||||||
}
|
}
|
||||||
return System.getProperty("pdfbox.layout.bullet.even", DOUBLE_ANGLE);
|
return System.getProperty("org.xbib.graphics.pdfbox.layout.bullet.even", DOUBLE_ANGLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String BULLET = "\u2022";
|
private static final String BULLET = "\u2022";
|
||||||
|
|
Loading…
Reference in a new issue