Closed arahansen closed 5 years ago
Here is a (pretty hacky) prototype of something that I may be able to leverage to get what I'm looking for. Using a theoretical maxLines prop on Text.
Basically, since textkit is already doing the heavy lifting to truncate the string, I would be able to use the first line found to determine the cutoff point. I still would need to be able to customize the hyphenization token, which would be a change in textkit afaict.
Thanks @arahansen ! I agree this is a cool feature to have, but unfortunately react-pdf does not support it yet.
It's true we don't rely on pdfkit
text and line breaking logic. We use textkit
to perform these tasks, which was coded to produce much more higher quality text, plus Knuth & Plass line breaking algorithm and many other cool features. Imo this is something that should be implemented in textkit itself, since involves mutating the glyphs when text ran out of space.
Hope I can tackle this soon, but if you would like to give it a shot I'll be happy to help on the onboarding!
yeah, I'd love to take a look into this. So far looking at textkit, I see we have access to the glyphs and could potentially override them.
The approach I'm seeing here seems pretty use-case specific which doesn't seem great:
ie, we have:
// pseudo-code model
{ lines: ['abc-', 'def'] }
we could maybe assume if:
lines.length > maxLines
then:
// pseudo-code
const lines = [lines[0]] // remove excess lines
let glyphs = line.glyphRuns[0].glyphs
glyphs = glyphs.slice(0, glyphs.length - 1) // remove last glyph (assuming its a hyphen)
This doesn't seem right since the fact that the first line has a hyphen that connects to the next line seems like an implementation detail of react-pdf.
any additional on-boarding help you might be able to provide would be very much appreciated!
Digging into this a bit more, I'm not quite sure the best way to go about this. Seems like Yoga does not provide a reliable container height (it usually returns NaN
here) so I'm not seeing how we can determine the height at which to truncate text, since it ends up being the page height.
Any ideas on how to tackle this?
This also seems to be the cause (at least partially?) for overflowing text like this which I can't seem to find a solution for:
This is still not working... In example bellow:
1) instead of ...
there is &
2) since there is no word-wrap
or word-break
, the text is overflowing.
I have a trick for this by using height property
<View style={{ display: 'flex', flexDirection: 'row', height: 10 }}>
<View style={{ flex: 1 }}>
<Text>NNNNNNNNNN NNNNNNNNNN NNNNNNNNNN NNNNNNNNNN NNNNNNNNNN</Text>
</View>
</View>
Is your feature request related to a problem? Please describe. I'm looking to add ellipses to my text rendering. It looks like pdfkit handles this, but react-pdf uses a custom layout engine that (from what I can tell) does not call out to pdfkit.
Is this a feature that react-pdf could support? I started digging in a little, but couldn't really find where to get started.
Describe the solution you'd like An API that would be nice for this use case would be to handle it in the stylesheet ie:
Describe alternatives you've considered I suppose this could also be done as a prop on the Text component as well, but this seems a styling concern.
Alternatively, would it be possible to use pdfkit for an alternative Text layout? (for example,
SimpleText
or something along those lines). I'm assuming react-pdf is not using pdfkit because the layout there is not powerful enough, or not compatible with yoga.Additional context