Skip to content

Feature: Explicit option for rendering emojis as Wide #1065

Closed

Description

@pagerc

Issue:

Neutral EastAsianWidth characters are always rendered as narrow

Desired Resolution:

CharWidth=neutral-wide to force rendering of Neutral EastAsianWidth characters as Wide

Terminal:

WSLTTY 3.4.3

WSLTTY config:

# Locale and Charset are unset in config while font is forced to Windows Segoe UI which should be fallback for unicode glyph rendering from other fonts
#Locale= 
#Charset= 
Font=Segoe UI

Bash ENV:

CHARSET=UTF-8
LANG=C.UTF-8
LC_COLLATE=C
LC_CTYPE=en_US.UTF-8

Alpine linux /etc/profile.d/locale.sh:

export CHARSET=UTF-8
export LANG=C.UTF-8
export LC_COLLATE=C

Background:

I've been struggling with unicode glyph rendering for a couple years with wsltty and assumed it was an improper understanding of the charwidth property or incompatible font selection. However, I've come to the conclusion my expectation is that Neutral EastAsianWidth characters are being forced to narrow rendering per http://unicode.org/reports/tr11/ recommendation and codepoint annotation (https://www.unicode.org/Public/UCD/latest/ucd/EastAsianWidth.txt). Issue #938 discusses tr11 but neglects the section which suggests that terminals should provide additional resolution for the ambiguity surrounding glyph width rendering.

My specific use-case is to use unicode for diagnostic style information and also for wttr.in weather icons. The Warning and Informational glyphs render narrow in wsltty when I want to force them to render wide to match the surrounding glyphs that are annotated as Wide in EastAsianWidth. Weather related glyphs from U+1F321 through U+1F32C render narrow based on the same adherence to Neutral EastAsianWidth rendering as narrow.

cat unicode.raw

⛔ - Critical - critical conditions
❌ - Error- error condtions
⚠ - Warning - warning conditions
📌 - Notice - normal, but significant, condition
ℹ - Informational - informational message
🚫 - Debug - debug-level message

### Characters by Unicode Block
**Dingbats**
- [ ] U+2728 ✨ Sparkles
- [ ] U+2744 ❄ Snowflake

**Miscellaneous Symbols**
- [X] U+2600 ☀ Black Sun with Rays
- [X] U+2601 ☁ Cloud
- [ ] U+26C5 ⛅ Sun Behind Cloud
- [ ] U+26C6 ⛆ Rain
- [ ] U+26C8 ⛈ Thunder Cloud and Rain

**Miscellaneous Symbols and Pictographs**
- [ ] U+1F300 🌀 Cyclone
- [ ] U+1F30C 🌌 Milky Way
- [ ] U+1F30D 🌍 Earth Globe Europe-Africa
- [ ] U+1F30E 🌎 Earth Globe Americas
- [ ] U+1F30F 🌏 Earth Globe Asia-Australia
- [ ] U+1F310 🌐 Globe with Meridians
- [ ] U+1F311 🌑 New Moon Symbol
- [ ] U+1F312 🌒 Waxing Crescent Moon Symbol
- [ ] U+1F313 🌓 First Quarter Moon Symbol
- [ ] U+1F314 🌔 Waxing Gibbous Moon Symbol
- [ ] U+1F315 🌕 Full Moon Symbol
- [ ] U+1F316 🌖 Waning Gibbous Moon Symbol
- [ ] U+1F317 🌗 Last Quarter Moon Symbol
- [ ] U+1F318 🌘 Waning Crescent Moon Symbol
- [ ] U+1F321 🌡 Themometer
- [ ] U+1F322 🌢 Black Droplet
- [ ] U+1F323 🌣 White Sun
- [ ] U+1F324 🌤 White Sun with Small Cloud
- [ ] U+1F325 🌥 White Sun Behind Cloud
- [ ] U+1F326 🌦 White Sun Behind Cloud with Rain

image

