From be735a865e2bdc6b7ac57161a24e4911741024f1 Mon Sep 17 00:00:00 2001 From: Context Git Mirror Bot Date: Thu, 9 Jun 2016 20:47:50 +0200 Subject: 2016-06-09 19:28:00 --- tex/generic/context/luatex/luatex-fonts-merged.lua | 247 ++++++++++++++++++++- tex/generic/context/luatex/luatex-fonts.lua | 1 + 2 files changed, 247 insertions(+), 1 deletion(-) (limited to 'tex/generic') diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index dbbe11f6b..89dcbbc86 100644 --- a/tex/generic/context/luatex/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex/luatex-fonts-merged.lua @@ -1,6 +1,6 @@ -- merged file : c:/data/develop/context/sources/luatex-fonts-merged.lua -- parent file : c:/data/develop/context/sources/luatex-fonts.lua --- merge date : 06/08/16 16:32:52 +-- merge date : 06/09/16 19:23:43 do -- begin closure to overcome local limits and interference @@ -15349,6 +15349,7 @@ otf.version=3.022 otf.cache=containers.define("fonts","otl",otf.version,true) otf.svgcache=containers.define("fonts","svg",otf.version,true) otf.pdfcache=containers.define("fonts","pdf",otf.version,true) +otf.svgenabled=false local otfreaders=otf.readers local hashes=fonts.hashes local definers=fonts.definers @@ -23097,6 +23098,250 @@ end -- closure do -- begin closure to overcome local limits and interference +if not modules then modules={} end modules ['font-ocl']={ + version=1.001, + comment="companion to font-otf.lua (context)", + author="Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright="PRAGMA ADE / ConTeXt Development Team", + license="see context related readme files" +} +local formatters=string.formatters +local otf=fonts.handlers.otf +local f_color_start=formatters["pdf:direct: %f %f %f rg"] +local s_color_stop="pdf:direct:" +if context then + local startactualtext=nil + local stopactualtext=nil + function otf.getactualtext(n) + if not startactualtext then + startactualtext=backends.codeinjections.startunicodetoactualtext + stopactualtext=backends.codeinjections.stopunicodetoactualtext + end + return startactualtext(n),stopactualtext() + end +else + local tounicode=fonts.mappings.tounicode16 + function otf.getactualtext(n) + return "/Span << /ActualText >> BDC","EMC" + end +end +local function initializecolr(tfmdata,kind,value) + if value then + local palettes=tfmdata.resources.colorpalettes + if palettes then + local palette=palettes[tonumber(value) or 1] or palettes[1] or {} + local classes=#palette + if classes==0 then + return + end + local characters=tfmdata.characters + local descriptions=tfmdata.descriptions + local properties=tfmdata.properties + local colorvalues={} + properties.virtualized=true + tfmdata.fonts={ + { id=0 } + } + for i=1,classes do + local p=palette[i] + colorvalues[i]={ "special",f_color_start(p[1]/255,p[2]/255,p[3]/255) } + end + local getactualtext=otf.getactualtext + for unicode,character in next,characters do + local description=descriptions[unicode] + if description then + local colorlist=description.colors + if colorlist then + local b,e=getactualtext(unicode) + local w=character.width or 0 + local s=#colorlist + local n=1 + local t={ + { "special","pdf:direct: q "..b } + } + for i=1,s do + local entry=colorlist[i] + n=n+1 t[n]=colorvalues[entry.class] + n=n+1 t[n]={ "char",entry.slot } + if s>1 and itestrun then + report_svg("quiting test run") + break + end + end + os.remove(svgfile) + return pdfshapes + end +else + function otfsvg.topdf(svgshapes) + local svgfile="temp-otf-svg-shape.svg" + local pdffile="temp-otf-svg-shape.pdf" + local command="inkscape "..svgfile.." --export-pdf="..pdffile + local pdfshapes={} + local nofshapes=#svgshapes + texio.write(formatters["[converting %i svg glyphs to pdf using command %q : "](nofshapes,command)) + for i=1,nofshapes do + local entry=svgshapes[i] + for j=entry.first,entry.last do + texio.write(formatters["%i "](j)) + io.savedata(svgfile,tostring(entry.data)) + os.execute(command) + pdfshapes[j]=io.loaddata(pdffile) + end + end + os.remove(svgfile) + texio.write("done]") + return pdfshapes + end +end +local function initializesvg(tfmdata,kind,value) + if value and otf.svgenabled then + local characters=tfmdata.characters + local descriptions=tfmdata.descriptions + local properties=tfmdata.properties + local svg=properties.svg + local hash=svg and svg.hash + local timestamp=svg and svg.timestamp + if not hash then + return + end + local pdffile=containers.read(otf.pdfcache,hash) + local pdfshapes=pdffile and pdffile.pdfshapes + if not pdfshapes or pdffile.timestamp~=timestamp then + local svgfile=containers.read(otf.svgcache,hash) + local svgshapes=svgfile and svgfile.svgshapes + pdfshapes=svgshapes and otfsvg.topdf(svgshapes) or {} + containers.write(otf.pdfcache,hash,{ + pdfshapes=pdfshapes, + timestamp=timestamp, + }) + end + if not pdfshapes or not next(pdfshapes) then + return + end + properties.virtualized=true + tfmdata.fonts={ + { id=0 } + } + local getactualtext=otf.getactualtext + local storepdfdata=otfsvg.storepdfdata + local nop={ "nop" } + for unicode,character in next,characters do + local index=character.index + if index then + local pdf=pdfshapes[index] + if pdf then + local setcode,name,nilcode=storepdfdata(pdf) + if name then + local bt,et=getactualtext(unicode) + local wd=character.width or 0 + local ht=character.height or 0 + local dp=character.depth or 0 + character.commands={ + { "special","pdf:direct:"..bt }, + { "down",dp }, + setcode and { "lua",setcode } or nop, + { "image",{ filename=name,width=wd,height=ht,depth=dp } }, + nilcode and { "lua",nilcode } or nop, + { "special","pdf:direct:"..et }, + } + character.svg=true + end + end + end + end + end +end +fonts.handlers.otf.features.register { + name="svg", + description="svg glyphs", + manipulators={ + base=initializesvg, + node=initializesvg, + } +} + +end -- closure + +do -- begin closure to overcome local limits and interference + if not modules then modules={} end modules ['font-onr']={ version=1.001, comment="companion to font-ini.mkiv", diff --git a/tex/generic/context/luatex/luatex-fonts.lua b/tex/generic/context/luatex/luatex-fonts.lua index 07d9343a7..83d52d9a5 100644 --- a/tex/generic/context/luatex/luatex-fonts.lua +++ b/tex/generic/context/luatex/luatex-fonts.lua @@ -258,6 +258,7 @@ if non_generic_context.luatex_fonts.skip_loading ~= true then loadmodule('font-ota.lua') loadmodule('font-ots.lua') loadmodule('font-osd.lua') + loadmodule('font-ocl.lua') -- svg needs 0.97 (for fix in memstreams) -- type one code -- cgit v1.2.3