summaryrefslogtreecommitdiff
path: root/tex/context/base/typo-txt.mkvi
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/typo-txt.mkvi')
-rw-r--r--tex/context/base/typo-txt.mkvi174
1 files changed, 150 insertions, 24 deletions
diff --git a/tex/context/base/typo-txt.mkvi b/tex/context/base/typo-txt.mkvi
index f2859b58f..f1c80c1bd 100644
--- a/tex/context/base/typo-txt.mkvi
+++ b/tex/context/base/typo-txt.mkvi
@@ -2,7 +2,7 @@
%D [ file=typo-txt,
%D version=2011.10.27,
%D title=\CONTEXT\ Typesetting Macros,
-%D subtitle=Texts,
+%D subtitle=Text Hacks,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
@@ -13,12 +13,63 @@
%D This module replaces the by now rather old supp-fun module.
+\writestatus{loading}{ConTeXt Typesetting Macros / Text Hacks}
+
\unprotect
-%D \NormalizeFontHeight \name {sample text} {height} {font}
-%D \NormalizeFontWidth \name {sample text} {width} {font}
-%D \NormalizeTextHeight {font} {height} {text}
-%D \NormalizeTextWidth {font} {width} {text}
+\registerctxluafile{typo-txt}{1.001}
+
+%D \macros
+%D {normalizefontheight,normalizefontwidth,normalizedfontsize}
+%D
+%D Next we introduce some font manipulation macros. When we
+%D want to typeset some text spread in a well defined area, it
+%D can be considered bad practice to manipulate character and
+%D word spacing. In such situations the next few macros can be
+%D of help:
+%D
+%D \starttyping
+%D \normalizefontheight \name {sample text} {height} {font}
+%D \normalizefontwidth \name {sample text} {width} {font}
+%D \stoptyping
+%D
+%D Consider for instance:
+%D
+%D \startbuffer[a]
+%D \NormalizeFontHeight \TempFont {X} {2\baselineskip} {Serif}
+%D \stopbuffer
+%D
+%D \startbuffer[b]
+%D \ruledhbox{\TempFont To Be Or Not To Be}
+%D \stopbuffer
+%D
+%D \typebuffer[a,b] \getbuffer[a]
+%D
+%D This shows up as:
+%D
+%D \startlinecorrection
+%D \ruledhbox{\getbuffer[b]}
+%D \stoplinecorrection
+%D
+%D The horizontal counterpart is:
+%D
+%D \startbuffer[a]
+%D \NormalizeFontWidth \TempFont {This Line Fits} {\hsize} {Serif}
+%D \stopbuffer
+%D
+%D \startbuffer[b]
+%D \ruledhbox{\TempFont This Line Fits}
+%D \stopbuffer
+%D
+%D \typebuffer[a,b] \getbuffer[a]
+%D
+%D This gives:
+%D
+%D \startlinecorrection
+%D \ruledhbox{\getbuffer[b]}
+%D \stoplinecorrection
+%D
+%D The calculated font scale is avaliable in \type {\normalizedfontsize}.
\newbox\b_typo_normalizers
@@ -26,14 +77,14 @@
{\dimexpr\ifdim#1\b_typo_normalizers=\zeropoint
\bodyfontsize
\else
- \cldcontext{\number\dimexpr10pt\relax*\number\dimexpr#size\relax/\number#axis\b_typo_normalizers}\scaledpoint
+ \luaexpr{\number\dimexpr10pt\relax*\number\dimexpr#size\relax/\number#axis\b_typo_normalizers}\scaledpoint
\fi\relax}
\def\typo_normalizers_font_at_size#axis#cs#text#size#font% avoid overflow by using lua
{\begingroup
\setbox\b_typo_normalizers\hbox{\definedfont[#font at 10pt]\settrialtypesetting#text}%
- \normalexpanded{\endgroup\edef\noexpand\TheNormalizedFontSize{\the\typo_normalizers_size{#axis}{#size}}}%
- \edef#cs{\noexpand\definedfont[#font at \TheNormalizedFontSize]}}
+ \normalexpanded{\endgroup\edef\noexpand\normalizedfontsize{\the\typo_normalizers_size{#axis}{#size}}}%
+ \definefont[\strippedcsname#cs][#font at \normalizedfontsize]}
\unexpanded\def\typo_normalizers_text_at_size#axis#font#size#text%
{\dontleavehmode
@@ -42,30 +93,105 @@
\definedfont[#font at \the\typo_normalizers_size{#axis}{#size}]#text%
\endgroup}
-\let\TheNormalizedFontSize\!!zeropoint
+\def\normalizedfontsize{\bodyfontsize}
+
+\unexpanded\def\normalizetextwidth {\typo_normalizers_text_at_size\wd}
+\unexpanded\def\normalizetextheight{\typo_normalizers_text_at_size\ht}
+\unexpanded\def\normalizetextdepth {\typo_normalizers_text_at_size\dp}
+\unexpanded\def\normalizetextline {\typo_normalizers_text_at_size\htdp}
+
+\unexpanded\def\normalizefontwidth {\typo_normalizers_font_at_size\wd}
+\unexpanded\def\normalizefontheight{\typo_normalizers_font_at_size\ht}
+\unexpanded\def\normalizefontdepth {\typo_normalizers_font_at_size\dp}
+\unexpanded\def\normalizefontline {\typo_normalizers_font_at_size\htdp}
-%D Traditionally we use UpperCasedNames for this kind of
-%D functionality.
+\unexpanded\def\widthspanningtext #text#size#specification{\hbox{\normalizefontwidth \temp{#text}{#size}{#specification}\temp#text}}
+\unexpanded\def\heightspanningtext#text#size#specification{\hbox{\normalizefontheight\temp{#text}{#size}{#specification}\temp#text}}
+\unexpanded\def\depthspanningtext #text#size#specification{\hbox{\normalizefontdepth \temp{#text}{#size}{#specification}\temp#text}}
+\unexpanded\def\linespanningtext #text#size#specification{\hbox{\normalizefontline \temp{#text}{#size}{#specification}\temp#text}}
-\unexpanded\def\NormalizeFontHeight{\typo_normalizers_font_at_size\ht}
-\unexpanded\def\NormalizeFontWidth {\typo_normalizers_font_at_size\wd}
+%D Traditionally we use UpperCasedNames for this kind of functionality.
-\unexpanded\def\NormalizeTextHeight{\typo_normalizers_text_at_size\ht}
-\unexpanded\def\NormalizeTextWidth {\typo_normalizers_text_at_size\wd}
+\let\NormalizeFontHeight \normalizefontheight
+\let\NormalizeFontWidth \normalizefontwidth
+\let\NormalizeTextHeight \normalizetextheight
+\let\NormalizeTextWidth \normalizetextwidth
-\unexpanded\def\WidthSpanningText#text#width#font% compatibility macro
- {\hbox{\NormalizeFontWidth\temp{#text}{#width}{#font}\temp\the\everydefinedfont#1}}
+\let\WidthSpanningText \widthspanningtext
+\def\TheNormalizedFontSize{\normalizedfontsize}
+
+%D \macros
+%D {vulgarfraction}
+%D
+%D This code is moved from \type {cor-mis.mkiv}. We show three versions. First
+%D the simple one using \type {\low} and \type {high}:
+%D
%D \startbuffer
-%D \NormalizeFontWidth \MyFontName {sample text} {10cm} {Serif*default}
+%D \def\vfrac#1#2%
+%D {\hbox{\high{\tx#1\kern-.25em}/\low{\kern-.25em\tx#2}}}
+%D
+%D test \vfrac{1}{2} test \vfrac{123}{456} test
+%D \stopbuffer
+%D
+%D \typebuffer {\showmakeup\getbuffer}
+%D
+%D A better way to handle the kerning is the following, here we kind of assume
+%D that tye slash is symmetrical and has nearly zero width.
%D
-%D \ruledhbox{\MyFontName sample text}
-%D \blank
-%D \blackrule[width=10cm]
-%D \blank
-%D \ruledhbox{\NormalizeTextWidth {Serif*default} {10cm} {sample text}}
+%D \startbuffer
+%D \def\vfract#1#2%
+%D {\hbox{\high{\tx#1}\hbox to \zeropoint{\hss/\hss}\low{\tx#2}}}
%D \stopbuffer
%D
-%D \typebuffer \getbuffer
+%D \typebuffer {\showmakeup\getbuffer}
+%D
+%D The third and best alternative is the following:
+%D
+%D {\showmakeup\getbuffer}\crlf\getbuffer
+%D
+%D This time we measure the height of the \type {/} and shift over the maximum
+%D height and depths of this character and the fractional digits (we use 57 as
+%D sample). Here we combine all methods in one macros.
+
+\setnewconstant\vulgarfractionmethod\plusthree
+
+\definehspace[\v!vulgarfraction][.25em] % [.15em]
+\definesymbol[\v!vulgarfraction][/] % [\raise.2ex\hbox{/}]
+
+\unexpanded\def\vulgarfraction#1#2%
+ {\dontleavehmode
+ \hbox
+ {\def\vulgarfraction{vulgarfraction}%
+ \ifcase\vulgarfractionmethod
+ #1\symbol[\v!vulgarfraction]#2%
+ \or
+ \high{\tx#1\kern-\hspaceamount\empty\v!vulgarfraction}%
+ \symbol[\vulgarfraction]%
+ \low {\kern-\hspaceamount\empty\v!vulgarfraction\tx#2}%
+ \or
+ \high{\tx#1}%
+ \hbox to \zeropoint{\hss\symbol[\v!vulgarfraction]\hss}%
+ \low{\tx#2}%
+ \or
+ \setbox0\hbox{\symbol[\vulgarfraction]}%
+ \setbox2\hbox{\txx57}%
+ \raise\ht0\hbox{\lower\ht2\hbox{\txx#1}}%
+ \hbox to \zeropoint{\hss\symbol[\v!vulgarfraction]\hss}%
+ \lower\dp0\hbox{\raise\dp2\hbox{\txx#2}}%
+ \fi}}
+
+\ifdefined\vfrac \else \let\vfrac\vulgarfraction \fi
+
+%D \starttabulate[|l|l|]
+%D \HL
+%D \NC \bf method \NC \bf visualization \NC\NR
+%D \HL
+%D \NC 0 \NC \vulgarfractionmethod0 \vulgarfraction{1}{2} \NC\NR
+%D \NC 1 \NC \vulgarfractionmethod1 \vulgarfraction{1}{2} \NC\NR
+%D \NC 2 \NC \vulgarfractionmethod2 \vulgarfraction{1}{2} \NC\NR
+%D \NC 3 \NC \vulgarfractionmethod3 \vulgarfraction{1}{2} \NC\NR
+%D \HL
+%D \stoptabulate
\protect \endinput