Skip to content

Commit 528de2b

Browse files
authored
fix: measureText未考虑旋转 (#340)
1 parent a2a90e6 commit 528de2b

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

packages/f-engine/src/canvas/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ function measureText(container: Group, px2hd, theme: ThemeType) {
5353
textAlign = theme.textAlign,
5454
textBaseline = theme.textBaseline,
5555
lineWidth = 1,
56+
transform = '',
5657
} = font || {};
5758

5859
const style = {
@@ -67,6 +68,7 @@ function measureText(container: Group, px2hd, theme: ThemeType) {
6768
textAlign,
6869
textBaseline,
6970
lineWidth,
71+
transform,
7072
visibility: 'hidden',
7173
};
7274

packages/f-engine/test/canvas/theme.test.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
import { transform } from '@antv/util';
12
import { jsx, Canvas, Component } from '../../src';
23
import { createContext, delay } from '../util';
34
const context = createContext();
45

56
class Text extends Component {
67
width: number;
8+
height: number;
79

810
constructor(props, context) {
911
super(props, context);
10-
const { width } = this.context.measureText('0.123', {});
12+
const { textStyle } = props;
13+
const { width, height } = this.context.measureText('0.123', textStyle);
1114
this.width = width;
15+
this.height = height;
1216
}
1317
}
1418

@@ -51,3 +55,24 @@ describe('Theme', () => {
5155
});
5256
});
5357
});
58+
59+
describe('measureText', () => {
60+
it('旋转', async () => {
61+
const textRef = { current: null };
62+
const { props } = (
63+
<Canvas context={context} pixelRatio={1}>
64+
<Text
65+
ref={textRef}
66+
textStyle={{
67+
transform: 'rotate(90deg)',
68+
}}
69+
/>
70+
</Canvas>
71+
);
72+
73+
const canvas = new Canvas(props);
74+
canvas.render();
75+
await delay(0);
76+
expect(textRef.current.height).toBeCloseTo(31.02);
77+
});
78+
});

0 commit comments

Comments
 (0)