ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: "Charles P. Schaum" <verbo.solo@sbcglobal.net>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Kerning and Scaling
Date: Sat, 23 Aug 2008 17:55:38 -0500	[thread overview]
Message-ID: <1219532138.8991.18.camel@elbereth> (raw)
In-Reply-To: <1219508410.5826.12.camel@elbereth>

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
___________________________________________________________________________________


      parent reply	other threads:[~2008-08-23 22:55 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-23 13:23 ConTeXt Minimals on Mac Alan Bowen
2008-08-23 16:20 ` Charles P. Schaum
2008-08-23 17:16   ` Alan Bowen
2008-08-23 23:35     ` Charles P. Schaum
2008-08-24 11:29       ` Alan Bowen
2008-08-24  1:04     ` Charles P. Schaum
2008-08-24 11:54       ` Alan Bowen
2008-08-24 18:32         ` Charles P. Schaum
2008-08-26 15:22           ` Alan Bowen
2008-08-23 22:55   ` Charles P. Schaum [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1219532138.8991.18.camel@elbereth \
    --to=verbo.solo@sbcglobal.net \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).