Skip to content

Commit

Permalink
fix: html text height (pixijs#11008)
Browse files Browse the repository at this point in the history
* fix nine slice not updating after GC

* add test back

* fix html text height measurment

---------

Co-authored-by: Zyie <[email protected]>
  • Loading branch information
GoodBoyDigital and Zyie authored Oct 22, 2024
1 parent dbc8b73 commit 68226e0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
5 changes: 1 addition & 4 deletions src/scene/text-html/utils/measureHtmlText.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { CanvasTextMetrics } from '../../text/canvas/CanvasTextMetrics';
import { HTMLTextRenderData } from '../HTMLTextRenderData';

import type { Size } from '../../../maths/misc/Size';
Expand Down Expand Up @@ -42,13 +41,11 @@ export function measureHtmlText(

svgRoot.remove();

const descenderPadding = CanvasTextMetrics.measureFont(style.fontStyle).descent;

// padding is included in the CSS calculation, so we need to remove it here
const doublePadding = style.padding * 2;

return {
width: contentBounds.width - doublePadding,
height: contentBounds.height + descenderPadding - doublePadding,
height: contentBounds.height - doublePadding,
};
}
5 changes: 1 addition & 4 deletions tests/renderering/text/measureHtmlText.tests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { CanvasTextMetrics } from '../../../src/scene/text/canvas/CanvasTextMetrics';
import { HTMLTextStyle } from '../../../src/scene/text-html/HtmlTextStyle';
import { measureHtmlText } from '../../../src/scene/text-html/utils/measureHtmlText';

Expand All @@ -19,10 +18,8 @@ describe('measureHtmlText', () =>
const style = new HTMLTextStyle();
const size = measureHtmlText('', style);

const descent = CanvasTextMetrics.measureFont(style.fontStyle).descent;

expect(size).toBeTruthy();
expect(size.width).toBe(0);
expect(size.height).toBe(descent);
expect(size.height).toBe(0);
});
});

0 comments on commit 68226e0

Please sign in to comment.