Search Unity

Using fonts with alternate characters

Discussion in 'UGUI & TextMesh Pro' started by adslitw, Jun 30, 2022.

  1. adslitw

    adslitw

    Joined:
    Aug 23, 2012
    Posts:
    275
    Is it possible to use alternate characters when creating text with TMP (e.g. a typeface might have 3 different versions of the letter 'S', and a random one is chosen each time)?
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Sort of ...

    Support for the OpenType Layout feature called Alternate is not currently available. However, provided you know the index of those alternate glyphs in the font file, you could access these by manually creating ligatures using version 3.2.0-pre.3 of the TMP package for Unity 2020.3 or newer or version 2.2.0-preview.3 for Unity 2019.4.

    For example, I am using the font called Alegreya-Black which does contain some alternate forms of glyphs. In this font, there is an alternate for the letter "C" which is the glyph with index #249 as seen below.

    upload_2022-6-30_22-37-50.png

    Although we can add glyphs by index in this current release, we can indirectly do so by creating a Ligature that references the glyph index as seen below.

    upload_2022-6-30_22-39-44.png

    Once the glyph has been added to the glyph table, I created a new character using a Unicode in the Private Area Range which is E000 to F8FF and pointed it to the desired glyph index as seen below.

    upload_2022-6-30_22-43-55.png

    I then deleted the Ligature because I didn't want to always replace "C" by this new alternate.

    To access these alternates, I could repeat this process assigning each alternate to some custom private area Unicode.

    Alternatively, I could setup some Ligatures where the input would be something like "C" + "_" + "0" = Ligature as seen below.

    upload_2022-6-30_22-53-4.png

    Note that when using Ligatures, the sorting order matters where as soon as we have a match the ligature is applied. This means that if "ff" is before "ffi" the "ff" will always be substituted and you won't ever get the "ffi". As such, the 3 component ligature "ffi" needs to be first then followed by "ff".

    Proper support for stylistic alternate is in the works but this should enable you to still access them for the time being.
     
    Daan-Gijzen likes this.
  3. adslitw

    adslitw

    Joined:
    Aug 23, 2012
    Posts:
    275
    OK that's great @Stephan_B - thanks for the detailed reply, much appreciated.
     
    Stephan_B likes this.
  4. Daan-Gijzen

    Daan-Gijzen

    Joined:
    Apr 6, 2017
    Posts:
    4
    Is this only possible in the old pre-releases? Cause I can't seem to find the "Ligature table" option on the TMPro-font settings. As you can see in the image below.

    I did find that I can mark my ligatures as ligature in the "Glyph Table" tho.
    upload_2023-3-24_16-53-21.png

    I also can't seem to be able to find the pre-release versions in the package manager (pre-release packages is on in the settings). The only thing that shows is version 3.0.6.
    And I was wondering where I should be able to find the version your talking about in your original explanation.

    Or if I do something dumb and need to look somewhere else entirely.

    If you need any more information from me please let me know!
     

    Attached Files: