Re: [NTG-context] Metafun: Finding intersection between characters

2018-09-28 Thread Jeong Dal
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  작성:
> 
> 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
___

Re: [NTG-context] Metafun: Finding intersection between characters

2018-09-27 Thread Hans Hagen

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
___

Re: [NTG-context] Metafun: Finding intersection between characters

2018-09-27 Thread Jeong Dal
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  작성:
> 
> On 9/26/2018 11:38 PM, Jeong Dal wrote:
>> Dear Hans,
>>> 2018. 9. 26. 오후 9:24, Hans Hagen >> > 작성:
>>> 
>>> 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
> -
> 

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

Re: [NTG-context] Metafun: Finding intersection between characters

2018-09-27 Thread Hans Hagen

On 9/26/2018 11:38 PM, Jeong Dal wrote:

Dear Hans,

2018. 9. 26. 오후 9:24, Hans Hagen > 작성:


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
-
\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
___
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
___

Re: [NTG-context] Metafun: Finding intersection between characters

2018-09-26 Thread Jeong Dal
Dear Hans,2018. 9. 26. 오후 9:24, Hans Hagen  작성: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 koreanI didn’t think of it.I attached a sample file.Thank you for your concern.Best regards,Dalyoung

outlineKorean.tex
Description: TeX document
___
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
___

Re: [NTG-context] Metafun: Finding intersection between characters

2018-09-26 Thread Hans Hagen

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  작성:

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 : 

Re: [NTG-context] Metafun: Finding intersection between characters

2018-09-26 Thread Jeong Dal
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  작성:
> 
> 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
___

Re: [NTG-context] Metafun: Finding intersection between characters

2018-09-26 Thread Jeong Dal
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
%%%



type-hcrlvt.mkiv
Description: Binary data


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

Re: [NTG-context] Metafun: Finding intersection between characters

2018-09-26 Thread Hans Hagen

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
___

Re: [NTG-context] Metafun: Finding intersection between characters

2018-09-26 Thread Hans Hagen

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
___

Re: [NTG-context] Metafun: Finding intersection between characters

2018-09-25 Thread Jeong Dal
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
___

Re: [NTG-context] Metafun: Finding intersection between characters

2018-09-22 Thread Hans Hagen

On 9/22/2018 3:41 PM, Alan Braslau wrote:

On Sat, 22 Sep 2018 13:45:17 +0200
Hans Hagen  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 works, C works, C works, but N does not work.
not N
Why would that be?
Thanks
.Floris





On 22 Sep 2018, at 11:27, Hans Hagen mailto:j.ha...@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 := 

Re: [NTG-context] Metafun: Finding intersection between characters

2018-09-22 Thread Alan Braslau
On Sat, 22 Sep 2018 13:45:17 +0200
Hans Hagen  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 works, C works, C works, but N does not work.
> > not N
> > Why would that be?
> > Thanks
> > .Floris
> > 
> > 
> > 
> > 
> >> On 22 Sep 2018, at 11:27, Hans Hagen  >> > 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
> >>
> >> 

Re: [NTG-context] Metafun: Finding intersection between characters

2018-09-22 Thread Hans Hagen

On 9/22/2018 12:08 PM, Floris van Manen wrote:

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




On 22 Sep 2018, at 11:27, Hans Hagen > 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 :
      

Re: [NTG-context] Metafun: Finding intersection between characters

2018-09-22 Thread Floris van Manen
It does not seem to work for all character combinations.
e.g. B works, C works, C works, but N does not work.
not N
Why would that be?
Thanks
.Floris





> On 22 Sep 2018, at 11:27, Hans Hagen  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 

Re: [NTG-context] Metafun: Finding intersection between characters

2018-09-22 Thread Hans Hagen

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 

[NTG-context] Metafun: Finding intersection between characters

2018-09-22 Thread Henri Menke
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
___