1 #include "textstyleinstance.hpp"
2 
TextStyleInstance(DocumentStyle const & themed_style)3 TextStyleInstance::TextStyleInstance(DocumentStyle const & themed_style)
4 {
5   preformatted.setFont(themed_style.preformatted_font);
6   preformatted.setForeground(themed_style.preformatted_color);
7 
8   standard.setFont(themed_style.standard_font);
9   standard.setForeground(themed_style.standard_color);
10 
11   standard_link.setFont(themed_style.standard_font);
12   standard_link.setForeground(QBrush(themed_style.internal_link_color));
13 
14   external_link.setFont(themed_style.standard_font);
15   external_link.setForeground(QBrush(themed_style.external_link_color));
16 
17   cross_protocol_link.setFont(themed_style.standard_font);
18   cross_protocol_link.setForeground(QBrush(themed_style.cross_scheme_link_color));
19 
20   standard_h1.setFont(themed_style.h1_font);
21   standard_h1.setForeground(QBrush(themed_style.h1_color));
22 
23   standard_h2.setFont(themed_style.h2_font);
24   standard_h2.setForeground(QBrush(themed_style.h2_color));
25 
26   standard_h3.setFont(themed_style.h3_font);
27   standard_h3.setForeground(QBrush(themed_style.h3_color));
28 
29   blockquote.setFont(themed_style.blockquote_font);
30   blockquote.setForeground(QBrush(themed_style.blockquote_fgcolor));
31   blockquote.setBackground(themed_style.blockquote_bgcolor);
32 
33   preformatted_format.setNonBreakableLines(true);
34 
35   // Other alignments
36   auto align = themed_style.justify_text ? Qt::AlignJustify : Qt::AlignLeft;
37 
38   standard_format.setAlignment(align);
39   standard_format.setLineHeight(themed_style.line_height_p,
40     QTextBlockFormat::LineDistanceHeight);
41   standard_format.setIndent(themed_style.indent_p);
42 
43   link_format.setLineHeight(themed_style.line_height_p,
44     QTextBlockFormat::LineDistanceHeight);
45 
46   blockquote_format.setAlignment(align);
47   blockquote_format.setLineHeight(themed_style.line_height_p,
48     QTextBlockFormat::LineDistanceHeight);
49   blockquote_tableformat.setBorderStyle(QTextFrameFormat::BorderStyle_None);
50   blockquote_tableformat.setHeaderRowCount(0);
51   blockquote_tableformat.setCellPadding(16.0);
52   blockquote_tableformat.setAlignment(Qt::AlignJustify);
53 
54   // We set blockquote indent manually, since it is a table.
55   blockquote_tableformat.setLeftMargin(themed_style.indent_size * themed_style.indent_bq);
56   blockquote_tableformat.setBottomMargin(20.0);
57 
58   list_format.setStyle(themed_style.list_symbol);
59   list_format.setIndent(themed_style.indent_l);
60 
61   preformatted_format.setIndent(themed_style.indent_p);
62 
63   heading_format.setLineHeight(themed_style.line_height_h, QTextBlockFormat::LineDistanceHeight);
64   heading_format.setIndent(themed_style.indent_h);
65 }
66