ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Metafun: Finding intersection between characters
@ 2018-09-22  8:35 Henri Menke
  2018-09-22  9:27 ` Hans Hagen
  0 siblings, 1 reply; 17+ messages in thread
From: Henri Menke @ 2018-09-22  8:35 UTC (permalink / raw)
  To: ntg-context

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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Metafun: Finding intersection between characters
  2018-09-22  8:35 Metafun: Finding intersection between characters Henri Menke
@ 2018-09-22  9:27 ` Hans Hagen
  2018-09-22 10:08   ` Floris van Manen
  0 siblings, 1 reply; 17+ messages in thread
From: Hans Hagen @ 2018-09-22  9:27 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Henri Menke

On 9/22/2018 10:35 AM, Henri Menke wrote:
> 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

You migh find more when you go top double mode .. anyway, these 
intersection calculations are not that accurate so you normally need to 
apply some overkill.

- a bit cleaned up outlinepath function
- use document namespace
- add helper for defineoutline
- do 4 runs over the shapes (probably too many now)
- more neutral fill code

It makes a nice example for the metafun (although then I'd do it 
slightly different). We need some rounding becaus eotherwise you get 
similar points (you can add a message(q) someplace).

\startluacode

function document.outlinepaths(character)
     local chardata  = fonts.hashes.characters[true] -- by unicode
     local shapedata = fonts.hashes.shapes[true] -- by index
     local c         = chardata[character]
     if c and c.index and shapedata then
         local shapeglyphs = shapedata.glyphs or { }
         local glyph       = shapeglyphs[c.index]
         if glyph and (glyph.segments or glyph.sequence) then
             local units  = shapedata.units or 1000
             local factor = 100/units
             return fonts.metapost.paths(glyph,factor)
         end
     end
     return { }
end

function document.defineoutline(char,target)
     local outlines = document.outlinepaths(char)
     local nofpaths = #outlines
     context("path %s[] ;",target)
     context("numeric %sn ; %sn := %s ;",target,target,nofpaths)
     for i=1,nofpaths do
         context("%s[%i] := %s ; ",target,i,outlines[i])
     end
end
\stopluacode

\def\mpdefineoutlines#1#2{\ctxlua{document.defineoutline(\number`#1,"#2")}}

\starttext

\startMPpage
pair shift ; shift := (1cm,-1cm);
numeric angle ; angle := 5;

\mpdefineoutlines{B}{B}
\mpdefineoutlines{T}{T}

for i=1 upto Bn - 1 : nofill B[i] ; endfor ;
eofill B[Bn] withcolor .5[blue,white] ;

for i=1 upto Tn :
     T[i] := T[i] shifted shift rotated angle ;
endfor ;

for i=1 upto Tn - 1 : nofill T[i] ; endfor ;
eofill T[Tn] withcolor .5[red,white] ;

pair found[] ;
boolean isnew ;
numeric n ; n := 0 ;
pair rq ;

def GoForIt(expr how) =
     path r ;
     for i = 1 upto Bn :
         for j = 1 upto Tn :
             r := B[i] ;
             forever:
                 pair q ;
                 if how = 1 :
                     r := r cutbefore T[j] ;
                 elseif how = 2 :
                     r := r cutbefore reverse T[j] ;
                 elseif how = 3 :
                     r := reverse r cutbefore T[j] ;
                 else :
                     r := reverse r cutbefore reverse T[j] ;
                 fi ;
                 exitif length cuttings = 0 ;
                 r := subpath(epsilon, length r) of r ;
                 q = point 0 of r ;
                 isnew := true ;
                 rq := round(q);
                 for f=1 upto n :
                     if found[f] = rq :
                         isnew := false ;
                         exitif true ;
                     fi ;
                 endfor ;
                 if isnew :
                     n := n + 1 ;
                     drawdot q withpen pencircle scaled 4 ;
                     draw textext("\strut\ttbf " & decimal n) ysized 3 
shifted q withcolor white ;
                     found[n] := rq ;
                 fi ;
             endfor;
         endfor ;
     endfor ;
enddef ;

for i=1 upto 4 : GoForIt(i) ; endfor ;

\stopMPpage

\stoptext




-- 

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Metafun: Finding intersection between characters
  2018-09-22  9:27 ` Hans Hagen
@ 2018-09-22 10:08   ` Floris van Manen
  2018-09-22 11:45     ` Hans Hagen
  0 siblings, 1 reply; 17+ messages in thread
From: Floris van Manen @ 2018-09-22 10:08 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1.1: Type: text/plain, Size: 7481 bytes --]

It does not seem to work for all character combinations.
e.g. B&T works, C&T works, C&M works, but N&T does not work.
not N&M
Why would that be?
Thanks
.Floris





> On 22 Sep 2018, at 11:27, Hans Hagen <j.hagen@xs4all.nl> wrote:
> 
> On 9/22/2018 10:35 AM, Henri Menke wrote:
>> 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
> 
> You migh find more when you go top double mode .. anyway, these intersection calculations are not that accurate so you normally need to apply some overkill.
> 
> - a bit cleaned up outlinepath function
> - use document namespace
> - add helper for defineoutline
> - do 4 runs over the shapes (probably too many now)
> - more neutral fill code
> 
> It makes a nice example for the metafun (although then I'd do it slightly different). We need some rounding becaus eotherwise you get similar points (you can add a message(q) someplace).
> 
> \startluacode
> 
> function document.outlinepaths(character)
>    local chardata  = fonts.hashes.characters[true] -- by unicode
>    local shapedata = fonts.hashes.shapes[true] -- by index
>    local c         = chardata[character]
>    if c and c.index and shapedata then
>        local shapeglyphs = shapedata.glyphs or { }
>        local glyph       = shapeglyphs[c.index]
>        if glyph and (glyph.segments or glyph.sequence) then
>            local units  = shapedata.units or 1000
>            local factor = 100/units
>            return fonts.metapost.paths(glyph,factor)
>        end
>    end
>    return { }
> end
> 
> function document.defineoutline(char,target)
>    local outlines = document.outlinepaths(char)
>    local nofpaths = #outlines
>    context("path %s[] ;",target)
>    context("numeric %sn ; %sn := %s ;",target,target,nofpaths)
>    for i=1,nofpaths do
>        context("%s[%i] := %s ; ",target,i,outlines[i])
>    end
> end
> \stopluacode
> 
> \def\mpdefineoutlines#1#2{\ctxlua{document.defineoutline(\number`#1,"#2")}}
> 
> \starttext
> 
> \startMPpage
> pair shift ; shift := (1cm,-1cm);
> numeric angle ; angle := 5;
> 
> \mpdefineoutlines{B}{B}
> \mpdefineoutlines{T}{T}
> 
> for i=1 upto Bn - 1 : nofill B[i] ; endfor ;
> eofill B[Bn] withcolor .5[blue,white] ;
> 
> for i=1 upto Tn :
>    T[i] := T[i] shifted shift rotated angle ;
> endfor ;
> 
> for i=1 upto Tn - 1 : nofill T[i] ; endfor ;
> eofill T[Tn] withcolor .5[red,white] ;
> 
> pair found[] ;
> boolean isnew ;
> numeric n ; n := 0 ;
> pair rq ;
> 
> def GoForIt(expr how) =
>    path r ;
>    for i = 1 upto Bn :
>        for j = 1 upto Tn :
>            r := B[i] ;
>            forever:
>                pair q ;
>                if how = 1 :
>                    r := r cutbefore T[j] ;
>                elseif how = 2 :
>                    r := r cutbefore reverse T[j] ;
>                elseif how = 3 :
>                    r := reverse r cutbefore T[j] ;
>                else :
>                    r := reverse r cutbefore reverse T[j] ;
>                fi ;
>                exitif length cuttings = 0 ;
>                r := subpath(epsilon, length r) of r ;
>                q = point 0 of r ;
>                isnew := true ;
>                rq := round(q);
>                for f=1 upto n :
>                    if found[f] = rq :
>                        isnew := false ;
>                        exitif true ;
>                    fi ;
>                endfor ;
>                if isnew :
>                    n := n + 1 ;
>                    drawdot q withpen pencircle scaled 4 ;
>                    draw textext("\strut\ttbf " & decimal n) ysized 3 shifted q withcolor white ;
>                    found[n] := rq ;
>                fi ;
>            endfor;
>        endfor ;
>    endfor ;
> enddef ;
> 
> for i=1 upto 4 : GoForIt(i) ; endfor ;
> 
> \stopMPpage
> 
> \stoptext
> 
> 
> 
> 
> --
> 
> -----------------------------------------------------------------
>                                          Hans Hagen | PRAGMA ADE
>              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
>       tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
> -----------------------------------------------------------------
> ___________________________________________________________________________________
> 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
> ___________________________________________________________________________________


