mirror of
https://github.com/danbulant/node-x11
synced 2026-05-21 21:39:13 +00:00
use solid pixap, resize glyphs to have width multiples of 4
This commit is contained in:
parent
8cfac532ec
commit
9731bc454e
1 changed files with 43 additions and 7 deletions
|
|
@ -3,6 +3,19 @@ var PointerMotion = x11.eventMask.PointerMotion;
|
|||
|
||||
function padWidth(buf, width) {
|
||||
var height = buf.length / width;
|
||||
if (width %4 === 0)
|
||||
return buf;
|
||||
else {
|
||||
var stride = (width+3)&~3;
|
||||
console.log('Resize: (' + width + 'x' + height + ') to ' + stride);
|
||||
var res = new Buffer(height*stride);
|
||||
res.fill(0);
|
||||
for (var y=0; y < height; ++y) {
|
||||
// memcpy(tmpbitmap+y*stride, bitmap->buffer+y*ginfo.width, ginfo.width);
|
||||
buf.copy(res, y*stride, y*width, y*width + width);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
var xclient = x11.createClient({ debug: true }, function(err, display) {
|
||||
|
|
@ -12,7 +25,7 @@ var xclient = x11.createClient({ debug: true }, function(err, display) {
|
|||
var wid = X.AllocID();
|
||||
var white = display.screen[0].white_pixel;
|
||||
varblack = display.screen[0].black_pixel;
|
||||
X.CreateWindow(wid, root, 10, 10, 400, 300, 0, 0, 0, 0, { backgroundPixel: white, eventMask: PointerMotion });
|
||||
X.CreateWindow(wid, root, 10, 10, 400, 300, 0, 0, 0, 0, { backgroundPixel: white, eventMask: x11.eventMask.Exposure });
|
||||
X.MapWindow(wid);
|
||||
|
||||
var glyphSet = X.AllocID();
|
||||
|
|
@ -21,6 +34,13 @@ var xclient = x11.createClient({ debug: true }, function(err, display) {
|
|||
var pict = X.AllocID();
|
||||
Render.CreatePicture(pict, wid, Render.rgb24);
|
||||
|
||||
var pix = X.AllocID();
|
||||
X.CreatePixmap(pix, root, 32, 1, 1);
|
||||
var pictSolidPix = X.AllocID();
|
||||
Render.CreatePicture(pictSolidPix, pix, Render.rgba32, {repeat: 1});
|
||||
Render.FillRectangles(1, pictSolidPix, [0x0, 0x0, 0x0, 0xffff], [0, 0, 100, 100]);
|
||||
//X.FreePixmap(pix);
|
||||
|
||||
var pictGrad = X.AllocID();
|
||||
Render.RadialGradient(pictGrad, [260,260], [260,260], 0, 260,
|
||||
[
|
||||
|
|
@ -32,20 +52,36 @@ var xclient = x11.createClient({ debug: true }, function(err, display) {
|
|||
]);
|
||||
|
||||
|
||||
var glyphs = require('./ob-font-50pt100dpi.json');
|
||||
|
||||
//Render.AddGlyphs(glyphSet, glyphs.slice(0, 128));
|
||||
var glyphs = require('./ob-font-50pt100dpi.json');
|
||||
debugger;
|
||||
|
||||
glyphs.forEach(function(g) {
|
||||
if (!g.image || g.image.length == 0)
|
||||
if (!g.image || (g.image.length == 0))
|
||||
g.image = new Buffer(0);
|
||||
else
|
||||
else {
|
||||
g.image = new Buffer(g.image, 'base64');
|
||||
//g.image = padWidth(g.image, w.width);
|
||||
g.image = padWidth(g.image, g.width);
|
||||
g.width = g.image.length / g.height;
|
||||
if (isNaN(g.width))
|
||||
debugger
|
||||
}
|
||||
});
|
||||
Render.AddGlyphs(glyphSet, [glyphs[10],glyphs[24]]);
|
||||
//Render.AddGlyphs(glyphSet, [glyphs[10],glyphs[24]]);
|
||||
Render.AddGlyphs(glyphSet, glyphs.slice(0, 128));
|
||||
//Render.AddGlyphs(glyphSet, glyphs);
|
||||
//for(var i=0; i < 120; ++i)
|
||||
// Render.AddGlyphs(glyphSet, [glyphs[i]]);
|
||||
|
||||
function draw(x, y) {
|
||||
Render.FillRectangles(1, pict, [0xffff, 0xffff, 0xffff, 0xffff], [0, 0, 1000, 1000]);
|
||||
// op, src, dst, maskFormat, gsid, srcX, srcY, dstX, dstY, glyphs
|
||||
Render.CompositeGlyphs8(3, pictGrad, pict, 0, glyphSet, 100, 100, ['----', '=']);
|
||||
|
||||
Render.CompositeGlyphs8(3, pictSolidPix, pict, 0, glyphSet, 0, 0, [[10, 60,'12345678 Hello! '], [100, 100, 'World *&@#$%']]);
|
||||
|
||||
//Render.CompositeGlyphs8(3, pictGrad, pict, 0, glyphSet, 0, 0, [[10, 60,'12345678 Hello! ', 'World']]);
|
||||
//Render.CompositeGlyphs8(3, pictSolidPix, pict, 0, glyphSet, 100, 100, [[50, 50,'----'], [10, 10, '=-=-']]);
|
||||
//Render.Composite(3, pictGrad, 0, pict, 0, 0, 0, 0, x-260, y-260, 520, 520);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue