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
									
								
								cpdfpage.ml
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								cpdfpage.ml
									
									
									
									
									
								
							| @@ -4,18 +4,14 @@ open Cpdferror | |||||||
| (* FIXME: Need to take account of inherited resources (among Xobjects and their children - pages | (* FIXME: Need to take account of inherited resources (among Xobjects and their children - pages | ||||||
|    are regularized upon loading). Would be nice to see a failing example first though. |    are regularized upon loading). Would be nice to see a failing example first though. | ||||||
|    FIXME: What would happen if a pattern was used in a transforming and non-transforming way - we |    FIXME: What would happen if a pattern was used in a transforming and non-transforming way - we | ||||||
|    would have to dedupulicate - again, no failing example available. |    would have to dedupulicate - again, no failing example available. *) | ||||||
|    FIXME: combine change_annotation_matrices, change_pattern_matrices and change_softmask_matrices |  | ||||||
|    into one *) |  | ||||||
|  |  | ||||||
| (* Transparency group soft masks appear to need altering with the inverse of | (* Transparency group soft masks appear to need altering with the inverse of | ||||||
|    the transformation matrix. We find them all, deduplicate, and then process |    the transformation matrix. We find them all, deduplicate, and then process | ||||||
|    in place. *) |    in place. *) | ||||||
|  |  | ||||||
| (* FIXME sub-xobjects! *) |  | ||||||
| (* For each xobject, look in /Resources -> /ExtGState -> /G, and get object number. *) | (* For each xobject, look in /Resources -> /ExtGState -> /G, and get object number. *) | ||||||
| let rec change_softmask_matrices_xobject pdf xobject = | let rec change_softmask_matrices_xobject pdf xobject = | ||||||
|   Printf.printf "change_softmask_matrices_xobject: %s\n" (Pdfwrite.string_of_pdf xobject); |  | ||||||
|   let objnums = ref [] in |   let objnums = ref [] in | ||||||
|     begin match xobject with |     begin match xobject with | ||||||
|     | Pdf.Indirect i -> |     | Pdf.Indirect i -> | ||||||
| @@ -24,16 +20,14 @@ let rec change_softmask_matrices_xobject pdf xobject = | |||||||
|           | Some d -> |           | Some d -> | ||||||
|               begin match Pdf.lookup_direct pdf "/ExtGState" d with |               begin match Pdf.lookup_direct pdf "/ExtGState" d with | ||||||
|               | Some (Pdf.Dictionary extgstates) -> |               | Some (Pdf.Dictionary extgstates) -> | ||||||
|                   Printf.printf "Found %i extgstates to examine\n" (length extgstates); |  | ||||||
|                   iter |                   iter | ||||||
|                     (function extgstate -> |                     (function extgstate -> | ||||||
|                        match Pdf.direct pdf extgstate with |                        match Pdf.direct pdf extgstate with | ||||||
|                        | Pdf.Dictionary d -> |                        | Pdf.Dictionary d -> | ||||||
|                            begin match lookup "/SMask" d with |                            begin match Pdf.lookup_direct pdf "/SMask" (Pdf.Dictionary d) with | ||||||
|                            | Some (Pdf.Dictionary d) -> |                            | Some (Pdf.Dictionary d) -> | ||||||
|                                begin match lookup "/G" d with |                                begin match lookup "/G" d with | ||||||
|                                | Some (Pdf.Indirect i) -> |                                | Some (Pdf.Indirect i) -> | ||||||
|                                    Printf.printf "Collecting objnum %i\n" i; |  | ||||||
|                                    objnums := i::!objnums |                                    objnums := i::!objnums | ||||||
|                                | _ -> () |                                | _ -> () | ||||||
|                                end |                                end | ||||||
| @@ -67,7 +61,6 @@ let change_softmask_matrices_page pdf tr page = | |||||||
|     | Some (Pdf.Dictionary d) -> d |     | Some (Pdf.Dictionary d) -> d | ||||||
|     | _ -> [] |     | _ -> [] | ||||||
|   in |   in | ||||||
|     Printf.printf "** page has %i xobjects to process\n" (length xobjects); |  | ||||||
|     let objnums = setify (flatten (map (change_softmask_matrices_xobject pdf) (map snd xobjects))) in |     let objnums = setify (flatten (map (change_softmask_matrices_xobject pdf) (map snd xobjects))) in | ||||||
|       iter |       iter | ||||||
|         (fun objnum -> |         (fun objnum -> | ||||||
| @@ -100,7 +93,7 @@ let rec change_pattern_matrices_resources pdf tr resources names_used_with_scn = | |||||||
|         (fun (k, v) ->  |         (fun (k, v) ->  | ||||||
|            match v with |            match v with | ||||||
|            | Pdf.Indirect i -> |            | Pdf.Indirect i -> | ||||||
|                Printf.printf "Processing form xobject %s for patterns\n" k; |                (*Printf.printf "Processing form xobject %s for patterns\n" k;*) | ||||||
|                change_pattern_matrices_xobject pdf tr v i |                change_pattern_matrices_xobject pdf tr v i | ||||||
|            | _ -> raise (Pdf.PDFError "change_pattern_matrices_page")) |            | _ -> raise (Pdf.PDFError "change_pattern_matrices_page")) | ||||||
|         elts |         elts | ||||||
| @@ -114,7 +107,7 @@ let rec change_pattern_matrices_resources pdf tr resources names_used_with_scn = | |||||||
|             match Hashtbl.find names_used_with_scn name with |             match Hashtbl.find names_used_with_scn name with | ||||||
|             | exception Not_found -> (name, p) |             | exception Not_found -> (name, p) | ||||||
|             | _ -> |             | _ -> | ||||||
|                 Printf.printf "Changing matrices of pattern %s\n" name; |                 (*Printf.printf "Changing matrices of pattern %s\n" name;*) | ||||||
|                 let old_pattern = Pdf.direct pdf p in |                 let old_pattern = Pdf.direct pdf p in | ||||||
|                   let new_pattern = |                   let new_pattern = | ||||||
|                     let existing_tr = Pdf.parse_matrix pdf "/Matrix" old_pattern in |                     let existing_tr = Pdf.parse_matrix pdf "/Matrix" old_pattern in | ||||||
| @@ -148,9 +141,9 @@ and change_pattern_matrices_xobject pdf tr xobj xobjnum = | |||||||
| let change_pattern_matrices_page pdf tr page = | let change_pattern_matrices_page pdf tr page = | ||||||
|   change_softmask_matrices_page pdf tr page; |   change_softmask_matrices_page pdf tr page; | ||||||
|   let used = patterns_used pdf page.Pdfpage.content page.Pdfpage.resources in |   let used = patterns_used pdf page.Pdfpage.content page.Pdfpage.resources in | ||||||
|     Printf.printf "Patterns for translation, due to being used as cs / CS"; |     (*Printf.printf "Patterns for translation, due to being used as cs / CS"; | ||||||
|     Hashtbl.iter (fun x _ -> Printf.printf "%s " x) used; |     Hashtbl.iter (fun x _ -> Printf.printf "%s " x) used; | ||||||
|     Printf.printf "\n"; |     Printf.printf "\n";*) | ||||||
|     {page with Pdfpage.resources = change_pattern_matrices_resources pdf tr page.Pdfpage.resources used} |     {page with Pdfpage.resources = change_pattern_matrices_resources pdf tr page.Pdfpage.resources used} | ||||||
|  |  | ||||||
| (* Concatenate inverse matrix to each /Matrix entry in those object numbers. *) | (* Concatenate inverse matrix to each /Matrix entry in those object numbers. *) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user