mirror of
https://github.com/johnwhitington/cpdf-source.git
synced 2025-02-09 08:28:52 +01:00
Wrote new implementation of 'protect'
This commit is contained in:
parent
849a41f5a1
commit
f7bdca371b
36
cpdf.ml
36
cpdf.ml
@ -573,16 +573,22 @@ let map_pages f pdf range =
|
|||||||
(ilist 1 (length pages))
|
(ilist 1 (length pages))
|
||||||
pages
|
pages
|
||||||
|
|
||||||
(* Add stack operators to a content stream to ensure it is composeable. FIXME:
|
(* Add stack operators to a content stream to ensure it is composeable. On
|
||||||
* This is only used for non-fast, and it blows up shared streams. Fix place
|
-fast, we don't check for Q deficit, assuming PDF is ISO. *)
|
||||||
* which use this not to blow up, and remove this code. *)
|
let protect fast pdf resources content =
|
||||||
let protect_removeme pdf resources content =
|
let deficit =
|
||||||
|
if fast then 0 else
|
||||||
let ops = Pdfops.parse_operators pdf resources content in
|
let ops = Pdfops.parse_operators pdf resources content in
|
||||||
let qs = length (keep (eq Pdfops.Op_q) ops)
|
let qs = length (keep (eq Pdfops.Op_q) ops) in
|
||||||
and bigqs = length (keep (eq Pdfops.Op_Q) ops) in
|
let bigqs = length (keep (eq Pdfops.Op_Q) ops) in
|
||||||
let deficit = if qs > bigqs then qs - bigqs else 0 in
|
let deficit = if qs > bigqs then qs - bigqs else 0 in
|
||||||
if deficit <> 0 then Printf.eprintf "Q Deficit was nonzero. Fixing. %i\n" deficit;
|
if deficit <> 0 then Printf.eprintf "Q Deficit was nonzero. Fixing. %i\n" deficit;
|
||||||
Pdfops.stream_of_ops ([Pdfops.Op_q] @ ops @ many Pdfops.Op_Q deficit @ [Pdfops.Op_Q])
|
deficit
|
||||||
|
in
|
||||||
|
let addstream ops = Pdf.addobj pdf (Pdfops.stream_of_ops ops) in
|
||||||
|
let q = addstream [Pdfops.Op_q] in
|
||||||
|
let qs = addstream (many Pdfops.Op_Q deficit @ [Pdfops.Op_Q]) in
|
||||||
|
[Pdf.Indirect q] @ content @ [Pdf.Indirect qs]
|
||||||
|
|
||||||
exception SoftError of string
|
exception SoftError of string
|
||||||
|
|
||||||
@ -2181,14 +2187,10 @@ let do_stamp relative_to_cropbox fast position topline midline scale_to_fit isov
|
|||||||
(if relative_to_cropbox then [Pdftransform.Translate (txmin, tymin)] else []) @
|
(if relative_to_cropbox then [Pdftransform.Translate (txmin, tymin)] else []) @
|
||||||
[Pdftransform.Scale ((sxmin, symin), scale, scale)]))
|
[Pdftransform.Scale ((sxmin, symin), scale, scale)]))
|
||||||
in
|
in
|
||||||
(* NOTE: This shares on -fast, because prepend_operators shares.
|
|
||||||
On slow, it breaks sharing *)
|
|
||||||
Pdfpage.prepend_operators pdf [scale_op] ~fast o
|
Pdfpage.prepend_operators pdf [scale_op] ~fast o
|
||||||
else
|
else
|
||||||
let sw = sxmax -. sxmin
|
let sw = sxmax -. sxmin and sh = symax -. symin
|
||||||
and sh = symax -. symin
|
and w = txmax -. txmin and h = tymax -. tymin in
|
||||||
and w = txmax -. txmin
|
|
||||||
and h = tymax -. tymin in
|
|
||||||
let dx, dy = stamp_shift_of_position topline midline sw sh w h position in
|
let dx, dy = stamp_shift_of_position topline midline sw sh w h position in
|
||||||
let translate_op =
|
let translate_op =
|
||||||
Pdfops.Op_cm
|
Pdfops.Op_cm
|
||||||
@ -2196,17 +2198,13 @@ let do_stamp relative_to_cropbox fast position topline midline scale_to_fit isov
|
|||||||
((if relative_to_cropbox then [Pdftransform.Translate (txmin, tymin)] else []) @
|
((if relative_to_cropbox then [Pdftransform.Translate (txmin, tymin)] else []) @
|
||||||
[Pdftransform.Translate (dx, dy)]))
|
[Pdftransform.Translate (dx, dy)]))
|
||||||
in
|
in
|
||||||
(* NOTE: This shares on -fast, because prepend_operators shares.
|
|
||||||
On slow, it breaks sharing *)
|
|
||||||
Pdfpage.prepend_operators pdf [translate_op] ~fast o
|
Pdfpage.prepend_operators pdf [translate_op] ~fast o
|
||||||
in
|
in
|
||||||
(* NOTE: On -fast, this is ok. Shares content streams properly. On slow,
|
|
||||||
protect_removeme would break sharing *)
|
|
||||||
{u with
|
{u with
|
||||||
Pdfpage.content =
|
Pdfpage.content =
|
||||||
(if isover then ( @ ) else ( @@ ))
|
(if isover then ( @ ) else ( @@ ))
|
||||||
(if fast then u.Pdfpage.content else [protect_removeme pdf u.Pdfpage.resources u.Pdfpage.content])
|
(protect fast pdf u.Pdfpage.resources u.Pdfpage.content)
|
||||||
(if fast then o.Pdfpage.content else [protect_removeme pdf o.Pdfpage.resources o.Pdfpage.content]);
|
(protect fast pdf o.Pdfpage.resources o.Pdfpage.content);
|
||||||
Pdfpage.resources =
|
Pdfpage.resources =
|
||||||
combine_pdf_resources pdf u.Pdfpage.resources o.Pdfpage.resources}
|
combine_pdf_resources pdf u.Pdfpage.resources o.Pdfpage.resources}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ let demo = false
|
|||||||
let noncomp = false
|
let noncomp = false
|
||||||
let major_version = 2
|
let major_version = 2
|
||||||
let minor_version = 2
|
let minor_version = 2
|
||||||
let version_date = "(build of 25th March 2016)"
|
let version_date = "(build of 3rd April 2016)"
|
||||||
|
|
||||||
open Pdfutil
|
open Pdfutil
|
||||||
open Pdfio
|
open Pdfio
|
||||||
|
Loading…
x
Reference in New Issue
Block a user