diff options
| author | Martin Owens <doctormo@gmail.com> | 2019-03-06 21:07:14 +0000 |
|---|---|---|
| committer | Martin Owens <doctormo@gmail.com> | 2019-03-06 21:07:14 +0000 |
| commit | be8fe9e27bffe527d2ef2817a60397ff56194d59 (patch) | |
| tree | 206c3789089c3a640a709d1f0be7f5171a940dc7 /src | |
| parent | Merge: Fix use of uninitialized variable (diff) | |
| download | inkscape-be8fe9e27bffe527d2ef2817a60397ff56194d59.tar.gz inkscape-be8fe9e27bffe527d2ef2817a60397ff56194d59.zip | |
Fix wmf/emf file opening and embed missing font config data.
Diffstat (limited to 'src')
| -rw-r--r-- | src/extension/internal/emf-print.cpp | 2 | ||||
| -rw-r--r-- | src/extension/internal/metafile-print.cpp | 79 | ||||
| -rw-r--r-- | src/extension/internal/metafile-print.h | 7 | ||||
| -rw-r--r-- | src/extension/internal/wmf-print.cpp | 2 |
4 files changed, 25 insertions, 65 deletions
diff --git a/src/extension/internal/emf-print.cpp b/src/extension/internal/emf-print.cpp index 1c294fcb7..880cd00d2 100644 --- a/src/extension/internal/emf-print.cpp +++ b/src/extension/internal/emf-print.cpp @@ -2180,8 +2180,6 @@ unsigned int PrintEmf::text(Inkscape::Extension::Print * /*mod*/, char const *te void PrintEmf::init() { - _load_ppt_fontfix_data(); - /* EMF print */ Inkscape::Extension::build_from_mem( "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n" diff --git a/src/extension/internal/metafile-print.cpp b/src/extension/internal/metafile-print.cpp index 6270f63e4..0935d3d8d 100644 --- a/src/extension/internal/metafile-print.cpp +++ b/src/extension/internal/metafile-print.cpp @@ -31,9 +31,6 @@ namespace Inkscape { namespace Extension { namespace Internal { -bool PrintMetafile::_ppt_fontfix_read = false; -PrintMetafile::FontfixMap PrintMetafile::_ppt_fixable_fonts; - PrintMetafile::~PrintMetafile() { #ifndef G_OS_WIN32 @@ -43,6 +40,28 @@ PrintMetafile::~PrintMetafile() return; } +static std::map<Glib::ustring, FontfixParams> _ppt_fixable_fonts = { + {{"Arial"}, { 0.05, -0.055, -0.065}}, + {{"Times New Roman"}, { 0.05, -0.055, -0.065}}, + {{"Lucida Sans"}, {-0.025, -0.055, -0.065}}, + {{"Sans"}, { 0.05, -0.055, -0.065}}, + {{"Microsoft Sans Serif"}, {-0.05, -0.055, -0.065}}, + {{"Serif"}, { 0.05, -0.055, -0.065}}, + {{"Garamond"}, { 0.05, -0.055, -0.065}}, + {{"Century Schoolbook"}, { 0.25, 0.025, 0.025}}, + {{"Verdana"}, { 0.025, 0.0, 0.0}}, + {{"Tahoma"}, { 0.045, 0.025, 0.025}}, + {{"Symbol"}, { 0.025, 0.0, 0.0}}, + {{"Wingdings"}, { 0.05, 0.0, 0.0}}, + {{"Zapf Dingbats"}, { 0.025, 0.0, 0.0}}, + {{"Convert To Symbol"}, { 0.025, 0.0, 0.0}}, + {{"Convert To Wingdings"}, { 0.05, 0.0, 0.0}}, + {{"Convert To Zapf Dingbats"}, { 0.025, 0.0, 0.0}}, + {{"Sylfaen"}, { 0.1, 0.0, 0.0}}, + {{"Palatino Linotype"}, { 0.175, 0.125, 0.125}}, + {{"Segoe UI"}, { 0.1, 0.0, 0.0}}, +}; + bool PrintMetafile::textToPath(Inkscape::Extension::Print *ext) { return ext->get_param_bool("textToPath"); @@ -66,60 +85,12 @@ unsigned int PrintMetafile::release(Inkscape::Extension::Print * /*mod*/) return 1; } -bool PrintMetafile::_load_ppt_fontfix_data() //this is not called by any other source files -{ - static bool ppt_fontfix_available = false; - - if (_ppt_fontfix_read) return ppt_fontfix_available; - _ppt_fontfix_read = true; - - // add default entry - _ppt_fixable_fonts.insert(std::make_pair(Glib::ustring(""), FontfixParams())); - - std::string fontfix_path = Glib::build_filename(INKSCAPE_EXTENSIONDIR, "fontfix.conf"); - std::ifstream fontfix_file(fontfix_path.c_str(), std::ios::in); - - if (!fontfix_file.is_open()) { - g_warning("Unable to open PowerPoint fontfix file: %s\n" - "PowerPoint ungrouping compensation in WMF/EMF export will not be available.", - fontfix_path.c_str()); - return (ppt_fontfix_available = false); - } - - char *oldlocale = g_strdup(setlocale(LC_NUMERIC, nullptr)); - setlocale(LC_NUMERIC, "C"); - - std::string instr; - while (std::getline(fontfix_file, instr)) { - if (instr[0] == '#') { - continue; - } - // not a comment, get the 4 values from the line - FontfixParams params; - char fontname[128]; - int elements = sscanf(instr.c_str(), "%lf %lf %lf %127[^\n]", - ¶ms.f1, ¶ms.f2, ¶ms.f3, &fontname[0]); - if (elements != 4) { - g_warning("Malformed line in %s: %s\n", fontfix_path.c_str(), instr.c_str()); - continue; - } - _ppt_fixable_fonts.insert(std::make_pair(Glib::ustring(fontname), params)); - } - fontfix_file.close(); // not strictly necessary - - setlocale(LC_NUMERIC, oldlocale); - g_free(oldlocale); - return (ppt_fontfix_available = true); -} - // Finds font fix parameters for the given fontname. void PrintMetafile::_lookup_ppt_fontfix(Glib::ustring const &fontname, FontfixParams ¶ms) { - if (!_ppt_fontfix_read) _load_ppt_fontfix_data(); - - FontfixMap::iterator f = _ppt_fixable_fonts.find(fontname); - if (f != _ppt_fixable_fonts.end()) { - params = f->second; + auto it = _ppt_fixable_fonts.find(fontname); + if (it!=_ppt_fixable_fonts.end()) { + params = it->second; } } diff --git a/src/extension/internal/metafile-print.h b/src/extension/internal/metafile-print.h index d3f525d7e..3aeb0a076 100644 --- a/src/extension/internal/metafile-print.h +++ b/src/extension/internal/metafile-print.h @@ -38,7 +38,6 @@ struct FontfixParams { double f1; //Vertical (rotating) offset factor (* font height) double f2; //Vertical (nonrotating) offset factor (* font height) double f3; //Horizontal (nonrotating) offset factor (* font height) - FontfixParams() : f1(0), f2(0), f3(0) {} }; class PrintMetafile @@ -84,7 +83,6 @@ protected: GRADVALUES gv; - static bool _load_ppt_fontfix_data(); static void _lookup_ppt_fontfix(Glib::ustring const &fontname, FontfixParams &); static U_COLORREF _gethexcolor(uint32_t color); static uint32_t _translate_weight(unsigned inkweight); @@ -109,11 +107,6 @@ protected: virtual void destroy_brush() = 0; virtual int create_pen(SPStyle const *style, const Geom::Affine &transform) = 0; virtual void destroy_pen() = 0; - -private: - typedef std::map<Glib::ustring, FontfixParams> FontfixMap; - static FontfixMap _ppt_fixable_fonts; - static bool _ppt_fontfix_read; }; } // namespace Internal diff --git a/src/extension/internal/wmf-print.cpp b/src/extension/internal/wmf-print.cpp index 7d13e218a..7c7e2572e 100644 --- a/src/extension/internal/wmf-print.cpp +++ b/src/extension/internal/wmf-print.cpp @@ -1563,8 +1563,6 @@ unsigned int PrintWmf::text(Inkscape::Extension::Print * /*mod*/, char const *te void PrintWmf::init() { - _load_ppt_fontfix_data(); - /* WMF print */ Inkscape::Extension::build_from_mem( "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n" |
