function textBounds(node, measureFn = measureText) {
  const lineBreakFn = resolveLineBreakAlgorithm(node);
  const fontSize = node['font-size'] || node.fontSize;
  const fontFamily = node['font-family'] || node.fontFamily;
  const tm = measureFn({ text: node.text, fontFamily, fontSize });

  if (lineBreakFn && (tm.width > node.maxWidth || includesLineBreak(node.text))) {
    const resolvedLineBreaks = lineBreakFn(node, (text) => measureFn({ text, fontFamily, fontSize }));
    const nodeCopy = extend({}, node);
    let maxWidth = 0;
    let widestLine = '';
    for (let i = 0, len = resolvedLineBreaks.lines.length; i < len; i++) {
      let line = resolvedLineBreaks.lines[i];
      line += i === len - 1 && resolvedLineBreaks.reduced ? ELLIPSIS_CHAR : '';
      const width = measureFn({ text: line, fontSize, fontFamily }).width;
      if (width >= maxWidth) {
        maxWidth = width;
        widestLine = line;
      }
    }
    nodeCopy.text = widestLine;
    const bounds = calcTextBounds(nodeCopy, measureFn);
    bounds.height = fontSizeToLineHeight(node) * resolvedLineBreaks.lines.length;

    return bounds;
  }

  return calcTextBounds(node, measureFn);
}
/**
 * Calculates the bounding rectangle of a text node. Including any line breaks.
 * @ignore
 * @param {object} node
 * @param {string} node.text - Text to measure
 * @param {number} [node.x=0] - X-coordinate
 * @param {number} [node.y=0] - Y-coordinate
 * @param {number} [node.dx=0] - Delta x-coordinate
 * @param {number} [node.dy=0] - Delta y-coordinate
 * @param {string} [node.anchor='start'] - Text anchor
 * @param {string} [node.fontSize] - Font size
 * @param {string} [node.fontFamily] - Font family
 * @param {string} [node['font-size']] - Font size
 * @param {string} [node['font-family']] - Font family
 * @param {string} [node.wordBreak] - Word-break option
 * @param {number} [node.maxWidth] - Maximum allowed text width
 * @param {number} [node.maxHeight] - Maximum allowed text height. If both maxLines and maxHeight are set, the property that results in the fewest number of lines is used
 * @param {number} [node.maxLines] - Maximum number of lines allowed.
 * @param {number} [node.lineHeight=1.2] - Line height
 * @param {function} [measureFn] - Optional text measure function
 * @return {object} The bounding rectangle
 */
Calculates the bounding rectangle of a text node. Including any line breaks.
Calculates the bounding rectangle of a text node . Including any line breaks .
function textBounds(node, measureFn = measureText) {
  const lineBreakFn = resolveLineBreakAlgorithm(node);
  const fontSize = node['font-size'] || node.fontSize;
  const fontFamily = node['font-family'] || node.fontFamily;
  const tm = measureFn({ text: node.text, fontFamily, fontSize });
  if (lineBreakFn && (tm.width > node.maxWidth || includesLineBreak(node.text))) {
    const resolvedLineBreaks = lineBreakFn(node, (text) => measureFn({ text, fontFamily, fontSize }));
    const nodeCopy = extend({}, node);
    let maxWidth = 0;
    let widestLine = '';
    for (let i = 0, len = resolvedLineBreaks.lines.length; i < len; i++) {
      let line = resolvedLineBreaks.lines[i];
      line += i === len - 1 && resolvedLineBreaks.reduced ? ELLIPSIS_CHAR : '';
      const width = measureFn({ text: line, fontSize, fontFamily }).width;
      if (width >= maxWidth) {
        maxWidth = width;
        widestLine = line;
      }
    }
    nodeCopy.text = widestLine;
    const bounds = calcTextBounds(nodeCopy, measureFn);
    bounds.height = fontSizeToLineHeight(node) * resolvedLineBreaks.lines.length;
    return bounds;
  }
  return calcTextBounds(node, measureFn);
}
function textBounds ( node , measureFn = measureText ) { const lineBreakFn = resolveLineBreakAlgorithm ( node ) ; const fontSize = node [ 'font-size' ] || node . fontSize ; const fontFamily = node [ 'font-family' ] || node . fontFamily ; const tm = measureFn ( { text : node . text , fontFamily , fontSize } ) ; if ( lineBreakFn && ( tm . width > node . maxWidth || includesLineBreak ( node . text ) ) ) { const resolvedLineBreaks = lineBreakFn ( node , ( text ) => measureFn ( { text , fontFamily , fontSize } ) ) ; const nodeCopy = extend ( { } , node ) ; let maxWidth = 0 ; let widestLine = '' ; for ( let i = 0 , len = resolvedLineBreaks . lines . length ; i < len ; i ++ ) { let line = resolvedLineBreaks . lines [ i ] ; line += i === len - 1 && resolvedLineBreaks . reduced ? ELLIPSIS_CHAR : '' ; const width = measureFn ( { text : line , fontSize , fontFamily } ) . width ; if ( width >= maxWidth ) { maxWidth = width ; widestLine = line ; } } nodeCopy . text = widestLine ; const bounds = calcTextBounds ( nodeCopy , measureFn ) ; bounds . height = fontSizeToLineHeight ( node ) * resolvedLineBreaks . lines . length ; return bounds ; } return calcTextBounds ( node , measureFn ) ; }
Calculates the bounding rectangle of a text node.
Calculates the bounding rectangle of a text node .