diff options
author | Norbert Preining <norbert@preining.info> | 2020-03-16 03:01:06 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2020-03-16 03:01:06 +0000 |
commit | d50a41b6ab3d05fe5605a3a3b50ff68f61059296 (patch) | |
tree | 29468e087e9c19acf30b392dc705a54288d79137 /dviware/dvisvgm/src/MetafontWrapper.cpp | |
parent | 87cddce361c3b477029d13b27bdaa57190b2d74b (diff) |
CTAN sync 202003160301
Diffstat (limited to 'dviware/dvisvgm/src/MetafontWrapper.cpp')
-rw-r--r-- | dviware/dvisvgm/src/MetafontWrapper.cpp | 62 |
1 files changed, 49 insertions, 13 deletions
diff --git a/dviware/dvisvgm/src/MetafontWrapper.cpp b/dviware/dvisvgm/src/MetafontWrapper.cpp index 202b65d6ec..11667fb5e7 100644 --- a/dviware/dvisvgm/src/MetafontWrapper.cpp +++ b/dviware/dvisvgm/src/MetafontWrapper.cpp @@ -2,7 +2,7 @@ ** MetafontWrapper.cpp ** ** ** ** This file is part of dvisvgm -- a fast DVI to SVG converter ** -** Copyright (C) 2005-2019 Martin Gieseking <martin.gieseking@uos.de> ** +** Copyright (C) 2005-2020 Martin Gieseking <martin.gieseking@uos.de> ** ** ** ** This program is free software; you can redistribute it and/or ** ** modify it under the terms of the GNU General Public License as ** @@ -79,18 +79,8 @@ bool MetafontWrapper::call (const string &mode, double mag) { string mf_messages; mf_process.run(_dir, &mf_messages); - // get resolution value from stdout created by above MF command - char buf[256]; - istringstream iss(mf_messages); - int resolution = 0; - while (iss) { - iss.getline(buf, sizeof(buf)); - string line = buf; - if (line.substr(0, 3) == ">> ") { - resolution = stoi(line.substr(3)); - break; - } - } + int resolution = getResolution(mf_messages); + // compose expected name of GF file (see Metafont Book, p. 324) string gfname = _dir + _fontname + "."; if (resolution > 0) @@ -101,6 +91,52 @@ bool MetafontWrapper::call (const string &mode, double mag) { } +/** Returns the resolution applied to a GF file generated by Metafont. Since the resolution + * is part of the filename suffix, we need this value in order to address the file. + * @param[in] mfMessage output written to stdout by Metafont + * @return the resolution (>0 on success, 0 otherwise) */ +int MetafontWrapper::getResolution (const string &mfMessage) const { + int res = 0; + char buf[256]; + if (!mfMessage.empty()) { + // try get resolution value written to stdout by above MF command + istringstream iss(mfMessage); + while (iss) { + iss.getline(buf, sizeof(buf)); + string line = buf; + if (line.substr(0, 3) == ">> ") { + res = stoi(line.substr(3)); + break; + } + } + } + // couldn't read resolution from stdout, try to get it from log file + if (res == 0) { + ifstream ifs(_dir+_fontname+".log"); + while (ifs) { + ifs.getline(buf, sizeof(buf)); + string line = buf; + if (line.substr(0, 18) == "Output written on ") { + line = line.substr(18); + size_t pos = line.find(' '); + line = line.substr(0, pos); + pos = line.rfind('.'); + if (pos != string::npos && line.substr(line.length()-2) == "gf") { + line.pop_back(); + line.pop_back(); + try { + res = stoi(line.substr(pos+1)); + } + catch (...) { + } + } + } + } + } + return res; +} + + /** Calls Metafont if output files (tfm and gf) don't already exist. * @param[in] mode Metafont mode to be used (e.g. 'ljfour') * @param[in] mag magnification factor |