-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathutils.ts
37 lines (29 loc) · 943 Bytes
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { Vector2 } from "three";
export const textAlign = {
center: new Vector2(0, 0),
left: new Vector2(1, 0),
top: new Vector2(0, -1),
topLeft: new Vector2(1, -1),
topRight: new Vector2(-1, -1),
right: new Vector2(-1, 0),
bottom: new Vector2(0, 1),
bottomLeft: new Vector2(1, 1),
bottomRight: new Vector2(-1, 1),
}
var fontHeightCache: { [id: string]: number; } = {};
export function getFontHeight (fontStyle: string) {
var result = fontHeightCache[fontStyle];
if (!result)
{
var body = document.getElementsByTagName('body')[0];
var dummy = document.createElement('div');
var dummyText = document.createTextNode('MÉq');
dummy.appendChild(dummyText);
dummy.setAttribute('style', `font:${ fontStyle };position:absolute;top:0;left:0`);
body.appendChild(dummy);
result = dummy.offsetHeight;
fontHeightCache[fontStyle] = result;
body.removeChild(dummy);
}
return result;
}