Skip to content

Commit

Permalink
Add missing font styles, documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
bigtimebuddy committed Dec 5, 2022
1 parent 0b40830 commit 45fce10
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/HTMLTextStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,40 @@ type HTMLTextStyleWhiteSpace = 'normal' | 'pre' | 'pre-line' | 'nowrap' | 'pre-w

// Subset of ITextStyle
type ITextStyleIgnore = 'whiteSpace' | 'fillGradientStops' | 'fillGradientType' | 'miterLimit' | 'textBaseline';

/**
* Modifed versions from ITextStyle.
* @extends ITextStyle
*/
interface IHTMLTextStyle extends Omit<ITextStyle, ITextStyleIgnore>
{
/**
* White-space with expanded options
* @type {'normal'|'pre'|'pre-line'|'nowrap'|'pre-wrap'}
*/
whiteSpace: HTMLTextStyleWhiteSpace;
}

/**
* Font information for HTMLText
*/
interface IHTMLFont
{
/** User-supplied URL request */
originalUrl: string;
/** Base64 string for font */
dataSrc: string;
fontFace: FontFace;
/** FontFace installed in the document */
fontFace: FontFace | null;
/** Blob-based URL for font */
src: string;
/** Family name of font */
family: string;
/** Weight of the font */
weight: TextStyleFontWeight;
/** Style of the font */
style: TextStyleFontStyle;
/** Reference counter */
refs: number;
}

Expand All @@ -30,6 +50,7 @@ interface IHTMLFont
* @class
* @extends PIXI.TextStyle
* @see {@link https://pixijs.download/dev/docs/PIXI.TextStyle.html PIXI.TextStyle}
* @param {PIXI.ITextStyle|IHTMLTextStyle} [style] - Style to copy.
*/
class HTMLTextStyle extends TextStyle
{
Expand Down Expand Up @@ -117,7 +138,7 @@ class HTMLTextStyle extends TextStyle
}

/** Because of how HTMLText renders, fonts need to be imported */
public loadFont(url: string, options: Partial<Omit<IHTMLFont, 'url'>> = {}): Promise<void>
public loadFont(url: string, options: Partial<Pick<IHTMLFont, 'weight' | 'style' | 'family'>> = {}): Promise<void>
{
const { availableFonts } = HTMLTextStyle;

Expand Down Expand Up @@ -146,7 +167,7 @@ class HTMLTextStyle extends TextStyle
}))
.then(async ([src, dataSrc]) =>
{
const font = Object.assign({
const font: IHTMLFont = Object.assign({
family: utils.path.basename(url, utils.path.extname(url)),
weight: 'normal',
style: 'normal',
Expand All @@ -155,7 +176,7 @@ class HTMLTextStyle extends TextStyle
refs: 1,
originalUrl: url,
fontFace: null,
}, options) as IHTMLFont;
}, options);

availableFonts[url] = font;
this._fonts.push(font);
Expand Down

0 comments on commit 45fce10

Please sign in to comment.