From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/43323 Path: news.gmane.org!not-for-mail From: "Charles P. Schaum" Newsgroups: gmane.comp.tex.context Subject: Kerning and Scaling Date: Sat, 23 Aug 2008 17:55:38 -0500 Message-ID: <1219532138.8991.18.camel@elbereth> References: <15635CB1-AD86-496A-B972-0515F05C53FA@princeton.edu> <1219508410.5826.12.camel@elbereth> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1219532245 20228 80.91.229.12 (23 Aug 2008 22:57:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 23 Aug 2008 22:57:25 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Sun Aug 24 00:58:18 2008 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from ronja.vet.uu.nl ([131.211.172.88] helo=ronja.ntg.nl) by lo.gmane.org with esmtp (Exim 4.50) id 1KX23j-0008Gs-DY for gctc-ntg-context-518@m.gmane.org; Sun, 24 Aug 2008 00:58:15 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 2E4F21FBC1; Sun, 24 Aug 2008 00:57:14 +0200 (CEST) Original-Received: from ronja.ntg.nl ([127.0.0.1]) by localhost (smtp.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 06276-02-5; Sun, 24 Aug 2008 00:56:27 +0200 (CEST) Original-Received: from ronja.vet.uu.nl (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 38A011FBD5; Sun, 24 Aug 2008 00:56:27 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 172D71FBD5 for ; Sun, 24 Aug 2008 00:56:23 +0200 (CEST) Original-Received: from ronja.ntg.nl ([127.0.0.1]) by localhost (smtp.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 06276-02-4 for ; Sun, 24 Aug 2008 00:55:44 +0200 (CEST) Original-Received: from smtp113.sbc.mail.mud.yahoo.com (smtp113.sbc.mail.mud.yahoo.com [68.142.198.212]) by ronja.ntg.nl (Postfix) with SMTP id 0FF2C1FBB5 for ; Sun, 24 Aug 2008 00:55:41 +0200 (CEST) Original-Received: (qmail 56257 invoked from network); 23 Aug 2008 22:55:40 -0000 Original-Received: from unknown (HELO ?192.168.1.103?) (verbo.solo@sbcglobal.net@69.155.5.152 with plain) by smtp113.sbc.mail.mud.yahoo.com with SMTP; 23 Aug 2008 22:55:40 -0000 X-YMail-OSG: PlbTN9YVM1mPSibfRtcRqo79Bpv4onlrHugTGxdnOrMmRxyguOSAsRFjmlFDJaTasRHptmwpClu9EZz7vu5Tumo9LK9CHKk4bbE6Jn7x_FN.chmHxjlvXE1cuxP3C7oBIE8- X-Yahoo-Newman-Property: ymail-3 In-Reply-To: <1219508410.5826.12.camel@elbereth> X-Mailer: Evolution 2.22.3.1 X-Virus-Scanned: amavisd-new at ntg.nl X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.9 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: ntg-context-bounces@ntg.nl Errors-To: ntg-context-bounces@ntg.nl X-Virus-Scanned: amavisd-new at ntg.nl Xref: news.gmane.org gmane.comp.tex.context:43323 Archived-At: Hi Folks, I wanted to confirm that Hans is **Correct** about font fitting. In fact, I think that scaling is superior. One thing I did find is that one must go real easy with the scaling, e.g., compute the difference between the size you want/need, and see that it isn't too great, as the test shows. This test suite, written for plain, nevertheless will work in ConText IF you set the conditional value \havecontexttrue, which I did below. Some of the exact font results will, however, differ between the two. That was just my not trying to rectify differences in the default fonts and sizes. I found this exercise to be fun for learning about macro expansion, as well as dealing with multiple constraints and tail recursion. Charles ----Cut Here----- %Testing insertion of kerns and stuff \newif\ifhavecontext %\havecontextfalse \havecontexttrue % Here we have two kerns that are equally smaller and larger \newdimen\KernSmall \newdimen\KernLarge \KernSmall=-0.033333em \KernLarge=0.033333em % This is Knuth's length macro from the \Tex Book \def\length#1{\count30=0 \getlength#1\end \number\count30} \def\getlength#1{\ifx#1\end \let\next=\relax \else\advance\count30 by1 \let\next=\getlength\fi \next} % This is a modified version of the length macro. % It's existence is to stuff kerns between any two internal tokens. \newcount\intraword \newdimen\intrakern {\catcode`@=11 \gdef\InsertKern#1#2{\intraword=0\intrakern=#1\@ppend#2\end} \gdef\@ppend#1{\ifx#1\end \def\insertium{}\else \def\insertium{\kern \intrakern}\fi \ifnum\intraword>0\insertium\fi \ifx#1\end \let\next= \relax\else\advance\intraword by1\let\next=\@ppend#1\fi\next}} % But who says you have to use only kerns? {\catcode`@=11 \gdef\InsertStuff#1#2{\intraword=0\gdef\StickIt{#1}\@ppendstuff#2\end} \gdef\@ppendstuff#1{\ifx#1\end \def\insertium{}\else \def \insertium{\StickIt}\fi \ifnum\intraword>0\insertium\fi \ifx#1\end \let \next=\relax\else\advance\intraword by1\let\next=\@ppendstuff#1\fi \next}} % SDF-1 will control the scaled box to equal the negative kerning \newdimen\SDFONE \newdimen\fitdimone \newdimen\fitdimtwo \def\fitbox#1{% \setbox30=\hbox{\InsertKern{\KernSmall}{Garbage\ in,\ garbage\ out.}} \SDFONE=\wd30 \font\custfont=cmr10 scaled 1000 \setbox30=\hbox{\custfont#1} \fitdimone=\SDFONE \fitdimtwo=\wd30 \divide\fitdimtwo by 1000 \divide\fitdimone\fitdimtwo \count30=\fitdimone \font\custfont=cmr10 scaled \count30 \hbox{\custfont#1} } % Okay, and this is what it all comes to\dots \ifhavecontext\starttext\fi \fitbox{OK, Class\dots}\par \bigskip Garbage in, garbage out.\par Ignore spaces and get Knuth's count of \length{Garbage in, garbage out.}.\par Count spaces and get Knuth's count of \length{Garbage\ in,\ garbage\ out.}.\par \smallskip This includes punctuation.\par \bigskip Here you can see the insertion points of the macro.\par \InsertStuff{$_\wedge$}{Garbage\ in,\ garbage\ out.} \medskip Hungry? Want {\bf \InsertStuff{$^{Snacks}$}{Food}}? \medskip Warning! You can put funky stuff in the insertium, but not in the text.\par If you do that, \TeX\ will either produce an error or give you strange results. \bigskip \newdimen\compn \newdimen\comps \newdimen\compl Inserting kerns does have an effect:\par \smallskip Length of ``Garbage in, garbage out'' is \setbox30=\hbox{Garbage in, garbage out}\the\wd30 \compn=\wd30\par Length of ``\InsertKern{\KernSmall}{Garbage\ in,\ garbage\ out}'' is \setbox30=\hbox{\InsertKern{\KernSmall}{Garbage\ in,\ garbage\ out}} \the\wd30 \comps=\wd30\par Length of ``\InsertKern{\KernLarge}{Garbage\ in,\ garbage\ out}'' is \setbox30=\hbox{\InsertKern{\KernLarge}{Garbage\ in,\ garbage\ out}} \the\wd30 \compl=\wd30\par \bigskip Size matters\dots \smallskip {\tt N:} Garbage in, garbage out.\par {\tt S:} {\InsertKern{\KernSmall}{Garbage\ in,\ garbage\ out.}\par {\tt L:} {\InsertKern{\KernLarge}{Garbage\ in,\ garbage\ out.}\par \bigskip Which looks better? Scaled \the\KernSmall \smallskip Negative kern insertion (top) vs. font scaling (bottom):\par \ \ \ \hbox{\InsertKern{\KernSmall}{Garbage\ in,\ garbage\ out.}}\par \ \fitbox{Garbage in, garbage out.} \bigskip I had in mind something a little more radical\dots \KernSmall=-0.066667em \ Scaled \the\KernSmall \smallskip Negative kern insertion (top) vs. font scaling (bottom):\par \ \ \ \hbox{\InsertKern{\KernSmall}{Garbage\ in,\ garbage\ out.}}\par \ \fitbox{Garbage in, garbage out.} \bigskip This is just sick\dots\par \KernSmall=-0.1em Scaled \the\KernSmall \smallskip Negative kern insertion (top) vs. font scaling (bottom):\par \ \ \ \hbox{\InsertKern{\KernSmall}{Garbage\ in,\ garbage\ out.}}\par \ \fitbox{Garbage in, garbage out.} \smallskip \KernSmall=-0.2em Scaled \the\KernSmall \smallskip Negative kern insertion (top) vs. font scaling (bottom):\par \ \ \ \hbox{\InsertKern{\KernSmall}{Garbage\ in,\ garbage\ out.}}\par \ \fitbox{Garbage in, garbage out.} \smallskip \KernSmall=-0.3em Scaled \the\KernSmall \smallskip Negative kern insertion (top) vs. font scaling (bottom):\par \ \ \ \hbox{\InsertKern{\KernSmall}{Garbage\ in,\ garbage\ out.}}\par \ \fitbox{Garbage in, garbage out.} \ifhavecontext\stoptext\else\bye\fi ___________________________________________________________________________________ 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://tex.aanhet.net archive : https://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________