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

Make Size::as_px return f32 #59

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ The sections should follow the order `Added`, `Changed`, `Fixed`, and `Removed`.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Changed

- `Size::as_px` now returns `f32`.

## 0.6.0

## Changed
### Changed

- `Size` now uses 6 floating point digits precision instead of rounding to 0.5.
- Add `Size::from_px`, `Size::as_px`, `Size::as_pt`, and `Size::scale`.
Expand Down
4 changes: 2 additions & 2 deletions src/directwrite/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl DirectWriteRasterizer {
character: char,
glyph_index: u16,
) -> Result<RasterizedGlyph, Error> {
let em_size = f32::from(size.as_px());
let em_size = size.as_px();

let glyph_run = DWRITE_GLYPH_RUN {
fontFace: unsafe { face.as_ptr() },
Expand Down Expand Up @@ -148,7 +148,7 @@ impl crate::Rasterize for DirectWriteRasterizer {
let face = &self.get_loaded_font(key)?.face;
let vmetrics = face.metrics().metrics0();

let scale = f32::from(size.as_px()) / f32::from(vmetrics.designUnitsPerEm);
let scale = size.as_px() / f32::from(vmetrics.designUnitsPerEm);

let underline_position = f32::from(vmetrics.underlinePosition) * scale;
let underline_thickness = f32::from(vmetrics.underlineThickness) * scale;
Expand Down
2 changes: 1 addition & 1 deletion src/ft/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl Rasterize for FreeTypeRasterizer {
let font_key = self.face_for_glyph(glyph_key);
let face = &self.loader.faces[&font_key];
let index = face.ft_face.get_char_index(glyph_key.character as usize);
let pixelsize = face.non_scalable.unwrap_or_else(|| glyph_key.size.as_px() as f32);
let pixelsize = face.non_scalable.unwrap_or_else(|| glyph_key.size.as_px());

if !face.colored_bitmap {
face.ft_face.set_char_size(to_freetype_26_6(pixelsize), 0, 0, 0)?;
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ impl Size {
}

/// Get size in `px`.
pub fn as_px(self) -> u16 {
(self.as_pt() * 96. / 72.).trunc() as u16
pub fn as_px(self) -> f32 {
self.as_pt() * 96. / 72.
}

/// Get the size in `pt`.
Expand Down