leafer-draw 1.4.2 → 1.5.1

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/web.cjs CHANGED
@@ -123,7 +123,7 @@ class LeaferCanvas extends core.LeaferCanvasBase {
123
123
  else {
124
124
  window.addEventListener('resize', this.windowListener = () => {
125
125
  const pixelRatio = core.Platform.devicePixelRatio;
126
- if (this.pixelRatio !== pixelRatio) {
126
+ if (!this.config.pixelRatio && this.pixelRatio !== pixelRatio) {
127
127
  const { width, height } = this;
128
128
  this.emitResize({ width, height, pixelRatio });
129
129
  }
@@ -140,7 +140,7 @@ class LeaferCanvas extends core.LeaferCanvasBase {
140
140
  checkAutoBounds(parentSize) {
141
141
  const view = this.view;
142
142
  const { x, y, width, height } = this.autoBounds.getBoundsFrom(parentSize);
143
- const size = { width, height, pixelRatio: core.Platform.devicePixelRatio };
143
+ const size = { width, height, pixelRatio: this.config.pixelRatio ? this.pixelRatio : core.Platform.devicePixelRatio };
144
144
  if (!this.isSameSize(size)) {
145
145
  const { style } = view;
146
146
  style.marginLeft = x + 'px';
@@ -2166,13 +2166,14 @@ function toChar(data, charX, rowData, isOverflow) {
2166
2166
  }
2167
2167
 
2168
2168
  function layoutText(drawData, style) {
2169
- const { rows, bounds } = drawData;
2169
+ const { rows, bounds } = drawData, countRows = rows.length;
2170
2170
  const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
2171
- let { x, y, width, height } = bounds, realHeight = __lineHeight * rows.length + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
2171
+ let { x, y, width, height } = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
2172
2172
  let starY = __baseLine;
2173
2173
  if (__clipText && realHeight > height) {
2174
2174
  realHeight = Math.max(height, __lineHeight);
2175
- drawData.overflow = rows.length;
2175
+ if (countRows > 1)
2176
+ drawData.overflow = countRows;
2176
2177
  }
2177
2178
  else if (height || autoSizeAlign) {
2178
2179
  switch (verticalAlign) {
@@ -2184,7 +2185,7 @@ function layoutText(drawData, style) {
2184
2185
  }
2185
2186
  starY += y;
2186
2187
  let row, rowX, rowWidth, layoutWidth = (width || autoSizeAlign) ? width : drawData.maxWidth;
2187
- for (let i = 0, len = rows.length; i < len; i++) {
2188
+ for (let i = 0, len = countRows; i < len; i++) {
2188
2189
  row = rows[i];
2189
2190
  row.x = x;
2190
2191
  if (row.width < width || (row.width > width && !__clipText)) {
@@ -2253,7 +2254,7 @@ function clipText(drawData, style, x, width) {
2253
2254
  if (i === end && charRight < right) {
2254
2255
  break;
2255
2256
  }
2256
- else if (charRight < right && char.char !== ' ') {
2257
+ else if ((charRight < right && char.char !== ' ') || !i) {
2257
2258
  row.data.splice(i + 1);
2258
2259
  row.width -= char.width;
2259
2260
  break;