summaryrefslogtreecommitdiff
path: root/Build/source/texk/dvisvgm/dvisvgm-src/src
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2018-08-31 23:11:41 +0000
committerKarl Berry <karl@freefriends.org>2018-08-31 23:11:41 +0000
commit8ba2cf02688200d56e4fe0839a451ef832ce15b6 (patch)
treefcec1a50903a6e5b939859a1f92e15342636f290 /Build/source/texk/dvisvgm/dvisvgm-src/src
parent5d0960aa5419651a9c9b6503e44be2f098831ef1 (diff)
dvisvgm 2.5, including potrace now bundled with dvisvgm instead of under libs/
git-svn-id: svn://tug.org/texlive/trunk@48527 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/dvisvgm/dvisvgm-src/src')
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/BasicDVIReader.hpp13
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/BoundingBox.cpp2
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/DVIToSVG.cpp26
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/DVIToSVG.hpp3
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/DVIToSVGActions.cpp3
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/DVIToSVGActions.hpp2
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/EPSToSVG.hpp4
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/FileFinder.cpp3
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/FilePath.cpp17
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/FilePath.hpp3
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/Ghostscript.cpp28
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/ImageToSVG.cpp100
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/ImageToSVG.hpp18
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/Length.cpp16
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/Length.hpp6
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/Makefile.am44
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/Makefile.in83
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/PDFToSVG.hpp16
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/PSInterpreter.cpp30
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/PSInterpreter.hpp4
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/PsSpecialHandler.cpp30
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/PsSpecialHandler.hpp5
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/SourceInput.cpp25
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/SpecialActions.hpp3
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/dvisvgm.cpp37
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/psdefs.cpp8
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/version.hpp2
27 files changed, 387 insertions, 144 deletions
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/BasicDVIReader.hpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/BasicDVIReader.hpp
index f3fc8c7d37c..82b9ee0dade 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/BasicDVIReader.hpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/BasicDVIReader.hpp
@@ -21,21 +21,19 @@
#ifndef BASICDVIREADER_HPP
#define BASICDVIREADER_HPP
+#include "Matrix.hpp"
#include "MessageException.hpp"
#include "StreamReader.hpp"
-struct DVIException : public MessageException
-{
+struct DVIException : public MessageException {
explicit DVIException (const std::string &msg) : MessageException(msg) {}
};
-struct InvalidDVIFileException : public DVIException
-{
+struct InvalidDVIFileException : public DVIException {
explicit InvalidDVIFileException (const std::string &msg) : DVIException(msg) {}
};
-class Matrix;
/** This class provides the basic functionality to read a DVI file.
* It just skips all DVI commands and apply any semantic to it. The latter must
@@ -44,8 +42,7 @@ class Matrix;
* require to read and evaluate the correct portion of data from the DVI stream.
* Since the DVI commands are almost skipped by advancing the file pointer,
* running through a DVI file is pretty fast. */
-class BasicDVIReader : public StreamReader
-{
+class BasicDVIReader : public StreamReader {
protected:
using CommandHandler = void (BasicDVIReader::*)(int);
enum DVIVersion {DVI_NONE=0, DVI_STANDARD=2, DVI_PTEX=3, DVI_XDV5=5, DVI_XDV6=6, DVI_XDV7=7};
@@ -62,7 +59,7 @@ class BasicDVIReader : public StreamReader
virtual void translateToX (double x) {}
virtual void translateToY (double y) {}
virtual int stackDepth () const {return 0;}
- virtual void getPageTransformation (Matrix &matrix) const {}
+ virtual Matrix getPageTransformation () const {return Matrix(1);}
virtual unsigned currentPageNumber () const {return 0;}
protected:
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/BoundingBox.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/BoundingBox.cpp
index ebdbd485d6a..65e2405eae5 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/BoundingBox.cpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/BoundingBox.cpp
@@ -257,6 +257,8 @@ ostream& BoundingBox::write (ostream &os) const {
os << '(' << _ulx << ", " << _uly << ", " << _lrx << ", " << _lry << ')';
if (!_valid)
os << " (invalid)";
+ else if (_locked)
+ os << " (locked)";
return os;
}
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/DVIToSVG.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/DVIToSVG.cpp
index 79744656f3a..9a0ff50bf82 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/DVIToSVG.cpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/DVIToSVG.cpp
@@ -187,9 +187,8 @@ void DVIToSVG::leaveEndPage (unsigned) {
// set bounding box and apply page transformations
BoundingBox bbox = _actions->bbox(); // bounding box derived from the DVI commands executed
if (_bboxFormatString == "min" || _bboxFormatString == "preview" || _bboxFormatString == "papersize") {
- Matrix matrix;
- getPageTransformation(matrix);
- bbox.transform(matrix);
+ bbox.unlock();
+ bbox.transform(getPageTransformation());
}
else if (_bboxFormatString == "dvi") {
// center page content
@@ -216,9 +215,7 @@ void DVIToSVG::leaveEndPage (unsigned) {
vector<Length> lengths = BoundingBox::extractLengths(_bboxFormatString);
if (lengths.size() == 1 || lengths.size() == 2) { // relative box size?
// apply the page transformation and adjust the bbox afterwards
- Matrix matrix;
- getPageTransformation(matrix);
- bbox.transform(matrix);
+ bbox.transform(getPageTransformation());
}
bbox.set(lengths);
}
@@ -242,25 +239,24 @@ void DVIToSVG::leaveEndPage (unsigned) {
}
-void DVIToSVG::getPageTransformation(Matrix &matrix) const {
- if (_transCmds.empty())
- matrix.set(1); // unity matrix
- else {
+Matrix DVIToSVG::getPageTransformation () const {
+ Matrix matrix(1); // unity matrix
+ if (!_transCmds.empty()) {
Calculator calc;
if (_actions) {
- const double bp2pt = 72.27/72;
+ const double bp2pt = (1_bp).pt();
BoundingBox &bbox = _actions->bbox();
calc.setVariable("ux", bbox.minX()*bp2pt);
calc.setVariable("uy", bbox.minY()*bp2pt);
calc.setVariable("w", bbox.width()*bp2pt);
calc.setVariable("h", bbox.height()*bp2pt);
}
- calc.setVariable("pt", 1);
- calc.setVariable("in", 72.27);
- calc.setVariable("cm", 72.27/2.54);
- calc.setVariable("mm", 72.27/25.4);
+ // add constants for length units to calculator
+ for (auto unit : Length::getUnits())
+ calc.setVariable(unit.first, Length(1, unit.second).pt());
matrix.set(_transCmds, calc);
}
+ return matrix;
}
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/DVIToSVG.hpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/DVIToSVG.hpp
index 5b5c619be02..3c9100a0ec7 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/DVIToSVG.hpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/DVIToSVG.hpp
@@ -27,7 +27,6 @@
#include "SVGTree.hpp"
struct DVIActions;
-class Matrix;
struct SVGOutputBase;
class DVIToSVG : public DVIReader {
@@ -36,7 +35,7 @@ class DVIToSVG : public DVIReader {
void convert (const std::string &range, std::pair<int,int> *pageinfo=0);
void setPageSize (const std::string &format) {_bboxFormatString = format;}
void setPageTransformation (const std::string &cmds) {_transCmds = cmds;}
- void getPageTransformation (Matrix &matrix) const override;
+ Matrix getPageTransformation () const override;
void translateToX (double x) override {_tx = x-dviState().h-_tx;}
void translateToY (double y) override {_ty = y-dviState().v-_ty;}
double getXPos() const override {return dviState().h+_tx;}
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/DVIToSVGActions.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/DVIToSVGActions.cpp
index d9af5936bc5..efe43be851f 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/DVIToSVGActions.cpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/DVIToSVGActions.cpp
@@ -228,8 +228,7 @@ void DVIToSVGActions::beginPage (unsigned pageno, const vector<int32_t>&) {
/** This method is called when an "end of page (eop)" command was found in the DVI file. */
void DVIToSVGActions::endPage (unsigned pageno) {
SpecialManager::instance().notifyEndPage(pageno, *this);
- Matrix matrix;
- _dvireader->getPageTransformation(matrix);
+ Matrix matrix = _dvireader->getPageTransformation();
_svg.transformPage(matrix);
if (_bgcolor != Color::TRANSPARENT) {
// create a rectangle filled with the background color
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/DVIToSVGActions.hpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/DVIToSVGActions.hpp
index 8b3ef317759..7d46fb7b10e 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/DVIToSVGActions.hpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/DVIToSVGActions.hpp
@@ -50,7 +50,7 @@ class DVIToSVGActions : public DVIActions, public SpecialActions {
void setColor (const Color &color) override {_svg.setColor(color);}
void setMatrix (const Matrix &m) override {_svg.setMatrix(m);}
const Matrix& getMatrix () const override {return _svg.getMatrix();}
- void getPageTransform (Matrix &matrix) const override {_dvireader->getPageTransformation(matrix);}
+ Matrix getPageTransformation () const override {return _dvireader->getPageTransformation();}
Color getColor () const override {return _svg.getColor();}
int getDVIStackDepth() const override {return _dvireader->stackDepth();}
unsigned getCurrentPageNumber() const override {return _dvireader->currentPageNumber();}
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/EPSToSVG.hpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/EPSToSVG.hpp
index 8e7dd29f9b2..fc3ff883666 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/EPSToSVG.hpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/EPSToSVG.hpp
@@ -24,9 +24,13 @@
#include "EPSFile.hpp"
#include "ImageToSVG.hpp"
+class PsSpecialHandler;
+
class EPSToSVG : public ImageToSVG {
public:
EPSToSVG (const std::string &fname, SVGOutputBase &out) : ImageToSVG(fname, out) {}
+ bool isSinglePageFormat() const override {return true;}
+ int totalPageCount() override {return 1;}
protected:
std::string imageFormat () const override {return "EPS";}
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/FileFinder.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/FileFinder.cpp
index 405a6f2da21..649ea5ea999 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/FileFinder.cpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/FileFinder.cpp
@@ -63,9 +63,6 @@ FileFinder::FileFinder () {
kpse_set_program_enabled(kpse_tfm_format, 1, kpse_src_env);
kpse_set_program_enabled(kpse_mf_format, 1, kpse_src_env);
kpse_make_tex_discard_errors = true; // suppress messages from mktexFOO tools
-#ifdef TEXLIVEWIN32
- texlive_gs_init();
-#endif
#endif
}
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/FilePath.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/FilePath.cpp
index f7fe431cf16..638689f6b57 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/FilePath.cpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/FilePath.cpp
@@ -78,14 +78,6 @@ bool FilePath::Directory::operator == (const Directory &dir) const {
}
-/** Constructs a FilePath object from a given path. Relative paths are
- * relative to the current working directory.
- * @param[in] path absolute or relative path to a file or directory */
-FilePath::FilePath (const string &path) {
- init(path, !FileSystem::isDirectory(path), FileSystem::getcwd());
-}
-
-
/** Constructs a FilePath object.
* @param[in] path absolute or relative path to a file or directory
* @param[in] isfile true if 'path' references a file, false if a directory is referenced
@@ -95,11 +87,20 @@ FilePath::FilePath (const string &path, bool isfile, const string &current_dir)
}
+/** Assigns a new path. Relative paths are relative to the current working directory.
+ * @param[in] path absolute or relative path to a file or directory */
+void FilePath::set(const string &path) {
+ init(path, !FileSystem::isDirectory(path), FileSystem::getcwd());
+}
+
+
/** Initializes a FilePath object. This method should be called by the constructors only.
* @param[in] path absolute or relative path to a file or directory
* @param[in] isfile true if 'path' references a file, false if a directory is referenced
* @param[in] current_dir if 'path' is a relative path expression it will be related to 'current_dir' */
void FilePath::init (string path, bool isfile, string current_dir) {
+ _dirs.clear();
+ _fname.clear();
single_slashes(path);
single_slashes(current_dir);
#ifdef _WIN32
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/FilePath.hpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/FilePath.hpp
index 385e1d2fb4b..a1e59a5db36 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/FilePath.hpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/FilePath.hpp
@@ -39,9 +39,10 @@ class FilePath {
};
public:
- FilePath (const std::string &path);
+ FilePath (const std::string &path) {set(path);}
FilePath (const std::string &path, bool isfile) : FilePath(path, isfile, "") {}
FilePath (const std::string &path, bool isfile, const std::string &current_dir);
+ void set (const std::string &path);
std::string absolute (bool with_filename=true) const;
std::string relative (std::string reldir="", bool with_filename=true) const;
std::string basename () const;
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/Ghostscript.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/Ghostscript.cpp
index dab7175e4fd..cbb3589efc8 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/Ghostscript.cpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/Ghostscript.cpp
@@ -19,7 +19,9 @@
*************************************************************************/
#include <config.h>
+#include "FilePath.hpp"
#include "Ghostscript.hpp"
+#include "utility.hpp"
#if !defined(DISABLE_GS)
#include <cstring>
#include <iomanip>
@@ -77,7 +79,27 @@ static string get_path_from_registry () {
#endif // RRF_RT_REG_SZ
return "";
}
-#endif // _WIN32
+#endif // _WIN32
+
+#if defined(_WIN32) && !defined(_WIN64)
+static string get_gsdll32 () {
+ string pathstr;
+#if defined(TEXLIVEWIN32)
+ char exepath[256];
+ if (GetModuleFileNameA(NULL, exepath, 256)) {
+ FilePath path(exepath);
+ path.set(path.absolute(false)+"/../../tlpkg/tlgs");
+ pathstr = util::replace(path.absolute(false)+"/", "/", "\\");
+ string envvar = "GS_LIB=";
+ for (string dirs : {"lib", "fonts", "Resource\\Init", "Resource", "kanji"})
+ envvar += pathstr+dirs+";";
+ _putenv(envvar.c_str());
+ pathstr += "bin\\";
+ }
+#endif
+ return pathstr+"gsdll32.dll";
+}
+#endif // _WIN32 && !_WIN64
/** Try to detect name of the Ghostscript shared library depending on the user settings.
@@ -101,11 +123,11 @@ static string get_libgs (const string &fname) {
string gsdll_path = get_path_from_registry();
if (!gsdll_path.empty())
return gsdll_path;
-#endif
+#endif //_WIN32
#if defined(_WIN64)
return "gsdll64.dll";
#elif defined(_WIN32)
- return "gsdll32.dll";
+ return get_gsdll32();
#else
// try to find libgs.so.X on the user's system
const int abi_min=7, abi_max=9; // supported libgs ABI versions
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/ImageToSVG.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/ImageToSVG.cpp
index 72c134d5a4e..4a14603a996 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/ImageToSVG.cpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/ImageToSVG.cpp
@@ -21,9 +21,11 @@
#include <config.h>
#include <fstream>
#include <sstream>
+#include "Calculator.hpp"
#include "ImageToSVG.hpp"
#include "Message.hpp"
#include "MessageException.hpp"
+#include "PageRanges.hpp"
#include "PsSpecialHandler.hpp"
#include "SVGOutput.hpp"
#include "System.hpp"
@@ -33,17 +35,27 @@
using namespace std;
-void ImageToSVG::convert () {
-#ifndef HAVE_LIBGS
- if (!Ghostscript().available())
- throw MessageException("Ghostscript is required to process "+imageFormat()+" files");
+void ImageToSVG::checkGSAndFileFormat () {
+ if (!_haveGS) {
+#ifdef HAVE_LIBGS
+ _haveGS = true;
+#else
+ _haveGS = Ghostscript().available();
#endif
- if (!imageIsValid())
- throw PSException("invalid "+imageFormat()+" file");
+ if (!_haveGS)
+ throw MessageException("Ghostscript is required to process "+imageFormat()+" files");
+ if (!imageIsValid())
+ throw MessageException("invalid "+imageFormat()+" file");
+ }
+}
+
+void ImageToSVG::convert (int pageno) {
+ checkGSAndFileFormat();
BoundingBox bbox = imageBBox();
if (bbox.valid() && (bbox.width() == 0 || bbox.height() == 0))
Message::wstream(true) << "bounding box of " << imageFormat() << " file is empty\n";
+ Message::mstream().indent(0);
Message::mstream(false, Message::MC_PAGE_NUMBER) << "processing " << imageFormat() << " file\n";
Message::mstream().indent(1);
_svg.newPage(1);
@@ -54,21 +66,25 @@ void ImageToSVG::convert () {
"lly=" << bbox.minY() << " "
"urx=" << bbox.maxX() << " "
"ury=" << bbox.maxY();
+ if (!isSinglePageFormat())
+ ss << " page=" << pageno;
try {
- PsSpecialHandler pshandler;
- pshandler.process(psSpecialCmd(), ss, *this);
+ _psHandler.process(psSpecialCmd(), ss, *this);
}
catch (...) {
progress(0); // remove progress message
throw;
}
progress(0);
+ Matrix matrix = getUserMatrix(_bbox);
// output SVG file
_svg.removeRedundantElements();
+ _svg.transformPage(matrix);
+ _bbox.transform(matrix);
_svg.setBBox(_bbox);
_svg.appendToDoc(util::make_unique<XMLCommentNode>(" This file was generated by dvisvgm " + string(PROGRAM_VERSION) + " "));
- bool success = _svg.write(_out.getPageStream(1, 1));
- string svgfname = _out.filename(1, 1);
+ bool success = _svg.write(_out.getPageStream(pageno, totalPageCount()));
+ string svgfname = _out.filename(pageno, totalPageCount());
if (svgfname.empty())
svgfname = "<stdout>";
if (!success)
@@ -82,6 +98,49 @@ void ImageToSVG::convert () {
" x " << XMLString(_bbox.height()*bp2mm) << "mm)\n";
Message::mstream(false, Message::MC_PAGE_WRITTEN) << "output written to " << svgfname << '\n';
}
+ _svg.reset();
+}
+
+
+void ImageToSVG::convert (int firstPage, int lastPage, pair<int,int> *pageinfo) {
+ checkGSAndFileFormat();
+ int pageCount = 1; // number of pages converted
+ if (isSinglePageFormat())
+ convert(1);
+ else {
+ if (firstPage > lastPage)
+ swap(firstPage, lastPage);
+ firstPage = max(1, firstPage);
+ if (firstPage > totalPageCount())
+ pageCount = 0;
+ else {
+ lastPage = min(totalPageCount(), lastPage);
+ pageCount = lastPage-firstPage+1;
+ for (int i=firstPage; i <= lastPage; i++)
+ convert(i);
+ }
+ }
+ if (pageinfo) {
+ pageinfo->first = pageCount;
+ pageinfo->second = totalPageCount();
+ }
+}
+
+
+void ImageToSVG::convert (const std::string &rangestr, pair<int,int> *pageinfo) {
+ checkGSAndFileFormat();
+ PageRanges ranges;
+ if (!ranges.parse(rangestr, totalPageCount()))
+ throw MessageException("invalid page range format");
+
+ int pageCount=0; // number of pages converted
+ for (const auto &range : ranges) {
+ convert(range.first, range.second, pageinfo);
+ if (pageinfo)
+ pageCount += pageinfo->first;
+ }
+ if (pageinfo)
+ pageinfo->first = pageCount;
}
@@ -116,3 +175,24 @@ void ImageToSVG::progress (const char *id) {
time = System::time();
}
}
+
+
+/** Returns the matrix describing the graphics transformations
+ * given by the user in terms of transformation commands.
+ * @param[in] bbox bounding box of the graphics to transform */
+Matrix ImageToSVG::getUserMatrix (const BoundingBox &bbox) const {
+ Matrix matrix(1);
+ if (!_transCmds.empty()) {
+ const double bp2pt = (1_bp).pt();
+ Calculator calc;
+ calc.setVariable("ux", bbox.minX()*bp2pt);
+ calc.setVariable("uy", bbox.minY()*bp2pt);
+ calc.setVariable("w", bbox.width()*bp2pt);
+ calc.setVariable("h", bbox.height()*bp2pt);
+ // add constants for length units to calculator
+ for (auto unit : Length::getUnits())
+ calc.setVariable(unit.first, Length(1, unit.second).pt());
+ matrix.set(_transCmds, calc);
+ }
+ return matrix;
+}
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/ImageToSVG.hpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/ImageToSVG.hpp
index a9424af38fb..5ff9e407bae 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/ImageToSVG.hpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/ImageToSVG.hpp
@@ -24,6 +24,7 @@
#include <istream>
#include <memory>
#include <string>
+#include "PsSpecialHandler.hpp"
#include "SpecialActions.hpp"
#include "SVGTree.hpp"
@@ -33,12 +34,19 @@ class ImageToSVG : protected SpecialActions {
public:
ImageToSVG (const std::string &fname, SVGOutputBase &out) : _fname(fname), _out(out) {}
virtual ~ImageToSVG () =default;
- void convert ();
- void setTransformation (const Matrix &m);
- void setPageSize (const std::string &name);
+ void convert (int pageno);
+ void convert (int firstPage, int lastPage, std::pair<int,int> *pageinfo);
+ void convert (const std::string &rangestr, std::pair<int,int> *pageinfo);
+ void setPageTransformation (const std::string &transCmds) {_transCmds = transCmds;}
+// void setPageSize (const std::string &name);
std::string filename () const {return _fname;}
+ PSInterpreter& psInterpreter () {return _psHandler.psInterpreter();}
+ virtual bool isSinglePageFormat () const =0;
+ virtual int totalPageCount () =0;
protected:
+ void checkGSAndFileFormat ();
+ Matrix getUserMatrix (const BoundingBox &bbox) const;
virtual std::string imageFormat () const =0;
virtual bool imageIsValid () const =0;
virtual BoundingBox imageBBox () const =0;
@@ -53,7 +61,6 @@ class ImageToSVG : protected SpecialActions {
Color getColor () const override {return _svg.getColor();}
void setMatrix (const Matrix &m) override {_svg.setMatrix(m);}
const Matrix& getMatrix () const override {return _svg.getMatrix();}
- void getPageTransform (Matrix &matrix) const override {}
void setBgColor (const Color &color) override {}
void appendToPage(std::unique_ptr<XMLNode> &&node) override {_svg.appendToPage(std::move(node));}
void appendToDefs(std::unique_ptr<XMLNode> &&node) override {_svg.appendToDefs(std::move(node));}
@@ -75,6 +82,9 @@ class ImageToSVG : protected SpecialActions {
SVGOutputBase &_out;
double _x=0, _y=0;
BoundingBox _bbox;
+ PsSpecialHandler _psHandler;
+ bool _haveGS=false; ///< true if Ghostscript is available
+ std::string _transCmds; ///< transformation commands
};
#endif
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/Length.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/Length.cpp
index f4c9d6638d0..aaafd6aa68e 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/Length.cpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/Length.cpp
@@ -139,3 +139,19 @@ void Length::set (double val, string unitstr) {
throw UnitException(string("invalid length unit: ")+unitstr);
set(val, stringToUnit(unitstr));
}
+
+
+map<string,Length::Unit> Length::getUnits () {
+ map<string,Length::Unit> units = {
+ {"pt", Unit::PT},
+ {"bp", Unit::BP},
+ {"in", Unit::IN},
+ {"cm", Unit::CM},
+ {"mm", Unit::MM},
+ {"pc", Unit::PC},
+ {"dd", Unit::DD},
+ {"cc", Unit::CC},
+ {"sp", Unit::SP},
+ };
+ return units;
+}
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/Length.hpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/Length.hpp
index f606dab4549..ef47b854a10 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/Length.hpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/Length.hpp
@@ -21,7 +21,8 @@
#ifndef LENGTH_HPP
#define LENGTH_HPP
-#include <string>
+#include <map>
+#include <vector>
#include "MessageException.hpp"
#ifdef IN
@@ -57,9 +58,12 @@ class Length {
double sp () const {return _pt*pt2sp;}
double get (Unit unit) const;
std::string toString (Unit unit) const;
+ bool operator == (Length len) const {return _pt == len._pt;}
+ bool operator != (Length len) const {return _pt != len._pt;}
static Unit stringToUnit (const std::string &unitstr);
static std::string unitToString (Unit unit);
+ static std::map<std::string,Unit> getUnits ();
public:
static constexpr double pt2in = 1.0/72.27;
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/Makefile.am b/Build/source/texk/dvisvgm/dvisvgm-src/src/Makefile.am
index e073594a218..cd668737062 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/Makefile.am
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/Makefile.am
@@ -12,19 +12,34 @@ dvisvgm_SOURCES = \
dvisvgm_LDADD = \
$(noinst_LIBRARIES) \
- ../libs/clipper/libclipper.a \
+ ../libs/clipper/libclipper.a
+
+if USE_BUNDLED_LIBS
+dvisvgm_LDADD += \
+ ../libs/potrace/libpotrace.a \
../libs/xxHash/libxxhash.a
+else
+dvisvgm_LDADD += \
+ $(POTRACE_LIBS) \
+ $(XXHASH_LIBS)
+endif
if ENABLE_WOFF
+if USE_BUNDLED_LIBS
dvisvgm_LDADD += \
../libs/ff-woff/libfontforge.a \
../libs/woff2/libwoff2.a \
../libs/brotli/libbrotli.a
+else
+dvisvgm_LDADD += \
+ ../libs/ff-woff/libfontforge.a \
+ $(WOFF2_LIBS) \
+ $(BROTLI_LIBS)
+endif
endif
dvisvgm_LDADD += \
$(KPATHSEA_LIBS) \
- $(POTRACE_LIBS) \
$(FREETYPE2_LIBS) \
$(FONTFORGE_LIBS) \
$(ZLIB_LIBS) \
@@ -257,12 +272,22 @@ AM_CFLAGS = $(WARNING_CFLAGS) \
$(ZLIB_INCLUDES) \
$(CODE_COVERAGE_CFLAGS)
-AM_CXXFLAGS = $(WARNING_CFLAGS) -Wnon-virtual-dtor \
+AM_CXXFLAGS = $(WARNING_CFLAGS) -Wnon-virtual-dtor -Wno-mismatched-tags \
-I$(dvisvgm_srcdir)/libs/clipper \
- -I$(dvisvgm_srcdir)/libs/variant/include \
+ -I$(dvisvgm_srcdir)/libs/variant/include
+
+if USE_BUNDLED_LIBS
+AM_CXXFLAGS += \
+ -I$(dvisvgm_srcdir)/libs/potrace \
-I$(dvisvgm_srcdir)/libs/xxHash
+else
+AM_CXXFLAGS += \
+ $(POTRACE_CFLAGS) \
+ $(XXHASH_CFLAGS)
+endif
AM_LDFLAGS = \
+ $(KPSE_LIBS) \
$(CODE_COVERAGE_LDFLAGS)
if ENABLE_WOFF
@@ -270,10 +295,17 @@ AM_CFLAGS += \
-I$(dvisvgm_srcdir)/libs/ff-woff/fontforge \
-I$(dvisvgm_srcdir)/libs/ff-woff/inc
+AM_CXXFLAGS += $(TTFAUTOHINT_CFLAGS)
+
+if USE_BUNDLED_LIBS
AM_CXXFLAGS += \
- $(TTFAUTOHINT_CFLAGS) \
-I$(dvisvgm_srcdir)/libs/brotli/include \
-I$(dvisvgm_srcdir)/libs/woff2/include
+else
+AM_CXXFLAGS += \
+ $(BROTLI_CFLAGS) \
+ $(WOFF2_CFLAGS)
+endif
AM_LDFLAGS += $(TTFAUTOHINT_LIBS)
endif
@@ -312,8 +344,6 @@ CLEANFILES = *.gcda *.gcno
## Rebuild libkpathsea
@KPATHSEA_RULE@
-## Rebuild libpotrace
-@POTRACE_RULE@
## Rebuild libfreetype
@FREETYPE2_RULE@
## Rebuild libz
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/Makefile.in b/Build/source/texk/dvisvgm/dvisvgm-src/src/Makefile.in
index f1f546553f9..f886c02f8c6 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/Makefile.in
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/Makefile.in
@@ -90,23 +90,48 @@ POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
bin_PROGRAMS = dvisvgm$(EXEEXT)
-@ENABLE_WOFF_TRUE@am__append_1 = \
-@ENABLE_WOFF_TRUE@ ../libs/ff-woff/libfontforge.a \
-@ENABLE_WOFF_TRUE@ ../libs/woff2/libwoff2.a \
-@ENABLE_WOFF_TRUE@ ../libs/brotli/libbrotli.a
-
-@ENABLE_WOFF_TRUE@am__append_2 = ffwrapper.c ffwrapper.h
-@ENABLE_WOFF_TRUE@am__append_3 = \
+@USE_BUNDLED_LIBS_TRUE@am__append_1 = \
+@USE_BUNDLED_LIBS_TRUE@ ../libs/potrace/libpotrace.a \
+@USE_BUNDLED_LIBS_TRUE@ ../libs/xxHash/libxxhash.a
+
+@USE_BUNDLED_LIBS_FALSE@am__append_2 = \
+@USE_BUNDLED_LIBS_FALSE@ $(POTRACE_LIBS) \
+@USE_BUNDLED_LIBS_FALSE@ $(XXHASH_LIBS)
+
+@ENABLE_WOFF_TRUE@@USE_BUNDLED_LIBS_TRUE@am__append_3 = \
+@ENABLE_WOFF_TRUE@@USE_BUNDLED_LIBS_TRUE@ ../libs/ff-woff/libfontforge.a \
+@ENABLE_WOFF_TRUE@@USE_BUNDLED_LIBS_TRUE@ ../libs/woff2/libwoff2.a \
+@ENABLE_WOFF_TRUE@@USE_BUNDLED_LIBS_TRUE@ ../libs/brotli/libbrotli.a
+
+@ENABLE_WOFF_TRUE@@USE_BUNDLED_LIBS_FALSE@am__append_4 = \
+@ENABLE_WOFF_TRUE@@USE_BUNDLED_LIBS_FALSE@ ../libs/ff-woff/libfontforge.a \
+@ENABLE_WOFF_TRUE@@USE_BUNDLED_LIBS_FALSE@ $(WOFF2_LIBS) \
+@ENABLE_WOFF_TRUE@@USE_BUNDLED_LIBS_FALSE@ $(BROTLI_LIBS)
+
+@ENABLE_WOFF_TRUE@am__append_5 = ffwrapper.c ffwrapper.h
+@USE_BUNDLED_LIBS_TRUE@am__append_6 = \
+@USE_BUNDLED_LIBS_TRUE@ -I$(dvisvgm_srcdir)/libs/potrace \
+@USE_BUNDLED_LIBS_TRUE@ -I$(dvisvgm_srcdir)/libs/xxHash
+
+@USE_BUNDLED_LIBS_FALSE@am__append_7 = \
+@USE_BUNDLED_LIBS_FALSE@ $(POTRACE_CFLAGS) \
+@USE_BUNDLED_LIBS_FALSE@ $(XXHASH_CFLAGS)
+
+@ENABLE_WOFF_TRUE@am__append_8 = \
@ENABLE_WOFF_TRUE@ -I$(dvisvgm_srcdir)/libs/ff-woff/fontforge \
@ENABLE_WOFF_TRUE@ -I$(dvisvgm_srcdir)/libs/ff-woff/inc
-@ENABLE_WOFF_TRUE@am__append_4 = \
-@ENABLE_WOFF_TRUE@ $(TTFAUTOHINT_CFLAGS) \
-@ENABLE_WOFF_TRUE@ -I$(dvisvgm_srcdir)/libs/brotli/include \
-@ENABLE_WOFF_TRUE@ -I$(dvisvgm_srcdir)/libs/woff2/include
+@ENABLE_WOFF_TRUE@am__append_9 = $(TTFAUTOHINT_CFLAGS)
+@ENABLE_WOFF_TRUE@@USE_BUNDLED_LIBS_TRUE@am__append_10 = \
+@ENABLE_WOFF_TRUE@@USE_BUNDLED_LIBS_TRUE@ -I$(dvisvgm_srcdir)/libs/brotli/include \
+@ENABLE_WOFF_TRUE@@USE_BUNDLED_LIBS_TRUE@ -I$(dvisvgm_srcdir)/libs/woff2/include
+
+@ENABLE_WOFF_TRUE@@USE_BUNDLED_LIBS_FALSE@am__append_11 = \
+@ENABLE_WOFF_TRUE@@USE_BUNDLED_LIBS_FALSE@ $(BROTLI_CFLAGS) \
+@ENABLE_WOFF_TRUE@@USE_BUNDLED_LIBS_FALSE@ $(WOFF2_CFLAGS)
-@ENABLE_WOFF_TRUE@am__append_5 = $(TTFAUTOHINT_LIBS)
-@WIN32_TRUE@am__append_6 = -DTEXLIVEWIN32
+@ENABLE_WOFF_TRUE@am__append_12 = $(TTFAUTOHINT_LIBS)
+@WIN32_TRUE@am__append_13 = -DTEXLIVEWIN32
subdir = dvisvgm-src/src
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/../../m4/ax_cxx_compile_stdcxx.m4 \
@@ -114,7 +139,6 @@ am__aclocal_m4_deps = $(top_srcdir)/../../m4/ax_cxx_compile_stdcxx.m4 \
$(top_srcdir)/../../m4/kpse-cxx-hack.m4 \
$(top_srcdir)/../../m4/kpse-freetype2-flags.m4 \
$(top_srcdir)/../../m4/kpse-kpathsea-flags.m4 \
- $(top_srcdir)/../../m4/kpse-potrace-flags.m4 \
$(top_srcdir)/../../m4/kpse-warnings.m4 \
$(top_srcdir)/../../m4/kpse-win32.m4 \
$(top_srcdir)/../../m4/kpse-zlib-flags.m4 \
@@ -249,6 +273,7 @@ libdvisvgm_a_OBJECTS = $(am_libdvisvgm_a_OBJECTS)
am_dvisvgm_OBJECTS = dvisvgm.$(OBJEXT)
dvisvgm_OBJECTS = $(am_dvisvgm_OBJECTS)
am__DEPENDENCIES_1 =
+@ENABLE_WOFF_TRUE@@USE_BUNDLED_LIBS_FALSE@am__DEPENDENCIES_2 = ../libs/ff-woff/libfontforge.a
AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
am__v_lt_0 = --silent
@@ -386,7 +411,9 @@ am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/version.hpp.in \
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
+AM_CPPFLAGS = @AM_CPPFLAGS@
AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
+AM_LDFLAGS = $(KPSE_LIBS) $(CODE_COVERAGE_LDFLAGS) $(am__append_12)
AR = @AR@
AS = @AS@
AUTOCONF = @AUTOCONF@
@@ -405,6 +432,7 @@ CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
CXXLD = @CXXLD@
CYGPATH_W = @CYGPATH_W@
+DATE = @DATE@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
DLLTOOL = @DLLTOOL@
@@ -461,9 +489,6 @@ PACKAGE_URL = @PACKAGE_URL@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
PKG_CONFIG = @PKG_CONFIG@
-POTRACE_DEPEND = @POTRACE_DEPEND@
-POTRACE_INCLUDES = @POTRACE_INCLUDES@
-POTRACE_LIBS = @POTRACE_LIBS@
RANLIB = @RANLIB@
SED = @SED@
SET_MAKE = @SET_MAKE@
@@ -534,9 +559,9 @@ dvisvgm_SOURCES = \
dvisvgm.cpp
dvisvgm_LDADD = $(noinst_LIBRARIES) ../libs/clipper/libclipper.a \
- ../libs/xxHash/libxxhash.a $(am__append_1) $(KPATHSEA_LIBS) \
- $(POTRACE_LIBS) $(FREETYPE2_LIBS) $(FONTFORGE_LIBS) \
- $(ZLIB_LIBS) $(LIBGS_LIBS)
+ $(am__append_1) $(am__append_2) $(am__append_3) \
+ $(am__append_4) $(KPATHSEA_LIBS) $(FREETYPE2_LIBS) \
+ $(FONTFORGE_LIBS) $(ZLIB_LIBS) $(LIBGS_LIBS)
dvisvgm_DEPENDENCIES = $(noinst_LIBRARIES) $(KPATHSEA_DEPEND) \
$(ZLIB_DEPEND) $(FREETYPE2_DEPEND)
libdvisvgm_a_SOURCES = AGLTable.hpp BasicDVIReader.cpp \
@@ -601,19 +626,18 @@ libdvisvgm_a_SOURCES = AGLTable.hpp BasicDVIReader.cpp \
VectorStream.hpp version.hpp VFActions.hpp VFReader.cpp \
VFReader.hpp windows.hpp XMLDocument.cpp XMLDocument.hpp \
XMLNode.cpp XMLNode.hpp XMLString.cpp XMLString.hpp \
- ZLibOutputStream.hpp $(am__append_2)
+ ZLibOutputStream.hpp $(am__append_5)
EXTRA_DIST = options.xml options.dtd iapi.h ierrors.h MiKTeXCom.hpp MiKTeXCom.cpp
dvisvgm_srcdir = $(top_srcdir)/dvisvgm-src
AM_CFLAGS = $(WARNING_CFLAGS) $(ZLIB_INCLUDES) $(CODE_COVERAGE_CFLAGS) \
- $(am__append_3)
+ $(am__append_8)
AM_CXXFLAGS = $(WARNING_CFLAGS) -Wnon-virtual-dtor \
- -I$(dvisvgm_srcdir)/libs/clipper \
- -I$(dvisvgm_srcdir)/libs/variant/include \
- -I$(dvisvgm_srcdir)/libs/xxHash $(am__append_4) \
- $(KPATHSEA_INCLUDES) $(POTRACE_INCLUDES) $(FREETYPE2_INCLUDES) \
- $(ZLIB_INCLUDES) $(LIBGS_INCLUDES) $(CODE_COVERAGE_CFLAGS) \
- $(am__append_6)
-AM_LDFLAGS = $(CODE_COVERAGE_LDFLAGS) $(am__append_5)
+ -Wno-mismatched-tags -I$(dvisvgm_srcdir)/libs/clipper \
+ -I$(dvisvgm_srcdir)/libs/variant/include $(am__append_6) \
+ $(am__append_7) $(am__append_9) $(am__append_10) \
+ $(am__append_11) $(KPATHSEA_INCLUDES) $(POTRACE_INCLUDES) \
+ $(FREETYPE2_INCLUDES) $(ZLIB_INCLUDES) $(LIBGS_INCLUDES) \
+ $(CODE_COVERAGE_CFLAGS) $(am__append_13)
CLEANFILES = *.gcda *.gcno
all: all-am
@@ -1293,7 +1317,6 @@ uninstall-am: uninstall-binPROGRAMS
@CODE_COVERAGE_RULES@
@KPATHSEA_RULE@
-@POTRACE_RULE@
@FREETYPE2_RULE@
@ZLIB_RULE@
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/PDFToSVG.hpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/PDFToSVG.hpp
index 570eecd6384..647bef5ee0e 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/PDFToSVG.hpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/PDFToSVG.hpp
@@ -24,9 +24,22 @@
#include <fstream>
#include "ImageToSVG.hpp"
+class PsSpecialHandler;
+
class PDFToSVG : public ImageToSVG {
public:
PDFToSVG (const std::string &fname, SVGOutputBase &out) : ImageToSVG(fname, out) {}
+ bool isSinglePageFormat() const override {return false;}
+
+ /** Returns the total number of pages in the PDF file. */
+ int totalPageCount() override {
+ if (_totalPageCount < 0) {
+ _totalPageCount = psInterpreter().pdfPageCount(filename());
+ if (_totalPageCount < 1)
+ throw MessageException("can't retrieve number of pages from file " + filename());
+ }
+ return _totalPageCount;
+ }
protected:
bool imageIsValid () const override {
@@ -41,6 +54,9 @@ class PDFToSVG : public ImageToSVG {
std::string imageFormat () const override {return "PDF";}
BoundingBox imageBBox () const override {return BoundingBox();}
std::string psSpecialCmd () const override {return "pdffile=";}
+
+ private:
+ mutable int _totalPageCount = -1;
};
#endif
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/PSInterpreter.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/PSInterpreter.cpp
index f87a6467a09..4bb34616432 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/PSInterpreter.cpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/PSInterpreter.cpp
@@ -263,7 +263,6 @@ void PSInterpreter::callActions (InputReader &in) {
{"makepattern", {-1, &PSActions::makepattern}},
{"moveto", { 2, &PSActions::moveto}},
{"newpath", { 1, &PSActions::newpath}},
- {"pdfpagebox", { 4, &PSActions::pdfpagebox}},
{"querypos", { 2, &PSActions::querypos}},
{"raw", {-1, nullptr}},
{"restore", { 1, &PSActions::restore}},
@@ -341,3 +340,32 @@ int GSDLLCALL PSInterpreter::error (void *inst, const char *buf, int len) {
return len;
}
+
+/** Returns the total number of pages of a PDF file.
+ * @param[in] fname name/path of the PDF file */
+int PSInterpreter::pdfPageCount (const string &fname) {
+ executeRaw("\n("+fname+")@pdfpagecount ", 1);
+ if (!_rawData.empty()) {
+ size_t index;
+ int ret = stoi(_rawData[0], &index, 10);
+ if (index > 0)
+ return ret;
+ }
+ return 0;
+}
+
+
+/** Returns the bounding box of a PDF page. If the selected page doesn't exist,
+ * the "invalid" flag of the returned bounding box is set.
+ * @param[in] fname name/path of the PDF file
+ * @param[in] pageno page number
+ * @return the bounding box of the given page */
+BoundingBox PSInterpreter::pdfPageBox (const string &fname, int pageno) {
+ BoundingBox pagebox;
+ executeRaw("\n"+to_string(pageno)+"("+fname+")@pdfpagebox ", 4);
+ if (_rawData.size() < 4)
+ pagebox.invalidate();
+ else
+ pagebox = BoundingBox(stod(_rawData[0]), stod(_rawData[1]), stod(_rawData[2]), stod(_rawData[3]));
+ return pagebox;
+}
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/PSInterpreter.hpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/PSInterpreter.hpp
index 2db857e0f61..6be12e34504 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/PSInterpreter.hpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/PSInterpreter.hpp
@@ -25,6 +25,7 @@
#include <istream>
#include <string>
#include <vector>
+#include "BoundingBox.hpp"
#include "Ghostscript.hpp"
#include "InputReader.hpp"
#include "MessageException.hpp"
@@ -55,7 +56,6 @@ struct PSActions {
virtual void makepattern (std::vector<double> &p) =0;
virtual void moveto (std::vector<double> &p) =0;
virtual void newpath (std::vector<double> &p) =0;
- virtual void pdfpagebox (std::vector<double> &p) =0;
virtual void querypos (std::vector<double> &p) =0;
virtual void restore (std::vector<double> &p) =0;
virtual void rotate (std::vector<double> &p) =0;
@@ -101,6 +101,8 @@ class PSInterpreter {
void limit (size_t max_bytes) {_bytesToRead = max_bytes;}
void setFilter (PSFilter *filter) {_filter = filter;}
PSActions* setActions (PSActions *actions);
+ int pdfPageCount (const std::string &fname);
+ BoundingBox pdfPageBox (const std::string &fname, int pageno);
const std::vector<std::string>& rawData () const {return _rawData;}
protected:
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/PsSpecialHandler.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/PsSpecialHandler.cpp
index 75d83f2b4b6..167ab0bc393 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/PsSpecialHandler.cpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/PsSpecialHandler.cpp
@@ -45,7 +45,7 @@ int PsSpecialHandler::SHADING_SEGMENT_SIZE = 20;
double PsSpecialHandler::SHADING_SIMPLIFY_DELTA = 0.01;
-PsSpecialHandler::PsSpecialHandler () : _psi(this), _actions(), _previewFilter(_psi), _psSection(PS_NONE), _xmlnode(), _savenode()
+PsSpecialHandler::PsSpecialHandler () : _psi(this), _actions(), _previewFilter(_psi), _xmlnode(), _savenode()
{
}
@@ -286,14 +286,15 @@ void PsSpecialHandler::imgfile (FileType filetype, const string &fname, const un
double lly = (it = attr.find("lly")) != attr.end() ? stod(it->second) : 0;
double urx = (it = attr.find("urx")) != attr.end() ? stod(it->second) : 0;
double ury = (it = attr.find("ury")) != attr.end() ? stod(it->second) : 0;
+ int pageno = (it = attr.find("page")) != attr.end() ? stoi(it->second, nullptr, 10) : 1;
if (filetype == FileType::PDF && llx == 0 && lly == 0 && urx == 0 && ury == 0) {
- _psi.execute("\n("+fname+")@getpdfpagebox ");
- if (_pdfpagebox.valid()) {
- llx = _pdfpagebox.minX();
- lly = _pdfpagebox.minY();
- urx = _pdfpagebox.maxX();
- ury = _pdfpagebox.maxY();
+ BoundingBox pagebox = _psi.pdfPageBox(fname, pageno);
+ if (pagebox.valid()) {
+ llx = pagebox.minX();
+ lly = pagebox.minY();
+ urx = pagebox.maxX();
+ ury = pagebox.maxY();
}
}
@@ -335,11 +336,13 @@ void PsSpecialHandler::imgfile (FileType filetype, const string &fname, const un
auto groupNode = util::make_unique<XMLElementNode>("g"); // append following elements to this group
_xmlnode = groupNode.get();
_psi.execute(
- "\n@beginspecial @setspecial" // enter special environment
- "/setpagedevice{@setpagedevice}def" // activate processing of operator "setpagedevice"
- "[1 0 0 -1 0 0] setmatrix" // don't apply outer PS transformations
- "(" + string(filepath) + ")run " // execute file content
- "@endspecial " // leave special environment
+ "\n@beginspecial @setspecial" // enter special environment
+ "/setpagedevice{@setpagedevice}def" // activate processing of operator "setpagedevice"
+ "[1 0 0 -1 0 0] setmatrix" // don't apply outer PS transformations
+ "/FirstPage "+to_string(pageno)+" def" // set number of fisrt page to convert (PDF only)
+ "/LastPage "+to_string(pageno)+" def" // set number of last page to convert (PDF only)
+ "(" + string(filepath) + ")run " // execute file content
+ "@endspecial " // leave special environment
);
if (!groupNode->empty()) { // has anything been drawn?
Matrix matrix(1);
@@ -421,8 +424,7 @@ void PsSpecialHandler::dviEndPage (unsigned, SpecialActions &actions) {
Message::mstream() << " preview package (version " << _previewFilter.version() << ")\n";
// apply page transformations to box extents
- Matrix pagetrans;
- actions.getPageTransform(pagetrans);
+ Matrix pagetrans = actions.getPageTransformation();
bool isBaselineHorizontal = transform_box_extents(pagetrans, w, h, d);
actions.bbox().lock();
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/PsSpecialHandler.hpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/PsSpecialHandler.hpp
index 1a16412fbb2..d531d9e4e0a 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/PsSpecialHandler.hpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/PsSpecialHandler.hpp
@@ -88,6 +88,7 @@ class PsSpecialHandler : public SpecialHandler, protected PSActions {
bool process (const std::string &prefix, std::istream &is, SpecialActions &actions) override;
void setDviScaleFactor (double dvi2bp) override {_previewFilter.setDviScaleFactor(dvi2bp);}
void enterBodySection ();
+ PSInterpreter& psInterpreter () {return _psi;}
public:
static bool COMPUTE_CLIPPATHS_INTERSECTIONS;
@@ -128,7 +129,6 @@ class PsSpecialHandler : public SpecialHandler, protected PSActions {
void makepattern (std::vector<double> &p) override;
void moveto (std::vector<double> &p) override;
void newpath (std::vector<double> &p) override;
- void pdfpagebox (std::vector<double> &p) override {_pdfpagebox = BoundingBox(p[0], p[1], p[2], p[3]);}
void querypos (std::vector<double> &p) override {_currentpoint = DPair(p[0], p[1]);}
void restore (std::vector<double> &p) override;
void rotate (std::vector<double> &p) override;
@@ -158,7 +158,7 @@ class PsSpecialHandler : public SpecialHandler, protected PSActions {
PSInterpreter _psi;
SpecialActions *_actions;
PSPreviewFilter _previewFilter; ///< filter to extract information generated by the preview package
- PsSection _psSection; ///< current section processed (nothing yet, headers, or body specials)
+ PsSection _psSection=PS_NONE; ///< current section processed (nothing yet, headers, or body specials)
XMLElementNode *_xmlnode; ///< if != 0, created SVG elements are appended to this node
XMLElementNode *_savenode; ///< pointer to temporaryly store _xmlnode
std::string _headerCode; ///< collected literal PS header code
@@ -179,7 +179,6 @@ class PsSpecialHandler : public SpecialHandler, protected PSActions {
ClippingStack _clipStack;
std::unordered_map<int, std::unique_ptr<PSPattern>> _patterns;
PSTilingPattern *_pattern; ///< current pattern
- BoundingBox _pdfpagebox;
};
#endif
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/SourceInput.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/SourceInput.cpp
index d1622fb66f5..d884be4ab7e 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/SourceInput.cpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/SourceInput.cpp
@@ -27,16 +27,21 @@
#include "utility.hpp"
#ifdef _WIN32
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <windows.h>
+# include <fcntl.h>
+# include <sys/stat.h>
+# include <windows.h>
+#else
+# include <config.h>
+# ifdef HAVE_UMASK
+# include <sys/stat.h>
+# endif
#endif
#ifdef _MSC_VER
-#include <io.h>
+# include <io.h>
#else
-#include <cstdlib>
-#include <unistd.h>
+# include <cstdlib>
+# include <unistd.h>
#endif
using namespace std;
@@ -60,8 +65,14 @@ bool TemporaryFile::create () {
_path = FileSystem::tmpdir();
#ifndef _WIN32
_path += "stdinXXXXXX";
+#ifdef HAVE_UMASK
+ mode_t mode_mask = umask(S_IXUSR | S_IRWXG | S_IRWXO); // set file permissions to 0600
+#endif
_fd = mkstemp(&_path[0]);
-#else
+#ifdef HAVE_UMASK
+ umask(mode_mask);
+#endif
+#else // !_WIN32
char fname[MAX_PATH];
std::replace(_path.begin(), _path.end(), '/', '\\');
if (GetTempFileName(_path.c_str(), "stdin", 0, fname)) {
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/SpecialActions.hpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/SpecialActions.hpp
index 80dbd595d91..4d8d964de37 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/SpecialActions.hpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/SpecialActions.hpp
@@ -42,7 +42,7 @@ class SpecialActions {
virtual Color getColor () const =0;
virtual void setMatrix (const Matrix &m) =0;
virtual const Matrix& getMatrix () const =0;
- virtual void getPageTransform (Matrix &matrix) const =0;
+ virtual Matrix getPageTransformation () const {return Matrix(1);}
virtual void setBgColor (const Color &color) =0;
virtual void appendToPage(std::unique_ptr<XMLNode> &&node) =0;
virtual void appendToDefs(std::unique_ptr<XMLNode> &&node) =0;
@@ -75,7 +75,6 @@ class EmptySpecialActions : public SpecialActions {
Color getColor () const override {return Color::BLACK;}
void setMatrix (const Matrix &m) override {}
const Matrix& getMatrix () const override {return _matrix;}
- void getPageTransform (Matrix &matrix) const override {}
void appendToPage(std::unique_ptr<XMLNode> &&node) override {}
void appendToDefs(std::unique_ptr<XMLNode> &&node) override {}
void prependToPage(std::unique_ptr<XMLNode> &&node) override {}
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/dvisvgm.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/dvisvgm.cpp
index d778c84c5f9..297844cb21d 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/dvisvgm.cpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/dvisvgm.cpp
@@ -52,7 +52,7 @@
#ifndef DISABLE_WOFF
#include <brotli/encode.h>
-#include <woff2/version.h>
+//#include <woff2/version.h>
#include "ffwrapper.h"
#include "TTFAutohint.hpp"
#endif
@@ -252,7 +252,7 @@ static void print_version (bool extended) {
versionInfo.add("Ghostscript", Ghostscript().revisionstr(), true);
#ifndef DISABLE_WOFF
versionInfo.add("brotli", BrotliEncoderVersion(), 3, 0x1000);
- versionInfo.add("woff2", woff2::version, 3, 0x100);
+// versionInfo.add("woff2", woff2::version, 3, 0x100);
versionInfo.add("fontforge", ff_version());
versionInfo.add("ttfautohint", TTFAutohint().version(), true);
#endif
@@ -320,6 +320,19 @@ static void set_variables (const CommandLine &cmdline) {
}
+static void timer_message (double start_time, const pair<int,int> *pageinfo) {
+ Message::mstream().indent(0);
+ if (!pageinfo)
+ Message::mstream(false, Message::MC_PAGE_NUMBER) << "\n" << "file";
+ else {
+ Message::mstream(false, Message::MC_PAGE_NUMBER) << "\n" << pageinfo->first << " of " << pageinfo->second << " page";
+ if (pageinfo->second > 1)
+ Message::mstream(false, Message::MC_PAGE_NUMBER) << 's';
+ }
+ Message::mstream(false, Message::MC_PAGE_NUMBER) << " converted in " << (System::time()-start_time) << " seconds\n";
+}
+
+
int main (int argc, char *argv[]) {
try {
CommandLine cmdline;
@@ -364,20 +377,15 @@ int main (int argc, char *argv[]) {
SVGOutput out(cmdline.stdoutOpt.given() ? "" : srcin.getFileName(),
cmdline.outputOpt.value(),
cmdline.zipOpt.given() ? cmdline.zipOpt.value() : 0);
+ pair<int,int> pageinfo;
if (cmdline.epsOpt.given() || cmdline.pdfOpt.given()) {
auto img2svg = unique_ptr<ImageToSVG>(
cmdline.epsOpt.given()
? static_cast<ImageToSVG*>(new EPSToSVG(srcin.getFilePath(), out))
: static_cast<ImageToSVG*>(new PDFToSVG(srcin.getFilePath(), out)));
- img2svg->convert();
- Message::mstream().indent(0);
- Message::mstream(false, Message::MC_PAGE_NUMBER) << "file converted in " << (System::time()-start_time) << " seconds\n";
- }
- else if (cmdline.pdfOpt.given()) {
- PDFToSVG pdf2svg(srcin.getFilePath(), out);
- pdf2svg.convert();
- Message::mstream().indent(0);
- Message::mstream(false, Message::MC_PAGE_NUMBER) << "file converted in " << (System::time()-start_time) << " seconds\n";
+ img2svg->setPageTransformation(get_transformation_string(cmdline));
+ img2svg->convert(cmdline.pageOpt.value(), &pageinfo);
+ timer_message(start_time, img2svg->isSinglePageFormat() ? nullptr : &pageinfo);
}
else {
init_fontmap(cmdline);
@@ -389,13 +397,8 @@ int main (int argc, char *argv[]) {
dvi2svg.setPageTransformation(get_transformation_string(cmdline));
dvi2svg.setPageSize(cmdline.bboxOpt.value());
- pair<int,int> 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)
- Message::mstream(false, Message::MC_PAGE_NUMBER) << 's';
- Message::mstream(false, Message::MC_PAGE_NUMBER) << " converted in " << (System::time()-start_time) << " seconds\n";
+ timer_message(start_time, &pageinfo);
}
}
catch (DVIException &e) {
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/psdefs.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/psdefs.cpp
index 5efa9db4dc4..3246ed22720 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/psdefs.cpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/psdefs.cpp
@@ -105,6 +105,8 @@ const char *PSInterpreter::PSDEFS =
"exec<</Normal 0/Compatible 0/Multiply 1/Screen 2/Overlay 3/SoftLight 4/HardLig"
"ht 5/ColorDodge 6/ColorBurn 7/Darken 8/Lighten 9/Difference 10/Exclusion 11/Hu"
"e 12/Saturation 13/Color 14/Luminosity 15/CompatibleOverprint 16>>exch get 1(s"
-"etblendmode)prcmd}def/@getpdfpagebox{GS_PDF_ProcSet begin pdfdict begin(r)file"
-" pdfopen begin 1 pdfgetpage/MediaBox pget pop aload pop 4(pdfpagebox)prcmd cur"
-"rentdict pdfclose end end end}def DELAYBIND{.bindnow}if ";
+"etblendmode)prcmd}def/@pdfpagecount{GS_PDF_ProcSet begin pdfdict begin(r)file "
+"pdfopen begin pdfpagecount currentdict pdfclose end end end}def/@pdfpagebox{GS"
+"_PDF_ProcSet begin pdfdict begin(r)file pdfopen begin dup dup 1 lt exch pdfpag"
+"ecount gt or{pop}{pdfgetpage/MediaBox pget pop aload pop}ifelse currentdict pd"
+"fclose end end end}def DELAYBIND{.bindnow}if ";
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/version.hpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/version.hpp
index 14bfeacaf85..cf86d2ca2d4 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/version.hpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/version.hpp
@@ -22,7 +22,7 @@
#define VERSION_HPP
constexpr const char *PROGRAM_NAME = "dvisvgm";
-constexpr const char *PROGRAM_VERSION = "2.4.2";
+constexpr const char *PROGRAM_VERSION = "2.5";
#endif