Activity

  1. mintty commented on Dec 2, 2020

    @mintty
    Owner

    Your illustrated use cases do not relate to East Asian characters, so maybe you'd like an option that makes all characters the same width. There is Charwidth=single, however it's single-width and rendering of CJK characters in this mode is not very desirable. I was considering a variation Charwidth=double that would render all characters as double-width, however including plain text.

    If you'd rather want to target particularly emojis, this has been discussed elsewhere and the problem is missing referable criteria by which to decide characters to be wide that are narrow by Unicode.
    Context-dependent width is something that terminals should never do.
    You can specify single characters to be double-width explicitly, however, since mintty 3.1.5, with control sequence PEC (CSI 1 SP Z emoji CSI SP Z ).

  2. pagerc commented on Dec 2, 2020

    @pagerc
    Author

    I'm definitely not after an option to force all characters to a specific width. I just want EastAsianWidth Neutral characters to render as wide instead of narrow. I'm not convinced this isn't related to the tr11 unicode report discussing EastAsianWidth annotations.

    My output clearly shows that some unicode characters render single cell width and others double cell width. The only document I can locate for defining what characters render double width and others single width is in relation to the content of https://www.unicode.org/Public/UCD/latest/ucd/EastAsianWidth.txt:

    Specifically if this is not related to EastAsianWidth, can you kindly explain why this subset from Miscellaneous Symbols and Pictographs (not emoticons/emojis) 1F300-1F320 render as wide-width and 1F321-1F32C render as narrow-width?
    printf '\U1F311#\n0123456789\n\U1F321#\n'

    While it's neat that the control sequences exist for a case by case basis of forcing single character output rendering as narrow/wide, it's not really feasible to run all text going to the tty through a control sequence manipulator just to adjust the rendering for character ranges from single-width to double-width. To better explain, while I use wttr.in for weather, I don't control it's output and there are other applications that emit non-emoji unicode that suffer from the narrow/wide issue and as such for proper rendering of Neutral EastAsianWidth characters I'd have to put a buffer between all programs and the tty which seems excessive.

    From EastAsianWidth, its clear that the unicode glyphs that I want to render wide are annotated as Neutral:
    2139;N # Ll INFORMATION SOURCE
    ...
    26A0;N # So WARNING SIGN
    26A1;W # So HIGH VOLTAGE SIGN
    ...
    26D4;W # So NO ENTRY
    ...
    274C;W # So CROSS MARK
    ...
    1F300..1F320;W # So [33] CYCLONE..SHOOTING STAR
    1F321..1F32C;N # So [12] THERMOMETER..WIND BLOWING FACE
    1F32D..1F335;W # So [9] HOT DOG..CACTUS
    ...
    1F680..1F6C5;W # So [70] ROCKET..LEFT LUGGAGE

  3. mintty commented on Dec 2, 2020

    @mintty
    Owner

    Let's stop talking about East Asian here as none of the examples you want widened are East Asian.
    Changing issue title.

    kindly explain why this subset from Miscellaneous Symbols and Pictographs (not emoticons/emojis) 1F300-1F320 render as wide-width and 1F321-1F32C render as narrow-width

    You've answered this question yourself by quoting from the file above and even marking the entries bold. Note that despite the filename EastAsianWidth, the file lists all Unicode characters.

  4. changed the title [-]Feature: Explicit option for rendering Neutral EastAsianWidth as Narrow or Wide[/-] [+]Feature: Explicit option for rendering emojis as Wide[/+] on Dec 2, 2020
  5. pagerc commented on Dec 2, 2020

    @pagerc
    Author

    I want to highlight these are not emoji/emoticons, they are Miscellaneous Symbols and Miscellaneous Symbols and Pictographs which predate emoji/emoticons and from my reading of the tr11 report it's an acceptable option for Neutral characters to be treated as Ambiguous by implementation election and therefore behave the same as ambiguous rendering.

    Excerpt from tr11 the relevant portion on modern rendering under section 4.2:

    4.2 Ambiguous Characters
    ...
    Modern Rendering Practice. Modern practice is evolving toward rendering ever more of the ambiguous characters with proportionally spaced, narrow forms that rotate with the direction of writing, making a distinction within the legacy character set. In other words, context information beyond the choice of font or source character set is employed to resolve the width of the character. This annex does not attempt to track such changes in practice; therefore, the set of characters with mappings to legacy character sets that have been assigned ambiguous width constitute a superset of the set of such characters that may be rendered as wide characters in a given context. In particular, an application might find it useful to treat characters from alphabetic scripts as narrow by default. Conversely, many of the symbols in the Unicode Standard have no mappings to legacy character sets, yet they may be rendered as “wide” characters if they appear in an East Asian context. An implementation might therefore elect to treat them as ambiguous even though they are classified as neutral here.

  6. mintty commented on Dec 2, 2020

    @mintty
    Owner

    See also #880, particularly #880 (comment), and #553. Liberal "modern rendering" practice isn't appropriate for a cell-based terminal. Main criteria for width considerations must be that any application shall be able to make reliable assumptions about the effective width of character output. By general paradigm, this is mediated by the locale mechanism.
    Exceptions are possible and in fact mintty offers a few of them (see manual), but for any such request you'd need to provide solid and reliable criteria by which any given character should deviate from its standard width. Not something fuzzy as "Asian", "emojis" or "miscellaneous".

  7. pagerc commented on Dec 2, 2020

    @pagerc
    Author

    An implementation might therefore elect to treat them as ambiguous even though they are classified as neutral here

    I have to disagree with this author:
    https://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c

    An implementation that allows the wholesale categorization of neutral characters to be equivalent to ambiguous width characters is suggested as a solution in the technical report.

    Therefore, I entirely see it as possible to add an option neutral=ambig so that the charwidth=ambig-wide would control the entire class of Neutral width characters to render as wide.

    The downside obviously is that you'll need a wcwidth implementation that follow the technical report which indicates rendering neutral as ambiguous is permitted by an implementation.

    To create the struct definition for static const struct interval neutral[] = { something like this should get it started:
    curl -kL https://www.unicode.org/Public/UCD/latest/ucd/EastAsianWidth.txt | grep ';N ' | sed -e 's:;.*::'

    *edited to include code correction on grep

  8. mintty commented on Dec 2, 2020

    @mintty
    Owner

    That should be grep ';N ' with space, to exclude ';Na'.
    It would include almost all letters, except plain ASCII, just to note. I doubt that is desirable.

  9. pagerc commented on Dec 3, 2020

    @pagerc
    Author

    The characters I'm most interested in are definitely all Symbols/emoji related, and you've characterized that as a "fuzzy" set.
    Which of these is the best path forward?

    • mintty neutral=ambig config option for forcing all neutral characters to wide

    • mintty wide symbol extension ^[]77119;3^G Render symbol unicode ranges or literally described as symbol in name as wide

    • Push for LANG=en_US@neutralambig or LANG=en_US@widesymbol as new modifier

    • Push unicode consortium to correct the published widths with a new categorization of "symbol" to identify a new class of unicode characters that should be considered wide, e.g. Symbols, Pictographs, and emoji

    • Wrap all apps with an output formatter that induces ^[[1 Z for unicode symbols/emoji that are currently classified as Neutral

  10. mintty commented on Dec 3, 2020

    @mintty
    Owner

    OSC 77119 is something I can imagine to offer, but still, to which ranges?
    Among Miscellaneous Symbols, e.g., there are some that should perhaps not be wide, like U+2640, U+2680. Should Miscellaneous Symbols and Arrows (U+2B00-U+2BFF) be affected? Etc.
    I could also imagine to provide an option to specify wide character ranges explicitly.

  11. pagerc commented on Dec 3, 2020

    @pagerc
    Author

    Going off on a tangent, I found that Windows Notepad appears to use dotnet System.Drawing.Graphics.MeasureString and I'm curious if that graphical measurement of font rendering may be preferred to wcwidth/wcswidth for character width calculations. If so, figuring out how cairo/pango implement MeasureString routines may be a means to get a superior implementation than wcwidth/wcswidth for width calculations.

    I've tracked the mono implementation to back to cairo/pango when mono System.Drawing.gdipFunctions imports GdiPlus dll like this:

    		private unsafe SizeF GdipMeasureString (IntPtr graphics, string text, Font font, ref RectangleF layoutRect,
    			IntPtr stringFormat)
    		{
    			if ((text == null) || (text.Length == 0))
    				return SizeF.Empty;
    
    			if (font == null)
    				throw new ArgumentNullException ("font");
    
    			RectangleF boundingBox = new RectangleF ();
    
    			Status status = GDIPlus.GdipMeasureString (nativeObject, text, text.Length, font.NativeObject, 
    				ref layoutRect, stringFormat, out boundingBox, null, null);
    			GDIPlus.CheckStatus (status);
    
    			return new SizeF (boundingBox.Width, boundingBox.Height);
    		}
    
    		[DllImport(GdiPlus, CharSet=CharSet.Unicode)]
    		internal unsafe static extern Status GdipMeasureString(IntPtr graphics, string str, int length,
    			IntPtr font, ref RectangleF layoutRect, IntPtr stringFormat, out RectangleF boundingBox,
    			int *codepointsFitted, int *linesFilled);
    

    https://github.com/mono/mono/blob/master/mcs/class/System.Drawing/System.Drawing/Graphics.cs#L1934
    https://github.com/mono/mono/blob/master/mcs/class/System.Drawing/System.Drawing/gdipFunctions.cs#L48
    https://github.com/mono/libgdiplus/blob/master/src/text.c#L72
    https://github.com/mono/libgdiplus/blob/master/src/text-pango.c#L563
    https://github.com/mono/libgdiplus/blob/master/src/text-cairo.c#L114

    image

    printf '%s\n%s%s\n' "1234" $(unichr 0x1f90d) "234"
    1234
    🤍234
    

    From https://stackoverflow.com/questions/602912/how-do-you-echo-a-4-digit-unicode-character-in-bash credit https://stackoverflow.com/users/912236.

    fast_chr ()
    {
        local __octal;
        local __char;
        printf -v __octal '%03o' $1;
        printf -v __char \\$__octal;
        REPLY=$__char
    }
    unichr ()
    {
        local c=$1;
        local l=0;
        local o=63;
        local p=128;
        local s='';
        (( c < 0x80 )) && {
            fast_chr "$c";
            echo -n "$REPLY";
            return
        };
        while (( c > o )); do
            fast_chr $(( t = 0x80 | c & 0x3f ));
            s="$REPLY$s";
            (( c >>= 6, l++, p += o+1, o>>=1 ));
        done;
        fast_chr $(( t = p | c ));
        echo -n "$REPLY$s"
    }
    
  12. mintty commented on Dec 3, 2020

    @mintty
    Owner

    Width measuring is proper for graphic output but not for cell-based output, for which wcwidth is the reference. Note that terminals force output width to fit into the cell matrix, so using font-based metrics makes no sense for terminal applications.

  13. pagerc commented on Dec 5, 2020

    @pagerc
    Author

    I've been comparing Microsoft Terminal and Alacritty to wsltty and I think my biggest issue with wsltty is the glyph clipping which doesn't seem to impact Alacritty. My intention behind this request was to force rendering of narrow characters to wide to resolve clipping. Alternatively to narrow/wide, are there any wsltty options to change/scale the glyph when rendering so that it doesn't clip/truncate?

    I want to highlight that Microsoft Terminal maintains it's own width descriptors. I haven't compared it to wcwidth or EastAsianWidth.txt to see how they deviate, but it'd be interesting to dig into what/why they're doing a custom codepoint width detector.
    microsoft/terminal#5934 - talks about Epres emoji widths
    microsoft/terminal#5795 - talks about failed attempt to set MS specific emojis to wide and breaking things
    microsoft/terminal#900 - identifies a sad spider
    https://github.com/microsoft/terminal/blob/main/src/types/CodepointWidthDetector.cpp

    Left: Microsoft Terminal | Center: wsltty | Right: Alacritty
    image

  14. mintty commented on Dec 5, 2020

    @mintty
    Owner

    wsltty options to change/scale the glyph when rendering so that it doesn't clip/truncate?

    Yes, there is auto-narrowing, which means the glyph is squeezed if it does not fit into the determined cell width. Auto-narrowing is a trade-off, however, as there are undesirable border cases (see #979, #922, #914, #892). Default value is 75, try to reduce e.g. CharNarrowing=60 to see whether your characters are affected. Which are they, anyway?

    Thanks for the references to MS width handling, I may check them out later. However, the only really authoritative source for character width properties should be Unicode, so the question for clear criteria for the set of characters to be made wide is still open, I guess.

  15. pagerc commented on Dec 6, 2020

    @pagerc
    Author

    I'm utterly confused as to why I'm getting clipping at this point. I've manually forced my font to Segoe UI because that's the default font fallback, and I get clipping with every settings variation I can think of with narrowing at 50, narrowing at 100, ambig-wide, etc. I'm not really noticing an impact from the CharNarrowing field, do I need another setting to trigger it? I've also used font sizes from 8 to 18 to see if I can see any difference (normally I use font size 8, but enlarged to 18 to see if clipping disappears with larger font, it does not).

    All of my screenshots show the output of unicode.raw that I pasted in my initial problem report at top. Key symbols that cause problems for clipping:

    ⚠ - Warning - warning conditions
    ℹ - Informational - informational message
    
    **Miscellaneous Symbols and Pictographs**
    - [ ] U+1F321 🌡 Themometer
    - [ ] U+1F322 🌢 Black Droplet
    - [ ] U+1F323 🌣 White Sun
    - [ ] U+1F324 🌤 White Sun with Small Cloud
    - [ ] U+1F325 🌥 White Sun Behind Cloud
    - [ ] U+1F326 🌦 White Sun Behind Cloud with Rain
    
  16. 3 remaining items

  17. pagerc commented on Dec 8, 2020

    @pagerc
    Author

    Uploaded some fixes for auto-narrowing, particularly implemented width detection for non-BMP characters.

    Are there nightly builds for such updates?

  18. mintty commented on Dec 8, 2020

    @mintty
    Owner

    No, but building mintty yourself is easy, you just need cygwin with packages gcc-core and make.

  19. k-takata commented on Dec 8, 2020

    @k-takata
    Contributor

    @mintty How about updating the INSTALL file, and link it from README.md?

  20. mintty commented on Dec 20, 2020

    @mintty
    Owner

    Released 3.4.4.

  21. mintty commented on Sep 3, 2021

    @mintty
    Owner

    Released 3.5.1.

  22. mintty commented on Feb 20, 2022

    @mintty
    Owner

    I had to tweak 81e327 for another issue.
    Please recheck this issue if possible.

  23. pagerc commented on Feb 20, 2022

    @pagerc
    Author

    Looks good on 3.5.3, maybe some left clipping on icons:

    # To use common configuration in %APPDATA%\mintty, simply remove this file
    #Columns=274
    #Rows=76
    Term=mintty-direct
    AllowSetSelection=yes
    RightClickAction=extend
    CursorType=block
    Transparency=low
    Scrollbar=none
    BoldAsFont=yes
    BoldAsColour=no
    #FontSmoothing=default
    FontChoice=PictoSymbols:1
    Font=Iosevka Term SS02
    #Font=Segoe UI Symbol
    #Font=Cascadia Mono
    #Font=Consolas
    Font1=Segoe UI Symbol
    #Font3=FuraCode NF
    FontHeight=11
    #FontHeight=8
    #FontWeight=400
    CharNarrowing=50
    #Charwidth=wide
    #Charwidth=ambig-wide
    #Emojis=windows
    #Emojis=noto
    #EmojiPlacement=full
    

    image

  24. pagerc commented on Feb 20, 2022

    @pagerc
    Author

    Narrowing turned off, still some minor clipping on the black droplet and the cloud symbols, but passably readable and better than my earlier issues:
    image

  25. mintty commented on Feb 20, 2022

    @mintty
    Owner

    Looks good on 3.5.3 ...

    Thanks, what I actually meant is to check the current master version / latest commit. Compiling mintty is easy, no further dependencies, just gcc and make needed.

  26. pagerc commented on Feb 21, 2022

    @pagerc
    Author

    Looks good on 3.5.3 ...

    Thanks, what I actually meant is to check the current master version / latest commit. Compiling mintty is easy, no further dependencies, just gcc and make needed.

    git clone https://github.com/mintty/wsltty
    Cloning into 'wsltty'...
    remote: Enumerating objects: 841, done.
    remote: Counting objects: 100% (134/134), done.
    remote: Compressing objects: 100% (84/84), done.
    remote: Total 841 (delta 73), reused 95 (delta 37), pack-reused 707
    Receiving objects: 100% (841/841), 344.10 KiB | 1.66 MiB/s, done.
    Resolving deltas: 100% (515/515), done.
    bash-5.1$ cd wsltty/
    bash-5.1$ make
    makefile:94: *** Target 'x86_64-alpine-linux-musl' not supported.  Stop.
    

    It might be easy, but the makefile is incompatible with my Alpine Linux WSL build environment on Windows. I might be able to address the incompatibility in a couple weeks to get a build going. In the meantime, if you have a wsltty build for Windows, I can test that sooner.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions