--- a/HelperStructs/Style.cpp
+++ b/HelperStructs/Style.cpp
@@ -32,10 +32,6 @@
using namespace std;
-/* font-size: 10pt; */
-static const string fntszexp(R"((\s*font-size\s*:\s*)([0-9]+)(pt\s*;\s*))");
-static regex fntszregex(fntszexp);
-
QString Style::get_style(bool dark, float multiplier)
{
#if !defined(Q_OS_MACOS) && !defined(Q_OS_MAC)
@@ -60,6 +56,19 @@
}
// The hell if I'm studying yet another regexp syntax, let's go std
+
+/* font-size: 10pt; */
+static const string fntsz_exp(
+ R"((\s*font-size\s*:\s*)([0-9]+)(pt\s*;\s*))"
+ );
+static regex fntsz_regex(fntsz_exp);
+
+/* body {margin: 20px 0px 0px 0px;}*/
+static const string bdmrg_exp(
+ R"((\s*body\s*\{\s*margin:\s*)([0-9]+)(px\s*[0-9]+px\s*[0-9]+px\s*[0-9]+px\s*;\s*\}))"
+ );
+static regex bdmrg_regex(bdmrg_exp);
+
string Style::scale_fonts(const string& style, float multiplier)
{
vector<string> lines;
@@ -67,18 +76,27 @@
for (unsigned int ln = 0; ln < lines.size(); ln++) {
const string& line = lines[ln];
smatch m;
- if (regex_match(line, m, fntszregex)) {
+ if (regex_match(line, m, fntsz_regex) && m.size() == 4) {
//cerr << "Got match (sz " << m.size() << ") for " << line << endl;
- if (m.size() == 4) {
- int fs = atoi(m[2].str().c_str());
- int nfs = round(fs * multiplier);
- char buf[20];
- snprintf(buf, 20, "%d", nfs);
- lines[ln] = m[1].str() + buf + m[3].str();
- //cerr << "New line: [" << lines[ln] << "]\n";
- }
+ int fs = atoi(m[2].str().c_str());
+ int nfs = round(fs * multiplier);
+ char buf[20];
+ snprintf(buf, 20, "%d", nfs);
+ lines[ln] = m[1].str() + buf + m[3].str();
+ //cerr << "New line: [" << lines[ln] << "]\n";
+ }
+ m = smatch();
+ if (regex_match(line, m, bdmrg_regex) && m.size() == 4) {
+ //cerr << "Got match (sz " << m.size() << ") for " << line << endl;
+ int fs = atoi(m[2].str().c_str());
+ int nfs = round(fs * multiplier);
+ char buf[20];
+ snprintf(buf, 20, "%d", nfs);
+ lines[ln] = m[1].str() + buf + m[3].str();
+ //cerr << "New line: [" << lines[ln] << "]\n";
}
}
+
string nstyle = string();
for (auto& ln : lines) {
nstyle += ln + "\n";