ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Scaling down symbols and emojis
@ 2019-01-16 20:56 User 19087
  2019-01-16 21:24 ` Wolfgang Schuster
  0 siblings, 1 reply; 10+ messages in thread
From: User 19087 @ 2019-01-16 20:56 UTC (permalink / raw)
  To: ntg-context


[-- Attachment #1.1: Type: text/plain, Size: 1226 bytes --]

I'm having trouble scaling down symbols and emojis. For a while I assumed
these don't scale with the current font size. Then I scoured the mailing
list and realized that while scaling down seems broken, scaling up works as
expected:


\usesymbols[mvs]

\setupsymbolset[martinvogel 2]

%\showallmakeup

\starttext
% Progressively larger as expected.
\symbol[ShortForty]
{\tfa\symbol[ShortForty]}
{\tfb\symbol[ShortForty]}
{\tfc\symbol[ShortForty]}
{\tfd\symbol[ShortForty]}

% Unexpectedly all the same size.
\symbol[ShortForty]
{\tfx\symbol[ShortForty]}
{\tfxx\symbol[ShortForty]}

% This works, but why? Isn't \small just a synonym for \tfx via
% \definealternativestyle? Anyway there is no synonym for \tfxx.
\symbol[ShortForty]
{\switchtobodyfont[small]\symbol[ShortForty]}
{\small\symbol[ShortForty]}

% This also works but is less than ideal when matching surrounding font
sizes.
% Which factor should I use to match \tfxx?
\symbol[ShortForty]
\scale[factor=4]{\symbol[ShortForty]}

% Same as above comment, more or less.
\symbol[ShortForty]
{\switchtobodyfont[5pt]\symbol[ShortForty]}
\stoptext


* MWE for builtin symbols; emojis require local fonts. I assume whichever
solution would apply equally to either.

thanks,

[-- Attachment #1.2: Type: text/html, Size: 1478 bytes --]

[-- Attachment #2: Type: text/plain, Size: 492 bytes --]

___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Scaling down symbols and emojis
  2019-01-16 20:56 Scaling down symbols and emojis User 19087
@ 2019-01-16 21:24 ` Wolfgang Schuster
  2019-01-16 23:29   ` User 19087
                     ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Wolfgang Schuster @ 2019-01-16 21:24 UTC (permalink / raw)
  To: mailing list for ConTeXt users, User 19087

User 19087 schrieb am 16.01.19 um 21:56:
> I'm having trouble scaling down symbols and emojis. For a while I 
> assumed these don't scale with the current font size. Then I scoured 
> the mailing list and realized that while scaling down seems broken, 
> scaling up works as expected:
\tx (or \tfx, \bfx etc.) and \txx are ignored in some cases unlike the 
other size switches (\tfa etc.).

When you need a switch for a smaller size which doesn’t has these 
limitations you can just create them:

\definefontsize [m]
\definefontsize [n]

\setupbodyfontenvironment
   [default]
   [m=0.8,
    n=0.6]

> \usesymbols[mvs]
>
> \setupsymbolset[martinvogel 2]
>
> %\showallmakeup
>
> \starttext
> % Progressively larger as expected.
> \symbol[ShortForty]
> {\tfa\symbol[ShortForty]}
> {\tfb\symbol[ShortForty]}
> {\tfc\symbol[ShortForty]}
> {\tfd\symbol[ShortForty]}
>
> % Unexpectedly all the same size.
> \symbol[ShortForty]
> {\tfx\symbol[ShortForty]}
> {\tfxx\symbol[ShortForty]}
>
> % This works, but why? Isn't \small just a synonym for \tfx via
> % \definealternativestyle? Anyway there is no synonym for \tfxx.
> \symbol[ShortForty]
> {\switchtobodyfont[small]\symbol[ShortForty]}
> {\small\symbol[ShortForty]}
No, \small us the same as \switchtobodyfont[small]
> % This also works but is less than ideal when matching surrounding 
> font sizes.
> % Which factor should I use to match \tfxx?
> \symbol[ShortForty]
> \scale[factor=4]{\symbol[ShortForty]}
x = 0.8
xx = 0.6

Wolfgang

___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Scaling down symbols and emojis
  2019-01-16 21:24 ` Wolfgang Schuster
