diff options
author | Context Git Mirror Bot <phg42.2a@gmail.com> | 2016-01-12 17:15:07 +0100 |
---|---|---|
committer | Context Git Mirror Bot <phg42.2a@gmail.com> | 2016-01-12 17:15:07 +0100 |
commit | 8d8d528d2ad52599f11250cfc567fea4f37f2a8b (patch) | |
tree | 94286bc131ef7d994f9432febaf03fe23d10eef8 /tex/context/base/mkiv/blob-ini.lua | |
parent | f5aed2e51223c36c84c5f25a6cad238b2af59087 (diff) | |
download | context-8d8d528d2ad52599f11250cfc567fea4f37f2a8b.tar.gz |
2016-01-12 16:26:00
Diffstat (limited to 'tex/context/base/mkiv/blob-ini.lua')
-rw-r--r-- | tex/context/base/mkiv/blob-ini.lua | 203 |
1 files changed, 203 insertions, 0 deletions
diff --git a/tex/context/base/mkiv/blob-ini.lua b/tex/context/base/mkiv/blob-ini.lua new file mode 100644 index 000000000..b837250ce --- /dev/null +++ b/tex/context/base/mkiv/blob-ini.lua @@ -0,0 +1,203 @@ +if not modules then modules = { } end modules ['blob-ini'] = { + version = 1.001, + comment = "companion to blob-ini.mkiv", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +-- Experimental ... names and functionality will change ... just a +-- place to collect code, so: +-- +-- DON'T USE THESE FUNCTIONS AS THEY WILL CHANGE! +-- +-- This module is just a playground. Occasionally we need to typeset +-- at the lua and and this is one method. In principle we can construct +-- pages this way too which sometimes makes sense in dumb cases. Actually, +-- if one only needs this, one does not really need tex, okay maybe the +-- parbuilder but that one can be simplified as well then. + +-- set fonts, attributes +-- rest already done in packers etc +-- add local par whatsit (or wait till cleaned up) +-- collapse or new pars +-- interline spacing etc + +-- blob.char +-- blob.line +-- blob.paragraph +-- blob.page + +local type, tostring = type, tostring +local lpegmatch, lpegpatterns = lpeg.match, lpeg.patterns + +local report_blobs = logs.reporter("blobs") + +local flush_node_list = node.flush_list +local hpack_node_list = node.hpack +local vpack_node_list = node.vpack +local write_node = node.write + +local typesetters = nodes.typesetters +local tonodes = typesetters.tonodes +local tohpack = typesetters.tohpack +local tohpackfast = typesetters.tohpackfast +local tovpack = typesetters.tovpack +local tovpackfast = typesetters.tovpackfast + +local implement = interfaces.implement + +blobs = blobs or { } + +-- provide copies here (nicer for manuals) + +blobs.tonodes = tonodes +blobs.tohpack = tohpack +blobs.tohpackfast = tohpackfast +blobs.tovpack = tovpack +blobs.tovpackfast = tovpackfast + +-- end of helpers + +local newline = lpeg.patterns.newline +local space = lpeg.patterns.spacer +local newpar = (space^0*newline*space^0)^2 + +local ctxtextcapture = lpeg.Ct ( ( space^0 * ( newpar + lpeg.Cs(((space^1/" " + 1)-newpar)^1) ) )^0) + +function blobs.new() + return { + list = { }, + } +end + +function blobs.dispose(t) + local list = t.list + for i=1,#list do + local li = list[i] + local pack = li.pack + if pack then + flush_node_list(pack) + li.pack = nil + end + end +end + +function blobs.append(t,str) -- compare concat and link + local typ = type(str) + local dummy = nil + if typ == "number" then + str = tostring(str) + typ = "string" + end + if typ == "string" then + local pars = lpegmatch(ctxtextcapture,str) + local list = t.list + for p=1,#pars do + local head, tail = tonodes(pars[p],nil,nil) + list[#list+1] = { head = head, tail = tail } + end + end +end + +function blobs.pack(t,how) + local list = t.list + for i=1,#list do + local pack = list[i].pack + if pack then + flush_node_list(node.pack) + end + if how == "vertical" then + -- we need to prepend a local par node + -- list[i].pack = vpack_node_list(list[i].head,"exactly") + report_blobs("vpack not yet supported") + else + list[i].pack = hpack_node_list(list[i].head,"exactly") + end + end +end + +function blobs.write(t) + local list = t.list + for i=1,#list do + local li = list[i] + local pack = li.pack + if pack then + write_node(pack) + flush_node_list(pack) + li.pack = nil + end + end +end + +function blobs.dimensions(t) + local list = t.list + local first = list and list[1] + if first then + local pack = first.pack + return pack.width, pack.height, pack.depth + else + return 0, 0, 0 + end +end + +-- blob.char +-- blob.line: head, tail +-- blob.paragraph +-- blob.page + +--~ local lineblob = { +--~ type = "line", +--~ head = false, +--~ tail = false, +--~ pack = false, +--~ properties = { }, +--~ end + +--~ local parblob = { +--~ type = "line", +--~ head = false, +--~ tail = false, +--~ pack = false, +--~ properties = { }, +--~ end + +-- for the moment here: + +local function strwd(str) + local l = tohpack(str) + local w = l.width + flush_node_list(l) + return w +end + +local function strht(str) + local l = tohpack(str) + local h = l.height + flush_node_list(l) + return h +end + +local function strdp(str) + local l = tohpack(str) + local d = l.depth + flush_node_list(l) + return d +end + +local function strhd(str) + local l = tohpack(str) + local s = l.height + l.depth + flush_node_list(l) + return s +end + +blobs.strwd = strwd +blobs.strht = strht +blobs.strdp = strdp +blobs.strhd = strhd + +implement { name = "strwd", arguments = "string", actions = { strwd, context } } +implement { name = "strht", arguments = "string", actions = { strht, context } } +implement { name = "strdp", arguments = "string", actions = { strdp, context } } +implement { name = "strhd", arguments = "string", actions = { strhd, context } } |