Last active
September 7, 2015 10:56
-
-
Save dohyunkim/35a40c3dbf5a9509128c to your computer and use it in GitHub Desktop.
draw glyph box for each and every glyph in a truetype/opentype font
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| \begingroup\expandafter\expandafter\expandafter\endgroup | |
| \expandafter\ifx\csname selectfont\endcsname\relax | |
| \edef\catcodeofatchar{\catcode`@=\the\catcode`@} | |
| \catcode`@=11 | |
| \newdimen\@tempdima \newdimen\@tempdimb | |
| \newcount\@tempcnta \newcount\@tempcntb | |
| \else | |
| \ProvidesPackage{fontglyphs}[2015/06/15 v0.1 Draw box of each and every glyphs in a truetype/opentype font] | |
| \fi | |
| \newdimen\glyphboxlinewd | |
| \glyphboxlinewd=0.1pt | |
| \begingroup | |
| \lccode`!=`a \lccode`?=`t | |
| \lowercase{\endgroup | |
| \def\removesizepart#1 !?#2\end{#1}} | |
| \def\fontglyphs{% | |
| \begingroup | |
| \baselineskip2em plus.2em minus.2em | |
| \parindent=0pt | |
| \fontname\font\par\bigskip | |
| \ifdefined\tiny\else | |
| \begingroup \lccode`!=`a \lccode`?=`t | |
| \lowercase{\endgroup\edef\x{\noexpand\removesizepart\fontname\font\space !?\noexpand\end}} | |
| \expandafter\font\expandafter\tiny\x\space at .5\fontdimen6\font\relax | |
| \fi | |
| \pretolerance=10000 \parfillskip=0pt % 문단 끝 오른쪽 정렬 | |
| \@tempcnta=0 % glyph index | |
| \@tempcntb\numexpr\XeTeXcountglyphs\font\relax % index of last glyph | |
| \ifnum\@tempcntb>65534 \@tempcntb=65534 \fi % weird. why not 65535 ? | |
| \loop \ifnum\@tempcnta<\@tempcntb | |
| % 500개마다 문단 나누기 | |
| \count@\@tempcnta | |
| \divide\count@ by500 \multiply\count@ by500 | |
| \ifnum\count@=\@tempcnta \endgraf \fi | |
| % 글리프의 높이와 깊이를 잰다 | |
| \setbox0\hbox{\XeTeXglyph\@tempcnta}\dimen@\ht0 \dimen@ii\dp0 | |
| \advance\dimen@\glyphboxlinewd | |
| \advance\dimen@ii\glyphboxlinewd | |
| % 10개마다 글리프 번호 표시 | |
| \count@\@tempcnta | |
| \divide\count@ by10 \multiply\count@ by10 | |
| \ifnum\count@=\@tempcnta | |
| \setbox2\hbox{\tiny\the\@tempcnta}\leavevmode\raise | |
| \dimexpr\ifdim\dimen@>1em \dimen@+.1em\else 1em\fi\relax\hbox to\z@{\unhbox2\hss}% | |
| \fi | |
| % 바운딩박스가 글자폭을 벗어나면 그만큼 간격을 주기 위해... | |
| \@tempdima=\XeTeXglyphbounds 1 \@tempcnta | |
| \@tempdimb=\XeTeXglyphbounds 3 \@tempcnta | |
| % 그려질 글리프 박스: | |
| \setbox0\vbox{\hsize=\dimexpr\wd0+2\glyphboxlinewd\relax | |
| \special{color push rgb 1 0.5 0}% | |
| \hrule height\glyphboxlinewd depth0pt | |
| \hbox{\vrule width\glyphboxlinewd | |
| \special{color pop}% | |
| \special{color push rgb 0 0.5 1}% | |
| \hbox to 0pt{\kern-.5pt\vrule width \dimexpr\wd0+1pt\relax height 0pt depth\glyphboxlinewd\hss}% | |
| \special{color pop}% | |
| \box0 | |
| \special{color push rgb 1 0.5 0}% | |
| \vrule width\glyphboxlinewd | |
| }\hrule height 0pt depth\glyphboxlinewd | |
| \special{color pop}% | |
| }\ht0\dimen@\dp0\dimen@ii | |
| % 이제 진짜 그린다 | |
| \ifnum\@tempdima<0 \kern-\@tempdima \fi | |
| \box0 | |
| \ifnum\@tempdimb<0 \kern-\@tempdimb \fi | |
| \space | |
| \advance\@tempcnta by1 \repeat | |
| \parfillskip=0pt plus 1fil % 마지막 문단 오른쪽은 가지런히 하지 않아도 된다 | |
| \par | |
| \endgroup | |
| } | |
| \ifdefined\catcodeofatchar\catcodeofatchar\fi | |
| \endinput |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
현재 폰트의 모든 글리프를 보여준다. xetex 또는 xelatex을 지원한다.