Skip to content

Ligature support #601

Closed
Closed

Description

@lf-

It would be really nice to be able to use ligatures in fonts like Iosevka and Fira Code with mintty.

Currently, it seems that ligatures are not displayed.

Activity

  1. mintty commented on Oct 10, 2016

    @mintty
    Owner

    This may be beyond the Windows API currently used for text output (ExtTextOut), see #430 and #438 (comment).
    Please describe more precisely what you are missing and what you see (e.g. rendered "fl" desired to be ligature ?).

  2. lf- commented on Oct 10, 2016

    @lf-
    Author

    Fira Code has some crazy ligatures for programming while remaining a
    monospace font. -> is a ligature, so is ==.

    The issue is that the raw characters are displayed and not the ligatures.

  3. mintty commented on Oct 10, 2016

    @mintty
    Owner

    So you are not asking about any Unicode ligatures but rather font-specific ligatures.
    I am not aware which Windows API, if any, would be able to handle them implicitly.
    So it might be necessary to handle font information explicitly in mintty to achieve that.
    You are welcome to make a proposal how to implement that.

  4. mintty commented on Oct 11, 2016

    @mintty
    Owner

    This functionality may be available with the Uniscribe API.
    Handling the complexity of that API is however beyond my current ambition to enhance mintty.

  5. mintty commented on Oct 18, 2016

    @mintty
    Owner

    So here's your homework :):

    • Either find any application with source code that implements this, find how it detects which character pairs have ligatures (mapping them to font glyphs).
    • Or find out how the TrueType cmap tables can be retrieved using the Windows API and which table contains the ligature information.
  6. mintty commented on Oct 20, 2016

    @mintty
    Owner

    @be5invis: taking over this issue here...

    You cannot enable ligatures unless you switch from GDI to DirectWrite or FreeType.

    FreeType is an external library, and DirectWrite as well as Uniscribe are of deterring complexity. I've experimented with Uniscribe, though, and it does not seem to support ligatures (so I guess notepad uses DirectWrite...).

    But: The information must be available somewhere in the font file. And using a mapping table like
    ('-', '>', '⟶') mintty could output those glyphs by glyph index rather than character code, like it does for right-to-left text already.

  7. be5invis commented on Oct 20, 2016

    @be5invis

    @mintty Uniscribe does not support enabling arbitrary OpenType feature tag unless it is one of the “required” tags for typesetting complex scripts (like Devanagari).

  8. mintty commented on Oct 20, 2016

    @mintty
    Owner

    @be5invis Thanks for the confirmation.
    What about the ligature information; isn't it available as a "table" in TrueType? Any idea how to access it?

  9. be5invis commented on Oct 20, 2016

    @be5invis

    @mintty It’s a feature located in GSUB table, and it is corresponded to a list of lookups. For most programming fonts, the feature is tagged as calt.

  10. mintty commented on Oct 20, 2016

    @mintty
    Owner

    Hmm, using a ttfdump tool, Iosevka doesn't seem to have any calt entries, and Fira Code has only 16 of them, looking as mysterious as this:

    'calt'
    FeatureT07b6
                          ; FeatureRecord[17]
    ...
    Feature FeatureT07b6
    NULL
    3
    25
    26
    27
    

    Probably not worth the effort...

  11. be5invis commented on Oct 20, 2016

    @be5invis

    @mintty To avoid some compatibility issues under Linux, Iosevka Term turned off ligatures by default.
    A feature is (usually) an array of lookup indexes, indicates if this feature is enabled, which of the lookups should be set to active.

  12. mintty commented on Oct 20, 2016

    @mintty
    Owner

    "By default" means the information is not contained in the font?

    Whatever, I think I'll just close this issue unless someone enthusiastic about the feature will

    • demonstrate how it would be useful for at least a few fonts, and not for just 16 characters of one strange font (just look at the ugly 'm' of Fira Code!)
    • provide code how to retrieve a suitable mapping table from a TrueType font (starting with the GDI function GetFontData) because I'm not going to dig into the incredibly over-engineered insanity of the TrueType format myself (that person would gain a place on the mintty credits page, of course)
  13. 54 remaining items

  14. mintty commented on Dec 27, 2019

    @mintty
    Owner

    OK, your report was it doesn't work. As you see in your line (foo == true), it does work.
    Please check the discussion above for specific combinations that are not combined into a ligature.
    I might add a summary to the documentation.

  15. chiefjester commented on Dec 28, 2019

    @chiefjester

    oh okay @mintty sorry about that, so basically mintty has partial support of ligatures? Looking forward to the summary thanks again for the great work. 🙏🏻

  16. scfrazer commented on Feb 15, 2020

    @scfrazer

    I verified that "<-" is in fact handed over to Uniscribe for output in one bunch, even without that patch, actually.
    Maybe some parameters to the Uniscribe functions (wintext.c) would make a difference?

    Sorry for the slow response, life got in the way.

    I finally got it to work! I played around with the Uniscribe parameters as you suggested, and the extra ligatures I wanted appeared when I passed in some different flags for the SCRIPT_CONTROL parameter in ScriptStringAnalyse:

      SCRIPT_CONTROL sctrl;
      ZeroMemory(&sctrl, sizeof(SCRIPT_CONTROL));
      sctrl.fMergeNeutralItems = 1;
      HRESULT hr = ScriptStringAnalyse(hdc, psz, cch, 0, -1,
        // could | SSA_FIT and use `width` (from win_text) instead of MAXLONG
        // to justify to monospace cell widths;
        // SSA_LINK is needed for Hangul and default-size CJK
        SSA_GLYPHS | SSA_FALLBACK | SSA_LINK, MAXLONG,
        &sctrl, NULL, dxs, NULL, NULL, &ssa);
    

    Is this something you would want to incorporate, or should I maintain my own fork?

  17. BrianInglis commented on Feb 15, 2020

    @BrianInglis

    Add another bit setting to enable this in LigaturesSupport?

  18. mintty commented on Feb 16, 2020

    @mintty
    Owner

    Thanks for digging this out. No forks, please, I'll add that to the code. But it can only be an option, due to the ambiguity discussed before, see the marked case in the screenshot:
    grafik
    Any idea how to tackle this (and other?) cases?
    Should it be a distinct option or a bitmask variation as Brian suggested?

  19. reopened this on Feb 16, 2020
  20. scfrazer commented on Feb 16, 2020

    @scfrazer

    Thanks for adding it as an option, I didn't want to have to keep up with all your releases.

    Regarding the ambiguity, I imagine the common case of, say, '<=' is less-than-or-equal-to, not double-arrow-pointing-left. The only way I see around it is if you think it is worthwhile to write code to scan blocks, potentially break them up, and feed them to Uniscribe with different options. I suggest starting out with everything on or off, and see if many people ask for fine-grained control. FWIW, all the other programs I have tried go the less-than-or-equal-to glyph route.

    For the option, you could hedge your bet about people wanting more control and have another option that is a bitmask. One bit for 'all ligatures on', and in the future other bits could be 'double-arrow-pointing-left on'.

  21. mintty commented on Feb 16, 2020

    @mintty
    Owner

    I wouldn't know how to persuade Uniscribe to render <= as left-arrow.

    The current option is about interactive line rendering support (i.e. rendering while typing), which isn't yet perfect actually.
    The new option would be about the range of ligatures to enable, so a bit different - maybe it should be a separate option Ligatures then.

  22. mintty commented on Feb 25, 2020

    @mintty
    Owner

    Released 3.1.4.

  23. mintty commented on Feb 25, 2020

    @mintty
    Owner

    There is a bug with crash potential in the wslbridge gateway. Waiting for its fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions