pixi-glyphs 4.2.0 → 4.3.0
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/README.md +1 -0
- package/dist/Glyphs.d.ts +1 -0
- package/dist/pixi-glyphs.js +34 -1
- package/dist/pixi-glyphs.js.map +1 -1
- package/dist/pixi-glyphs.m.js +34 -1
- package/dist/pixi-glyphs.m.js.map +1 -1
- package/dist/pixi-glyphs.modern.js +36 -2
- package/dist/pixi-glyphs.modern.js.map +1 -1
- package/dist/pixi-glyphs.umd.js +34 -1
- package/dist/pixi-glyphs.umd.js.map +1 -1
- package/dist/types.d.ts +4 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -83,6 +83,7 @@ The style objects are modified versions (supersets) of `PIXI.TextStyle` (referre
|
|
|
83
83
|
- `fontScaleWidth` - Percentage to scale the font e.g. `0.5` = 50%
|
|
84
84
|
- `fontScaleHeight` - Percentage to scale the font e.g. `1.25` = 125%
|
|
85
85
|
- `letterSpacing` - Additional horizontal spacing between each character in pixels. Can be positive to spread letters apart or negative to bring them closer together. Default is `0`.
|
|
86
|
+
- `wordSpacing` - Additional horizontal spacing for word separators (spaces) in pixels. Adjusts the width of spaces between words. Can be positive to increase spacing or negative to decrease spacing. Default is `0`.
|
|
86
87
|
- `lineSpacing` - Additional vertical spacing between lines of text in pixels. This spacing is added between all lines within a paragraph. Default is `0`.
|
|
87
88
|
- `paragraphSpacing` - Additional spacing between paragraphs that is added when you use an explicit carriage return rather than letting the text wrap at the end of a line. Default is `0`. Can also be negative.
|
|
88
89
|
- `breakLines` - When `breakLines` is `false`, the text in the tag will ignore the `wordWrapWidth` property and never wrap to the next line unless you explicitly include a newline character. It essentially treats the whole tag as a single word. If a nested tag overrides this, only the text inside the nested tag will wrap. Default is `true`.
|
package/dist/Glyphs.d.ts
CHANGED
|
@@ -47,6 +47,7 @@ export default class Glyphs<TextType extends PixiTextTypes = PIXI.Text> extends
|
|
|
47
47
|
get spriteContainer(): PIXI.Container;
|
|
48
48
|
private _debugContainer;
|
|
49
49
|
get debugContainer(): PIXI.Container;
|
|
50
|
+
private _maskGraphics;
|
|
50
51
|
private logWarning;
|
|
51
52
|
constructor(text?: string, tagStyles?: TextStyleSet, options?: TaggedTextOptions);
|
|
52
53
|
destroyImgMap(): void;
|
package/dist/pixi-glyphs.js
CHANGED
|
@@ -889,10 +889,20 @@ const verticalAlignInLines = (lines, lineSpacing, overrideValign) => {
|
|
|
889
889
|
let tallestToken = getTallestToken(line);
|
|
890
890
|
let baseHeight = tallestToken.bounds?.height ?? 0;
|
|
891
891
|
let baseTallestAscent = 0;
|
|
892
|
+
let baseTallestDescent = 0;
|
|
893
|
+
let tallestSpriteHeight = 0;
|
|
892
894
|
const hasRealContent = line.flat(2).some(seg => !isWhitespaceToken(seg) && !isNewlineToken(seg));
|
|
893
895
|
for (const word of line) {
|
|
894
896
|
for (const segment of word) {
|
|
897
|
+
if (isSpriteToken(segment)) {
|
|
898
|
+
const spriteHeight = segment.bounds?.height ?? 0;
|
|
899
|
+
if (spriteHeight > tallestSpriteHeight) {
|
|
900
|
+
tallestSpriteHeight = spriteHeight;
|
|
901
|
+
}
|
|
902
|
+
continue;
|
|
903
|
+
}
|
|
895
904
|
let segAscent = segment.fontProperties?.ascent ?? 0;
|
|
905
|
+
const segDescent = segment.fontProperties?.descent ?? 0;
|
|
896
906
|
const style = segment.style;
|
|
897
907
|
const strokeWidth = typeof style?.stroke === 'object' ? style.stroke.width : 0;
|
|
898
908
|
const legacyStrokeThickness = style.strokeThickness || 0;
|
|
@@ -914,9 +924,12 @@ const verticalAlignInLines = (lines, lineSpacing, overrideValign) => {
|
|
|
914
924
|
}
|
|
915
925
|
if (segAscent > baseTallestAscent) {
|
|
916
926
|
baseTallestAscent = segAscent;
|
|
927
|
+
baseTallestDescent = segDescent;
|
|
917
928
|
}
|
|
918
929
|
}
|
|
919
930
|
}
|
|
931
|
+
const textBasedHeight = baseTallestAscent + baseTallestDescent;
|
|
932
|
+
baseHeight = Math.max(textBasedHeight, tallestSpriteHeight);
|
|
920
933
|
if (baseHeight === 0 && baseTallestAscent === 0) {
|
|
921
934
|
baseHeight = lastNonEmptyTallestToken.bounds?.height ?? 0;
|
|
922
935
|
baseTallestAscent = lastNonEmptyTallestToken.fontProperties?.ascent ?? 0;
|
|
@@ -1263,7 +1276,8 @@ const calculateTokens = (styledTokens, splitStyle = "words", scaleIcons = true,
|
|
|
1263
1276
|
const baselineAdjustment = getBaselineAdjustment(style, adjustFontBaseline, fontProperties.ascent);
|
|
1264
1277
|
fontProperties.ascent += baselineAdjustment;
|
|
1265
1278
|
const {
|
|
1266
|
-
letterSpacing
|
|
1279
|
+
letterSpacing,
|
|
1280
|
+
wordSpacing
|
|
1267
1281
|
} = style;
|
|
1268
1282
|
if (letterSpacing) {
|
|
1269
1283
|
bounds.width += letterSpacing;
|
|
@@ -1276,6 +1290,9 @@ const calculateTokens = (styledTokens, splitStyle = "words", scaleIcons = true,
|
|
|
1276
1290
|
fontProperties,
|
|
1277
1291
|
textDecorations
|
|
1278
1292
|
};
|
|
1293
|
+
if (wordSpacing && isOnlyWhitespace(str)) {
|
|
1294
|
+
convertedToken.bounds.width += wordSpacing;
|
|
1295
|
+
}
|
|
1279
1296
|
return convertedToken;
|
|
1280
1297
|
});
|
|
1281
1298
|
output = output.concat(textTokens);
|
|
@@ -1552,6 +1569,7 @@ class Glyphs extends PIXI__namespace.Container {
|
|
|
1552
1569
|
this._decorationContainer = void 0;
|
|
1553
1570
|
this._spriteContainer = void 0;
|
|
1554
1571
|
this._debugContainer = void 0;
|
|
1572
|
+
this._maskGraphics = null;
|
|
1555
1573
|
this.logWarning = (code, message) => logWarning(this.options.errorHandler, this.options.supressConsole, this)(code, message);
|
|
1556
1574
|
this._textContainer = new PIXI__namespace.Container();
|
|
1557
1575
|
this._spriteContainer = new PIXI__namespace.Container();
|
|
@@ -1632,6 +1650,9 @@ class Glyphs extends PIXI__namespace.Container {
|
|
|
1632
1650
|
this._options = {};
|
|
1633
1651
|
}
|
|
1634
1652
|
resetChildren() {
|
|
1653
|
+
if (this._maskGraphics && this._maskGraphics.parent === this) {
|
|
1654
|
+
this.removeChild(this._maskGraphics);
|
|
1655
|
+
}
|
|
1635
1656
|
if (this._highlightContainer) {
|
|
1636
1657
|
this._highlightContainer.removeChildren().forEach(child => child.destroy());
|
|
1637
1658
|
const removed = this.removeChild(this._highlightContainer);
|
|
@@ -1849,6 +1870,18 @@ class Glyphs extends PIXI__namespace.Container {
|
|
|
1849
1870
|
if (drawWhitespace === false && drewDecorations) {
|
|
1850
1871
|
this.logWarning("text-decoration-and-whitespace", "Text decorations, such as underlines, will not appear under whitespace unless the `drawWhitespace` option is set to `true`.");
|
|
1851
1872
|
}
|
|
1873
|
+
if (!this._maskGraphics) {
|
|
1874
|
+
this._maskGraphics = new PIXI__namespace.Graphics();
|
|
1875
|
+
} else {
|
|
1876
|
+
this._maskGraphics.clear();
|
|
1877
|
+
}
|
|
1878
|
+
this._maskGraphics.rect(0, 0, 10000, 10000);
|
|
1879
|
+
this._maskGraphics.fill({
|
|
1880
|
+
color: 0xffffff
|
|
1881
|
+
});
|
|
1882
|
+
this._maskGraphics.alpha = 0;
|
|
1883
|
+
this.addChildAt(this._maskGraphics, 0);
|
|
1884
|
+
this.mask = this._maskGraphics;
|
|
1852
1885
|
if (this.options.debug) {
|
|
1853
1886
|
this.drawDebug();
|
|
1854
1887
|
}
|