5
5
6
6
import { Renderer } from '../core/p5.Renderer' ;
7
7
8
- function textCore ( p5 , fn ) {
9
-
10
- // additional constants
11
- fn . IDEOGRAPHIC = 'ideographic' ;
12
- fn . RIGHT_TO_LEFT = 'rtl' ;
13
- fn . LEFT_TO_RIGHT = 'ltr' ;
14
- fn . _CTX_MIDDLE = 'middle' ;
15
- fn . _TEXT_BOUNDS = '_textBoundsSingle' ;
16
- fn . _FONT_BOUNDS = '_fontBoundsSingle' ;
17
- fn . HANGING = 'hanging' ;
18
- fn . START = 'start' ;
19
- fn . END = 'end' ;
8
+ export const textCoreConstants = {
9
+ IDEOGRAPHIC : 'ideographic' ,
10
+ RIGHT_TO_LEFT : 'rtl' ,
11
+ LEFT_TO_RIGHT : 'ltr' ,
12
+ _CTX_MIDDLE : 'middle' ,
13
+ _TEXT_BOUNDS : '_textBoundsSingle' ,
14
+ _FONT_BOUNDS : '_fontBoundsSingle' ,
15
+ HANGING : 'hanging' ,
16
+ START : 'start' ,
17
+ END : 'end' ,
18
+ }
20
19
20
+ function textCore ( p5 , fn ) {
21
21
const LeadingScale = 1.275 ;
22
22
const DefaultFill = '#000000' ;
23
23
const LinebreakRe = / \r ? \n / g;
@@ -265,7 +265,7 @@ function textCore(p5, fn) {
265
265
*/
266
266
Renderer . prototype . textBounds = function ( str , x , y , width , height ) {
267
267
// delegate to _textBoundsSingle for measuring
268
- return this . _computeBounds ( fn . _TEXT_BOUNDS , str , x , y , width , height ) . bounds ;
268
+ return this . _computeBounds ( textCoreConstants . _TEXT_BOUNDS , str , x , y , width , height ) . bounds ;
269
269
} ;
270
270
271
271
/**
@@ -280,7 +280,7 @@ function textCore(p5, fn) {
280
280
*/
281
281
Renderer . prototype . fontBounds = function ( str , x , y , width , height ) {
282
282
// delegate to _fontBoundsSingle for measuring
283
- return this . _computeBounds ( fn . _FONT_BOUNDS , str , x , y , width , height ) . bounds ;
283
+ return this . _computeBounds ( textCoreConstants . _FONT_BOUNDS , str , x , y , width , height ) . bounds ;
284
284
} ;
285
285
286
286
/**
@@ -355,7 +355,7 @@ function textCore(p5, fn) {
355
355
this . states . setValue ( 'textAlign' , h ) ;
356
356
if ( typeof v !== 'undefined' ) {
357
357
if ( v === fn . CENTER ) {
358
- v = fn . _CTX_MIDDLE ;
358
+ v = textCoreConstants . _CTX_MIDDLE ;
359
359
}
360
360
this . states . setValue ( 'textBaseline' , v ) ;
361
361
}
@@ -970,9 +970,9 @@ function textCore(p5, fn) {
970
970
return width / 2 ;
971
971
case fn . RIGHT :
972
972
return width ;
973
- case fn . START :
973
+ case textCoreConstants . START :
974
974
return 0 ;
975
- case fn . END :
975
+ case textCoreConstants . END :
976
976
throw new Error ( 'textBounds: END not yet supported for textAlign' ) ;
977
977
default :
978
978
return 0 ;
@@ -1282,7 +1282,7 @@ function textCore(p5, fn) {
1282
1282
1283
1283
for ( let i = 0 ; i < lines . length ; i ++ ) {
1284
1284
switch ( textAlign ) {
1285
- case fn . START :
1285
+ case textCoreConstants . START :
1286
1286
throw new Error ( 'textBounds: START not yet supported for textAlign' ) ; // default to LEFT
1287
1287
case fn . LEFT :
1288
1288
adjustedX = x ;
@@ -1293,7 +1293,7 @@ function textCore(p5, fn) {
1293
1293
case fn . RIGHT :
1294
1294
adjustedX = x + adjustedW ;
1295
1295
break ;
1296
- case fn . END :
1296
+ case textCoreConstants . END :
1297
1297
throw new Error ( 'textBounds: END not yet supported for textAlign' ) ;
1298
1298
}
1299
1299
lineData [ i ] = { text : lines [ i ] , x : adjustedX , y : y + i * textLeading } ;
@@ -1319,16 +1319,16 @@ function textCore(p5, fn) {
1319
1319
break ; // ??
1320
1320
case fn . BASELINE :
1321
1321
break ;
1322
- case fn . _CTX_MIDDLE :
1322
+ case textCoreConstants . _CTX_MIDDLE :
1323
1323
yOff = ydiff / 2 ;
1324
1324
break ;
1325
1325
case fn . BOTTOM :
1326
1326
yOff = ydiff ;
1327
1327
break ;
1328
- case fn . IDEOGRAPHIC :
1328
+ case textCoreConstants . IDEOGRAPHIC :
1329
1329
console . warn ( 'textBounds: IDEOGRAPHIC not yet supported for textBaseline' ) ; // FES?
1330
1330
break ;
1331
- case fn . HANGING :
1331
+ case textCoreConstants . HANGING :
1332
1332
console . warn ( 'textBounds: HANGING not yet supported for textBaseline' ) ; // FES?
1333
1333
break ;
1334
1334
}
@@ -1358,7 +1358,7 @@ function textCore(p5, fn) {
1358
1358
1359
1359
for ( let i = 0 ; i < lines . length ; i ++ ) {
1360
1360
switch ( textAlign ) {
1361
- case fn . START :
1361
+ case textCoreConstants . START :
1362
1362
throw new Error ( 'textBounds: START not yet supported for textAlign' ) ; // default to LEFT
1363
1363
case fn . LEFT :
1364
1364
adjustedX = x ;
@@ -1369,7 +1369,7 @@ function textCore(p5, fn) {
1369
1369
case fn . RIGHT :
1370
1370
adjustedX = x + adjustedW - widths [ i ] - adjustedW + ( width || 0 ) ;
1371
1371
break ;
1372
- case fn . END :
1372
+ case textCoreConstants . END :
1373
1373
throw new Error ( 'textBounds: END not yet supported for textAlign' ) ;
1374
1374
}
1375
1375
lineData [ i ] = { text : lines [ i ] , x : adjustedX , y : y + i * textLeading } ;
@@ -1393,7 +1393,7 @@ function textCore(p5, fn) {
1393
1393
break ;
1394
1394
case fn . BASELINE :
1395
1395
break ;
1396
- case fn . _CTX_MIDDLE :
1396
+ case textCoreConstants . _CTX_MIDDLE :
1397
1397
yOff = - totalHeight / 2 + textSize + ( height || 0 ) / 2 ;
1398
1398
break ;
1399
1399
case fn . BOTTOM :
0 commit comments