@ 2019-01-16 23:29   ` User 19087
  2019-01-17 12:39   ` User 19087
  2019-01-17 13:30   ` User 19087
  2 siblings, 0 replies; 10+ messages in thread
From: User 19087 @ 2019-01-16 23:29 UTC (permalink / raw)
  To: Wolfgang Schuster; +Cc: mailing list for ConTeXt users

On Wed, Jan 16, 2019 at 4:24 PM Wolfgang Schuster
<wolfgang.schuster.lists@gmail.com> wrote:
> When you need a switch for a smaller size which doesn’t has these
> limitations you can just create them:
>
> \definefontsize [m]
> \definefontsize [n]
>
> \setupbodyfontenvironment
>    [default]
>    [m=0.8,
>     n=0.6]

In case the current bodyfontenvironment overrides the smaller sizes is
it possible to define 'n' and 'm' in terms of 'x' and 'xx'?

% this should happen after \setupbodyfont so the correct values are fetched
\setupbodyfontenvironment
    [default]
    [m=\getcurrentbodyfontenvironment{x},
     n=\getcurrentbodyfontenvironment{xx}]

> > % This also works but is less than ideal when matching surrounding
> > font sizes.
> > % Which factor should I use to match \tfxx?
> > \symbol[ShortForty]
> > \scale[factor=4]{\symbol[ShortForty]}
> x = 0.8
> xx = 0.6

Or I use {\switchtobodyfont[...]\symbol[ShortForty]} in the document.
At that point the body font may have been switched to a size whose
environment defines different values for 'x' and 'xx'. Or perhaps the
current or default body font, via \definebodyfont, overrides the 'x'
and 'xx' sizes. In either case it would be more flexible to query the
current values of 'x' and 'xx' rather than hardcoding the values of
'n' and 'm'. Is something like this possible:

% provide size name ('xx', 'x', 'a', 'b', 'c', 'd') and contents
\define[2]\at_size_unrestricted{\switchtobodyfont[\getcurrentsize[#1]]#2}

thanks
___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Scaling down symbols and emojis
  2019-01-16 21:24 ` Wolfgang Schuster
  2019-01-16 23:29   ` User 19087
@ 2019-01-17 12:39   ` User 19087
  2019-01-17 13:30   ` User 19087
  2 siblings, 0 replies; 10+ messages in thread
From: User 19087 @ 2019-01-17 12:39 UTC (permalink / raw)
  To: Wolfgang Schuster; +Cc: mailing list for ConTeXt users

On Wed, Jan 16, 2019 at 4:24 PM Wolfgang Schuster
<wolfgang.schuster.lists@gmail.com> wrote:
>
> User 19087 schrieb am 16.01.19 um 21:56:
> > I'm having trouble scaling down symbols and emojis. For a while I
> > assumed these don't scale with the current font size. Then I scoured
> > the mailing list and realized that while scaling down seems broken,
> > scaling up works as expected:
> \tx (or \tfx, \bfx etc.) and \txx are ignored in some cases unlike the
> other size switches (\tfa etc.).

Out of curiosity, why are these switches sometimes ignored?
___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Scaling down symbols and emojis
  2019-01-16 21:24 ` Wolfgang Schuster
  2019-01-16 23:29   ` User 19087
  2019-01-17 12:39   ` User 19087
@ 2019-01-17 13:30   ` User 19087
  2019-01-18 11:47     ` Wolfgang Schuster
  2 siblings, 1 reply; 10+ messages in thread
From: User 19087 @ 2019-01-17 13:30 UTC (permalink / raw)
  To: Wolfgang Schuster; +Cc: mailing list for ConTeXt users

