MCPcopy Create free account
hub / github.com/esengine/esengine / loadFont

Method loadFont

packages/fairygui/src/package/UIPackage.ts:667–718  ·  view source on GitHub ↗

* Load font data * 加载字体数据

(item: PackageItem)

Source from the content-addressed store, hash-verified

665 * 加载字体数据
666 */
667 private loadFont(item: PackageItem): void {
668 const buffer = item.rawData as ByteBuffer;
669 if (!buffer) return;
670
671 buffer.seek(0, 0);
672
673 const ttf = buffer.readBool();
674 const tint = buffer.readBool();
675 buffer.readBool(); // autoScaleSize
676 buffer.readBool(); // has channel
677 const fontSize = Math.max(buffer.getInt32(), 1);
678 const xadvance = buffer.getInt32();
679 const lineHeight = buffer.getInt32();
680
681 const font: any = {
682 ttf,
683 tint,
684 fontSize,
685 lineHeight: Math.max(lineHeight, fontSize),
686 glyphs: new Map()
687 };
688
689 buffer.seek(0, 1);
690
691 const glyphCount = buffer.getInt32();
692 for (let i = 0; i < glyphCount; i++) {
693 let nextPos = buffer.getInt16();
694 nextPos += buffer.pos;
695
696 const ch = buffer.getUint16();
697 const glyph: any = {};
698
699 const img = buffer.readS();
700 const bx = buffer.getInt32();
701 const by = buffer.getInt32();
702 glyph.x = buffer.getInt32();
703 glyph.y = buffer.getInt32();
704 glyph.width = buffer.getInt32();
705 glyph.height = buffer.getInt32();
706 glyph.advance = buffer.getInt32();
707 buffer.readByte(); // channel
708
709 if (!ttf && glyph.advance === 0) {
710 glyph.advance = xadvance > 0 ? xadvance : glyph.x + glyph.width;
711 }
712
713 font.glyphs.set(ch, glyph);
714 buffer.pos = nextPos;
715 }
716
717 item.bitmapFont = font;
718 }
719
720 /**
721 * Create object from item name

Callers 1

getItemAssetMethod · 0.95

Calls 9

readBoolMethod · 0.80
getInt32Method · 0.80
getInt16Method · 0.80
getUint16Method · 0.80
readSMethod · 0.80
readByteMethod · 0.80
seekMethod · 0.65
setMethod · 0.65
maxMethod · 0.45

Tested by

no test coverage detected