/
githubmirror
/
pixijs
Обзор
Документация
Войти
/
githubmirror
/
pixijs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
src/scene/text-bitmap/asset/__tests__/bitmapFontTextParser.test.ts
55 строк
2 KB
Zyie
fix: handle missing base in bitmap font parsers (#12121)
13 июл 2026, 11:40
Не верифицирован
13 июл 2026, 11:40
1d90a20
Код
Авторство
О чём код?
import { bitmapFontTextParser } from '../bitmapFontTextParser'; const rawFontString = ` info face="sans-serif" size=36 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=1 aa=1 padding=1,1,1,1 spacing=1,1 common lineHeight=36 base=27 scaleW=256 scaleH=256 pages=1 packed=0 page id=0 file="sans-serif.png" chars count=2 char id=32 x=0 y=0 width=0 height=0 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15 char id=33 x=244 y=107 width=8 height=30 xoffset=4 yoffset=0 xadvance=15 page=0 chnl=15 `; const rawFontStringNoBase = ` info face="sans-serif" size=36 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=1 aa=1 padding=1,1,1,1 spacing=1,1 common lineHeight=36 scaleW=256 scaleH=256 pages=1 packed=0 page id=0 file="sans-serif.png" chars count=2 char id=32 x=0 y=0 width=0 height=0 xoffset=0 yoffset=0 xadvance=12 page=0 chnl=15 char id=33 x=244 y=107 width=8 height=30 xoffset=4 yoffset=0 xadvance=15 page=0 chnl=15 `; describe('bitmapFontTextParser', () => { it('should parse text chars, if no letter or char property is present', async () => { const parsedText = bitmapFontTextParser.parse(rawFontString); expect(parsedText.chars['!']).toEqual({ id: 33, page: 0, x: 244, y: 107, width: 8, height: 30, xOffset: 4, yOffset: 0, xAdvance: 15, kerning: {} }); }); it('should parse baseLineOffset from base', () => { const parsedText = bitmapFontTextParser.parse(rawFontString); expect(parsedText.baseLineOffset).toBe(9); }); it('should default baseLineOffset to 0 when base is missing', () => { const parsedText = bitmapFontTextParser.parse(rawFontStringNoBase); expect(parsedText.baseLineOffset).toBe(0); expect(Number.isFinite(parsedText.baseLineOffset)).toBe(true); }); });