Permalink
Browse files

Add initializer and example usage

  • Loading branch information...
1 parent 858335a commit 74730dd68613c59c972621034ab7c4d9972ffeaa @Benvie committed Apr 8, 2012
Showing with 21 additions and 4 deletions.
  1. +2 −1 examples/ttf/labels.json
  2. +11 −2 examples/ttf/ttf.js
  3. +8 −1 lib/genesis.js
@@ -494,5 +494,6 @@
"10280-1029F": "Lycian ",
"10920-1093F": "Lydian ",
"1F030-1F09F": "Domino Tiles ",
- "1F000-1F02F": "Mahjong Tiles" }
+ "1F000-1F02F": "Mahjong Tiles" },
+ "platformID": [ "Unicode", "Macintosh", "ISO", "Windows", "Custom" ]
}
View
@@ -243,14 +243,23 @@ TableTypes['OS/2'] = StructT('OS2', {
-var NameIndex = StructT('NameIndex', {
+TableTypes.name = StructT('NameIndex', {
format : Uint16,
length : Uint16,
contents : Uint16
+}).initializer(function(){
+ var arr = NameRecord.array(this.length.reify());
+ this.items = new arr(this._data, this._offset + this.bytes);
+ return this;
+}).reifier(function(reify){
+ var ret = reify();
+ ret.items = this.items.reify();
+ return ret;
});
+
var NameRecord = StructT('NameRecord', {
- platformID : Uint16,
+ platformID : Uint16.typeDef('PlatformID', function(reify){ return labels.platformID[reify()] }),
encodingID : Uint16,
languageID : Uint16,
nameID : Uint16,
View
@@ -147,6 +147,10 @@ copy({
}
return iface;
},
+ initializer: function initializer(handler){
+ this.prototype.init = handler;
+ return this;
+ },
reifier: function reifier(handler){
var oldReifier = this.prototype.reify;
if (!handler) {
@@ -195,7 +199,7 @@ function createInterface(name, ctor, type){
var count = name.match(/^[*]+/)[0].length;
fnName = Array(count + 1).join('Ptr_') + fnName;
}
- var src = 'return function '+fnName+'(data, offset, values){ return Ctor.call(Object.create('+fnName+'.prototype), data, offset, values) }';
+ var src = 'return function '+fnName+'(data, offset, values){ return Ctor.call(Object.create('+fnName+'.prototype), data, offset, values).init() }';
var iface = Function('Ctor', src)(ctor);
ifaceMap.set(iface, ctor);
@@ -239,6 +243,9 @@ var Data = Type.prototype = {
}
api(this, '_data', data);
},
+ init: function init(ctor){
+ return this;
+ },
realign: function realign(offset){
this._offset = +offset || 0;
},

0 comments on commit 74730dd

Please sign in to comment.