mirror of
https://github.com/johnwhitington/cpdf-source.git
synced 2025-06-05 22:09:39 +02:00
more
This commit is contained in:
19
compressor/Makefile
Normal file
19
compressor/Makefile
Normal file
@ -0,0 +1,19 @@
|
||||
SOURCES = compressor.ml
|
||||
|
||||
RESULT = compressor
|
||||
|
||||
PACKS = camlpdf
|
||||
|
||||
TARGETS := native-code
|
||||
|
||||
OCAMLFLAGS = -bin-annot
|
||||
OCAMLNCFLAGS = -g -safe-string -w -3
|
||||
OCAMLBCFLAGS = -g -safe-string -w -3
|
||||
OCAMLLDFLAGS = -g
|
||||
|
||||
all : $(TARGETS)
|
||||
|
||||
clean ::
|
||||
rm -rf doc foo foo2 out.pdf out2.pdf *.cmt *.cmti *.zlib
|
||||
|
||||
-include OCamlMakefile
|
1299
compressor/OCamlMakefile
Executable file
1299
compressor/OCamlMakefile
Executable file
File diff suppressed because it is too large
Load Diff
34626
compressor/UnicodeData.txt
Normal file
34626
compressor/UnicodeData.txt
Normal file
File diff suppressed because it is too large
Load Diff
37
compressor/compressor.ml
Normal file
37
compressor/compressor.ml
Normal file
@ -0,0 +1,37 @@
|
||||
(* compressor <infile> <outfile> [<compress>] substitutes data files specified
|
||||
by __DATA:<filename>\n into the <infile> template, writing to <outfile>. The
|
||||
data is printed in way which meets OCaml's syntax. It is optionally
|
||||
compressed by zlib. *)
|
||||
open Pdfutil
|
||||
|
||||
let contents_of_file filename =
|
||||
let ch = open_in_bin filename in
|
||||
let s = really_input_string ch (in_channel_length ch) in
|
||||
close_in ch;
|
||||
s
|
||||
|
||||
let contents_to_file filename contents =
|
||||
let ch = open_out_bin filename in
|
||||
output_string ch contents;
|
||||
close_out ch
|
||||
|
||||
let rec process a = function
|
||||
| '_'::'_'::'D'::'A'::'T'::'A'::':'::more ->
|
||||
let filename, rest = cleavewhile (neq '\n') more in
|
||||
let data = all_but_last (explode (contents_of_file (implode filename))) in
|
||||
let compressed = Pdfio.string_of_bytes (Pdfcodec.encode_flate (Pdfio.bytes_of_string (implode data))) in
|
||||
let ocaml = explode (Printf.sprintf "%S" compressed) in
|
||||
process (rev ocaml @ a) rest
|
||||
| h::t -> process (h::a) t
|
||||
| [] -> rev a
|
||||
|
||||
let go infile outfile compress =
|
||||
let indata = explode (contents_of_file infile) in
|
||||
let processed = process [] indata in
|
||||
contents_to_file outfile (implode processed)
|
||||
|
||||
let () =
|
||||
match Sys.argv with
|
||||
| [|_; infile; outfile|] -> go infile outfile false
|
||||
| [|_; infile; outfile; "compress"|] -> go infile outfile true
|
||||
| _ -> Printf.eprintf "compressor: unknown command line\n"
|
2
compressor/run
Executable file
2
compressor/run
Executable file
@ -0,0 +1,2 @@
|
||||
./compressor ../pdfglyphlist.source.ml ../pdfglyphlist.ml
|
||||
./compressor ../pdfafmdata.source.ml ../pdfafmdata.ml
|
Reference in New Issue
Block a user