melonjs 15.3.0 → 15.4.1
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.
- package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +1 -1
- package/dist/melonjs.mjs/_virtual/earcut.js +1 -1
- package/dist/melonjs.mjs/_virtual/howler.js +1 -1
- package/dist/melonjs.mjs/_virtual/index.js +1 -1
- package/dist/melonjs.mjs/application/application.js +53 -5
- package/dist/melonjs.mjs/application/header.js +2 -2
- package/dist/melonjs.mjs/application/resize.js +4 -8
- package/dist/melonjs.mjs/application/settings.js +5 -5
- package/dist/melonjs.mjs/audio/audio.js +4 -6
- package/dist/melonjs.mjs/camera/camera2d.js +12 -14
- package/dist/melonjs.mjs/const.js +1 -1
- package/dist/melonjs.mjs/entity/entity.js +3 -4
- package/dist/melonjs.mjs/geometries/ellipse.js +26 -59
- package/dist/melonjs.mjs/geometries/line.js +18 -25
- package/dist/melonjs.mjs/geometries/path2d.js +16 -13
- package/dist/melonjs.mjs/geometries/point.js +8 -16
- package/dist/melonjs.mjs/geometries/poly.js +40 -97
- package/dist/melonjs.mjs/geometries/rectangle.js +37 -91
- package/dist/melonjs.mjs/geometries/roundrect.js +26 -35
- package/dist/melonjs.mjs/index.js +6 -6
- package/dist/melonjs.mjs/input/gamepad.js +1 -1
- package/dist/melonjs.mjs/input/input.js +1 -1
- package/dist/melonjs.mjs/input/keyboard.js +3 -3
- package/dist/melonjs.mjs/input/pointer.js +4 -4
- package/dist/melonjs.mjs/input/pointerevent.js +6 -7
- package/dist/melonjs.mjs/lang/console.js +1 -1
- package/dist/melonjs.mjs/lang/deprecated.js +2 -2
- package/dist/melonjs.mjs/level/level.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXGroup.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXLayer.js +16 -33
- package/dist/melonjs.mjs/level/tiled/TMXObject.js +3 -4
- package/dist/melonjs.mjs/level/tiled/TMXTile.js +4 -4
- package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXTileset.js +4 -7
- package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +2 -2
- package/dist/melonjs.mjs/level/tiled/TMXUtils.js +26 -29
- package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +3 -3
- package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +2 -2
- package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +2 -2
- package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +2 -2
- package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +2 -2
- package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
- package/dist/melonjs.mjs/loader/cache.js +1 -1
- package/dist/melonjs.mjs/loader/loader.js +1 -1
- package/dist/melonjs.mjs/loader/loadingscreen.js +1 -1
- package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
- package/dist/melonjs.mjs/loader/parser.js +4 -5
- package/dist/melonjs.mjs/loader/settings.js +1 -1
- package/dist/melonjs.mjs/math/color.js +2 -2
- package/dist/melonjs.mjs/math/math.js +1 -1
- package/dist/melonjs.mjs/math/matrix2.js +5 -59
- package/dist/melonjs.mjs/math/matrix3.js +82 -141
- package/dist/melonjs.mjs/math/observable_vector2.js +7 -7
- package/dist/melonjs.mjs/math/observable_vector3.js +5 -5
- package/dist/melonjs.mjs/math/vector2.js +7 -91
- package/dist/melonjs.mjs/math/vector3.js +6 -90
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/arraymultimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/multimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
- package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +1 -1
- package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +1 -1
- package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +1 -1
- package/dist/melonjs.mjs/particles/emitter.js +2 -2
- package/dist/melonjs.mjs/particles/particle.js +2 -2
- package/dist/melonjs.mjs/particles/settings.js +1 -1
- package/dist/melonjs.mjs/physics/body.js +22 -20
- package/dist/melonjs.mjs/physics/bounds.js +27 -33
- package/dist/melonjs.mjs/physics/collision.js +5 -5
- package/dist/melonjs.mjs/physics/detector.js +10 -10
- package/dist/melonjs.mjs/physics/quadtree.js +5 -5
- package/dist/melonjs.mjs/physics/response.js +1 -1
- package/dist/melonjs.mjs/physics/sat.js +3 -4
- package/dist/melonjs.mjs/physics/world.js +6 -9
- package/dist/melonjs.mjs/plugin/plugin.js +3 -3
- package/dist/melonjs.mjs/renderable/collectable.js +2 -2
- package/dist/melonjs.mjs/renderable/colorlayer.js +4 -4
- package/dist/melonjs.mjs/renderable/container.js +25 -25
- package/dist/melonjs.mjs/renderable/draggable.js +1 -1
- package/dist/melonjs.mjs/renderable/dragndrop.js +1 -1
- package/dist/melonjs.mjs/renderable/imagelayer.js +4 -4
- package/dist/melonjs.mjs/renderable/light2d.js +3 -3
- package/dist/melonjs.mjs/renderable/nineslicesprite.js +2 -2
- package/dist/melonjs.mjs/renderable/renderable.js +26 -26
- package/dist/melonjs.mjs/renderable/sprite.js +3 -3
- package/dist/melonjs.mjs/renderable/text/bitmaptext.js +421 -0
- package/dist/melonjs.mjs/renderable/text/bitmaptextdata.js +195 -0
- package/dist/melonjs.mjs/renderable/text/glyph.js +65 -0
- package/dist/melonjs.mjs/renderable/text/text.js +422 -0
- package/dist/melonjs.mjs/renderable/text/textmetrics.js +175 -0
- package/dist/melonjs.mjs/renderable/text/textstyle.js +21 -0
- package/dist/melonjs.mjs/renderable/trigger.js +10 -10
- package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +7 -7
- package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +7 -7
- package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +3 -3
- package/dist/melonjs.mjs/state/stage.js +2 -2
- package/dist/melonjs.mjs/state/state.js +1 -38
- package/dist/melonjs.mjs/system/device.js +49 -10
- package/dist/melonjs.mjs/system/dom.js +1 -1
- package/dist/melonjs.mjs/system/event.js +24 -2
- package/dist/melonjs.mjs/system/platform.js +18 -18
- package/dist/melonjs.mjs/system/pooling.js +10 -10
- package/dist/melonjs.mjs/system/save.js +1 -1
- package/dist/melonjs.mjs/system/timer.js +1 -1
- package/dist/melonjs.mjs/text/bitmaptext.js +1 -1
- package/dist/melonjs.mjs/text/bitmaptextdata.js +3 -6
- package/dist/melonjs.mjs/text/glyph.js +1 -1
- package/dist/melonjs.mjs/text/text.js +1 -1
- package/dist/melonjs.mjs/text/textmetrics.js +1 -1
- package/dist/melonjs.mjs/text/textstyle.js +1 -1
- package/dist/melonjs.mjs/tweens/easing.js +1 -1
- package/dist/melonjs.mjs/tweens/interpolation.js +1 -1
- package/dist/melonjs.mjs/tweens/tween.js +2 -2
- package/dist/melonjs.mjs/utils/agent.js +1 -1
- package/dist/melonjs.mjs/utils/array.js +1 -1
- package/dist/melonjs.mjs/utils/file.js +1 -1
- package/dist/melonjs.mjs/utils/function.js +2 -3
- package/dist/melonjs.mjs/utils/string.js +1 -1
- package/dist/melonjs.mjs/utils/utils.js +1 -1
- package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +3 -7
- package/dist/melonjs.mjs/video/renderer.js +16 -16
- package/dist/melonjs.mjs/video/texture/atlas.js +13 -13
- package/dist/melonjs.mjs/video/texture/cache.js +1 -1
- package/dist/melonjs.mjs/video/texture/canvas_texture.js +15 -15
- package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
- package/dist/melonjs.mjs/video/video.js +4 -4
- package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +3 -3
- package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +13 -14
- package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +5 -5
- package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +2 -3
- package/dist/melonjs.mjs/video/webgl/glshader.js +2 -2
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/attributes.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/precision.js +4 -4
- package/dist/melonjs.mjs/video/webgl/utils/program.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +1 -1
- package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +50 -52
- package/dist/melonjs.module.js +1137 -1576
- package/dist/types/application/application.d.ts +28 -4
- package/dist/types/application/header.d.ts +2 -2
- package/dist/types/application/settings.d.ts +23 -23
- package/dist/types/audio/audio.d.ts +3 -5
- package/dist/types/camera/camera2d.d.ts +13 -16
- package/dist/types/entity/entity.d.ts +0 -1
- package/dist/types/geometries/ellipse.d.ts +18 -50
- package/dist/types/geometries/path2d.d.ts +1 -1
- package/dist/types/geometries/point.d.ts +5 -13
- package/dist/types/geometries/poly.d.ts +26 -75
- package/dist/types/geometries/rectangle.d.ts +12 -58
- package/dist/types/geometries/roundrect.d.ts +2 -11
- package/dist/types/index.d.ts +3 -3
- package/dist/types/input/gamepad.d.ts +31 -31
- package/dist/types/input/keyboard.d.ts +105 -105
- package/dist/types/input/pointer.d.ts +21 -21
- package/dist/types/input/pointerevent.d.ts +6 -6
- package/dist/types/level/tiled/TMXLayer.d.ts +1 -1
- package/dist/types/math/matrix2.d.ts +9 -63
- package/dist/types/math/matrix3.d.ts +9 -68
- package/dist/types/math/observable_vector2.d.ts +2 -2
- package/dist/types/math/observable_vector3.d.ts +2 -2
- package/dist/types/math/vector2.d.ts +8 -92
- package/dist/types/math/vector3.d.ts +8 -92
- package/dist/types/particles/settings.d.ts +29 -29
- package/dist/types/physics/body.d.ts +10 -8
- package/dist/types/physics/bounds.d.ts +24 -30
- package/dist/types/physics/collision.d.ts +12 -12
- package/dist/types/physics/detector.d.ts +1 -1
- package/dist/types/physics/world.d.ts +4 -7
- package/dist/types/renderable/container.d.ts +19 -19
- package/dist/types/renderable/imagelayer.d.ts +6 -6
- package/dist/types/renderable/light2d.d.ts +7 -7
- package/dist/types/renderable/renderable.d.ts +9 -16
- package/dist/types/renderable/text/bitmaptext.d.ts +151 -0
- package/dist/types/renderable/text/bitmaptextdata.d.ts +35 -0
- package/dist/types/renderable/text/glyph.d.ts +28 -0
- package/dist/types/renderable/text/text.d.ts +159 -0
- package/dist/types/renderable/text/textmetrics.d.ts +47 -0
- package/dist/types/renderable/text/textstyle.d.ts +5 -0
- package/dist/types/renderable/ui/uibaseelement.d.ts +0 -1
- package/dist/types/renderable/ui/uispriteelement.d.ts +0 -1
- package/dist/types/renderable/ui/uitextbutton.d.ts +2 -7
- package/dist/types/state/state.d.ts +11 -11
- package/dist/types/system/device.d.ts +15 -9
- package/dist/types/system/event.d.ts +20 -0
- package/dist/types/system/platform.d.ts +17 -17
- package/dist/types/utils/function.d.ts +1 -2
- package/dist/types/video/renderer.d.ts +13 -13
- package/dist/types/video/texture/canvas_texture.d.ts +14 -14
- package/dist/types/video/video.d.ts +2 -2
- package/dist/types/video/webgl/buffer/vertex.d.ts +2 -2
- package/dist/types/video/webgl/compositors/compositor.d.ts +24 -13
- package/dist/types/video/webgl/compositors/primitive_compositor.d.ts +0 -1
- package/dist/types/video/webgl/compositors/quad_compositor.d.ts +0 -1
- package/dist/types/video/webgl/utils/precision.d.ts +1 -1
- package/dist/types/video/webgl/webgl_renderer.d.ts +47 -50
- package/package.json +15 -15
- package/src/application/application.js +51 -3
- package/src/application/header.js +1 -1
- package/src/application/resize.js +3 -7
- package/src/application/settings.js +4 -4
- package/src/audio/audio.js +3 -5
- package/src/camera/camera2d.js +11 -13
- package/src/entity/entity.js +2 -3
- package/src/geometries/ellipse.js +25 -58
- package/src/geometries/line.js +17 -24
- package/src/geometries/path2d.js +15 -12
- package/src/geometries/point.js +7 -15
- package/src/geometries/poly.js +39 -96
- package/src/geometries/rectangle.js +36 -90
- package/src/geometries/roundrect.js +25 -34
- package/src/index.js +4 -4
- package/src/input/keyboard.js +2 -2
- package/src/input/pointer.js +3 -3
- package/src/input/pointerevent.js +5 -6
- package/src/lang/deprecated.js +1 -1
- package/src/level/tiled/TMXLayer.js +15 -32
- package/src/level/tiled/TMXObject.js +2 -3
- package/src/level/tiled/TMXTile.js +3 -3
- package/src/level/tiled/TMXTileMap.js +2 -2
- package/src/level/tiled/TMXTileset.js +3 -6
- package/src/level/tiled/TMXTilesetGroup.js +1 -1
- package/src/level/tiled/TMXUtils.js +25 -28
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +2 -2
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
- package/src/loader/parser.js +3 -4
- package/src/math/color.js +1 -1
- package/src/math/matrix2.js +4 -58
- package/src/math/matrix3.js +81 -140
- package/src/math/observable_vector2.js +6 -6
- package/src/math/observable_vector3.js +4 -4
- package/src/math/vector2.js +6 -90
- package/src/math/vector3.js +5 -89
- package/src/particles/emitter.js +1 -1
- package/src/particles/particle.js +1 -1
- package/src/physics/body.js +21 -19
- package/src/physics/bounds.js +26 -32
- package/src/physics/collision.js +4 -4
- package/src/physics/detector.js +9 -9
- package/src/physics/quadtree.js +4 -4
- package/src/physics/sat.js +2 -3
- package/src/physics/world.js +5 -8
- package/src/polyfill/roundrect.js +163 -163
- package/src/renderable/collectable.js +1 -1
- package/src/renderable/colorlayer.js +3 -3
- package/src/renderable/container.js +24 -24
- package/src/renderable/imagelayer.js +3 -3
- package/src/renderable/light2d.js +2 -2
- package/src/renderable/nineslicesprite.js +1 -1
- package/src/renderable/renderable.js +25 -25
- package/src/renderable/sprite.js +2 -2
- package/src/{text → renderable/text}/bitmaptext.js +8 -8
- package/src/{text → renderable/text}/bitmaptextdata.js +4 -7
- package/src/{text → renderable/text}/glyph.js +1 -1
- package/src/{text → renderable/text}/text.js +16 -17
- package/src/{text → renderable/text}/textmetrics.js +2 -2
- package/src/renderable/trigger.js +9 -9
- package/src/renderable/ui/uibaseelement.js +6 -6
- package/src/renderable/ui/uispriteelement.js +6 -6
- package/src/renderable/ui/uitextbutton.js +2 -2
- package/src/state/stage.js +1 -1
- package/src/state/state.js +0 -49
- package/src/system/device.js +48 -9
- package/src/system/event.js +22 -0
- package/src/system/platform.js +18 -18
- package/src/system/pooling.js +9 -9
- package/src/tweens/tween.js +1 -1
- package/src/utils/function.js +1 -2
- package/src/video/canvas/canvas_renderer.js +2 -6
- package/src/video/renderer.js +15 -15
- package/src/video/texture/atlas.js +12 -12
- package/src/video/texture/canvas_texture.js +14 -14
- package/src/video/video.js +3 -3
- package/src/video/webgl/buffer/vertex.js +2 -2
- package/src/video/webgl/compositors/compositor.js +12 -13
- package/src/video/webgl/compositors/primitive_compositor.js +4 -4
- package/src/video/webgl/compositors/quad_compositor.js +1 -2
- package/src/video/webgl/glshader.js +1 -1
- package/src/video/webgl/utils/precision.js +3 -3
- package/src/video/webgl/webgl_renderer.js +49 -51
- /package/src/{text → renderable/text}/textstyle.js +0 -0
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* melonJS Game Engine - v15.4.1
|
|
3
|
+
* http://www.melonjs.org
|
|
4
|
+
* melonjs is licensed under the MIT License.
|
|
5
|
+
* http://www.opensource.org/licenses/mit-license
|
|
6
|
+
* @copyright (C) 2011 - 2023 Olivier Biot (AltByte Pte Ltd)
|
|
7
|
+
*/
|
|
8
|
+
import Color from '../../math/color.js';
|
|
9
|
+
import pool from '../../system/pooling.js';
|
|
10
|
+
import { getImage, getBinary } from '../../loader/loader.js';
|
|
11
|
+
import Renderable from '../renderable.js';
|
|
12
|
+
import TextMetrics from './textmetrics.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @classdesc
|
|
16
|
+
* a bitmap font object
|
|
17
|
+
* @augments Renderable
|
|
18
|
+
*/
|
|
19
|
+
class BitmapText extends Renderable {
|
|
20
|
+
/**
|
|
21
|
+
* @param {number} x - position of the text object
|
|
22
|
+
* @param {number} y - position of the text object
|
|
23
|
+
* @param {object} settings - the text configuration
|
|
24
|
+
* @param {string|Image} settings.font - a font name to identify the corresponing source image
|
|
25
|
+
* @param {string} [settings.fontData=settings.font] - the bitmap font data corresponding name, or the bitmap font data itself
|
|
26
|
+
* @param {number} [settings.size] - size a scaling ratio
|
|
27
|
+
* @param {Color|string} [settings.fillStyle] - a CSS color value used to tint the bitmapText (@see BitmapText.tint)
|
|
28
|
+
* @param {number} [settings.lineWidth=1] - line width, in pixels, when drawing stroke
|
|
29
|
+
* @param {string} [settings.textAlign="left"] - horizontal text alignment
|
|
30
|
+
* @param {string} [settings.textBaseline="top"] - the text baseline
|
|
31
|
+
* @param {number} [settings.lineHeight=1.0] - line spacing height
|
|
32
|
+
* @param {Vector2d} [settings.anchorPoint={x:0.0, y:0.0}] - anchor point to draw the text at
|
|
33
|
+
* @param {number} [settings.wordWrapWidth] - the maximum length in CSS pixel for a single segment of text
|
|
34
|
+
* @param {(string|string[])} [settings.text] - a string, or an array of strings
|
|
35
|
+
* @example
|
|
36
|
+
* // Use me.loader.preload or me.loader.load to load assets
|
|
37
|
+
* me.loader.preload([
|
|
38
|
+
* { name: "arial", type: "binary" src: "data/font/arial.fnt" },
|
|
39
|
+
* { name: "arial", type: "image" src: "data/font/arial.png" },
|
|
40
|
+
* ])
|
|
41
|
+
* // Then create an instance of your bitmap font:
|
|
42
|
+
* let myFont = new me.BitmapText(x, y, {font:"arial", text:"Hello"});
|
|
43
|
+
* // two possibilities for using "myFont"
|
|
44
|
+
* // either call the draw function from your Renderable draw function
|
|
45
|
+
* myFont.draw(renderer, "Hello!", 0, 0);
|
|
46
|
+
* // or just add it to the word container
|
|
47
|
+
* me.game.world.addChild(myFont);
|
|
48
|
+
*/
|
|
49
|
+
constructor(x, y, settings) {
|
|
50
|
+
// call the parent constructor
|
|
51
|
+
super(x, y, settings.width || 0, settings.height || 0);
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Set the default text alignment (or justification),<br>
|
|
55
|
+
* possible values are "left", "right", and "center".
|
|
56
|
+
* @public
|
|
57
|
+
* @type {string}
|
|
58
|
+
* @default "left"
|
|
59
|
+
*/
|
|
60
|
+
this.textAlign = settings.textAlign || "left";
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Set the text baseline (e.g. the Y-coordinate for the draw operation), <br>
|
|
64
|
+
* possible values are "top", "hanging, "middle, "alphabetic, "ideographic, "bottom"<br>
|
|
65
|
+
* @public
|
|
66
|
+
* @type {string}
|
|
67
|
+
* @default "top"
|
|
68
|
+
*/
|
|
69
|
+
this.textBaseline = settings.textBaseline || "top";
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Set the line spacing height (when displaying multi-line strings). <br>
|
|
73
|
+
* Current font height will be multiplied with this value to set the line height.
|
|
74
|
+
* @public
|
|
75
|
+
* @type {number}
|
|
76
|
+
* @default 1.0
|
|
77
|
+
*/
|
|
78
|
+
this.lineHeight = settings.lineHeight || 1.0;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* the maximum length in CSS pixel for a single segment of text.
|
|
82
|
+
* (use -1 to disable word wrapping)
|
|
83
|
+
* @public
|
|
84
|
+
* @type {number}
|
|
85
|
+
* @default -1
|
|
86
|
+
*/
|
|
87
|
+
this.wordWrapWidth = settings.wordWrapWidth || -1;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* the text to be displayed
|
|
91
|
+
* @private
|
|
92
|
+
*/
|
|
93
|
+
this._text = [];
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* scaled font size
|
|
97
|
+
* @private
|
|
98
|
+
*/
|
|
99
|
+
this.fontScale = pool.pull("Vector2d", 1.0, 1.0);
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* font image
|
|
103
|
+
* @private
|
|
104
|
+
*/
|
|
105
|
+
this.fontImage = (typeof settings.font === "object") ? settings.font : getImage(settings.font);
|
|
106
|
+
|
|
107
|
+
if (typeof settings.fontData !== "string") {
|
|
108
|
+
/**
|
|
109
|
+
* font data
|
|
110
|
+
* @private
|
|
111
|
+
*/
|
|
112
|
+
// use settings.font to retreive the data from the loader
|
|
113
|
+
this.fontData = pool.pull("BitmapTextData", getBinary(settings.font));
|
|
114
|
+
} else {
|
|
115
|
+
this.fontData = pool.pull("BitmapTextData",
|
|
116
|
+
// if starting/includes "info face" the whole data string was passed as parameter
|
|
117
|
+
(settings.fontData.includes("info face")) ? settings.fontData : getBinary(settings.fontData)
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// if floating was specified through settings
|
|
122
|
+
if (typeof settings.floating !== "undefined") {
|
|
123
|
+
this.floating = !!settings.floating;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// apply given fillstyle
|
|
127
|
+
if (typeof settings.fillStyle !== "undefined") {
|
|
128
|
+
this.fillStyle = settings.fillStyle;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// update anchorPoint if provided
|
|
132
|
+
if (typeof settings.anchorPoint !== "undefined") {
|
|
133
|
+
this.anchorPoint.set(settings.anchorPoint.x, settings.anchorPoint.y);
|
|
134
|
+
} else {
|
|
135
|
+
this.anchorPoint.set(0, 0);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// instance to text metrics functions
|
|
139
|
+
this.metrics = new TextMetrics(this);
|
|
140
|
+
|
|
141
|
+
// resize if necessary
|
|
142
|
+
if (typeof settings.size === "number" && settings.size !== 1.0) {
|
|
143
|
+
this.resize(settings.size);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// set the text
|
|
147
|
+
this.setText(settings.text);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* change the font settings
|
|
152
|
+
* @param {string} textAlign - ("left", "center", "right")
|
|
153
|
+
* @param {number} [scale]
|
|
154
|
+
* @returns {BitmapText} this object for chaining
|
|
155
|
+
*/
|
|
156
|
+
set(textAlign, scale) {
|
|
157
|
+
this.textAlign = textAlign;
|
|
158
|
+
// updated scaled Size
|
|
159
|
+
if (scale) {
|
|
160
|
+
this.resize(scale);
|
|
161
|
+
}
|
|
162
|
+
this.isDirty = true;
|
|
163
|
+
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* change the text to be displayed
|
|
169
|
+
* @param {number|string|string[]} value - a string, or an array of strings
|
|
170
|
+
* @returns {BitmapText} this object for chaining
|
|
171
|
+
*/
|
|
172
|
+
setText(value = "") {
|
|
173
|
+
if (this._text.toString() !== value.toString()) {
|
|
174
|
+
if (!Array.isArray(value)) {
|
|
175
|
+
this._text = ("" + value).split("\n");
|
|
176
|
+
} else {
|
|
177
|
+
this._text = value;
|
|
178
|
+
}
|
|
179
|
+
this.isDirty = true;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (this._text.length > 0 && this.wordWrapWidth > 0) {
|
|
183
|
+
this._text = this.metrics.wordWrap(this._text, this.wordWrapWidth);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
this.updateBounds();
|
|
187
|
+
|
|
188
|
+
return this;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* update the bounding box for this Bitmap Text.
|
|
193
|
+
* @param {boolean} [absolute=true] - update the bounds size and position in (world) absolute coordinates
|
|
194
|
+
* @returns {Bounds} this Bitmap Text bounding box Rectangle object
|
|
195
|
+
*/
|
|
196
|
+
updateBounds(absolute = true) {
|
|
197
|
+
let bounds = this.getBounds();
|
|
198
|
+
|
|
199
|
+
bounds.clear();
|
|
200
|
+
|
|
201
|
+
if (typeof this.metrics !== "undefined") {
|
|
202
|
+
let ax, ay;
|
|
203
|
+
|
|
204
|
+
bounds.addBounds(this.metrics.measureText(this._text));
|
|
205
|
+
|
|
206
|
+
switch (this.textAlign) {
|
|
207
|
+
case "right":
|
|
208
|
+
ax = this.metrics.width * 1.0;
|
|
209
|
+
break;
|
|
210
|
+
|
|
211
|
+
case "center":
|
|
212
|
+
ax = this.metrics.width * 0.5;
|
|
213
|
+
break;
|
|
214
|
+
|
|
215
|
+
default :
|
|
216
|
+
ax = this.metrics.width * 0.0;
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// adjust y pos based on alignment value
|
|
221
|
+
switch (this.textBaseline) {
|
|
222
|
+
case "middle":
|
|
223
|
+
ay = this.metrics.height * 0.5;
|
|
224
|
+
break;
|
|
225
|
+
|
|
226
|
+
case "ideographic":
|
|
227
|
+
case "alphabetic":
|
|
228
|
+
case "bottom":
|
|
229
|
+
ay = this.metrics.height * 1.0;
|
|
230
|
+
break;
|
|
231
|
+
|
|
232
|
+
default :
|
|
233
|
+
ay = this.metrics.height * 0.0;
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// translate the bounds accordingly
|
|
238
|
+
bounds.translate(ax, ay);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (absolute === true) {
|
|
242
|
+
if (typeof this.ancestor !== "undefined" && typeof this.ancestor.getAbsolutePosition === "function" && this.floating !== true) {
|
|
243
|
+
bounds.translate(this.ancestor.getAbsolutePosition());
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return bounds;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* defines the color used to tint the bitmap text
|
|
252
|
+
* @public
|
|
253
|
+
* @type {Color}
|
|
254
|
+
* @see Renderable#tint
|
|
255
|
+
*/
|
|
256
|
+
get fillStyle() {
|
|
257
|
+
return this.tint;
|
|
258
|
+
}
|
|
259
|
+
set fillStyle(value) {
|
|
260
|
+
if (value instanceof Color) {
|
|
261
|
+
this.tint.copy(value);
|
|
262
|
+
} else {
|
|
263
|
+
// string (#RGB, #ARGB, #RRGGBB, #AARRGGBB)
|
|
264
|
+
this.tint.parseCSS(value);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* change the font display size
|
|
270
|
+
* @param {number} scale - ratio
|
|
271
|
+
* @returns {BitmapText} this object for chaining
|
|
272
|
+
*/
|
|
273
|
+
resize(scale) {
|
|
274
|
+
this.fontScale.set(scale, scale);
|
|
275
|
+
|
|
276
|
+
this.updateBounds();
|
|
277
|
+
|
|
278
|
+
this.isDirty = true;
|
|
279
|
+
|
|
280
|
+
return this;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* measure the given text size in pixels
|
|
285
|
+
* @param {string} [text]
|
|
286
|
+
* @returns {TextMetrics} a TextMetrics object with two properties: `width` and `height`, defining the output dimensions
|
|
287
|
+
*/
|
|
288
|
+
measureText(text = this._text) {
|
|
289
|
+
return this.metrics.measureText(text);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* draw the bitmap font
|
|
294
|
+
* @param {CanvasRenderer|WebGLRenderer} renderer - Reference to the destination renderer instance
|
|
295
|
+
* @param {string} [text]
|
|
296
|
+
* @param {number} [x]
|
|
297
|
+
* @param {number} [y]
|
|
298
|
+
*/
|
|
299
|
+
draw(renderer, text, x, y) {
|
|
300
|
+
// save the previous global alpha value
|
|
301
|
+
let _alpha = renderer.globalAlpha();
|
|
302
|
+
|
|
303
|
+
// allows to provide backward compatibility when
|
|
304
|
+
// adding Bitmap Font to an object container
|
|
305
|
+
if (typeof this.ancestor === "undefined") {
|
|
306
|
+
// update cache
|
|
307
|
+
this.setText(text);
|
|
308
|
+
renderer.setGlobalAlpha(_alpha * this.getOpacity());
|
|
309
|
+
} else {
|
|
310
|
+
// added directly to an object container
|
|
311
|
+
x = this.pos.x;
|
|
312
|
+
y = this.pos.y;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
let lX = x;
|
|
316
|
+
let stringHeight = this.metrics.lineHeight();
|
|
317
|
+
let maxWidth = 0;
|
|
318
|
+
|
|
319
|
+
for (let i = 0; i < this._text.length; i++) {
|
|
320
|
+
x = lX;
|
|
321
|
+
const string = this._text[i].trimEnd();
|
|
322
|
+
// adjust x pos based on alignment value
|
|
323
|
+
let stringWidth = this.metrics.lineWidth(string);
|
|
324
|
+
switch (this.textAlign) {
|
|
325
|
+
case "right":
|
|
326
|
+
x -= stringWidth;
|
|
327
|
+
break;
|
|
328
|
+
|
|
329
|
+
case "center":
|
|
330
|
+
x -= stringWidth * 0.5;
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// adjust y pos based on alignment value
|
|
335
|
+
switch (this.textBaseline) {
|
|
336
|
+
case "middle":
|
|
337
|
+
y -= stringHeight * 0.5;
|
|
338
|
+
break;
|
|
339
|
+
|
|
340
|
+
case "ideographic":
|
|
341
|
+
case "alphabetic":
|
|
342
|
+
case "bottom":
|
|
343
|
+
y -= stringHeight;
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// update initial position if required
|
|
348
|
+
if (this.isDirty === true && typeof this.ancestor === "undefined") {
|
|
349
|
+
if (i === 0) {
|
|
350
|
+
this.pos.y = y;
|
|
351
|
+
}
|
|
352
|
+
if (maxWidth < stringWidth) {
|
|
353
|
+
maxWidth = stringWidth;
|
|
354
|
+
this.pos.x = x;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// draw the string
|
|
359
|
+
let lastGlyph = null;
|
|
360
|
+
for (let c = 0, len = string.length; c < len; c++) {
|
|
361
|
+
// calculate the char index
|
|
362
|
+
let ch = string.charCodeAt(c);
|
|
363
|
+
let glyph = this.fontData.glyphs[ch];
|
|
364
|
+
|
|
365
|
+
if (typeof glyph !== "undefined") {
|
|
366
|
+
let glyphWidth = glyph.width;
|
|
367
|
+
let glyphHeight = glyph.height;
|
|
368
|
+
let kerning = (lastGlyph && lastGlyph.kerning) ? lastGlyph.getKerning(ch) : 0;
|
|
369
|
+
let scaleX = this.fontScale.x;
|
|
370
|
+
let scaleY = this.fontScale.y;
|
|
371
|
+
|
|
372
|
+
// draw it
|
|
373
|
+
if (glyphWidth !== 0 && glyphHeight !== 0) {
|
|
374
|
+
// some browser throw an exception when drawing a 0 width or height image
|
|
375
|
+
renderer.drawImage(this.fontImage,
|
|
376
|
+
glyph.x, glyph.y,
|
|
377
|
+
glyphWidth, glyphHeight,
|
|
378
|
+
x + glyph.xoffset * scaleX,
|
|
379
|
+
y + glyph.yoffset * scaleY,
|
|
380
|
+
glyphWidth * scaleX, glyphHeight * scaleY
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// increment position
|
|
385
|
+
x += (glyph.xadvance + kerning) * scaleX;
|
|
386
|
+
lastGlyph = glyph;
|
|
387
|
+
} else {
|
|
388
|
+
console.warn("BitmapText: no defined Glyph in for " + String.fromCharCode(ch));
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
// increment line
|
|
392
|
+
y += stringHeight;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
if (typeof this.ancestor === "undefined") {
|
|
396
|
+
// restore the previous global alpha value
|
|
397
|
+
renderer.setGlobalAlpha(_alpha);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// clear the dirty flag here for
|
|
401
|
+
// backward compatibility
|
|
402
|
+
this.isDirty = false;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Destroy function
|
|
407
|
+
* @ignore
|
|
408
|
+
*/
|
|
409
|
+
destroy() {
|
|
410
|
+
pool.push(this.fontScale);
|
|
411
|
+
this.fontScale = undefined;
|
|
412
|
+
pool.push(this.fontData);
|
|
413
|
+
this.fontData = undefined;
|
|
414
|
+
this._text.length = 0;
|
|
415
|
+
this.metrics = undefined;
|
|
416
|
+
super.destroy();
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
export { BitmapText as default };
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* melonJS Game Engine - v15.4.1
|
|
3
|
+
* http://www.melonjs.org
|
|
4
|
+
* melonjs is licensed under the MIT License.
|
|
5
|
+
* http://www.opensource.org/licenses/mit-license
|
|
6
|
+
* @copyright (C) 2011 - 2023 Olivier Biot (AltByte Pte Ltd)
|
|
7
|
+
*/
|
|
8
|
+
import Glyph from './glyph.js';
|
|
9
|
+
|
|
10
|
+
// bitmap constants
|
|
11
|
+
const capChars = ["M", "N", "B", "D", "C", "E", "F", "K", "A", "G", "H", "I", "J", "L", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Gets the value from a string of pairs.
|
|
15
|
+
* @ignore
|
|
16
|
+
*/
|
|
17
|
+
function getValueFromPair(string, pattern) {
|
|
18
|
+
let value = string.match(pattern);
|
|
19
|
+
if (!value) {
|
|
20
|
+
throw new Error("Could not find pattern " + pattern + " in string: " + string);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return value[0].split("=")[1];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Gets the first glyph in the map that is not a space character
|
|
28
|
+
* @ignore
|
|
29
|
+
* @name _getFirstGlyph
|
|
30
|
+
* @memberof BitmapTextData
|
|
31
|
+
* @param {object} glyphs - the map of glyphs, each key is a char code
|
|
32
|
+
* @returns {Glyph}
|
|
33
|
+
*/
|
|
34
|
+
function getFirstGlyph(glyphs) {
|
|
35
|
+
let keys = Object.keys(glyphs);
|
|
36
|
+
for (let i = 0; i < keys.length; i++) {
|
|
37
|
+
if (keys[i] > 32) {
|
|
38
|
+
return glyphs[keys[i]];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Creates a glyph to use for the space character
|
|
46
|
+
* @ignore
|
|
47
|
+
* @name createSpaceGlyph
|
|
48
|
+
* @memberof BitmapTextData
|
|
49
|
+
* @param {object} glyphs - the map of glyphs, each key is a char code
|
|
50
|
+
*/
|
|
51
|
+
function createSpaceGlyph(glyphs) {
|
|
52
|
+
let spaceCharCode = " ".charCodeAt(0);
|
|
53
|
+
let glyph = glyphs[spaceCharCode];
|
|
54
|
+
if (!glyph) {
|
|
55
|
+
glyph = new Glyph();
|
|
56
|
+
glyph.id = spaceCharCode;
|
|
57
|
+
glyph.xadvance = getFirstGlyph(glyphs).xadvance;
|
|
58
|
+
glyphs[spaceCharCode] = glyph;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Class for storing relevant data from the font file.
|
|
64
|
+
* @ignore
|
|
65
|
+
*/
|
|
66
|
+
class BitmapTextData {
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @param {string} data - The bitmap font data pulled from the resource loader using me.loader.getBinary()
|
|
70
|
+
*/
|
|
71
|
+
constructor(data) {
|
|
72
|
+
this.onResetEvent(data);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @ignore
|
|
77
|
+
*/
|
|
78
|
+
onResetEvent(data) {
|
|
79
|
+
this.padTop = 0;
|
|
80
|
+
this.padRight = 0;
|
|
81
|
+
this.padBottom = 0;
|
|
82
|
+
this.padLeft = 0;
|
|
83
|
+
this.lineHeight = 0;
|
|
84
|
+
// The distance from the top of most uppercase characters to the baseline. Since the drawing position is the cap height of
|
|
85
|
+
// the first line, the cap height can be used to get the location of the baseline.
|
|
86
|
+
this.capHeight = 1;
|
|
87
|
+
// The distance from the bottom of the glyph that extends the lowest to the baseline. This number is negative.
|
|
88
|
+
this.descent = 0;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The map of glyphs, each key is a char code.
|
|
92
|
+
* @name glyphs
|
|
93
|
+
* @type {object}
|
|
94
|
+
* @memberof BitmapTextData
|
|
95
|
+
*/
|
|
96
|
+
this.glyphs = {};
|
|
97
|
+
|
|
98
|
+
// parse the data
|
|
99
|
+
this.parse(data);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* This parses the font data text and builds a map of glyphs containing the data for each character
|
|
104
|
+
* @name parse
|
|
105
|
+
* @memberof BitmapTextData
|
|
106
|
+
* @param {string} fontData
|
|
107
|
+
*/
|
|
108
|
+
parse(fontData) {
|
|
109
|
+
if (!fontData) {
|
|
110
|
+
throw new Error("File containing font data was empty, cannot load the bitmap font.");
|
|
111
|
+
}
|
|
112
|
+
let lines = fontData.split(/\r\n|\n/);
|
|
113
|
+
let padding = fontData.match(/padding\=\d+,\d+,\d+,\d+/g);
|
|
114
|
+
if (!padding) {
|
|
115
|
+
throw new Error("Padding not found in first line");
|
|
116
|
+
}
|
|
117
|
+
let paddingValues = padding[0].split("=")[1].split(",");
|
|
118
|
+
this.padTop = parseFloat(paddingValues[0]);
|
|
119
|
+
this.padLeft = parseFloat(paddingValues[1]);
|
|
120
|
+
this.padBottom = parseFloat(paddingValues[2]);
|
|
121
|
+
this.padRight = parseFloat(paddingValues[3]);
|
|
122
|
+
|
|
123
|
+
this.lineHeight = parseFloat(getValueFromPair(lines[1], /lineHeight\=\d+/g));
|
|
124
|
+
|
|
125
|
+
let baseLine = parseFloat(getValueFromPair(lines[1], /base\=\d+/g));
|
|
126
|
+
let padY = this.padTop + this.padBottom;
|
|
127
|
+
let glyph = null;
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
for (let i = 4; i < lines.length; i++) {
|
|
131
|
+
let line = lines[i];
|
|
132
|
+
let characterValues = line.split(/=|\s+/);
|
|
133
|
+
if (!line || /^kernings/.test(line)) {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (/^kerning\s/.test(line)) {
|
|
137
|
+
let first = parseFloat(characterValues[2]);
|
|
138
|
+
let second = parseFloat(characterValues[4]);
|
|
139
|
+
let amount = parseFloat(characterValues[6]);
|
|
140
|
+
|
|
141
|
+
glyph = this.glyphs[first];
|
|
142
|
+
if (glyph !== null && typeof glyph !== "undefined") {
|
|
143
|
+
glyph.setKerning(second, amount);
|
|
144
|
+
}
|
|
145
|
+
} else {
|
|
146
|
+
glyph = new Glyph();
|
|
147
|
+
|
|
148
|
+
let ch = parseFloat(characterValues[2]);
|
|
149
|
+
glyph.id = ch;
|
|
150
|
+
glyph.x = parseFloat(characterValues[4]);
|
|
151
|
+
glyph.y = parseFloat(characterValues[6]);
|
|
152
|
+
glyph.width = parseFloat(characterValues[8]);
|
|
153
|
+
glyph.height = parseFloat(characterValues[10]);
|
|
154
|
+
glyph.xoffset = parseFloat(characterValues[12]);
|
|
155
|
+
glyph.yoffset = parseFloat(characterValues[14]);
|
|
156
|
+
glyph.xadvance = parseFloat(characterValues[16]);
|
|
157
|
+
|
|
158
|
+
if (glyph.width > 0 && glyph.height > 0) {
|
|
159
|
+
this.descent = Math.min(baseLine + glyph.yoffset, this.descent);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
this.glyphs[ch] = glyph;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
this.descent += this.padBottom;
|
|
167
|
+
|
|
168
|
+
createSpaceGlyph(this.glyphs);
|
|
169
|
+
|
|
170
|
+
let capGlyph = null;
|
|
171
|
+
for (let i = 0; i < capChars.length; i++) {
|
|
172
|
+
let capChar = capChars[i];
|
|
173
|
+
capGlyph = this.glyphs[capChar.charCodeAt(0)];
|
|
174
|
+
if (capGlyph) {
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (!capGlyph) {
|
|
179
|
+
for (let charCode in this.glyphs) {
|
|
180
|
+
if (this.glyphs.hasOwnProperty(charCode)) {
|
|
181
|
+
glyph = this.glyphs[charCode];
|
|
182
|
+
if (glyph.height === 0 || glyph.width === 0) {
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
this.capHeight = Math.max(this.capHeight, glyph.height);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
} else {
|
|
189
|
+
this.capHeight = capGlyph.height;
|
|
190
|
+
}
|
|
191
|
+
this.capHeight -= padY;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export { BitmapTextData as default };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* melonJS Game Engine - v15.4.1
|
|
3
|
+
* http://www.melonjs.org
|
|
4
|
+
* melonjs is licensed under the MIT License.
|
|
5
|
+
* http://www.opensource.org/licenses/mit-license
|
|
6
|
+
* @copyright (C) 2011 - 2023 Olivier Biot (AltByte Pte Ltd)
|
|
7
|
+
*/
|
|
8
|
+
// bitmap constants
|
|
9
|
+
const LOG2_PAGE_SIZE = 9;
|
|
10
|
+
const PAGE_SIZE = 1 << LOG2_PAGE_SIZE;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* a glyph representing a single character in a font
|
|
14
|
+
* @ignore
|
|
15
|
+
*/
|
|
16
|
+
class Glyph {
|
|
17
|
+
/**
|
|
18
|
+
* @ignore
|
|
19
|
+
*/
|
|
20
|
+
constructor() {
|
|
21
|
+
this.id = 0;
|
|
22
|
+
this.x = 0;
|
|
23
|
+
this.y = 0;
|
|
24
|
+
this.width = 0;
|
|
25
|
+
this.height = 0;
|
|
26
|
+
this.u = 0;
|
|
27
|
+
this.v = 0;
|
|
28
|
+
this.u2 = 0;
|
|
29
|
+
this.v2 = 0;
|
|
30
|
+
this.xoffset = 0;
|
|
31
|
+
this.yoffset = 0;
|
|
32
|
+
this.xadvance = 0;
|
|
33
|
+
this.fixedWidth = false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @ignore
|
|
38
|
+
*/
|
|
39
|
+
getKerning(ch) {
|
|
40
|
+
if (this.kerning) {
|
|
41
|
+
let page = this.kerning[ch >>> LOG2_PAGE_SIZE];
|
|
42
|
+
if (page) {
|
|
43
|
+
return page[ch & PAGE_SIZE - 1] || 0;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @ignore
|
|
51
|
+
*/
|
|
52
|
+
setKerning(ch, value) {
|
|
53
|
+
if (!this.kerning) {
|
|
54
|
+
this.kerning = {};
|
|
55
|
+
}
|
|
56
|
+
let page = this.kerning[ch >>> LOG2_PAGE_SIZE];
|
|
57
|
+
if (typeof page === "undefined") {
|
|
58
|
+
this.kerning[ch >>> LOG2_PAGE_SIZE] = {};
|
|
59
|
+
page = this.kerning[ch >>> LOG2_PAGE_SIZE];
|
|
60
|
+
}
|
|
61
|
+
page[ch & PAGE_SIZE - 1] = value;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { Glyph as default };
|