Scaling characters without font switching in CLD
Dear gang, I. In Context, as is well known, scaling a character is not independent of switching the font: ======= \startTEXpage[offset=1em] \definefont[Times][times @ 14pt] \Times Test \tfx Test \setupinterlinespace \Times Test \switchtobodyfont[x]Test \Times Test \high{Test} \stopTEXpage ======= \tfx causes a switch to computer modern. Of course, with the right typescripts and \setupbodyfont, one can maintain stylistic consistency when switching fonts. But what if we want to scale independently of font switching? II. One approach might be to use symbols: \startTEXpage \definesymbol[Tee][\getglyph{times}{T}] \symbol[Tee]est \tfx \symbol[Tee]est \tfa \symbol[Tee]est \stopTEXpage In this example, \tfa does scale the symbol Tee. But \tfx does not scale the symbol! Why does \tfa (or higher such as \tfb etc.) work, but not \tfx (or lower)? III. The best approach would be to do it in CLD (Context Lua Code). That is mostly beyond my skill to write from scratch without a template, but there are some experiments in the system file font-imp-effects.lua. There we will find, e.g., local specification = { name = "extend", description = "scale glyphs horizontally", initializers = { base = initializeextend, node = initializeextend, } } local specification = { name = "squeeze", description = "scale glyphs vertically", initializers = { base = initializesqueeze, node = initializesqueeze, } } This seems hopeful: \definecolor [transparentgreen] [g=1,t=.7,a=1] \definecolor [transparentred] [r=1,t=.7,a=1] \definecolor [transparentyellow] [y=1,t=.7,a=1] \startTEXpage[offset=1em] \definefontfeature[scale][default][extend=yes,squeeze=yes] \hbox{\rlap{\definedfont[times @ 14pt]\transparentgreen Test}% \definedfont[times*scale @ 14pt]\transparentred Test} \stopTEXpage But there is no scaling of the character, extend=yes shifts the glyphs to the left, and squeeze=yes appears to do nothing at all. Here is a file collecting these experiments: https://www.dropbox.com/scl/fi/dggj3ypgjjeia1bo4eelb/test-scaling.tex?rlkey=hcky6ol594mw8u0j2j1z22heh&dl=0 https://www.dropbox.com/scl/fi/o2u1tsq515ycyoeup43qg/test-scaling.pdf?rlkey=h7gof1vyq3r0bh72qynh71apc&dl=0 IV. Objective: I need to be able to define a couple of characters in CLD -- glottal stops --, and add commands to scale and/or rotate a character without triggering a font switch. Again, writing this from scratch is beyond my current skill set - although I've recently started to study CLD. Something like this -- some of the semantics is almost certainly wrong and/or clumsy -) ============== -- ʿ ringhalfleft local function ringhalfleft (characters,target,base,accent) -- if not characters[target] then local data1 = characters[base] local data2 = characters[accent] if data1 and data2 then characters[target] = { -- "ʿ" height = data1.height, depth = (data1.depth or 0) + 0.5*(data2.height or 0), width = data1.width, unicode = target, commands = { { "slot", 0, 0 }, { "left", -0.5*(data2.width or 0) + 0.5*(data2.width or 0)}, -- { "down", 0.2*(data2.height or 0) + (data2.height or 0) }, { "up", 0.0*(data2.height or 0) + (data2.height or 0) }, { "slot", 0, 0x063, }, { "squeeze", 0.75*(data2.height or 0) }, { "extend", 0.75*(data2.width or 0) }, }, } end -- end end -- ʾ ringhalfright local function ringhalfright (characters,target,base,accent) -- if not characters[target] then local data1 = characters[base] local data2 = characters[accent] if data1 and data2 then characters[target] = { -- "ʾ" height = data1.height, depth = (data1.depth or 0) + 0.5*(data2.height or 0), width = data1.width, unicode = target, commands = { { "slot", 0, 0 }, { "left", -0.35*(data2.width or 0) + 0.5*(data2.width or 0)}, { "down", 0.0*(data2.height or 0) + (data2.height or 0) }, -- { "up", 0.0*(data2.height or 0) + (data2.height or 0) }, { "slot", 0, 0x063, }, { "squeeze", 0.75*(data2.height or 0) }, { "extend", 0.75*(data2.width or 0) }, }, } end -- end end local function initialize(tfmdata,value) if value then -- Hdotbelow(tfmdata.characters,0x02BF,0x063,0) -- ringhalfleft (tfmdata.characters,0x02BF,0x063,0x063) ringhalfright(tfmdata.characters,0x02BE,0x063,0x063) -- (i.e., tfmdata.characters,target,base,accent) -- hdotbelow(tfmdata.characters,0x1E25,0x068,0x2D9) end end local function scale (ringhalfleft,ringhalfright) for v in next, ringhalfleft do v.height = 0.75 * (v.height or 0) v.width = 0.75 * (v.width or 0) v.depth = 0.75 * (v.depth or 0) end for v in next, ringhalfright do v.height = 0.75 * (v.height or 0) v.width = 0.75 * (v.width or 0) v.depth = 0.75 * (v.depth or 0) end end local specification = { name = "glottalstops", description = "glottalstops", manipulators = { base = initialize, node = initialize, } } ============== Rotation for one of the characters is also needed. Here is an experimental test file: https://www.dropbox.com/scl/fi/wi81e23wg17k8jasqpeon/transliteration-glottal-lua.tex?rlkey=gfwgjduhta1iemouwvjp1n6v3&dl=0 https://www.dropbox.com/scl/fi/rca5v6uusyj6mogyklfpd/transliteration-glottal-lua.pdf?rlkey=ou1lbfdkwec4tpbgkkk3kh9b9&dl=0 Thank you in advance for your guidance. Best wishes Idris -- Professor Idris Samawi Hamid Department of Philosophy Colorado State University Fort Collins, CO 80523
On 8/12/2023 4:03 PM, Hamid,Idris wrote:
\tfx causes a switch to computer modern.
Indeed. Something I need to discuss with Wolfgang as double checking is needed before I patch.
But what if we want to scale independently of font switching? There is no need to go lua here (esp when you have not done vf magick before and i'm not going to debug code that i have little clue what it's about to do).
- we cheat here and yuse glyph scaled (I have to provide a relative to current x/y scaling, don't use \glyphscale as that one is used by context itself - we use the style variant so that it adapts - you have to replace "Serif" with "YourFont" and map that one onto a file (YourFont YourFontBold etc) - more about these box manipulations in the low level manual \startsetups glyph:iTee \dontleavehmode\hpack\bgroup \setbox\scratchbox \ruledhbox \bgroup \glyphxscale 400 \glyphyscale 400 \getglyphstyled{Serif}{T}% choose a font here \egroup \scratchheight 2.75\ht\scratchbox \boxyoffset \scratchbox\scratchheight \boxorientation\scratchbox\plustwo \ht \scratchbox\scratchheight \box\scratchbox \egroup \stopsetups \definesymbol [iTee] [\directsetup{glyph:iTee}] \startTEXpage [offset=1ts,width=2cm] \ruledhbox {\tfx T \symbol{iTee}} \par \ruledhbox {T \symbol{iTee}} \par \ruledhbox {\tfa T \symbol{iTee}} \par \ruledhbox {\bfd T \symbol{iTee}} \stopTEXpage Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
On Aug 12, 2023, 9:35 AM -0600, Hans Hagen
On 8/12/2023 8:05 PM, Hamid,Idris wrote:
On Aug 12, 2023, 9:35 AM -0600, Hans Hagen
, wrote: ** Caution: EXTERNAL Sender ** On 8/12/2023 4:03 PM, Hamid,Idris wrote:
\tfx causes a switch to computer modern.
Indeed. Something I need to discuss with Wolfgang as double checking is needed before I patch.
Ah.. ok. impossible to reply as impossible to see what is your and mine text here
Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
On Aug 12, 2023, 2:11 PM -0600, Hans Hagen via ntg-context
impossible to reply as impossible to see what is your and mine text here
Hm.. This new/modern email client (forced to update by the university) supports inline replies, and I can see the levels, but the distinctions between levels of reply appears to get lost when filtered by the ntg-context list (looking at the archives). So here it is again, with levels of reply made explicit:
On Aug 12, 2023, 9:35 AM -0600, Hans Hagen
\tfx causes a switch to computer modern.
Indeed. Something I need to discuss with Wolfgang as double checking is needed before I patch.
Ah.. ok.
But what if we want to scale independently of font switching?
There is no need to go lua here (esp when you have not done vf magick before and i'm not going to debug code that i have little clue what it's about to do).
Many thanks. Part of the context is that I have some updatable mission-critical documents that depended on \defineactivecharacter, which is apparently deprecated in LMTX. See earlier thread with that subject line. [BTW: Just this morning someone from the Persian Gulf asked for an updated version of a document whose compilation depended on \defineactivecharacter, so I need to get this working in the new regime -)] Now the templates that you provided - many, many thanks! - have what is needed to care of everything except for two characters: 02BE and 02BF. For one of those two remaining characters we also need scaling, for the other we also need scaling + rotation. It is not clear to me whether the scaling/rotation commands should fall under the character function, e.g., ======= -- ʿ ringhalfleft local function ringhalfleft (characters,target,base,accent) ======= the initialize function ======= local function initialize(tfmdata,value) ======= or whether we just make a new function altogether ======= local function scale (ringhalfleft) -- shooting in the dark here ======= So the reason I said CLD is best is because we already defined all of the needed characters that way -- using your template -- except for these two, for which we need to add scaling and or rotation.
The attached (linked in the previous email but attached here) gives us rotation but no scaling. - we cheat here and yuse glyph scaled (I have to provide a relative to current x/y scaling, don't use \glyphscale as that one is used by context itself - we use the style variant so that it adapts - you have to replace "Serif" with "YourFont" and map that one onto a file (YourFont YourFontBold etc) - more about these box manipulations in the low level manual
Ok. Just discovered the 11 low-level manuals yesterday, not sure which one to focus on in this case -)
\startsetups glyph:iTee \dontleavehmode\hpack\bgroup \setbox\scratchbox \ruledhbox \bgroup \glyphxscale 400 \glyphyscale 400 \getglyphstyled{Serif}{T}> choose a font here \egroup \scratchheight 2.75\ht\scratchbox \boxyoffset \scratchbox\scratchheight \boxorientation\scratchbox\plustwo \ht \scratchbox\scratchheight \box\scratchbox \egroup \stopsetups
\definesymbol [iTee] [\directsetup{glyph:iTee}]
\startTEXpage [offset=1ts,width=2cm] \ruledhbox {\tfx T \symbol{iTee}} \par \ruledhbox {T \symbol{iTee}} \par \ruledhbox {\tfa T \symbol{iTee}} \par \ruledhbox {\bfd T \symbol{iTee}} \stopTEXpage
Great, will study this. The challenge (for me) will be integrating this approach into the lua definitions of the two needed characters. With \defineactivecharacter deprecated, there seems to be no way other than CLD to make and register the needed macro for \definefontfeature -- and we want to move forward with the new regime and not look back. With many thanks and much gratitude, Hans. Best wishes Idris -- Professor Idris Samawi Hamid Department of Philosophy Colorado State University Fort Collins, CO 80523
On 8/12/2023 11:33 PM, Hamid,Idris wrote:
On Aug 12, 2023, 2:11 PM -0600, Hans Hagen via ntg-context
, wrote: impossible to reply as impossible to see what is your and mine text here
Hm.. This new/modern email client (forced to update by the university) supports inline replies, and I can see the levels, but the distinctions between levels of reply appears to get lost when filtered by the ntg-context list (looking at the archives). So here it is again, with levels of reply made explicit:
On Aug 12, 2023, 9:35 AM -0600, Hans Hagen
, wrote: ** Caution: EXTERNAL Sender ** On 8/12/2023 4:03 PM, Hamid,Idris wrote:
\tfx causes a switch to computer modern.
Indeed. Something I need to discuss with Wolfgang as double checking is needed before I patch.
Ah.. ok.
But what if we want to scale independently of font switching?
There is no need to go lua here (esp when you have not done vf magick before and i'm not going to debug code that i have little clue what it's about to do).
Many thanks. Part of the context is that I have some updatable mission-critical documents that depended on \defineactivecharacter, which is apparently deprecated in LMTX. See earlier thread with that subject line.
i adapted some recently but anyway active chars are a bad idea
[BTW: Just this morning someone from the Persian Gulf asked for an updated version of a document whose compilation depended on \defineactivecharacter, so I need to get this working in the new regime -)]
Now the templates that you provided - many, many thanks! - have what is needed to care of everything except for two characters: 02BE and 02BF.
you'll figure it out, right?
For one of those two remaining characters we also need scaling, for the other we also need scaling + rotation. It is not clear to me whether the scaling/rotation commands should fall under the character function, e.g.,
the demo shows both: x/.y scaling and 90/180/270 rotation
======= -- ʿ ringhalfleft local function ringhalfleft (characters,target,base,accent) =======
the initialize function
======= local function initialize(tfmdata,value) =======
or whether we just make a new function altogether
======= local function scale (ringhalfleft) -- shooting in the dark here =======
So the reason I said CLD is best is because we already defined all of the needed characters that way -- using your template -- except for these two, for which we need to add scaling and or rotation.
The attached (linked in the previous email but attached here) gives us rotation but no scaling. - we cheat here and yuse glyph scaled (I have to provide a relative to current x/y scaling, don't use \glyphscale as that one is used by context itself - we use the style variant so that it adapts - you have to replace "Serif" with "YourFont" and map that one onto a file (YourFont YourFontBold etc) - more about these box manipulations in the low level manual
Ok. Just discovered the 11 low-level manuals yesterday, not sure which one to focus on in this case -)
\startsetups glyph:iTee \dontleavehmode\hpack\bgroup \setbox\scratchbox \ruledhbox \bgroup \glyphxscale 400 \glyphyscale 400 \getglyphstyled{Serif}{T}> choose a font here \egroup \scratchheight 2.75\ht\scratchbox \boxyoffset \scratchbox\scratchheight \boxorientation\scratchbox\plustwo \ht \scratchbox\scratchheight \box\scratchbox \egroup \stopsetups
\definesymbol [iTee] [\directsetup{glyph:iTee}]
\startTEXpage [offset=1ts,width=2cm] \ruledhbox {\tfx T \symbol{iTee}} \par \ruledhbox {T \symbol{iTee}} \par \ruledhbox {\tfa T \symbol{iTee}} \par \ruledhbox {\bfd T \symbol{iTee}} \stopTEXpage
Great, will study this. The challenge (for me) will be integrating this approach into the lua definitions of the two needed characters. With \defineactivecharacter deprecated, there seems to be no way other than CLD to make and register the needed macro for \definefontfeature -- and we want to move forward with the new regime and not look back.
well, you wented symbols so ... why lua then (btw, no need for squeezine as there are virtual commands for scaling; not for rotating; an alternative is to define some chars in metapost (see meta-imp-gamesymbols) which gives you plenty freedom
With many thanks and much gratitude, Hans.
Best wishes Idris -- Professor Idris Samawi Hamid Department of Philosophy Colorado State University Fort Collins, CO 80523
___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___________________________________________________________________________________
-- ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
On Aug 12, 2023, 3:49 PM -0600, Hans Hagen
you'll figure it out, right?
I hope so and I'm working on it -- with your help -)
the demo shows both: x/.y scaling and 90/180/270 rotation
Yes, here is what I have so far: ============== % % Hans' original template % \startsetups glyph:iTee % \dontleavehmode\hpack\bgroup % \setbox\scratchbox \ruledhbox \bgroup % \glyphxscale 400 % \glyphyscale 400 % \getglyphstyled{Serif}{T}% choose a font here % \egroup % \scratchheight 2.75\ht\scratchbox % \boxyoffset \scratchbox\scratchheight % \boxorientation\scratchbox\plustwo % \ht \scratchbox\scratchheight % \box\scratchbox % \egroup % \stopsetups % \definesymbol % [iTee] % [\directsetup{glyph:iTee}] % \startTEXpage [offset=1ts,width=2cm] % \ruledhbox {\tfx T \symbol{iTee}} \par % \ruledhbox {T \symbol{iTee}} \par % \ruledhbox {\tfa T \symbol{iTee}} \par % \ruledhbox {\bfd T \symbol{iTee}} % \stopTEXpage \definefontsynonym[MinionRegular][MinionPro-Regular.otf*default] \startsetups glyph:glottalhamzah \dontleavehmode\hpack\bgroup \setbox\scratchbox \ruledhbox \bgroup \glyphxscale 500 \glyphyscale 500 \getglyphstyled{MinionRegular}{c}% choose a font here \egroup \scratchheight 2.03\ht\scratchbox \boxyoffset \scratchbox\scratchheight \boxorientation\scratchbox\plustwo \ht \scratchbox\scratchheight \box\scratchbox \egroup \stopsetups \startsetups glyph:glottalayn \dontleavehmode\hpack\bgroup \setbox\scratchbox \ruledhbox \bgroup \glyphxscale 500 \glyphyscale 500 \getglyphstyled{MinionRegular}{c}% choose a font here \egroup \scratchheight 1.00\ht\scratchbox \boxyoffset \scratchbox\scratchheight % \boxorientation\scratchbox\plustwo \ht \scratchbox\scratchheight \box\scratchbox \egroup \stopsetups \definesymbol [glottalhamzah] [\directsetup{glyph:glottalhamzah}] \definesymbol [glottalayn] [\directsetup{glyph:glottalayn}] \definecolor [transparentgreen] [g=1,t=.7,a=1] \definecolor [transparentred] [r=1,t=.7,a=1] \definecolor [transparentyellow] [y=1,t=.7,a=1] \startTEXpage [offset=1ts,width=2cm] \ruledhbox {\tfx c\symbol{glottalhamzah}c} \par \ruledhbox {c\symbol{glottalhamzah}c} \par \ruledhbox {\tfa c\symbol{glottalhamzah}c} \par \ruledhbox {\bfd c\symbol{glottalhamzah}c} \par \ruledhbox {\tfx c\symbol{glottalayn}c} \par \ruledhbox {c\symbol{glottalayn}c} \par \ruledhbox {\tfa c\symbol{glottalayn}c} \par \ruledhbox {\bfd c\symbol{glottalayn}c} \par \hbox{\rlap{\ruledhbox {\transparentgreen\tfx c\symbol{glottalhamzah}c}}% \hskip-.09em \ruledhbox {\transparentred c\symbol{glottalhamzah}c}} \hbox{\rlap{\ruledhbox {\transparentgreen\tfx c\symbol{glottalayn}c}}% \ruledhbox {\transparentred c\symbol{glottalayn}c}} \stopTEXpage ============== Note the \rlap's (see attached pdf): we see that \tfx doesn't scale the \symbol, although \tfa and higher do work. I guess fixing \tfx-symbol interaction will be part of your conversation with Wolfgang -)
well, you wented symbols so
Ultimately I just want to be able to type the Unicode symbols for 02BE and 02BF -- ʾ and ʿ -- and get proper results. The overwhelming majority of hq fonts don't have them, and the few that do do them poorly, etc. (So there is no substitute for full control of these transliteration characters.) So even if we use symbols, would like to feed these setups to the CLD template you provided some days ago and feed the final result to \definefontfeature. ======= Best wishes Idris -- Professor Idris Samawi Hamid Department of Philosophy Colorado State University Fort Collins, CO 80523
More precise \rlaps for the previous MWE:
\hbox{\rlap{\ruledhbox {\transparentgreen\tfx c\symbol{glottalhamzah}c}}%
\hskip-.075em \ruledhbox {\transparentred c\symbol{glottalhamzah}c}}
\hbox{\rlap{\ruledhbox {\transparentgreen\tfx c\symbol{glottalayn}c}}%
\hskip-.075em \ruledhbox {\transparentred c\symbol{glottalayn}c}}
--
Professor Idris Samawi Hamid
Department of Philosophy
Colorado State University
Fort Collins, CO 80523
On Aug 12, 2023, 4:11 PM -0600, Idris Samawi Hamid ادريس سماوي حامد
On Aug 12, 2023, 4:20 PM -0600, Hans Hagen
btw, no need for squeezine as there are virtual commands for scaling; not for rotating
From your original CLD template: local function topthing(characters,target,base,accent) -- if not characters[target] then local data1 = characters[base] local data2 = characters[accent] if data1 and data2 then characters[target] = { -- "Ḥ" height = (data1.height or 0) + 0.5*(data2.height or 0), depth = data1.depth, width = data1.width, unicode = target, commands = { { "slot", 0, 0x048 }, { "left", 0.5*(data2.width or 0) + 0.5*(data1.width or 0) }, { "up", 0.5*(data2.height or 0) }, { "slot", 0, 0x2D9, }, }, } end -- end end What are the virtual commands for scaling? Can they be added under "commands =" in the above? Or will that have to go under another local function? Of course, we may still have to insert the \symbol's for rotation, so perhaps better to stick with \symbol's for scaling as well (you know best). Now that the \symbol's for the glottals have been defined with your second template, I need to figure out where/how to plug them into the CLD based on your first template. Best wishes Idris -- Professor Idris Samawi Hamid Department of Philosophy Colorado State University Fort Collins, CO 80523
On 8/13/2023 12:56 AM, Hamid,Idris wrote:
On Aug 12, 2023, 4:20 PM -0600, Hans Hagen
, wrote: btw, no need for squeezine as there are virtual commands for scaling; not for rotating
From your original CLD template:
local function topthing(characters,target,base,accent) -- if not characters[target] then local data1 = characters[base] local data2 = characters[accent] if data1 and data2 then characters[target] = { -- "Ḥ" height = (data1.height or 0) + 0.5*(data2.height or 0), depth = data1.depth, width = data1.width, unicode = target, commands = { { "slot", 0, 0x048 }, { "left", 0.5*(data2.width or 0) + 0.5*(data1.width or 0) }, { "up", 0.5*(data2.height or 0) }, { "slot", 0, 0x2D9, }, }, } end -- end end a little lesson in efficiency attached
Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
participants (3)
-
Hamid,Idris
-
Hans Hagen
-
Hans Hagen