From a930aa4d13448504214e94ee042c2f86badb0888 Mon Sep 17 00:00:00 2001 From: Andrey Sidorov Date: Mon, 31 Mar 2014 11:22:05 +1100 Subject: [PATCH] gradient example --- examples/simple/render-glyph.js | 54 ++++++++++++++------------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/examples/simple/render-glyph.js b/examples/simple/render-glyph.js index 316760e..a0d1886 100644 --- a/examples/simple/render-glyph.js +++ b/examples/simple/render-glyph.js @@ -1,5 +1,6 @@ var x11 = require('../../lib'); var PointerMotion = x11.eventMask.PointerMotion; +var Exposure = x11.eventMask.Exposure; function padWidth(buf, width) { var height = buf.length / width; @@ -7,7 +8,6 @@ function padWidth(buf, width) { 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) { @@ -15,7 +15,7 @@ function padWidth(buf, width) { buf.copy(res, y*stride, y*width, y*width + width); } return res; - } + } } var xclient = x11.createClient({ debug: true }, function(err, display) { @@ -25,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: x11.eventMask.Exposure }); + X.CreateWindow(wid, root, 10, 10, 400, 300, 0, 0, 0, 0, { backgroundPixel: white, eventMask: Exposure|PointerMotion }); X.MapWindow(wid); var glyphSet = X.AllocID(); @@ -44,45 +44,37 @@ var xclient = x11.createClient({ debug: true }, function(err, display) { var pictGrad = X.AllocID(); Render.RadialGradient(pictGrad, [260,260], [260,260], 0, 260, [ - [0, [0,0,0,0x0fff ] ], - //[0.3, [0,0,0,0x0fff ] ], - //[0.997, [0xffff, 0xf, 0, 0x1] ], - //[1, [0xffff, 0xffff, 0, 0x0] ], - [1, [0,0,0,0x0fff ] ], - ]); - - - - //Render.AddGlyphs(glyphSet, glyphs.slice(0, 128)); - var glyphs = require('./ob-font-50pt100dpi.json'); - debugger; + [0, [0x0000, 0x0, 0, 0xffff ] ], + [0.3, [0xffff, 0x0, 0, 0xffff ] ], + [0.997, [0xffff, 0xf, 0, 0x1] ], + [1, [0x0000, 0x0, 0, 0x0fff ] ], + ] + ); + // TODO integrate freetype2 module here + var glyphs = require('./ob-font-50pt100dpi.json'); glyphs.forEach(function(g) { if (!g.image || (g.image.length == 0)) - g.image = new Buffer(0); + g.image = new Buffer(0); else { - g.image = new Buffer(g.image, 'base64'); - g.image = padWidth(g.image, g.width); - g.width = g.image.length / g.height; - if (isNaN(g.width)) - debugger - } + g.image = new Buffer(g.image, 'base64'); + g.image = padWidth(g.image, g.width); + g.width = g.image.length / g.height; + } }); - //Render.AddGlyphs(glyphSet, [glyphs[10],glyphs[24]]); + Render.AddGlyphs(glyphSet, glyphs.slice(0, 128)); + // TODO: check BigReq with big glyphset data //Render.AddGlyphs(glyphSet, glyphs); - //for(var i=0; i < 120; ++i) - // Render.AddGlyphs(glyphSet, [glyphs[i]]); + //for(var i=0; i < 120; ++i) + // Render.AddGlyphs(glyphSet, [glyphs[i]]); function draw(x, y) { + // TODO: example with multiple glyphsets in one CompositeGlyphs call 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, 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); + //Render.CompositeGlyphs8(3, pictSolidPix, pict, 0, glyphSet, 0, 0, [[10, 60,'12345678 Hello! '], [100, 100, 'World *&@#$%']]); + Render.CompositeGlyphs8(3, pictGrad, pict, 0, glyphSet, x, y, [[10, 60,'12345678 Hello! '], 'World']); } X.on('event', function(ev) {