Closed arnaud-zg closed 6 years ago
Thanks @arnaud-zg for working on this :) I'll take a deeper look at the PR tomorrow.
It's been a while that my pull request is on pending status, actually I need this feature on my project. It would be great if it can be merged this week.
@arnaud-zg: sorry for taking so long to come back. This implementation may compute wrong values as the browser would not break the words like this (won't add -
at the end)
I think it's important that the result reflects the behavior from the browser. Did you know that you can use the word-break: 'break-all'
css rule (either in css or overwrite in your call)
textMetrics(el).lines(text, {}, {'word-break': 'break-all'})
/*
[ 'Craspharetraph',
'aretragravida.Vi',
'vamusconsequ',
'atlacusvelposu',
'erecongue.Duis',
'aloremvitaeexa',
'uctorscelerisqu',
'enoneuturpis.Ut',
'imperdietmagn',
'asitametjustobi',
'bendumvehicul',
'a.' ]
*/
Browser:
Sorry to not mention this before.
Does this help with your project or do you depend on text-metrics
adding the ­
to each line?
You should also keep in mind, that adding the separator will result in grammatical errors
According to word-break
and hyphens
documentation, I updated my code and added those two option.
Case 1
textMetrics(el).lines(text, {}, {wordBreak: 'break-all'})
/*
[ 'Craspharetraph',
'aretragravida.Vi',
'vamusconsequ',
'atlacusvelposu',
'erecongue.Duis',
'aloremvitaeexa',
'uctorscelerisqu',
'enoneuturpis.Ut',
'imperdietmagn',
'asitametjustobi',
'bendumvehicul',
'a.' ]
*/
Case 2
textMetrics(el).lines(text, {}, {hyphens: 'auto'})
/*
[ 'Craspharetraph-',
'aretragravida.Vi-',
'vamusconsequ-',
'atlacusvelposu-',
'erecongue.Duis-',
'aloremvitaeexa-',
'uctorscelerisqu-',
'enoneuturpis.Ut-',
'imperdietmagn-',
'asitametjustobi-',
'bendumvehicul-',
'a.' ]
*/
Up
Sorry @arnaud-zg, i don't think it's a good idea to add this feature as this won't match the expected behavior. When doing auto hyphens this should be done properly with grammatical correct results.
:+1:
Details on issue #2