Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Feature Request - Underline annotation StyleText #117

Open
fgarcia-student opened this issue Feb 15, 2021 · 2 comments
Open

New Feature Request - Underline annotation StyleText #117

fgarcia-student opened this issue Feb 15, 2021 · 2 comments

Comments

@fgarcia-student
Copy link

pdfbox-layout supports underline styled text. I would like this feature exposed by easy-table through an AnnotationStyleTextBuilder.

@grasshopper7
Copy link

I have coded something similar for annotations with destination. U can find it here - https://github.com/grasshopper7/cucumber-pdf-report/tree/master/cucumber-pdf-report/src/main/java/tech/grasshopper/pdf/annotation/cell.
This is kind of coupled to other code but if u r interested to build upon it, feel free.

@jesudornenkrone
Copy link

Perhaps, we could have something like this:

package org.vandeseer.easytable.structure.cell.paragraph;

import lombok.Builder;
import lombok.Getter;
import lombok.NonNull;
import lombok.SneakyThrows;
import lombok.experimental.SuperBuilder;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.vandeseer.easytable.settings.Settings;
import org.vandeseer.easytable.util.PdfUtil;
import rst.pdfbox.layout.elements.Paragraph;
import rst.pdfbox.layout.text.FontDescriptor;
import rst.pdfbox.layout.text.NewLine;

import java.awt.*;

@SuperBuilder(toBuilder = true)
@getter
public class StyledText implements ParagraphProcessable {

@NonNull
private String text;

private Float fontSize;

private PDFont font;

private Color color;

@SneakyThrows
@Override
public void process(Paragraph paragraph, Settings settings) {
    final Float actualFontSize = getFontSize() != null ? getFontSize() : settings.getFontSize();
    final PDFont actualFont = getFont() != null ? getFont() : settings.getFont();
    final Color actualColor = getColor() != null ? getColor() : settings.getTextColor();

    // Handle new lines properly ...
    String[] lines = getText().split(PdfUtil.NEW_LINE_REGEX);
    for (int i = 0; i < lines.length; i++) {
        paragraph.add(new rst.pdfbox.layout.text.StyledText(lines[i], actualFontSize, actualFont, actualColor));
        if (i < lines.length - 1) {
            paragraph.add(new NewLine(new FontDescriptor(actualFont, actualFontSize)));
        }
    }

}

}

PS: I am very grateful for this great API. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants