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

Refined text glyph snapping #1465

Merged
merged 1 commit into from Jul 13, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -261,6 +261,7 @@ impl GlyphRasterizer {
for job in rasterized_glyphs {
let image_id = job.result.and_then(
|glyph| if glyph.width > 0 && glyph.height > 0 {
assert_eq!((glyph.left.fract(), glyph.top.fract()), (0.0, 0.0));
let image_id = texture_cache.insert(
ImageDescriptor {
width: glyph.width,
@@ -334,7 +335,7 @@ impl GlyphRequest {
point: LayoutPoint,
render_mode: FontRenderMode,
glyph_options: Option<GlyphOptions>,
) -> GlyphRequest {
) -> Self {
GlyphRequest {
key: GlyphKey::new(font_key, size, color, index, point, render_mode),
render_mode,
@@ -536,10 +536,24 @@ impl TextRunPrimitiveCpu {
// GPU block.
let first_glyph = glyph_chunk.first().unwrap();
let second_glyph = glyph_chunk.last().unwrap();
request.push([first_glyph.point.x,
first_glyph.point.y,
second_glyph.point.x,
second_glyph.point.y]);
let data = match self.render_mode {
FontRenderMode::Mono |
FontRenderMode::Alpha => [
first_glyph.point.x,
first_glyph.point.y,
second_glyph.point.x,
second_glyph.point.y,
],
// The sub-pixel offset has already been taken into account
// by the glyph rasterizer, thus the truncating here.
FontRenderMode::Subpixel => [

This comment has been minimized.

@glennw

glennw Jul 12, 2017

Member

Instead of a conditional here, can we do this in the prepare_prim_for_render when the glyph_instances array is created? That would mean only doing it once, not each time it needs to get added to the cache.

first_glyph.point.x.trunc(),
first_glyph.point.y.trunc(),
second_glyph.point.x.trunc(),
second_glyph.point.y.trunc(),
],
};
request.push(data);
}
}
}
@@ -20,7 +20,7 @@ use texture_cache::{TextureCache, TextureCacheItemId};
use api::{Epoch, FontKey, FontTemplate, GlyphKey, ImageKey, ImageRendering};
use api::{FontRenderMode, ImageData, GlyphDimensions, WebGLContextId};
use api::{DevicePoint, DeviceIntSize, DeviceUintRect, ImageDescriptor, ColorF};
use api::{GlyphOptions, GlyphInstance, TileOffset, TileSize};
use api::{GlyphOptions, GlyphInstance, SubpixelPoint, TileOffset, TileSize};
use api::{BlobImageRenderer, BlobImageDescriptor, BlobImageError, BlobImageRequest, BlobImageData};
use api::BlobImageResources;
use api::{ExternalImageData, ExternalImageType, LayoutPoint};
@@ -482,21 +482,21 @@ impl ResourceCache {
glyph_options: Option<GlyphOptions>,
mut f: F) -> SourceTexture where F: FnMut(usize, &GpuCacheHandle) {
debug_assert_eq!(self.state, State::QueryResources);
let mut glyph_key = GlyphRequest::new(
let mut glyph_request = GlyphRequest::new(
font_key,
size,
color,
0,
LayoutPoint::new(0.0, 0.0),
LayoutPoint::zero(),
render_mode,
glyph_options
);
let mut texture_id = None;
for (loop_index, glyph_instance) in glyph_instances.iter().enumerate() {
glyph_key.key.index = glyph_instance.index;
glyph_key.key.subpixel_point.set_offset(glyph_instance.point, render_mode);
glyph_request.key.index = glyph_instance.index;
glyph_request.key.subpixel_point = SubpixelPoint::new(glyph_instance.point, render_mode);

let image_id = self.cached_glyphs.get(&glyph_key, self.current_frame_id);
let image_id = self.cached_glyphs.get(&glyph_request, self.current_frame_id);
let cache_item = image_id.map(|image_id| self.texture_cache.get(image_id));
if let Some(cache_item) = cache_item {
f(loop_index, &cache_item.uv_rect_handle);
@@ -149,11 +149,6 @@ impl SubpixelPoint {
pub fn to_f64(&self) -> (f64, f64) {
(self.x.into(), self.y.into())
}

pub fn set_offset(&mut self, point: LayoutPoint, render_mode: FontRenderMode) {
self.x = render_mode.subpixel_quantize_offset(point.x);
self.y = render_mode.subpixel_quantize_offset(point.y);
}
}

#[derive(Clone, Hash, PartialEq, Eq, Debug, Deserialize, Serialize, Ord, PartialOrd)]
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.