Skip to content

Commit fc66c4a

Browse files
committed
Addresses 4352
Add more colors to built-in color list. Addresses #4352.
1 parent c4ba81e commit fc66c4a

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

src/utils.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3235,6 +3235,21 @@ def getColorInfoList() -> list:
32353235
("GRAY97", 247, 247, 247),
32363236
("GRAY98", 250, 250, 250),
32373237
("GRAY99", 252, 252, 252),
3238+
("AQUA", 0, 255, 255),
3239+
("CRIMSON", 220, 20, 60),
3240+
("DARKGREY", 169, 169, 169),
3241+
("DARKSLATEGREY", 47, 79, 79),
3242+
("DIMGREY", 105, 105, 105),
3243+
("FUCHSIA", 255, 0, 255),
3244+
("GREY", 128, 128, 128),
3245+
("INDIGO", 75, 0, 130),
3246+
("LIGHTGREY", 211, 211, 211),
3247+
("LIGHTSLATEGREY", 119, 136, 153),
3248+
("LIME", 0, 255, 0),
3249+
("OLIVE", 128, 128, 0),
3250+
("SILVER", 192, 192, 192),
3251+
("SLATEGREY", 112, 128, 144),
3252+
("TEAL", 0, 128, 128),
32383253
("HONEYDEW", 240, 255, 240),
32393254
("HONEYDEW1", 240, 255, 240),
32403255
("HONEYDEW2", 224, 238, 224),
@@ -3543,12 +3558,9 @@ def getColor(name: str) -> tuple:
35433558
Returns:
35443559
a triple of floats in range 0 to 1. In case of name-not-found, "white" is returned.
35453560
"""
3546-
try:
3547-
c = getColorInfoList()[getColorList().index(name.upper())]
3548-
return (c[1] / 255.0, c[2] / 255.0, c[3] / 255.0)
3549-
except Exception:
3550-
pymupdf.exception_info()
3551-
return (1, 1, 1)
3561+
color_dict = getColorInfoDict()
3562+
c = color_dict.get(name, (255, 255, 255))
3563+
return (c[0] / 255.0, c[1] / 255.0, c[2] / 255.0)
35523564

35533565

35543566
def getColorHSV(name: str) -> tuple:

tests/test_annots.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def test_1645():
243243
annot_loc * page.derotation_matrix,
244244
"TEST",
245245
fontsize=18,
246-
fill_color=pymupdf.utils.getColor("FIREBRICK1"),
246+
fill_color=pymupdf.pdfcolor["firebrick1"],
247247
rotate=page.rotation,
248248
)
249249
doc.save(path_out, garbage=1, deflate=True, no_new_id=True)
@@ -372,17 +372,17 @@ def test_3863():
372372
if pymupdf.mupdf_version_tuple < (1, 24, 10):
373373
print(f'test_3863(): not running because {pymupdf.mupdf_version_tuple=} < 1.24.10.')
374374
return
375-
375+
376376
path_in = os.path.normpath(f'{__file__}/../../tests/resources/test_3863.pdf')
377377
path_out = os.path.normpath(f'{__file__}/../../tests/test_3863.pdf.pdf')
378-
378+
379379
# Create redacted PDF.
380380
print(f'Loading {path_in=}.')
381381
with pymupdf.open(path_in) as document:
382-
382+
383383
for num, page in enumerate(document):
384384
print(f"Page {num + 1} - {page.rect}:")
385-
385+
386386
for image in page.get_images(full=True):
387387
print(f" - Image: {image}")
388388

@@ -396,18 +396,18 @@ def test_3863():
396396

397397
print(f'Writing to {path_out=}.')
398398
document.save(path_out)
399-
399+
400400
with pymupdf.open(path_out) as document:
401401
assert len(document) == 8
402-
402+
403403
# Create PNG for each page of redacted PDF.
404404
for num, page in enumerate(document):
405405
path_png = f'{path_out}.{num}.png'
406406
pixmap = page.get_pixmap()
407407
print(f'Writing to {path_png=}.')
408408
pixmap.save(path_png)
409409
# Compare with expected png.
410-
410+
411411
print(f'Comparing page PNGs with expected PNGs.')
412412
for num, _ in enumerate(document):
413413
path_png = f'{path_out}.{num}.png'
@@ -480,7 +480,7 @@ def test_4079():
480480
if pymupdf.mupdf_version_tuple >= (1, 26):
481481
path_after = os.path.normpath(f'{__file__}/../../tests/resources/test_4079_after.pdf')
482482
else:path_after = os.path.normpath(f'{__file__}/../../tests/resources/test_4079_after_1.25.pdf')
483-
483+
484484
path_out = os.path.normpath(f'{__file__}/../../tests/test_4079_out')
485485
with pymupdf.open(path_after) as document_after:
486486
page = document_after[0]

0 commit comments

Comments
 (0)