Removal or commenting of unused code

This commit is contained in:
John Whitington 2024-02-23 16:17:12 +00:00
parent e305db72f5
commit 24c8b63808
15 changed files with 19 additions and 245 deletions

View File

@ -23,12 +23,6 @@ let charcodes_of_utf8 font s =
in
implode (map char_of_int charcodes)
let unicode_codepoint_of_pdfcode encoding_table glyphlist_table p =
try
hd (Hashtbl.find glyphlist_table (Hashtbl.find encoding_table p))
with
Not_found -> 0
(* Get the width of some text in the given font *)
let width_of_text font text =
match font with
@ -121,33 +115,6 @@ let extract_num header s =
| [Pdfgenlex.LexReal f] -> Pdf.Real f
| _ -> raise (Failure ("extract_num: " ^ s))
let extract_fontbbox header s =
let num = function
Pdfgenlex.LexInt i -> Pdf.Integer i
| Pdfgenlex.LexReal f -> Pdf.Real f
| _ -> raise (Failure "extract_fontbbox")
in
match Pdfgenlex.lex_string (Hashtbl.find header s) with
[a; b; c; d] -> [num a; num b; num c; num d]
| _ -> raise (Failure "extract_fontbbox")
let remove_slash s =
match explode s with
'/'::x -> implode x
| _ -> raise (Failure "remove_slash")
let extract_widths chars_and_widths =
let win_to_name = map (fun (x, y) -> (y, x)) Pdfglyphlist.name_to_win in
map
(fun x ->
try
let name = List.assoc x win_to_name in
let width = List.assoc (remove_slash name) chars_and_widths in
width
with
_ -> 0)
(ilist 0 255)
(* For finding the height for URL links, we try to find the Cap Height for the
font. We fall back to using the font size alone if we cannot get the cap
height. *)

View File

