1- // Copyright 2018 the Tectonic Project
1+ // Copyright 2018-2021 the Tectonic Project
22// Licensed under the MIT License.
33
44//! Parse an XDV/SPX file and dump some stats about its contents.
@@ -66,6 +66,24 @@ impl tectonic_xdv::XdvEvents for Stats {
6666 Ok ( ( ) )
6767 }
6868
69+ fn handle_define_native_font (
70+ & mut self ,
71+ name : & str ,
72+ font_num : i32 ,
73+ size : i32 ,
74+ face_index : u32 ,
75+ color_rgba : Option < u32 > ,
76+ extend : Option < u32 > ,
77+ slant : Option < u32 > ,
78+ embolden : Option < u32 > ,
79+ ) -> Result < ( ) , Self :: Error > {
80+ println ! (
81+ "define native font: `{}` num={} size={} faceIndex={} color={:?} extend={:?} slant={:?} embolden={:?}" ,
82+ name, font_num, size, face_index, color_rgba, extend, slant, embolden
83+ ) ;
84+ Ok ( ( ) )
85+ }
86+
6987 fn handle_begin_page (
7088 & mut self ,
7189 counters : & [ i32 ] ,
@@ -88,10 +106,10 @@ impl tectonic_xdv::XdvEvents for Stats {
88106 Ok ( ( ) )
89107 }
90108
91- fn handle_special ( & mut self , contents : & [ u8 ] ) -> Result < ( ) , Self :: Error > {
109+ fn handle_special ( & mut self , x : i32 , y : i32 , contents : & [ u8 ] ) -> Result < ( ) , Self :: Error > {
92110 match str:: from_utf8 ( contents) {
93111 Ok ( s) => {
94- println ! ( "special: {}" , s) ;
112+ println ! ( "special: {} (@ {},{}) " , s, x , y ) ;
95113 }
96114 Err ( e) => {
97115 println ! ( "cannot UTF8-parse special: {}" , e) ;
@@ -101,20 +119,41 @@ impl tectonic_xdv::XdvEvents for Stats {
101119 Ok ( ( ) )
102120 }
103121
104- fn handle_char_run ( & mut self , chars : & [ i32 ] ) -> Result < ( ) , Self :: Error > {
122+ fn handle_char_run ( & mut self , font_num : i32 , chars : & [ i32 ] ) -> Result < ( ) , Self :: Error > {
105123 let all_ascii_printable = chars. iter ( ) . all ( |c| * c > 0x20 && * c < 0x7F ) ;
106124 println ! (
107- "chars: {:?} all_ascii_printable={:?}" ,
108- chars, all_ascii_printable
125+ "chars font={} : {:?} all_ascii_printable={:?}" ,
126+ font_num , chars, all_ascii_printable
109127 ) ;
110128 Ok ( ( ) )
111129 }
130+
131+ fn handle_glyph_run (
132+ & mut self ,
133+ font_num : i32 ,
134+ glyphs : & [ u16 ] ,
135+ x : & [ i32 ] ,
136+ y : & [ i32 ] ,
137+ ) -> Result < ( ) , Self :: Error > {
138+ println ! ( "glyphs font={}: {:?} (@ {:?}, {:?}" , font_num, glyphs, x, y) ;
139+ Ok ( ( ) )
140+ }
141+
142+ fn handle_rule ( & mut self , x : i32 , y : i32 , height : i32 , width : i32 ) -> Result < ( ) , Self :: Error > {
143+ println ! ( "rule W={} H={} @ {:?}, {:?}" , width, height, x, y) ;
144+ Ok ( ( ) )
145+ }
112146}
113147
114148fn main ( ) {
115149 let matches = App :: new ( "xdvdump" )
116150 . version ( crate_version ! ( ) )
117151 . about ( "Parse an XDV or SPX file and report some stats about its contents" )
152+ . arg (
153+ Arg :: with_name ( "seek" )
154+ . long ( "seek" )
155+ . help ( "Seek around the file, parsing the trailers first" ) ,
156+ )
118157 . arg (
119158 Arg :: with_name ( "PATH" )
120159 . help ( "The path to the XDV or SPX file" )
@@ -137,17 +176,33 @@ fn main() {
137176 }
138177 } ;
139178
140- let ( _stats, n_bytes) = match tectonic_xdv:: XdvParser :: process ( file, Stats :: new ( ) ) {
141- Ok ( x) => x,
142- Err ( e) => {
143- eprintln ! (
144- "error: failed to parse \" {}\" : {}" ,
145- path. to_string_lossy( ) ,
146- e
147- ) ;
148- process:: exit ( 1 ) ;
149- }
150- } ;
179+ if matches. is_present ( "seek" ) {
180+ match tectonic_xdv:: XdvParser :: process_with_seeks ( file, Stats :: new ( ) ) {
181+ Ok ( x) => x,
182+ Err ( e) => {
183+ eprintln ! (
184+ "error: failed to parse \" {}\" : {}" ,
185+ path. to_string_lossy( ) ,
186+ e
187+ ) ;
188+ process:: exit ( 1 ) ;
189+ }
190+ } ;
191+
192+ println ! ( "Finished parsing the file." ) ;
193+ } else {
194+ let ( _stats, n_bytes) = match tectonic_xdv:: XdvParser :: process ( file, Stats :: new ( ) ) {
195+ Ok ( x) => x,
196+ Err ( e) => {
197+ eprintln ! (
198+ "error: failed to parse \" {}\" : {}" ,
199+ path. to_string_lossy( ) ,
200+ e
201+ ) ;
202+ process:: exit ( 1 ) ;
203+ }
204+ } ;
151205
152- println ! ( "{} bytes parsed." , n_bytes) ;
206+ println ! ( "{} bytes parsed." , n_bytes) ;
207+ }
153208}
0 commit comments