phax/ph-pdf-layout

How to make indent of multiline text

RangerMak opened this issue · 7 comments

I need to make paragraphs and lists (bulleted and numbered).
How to make indentation of multiline text with prefix (bullet symbol or another text)?

phax commented

That is a very good question - I haven't done this myself yet....
If you are willing to brainstorm with me, we could use this thread.

For simple indent i'm use function

private PLHBox makeIndentedPLHBox(String prefix, EHorzAlignment prefixHorizAlignment,
                                    String text, EHorzAlignment textHorizAlignment,
                                    FontSpec fontSpec, float indentSize) {

    EHorzAlignment prefHAl = prefixHorizAlignment;
    if (prefHAl == null) {
      prefHAl = EHorzAlignment.DEFAULT;
    }

    EHorzAlignment txtHAL = textHorizAlignment;
    if (txtHAL == null) {
      txtHAL = EHorzAlignment.DEFAULT;
    }

    PLHBox plhBox = new PLHBox();
    plhBox.addColumn(new PLBox(new PLText(prefix, fontSpec)).setHorzAlign(prefHAl), WidthSpec.abs(indentSize));
    plhBox.addColumn(new PLText(text, fontSpec).setHorzAlign(txtHAL), WidthSpec.auto());

    return plhBox;
  }

With it i can make lists.

But i still have problem with text flows around indent box.

phax commented

Okay that looks like a reasonable start.
As I have done quite some work on tables (cell splitting, repeating headers etc.) I suggest to use that as the basis.
Could we do an API like this:

interface IBulletPointCreator {
  String getBulletPointText (int nIndex);
}

class PLBulletPointList implements IPLElement {
  setLeftWidth (WidthSpec IndentWidth);
  setBulletPointCreator (IBulletPointCreator  bpc);
  void addListItem (IPLElement<?> aElement);
}

That would:

  • Add arbitrary elements (with arbitrary styling) as bullet point items
  • Allow nested bullet point lists
  • Allow for arbitrary "bullet points" (like dots, numbers, letters, etc.)
  • Render as a big table with 2 columns

What do you think?

I have some doubt about rendering as table.
How this elements will copy/paste from result PDF to another editors?

phax commented

That is a very good question I cannot answer. Basically the table also "just" aligned text. There is no such construct in PDF.
When copy pasting I think it is important that the "baseline" of the stuff is the same. And if the text is "en-block" inside the PDF it will also help I guess... But we basically need to try it

phax commented

A first version based on a table works. Using the Symbol font with vertical alignment was a bit tricky, but the output look okay to me. Everything should be customizable enough.

phax commented

Part of 5.1.0 release