Use euclid::Scale to convert between physical and logical coord spaces
This commit is contained in:
1 parent
8ba72fd7df
commit
8d17f8e64f
12 files changed
+70
-155
No files matched your search
@@ -8,19 +8,19 @@ pub struct GlyphKey {
|
||||
glyph_id: swash::GlyphId,
|
||||
style_id: StyleId,
|
||||
x_bin: SubpixelBin<4>,
|
||||
pixels_per_point: OrderedFloat<f32>,
|
||||
scale_factor: OrderedFloat<f32>,
|
||||
}
|
||||
|
||||
impl GlyphKey {
|
||||
pub fn from_glyph(
|
||||
glyph: &Glyph,
|
||||
style_id: StyleId,
|
||||
pixels_per_point: f32,
|
||||
scale_factor: f32,
|
||||
) -> (Self, PhysicalPoint<i32>) {
|
||||
// Use subpixel binning for x coordinate
|
||||
let (x, x_bin) = SubpixelBin::<4>::new(glyph.x * pixels_per_point);
|
||||
let (x, x_bin) = SubpixelBin::<4>::new(glyph.x * scale_factor);
|
||||
// No binning for y coordinate, just rounding
|
||||
let y = (glyph.y * pixels_per_point).round() as i32;
|
||||
let y = (glyph.y * scale_factor).round() as i32;
|
||||
let glyph_pos = PhysicalPoint::new(x, y);
|
||||
|
||||
(
|
||||
@@ -28,7 +28,7 @@ impl GlyphKey {
|
||||
glyph_id: glyph.id as u16,
|
||||
style_id,
|
||||
x_bin,
|
||||
pixels_per_point: OrderedFloat(pixels_per_point),
|
||||
scale_factor: OrderedFloat(scale_factor),
|
||||
},
|
||||
glyph_pos,
|
||||
)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use crate::{
|
||||
color::Srgba,
|
||||
dpi::{
|
||||
ConvertToLogical, LogicalRect, LogicalVector, NormalizedRect, PhysicalPoint, PhysicalRect,
|
||||
PhysicalVector,
|
||||
LogicalRect, LogicalVector, NormalizedRect, PhysicalPoint, PhysicalRect, PhysicalVector,
|
||||
ScaleFactor,
|
||||
},
|
||||
fonts::{atlas::FontAtlas, glyph_key::GlyphKey},
|
||||
math::Size,
|
||||
@@ -71,7 +71,7 @@ impl RasterizedGlyph {
|
||||
cached: CachedGlyph,
|
||||
position: PhysicalPoint<i32>,
|
||||
color: Srgba,
|
||||
pixels_per_point: f32,
|
||||
scale_factor: ScaleFactor<f32>,
|
||||
) -> Self {
|
||||
let glyph_rect = PhysicalRect::from_origin_and_size(
|
||||
position + cached.baseline_offset,
|
||||
@@ -79,7 +79,7 @@ impl RasterizedGlyph {
|
||||
);
|
||||
|
||||
RasterizedGlyph {
|
||||
rect: glyph_rect.to_logical(pixels_per_point),
|
||||
rect: glyph_rect.cast() / scale_factor,
|
||||
uv: cached.uv,
|
||||
texture_layer_idx: cached.texture_layer_idx,
|
||||
color,
|
||||
@@ -161,11 +161,11 @@ impl GlyphRasterizer {
|
||||
glyph_run: &'run GlyphRun<'_, Srgba>,
|
||||
// additional offset relative to layout origin
|
||||
glyph_offset: LogicalVector<f32>,
|
||||
pixels_per_point: f32,
|
||||
scale_factor: ScaleFactor<f32>,
|
||||
) -> impl Iterator<Item = Option<RasterizedGlyph>> + use<'slf, 'run, 'atlas> {
|
||||
let run = glyph_run.run();
|
||||
let color = glyph_run.style().brush;
|
||||
let font_size = run.font_size() * pixels_per_point;
|
||||
let font_size = run.font_size() * scale_factor.get();
|
||||
let normalized_coords = run.normalized_coords();
|
||||
let skew = run.synthesis().skew(); // skew angle for faux italic
|
||||
|
||||
@@ -192,11 +192,11 @@ impl GlyphRasterizer {
|
||||
glyph.x += glyph_offset.x;
|
||||
glyph.y += glyph_offset.y;
|
||||
|
||||
let (glyph_key, glyph_pos) = GlyphKey::from_glyph(&glyph, style_id, pixels_per_point);
|
||||
let (glyph_key, glyph_pos) = GlyphKey::from_glyph(&glyph, style_id, scale_factor.get());
|
||||
|
||||
if let Some(cached_glyph) = cached_glyphs.get(&glyph_key) {
|
||||
return cached_glyph.map(|cached| {
|
||||
RasterizedGlyph::from_cached(cached, glyph_pos, color, pixels_per_point)
|
||||
RasterizedGlyph::from_cached(cached, glyph_pos, color, scale_factor)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ impl GlyphRasterizer {
|
||||
cached_glyph,
|
||||
glyph_pos,
|
||||
color,
|
||||
pixels_per_point,
|
||||
scale_factor,
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user