Skip to content

Commit 6991439

Browse files
committed
layout.py: bugfixes
Signed-off-by: Hector Martin <marcan@marcan.st>
1 parent a455c35 commit 6991439

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

blitzloop/layout.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ def add(self, molecule, get_atom_time, style, font, ruby_font):
149149
edge_px = None
150150
edge_l_px = None
151151
glyphs = []
152+
first_glyph = len(self.glyphs)
152153
# add the atom's base text as glyphs
153154
for i,c in enumerate(atom.text):
154155
if atom.particle_edge is not None and i == atom.particle_edge:
@@ -211,25 +212,29 @@ def add(self, molecule, get_atom_time, style, font, ruby_font):
211212
par_step += particle.steps
212213
ruby_glyphs += par_glyphs
213214
# center the ruby text over the atom
215+
atom_x_edge = atom_x
214216
if edge_l_px is not None:
215-
atom_x = edge_l_px
217+
atom_x_edge = edge_l_px
216218
if edge_px is not None:
217-
atom_width = edge_px - atom_x
219+
atom_width = edge_px - atom_x_edge
218220
else:
219-
atom_width = self.px - atom_x
220-
dx = self.display.round_coord(atom_x + (atom_width - ruby_px) / 2.0)
221+
atom_width = self.px - atom_x_edge
222+
dx = self.display.round_coord(atom_x_edge + (atom_width - ruby_px) / 2.0)
221223
for glyph in ruby_glyphs:
222224
glyph.tx1 += dx
223225
glyph.tx2 += dx
224226
glyph.x += dx
225227
self.glyphs.append(glyph)
226-
if self.layout_options["ruby_expand"] == 1 and dx < 0:
227-
for glyph in self.glyphs:
228-
glyph.tx1 -= dx
229-
glyph.tx2 -= dx
230-
glyph.x -= dx
231-
self.px = ruby_px
232-
dx = 0
228+
if self.layout_options["ruby_expand"] == 1:
229+
if dx < atom_x:
230+
for glyph in self.glyphs[first_glyph:]:
231+
glyph.tx1 += atom_x - dx
232+
glyph.tx2 += atom_x - dx
233+
glyph.x += atom_x - dx
234+
self.px += atom_x - dx
235+
dx = atom_x
236+
if dx + ruby_px > self.px:
237+
self.px = dx + ruby_px
233238
self.min_px = min(self.min_px, dx)
234239
self.max_px = max(self.max_px, dx + ruby_px)
235240

@@ -308,7 +313,8 @@ def _merge_lines(self):
308313
else:
309314
tmp = line.copy()
310315
tmp.add(molecule, get_atom_time, tag_info.style, font, ruby_font)
311-
if tmp.px > self.wrapwidth:
316+
wrapwidth = 1.0 - 2 * line.layout_options["margin_x"]
317+
if tmp.px > wrapwidth:
312318
line = DisplayLine(self.renderer.display)
313319
line.layout_options.update(tag_info.layout_options)
314320
line.add(molecule, get_atom_time, tag_info.style, font, ruby_font)

0 commit comments

Comments
 (0)