Squeeze now doesn't do too much work on duplicate references to xobjects
This commit is contained in:
parent
9a2ccc39e0
commit
6bb8715f23
8
cpdf.ml
8
cpdf.ml
|
@ -104,7 +104,11 @@ let really_squeeze pdf =
|
||||||
(* Squeeze the form xobject at objnum. FIXME: For old PDFs (< v1.2) any
|
(* Squeeze the form xobject at objnum. FIXME: For old PDFs (< v1.2) any
|
||||||
resources from the page (or its ancestors in the page tree!) are also needed -
|
resources from the page (or its ancestors in the page tree!) are also needed -
|
||||||
we must merge them with the ones from the xobject itself. *)
|
we must merge them with the ones from the xobject itself. *)
|
||||||
|
let xobjects_done = ref []
|
||||||
|
|
||||||
let squeeze_form_xobject pdf objnum =
|
let squeeze_form_xobject pdf objnum =
|
||||||
|
if mem objnum !xobjects_done then () else
|
||||||
|
xobjects_done := objnum :: !xobjects_done;
|
||||||
let obj = Pdf.lookup_obj pdf objnum in
|
let obj = Pdf.lookup_obj pdf objnum in
|
||||||
match Pdf.lookup_direct pdf "/Subtype" obj with
|
match Pdf.lookup_direct pdf "/Subtype" obj with
|
||||||
Some (Pdf.Name "/Form") ->
|
Some (Pdf.Name "/Form") ->
|
||||||
|
@ -133,6 +137,7 @@ let squeeze_form_xobject pdf objnum =
|
||||||
(* For each object in the PDF marked with /Type /Page, for each /Contents
|
(* For each object in the PDF marked with /Type /Page, for each /Contents
|
||||||
indirect reference or array of such, decode and recode that content stream. *)
|
indirect reference or array of such, decode and recode that content stream. *)
|
||||||
let squeeze_all_content_streams pdf =
|
let squeeze_all_content_streams pdf =
|
||||||
|
xobjects_done := [];
|
||||||
Pdf.objiter
|
Pdf.objiter
|
||||||
(fun objnum _ ->
|
(fun objnum _ ->
|
||||||
match Pdf.lookup_obj pdf objnum with
|
match Pdf.lookup_obj pdf objnum with
|
||||||
|
@ -165,8 +170,7 @@ let squeeze_all_content_streams pdf =
|
||||||
d "/Contents" (Pdf.Indirect (Pdf.addobj pdf newstream))
|
d "/Contents" (Pdf.Indirect (Pdf.addobj pdf newstream))
|
||||||
in
|
in
|
||||||
Pdf.addobj_given_num pdf (objnum, newdict);
|
Pdf.addobj_given_num pdf (objnum, newdict);
|
||||||
(* Now process all xobjects related to this page
|
(* Now process all xobjects related to this page *)
|
||||||
FIXME due to their shared nature, we are overdoing this work! *)
|
|
||||||
begin match Pdf.lookup_direct pdf "/XObject" resources with
|
begin match Pdf.lookup_direct pdf "/XObject" resources with
|
||||||
Some (Pdf.Dictionary xobjs) ->
|
Some (Pdf.Dictionary xobjs) ->
|
||||||
iter
|
iter
|
||||||
|
|
Loading…
Reference in New Issue