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

Don't render the \r (Carriage Return) character, because it sucks #2452

Merged
merged 3 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ NOTE: [`epaint`](crates/epaint/CHANGELOG.md), [`eframe`](crates/eframe/CHANGELOG

### Fixed 🐛
* Expose `TextEdit`'s multiline flag to AccessKit ([#2448](https://github.com/emilk/egui/pull/2448)).
* Don't render `\r` (Carriage Return) ([#2452](https://github.com/emilk/egui/pull/2452)).


## 0.20.1 - 2022-12-11 - Fix key-repeat
Expand Down
3 changes: 2 additions & 1 deletion crates/epaint/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to the epaint crate will be documented in this file.

## Unreleased
* Improve the look of thin white lines ([#2437](https://github.com/emilk/egui/pull/2437)).
* Don't render `\r` (Carriage Return) ([#2452](https://github.com/emilk/egui/pull/2452)).


## 0.20.0 - 2022-12-08
Expand All @@ -20,7 +21,7 @@ All notable changes to the epaint crate will be documented in this file.
* Added `epaint::hex_color!` to create `Color32`'s from hex strings under the `color-hex` feature ([#1596](https://github.com/emilk/egui/pull/1596)).
* Optimize tessellation of filled circles by 10x or more ([#1616](https://github.com/emilk/egui/pull/1616)).
* Added opt-in feature `deadlock_detection` to detect double-lock of mutexes on the same thread ([#1619](https://github.com/emilk/egui/pull/1619)).
* Texture loading now takes a `TexureOptions` with minification and magnification filters ([#2224](https://github.com/emilk/egui/pull/2224)).
* Texture loading now takes a `TextureOptions` with minification and magnification filters ([#2224](https://github.com/emilk/egui/pull/2224)).


## 0.18.1 - 2022-05-01
Expand Down
31 changes: 21 additions & 10 deletions crates/epaint/src/text/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ pub struct GlyphInfo {
/// Unit: points.
pub advance_width: f32,

/// Texture coordinates. None for space.
/// Texture coordinates.
pub uv_rect: UvRect,
}

impl Default for GlyphInfo {
/// Basically a zero-width space.
fn default() -> Self {
Self {
id: ab_glyph::GlyphId(0),
Expand Down Expand Up @@ -105,6 +106,9 @@ impl FontImpl {
}
}

/// Code points that will always be replaced by the replacement character.
///
/// See also [`invisible_char`].
fn ignore_character(&self, chr: char) -> bool {
if self.name == "emoji-icon-font" {
// HACK: https://github.com/emilk/egui/issues/1284 https://github.com/jslegers/emoji-icon-font/issues/18
Expand Down Expand Up @@ -142,7 +146,7 @@ impl FontImpl {
}

if self.ignore_character(c) {
return None;
return None; // these will result in the replacement character when rendering
}

if c == '\t' {
Expand Down Expand Up @@ -173,19 +177,18 @@ impl FontImpl {
}
}

if invisible_char(c) {
let glyph_info = GlyphInfo::default();
self.glyph_info_cache.write().insert(c, glyph_info);
return Some(glyph_info);
}

// Add new character:
use ab_glyph::Font as _;
let glyph_id = self.ab_glyph_font.glyph_id(c);

if glyph_id.0 == 0 {
if invisible_char(c) {
// hack
let glyph_info = GlyphInfo::default();
self.glyph_info_cache.write().insert(c, glyph_info);
Some(glyph_info)
} else {
None // unsupported character
}
None // unsupported character
} else {
let glyph_info = allocate_glyph(
&mut self.atlas.lock(),
Expand Down Expand Up @@ -376,8 +379,16 @@ impl Font {
}
}

/// Code points that will always be invisible (zero width).
///
/// See also [`FontImpl::ignore_character`].
#[inline]
fn invisible_char(c: char) -> bool {
if c == '\r' {
// A character most vile and pernicious. Don't display it.
return true;
}

// See https://github.com/emilk/egui/issues/336

// From https://www.fileformat.info/info/unicode/category/Cf/list.htm
Expand Down