aboutsummaryrefslogtreecommitdiff
path: root/src/renderers/textstyleinstance.cpp
blob: 7a7822e0e65ee8d64b807a17844f4a35a9366e31 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "textstyleinstance.hpp"

TextStyleInstance::TextStyleInstance(DocumentStyle const & themed_style)
{
  preformatted.setFont(themed_style.preformatted_font);
  preformatted.setForeground(themed_style.preformatted_color);

  standard.setFont(themed_style.standard_font);
  standard.setForeground(themed_style.standard_color);

  standard_link.setFont(themed_style.standard_font);
  standard_link.setForeground(QBrush(themed_style.internal_link_color));

  external_link.setFont(themed_style.standard_font);
  external_link.setForeground(QBrush(themed_style.external_link_color));

  cross_protocol_link.setFont(themed_style.standard_font);
  cross_protocol_link.setForeground(QBrush(themed_style.cross_scheme_link_color));

  standard_h1.setFont(themed_style.h1_font);
  standard_h1.setForeground(QBrush(themed_style.h1_color));

  standard_h2.setFont(themed_style.h2_font);
  standard_h2.setForeground(QBrush(themed_style.h2_color));

  standard_h3.setFont(themed_style.h3_font);
  standard_h3.setForeground(QBrush(themed_style.h3_color));

  blockquote.setFont(themed_style.blockquote_font);
  blockquote.setForeground(QBrush(themed_style.blockquote_fgcolor));
  blockquote.setBackground(themed_style.blockquote_bgcolor);

  preformatted_format.setNonBreakableLines(true);

  // Other alignments
  auto align = themed_style.justify_text ? Qt::AlignJustify : Qt::AlignLeft;

  standard_format.setAlignment(align);
  standard_format.setLineHeight(themed_style.line_height_p,
    QTextBlockFormat::LineDistanceHeight);
  standard_format.setIndent(themed_style.indent_p);

  link_format.setLineHeight(themed_style.line_height_p,
    QTextBlockFormat::LineDistanceHeight);

  blockquote_format.setAlignment(align);
  blockquote_format.setLineHeight(themed_style.line_height_p,
    QTextBlockFormat::LineDistanceHeight);
  blockquote_tableformat.setBorderStyle(QTextFrameFormat::BorderStyle_None);
  blockquote_tableformat.setHeaderRowCount(0);
  blockquote_tableformat.setCellPadding(16.0);
  blockquote_tableformat.setAlignment(Qt::AlignJustify);

  // We set blockquote indent manually, since it is a table.
  blockquote_tableformat.setLeftMargin(themed_style.indent_size * themed_style.indent_bq);
  blockquote_tableformat.setBottomMargin(20.0);

  list_format.setStyle(themed_style.list_symbol);
  list_format.setIndent(themed_style.indent_l);

  preformatted_format.setIndent(themed_style.indent_p);

  heading_format.setLineHeight(themed_style.line_height_h, QTextBlockFormat::LineDistanceHeight);
  heading_format.setIndent(themed_style.indent_h);
}