@@ -171,25 +171,25 @@ impl NetHandler<Resource> for CssHandler {
171171struct FontFaceHandler ( FontFaceSourceFormatKeyword ) ;
172172impl NetHandler < Resource > for FontFaceHandler {
173173 fn bytes ( mut self : Box < Self > , doc_id : usize , bytes : Bytes , callback : SharedCallback < Resource > ) {
174- if self . 0 == FontFaceSourceFormatKeyword :: None {
175- self . 0 = match bytes. as_ref ( ) {
174+ if self . 0 == FontFaceSourceFormatKeyword :: None && bytes . len ( ) >= 4 {
175+ self . 0 = match & bytes. as_ref ( ) [ 0 .. 4 ] {
176176 // WOFF (v1) files begin with 0x774F4646 ('wOFF' in ascii)
177177 // See: <https://w3c.github.io/woff/woff1/spec/Overview.html#WOFFHeader>
178- // #[cfg(any(feature = "woff-c"))]
179- // [b'w', b'O', b'F', b'F', ..] => FontFaceSourceFormatKeyword::Woff,
178+ #[ cfg( any( feature = "woff-c" , feature = "woff-rust ") ) ]
179+ b"wOFF" => FontFaceSourceFormatKeyword :: Woff ,
180180 // WOFF2 files begin with 0x774F4632 ('wOF2' in ascii)
181181 // See: <https://w3c.github.io/woff/woff2/#woff20Header>
182182 #[ cfg( any( feature = "woff-c" , feature = "woff-rust" ) ) ]
183- [ b'w' , b'O' , b'F' , b'2' , .. ] => FontFaceSourceFormatKeyword :: Woff2 ,
183+ b"wOF2" => FontFaceSourceFormatKeyword :: Woff2 ,
184184 // Opentype fonts with CFF data begin with 0x4F54544F ('OTTO' in ascii)
185185 // See: <https://learn.microsoft.com/en-us/typography/opentype/spec/otff#organization-of-an-opentype-font>
186- [ b'O' , b'T' , b'T' , b'O' , .. ] => FontFaceSourceFormatKeyword :: Opentype ,
186+ b"OTTO" => FontFaceSourceFormatKeyword :: Opentype ,
187187 // Opentype fonts truetype outlines begin with 0x00010000
188188 // See: <https://learn.microsoft.com/en-us/typography/opentype/spec/otff#organization-of-an-opentype-font>
189- [ 0x00 , 0x01 , 0x00 , 0x00 , .. ] => FontFaceSourceFormatKeyword :: Truetype ,
189+ & [ 0x00 , 0x01 , 0x00 , 0x00 ] => FontFaceSourceFormatKeyword :: Truetype ,
190190 // Truetype fonts begin with 0x74727565 ('true' in ascii)
191191 // See: <https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6.html#ScalerTypeNote>
192- [ b't' , b'r' , b'u' , b'e' , .. ] => FontFaceSourceFormatKeyword :: Truetype ,
192+ b"true" => FontFaceSourceFormatKeyword :: Truetype ,
193193 _ => FontFaceSourceFormatKeyword :: None ,
194194 }
195195 }
@@ -199,21 +199,26 @@ impl NetHandler<Resource> for FontFaceHandler {
199199 let mut bytes = bytes;
200200
201201 match self . 0 {
202- // #[cfg(feature = "woff-c")]
203- // FontFaceSourceFormatKeyword::Woff => {
204- // #[cfg(feature = "tracing")]
205- // tracing::info!("Decompressing woff1 font");
202+ #[ cfg( any ( feature = "woff-c" , feature = "woff-rust" ) ) ]
203+ FontFaceSourceFormatKeyword :: Woff => {
204+ #[ cfg( feature = "tracing" ) ]
205+ tracing:: info!( "Decompressing woff1 font" ) ;
206206
207- // // Use woff crate to decompress font
208- // let decompressed = woff::version1::decompress(&bytes);
207+ // Use woff crate to decompress font
208+ #[ cfg( feature = "woff-c" ) ]
209+ let decompressed = woff:: version1:: decompress ( & bytes) ;
210+
211+ // Use wuff crate to decompress font
212+ #[ cfg( feature = "woff-rust" ) ]
213+ let decompressed = wuff:: decompress_woff1 ( & bytes) . ok ( ) ;
209214
210- // if let Some(decompressed) = decompressed {
211- // bytes = Bytes::from(decompressed);
212- // } else {
213- // #[cfg(feature = "tracing")]
214- // tracing::warn!("Failed to decompress woff1 font");
215- // }
216- // }
215+ if let Some ( decompressed) = decompressed {
216+ bytes = Bytes :: from ( decompressed) ;
217+ } else {
218+ #[ cfg( feature = "tracing" ) ]
219+ tracing:: warn!( "Failed to decompress woff1 font" ) ;
220+ }
221+ }
217222 #[ cfg( any( feature = "woff-c" , feature = "woff-rust" ) ) ]
218223 FontFaceSourceFormatKeyword :: Woff2 => {
219224 #[ cfg( feature = "tracing" ) ]
@@ -223,9 +228,9 @@ impl NetHandler<Resource> for FontFaceHandler {
223228 #[ cfg( feature = "woff-c" ) ]
224229 let decompressed = woff:: version2:: decompress ( & bytes) ;
225230
226- // Use woff2 crate to decompress font
231+ // Use wuff crate to decompress font
227232 #[ cfg( feature = "woff-rust" ) ]
228- let decompressed = woff2 :: decode :: convert_woff2_to_ttf ( & mut bytes) . ok ( ) ;
233+ let decompressed = wuff :: decompress_woff2 ( & bytes) . ok ( ) ;
229234
230235 if let Some ( decompressed) = decompressed {
231236 bytes = Bytes :: from ( decompressed) ;
0 commit comments