Skip to content

Commit

Permalink
Only scale available reportlab attributes (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
cydanil authored Jul 12, 2021
2 parents ca4ad62 + 0133f98 commit a617327
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/gourmet/plugins/import_export/pdf_plugin/pdf_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,15 @@ def setup_frames(self,
f'not {mode}')
return frames

def scale_stylesheet (self, perc):
for name,sty in list(self.styleSheet.byName.items()):
def scale_stylesheet(self, perc: float):
for name, sty in list(self.styleSheet.byName.items()):
for attr in ['firstLineIndent',
'fontSize',
'leftIndent',
'rightIndent',
'leading']:
setattr(sty,attr,int(perc*getattr(sty,attr)))
if hasattr(sty, attr):
setattr(sty, attr, int(perc * getattr(sty, attr)))

def setup_column_frames (self, n):
COLUMN_SEPARATOR = 0.5 * inch
Expand Down Expand Up @@ -863,13 +864,23 @@ class PdfPrefGetter:
_('Index Cards (4x6)'),
_('Index Cards (A7)')]
layouts = {_('Plain'): ('column', 1),
_('2 Columns'): ('column', 2),
_('3 Columns'): ('column', 3),
_('4 Columns'): ('column', 4),
_('5 Columns'): ('column', 5),
_('Index Cards (3.5x5)'): ('index_cards', (5 * inch, 3.5 * inch)),
_('Index Cards (4x6)'): ('index_cards', (6 * inch, 4 * inch)),
_('Index Cards (A7)'): ('index_cards', (105 * mm, 74 * mm))}
for n in range(2, 5):
layouts[ngettext('%s Column', '%s Columns', n) % n] = ('column', n)

# These two dictionaries are here to be able to store the preferences in the persistent toml file.
# This allows us to have a locale-agnostic GUI.
_layouts_to_settings = {_('Plain'): 'plain',
_('2 Columns'): '2_columns',
_('3 Columns'): '3_columns',
_('4 Columns'): '4_columns',
_('5 Columns'): '5_columns',
_('Index Cards (3.5x5)'): 'index_cards_35_5',
_('Index Cards (4x6)'): 'index_cards_4_6',
_('Index Cards (A7)'): 'a7'}
Expand All @@ -884,9 +895,6 @@ class PdfPrefGetter:
def __init__(self):
self.size_strings = list(self.page_sizes.keys())
self.size_strings.sort()
for n in range(2,5):
self.layouts[ngettext('%s Column','%s Columns',n)%n]=('column',n)

self.page_sizes_r = {v: k for k, v in self.page_sizes.items()}
self.layouts_r = {v: k for k, v in self.layouts.items()}
self.page_modes_r = {v: k for k, v in self.page_modes.items()}
Expand Down Expand Up @@ -920,7 +928,6 @@ def __init__(self):
default_layout = defaults.get('page_layout',
PDF_PREF_DEFAULT['page_layout'])
default_layout = self._settings_to_layout[default_layout]
# default_layout = self.layouts_r[default_layout]
layout = [_('Page _Layout'),
(default_layout, self.layout_strings)]

Expand Down Expand Up @@ -1012,10 +1019,6 @@ def change_cb(self, option_table, *args,**kwargs):
if n in [i[0] for i in self.index_card_layouts_to_put_back]:
default_pos = self.layout_strings.index(_('Plain'))
cb.set_active(default_pos)
self.index_card_layouts_to_put_back.reverse()
for pos,txt in self.index_card_layouts_to_put_back:
cb.remove_text(pos)
self.index_card_layouts_to_put_back.reverse()
elif pagesize not in self.INDEX_CARDS and last_pagesize in self.INDEX_CARDS:
changed = True
option_table.set_option(self.OPT_PO,_('Portrait'))
Expand Down

0 comments on commit a617327

Please sign in to comment.