@ -1,17 +1,6 @@
open Pdfutil
open Cpdferror
(* Add bookmarks *)
let read_lines input =
let lines = ref [] in
try
while true do
let c = read_line input in
lines =| c
done; []
with
_ -> rev !lines
(* Verify a list of bookmarks. Positive jumps of > 1 not allowed, no numbers
smaller than 0. *)
let rec verify_bookmarks pdf lastlevel fastrefnums endpage = function
@ -41,9 +30,6 @@ let rec fixup_characters prev = function
| '\\'::'n'::t -> fixup_characters ('\n'::prev) t
| h::t -> fixup_characters (h::prev) t
let debug_bookmark_string s =
Printf.printf "STR: %s\n" s
(* If optionaldest = [Pdfgenlex.LexString s], we parse the string, convert the
* integer to an indirect of the real page target, and then put it in. *)
let target_of_markfile_obj pdf i' pdfobj =
@ -68,6 +54,9 @@ let target_of_markfile_target pdf i' = function
target_of_markfile_obj pdf i' pdfobj
| _ -> Pdfpage.target_of_pagenumber pdf i'
(*let debug_bookmark_string s =
Printf.printf "STR: %s\n" s*)
let bookmark_of_data pdf i s i' isopen optionaldest =
(*debug_bookmark_string s;
debug_bookmark_string (implode (fixup_characters [] (explode s)));
@ -267,31 +256,6 @@ let get_bookmarks_json pdf =
list_bookmarks ~json:true Cpdfmetadata.UTF8 (ilist 1 (Pdfpage.endpage pdf)) pdf o;
Pdfio.extract_bytes_from_input_output o br
(* Split at bookmarks *)
let get_bookmark_name pdf marks splitlevel n _ =
let refnums = Pdf.page_reference_numbers pdf in
let fastrefnums = hashtable_of_dictionary (combine refnums (indx refnums)) in
match keep (function m -> n = Pdfpage.pagenumber_of_target ~fastrefnums pdf m.Pdfmarks.target && m.Pdfmarks.level <= splitlevel) marks with
| {Pdfmarks.text = title}::_ -> Cpdfattach.remove_unsafe_characters Cpdfmetadata.UTF8 title
| _ -> ""
(* Return list, in order, a *set* of page numbers of bookmarks at a given level *)
let bookmark_pages level pdf =
let refnums = Pdf.page_reference_numbers pdf in
let fastrefnums = hashtable_of_dictionary (combine refnums (indx refnums)) in
setify_preserving_order
(option_map
(function l when l.Pdfmarks.level = level -> Some (Pdfpage.pagenumber_of_target ~fastrefnums pdf l.Pdfmarks.target) | _ -> None)
(Pdfmarks.read_bookmarks pdf))
(* Called from cpdflib.ml - different from above *)
let split_on_bookmarks pdf level =
let points = lose (eq 0) (map pred (bookmark_pages level pdf))
in let pdf_pages = Pdfpage.pages_of_pagetree pdf in
let ranges = splitat points (indx pdf_pages) in
map (fun rs -> Pdfpage.pdf_of_pages pdf rs) ranges
let get_bookmark_name encoding pdf marks splitlevel n _ =
let refnums = Pdf.page_reference_numbers pdf in
let fastrefnums = hashtable_of_dictionary (combine refnums (indx refnums)) in

View File

@ -23,7 +23,6 @@ let null () = ()
let initial_file_size = ref 0
let empty = Pdf.empty ()
let emptypage = Pdfpage.blankpage Pdfpaper.a4
let fontnames =
[(Pdftext.TimesRoman, ["NimbusRoman-Regular.ttf"]);
@ -1345,11 +1344,6 @@ let setbatesrange n =
in
args.bates <- n + 1 - first_page
let setpagerotation r =
match r with
| 90 | 270 -> args.pagerotation <- r
| _ -> error "Bad Page rotation. Try 90 or 270."
let set_input s =
args.original_filename <- s;
args.inputs <- (InFile s, "all", "", "", ref false, None)::args.inputs
@ -1692,15 +1686,6 @@ let setidironlypdfs () =
let setnowarnrotate () =
args.no_warn_rotate <- true
(* Unused for now *)
let setfontttfencoding s =
args.fontencoding <-
match s with
| "MacRomanEncoding" -> Pdftext.MacRomanEncoding
| "WinAnsiEncoding" -> Pdftext.WinAnsiEncoding
| "StandardEncoding" -> Pdftext.StandardEncoding
| _ -> error "Unknown encoding"
let whingemalformed () =
Pdfe.log "Command line must be of exactly the form\ncpdf <infile> -gs <path> -gs-malformed-force -o <outfile>\n";
exit 1
@ -2970,9 +2955,6 @@ let rec get_single_pdf ?(decrypt=true) ?(fail=false) op read_lazy =
| _ ->
raise (Arg.Bad "cpdf: No input specified.\n")
let get_single_pdf_nodecrypt read_lazy =
get_single_pdf ~decrypt:false None read_lazy
let filenames = null_hash ()
let squeeze_logto filename x =
@ -3333,19 +3315,6 @@ let getencryption pdf =
| Some (Pdfwrite.AES256bitISO true) -> "256bit AES ISO, Metadata encrypted"
| Some (Pdfwrite.AES256bitISO false) -> "256bit AES ISO, Metadata not encrypted"
(* If pages in stamp < pages in main, extend stamp by repeating its last page. If pages in stamp more, chop stamp *)
let equalize_pages_extend main stamp =
let length_stamp = Pdfpage.endpage stamp
in let length_main = Pdfpage.endpage main
in let extend_lastpage lastpage page len =
Pdfpage.change_pages true page (Pdfpage.pages_of_pagetree page @ (many lastpage len))
in let chop pdf n =
Pdfpage.change_pages true pdf (take (Pdfpage.pages_of_pagetree pdf) n)
in
if length_stamp > length_main
then chop stamp length_main
else extend_lastpage (last (Pdfpage.pages_of_pagetree stamp)) stamp (length_main - length_stamp)
let write_json output pdf =
match output with
| NoOutputSpecified ->

View File

@ -51,7 +51,7 @@ type drawops =
| RenderMode of int
| Rise of float
let rec string_of_drawop = function
(*let rec string_of_drawop = function
| Qq o -> "Qq (" ^ string_of_drawops o ^ ")"
| FormXObject (_, _, _, _, _, o) -> "FormXObject (" ^ string_of_drawops o ^ ")"
| TextSection o -> "TextSection (" ^ string_of_drawops o ^ ")"
@ -72,7 +72,7 @@ let rec string_of_drawop = function
| RenderMode _ -> "RenderMode" | Rise _ -> "Rise"
and string_of_drawops l =
fold_left (fun x y -> x ^ " " ^ y) "" (map string_of_drawop l)
fold_left (fun x y -> x ^ " " ^ y) "" (map string_of_drawop l)*)
(* Per page / xobject resources *)
type res =

View File

@ -313,7 +313,7 @@ let bytes_of_xmltree t =
Cpdfxmlm.output_doc_tree frag o t;
bytes_of_string (Buffer.contents buf)
let rec string_of_xmltree = function
(*let rec string_of_xmltree = function
D d ->
Printf.sprintf "DATA {%s}" d
| E (tag, trees) ->
@ -335,7 +335,7 @@ and string_of_attributes attrs =
and string_of_xmltrees trees =
fold_left
(fun a b -> a ^ " " ^ b) "" (map string_of_xmltree trees)
(fun a b -> a ^ " " ^ b) "" (map string_of_xmltree trees)*)
let adobe = "http://ns.adobe.com/pdf/1.3/"
let xmp = "http://ns.adobe.com/xap/1.0/"

View File

@ -23,9 +23,6 @@ let rec insert_after_many_changes isbefore padsize offset range = function
else
item::insert_after_many_changes isbefore padsize offset range t
let print_changes =
iter (fun (f, t) -> Printf.printf "%i --> %i\n" f t)
let pad_with_pdf (range : int list) (pdf : Pdf.t) (isbefore : bool) (padfile : Pdf.t) =
let range = sort compare (setify range) in
let merged =

View File

@ -260,5 +260,5 @@ let string_of_pagespec pdf = function
in
fold_left ( ^ ) "" (interleave "," rangestrings)
let string_of_range r =
fold_left (fun a b -> a ^ " " ^ b) "" (map string_of_int r)
(*let string_of_range r =
fold_left (fun a b -> a ^ " " ^ b) "" (map string_of_int r)*)

View File

@ -13,7 +13,7 @@ type t =
idat : bytes}
(* Writing *)
let tbl =
(*let tbl =
ref ([||] : int32 array)
let mktbl () =
@ -80,7 +80,7 @@ let write_png png o =
Bytes.set ihdr 12 (char_of_int 0); (* interlace method *)
write_chunk o "IHDR" ihdr;
write_chunk o "IDAT" (Bytes.unsafe_of_string (string_of_bytes png.idat));
write_chunk o "IEND" (Bytes.create 0)
write_chunk o "IEND" (Bytes.create 0)*)
(* Reading *)
let string_of_tag t =

View File

@ -1,4 +1,4 @@
(* \chaptertitle{Shapes}{Stroking lines and making shapes} *)
(* Stroking lines and making shapes *)
(* This module provides for the stroking of lines, and production of shape
primitives (circles, regular polygons etc). *)
@ -30,22 +30,6 @@ control lines when approximating quarter arcs to make semicircles and circles.
*)
let kappa = ((sqrt 2. -. 1.) /. 3.) *. 4.
(* Calculate rotation from [p] to [p'] about [c] with the shorter arc-length.
When arc-lengths are equal, the result may be either. *)
let rotation (cx, cy) (px, py) (px', py') =
let px = px -. cx and py = py -. cy
and px' = px' -. cx and py' = py' -. cy in
let a = px *. py' -. py *. px'
and b = px *. px' +. py *. py' in
atan2 a b
(* The absolute angle to a point [p] from a centre [c]. The angle is the
rotation clockwise (i.e the first quadrant encountered has positive [x] and [y]
values) from East. When the point is [(0, 0)], the result is [0].*)
let angle_to (cx, cy) (px, py) =
let r = atan2 (py -. cy) (px -. cx) in
if r < 0. then r +. 2. *. pi else r
(* Restrict an angle [a] to one of those at $s, 2s, 3s\ldots$. We find the two
candidate angles, and see which [a] is numerically closer to. The candidate
points are taken modulo $2\pi$ for this to work. *)
@ -54,7 +38,7 @@ let restrict_angle s a =
let p' = mod_float (p +. s) (2. *. pi) in
if abs_float (p -. a) < abs_float (p' -. a) then p else p'
(* \section{Some Useful Shapes} *)
(* Some Useful Shapes *)
(* Make a quarter-circle from a single bezier curve from [s] to $(s + \pi / 2)
\bmod 2\pi$ with centre [c] and radius [r]. We cheat by making the standard
@ -74,12 +58,6 @@ let quarter s (cx, cy) r =
| [p; q; r; s] -> Bezier(p, q, r, s)
| _ -> raise (Pdf.PDFError ("Shapes.quarter: inconsistency"))
(* The anticlockwise variant. *)
let quarter_anticlockwise s c r =
match quarter s c r with
| Bezier(p, q, r, s) -> Bezier(s, r, q, p)
| _ -> raise (Pdf.PDFError "Shapes.quarter_anticlockwise: inconsistency")
(* Some of the following functions generate what is supposed to be a connected
list of segments. However, since they operate by calculating each segment
seperately, floating point inaccuracies can arise, making the end of one
@ -94,56 +72,6 @@ let rec joinsegs segments =
s::joinsegs (Bezier(d, b', c', d')::rest)
| _ -> raise (Pdf.PDFError "PDFShapes.joinsegs: Segment not supported")
(* This version sets the start and end points to p1 and p2 respectively. Used
for ensuring round joins join correctly to the rails they connect *)
let joinsegs_ends p1 p2 segments =
match joinsegs segments with
| [] -> []
| [Bezier(a, b, c, d)] -> [Bezier(p1, b, c, p2)]
| segs ->
match extremes_and_middle segs with
| Bezier(_, b, c, d), m, Bezier(a', b', c', _) ->
Bezier(p1, b, c, d)::m @ [Bezier(a', b', c', p2)]
| _ -> raise (Pdf.PDFError "PDFShapes.joinsegs_ends: Segment not supported")
(* The shorter arc made from bezier curves from [p1] to [p2] with centre [c].
The arc is formed from zero or more quarter arcs rotated accordingly, and at
most one partial arc produced by truncating a quarter arc, again rotated. If
[p1=p2], no segments are produced. If the two curves defined by the arguments
are of equal length, the one chosen is undefined. *)
(*i let arc p1 p2 c =
let ninety = pi /. 2.
and angletogo = rotation c p1 p2 (*r signed angle to turn through *)
and abs_angle = angle_to c p1 (*r absolute angle to the first point *)
and r = distance_between p1 c in (*r radius of the resultant arc *)
let quarter, ninety_abs =
if angletogo > 0.
then quarter, ninety
else quarter_anticlockwise, ~-.ninety
in
let segments = ref []
and angletogo = ref (abs_float angletogo) (*r Have dealt with sign. *)
and abs_angle = ref abs_angle in
while !angletogo > 0. do
if !angletogo >= ninety then
begin
angletogo := !angletogo -. ninety;
segments := (quarter !abs_angle c r)::!segments;
abs_angle := mod_float (!abs_angle +. ninety_abs) (2. *. pi)
end
else
(* Calculate a partial arc to finish, if required. *)
if !angletogo > 0. then
begin
let q = quarter !abs_angle c r in
let portion_needed = !angletogo /. ninety in
let portion, _ = Polygon.bezier_split portion_needed q in
segments := portion::!segments;
angletogo := 0.
end;
done;
joinsegs_ends p1 p2 (rev !segments) i*)
(* Approximate a circle using four bezier curves.*)
let circle x y r =
NonZero,

View File

@ -1,8 +1,5 @@
open Pdfutil
let print_spot_colour n s =
Printf.printf "%i %s\n" n s
let list_spot_colours pdf =
Pdf.objiter
(fun _ obj ->
@ -14,4 +11,3 @@ let list_spot_colours pdf =
end
| _ -> ())
pdf

View File

@ -2,14 +2,14 @@ open Pdfutil
open Pdfio
(* For debugging *)
let report_pdf_size pdf =
(*let report_pdf_size pdf =
Pdf.remove_unreferenced pdf;
Pdfwrite.pdf_to_file_options ~preserve_objstm:false ~generate_objstm:false
~compress_objstm:false None false pdf "temp.pdf";
let fh = open_in_bin "temp.pdf" in
Printf.printf "Size %i bytes\n" (in_channel_length fh);
flush stdout;
close_in fh
close_in fh*)
(* Recompress anything which isn't compressed, unless it's metadata. *)
let recompress_stream pdf = function

View File

@ -111,11 +111,6 @@ let contents_of_file filename =
s
(* Platform-independent current time and date with no Unix module *)
let debug_str s =
for x = 0 to String.length s - 1 do
Printf.printf "%i\t%C\n" x s.[x]
done
let utf8_of_utf16le s =
implode (drop_evens (tl (tl (explode s))))

View File

@ -66,9 +66,9 @@ let read_byte b = getval_31 b 8
let read_short b = sign_extend 16 (getval_31 b 16)
let read_f2dot14 b =
(*let read_f2dot14 b =
let v = read_ushort b in
float_of_int (sign_extend 2 (v lsr 14)) +. (float_of_int (v land 0x3FFF) /. 16384.)
float_of_int (sign_extend 2 (v lsr 14)) +. (float_of_int (v land 0x3FFF) /. 16384.)*)
let discard_bytes b n =
for x = 1 to n do ignore (getval_31 b 8) done
@ -129,7 +129,7 @@ let read_format_4_encoding_table b =
done;
t
let print_encoding_table fmt table =
(*let print_encoding_table fmt table =
let unicodedata = Cpdfunicodedata.unicodedata () in
let unicodetable = Hashtbl.create 16000 in
iter
@ -144,7 +144,7 @@ let print_encoding_table fmt table =
if !dbg then
Printf.printf "Char %s (%s) is at glyph index %i\n"
str (try Hashtbl.find unicodetable str with Not_found -> "Not_found") gi)
l
l*)
let read_encoding_table fmt length version b =
if !dbg then Printf.printf "********** format %i table has length, version %i, %i\n" fmt length version;
@ -375,10 +375,6 @@ let calculate_width_higher unitsPerEm firstchar lastchar subset cmapdata hmtxdat
let calculate_maxwidth unitsPerEm hmtxdata =
pdf_unit unitsPerEm (hd (sort (fun a b -> compare b a) (Array.to_list hmtxdata)))
let fonumr = ref (-1)
let fonum () = fonumr += 1; !fonumr
let subset_font major minor tables indexToLocFormat subset encoding cmap loca mk_b glyfoffset data =
let tables = Array.of_list (sort (fun (_, _, o, _) (_, _, o', _) -> compare o o') tables) in
let tablesout = ref [] in

View File

@ -110,25 +110,6 @@ let rec parse_unicodedata a i =
then rev a
else parse_unicodedata (parse_entry i::a) i
let print_entry e =
Printf.printf
"{{%s;%s;%s;%s;%s;%s;%s;%s;%s;%s;%s;%s;%s;%s;%s}}\n"
e.code_value
e.character_name
e.general_category
e.canonical_combining_classes
e.bidirectional_category
e.character_decomposition_mapping
e.decimal_digit_value
e.digit_value
e.numeric_value
e.mirrored
e.unicode_10_name
e.iso_10646_comment_field
e.uppercase_mapping
e.lowercase_mapping
e.titlecase_mapping
let unicodedata =
memoize
(fun () ->

View File

@ -110,25 +110,6 @@ let rec parse_unicodedata a i =
then rev a
else parse_unicodedata (parse_entry i::a) i
let print_entry e =
Printf.printf
"{{%s;%s;%s;%s;%s;%s;%s;%s;%s;%s;%s;%s;%s;%s;%s}}\n"
e.code_value
e.character_name
e.general_category
e.canonical_combining_classes
e.bidirectional_category
e.character_decomposition_mapping
e.decimal_digit_value
e.digit_value
e.numeric_value
e.mirrored
e.unicode_10_name
e.iso_10646_comment_field
e.uppercase_mapping
e.lowercase_mapping
e.titlecase_mapping
let unicodedata =
memoize
(fun () ->