aboutsummaryrefslogtreecommitdiff
path: root/src/renderers/plaintextrenderer.cpp
blob: d12ec2689948e540348418ff49b616bde4dd7c79 (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

#include "plaintextrenderer.hpp"
#include "renderhelpers.hpp"
#include <QByteArray>
#include <QTextImageFormat>
#include <QTextCursor>
#include <QTextDocument>
#include <memory>

std::unique_ptr<QTextDocument> PlainTextRenderer::render(const QByteArray &input, const DocumentStyle &style)
{
    QTextCharFormat standard;
    standard.setFont(style.preformatted_font);
    standard.setForeground(style.preformatted_color);

    std::unique_ptr<QTextDocument> result = std::make_unique<QTextDocument>();
    renderhelpers::setPageMargins(result.get(), style.margin_h, style.margin_v);

    QTextCursor cursor { result.get() };
    QTextCharFormat text_fmt = standard;
    renderhelpers::renderEscapeCodes(input, text_fmt, standard, cursor);

    return result;
}