Skip to content

Commit 99eded4

Browse files
committed
Initial pass at accelerating processing of large documents
1 parent 55190a9 commit 99eded4

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/main/python/ttconv/isd.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,17 @@ def _region_always_has_background(region: typing.Type[model.Region]) -> bool:
199199
return False
200200

201201
bg_color: styles.ColorType = region.get_style(styles.StyleProperties.BackgroundColor)
202+
if bg_color is None:
203+
bg_color = region.get_doc().get_initial_value(styles.StyleProperties.BackgroundColor);
202204
if bg_color is not None:
203205
if bg_color.ident is not styles.ColorType.Colorimetry.RGBA8:
204206
raise RuntimeError(f"Unsupported colorimetry system: {bg_color.ident}")
205207

206208
if bg_color.components[3] == 0:
207209
return False
210+
else:
211+
# no background color specified, so transparent
212+
return False
208213

209214
return True
210215

src/test/python/test_isd_cache.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
# pylint: disable=R0201,C0115,C0116
2929

30+
from fractions import Fraction
3031
import unittest
3132
from ttconv.isd import ISD
3233
import ttconv.model as model
@@ -37,6 +38,34 @@
3738

3839
class ISDCacheTests(unittest.TestCase):
3940

41+
def test_large_number_of_regions(self):
42+
doc = model.ContentDocument()
43+
body = model.Body(doc)
44+
doc.set_body(body)
45+
46+
for i in range(1000):
47+
r_id = "r" + str(i)
48+
r = model.Region(r_id, doc)
49+
doc.put_region(r)
50+
51+
div = model.Div(doc)
52+
div.set_region(r)
53+
body.push_child(div)
54+
55+
p = model.P(doc)
56+
p.set_begin(Fraction(2*i))
57+
p.set_end(Fraction(2*i + 1))
58+
div.push_child(p)
59+
60+
span = model.Span(doc)
61+
span.push_child(model.Text(doc, f"div {i} content"))
62+
p.push_child(span)
63+
64+
sig_times = ISD.significant_times(doc)
65+
66+
for t in sig_times:
67+
ISD.from_model(doc, t, sig_times)
68+
4069
def test_show_background(self):
4170
ttml_doc = """<tt xml:lang="en"
4271
xmlns="http://www.w3.org/ns/ttml"

0 commit comments

Comments
 (0)