vandeseer / easytable

Small table drawing library built upon Apache PDFBox
MIT License
246 stars 94 forks source link

support superscript at the end of the text #95

Closed VakhoQ closed 3 years ago

VakhoQ commented 4 years ago

I added functionality for SuperScritp.

Usage:


  .text("Hello World").borderWidth(4).backgroundColor(Color.WHITE)
  .superScript(TextCell.builder().text("2").fontSize(6).textRise(5).build())

By default textRise is 0.

Note, right now only TextCell supports this functionality. In the future , I think we need abstract methods in the AbstractTextCell to avoid casting and checking instances:

    public abstract boolean hasSuperScript();
    public abstract AbstractTextCell superText();

Under the hood we have the following:

contentStream.setTextRise(styledText.getTextRise());

Additionally, I add logic to move text to the next line if super-text does not fit to the current column.

vandeseer commented 4 years ago

Hi @VakhoQ, thanks for your pull request.

I will look at it a bit closer as soon as I find time for it. That could last a bit though, I am pretty busy at the moment.

Best, Stefan

VakhoQ commented 3 years ago

@vandeseer Hi. Let me ask you if you had chance to look into the pull request?

vandeseer commented 3 years ago

Hey @VakhoQ,

I am really sorry not having had a look earlier!

There are some general remarks I have now after a first look: As you already said there is a lot of casting going on and it feels a bit hacky the way it is implemented right now. Reason being that is implemented within TextCell. What I mean by "hacky" is:

                if(cell instanceof TextCell){
                    TextCell textCell = (TextCell) cell;
                    if(textCell.hasSuperScript()){
                        textCell= textCell.getSuperScript();
                        textCell.getSettings().fillingMergeBy(row.getSettings());
                    }
                }

This is not very elegant. So I would suggest the following approach: Why not using a cell type of its own? E.g. SuperScriptCell or maybe (to be a bit more generic and allow for further similar changes): ExtendedTextCell or something similar. Then there is no need for such casts on the one hand side and and secondly it's implementation is more independent. There would be some kind of "basic text cell" and another one that is all of that plus some extras.

vandeseer commented 3 years ago

Closed due to https://github.com/vandeseer/easytable/pull/125