@@ -21,6 +21,7 @@ function equalTrees(rootA, rootB) {
2121 expect ( a . role ) . toEqual ( b . role ) ;
2222 expect ( a . lang ) . toEqual ( b . lang ) ;
2323 expect ( a . type ) . toEqual ( b . type ) ;
24+ expect ( a . mathML ) . toEqual ( b . mathML ) ;
2425 expect ( "children" in a ) . toEqual ( "children" in b ) ;
2526 if ( ! a . children ) {
2627 return ;
@@ -151,4 +152,154 @@ describe("struct tree", function () {
151152 ) ;
152153 await loadingTask . destroy ( ) ;
153154 } ) ;
155+
156+ it ( "parses structure with some MathML in AF dictionary" , async function ( ) {
157+ const filename = "bug1937438_af_from_latex.pdf" ;
158+ const params = buildGetDocumentParams ( filename ) ;
159+ const loadingTask = getDocument ( params ) ;
160+ const doc = await loadingTask . promise ;
161+ const page = await doc . getPage ( 1 ) ;
162+ const struct = await page . getStructTree ( ) ;
163+ equalTrees (
164+ {
165+ children : [
166+ {
167+ role : "Document" ,
168+ children : [
169+ {
170+ role : "Part" ,
171+ children : [
172+ {
173+ role : "P" ,
174+ children : [
175+ {
176+ role : "P" ,
177+ children : [ { type : "content" , id : "p58R_mc0" } ] ,
178+ } ,
179+ ] ,
180+ } ,
181+ {
182+ role : "P" ,
183+ children : [ { type : "content" , id : "p58R_mc1" } ] ,
184+ } ,
185+ {
186+ role : "P" ,
187+ children : [ { type : "content" , id : "p58R_mc2" } ] ,
188+ } ,
189+ ] ,
190+ } ,
191+ {
192+ role : "Sect" ,
193+ children : [
194+ {
195+ role : "H1" ,
196+ children : [
197+ {
198+ role : "Lbl" ,
199+ children : [ { type : "content" , id : "p58R_mc3" } ] ,
200+ } ,
201+ { type : "content" , id : "p58R_mc4" } ,
202+ ] ,
203+ } ,
204+ {
205+ role : "Part" ,
206+ children : [
207+ {
208+ role : "P" ,
209+ children : [
210+ { type : "content" , id : "p58R_mc5" } ,
211+ {
212+ role : "Formula" ,
213+ children : [ { type : "content" , id : "p58R_mc6" } ] ,
214+ mathML : "<math> <mi>x</mi> </math>" ,
215+ } ,
216+ { type : "content" , id : "p58R_mc7" } ,
217+ {
218+ role : "Formula" ,
219+ children : [ { type : "content" , id : "p58R_mc8" } ] ,
220+ mathML : "<math> <mi>y</mi> </math>" ,
221+ } ,
222+ { type : "content" , id : "p58R_mc9" } ,
223+ {
224+ role : "Formula" ,
225+ children : [ { type : "content" , id : "p58R_mc10" } ] ,
226+ mathML :
227+ "<math> <mi>x</mi> <mo>></mo> <mi>y</mi> </math>" ,
228+ } ,
229+ { type : "content" , id : "p58R_mc11" } ,
230+ ] ,
231+ } ,
232+ ] ,
233+ } ,
234+ {
235+ role : "Part" ,
236+ children : [
237+ {
238+ role : "P" ,
239+ children : [ { type : "content" , id : "p58R_mc12" } ] ,
240+ } ,
241+ {
242+ role : "Formula" ,
243+ children : [ { type : "content" , id : "p58R_mc13" } ] ,
244+ mathML :
245+ '<math> <msqrt><msup><mi>x</mi><mn>2</mn></msup></msqrt> <mo>=</mo> <mrow intent="absolute-value($x)"><mo>|</mo><mi arg="x">x</mi><mo>|</mo></mrow> </math>' ,
246+ } ,
247+ ] ,
248+ } ,
249+ ] ,
250+ } ,
251+ ] ,
252+ } ,
253+ ] ,
254+ role : "Root" ,
255+ } ,
256+ struct
257+ ) ;
258+ await loadingTask . destroy ( ) ;
259+ } ) ;
260+
261+ it ( "parses structure with some MathML in MS Office specific entry" , async function ( ) {
262+ const filename = "bug1937438_from_word.pdf" ;
263+ const params = buildGetDocumentParams ( filename ) ;
264+ const loadingTask = getDocument ( params ) ;
265+ const doc = await loadingTask . promise ;
266+ const page = await doc . getPage ( 1 ) ;
267+ const struct = await page . getStructTree ( ) ;
268+ equalTrees (
269+ {
270+ children : [
271+ {
272+ role : "Document" ,
273+ children : [
274+ {
275+ role : "P" ,
276+ children : [
277+ { type : "content" , id : "p3R_mc0" } ,
278+ {
279+ role : "Formula" ,
280+ children : [ { type : "content" , id : "p3R_mc1" } ] ,
281+ alt : "pi" ,
282+ mathML : '<math display="block"><mi>𝜋</mi></math>' ,
283+ } ,
284+ { type : "content" , id : "p3R_mc2" } ,
285+ ] ,
286+ } ,
287+ {
288+ role : "Formula" ,
289+ children : [ { type : "content" , id : "p3R_mc3" } ] ,
290+ alt : "6 sum from n equals 1 to infinity of 1 over n squared , equals pi squared" ,
291+ mathML :
292+ '<math display="block"><mn>6</mn><mrow><munderover><mo stretchy="false">∑</mo><mrow><mi>n</mi><mo>=</mo><mn>1</mn></mrow><mo>∞</mo></munderover><mfrac><mn>1</mn><msup><mrow><mi>n</mi></mrow><mn>2</mn></msup></mfrac></mrow><mo>=</mo><msup><mrow><mi>𝜋</mi></mrow><mn>2</mn></msup></math>' ,
293+ } ,
294+ { role : "P" , children : [ { type : "content" , id : "p3R_mc4" } ] } ,
295+ { role : "P" , children : [ { type : "content" , id : "p3R_mc5" } ] } ,
296+ ] ,
297+ } ,
298+ ] ,
299+ role : "Root" ,
300+ } ,
301+ struct
302+ ) ;
303+ await loadingTask . destroy ( ) ;
304+ } ) ;
154305} ) ;
0 commit comments