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

Add debug and clone to Font and its types. #56

Closed
wants to merge 3 commits into from
Closed
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
16 changes: 14 additions & 2 deletions src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl LineMetrics {
}
}

#[derive(Clone)]
#[derive(Clone, Debug)]
pub(crate) struct Glyph {
pub v_lines: Vec<Line>,
pub m_lines: Vec<Line>,
Expand All @@ -149,7 +149,7 @@ impl Default for Glyph {
}

/// Settings for controlling specific font and layout behavior.
#[derive(Copy, Clone, PartialEq)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct FontSettings {
/// The default is true. This offsets glyphs relative to their position in their scaled
/// bounding box. This is required for laying out glyphs correctly, but can be disabled to make
Expand All @@ -175,6 +175,7 @@ impl Default for FontSettings {
}

/// Represents a font. Fonts are immutable after creation and owns its own copy of the font data.
#[derive(Clone)]
pub struct Font {
units_per_em: f32,
glyphs: Vec<Glyph>,
Expand All @@ -184,6 +185,17 @@ pub struct Font {
settings: FontSettings,
}

impl core::fmt::Debug for Font {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
// when `finish_non_exhaustive` is stablized, we'll use it here
// but for now, this is fine
f.debug_struct("Font")
.field("units_per_em", &self.units_per_em)
.field("settings", &self.settings)
.finish()
}
}

/// Converts a ttf-parser FaceParsingError into a string.
fn convert_error(error: FaceParsingError) -> &'static str {
use FaceParsingError::*;
Expand Down
17 changes: 16 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
//! Fontdue is a font parser, rasterizer, and layout tool.
//!
//! This is a #![no_std] crate, but still requires the alloc crate.

#![no_std]
#![allow(dead_code)]
#![allow(
clippy::excessive_precision,
clippy::approx_constant,
clippy::float_cmp,
clippy::needless_bool,
clippy::upper_case_acronyms,
clippy::many_single_char_names,
clippy::wildcard_in_or_patterns,
clippy::needless_return,
clippy::transmute_int_to_float,
clippy::transmute_float_to_int,
clippy::ptr_arg,
clippy::transmute_ptr_to_ptr,
clippy::let_and_return,
clippy::redundant_slicing,
)]

extern crate alloc;

Expand Down
2 changes: 1 addition & 1 deletion src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl Point {
}
}

#[derive(Copy, Clone)]
#[derive(Debug, Copy, Clone)]
pub struct Line {
/// X0, Y0, X1, Y1.
pub coords: f32x4,
Expand Down
2 changes: 1 addition & 1 deletion src/platform/simd_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use core::mem::transmute;
use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};

#[repr(C)]
#[derive(Copy, Clone)]
#[derive(Debug, Copy, Clone)]
pub struct f32x4 {
x0: f32,
x1: f32,
Expand Down
2 changes: 1 addition & 1 deletion src/platform/simd_x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use core::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use core::arch::x86_64::*;

#[derive(Copy, Clone)]
#[derive(Debug, Copy, Clone)]
#[repr(transparent)]
pub struct f32x4(__m128);

Expand Down