Xobjects were being processed multiple times in squeeze

This commit is contained in:
John Whitington 2023-02-01 14:52:39 +00:00
parent 8ae103ade7
commit 214e3c3fa2

View File

@ -89,35 +89,38 @@ the page tree!) are also needed - we must merge them with the ones from the
xobject itself. However, it it safe for now -- in the unlikely event that the xobject itself. However, it it safe for now -- in the unlikely event that the
resources actually need to be available, the parse will fail, the squeeze of resources actually need to be available, the parse will fail, the squeeze of
this object will fail, and we bail out. *) this object will fail, and we bail out. *)
(* FIXME: XObjects inside xobjects? *)
let xobjects_done = ref [] let xobjects_done = ref []
let squeeze_form_xobject pdf objnum = let squeeze_form_xobject pdf objnum =
if mem objnum !xobjects_done then () else if mem objnum !xobjects_done then () else
xobjects_done := objnum :: !xobjects_done; begin
let obj = Pdf.lookup_obj pdf objnum in xobjects_done := objnum :: !xobjects_done;
match Pdf.lookup_direct pdf "/Subtype" obj with let obj = Pdf.lookup_obj pdf objnum in
Some (Pdf.Name "/Form") -> match Pdf.lookup_direct pdf "/Subtype" obj with
let resources = Some (Pdf.Name "/Form") ->
match Pdf.lookup_direct pdf "/Resources" obj with let resources =
Some d -> d match Pdf.lookup_direct pdf "/Resources" obj with
| None -> Pdf.Dictionary [] Some d -> d
in | None -> Pdf.Dictionary []
begin match in
Pdfops.stream_of_ops begin match
(Pdfops.parse_operators pdf resources [Pdf.Indirect objnum]) Pdfops.stream_of_ops
with (Pdfops.parse_operators pdf resources [Pdf.Indirect objnum])
Pdf.Stream {contents = (_, Pdf.Got data)} -> with
(* Put replacement data in original stream, and overwrite /Length *) Pdf.Stream {contents = (_, Pdf.Got data)} ->
begin match obj with (* Put replacement data in original stream, and overwrite /Length *)
Pdf.Stream ({contents = (d, _)} as str) -> begin match obj with
str := Pdf.Stream ({contents = (d, _)} as str) ->
(Pdf.add_dict_entry d "/Length" (Pdf.Integer (bytes_size data)), str :=
Pdf.Got data) (Pdf.add_dict_entry d "/Length" (Pdf.Integer (bytes_size data)),
| _ -> failwith "squeeze_form_xobject" Pdf.Got data)
end | _ -> failwith "squeeze_form_xobject"
| _ -> failwith "squeeze_form_xobject" end
end | _ -> failwith "squeeze_form_xobject"
| _ -> () end
| _ -> ()
end
(* For a list of indirects representing content streams, make sure that none of (* For a list of indirects representing content streams, make sure that none of
them are duplicated in the PDF. This indicates sharing, which parsing and them are duplicated in the PDF. This indicates sharing, which parsing and