@leafer-draw/worker 1.4.1 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1986,13 +1986,14 @@ function toChar(data, charX, rowData, isOverflow) {
1986
1986
  }
1987
1987
 
1988
1988
  function layoutText(drawData, style) {
1989
- const { rows, bounds } = drawData;
1989
+ const { rows, bounds } = drawData, countRows = rows.length;
1990
1990
  const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
1991
- let { x, y, width, height } = bounds, realHeight = __lineHeight * rows.length + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
1991
+ let { x, y, width, height } = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
1992
1992
  let starY = __baseLine;
1993
1993
  if (__clipText && realHeight > height) {
1994
1994
  realHeight = Math.max(height, __lineHeight);
1995
- drawData.overflow = rows.length;
1995
+ if (countRows > 1)
1996
+ drawData.overflow = countRows;
1996
1997
  }
1997
1998
  else if (height || autoSizeAlign) {
1998
1999
  switch (verticalAlign) {
@@ -2004,7 +2005,7 @@ function layoutText(drawData, style) {
2004
2005
  }
2005
2006
  starY += y;
2006
2007
  let row, rowX, rowWidth, layoutWidth = (width || autoSizeAlign) ? width : drawData.maxWidth;
2007
- for (let i = 0, len = rows.length; i < len; i++) {
2008
+ for (let i = 0, len = countRows; i < len; i++) {
2008
2009
  row = rows[i];
2009
2010
  row.x = x;
2010
2011
  if (row.width < width || (row.width > width && !__clipText)) {
@@ -2073,7 +2074,7 @@ function clipText(drawData, style, x, width) {
2073
2074
  if (i === end && charRight < right) {
2074
2075
  break;
2075
2076
  }
2076
- else if (charRight < right && char.char !== ' ') {
2077
+ else if ((charRight < right && char.char !== ' ') || !i) {
2077
2078
  row.data.splice(i + 1);
2078
2079
  row.width -= char.width;
2079
2080
  break;