From: Henri Menke <henrimenke@gmail.com>
To: ntg-context@ntg.nl
Subject: Metafun: Finding intersection between characters
Date: Sat, 22 Sep 2018 20:35:13 +1200 [thread overview]
Message-ID: <f28355f6-dddc-4cdb-e30c-831662eceeea@gmail.com> (raw)
Dear list,
Challanged by a very old TeX.SX question
https://tex.stackexchange.com/questions/180510
I wanted to calculate all the intersection points between two
characters. Therefore I ripped off the \showshape macro to load the
outlines from the font and convert them to MetaPost paths. Then I try
to find all intersections by cutting the path.
It somewhat works but for some reason, in the MWE below two intersection
points are missing. I also have the feeling that my implementation is
extremely inefficient. I would very much appreciate some hints by the
MetaPost experts!
Cheers, Henri
---
\startluacode
-- That's a simple reimplemetation of the showshape macro
function outlinepaths(character)
local fontid = font.current()
local shapedata = fonts.hashes.shapes[fontid] -- by index
local chardata = fonts.hashes.characters[fontid] -- by unicode
local shapeglyphs = shapedata.glyphs or { }
character = utf.byte(character)
local c = chardata[character]
if c then
if not c.index then
return {}
end
local glyph = shapeglyphs[c.index]
if glyph and (glyph.segments or glyph.sequence) then
local units = shapedata.units or 1000
local factor = 100/units
local paths = fonts.metapost.paths(glyph,factor)
return paths
end
end
end
\stopluacode
\def\mpdefineoutlines#1#2{\ctxlua{
local char = "\luaescapestring{#1}"
local outlines = outlinepaths("#2")
local len = \letterhash outlines
tex.print("path " .. char .. "[];")
tex.print(char .. "n := " .. len .. ";")
for i, path in ipairs(outlines) do
tex.print(char .. "[" .. i .. "] := " .. path .. ";")
end
}}
\starttext
\startMPpage
pair shift; shift := (1cm,-1cm);
numeric angle; angle := 5;
\mpdefineoutlines{B}{B}
\mpdefineoutlines{T}{T}
nofill B2;
nofill B3;
eofill B1 withcolor .5[blue,white];
fill T1 shifted (shift) rotated (angle) withcolor .5[red,white];
path r;
numeric n; n := 0;
for i = 1 upto Bn:
for j = 1 upto Tn:
r := B[i];
forever:
pair q;
r := r cutbefore (T[j] shifted (shift) rotated (angle));
exitif length cuttings = 0;
r := subpath(epsilon, length r) of r;
q = point 0 of r;
n := n + 1;
dotlabel.urt(textext("\tfx" & decimal n), q);
endfor;
endfor ;
endfor ;
\stopMPpage
\stoptext
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
next reply other threads:[~2018-09-22 8:35 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-22 8:35 Henri Menke [this message]
2018-09-22 9:27 ` Hans Hagen
2018-09-22 10:08 ` Floris van Manen
2018-09-22 11:45 ` Hans Hagen
2018-09-22 13:41 ` Alan Braslau
2018-09-22 17:06 ` Hans Hagen
[not found] <mailman.3457.1537623691.2042.ntg-context@ntg.nl>
2018-09-25 23:48 ` Jeong Dal
2018-09-26 7:59 ` Hans Hagen
2018-09-26 11:44 ` Jeong Dal
2018-09-26 10:10 ` Hans Hagen
2018-09-26 12:14 ` Jeong Dal
2018-09-26 12:24 ` Hans Hagen
2018-09-26 21:38 ` Jeong Dal
2018-09-27 8:49 ` Hans Hagen
2018-09-27 15:06 ` Jeong Dal
2018-09-27 15:43 ` Hans Hagen
2018-09-28 10:09 ` Jeong Dal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f28355f6-dddc-4cdb-e30c-831662eceeea@gmail.com \
--to=henrimenke@gmail.com \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).