* update the bounding box for this Bitmap Text. * @param {boolean} [absolute=true] - update the bounds size and position in (world) absolute coordinates * @returns {Bounds} this Bitmap Text bounding box Rectangle object
(absolute = true)
| 252 | * @returns {Bounds} this Bitmap Text bounding box Rectangle object |
| 253 | */ |
| 254 | updateBounds(absolute = true) { |
| 255 | const bounds = this.getBounds(); |
| 256 | |
| 257 | bounds.clear(); |
| 258 | |
| 259 | if (typeof this.metrics !== "undefined") { |
| 260 | const w = this.metrics.width; |
| 261 | const h = this.metrics.height; |
| 262 | |
| 263 | // compute x offset based on textAlign |
| 264 | let ax = 0; |
| 265 | switch (this.textAlign) { |
| 266 | case "right": |
| 267 | ax = w; |
| 268 | break; |
| 269 | case "center": |
| 270 | ax = w / 2; |
| 271 | break; |
| 272 | } |
| 273 | |
| 274 | // baseline shift based on total text height (matching draw code) |
| 275 | const gy = this.metrics.glyphYOffset || 0; |
| 276 | let ay = 0; |
| 277 | switch (this.textBaseline) { |
| 278 | case "middle": |
| 279 | ay = gy + h * 0.5; |
| 280 | break; |
| 281 | case "ideographic": |
| 282 | case "alphabetic": |
| 283 | case "bottom": |
| 284 | ay = gy + h; |
| 285 | break; |
| 286 | } |
| 287 | |
| 288 | bounds.addFrame(-ax, -ay + gy, w - ax, -ay + gy + h); |
| 289 | } |
| 290 | |
| 291 | if (absolute === true) { |
| 292 | const absPos = this.getAbsolutePosition(); |
| 293 | bounds.centerOn( |
| 294 | absPos.x + bounds.x + bounds.width / 2, |
| 295 | absPos.y + bounds.y + bounds.height / 2, |
| 296 | ); |
| 297 | } |
| 298 | |
| 299 | return bounds; |
| 300 | } |
| 301 | |
| 302 | /** |
| 303 | * defines the color used to tint the bitmap text |