Re: [NTG-context] Metafun: Finding intersection between characters
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 ;
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 -----------------------------------------------------------------
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 %%%%%%%
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 -----------------------------------------------------------------
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 -----------------------------------------------------------------
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 -----------------------------------------------------------------
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. Thank you for your concern. Best regards, Dalyoung
On 9/26/2018 11:38 PM, Jeong Dal wrote:
Dear Hans,
2018. 9. 26. 오후 9:24, Hans Hagen
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 -----------------------------------------------------------------
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
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 -----------------------------------------------------------------
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 -----------------------------------------------------------------
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 -----------------------------------------------------------------
participants (2)
-
Hans Hagen
-
Jeong Dal