jeffchan / truncate.js

fast, intelligent javascript text truncation
MIT License
98 stars 45 forks source link

maxHeight calculation should not use parseInt #31

Open drukepple opened 8 years ago

drukepple commented 8 years ago

At line 416 maxHeight is calculated by parseInt(this.options.lineHeight, 10). If lineHeight is set to something like 1.2em, for some font sizes it becomes a computed value of something like 21.6px. parseInt then floors this value, making it 21.

If lines is then set to 2, maxHeight becomes 42, which actually will truncate to 1 line.

If lineHeight is parseFloated, on the other hand, maxHeight becomes 43.2, and the truncation is applied at 2 lines.

My workaround for now is to do this math myself and set options.maxHeight manually.

drukepple commented 8 years ago

https://github.com/jeffchan/truncate.js/pull/32

Tuizi commented 8 years ago

Thank you @drukepple for your contribution. Ok good catch with the em issue, I just prefer to round with Math.round or something like that, because it's very not natural to have height like 12.3pixel or 43.2pixel.

Can you create at least one test to explain and fixe the issue?

rogeriotaques commented 8 years ago

👍