mirror of
				https://github.com/johnwhitington/cpdf-source.git
				synced 2025-06-05 22:09:39 +02:00 
			
		
		
		
	reworking cpdfdraw for new font system
This commit is contained in:
		| @@ -1114,23 +1114,6 @@ let setattachfile s = | ||||
|       setop (AttachFile [s]) () | ||||
|   | Some _ -> detect_duplicate_op (AttachFile [s]) | ||||
|  | ||||
| let setfont f = | ||||
|   let convert f = (* convert from written PDF representation to internal PDF string e.g # sequences *) | ||||
|     match Pdfread.lex_name (Pdfio.input_of_string f) with Pdfgenlex.LexName s -> s | _ -> assert false | ||||
|   in | ||||
|   args.font <- | ||||
|     begin match Pdftext.standard_font_of_name ("/" ^ f) with | ||||
|     | Some x -> StandardFont x | ||||
|     | None -> | ||||
|         if f <> "" && hd (explode f) <> '/' then error "Custom font names must begin with /"; | ||||
|         OtherFont (convert f) | ||||
|     end; | ||||
|   args.fontname <- | ||||
|     begin match Pdftext.standard_font_of_name ("/" ^ f) with | ||||
|     | Some x -> f | ||||
|     | None -> convert f | ||||
|     end | ||||
|  | ||||
| let setextracttextfontsize f = | ||||
|   args.extract_text_font_size <- Some f | ||||
|  | ||||
| @@ -1777,6 +1760,8 @@ let addop o = | ||||
|   | [] -> error "no drawops" | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| let endxobj () = | ||||
|   match !drawops with | ||||
|   | (n, ops)::t -> | ||||
| @@ -2091,6 +2076,25 @@ let embed_font () = | ||||
|       with | ||||
|         Not_found -> error (Printf.sprintf "Font %s not found" name) | ||||
|  | ||||
| let setfont f = | ||||
|   let convert f = (* convert from written PDF representation to internal PDF string e.g # sequences *) | ||||
|     match Pdfread.lex_name (Pdfio.input_of_string f) with Pdfgenlex.LexName s -> s | _ -> assert false | ||||
|   in | ||||
|   args.font <- | ||||
|     begin match Pdftext.standard_font_of_name ("/" ^ f) with | ||||
|     | Some x -> StandardFont x | ||||
|     | None -> | ||||
|         if f <> "" && hd (explode f) <> '/' then error "Custom font names must begin with /"; | ||||
|         OtherFont (convert f) | ||||
|     end; | ||||
|   args.fontname <- | ||||
|     begin match Pdftext.standard_font_of_name ("/" ^ f) with | ||||
|     | Some x -> f | ||||
|     | None -> convert f | ||||
|     end; | ||||
|   (* If drawing, add the font pack as an op. *) | ||||
|   begin match args.op with Some Draw -> addop (Cpdfdraw.FontPack (f, embed_font (), null_hash ())) | _ -> () end | ||||
|  | ||||
| let loadttf n = | ||||
|   let name, filename = | ||||
|     match String.split_on_char '=' n with | ||||
| @@ -2104,7 +2108,8 @@ let loadttf n = | ||||
|           ttfs | ||||
|           name | ||||
|           (fontname, Cpdfembed.EmbedInfo {fontfile; fontname; encoding = args.fontencoding}); | ||||
|         addop (Cpdfdraw.FontPack (fontname, embed_font (), null_hash ())); | ||||
|         (* If drawing, add the font pack as an op. *) | ||||
|         begin match args.op with Some Draw -> addop (Cpdfdraw.FontPack (fontname, embed_font (), null_hash ())) | _ -> () end | ||||
|     with | ||||
|       _ -> error "addjpeg: could not load JPEG" | ||||
|      | ||||
| @@ -4458,6 +4463,8 @@ let go () = | ||||
|   | Some Draw -> | ||||
|       let pdf = get_single_pdf args.op false in | ||||
|       let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in | ||||
|       (* Whatever the font is going in to -draw, add its fontpack. *) | ||||
|       addop (Cpdfdraw.FontPack (args.fontname, embed_font (), null_hash ())); | ||||
|       let ops = match !drawops with [("_MAIN", ops)] -> rev ops | _ -> error "not enough -end-xobj or -et" in | ||||
|         write_pdf | ||||
|           false | ||||
|   | ||||
| @@ -65,8 +65,8 @@ let rec string_of_drawop = function | ||||
|   | FillStroke -> "FillStroke" | FillStrokeEvenOdd -> "FillStrokeEvenOdd" | ||||
|   | Clip -> "Clip" | ClipEvenOdd -> "ClipEvenOdd" | Use _ -> "Use" | ||||
|   | ImageXObject _ -> "ImageXObject" | Image _ -> "Image" | NewPage -> "NewPage" | ||||
|   | Opacity _ -> "Opacity" | SOpacity _ -> "SOpacity" | FontPack _ -> "FontPack" | ||||
|   | Font _ -> "Font" | Text _ -> "Text" | SpecialText _ -> "SpecialText" | ||||
|   | Opacity _ -> "Opacity" | SOpacity _ -> "SOpacity" | FontPack (n, _, _) -> "FontPack " ^ n ^ " " | ||||
|   | Font (f, _) -> "Font " ^ f ^ " " | Text _ -> "Text" | SpecialText _ -> "SpecialText" | ||||
|   | Newline -> "Newline" | Leading _ -> "Leading" | CharSpace _ -> "CharSpace" | ||||
|   | WordSpace _ -> "WordSpace" | TextScale _ -> "TextScale" | ||||
|   | RenderMode _ -> "RenderMode" | Rise _ -> "Rise" | ||||
| @@ -251,6 +251,7 @@ let rec ops_of_drawop dryrun pdf endpage filename bates batespad num page = func | ||||
|   | Opacity v -> [Pdfops.Op_gs (extgstate "/ca" v)] | ||||
|   | SOpacity v -> [Pdfops.Op_gs (extgstate "/CA" v)] | ||||
|   | FontPack (identifier, cpdffont, codepoints) -> | ||||
|       Printf.printf "Cpdfdraw: storing fontpack %s\n" identifier; | ||||
|       if dryrun then (res ()).current_fontpack_codepoints <- codepoints; | ||||
|       let fontpack = | ||||
|         match cpdffont with | ||||
| @@ -277,6 +278,7 @@ let rec ops_of_drawop dryrun pdf endpage filename bates batespad num page = func | ||||
|         (res ()).page_names <- ns @ (res ()).page_names; | ||||
|         [] | ||||
|   | Font (identifier, size) -> | ||||
|       Printf.printf "Changing to stored font %s\n" identifier; | ||||
|       (res ()).current_fontpack <- Hashtbl.find fontpacks identifier; | ||||
|       (res ()).font_size <- size; | ||||
|       [] | ||||
| @@ -402,6 +404,7 @@ let draw_single ~fast ~underneath ~filename ~bates ~batespad fast range pdf draw | ||||
|     Pdfpage.change_pages true pdf pages | ||||
|  | ||||
| let draw ?(fast=false) ?(underneath=false) ~filename ~bates ~batespad fast range pdf drawops = | ||||
|   Printf.printf "%s\n" (string_of_drawops drawops);  | ||||
|   resstack := [empty_res ()]; | ||||
|   Hashtbl.clear fontpacks; | ||||
|   (res ()).time <- Cpdfstrftime.current_time (); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user