Skip to content

Commit

Permalink
Inverting text subpixel y
Browse files Browse the repository at this point in the history
Because of the inversion of the orientation of drawing, the subpixel is
actually subtractive.
  • Loading branch information
ecton committed Dec 14, 2023
1 parent 2fffa61 commit 9466269
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions examples/text-metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn main() -> Result<(), EventLoopError> {
Point::new(measured.left, line_height - measured.ascent),
Size::new(measured.size.width - measured.left, measured.ascent),
),
Color::new(0, 40, 0, 255),
Color::new(0, 255, 0, 128),
)
.translate_by(inset),
);
Expand All @@ -31,7 +31,7 @@ fn main() -> Result<(), EventLoopError> {
Point::new(measured.left, line_height),
Size::new(measured.size.width - measured.left, -measured.descent),
),
Color::new(0, 0, 40, 255),
Color::new(0, 0, 255, 128),
)
.translate_by(inset),
);
Expand Down
14 changes: 8 additions & 6 deletions src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,15 +494,17 @@ pub(crate) fn map_each_glyph(
continue;
};

let subpixel = Point::new(
physical.cache_key.x_bin.as_float(),
1.0 - physical.cache_key.y_bin.as_float(),
)
.map(Px::from);

let blit = TextureBlit::new(
cached.texture.region,
Rect::new(
(Point::new(physical.x, physical.y)).cast::<Px>()
+ Point::new(
physical.cache_key.x_bin.as_float(),
physical.cache_key.y_bin.as_float(),
)
.map(Px::from)
+ subpixel
+ Point::new(
image.placement.left,
metrics.line_height.cast::<i32>() - image.placement.top,
Expand Down Expand Up @@ -586,7 +588,7 @@ where
} else {
MeasuredText {
ascent: line_height - Unit::from_px(min.y, kludgine.scale),
descent: Unit::from_px(first_line_max_y, kludgine.scale) - line_height,
descent: line_height - Unit::from_px(first_line_max_y, kludgine.scale),
left: Unit::from_px(min.x, kludgine.scale),
size: Size {
width: Unit::from_px(max.x, kludgine.scale),
Expand Down

0 comments on commit 9466269

Please sign in to comment.