diff options
author | Norbert Preining <norbert@preining.info> | 2023-01-12 03:01:29 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2023-01-12 03:01:29 +0000 |
commit | 6a7900c93acc16d1bbd2f1e26286c7dd7387e6c0 (patch) | |
tree | 76196287351cba68a51934c49468bf1a7846aa76 /dviware/dvisvgm/src/ImageToSVG.cpp | |
parent | c1c19023b4b1d43cb874f84df5102b485853e672 (diff) |
CTAN sync 202301120301
Diffstat (limited to 'dviware/dvisvgm/src/ImageToSVG.cpp')
-rw-r--r-- | dviware/dvisvgm/src/ImageToSVG.cpp | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/dviware/dvisvgm/src/ImageToSVG.cpp b/dviware/dvisvgm/src/ImageToSVG.cpp index c38d3cc9b9..990647a008 100644 --- a/dviware/dvisvgm/src/ImageToSVG.cpp +++ b/dviware/dvisvgm/src/ImageToSVG.cpp @@ -2,7 +2,7 @@ ** ImageToSVG.cpp ** ** ** ** This file is part of dvisvgm -- a fast DVI to SVG converter ** -** Copyright (C) 2005-2022 Martin Gieseking <martin.gieseking@uos.de> ** +** Copyright (C) 2005-2023 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 ** @@ -36,18 +36,17 @@ using namespace std; +ImageToSVG::ImageToSVG (std::string fname, SVGOutputBase &out) + : _fname(std::move(fname)), _out(out), _gsVersion(Ghostscript().revision()) +{ +} + + void ImageToSVG::checkGSAndFileFormat () { - if (!_haveGS) { -#ifdef HAVE_LIBGS - _haveGS = true; -#else - _haveGS = Ghostscript().available(); -#endif - if (!_haveGS) - throw MessageException("Ghostscript is required to process "+imageFormat()+" files"); - if (!imageIsValid()) - throw MessageException("invalid "+imageFormat()+" file"); - } + if (!_gsVersion) + throw MessageException("Ghostscript is required to process "+imageFormat()+" files"); + if (!imageIsValid()) + throw MessageException("invalid "+imageFormat()+" file"); } @@ -59,7 +58,7 @@ void ImageToSVG::convert (int pageno) { Message::mstream().indent(0); Message::mstream(false, Message::MC_PAGE_NUMBER) << "processing " << imageFormat() << " file\n"; Message::mstream().indent(1); - _svg.newPage(1); + _svg.newPage(pageno); // create a psfile special and forward it to the PsSpecialHandler stringstream ss; ss << "\"" << _fname << "\" " @@ -69,7 +68,7 @@ void ImageToSVG::convert (int pageno) { "ury=" << bbox.maxY(); _currentPageNumber = pageno; if (!isSinglePageFormat()) - ss << " page=" << pageno; + ss << " page=" << pageno << " proc=gs"; try { _psHandler.process(psSpecialCmd(), ss, *this); } @@ -77,6 +76,11 @@ void ImageToSVG::convert (int pageno) { progress(nullptr); // remove progress message throw; } + writeSVG(pageno); +} + + +void ImageToSVG::writeSVG (int pageno) { progress(nullptr); Matrix matrix = getUserMatrix(_bbox); // output SVG file @@ -87,6 +91,7 @@ void ImageToSVG::convert (int pageno) { _svg.appendToDoc(util::make_unique<XMLComment>(" This file was generated by dvisvgm " + string(PROGRAM_VERSION) + " ")); bool success = _svg.write(_out.getPageStream(pageno, totalPageCount())); string svgfname = _out.filepath(pageno, totalPageCount()).shorterAbsoluteOrRelative(); + _out.finish(); if (svgfname.empty()) svgfname = "<stdout>"; if (!success) @@ -94,10 +99,11 @@ void ImageToSVG::convert (int pageno) { else { const double bp2pt = 72.27/72; const double bp2mm = 25.4/72; - Message::mstream(false, Message::MC_PAGE_SIZE) << "graphic size: " << XMLString(_bbox.width()*bp2pt) << "pt" - " x " << XMLString(_bbox.height()*bp2pt) << "pt" - " (" << XMLString(_bbox.width()*bp2mm) << "mm" - " x " << XMLString(_bbox.height()*bp2mm) << "mm)\n"; + Message::mstream(false,Message::MC_PAGE_SIZE) + << "graphic size: " << XMLString(_bbox.width()*bp2pt) << "pt" + << " x " << XMLString(_bbox.height()*bp2pt) << "pt" + << " (" << XMLString(_bbox.width()*bp2mm) << "mm" + << " x " << XMLString(_bbox.height()*bp2mm) << "mm)\n"; Message::mstream(false, Message::MC_PAGE_WRITTEN) << "output written to " << svgfname << '\n'; } _bbox.invalidate(); |