cosmic_text: Handle subpixel variants (#16238)
Closes https://github.com/zed-industries/zed/issues/14169, closes https://github.com/zed-industries/zed/issues/14387 | Before | After | | --- | ---| |  |  | |  |  | Release Notes: - Linux: Improved text rendering by handling subpixel positioning.
This commit is contained in:
parent
99d45ba694
commit
e7c8dba54f
1 changed files with 7 additions and 7 deletions
|
@ -1,7 +1,7 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
point, size, Bounds, DevicePixels, Font, FontFeatures, FontId, FontMetrics, FontRun, FontStyle,
|
point, size, Bounds, DevicePixels, Font, FontFeatures, FontId, FontMetrics, FontRun, FontStyle,
|
||||||
FontWeight, GlyphId, LineLayout, Pixels, PlatformTextSystem, Point, RenderGlyphParams,
|
FontWeight, GlyphId, LineLayout, Pixels, PlatformTextSystem, Point, RenderGlyphParams,
|
||||||
ShapedGlyph, SharedString, Size,
|
ShapedGlyph, SharedString, Size, SUBPIXEL_VARIANTS,
|
||||||
};
|
};
|
||||||
use anyhow::{anyhow, Context, Ok, Result};
|
use anyhow::{anyhow, Context, Ok, Result};
|
||||||
use collections::HashMap;
|
use collections::HashMap;
|
||||||
|
@ -284,11 +284,10 @@ impl CosmicTextSystemState {
|
||||||
|
|
||||||
fn raster_bounds(&mut self, params: &RenderGlyphParams) -> Result<Bounds<DevicePixels>> {
|
fn raster_bounds(&mut self, params: &RenderGlyphParams) -> Result<Bounds<DevicePixels>> {
|
||||||
let font = &self.loaded_fonts_store[params.font_id.0];
|
let font = &self.loaded_fonts_store[params.font_id.0];
|
||||||
let font_system = &mut self.font_system;
|
|
||||||
let image = self
|
let image = self
|
||||||
.swash_cache
|
.swash_cache
|
||||||
.get_image(
|
.get_image(
|
||||||
font_system,
|
&mut self.font_system,
|
||||||
CacheKey::new(
|
CacheKey::new(
|
||||||
font.id(),
|
font.id(),
|
||||||
params.glyph_id.0 as u16,
|
params.glyph_id.0 as u16,
|
||||||
|
@ -315,19 +314,20 @@ impl CosmicTextSystemState {
|
||||||
if glyph_bounds.size.width.0 == 0 || glyph_bounds.size.height.0 == 0 {
|
if glyph_bounds.size.width.0 == 0 || glyph_bounds.size.height.0 == 0 {
|
||||||
Err(anyhow!("glyph bounds are empty"))
|
Err(anyhow!("glyph bounds are empty"))
|
||||||
} else {
|
} else {
|
||||||
// todo(linux) handle subpixel variants
|
|
||||||
let bitmap_size = glyph_bounds.size;
|
let bitmap_size = glyph_bounds.size;
|
||||||
let font = &self.loaded_fonts_store[params.font_id.0];
|
let font = &self.loaded_fonts_store[params.font_id.0];
|
||||||
let font_system = &mut self.font_system;
|
let subpixel_shift = params
|
||||||
|
.subpixel_variant
|
||||||
|
.map(|v| v as f32 / (SUBPIXEL_VARIANTS as f32 * params.scale_factor));
|
||||||
let mut image = self
|
let mut image = self
|
||||||
.swash_cache
|
.swash_cache
|
||||||
.get_image(
|
.get_image(
|
||||||
font_system,
|
&mut self.font_system,
|
||||||
CacheKey::new(
|
CacheKey::new(
|
||||||
font.id(),
|
font.id(),
|
||||||
params.glyph_id.0 as u16,
|
params.glyph_id.0 as u16,
|
||||||
(params.font_size * params.scale_factor).into(),
|
(params.font_size * params.scale_factor).into(),
|
||||||
(0.0, 0.0),
|
(subpixel_shift.x, subpixel_shift.y.trunc()),
|
||||||
cosmic_text::CacheKeyFlags::empty(),
|
cosmic_text::CacheKeyFlags::empty(),
|
||||||
)
|
)
|
||||||
.0,
|
.0,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue