summaryrefslogtreecommitdiff
path: root/Build/source/texk/dvisvgm/dvisvgm-1.0.11/src/GFTracer.cpp
diff options
context:
space:
mode:
authorPeter Breitenlohner <peb@mppmu.mpg.de>2012-03-12 09:47:56 +0000
committerPeter Breitenlohner <peb@mppmu.mpg.de>2012-03-12 09:47:56 +0000
commit2386c1184c15a8ee1fb679e2de49b5972d3d179d (patch)
tree9cc045f5cc0ceb4e45293a23932aad193ea564ee /Build/source/texk/dvisvgm/dvisvgm-1.0.11/src/GFTracer.cpp
parent57768fa5c30bc7206778ce0c52818eac8dfa2518 (diff)
dvisvgm 1.0.11
git-svn-id: svn://tug.org/texlive/trunk@25614 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/dvisvgm/dvisvgm-1.0.11/src/GFTracer.cpp')
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-1.0.11/src/GFTracer.cpp102
1 files changed, 102 insertions, 0 deletions
diff --git a/Build/source/texk/dvisvgm/dvisvgm-1.0.11/src/GFTracer.cpp b/Build/source/texk/dvisvgm/dvisvgm-1.0.11/src/GFTracer.cpp
new file mode 100644
index 00000000000..ec50cb65896
--- /dev/null
+++ b/Build/source/texk/dvisvgm/dvisvgm-1.0.11/src/GFTracer.cpp
@@ -0,0 +1,102 @@
+/*************************************************************************
+** GFTracer.cpp **
+** **
+** This file is part of dvisvgm -- the DVI to SVG converter **
+** Copyright (C) 2005-2012 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 **
+** published by the Free Software Foundation; either version 3 of **
+** the License, or (at your option) any later version. **
+** **
+** This program is distributed in the hope that it will be useful, but **
+** WITHOUT ANY WARRANTY; without even the implied warranty of **
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
+** GNU General Public License for more details. **
+** **
+** You should have received a copy of the GNU General Public License **
+** along with this program; if not, see <http://www.gnu.org/licenses/>. **
+*************************************************************************/
+
+#include <iostream>
+#include <fstream>
+#include <sstream>
+#include "GFTracer.h"
+#include "Glyph.h"
+#include "Message.h"
+
+#ifdef __MSVC__
+#include <potracelib.h>
+#else
+extern "C" {
+#include <potracelib.h>
+}
+#endif
+
+using namespace std;
+
+
+GFTracer::GFTracer (istream &is)
+ : GFReader(is), _unitsPerPoint(0.0)
+{
+}
+
+
+/** Constructs a new GFTracer.
+ * @param[in] is GF file is read from this stream
+ * @param[in] upp target units per TeX point */
+GFTracer::GFTracer (istream &is, double upp)
+ : GFReader(is), _unitsPerPoint(upp)
+{
+}
+
+
+void GFTracer::beginChar (UInt32 c) {
+}
+
+
+void GFTracer::endChar (UInt32 c) {
+ const Bitmap &bitmap = getBitmap();
+ if (bitmap.empty())
+ return;
+
+ // prepare potrace's bitmap structure
+ vector<potrace_word> buffer;
+ potrace_bitmap_t pobitmap;
+ pobitmap.w = bitmap.width();
+ pobitmap.h = bitmap.height();
+ pobitmap.dy = bitmap.copy(buffer);
+ pobitmap.map = &buffer[0];
+ potrace_param_t *param = potrace_param_default();
+ potrace_state_t *state = potrace_trace(param, &pobitmap);
+ potrace_param_free(param);
+
+ if (!state || state->status == POTRACE_STATUS_INCOMPLETE)
+ Message::wstream(true) << "error while tracing character\n";
+ else {
+ double hsf=1.0, vsf=1.0; // horizontal a d vertical scale factor
+ if (_unitsPerPoint != 0.0) {
+ hsf = _unitsPerPoint/getHPixelsPerPoint(); // horizontal scale factor
+ vsf = _unitsPerPoint/getVPixelsPerPoint(); // vertical scale factor
+ }
+ for (potrace_path_t *path = state->plist; path; path = path->next) {
+ potrace_dpoint_t &p = path->curve.c[path->curve.n-1][2]; // start/end point
+ moveTo(hsf*(p.x+bitmap.xshift()), vsf*(p.y+bitmap.yshift()));
+ for (int i=0; i < path->curve.n; i++) {
+ if (path->curve.tag[i] == POTRACE_CURVETO) {
+ curveTo(hsf*(path->curve.c[i][0].x+bitmap.xshift()), vsf*(path->curve.c[i][0].y+bitmap.yshift()),
+ hsf*(path->curve.c[i][1].x+bitmap.xshift()), vsf*(path->curve.c[i][1].y+bitmap.yshift()),
+ hsf*(path->curve.c[i][2].x+bitmap.xshift()), vsf*(path->curve.c[i][2].y+bitmap.yshift()));
+ }
+ else {
+ lineTo(hsf*(path->curve.c[i][1].x+bitmap.xshift()), vsf*(path->curve.c[i][1].y+bitmap.yshift()));
+ if (i == path->curve.n-1)
+ closePath();
+ else
+ lineTo(hsf*(path->curve.c[i][2].x+bitmap.xshift()), vsf*(path->curve.c[i][2].y+bitmap.yshift()));
+ }
+ }
+ }
+ }
+ potrace_state_free(state);
+}