use helpers::InternalConstructor;
use std::mem;
use winapi::um::dwrite::*;
#[derive(Copy, Clone)]
pub struct Metrics {
metrics: DWRITE_TEXT_METRICS,
}
impl InternalConstructor for Metrics {
type Arguments = DWRITE_TEXT_METRICS;
#[inline]
fn build(args: DWRITE_TEXT_METRICS) -> Self {
Metrics { metrics: args }
}
}
impl Metrics {
#[inline]
pub fn left(&self) -> f32 {
self.metrics.left
}
#[inline]
pub fn top(&self) -> f32 {
self.metrics.top
}
#[inline]
pub fn width(&self) -> f32 {
self.metrics.width
}
#[inline]
pub fn width_including_trailing_whitespace(&self) -> f32 {
self.metrics.widthIncludingTrailingWhitespace
}
#[inline]
pub fn height(&self) -> f32 {
self.metrics.height
}
#[inline]
pub fn layout_width(&self) -> f32 {
self.metrics.layoutWidth
}
#[inline]
pub fn layout_height(&self) -> f32 {
self.metrics.layoutHeight
}
#[inline]
pub fn max_bidi_reordering_depth(&self) -> u32 {
self.metrics.maxBidiReorderingDepth
}
#[inline]
pub fn line_count(&self) -> u32 {
self.metrics.lineCount
}
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct ClusterMetrics {
metrics: DWRITE_CLUSTER_METRICS,
}
impl Default for ClusterMetrics {
#[inline]
fn default() -> Self {
unsafe { mem::zeroed() }
}
}
impl InternalConstructor for ClusterMetrics {
type Arguments = DWRITE_CLUSTER_METRICS;
#[inline]
fn build(args: DWRITE_CLUSTER_METRICS) -> Self {
ClusterMetrics { metrics: args }
}
}
impl ClusterMetrics {
#[inline]
pub fn width(&self) -> f32 {
self.metrics.width
}
#[inline]
pub fn length(&self) -> u16 {
self.metrics.length
}
#[inline]
pub fn can_wrap_line_after(&self) -> bool {
self.metrics.canWrapLineAfter() != 0
}
#[inline]
pub fn is_whitespace(&self) -> bool {
self.metrics.isWhitespace() != 0
}
#[inline]
pub fn is_newline(&self) -> bool {
self.metrics.isNewline() != 0
}
#[inline]
pub fn is_soft_hyphen(&self) -> bool {
self.metrics.isSoftHyphen() != 0
}
#[inline]
pub fn is_right_to_left(&self) -> bool {
self.metrics.isRightToLeft() != 0
}
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct LineMetrics {
metrics: DWRITE_LINE_METRICS,
}
impl Default for LineMetrics {
#[inline]
fn default() -> Self {
unsafe { mem::zeroed() }
}
}
impl InternalConstructor for LineMetrics {
type Arguments = DWRITE_LINE_METRICS;
#[inline]
fn build(args: DWRITE_LINE_METRICS) -> Self {
LineMetrics { metrics: args }
}
}
impl LineMetrics {
#[inline]
pub fn length(&self) -> u32 {
self.metrics.length
}
#[inline]
pub fn trailing_whitespace_length(&self) -> u32 {
self.metrics.trailingWhitespaceLength
}
#[inline]
pub fn newline_length(&self) -> u32 {
self.metrics.newlineLength
}
#[inline]
pub fn height(&self) -> f32 {
self.metrics.height
}
#[inline]
pub fn baseline(&self) -> f32 {
self.metrics.baseline
}
#[inline]
pub fn is_trimmed(&self) -> bool {
self.metrics.isTrimmed != 0
}
}
#[derive(Copy, Clone)]
pub struct OverhangMetrics {
metrics: DWRITE_OVERHANG_METRICS,
}
impl InternalConstructor for OverhangMetrics {
type Arguments = DWRITE_OVERHANG_METRICS;
#[inline]
fn build(args: DWRITE_OVERHANG_METRICS) -> Self {
OverhangMetrics { metrics: args }
}
}
impl OverhangMetrics {
#[inline]
pub fn left(&self) -> f32 {
self.metrics.left
}
#[inline]
pub fn top(&self) -> f32 {
self.metrics.top
}
#[inline]
pub fn right(&self) -> f32 {
self.metrics.right
}
#[inline]
pub fn bottom(&self) -> f32 {
self.metrics.bottom
}
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct HitTestMetrics {
metrics: DWRITE_HIT_TEST_METRICS,
}
impl Default for HitTestMetrics {
#[inline]
fn default() -> Self {
unsafe { mem::zeroed() }
}
}
impl InternalConstructor for HitTestMetrics {
type Arguments = DWRITE_HIT_TEST_METRICS;
#[inline]
fn build(args: Self::Arguments) -> Self {
HitTestMetrics { metrics: args }
}
}
impl HitTestMetrics {
pub fn text_position(&self) -> u32 {
self.metrics.textPosition
}
pub fn length(&self) -> u32 {
self.metrics.length
}
pub fn left(&self) -> f32 {
self.metrics.left
}
pub fn top(&self) -> f32 {
self.metrics.top
}
pub fn width(&self) -> f32 {
self.metrics.width
}
pub fn height(&self) -> f32 {
self.metrics.height
}
pub fn bidi_level(&self) -> u32 {
self.metrics.bidiLevel
}
pub fn is_text(&self) -> bool {
self.metrics.isText != 0
}
pub fn is_trimmed(&self) -> bool {
self.metrics.isTrimmed != 0
}
}