Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions latex2dnd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ def WhiteBox(self, boxes, outfn=None):
for box in boxes:
# make sure box is set for context of this image
box.offset_by_bb(self.hrbb)
geom = box.png_geom(self.sizex, self.sizey, delta=4.5)
# png_geom has a historical 4-pixel downward offset. Trim the
# same amount from the white-out height so it does not cover the
# bottom target border.
geom = box.png_geom(self.sizex, self.sizey, delta=4.5,
bottom_trim=4)

regions.append('-region {geom} -threshold -1 '.format(geom=geom))

Expand Down Expand Up @@ -258,17 +262,18 @@ def in_to_px(x):
return list(map(in_to_px, [self.pos[0], ysize-self.pos[1], self.pos[2], ysize-self.pos[3]]))


def png_geom(self, imx, imy, delta=0):
def png_geom(self, imx, imy, delta=0, bottom_trim=0):
'''
return geometry string for box, in units of pixels (for PNG file)
it is assumed that the PNG file has a width which imx which is
equal to that given by hrbb, i.e. hrbb[2]-hrbb[0].

the geometry string uses a coordinate system with (0,0) in the upper left
bottom_trim removes additional pixels from the bottom of the region
'''
pp = self.png_pos(imx, imy)
dx = int(pp[2] - pp[0] - 2*delta)
dy = int(pp[1] - pp[3] - 2*delta)
dy = int(pp[1] - pp[3] - 2*delta - bottom_trim)
geom = '%dx%d+%d+%d' % (dx, dy, int(pp[0]+delta), int(pp[3]+4+delta))
return geom

Expand Down
11 changes: 11 additions & 0 deletions latex2dnd/test/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from latex2dnd.main import Box


def test_png_geom_bottom_trim_only_changes_height():
box = Box.__new__(Box)
box.png_pos = lambda imx, imy: [10, 110, 210, 20]

assert box.png_geom(300, 200, delta=4.5) == "191x81+14+28"
assert box.png_geom(
300, 200, delta=4.5, bottom_trim=4
) == "191x77+14+28"
Loading