From cefaaf942fbe1ddd92286981447b613c1fa4793f Mon Sep 17 00:00:00 2001 From: Andrey Sidorov Date: Fri, 4 Apr 2014 14:23:51 +1100 Subject: [PATCH] fix in changefont glyphele serialization --- lib/ext/render.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/ext/render.js b/lib/ext/render.js index 10bb012..e99629d 100644 --- a/lib/ext/render.js +++ b/lib/ext/render.js @@ -372,11 +372,24 @@ exports.requireExt = function(display, callback) var imageBytes = 0; var glyphPaddedLength; var glyphLength; + var stride; + var glyph; for (var i = 0; i < numGlyphs; i++) { + glyph = glyphs[i]; + if (glyph.width % 4 !== 0) { + var stride = (glyph.width+3)&~3; + var res = new Buffer(glyph.height*stride); + res.fill(0); + for (var y=0; y < glyph.height; ++y) { + glyph.image.copy(res, y*stride, y*glyph.width, y*glyph.width + glyph.width); + } + glyph.image = res; + glyph.width = stride; + } glyphLength = glyphs[i].image.length; - if (glyphLength % 4 !== 0) - throw new Error('Glyph image length must be divisible by 4!'); imageBytes += glyphLength; + glyph.offX = glyph.offX / 64; + glyph.offY = glyph.offY / 64; } var len = numGlyphs * 4 + imageBytes/4 + 3; // TODO: check length, use bigReq @@ -447,6 +460,7 @@ exports.requireExt = function(display, callback) var charLength = glyphBits / 8; X.seq_num++; var length = 7; + var glyphs_length_split = []; for (var i=0; i < glyphs.length; ++i) { var g = glyphs[i]; switch (typeof g) { @@ -457,7 +471,7 @@ exports.requireExt = function(display, callback) length += xutil.padded_length(g[2].length*charLength)/4 + 2; break; case 'number': // glyphset id - length += 2; + length += 3; break; } } @@ -475,7 +489,7 @@ exports.requireExt = function(display, callback) X.pack_stream.pack('Cxxxssa', [g[2].length, g[0], g[1], wstring(glyphBits, g[2])]); break; case 'number': // glyphset id - X.pack_stream.pack('CxxxL', [0xff, g]); + X.pack_stream.pack('CxxxSSL', [0xff, 0, 0, g]); break; } }