summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2024-10-06 19:51:00 +0000
committerKarl Berry <karl@freefriends.org>2024-10-06 19:51:00 +0000
commitd50c8f0cc2127805f433b0b65cf470291f9d7af6 (patch)
tree548976431947dd3c7f47036f4f344ca46a21b0ac /Master/texmf-dist/tex
parentf38e17b5b900ea3fe4de3e01997751b13d65d3d2 (diff)
fontscale (6oct24)
git-svn-id: svn://tug.org/texlive/trunk@72479 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r--Master/texmf-dist/tex/latex/fontscale/fontscale.sty470
1 files changed, 258 insertions, 212 deletions
diff --git a/Master/texmf-dist/tex/latex/fontscale/fontscale.sty b/Master/texmf-dist/tex/latex/fontscale/fontscale.sty
index 01c9c8e8e42..9f0fa3bca7c 100644
--- a/Master/texmf-dist/tex/latex/fontscale/fontscale.sty
+++ b/Master/texmf-dist/tex/latex/fontscale/fontscale.sty
@@ -8,8 +8,8 @@
\NeedsTeXFormat{LaTeX2e}[2023-11-01]
\ProvidesExplPackage
{fontscale}
- {2024-09-10}
- {2.4.0}
+ {2024-10-05}
+ {3.0.0}
{A flexible interface for setting font sizes}
% l3kernel version 2023-10-10 added many 'e'-variants.
@@ -26,7 +26,10 @@
% This package does not require any other packages!
-% DECLARE FONT SIZE PARAMETER VARIABLES
+% SOME VARIABLES
+
+% Declares and initializes the font step, font scale, font size, and font
+% baselineskip of each font size command from \tiny to \Huge.
\fp_const:Nn \c_fontscale_tiny_step_fp { -4 }
\fp_const:Nn \c_fontscale_scriptsize_step_fp { -3 }
@@ -73,8 +76,6 @@
\skip_new:N \l_fontscale_huge_baselineskip_skip
\skip_new:N \l_fontscale_Huge_baselineskip_skip
-% INITIALIZE FONT SIZE PARAMETER VARIABLES
-
\fp_set:Nn \l_fontscale_tiny_scale_fp { 0.6 }
\fp_set:Nn \l_fontscale_scriptsize_scale_fp { 0.7 }
\fp_set:Nn \l_fontscale_footnotesize_scale_fp { 0.8 }
@@ -107,17 +108,121 @@
\skip_set:Nn \l_fontscale_huge_baselineskip_skip { 19.2pt }
\skip_set:Nn \l_fontscale_Huge_baselineskip_skip { 21.6pt }
-% SOME VARIABLES
+% Stores the current font step, font scale, font size, and font baselineskip.
+% They are set in the selectfont hook.
+\fp_new:N \l_fontscale_step_fp
+\fp_new:N \l_fontscale_scale_fp
+\dim_new:N \l_fontscale_size_dim
+\skip_new:N \l_fontscale_baselineskip_skip
+
+% For speed, \__fontscale_hook_selectfont: tries to avoid computing a floating
+% point expression by using \fp_set_eq:NN when the font size equals the font
+% size of any font size command from \tiny to \Huge. The case when the font
+% size equals that of \normalsize is optimized further because it is by far
+% the most common case.
+\hook_gput_code:nnn { selectfont } { fontscale }
+ { \__fontscale_hook_selectfont: }
+\cs_new_protected:Npn \__fontscale_hook_selectfont:
+ {
+ \dim_set:Nn \l_fontscale_size_dim { \f@size pt }
+ \skip_set:Nn \l_fontscale_baselineskip_skip { \f@baselineskip }
+ \dim_compare:nNnTF \l_fontscale_size_dim = \l_fontscale_normalsize_size_dim
+ {
+ \fp_set_eq:NN \l_fontscale_step_fp \c_fontscale_normalsize_step_fp
+ \fp_set_eq:NN \l_fontscale_scale_fp \c_fontscale_normalsize_scale_fp
+ }
+ { \__fontscale_hook_selectfont_auxi: }
+ }
+\cs_new_protected:Npn \__fontscale_hook_selectfont_auxi:
+ {
+ \dim_case:nnF { \l_fontscale_size_dim }
+ {
+ { \l_fontscale_small_size_dim }
+ {
+ \fp_set_eq:NN \l_fontscale_step_fp \c_fontscale_small_step_fp
+ \fp_set_eq:NN \l_fontscale_scale_fp \l_fontscale_small_scale_fp
+ }
+ { \l_fontscale_large_size_dim }
+ {
+ \fp_set_eq:NN \l_fontscale_step_fp \c_fontscale_large_step_fp
+ \fp_set_eq:NN \l_fontscale_scale_fp \l_fontscale_large_scale_fp
+ }
+ { \l_fontscale_footnotesize_size_dim }
+ {
+ \fp_set_eq:NN \l_fontscale_step_fp \c_fontscale_footnotesize_step_fp
+ \fp_set_eq:NN \l_fontscale_scale_fp
+ \l_fontscale_footnotesize_scale_fp
+ }
+ { \l_fontscale_Large_size_dim }
+ {
+ \fp_set_eq:NN \l_fontscale_step_fp \c_fontscale_Large_step_fp
+ \fp_set_eq:NN \l_fontscale_scale_fp \l_fontscale_Large_scale_fp
+ }
+ { \l_fontscale_scriptsize_size_dim }
+ {
+ \fp_set_eq:NN \l_fontscale_step_fp \c_fontscale_scriptsize_step_fp
+ \fp_set_eq:NN \l_fontscale_scale_fp \l_fontscale_scriptsize_scale_fp
+ }
+ { \l_fontscale_LARGE_size_dim }
+ {
+ \fp_set_eq:NN \l_fontscale_step_fp \c_fontscale_LARGE_step_fp
+ \fp_set_eq:NN \l_fontscale_scale_fp \l_fontscale_LARGE_scale_fp
+ }
+ { \l_fontscale_tiny_size_dim }
+ {
+ \fp_set_eq:NN \l_fontscale_step_fp \c_fontscale_tiny_step_fp
+ \fp_set_eq:NN \l_fontscale_scale_fp \l_fontscale_tiny_scale_fp
+ }
+ { \l_fontscale_huge_size_dim }
+ {
+ \fp_set_eq:NN \l_fontscale_step_fp \c_fontscale_huge_step_fp
+ \fp_set_eq:NN \l_fontscale_scale_fp \l_fontscale_huge_scale_fp
+ }
+ { \l_fontscale_Huge_size_dim }
+ {
+ \fp_set_eq:NN \l_fontscale_step_fp \c_fontscale_Huge_step_fp
+ \fp_set_eq:NN \l_fontscale_scale_fp \l_fontscale_Huge_scale_fp
+ }
+ }
+ { \__fontscale_hook_selectfont_auxii: }
+ }
+% For speed, \f@size is used here instead of \l_fontscale_size_dim. The case
+% where the base font size of the musical typographic scale equals the font
+% size of \normalsize is optimized further.
+\cs_new_protected:Npn \__fontscale_hook_selectfont_auxii:
+ {
+ \fp_set:Nn \l_fontscale_scale_fp
+ { \f@size / \l__fontscale_normalsize_size_fp }
+ \str_if_eq:VnTF \l__fontscale_typographic_scale_str { musical }
+ {
+ \dim_compare:nNnTF \l__fontscale_musical_base_dim =
+ \l_fontscale_normalsize_size_dim
+ {
+ \fp_set:Nn \l_fontscale_step_fp
+ {
+ \l__fontscale_musical_selectfont_fp
+ * ln ( \l_fontscale_scale_fp )
+ }
+ }
+ {
+ \fp_set:Nn \l_fontscale_step_fp
+ {
+ \l__fontscale_musical_selectfont_fp
+ * ln ( \f@size / \l__fontscale_musical_base_fp )
+ }
+ }
+ }
+ { \fp_set_eq:NN \l_fontscale_step_fp \c_nan_fp }
+ }
-% Used to speed up floating point calculations.
+% Used only to speed up floating point calculations.
\fp_new:N \l__fontscale_normalsize_size_fp
\fp_set:Nn \l__fontscale_normalsize_size_fp { 10 }
\fp_new:N \l__fontscale_musical_base_fp
\fp_new:N \l__fontscale_musical_notes_fp
+\fp_new:N \l__fontscale_musical_selectfont_fp
% Scratch variables
-\tl_new:N \l__fontscale_tmp_tl
-\str_new:N \l__fontscale_tmp_str
\dim_new:N \l__fontscale_tmp_dim
\skip_new:N \l__fontscale_tmp_skip
\fp_new:N \l__fontscale_tmp_fp
@@ -127,7 +232,7 @@
% Variants of l3kernel functions
\cs_generate_variant:Nn \msg_error:nnnn { nnv , nne }
% Sets a dimen/skip variable from a dimen/skip expression, appending a default
-% unit of pt. This also removes extra tokens.
+% unit of pt. This also removes any extra tokens.
\cs_new_protected:Npn \__fontscale_dim_set_default_pt:Nn #1#2
{
\afterassignment \use_none_delimit_by_q_stop:w
@@ -142,56 +247,59 @@
\q_stop
}
\cs_generate_variant:Nn \__fontscale_skip_set_default_pt:Nn { c }
+% Argument processors. A default 'pt' is appended only in user-level commands,
+% not in internal programming functions.
+\cs_new_protected:Npn \__fontscale_arg_to_dim_default_pt:n #1
+ {
+ \__fontscale_dim_set_default_pt:Nn \l__fontscale_tmp_dim {#1}
+ \tl_set:NV \ProcessedArgument \l__fontscale_tmp_dim
+ }
+\cs_new_protected:Npn \__fontscale_arg_to_skip_default_pt:n #1
+ {
+ \__fontscale_skip_set_default_pt:Nn \l__fontscale_tmp_skip {#1}
+ \tl_set:NV \ProcessedArgument \l__fontscale_tmp_skip
+ }
% Used to define \tiny to \Huge. Sets \@currsize only for compatibility. Need
% \dim_use:N only for compatibility with the microtype package.
-\cs_new_protected:Npn \__fontscale_fontsize:NNN #1#2#3
+\cs_new_protected:Npn \__fontscale_name:NNN #1#2#3
{
\cs_set_eq:NN \@currsize #1
\fontsize { \dim_use:N #2 } #3 \selectfont
}
% Similar to \fontsize + \selectfont, except that it:
-% (1) Takes dimen and skip expressions as arguments.
+% (1) Takes dimen and skip expressions as arguments without appending a default
+% unit of pt.
% (2) Avoids the issue where \f@size is set to the new font size before the
% second argument is expanded.
% (3) Issues a user-friendly error message if the font size is not a positive
% length.
-\dim_new:N \l__fontscale_fontsize_dim
-\skip_new:N \l__fontscale_fontsize_skip
-\cs_new_protected:Npn \__fontscale_fontsize:nn #1#2
+\cs_new_protected:Npn \__fontscale_set_font_size:nn #1#2
{
- \__fontscale_dim_set_default_pt:Nn \l__fontscale_fontsize_dim {#1}
- \__fontscale_skip_set_default_pt:Nn \l__fontscale_fontsize_skip {#2}
- \dim_compare:nNnTF \l__fontscale_fontsize_dim > \c_zero_dim
- {
- \fontsize \l__fontscale_fontsize_dim \l__fontscale_fontsize_skip
- \selectfont
- }
+ \use:e
{
- \msg_error:nnV { fontscale } { font-size-out-of-bounds }
- \l__fontscale_fontsize_dim
+ \__fontscale_set_font_size_aux:nn { \dim_eval:n {#1} }
+ { \skip_eval:n {#2} }
}
}
-% Similar to the above function, except that it sets the font baselineskip
-% equal to the new font size times the baselineskip-size-ratio.
-\cs_new_protected:Npn \__fontscale_fontsize:n #1
+\cs_new_protected:Npn \__fontscale_set_font_size_aux:nn #1#2
{
- \__fontscale_dim_set_default_pt:Nn \l__fontscale_fontsize_dim {#1}
- \dim_compare:nNnTF \l__fontscale_fontsize_dim > \c_zero_dim
+ \dim_compare:nNnTF {#1} > \c_zero_dim
+ { \fontsize {#1} {#2} \selectfont }
+ { \msg_error:nnn { fontscale } { font-size-out-of-bounds } {#1} }
+ }
+% Similar to \__fontscale_set_font_size:nn, except that it sets the font
+% baselineskip equal to the new font size times the baselineskip-size-ratio.
+\cs_new_protected:Npn \__fontscale_set_font_size:n #1
+ { \use:e { \__fontscale_set_font_size_aux:n { \dim_to_decimal:n {#1} } } }
+\cs_new_protected:Npn \__fontscale_set_font_size_aux:n #1
+ {
+ \dim_compare:nNnTF { #1 pt } > \c_zero_dim
{
- \fontsize \l__fontscale_fontsize_dim
- {
- \fp_to_dim:n
- {
- \l__fontscale_fontsize_dim
- * \l__fontscale_baselineskip_size_ratio_fp
- }
- }
+ \fontsize { #1 pt }
+ { \fp_to_dim:n { #1 * \l__fontscale_baselineskip_size_ratio_fp } }
\selectfont
}
- {
- \msg_error:nnV { fontscale } { font-size-out-of-bounds }
- \l__fontscale_fontsize_dim
- }
+ { \msg_error:nnn { fontscale } { font-size-out-of-bounds } { #1 pt } }
}
% MESSAGES
@@ -247,12 +355,13 @@
\msg_new:nnn { fontscale } { font-step-out-of-bounds }
{
Invalid~ font~ step~ '#1'~ \msg_line_context:. \\
- The~ font~ step~ must~ equal~ an~ integer~ from~ -4~ to~ 5,~
+ The~ font~ step~ must~ equal~ the~ font~ step~ of~
+ any~ font~ size~ command~ from~ \iow_char:N \\tiny~ to~ \iow_char:N \\Huge~
unless~ the~ value~ of~ the~ key~ 'typographic-scale'~ is~ 'musical'.
}
\msg_new:nnn { fontscale } { current-font-step-out-of-bounds }
{
- '\iow_char:N \\SetFontStep*'~ could~ not~ calculate~ the~ new~ font~ step~
+ The~ new~ font~ step~ could~ not~ be~ calculated~
because~ the~ current~ font~ step~ is~ undefined~ \msg_line_context:.
}
@@ -448,8 +557,6 @@
, Huge .value_required:n = true
}
-% INITIALIZE AND PRE-COMPILE KEYS
-
% Pre-compiles the keys with their initial values and then sets the keys to
% their initial values. This is significantly faster than using .initial:n and
% \keys_precompile:nnN.
@@ -514,6 +621,8 @@
{ \__fontscale_keys_set:n {#2} }
}
}
+\cs_new_protected:Npn \__fontscale_keys_reset:n
+ { \__fontscale_keys_set_initial: \__fontscale_keys_set:n }
\cs_new_protected:Npn \__fontscale_keys_set:n #1
{
\keys_set:nn { fontscale } {#1}
@@ -522,8 +631,6 @@
\prg_break:
\prg_break_point:
}
-\cs_new_protected:Npn \__fontscale_keys_reset:n
- { \__fontscale_keys_set_initial: \__fontscale_keys_set:n }
\cs_new_protected:Npn \__fontscale_keys_process:
{
\__fontscale_keys_process_start:
@@ -682,6 +789,11 @@
{ \l__fontscale_musical_base_dim }
\fp_set:Nn \l__fontscale_musical_notes_fp
{ \l__fontscale_musical_notes_int }
+ \fp_set:Nn \l__fontscale_musical_selectfont_fp
+ {
+ \l__fontscale_musical_notes_fp
+ / ln ( \l__fontscale_musical_ratio_fp )
+ }
}
}
\tl_map_function:nN
@@ -737,20 +849,25 @@
{ \__fontscale_keys_process_other_fn_aux:n {#1} }
\prg_break:
\prg_break_point:
- \fp_set:cn { l_fontscale_#1_scale_fp }
- { \use:c { l_fontscale_#1_size_dim } / \l__fontscale_normalsize_size_fp }
\quark_if_no_value:cTF { l__fontscale_#1_baselineskip_tl }
{
+ \fp_set:Nn \l__fontscale_tmp_fp { \use:c { l_fontscale_#1_size_dim } }
+ \fp_set:cn { l_fontscale_#1_scale_fp }
+ { \l__fontscale_tmp_fp / \l__fontscale_normalsize_size_fp }
\skip_set:cn { l_fontscale_#1_baselineskip_skip }
{
\fp_to_dim:n
{
- \use:c { l_fontscale_#1_size_dim }
- * \l__fontscale_baselineskip_size_ratio_fp
+ \l__fontscale_tmp_fp * \l__fontscale_baselineskip_size_ratio_fp
}
}
}
{
+ \fp_set:cn { l_fontscale_#1_scale_fp }
+ {
+ \use:c { l_fontscale_#1_size_dim }
+ / \l__fontscale_normalsize_size_fp
+ }
\__fontscale_skip_set_default_pt:cn
{ l_fontscale_#1_baselineskip_skip }
{ \use:c { l__fontscale_#1_baselineskip_tl } }
@@ -792,7 +909,7 @@
}
\cs_new_protected:Npn \__fontscale_tiny:
{
- \__fontscale_fontsize:NNN \tiny \l_fontscale_tiny_size_dim
+ \__fontscale_name:NNN \tiny \l_fontscale_tiny_size_dim
\l_fontscale_tiny_baselineskip_skip
}
\DeclareDocumentCommand \scriptsize { }
@@ -806,7 +923,7 @@
}
\cs_new_protected:Npn \__fontscale_scriptsize:
{
- \__fontscale_fontsize:NNN \scriptsize \l_fontscale_scriptsize_size_dim
+ \__fontscale_name:NNN \scriptsize \l_fontscale_scriptsize_size_dim
\l_fontscale_scriptsize_baselineskip_skip
}
\DeclareDocumentCommand \footnotesize { }
@@ -820,7 +937,7 @@
}
\cs_new_protected:Npn \__fontscale_footnotesize:
{
- \__fontscale_fontsize:NNN \footnotesize \l_fontscale_footnotesize_size_dim
+ \__fontscale_name:NNN \footnotesize \l_fontscale_footnotesize_size_dim
\l_fontscale_footnotesize_baselineskip_skip
}
\DeclareDocumentCommand \small { }
@@ -834,7 +951,7 @@
}
\cs_new_protected:Npn \__fontscale_small:
{
- \__fontscale_fontsize:NNN \small \l_fontscale_small_size_dim
+ \__fontscale_name:NNN \small \l_fontscale_small_size_dim
\l_fontscale_small_baselineskip_skip
}
\DeclareDocumentCommand \normalsize { }
@@ -848,7 +965,7 @@
}
\cs_new_protected:Npn \__fontscale_normalsize:
{
- \__fontscale_fontsize:NNN \normalsize \l_fontscale_normalsize_size_dim
+ \__fontscale_name:NNN \normalsize \l_fontscale_normalsize_size_dim
\l_fontscale_normalsize_baselineskip_skip
}
\DeclareDocumentCommand \large { }
@@ -862,7 +979,7 @@
}
\cs_new_protected:Npn \__fontscale_large:
{
- \__fontscale_fontsize:NNN \large \l_fontscale_large_size_dim
+ \__fontscale_name:NNN \large \l_fontscale_large_size_dim
\l_fontscale_large_baselineskip_skip
}
\DeclareDocumentCommand \Large { }
@@ -876,7 +993,7 @@
}
\cs_new_protected:Npn \__fontscale_Large:
{
- \__fontscale_fontsize:NNN \Large \l_fontscale_Large_size_dim
+ \__fontscale_name:NNN \Large \l_fontscale_Large_size_dim
\l_fontscale_Large_baselineskip_skip
}
\DeclareDocumentCommand \LARGE { }
@@ -890,7 +1007,7 @@
}
\cs_new_protected:Npn \__fontscale_LARGE:
{
- \__fontscale_fontsize:NNN \LARGE \l_fontscale_LARGE_size_dim
+ \__fontscale_name:NNN \LARGE \l_fontscale_LARGE_size_dim
\l_fontscale_LARGE_baselineskip_skip
}
\DeclareDocumentCommand \huge { }
@@ -904,7 +1021,7 @@
}
\cs_new_protected:Npn \__fontscale_huge:
{
- \__fontscale_fontsize:NNN \huge \l_fontscale_huge_size_dim
+ \__fontscale_name:NNN \huge \l_fontscale_huge_size_dim
\l_fontscale_huge_baselineskip_skip
}
\DeclareDocumentCommand \Huge { }
@@ -918,109 +1035,25 @@
}
\cs_new_protected:Npn \__fontscale_Huge:
{
- \__fontscale_fontsize:NNN \Huge \l_fontscale_Huge_size_dim
+ \__fontscale_name:NNN \Huge \l_fontscale_Huge_size_dim
\l_fontscale_Huge_baselineskip_skip
}
\normalsize
\NewExpandableDocumentCommand \CurrentFontStep { } { \__fontscale_step: }
\cs_new:Npn \__fontscale_step:
- {
- \dim_case:nnF { \f@size pt }
- {
- { \l_fontscale_tiny_size_dim } { -4 }
- { \l_fontscale_scriptsize_size_dim } { -3 }
- { \l_fontscale_footnotesize_size_dim } { -2 }
- { \l_fontscale_small_size_dim } { -1 }
- { \l_fontscale_normalsize_size_dim } { 0 }
- { \l_fontscale_large_size_dim } { 1 }
- { \l_fontscale_Large_size_dim } { 2 }
- { \l_fontscale_LARGE_size_dim } { 3 }
- { \l_fontscale_huge_size_dim } { 4 }
- { \l_fontscale_Huge_size_dim } { 5 }
- }
- {
- \str_if_eq:VnT \l__fontscale_typographic_scale_str { musical }
- {
- \fp_eval:n
- {
- \l__fontscale_musical_notes_fp
- * ln ( \f@size / \l__fontscale_musical_base_fp )
- / ln ( \l__fontscale_musical_ratio_fp )
- }
- }
- }
- }
+ { \fp_if_nan:nF { \l_fontscale_step_fp } { \fp_use:N \l_fontscale_step_fp } }
\NewExpandableDocumentCommand \CurrentFontScale { } { \__fontscale_scale: }
-\cs_new:Npn \__fontscale_scale:
- { \fp_eval:n { \f@size / \l__fontscale_normalsize_size_fp } }
+\cs_new:Npn \__fontscale_scale: { \fp_use:N \l_fontscale_scale_fp }
\NewExpandableDocumentCommand \CurrentFontSize { } { \__fontscale_size: }
-\cs_new:Npn \__fontscale_size: { \f@size pt }
+\cs_new:Npn \__fontscale_size: { \dim_use:N \l_fontscale_size_dim }
\NewExpandableDocumentCommand \CurrentFontBaselineskip { }
{ \__fontscale_baselineskip: }
-\cs_new:Npn \__fontscale_baselineskip: { \f@baselineskip }
-
-\NewExpandableDocumentCommand \CurrentFontSizeCommand { }
- { \__fontscale_name: }
-\cs_new:Npn \__fontscale_name:
- {
- \dim_case:nn { \f@size pt }
- {
- { \l_fontscale_tiny_size_dim }
- {
- \skip_if_eq:nnT { \l_fontscale_tiny_baselineskip_skip }
- { \f@baselineskip } { tiny }
- }
- { \l_fontscale_scriptsize_size_dim }
- {
- \skip_if_eq:nnT { \l_fontscale_scriptsize_baselineskip_skip }
- { \f@baselineskip } { scriptsize }
- }
- { \l_fontscale_footnotesize_size_dim }
- {
- \skip_if_eq:nnT { \l_fontscale_footnotesize_baselineskip_skip }
- { \f@baselineskip } { footnotesize }
- }
- { \l_fontscale_small_size_dim }
- {
- \skip_if_eq:nnT { \l_fontscale_small_baselineskip_skip }
- { \f@baselineskip } { small }
- }
- { \l_fontscale_normalsize_size_dim }
- {
- \skip_if_eq:nnT { \l_fontscale_normalsize_baselineskip_skip }
- { \f@baselineskip } { normalsize }
- }
- { \l_fontscale_large_size_dim }
- {
- \skip_if_eq:nnT { \l_fontscale_large_baselineskip_skip }
- { \f@baselineskip } { large }
- }
- { \l_fontscale_Large_size_dim }
- {
- \skip_if_eq:nnT { \l_fontscale_Large_baselineskip_skip }
- { \f@baselineskip } { Large }
- }
- { \l_fontscale_LARGE_size_dim }
- {
- \skip_if_eq:nnT { \l_fontscale_LARGE_baselineskip_skip }
- { \f@baselineskip } { LARGE }
- }
- { \l_fontscale_huge_size_dim }
- {
- \skip_if_eq:nnT { \l_fontscale_huge_baselineskip_skip }
- { \f@baselineskip } { huge }
- }
- { \l_fontscale_Huge_size_dim }
- {
- \skip_if_eq:nnT { \l_fontscale_Huge_baselineskip_skip }
- { \f@baselineskip } { Huge }
- }
- }
- }
+\cs_new:Npn \__fontscale_baselineskip:
+ { \skip_use:N \l_fontscale_baselineskip_skip }
\NewDocumentCommand \SetFontStep { s m }
{
@@ -1035,11 +1068,18 @@
{ \__fontscale_set_font_step:n {#2} }
}
}
+\cs_new_protected:Npn \__fontscale_add_font_step:n #1
+ {
+ \fp_if_nan:nTF { \l_fontscale_step_fp }
+ { \msg_error:nn { fontscale } { current-font-step-out-of-bounds } }
+ { \__fontscale_set_font_step:n { (#1) + \l_fontscale_step_fp } }
+ }
% Using \str_case: here is significantly faster (and easier to write) than
% repeatedly testing \fp_compare:.
\cs_new_protected:Npn \__fontscale_set_font_step:n #1
{
- \str_case:enF { \fp_eval:n {#1} }
+ \fp_set:Nn \l__fontscale_tmp_fp { round ( #1 , 5 ) }
+ \str_case:enF { \fp_use:N \l__fontscale_tmp_fp }
{
{ -4 } { \tiny }
{ -3 } { \scriptsize }
@@ -1055,30 +1095,22 @@
{
\str_if_eq:VnTF \l__fontscale_typographic_scale_str { musical }
{
- \__fontscale_fontsize:n
+ \__fontscale_set_font_size:n
{
\fp_to_dim:n
{
\l__fontscale_musical_base_fp
* \l__fontscale_musical_ratio_fp
- ^ ( (#1) / \l__fontscale_musical_notes_fp )
+ ^ ( \l__fontscale_tmp_fp / \l__fontscale_musical_notes_fp )
}
}
}
{
\msg_error:nne { fontscale } { font-step-out-of-bounds }
- { \fp_eval:n {#1} }
+ { \fp_use:N \l__fontscale_tmp_fp }
}
}
}
-\cs_new_protected:Npn \__fontscale_add_font_step:n #1
- {
- \tl_set:Ne \l__fontscale_tmp_tl { \__fontscale_step: }
- \tl_if_empty:NTF \l__fontscale_tmp_tl
- { \msg_error:nn { fontscale } { current-font-step-out-of-bounds } }
- { \__fontscale_add_font_step_aux:n { (#1) + \l__fontscale_tmp_tl } }
- }
-\cs_new_eq:NN \__fontscale_add_font_step_aux:n \__fontscale_set_font_step:n
\NewDocumentCommand \SetFontScale { s m }
{
@@ -1093,18 +1125,16 @@
{ \__fontscale_set_font_scale:n {#2} }
}
}
-\cs_new_protected:Npn \__fontscale_set_font_scale:n #1
- {
- \__fontscale_fontsize:n
- { \fp_to_dim:n { \l__fontscale_normalsize_size_fp * (#1) } }
- }
\cs_new_protected:Npn \__fontscale_add_font_scale:n #1
+ { \__fontscale_set_font_scale:n { (#1) + \l_fontscale_scale_fp } }
+\cs_new_protected:Npn \__fontscale_set_font_scale:n #1
{
- \__fontscale_fontsize:n
- { \fp_to_dim:n { \l__fontscale_normalsize_size_fp * (#1) + \f@size } }
+ \__fontscale_set_font_size:n
+ { \fp_to_dim:n { (#1) * \l__fontscale_normalsize_size_fp } }
}
-\NewDocumentCommand \SetFontSize { s m }
+\NewDocumentCommand \SetFontSize
+ { s >{ \__fontscale_arg_to_dim_default_pt:n } m }
{
\mode_if_math:TF
{
@@ -1117,12 +1147,8 @@
{ \__fontscale_set_font_size:n {#2} }
}
}
-\cs_new_eq:NN \__fontscale_set_font_size:n \__fontscale_fontsize:n
\cs_new_protected:Npn \__fontscale_add_font_size:n #1
- {
- \__fontscale_dim_set_default_pt:Nn \l__fontscale_tmp_dim {#1}
- \__fontscale_fontsize:n { \l__fontscale_tmp_dim + \f@size pt }
- }
+ { \__fontscale_set_font_size:n { (#1) + \l_fontscale_size_dim } }
\NewDocumentCommand \ScaleFont { m }
{
@@ -1136,27 +1162,29 @@
\cs_new_protected:Npn \__fontscale_scale_font:n #1
{
\fp_set:Nn \l__fontscale_tmp_fp {#1}
- \__fontscale_fontsize:nn
- { \fp_to_dim:n { \f@size * \l__fontscale_tmp_fp } }
+ \__fontscale_set_font_size:nn
+ { \fp_to_dim:n { \l__fontscale_tmp_fp * \l_fontscale_size_dim } }
{
- \fp_to_dim:n
- { \dim_to_fp:n { \f@baselineskip } * \l__fontscale_tmp_fp }
+ \fp_to_dim:n { \l__fontscale_tmp_fp * \l_fontscale_baselineskip_skip }
}
}
-\NewDocumentCommand \SetFontSizeBaselineskip { m m }
+\NewDocumentCommand \SetFontSizeBaselineskip
+ {
+ >{ \__fontscale_arg_to_dim_default_pt:n } m
+ >{ \__fontscale_arg_to_skip_default_pt:n } m
+ }
{
\mode_if_math:TF
{
\msg_warning:nne { fontscale } { math-mode-warning }
{ \token_to_str:N \SetFontSizeBaselineskip }
}
- { \__fontscale_set_font_size_baselineskip:nn {#1} {#2} }
+ { \__fontscale_set_font_size:nn {#1} {#2} }
}
-\cs_new_eq:NN \__fontscale_set_font_size_baselineskip:nn
- \__fontscale_fontsize:nn
-\NewDocumentCommand \SetFontBaselineskip { s m }
+\NewDocumentCommand \SetFontBaselineskip
+ { s >{ \__fontscale_arg_to_skip_default_pt:n } m }
{
\mode_if_math:TF
{
@@ -1169,14 +1197,13 @@
{ \__fontscale_set_font_baselineskip:n {#2} }
}
}
-\cs_new_protected:Npn \__fontscale_set_font_baselineskip:n
- { \__fontscale_fontsize:nn { \f@size pt } }
\cs_new_protected:Npn \__fontscale_add_font_baselineskip:n #1
{
- \__fontscale_skip_set_default_pt:Nn \l__fontscale_tmp_skip {#1}
- \__fontscale_fontsize:nn { \f@size pt }
- { \l__fontscale_tmp_skip + \f@baselineskip }
+ \__fontscale_set_font_baselineskip:n
+ { (#1) + \l_fontscale_baselineskip_skip }
}
+\cs_new_protected:Npn \__fontscale_set_font_baselineskip:n
+ { \__fontscale_set_font_size:nn { \l_fontscale_size_dim } }
\NewDocumentCommand \PrintFontSizeParameters { }
{ \__fontscale_print_font_size_parameters: }
@@ -1215,7 +1242,7 @@
}
}
-\NewDocumentCommand \PrintSampleText { s +m }
+\NewDocumentCommand \PrintSampleText { >{ \ReverseBoolean } s +m }
{
\mode_if_math:TF
{
@@ -1223,30 +1250,32 @@
{ \token_to_str:N \PrintSampleText }
}
{
- \group_begin:
- \IfBooleanTF #1
- { \__fontscale_print_sample_text_descending_order:n {#2} }
- { \__fontscale_print_sample_text_ascending_order:n {#2} }
- \group_end:
+ \IfBooleanTF #1
+ { \__fontscale_print_sample_text_ascending_order:n {#2} }
+ { \__fontscale_print_sample_text_descending_order:n {#2} }
}
}
\cs_new_protected:Npn \__fontscale_print_sample_text_ascending_order:n #1
{
- \tl_map_inline:nn
- {
- \tiny \scriptsize \footnotesize \small \normalsize
- \large \Large \LARGE \huge \Huge
- }
- { ##1 #1 \par }
+ \group_begin:
+ \tl_map_inline:nn
+ {
+ \tiny \scriptsize \footnotesize \small \normalsize
+ \large \Large \LARGE \huge \Huge
+ }
+ { ##1 #1 \par }
+ \group_end:
}
\cs_new_protected:Npn \__fontscale_print_sample_text_descending_order:n #1
{
- \tl_map_inline:nn
- {
- \Huge \huge \LARGE \Large \large
- \normalsize \small \footnotesize \scriptsize \tiny
- }
- { ##1 #1 \par }
+ \group_begin:
+ \tl_map_inline:nn
+ {
+ \Huge \huge \LARGE \Large \large
+ \normalsize \small \footnotesize \scriptsize \tiny
+ }
+ { ##1 #1 \par }
+ \group_end:
}
\NewDocumentCommand \PrintFontSizeCommand { }
@@ -1260,10 +1289,24 @@
}
\cs_new_protected:Npn \__fontscale_print_name:
{
- \str_set:Ne \l__fontscale_tmp_str { \__fontscale_name: }
- \str_if_empty:NTF \l__fontscale_tmp_str
- { \token_to_str:N \undefined }
- { \c_backslash_str \l__fontscale_tmp_str \@ }
+ \token_to_str:c
+ {
+ \dim_case:nnF { \l_fontscale_size_dim }
+ {
+ { \l_fontscale_tiny_size_dim } { tiny }
+ { \l_fontscale_scriptsize_size_dim } { scriptsize }
+ { \l_fontscale_footnotesize_size_dim } { footnotesize }
+ { \l_fontscale_small_size_dim } { small }
+ { \l_fontscale_normalsize_size_dim } { normalsize }
+ { \l_fontscale_large_size_dim } { large }
+ { \l_fontscale_Large_size_dim } { Large }
+ { \l_fontscale_LARGE_size_dim } { LARGE }
+ { \l_fontscale_huge_size_dim } { huge }
+ { \l_fontscale_Huge_size_dim } { Huge }
+ }
+ { undefined }
+ }
+ \@
}
% TEXT PURIFY
@@ -1271,7 +1314,10 @@
\NewExpandableDocumentCommand \__fontscale_use_none_sm:w { s m } { }
\tl_map_inline:nn
{
- \fontscalesetup \SetFontStep \SetFontScale \SetFontSize
+ \fontscalesetup
+ \SetFontStep
+ \SetFontScale
+ \SetFontSize
\SetFontBaselineskip
}
{ \text_declare_purify_equivalent:Nn #1 { \__fontscale_use_none_sm:w } }