From 65e7bbf68f294d957853539266e32d670d27d2cb Mon Sep 17 00:00:00 2001 From: John Whitington Date: Wed, 7 Jun 2023 16:35:26 +0100 Subject: [PATCH] more --- cpdfcolours.ml | 2 +- cpdfcommand.ml | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cpdfcolours.ml b/cpdfcolours.ml index 6e490e6..bccd9ef 100644 --- a/cpdfcolours.ml +++ b/cpdfcolours.ml @@ -3,7 +3,7 @@ open Pdfutil let colours = map - (fun (a, b) -> (b, a)) + (fun (a, b) -> (String.lowercase_ascii b, a)) [(0xF0F8FF, "AliceBlue"); (0xFAEBD7, "AntiqueWhite"); (0x00FFFF, "Aqua"); diff --git a/cpdfcommand.ml b/cpdfcommand.ml index af0a482..3e4c628 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -1140,13 +1140,13 @@ let setaddtext s = setop (AddText s) () let parse_color s = - match String.lowercase_ascii s with - | "white" -> Cpdfaddtext.RGB (1., 1., 1.) - | "black" -> Cpdfaddtext.RGB (0., 0., 0.) - | "red" -> Cpdfaddtext.RGB (1., 0., 0.) - | "green" -> Cpdfaddtext.RGB (0., 1., 0.) - | "blue" -> Cpdfaddtext.RGB (0., 0., 1.) - | _ -> + match lookup (String.lowercase_ascii s) Cpdfcolours.colours with + | Some c -> + let r = float_of_int ((c land 0xFF0000) lsr 16) /. 255. in + let g = float_of_int ((c land 0x00FF00) lsr 8) /. 255. in + let b = float_of_int (c land 0x0000FF) /. 255. in + Cpdfaddtext.RGB (r, g, b) + | None -> let getnum = function | Pdfgenlex.LexInt i -> float i | Pdfgenlex.LexReal f -> f @@ -1154,7 +1154,7 @@ let parse_color s = in match Pdfgenlex.lex_string s with | [g] -> Cpdfaddtext.Grey (getnum g) - | [r;g;b] -> Cpdfaddtext.RGB (getnum r, getnum g, getnum b) + | [r; g; b] -> Cpdfaddtext.RGB (getnum r, getnum g, getnum b) | [c; y; m; k] -> Cpdfaddtext.CYMK (getnum c, getnum y, getnum m, getnum k) | _ -> error "Bad color"