diff options
Diffstat (limited to 'Build/source/texk/dvisvgm/dvisvgm-src/src/dvisvgm.cpp')
-rw-r--r-- | Build/source/texk/dvisvgm/dvisvgm-src/src/dvisvgm.cpp | 284 |
1 files changed, 147 insertions, 137 deletions
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/dvisvgm.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/dvisvgm.cpp index 03d6463cf33..3502a0f1004 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/src/dvisvgm.cpp +++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/dvisvgm.cpp @@ -2,7 +2,7 @@ ** dvisvgm.cpp ** ** ** ** This file is part of dvisvgm -- a fast DVI to SVG converter ** -** Copyright (C) 2005-2016 Martin Gieseking <martin.gieseking@uos.de> ** +** Copyright (C) 2005-2017 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 ** @@ -18,44 +18,40 @@ ** along with this program; if not, see <http://www.gnu.org/licenses/>. ** *************************************************************************/ -#include <config.h> #include <clipper.hpp> #include <fstream> #include <iostream> #include <potracelib.h> #include <sstream> #include <xxhash.h> -#include "gzstream.h" -#include "CommandLine.h" -#include "DVIToSVG.h" -#include "DVIToSVGActions.h" -#include "EPSToSVG.h" -#include "FileFinder.h" -#include "FileSystem.h" -#include "Font.h" -#include "FontEngine.h" -#include "Ghostscript.h" -#include "HtmlSpecialHandler.h" -#include "Message.h" -#include "PageSize.h" -#include "PSInterpreter.h" -#include "PsSpecialHandler.h" -#include "SignalHandler.h" -#include "SVGOutput.h" -#include "System.h" +#include <zlib.h> +#include "CommandLine.hpp" +#include "DVIToSVG.hpp" +#include "DVIToSVGActions.hpp" +#include "EPSToSVG.hpp" +#include "FileFinder.hpp" +#include "FileSystem.hpp" +#include "Font.hpp" +#include "FontEngine.hpp" +#include "Ghostscript.hpp" +#include "HtmlSpecialHandler.hpp" +#include "Message.hpp" +#include "PageSize.hpp" +#include "PSInterpreter.hpp" +#include "PsSpecialHandler.hpp" +#include "SignalHandler.hpp" +#include "SVGOutput.hpp" +#include "System.hpp" +#include "version.hpp" + +#ifndef DISABLE_WOFF +#include "ffwrapper.h" +#endif using namespace std; - //////////////////////////////////////////////////////////////////////////////// -static void show_help (const CommandLine &cmd) { - cout << PACKAGE_STRING "\n\n"; - cmd.help(cmd.help_arg()); - cout << "\nCopyright (C) 2005-2016 Martin Gieseking <martin.gieseking@uos.de> \n\n"; -} - - static string remove_path (string fname) { fname = FileSystem::adaptPathSeperators(fname); size_t slashpos = fname.rfind('/'); @@ -75,22 +71,22 @@ static string ensure_suffix (string fname, bool eps) { static string get_transformation_string (const CommandLine &args) { ostringstream oss; - if (args.rotate_given()) - oss << 'R' << args.rotate_arg() << ",w/2,h/2"; - if (args.translate_given()) - oss << 'T' << args.translate_arg(); - if (args.scale_given()) - oss << 'S' << args.scale_arg(); - if (args.transform_given()) - oss << args.transform_arg(); + if (args.rotateOpt.given()) + oss << 'R' << args.rotateOpt.value() << ",w/2,h/2"; + if (args.translateOpt.given()) + oss << 'T' << args.translateOpt.value(); + if (args.scaleOpt.given()) + oss << 'S' << args.scaleOpt.value(); + if (args.transformOpt.given()) + oss << args.transformOpt.value(); return oss.str(); } static void set_libgs (CommandLine &args) { #if !defined(DISABLE_GS) && !defined(HAVE_LIBGS) - if (args.libgs_given()) - Ghostscript::LIBGS_NAME = args.libgs_arg(); + if (args.libgsOpt.given()) + Ghostscript::LIBGS_NAME = args.libgsOpt.value(); else if (getenv("LIBGS")) Ghostscript::LIBGS_NAME = getenv("LIBGS"); #endif @@ -98,13 +94,13 @@ static void set_libgs (CommandLine &args) { static bool set_cache_dir (const CommandLine &args) { - if (args.cache_given() && !args.cache_arg().empty()) { - if (args.cache_arg() == "none") + if (args.cacheOpt.given() && !args.cacheOpt.value().empty()) { + if (args.cacheOpt.value() == "none") PhysicalFont::CACHE_PATH = 0; - else if (FileSystem::exists(args.cache_arg())) - PhysicalFont::CACHE_PATH = args.cache_arg().c_str(); + else if (FileSystem::exists(args.cacheOpt.value())) + PhysicalFont::CACHE_PATH = args.cacheOpt.value().c_str(); else - Message::wstream(true) << "cache directory '" << args.cache_arg() << "' does not exist (caching disabled)\n"; + Message::wstream(true) << "cache directory '" << args.cacheOpt.value() << "' does not exist (caching disabled)\n"; } else if (const char *userdir = FileSystem::userdir()) { static string cachepath = userdir + string("/.dvisvgm/cache"); @@ -112,13 +108,13 @@ static bool set_cache_dir (const CommandLine &args) { FileSystem::mkdir(cachepath); PhysicalFont::CACHE_PATH = cachepath.c_str(); } - if (args.cache_given() && args.cache_arg().empty()) { + if (args.cacheOpt.given() && args.cacheOpt.value().empty()) { cout << "cache directory: " << (PhysicalFont::CACHE_PATH ? PhysicalFont::CACHE_PATH : "(none)") << '\n'; try { FontCache::fontinfo(PhysicalFont::CACHE_PATH, cout, true); } catch (StreamReaderException &e) { - Message::wstream(true) << "failed reading cache data"; + Message::wstream(true) << "failed reading cache data\n"; } return false; } @@ -126,6 +122,19 @@ static bool set_cache_dir (const CommandLine &args) { } +static bool set_temp_dir (const CommandLine &args) { + if (args.tmpdirOpt.given()) { + if (!args.tmpdirOpt.value().empty()) + FileSystem::TMPDIR = args.tmpdirOpt.value().c_str(); + else { + cout << "temporary folder: " << FileSystem::tmpdir() << '\n'; + return false; + } + } + return true; +} + + static bool check_bbox (const string &bboxstr) { const char *formats[] = {"none", "min", "preview", "papersize", "dvi", 0}; for (const char **p=formats; *p; ++p) @@ -156,14 +165,17 @@ static bool check_bbox (const string &bboxstr) { static void print_version (bool extended) { ostringstream oss; - oss << PACKAGE_STRING; + oss << "dvisvgm " << PROGRAM_VERSION; if (extended) { if (strlen(TARGET_SYSTEM) > 0) oss << " (" TARGET_SYSTEM ")"; int len = oss.str().length(); oss << "\n" << string(len, '-') << "\n" - "clipper: " << CLIPPER_VERSION "\n" - "freetype: " << FontEngine::version() << "\n"; + "clipper: " << CLIPPER_VERSION "\n"; +#ifndef DISABLE_WOFF + oss << "fontforge: " << ff_version() << '\n'; +#endif + oss << "freetype: " << FontEngine::version() << "\n"; Ghostscript gs; string gsver = gs.revision(true); @@ -172,9 +184,9 @@ static void print_version (bool extended) { const unsigned xxh_ver = XXH_versionNumber(); oss << #ifdef MIKTEX - "MiKTeX: " << FileFinder::version() << "\n" + "MiKTeX: " << FileFinder::instance().version() << "\n" #else - "kpathsea: " << FileFinder::version() << "\n" + "kpathsea: " << FileFinder::instance().version() << "\n" #endif "potrace: " << (strchr(potrace_version(), ' ') ? strchr(potrace_version(), ' ')+1 : "unknown") << "\n" "xxhash: " << xxh_ver/10000 << '.' << (xxh_ver/100)%100 << '.' << xxh_ver%100 << "\n" @@ -184,8 +196,8 @@ static void print_version (bool extended) { } -static void init_fontmap (const CommandLine &args) { - const char *mapseq = args.fontmap_given() ? args.fontmap_arg().c_str() : 0; +static void init_fontmap (const CommandLine &cmdline) { + const char *mapseq = cmdline.fontmapOpt.given() ? cmdline.fontmapOpt.value().c_str() : 0; bool additional = mapseq && strchr("+-=", *mapseq); if (!mapseq || additional) { const char *mapfiles[] = {"ps2pk.map", "dvipdfm.map", "psfonts.map", 0}; @@ -193,119 +205,119 @@ static void init_fontmap (const CommandLine &args) { for (const char **p=mapfiles; *p && !found; p++) found = FontMap::instance().read(*p); if (!found) - Message::wstream(true) << "none of the default map files could be found"; + Message::wstream(true) << "none of the default map files could be found\n"; } if (mapseq) FontMap::instance().read(mapseq); } -int main (int argc, char *argv[]) { - CommandLine args; - args.parse(argc, argv); - if (args.error()) - return 1; - - if (argc == 1 || args.help_given()) { - show_help(args); - return 0; +static void set_variables (const CommandLine &cmdline) { + Message::COLORIZE = cmdline.colorOpt.given(); + if (cmdline.progressOpt.given()) { + DVIToSVG::COMPUTE_PROGRESS = true; + SpecialActions::PROGRESSBAR_DELAY = cmdline.progressOpt.value(); + } + Color::SUPPRESS_COLOR_NAMES = !cmdline.colornamesOpt.given(); + SVGTree::CREATE_CSS = !cmdline.noStylesOpt.given(); + SVGTree::USE_FONTS = !cmdline.noFontsOpt.given(); + if (!SVGTree::setFontFormat(cmdline.fontFormatOpt.value())) { + string msg = "unknown font format '"+cmdline.fontFormatOpt.value()+"' (supported formats: "; + ostringstream oss; + for (const string &format : FontWriter::supportedFormats()) + oss << ", " << format; + msg += oss.str().substr(2) + ')'; + throw CL::CommandLineException(msg); } + SVGTree::CREATE_USE_ELEMENTS = cmdline.noFontsOpt.value() < 1; + SVGTree::ZOOM_FACTOR = cmdline.zoomOpt.value(); + SVGTree::RELATIVE_PATH_CMDS = cmdline.relativeOpt.given(); + SVGTree::MERGE_CHARS = !cmdline.noMergeOpt.given(); + SVGTree::ADD_COMMENTS = cmdline.commentsOpt.given(); + DVIToSVG::TRACE_MODE = cmdline.traceAllOpt.given() ? (cmdline.traceAllOpt.value() ? 'a' : 'm') : 0; + Message::LEVEL = cmdline.verbosityOpt.value(); + PhysicalFont::EXACT_BBOX = cmdline.exactOpt.given(); + PhysicalFont::KEEP_TEMP_FILES = cmdline.keepOpt.given(); + PhysicalFont::METAFONT_MAG = max(1.0, cmdline.magOpt.value()); + XMLString::DECIMAL_PLACES = max(0, min(6, cmdline.precisionOpt.value())); + PsSpecialHandler::COMPUTE_CLIPPATHS_INTERSECTIONS = cmdline.clipjoinOpt.given(); + PsSpecialHandler::SHADING_SEGMENT_OVERLAP = cmdline.gradOverlapOpt.given(); + PsSpecialHandler::SHADING_SEGMENT_SIZE = max(1, cmdline.gradSegmentsOpt.value()); + PsSpecialHandler::SHADING_SIMPLIFY_DELTA = cmdline.gradSimplifyOpt.value(); +} - Message::COLORIZE = args.color_given(); +int main (int argc, char *argv[]) { + CommandLine cmdline; try { - FileFinder::init(argv[0], "dvisvgm", !args.no_mktexmf_given()); + cmdline.parse(argc, argv); + if (argc == 1 || cmdline.helpOpt.given()) { + cmdline.help(cout, cmdline.helpOpt.value()); + return 0; + } + FileFinder::init(argv[0], "dvisvgm", !cmdline.noMktexmfOpt.given()); + set_libgs(cmdline); + if (cmdline.versionOpt.given()) { + print_version(cmdline.versionOpt.value()); + return 0; + } + if (cmdline.listSpecialsOpt.given()) { + DVIToSVG::setProcessSpecials(); + SpecialManager::instance().writeHandlerInfo(cout); + return 0; + } + if (!set_cache_dir(cmdline) || !set_temp_dir(cmdline)) + return 0; + if (cmdline.stdoutOpt.given() && cmdline.zipOpt.given()) { + Message::estream(true) << "writing SVGZ files to stdout is not supported\n"; + return 1; + } + if (!check_bbox(cmdline.bboxOpt.value())) + return 1; + if (!HtmlSpecialHandler::setLinkMarker(cmdline.linkmarkOpt.value())) + Message::wstream(true) << "invalid argument '"+cmdline.linkmarkOpt.value()+"' supplied for option --linkmark\n"; + if (argc > 1 && cmdline.filenames().size() < 1) { + Message::estream(true) << "no input file given\n"; + return 1; + } } catch (MessageException &e) { - Message::estream(true) << e.what() << '\n'; - return 0; - } - - set_libgs(args); - if (args.version_given()) { - print_version(args.version_arg()); - return 0; - } - if (args.list_specials_given()) { - DVIToSVG::setProcessSpecials(); - SpecialManager::instance().writeHandlerInfo(cout); - return 0; - } - - if (!set_cache_dir(args)) - return 0; - - if (argc > 1 && args.numFiles() < 1) { - Message::estream(true) << "no input file given\n"; - return 1; - } - - if (args.stdout_given() && args.zip_given()) { - Message::estream(true) << "writing SVGZ files to stdout is not supported\n"; + Message::estream() << e.what() << '\n'; return 1; } - if (!check_bbox(args.bbox_arg())) - return 1; - - if (args.progress_given()) { - DVIToSVG::COMPUTE_PROGRESS = args.progress_given(); - SpecialActions::PROGRESSBAR_DELAY = args.progress_arg(); - } - Color::SUPPRESS_COLOR_NAMES = !args.colornames_given(); - SVGTree::CREATE_CSS = !args.no_styles_given(); - SVGTree::USE_FONTS = !args.no_fonts_given(); - SVGTree::CREATE_USE_ELEMENTS = args.no_fonts_arg() < 1; - SVGTree::ZOOM_FACTOR = args.zoom_arg(); - SVGTree::RELATIVE_PATH_CMDS = args.relative_given(); - SVGTree::MERGE_CHARS = !args.no_merge_given(); - SVGTree::ADD_COMMENTS = args.comments_given(); - DVIToSVG::TRACE_MODE = args.trace_all_given() ? (args.trace_all_arg() ? 'a' : 'm') : 0; - Message::LEVEL = args.verbosity_arg(); - PhysicalFont::EXACT_BBOX = args.exact_given(); - PhysicalFont::KEEP_TEMP_FILES = args.keep_given(); - PhysicalFont::METAFONT_MAG = max(1.0, args.mag_arg()); - XMLString::DECIMAL_PLACES = max(0, min(6, args.precision_arg())); - if (!HtmlSpecialHandler::setLinkMarker(args.linkmark_arg())) - Message::wstream(true) << "invalid argument '"+args.linkmark_arg()+"' supplied for option --linkmark\n"; - double start_time = System::time(); - bool eps_given=false; -#ifndef DISABLE_GS - eps_given = args.eps_given(); - PsSpecialHandler::COMPUTE_CLIPPATHS_INTERSECTIONS = args.clipjoin_given(); - PsSpecialHandler::SHADING_SEGMENT_OVERLAP = args.grad_overlap_given(); - PsSpecialHandler::SHADING_SEGMENT_SIZE = max(1, args.grad_segments_arg()); - PsSpecialHandler::SHADING_SIMPLIFY_DELTA = args.grad_simplify_arg(); -#endif - string inputfile = ensure_suffix(args.file(0), eps_given); + bool eps_given = cmdline.epsOpt.given(); + string inputfile = ensure_suffix(cmdline.filenames()[0], eps_given); ifstream ifs(inputfile.c_str(), ios::binary|ios::in); if (!ifs) { Message::estream(true) << "can't open file '" << inputfile << "' for reading\n"; return 0; } try { - SVGOutput out(args.stdout_given() ? 0 : inputfile.c_str(), args.output_arg(), args.zip_given() ? args.zip_arg() : 0); + double start_time = System::time(); + set_variables(cmdline); + SVGOutput out(cmdline.stdoutOpt.given() ? nullptr : inputfile.c_str(), + cmdline.outputOpt.value(), + cmdline.zipOpt.given() ? cmdline.zipOpt.value() : 0); SignalHandler::instance().start(); -#ifndef DISABLE_GS - if (args.eps_given()) { + if (cmdline.epsOpt.given()) { EPSToSVG eps2svg(inputfile, out); eps2svg.convert(); Message::mstream().indent(0); - Message::mstream(false, Message::MC_PAGE_NUMBER) - << "file converted in " << (System::time()-start_time) << " seconds\n"; + Message::mstream(false, Message::MC_PAGE_NUMBER) << "file converted in " << (System::time()-start_time) << " seconds\n"; } - else -#endif - { - init_fontmap(args); + else { + init_fontmap(cmdline); DVIToSVG dvi2svg(ifs, out); - const char *ignore_specials = args.no_specials_given() ? (args.no_specials_arg().empty() ? "*" : args.no_specials_arg().c_str()) : 0; + const char *ignore_specials=nullptr; + if (cmdline.noSpecialsOpt.given()) + ignore_specials = cmdline.noSpecialsOpt.value().empty() ? "*" : cmdline.noSpecialsOpt.value().c_str(); dvi2svg.setProcessSpecials(ignore_specials, true); - dvi2svg.setPageTransformation(get_transformation_string(args)); - dvi2svg.setPageSize(args.bbox_arg()); + dvi2svg.setPageTransformation(get_transformation_string(cmdline)); + dvi2svg.setPageSize(cmdline.bboxOpt.value()); pair<int,int> pageinfo; - dvi2svg.convert(args.page_arg(), &pageinfo); + dvi2svg.convert(cmdline.pageOpt.value(), &pageinfo); Message::mstream().indent(0); Message::mstream(false, Message::MC_PAGE_NUMBER) << "\n" << pageinfo.first << " of " << pageinfo.second << " page"; if (pageinfo.second > 1) @@ -326,7 +338,5 @@ int main (int argc, char *argv[]) { catch (MessageException &e) { Message::estream(true) << e.what() << '\n'; } - FileFinder::finish(); return 0; } - |