[-- Attachment #1.1.2.1: Type: text/html, Size: 13197 bytes --]

[-- Attachment #1.1.2.2: Screen Shot 2018-09-22 at 12.04.54.PNG --]
[-- Type: image/png, Size: 17676 bytes --]

[-- Attachment #1.2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 492 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Metafun: Finding intersection between characters
  2018-09-22 10:08   ` Floris van Manen
@ 2018-09-22 11:45     ` Hans Hagen
  2018-09-22 13:41       ` Alan Braslau
  0 siblings, 1 reply; 17+ messages in thread
From: Hans Hagen @ 2018-09-22 11:45 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Floris van Manen

On 9/22/2018 12:08 PM, Floris van Manen wrote:
> It does not seem to work for all character combinations.
> e.g. B&T works, C&T works, C&M works, but N&T does not work.
> not N&M
> Why would that be?
> Thanks
> .Floris
> 
> 
> 
> 
>> On 22 Sep 2018, at 11:27, Hans Hagen <j.hagen@xs4all.nl 
>> <mailto:j.hagen@xs4all.nl>> wrote:
>>
>> On 9/22/2018 10:35 AM, Henri Menke wrote:
>>> 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
>>
>> You migh find more when you go top double mode .. anyway, these 
>> intersection calculations are not that accurate so you normally need 
>> to apply some overkill.
>>
>> - a bit cleaned up outlinepath function
>> - use document namespace
>> - add helper for defineoutline
>> - do 4 runs over the shapes (probably too many now)
>> - more neutral fill code
>>
>> It makes a nice example for the metafun (although then I'd do it 
>> slightly different). We need some rounding becaus eotherwise you get 
>> similar points (you can add a message(q) someplace).
>>
>> \startluacode
>>
>> function document.outlinepaths(character)
>>    local chardata  = fonts.hashes.characters[true] -- by unicode
>>    local shapedata = fonts.hashes.shapes[true] -- by index
>>    local c         = chardata[character]
>>    if c and c.index and shapedata then
>>        local shapeglyphs = shapedata.glyphs or { }
>>        local glyph       = shapeglyphs[c.index]
>>        if glyph and (glyph.segments or glyph.sequence) then
>>            local units  = shapedata.units or 1000
>>            local factor = 100/units
>>            return fonts.metapost.paths(glyph,factor)
>>        end
>>    end
>>    return { }
>> end
>>
>> function document.defineoutline(char,target)
>>    local outlines = document.outlinepaths(char)
>>    local nofpaths = #outlines
>>    context("path %s[] ;",target)
>>    context("numeric %sn ; %sn := %s ;",target,target,nofpaths)
>>    for i=1,nofpaths do
>>        context("%s[%i] := %s ; ",target,i,outlines[i])
>>    end
>> end
>> \stopluacode
>>
>> \def\mpdefineoutlines#1#2{\ctxlua{document.defineoutline(\number`#1,"#2")}}
>>
>> \starttext
>>
>> \startMPpage
>> pair shift ; shift := (1cm,-1cm);
>> numeric angle ; angle := 5;
>>
>> \mpdefineoutlines{B}{B}
>> \mpdefineoutlines{T}{T}
>>
>> for i=1 upto Bn - 1 : nofill B[i] ; endfor ;
>> eofill B[Bn] withcolor .5[blue,white] ;
>>
>> for i=1 upto Tn :
>>    T[i] := T[i] shifted shift rotated angle ;
>> endfor ;
>>
>> for i=1 upto Tn - 1 : nofill T[i] ; endfor ;
>> eofill T[Tn] withcolor .5[red,white] ;
>>
>> pair found[] ;
>> boolean isnew ;
>> numeric n ; n := 0 ;
>> pair rq ;
>>
>> def GoForIt(expr how) =
>>    path r ;
>>    for i = 1 upto Bn :
>>        for j = 1 upto Tn :
>>            r := B[i] ;
>>            forever:
>>                pair q ;
>>                if how = 1 :
>>                    r := r cutbefore T[j] ;
>>                elseif how = 2 :
>>                    r := r cutbefore reverse T[j] ;
>>                elseif how = 3 :
>>                    r := reverse r cutbefore T[j] ;
>>                else :
>>                    r := reverse r cutbefore reverse T[j] ;
>>                fi ;
>>                exitif length cuttings = 0 ;
>>                r := subpath(epsilon, length r) of r ;
>>                q = point 0 of r ;
>>                isnew := true ;
>>                rq := round(q);
>>                for f=1 upto n :
>>                    if found[f] = rq :
>>                        isnew := false ;
>>                        exitif true ;
>>                    fi ;
>>                endfor ;
>>                if isnew :
>>                    n := n + 1 ;
>>                    drawdot q withpen pencircle scaled 4 ;
>>                    draw textext("\strut\ttbf " & decimal n) ysized 3 
>> shifted q withcolor white ;
>>                    found[n] := rq ;
>>                fi ;
>>            endfor;
>>        endfor ;
>>    endfor ;
>> enddef ;
>>
>> for i=1 upto 4 : GoForIt(i) ; endfor ;
>>
>> \stopMPpage
>>
>> \stoptext
Ok, a different approach then (probably still not all points as we need 
to loop over segments but better) .. no more time now.

It also shows that we don't need lua/tex juggling as we already can have 
the paths in mp. (For sure now someone can complain that this is not 
well documented.)

\starttext

\startMPdefinitions

     % will be added to metafun:

     def filloutlinetext(expr o) =
         draw image (
             save n, m ; numeric n, m ; n := m := 0 ;
             for i within o :
                 n := n + 1 ;
             endfor ;
             for i within o :
                 m := m + 1 ;
                 if n = m :
                     eofill
                 else :
                     nofill
                 fi pathpart i ;
             endfor ;
         )
     enddef ;

     def drawoutlinetext(expr o) =
         draw image (
             % nicer for properties
             for i within o :
                 draw pathpart i ;
             endfor ;
         )
     enddef ;

     def outlinetexttopath(text o, p, n) =
         scantokens("numeric " & str n &   ";") ;
         scantokens("path "    & str p & "[];") ;
         n := 0 ;
         for i within o : p[incr(n)] := pathpart i ; endfor ;
     enddef ;

\stopMPdefinitions

\startMPdefinitions

     % outlinetexttopath(Bo)(B)(Bn) ;
     %
     % Bn := listsize(T)

     def showoverlapinoutlines(expr first, second) =

         path p_i, p_j, s_i, s_j ;
         numeric n_i, n_j, index ;
         pair found ;
         index := 0 ;
         for i within first :
             for j within second :
                 p_i := pathpart i ; n_i := length(p_i) ;
                 p_j := pathpart j ; n_j := length(p_j) ;
                 for ii = 0 upto n_i - 1 :
                     s_i := subpath(ii,ii+1) of p_i ;
                     for jj = 0 upto n_j - 1 :
                         s_j := subpath(jj,jj+1) of p_j ;
                         found := s_i intersection_point s_j ;
                         if intersection_found :
                             index := index + 1 ;
                             drawdot found withpen pencircle scaled 4 
withtransparency (1,.5);
                             draw textext("\strut\ttbf " & decimal 
index) ysized 3 shifted found withcolor white withtransparency (1,.5);
                         fi ;
                     endfor ;
                 endfor ;
             endfor ;
         endfor ;

     enddef ;

\stopMPdefinitions

\startMPpage

     picture first  ; first  := outlinetext.p("N") ; first  := first 
scaled 10 ;
     picture second ; second := outlinetext.p("T") ; second := second 
scaled 10 ;

     second := second rotatedaround(center second, 5) shifted (1,-1) ;

     filloutlinetext(first ) withcolor .5[blue,white] ;
     filloutlinetext(second) withcolor .5[red,white] ;

     drawoutlinetext(first ) ;
     drawoutlinetext(second) ;

     showoverlapinoutlines(first, second) ;

\stopMPpage

\startMPdefinitions

     def showoverlap(expr f, s) =
         picture first  ; first  := outlinetext.p(f) ; first  := first 
scaled 10 ;
         picture second ; second := outlinetext.p(s) ; second := second 
scaled 10 ;

         filloutlinetext(first ) withcolor .5blue ;
         drawoutlinetext(first ) ;

         filloutlinetext(second) withcolor .5red  ;
         drawoutlinetext(second) ;

         showoverlapinoutlines(first, second) ;
     enddef ;

\stopMPdefinitions

\startMPpage
     showoverlap("N","T") ;
\stopMPpage

\startMPpage
     showoverlap("\$","Q") ;
\stopMPpage

\startMPpage
     showoverlap("\tttf ABC","\tttf PQR") ;
\stopMPpage

\stoptext




-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Metafun: Finding intersection between characters
  2018-09-22 11:45     ` Hans Hagen
@ 2018-09-22 13:41       ` Alan Braslau
  2018-09-22 17:06         ` Hans Hagen
  0 siblings, 1 reply; 17+ messages in thread
From: Alan Braslau @ 2018-09-22 13:41 UTC (permalink / raw)
  To: Hans Hagen; +Cc: mailing list for ConTeXt users

On Sat, 22 Sep 2018 13:45:17 +0200
Hans Hagen <j.hagen@xs4all.nl> wrote:

> On 9/22/2018 12:08 PM, Floris van Manen wrote:
> > It does not seem to work for all character combinations.
> > e.g. B&T works, C&T works, C&M works, but N&T does not work.
> > not N&M
> > Why would that be?
> > Thanks
> > .Floris
> > 
> > 
> > 
> > 
> >> On 22 Sep 2018, at 11:27, Hans Hagen <j.hagen@xs4all.nl 
> >> <mailto:j.hagen@xs4all.nl>> wrote:
> >>
> >> On 9/22/2018 10:35 AM, Henri Menke wrote:
> >>> 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
> >>
> >> You migh find more when you go top double mode .. anyway, these 
> >> intersection calculations are not that accurate so you normally need 
> >> to apply some overkill.
> >>
> >> - a bit cleaned up outlinepath function
> >> - use document namespace
> >> - add helper for defineoutline
> >> - do 4 runs over the shapes (probably too many now)
> >> - more neutral fill code
> >>
> >> It makes a nice example for the metafun (although then I'd do it 
> >> slightly different). We need some rounding becaus eotherwise you get 
> >> similar points (you can add a message(q) someplace).
> >>
> >> \startluacode
> >>
> >> function document.outlinepaths(character)
> >>    local chardata  = fonts.hashes.characters[true] -- by unicode
> >>    local shapedata = fonts.hashes.shapes[true] -- by index
> >>    local c         = chardata[character]
> >>    if c and c.index and shapedata then
> >>        local shapeglyphs = shapedata.glyphs or { }
> >>        local glyph       = shapeglyphs[c.index]
> >>        if glyph and (glyph.segments or glyph.sequence) then
> >>            local units  = shapedata.units or 1000
> >>            local factor = 100/units
> >>            return fonts.metapost.paths(glyph,factor)
> >>        end
> >>    end
> >>    return { }
> >> end
> >>
> >> function document.defineoutline(char,target)
> >>    local outlines = document.outlinepaths(char)
> >>    local nofpaths = #outlines
> >>    context("path %s[] ;",target)
> >>    context("numeric %sn ; %sn := %s ;",target,target,nofpaths)
> >>    for i=1,nofpaths do
> >>        context("%s[%i] := %s ; ",target,i,outlines[i])
> >>    end
> >> end
> >> \stopluacode
> >>
> >> \def\mpdefineoutlines#1#2{\ctxlua{document.defineoutline(\number`#1,"#2")}}
> >>
> >> \starttext
> >>
> >> \startMPpage
> >> pair shift ; shift := (1cm,-1cm);
> >> numeric angle ; angle := 5;
> >>
> >> \mpdefineoutlines{B}{B}
> >> \mpdefineoutlines{T}{T}
> >>
> >> for i=1 upto Bn - 1 : nofill B[i] ; endfor ;
> >> eofill B[Bn] withcolor .5[blue,white] ;
> >>
> >> for i=1 upto Tn :
> >>    T[i] := T[i] shifted shift rotated angle ;
> >> endfor ;
> >>
> >> for i=1 upto Tn - 1 : nofill T[i] ; endfor ;
> >> eofill T[Tn] withcolor .5[red,white] ;
> >>
> >> pair found[] ;
> >> boolean isnew ;
> >> numeric n ; n := 0 ;
> >> pair rq ;
> >>
> >> def GoForIt(expr how) =
> >>    path r ;
> >>    for i = 1 upto Bn :
> >>        for j = 1 upto Tn :
> >>            r := B[i] ;
> >>            forever:
> >>                pair q ;
> >>                if how = 1 :
> >>                    r := r cutbefore T[j] ;
> >>                elseif how = 2 :
> >>                    r := r cutbefore reverse T[j] ;
> >>                elseif how = 3 :
> >>                    r := reverse r cutbefore T[j] ;
> >>                else :
> >>                    r := reverse r cutbefore reverse T[j] ;
> >>                fi ;
> >>                exitif length cuttings = 0 ;
> >>                r := subpath(epsilon, length r) of r ;
> >>                q = point 0 of r ;
> >>                isnew := true ;
> >>                rq := round(q);
> >>                for f=1 upto n :
> >>                    if found[f] = rq :
> >>                        isnew := false ;
> >>                        exitif true ;
> >>                    fi ;
> >>                endfor ;
> >>                if isnew :
> >>                    n := n + 1 ;
> >>                    drawdot q withpen pencircle scaled 4 ;
> >>                    draw textext("\strut\ttbf " & decimal n) ysized 3 
> >> shifted q withcolor white ;
> >>                    found[n] := rq ;
> >>                fi ;
> >>            endfor;
> >>        endfor ;
> >>    endfor ;
> >> enddef ;
> >>
> >> for i=1 upto 4 : GoForIt(i) ; endfor ;
> >>
> >> \stopMPpage
> >>
> >> \stoptext
> Ok, a different approach then (probably still not all points as we need 
> to loop over segments but better) .. no more time now.
> 
> It also shows that we don't need lua/tex juggling as we already can have 
> the paths in mp. (For sure now someone can complain that this is not 
> well documented.)
> 
> \starttext
> 
> \startMPdefinitions
> 
>      % will be added to metafun:
> 
>      def filloutlinetext(expr o) =
>          draw image (
>              save n, m ; numeric n, m ; n := m := 0 ;
>              for i within o :
>                  n := n + 1 ;
>              endfor ;
>              for i within o :
>                  m := m + 1 ;
>                  if n = m :
>                      eofill
>                  else :
>                      nofill
>                  fi pathpart i ;
>              endfor ;
>          )
>      enddef ;
> 
>      def drawoutlinetext(expr o) =
>          draw image (
>              % nicer for properties
>              for i within o :
>                  draw pathpart i ;
>              endfor ;
>          )
>      enddef ;
> 
>      def outlinetexttopath(text o, p, n) =
>          scantokens("numeric " & str n &   ";") ;
>          scantokens("path "    & str p & "[];") ;
>          n := 0 ;
>          for i within o : p[incr(n)] := pathpart i ; endfor ;
>      enddef ;
> 
> \stopMPdefinitions
> 
> \startMPdefinitions
> 
>      % outlinetexttopath(Bo)(B)(Bn) ;
>      %
>      % Bn := listsize(T)
> 
>      def showoverlapinoutlines(expr first, second) =
> 
>          path p_i, p_j, s_i, s_j ;
>          numeric n_i, n_j, index ;
>          pair found ;
>          index := 0 ;
>          for i within first :
>              for j within second :
>                  p_i := pathpart i ; n_i := length(p_i) ;
>                  p_j := pathpart j ; n_j := length(p_j) ;
>                  for ii = 0 upto n_i - 1 :
>                      s_i := subpath(ii,ii+1) of p_i ;
>                      for jj = 0 upto n_j - 1 :
>                          s_j := subpath(jj,jj+1) of p_j ;
>                          found := s_i intersection_point s_j ;
>                          if intersection_found :
>                              index := index + 1 ;
>                              drawdot found withpen pencircle scaled 4 
> withtransparency (1,.5);
>                              draw textext("\strut\ttbf " & decimal 
> index) ysized 3 shifted found withcolor white withtransparency (1,.5);
>                          fi ;
>                      endfor ;
>                  endfor ;
>              endfor ;
>          endfor ;
> 
>      enddef ;
> 
> \stopMPdefinitions
> 
> \startMPpage
> 
>      picture first  ; first  := outlinetext.p("N") ; first  := first 
> scaled 10 ;
>      picture second ; second := outlinetext.p("T") ; second := second 
> scaled 10 ;
> 
>      second := second rotatedaround(center second, 5) shifted (1,-1) ;
> 
>      filloutlinetext(first ) withcolor .5[blue,white] ;
>      filloutlinetext(second) withcolor .5[red,white] ;
> 
>      drawoutlinetext(first ) ;
>      drawoutlinetext(second) ;
> 
>      showoverlapinoutlines(first, second) ;
> 
> \stopMPpage
> 
> \startMPdefinitions
> 
>      def showoverlap(expr f, s) =
>          picture first  ; first  := outlinetext.p(f) ; first  := first 
> scaled 10 ;
>          picture second ; second := outlinetext.p(s) ; second := second 
> scaled 10 ;
> 
>          filloutlinetext(first ) withcolor .5blue ;
>          drawoutlinetext(first ) ;
> 
>          filloutlinetext(second) withcolor .5red  ;
>          drawoutlinetext(second) ;
> 
>          showoverlapinoutlines(first, second) ;
>      enddef ;
> 
> \stopMPdefinitions
> 
> \startMPpage
>      showoverlap("N","T") ;
> \stopMPpage
> 
> \startMPpage
>      showoverlap("\$","Q") ;
> \stopMPpage
> 
> \startMPpage
>      showoverlap("\tttf ABC","\tttf PQR") ;
> \stopMPpage
> 
> \stoptext


Take a look, also, at the crossingunder macro in mp-tool.mpiv

Alan

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Metafun: Finding intersection between characters
  2018-09-22 13:41       ` Alan Braslau
@ 2018-09-22 17:06         ` Hans Hagen
  0 siblings, 0 replies; 17+ messages in thread
From: Hans Hagen @ 2018-09-22 17:06 UTC (permalink / raw)
  To: Alan Braslau; +Cc: mailing list for ConTeXt users

On 9/22/2018 3:41 PM, Alan Braslau wrote:
> On Sat, 22 Sep 2018 13:45:17 +0200
> Hans Hagen <j.hagen@xs4all.nl> wrote:
> 
>> On 9/22/2018 12:08 PM, Floris van Manen wrote:
>>> It does not seem to work for all character combinations.
>>> e.g. B&T works, C&T works, C&M works, but N&T does not work.
>>> not N&M
>>> Why would that be?
>>> Thanks
>>> .Floris
>>>
>>>
>>>
>>>
>>>> On 22 Sep 2018, at 11:27, Hans Hagen <j.hagen@xs4all.nl
>>>> <mailto:j.hagen@xs4all.nl>> wrote:
>>>>
>>>> On 9/22/2018 10:35 AM, Henri Menke wrote:
>>>>> 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
>>>>
>>>> You migh find more when you go top double mode .. anyway, these
>>>> intersection calculations are not that accurate so you normally need
>>>> to apply some overkill.
>>>>
>>>> - a bit cleaned up outlinepath function
>>>> - use document namespace
>>>> - add helper for defineoutline
>>>> - do 4 runs over the shapes (probably too many now)
>>>> - more neutral fill code
>>>>
>>>> It makes a nice example for the metafun (although then I'd do it
>>>> slightly different). We need some rounding becaus eotherwise you get
>>>> similar points (you can add a message(q) someplace).
>>>>
>>>> \startluacode
>>>>
>>>> function document.outlinepaths(character)
>>>>     local chardata  = fonts.hashes.characters[true] -- by unicode
>>>>     local shapedata = fonts.hashes.shapes[true] -- by index
>>>>     local c         = chardata[character]
>>>>     if c and c.index and shapedata then
>>>>         local shapeglyphs = shapedata.glyphs or { }
>>>>         local glyph       = shapeglyphs[c.index]
>>>>         if glyph and (glyph.segments or glyph.sequence) then
>>>>             local units  = shapedata.units or 1000
>>>>             local factor = 100/units
>>>>             return fonts.metapost.paths(glyph,factor)
>>>>         end
>>>>     end
>>>>     return { }
>>>> end
>>>>
>>>> function document.defineoutline(char,target)
>>>>     local outlines = document.outlinepaths(char)
>>>>     local nofpaths = #outlines
>>>>     context("path %s[] ;",target)
>>>>     context("numeric %sn ; %sn := %s ;",target,target,nofpaths)
>>>>     for i=1,nofpaths do
>>>>         context("%s[%i] := %s ; ",target,i,outlines[i])
>>>>     end
>>>> end
>>>> \stopluacode
>>>>
>>>> \def\mpdefineoutlines#1#2{\ctxlua{document.defineoutline(\number`#1,"#2")}}
>>>>
>>>> \starttext
>>>>
>>>> \startMPpage
>>>> pair shift ; shift := (1cm,-1cm);
>>>> numeric angle ; angle := 5;
>>>>
>>>> \mpdefineoutlines{B}{B}
>>>> \mpdefineoutlines{T}{T}
>>>>
>>>> for i=1 upto Bn - 1 : nofill B[i] ; endfor ;
>>>> eofill B[Bn] withcolor .5[blue,white] ;
>>>>
>>>> for i=1 upto Tn :
>>>>     T[i] := T[i] shifted shift rotated angle ;
>>>> endfor ;
>>>>
>>>> for i=1 upto Tn - 1 : nofill T[i] ; endfor ;
>>>> eofill T[Tn] withcolor .5[red,white] ;
>>>>
>>>> pair found[] ;
>>>> boolean isnew ;
>>>> numeric n ; n := 0 ;
>>>> pair rq ;
>>>>
>>>> def GoForIt(expr how) =
>>>>     path r ;
>>>>     for i = 1 upto Bn :
>>>>         for j = 1 upto Tn :
>>>>             r := B[i] ;
>>>>             forever:
>>>>                 pair q ;
>>>>                 if how = 1 :
>>>>                     r := r cutbefore T[j] ;
>>>>                 elseif how = 2 :
>>>>                     r := r cutbefore reverse T[j] ;
>>>>                 elseif how = 3 :
>>>>                     r := reverse r cutbefore T[j] ;
>>>>                 else :
>>>>                     r := reverse r cutbefore reverse T[j] ;
>>>>                 fi ;
>>>>                 exitif length cuttings = 0 ;
>>>>                 r := subpath(epsilon, length r) of r ;
>>>>                 q = point 0 of r ;
>>>>                 isnew := true ;
>>>>                 rq := round(q);
>>>>                 for f=1 upto n :
>>>>                     if found[f] = rq :
>>>>                         isnew := false ;
>>>>                         exitif true ;
>>>>                     fi ;
>>>>                 endfor ;
>>>>                 if isnew :
>>>>                     n := n + 1 ;
>>>>                     drawdot q withpen pencircle scaled 4 ;
>>>>                     draw textext("\strut\ttbf " & decimal n) ysized 3
>>>> shifted q withcolor white ;
>>>>                     found[n] := rq ;
>>>>                 fi ;
>>>>             endfor;
>>>>         endfor ;
>>>>     endfor ;
>>>> enddef ;
>>>>
>>>> for i=1 upto 4 : GoForIt(i) ; endfor ;
>>>>
>>>> \stopMPpage
>>>>
>>>> \stoptext
>> Ok, a different approach then (probably still not all points as we need
>> to loop over segments but better) .. no more time now.
>>
>> It also shows that we don't need lua/tex juggling as we already can have
>> the paths in mp. (For sure now someone can complain that this is not
>> well documented.)
>>
>> \starttext
>>
>> \startMPdefinitions
>>
>>       % will be added to metafun:
>>
>>       def filloutlinetext(expr o) =
>>           draw image (
>>               save n, m ; numeric n, m ; n := m := 0 ;
>>               for i within o :
>>                   n := n + 1 ;
>>               endfor ;
>>               for i within o :
>>                   m := m + 1 ;
>>                   if n = m :
>>                       eofill
>>                   else :
>>                       nofill
>>                   fi pathpart i ;
>>               endfor ;
>>           )
>>       enddef ;
>>
>>       def drawoutlinetext(expr o) =
>>           draw image (
>>               % nicer for properties
>>               for i within o :
>>                   draw pathpart i ;
>>               endfor ;
>>           )
>>       enddef ;
>>
>>       def outlinetexttopath(text o, p, n) =
>>           scantokens("numeric " & str n &   ";") ;
>>           scantokens("path "    & str p & "[];") ;
>>           n := 0 ;
>>           for i within o : p[incr(n)] := pathpart i ; endfor ;
>>       enddef ;
>>
>> \stopMPdefinitions
>>
>> \startMPdefinitions
>>
>>       % outlinetexttopath(Bo)(B)(Bn) ;
>>       %
>>       % Bn := listsize(T)
>>
>>       def showoverlapinoutlines(expr first, second) =
>>
>>           path p_i, p_j, s_i, s_j ;
>>           numeric n_i, n_j, index ;
>>           pair found ;
>>           index := 0 ;
>>           for i within first :
>>               for j within second :
>>                   p_i := pathpart i ; n_i := length(p_i) ;
>>                   p_j := pathpart j ; n_j := length(p_j) ;
>>                   for ii = 0 upto n_i - 1 :
>>                       s_i := subpath(ii,ii+1) of p_i ;
>>                       for jj = 0 upto n_j - 1 :
>>                           s_j := subpath(jj,jj+1) of p_j ;
>>                           found := s_i intersection_point s_j ;
>>                           if intersection_found :
>>                               index := index + 1 ;
>>                               drawdot found withpen pencircle scaled 4
>> withtransparency (1,.5);
>>                               draw textext("\strut\ttbf " & decimal
>> index) ysized 3 shifted found withcolor white withtransparency (1,.5);
>>                           fi ;
>>                       endfor ;
>>                   endfor ;
>>               endfor ;
>>           endfor ;
>>
>>       enddef ;
>>
>> \stopMPdefinitions
>>
>> \startMPpage
>>
>>       picture first  ; first  := outlinetext.p("N") ; first  := first
>> scaled 10 ;
>>       picture second ; second := outlinetext.p("T") ; second := second
>> scaled 10 ;
>>
>>       second := second rotatedaround(center second, 5) shifted (1,-1) ;
>>
>>       filloutlinetext(first ) withcolor .5[blue,white] ;
>>       filloutlinetext(second) withcolor .5[red,white] ;
>>
>>       drawoutlinetext(first ) ;
>>       drawoutlinetext(second) ;
>>
>>       showoverlapinoutlines(first, second) ;
>>
>> \stopMPpage
>>
>> \startMPdefinitions
>>
>>       def showoverlap(expr f, s) =
>>           picture first  ; first  := outlinetext.p(f) ; first  := first
>> scaled 10 ;
>>           picture second ; second := outlinetext.p(s) ; second := second
>> scaled 10 ;
>>
>>           filloutlinetext(first ) withcolor .5blue ;
>>           drawoutlinetext(first ) ;
>>
>>           filloutlinetext(second) withcolor .5red  ;
>>           drawoutlinetext(second) ;
>>
>>           showoverlapinoutlines(first, second) ;
>>       enddef ;
>>
>> \stopMPdefinitions
>>
>> \startMPpage
>>       showoverlap("N","T") ;
>> \stopMPpage
>>
>> \startMPpage
>>       showoverlap("\$","Q") ;
>> \stopMPpage
>>
>> \startMPpage
>>       showoverlap("\tttf ABC","\tttf PQR") ;
>> \stopMPpage
>>
>> \stoptext
> 
> 
> Take a look, also, at the crossingunder macro in mp-tool.mpiv
something

     % based on crossingunder

     def showoverlapinoutlines(expr first, second) =
         begingroup ;
         save p, q, n, t, a, b, c, bcuttings, hold, found ;
         path p, q ;
         numeric n, t[], hold ;
         path a, b, c, bcuttings, hold[] ;
         pair found ;
         c := makepath(currentpen scaled crossingscale) ;
         t[0] := n := hold := 0 ;
         for f within first :
             for s within second :
                 p := pathpart f ;
                 q := pathpart s ;
                 a := p ;
                 for i=1 upto crossingnumbermax : % safeguard
                     clearxy ; z = a intersectiontimes q ;
                     if x < 0 :
                         exitif hold < 1 ;
                         a := hold[hold] ; hold := hold - 1 ;
                         clearxy ; z = a intersectiontimes q ;
                     fi
                     (t[incr n], whatever) = p intersectiontimes point x 
of a ;
                     if x = 0 :
                         a := a cutbefore c shifted point x of a ;
                     elseif x = length a :
                         a := a cutafter  c shifted point x of a ;
                     else : % before or after?
                         b := subpath (0,x)        of a cutafter  c 
shifted point x of a ;
                         bcuttings := cuttings ;
                         a := subpath (x,length a) of a cutbefore c 
shifted point x of a ;
                         clearxy ; z = a intersectiontimes q ;
                         if x < 0 :
                             a := b ;
                             cuttings := bcuttings ;
                         else :
                             if length bcuttings > 0 :
                                 clearxy ; z = b intersectiontimes q ;
                                 if x >= 0 :
                                     hold[incr hold] := b ;
                                 fi
                             fi
                         fi
                     fi
                     if length cuttings = 0 :
                         exitif hold < 1 ;
                         a := hold[hold] ; hold := hold - 1 ;
                     fi
                 endfor ;

             endfor ;
         endfor ;

         t[incr n] = length p ;
         for i=1 upto n :
             found := point t[i] of p ;
             drawdot found withpen pencircle scaled 4 withtransparency 
(1,.5);
             draw textext("\strut\ttbf " & decimal i) ysized 3 shifted 
found withcolor white withtransparency (1,.5);
         endfor ;

         endgroup ;
     enddef ;



-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Metafun: Finding intersection between characters
  2018-09-27 15:43               ` Hans Hagen
@ 2018-09-28 10:09                 ` Jeong Dal
  0 siblings, 0 replies; 17+ messages in thread
From: Jeong Dal @ 2018-09-28 10:09 UTC (permalink / raw)
  To: Hans Hagen
  Cc: list ntg-context@ntg.nl ntg-context@ntg.nl ntg-context@ntg.nl
	ntg-context@ntg.nl

Dear Hans,

Thank you so much for a new code which works fine.
It can be used for the title of chapters.
I will play with this to make a nice title.

Thank you again.

Best regards,

Dalyoung


> 2018. 9. 28. 오전 12:43, Hans Hagen <j.hagen@xs4all.nl> 작성:
> 
> On 9/27/2018 5:06 PM, Jeong Dal wrote:
>> Dear Hans,
>> First, I appreciate for your concerning and sharing your valuable time on this matter.
>> I think that there is no one who has an interest in outlining Korean letters.
>> It is my self-interest to use outlined text for titles of chapters.
>> As we know, Korean letters are different from English letters. In one glyph, there are several parts, which makes the job difficult.
> 
> Here's some more to play with ...
> 
> \definefontfeature
> [korean-base]
> [mode=node,
>  script=hang,
>  language=kor]
> 
> \definefontfeature[outlined-10]
> [effect={effect=outline,width=0.10,auto=yes}]
> \definefontfeature[outlined-20]
> [effect={effect=outline,width=0.20,auto=yes}]
> \definefontfeature[outlined-30]
> [effect={effect=outline,width=0.30,auto=yes}]
> 
> \definefont[KoreanFontA][hanbatanglvt*korean-base             @ 45pt]
> \definefont[KoreanFontB][hanbatanglvt*korean-base,boldened-10 @ 45pt]
> \definefont[KoreanFontC][hanbatanglvt*korean-base,boldened-20 @ 45pt]
> \definefont[KoreanFontD][hanbatanglvt*korean-base,boldened-30 @ 45pt]
> \definefont[KoreanFontE][hanbatanglvt*korean-base,outlined-10 @ 45pt]
> \definefont[KoreanFontF][hanbatanglvt*korean-base,outlined-20 @ 45pt]
> \definefont[KoreanFontG][hanbatanglvt*korean-base,outlined-30 @ 45pt]
> 
> \starttext
> 
>   \startlines
>       \KoreanFontA 랏논왕닭박서
>       \KoreanFontB 랏논왕닭박서
>       \KoreanFontC 랏논왕닭박서
>       \KoreanFontD 랏논왕닭박서
>       \KoreanFontE 랏논왕닭박서
>       \KoreanFontF 랏논왕닭박서
>       \KoreanFontG 랏논왕닭박서
>   \stoplines
> 
> \stoptext
> 
> This is probably easier to configure when you use titles.
> 
> Hans
> 
> 
> 
> 
> -----------------------------------------------------------------
>                                         Hans Hagen | PRAGMA ADE
>             Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
>      tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
> -----------------------------------------------------------------

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Metafun: Finding intersection between characters
  2018-09-27 15:06             ` Jeong Dal
@ 2018-09-27 15:43               ` Hans Hagen
  2018-09-28 10:09                 ` Jeong Dal
  0 siblings, 1 reply; 17+ messages in thread
From: Hans Hagen @ 2018-09-27 15:43 UTC (permalink / raw)
  To: Jeong Dal
  Cc: list ntg-context@ntg.nl ntg-context@ntg.nl ntg-context@ntg.nl
	ntg-context@ntg.nl

On 9/27/2018 5:06 PM, Jeong Dal wrote:
> Dear Hans,
> 
> First, I appreciate for your concerning and sharing your valuable time on this matter.
> I think that there is no one who has an interest in outlining Korean letters.
> It is my self-interest to use outlined text for titles of chapters.
> 
> As we know, Korean letters are different from English letters. In one glyph, there are several parts, which makes the job difficult.

Here's some more to play with ...

\definefontfeature
   [korean-base]
   [mode=node,
    script=hang,
    language=kor]

\definefontfeature[outlined-10]
   [effect={effect=outline,width=0.10,auto=yes}]
\definefontfeature[outlined-20]
   [effect={effect=outline,width=0.20,auto=yes}]
\definefontfeature[outlined-30]
   [effect={effect=outline,width=0.30,auto=yes}]

\definefont[KoreanFontA][hanbatanglvt*korean-base             @ 45pt]
\definefont[KoreanFontB][hanbatanglvt*korean-base,boldened-10 @ 45pt]
\definefont[KoreanFontC][hanbatanglvt*korean-base,boldened-20 @ 45pt]
\definefont[KoreanFontD][hanbatanglvt*korean-base,boldened-30 @ 45pt]
\definefont[KoreanFontE][hanbatanglvt*korean-base,outlined-10 @ 45pt]
\definefont[KoreanFontF][hanbatanglvt*korean-base,outlined-20 @ 45pt]
\definefont[KoreanFontG][hanbatanglvt*korean-base,outlined-30 @ 45pt]

\starttext

     \startlines
         \KoreanFontA 랏논왕닭박서
         \KoreanFontB 랏논왕닭박서
         \KoreanFontC 랏논왕닭박서
         \KoreanFontD 랏논왕닭박서
         \KoreanFontE 랏논왕닭박서
         \KoreanFontF 랏논왕닭박서
         \KoreanFontG 랏논왕닭박서
     \stoplines

\stoptext

This is probably easier to configure when you use titles.

Hans




-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Metafun: Finding intersection between characters
  2018-09-27  8:49           ` Hans Hagen
@ 2018-09-27 15:06             ` Jeong Dal
  2018-09-27 15:43               ` Hans Hagen
  0 siblings, 1 reply; 17+ messages in thread
From: Jeong Dal @ 2018-09-27 15:06 UTC (permalink / raw)
  To: Hans Hagen
  Cc: list ntg-context@ntg.nl ntg-context@ntg.nl ntg-context@ntg.nl
	ntg-context@ntg.nl

Dear Hans,

First, I appreciate for your concerning and sharing your valuable time on this matter.
I think that there is no one who has an interest in outlining Korean letters.
It is my self-interest to use outlined text for titles of chapters. 

As we know, Korean letters are different from English letters. In one glyph, there are several parts, which makes the job difficult.

Thank you so much.

Best regards,

Dalyoung




> 2018. 9. 27. 오후 5:49, Hans Hagen <j.hagen@xs4all.nl> 작성:
> 
> On 9/26/2018 11:38 PM, Jeong Dal wrote:
>> Dear Hans,
>>> 2018. 9. 26. 오후 9:24, Hans Hagen <j.hagen@xs4all.nl <mailto:j.hagen@xs4all.nl>> 작성:
>>> 
>>> On 9/26/2018 2:14 PM, Jeong Dal wrote:
>>>> Dear Hans,
>>>> I tested for more characters and found an interesting fact.
>>>> If the first consonant and the vowels are connected in a glyph, then the outlining works OK, otherwise, it makes outline of the first consonant only.
>>> 
>>> you need to send a file not embedded .. otherwise the mail agent will apply magic to korean
>>> 
>>> 
>> I didn’t think of it.
>> I attached a sample file.
> attached
> 
> Hans
> 
> -----------------------------------------------------------------
>                                          Hans Hagen | PRAGMA ADE
>              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
>       tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
> -----------------------------------------------------------------
> <todo-korean.tex>

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Metafun: Finding intersection between characters
  2018-09-26 21:38         ` Jeong Dal
@ 2018-09-27  8:49           ` Hans Hagen
  2018-09-27 15:06             ` Jeong Dal
  0 siblings, 1 reply; 17+ messages in thread
From: Hans Hagen @ 2018-09-27  8:49 UTC (permalink / raw)
  To: Jeong Dal
  Cc: list ntg-context@ntg.nl ntg-context@ntg.nl ntg-context@ntg.nl
	ntg-context@ntg.nl

[-- Attachment #1: Type: text/plain, Size: 957 bytes --]

On 9/26/2018 11:38 PM, Jeong Dal wrote:
> Dear Hans,
> 
>> 2018. 9. 26. 오후 9:24, Hans Hagen <j.hagen@xs4all.nl 
>> <mailto:j.hagen@xs4all.nl>> 작성:
>>
>> On 9/26/2018 2:14 PM, Jeong Dal wrote:
>>> Dear Hans,
>>> I tested for more characters and found an interesting fact.
>>> If the first consonant and the vowels are connected in a glyph, then 
>>> the outlining works OK, otherwise, it makes outline of the first 
>>> consonant only.
>>
>> you need to send a file not embedded .. otherwise the mail agent will 
>> apply magic to korean
>>
>>
> 
> I didn’t think of it.
> I attached a sample file.
attached

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------

[-- Attachment #2: todo-korean.tex --]
[-- Type: text/plain, Size: 2323 bytes --]

\definefontfeature
  [korean-base]
  [goodies=hanbatanglvt,
   colorscheme=default,
   mode=node,
   script=hang,
   language=kor]

\definefont[KoreanFont][hanbatanglvt*korean-base]

\starttext

\startMPdefinitions
    string KoreanColors[] ;

    KoreanColors[1] := "darkred" ;
    KoreanColors[2] := "darkgreen" ;
    KoreanColors[3] := "darkblue" ;
    KoreanColors[4] := "darkyellow" ;
    KoreanColors[5] := "darkgray" ;

    newinternal KoreanSplit ; KoreanSplit := -1 ;
    newinternal KoreanCode  ; KoreanCode  := -2 ;
    newinternal KoreanMode  ; KoreanMode  := KoreanSplit ;

    def KoreanOutline(expr txt) =
        picture p ; p := outlinetext.p(txt) ;
        numeric n ; n := 0 ;
        string old, new ; old := "" ;
        for i within p :
            if KoreanMode == KoreanSplit :
                n := n + 1 ;
            elseif KoreanMode == KoreanCode :
              new := prescriptpart i ;
              if new <> old :
                  old := new ;
                  n := n + 1 ;
              fi ;
            else :
                n := KoreanMode ;
            fi ;
            if unknown KoreanColors[n] :
                n := 1 ;
            fi ;
            draw pathpart i
                withpen pencircle scaled 1/10
                withcolor KoreanColors[n] ;
        endfor ;
    enddef ;

    def KoreanTest(expr txt) =
        KoreanMode  := KoreanSplit ; KoreanOutline(txt) ;
        currentpicture := currentpicture shifted (- xpart urcorner currentpicture, 0);
        KoreanMode  := KoreanCode ; KoreanOutline(txt) ;
        currentpicture := currentpicture shifted (- xpart urcorner currentpicture, 0);
        KoreanMode  := 3 ; KoreanOutline(txt) ;
    enddef ;

\stopMPdefinitions

% entered as three characters: ᄅ  ᅡ  ᆺ (mail collapses)

\startMPpage
    KoreanTest("\KoreanFont 랏") ;
\stopMPpage
\startMPpage
    KoreanTest("\KoreanFont 랏") ;
\stopMPpage
\startMPpage
    KoreanTest("\KoreanFont 논") ;
\stopMPpage
\startMPpage
    KoreanTest("\KoreanFont 왕") ;
\stopMPpage
\startMPpage
    KoreanTest("\KoreanFont 닭") ;
\stopMPpage
\startMPpage
    KoreanTest("\KoreanFont 박") ;
\stopMPpage
\startMPpage
    KoreanTest("\KoreanFont 서") ;
\stopMPpage

\stoptext

[-- Attachment #3: Type: text/plain, Size: 492 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Metafun: Finding intersection between characters
  2018-09-26 12:24       ` Hans Hagen
@ 2018-09-26 21:38         ` Jeong Dal
  2018-09-27  8:49           ` Hans Hagen
  0 siblings, 1 reply; 17+ messages in thread
From: Jeong Dal @ 2018-09-26 21:38 UTC (permalink / raw)
  To: Hans Hagen
  Cc: list ntg-context@ntg.nl ntg-context@ntg.nl ntg-context@ntg.nl
	ntg-context@ntg.nl


[-- Attachment #1.1: Type: text/plain, Size: 584 bytes --]

Dear Hans,

> 2018. 9. 26. 오후 9:24, Hans Hagen <j.hagen@xs4all.nl> 작성:
> 
> On 9/26/2018 2:14 PM, Jeong Dal wrote:
>> Dear Hans,
>> I tested for more characters and found an interesting fact.
>> If the first consonant and the vowels are connected in a glyph, then the outlining works OK, otherwise, it makes outline of the first consonant only.
> 
> you need to send a file not embedded .. otherwise the mail agent will apply magic to korean
> 
> 

I didn’t think of it.
I attached a sample file.

Thank you for your concern.

Best regards,

Dalyoung


[-- Attachment #1.2.1: Type: text/html, Size: 4220 bytes --]

[-- Attachment #1.2.2: outlineKorean.tex --]
[-- Type: application/x-tex, Size: 1470 bytes --]

[-- Attachment #1.2.3: Type: text/html, Size: 268 bytes --]

[-- Attachment #2: Type: text/plain, Size: 492 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Metafun: Finding intersection between characters
  2018-09-26 12:14     ` Jeong Dal
@ 2018-09-26 12:24       ` Hans Hagen
  2018-09-26 21:38         ` Jeong Dal
  0 siblings, 1 reply; 17+ messages in thread
From: Hans Hagen @ 2018-09-26 12:24 UTC (permalink / raw)
  To: Jeong Dal
  Cc: list ntg-context@ntg.nl ntg-context@ntg.nl ntg-context@ntg.nl
	ntg-context@ntg.nl

On 9/26/2018 2:14 PM, Jeong Dal wrote:
> Dear Hans,
> 
> I tested for more characters and found an interesting fact.
> If the first consonant and the vowels are connected in a glyph, then the outlining works OK, otherwise, it makes outline of the first consonant only.

you need to send a file not embedded .. otherwise the mail agent will 
apply magic to korean


> Here is a MWE.
> 
> Thank you.
> Best regards,
> 
> Dalyoung
> 
> %%%%%
> \definefontfeature
>   [korean-base]
>   [goodies=hanbatanglvt,
>    colorscheme=default,
>    mode=node,
>    script=hang,
>    language=kor]
> 
> \definefont[KoreanFont][hanbatanglvt*korean-base]
> 
> \starttext
> 
> \startMPdefinitions
>     string KoreanColors[] ;
> 
>     KoreanColors[1] := "darkred" ;
>     KoreanColors[2] := "darkgreen" ;
>     KoreanColors[3] := "darkblue" ;
>     KoreanColors[4] := "darkyellow" ;
>     KoreanColors[5] := "darkgray" ;
> 
>     def KoreanOutline(expr txt) =
>         picture p ; p := outlinetext.p(txt) ;
>         numeric n ; n := 0 ;
>         string old, new ; old := "" ;
>         for i within p :
>             new := prescriptpart i ;
>             if (new = "") or (new <> old) :
>                 old := new ;
>                 n := n + 1 ;
>                 if unknown KoreanColors[n] :
>                     n := 1 ;
>                 fi ;
>             fi ;
>             draw pathpart i
>                 withpen pencircle scaled 1/10
>                 withcolor KoreanColors[n] ;
>         endfor ;
>     enddef ;
> \stopMPdefinitions
>     % entered as three characters: ᄅ  ᅡ  ᆺ (mail collapses)
> \startMPpage
>     KoreanOutline("\KoreanFont 랏") ;
> \stopMPpage
> \startMPpage
>     KoreanOutline("\KoreanFont 논") ;
> \stopMPpage
> \startMPpage
>     KoreanOutline("\KoreanFont 왕") ;
> \stopMPpage
> \startMPpage
>     KoreanOutline("\KoreanFont 닭") ;
> \stopMPpage
> \startMPpage
>     KoreanOutline("\KoreanFont 박") ;
> \stopMPpage
> \startMPpage
>     KoreanOutline("\KoreanFont 서") ;
> \stopMPpage
> 
> %%%%%%%%%
> 
>> 2018. 9. 26. 오후 7:10, Hans Hagen <j.hagen@xs4all.nl> 작성:
>>
>> On 9/26/2018 1:48 AM, Jeong Dal wrote:
>>> Dear Hans,
>>> First, it is great to know a new method of drawing an outlined font!
>>>   I have applied it to Korean fonts. As you know, every Korean character is composed with “consonant+vowel(+consonant)” type. If consonant and vowel are connected (for example, “호”), then it draws correctly, otherwise (for example, “하”)  it draws only consonant.
>>> Is there a way to count all the paths in a character(even if it is not connected)?
>> I assume that you want to identify the upto 3 snippets in a glyph so what you can do is loop over a picture.
>>
>> \definefontfeature
>>   [korean-base]
>>   [goodies=hanbatanglvt,
>>    colorscheme=default,
>>    mode=node,
>>    script=hang,
>>    language=kor]
>>
>> \definefont[KoreanFont][hanbatanglvt*korean-base]
>>
>> \starttext
>>
>> \startMPpage
>>     string KoreanColors[] ;
>>
>>     KoreanColors[1] := "darkred" ;
>>     KoreanColors[2] := "darkgreen" ;
>>     KoreanColors[3] := "darkblue" ;
>>     KoreanColors[4] := "darkyellow" ;
>>     KoreanColors[5] := "darkgray" ;
>>
>>     def KoreanOutline(expr txt) =
>>         picture p ; p := outlinetext.p(txt) ;
>>         numeric n ; n := 0 ;
>>         string old, new ; old := "" ;
>>         for i within p :
>>             new := prescriptpart i ;
>>             if (new = "") or (new <> old) :
>>                 old := new ;
>>                 n := n + 1 ;
>>                 if unknown KoreanColors[n] :
>>                     n := 1 ;
>>                 fi ;
>>             fi ;
>>             draw pathpart i
>>                 withpen pencircle scaled 1/10
>>                 withcolor KoreanColors[n] ;
>>         endfor ;
>>     enddef ;
>>
>>     % entered as three characters: ᄅ  ᅡ  ᆺ (mail collapses)
>>
>>     KoreanOutline("\KoreanFont 랏") ;
>> \stopMPpage
>>
>> \stoptext
>>
>> The prescript will be set in a next beta so then you get better results for more complex shapes.
>>
>> Loading the font takes a bit of time and memory because the first time the outlines are filtered and converted and saved. But I assume Koreans TeX users have fast computers with lots of memory.
>>
>> Hans
>>
>>
>> -----------------------------------------------------------------
>>                                           Hans Hagen | PRAGMA ADE
>>               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
>>        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
>> -----------------------------------------------------------------
> 


-- 

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Metafun: Finding intersection between characters
  2018-09-26 10:10   ` Hans Hagen
@ 2018-09-26 12:14     ` Jeong Dal
  2018-09-26 12:24       ` Hans Hagen
  0 siblings, 1 reply; 17+ messages in thread
From: Jeong Dal @ 2018-09-26 12:14 UTC (permalink / raw)
  To: Hans Hagen
  Cc: list ntg-context@ntg.nl ntg-context@ntg.nl ntg-context@ntg.nl
	ntg-context@ntg.nl

Dear Hans,

I tested for more characters and found an interesting fact.
If the first consonant and the vowels are connected in a glyph, then the outlining works OK, otherwise, it makes outline of the first consonant only.

Here is a MWE.

Thank you.
Best regards,

Dalyoung

%%%%%
\definefontfeature
 [korean-base]
 [goodies=hanbatanglvt,
  colorscheme=default,
  mode=node,
  script=hang,
  language=kor]

\definefont[KoreanFont][hanbatanglvt*korean-base]

\starttext

\startMPdefinitions
   string KoreanColors[] ;

   KoreanColors[1] := "darkred" ;
   KoreanColors[2] := "darkgreen" ;
   KoreanColors[3] := "darkblue" ;
   KoreanColors[4] := "darkyellow" ;
   KoreanColors[5] := "darkgray" ;

   def KoreanOutline(expr txt) =
       picture p ; p := outlinetext.p(txt) ;
       numeric n ; n := 0 ;
       string old, new ; old := "" ;
       for i within p :
           new := prescriptpart i ;
           if (new = "") or (new <> old) :
               old := new ;
               n := n + 1 ;
               if unknown KoreanColors[n] :
                   n := 1 ;
               fi ;
           fi ;
           draw pathpart i
               withpen pencircle scaled 1/10
               withcolor KoreanColors[n] ;
       endfor ;
   enddef ;
\stopMPdefinitions
   % entered as three characters: ᄅ  ᅡ  ᆺ (mail collapses)
\startMPpage
   KoreanOutline("\KoreanFont 랏") ;
\stopMPpage
\startMPpage
   KoreanOutline("\KoreanFont 논") ;
\stopMPpage
\startMPpage
   KoreanOutline("\KoreanFont 왕") ;
\stopMPpage
\startMPpage
   KoreanOutline("\KoreanFont 닭") ;
\stopMPpage
\startMPpage
   KoreanOutline("\KoreanFont 박") ;
\stopMPpage
\startMPpage
   KoreanOutline("\KoreanFont 서") ;
\stopMPpage

%%%%%%%%%

> 2018. 9. 26. 오후 7:10, Hans Hagen <j.hagen@xs4all.nl> 작성:
> 
> On 9/26/2018 1:48 AM, Jeong Dal wrote:
>> Dear Hans,
>> First, it is great to know a new method of drawing an outlined font!
>>  I have applied it to Korean fonts. As you know, every Korean character is composed with “consonant+vowel(+consonant)” type. If consonant and vowel are connected (for example, “호”), then it draws correctly, otherwise (for example, “하”)  it draws only consonant.
>> Is there a way to count all the paths in a character(even if it is not connected)?
> I assume that you want to identify the upto 3 snippets in a glyph so what you can do is loop over a picture.
> 
> \definefontfeature
>  [korean-base]
>  [goodies=hanbatanglvt,
>   colorscheme=default,
>   mode=node,
>   script=hang,
>   language=kor]
> 
> \definefont[KoreanFont][hanbatanglvt*korean-base]
> 
> \starttext
> 
> \startMPpage
>    string KoreanColors[] ;
> 
>    KoreanColors[1] := "darkred" ;
>    KoreanColors[2] := "darkgreen" ;
>    KoreanColors[3] := "darkblue" ;
>    KoreanColors[4] := "darkyellow" ;
>    KoreanColors[5] := "darkgray" ;
> 
>    def KoreanOutline(expr txt) =
>        picture p ; p := outlinetext.p(txt) ;
>        numeric n ; n := 0 ;
>        string old, new ; old := "" ;
>        for i within p :
>            new := prescriptpart i ;
>            if (new = "") or (new <> old) :
>                old := new ;
>                n := n + 1 ;
>                if unknown KoreanColors[n] :
>                    n := 1 ;
>                fi ;
>            fi ;
>            draw pathpart i
>                withpen pencircle scaled 1/10
>                withcolor KoreanColors[n] ;
>        endfor ;
>    enddef ;
> 
>    % entered as three characters: ᄅ  ᅡ  ᆺ (mail collapses)
> 
>    KoreanOutline("\KoreanFont 랏") ;
> \stopMPpage
> 
> \stoptext
> 
> The prescript will be set in a next beta so then you get better results for more complex shapes.
> 
> Loading the font takes a bit of time and memory because the first time the outlines are filtered and converted and saved. But I assume Koreans TeX users have fast computers with lots of memory.
> 
> Hans
> 
> 
> -----------------------------------------------------------------
>                                          Hans Hagen | PRAGMA ADE
>              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
>       tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
> -----------------------------------------------------------------

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Metafun: Finding intersection between characters
  2018-09-26  7:59   ` Hans Hagen
@ 2018-09-26 11:44     ` Jeong Dal
  0 siblings, 0 replies; 17+ messages in thread
From: Jeong Dal @ 2018-09-26 11:44 UTC (permalink / raw)
  To: Hans Hagen
  Cc: list ntg-context@ntg.nl ntg-context@ntg.nl ntg-context@ntg.nl
	ntg-context@ntg.nl

[-- Attachment #1: Type: text/plain, Size: 2039 bytes --]

Dear Hans,

I have tested using your code. I just replace “N”, “T” with Korean letters.

Here is an MWE which is a simplified version of your code.
I tested using two fonts, and the outputs are different.

Thank you for your concern.

Best regards,

Dalyoung

%%%%%%%
\usetypescriptfile[type-hcrlvt]
\usetypescript[HcrFont] 
\setupbodyfont[Myface, rm, 12pt]
%\setupbodyfont[unfonts, rm, 12pt]

\startMPdefinitions
    def filloutlinetext(expr o) =
        draw image (
            save n, m ; numeric n, m ; n := m := 0 ;
            for i within o :
                n := n + 1 ;
            endfor ;
            for i within o :
                m := m + 1 ;
                if n = m :
                    eofill
                else :
                    nofill
                fi pathpart i ;
            endfor ;
        )
    enddef ;

    def drawoutlinetext(expr o) =
        draw image (
            % nicer for properties
            for i within o :
                draw pathpart i ;
            endfor ;
        )
    enddef ;

    def outlinetexttopath(text o, p, n) =
        scantokens("numeric " & str n &   ";") ;
        scantokens("path "    & str p & "[];") ;
        n := 0 ;
        for i within o : p[incr(n)] := pathpart i ; endfor ;
    enddef ;

\stopMPdefinitions

\startbuffer[ho]
	picture first  ; first  := outlinetext.p("호") ; first  := first scaled 10 ;
	filloutlinetext(first ) withcolor .5[blue,white] ;
	drawoutlinetext(first ) ;
\stopbuffer
\startbuffer[ha]
	picture first  ; first  := outlinetext.p("하") ; first  := first scaled 10 ;
	filloutlinetext(first ) withcolor .5[blue,white] ;
	drawoutlinetext(first ) ;
\stopbuffer
\startbuffer[wang]
	picture first  ; first  := outlinetext.p("왕") ; first  := first scaled 10 ;
	filloutlinetext(first ) withcolor .5[blue,white] ;
	drawoutlinetext(first ) ;
\stopbuffer

\starttext

\processMPbuffer[ho]
\processMPbuffer[ha]
\processMPbuffer[wang]

\stoptext
%%%%%%%


[-- Attachment #2: type-hcrlvt.mkiv --]
[-- Type: application/octet-stream, Size: 8227 bytes --]

%D \module
%D   [       file=type-imp-hcrfonts,
%D        version=2013.11.11,
%D          title=\CONTEXT\ Typescript Macros,
%D       subtitle=HcrFonts,
%D         author=...,
%D           date=\currentdate,
%D      copyright=...]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
%%% Hamchorom-LVT fonts scripts
%%% 
\loadtypescriptfile[texgyre]
%\loadtypescriptfile[euler]
%\loadtypescriptfile[xits]

\definefontfeature
  [kr-default]
  [mode=node,script=hang,lang=kor]

\definefontfeature
  [kr-slanted]
  [mode=node,script=hang,lang=kor,slant=.2]

\definefontfeature
  [kr-latin-default]
  [default]

\definefontfeature
  [kr-latin-slanted]
  [krlatindefault]
  [slant=.2]

\definefontfeature
  [kr-latin-slanted-mono]
  [slant=.2]

\definefontfeature
  [kr-latin-smallcaps]
  [krlatindefault]
  [smcp=yes]

\definefontfeature
  [kr-latin-smallcaps-mono]
  [cmcp=yes]

\definefontfallback[kr-serif]           [texgyrepagella-regular*kr-latin-default]      [0x0000-0x0400][force=yes]
\definefontfallback[kr-serifbold]       [texgyrepagella-bold*kr-latin-default]         [0x0000-0x0400][force=yes]
\definefontfallback[kr-serifitalic]     [texgyrepagella-italic*kr-latin-default]       [0x0000-0x0400][force=yes]
\definefontfallback[kr-serifbolditalic] [texgyrepagella-bolditalic*kr-latin-default]   [0x0000-0x0400][force=yes]
\definefontfallback[kr-serifslanted]    [texgyrepagella-regular*kr-latin-slanted]      [0x0000-0x0400][force=yes]
\definefontfallback[kr-serifboldslanted][texgyrepagella-bold*kr-latin-slanted]         [0x0000-0x0400][force=yes]
\definefontfallback[kr-serifcaps]       [texgyrepagella-regular*kr-latin-smallcaps]    [0x0000-0x0400][force=yes]
\definefontfallback[kr-sans]            [texgyreheros-regular*kr-latin-default]        [0x0000-0x0400][force=yes]
\definefontfallback[kr-sansbold]        [texgyreheros-bold*kr-latin-default]           [0x0000-0x0400][force=yes]
\definefontfallback[kr-sansitalic]      [texgyreheros-italic*kr-latin-default]         [0x0000-0x0400][force=yes]
\definefontfallback[kr-sansbolditalic]  [texgyreheros-bolditalic*kr-latin-default]     [0x0000-0x0400][force=yes]
\definefontfallback[kr-sansslanted]     [texgyreheros-regular*kr-latin-slanted]        [0x0000-0x0400][force=yes]
\definefontfallback[kr-sansboldslanted] [texgyreheros-bold*kr-latin-slanted]           [0x0000-0x0400][force=yes]
\definefontfallback[kr-sanscaps]        [texgyreheros-regular*kr-latin-smallcaps]      [0x0000-0x0400][force=yes]
\definefontfallback[kr-mono]            [texgyrecursor-regular]                        [0x0000-0x0400][force=yes]
\definefontfallback[kr-monobold]        [texgyrecursor-bold]                           [0x0000-0x0400][force=yes]
\definefontfallback[kr-monoitalic]      [texgyrecursor-italic]                         [0x0000-0x0400][force=yes]
\definefontfallback[kr-monobolditalic]  [texgyrecursor-bolditalic]                     [0x0000-0x0400][force=yes]
\definefontfallback[kr-monoslanted]     [texgyrecursor-regular*kr-latin-slanted-mono]  [0x0000-0x0400][force=yes]
\definefontfallback[kr-monoboldslanted] [texgyrecursor-bold*kr-latin-slanted-mono]     [0x0000-0x0400][force=yes]
\definefontfallback[kr-monocaps]        [texgyrecursor-regular*kr-latin-smallcaps-mono][0x0000-0x0400][force=yes]

%\starttypescriptcollection[hcrfonts]

\starttypescript [serif] [HCRMJ]
        \definefontsynonym [HanBatang]           [file:HANBatang-LVT.ttf]    [features=kr-default,fallbacks=kr-serif]
        \definefontsynonym [HanBatangbold]       [file:HANBatangB-LVT.ttf][features=kr-default,fallbacks=kr-serifbold]
        \definefontsynonym [HanBatangitalic]     [file:HANBatang-LVT.ttf]    [features=kr-slanted,fallbacks=kr-serifitalic]
        \definefontsynonym [HanBatangbolditalic] [file:HANBatangB-LVT.ttf][features=kr-slanted,fallbacks=kr-serifbolditalic]
        \definefontsynonym [HanBatangslanted]    [file:HANBatang-LVT.ttf]    [features=kr-slanted,fallbacks=kr-serifslanted]
        \definefontsynonym [HanBatangboldslanted][file:HANBatangB-LVT.ttf][features=kr-slanted,fallbacks=kr-serifboldslanted]
        \definefontsynonym [HanBatangcaps]       [file:HANBatang-LVT.ttf]    [features=kr-default,fallbacks=kr-serifcaps]
\stoptypescript

\starttypescript [sans] [HCRGo]
        \definefontsynonym[HanDotum]             [file:HANDotum-LVT.ttf]     [features=kr-default,fallbacks=kr-sans]
        \definefontsynonym[HanDotumbold]         [file:HANDotumB-LVT.ttf] [features=kr-default,fallbacks=kr-sansbold]
        \definefontsynonym[HanDotumitalic]       [file:HANDotum-LVT.ttf]     [features=kr-slanted,fallbacks=kr-sansitalic]
        \definefontsynonym[HanDotumbolditalic]   [file:HANDotumB-LVT.ttf] [features=kr-slanted,fallbacks=kr-sansbolditalic]
        \definefontsynonym[HanDotumslanted]      [file:HANDotum-LVT.ttf]     [features=kr-slanted,fallbacks=kr-sansslanted]
        \definefontsynonym[HanDotumboldslanted]  [file:HANDotumB-LVT.ttf] [features=kr-slanted,fallbacks=kr-sansboldslanted]
        \definefontsynonym[HanDotumcaps]         [file:HANDotum-LVT.ttf]     [features=kr-default,fallbacks=kr-sanscaps]
\stoptypescript

\starttypescript [mono] [untype]
        \definefontsynonym[untype]              [file:NotoSansCJKkr-regular.otf]     [features=kr-default,fallbacks=kr-sans]
        \definefontsynonym[untypebold]          [file:NotoSansCJKkr-bold.otf]     [features=kr-default,fallbacks=kr-sansbold]
        \definefontsynonym[untypeitalic]        [file:NotoSansCJKkr-regular.otf]   [features=kr-slanted,fallbacks=kr-sansitalic]
        \definefontsynonym[untypebolditalic]    [file:NotoSansCJKkr-regular.otf]     [features=kr-slanted,fallbacks=kr-sansbolditalic]
        \definefontsynonym[untypeslanted]       [file:NotoSansCJKkr-regular.otf]      [features=kr-slanted,fallbacks=kr-sansslanted]
        \definefontsynonym[untypeboldslanted]   [file:NotoSansCJKkr-bold.otf]     [features=kr-slanted,fallbacks=kr-sansboldslanted]
        \definefontsynonym[untypecaps]          [file:NotoSansCJKkr-regular.otf]      [features=kr-default,fallbacks=kr-sanscaps]
\stoptypescript

    \starttypescript [serif] [HCRMJ] [name]
        \definefontsynonym[Serif]           [HanBatang]
        \definefontsynonym[SerifBold]       [HanBatangbold]
        \definefontsynonym[SerifItalic]     [HanBatangitalic]
        \definefontsynonym[SerifBoldItalic] [HanBatangbolditalic]
        \definefontsynonym[SerifSlanted]    [HanBatangslanted]
        \definefontsynonym[SerifBoldSlanted][HanBatangboldslanted]
        \definefontsynonym[SerifCaps]       [HanBatangcaps]
    \stoptypescript

    \starttypescript [sans] [HCRGo] [name]
        \definefontsynonym[Sans]            [HanDotum]
        \definefontsynonym[SansBold]        [HanDotumbold]
        \definefontsynonym[SansItalic]      [HanDotumitalic]
        \definefontsynonym[SansBoldItalic]  [HanDotumbolditalic]
        \definefontsynonym[SansSlanted]     [HanDotumslanted]
        \definefontsynonym[SansBoldSlanted] [HanDotumboldslanted]
        \definefontsynonym[SansCaps]        [HanDotumcaps]
    \stoptypescript

    \starttypescript [mono] [untype] [name]
        \definefontsynonym[Mono]            [untype]
        \definefontsynonym[MonoBold]        [untypebold]
        \definefontsynonym[MonoItalic]      [untypeitalic]
        \definefontsynonym[MonoBoldItalic]  [untypebolditalic]
        \definefontsynonym[MonoSlanted]     [untypeslanted]
        \definefontsynonym[MonoBoldSlanted] [untypeboldslanted]
        \definefontsynonym[MonoCaps]        [untypecaps]
    \stoptypescript

    % xits might get replaced with a pagella once we have it

    \starttypescript[HcrFont]
        \definetypeface [Myface] [rm] [serif] [HCRMJ]
        \definetypeface [Myface] [ss] [sans]  [HCRGo]
        \definetypeface [Myface] [tt] [mono]  [untype]
%	\definetypeface [Myface] [mm][pagellaovereuler][default]
%    \definetypeface [Myface][mm] [math]  [xits]
%        \definetypeface [Myface][mm] [math]  [tex gyre pagella math]
%    \definetypeface [Myface][mm][TeX Gyre Termes Math]%[scale=0.94]
	\definetypeface [Myface] [mm][math]  [modern]
     \stoptypescript

%\stoptypescriptcollection

[-- Attachment #3: Type: text/plain, Size: 2 bytes --]




[-- Attachment #4: Type: text/plain, Size: 492 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Metafun: Finding intersection between characters
  2018-09-25 23:48 ` Jeong Dal
  2018-09-26  7:59   ` Hans Hagen
@ 2018-09-26 10:10   ` Hans Hagen
  2018-09-26 12:14     ` Jeong Dal
  1 sibling, 1 reply; 17+ messages in thread
From: Hans Hagen @ 2018-09-26 10:10 UTC (permalink / raw)
  To: Jeong Dal,
	list ntg-context@ntg.nl ntg-context@ntg.nl ntg-context@ntg.nl
	ntg-context@ntg.nl

On 9/26/2018 1:48 AM, Jeong Dal wrote:
> Dear Hans,
> 
> First, it is great to know a new method of drawing an outlined font!
> 
>   I have applied it to Korean fonts. As you know, every Korean character is composed with “consonant+vowel(+consonant)” type. If consonant and vowel are connected (for example, “호”), then it draws correctly, otherwise (for example, “하”)  it draws only consonant.
> Is there a way to count all the paths in a character(even if it is not connected)?
I assume that you want to identify the upto 3 snippets in a glyph so 
what you can do is loop over a picture.

\definefontfeature
   [korean-base]
   [goodies=hanbatanglvt,
    colorscheme=default,
    mode=node,
    script=hang,
    language=kor]

\definefont[KoreanFont][hanbatanglvt*korean-base]

\starttext

\startMPpage
     string KoreanColors[] ;

     KoreanColors[1] := "darkred" ;
     KoreanColors[2] := "darkgreen" ;
     KoreanColors[3] := "darkblue" ;
     KoreanColors[4] := "darkyellow" ;
     KoreanColors[5] := "darkgray" ;

     def KoreanOutline(expr txt) =
         picture p ; p := outlinetext.p(txt) ;
         numeric n ; n := 0 ;
         string old, new ; old := "" ;
         for i within p :
             new := prescriptpart i ;
             if (new = "") or (new <> old) :
                 old := new ;
                 n := n + 1 ;
                 if unknown KoreanColors[n] :
                     n := 1 ;
                 fi ;
             fi ;
             draw pathpart i
                 withpen pencircle scaled 1/10
                 withcolor KoreanColors[n] ;
         endfor ;
     enddef ;

     % entered as three characters: ᄅ  ᅡ  ᆺ (mail collapses)

     KoreanOutline("\KoreanFont 랏") ;
\stopMPpage

\stoptext

The prescript will be set in a next beta so then you get better results 
for more complex shapes.

Loading the font takes a bit of time and memory because the first time 
the outlines are filtered and converted and saved. But I assume Koreans 
TeX users have fast computers with lots of memory.

Hans


-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Metafun: Finding intersection between characters
  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
  1 sibling, 1 reply; 17+ messages in thread
From: Hans Hagen @ 2018-09-26  7:59 UTC (permalink / raw)
  To: Jeong Dal,
	list ntg-context@ntg.nl ntg-context@ntg.nl ntg-context@ntg.nl
	ntg-context@ntg.nl

On 9/26/2018 1:48 AM, Jeong Dal wrote:
> Dear Hans,
> 
> First, it is great to know a new method of drawing an outlined font!
> 
>   I have applied it to Korean fonts. As you know, every Korean character is composed with “consonant+vowel(+consonant)” type. If consonant and vowel are connected (for example, “호”), then it draws correctly, otherwise (for example, “하”)  it draws only consonant.
> Is there a way to count all the paths in a character(even if it is not connected)?
mwe ...

Hans


-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Metafun: Finding intersection between characters
       [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 10:10   ` Hans Hagen
  0 siblings, 2 replies; 17+ messages in thread
From: Jeong Dal @ 2018-09-25 23:48 UTC (permalink / raw)
  To: list ntg-context@ntg.nl ntg-context@ntg.nl ntg-context@ntg.nl
	ntg-context@ntg.nl

Dear Hans,

First, it is great to know a new method of drawing an outlined font!

 I have applied it to Korean fonts. As you know, every Korean character is composed with “consonant+vowel(+consonant)” type. If consonant and vowel are connected (for example, “호”), then it draws correctly, otherwise (for example, “하”)  it draws only consonant.
Is there a way to count all the paths in a character(even if it is not connected)?

Thank you.
Best regards,

Dalyoung


> 
> \starttext
> 
> \startMPdefinitions
> 
>     % will be added to metafun:
> 
>     def filloutlinetext(expr o) =
>         draw image (
>             save n, m ; numeric n, m ; n := m := 0 ;
>             for i within o :
>                 n := n + 1 ;
>             endfor ;
>             for i within o :
>                 m := m + 1 ;
>                 if n = m :
>                     eofill
>                 else :
>                     nofill
>                 fi pathpart i ;
>             endfor ;
>         )
>     enddef ;
> 

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2018-09-28 10:09 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-22  8:35 Metafun: Finding intersection between characters Henri Menke
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

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).