On Wed, Jan 16, 2019 at 4:24 PM Wolfgang Schuster
<wolfgang.schuster.lists@gmail.com> wrote:
> > % Which factor should I use to match \tfxx?
> > \symbol[ShortForty]
> > \scale[factor=4]{\symbol[ShortForty]}
> x = 0.8
> xx = 0.6

That's what the ConTeXt Reference Manual also says, but that doesn't
seem to match what ConTeXt does. The 'x' ratio is 0.835 and the 'xx'
ratio is 0.6667. The 'm' ratio is 0.802 and the 'n' ratio is 0.601,
which is "close enough".

\definefontsize[m]
\definefontsize[n]

\setupbodyfontenvironment
  [default]
  [m=0.8,
   n=0.6,
  ]

\starttext
{\tfx m}{\tfm m}m
{\tfxx m}{\tfn m}m

\setbox\scratchbox\hbox{m}
\the\ht\scratchbox
\setbox\scratchbox\hbox{\tfx m}
\the\ht\scratchbox
\setbox\scratchbox\hbox{\tfxx m}
\the\ht\scratchbox

\setbox\scratchbox\hbox{m}
\the\ht\scratchbox
\setbox\scratchbox\hbox{\tfm m}
\the\ht\scratchbox
\setbox\scratchbox\hbox{\tfn m}
\the\ht\scratchbox
\stoptext
___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Scaling down symbols and emojis
  2019-01-17 13:30   ` User 19087
@ 2019-01-18 11:47     ` Wolfgang Schuster
  2019-01-18 21:44       ` User 19087
  0 siblings, 1 reply; 10+ messages in thread
From: Wolfgang Schuster @ 2019-01-18 11:47 UTC (permalink / raw)
  To: User 19087; +Cc: mailing list for ConTeXt users



User 19087 schrieb am 17.01.19 um 14:30:
> On Wed, Jan 16, 2019 at 4:24 PM Wolfgang Schuster
> <wolfgang.schuster.lists@gmail.com> wrote:
>>> % Which factor should I use to match \tfxx?
>>> \symbol[ShortForty]
>>> \scale[factor=4]{\symbol[ShortForty]}
>> x = 0.8
>> xx = 0.6
> That's what the ConTeXt Reference Manual also says, but that doesn't
> seem to match what ConTeXt does. The 'x' ratio is 0.835 and the 'xx'
> ratio is 0.6667.
The default sizes (12pt, 14.4pt etc,) set the x and xx sizes to a fixed 
size which leads
to differences and the scale factor.

Below are the settings for the 12pt size from font-pre.mkiv:

\definebodyfontenvironment
   [12pt]
   [x=10pt,
    xx=8pt]

Wolfgang

___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Scaling down symbols and emojis
  2019-01-18 11:47     ` Wolfgang Schuster
@ 2019-01-18 21:44       ` User 19087
  2019-01-19  8:42         ` User 19087
  0 siblings, 1 reply; 10+ messages in thread
From: User 19087 @ 2019-01-18 21:44 UTC (permalink / raw)
  To: Wolfgang Schuster; +Cc: mailing list for ConTeXt users

On Wed, Jan 16, 2019 at 6:29 PM User 19087 <se.user19087@gmail.com> wrote:
>> Or I use {\switchtobodyfont[...]\symbol[ShortForty]} in the document.
>> At that point the body font may have been switched to a size whose
>> environment defines different values for 'x' and 'xx'. Or perhaps the
>> current or default body font, via \definebodyfont, overrides the 'x'
>> and 'xx' sizes. In either case it would be more flexible to query the
>> current values of 'x' and 'xx' rather than hardcoding the values of
>> 'n' and 'm'.

On Fri, Jan 18, 2019 at 6:47 AM Wolfgang Schuster
<wolfgang.schuster.lists@gmail.com> wrote:
> The default sizes (12pt, 14.4pt etc,) set the x and xx sizes to a fixed
> size which leads
> to differences and the scale factor.

