UNPKG

@awayjs/scene

Version:
110 lines (109 loc) 3.71 kB
import { __extends } from "tslib"; import { AssetBase } from '@awayjs/core'; import { TesselatedFontTable } from './TesselatedFontTable'; import { BitmapFontTable } from './BitmapFontTable'; /** * Font is a container for FontTables. * * * */ var Font = /** @class */ (function (_super) { __extends(Font, _super); /** * Creates a new TesselatedFont object */ function Font() { var _this = _super.call(this) || this; _this._font_styles = {}; _this.fontName = null; _this.regularFontStyle = null; return _this; } Object.defineProperty(Font, "emptyFontTable", { get: function () { if (!this._emptyFontTable) { this._emptyFontTable = new TesselatedFontTable(); } return this._emptyFontTable; }, enumerable: false, configurable: true }); // ------------ dummys for as3web: Font.registerFont = function (any) { }; Object.defineProperty(Font.prototype, "font_styles", { // ------------ get: function () { return this._font_styles; }, enumerable: false, configurable: true }); Object.defineProperty(Font.prototype, "assetType", { /** * */ get: function () { return Font.assetType; }, enumerable: false, configurable: true }); /** * */ Font.prototype.dispose = function () { for (var key in this._font_styles) { this._font_styles[key].dispose(); } this._font_styles = null; }; Font.prototype.replace_font_table = function (style_name, table) { this._font_styles[style_name] = table; }; Font.prototype.create_font_table = function (style_name, assetType, openTypeFont) { if (assetType === void 0) { assetType = TesselatedFontTable.assetType; } if (openTypeFont === void 0) { openTypeFont = null; } var existingTable = this.get_font_table(style_name, assetType, openTypeFont); if (existingTable) { console.warn("[Font] - create_font_table - ".concat(style_name, " - already exists")); } var font_style = null; if (assetType == TesselatedFontTable.assetType) { font_style = new TesselatedFontTable(openTypeFont); } else if (assetType == BitmapFontTable.assetType) { font_style = new BitmapFontTable(); } font_style.name = style_name; font_style.font = this; this._font_styles[style_name] = font_style; return font_style; }; /** *Get a font-table for a specific name, or create one if it does not exists. */ Font.prototype.get_font_table = function (style_name, assetType, openTypeFont, returnDifferentStyle) { if (assetType === void 0) { assetType = TesselatedFontTable.assetType; } if (openTypeFont === void 0) { openTypeFont = null; } if (returnDifferentStyle === void 0) { returnDifferentStyle = false; } var table = this._font_styles[style_name]; if (table) { if (table.assetType != assetType) { throw ('[Font] - get_font_table - existing table has wrong assetType'); } return table; } if (returnDifferentStyle && Object.keys(this._font_styles).length > 0) { for (var key in this._font_styles) { console.log('font style not found return different', key); return this._font_styles[key]; } } return null; }; Font.assetType = '[asset Font]'; return Font; }(AssetBase)); export { Font };