Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hyphenating text #1511

Open
Christian24 opened this issue Oct 3, 2018 · 4 comments
Open

hyphenating text #1511

Christian24 opened this issue Oct 3, 2018 · 4 comments

Comments

@Christian24
Copy link

Hello,

A client asks me for hyphenating text in the pdf output. Looking at #264 it is currently not possible. I am thinking about implementing this if it is possible in a reasonable timeframe and you're happy to accept a pull request. My goal would be to offer a callback hyphenateWord(word) that the user can override with whatever functionality the user pleases. I do not want to add new dependencies or locale features to pdfmake.

I think my new code should be executed somewhere here:

var widthPerChar = inline.width / inline.text.length;

Am I on the right path?

@liborm85
Copy link
Collaborator

liborm85 commented Oct 5, 2018

Issue #264 is about hiding text without breaking.

Now is supported by issue #204 "hard-wrapping" text words (if is word too long is breaked after max size) here:

if (!inline.noWrap && inline.text.length > 1 && inline.width > line.getAvailableWidth()) {
var widthPerChar = inline.width / inline.text.length;
var maxChars = Math.floor(line.getAvailableWidth() / widthPerChar);
if (maxChars < 1) {
maxChars = 1;
}
if (maxChars < inline.text.length) {
var newInline = cloneInline(inline);
newInline.text = inline.text.substr(maxChars);
inline.text = inline.text.substr(0, maxChars);
newInline.width = textTools.widthOfString(newInline.text, newInline.font, newInline.fontSize, newInline.characterSpacing, newInline.fontFeatures);
inline.width = textTools.widthOfString(inline.text, inline.font, inline.fontSize, inline.characterSpacing, inline.fontFeatures);
textNode._inlines.unshift(newInline);
isHardWrap = true;
}
}

Text hyphenating according to some algorithm is too complicated to implementation. I do not know how it could be solved now.

@Christian24
Copy link
Author

How about offering a callback function like a suggested, so users can implement it themselves? If the callback function is undefined, the library would just fall back to the default behavior that is there now.

@SandraK82
Copy link

One nice way could be the support of softhyphens (html ­ symbol, utf8 U+00AD). This way the dev can supply pre tagged text to pdfmake and pdfmake does not need to rely on anything. If no soft hyphen is supplied, nothing changes.
Currently, the softhyphen is interpreted as whitespace, therefore the line break is done correctly, but at the end of a line, the U+00AD needs to replaced by - or U+2011 (which might result in a moving of the word to the next line).

@luizbills
Copy link

any progress on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants