phax / ph-pdf-layout

Java library for creating fluid page layouts with Apache PDFBox. Supporting multi-page tables, different page layouts etc.
Apache License 2.0
61 stars 11 forks source link

How to place different styled text in one string? #11

Open RangerMak opened 4 years ago

RangerMak commented 4 years ago

For example, I want to make some part of text bold styled: This text contains bold part.

Calling pagesSet.addElement(new PLText(lorem, italicFont12)); will add string with specified font. New call of pagesSet.addElement wall add new string.

PLText don't support markups. Also there is not element what containing list of PLText.

Is it possible to solve this problem with current functional?

phax commented 4 years ago

Hi, that is currently not possible. I would have needed that myself already a couple of times but was always afraid of the effort :/

RangerMak commented 4 years ago

I think this problem can be solved by creating of renderable list what containing renderable elements.

All elements of this list should be rendered one after another. After rendering of first element we need to save its end position. This position will be start offset for next element of list. And so on. Using offset of first line in lines preparing function helps to place rendered element into proper position. Also offset of first line in lines preparing function can solve indent issue (see #9).

What do you think about this?

The problem for justify alignment. If text have justify alignment its need to check if current element of list is last? Last element aligns as usual. But i don't know how to make justify alignment of current element when we don't know length of next element.

phax commented 4 years ago

Well we could go for "inline elements" only, so all subclasses of AbstractPLInlineElement. Inline elements usually don't have an alignment (the alignment of PLText is somehow special), and a "list of inline elements with alignment" could be a subtask.

I don't think this would help for #9, because of the "more intelligent indentation" required for multiline bullet point values. But having this "sequence of inline elements" sure could be used as the basis for other elements. But special ligature handling etc. will be an issue, but an issue to deal with at a later point in time

RangerMak commented 4 years ago

By talking about #9 i mean text flowing around indent (like in Word document).

If indent element will be "inline element" (AbstractPLInlineElement) with specified size (length) then it can be placed at begin of "list of inline elements". So we can receive text flow around this element.

This solution not for bullet point lists.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

phax commented 1 month ago

Copying some logic over from https://github.com/ralfstuckert/pdfbox-layout might be a good starting point