prawnpdf / prawn

Fast, Nimble PDF Writer for Ruby
https://prawnpdf.org
Other
4.68k stars 688 forks source link

HTML colours support as-is? #1215

Closed rubyFeedback closed 3 years ago

rubyFeedback commented 3 years ago

I was using this code:

pdf.fill_color "steelblue"

prawn does not like that:

prawn/graphics/color.rb:104:in `color_type': Unknown type of color: "steelblue" (ArgumentError)

Would it be possible to support the "HTML colour names"? It's no problem for me to automatically convert it; I have a gem for that, so it is not a real issue. But mentally I'd prefer if we can also use HTML colours and have prawn find whatever it needs internally (perhaps RGB values or hexadeciaml values but normal words are much easier for me to remember).

pointlessone commented 3 years ago

I'm unsure on this one.

PDF has very little relation to HTML, CSS, or X11. HTML has only 16 colors defined. CSS list is not stable. CSS1 has 16 colors, later versions have much more. It's not guaranteed the list is forever stable so who's going to maintain it? CSS has same names as X11 but different values. This is confusing. I doubt that anyone would need the full list so it's probably wasteful to carry it all around.

It's probably easier to have it in the application. Look up the colors you need, put them in nicely named constants and there you go. If you don't want to look the colors up, there's most likely a gem that defines them all.