summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/grph-rul.lua
diff options
context:
space:
mode:
authorContext Git Mirror Bot <phg42.2a@gmail.com>2016-02-20 15:15:08 +0100
committerContext Git Mirror Bot <phg42.2a@gmail.com>2016-02-20 15:15:08 +0100
commit93dce457ab8769ef45a56b2e0f7ad447d7a47a83 (patch)
tree2374ca50eceb2aab1a5d0af0ba26dc129eb19ab6 /tex/context/base/mkiv/grph-rul.lua
parentb13dd166ce8563c60c10affc97ab28940d6a7776 (diff)
downloadcontext-93dce457ab8769ef45a56b2e0f7ad447d7a47a83.tar.gz
2016-02-20 14:58:00
Diffstat (limited to 'tex/context/base/mkiv/grph-rul.lua')
-rw-r--r--tex/context/base/mkiv/grph-rul.lua48
1 files changed, 46 insertions, 2 deletions
diff --git a/tex/context/base/mkiv/grph-rul.lua b/tex/context/base/mkiv/grph-rul.lua
index c0ba5f9d8..4ca36b677 100644
--- a/tex/context/base/mkiv/grph-rul.lua
+++ b/tex/context/base/mkiv/grph-rul.lua
@@ -21,6 +21,11 @@ local a_color = attributes.private('color')
local a_transparency = attributes.private('transparency')
local a_colorspace = attributes.private('colormodel')
+local mpcolor = attributes.colors.mpcolor
+
+local floor = math.floor
+local random = math.random
+
do
local simplemetapost = metapost.simple
@@ -63,16 +68,27 @@ do
endfig ;
]]
+ local predefined = {
+ ["fake:word"] = [[
+fill unitsquare xscaled RuleWidth yscaled RuleHeight withcolor RuleColor ;
+draw (0,RuleDepth+RuleThickness/2) -- (RuleWidth,RuleDepth+RuleThickness/2) withpen pencircle scaled RuleThickness withcolor white ;
+ ]],
+ ["fake:rule"] = [[
+fill unitsquare xscaled RuleWidth yscaled RuleHeight withcolor RuleColor ;
+ ]],
+ }
+
ruleactions.mp = function(p,h,v,i,n)
+ local name = p.name
local code = makecode {
- data = p.data,
+ data = name and predefined[name] or p.data or "",
width = p.width * bpfactor,
height = p.height * bpfactor,
depth = p.depth * bpfactor,
factor = (p.factor or 0) * bpfactor, -- needs checking
offset = p.offset or 0,
line = (p.line or 65536) * bpfactor,
- color = attributes.colors.mpcolor(p.ma,p.ca,p.ta),
+ color = mpcolor(p.ma,p.ca,p.ta),
}
local m = cache[code]
if m and m ~= "" then
@@ -129,6 +145,7 @@ interfaces.implement {
{ "line", "dimension" },
{ "type", "string" },
{ "data", "string" },
+ { "name", "string" },
} } ,
actions = function(t)
if t.type == "mp" then
@@ -141,3 +158,30 @@ interfaces.implement {
end
}
+interfaces.implement {
+ name = "fakeword",
+ arguments = { {
+ { "factor", "dimension" },
+ { "name", "string" }, -- can be type
+ { "min", "dimension" },
+ { "max", "dimension" },
+ { "n", "integer" },
+ } } ,
+ actions = function(t)
+ local factor = t.factor or 0
+ local rule = userrule {
+ height = 1.25*factor,
+ depth = 0.25*factor,
+ width = floor(random(t.min,t.max)/10000) * 10000,
+ line = 0.10*factor,
+ ma = getattribute(a_colorspace) or 1,
+ ca = getattribute(a_color),
+ ta = getattribute(a_transparency),
+ type = "mp",
+ name = t.name,
+ }
+ context(rule)
+ end
+}
+
+