mirror of
https://github.com/danbulant/node-x11
synced 2026-06-24 17:21:47 +00:00
Merge pull request #61 from sidorares/render-glyphs
WIP: Render extension text related functions
This commit is contained in:
commit
bcee037683
9 changed files with 447 additions and 105 deletions
|
|
@ -78,9 +78,14 @@ Core requests usage:
|
||||||
- C: XLib - http://www.sbin.org/doc/Xlib/ http://www.tronche.com/gui/x/xlib/ http://www.x.org/docs/X11/xlib.pdf
|
- C: XLib - http://www.sbin.org/doc/Xlib/ http://www.tronche.com/gui/x/xlib/ http://www.x.org/docs/X11/xlib.pdf
|
||||||
- C: XCB - http://xcb.freedesktop.org/
|
- C: XCB - http://xcb.freedesktop.org/
|
||||||
- Python: http://sourceforge.net/projects/python-xlib/ ( github fork: https://github.com/Ademan/python-xlib-branch pypi: http://pypi.python.org/pypi/Python%20Xlib )
|
- Python: http://sourceforge.net/projects/python-xlib/ ( github fork: https://github.com/Ademan/python-xlib-branch pypi: http://pypi.python.org/pypi/Python%20Xlib )
|
||||||
|
- https://github.com/alexer/python-xlib-render
|
||||||
- Python/twisted: https://launchpad.net/twisted-x11
|
- Python/twisted: https://launchpad.net/twisted-x11
|
||||||
- Perl: http://search.cpan.org/~smccam/X11-Protocol-0.56/Protocol.pm
|
- Perl: http://search.cpan.org/~smccam/X11-Protocol-0.56/Protocol.pm
|
||||||
|
- Go: https://github.com/BurntSushi/xgb
|
||||||
|
- Java: https://github.com/xderoche/J11
|
||||||
|
- Ruby: https://github.com/dj2/x-ruby-bindings
|
||||||
|
- Clojure: https://github.com/noodlewiz/xcljb
|
||||||
|
- Guile: https://github.com/mwitmer/guile-xcb
|
||||||
|
|
||||||
[](https://bitdeli.com/free "Bitdeli Badge")
|
[](https://bitdeli.com/free "Bitdeli Badge")
|
||||||
|
|
||||||
|
|
|
||||||
14
examples/simple/text/package.json
Normal file
14
examples/simple/text/package.json
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"name": "text",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"description": "ERROR: No README.md file found!",
|
||||||
|
"main": "render-glyph.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "BSD-2-Clause",
|
||||||
|
"dependencies": {
|
||||||
|
"freetype2_render": "~0.1.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
133
examples/simple/text/render-glyph.js
Normal file
133
examples/simple/text/render-glyph.js
Normal file
|
|
@ -0,0 +1,133 @@
|
||||||
|
var x11 = require('../../../lib');
|
||||||
|
var fs = require('fs');
|
||||||
|
var PointerMotion = x11.eventMask.PointerMotion;
|
||||||
|
var Exposure = x11.eventMask.Exposure;
|
||||||
|
|
||||||
|
|
||||||
|
var ft2 = require('freetype2_render');
|
||||||
|
var fontface= ft2.parse(fs.readFileSync(process.argv[2]))
|
||||||
|
//console.log(fontface.hasKerning(), process.argv[2], '\n', fontface);
|
||||||
|
//process.exit(0);
|
||||||
|
/*
|
||||||
|
fontface.available_characters.forEach(function(left) {
|
||||||
|
fontface.available_characters.forEach(function(right) {
|
||||||
|
var kern = fontface.kerning(left, right, 50, 0, 96, 0);
|
||||||
|
if (kern.x != 0 || kern.y != 0)
|
||||||
|
console.log(left, right, kern);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
console.log(fontface.kerning('A'.charCodeAt(0), 'V'.charCodeAt(0), 50, 0, 96, 0))
|
||||||
|
|
||||||
|
|
||||||
|
function padWidth(buf, width) {
|
||||||
|
var height = buf.length / width;
|
||||||
|
if (width %4 === 0)
|
||||||
|
return buf;
|
||||||
|
else {
|
||||||
|
var stride = (width+3)&~3;
|
||||||
|
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) {
|
||||||
|
var X = display.client;
|
||||||
|
var root = display.screen[0].root;
|
||||||
|
display.client.require('render', function(Render) {
|
||||||
|
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: Exposure|PointerMotion });
|
||||||
|
X.MapWindow(wid);
|
||||||
|
|
||||||
|
var glyphSet = X.AllocID();
|
||||||
|
Render.CreateGlyphSet(glyphSet, Render.a8);
|
||||||
|
|
||||||
|
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,
|
||||||
|
[
|
||||||
|
[0, [0x0000, 0x0, 0, 0xffff ] ],
|
||||||
|
[0.3, [0xffff, 0x0, 0, 0xffff ] ],
|
||||||
|
[0.997, [0xffff, 0xf, 0, 0x1] ],
|
||||||
|
[1, [0x0000, 0x0, 0, 0xffff ] ],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
var pictLinearGrad = X.AllocID();
|
||||||
|
Render.LinearGradient(pictLinearGrad, [0,0], [1000,100],
|
||||||
|
[
|
||||||
|
[0, [0,0,0,0xffff ] ],
|
||||||
|
// [0.1, [0xfff, 0, 0xffff, 0x1000] ] ,
|
||||||
|
// [0.25, [0xffff, 0, 0xfff, 0x3000] ] ,
|
||||||
|
// [0.5, [0xffff, 0, 0xffff, 0x4000] ] ,
|
||||||
|
[1, [0xffff, 0xffff, 0, 0xffff] ]
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var glyphs = fontface.available_characters.map(function(ch) { return fontface.render(ch, parseInt(process.argv[3]*64), 0, 96, 0); });
|
||||||
|
var glyphFromCode = [];
|
||||||
|
glyphs.forEach(function(g) {
|
||||||
|
if (!g.image || (g.image.length == 0)) {
|
||||||
|
g.image = new Buffer(64);
|
||||||
|
g.image.fill(0);
|
||||||
|
g.width = 8;
|
||||||
|
g.height = 8;
|
||||||
|
g.x = 0;
|
||||||
|
g.y = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
g.origWidth = g.width;
|
||||||
|
g.image = padWidth(g.image, g.width);
|
||||||
|
g.width = g.image.length / g.height;
|
||||||
|
}
|
||||||
|
g.offX = g.offX / 64;
|
||||||
|
g.offY = g.offY / 64;
|
||||||
|
glyphFromCode[g.id] = g;
|
||||||
|
|
||||||
|
if (g.id == 'A'.charCodeAt(0))
|
||||||
|
g.offX -= 17;
|
||||||
|
});
|
||||||
|
|
||||||
|
//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]]);
|
||||||
|
|
||||||
|
function draw(x, y) {
|
||||||
|
if (!y)
|
||||||
|
y = 0;
|
||||||
|
if (!x)
|
||||||
|
x = 0;
|
||||||
|
// TODO: example with multiple glyphsets in one CompositeGlyphs call
|
||||||
|
Render.FillRectangles(1, pict, [0xffff, 0xffff, 0xffff, 0xffff], [0, 0, 3000, 3000]);
|
||||||
|
//Render.Composite(3, pictLinearGrad, 0, pict, 0, 0, 0, 0, 0, 0, 2500, 2500);
|
||||||
|
// op, src, dst, maskFormat, gsid, srcX, srcY, dstX, dstY, glyphs
|
||||||
|
//Render.CompositeGlyphs8(3, pictSolidPix, pict, 0, glyphSet, 0, 0, [[10, 60, process.argv[4]]]);
|
||||||
|
var yoff = 2*parseInt(process.argv[3]);
|
||||||
|
Render.CompositeGlyphs8(3, pictSolidPix, pict, 0, glyphSet, 260-x, yoff+260-y, [[20, 50, process.argv[4]]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
X.on('event', function(ev) {
|
||||||
|
draw(ev.x, ev.y);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
var Buffer = require('buffer').Buffer;
|
var Buffer = require('buffer').Buffer;
|
||||||
var x11 = require('../../lib');
|
var x11 = require('../../lib');
|
||||||
|
|
||||||
var xclient = x11.createClient();
|
|
||||||
var Exposure = x11.eventMask.Exposure;
|
var Exposure = x11.eventMask.Exposure;
|
||||||
var PointerMotion = x11.eventMask.PointerMotion;
|
var PointerMotion = x11.eventMask.PointerMotion;
|
||||||
|
|
||||||
|
|
@ -20,13 +19,10 @@ for (var i=0; i < bitmap.length; ++i)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
xclient.on('connect', function(err, display) {
|
x11.createClient(function(err, display) {
|
||||||
|
if (err) throw err;
|
||||||
|
|
||||||
var X = display.client;
|
var X = display.client;
|
||||||
X.require('big-requests', function(BigReq) {
|
|
||||||
|
|
||||||
BigReq.Enable(function(maxLen) { console.log( maxLen ); });
|
|
||||||
|
|
||||||
X.require('render', function(Render) {
|
X.require('render', function(Render) {
|
||||||
|
|
||||||
var root = display.screen[0].root;
|
var root = display.screen[0].root;
|
||||||
|
|
@ -72,5 +68,4 @@ X.require('render', function(Render) {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
// full list of event/error/request codes for all extensions:
|
||||||
|
// http://www.opensource.apple.com/source/X11server/X11server-106.7/kdrive/xorg-server-1.6.5-apple3/dix/protocol.txt
|
||||||
|
|
||||||
var xutil = require('./xutil');
|
var xutil = require('./xutil');
|
||||||
var hexy = require('./hexy').hexy;
|
var hexy = require('./hexy').hexy;
|
||||||
|
|
||||||
|
|
@ -642,7 +645,12 @@ var templates = {
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
// opcode 55
|
FreePixmap: [
|
||||||
|
function(pixmap) {
|
||||||
|
return [ 'CxSL', [ 54, 2, pixmap ] ];
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
CreateGC: [
|
CreateGC: [
|
||||||
function(cid, drawable, values) {
|
function(cid, drawable, values) {
|
||||||
var format = 'CxSLLL';
|
var format = 'CxSLLL';
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,9 @@
|
||||||
|
|
||||||
http://www.opengl.org/wiki/Tutorial:_OpenGL_3.0_Context_Creation_(GLX)
|
http://www.opengl.org/wiki/Tutorial:_OpenGL_3.0_Context_Creation_(GLX)
|
||||||
|
|
||||||
|
https://github.com/xderoche/J11/blob/master/src/gnu/x11/extension/glx/GL.java
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
var x11 = require('..');
|
var x11 = require('..');
|
||||||
// TODO: move to templates
|
// TODO: move to templates
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
// this will be eventually moved to lib/node-x11/extensions
|
|
||||||
|
|
||||||
var x11 = require('..');
|
var x11 = require('..');
|
||||||
|
var xutil = require('../xutil');
|
||||||
|
|
||||||
// adding XRender functions manually from
|
// adding XRender functions manually from
|
||||||
// http://cgit.freedesktop.org/xcb/proto/tree/src/render.xml?id=HEAD
|
// http://cgit.freedesktop.org/xcb/proto/tree/src/render.xml?id=HEAD
|
||||||
|
|
@ -9,14 +8,6 @@ var x11 = require('..');
|
||||||
exports.requireExt = function(display, callback)
|
exports.requireExt = function(display, callback)
|
||||||
{
|
{
|
||||||
|
|
||||||
function captureStack()
|
|
||||||
{
|
|
||||||
var err = new Error;
|
|
||||||
//err.name = reqName;
|
|
||||||
Error.captureStackTrace(err, arguments.callee);
|
|
||||||
display.client.seq2stack[display.client.seq_num] = err.stack;
|
|
||||||
}
|
|
||||||
|
|
||||||
var X = display.client;
|
var X = display.client;
|
||||||
X.QueryExtension('RENDER', function(err, ext) {
|
X.QueryExtension('RENDER', function(err, ext) {
|
||||||
|
|
||||||
|
|
@ -28,7 +19,6 @@ exports.requireExt = function(display, callback)
|
||||||
ext.QueryVersion = function(clientMaj, clientMin, callback)
|
ext.QueryVersion = function(clientMaj, clientMin, callback)
|
||||||
{
|
{
|
||||||
X.seq_num++;
|
X.seq_num++;
|
||||||
captureStack();
|
|
||||||
X.pack_stream.pack('CCSLL', [ext.majorOpcode, 0, 3, clientMaj, clientMin]);
|
X.pack_stream.pack('CCSLL', [ext.majorOpcode, 0, 3, clientMaj, clientMin]);
|
||||||
X.replies[X.seq_num] = [
|
X.replies[X.seq_num] = [
|
||||||
function(buf, opt) {
|
function(buf, opt) {
|
||||||
|
|
@ -43,7 +33,6 @@ exports.requireExt = function(display, callback)
|
||||||
ext.QueryPictFormat = function(callback)
|
ext.QueryPictFormat = function(callback)
|
||||||
{
|
{
|
||||||
X.seq_num++;
|
X.seq_num++;
|
||||||
captureStack();
|
|
||||||
X.pack_stream.pack('CCS', [ext.majorOpcode, 1, 1]);
|
X.pack_stream.pack('CCS', [ext.majorOpcode, 1, 1]);
|
||||||
X.replies[X.seq_num] = [
|
X.replies[X.seq_num] = [
|
||||||
function (buf, opt) {
|
function (buf, opt) {
|
||||||
|
|
@ -74,7 +63,6 @@ exports.requireExt = function(display, callback)
|
||||||
ext.QueryFilters = function(callback)
|
ext.QueryFilters = function(callback)
|
||||||
{
|
{
|
||||||
X.seq_num++;
|
X.seq_num++;
|
||||||
captureStack();
|
|
||||||
X.pack_stream.pack('CCSL', [ext.majorOpcode, 29, 2, display.screen[0].root]);
|
X.pack_stream.pack('CCSL', [ext.majorOpcode, 29, 2, display.screen[0].root]);
|
||||||
X.replies[X.seq_num] = [
|
X.replies[X.seq_num] = [
|
||||||
function(buf, opt) {
|
function(buf, opt) {
|
||||||
|
|
@ -130,9 +118,7 @@ exports.requireExt = function(display, callback)
|
||||||
|
|
||||||
ext.CreatePicture = function(pid, drawable, pictformat, values)
|
ext.CreatePicture = function(pid, drawable, pictformat, values)
|
||||||
{
|
{
|
||||||
console.log([pid, drawable, pictformat, values]);
|
|
||||||
X.seq_num++;
|
X.seq_num++;
|
||||||
captureStack();
|
|
||||||
var mask = 0;
|
var mask = 0;
|
||||||
var reqLen = 5; // + (values + pad)/4
|
var reqLen = 5; // + (values + pad)/4
|
||||||
var format = 'CCSLLLL';
|
var format = 'CCSLLLL';
|
||||||
|
|
@ -145,7 +131,6 @@ exports.requireExt = function(display, callback)
|
||||||
{
|
{
|
||||||
var name = valueList[i][0];
|
var name = valueList[i][0];
|
||||||
var val = values[name];
|
var val = values[name];
|
||||||
console.log([name, val]);
|
|
||||||
if (val) {
|
if (val) {
|
||||||
mask |= (1 << i);
|
mask |= (1 << i);
|
||||||
params.push(val);
|
params.push(val);
|
||||||
|
|
@ -162,7 +147,6 @@ exports.requireExt = function(display, callback)
|
||||||
params[2] = reqLen;
|
params[2] = reqLen;
|
||||||
params[6] = mask;
|
params[6] = mask;
|
||||||
}
|
}
|
||||||
console.log(['CreatePicture', format, params]);
|
|
||||||
X.pack_stream.pack(format, params);
|
X.pack_stream.pack(format, params);
|
||||||
X.pack_stream.flush();
|
X.pack_stream.flush();
|
||||||
}
|
}
|
||||||
|
|
@ -177,7 +161,6 @@ exports.requireExt = function(display, callback)
|
||||||
ext.SetPictureFilter = function(pid, name, filterParams)
|
ext.SetPictureFilter = function(pid, name, filterParams)
|
||||||
{
|
{
|
||||||
X.seq_num++;
|
X.seq_num++;
|
||||||
captureStack();
|
|
||||||
var reqLen = 2; //header + params + 1xStopfix+2xColors
|
var reqLen = 2; //header + params + 1xStopfix+2xColors
|
||||||
var format = 'CCSLa';
|
var format = 'CCSLa';
|
||||||
var params = [ext.majorOpcode, 30, reqLen, pid];
|
var params = [ext.majorOpcode, 30, reqLen, pid];
|
||||||
|
|
@ -192,16 +175,21 @@ exports.requireExt = function(display, callback)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
params[2] = reqLen;
|
params[2] = reqLen;
|
||||||
//console.log([format, params]);
|
|
||||||
X.pack_stream.pack(format, params);
|
X.pack_stream.pack(format, params);
|
||||||
X.pack_stream.flush();
|
X.pack_stream.flush();
|
||||||
}
|
};
|
||||||
|
|
||||||
|
ext.CreateSolidFill = function(pid, r, g, b, a)
|
||||||
|
{
|
||||||
|
X.seq_num++;
|
||||||
|
X.pack_stream.pack('CCSLSSSS', [ext.majorOpcode, 33, 4, pid, floatToFix(r), floatToFix(g), floatToFix(b), floatToFix(a)]);
|
||||||
|
X.pack_stream.flush();
|
||||||
|
};
|
||||||
|
|
||||||
ext.RadialGradient = function(pid, p1, p2, r1, r2, stops)
|
ext.RadialGradient = function(pid, p1, p2, r1, r2, stops)
|
||||||
{
|
{
|
||||||
// TODO: merge with linear gradient
|
// TODO: merge with linear gradient
|
||||||
X.seq_num++;
|
X.seq_num++;
|
||||||
captureStack();
|
|
||||||
var reqLen = 9+stops.length*3; //header + params + 1xStopfix+2xColors
|
var reqLen = 9+stops.length*3; //header + params + 1xStopfix+2xColors
|
||||||
var format = 'CCSLLLLLLLL';
|
var format = 'CCSLLLLLLLL';
|
||||||
var params = [ext.majorOpcode, 35, reqLen, pid];
|
var params = [ext.majorOpcode, 35, reqLen, pid];
|
||||||
|
|
@ -228,15 +216,13 @@ exports.requireExt = function(display, callback)
|
||||||
for (var j=0; j < 4; ++j)
|
for (var j=0; j < 4; ++j)
|
||||||
params.push(stops[i][1][j]);
|
params.push(stops[i][1][j]);
|
||||||
}
|
}
|
||||||
//console.log([format, params]);
|
|
||||||
X.pack_stream.pack(format, params);
|
X.pack_stream.pack(format, params);
|
||||||
X.pack_stream.flush();
|
X.pack_stream.flush();
|
||||||
}
|
};
|
||||||
|
|
||||||
ext.LinearGradient = function(pid, p1, p2, stops)
|
ext.LinearGradient = function(pid, p1, p2, stops)
|
||||||
{
|
{
|
||||||
X.seq_num++;
|
X.seq_num++;
|
||||||
captureStack();
|
|
||||||
var reqLen = 7+stops.length*3; //header + params + 1xStopfix+2xColors
|
var reqLen = 7+stops.length*3; //header + params + 1xStopfix+2xColors
|
||||||
var format = 'CCSLLLLLL';
|
var format = 'CCSLLLLLL';
|
||||||
var params = [ext.majorOpcode, 34, reqLen, pid];
|
var params = [ext.majorOpcode, 34, reqLen, pid];
|
||||||
|
|
@ -262,7 +248,6 @@ exports.requireExt = function(display, callback)
|
||||||
for (var j=0; j < 4; ++j)
|
for (var j=0; j < 4; ++j)
|
||||||
params.push(stops[i][1][j]);
|
params.push(stops[i][1][j]);
|
||||||
}
|
}
|
||||||
//console.log([format, params]);
|
|
||||||
X.pack_stream.pack(format, params);
|
X.pack_stream.pack(format, params);
|
||||||
X.pack_stream.flush();
|
X.pack_stream.flush();
|
||||||
}
|
}
|
||||||
|
|
@ -270,7 +255,6 @@ exports.requireExt = function(display, callback)
|
||||||
ext.ConicalGradient = function(pid, center, angle, stops)
|
ext.ConicalGradient = function(pid, center, angle, stops)
|
||||||
{
|
{
|
||||||
X.seq_num++;
|
X.seq_num++;
|
||||||
captureStack();
|
|
||||||
var reqLen = 6+stops.length*3; //header + params + 1xStopfix+2xColors
|
var reqLen = 6+stops.length*3; //header + params + 1xStopfix+2xColors
|
||||||
var format = 'CCSLLLLL';
|
var format = 'CCSLLLLL';
|
||||||
var params = [ext.majorOpcode, 36, reqLen, pid];
|
var params = [ext.majorOpcode, 36, reqLen, pid];
|
||||||
|
|
@ -295,7 +279,6 @@ exports.requireExt = function(display, callback)
|
||||||
for (var j=0; j < 4; ++j)
|
for (var j=0; j < 4; ++j)
|
||||||
params.push(stops[i][1][j]);
|
params.push(stops[i][1][j]);
|
||||||
}
|
}
|
||||||
//console.log([format, params]);
|
|
||||||
X.pack_stream.pack(format, params);
|
X.pack_stream.pack(format, params);
|
||||||
X.pack_stream.flush();
|
X.pack_stream.flush();
|
||||||
}
|
}
|
||||||
|
|
@ -303,7 +286,6 @@ exports.requireExt = function(display, callback)
|
||||||
ext.FillRectangles = function(op, pid, color, rects)
|
ext.FillRectangles = function(op, pid, color, rects)
|
||||||
{
|
{
|
||||||
X.seq_num++;
|
X.seq_num++;
|
||||||
captureStack();
|
|
||||||
var reqLen = 5+rects.length/2;
|
var reqLen = 5+rects.length/2;
|
||||||
var format = 'CCSCxxxLSSSS';
|
var format = 'CCSCxxxLSSSS';
|
||||||
var params = [ext.majorOpcode, 26, reqLen, op, pid];
|
var params = [ext.majorOpcode, 26, reqLen, op, pid];
|
||||||
|
|
@ -324,7 +306,6 @@ exports.requireExt = function(display, callback)
|
||||||
ext.Composite = function(op, src, mask, dst, srcX, srcY, maskX, maskY, dstX, dstY, width, height)
|
ext.Composite = function(op, src, mask, dst, srcX, srcY, maskX, maskY, dstX, dstY, width, height)
|
||||||
{
|
{
|
||||||
X.seq_num++;
|
X.seq_num++;
|
||||||
captureStack();
|
|
||||||
X.pack_stream.pack(
|
X.pack_stream.pack(
|
||||||
'CCSCxxxLLLssssssSS',
|
'CCSCxxxLLLssssssSS',
|
||||||
[ext.majorOpcode, 8, 9, op, src, mask, dst, srcX, srcY, maskX, maskY, dstX, dstY, width, height]
|
[ext.majorOpcode, 8, 9, op, src, mask, dst, srcX, srcY, maskX, maskY, dstX, dstY, width, height]
|
||||||
|
|
@ -335,7 +316,6 @@ exports.requireExt = function(display, callback)
|
||||||
ext.Trapezoids = function(op, src, srcX, srcY, dst, maskFormat, trapz)
|
ext.Trapezoids = function(op, src, srcX, srcY, dst, maskFormat, trapz)
|
||||||
{
|
{
|
||||||
X.seq_num++;
|
X.seq_num++;
|
||||||
captureStack();
|
|
||||||
var format = 'CCSCxxxLLLss';
|
var format = 'CCSCxxxLLLss';
|
||||||
var params = [ext.majorOpcode, 10, 6+trapz.length, op, src, dst, maskFormat, srcX, srcY];
|
var params = [ext.majorOpcode, 10, 6+trapz.length, op, src, dst, maskFormat, srcX, srcY];
|
||||||
for (var i=0; i < trapz.length; i+=10)
|
for (var i=0; i < trapz.length; i+=10)
|
||||||
|
|
@ -344,15 +324,13 @@ exports.requireExt = function(display, callback)
|
||||||
for (var j=0; j < 10; ++j)
|
for (var j=0; j < 10; ++j)
|
||||||
params.push(floatToFix(trapz[i*10 + j]));
|
params.push(floatToFix(trapz[i*10 + j]));
|
||||||
}
|
}
|
||||||
//console.log([format, params]);
|
|
||||||
X.pack_stream.pack(format, params);
|
X.pack_stream.pack(format, params);
|
||||||
X.pack_stream.flush();
|
X.pack_stream.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
ext.Triangles = function(op, src, srcX, srcY, dst, maskFormat, tris)
|
ext.Triangles = function(op, src, srcX, srcY, dst, maskFormat, tris)
|
||||||
{
|
{
|
||||||
X.seq_num++;
|
X.seq_num++;
|
||||||
captureStack();
|
|
||||||
var format = 'CCSCxxxLLLss';
|
var format = 'CCSCxxxLLLss';
|
||||||
var params = [ext.majorOpcode, 11, 6+tris.length, op, src, dst, maskFormat, srcX, srcY];
|
var params = [ext.majorOpcode, 11, 6+tris.length, op, src, dst, maskFormat, srcX, srcY];
|
||||||
for (var i=0; i < tris.length; i+=6)
|
for (var i=0; i < tris.length; i+=6)
|
||||||
|
|
@ -370,8 +348,188 @@ exports.requireExt = function(display, callback)
|
||||||
X.pack_stream.flush();
|
X.pack_stream.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ext.CreateGlyphSet = function(gsid, format) {
|
||||||
|
X.seq_num++;
|
||||||
|
X.pack_stream.pack('CCSLL', [ext.majorOpcode, 17, 3, gsid, format]);
|
||||||
|
X.pack_stream.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
ext.ReferenceGlyphSet = function(gsid, existing) {
|
||||||
|
X.seq_num++;
|
||||||
|
X.pack_stream.pack('CCSLL', [ext.majorOpcode, 18, 3, gsid, existing]);
|
||||||
|
X.pack_stream.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
ext.FreeGlyphSet = function(gsid) {
|
||||||
|
X.seq_num++;
|
||||||
|
X.pack_stream.pack('CCSL', [ext.majorOpcode, 19, 2, gsid]);
|
||||||
|
X.pack_stream.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
ext.AddGlyphs = function(gsid, glyphs) {
|
||||||
|
X.seq_num++;
|
||||||
|
var numGlyphs = glyphs.length;
|
||||||
|
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;
|
||||||
|
imageBytes += glyphLength;
|
||||||
|
glyph.offX = glyph.offX / 64;
|
||||||
|
glyph.offY = glyph.offY / 64;
|
||||||
|
}
|
||||||
|
var len = numGlyphs * 4 + imageBytes/4 + 3;
|
||||||
|
// TODO: check length, use bigReq
|
||||||
|
// X.pack_stream.pack('CCSLL', [ext.majorOpcode, 20, len, gsid, glyphs.length]);
|
||||||
|
|
||||||
|
// BigReq: S + [ length ] replaced with SL + [ 0, length+1 ]
|
||||||
|
X.pack_stream.pack('CCSLLL', [ext.majorOpcode, 20, 0, len+1, gsid, glyphs.length]);
|
||||||
|
|
||||||
|
// glyph ids
|
||||||
|
for (i = 0; i < numGlyphs; i++) {
|
||||||
|
X.pack_stream.pack('L', [glyphs[i].id]);
|
||||||
|
}
|
||||||
|
// width + heiht + origin xy + advance xy
|
||||||
|
for (i = 0; i < numGlyphs; i++) {
|
||||||
|
X.pack_stream.pack('SSssss', [glyphs[i].width, glyphs[i].height, -glyphs[i].x, glyphs[i].y, glyphs[i].offX, glyphs[i].offY]);
|
||||||
|
}
|
||||||
|
// image
|
||||||
|
for (i = 0; i < numGlyphs; i++) {
|
||||||
|
X.pack_stream.write_queue.push(glyphs[i].image);
|
||||||
|
}
|
||||||
|
X.pack_stream.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
//AddGlyphsFromPicture, opcode=21 (not in spec)
|
||||||
|
// FreeGlyps - opcode 22
|
||||||
|
// gsid(L) , glyphs.length (L) + each glyph id (L)
|
||||||
|
//
|
||||||
|
|
||||||
|
// each GlyphEle:
|
||||||
|
// 1 byte - number of glyphs
|
||||||
|
// xxx
|
||||||
|
// int16 deltax, deltay
|
||||||
|
// + list of 8/16/32 byte indexesext.CompositeGlyphs
|
||||||
|
// OR
|
||||||
|
// 255 + 0 + 0 + glyphsetId / font:
|
||||||
|
// CxxxssL, [255, 0, 0, glyphable]
|
||||||
|
//
|
||||||
|
// Each GlyphEle must be padded to 4 byte boundary
|
||||||
|
//
|
||||||
|
// glyphs as input:
|
||||||
|
// [ "just string (0,0) offset is used", [ 10, 10, "string offseted 10,10 from previous pen position" ], 1234567 ] 1234567 is glypfset id or FONT
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: pre-process input so strings larger than 254 chars are supported
|
||||||
|
// (split them into multiple entries with 0,0 offset)
|
||||||
|
|
||||||
|
var formatFromBits = [,,,,,,,,'C',,,,,,,,'S',,,,,,,,,,,,,,,,'L'];
|
||||||
|
var bufferWriteBits = [,,,,,,,,'writeUInt8',,,,,,,,'writeUInt16LE',,,,,,,,,,,,,,,,'writeUInt32LE'];
|
||||||
|
|
||||||
|
// 8/16/32 bit string + 4-byte pad
|
||||||
|
function wstring(bits, s) {
|
||||||
|
var charLength = bits / 8;
|
||||||
|
var dataLength = s.length*charLength;
|
||||||
|
var res = new Buffer(xutil.padded_length(dataLength));
|
||||||
|
debugger;
|
||||||
|
var write = res[bufferWriteBits[bits]]
|
||||||
|
res.fill(0);
|
||||||
|
for(var i=0; i < s.length; i++)
|
||||||
|
write.call(res, s.charCodeAt(i), i*charLength);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
var compositeGlyphsOpcodeFromBits = [,,,,,,,,23,,,,,,,,24,,,,,,,,,,,,,,,,25];
|
||||||
|
ext.CompositeGlyphs = function(glyphBits, op, src, dst, maskFormat, gsid, srcX, srcY, glyphs)
|
||||||
|
{
|
||||||
|
var opcode = compositeGlyphsOpcodeFromBits[glyphBits];
|
||||||
|
var charFormat = formatFromBits[glyphBits];
|
||||||
|
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) {
|
||||||
|
case 'string':
|
||||||
|
length += xutil.padded_length(g.length*charLength)/4 + 2;
|
||||||
|
break;
|
||||||
|
case 'object':
|
||||||
|
length += xutil.padded_length(g[2].length*charLength)/4 + 2;
|
||||||
|
break;
|
||||||
|
case 'number': // glyphset id
|
||||||
|
length += 3;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
X.pack_stream.pack(
|
||||||
|
'CCSCxxxLLLLss',
|
||||||
|
[ext.majorOpcode, opcode, length, op, src, dst, maskFormat, gsid, srcX, srcY]
|
||||||
|
);
|
||||||
|
for (var i=0; i < glyphs.length; ++i) {
|
||||||
|
var g = glyphs[i];
|
||||||
|
switch (typeof g) {
|
||||||
|
case 'string':
|
||||||
|
X.pack_stream.pack('Cxxxssa', [g.length, 0, 0, wstring(glyphBits, g)]);
|
||||||
|
break;
|
||||||
|
case 'object': // array
|
||||||
|
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('CxxxSSL', [0xff, 0, 0, g]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
X.pack_stream.flush();
|
||||||
|
};
|
||||||
|
|
||||||
|
ext.CompositeGlyphs8 = function(op, src, dst, maskFormat, gsid, srcX, srcY, glyphs)
|
||||||
|
{
|
||||||
|
return ext.CompositeGlyphs(8, op, src, dst, maskFormat, gsid, srcX, srcY, glyphs);
|
||||||
|
};
|
||||||
|
|
||||||
|
ext.CompositeGlyphs16 = function(op, src, dst, maskFormat, gsid, srcX, srcY, glyphs)
|
||||||
|
{
|
||||||
|
return ext.CompositeGlyphs(16, op, src, dst, maskFormat, gsid, srcX, srcY, glyphs);
|
||||||
|
};
|
||||||
|
|
||||||
|
ext.CompositeGlyphs32 = function(op, src, dst, maskFormat, gsid, srcX, srcY, glyphs)
|
||||||
|
{
|
||||||
|
return ext.CompositeGlyphs(32, op, src, dst, maskFormat, gsid, srcX, srcY, glyphs);
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO: implement xutil-like code https://github.com/alexer/python-xlib-render/blob/master/xutil.py
|
||||||
|
|
||||||
|
// TODO: name format fields
|
||||||
|
// 0 - id
|
||||||
|
// 1 - type ( direct / ? /)
|
||||||
|
// 2 - depth
|
||||||
|
//
|
||||||
|
// 3 - red shift
|
||||||
|
// 4 - red mask
|
||||||
|
// 5 - green shift
|
||||||
|
// 6 - green mask
|
||||||
|
// 7 - blue shift
|
||||||
|
// 8 - blue mask
|
||||||
|
// 9 - alpha shift
|
||||||
|
// 10 - alpha mask
|
||||||
|
|
||||||
|
// 11 - colormap or none
|
||||||
|
|
||||||
ext.QueryPictFormat(function(err, formats) {
|
ext.QueryPictFormat(function(err, formats) {
|
||||||
console.log(formats);
|
|
||||||
for (var i=0; i < formats.formats.length; ++i) {
|
for (var i=0; i < formats.formats.length; ++i) {
|
||||||
var f = formats.formats[i];
|
var f = formats.formats[i];
|
||||||
if (f[2] == 1 && f[10] == 1)
|
if (f[2] == 1 && f[10] == 1)
|
||||||
|
|
@ -381,8 +539,23 @@ exports.requireExt = function(display, callback)
|
||||||
// 1, 32, 16, 255, 8, 255, 0, 255, 24, 255, 0
|
// 1, 32, 16, 255, 8, 255, 0, 255, 24, 255, 0
|
||||||
if (f[2] == 32 && f[3] == 16 && f[4] == 255 && f[5] == 8 && f[6] == 255 && f[7] == 0 && f[9] == 24)
|
if (f[2] == 32 && f[3] == 16 && f[4] == 255 && f[5] == 8 && f[6] == 255 && f[7] == 0 && f[9] == 24)
|
||||||
ext.rgba32 = f[0] ;
|
ext.rgba32 = f[0] ;
|
||||||
|
if (f[2] == 8 && f[10] == 255)
|
||||||
|
ext.a8 = f[0];
|
||||||
}
|
}
|
||||||
callback(ext);
|
callback(ext);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
[
|
||||||
|
"PICTFORMAT argument does not name a defined PICTFORMAT",
|
||||||
|
"PICTURE argument does not name a defined PICTURE",
|
||||||
|
"PICTOP argument does not name a defined PICTOP",
|
||||||
|
"GLYPHSET argument does not name a defined GLYPHSET",
|
||||||
|
"GLYPH argument does not name a defined GLYPH in the glyphset"
|
||||||
|
].forEach(function(desc, code) {
|
||||||
|
X.errorParsers[ext.firstError + code] = function(err) {
|
||||||
|
err.message = "XRender: a value for a " + desc;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -245,13 +245,23 @@ UnpackStream.prototype.pack = function(format, args)
|
||||||
var n = args[arg++];
|
var n = args[arg++];
|
||||||
buf[offset++] = n;
|
buf[offset++] = n;
|
||||||
break;
|
break;
|
||||||
case 's': // TODO: implement signed INT16!!!
|
case 's':
|
||||||
|
var n = args[arg++];
|
||||||
|
buf.writeInt16LE(n, offset);
|
||||||
|
offset += 2;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'S':
|
case 'S':
|
||||||
var n = args[arg++];
|
var n = args[arg++];
|
||||||
buf[offset++] = n & 0xff;
|
buf[offset++] = n & 0xff;
|
||||||
buf[offset++] = (n >> 8) & 0xff;
|
buf[offset++] = (n >> 8) & 0xff;
|
||||||
break;
|
break;
|
||||||
case 'l': // TODO: implement signed INT32!!!
|
case 'l':
|
||||||
|
var n = args[arg++];
|
||||||
|
buf.writeInt32LE(n, offset);
|
||||||
|
offset += 4;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'L':
|
case 'L':
|
||||||
var n = args[arg++];
|
var n = args[arg++];
|
||||||
buf[offset++] = n & 0xff;
|
buf[offset++] = n & 0xff;
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,8 @@ describe('Client', function() {
|
||||||
|
|
||||||
it('should emit error which is instance of Error with sequence number corresponding to source request', function(done) {
|
it('should emit error which is instance of Error with sequence number corresponding to source request', function(done) {
|
||||||
var times = 0;
|
var times = 0;
|
||||||
display.client.CreateWindow(); // should emit error
|
//id, parentId, x, y, width, height, borderWidth, depth, _class, visual, values
|
||||||
|
display.client.CreateWindow(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {});
|
||||||
var seq = display.client.seq_num;
|
var seq = display.client.seq_num;
|
||||||
display.client.on('error', function(err) {
|
display.client.on('error', function(err) {
|
||||||
switch (++ times) {
|
switch (++ times) {
|
||||||
|
|
@ -26,7 +27,7 @@ describe('Client', function() {
|
||||||
default:
|
default:
|
||||||
assert.equal(err.constructor, Error);
|
assert.equal(err.constructor, Error);
|
||||||
assert.equal(seq, err.seq);
|
assert.equal(seq, err.seq);
|
||||||
display.client.CreateWindow(); // should emit error
|
display.client.CreateWindow(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {}); // should emit error
|
||||||
seq = display.client.seq_num;
|
seq = display.client.seq_num;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue