Remove pdfgraphics to old/
This commit is contained in:
parent
117a40c3d6
commit
0cc062b302
2
Makefile
2
Makefile
|
@ -7,7 +7,7 @@ DOC = cpdfunicodedata cpdferror cpdfdebug cpdfjson cpdfstrftime cpdfcoord \
|
||||||
cpdfembed cpdfaddtext cpdffont cpdftype cpdfpad cpdfocg \
|
cpdfembed cpdfaddtext cpdffont cpdftype cpdfpad cpdfocg \
|
||||||
cpdfsqueeze cpdfdraft cpdfspot cpdfpagelabels cpdfcreate cpdfannot \
|
cpdfsqueeze cpdfdraft cpdfspot cpdfpagelabels cpdfcreate cpdfannot \
|
||||||
cpdfxobject cpdfimpose cpdftweak cpdftexttopdf cpdftoc cpdfjpeg \
|
cpdfxobject cpdfimpose cpdftweak cpdftexttopdf cpdftoc cpdfjpeg \
|
||||||
cpdfpng cpdfimage cpdfdraw cpdfcomposition cpdfgraphics cpdfshape \
|
cpdfpng cpdfimage cpdfdraw cpdfcomposition cpdfshape \
|
||||||
cpdfcolours cpdfcommand
|
cpdfcolours cpdfcommand
|
||||||
|
|
||||||
MODS = $(NONDOC) $(DOC)
|
MODS = $(NONDOC) $(DOC)
|
||||||
|
|
|
@ -431,8 +431,11 @@ let
|
||||||
let realfontname = ref fontname in
|
let realfontname = ref fontname in
|
||||||
let font =
|
let font =
|
||||||
match cpdffont with
|
match cpdffont with
|
||||||
| Cpdfembed.PreMadeFontPack f -> Some (hd (fst f))
|
| Cpdfembed.PreMadeFontPack f ->
|
||||||
| Cpdfembed.EmbedInfo {fontfile; fontname; encoding} ->
|
(*Printf.printf "Cpdfaddtext.addtexts: PreMadeFontPack\n";*)
|
||||||
|
Some (hd (fst f))
|
||||||
|
| Cpdfembed.EmbedInfo {fontfile; fontname; encoding} ->
|
||||||
|
(*Printf.printf "Cpdfaddtext.addtexts: EmbedInfo\n";*)
|
||||||
let embedded = Cpdfembed.embed_truetype pdf ~fontfile ~fontname ~codepoints:[] ~encoding in
|
let embedded = Cpdfembed.embed_truetype pdf ~fontfile ~fontname ~codepoints:[] ~encoding in
|
||||||
Some (hd (fst embedded))
|
Some (hd (fst embedded))
|
||||||
| Cpdfembed.ExistingNamedFont -> None
|
| Cpdfembed.ExistingNamedFont -> None
|
||||||
|
|
|
@ -1854,12 +1854,12 @@ let addcircle s =
|
||||||
| [x; y; r] ->
|
| [x; y; r] ->
|
||||||
let _, _, segs = hd (snd (Cpdfshape.circle x y r)) in
|
let _, _, segs = hd (snd (Cpdfshape.circle x y r)) in
|
||||||
(match segs with
|
(match segs with
|
||||||
| Cpdfgraphics.Bezier ((a, b), _, _, _)::_ -> addop (Cpdfdraw.To (a, b))
|
| Cpdfshape.Bezier ((a, b), _, _, _)::_ -> addop (Cpdfdraw.To (a, b))
|
||||||
| _ -> assert false);
|
| _ -> assert false);
|
||||||
iter
|
iter
|
||||||
(function
|
(function
|
||||||
| Cpdfgraphics.Bezier (_, (c, d), (e, f), (g, h)) -> addop (Cpdfdraw.Bezier (c, d, e, f, g, h))
|
| Cpdfshape.Bezier (_, (c, d), (e, f), (g, h)) -> addop (Cpdfdraw.Bezier (c, d, e, f, g, h))
|
||||||
| Cpdfgraphics.Straight _ -> assert false)
|
| Cpdfshape.Straight _ -> assert false)
|
||||||
segs
|
segs
|
||||||
| _ -> error "-circle requires three numbers"
|
| _ -> error "-circle requires three numbers"
|
||||||
| exception _ -> error "malformed -circle"
|
| exception _ -> error "malformed -circle"
|
||||||
|
|
53
cpdfshape.ml
53
cpdfshape.ml
|
@ -4,6 +4,25 @@
|
||||||
primitives (circles, regular polygons etc). *)
|
primitives (circles, regular polygons etc). *)
|
||||||
open Pdfutil
|
open Pdfutil
|
||||||
|
|
||||||
|
type fpoint = float * float
|
||||||
|
|
||||||
|
type winding_rule = EvenOdd | NonZero
|
||||||
|
|
||||||
|
type segment =
|
||||||
|
| Straight of fpoint * fpoint
|
||||||
|
| Bezier of fpoint * fpoint * fpoint * fpoint
|
||||||
|
|
||||||
|
(* Each segment list may be marked as a hole or not. *)
|
||||||
|
type hole = Hole | Not_hole
|
||||||
|
|
||||||
|
(* A [subpath] is either closed or open. *)
|
||||||
|
type closure = Closed | Open
|
||||||
|
|
||||||
|
(* A [subpath] is the pair of a hole and a list of segments. *)
|
||||||
|
type subpath = hole * closure * segment list
|
||||||
|
|
||||||
|
(* A path is made from a number of subpaths. *)
|
||||||
|
type path = winding_rule * subpath list
|
||||||
(* \section{Common geometric functions} *)
|
(* \section{Common geometric functions} *)
|
||||||
|
|
||||||
(* The factor by which we multiply the radius to find the length of the bezier
|
(* The factor by which we multiply the radius to find the length of the bezier
|
||||||
|
@ -52,13 +71,13 @@ let quarter s (cx, cy) r =
|
||||||
match
|
match
|
||||||
map (Pdftransform.transform transform) standard_quarter_points
|
map (Pdftransform.transform transform) standard_quarter_points
|
||||||
with
|
with
|
||||||
| [p; q; r; s] -> Cpdfgraphics.Bezier(p, q, r, s)
|
| [p; q; r; s] -> Bezier(p, q, r, s)
|
||||||
| _ -> raise (Pdf.PDFError ("Shapes.quarter: inconsistency"))
|
| _ -> raise (Pdf.PDFError ("Shapes.quarter: inconsistency"))
|
||||||
|
|
||||||
(* The anticlockwise variant. *)
|
(* The anticlockwise variant. *)
|
||||||
let quarter_anticlockwise s c r =
|
let quarter_anticlockwise s c r =
|
||||||
match quarter s c r with
|
match quarter s c r with
|
||||||
| Cpdfgraphics.Bezier(p, q, r, s) -> Cpdfgraphics.Bezier(s, r, q, p)
|
| Bezier(p, q, r, s) -> Bezier(s, r, q, p)
|
||||||
| _ -> raise (Pdf.PDFError "Shapes.quarter_anticlockwise: inconsistency")
|
| _ -> raise (Pdf.PDFError "Shapes.quarter_anticlockwise: inconsistency")
|
||||||
|
|
||||||
(* Some of the following functions generate what is supposed to be a connected
|
(* Some of the following functions generate what is supposed to be a connected
|
||||||
|
@ -71,8 +90,8 @@ let rec joinsegs segments =
|
||||||
match segments with
|
match segments with
|
||||||
| [] -> []
|
| [] -> []
|
||||||
| [x] -> [x]
|
| [x] -> [x]
|
||||||
| Cpdfgraphics.Bezier(_, _, _, d) as s::Cpdfgraphics.Bezier(_, b', c', d')::rest ->
|
| Bezier(_, _, _, d) as s::Bezier(_, b', c', d')::rest ->
|
||||||
s::joinsegs (Cpdfgraphics.Bezier(d, b', c', d')::rest)
|
s::joinsegs (Bezier(d, b', c', d')::rest)
|
||||||
| _ -> raise (Pdf.PDFError "PDFShapes.joinsegs: Segment not supported")
|
| _ -> raise (Pdf.PDFError "PDFShapes.joinsegs: Segment not supported")
|
||||||
|
|
||||||
(* This version sets the start and end points to p1 and p2 respectively. Used
|
(* This version sets the start and end points to p1 and p2 respectively. Used
|
||||||
|
@ -80,11 +99,11 @@ for ensuring round joins join correctly to the rails they connect *)
|
||||||
let joinsegs_ends p1 p2 segments =
|
let joinsegs_ends p1 p2 segments =
|
||||||
match joinsegs segments with
|
match joinsegs segments with
|
||||||
| [] -> []
|
| [] -> []
|
||||||
| [Cpdfgraphics.Bezier(a, b, c, d)] -> [Cpdfgraphics.Bezier(p1, b, c, p2)]
|
| [Bezier(a, b, c, d)] -> [Bezier(p1, b, c, p2)]
|
||||||
| segs ->
|
| segs ->
|
||||||
match extremes_and_middle segs with
|
match extremes_and_middle segs with
|
||||||
| Cpdfgraphics.Bezier(_, b, c, d), m, Cpdfgraphics.Bezier(a', b', c', _) ->
|
| Bezier(_, b, c, d), m, Bezier(a', b', c', _) ->
|
||||||
Cpdfgraphics.Bezier(p1, b, c, d)::m @ [Cpdfgraphics.Bezier(a', b', c', p2)]
|
Bezier(p1, b, c, d)::m @ [Bezier(a', b', c', p2)]
|
||||||
| _ -> raise (Pdf.PDFError "PDFShapes.joinsegs_ends: Segment not supported")
|
| _ -> raise (Pdf.PDFError "PDFShapes.joinsegs_ends: Segment not supported")
|
||||||
|
|
||||||
(* The shorter arc made from bezier curves from [p1] to [p2] with centre [c].
|
(* The shorter arc made from bezier curves from [p1] to [p2] with centre [c].
|
||||||
|
@ -127,9 +146,9 @@ are of equal length, the one chosen is undefined. *)
|
||||||
|
|
||||||
(* Approximate a circle using four bezier curves.*)
|
(* Approximate a circle using four bezier curves.*)
|
||||||
let circle x y r =
|
let circle x y r =
|
||||||
Cpdfgraphics.NonZero,
|
NonZero,
|
||||||
[(Cpdfgraphics.Not_hole,
|
[(Not_hole,
|
||||||
Cpdfgraphics.Closed,
|
Closed,
|
||||||
joinsegs
|
joinsegs
|
||||||
[quarter 0. (x, y) r;
|
[quarter 0. (x, y) r;
|
||||||
quarter (pi /. 2.) (x, y) r;
|
quarter (pi /. 2.) (x, y) r;
|
||||||
|
@ -137,10 +156,10 @@ let circle x y r =
|
||||||
quarter (3. *. pi /. 2.) (x, y) r ])]
|
quarter (3. *. pi /. 2.) (x, y) r ])]
|
||||||
|
|
||||||
let rectangle x y w h =
|
let rectangle x y w h =
|
||||||
(Cpdfgraphics.EvenOdd,
|
(EvenOdd,
|
||||||
([(Cpdfgraphics.Not_hole,
|
([(Not_hole,
|
||||||
Cpdfgraphics.Closed,
|
Closed,
|
||||||
[Cpdfgraphics.Straight ((x, y), (x +. w, y));
|
[Straight ((x, y), (x +. w, y));
|
||||||
Cpdfgraphics.Straight ((x +. w, y), (x +. w, y +. h));
|
Straight ((x +. w, y), (x +. w, y +. h));
|
||||||
Cpdfgraphics.Straight ((x +. w, y +. h), (x, y +. h));
|
Straight ((x +. w, y +. h), (x, y +. h));
|
||||||
Cpdfgraphics.Straight ((x, y +. h), (x, y))])]))
|
Straight ((x, y +. h), (x, y))])]))
|
||||||
|
|
|
@ -1,5 +1,24 @@
|
||||||
(** Basic Shapes *)
|
(** Basic Shapes *)
|
||||||
|
|
||||||
|
type fpoint = float * float
|
||||||
|
|
||||||
|
type winding_rule = EvenOdd | NonZero
|
||||||
|
|
||||||
|
type segment =
|
||||||
|
| Straight of fpoint * fpoint
|
||||||
|
| Bezier of fpoint * fpoint * fpoint * fpoint
|
||||||
|
|
||||||
|
(* Each segment list may be marked as a hole or not. *)
|
||||||
|
type hole = Hole | Not_hole
|
||||||
|
|
||||||
|
(* A [subpath] is either closed or open. *)
|
||||||
|
type closure = Closed | Open
|
||||||
|
|
||||||
|
(* A [subpath] is the pair of a hole and a list of segments. *)
|
||||||
|
type subpath = hole * closure * segment list
|
||||||
|
|
||||||
|
(* A path is made from a number of subpaths. *)
|
||||||
|
type path = winding_rule * subpath list
|
||||||
(** The factor by which the radius of a circle is multiplied to find the length
|
(** The factor by which the radius of a circle is multiplied to find the length
|
||||||
of the bezier control lines when approximating quarter arcs to make circles. *)
|
of the bezier control lines when approximating quarter arcs to make circles. *)
|
||||||
val kappa : float
|
val kappa : float
|
||||||
|
@ -10,8 +29,8 @@ val restrict_angle : float -> float -> float
|
||||||
|
|
||||||
(** Calling [circle x y r] builds a path representing a circle at [(x, y)] with
|
(** Calling [circle x y r] builds a path representing a circle at [(x, y)] with
|
||||||
radius [r]. *)
|
radius [r]. *)
|
||||||
val circle : float -> float -> float -> Cpdfgraphics.path
|
val circle : float -> float -> float -> path
|
||||||
|
|
||||||
(** Calling [rectangle x y w h] builds a path representing a rectangle with top
|
(** Calling [rectangle x y w h] builds a path representing a rectangle with top
|
||||||
left [(x, y)], width [w] and height [h]. *)
|
left [(x, y)], width [w] and height [h]. *)
|
||||||
val rectangle : float -> float -> float -> float -> Cpdfgraphics.path
|
val rectangle : float -> float -> float -> float -> path
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
open Pdfutil
|
open Pdfutil
|
||||||
open Pdfio
|
open Pdfio
|
||||||
|
|
||||||
let fontpack_experiment = false
|
let fontpack_experiment = true
|
||||||
|
|
||||||
let dbg = ref true
|
let dbg = ref false
|
||||||
|
|
||||||
type t =
|
type t =
|
||||||
{flags : int;
|
{flags : int;
|
||||||
|
@ -436,8 +436,12 @@ let subset_font major minor tables indexToLocFormat subset encoding cmap loca mk
|
||||||
end;
|
end;
|
||||||
obs
|
obs
|
||||||
|
|
||||||
|
(* FIXME: remove *)
|
||||||
|
let _ =
|
||||||
|
Pdfe.logger := (fun s -> print_string s; flush stdout)
|
||||||
|
|
||||||
let parse ?(subset=[]) data encoding =
|
let parse ?(subset=[]) data encoding =
|
||||||
if !dbg then
|
(*if !dbg then*)
|
||||||
begin
|
begin
|
||||||
Printf.printf "********SUBSET is ";
|
Printf.printf "********SUBSET is ";
|
||||||
iter (Printf.printf "%i ") subset;
|
iter (Printf.printf "%i ") subset;
|
||||||
|
@ -554,7 +558,7 @@ let parse ?(subset=[]) data encoding =
|
||||||
end;
|
end;
|
||||||
let flags = calculate_flags italicangle in
|
let flags = calculate_flags italicangle in
|
||||||
let firstchar_1, lastchar_1 = calculate_limits subset_1 in
|
let firstchar_1, lastchar_1 = calculate_limits subset_1 in
|
||||||
let firstchar_2, lastchar_2 = (0, length subset_2 - 1) in
|
let firstchar_2, lastchar_2 = (0, max 0 (length subset_2 - 1)) in
|
||||||
let numOfLongHorMetrics =
|
let numOfLongHorMetrics =
|
||||||
match keep (function (t, _, _, _) -> string_of_tag t = "hhea") !tables with
|
match keep (function (t, _, _, _) -> string_of_tag t = "hhea") !tables with
|
||||||
| (_, _, o, l)::_ -> let b = mk_b (i32toi o) in read_hhea_table b
|
| (_, _, o, l)::_ -> let b = mk_b (i32toi o) in read_hhea_table b
|
||||||
|
@ -565,9 +569,9 @@ let parse ?(subset=[]) data encoding =
|
||||||
| (_, _, o, _)::_ -> read_hmtx_table numOfLongHorMetrics (mk_b (i32toi o))
|
| (_, _, o, _)::_ -> read_hmtx_table numOfLongHorMetrics (mk_b (i32toi o))
|
||||||
| [] -> raise (Pdf.PDFError "No hmtx table found in TrueType font")
|
| [] -> raise (Pdf.PDFError "No hmtx table found in TrueType font")
|
||||||
in
|
in
|
||||||
(*Printf.printf "firstchar_1, lastchar_1, firstchar_2, lastchar_2 = %i, %i, %i%, %i\n" firstchar_1 lastchar_1 firstchar_2 lastchar_2;*)
|
Printf.printf "firstchar_1, lastchar_1, firstchar_2, lastchar_2 = %i, %i, %i%, %i\n" firstchar_1 lastchar_1 firstchar_2 lastchar_2;
|
||||||
let widths_1 = calculate_widths unitsPerEm encoding firstchar_1 lastchar_1 subset_1 !glyphcodes hmtxdata in
|
let widths_1 = calculate_widths unitsPerEm encoding firstchar_1 lastchar_1 subset_1 !glyphcodes hmtxdata in
|
||||||
(*let widths_2 = calculate_widths unitsPerEm encoding firstchar_2 lastchar_2 subset_2 !glyphcodes hmtxdata in*)
|
let widths_2 = calculate_widths unitsPerEm encoding firstchar_2 lastchar_2 subset_2 !glyphcodes hmtxdata in
|
||||||
let maxwidth = calculate_maxwidth unitsPerEm hmtxdata in
|
let maxwidth = calculate_maxwidth unitsPerEm hmtxdata in
|
||||||
let stemv = calculate_stemv () in
|
let stemv = calculate_stemv () in
|
||||||
let b = mk_b (i32toi locaoffset) in
|
let b = mk_b (i32toi locaoffset) in
|
||||||
|
@ -581,23 +585,23 @@ let parse ?(subset=[]) data encoding =
|
||||||
subset_font major minor !tables indexToLocFormat subset_1
|
subset_font major minor !tables indexToLocFormat subset_1
|
||||||
encoding !glyphcodes loca mk_b glyfoffset data
|
encoding !glyphcodes loca mk_b glyfoffset data
|
||||||
in
|
in
|
||||||
(*let second_subset =
|
let second_subset =
|
||||||
subset_font major minor !tables indexToLocFormat subset_2
|
subset_font major minor !tables indexToLocFormat subset_2
|
||||||
encoding !glyphcodes loca mk_b glyfoffset data
|
encoding !glyphcodes loca mk_b glyfoffset data
|
||||||
in*)
|
in
|
||||||
(*let second_tounicode =
|
let second_tounicode =
|
||||||
if subset = [] then None else
|
if subset = [] then None else
|
||||||
let h = null_hash () in
|
let h = null_hash () in
|
||||||
let s = (implode (tl (tl (explode (Pdftext.utf16be_of_codepoints [hd subset]))))) in
|
let s = (implode (tl (tl (explode (Pdftext.utf16be_of_codepoints [hd subset]))))) in
|
||||||
Printf.printf "String for tounicode = %S\n" s;
|
Printf.printf "String for tounicode = %S\n" s;
|
||||||
Hashtbl.add h 0 s;
|
Hashtbl.add h 0 s;
|
||||||
Some h
|
Some h
|
||||||
in*)
|
in
|
||||||
[{flags; minx; miny; maxx; maxy; italicangle; ascent; descent;
|
[{flags; minx; miny; maxx; maxy; italicangle; ascent; descent;
|
||||||
capheight; stemv; xheight; avgwidth; maxwidth; firstchar = firstchar_1; lastchar = lastchar_1;
|
capheight; stemv; xheight; avgwidth; maxwidth; firstchar = firstchar_1; lastchar = lastchar_1;
|
||||||
widths = widths_1; subset_fontfile = main_subset; subset = subset_1; tounicode = None}]
|
widths = widths_1; subset_fontfile = main_subset; subset = subset_1; tounicode = None}]
|
||||||
(*@ if fontpack_experiment then
|
@ if fontpack_experiment then
|
||||||
[{flags; minx; miny; maxx; maxy; italicangle; ascent; descent;
|
[{flags; minx; miny; maxx; maxy; italicangle; ascent; descent;
|
||||||
capheight; stemv; xheight; avgwidth; maxwidth; firstchar = firstchar_2; lastchar = lastchar_2;
|
capheight; stemv; xheight; avgwidth; maxwidth; firstchar = firstchar_2; lastchar = lastchar_2;
|
||||||
widths = widths_2; subset_fontfile = second_subset; subset = subset_2;
|
widths = widths_2; subset_fontfile = second_subset; subset = subset_2;
|
||||||
tounicode = second_tounicode}] else []*)
|
tounicode = second_tounicode}] else []
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
An old, unfinished module from CPDF's very early life. To be resuccitated one day?
|
Loading…
Reference in New Issue