That's yet another reason to avoiding fixing the values of the 'm' and
'n' sizes. As of now, you have to first decide your font size, lookup
the 'x' and 'xx' sizes in font-pre.mkiv and do a little math... every
time you switch fonts. Instead I've come up with a function that
doesn't depend on hardcoded globals:

\define[2]\tosize{%
    \setbox0=\hbox{\tf x}%
    \setbox1=\hbox{#1 x}%
    \startluacode
    tex.dimen[2] = tex.getdimen("bodyfontsize") * tex.box[1].height /
tex.box[0].height
    \stopluacode%
    {\switchtobodyfont[\the\dimen2]#2}%
}

\tosize{\tfx}{\symbol[ShortForty]}


However I worry that measuring individual letter sizes to deduce the
actual font size may not be foolproof, especially with optical sizes
and so on. There must be some other method (at least via luatex) to
obtain the 'x' and 'xx' sizes as workable dimensions.

thanks,
___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Scaling down symbols and emojis
  2019-01-18 21:44       ` User 19087
@ 2019-01-19  8:42         ` User 19087
  2019-01-19  8:59           ` Wolfgang Schuster
  0 siblings, 1 reply; 10+ messages in thread
From: User 19087 @ 2019-01-19  8:42 UTC (permalink / raw)
  To: Wolfgang Schuster; +Cc: mailing list for ConTeXt users

On Fri, Jan 18, 2019 at 4:44 PM User 19087 <se.user19087@gmail.com> wrote:
> There must be some other method (at least via luatex) to
> obtain the 'x' and 'xx' sizes as workable dimensions.

I've come up with the following macro and I'd like some feedback. Will
it work consistently? Any suggestions for improvement?


% A '\start...\stopluacode' block inside a macro is just as bad (or worse?) to
% escape as '\ctxlua' code. So create a function here for use elsewhere.
%
% There were multiple font sizes in the "specification" and "parameters"
% tables, hopefully I picked the right one.
%
% It turns out that for ConTeXt there is a difference between the 10pt and
% 10.0pt sizes: the former is predefined in the body font environment that
% ships with ConTeXt while the latter causes ConTeXt to generate a new body
% font environment. Unfortunately '\the' displays values with trailing 0s, and
% so the result must be converted to a string and truncated in lua.
\startluacode
userdata = userdata or {}
userdata.fontsize = function ()
    local fs
    fs = font.getfont(font.current()).specification.size
    fs = tostring(fs/2^16):gsub("%.?0+$","") .. "pt"
    return fs
end
\stopluacode

% In some situations the 'tx' and 'txx' sizes are ignored by ConTeXt. This
% macro determines the font size that would have been used by such a command
% and switches the entire body font to that size for the duration of the second
% argument. The chosen size depends on the 'x' and 'xx' values of the specific
% body font environment nearest in size to the current body font, though the
% font itself (via definebodyfont) may override those values.
\define[2]\tosize{%
    % Use a scratch box to prevent any typesetting. Otherwise changes to the
    % font size would be compounded: 'tfxx' remaining in effect after
    % 'switchtobodyfont'. I've also tried stop...starthiding, but that prevents
    % all processing of contents.
    \setbox\scratchbox\hbox{%
        #1%
        % Use a global lua variable rather than globally setting a scratch
        % register.
        \startluacode
        userdata = userdata or {}
        userdata.lastfontsize = userdata.fontsize()
        \stopluacode%
    }%
    {\switchtobodyfont[\ctxlua{context(userdata.lastfontsize)}]#2}%
}

Test{\tfx Test}
\tosize{\tfx Unwanted}{Test{\tfx Test}}
___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Scaling down symbols and emojis
  2019-01-19  8:42         ` User 19087
@ 2019-01-19  8:59           ` Wolfgang Schuster
  2019-01-19 17:50             ` User 19087
  0 siblings, 1 reply; 10+ messages in thread
From: Wolfgang Schuster @ 2019-01-19  8:59 UTC (permalink / raw)
  To: User 19087; +Cc: mailing list for ConTeXt users

User 19087 schrieb am 19.01.19 um 09:42:
> On Fri, Jan 18, 2019 at 4:44 PM User 19087 <se.user19087@gmail.com> wrote:
>> There must be some other method (at least via luatex) to
>> obtain the 'x' and 'xx' sizes as workable dimensions.
Why do you need this when you can just change the style of commands
with use \tfx (e.g. \high or \low) to use the \tfm size?

Wolfgang

___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Scaling down symbols and emojis
  2019-01-19  8:59           ` Wolfgang Schuster
@ 2019-01-19 17:50             ` User 19087
  0 siblings, 0 replies; 10+ messages in thread
From: User 19087 @ 2019-01-19 17:50 UTC (permalink / raw)
  To: Wolfgang Schuster; +Cc: mailing list for ConTeXt users

As far as I can tell (by experimentation), bodyfont environment
features resolve in this order:
* matching size in the current file
* default environment in the current file
* matching size in 'font-pre.mkiv'
* default environment in 'font-pre.mkiv'
* default to 1.0 otherwise
This applies to individual features such as 'a' and 'b' and not entire
blocks. For example, if the [12pt] block provides 'a' but not 'b'
while the [default] block provides 'a' and 'b', then both blocks will
be used: 'a' from [12pt] and 'b' from [default].

With one exception: the 'x' and 'xx' sizes cannot be modified by the
current file:

    \setupbodyfont[12pt]
    \setupbodyfontenvironment [default] [x=2.0,xx=2.0]
    \starttext
      m{\tfx m}{\tfxx m}
    \stoptext

Furthermore there seems to be some extraneous output when the
bodyfontenvironment matches the current bodyfont size. For example,
the following outputs: "m12.0ptm12.0ptm"

    \setupbodyfontenvironment [12pt] [m=2.0,n=2.0,]
    \starttext
      m{\tfm m}{\tfn m}
    \stoptext

On Sat, Jan 19, 2019 at 3:59 AM Wolfgang Schuster
<wolfgang.schuster.lists@gmail.com> wrote:
> Why do you need this when you can just change the style of commands
> with use \tfx (e.g. \high or \low) to use the \tfm size?

With that out of the way, I don't know how to change commands which
use '\tfx' to use '\tfm' instead. Unless you mean this (though
technically they still use '\tfx', it just matches '\tfm'):

    \setupbodyfontenvironment [default] [m=0.8,n=0.6,x=0.8,xx=0.6]

Even if that did work, which it doesn't (see above), it would be
preferable to use the default bodyfont environment shipped by ConTeXt.
It probably exists for good reasons: matching the most common optical
font sizes, for aesthetics, and for consistency. I don't want the 'x'
and 'xx' sizes to vary between standard ConTeXt documents, and
documents which need to provide the 'n' and 'm' sizes.

It's also more work, as mentioned further up the thread. It may not be
strictly necessary to specify 'x' and 'xx' for each new size-specific
bodyfont environment, as they'll be inherited from [default]. But for
consistency each bodyfont size should have 'x' and 'xx' sizes matching
those from ConTeXt, and these vary with bodyfont size. That means
looking them up in 'font-pre.mkiv', a little math, and remembering to
do it every time you switch sizes. And that's ignoring the fact that
'\definebodyfont' can also override these sizes. I think using a macro
is simpler.
___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-01-19 17:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-16 20:56 Scaling down symbols and emojis User 19087
2019-01-16 21:24 ` Wolfgang Schuster
2019-01-16 23:29   ` User 19087
2019-01-17 12:39   ` User 19087
2019-01-17 13:30   ` User 19087
2019-01-18 11:47     ` Wolfgang Schuster
2019-01-18 21:44       ` User 19087
2019-01-19  8:42         ` User 19087
2019-01-19  8:59           ` Wolfgang Schuster
2019-01-19 17:50             ` User 19087

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).