-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH: Add ability to add hex encoded colors to outline items #1186
Conversation
I fear that this might overall do more harm than good:
Those disadvantages can be avoided when you would create a Color helper class. That helper class could have class attributes that map to the hex value. Or even better they are returning a Color object which has a ".tohex()" function... This way you could also add methods like darken / mix / interpolate to combine colors. Maybe there are even good 3rd party libraries that offer this? |
Or we really add just a minimal color class that has those color names as class attributes and the hey codes as values... That might be a good middle ground |
What do you think about https://pypi.org/project/colour/? |
You raise some very good points, many of which I thought about but wasn't sure what was the best path forward. My overall aim goal was to reduce the clunkiness of the current color attribute within the outline item (with the potential to expand it to other aspects of the library). The RGB tuple from 0-1 is not very intuitive or common for encoding colors. At first, I simply wanted to add the hex values in basic 6 digit format (ex.,#800080). I think those are the most straight forward, common due to the web, and easier to work-with. But then I thought that sometimes, you don't want to look up a hex code for a basic color and thought using color names might be reasonable. For example, simply
That was the logical step if we wanted to go "all in" on color features. But I don't think that colors are that central to the primary purpose of PyPDF2. I think it is overkill for the needs of the library.
Yea, that may be a better idea. Keep it simple. I think in retrospect either 1) ditching the naming convention entirely and only supporting hexstrings or 2) use a minimal class to serve essentially as a dictionary for convenience. |
Yes!
I agree. I was thinking more about having a look at this library and pointing to it in the documentation :-)
Both make sense to me. I think we could do both at the same time. However, we would need to support both, the (r, g, b) tuple and the hex-string, for a while. |
I slept on it and think that removing the named colors is probably the best route forward. It's more complicated than it is worth. Rather, I'm proposing to add the ability to parse hex strings instead. I've only implemented this for the outline items but think this could be expanded to other areas of the PDF where the color attribute is employed. For now, I think this is only within the outline item workflow, but is implied for other components (such as annotations) via a dictionary |
Codecov Report
@@ Coverage Diff @@
## main #1186 +/- ##
==========================================
- Coverage 92.14% 92.10% -0.04%
==========================================
Files 24 24
Lines 4911 4913 +2
Branches 1016 1017 +1
==========================================
Hits 4525 4525
Misses 244 244
- Partials 142 144 +2
Continue to review full report at Codecov.
|
@mtd91429 Thank you for all the work you continuously put into PyPDF2 🤗 |
New Features (ENH): - Add ability to add hex encoded colors to outline items (#1186) - Add support for pathlib.Path in PdfMerger.merge (#1190) - Add link annotation (#1189) - Add capability to filter text extraction by orientation (#1175) Bug Fixes (BUG): - Named Dest in PDF1.1 (#1174) - Incomplete Graphic State save/restore (#1172) Documentation (DOC): - Update changelog url in package metadata (#1180) - Table extraction (#1179) - Mention pyHanko for signing PDF documents (#1178) - We now have CMAP support (#1177) Maintenance (MAINT): - Consistant usage of warnings / log messages (#1164) - Consistent terminology for outline items (#1156) Code Style (STY): - Apply pre-commit (#1188) Full Changelog: 2.8.1...2.9.0
Add hexstring and basic named color parsing to
PdfWriter
methodadd_outline_item()