From 7f8714a40f781ffef327ae85086018188608bdcd Mon Sep 17 00:00:00 2001 From: yelouafi Date: Fri, 12 Sep 2014 18:34:44 +0000 Subject: [PATCH 1/3] TTFFont.parse should call *Table constructors with explicit @tag param --- lib/font/ttf.coffee | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/font/ttf.coffee b/lib/font/ttf.coffee index 59023b1e7..3dfd5b966 100644 --- a/lib/font/ttf.coffee +++ b/lib/font/ttf.coffee @@ -68,16 +68,16 @@ class TTFFont parse: -> @directory = new Directory(@contents) - @head = new HeadTable(this) - @name = new NameTable(this) - @cmap = new CmapTable(this) - @hhea = new HheaTable(this) - @maxp = new MaxpTable(this) - @hmtx = new HmtxTable(this) - @post = new PostTable(this) - @os2 = new OS2Table(this) - @loca = new LocaTable(this) - @glyf = new GlyfTable(this) + @head = new HeadTable(this, 'HeadTable') + @name = new NameTable(this, 'NameTable') + @cmap = new CmapTable(this, 'CmapTable') + @hhea = new HheaTable(this, 'HheaTable') + @maxp = new MaxpTable(this, 'MaxpTable') + @hmtx = new HmtxTable(this, 'HmtxTable') + @post = new PostTable(this, 'PostTable') + @os2 = new OS2Table(this, 'OS2Table') + @loca = new LocaTable(this, 'LocaTable') + @glyf = new GlyfTable(this, 'GlyfTable') @ascender = (@os2.exists and @os2.ascender) or @hhea.ascender @decender = (@os2.exists and @os2.decender) or @hhea.decender From c7c20ef6b78ed3b36fda5ac6258a6b90d9c6dcf5 Mon Sep 17 00:00:00 2001 From: yelouafi Date: Fri, 12 Sep 2014 21:47:46 +0000 Subject: [PATCH 2/3] removed @constructor.name line, corrected @tag params --- lib/font/table.coffee | 1 - lib/font/ttf.coffee | 20 ++++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/font/table.coffee b/lib/font/table.coffee index 435ca95c0..6f07a7af2 100644 --- a/lib/font/table.coffee +++ b/lib/font/table.coffee @@ -1,6 +1,5 @@ class Table constructor: (@file, @tag) -> - @tag ?= @constructor.name.replace('Table', '').toLowerCase() info = @file.directory.tables[@tag] @exists = !!info diff --git a/lib/font/ttf.coffee b/lib/font/ttf.coffee index 3dfd5b966..b92659ca7 100644 --- a/lib/font/ttf.coffee +++ b/lib/font/ttf.coffee @@ -68,16 +68,16 @@ class TTFFont parse: -> @directory = new Directory(@contents) - @head = new HeadTable(this, 'HeadTable') - @name = new NameTable(this, 'NameTable') - @cmap = new CmapTable(this, 'CmapTable') - @hhea = new HheaTable(this, 'HheaTable') - @maxp = new MaxpTable(this, 'MaxpTable') - @hmtx = new HmtxTable(this, 'HmtxTable') - @post = new PostTable(this, 'PostTable') - @os2 = new OS2Table(this, 'OS2Table') - @loca = new LocaTable(this, 'LocaTable') - @glyf = new GlyfTable(this, 'GlyfTable') + @head = new HeadTable(this, 'head') + @name = new NameTable(this, 'name') + @cmap = new CmapTable(this, 'cmap') + @hhea = new HheaTable(this, 'hhea') + @maxp = new MaxpTable(this, 'maxp') + @hmtx = new HmtxTable(this, 'hmtx') + @post = new PostTable(this, 'post') + @os2 = new OS2Table(this, 'os2') + @loca = new LocaTable(this, 'loca') + @glyf = new GlyfTable(this, 'glyf') @ascender = (@os2.exists and @os2.ascender) or @hhea.ascender @decender = (@os2.exists and @os2.decender) or @hhea.decender From 9f4c6345c561bbce98dea9d1d13ab9d086b3929a Mon Sep 17 00:00:00 2001 From: yelouafi Date: Sat, 13 Sep 2014 17:30:42 +0000 Subject: [PATCH 3/3] Moved @tag definition to the derived Table constructors --- lib/font/table.coffee | 2 +- lib/font/tables/cmap.coffee | 4 ++++ lib/font/tables/glyf.coffee | 4 ++++ lib/font/tables/head.coffee | 4 ++++ lib/font/tables/hhea.coffee | 4 ++++ lib/font/tables/hmtx.coffee | 4 ++++ lib/font/tables/loca.coffee | 4 ++++ lib/font/tables/maxp.coffee | 4 ++++ lib/font/tables/name.coffee | 4 ++++ lib/font/tables/post.coffee | 4 ++++ lib/font/ttf.coffee | 20 ++++++++++---------- 11 files changed, 47 insertions(+), 11 deletions(-) diff --git a/lib/font/table.coffee b/lib/font/table.coffee index 6f07a7af2..98394cb7f 100644 --- a/lib/font/table.coffee +++ b/lib/font/table.coffee @@ -1,5 +1,5 @@ class Table - constructor: (@file, @tag) -> + constructor: (@file) -> info = @file.directory.tables[@tag] @exists = !!info diff --git a/lib/font/tables/cmap.coffee b/lib/font/tables/cmap.coffee index 7a66f7289..25de025e9 100644 --- a/lib/font/tables/cmap.coffee +++ b/lib/font/tables/cmap.coffee @@ -2,6 +2,10 @@ Table = require '../table' Data = require '../../data' class CmapTable extends Table + constructor: -> + @tag = 'cmap' + super + parse: (data) -> data.pos = @offset diff --git a/lib/font/tables/glyf.coffee b/lib/font/tables/glyf.coffee index 4cf143135..9116c0b9f 100644 --- a/lib/font/tables/glyf.coffee +++ b/lib/font/tables/glyf.coffee @@ -2,6 +2,10 @@ Table = require '../table' Data = require '../../data' class GlyfTable extends Table + constructor: -> + @tag = 'glyf' + super + parse: (data) -> # We're not going to parse the whole glyf table, just the glyfs we need. See below. @cache = {} diff --git a/lib/font/tables/head.coffee b/lib/font/tables/head.coffee index 6c45b228e..0b5d726ef 100644 --- a/lib/font/tables/head.coffee +++ b/lib/font/tables/head.coffee @@ -2,6 +2,10 @@ Table = require '../table' Data = require '../../data' class HeadTable extends Table + constructor: -> + @tag = 'head' + super + parse: (data) -> data.pos = @offset diff --git a/lib/font/tables/hhea.coffee b/lib/font/tables/hhea.coffee index 2cb3cb580..c824a099c 100644 --- a/lib/font/tables/hhea.coffee +++ b/lib/font/tables/hhea.coffee @@ -2,6 +2,10 @@ Table = require '../table' Data = require '../../data' class HheaTable extends Table + constructor: -> + @tag = 'hhea' + super + parse: (data) -> data.pos = @offset diff --git a/lib/font/tables/hmtx.coffee b/lib/font/tables/hmtx.coffee index b40695b56..915c524af 100644 --- a/lib/font/tables/hmtx.coffee +++ b/lib/font/tables/hmtx.coffee @@ -2,6 +2,10 @@ Table = require '../table' Data = require '../../data' class HmtxTable extends Table + constructor: -> + @tag = 'hmtx' + super + parse: (data) -> data.pos = @offset diff --git a/lib/font/tables/loca.coffee b/lib/font/tables/loca.coffee index 44ac90716..6a78e4703 100644 --- a/lib/font/tables/loca.coffee +++ b/lib/font/tables/loca.coffee @@ -2,6 +2,10 @@ Table = require '../table' Data = require '../../data' class LocaTable extends Table + constructor: -> + @tag = 'loca' + super + parse: (data) -> data.pos = @offset format = @file.head.indexToLocFormat diff --git a/lib/font/tables/maxp.coffee b/lib/font/tables/maxp.coffee index 4a308da36..8b1abc886 100644 --- a/lib/font/tables/maxp.coffee +++ b/lib/font/tables/maxp.coffee @@ -2,6 +2,10 @@ Table = require '../table' Data = require '../../data' class MaxpTable extends Table + constructor: -> + @tag = 'maxp' + super + parse: (data) -> data.pos = @offset diff --git a/lib/font/tables/name.coffee b/lib/font/tables/name.coffee index 4aa7a98ad..6dbaec274 100644 --- a/lib/font/tables/name.coffee +++ b/lib/font/tables/name.coffee @@ -3,6 +3,10 @@ Data = require '../../data' utils = require '../utils' class NameTable extends Table + constructor: -> + @tag = 'name' + super + parse: (data) -> data.pos = @offset diff --git a/lib/font/tables/post.coffee b/lib/font/tables/post.coffee index d2c496b37..2ed5d772a 100644 --- a/lib/font/tables/post.coffee +++ b/lib/font/tables/post.coffee @@ -2,6 +2,10 @@ Table = require '../table' Data = require '../../data' class PostTable extends Table + constructor: -> + @tag = 'post' + super + parse: (data) -> data.pos = @offset diff --git a/lib/font/ttf.coffee b/lib/font/ttf.coffee index b92659ca7..59023b1e7 100644 --- a/lib/font/ttf.coffee +++ b/lib/font/ttf.coffee @@ -68,16 +68,16 @@ class TTFFont parse: -> @directory = new Directory(@contents) - @head = new HeadTable(this, 'head') - @name = new NameTable(this, 'name') - @cmap = new CmapTable(this, 'cmap') - @hhea = new HheaTable(this, 'hhea') - @maxp = new MaxpTable(this, 'maxp') - @hmtx = new HmtxTable(this, 'hmtx') - @post = new PostTable(this, 'post') - @os2 = new OS2Table(this, 'os2') - @loca = new LocaTable(this, 'loca') - @glyf = new GlyfTable(this, 'glyf') + @head = new HeadTable(this) + @name = new NameTable(this) + @cmap = new CmapTable(this) + @hhea = new HheaTable(this) + @maxp = new MaxpTable(this) + @hmtx = new HmtxTable(this) + @post = new PostTable(this) + @os2 = new OS2Table(this) + @loca = new LocaTable(this) + @glyf = new GlyfTable(this) @ascender = (@os2.exists and @os2.ascender) or @hhea.ascender @decender = (@os2.exists and @os2.decender) or @hhea.decender