@shapediver/viewer.data-engine.tag3d-engine 1.15.7 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,196 @@
1
+ import {
2
+ FileLoader,
3
+ Loader,
4
+ ShapePath
5
+ } from 'three';
6
+
7
+ class FontLoader extends Loader {
8
+
9
+ constructor( manager ) {
10
+
11
+ super( manager );
12
+
13
+ }
14
+
15
+ load( url, onLoad, onProgress, onError ) {
16
+
17
+ const scope = this;
18
+
19
+ const loader = new FileLoader( this.manager );
20
+ loader.setPath( this.path );
21
+ loader.setRequestHeader( this.requestHeader );
22
+ loader.setWithCredentials( scope.withCredentials );
23
+ loader.load( url, function ( text ) {
24
+
25
+ let json;
26
+
27
+ try {
28
+
29
+ json = JSON.parse( text );
30
+
31
+ } catch ( e ) {
32
+
33
+ console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
34
+ json = JSON.parse( text.substring( 65, text.length - 2 ) );
35
+
36
+ }
37
+
38
+ const font = scope.parse( json );
39
+
40
+ if ( onLoad ) onLoad( font );
41
+
42
+ }, onProgress, onError );
43
+
44
+ }
45
+
46
+ parse( json ) {
47
+
48
+ return new Font( json );
49
+
50
+ }
51
+
52
+ }
53
+
54
+ //
55
+
56
+ class Font {
57
+
58
+ constructor( data ) {
59
+
60
+ this.type = 'Font';
61
+
62
+ this.data = data;
63
+
64
+ }
65
+
66
+ generateShapes( text, size = 100 ) {
67
+
68
+ const shapes = [];
69
+ const paths = createPaths( text, size, this.data );
70
+
71
+ for ( let p = 0, pl = paths.length; p < pl; p ++ ) {
72
+
73
+ Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
74
+
75
+ }
76
+
77
+ return shapes;
78
+
79
+ }
80
+
81
+ }
82
+
83
+ function createPaths( text, size, data ) {
84
+
85
+ const chars = Array.from( text );
86
+ const scale = size / data.resolution;
87
+ const line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
88
+
89
+ const paths = [];
90
+
91
+ let offsetX = 0, offsetY = 0;
92
+
93
+ for ( let i = 0; i < chars.length; i ++ ) {
94
+
95
+ const char = chars[ i ];
96
+
97
+ if ( char === '\n' ) {
98
+
99
+ offsetX = 0;
100
+ offsetY -= line_height;
101
+
102
+ } else {
103
+
104
+ const ret = createPath( char, scale, offsetX, offsetY, data );
105
+ offsetX += ret.offsetX;
106
+ paths.push( ret.path );
107
+
108
+ }
109
+
110
+ }
111
+
112
+ return paths;
113
+
114
+ }
115
+
116
+ function createPath( char, scale, offsetX, offsetY, data ) {
117
+
118
+ const glyph = data.glyphs[ char ] || data.glyphs[ '?' ];
119
+
120
+ if ( ! glyph ) {
121
+
122
+ console.error( 'THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.' );
123
+
124
+ return;
125
+
126
+ }
127
+
128
+ const path = new ShapePath();
129
+
130
+ let x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
131
+
132
+ if ( glyph.o ) {
133
+
134
+ const outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
135
+
136
+ for ( let i = 0, l = outline.length; i < l; ) {
137
+
138
+ const action = outline[ i ++ ];
139
+
140
+ switch ( action ) {
141
+
142
+ case 'm': // moveTo
143
+
144
+ x = outline[ i ++ ] * scale + offsetX;
145
+ y = outline[ i ++ ] * scale + offsetY;
146
+
147
+ path.moveTo( x, y );
148
+
149
+ break;
150
+
151
+ case 'l': // lineTo
152
+
153
+ x = outline[ i ++ ] * scale + offsetX;
154
+ y = outline[ i ++ ] * scale + offsetY;
155
+
156
+ path.lineTo( x, y );
157
+
158
+ break;
159
+
160
+ case 'q': // quadraticCurveTo
161
+
162
+ cpx = outline[ i ++ ] * scale + offsetX;
163
+ cpy = outline[ i ++ ] * scale + offsetY;
164
+ cpx1 = outline[ i ++ ] * scale + offsetX;
165
+ cpy1 = outline[ i ++ ] * scale + offsetY;
166
+
167
+ path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
168
+
169
+ break;
170
+
171
+ case 'b': // bezierCurveTo
172
+
173
+ cpx = outline[ i ++ ] * scale + offsetX;
174
+ cpy = outline[ i ++ ] * scale + offsetY;
175
+ cpx1 = outline[ i ++ ] * scale + offsetX;
176
+ cpy1 = outline[ i ++ ] * scale + offsetY;
177
+ cpx2 = outline[ i ++ ] * scale + offsetX;
178
+ cpy2 = outline[ i ++ ] * scale + offsetY;
179
+
180
+ path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
181
+
182
+ break;
183
+
184
+ }
185
+
186
+ }
187
+
188
+ }
189
+
190
+ return { offsetX: glyph.ha * scale, path: path };
191
+
192
+ }
193
+
194
+ Font.prototype.isFont = true;
195
+
196
+ export { FontLoader, Font };
package/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "include": [
4
+ "./**/*.js",
5
+ "./**/*.d.ts",
6
+ "./**/*.ts"
7
+ ],
8
+ "compilerOptions": {
9
+ "rootDir": "src",
10
+ "outDir": "dist",
11
+ "allowJs": true
12
+ },
13
+ "exclude": [
14
+ "__tests__",
15
+ "node_modules",
16
+ "dist",
17
+ "dist-dev",
18
+ "dist-prod"
19
+ ]
20
+ }