Switch to unified view

a/HelperStructs/Style.cpp b/HelperStructs/Style.cpp
...
...
30
#include <regex>
30
#include <regex>
31
#include <array>
31
#include <array>
32
32
33
using namespace std;
33
using namespace std;
34
34
35
/* font-size: 10pt; */
36
static const string fntszexp(R"((\s*font-size\s*:\s*)([0-9]+)(pt\s*;\s*))");
37
static regex fntszregex(fntszexp);
38
39
QString Style::get_style(bool dark, float multiplier)
35
QString Style::get_style(bool dark, float multiplier)
40
{
36
{
41
#if !defined(Q_OS_MACOS) && !defined(Q_OS_MAC)
37
#if !defined(Q_OS_MACOS) && !defined(Q_OS_MAC)
42
    QString dir = Helper::getSharePath();
38
    QString dir = Helper::getSharePath();
43
#else
39
#else
...
...
58
54
59
    return commonstyle + style;
55
    return commonstyle + style;
60
}
56
}
61
57
62
// The hell if I'm studying yet another regexp syntax, let's go std
58
// The hell if I'm studying yet another regexp syntax, let's go std
59
60
/* font-size: 10pt; */
61
static const string fntsz_exp(
62
    R"((\s*font-size\s*:\s*)([0-9]+)(pt\s*;\s*))"
63
    );
64
static regex fntsz_regex(fntsz_exp);
65
66
/* body {margin: 20px 0px 0px 0px;}*/
67
static const string bdmrg_exp(
68
    R"((\s*body\s*\{\s*margin:\s*)([0-9]+)(px\s*[0-9]+px\s*[0-9]+px\s*[0-9]+px\s*;\s*\}))"
69
    );
70
static regex bdmrg_regex(bdmrg_exp);
71
63
string Style::scale_fonts(const string& style, float multiplier)
72
string Style::scale_fonts(const string& style, float multiplier)
64
{
73
{
65
    vector<string> lines;
74
    vector<string> lines;
66
    stringToTokens(style, lines, "\n");
75
    stringToTokens(style, lines, "\n");
67
    for (unsigned int ln = 0; ln < lines.size(); ln++) {
76
    for (unsigned int ln = 0; ln < lines.size(); ln++) {
68
        const string& line = lines[ln];
77
        const string& line = lines[ln];
69
        smatch m;
78
        smatch m;
70
        if (regex_match(line, m, fntszregex)) {
79
        if (regex_match(line, m, fntsz_regex) && m.size() == 4) {
71
            //cerr << "Got match (sz " << m.size() << ") for " << line << endl;
80
            //cerr << "Got match (sz " << m.size() << ") for " << line << endl;
72
            if (m.size() == 4) {
73
                int fs = atoi(m[2].str().c_str());
81
            int fs = atoi(m[2].str().c_str());
74
                int nfs = round(fs * multiplier);
82
            int nfs = round(fs * multiplier);
75
                char buf[20];
83
            char buf[20];
76
                snprintf(buf, 20, "%d", nfs);
84
            snprintf(buf, 20, "%d", nfs);
77
                lines[ln] = m[1].str() + buf + m[3].str();
85
            lines[ln] = m[1].str() + buf + m[3].str();
78
                //cerr << "New line: [" << lines[ln] << "]\n";
86
            //cerr << "New line: [" << lines[ln] << "]\n";
79
            }
87
        }
88
        m = smatch();
89
        if (regex_match(line, m, bdmrg_regex) && m.size() == 4) {
90
            //cerr << "Got match (sz " << m.size() << ") for " << line << endl;
91
            int fs = atoi(m[2].str().c_str());
92
            int nfs = round(fs * multiplier);
93
            char buf[20];
94
            snprintf(buf, 20, "%d", nfs);
95
            lines[ln] = m[1].str() + buf + m[3].str();
96
            //cerr << "New line: [" << lines[ln] << "]\n";
80
        }
97
        }
81
    }
98
    }
99
    
82
    string nstyle = string();
100
    string nstyle = string();
83
    for (auto& ln : lines) {
101
    for (auto& ln : lines) {
84
        nstyle += ln + "\n";
102
        nstyle += ln + "\n";
85
    }
103
    }
86
    return nstyle;
104
    return nstyle;