summaryrefslogtreecommitdiff
path: root/tex/context/base/m-punk.mkiv
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2010-08-14 15:56:20 +0300
committerMarius <mariausol@gmail.com>2010-08-14 15:56:20 +0300
commitb469b8ec1b494ab72cd462bfc539ce01440e6aaf (patch)
tree3a9c3fb8433c5f75020fef1d531bedb7c948f66c /tex/context/base/m-punk.mkiv
parent39e30629c15ae4a899532d84c4abea127f2847a6 (diff)
downloadcontext-b469b8ec1b494ab72cd462bfc539ce01440e6aaf.tar.gz
beta 2010.08.10 17:14
Diffstat (limited to 'tex/context/base/m-punk.mkiv')
-rw-r--r--tex/context/base/m-punk.mkiv358
1 files changed, 178 insertions, 180 deletions
diff --git a/tex/context/base/m-punk.mkiv b/tex/context/base/m-punk.mkiv
index 6099ee6f4..3ea738003 100644
--- a/tex/context/base/m-punk.mkiv
+++ b/tex/context/base/m-punk.mkiv
@@ -17,190 +17,195 @@
% ConTeXt MkIV kernel.
\startluacode
-do
- local concat = table.concat
- local chardata = characters.data
- local fontdata = fonts.ids
+local concat = table.concat
+local chardata = characters.data
+local fontdata = fonts.ids
- fonts.mp = fonts.mp or { }
+fonts.mp = fonts.mp or { }
- fonts.mp.version = fonts.mp.version or 1.11
- fonts.mp.inline = true
- fonts.mp.cache = containers.define("fonts", "mp", fonts.mp.version, true)
+fonts.mp.version = fonts.mp.version or 1.15
+fonts.mp.inline = true
+fonts.mp.cache = containers.define("fonts", "mp", fonts.mp.version, true)
- metapost.characters = metapost.characters or { }
+metapost.characters = metapost.characters or { }
-- todo: use table share as in otf
- local characters, descriptions = { }, { }
- local factor, l, n, w, h, d, total, variants = 100, { }, 0, 0, 0, 0, 0, 0, true
-
- -- A next version of mplib will provide the tfm font information which
- -- gives better glyph dimensions, plus additional kerning information.
-
- local flusher = {
- startfigure = function(chrnum,llx,lly,urx,ury)
- l, n = { }, chrnum
- w, h, d = urx - llx, ury, -lly
- total = total + 1
- inline = fonts.mp.inline
- end,
- flushfigure = function(t)
- for i=1, #t do
- l[#l+1] = t[i]
- end
- end,
- stopfigure = function()
- local cd = chardata[n]
- if inline then
- descriptions[n] = {
- -- unicode = n,
- name = cd and cd.adobename,
- width = w*100,
- height = h*100,
- depth = d*100,
- boundingbox = { 0, -d, w, h },
- }
- characters[n] = {
- commands = { -- todo: xforms, should happen in backend
- { "special", "pdf: " .. concat(l," ") },
- }
- }
- else
- descriptions[n] = {
- -- unicode = n,
- name = cd and cd.adobename,
- width = w*100,
- height = h*100,
- depth = d*100,
- boundingbox = { 0, -d, w, h },
- }
- characters[n] = {
- commands = {
- { "image", { stream = concat(l," "), bbox = { 0, -d*65536, w*65536, h*65536 } } },
- }
- }
- end
+local characters, descriptions = { }, { }
+local factor, l, n, w, h, d, total, variants = 100, { }, 0, 0, 0, 0, 0, 0, true
+
+-- A next version of mplib will provide the tfm font information which
+-- gives better glyph dimensions, plus additional kerning information.
+
+local flusher = {
+ startfigure = function(chrnum,llx,lly,urx,ury)
+ l, n = { }, chrnum
+ w, h, d = urx - llx, ury, -lly
+ total = total + 1
+ inline = fonts.mp.inline
+ end,
+ flushfigure = function(t)
+ for i=1, #t do
+ l[#l+1] = t[i]
end
- }
-
- metapost.characters.instances = metapost.characters.instances or 10
-
- function metapost.characters.process(mpxformat, name, instances, scalefactor)
- statistics.starttiming(metapost.characters)
- scalefactor = scalefactor or 1
- instances = instances or metapost.characters.instances or 10
- local fontname = file.removesuffix(file.basename(name))
- local hash = file.robustname(string.format("%s %05i %03i", fontname, scalefactor*1000, instances))
- local lists = containers.read(fonts.mp.cache, hash)
- if not lists then
- statistics.starttiming(flusher)
- -- we can use a format per font
- local data = io.loaddata(resolvers.find_file(name))
- metapost.reset(mpxformat)
- metapost.set_outer_color(2) -- no outer color and no reset either
- lists = { }
- for i=1,instances do
- list = { }
- characters, descriptions = { }, { }
- metapost.process(
- mpxformat,
- {
- "randomseed := " .. i*10 .. ";",
- "scale_factor := " .. scalefactor .. " ;",
- data
- },
- false,
- flusher
- )
- lists[i] = {
- designsize = 655360,
- name = string.format("%s-%03i",hash,i),
- parameters = {
- slant = 0,
- space = 333 * scalefactor,
- space_stretch = 166.5 * scalefactor,
- space_shrink = 111 * scalefactor,
- x_height = 431 * scalefactor,
- quad =1000 * scalefactor,
- extra_space = 0
- },
- ["type"] = "virtual",
- characters = characters,
- descriptions = descriptions,
- -- embedding = "subset",
- -- mkiv:
- spacer = "space",
- unit = 1000,
- shared = { },
- unique = { },
+ end,
+ stopfigure = function()
+ local cd = chardata[n]
+ if inline then
+ descriptions[n] = {
+ -- unicode = n,
+ name = cd and cd.adobename,
+ width = w*100,
+ height = h*100,
+ depth = d*100,
+ boundingbox = { 0, -d, w, h },
+ }
+ characters[n] = {
+ commands = { -- todo: xforms, should happen in backend
+ { "special", "pdf: " .. concat(l," ") },
}
- end
- metapost.reset(mpxformat) -- saves memory
- lists = containers.write(fonts.mp.cache, hash, lists)
- statistics.stoptiming(flusher)
+ }
+ else
+ descriptions[n] = {
+ -- unicode = n,
+ name = cd and cd.adobename,
+ width = w*100,
+ height = h*100,
+ depth = d*100,
+ boundingbox = { 0, -d, w, h },
+ }
+ characters[n] = {
+ commands = {
+ { "image", { stream = concat(l," "), bbox = { 0, -d*65536, w*65536, h*65536 } } },
+ }
+ }
end
- variants = variants + #lists
- statistics.stoptiming(metapost.characters)
- return lists
end
-
- function fonts.vf.aux.combine.commands.metafont(g,v)
- local size = g.specification.size
- local data = metapost.characters.process(v[2],v[3],v[4],size/655360)
- local list, t = { }, { }
- for d=1,#data do
- t = data[d]
- t = fonts.tfm.scale(t, -1000)
- local id = font.nextid()
- t.fonts = { { id = id } }
- fontdata[id] = t
- fonts.vf.aux.compose_characters(t)
- list[d] = font.define(t)
+}
+
+metapost.characters.instances = metapost.characters.instances or 10
+
+function metapost.characters.process(mpxformat, name, instances, scalefactor)
+ statistics.starttiming(metapost.characters)
+ scalefactor = scalefactor or 1
+ instances = instances or metapost.characters.instances or 10
+ local fontname = file.removesuffix(file.basename(name))
+ local hash = file.robustname(string.format("%s %05i %03i", fontname, scalefactor*1000, instances))
+ local lists = containers.read(fonts.mp.cache, hash)
+ if not lists then
+ statistics.starttiming(flusher)
+ -- we can use a format per font
+ local data = io.loaddata(resolvers.find_file(name))
+ metapost.reset(mpxformat)
+ metapost.set_outer_color(2) -- no outer color and no reset either
+ lists = { }
+ for i=1,instances do
+ characters, descriptions = { }, { }
+ metapost.process(
+ mpxformat,
+ {
+ "randomseed := " .. i*10 .. ";",
+ "scale_factor := " .. scalefactor .. " ;",
+ data
+ },
+ false,
+ flusher
+ )
+ lists[i] = {
+ designsize = 655360,
+ name = string.format("%s-%03i",hash,i),
+ parameters = {
+ slant = 0,
+ space = 333 * scalefactor,
+ space_stretch = 166.5 * scalefactor,
+ space_shrink = 111 * scalefactor,
+ x_height = 431 * scalefactor,
+ quad =1000 * scalefactor,
+ extra_space = 0
+ },
+ ["type"] = "virtual",
+ characters = characters,
+ descriptions = descriptions,
+ -- embedding = "subset",
+ -- mkiv:
+ spacer = "space",
+ unit = 1000,
+ shared = { },
+ unique = { },
+ }
end
- for k=1,#t do
- g[k] = t[k] -- kind of replace, when not present, make nil
- end
- g.virtualized = true
- g.variants = list
+ metapost.reset(mpxformat) -- saves memory
+ lists = containers.write(fonts.mp.cache, hash, lists)
+ statistics.stoptiming(flusher)
end
+ variants = variants + #lists
+ statistics.stoptiming(metapost.characters)
+ return lists
+end
- fonts.define.methods.install( "punk", {
- { "metafont", "mfplain", "punkfont.mp", 10 },
- } )
-
- typesetting.cases.actions[99] = function(current)
- local used = fontdata[current.font].variants
- if used then
- local f = math.random(1,#used)
- current.font = used[f]
- return current, true
- else
- return current, false
- end
+function fonts.vf.aux.combine.commands.metafont(g,v)
+ local size = g.specification.size
+ local data = metapost.characters.process(v[2],v[3],v[4],size/655360)
+ local list, t = { }, { }
+ for d=1,#data do
+ t = data[d]
+ t = fonts.tfm.scale(t, -1000)
+ local id = font.nextid()
+ t.fonts = { { id = id } }
+ fontdata[id] = t
+ fonts.vf.aux.compose_characters(t)
+ list[d] = font.define(t)
end
+ for k, v in next, t do
+ g[k] = v -- kind of replace, when not present, make nil
+ end
+ g.virtualized = true
+ g.variants = list
+end
- metapost.characters.flusher = flusher
-
- statistics.register("metapost font generation", function()
- local time = statistics.elapsedtime(flusher)
- if total > 0 then
- return string.format("%i glyphs, %.3f seconds runtime, %i glyphs/second", total, time, total/time)
- else
- return string.format("%i glyphs, %.3f seconds runtime", total, time)
- end
- end)
+fonts.define.methods.install( "punk", {
+ { "metafont", "mfplain", "punkfont.mp", 10 },
+} )
+fonts.define.methods.install( "punkbold", {
+ { "metafont", "mfplain", "punkfont-bold.mp", 10 },
+} )
+fonts.define.methods.install( "punkslanted", {
+ { "metafont", "mfplain", "punkfont-slanted.mp", 10 },
+} )
+fonts.define.methods.install( "punkboldslanted", {
+ { "metafont", "mfplain", "punkfont-boldslanted.mp", 10 },
+} )
+
+typesetting.cases.actions[99] = function(current)
+ local used = fontdata[current.font].variants
+ if used then
+ local f = math.random(1,#used)
+ current.font = used[f]
+ return current, true
+ else
+ return current, false
+ end
+end
- statistics.register("metapost font loading",function()
- local time = statistics.elapsedtime(metapost.characters)
- if variants > 0 then
- return string.format("%.3f seconds, %i instances, %0.3f instances/second", time, variants, variants/time)
- else
- return string.format("%.3f seconds, %i instances", time, variants)
- end
- end)
+metapost.characters.flusher = flusher
-end
+statistics.register("metapost font generation", function()
+ local time = statistics.elapsedtime(flusher)
+ if total > 0 then
+ return string.format("%i glyphs, %.3f seconds runtime, %i glyphs/second", total, time, total/time)
+ else
+ return string.format("%i glyphs, %.3f seconds runtime", total, time)
+ end
+end)
+
+statistics.register("metapost font loading",function()
+ local time = statistics.elapsedtime(metapost.characters)
+ if variants > 0 then
+ return string.format("%.3f seconds, %i instances, %0.3f instances/second", time, variants, variants/time)
+ else
+ return string.format("%.3f seconds, %i instances", time, variants)
+ end
+end)
\stopluacode
\unexpanded\def\EnableRandomPunk {\setcharactercasing[99]}
@@ -209,25 +214,18 @@ end
\unexpanded\def\StopRandomPunk {\endgroup}
\starttypescript [serif] [punk] [default]
- \setups[font:fallback:serif] % no style variants yet
- \definefontsynonym [Serif] [demo@punk]
+ \definefontsynonym [Serif] [demo@punk]
+ \definefontsynonym [SerifBold] [demobold@punkbold]
+ \definefontsynonym [SerifSlanted] [demoslanted@punkslanted]
+ \definefontsynonym [SerifBoldSlanted] [demoboldslanted@punkboldslanted]
+ \definefontsynonym [SerifItalic] [SerifSlanted]
+ \definefontsynonym [SerifBoldItalic] [SerifBoldSlanted]
\stoptypescript
\starttypescript [punk]
\definetypeface [punk] [rm] [serif] [punk] [default]
\stoptypescript
-% \definefontfeature[punknova][mode=node,script=latn,rand=yes,kern=yes,liga=yes,tlig=yes]
-
-% \starttypescript [serif] [punknova]
-% \setups[font:fallback:serif] % no style variants yet, actually it's a sans
-% \definefontsynonym [Serif] [file:punknova] [features=punknova]
-% \stoptypescript
-
-% \starttypescript [punknova]
-% \definetypeface [punknova] [rm] [serif] [punknova] [default]
-% \stoptypescript
-
\endinput
\usetypescript[punk]