MCPcopy Index your code
hub / github.com/Moddable-OpenSource/moddable / run

Method run

tools/compressbmf.js:100–261  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

98 }
99
100 run() {
101 let bmf = parseBMF(this.readFileBuffer(this.fontPath), true);
102 let bytes = new Uint8Array(bmf);
103 bytes.position = bmf.position + 4;
104 bmf.writePosition = bmf.byteLength;
105
106 let bmp = parseBMP(this.readFileBuffer(this.bitmapPath));
107 let bmpIs4 = 4 == Bitmap.depth(bmp.pixelFormat);
108
109 let output = new FILE(this.outputPath, "wb");
110
111 let convert = new Converter(bmp.pixelFormat, Bitmap.Gray16);
112 let chars = new Array(bmf.charCount);
113
114 let sourceRowBytes = ((bmp.width * Bitmap.depth(bmp.pixelFormat)) + 7) >> 3;
115
116 /*
117 set our extra flags in the chnl field of the first glyph
118 */
119 let position = bytes.position;
120 let prev = this.readU32(bytes);
121 let continuous = true, ascending = true;
122 for (let char = 1; char < bmf.charCount; char++) {
123 bytes.position = position + (20 * char);
124 let c = this.readU32(bytes);
125 if (c != (prev + 1))
126 continuous = false;
127 if (c <= prev)
128 ascending = false;
129 bytes.position = position + (20 * (char + 1));
130 prev = c;
131 }
132 bytes.position = position;
133 if (!continuous && !ascending)
134 throw new Error("character codes must be ascending");
135 bytes[position + 19] |= 0x80;
136 if (continuous)
137 bytes[position + 19] |= 0x40;
138 if (ascending)
139 bytes[position + 19] |= 0x20;
140
141 bytes[position + 19] |= 0x10; // kerning table sorted (below)
142
143 /*
144 compress each glyph independently
145 */
146 for (let char = 0; char < bmf.charCount; char += 1, bytes.position += 8) {
147 let dataOffset = bmf.writePosition - bytes.position; // byte offset from characters entry
148 let charCode = this.readU32(bytes);
149 let sx = this.readS16(bytes);
150 let sy = this.readS16(bytes);
151 let sw = this.readS16(bytes);
152 let sh = this.readS16(bytes);
153 let tc, td;
154
155 switch (this.rotation) {
156 case 90:
157 tc = sx;

Callers

nothing calls this directly

Calls 11

beginMethod · 0.95
sendMethod · 0.95
endMethod · 0.95
readU32Method · 0.80
readS16Method · 0.80
readU8Method · 0.80
sliceMethod · 0.65
closeMethod · 0.65
depthMethod · 0.45
processMethod · 0.45
writeBufferMethod · 0.45

Tested by

no test coverage detected