diff --git a/graphics-pdfbox-layout/NOTICE.txt b/graphics-pdfbox-layout/NOTICE.txt index 076cb25..2b9a2a7 100644 --- a/graphics-pdfbox-layout/NOTICE.txt +++ b/graphics-pdfbox-layout/NOTICE.txt @@ -4,4 +4,20 @@ https://github.com/ralfstuckert/pdfbox-layout (MIT License) -as of October, 2020 \ No newline at end of file +as of October, 2020 + +and extended by "easytable" + +https://github.com/vandeseer/easytable + +(MIT License) + +as of March, 2021 + +and extended by "boxable" + +https://github.com/dhorions/boxable + +(Apache 2.0 License) + +as of March, 2021 diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/AbstractCell.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/AbstractCell.java index e797803..217c6c8 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/AbstractCell.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/AbstractCell.java @@ -211,119 +211,4 @@ public abstract class AbstractCell { public boolean isVerticallyAligned(VerticalAlignment alignment) { return getSettings().getVerticalAlignment() == alignment; } - - /*public abstract static class AbstractCellBuilder> { - - protected Settings settings = new Settings(); - - // We don't want to expose settings directly! - private void settings(Settings settings) {} - - public B borderWidth(final float borderWidth) { - settings.setBorderWidthTop(borderWidth); - settings.setBorderWidthBottom(borderWidth); - settings.setBorderWidthLeft(borderWidth); - settings.setBorderWidthRight(borderWidth); - return (B) this; - } - - public B borderWidthTop(final float borderWidth) { - settings.setBorderWidthTop(borderWidth); - return (B) this; - } - - public B borderWidthBottom(final float borderWidth) { - settings.setBorderWidthBottom(borderWidth); - return (B) this; - } - - public B borderWidthLeft(final float borderWidth) { - settings.setBorderWidthLeft(borderWidth); - return (B) this; - } - - public B borderWidthRight(final float borderWidth) { - settings.setBorderWidthRight(borderWidth); - return (B) this; - } - - public B borderStyleTop(final BorderStyleInterface style) { - settings.setBorderStyleTop(style); - return (B) this; - } - - public B borderStyleBottom(final BorderStyleInterface style) { - settings.setBorderStyleBottom(style); - return (B) this; - } - - public B borderStyleLeft(final BorderStyleInterface style) { - settings.setBorderStyleLeft(style); - return (B) this; - } - - public B borderStyleRight(final BorderStyleInterface style) { - settings.setBorderStyleRight(style); - return (B) this; - } - - public B borderStyle(final BorderStyleInterface style) { - return this.borderStyleLeft(style) - .borderStyleRight(style) - .borderStyleBottom(style) - .borderStyleTop(style); - } - - public B padding(final float padding) { - return this.paddingTop(padding) - .paddingBottom(padding) - .paddingLeft(padding) - .paddingRight(padding); - } - - public B paddingTop(final float padding) { - settings.setPaddingTop(padding); - return (B) this; - } - - public B paddingBottom(final float padding) { - settings.setPaddingBottom(padding); - return (B) this; - } - - public B paddingLeft(final float padding) { - settings.setPaddingLeft(padding); - return (B) this; - } - - public B paddingRight(final float padding) { - settings.setPaddingRight(padding); - return (B) this; - } - - public B horizontalAlignment(final HorizontalAlignment alignment) { - settings.setHorizontalAlignment(alignment); - return (B) this; - } - - public B verticalAlignment(final VerticalAlignment alignment) { - settings.setVerticalAlignment(alignment); - return (B) this; - } - - public B backgroundColor(final Color backgroundColor) { - settings.setBackgroundColor(backgroundColor); - return (B) this; - } - - public B borderColor(final Color borderColor) { - settings.setBorderColor(borderColor); - return (B) this; - } - - public B wordBreak(final Boolean wordBreak) { - settings.setWordBreak(wordBreak); - return (B) this; - } - }*/ } diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/AbstractTextCell.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/AbstractTextCell.java index 3954231..9d0aced 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/AbstractTextCell.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/AbstractTextCell.java @@ -78,23 +78,4 @@ public abstract class AbstractTextCell extends AbstractCell { public float getMaxWidth() { return getMaxWidthOfText() - getHorizontalPadding(); } - - /*public abstract static class AbstractTextCellBuilder> extends AbstractCellBuilder { - - public B font(final Font font) { - settings.setFont(font); - return (B) this; - } - - public B fontSize(final Integer fontSize) { - settings.setFontSize(fontSize); - return (B) this; - } - - public B textColor(final Color textColor) { - settings.setTextColor(textColor); - return (B) this; - } - - }*/ } diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/ParagraphCell.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/ParagraphCell.java index 4bad104..bc1dbbe 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/ParagraphCell.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/ParagraphCell.java @@ -76,59 +76,5 @@ public class ParagraphCell extends AbstractCell { public org.xbib.graphics.pdfbox.layout.elements.Paragraph getWrappedParagraph() { return wrappedParagraph; } - - /*public static class ParagraphBuilder { - - private final List processables = new LinkedList<>(); - - private ParagraphBuilder() { - } - - public ParagraphBuilder append(StyledText styledText) { - processables.add(styledText); - return this; - } - - public ParagraphBuilder append(Hyperlink hyperlink) { - processables.add(hyperlink); - return this; - } - - public ParagraphBuilder append(Markup markup) { - processables.add(markup); - return this; - } - - public ParagraphBuilder appendNewLine(Font font, float fontSize) { - processables.add(new NewLine(font, fontSize)); - return this; - } - - public Paragraph build() { - return new Paragraph(processables); - } - } - - public static ParagraphBuilder builder() { - return new ParagraphBuilder(); - }*/ } - - /*public abstract static class ParagraphCellBuilder> extends AbstractCellBuilder { - - public B font(final Font font) { - settings.setFont(font); - return (B) this; - } - - public B fontSize(final Integer fontSize) { - settings.setFontSize(fontSize); - return (B) this; - } - - public B textColor(final Color textColor) { - settings.setTextColor(textColor); - return (B) this; - } - }*/ } diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/PdfUtil.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/PdfUtil.java index bdc8b4a..180ccb0 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/PdfUtil.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/table/PdfUtil.java @@ -26,7 +26,7 @@ public final class PdfUtil { * @param fontSize FontSize of String * @return Width (in points) */ - public static float getStringWidth(final String text, final Font font, final int fontSize) { + public static float getStringWidth(String text, Font font, int fontSize) { return Arrays.stream(text.split(NEW_LINE_REGEX)) .max(Comparator.comparing(String::length)) .map(x -> { @@ -40,25 +40,20 @@ public final class PdfUtil { } private static float getWidthOfStringWithoutNewlines(String text, Font font, int fontSize) throws IOException { - - final List codePointsAsString = text.codePoints() + List codePointsAsString = text.codePoints() .mapToObj(codePoint -> new String(new int[]{codePoint}, 0, 1)) .collect(Collectors.toList()); - List widths = new ArrayList<>(); - - for (final String codepoint : codePointsAsString) { + for (String codepoint : codePointsAsString) { try { widths.add(font.getRegularFont().getStringWidth(codepoint) * fontSize / 1000F); } catch (final IllegalArgumentException | IOException e) { widths.add(font.getRegularFont().getStringWidth("–") * fontSize / 1000F); } } - return widths.stream().reduce(0.0f, Float::sum); } - /** * Computes the height of a font. * @@ -66,7 +61,7 @@ public final class PdfUtil { * @param fontSize FontSize * @return Height of font */ - public static float getFontHeight(Font font, final int fontSize) { + public static float getFontHeight(Font font, int fontSize) { return font.getRegularFont().getFontDescriptor().getCapHeight() * fontSize / 1000F; } @@ -79,21 +74,20 @@ public final class PdfUtil { * @param maxWidth Maximal width of resulting text-lines * @return A list of lines, where all are smaller than maxWidth */ - public static List getOptimalTextBreakLines(final String text, final Font font, final int fontSize, final float maxWidth) { + public static List getOptimalTextBreakLines(String text, Font font, int fontSize, float maxWidth) { List result = new ArrayList<>(); - for (final String line : text.split(NEW_LINE_REGEX)) { + for (String line : text.split(NEW_LINE_REGEX)) { if (PdfUtil.doesTextLineFit(line, font, fontSize, maxWidth)) { result.add(line); } else { result.addAll(PdfUtil.wrapLine(line, font, fontSize, maxWidth)); } } - return result; } - private static List wrapLine(final String line, final Font font, final int fontSize, final float maxWidth) { - if (PdfUtil.doesTextLineFit(line, font, fontSize, maxWidth)) { + private static List wrapLine(String line, Font font, int fontSize, float maxWidth) { + if (doesTextLineFit(line, font, fontSize, maxWidth)) { return Collections.singletonList(line); } List goodLines = new ArrayList<>(); @@ -106,7 +100,7 @@ public final class PdfUtil { return goodLines; } - private static List splitBySize(final String line, final Font font, final int fontSize, final float maxWidth) { + private static List splitBySize(String line, Font font, int fontSize, float maxWidth) { List returnList = new ArrayList<>(); for (int i = line.length() - 1; i > 0; i--) { String fittedNewLine = line.substring(0, i) + "-"; @@ -120,11 +114,10 @@ public final class PdfUtil { return returnList; } - - private static String buildALine(final Stack words, - final Font font, - final int fontSize, - final float maxWidth) { + private static String buildALine(Stack words, + Font font, + int fontSize, + float maxWidth) { StringBuilder line = new StringBuilder(); float width = 0; while (!words.empty()) {