Skip to content

Commit fd03afa

Browse files
author
ashariyar
committed
Color Xobject:Image violet, color /URI grey
1 parent c0ed7cd commit fd03afa

File tree

6 files changed

+48
-40
lines changed

6 files changed

+48
-40
lines changed

pdfalyzer/decorators/pdf_object_properties.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pdfalyzer.output.highlighter import PdfHighlighter
99
from pdfalyzer.output.theme import (COMPLETE_THEME_DICT, DEFAULT_LABEL_STYLE, get_class_style,
1010
get_class_style_dim, get_class_style_italic)
11-
from pdfalyzer.util.adobe_strings import GO_TO_E, GO_TO_R, S, SUBTYPE, TYPE, UNLABELED, XOBJECT
11+
from pdfalyzer.util.adobe_strings import GO_TO_E, GO_TO_R, IMAGE, S, SUBTYPE, TYPE, UNLABELED, XOBJECT
1212
from pdfalyzer.util.helpers.pdf_object_helper import pypdf_class_name
1313
from pdfalyzer.util.helpers.rich_helper import comma_join_txt
1414
from pdfalyzer.util.helpers.string_helper import coerce_address, is_array_idx, props_string_indented, root_address
@@ -49,10 +49,9 @@ def label_style(self) -> str:
4949
sub_type = self.sub_type or ''
5050

5151
if sub_type.startswith(GO_TO_R) or sub_type.startswith(GO_TO_E):
52-
return COMPLETE_THEME_DICT[GO_TO_R]
53-
# TODO: enable this
54-
# elif self.type == XOBJECT and sub_type == '/Image':
55-
# return 'medium_violet_red'
52+
return COMPLETE_THEME_DICT[PdfHighlighter.prefixed_style(GO_TO_R)]
53+
elif self.type == XOBJECT and sub_type == IMAGE:
54+
return COMPLETE_THEME_DICT[PdfHighlighter.prefixed_style(IMAGE)]
5655

5756
return COMPLETE_THEME_DICT.get(PdfHighlighter.prefixed_style(type_no_slash), DEFAULT_LABEL_STYLE)
5857

pdfalyzer/output/highlighter.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ def _debug_highlight_patterns(cls):
107107
class PdfHighlighter(LogHighlighter):
108108
base_style = PDF_OBJ_STYLE_PREFIX
109109

110+
@classmethod
111+
def prefixed_style(cls, style: str) -> str:
112+
"""Prepend this highlighter's `base_style` to `style` string, removing first slash."""
113+
return cls.base_style + style.removeprefix('/')
114+
110115

111116
# Instantiate highlighters
112117
log_highlighter = LogHighlighter()

pdfalyzer/output/theme.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@
132132
adobe_strings.UNLABELED: 'grey35 reverse',
133133
adobe_strings.XOBJECT: 'grey37',
134134
adobe_strings.XREF: 'color(148)',
135-
'/URI': 'white', # TODO: use YARALYZER_THEME_DICT['grey.light']
135+
# Images
136+
adobe_strings.IMAGE: 'medium_violet_red',
137+
adobe_strings.URI: 'color(244)',
136138
# Pages
137139
adobe_strings.PAGES: 'dark_orange3',
138140
adobe_strings.PAGE: PAGE_OBJ_STYLE,

pdfalyzer/util/adobe_strings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
GO_TO_E = '/GoToE' # Go to a destination in an embedded file
3737
GO_TO_R = '/GoToR' # Go to a destination in another document.
3838
GROUP = '/Group'
39+
IMAGE = '/Image'
3940
IMPORT_DATA = '/ImportData'
4041
INFO = '/Info'
4142
JAVASCRIPT = '/JavaScript'
@@ -77,6 +78,7 @@
7778
TRUE = '/True'
7879
TYPE = PageAttributes.TYPE
7980
TYPE1_FONT = '/Type1'
81+
URI = '/URI'
8082
W = '/W' # Equivalen of /Widths in some situations
8183
WIDGET = '/Widget'
8284
WIDTHS = '/Widths'

tests/fixtures/rendered/SF424_page2.pdf.rich_table_tree.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4600,7 +4600,7 @@ Invoked with this command:
46004600
│ │ │ │ │ │ │ │ /Filter │ [/FlateDecode]  │ Array  │
46014601
│ │ │ │ │ │ │ │ /FormType │ 1  │ Number  │
46024602
│ │ │ │ │ │ │ │ /Matrix │ [1, 0, 0, 1, -306, -396]  │ Array  │
4603-
│ │ │ │ │ │ │ │ /Resources  │ {/XObject: {/im1: <46:XObject:Image(EncodedStream)>}, /ProcSet:  │ Dictionary  │
4603+
│ │ │ │ │ │ │ │ /Resources  │ {/XObject: {/im1: <46:XObject:Image(EncodedStream)>}, /ProcSet:  │ Dictionary  │
46044604
│ │ │ │ │ │ │ │ │ <47:Resources(Array)>}  │ │
46054605
│ │ │ │ │ │ │ │ StreamData  │ q \r288 0 0 299.52 162 246.24 cm \r/im1 Do\r\rQ \r  │ │
46064606
│ │ │ │ │ │ │ │  (45 bytes)  │ │ │
@@ -4609,12 +4609,12 @@ Invoked with this command:
46094609
│ │ │ │ │ │ │ │ StreamLength  │ 0.0 kb (45 bytes)  │ │
46104610
│ │ │ │ │ │ │ └──────────────────┴───────────────────────────────────────────────────────────────────────────────────┴───────────────┘
46114611
│ │ │ │ │ │ │ ├── ┌───────────────────┬──────────────────────────────────────────────────────────────────────────────┬───────────────┐
4612-
│ │ │ │ │ │ │ │ │ │ ...arent/Kids[0]/Kids[0]/Kids[0]/Annots/Annots/Parent[39]/MK[/I]/Resources[/ │ │
4613-
│ │ │ │ │ │ │ │ │ 46./XObject:Image │ XObject][/im1]  │ EncodedStream │
4612+
│ │ │ │ │ │ │ │ │ │ ...arent/Kids[0]/Kids[0]/Kids[0]/Annots/Annots/Parent[39]/MK[/I]/Resources[/ │ │
4613+
│ │ │ │ │ │ │ │ │ 46./XObject:Image │ XObject][/im1]  │ EncodedStream │
46144614
│ │ │ │ │ │ │ │ ├───────────────────┼──────────────────────────────────────────────────────────────────────────────┼───────────────┤
46154615
│ │ │ │ │ │ │ │ │ AddressInParent  │ /Resources[/XObject][/im1]  │   │
46164616
│ │ │ │ │ │ │ │ │ /Type  │ /XObject  │ Name  │
4617-
│ │ │ │ │ │ │ │ │ /Subtype  │ /Image  │ Name  │
4617+
│ │ │ │ │ │ │ │ │ /Subtype  │ /Image  │ Name  │
46184618
│ │ │ │ │ │ │ │ │ /Name │ /im1 │ Name  │
46194619
│ │ │ │ │ │ │ │ │ /BitsPerComponent │ 1  │ Number  │
46204620
│ │ │ │ │ │ │ │ │ /ColorSpace  │ /DeviceGray  │ Name  │

0 commit comments

Comments
 (0)