It can be useful to have control over whitespace. At the moment the measure function in lib/measure/index.js assumes you want "normal" HTML/SVG whitespace handling (like CSS's white-space: normal). This PR adds two arguments to the function that allow the caller to control whether the whitespace is trimmed or collapsed. It also makes the three measuring handlers consistent: before now, only the canvas handler trimmed and collapsed whitespace; the SVG and "dumb" handler left the text as-is.
When there are line breaks in the text but we're either not trimming whitespace or not collapsing whitespace, the function does what HTML's input element does and converts all "\n" to " ".
It can be useful to have control over whitespace. At the moment the
measure
function inlib/measure/index.js
assumes you want "normal" HTML/SVG whitespace handling (like CSS'swhite-space: normal
). This PR adds two arguments to the function that allow the caller to control whether the whitespace is trimmed or collapsed. It also makes the three measuring handlers consistent: before now, only the canvas handler trimmed and collapsed whitespace; the SVG and "dumb" handler left the text as-is.When there are line breaks in the text but we're either not trimming whitespace or not collapsing whitespace, the function does what HTML's input element does and converts all "\n" to " ".
Fixes #23.