Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paint tab characters as a single space #34389

Merged
merged 5 commits into from
Jul 1, 2022
Merged

Conversation

loic-sharma
Copy link
Member

@loic-sharma loic-sharma commented Jun 30, 2022

This change makes Windows render tabs as a single space. Previously, tabs rendered differently depending on your platform:

  • Windows, Web - a tofu is rendered
  • iOS, Android, macOS, Linux - a single space is rendered

Part of flutter/flutter#79153.

Background

During text shaping, Skia’s SkPagraph converts characters into font glyphs. Most fonts don't have a glyph for \t, so the "unknown" glyph should be selected and a tofu should be drawn. However, some platforms will override this using their own platform-specific logic and select the glyph for a single space instead. For more information, see: https://bugs.chromium.org/p/skia/issues/detail?id=12334

Skia added a feature to substitute tabs with a single space so that platforms could behave consistently. This change enables this new feature on Flutter, thereby making tabs no longer render as a tofu on Windows.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@GaryQian
Copy link
Contributor

Tabs are typically rendered as multiple spaces, but it looks like this skparagraph impl always replaces with a single space. This would result in changed layouts and potentially unexpected tab behavior (one space, expecting 2 spaces), no?

@loic-sharma
Copy link
Member Author

loic-sharma commented Jun 30, 2022

During text shaping, Skia’s SkPagraph converts characters into font glyphs. Most fonts don't have a glyph for \t, so the "unknown" glyph should be selected and a tofu should be drawn. However, some platforms will override this using their own platform-specific logic and select some other glyph instead. This results in differences across platforms:

  • Windows, Web - a tofu is rendered
  • iOS, Android, macOS, Linux - whitespace is rendered. I believe this is a single space, but I'll double-check this. EDIT: This is a single space on iOS and macOS.

In other words, this change makes Windows consistent with iOS, Android, macOS, and Linux. See this Google internal doc on Flutter control characters for more information.

I agree that drawing a \t as a single space is not ideal behavior. However, proper support for tabs is non-trivial and is out-of-scope for this fix.

@jason-simmons
Copy link
Member

The test is failing on CI

@loic-sharma
Copy link
Member Author

FYI I changed the test as the original one failed due to differences in rendering across platforms.

The new test creates 3 images: a baseline image of text containing a space, a baseline image of text containing a tofu, and a test image of text containing a tab. If then compares these three images to verify that a tab is rendered identically to a space on that platform.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants