Skip to content

Commit

Permalink
fix: use outerWidth for bounding box
Browse files Browse the repository at this point in the history
  • Loading branch information
Ovilia committed Dec 9, 2021
1 parent 7b5a564 commit bd2642e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/graphic/Text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,8 @@ class ZRText extends Displayable<TextProps> implements GroupLike {
const needDrawBg = needDrawBackground(style);
const bgColorDrawn = !!(style.backgroundColor);

// outerWidth is the real text width containing padding.
const outerHeight = contentBlock.outerHeight;
const outerWidth = contentBlock.outerWidth;
const contentWidth = contentBlock.contentWidth;

const textLines = contentBlock.lines;
Expand All @@ -503,10 +503,9 @@ class ZRText extends Displayable<TextProps> implements GroupLike {

if (needDrawBg || textPadding) {
// Consider performance, do not call getTextWidth util necessary.
const boxX = adjustTextX(baseX, contentWidth, textAlign);
const boxX = adjustTextX(baseX, outerWidth, textAlign);
const boxY = adjustTextY(baseY, outerHeight, verticalAlign);

needDrawBg && this._renderBackground(style, style, boxX, boxY, contentWidth, outerHeight);
needDrawBg && this._renderBackground(style, style, boxX, boxY, outerWidth, outerHeight);
}

// `textBaseline` is set as 'middle'.
Expand Down Expand Up @@ -605,7 +604,7 @@ class ZRText extends Displayable<TextProps> implements GroupLike {
* Otherwise, there will be extra space in the
* bounding rect calculated.
*/
innerWidth,
contentWidth,
calculatedLineHeight
));
}
Expand Down
2 changes: 1 addition & 1 deletion src/graphic/helper/parseText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export function parsePlainText(
outerHeight: outerHeight,
lineHeight: lineHeight,
calculatedLineHeight: calculatedLineHeight,
contentWidth: outerWidth,
contentWidth: contentWidth,
contentHeight: contentHeight,
width: width
};
Expand Down

0 comments on commit bd2642e

Please sign in to comment.