Flipping alternates

Nick Shinn
Nick Shinn Posts: 2,208
edited October 2023 in Technique and Theory
I can’t figure out how to code this the way I’d like to.
Suggestions would be welcome!

The premise of the font is to alternate characters between roman and italic.
The basic code is very simple.
@default = roman glyphs
@alts = italic glyphs (e.g. A.alt etc.)
sub @default @alts' by @italics;
The result:

Inserting a space before the sentence produces another option for the user:

However, I’m not happy that the letters on either side of the space have the same inclination.
It occurs to me that alternating the slant across the word space would be better.
This I achieve by adding a line of code at the beginning, to put two characters between words:
sub space by space.half space.half;

But his means that when the user inserts a space at the beginning, it becomes two characters and will thus not produce the optional look, merely moving the image to the right. A period or any other single character would do the job:


I would rather that the user achieve this effect by inserting a space—but how?
Is there some method involving “ignore” or lookups?
Or some other method entirely?
Any ideas?

Comments

  • John Hudson
    John Hudson Posts: 3,191
    There are a few ways you could handle this as you describe, but I am questioning the notion of using insertion of a space to trigger the optional behaviour. Ideally, affecting the appearance of text should not involve changing the context of the text. Why not make the starts-on-italic option a stylistic set feature? In any case, you will need to sort out the first-glyph-in-run using a negative context, i.e. sub roman by italic if not preceded by any other glyph.

    So you want to continue with the concept of using a preceding space to trigger the optional behaviour, you can perhaps add contextual code to your two-half-space substitutions that disables it when not preceded by any other glyph? [Sorry, I can’t remember how to do this in AFDKO syntax.]

  • Nick Shinn
    Nick Shinn Posts: 2,208
    edited October 2023
    I’m putting this in the <rlig> feature, so “double spacing” won’t affect the underlying text.

    (<rlig> maintains the effect when substantially tracked, whereas the more normal <calt> and <liga> do not.)

    I’d rather not use a stylistic set for the optional appearance.
    I have tried negative context, but couldn’t get it to work—hence my post!
    I’m not tied to the double-spacing method, if there is a better way…

    I’ve used negative context for initial swash capitals, but here only want to enable the effect at the beginning of a sentence, not at the beginning of every word as well.
  • What about exclude space from @default?

    Or maybe:
    ignore sub space @default;

  • However, I’m not happy that the letters on either side of the space have the same inclination.

    have You try with extra rule for space first?
    @default = roman glyphs
    @alts = italic glyphs (e.g. A.alt etc.)
    @spaces = space (emspace hyphen etc.) 
    sub @default @spaces @alts' by @italics;
    sub @default @alts' by @italics;

  • If you want them to alternate, but with arbitrary ignored glyphs in the middle, then (and this is completely over-engineering it) give the glyphs that you want to ignore the "ligature" category in the GDEF table, and set the "IgnoreLigatures" lookup flag.
  • John Hudson
    John Hudson Posts: 3,191
    I’m putting this in the <rlig> feature, so “double spacing” won’t affect the underlying text.
    I was referring to insertion of space at the beginning of a run to affect the variant behaviour.

  • Nick Shinn
    Nick Shinn Posts: 2,208
    Thanks for the advice everybody! I will take another crack at it and report back in a while (but not immediately, I’m busy with many things at the moment). 
  • Nick Shinn
    Nick Shinn Posts: 2,208
    @Simon Cozens

    I don’t understand that, Simon, could you please put it into feature code? 
  • The feature code would be

    lookupflag IgnoreLigatures;
    sub @default @alts' by @italics;

    but to make it work you would need to set the GDEF categories. If you are using Glyphs, select all the glyphs you want to be ignored (space, punctuation, etc.), press command-option-I (or Edit menu > Info for selection), and click on the check boxes next to Category and Subcategory, filling in the information like this:




  • Grzegorz Luk (gluk)
    Grzegorz Luk (gluk) Posts: 161
    edited October 2023

    However, I’m not happy that the letters on either side of the space have the same inclination.

    have You try with extra rule for space first?
    I couldn't resist and I tried. Working (quick&dirty) demo HERE


  • Nick Shinn
    Nick Shinn Posts: 2,208
    Thanks again Grzegorz, Simon, John, Michael.

    I’ve actually opted for “none of the above”, and will make two separate fonts, one which starts with roman, the other with italic.
    The impetus was John’s comment about the insertion of a space at the beginning, which messes up layouts.

    I’ve never considered this two-font method in my previous, pseudo-random typefaces (Fontesque, Duffy, Neology), perhaps because they all have large-ish families and duplicating them would create menu clutter, and I’ve always used the “add space at beginning” method in cycling through the alternates in prototyping such designs.

    However, rather than burying the option in a Stylistic Set, having a separate “B” font up front in a layout app menu makes sense here. 
  • Grzegorz Luk (gluk)
    Grzegorz Luk (gluk) Posts: 161
    edited October 2023
    For fun and tests I made version with StylisticSet, however, if you insist on a solution with a space at the beginning you can achieve this simply by (avoiding space.half and using ignore):

    lookup caltflip {
      lookupflag 0;
        ignore sub [ A.alt B.alt C.alt ... a.alt b.alt c.alt ] [ space ] [A B C ... a b c ... ]' ;
        sub [space exclam quotedbl numbersign ... A B C ... a b c ... ] [A B C ... a b c ... ]'  by [A.alt B.alt C.alt ... a.alt b.alt c.alt ...];
    } caltflip;

    Unfortunately, version with ignore work properly on Firefox, Safari, Inkscape.. and not on Chrome.

    Working demo with both fonts HERE