mirror of
https://github.com/danbulant/node-x11
synced 2026-06-15 04:31:17 +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
13
README.md
13
README.md
|
|
@ -1,6 +1,6 @@
|
|||
# About
|
||||
X11 protocol client for node.js
|
||||
|
||||
|
||||
Implements core X11 protocol, as well as Xrender, Damage, Composite, Big-Requests, Dpms, Screensaver, XFixes, Shape, XTest, XC-Misc, GLX and Apple-WM extensions.
|
||||
# install
|
||||
|
||||
|
|
@ -61,11 +61,11 @@ Core requests usage:
|
|||
# In use
|
||||
- [ntk](https://github.com/sidorares/ntk) - higher level toolkit on top of X11
|
||||
- [node-remote](https://github.com/AndrewSwerlick/node-remote) - metia center controller
|
||||
- [tiles](https://github.com/dominictarr/tiles) - tiling window manager
|
||||
- [tiles](https://github.com/dominictarr/tiles) - tiling window manager
|
||||
- [vnc](https://github.com/sidorares/node-vnc) - vnc client.
|
||||
- [node-ewmh](https://github.com/santigimeno/node-ewmh) - set of EWMH helpers.
|
||||
- [OdieWM](https://github.com/bu/OdieWM) - window manager
|
||||
- [Dbusmenu](https://github.com/sidorares/node-dbusmenu) - unity global menu client.
|
||||
- [Dbusmenu](https://github.com/sidorares/node-dbusmenu) - unity global menu client.
|
||||
|
||||
# Protocol documentation
|
||||
|
||||
|
|
@ -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: 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 )
|
||||
- https://github.com/alexer/python-xlib-render
|
||||
- Python/twisted: https://launchpad.net/twisted-x11
|
||||
- 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")
|
||||
|
||||
|
|
|
|||
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 x11 = require('../../lib');
|
||||
|
||||
var xclient = x11.createClient();
|
||||
var Exposure = x11.eventMask.Exposure;
|
||||
var PointerMotion = x11.eventMask.PointerMotion;
|
||||
|
||||
|
|
@ -17,16 +16,13 @@ for (var i=0; i < bitmap.length; ++i)
|
|||
bitmap[i] = parseInt((i/256)%256);
|
||||
if (byteNum == 2)
|
||||
bitmap[i] = parseInt((i/1024)%256);
|
||||
|
||||
|
||||
}
|
||||
|
||||
xclient.on('connect', function(err, display) {
|
||||
|
||||
var X = display.client;
|
||||
X.require('big-requests', function(BigReq) {
|
||||
|
||||
BigReq.Enable(function(maxLen) { console.log( maxLen ); });
|
||||
x11.createClient(function(err, display) {
|
||||
if (err) throw err;
|
||||
|
||||
var X = display.client;
|
||||
X.require('render', function(Render) {
|
||||
|
||||
var root = display.screen[0].root;
|
||||
|
|
@ -36,23 +32,23 @@ X.require('render', function(Render) {
|
|||
|
||||
var wid = X.AllocID();
|
||||
X.CreateWindow(
|
||||
wid, root,
|
||||
10, 10, 400, 300,
|
||||
wid, root,
|
||||
10, 10, 400, 300,
|
||||
1, 1, 0,
|
||||
{
|
||||
backgroundPixel: white, eventMask: Exposure|PointerMotion
|
||||
{
|
||||
backgroundPixel: white, eventMask: Exposure|PointerMotion
|
||||
}
|
||||
);
|
||||
X.MapWindow(wid);
|
||||
|
||||
|
||||
var gc = X.AllocID();
|
||||
X.CreateGC(gc, wid, { foreground: black, background: white } );
|
||||
|
||||
var pixmap1 = X.AllocID();
|
||||
X.CreatePixmap(pixmap1, wid, 32, 128, 128);
|
||||
var pic = X.AllocID();
|
||||
var pic = X.AllocID();
|
||||
Render.CreatePicture(pic, pixmap1, Render.rgba32);
|
||||
|
||||
|
||||
|
||||
var pic1 = X.AllocID();
|
||||
Render.CreatePicture(pic1, wid, Render.rgb24);
|
||||
|
|
@ -64,7 +60,7 @@ X.require('render', function(Render) {
|
|||
X.PutImage(2, pixmap1, gc, 128, 128, 0, 0, 0, 32, bitmap);
|
||||
//Render.Composite(3, pic1, 0, pic, 0, 0, 0, 0, 30, 40, 128, 128);
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
X.on('error', function(e) {
|
||||
console.log(e);
|
||||
|
|
@ -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 hexy = require('./hexy').hexy;
|
||||
|
||||
|
|
@ -301,7 +304,7 @@ var templates = {
|
|||
return [format, [12, n, win, mask].concat(params)];
|
||||
}
|
||||
],
|
||||
|
||||
|
||||
ResizeWindow: [
|
||||
function(win, width, height) {
|
||||
return module.exports.ConfigureWindow[0](win, { width : width, height: height });
|
||||
|
|
@ -516,7 +519,7 @@ var templates = {
|
|||
function(buf, status) {
|
||||
return status;
|
||||
}
|
||||
],
|
||||
],
|
||||
|
||||
UngrabKeyboard: [
|
||||
function(time) {
|
||||
|
|
@ -527,7 +530,7 @@ var templates = {
|
|||
GrabKey: [
|
||||
function(wid, ownerEvents, modifiers, key, pointerMode, keybMode) {
|
||||
return [ 'CCSLSCCCxxx', [ 33, ownerEvents, 4, wid, modifiers, key, pointerMode, keybMode ] ];
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
UngrabKey: [
|
||||
|
|
@ -535,7 +538,7 @@ var templates = {
|
|||
return [ 'CCSLSxx', [ 34, key, 3, wid, modifiers ] ];
|
||||
}
|
||||
],
|
||||
|
||||
|
||||
GrabServer: [
|
||||
[ 'CxS', [36, 1]]
|
||||
],
|
||||
|
|
@ -560,7 +563,7 @@ var templates = {
|
|||
};
|
||||
}
|
||||
],
|
||||
|
||||
|
||||
TranslateCoordinates: [
|
||||
function(srcWid, dstWid, srcX, srcY) {
|
||||
return [ 'CxSLLSS', [ 40, 4, srcWid, dstWid, srcX, srcY ] ];
|
||||
|
|
@ -584,7 +587,7 @@ var templates = {
|
|||
return [ 'CCSLL', [42, revertTo, 3, wid, 0] ];
|
||||
}
|
||||
],
|
||||
|
||||
|
||||
GetInputFocus: [
|
||||
function() {
|
||||
return [ 'CxS', [ 43, 1 ] ];
|
||||
|
|
@ -642,7 +645,12 @@ var templates = {
|
|||
}
|
||||
],
|
||||
|
||||
// opcode 55
|
||||
FreePixmap: [
|
||||
function(pixmap) {
|
||||
return [ 'CxSL', [ 54, 2, pixmap ] ];
|
||||
}
|
||||
],
|
||||
|
||||
CreateGC: [
|
||||
function(cid, drawable, values) {
|
||||
var format = 'CxSLLL';
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@
|
|||
|
||||
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('..');
|
||||
// TODO: move to templates
|
||||
|
|
@ -253,11 +256,11 @@ exports.requireExt = function(display, callback)
|
|||
// 1330 - X_GLXvop_BindTexImageEXT
|
||||
// 1331 - X_GLXvop_ReleaseTexImageEXT
|
||||
ext.BindTexImage = function(ctx, drawable, buffer, attribs) {
|
||||
if (!attribs)
|
||||
if (!attribs)
|
||||
attribs = [];
|
||||
var data = new Buffer(12 + attribs.length*4);
|
||||
data.writeUInt32LE(drawable, 0);
|
||||
data.writeUInt32LE(buffer, 4);
|
||||
data.writeUInt32LE(drawable, 0);
|
||||
data.writeUInt32LE(buffer, 4);
|
||||
data.writeUInt32LE(attribs.length, 8);
|
||||
for (var i=0; i < attribs.length; ++i)
|
||||
data.writeUint32LE(attribs.length, 12+i*4);
|
||||
|
|
@ -278,7 +281,7 @@ exports.requireExt = function(display, callback)
|
|||
|
||||
//var data = Buffer.concat(data);
|
||||
var padLength = 4 - data.length % 4;
|
||||
if (padLength == 4)
|
||||
if (padLength == 4)
|
||||
padLength = 0;
|
||||
var length = 4 + (data.length+padLength) / 4;
|
||||
X.pack_stream.pack('CCSLSSL', [ext.majorOpcode, 2, length, ctx, requestNum, requestTotal, data.length]);
|
||||
|
|
|
|||
|
|
@ -1,38 +1,28 @@
|
|||
// this will be eventually moved to lib/node-x11/extensions
|
||||
|
||||
var x11 = require('..');
|
||||
var xutil = require('../xutil');
|
||||
|
||||
// adding XRender functions manually from
|
||||
// http://cgit.freedesktop.org/xcb/proto/tree/src/render.xml?id=HEAD
|
||||
// and http://www.x.org/releases/X11R7.6/doc/renderproto/renderproto.txt
|
||||
// TODO: move to templates
|
||||
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;
|
||||
X.QueryExtension('RENDER', function(err, ext) {
|
||||
X.QueryExtension('RENDER', function(err, ext) {
|
||||
|
||||
if (!ext.present)
|
||||
{
|
||||
return callback(new Error('extension not available'));
|
||||
}
|
||||
|
||||
|
||||
ext.QueryVersion = function(clientMaj, clientMin, callback)
|
||||
{
|
||||
X.seq_num++;
|
||||
captureStack();
|
||||
X.pack_stream.pack('CCSLL', [ext.majorOpcode, 0, 3, clientMaj, clientMin]);
|
||||
X.replies[X.seq_num] = [
|
||||
function(buf, opt) {
|
||||
var res = buf.unpack('LL');
|
||||
var res = buf.unpack('LL');
|
||||
return res;
|
||||
},
|
||||
callback
|
||||
|
|
@ -43,7 +33,6 @@ exports.requireExt = function(display, callback)
|
|||
ext.QueryPictFormat = function(callback)
|
||||
{
|
||||
X.seq_num++;
|
||||
captureStack();
|
||||
X.pack_stream.pack('CCS', [ext.majorOpcode, 1, 1]);
|
||||
X.replies[X.seq_num] = [
|
||||
function (buf, opt) {
|
||||
|
|
@ -56,11 +45,11 @@ exports.requireExt = function(display, callback)
|
|||
var num_subpixel = res1[4];
|
||||
// formats list:
|
||||
var offset = 24;
|
||||
res.formats = [];
|
||||
res.formats = [];
|
||||
for (var i=0; i < num_formats; ++i)
|
||||
{
|
||||
var format = {};
|
||||
var f = buf.unpack('LCCxxSSSSSSSSL', offset);
|
||||
var f = buf.unpack('LCCxxSSSSSSSSL', offset);
|
||||
res.formats.push(f);
|
||||
offset += 28;
|
||||
}
|
||||
|
|
@ -70,15 +59,14 @@ exports.requireExt = function(display, callback)
|
|||
];
|
||||
X.pack_stream.flush();
|
||||
}
|
||||
|
||||
|
||||
ext.QueryFilters = function(callback)
|
||||
{
|
||||
X.seq_num++;
|
||||
captureStack();
|
||||
X.pack_stream.pack('CCSL', [ext.majorOpcode, 29, 2, display.screen[0].root]);
|
||||
X.replies[X.seq_num] = [
|
||||
function(buf, opt) {
|
||||
var h = buf.unpack('LL');
|
||||
var h = buf.unpack('LL');
|
||||
var num_aliases = h[0];
|
||||
var num_filters = h[1];
|
||||
var aliases = [];
|
||||
|
|
@ -103,8 +91,8 @@ exports.requireExt = function(display, callback)
|
|||
];
|
||||
X.pack_stream.flush();
|
||||
}
|
||||
|
||||
var valueList = [
|
||||
|
||||
var valueList = [
|
||||
['repeat', 'Cxxx'],
|
||||
['alphaMap', 'L'],
|
||||
['alphaXOrigin', 'sxx'],
|
||||
|
|
@ -130,10 +118,8 @@ exports.requireExt = function(display, callback)
|
|||
|
||||
ext.CreatePicture = function(pid, drawable, pictformat, values)
|
||||
{
|
||||
console.log([pid, drawable, pictformat, values]);
|
||||
X.seq_num++;
|
||||
captureStack();
|
||||
var mask = 0;
|
||||
var mask = 0;
|
||||
var reqLen = 5; // + (values + pad)/4
|
||||
var format = 'CCSLLLL';
|
||||
var params = [ext.majorOpcode, 4, reqLen, pid, drawable, pictformat, mask];
|
||||
|
|
@ -145,7 +131,6 @@ exports.requireExt = function(display, callback)
|
|||
{
|
||||
var name = valueList[i][0];
|
||||
var val = values[name];
|
||||
console.log([name, val]);
|
||||
if (val) {
|
||||
mask |= (1 << i);
|
||||
params.push(val);
|
||||
|
|
@ -162,7 +147,6 @@ exports.requireExt = function(display, callback)
|
|||
params[2] = reqLen;
|
||||
params[6] = mask;
|
||||
}
|
||||
console.log(['CreatePicture', format, params]);
|
||||
X.pack_stream.pack(format, params);
|
||||
X.pack_stream.flush();
|
||||
}
|
||||
|
|
@ -177,7 +161,6 @@ exports.requireExt = function(display, callback)
|
|||
ext.SetPictureFilter = function(pid, name, filterParams)
|
||||
{
|
||||
X.seq_num++;
|
||||
captureStack();
|
||||
var reqLen = 2; //header + params + 1xStopfix+2xColors
|
||||
var format = 'CCSLa';
|
||||
var params = [ext.majorOpcode, 30, reqLen, pid];
|
||||
|
|
@ -192,16 +175,21 @@ exports.requireExt = function(display, callback)
|
|||
}
|
||||
*/
|
||||
params[2] = reqLen;
|
||||
//console.log([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)
|
||||
{
|
||||
// TODO: merge with linear gradient
|
||||
X.seq_num++;
|
||||
captureStack();
|
||||
var reqLen = 9+stops.length*3; //header + params + 1xStopfix+2xColors
|
||||
var format = 'CCSLLLLLLLL';
|
||||
var params = [ext.majorOpcode, 35, reqLen, pid];
|
||||
|
|
@ -218,7 +206,7 @@ exports.requireExt = function(display, callback)
|
|||
for (var i=0; i < stops.length; ++i)
|
||||
{
|
||||
format += 'L';
|
||||
// TODO: we know total params length in advance. ? params[index] =
|
||||
// TODO: we know total params length in advance. ? params[index] =
|
||||
params.push(floatToFix(stops[i][0]))
|
||||
}
|
||||
// colors
|
||||
|
|
@ -228,15 +216,13 @@ exports.requireExt = function(display, callback)
|
|||
for (var j=0; j < 4; ++j)
|
||||
params.push(stops[i][1][j]);
|
||||
}
|
||||
//console.log([format, params]);
|
||||
X.pack_stream.pack(format, params);
|
||||
X.pack_stream.flush();
|
||||
}
|
||||
X.pack_stream.flush();
|
||||
};
|
||||
|
||||
ext.LinearGradient = function(pid, p1, p2, stops)
|
||||
{
|
||||
X.seq_num++;
|
||||
captureStack();
|
||||
var reqLen = 7+stops.length*3; //header + params + 1xStopfix+2xColors
|
||||
var format = 'CCSLLLLLL';
|
||||
var params = [ext.majorOpcode, 34, reqLen, pid];
|
||||
|
|
@ -252,7 +238,7 @@ exports.requireExt = function(display, callback)
|
|||
for (var i=0; i < stops.length; ++i)
|
||||
{
|
||||
format += 'L';
|
||||
// TODO: we know total params length in advance. ? params[index] =
|
||||
// TODO: we know total params length in advance. ? params[index] =
|
||||
params.push(floatToFix(stops[i][0]))
|
||||
}
|
||||
// colors
|
||||
|
|
@ -262,15 +248,13 @@ exports.requireExt = function(display, callback)
|
|||
for (var j=0; j < 4; ++j)
|
||||
params.push(stops[i][1][j]);
|
||||
}
|
||||
//console.log([format, params]);
|
||||
X.pack_stream.pack(format, params);
|
||||
X.pack_stream.flush();
|
||||
X.pack_stream.flush();
|
||||
}
|
||||
|
||||
ext.ConicalGradient = function(pid, center, angle, stops)
|
||||
{
|
||||
X.seq_num++;
|
||||
captureStack();
|
||||
var reqLen = 6+stops.length*3; //header + params + 1xStopfix+2xColors
|
||||
var format = 'CCSLLLLL';
|
||||
var params = [ext.majorOpcode, 36, reqLen, pid];
|
||||
|
|
@ -285,7 +269,7 @@ exports.requireExt = function(display, callback)
|
|||
for (var i=0; i < stops.length; ++i)
|
||||
{
|
||||
format += 'L';
|
||||
// TODO: we know total params length in advance. ? params[index] =
|
||||
// TODO: we know total params length in advance. ? params[index] =
|
||||
params.push(floatToFix(stops[i][0]))
|
||||
}
|
||||
// colors
|
||||
|
|
@ -295,16 +279,14 @@ exports.requireExt = function(display, callback)
|
|||
for (var j=0; j < 4; ++j)
|
||||
params.push(stops[i][1][j]);
|
||||
}
|
||||
//console.log([format, params]);
|
||||
X.pack_stream.pack(format, params);
|
||||
X.pack_stream.flush();
|
||||
X.pack_stream.flush();
|
||||
}
|
||||
|
||||
ext.FillRectangles = function(op, pid, color, rects)
|
||||
{
|
||||
X.seq_num++;
|
||||
captureStack();
|
||||
var reqLen = 5+rects.length/2;
|
||||
var reqLen = 5+rects.length/2;
|
||||
var format = 'CCSCxxxLSSSS';
|
||||
var params = [ext.majorOpcode, 26, reqLen, op, pid];
|
||||
for (var j=0; j < 4; ++j)
|
||||
|
|
@ -318,15 +300,14 @@ exports.requireExt = function(display, callback)
|
|||
params.push(rects[i*4 + 3]);
|
||||
}
|
||||
X.pack_stream.pack(format, params);
|
||||
X.pack_stream.flush();
|
||||
X.pack_stream.flush();
|
||||
}
|
||||
|
||||
ext.Composite = function(op, src, mask, dst, srcX, srcY, maskX, maskY, dstX, dstY, width, height)
|
||||
{
|
||||
X.seq_num++;
|
||||
captureStack();
|
||||
X.pack_stream.pack(
|
||||
'CCSCxxxLLLssssssSS',
|
||||
'CCSCxxxLLLssssssSS',
|
||||
[ext.majorOpcode, 8, 9, op, src, mask, dst, srcX, srcY, maskX, maskY, dstX, dstY, width, height]
|
||||
)
|
||||
.flush();
|
||||
|
|
@ -335,27 +316,24 @@ exports.requireExt = function(display, callback)
|
|||
ext.Trapezoids = function(op, src, srcX, srcY, dst, maskFormat, trapz)
|
||||
{
|
||||
X.seq_num++;
|
||||
captureStack();
|
||||
var format = 'CCSCxxxLLLss';
|
||||
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)
|
||||
{
|
||||
format += 'llllllllll';
|
||||
for (var j=0; j < 10; ++j)
|
||||
params.push(floatToFix(trapz[i*10 + j]));
|
||||
}
|
||||
//console.log([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++;
|
||||
captureStack();
|
||||
var format = 'CCSCxxxLLLss';
|
||||
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)
|
||||
{
|
||||
format += 'llllll';
|
||||
//TODO: Array.copy
|
||||
|
|
@ -367,11 +345,191 @@ exports.requireExt = function(display, callback)
|
|||
params.push(floatToFix(tris[i*6 + 5])); // y3
|
||||
}
|
||||
X.pack_stream.pack(format, params);
|
||||
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) {
|
||||
console.log(formats);
|
||||
for (var i=0; i < formats.formats.length; ++i) {
|
||||
var f = formats.formats[i];
|
||||
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
|
||||
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] ;
|
||||
if (f[2] == 8 && f[10] == 255)
|
||||
ext.a8 = f[0];
|
||||
}
|
||||
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;
|
||||
};
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ ReadFormatRequest.prototype.execute = function(bufferlist, tag1, tag2)
|
|||
// maybe best approach is to wait all data required for format and then process fixed buffer
|
||||
// TODO: byte order!!!
|
||||
switch (arg) {
|
||||
case 'C':
|
||||
case 'C':
|
||||
this.data.push(bufferlist.getbyte());
|
||||
break;
|
||||
case 'S':
|
||||
|
|
@ -121,7 +121,7 @@ UnpackStream.prototype.unpackTo = function(destination, names_formats, callback)
|
|||
{
|
||||
var names = [];
|
||||
var format = '';
|
||||
|
||||
|
||||
for (var i=0; i < names_formats.length; ++i)
|
||||
{
|
||||
var off = 0;
|
||||
|
|
@ -172,7 +172,7 @@ UnpackStream.prototype.resume = function()
|
|||
}
|
||||
|
||||
UnpackStream.prototype.getbyte = function()
|
||||
{
|
||||
{
|
||||
var res = 0;
|
||||
var b = this.readlist[0];
|
||||
if (this.offset + 1 < b.length)
|
||||
|
|
@ -180,7 +180,7 @@ UnpackStream.prototype.getbyte = function()
|
|||
res = b[this.offset];
|
||||
this.offset++;
|
||||
this.length--;
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
// last byte in current buffer, shift read list
|
||||
|
|
@ -202,7 +202,7 @@ UnpackStream.prototype.pstr = function(str)
|
|||
if (len == 0)
|
||||
return; // nothing to write
|
||||
var buf = new Buffer(len);
|
||||
buf.write(str, 'binary');
|
||||
buf.write(str, 'binary');
|
||||
this.write_queue.push(buf);
|
||||
}
|
||||
*/
|
||||
|
|
@ -211,7 +211,7 @@ UnpackStream.prototype.pstr = function(str)
|
|||
UnpackStream.prototype.pack = function(format, args)
|
||||
{
|
||||
var packetlength = 0;
|
||||
|
||||
|
||||
var arg = 0;
|
||||
for (var i = 0; i < format.length; ++i)
|
||||
{
|
||||
|
|
@ -238,20 +238,30 @@ UnpackStream.prototype.pack = function(format, args)
|
|||
{
|
||||
switch(format[i])
|
||||
{
|
||||
case 'x':
|
||||
case 'x':
|
||||
buf[offset++] = 0;
|
||||
break;
|
||||
case 'C':
|
||||
var n = args[arg++];
|
||||
buf[offset++] = n;
|
||||
break;
|
||||
case 's': // TODO: implement signed INT16!!!
|
||||
case 's':
|
||||
var n = args[arg++];
|
||||
buf.writeInt16LE(n, offset);
|
||||
offset += 2;
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
var n = args[arg++];
|
||||
buf[offset++] = n & 0xff;
|
||||
buf[offset++] = (n >> 8) & 0xff;
|
||||
break;
|
||||
case 'l': // TODO: implement signed INT32!!!
|
||||
case 'l':
|
||||
var n = args[arg++];
|
||||
buf.writeInt32LE(n, offset);
|
||||
offset += 4;
|
||||
break;
|
||||
|
||||
case 'L':
|
||||
var n = args[arg++];
|
||||
buf[offset++] = n & 0xff;
|
||||
|
|
@ -281,7 +291,7 @@ UnpackStream.prototype.pack = function(format, args)
|
|||
for (; c < len; ++c)
|
||||
buf[offset++] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.write_queue.push(buf);
|
||||
this.write_length += buf.length;
|
||||
|
|
@ -290,7 +300,7 @@ UnpackStream.prototype.pack = function(format, args)
|
|||
|
||||
UnpackStream.prototype.flush = function(stream)
|
||||
{
|
||||
// TODO: measure performance benefit of
|
||||
// TODO: measure performance benefit of
|
||||
// creating and writing one big concatenated buffer
|
||||
|
||||
// TODO: check write result
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
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;
|
||||
display.client.on('error', function(err) {
|
||||
switch (++ times) {
|
||||
|
|
@ -26,7 +27,7 @@ describe('Client', function() {
|
|||
default:
|
||||
assert.equal(err.constructor, Error);
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue