the following lua code is just a simple demo of TrueType&OpenType font load process for myself use. and I've found that it can't work with some OTF files recently. for example: AdobeSongStd-Light.otf. but it's ok when I try to load the TrueType font for example: SimHei.ttf callback.register('define_font', function(name, size) filename=kpse.find_file(name,"truetype fonts") if (filename) then ttffont = fontforge.to_table(fontforge.open(filename)) if ttffont then f = { } f.name = ttffont.fontname f.fullname = ttffont.names[1].names.fullname f.size = size f.characters = {} for char, glyph in pairs(ttffont.map.map) do glyph_table = ttffont.glyphs[glyph] f.characters[char] = { index = glyph, width = glyph_table.width * size/ttffont.units_per_em, name = glyph_table.name, } end f.filename = filename f.type = 'real' f.format = 'truetype' f.cidinfo = { registry = "Adobe", ordering = "Identity", supplement = 0, version = 1 } end else f = font.read_tfm(name, size) end return f end ) } and luatex give me the error: ! LuaTeX error <\directlua0>:1: attempt to index field 'map' (a nil value). I doubt maybe the OpenType file support in the fontforge is broken now. Can anyone help to check this ?
luoyi wrote:
the following lua code is just a simple demo of TrueType&OpenType font load process for myself use. and I've found that it can't work with some OTF files recently. for example: AdobeSongStd-Light.otf. but it's ok when I try to load the TrueType font for example: SimHei.ttf
callback.register('define_font', function(name, size) filename=kpse.find_file(name,"truetype fonts") if (filename) then ttffont = fontforge.to_table(fontforge.open(filename)) if ttffont then f = { } f.name = ttffont.fontname f.fullname = ttffont.names[1].names.fullname f.size = size f.characters = {}
for char, glyph in pairs(ttffont.map.map) do glyph_table = ttffont.glyphs[glyph]
f.characters[char] = { index = glyph, width = glyph_table.width * size/ttffont.units_per_em, name = glyph_table.name, } end f.filename = filename f.type = 'real' f.format = 'truetype' f.cidinfo = { registry = "Adobe", ordering = "Identity", supplement = 0, version = 1 } end else f = font.read_tfm(name, size) end return f end ) }
and luatex give me the error: ! LuaTeX error <\directlua0>:1: attempt to index field 'map' (a nil value).
I doubt maybe the OpenType file support in the fontforge is broken now. Can anyone help to check this ?
it's a CID font so you need to use the subfonts table in combination with cid vectors; you can think of the glyphs table being like like this: for n, subfont in pairs(yourtable.subfonts) do for index, glyph in pairs(subfont.glyphs) do glyphs[index] = glyph end end the relevant cid info is in a subtable in the root of the fonts ["cidinfo"]={ ["ordering"]="GB1", ["registry"]="Adobe", ["supplement"]=5, ["version"]=5, }, Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
could you tell me where can I find the document about the structure
of the subfonts table ? I can't fullly understand your example code
without know the exactly structure of the table.
thank you
2009/3/2 Hans Hagen
luoyi wrote:
the following lua code is just a simple demo of TrueType&OpenType font load process for myself use. and I've found that it can't work with some OTF files recently. for example: AdobeSongStd-Light.otf. but it's ok when I try to load the TrueType font for example: SimHei.ttf
callback.register('define_font', function(name, size) filename=kpse.find_file(name,"truetype fonts") if (filename) then ttffont = fontforge.to_table(fontforge.open(filename)) if ttffont then f = { } f.name = ttffont.fontname f.fullname = ttffont.names[1].names.fullname f.size = size f.characters = {}
for char, glyph in pairs(ttffont.map.map) do glyph_table = ttffont.glyphs[glyph]
f.characters[char] = { index = glyph, width = glyph_table.width * size/ttffont.units_per_em, name = glyph_table.name, } end f.filename = filename f.type = 'real' f.format = 'truetype' f.cidinfo = { registry = "Adobe", ordering = "Identity", supplement = 0, version = 1 } end else f = font.read_tfm(name, size) end return f end ) }
and luatex give me the error: ! LuaTeX error <\directlua0>:1: attempt to index field 'map' (a nil value).
I doubt maybe the OpenType file support in the fontforge is broken now. Can anyone help to check this ?
it's a CID font so you need to use the subfonts table in combination with cid vectors; you can think of the glyphs table being like like this:
for n, subfont in pairs(yourtable.subfonts) do for index, glyph in pairs(subfont.glyphs) do glyphs[index] = glyph end end
the relevant cid info is in a subtable in the root of the fonts
["cidinfo"]={ ["ordering"]="GB1", ["registry"]="Adobe", ["supplement"]=5, ["version"]=5, },
Hans
----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
luoyi wrote:
could you tell me where can I find the document about the structure of the subfonts table ? I can't fullly understand your example code without know the exactly structure of the table.
thank you
Subfonts is just a way of having more fonts in one file; the subtables and the cidinfo table has the info that points to a cid vector (in your case an adobe gb one). What you do with these subtables is up to youself (or the macro package): use only one, merge them, merge a few etc This is a subfonts entry ["subfonts"]={ { ["ascent"]=800, ["cidinfo"]={ ["supplement"]=0, ["version"]=0, }, ["creationtime"]=1235924579, ["descent"]=200, ["design_range_bottom"]=0, ["design_range_top"]=0, ["design_size"]=0, ["encodingchanged"]=0, ["extrema_bound"]=0, ["fontname"]="AdobeSongStd-Light-Alphabetic", ["fontstyle_id"]=0, ["glyphcnt"]=700, ["glyphmax"]=700, ["glyphs"]={ [0]={}, {}, ["fontname"]="AdobeSongStd-Light-Alphabetic", ["fontname"]="AdobeSongStd-Light-Dingbats", ["fontname"]="AdobeSongStd-Light-Generic", ["fontname"]="AdobeSongStd-Light-HRoman", ["fontname"]="AdobeSongStd-Light-HRomanRot", ["fontname"]="AdobeSongStd-Light-Hanzi", etc. Shapes can be shared which makes the font more compact. Cid fonts are currently somewhat inefficient, mostly because the vectors have many empty entries ["glyphs"]={ [0]={}, {}, {}, {}, {}, so future releases of luatex miight use the ["glyphs"]={ [12345]={...}, {...}, {...}, {...}, [23456={...}, syntax In practice you can just overlay these subfonts and then use the info from the external cid vector from the manual: "The cidinfo will be used as the character set (the CID /Ordering and /Registry keys)." once the font table structure is 'frozen' we will add some more detailed info to the manual Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
participants (2)
-
Hans Hagen
-
luoyi