def get_optimized_font_size(self, line, font, max_width): """ for a given width, guess the best font size which is equals or smaller than font which make line fit into max_width """ test_font = FontStyle(font) width = utils.pt2cm(self.doc.string_width(test_font, line)) while width > max_width and test_font.get_size() > 1: test_font.set_size(test_font.get_size() - 1) width = utils.pt2cm(self.doc.string_width(test_font, line)) return test_font.get_size()
def make_default_style(self, default_style): """Make the default output style for the Descendant Report.""" fstyle = FontStyle() fstyle.set_size(12) fstyle.set_type_face(FONT_SANS_SERIF) fstyle.set_bold(1) pstyle = ParagraphStyle() pstyle.set_header_level(1) pstyle.set_bottom_border(1) pstyle.set_top_margin(utils.pt2cm(3)) pstyle.set_bottom_margin(utils.pt2cm(3)) pstyle.set_font(fstyle) pstyle.set_alignment(PARA_ALIGN_CENTER) pstyle.set_description(_("The style used for the title of the page.")) default_style.add_paragraph_style("DR-Title", pstyle) fstyle = FontStyle() fstyle.set_size(10) for i in range(1, 33): pstyle = ParagraphStyle() pstyle.set_font(fstyle) pstyle.set_top_margin(utils.pt2cm(fstyle.get_size() * 0.125)) pstyle.set_bottom_margin(utils.pt2cm(fstyle.get_size() * 0.125)) pstyle.set_first_indent(-0.5) pstyle.set_left_margin(min(10.0, float(i - 0.5))) pstyle.set_description( _("The style used for the level %d display.") % i) default_style.add_paragraph_style("DR-Level%d" % min(i, 32), pstyle) pstyle = ParagraphStyle() pstyle.set_font(fstyle) pstyle.set_top_margin(utils.pt2cm(fstyle.get_size() * 0.125)) pstyle.set_bottom_margin(utils.pt2cm(fstyle.get_size() * 0.125)) pstyle.set_left_margin(min(10.0, float(i - 0.5))) pstyle.set_description( _("The style used for the spouse level %d display.") % i) default_style.add_paragraph_style("DR-Spouse%d" % min(i, 32), pstyle)