How to fix Leading causing vertical alignment to be ignored #1175
-
I am trying to set the spacing between text that is wrapped to be slightly larger. To my knowledge, this can be achieved through the leading property of a PdfPCell. However, every time that I try to add leading to my PdfPCell, it seems to suddenly ignore my vertical alignment that I assign it. Even when I set the leading to the default leading, it seems to ignore the vertical formatting.
If I try to split up the wrapped text into different chunks, I seem to encounter the same issue.
I am able to pad the tops and/or bottoms of the cells to try to get these to be middle-aligned, but this is a hacky solution that produces cells that are larger than desired.
Does anyone know a better solution to have vertical formatting followed, while also having spacing between wrapped text lines to be followed? Thank you in advance, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I finally found the time to investigate this issue more thoroughly. While at first, it may appear that leading causes vertical alignment to be ignored, this could be less from true. With this example, where the vertical alignment is set to ALIGN_BOTTOM, we can see that the vertical alignment is respected.
If we look at the example below, we can start to get a better picture of what's going on.
Upon analyzing the source code of OpenPDF, particularly regarding the handling of leading for PdfPCells and ColumnTexts, it becomes apparent that the current implementation deviates from the standard definition of leading as described by Adobe. According to Adobe, "leading" refers to the vertical space between lines of type. In the current implementation, leading is applied between the margin and the first line that appears for PdfPCells and ColumnTexts. This is counterintuitive to Adobe's definition, where leading is defined as affecting the space between successive lines of text. To address this issue, a straightforward solution would be to introduce a boolean variable in the 'go(boolean)' method which could effectively distinguish whether the current cell is the first in sequence. This addition would enable precise control over when leading should be applied, thereby resolving the above discrepancy. Edit: I found a built in solution to this problem which acts nearly the same as my proposed solution. Column Texts and in turn PdfPCells have a function called 'setUseAscender', which determines if the leading will apply to the first line or not. I find it an interesting choice to have this default to false, but it is nice to have a proper fix. |
Beta Was this translation helpful? Give feedback.
I finally found the time to investigate this issue more thoroughly. While at first, it may appear that leading causes vertical alignment to be ignored, this could be less from true. With this example, where the vertical alignment is set to ALIGN_BOTTOM, we can see that the vertical alignment is respected.
If we look at the example below, we can start to get a better picture of what's going on.