fit to selected bbox

This commit is contained in:
rigoni
2024-08-23 19:27:58 +02:00
parent ee3094c83b
commit 0338ffbb7d

View File

@@ -421,6 +421,7 @@ class CalendarioSanti(inkex.Effect):
'saint': (x+ dbb[0] + s.padding+s.margin_left , y+ dbb[1]-s.padding-s.margin_bottom),
'hline': (x , y+ dbb[1]),
'moon' : (x + cw - m.size-2*m.padding-m.margin_right, y+ m.size+2*m.padding+m.margin_top),
'bbox' : (dbb[0], dbb[1]),
}
return ans
@@ -445,8 +446,12 @@ class CalendarioSanti(inkex.Effect):
sk = sk.replace('-','_')
self.spacing[el].__dict__[sk] = self.svg.unittouu( str(getattr(self.options ,el+'_'+sk)) + self.options.units)
self.spacing['linewidth'] = getattr(self.options ,'linewidth')
self.spacing['columnwidth'] = self.svg.unittouu( str(getattr(self.options ,'columnwidth')) + self.options.units)
self.spacing['rowheight'] = self.svg.unittouu( str(getattr(self.options ,'rowheight')) + self.options.units)
if selected:
self.spacing['columnwidth'] = bbox.width
else:
self.spacing['columnwidth'] = self.svg.unittouu( str(getattr(self.options ,'columnwidth')) + self.options.units)
if len(self.options.saints_file):
ss = WikiSaints()
@@ -457,7 +462,13 @@ class CalendarioSanti(inkex.Effect):
compute_date = lambda d: { 'day' : d, 'month' : self.options.month, 'year': self.options.year,
'saint' : str(ss.get_saint(self.options.month, d)[0]), 'fest' : str(ss.get_saint(self.options.month, d)[2]) }
for n,d in enumerate(range(self.options.dayfrom, self.options.dayto + 1)):
if selected:
day_bbox = self._compute_spacing(self.x_offset, self.y_offset, 0)['bbox']
available_days = int(ceil(bbox.height / day_bbox[1])) -1
self.options.dayto = min(self.options.dayfrom + available_days - 1, self.options.dayto)
for n,d in enumerate(range(self.options.dayfrom, self.options.dayto)):
cal_date = compute_date(d)
pos = self._compute_spacing(self.x_offset, self.y_offset, n)
self.draw_day(cal_date, pos, parent)