@leafer-draw/worker 1.4.2 → 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.
package/dist/worker.cjs CHANGED
@@ -1985,13 +1985,14 @@ function toChar(data, charX, rowData, isOverflow) {
1985
1985
  }
1986
1986
 
1987
1987
  function layoutText(drawData, style) {
1988
- const { rows, bounds } = drawData;
1988
+ const { rows, bounds } = drawData, countRows = rows.length;
1989
1989
  const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
1990
- let { x, y, width, height } = bounds, realHeight = __lineHeight * rows.length + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
1990
+ let { x, y, width, height } = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
1991
1991
  let starY = __baseLine;
1992
1992
  if (__clipText && realHeight > height) {
1993
1993
  realHeight = Math.max(height, __lineHeight);
1994
- drawData.overflow = rows.length;
1994
+ if (countRows > 1)
1995
+ drawData.overflow = countRows;
1995
1996
  }
1996
1997
  else if (height || autoSizeAlign) {
1997
1998
  switch (verticalAlign) {
@@ -2003,7 +2004,7 @@ function layoutText(drawData, style) {
2003
2004
  }
2004
2005
  starY += y;
2005
2006
  let row, rowX, rowWidth, layoutWidth = (width || autoSizeAlign) ? width : drawData.maxWidth;
2006
- for (let i = 0, len = rows.length; i < len; i++) {
2007
+ for (let i = 0, len = countRows; i < len; i++) {
2007
2008
  row = rows[i];
2008
2009
  row.x = x;
2009
2010
  if (row.width < width || (row.width > width && !__clipText)) {
@@ -2072,7 +2073,7 @@ function clipText(drawData, style, x, width) {
2072
2073
  if (i === end && charRight < right) {
2073
2074
  break;
2074
2075
  }
2075
- else if (charRight < right && char.char !== ' ') {
2076
+ else if ((charRight < right && char.char !== ' ') || !i) {
2076
2077
  row.data.splice(i + 1);
2077
2078
  row.width -= char.width;
2078
2079
  break;