mirror of
https://github.com/Kozea/WeasyPrint.git
synced 2024-10-04 16:07:57 +03:00
Revert "Use the same Resources dictionary across the whole document"
This reverts commit af92f3eba6
.
This commit is contained in:
parent
e4bcb07d55
commit
5e932d3fca
@ -184,11 +184,21 @@ class Context(pydyf.Stream):
|
||||
return self._document.fonts
|
||||
|
||||
def add_transparency_group(self, bounding_box):
|
||||
alpha_states = pydyf.Dictionary()
|
||||
x_objects = pydyf.Dictionary()
|
||||
patterns = pydyf.Dictionary()
|
||||
shadings = pydyf.Dictionary()
|
||||
resources = pydyf.Dictionary({
|
||||
'ExtGState': alpha_states,
|
||||
'XObject': x_objects,
|
||||
'Pattern': patterns,
|
||||
'Shading': shadings,
|
||||
})
|
||||
extra = pydyf.Dictionary({
|
||||
'Type': '/XObject',
|
||||
'Subtype': '/Form',
|
||||
'BBox': pydyf.Array(bounding_box),
|
||||
'Resources': None, # Will be set by _use_references
|
||||
'Resources': resources,
|
||||
'Group': pydyf.Dictionary({
|
||||
'Type': '/Group',
|
||||
'S': '/Transparency',
|
||||
@ -197,8 +207,8 @@ class Context(pydyf.Stream):
|
||||
}),
|
||||
})
|
||||
group = Context(
|
||||
self._document, self.page_rectangle, self._alpha_states,
|
||||
self._x_objects, self._patterns, self._shadings, extra=extra)
|
||||
self._document, self.page_rectangle, alpha_states, x_objects,
|
||||
patterns, shadings, extra=extra)
|
||||
group.id = f'x{len(self._x_objects)}'
|
||||
self._x_objects[group.id] = group
|
||||
return group
|
||||
@ -267,6 +277,16 @@ class Context(pydyf.Stream):
|
||||
return image_name
|
||||
|
||||
def add_pattern(self, x, y, width, height, repeat_width, repeat_height):
|
||||
alpha_states = pydyf.Dictionary()
|
||||
x_objects = pydyf.Dictionary()
|
||||
patterns = pydyf.Dictionary()
|
||||
shadings = pydyf.Dictionary()
|
||||
resources = pydyf.Dictionary({
|
||||
'ExtGState': alpha_states,
|
||||
'XObject': x_objects,
|
||||
'Pattern': patterns,
|
||||
'Shading': shadings,
|
||||
})
|
||||
matrix = (1, 0, 0, -1, x, self.page_rectangle[3] - y)
|
||||
extra = pydyf.Dictionary({
|
||||
'PatternType': 1,
|
||||
@ -276,11 +296,11 @@ class Context(pydyf.Stream):
|
||||
'TilingType': 1,
|
||||
'PaintType': 1,
|
||||
'Matrix': pydyf.Array(0.75 * i for i in matrix),
|
||||
'Resources': None,
|
||||
'Resources': resources,
|
||||
})
|
||||
pattern = Context(
|
||||
self._document, self.page_rectangle, self._alpha_states,
|
||||
self._x_objects, self._patterns, self._shadings, extra=extra)
|
||||
self._document, self.page_rectangle, alpha_states, x_objects,
|
||||
patterns, shadings, extra=extra)
|
||||
pattern.id = f'p{len(self._patterns)}'
|
||||
self._patterns[pattern.id] = pattern
|
||||
return pattern
|
||||
@ -806,15 +826,19 @@ class Document:
|
||||
pdf.add_object(x_object)
|
||||
resources['XObject'][key] = x_object.reference
|
||||
if 'Resources' in x_object.extra:
|
||||
x_object.extra['Resources'] = resources.reference
|
||||
|
||||
self._use_references(pdf, x_object.extra['Resources'])
|
||||
pdf.add_object(x_object.extra['Resources'])
|
||||
x_object.extra['Resources'] = (
|
||||
x_object.extra['Resources'].reference)
|
||||
# Patterns
|
||||
for key, pattern in resources.get('Pattern', {}).items():
|
||||
pdf.add_object(pattern)
|
||||
resources['Pattern'][key] = pattern.reference
|
||||
if 'Resources' in pattern.extra:
|
||||
pattern.extra['Resources'] = resources.reference
|
||||
|
||||
self._use_references(pdf, pattern.extra['Resources'])
|
||||
pdf.add_object(pattern.extra['Resources'])
|
||||
pattern.extra['Resources'] = (
|
||||
pattern.extra['Resources'].reference)
|
||||
# Shadings
|
||||
for key, shading in resources.get('Shading', {}).items():
|
||||
pdf.add_object(shading)
|
||||
|
Loading…
Reference in New Issue
Block a user