q/Q/BT/ET by data structure
This commit is contained in:
parent
a2628254b8
commit
6bc3ada2b2
|
@ -1777,7 +1777,7 @@ let whingemalformed () =
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
(* Drawing operations. *)
|
(* Drawing operations. *)
|
||||||
let drawops = ref [("main", [])]
|
let drawops = ref [("_MAIN", [])]
|
||||||
|
|
||||||
let startxobj n =
|
let startxobj n =
|
||||||
drawops := (n, [])::!drawops
|
drawops := (n, [])::!drawops
|
||||||
|
@ -1797,17 +1797,27 @@ let endxobj () =
|
||||||
let a, b, c, d = args.xobj_bbox in
|
let a, b, c, d = args.xobj_bbox in
|
||||||
addop (Cpdfdraw.FormXObject (a, b, c, d, n, rev ops))
|
addop (Cpdfdraw.FormXObject (a, b, c, d, n, rev ops))
|
||||||
| [] ->
|
| [] ->
|
||||||
error "too many -endxobj"
|
error "too many -endxobj or -et"
|
||||||
|
|
||||||
let tdeep = ref 0
|
|
||||||
|
|
||||||
let addbt () =
|
let addbt () =
|
||||||
addop Cpdfdraw.BT;
|
drawops := ("_TEXT", [])::!drawops
|
||||||
tdeep +=1
|
|
||||||
|
|
||||||
let addet () =
|
let addet () =
|
||||||
addop Cpdfdraw.ET;
|
match !drawops with
|
||||||
tdeep -=1
|
| ("_TEXT", ops)::t ->
|
||||||
|
drawops := t;
|
||||||
|
addop (Cpdfdraw.TextSection (rev ops))
|
||||||
|
| _ -> error "not in a text section at -et"
|
||||||
|
|
||||||
|
let push () =
|
||||||
|
drawops := ("_PUSH", [])::!drawops
|
||||||
|
|
||||||
|
let pop () =
|
||||||
|
match !drawops with
|
||||||
|
| ("_PUSH", ops)::t ->
|
||||||
|
drawops := t;
|
||||||
|
addop (Cpdfdraw.Qq (rev ops))
|
||||||
|
| _ -> error "not in a Q section at -q"
|
||||||
|
|
||||||
let readfloats s = map float_of_string (String.split_on_char ' ' s)
|
let readfloats s = map float_of_string (String.split_on_char ' ' s)
|
||||||
|
|
||||||
|
@ -1922,11 +1932,6 @@ let setdash s =
|
||||||
with
|
with
|
||||||
_ -> error "Dash pattern elements must one or more numbers"
|
_ -> error "Dash pattern elements must one or more numbers"
|
||||||
|
|
||||||
let push () =
|
|
||||||
addop Cpdfdraw.Push
|
|
||||||
|
|
||||||
let pop () =
|
|
||||||
addop Cpdfdraw.Pop
|
|
||||||
|
|
||||||
let setmatrix s =
|
let setmatrix s =
|
||||||
match readfloats s with
|
match readfloats s with
|
||||||
|
@ -4460,10 +4465,9 @@ let go () =
|
||||||
let w = (float rawwidth *. args.fontsize) /. 1000. in
|
let w = (float rawwidth *. args.fontsize) /. 1000. in
|
||||||
Printf.printf "%f\n" w
|
Printf.printf "%f\n" w
|
||||||
| Some Draw ->
|
| Some Draw ->
|
||||||
if !tdeep <> 0 then error "Unmatched -bt / -et" else
|
|
||||||
let pdf = get_single_pdf args.op false in
|
let pdf = get_single_pdf args.op false in
|
||||||
let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in
|
let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in
|
||||||
let ops = match !drawops with [("main", ops)] -> rev ops | _ -> error "not enough -endxobj" in
|
let ops = match !drawops with [("_MAIN", ops)] -> rev ops | _ -> error "not enough -endxobj or -et" in
|
||||||
write_pdf
|
write_pdf
|
||||||
false
|
false
|
||||||
(Cpdfdraw.draw ~filename:args.original_filename ~bates:args.bates ~batespad:args.batespad args.fast range pdf ops)
|
(Cpdfdraw.draw ~filename:args.original_filename ~bates:args.bates ~batespad:args.batespad args.fast range pdf ops)
|
||||||
|
|
12
cpdfdraw.ml
12
cpdfdraw.ml
|
@ -20,8 +20,7 @@ type drawops =
|
||||||
| SetMiterLimit of float
|
| SetMiterLimit of float
|
||||||
| SetDashPattern of float list * float
|
| SetDashPattern of float list * float
|
||||||
| Matrix of Pdftransform.transform_matrix
|
| Matrix of Pdftransform.transform_matrix
|
||||||
| Push
|
| Qq of drawops list
|
||||||
| Pop
|
|
||||||
| Fill
|
| Fill
|
||||||
| FillEvenOdd
|
| FillEvenOdd
|
||||||
| Stroke
|
| Stroke
|
||||||
|
@ -37,8 +36,7 @@ type drawops =
|
||||||
| Opacity of float
|
| Opacity of float
|
||||||
| SOpacity of float
|
| SOpacity of float
|
||||||
| Font of Pdftext.standard_font * float
|
| Font of Pdftext.standard_font * float
|
||||||
| BT
|
| TextSection of drawops list
|
||||||
| ET
|
|
||||||
| Text of string
|
| Text of string
|
||||||
| SpecialText of string
|
| SpecialText of string
|
||||||
| Newline
|
| Newline
|
||||||
|
@ -146,8 +144,7 @@ let update_resources pdf old_resources =
|
||||||
(Pdf.Dictionary new_fonts)
|
(Pdf.Dictionary new_fonts)
|
||||||
|
|
||||||
let rec ops_of_drawop pdf endpage filename bates batespad num page = function
|
let rec ops_of_drawop pdf endpage filename bates batespad num page = function
|
||||||
| Push -> [Pdfops.Op_q]
|
| Qq ops -> [Pdfops.Op_q] @ ops_of_drawops pdf endpage filename bates batespad num page ops @ [Pdfops.Op_Q]
|
||||||
| Pop -> [Pdfops.Op_Q]
|
|
||||||
| Matrix m -> [Pdfops.Op_cm m]
|
| Matrix m -> [Pdfops.Op_cm m]
|
||||||
| Rect (x, y, w, h) -> [Pdfops.Op_re (x, y, w, h)]
|
| Rect (x, y, w, h) -> [Pdfops.Op_re (x, y, w, h)]
|
||||||
| Bezier (a, b, c, d, e, f) -> [Pdfops.Op_c (a, b, c, d, e, f)]
|
| Bezier (a, b, c, d, e, f) -> [Pdfops.Op_c (a, b, c, d, e, f)]
|
||||||
|
@ -208,8 +205,7 @@ let rec ops_of_drawop pdf endpage filename bates batespad num page = function
|
||||||
(res ()).current_font <- font;
|
(res ()).current_font <- font;
|
||||||
(res ()).page_names <- n::(res ()).page_names;
|
(res ()).page_names <- n::(res ()).page_names;
|
||||||
[Pdfops.Op_Tf (n, f)]
|
[Pdfops.Op_Tf (n, f)]
|
||||||
| BT -> [Pdfops.Op_BT]
|
| TextSection ops -> [Pdfops.Op_BT] @ ops_of_drawops pdf endpage filename bates batespad num page ops @ [Pdfops.Op_ET]
|
||||||
| ET -> [Pdfops.Op_ET]
|
|
||||||
| Text s -> [Pdfops.Op_Tj (charcodes_of_utf8 s)]
|
| Text s -> [Pdfops.Op_Tj (charcodes_of_utf8 s)]
|
||||||
| SpecialText s ->
|
| SpecialText s ->
|
||||||
let s = process_specials pdf endpage filename bates batespad num page s in
|
let s = process_specials pdf endpage filename bates batespad num page s in
|
||||||
|
|
|
@ -18,8 +18,7 @@ type drawops =
|
||||||
| SetMiterLimit of float
|
| SetMiterLimit of float
|
||||||
| SetDashPattern of float list * float
|
| SetDashPattern of float list * float
|
||||||
| Matrix of Pdftransform.transform_matrix
|
| Matrix of Pdftransform.transform_matrix
|
||||||
| Push
|
| Qq of drawops list
|
||||||
| Pop
|
|
||||||
| Fill
|
| Fill
|
||||||
| FillEvenOdd
|
| FillEvenOdd
|
||||||
| Stroke
|
| Stroke
|
||||||
|
@ -35,8 +34,7 @@ type drawops =
|
||||||
| Opacity of float
|
| Opacity of float
|
||||||
| SOpacity of float
|
| SOpacity of float
|
||||||
| Font of Pdftext.standard_font * float
|
| Font of Pdftext.standard_font * float
|
||||||
| BT
|
| TextSection of drawops list
|
||||||
| ET
|
|
||||||
| Text of string
|
| Text of string
|
||||||
| SpecialText of string
|
| SpecialText of string
|
||||||
| Newline
|
| Newline
|
||||||
|
|
|
@ -140,7 +140,8 @@ let impose_pages fit x y columns rtl btt center margin output_mediabox fast fit_
|
||||||
[Pdfops.stream_of_ops [Pdfops.Op_q; Pdfops.Op_cm transform]] @ contents @ [Pdfops.stream_of_ops [Pdfops.Op_Q]]
|
[Pdfops.stream_of_ops [Pdfops.Op_q; Pdfops.Op_cm transform]] @ contents @ [Pdfops.stream_of_ops [Pdfops.Op_Q]]
|
||||||
else
|
else
|
||||||
(* If slow, use protect from Pdfpage. *)
|
(* If slow, use protect from Pdfpage. *)
|
||||||
let ops = Pdfpage.protect pdf resources' contents @ Pdfops.parse_operators pdf resources' contents in
|
let ours = Pdfops.parse_operators pdf resources' contents in
|
||||||
|
let ops = Pdfpage.protect ours @ ours in
|
||||||
[Pdfops.stream_of_ops ([Pdfops.Op_q] @ [Pdfops.Op_cm transform] @ ops @ [Pdfops.Op_Q])]
|
[Pdfops.stream_of_ops ([Pdfops.Op_q] @ [Pdfops.Op_cm transform] @ ops @ [Pdfops.Op_Q])]
|
||||||
in
|
in
|
||||||
flatten
|
flatten
|
||||||
|
|
Loading…
Reference in New Issue