Browse Source

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

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

* Update PR links

* Fix doclink
pull/2476/head
Emil Ernerfeldt 2 years ago
committed by GitHub
parent
commit
4e8341d35c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 3
      crates/epaint/CHANGELOG.md
  3. 31
      crates/epaint/src/text/font.rs

1
CHANGELOG.md

@ -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

3
crates/epaint/CHANGELOG.md

@ -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
@ -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

31
crates/epaint/src/text/font.rs

@ -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),
@ -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
@ -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' {
@ -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(),
@ -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

Loading…
Cancel
Save