-
Notifications
You must be signed in to change notification settings - Fork 138
/
TextManager.js
103 lines (65 loc) · 2.09 KB
/
TextManager.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import MSDFText from '../../content/MSDFText.js';
/**
Job:
- Routing the request for Text dimensions and Text creation depending on Text type.
Knows:
- this component's textType attribute
Note:
Only one Text type is natively supported by the library at the moment,
but the architecture allows you to easily stick in your custom Text type.
More information here :
https://github.com/felixmariotto/three-mesh-ui/wiki/Using-a-custom-text-type
*/
export default function TextManager( Base ) {
return class TextManager extends Base {
createText() {
const component = this;
const mesh = ( () => {
switch ( this.getTextType() ) {
case 'MSDF' :
return MSDFText.buildText.call( this );
default :
console.warn( `'${this.getTextType()}' is not a supported text type.\nSee https://github.com/felixmariotto/three-mesh-ui/wiki/Using-a-custom-text-type` );
break;
}
} )();
mesh.renderOrder = Infinity;
// This is for hiddenOverflow to work
mesh.onBeforeRender = function () {
if ( component.updateClippingPlanes ) {
component.updateClippingPlanes();
}
};
return mesh;
}
/**
* Called by Text to get the dimensions of a particular glyph,
* in order for InlineManager to compute its position
*/
getGlyphDimensions( options ) {
switch ( options.textType ) {
case 'MSDF' :
return MSDFText.getGlyphDimensions( options );
default :
console.warn( `'${options.textType}' is not a supported text type.\nSee https://github.com/felixmariotto/three-mesh-ui/wiki/Using-a-custom-text-type` );
break;
}
}
/**
* Called by Text to get the amount of kerning for pair of glyph
* @param textType
* @param font
* @param glyphPair
* @returns {number}
*/
getGlyphPairKerning( textType, font, glyphPair ) {
switch ( textType ) {
case 'MSDF' :
return MSDFText.getGlyphPairKerning( font, glyphPair );
default :
console.warn( `'${textType}' is not a supported text type.\nSee https://github.com/felixmariotto/three-mesh-ui/wiki/Using-a-custom-text-type` );
break;
}
}
};
}