Skip to content

Playground font is non-fixed-width for some unicode characters #589

@RalfJung

Description

@RalfJung
Member

I am putting the following code into playground:

fn main() {
    println!("0x00 │ ╾─────alloc777+0──────╼ 2a 00 00 00 00 00 00 00 │ ╾──────╼*.......");
    println!("0x10 │ 2a 00 00 00 00 00 00 00                         │ *.......");
}

Both for the code view and the resulting output, the vertical bars on the right are not properly aligned, even though we can see here in GitHub that in a fixed-width font, they should be aligned.

Also, the cursor (at least in Firefox) behaves really weird in that first line; the indicated position and the position where characters are inserted do not agree...

Activity

shepmaster

shepmaster commented on Apr 5, 2020

@shepmaster
Member

Please add a screenshot of the problem, your OS, and your browser version.

If I understand you correctly, it looks OK for me:

image

  • macOS 10.15.3 (19D76)
  • Chrome Canary 84.0.4104.0
shepmaster

shepmaster commented on Apr 5, 2020

@shepmaster
Member

Also, try your code on the Ace kitchen sink example; to see if it might be an Ace-specific issue.

RalfJung

RalfJung commented on Apr 6, 2020

@RalfJung
MemberAuthor

Yes that looks like I would expect. This is how it looks for me:

Screenshot_2020-04-06 Rust Playground

That's with Firefox 75.0 on Debian testing (amd64).

The page inspector tells me that for the program output on the right, the primary font used is "Source Code Pro", but it uses Fira Mono as a fallback font for , , , . Probably the issue then is that these two fonts do not have the same width?

RalfJung

RalfJung commented on Apr 6, 2020

@RalfJung
MemberAuthor

On https://ace.c9.io/build/kitchen-sink.html, everything is aligned as expected and there is also no "cursor weirdness".

The page inspector lists the same two fonts used for the editor field there. However, I noticed the font size is given in "px" there and in "em" on the playground. And indeed changing the size to use "px" on playground fixes the alignment.

shepmaster

shepmaster commented on Apr 6, 2020

@shepmaster
Member

I see the issue on Firefox myself as well.

And indeed changing the size to use "px" on playground

How did you make this change? I modified .editor-advanced to have font-size: 14px (slightly smaller, so I know it was applied), but the lines continue to be misaligned,

RalfJung

RalfJung commented on Apr 6, 2020

@RalfJung
MemberAuthor

I went to the "fonts" tab in the inspector, and changed it there.

Interestingly this only helps for the "Execution" output tab, not the editor...

RalfJung

RalfJung commented on Apr 6, 2020

@RalfJung
MemberAuthor

Ah, for the editor I also have to change the font size a bit. "14.4px" is broken, but "14px" and "14.5x" px are fine. Wtf...

shepmaster

shepmaster commented on Apr 6, 2020

@shepmaster
Member

I think the fallback issue is related, but I'm unclear why Chrome and FF differ here. I also can't see why specifying in pixels vs em would make a difference.

The Ace kitchen sink example specifies multiple fonts:

 font: 12px/normal 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;

The playground only tries for Source Code Pro, then falls back to the browser's monospace font. My assumption was that the fallback font would always work (poor assumption, I guess). My Firefox settings say that this should be Courier.

If I change the playground to list the fallbacks, it seems to look correct-er

 font-family:'Source Code Pro', 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;

It looks like I need to have both Monaco and Menlo to provide the glyphs you are using.

added
bugThe playground isn't doing what it was intended to
help wantedNot immediately going to be prioritized — ask for mentoring instructions!
on Apr 6, 2020
shepmaster

shepmaster commented on Apr 6, 2020

@shepmaster
Member

Can you try just changing the font-family in the playground to see if that also works for you?

RalfJung

RalfJung commented on Apr 6, 2020

@RalfJung
MemberAuthor

I also can't see why specifying in pixels vs em would make a difference.

My guess is that it works for some font sizes and not for others, and switching units switched it to a font size that works. Not sure though.

Setting it to 1em also makes it look right.

The playground only tries for Source Code Pro, then falls back to the browser's monospace font. My assumption was that the fallback font would always work (poor assumption, I guess). My Firefox settings say that this should be Courier.

It's Fira Mono for me.

Setting the font to 'Source Code Pro', 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace does not seem to make a difference -- I don't think I have any of the others installed.

shepmaster

shepmaster commented on Apr 6, 2020

@shepmaster
Member

Looking at .ace_content, Firefox does indeed show that Source Code Pro isn't enough for that content:

image

Haha, I just realized why my Chrome works — I set my default monospace font to Source Code Pro 🤦‍♀

Setting the same in Firefox makes it look correct. Can you confirm the same behavior? I don't understand how that would apply though...

RalfJung

RalfJung commented on Apr 6, 2020

@RalfJung
MemberAuthor

I don't have Source Code Pro installed I think, at least I can't find it in Firefox' list. I thought it would come in as a webfont here?

Setting the same in Firefox makes it look correct.

Well that's weird, if the glyphs are missing from that font then why would it help to also use it as fallback... maybe it picked a different substitution font then or so? Maybe the webfont (if any) has fewer glyphs than your local version?

shepmaster

shepmaster commented on Apr 6, 2020

@shepmaster
Member

I don't have Source Code Pro installed I think, at least I can't find it in Firefox' list. I thought it would come in as a webfont here?

Oooooh. It is a webfont, but: subset=latin-ext. I wonder if my local copy has more glyphs than the webfont. I tried to update the playground to have a broader set, but that didn't seem to magically work.

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

    bugThe playground isn't doing what it was intended tohelp wantedNot immediately going to be prioritized — ask for mentoring instructions!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @shepmaster@RalfJung

        Issue actions

          Playground font is non-fixed-width for some unicode characters · Issue #589 · rust-lang/rust-playground