From ef3bcd48cfa9a681ee5f74ee1584b175c87e8cad Mon Sep 17 00:00:00 2001 From: Ana Gelez Date: Wed, 17 Apr 2024 16:46:37 +0200 Subject: [PATCH] Make sealed trait methods not usable outside of pdf-writer --- src/font.rs | 53 +++++++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/src/font.rs b/src/font.rs index 871dd3f..a864d88 100644 --- a/src/font.rs +++ b/src/font.rs @@ -655,7 +655,7 @@ impl<'a> Cmap<'a> { deref!('a, Cmap<'a> => Stream<'a>, stream); /// A builder for a `/ToUnicode` character map stream. -pub struct UnicodeCmap { +pub struct UnicodeCmap { buf: Vec, mappings: Vec, count: i32, @@ -790,38 +790,43 @@ where } } -/// Type3 fonts require (in Acrobat at least) IDs in CMaps to be encoded with one byte only, whereas other font types use two bytes. +/// Type3 fonts require (in Acrobat at least) IDs in CMaps to be encoded with +/// one byte only, whereas other font types use two bytes. /// /// This trait provides an abstraction to support both. -pub trait GlyphId: private::Sealed { - const MIN: Self; - const MAX: Self; - fn push(self, buf: &mut Vec); -} +pub trait GlyphId: private::Sealed {} + +impl GlyphId for u8 {} -impl GlyphId for u8 { - const MIN: Self = u8::MIN; - const MAX: Self = u8::MAX; +impl GlyphId for u16 {} - fn push(self, buf: &mut Vec) { - buf.push_hex(self); +/// Module to seal the `GlyphId` trait. +mod private { + use crate::buf::BufExt; + + pub trait Sealed { + const MIN: Self; + const MAX: Self; + fn push(self, buf: &mut Vec); } -} -impl GlyphId for u16 { - const MIN: Self = u16::MIN; - const MAX: Self = u16::MAX; + impl Sealed for u8 { + const MIN: Self = u8::MIN; + const MAX: Self = u8::MAX; - fn push(self, buf: &mut Vec) { - buf.push_hex_u16(self); + fn push(self, buf: &mut Vec) { + buf.push_hex(self); + } } -} -/// Module to seal the `GlyphId` trait. -mod private { - pub trait Sealed {} - impl Sealed for u8 {} - impl Sealed for u16 {} + impl Sealed for u16 { + const MIN: Self = u16::MIN; + const MAX: Self = u16::MAX; + + fn push(self, buf: &mut Vec) { + buf.push_hex_u16(self); + } + } } /// Specifics about a character collection.