Merge lp:~noskcaj/ubuntu/trusty/klatexformula/3.2.8 into lp:ubuntu/trusty/klatexformula

Proposed by Jackson Doak
Status: Merged
Merge reported by: Sebastien Bacher
Merged at revision: not available
Proposed branch: lp:~noskcaj/ubuntu/trusty/klatexformula/3.2.8
Merge into: lp:ubuntu/trusty/klatexformula
Diff against target: 761 lines (+465/-95)
8 files modified
VERSION (+1/-1)
debian/changelog (+7/-0)
debian/control (+2/-1)
src/CMakeLists.txt (+7/-4)
src/klfbackend/klfbackend.cpp (+434/-77)
src/klfbackend/klfblockprocess.cpp (+9/-9)
src/klfbackend/klfdebug.h (+2/-2)
src/klfbackend/klfqt34common.h (+3/-1)
To merge this branch: bzr merge lp:~noskcaj/ubuntu/trusty/klatexformula/3.2.8
Reviewer Review Type Date Requested Status
Sebastien Bacher Approve
Review via email: mp+212506@code.launchpad.net

Description of the change

New upstream bugfix release, only one change. Fixes bug caused by a ghostscript change

To post a comment you must log in.
Revision history for this message
Sebastien Bacher (seb128) wrote :

Thanks, sponsored to trusty (it's in the unapproved queue)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'VERSION'
2--- VERSION 2013-07-22 17:50:27 +0000
3+++ VERSION 2014-03-24 20:24:05 +0000
4@@ -1,1 +1,1 @@
5-3.2.7
6+3.2.8
7
8=== modified file 'debian/changelog'
9--- debian/changelog 2013-07-22 17:50:27 +0000
10+++ debian/changelog 2014-03-24 20:24:05 +0000
11@@ -1,3 +1,10 @@
12+klatexformula (3.2.8-0ubuntu1) trusty; urgency=medium
13+
14+ * New upstream release. LP: #1296902
15+ - fixes a bug caused by recent versions of ghostscript
16+
17+ -- Jackson Doak <noskcaj@ubuntu.com> Tue, 25 Mar 2014 07:03:05 +1100
18+
19 klatexformula (3.2.7-1) unstable; urgency=low
20
21 * New upstream release
22
23=== modified file 'debian/control'
24--- debian/control 2013-07-22 17:50:27 +0000
25+++ debian/control 2014-03-24 20:24:05 +0000
26@@ -1,7 +1,8 @@
27 Source: klatexformula
28 Section: tex
29 Priority: extra
30-Maintainer: Tobias Winchen <winchen@physik.rwth-aachen.de>
31+Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
32+XSBC-Original-Maintainer: Tobias Winchen <winchen@physik.rwth-aachen.de>
33 Build-Depends: cdbs, debhelper (>= 7), docbook-to-man, cmake, libqt4-dev, pkg-kde-tools, kdelibs5-dev, libx11-dev
34 Standards-Version: 3.9.4
35 Vcs-git: git://github.com/winchen/klatexformula_debian.git
36
37=== modified file 'src/CMakeLists.txt'
38--- src/CMakeLists.txt 2012-01-02 20:23:27 +0000
39+++ src/CMakeLists.txt 2014-03-24 20:24:05 +0000
40@@ -1,7 +1,7 @@
41 # ######################################## #
42 # CMake project file for klatexformula/src #
43 # ######################################## #
44-# $Id: CMakeLists.txt 742 2011-10-09 11:02:08Z phfaist $
45+# $Id: CMakeLists.txt 864 2013-11-23 13:52:28Z phfaist $
46 # ######################################## #
47
48 if(KLF_MACOSX_BUNDLES)
49@@ -503,9 +503,12 @@
50 if(WIN32 AND KLF_INSTALL_QTLIBS)
51 # Install Qt libs
52 # QT_BINARY_DIR and QT_PLUGINS_DIR are set by FindQt4 CMake module
53- install(DIRECTORY "${QT_BINARY_DIR}/" DESTINATION "${KLF_INSTALL_LIB_DIR}"
54- FILES_MATCHING REGEX "/Qt(Core|Gui|Sql|Xml)4?\\.dll$" REGEX "/libgcc.*\\.dll" REGEX "/mingw.*\\.dll"
55- )
56+ #message(STATUS "QT_BINARY_DIR is ${QT_BINARY_DIR}")
57+ install(DIRECTORY "${QT_BINARY_DIR}/" DESTINATION "${KLF_INSTALL_LIB_DIR}" FILES_MATCHING
58+ PATTERN "libgcc*.dll"
59+ PATTERN "mingw*.dll"
60+ REGEX "/Qt(Core|Gui|Sql|Xml)4?\\.dll$"
61+ )
62 set(qtplugin_list ${KLF_INSTALL_QTPLUGINS_LIST})
63 set(qtplugin_list "dummyitem" ${qtplugin_list})
64 string(REGEX REPLACE ";" ";${QT_PLUGINS_DIR}/" qtplugin_list_temp "${qtplugin_list}")
65
66=== modified file 'src/klfbackend/klfbackend.cpp'
67--- src/klfbackend/klfbackend.cpp 2012-01-02 20:23:27 +0000
68+++ src/klfbackend/klfbackend.cpp 2014-03-24 20:24:05 +0000
69@@ -19,7 +19,7 @@
70 * Free Software Foundation, Inc., *
71 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
72 ***************************************************************************/
73-/* $Id: klfbackend.cpp 748 2012-01-01 15:06:40Z phfaist $ */
74+/* $Id: klfbackend.cpp 863 2013-11-23 13:14:34Z phfaist $ */
75
76 #include <stdio.h>
77 #include <stdlib.h>
78@@ -33,7 +33,6 @@
79 #include <qbuffer.h>
80 #include <qdir.h>
81
82-
83 #include "klfblockprocess.h"
84 #include "klfbackend.h"
85
86@@ -205,6 +204,22 @@
87
88
89
90+// utilities for dealing with bounding boxes in EPS file
91+// (backported from 3.3)
92+
93+// A Bounding Box
94+struct klfbbox {
95+ double x1, x2, y1, y2;
96+};
97+static bool read_eps_bbox(const QByteArray& epsdata, klfbbox *bbox, KLFBackend::klfOutput * resError);
98+static void correct_eps_bbox(const QByteArray& epsdata, const klfbbox& bbox_corrected, const klfbbox& bbox_orig,
99+ double vectorscale, QByteArray * epsdatacorrected);
100+
101+
102+
103+
104+
105+
106 KLFBackend::klfOutput KLFBackend::getLatexFormula(const klfInput& in, const klfSettings& settings)
107 {
108 // ALLOW ONLY ONE RUNNING getLatexFormula() AT A TIME
109@@ -254,7 +269,13 @@
110 // - if epstopdfexec is not empty, run epstopdf and get PDF file.
111
112 QString tempfname = settings.tempdir + "/klatexformulatmp" KLF_VERSION_STRING "-"
113- + QDateTime::currentDateTime().toString("hh-mm-ss");
114+ + QDateTime::currentDateTime().toString("hh-mm-ss")
115+#ifdef KLFBACKEND_QT4
116+ + "-p"+ QString("%1").arg(QApplication::applicationPid(), 0, 26)
117+#else
118+ + "-p" + QString("%1").arg(rand()%100000, 0, 26)
119+#endif
120+ ;
121
122 QString fnTex = tempfname + ".tex";
123 QString fnDvi = tempfname + ".dvi";
124@@ -391,71 +412,122 @@
125 return res;
126 }
127
128- // add some space on bounding-box to avoid some too tight bounding box bugs
129- // read eps file
130- QFile epsfile(fnRawEps);
131- r = epsfile.open(dev_READONLY);
132- if ( ! r ) {
133- res.status = KLFERR_EPSREADFAIL;
134- res.errorstr = QObject::tr("Can't read file '%1'!\n", "KLFBackend").arg(fnRawEps);
135- return res;
136- }
137- /** \todo Hi-Res bounding box adjustment. Shouldn't be too hard to do, but needs tests to see
138- * how this works... [ Currently: only integer-valued BoundingBox: is adjusted. ] */
139- QByteArray epscontent = epsfile.readAll();
140-#ifdef KLFBACKEND_QT4
141- QByteArray epscontent_s = epscontent;
142- int i = epscontent_s.indexOf("%%BoundingBox: ");
143-#else
144- QCString epscontent_s(epscontent.data(), epscontent.size());
145- int i = epscontent_s.find("%%BoundingBox: ");
146-#endif
147- // process file data and transform it
148- if ( i == -1 ) {
149- res.status = KLFERR_NOEPSBBOX;
150- res.errorstr = QObject::tr("File '%1' does not contain line \"%%BoundingBox: ... \" !",
151- "KLFBackend").arg(fnRawEps);
152- return res;
153- }
154- int ax, ay, bx, by;
155- char temp[250];
156- const int k = i;
157- i += strlen("%%BoundingBox:");
158- int n = sscanf(epscontent_s.data()+i, "%d %d %d %d", &ax, &ay, &bx, &by);
159- if ( n != 4 ) {
160- res.status = KLFERR_BADEPSBBOX;
161- res.errorstr = QObject::tr("file %1: Line %%BoundingBox: can't read values!\n", "KLFBackend")
162- .arg(fnRawEps);
163- return res;
164- }
165- // grow bbox by settings.Xborderoffset points
166- // Don't forget: '%' in printf has special meaning (!) -> double percent signs '%'->'%%'
167- sprintf(temp, "%%%%BoundingBox: %d %d %d %d",
168- (int)(ax-settings.lborderoffset+0.5),
169- (int)(ay-settings.bborderoffset+0.5),
170- (int)(bx+settings.rborderoffset+0.5),
171- (int)(by+settings.tborderoffset+0.5));
172- QString chunk = QString::fromLocal8Bit(epscontent_s.data()+k);
173- QRegExp rx("^%%BoundingBox: [0-9]+ [0-9]+ [0-9]+ [0-9]+");
174- rx.rx_indexin(chunk);
175- int l = rx.matchedLength();
176- epscontent_s.replace(k, l, temp);
177-
178- // write content back to second file
179- QFile epsgoodfile(fnBBCorrEps);
180- r = epsgoodfile.open(dev_WRITEONLY);
181- if ( ! r ) {
182- res.status = KLFERR_EPSWRITEFAIL;
183- res.errorstr = QObject::tr("Can't write to file '%1'!\n", "KLFBackend")
184- .arg(fnBBCorrEps);
185- return res;
186- }
187- epsgoodfile.dev_write(epscontent_s);
188-
189- if ( ! settings.outlineFonts ) {
190- res.epsdata.ba_assign(epscontent_s);
191- }
192- // res.epsdata is now set.
193+// { // DEAL WITH BOUNDING BOX
194+
195+// // add some space on bounding-box to avoid some too tight bounding box bugs
196+// // read eps file
197+// QFile epsfile(fnRawEps);
198+// r = epsfile.open(dev_READONLY);
199+// if ( ! r ) {
200+// res.status = KLFERR_EPSREADFAIL;
201+// res.errorstr = QObject::tr("Can't read file '%1'!\n", "KLFBackend").arg(fnRawEps);
202+// return res;
203+// }
204+// /** \todo Hi-Res bounding box adjustment. Shouldn't be too hard to do, but needs tests to see
205+// * how this works... [ Currently: only integer-valued BoundingBox: is adjusted. ] */
206+// QByteArray epscontent = epsfile.readAll();
207+// #ifdef KLFBACKEND_QT4
208+// QByteArray epscontent_s = epscontent;
209+// int i = epscontent_s.indexOf("%%BoundingBox: ");
210+// #else
211+// QCString epscontent_s(epscontent.data(), epscontent.size());
212+// int i = epscontent_s.find("%%BoundingBox: ");
213+// #endif
214+// // process file data and transform it
215+// if ( i == -1 ) {
216+// res.status = KLFERR_NOEPSBBOX;
217+// res.errorstr = QObject::tr("File '%1' does not contain line \"%%BoundingBox: ... \" !",
218+// "KLFBackend").arg(fnRawEps);
219+// return res;
220+// }
221+// int ax, ay, bx, by;
222+// char temp[250];
223+// const int k = i;
224+// i += strlen("%%BoundingBox:");
225+// int n = sscanf(epscontent_s.data()+i, "%d %d %d %d", &ax, &ay, &bx, &by);
226+// if ( n != 4 ) {
227+// res.status = KLFERR_BADEPSBBOX;
228+// res.errorstr = QObject::tr("file %1: Line %%BoundingBox: can't read values!\n", "KLFBackend")
229+// .arg(fnRawEps);
230+// return res;
231+// }
232+// // grow bbox by settings.Xborderoffset points
233+// // Don't forget: '%' in printf has special meaning (!) -> double percent signs '%'->'%%'
234+// sprintf(temp, "%%%%BoundingBox: %d %d %d %d",
235+// (int)(ax-settings.lborderoffset+0.5),
236+// (int)(ay-settings.bborderoffset+0.5),
237+// (int)(bx+settings.rborderoffset+0.5),
238+// (int)(by+settings.tborderoffset+0.5));
239+// QString chunk = QString::fromLocal8Bit(epscontent_s.data()+k);
240+// QRegExp rx("^%%BoundingBox: [0-9]+ [0-9]+ [0-9]+ [0-9]+");
241+// rx.rx_indexin(chunk);
242+// int l = rx.matchedLength();
243+// epscontent_s.replace(k, l, temp);
244+
245+// // write content back to second file
246+// QFile epsgoodfile(fnBBCorrEps);
247+// r = epsgoodfile.open(dev_WRITEONLY);
248+// if ( ! r ) {
249+// res.status = KLFERR_EPSWRITEFAIL;
250+// res.errorstr = QObject::tr("Can't write to file '%1'!\n", "KLFBackend")
251+// .arg(fnBBCorrEps);
252+// return res;
253+// }
254+// epsgoodfile.dev_write(epscontent_s);
255+
256+// if ( ! settings.outlineFonts ) {
257+// res.epsdata.ba_assign(epscontent_s);
258+// }
259+// // res.epsdata is now set.
260+
261+// }
262+
263+ { // DEAL WITH BBOX: BACKPORT FROM 3.3
264+
265+ // read eps file
266+ QFile epsfile(fnRawEps);
267+ r = epsfile.open(dev_READONLY);
268+ if ( ! r ) {
269+ res.status = KLFERR_EPSREADFAIL;
270+ res.errorstr = QObject::tr("Can't read file '%1'!\n", "KLFBackend").arg(fnRawEps);
271+ return res;
272+ }
273+ QByteArray rawepsdata = epsfile.readAll();
274+
275+ klfbbox bbox, bbox_corrected;
276+ bool ok = read_eps_bbox(rawepsdata, &bbox, &res);
277+ if (!ok)
278+ return res; // res was set by the function
279+
280+ bbox.x1 -= settings.lborderoffset;
281+ bbox.y1 -= settings.bborderoffset;
282+ bbox.x2 += settings.rborderoffset;
283+ bbox.y2 += settings.tborderoffset;
284+
285+ int width_pt = bbox.x2 - bbox.x1;
286+ int height_pt = bbox.y2 - bbox.y1;
287+
288+ // now correct the bbox to (0,0,width,height)
289+
290+ bbox_corrected.x1 = 0;
291+ bbox_corrected.y1 = 0;
292+ bbox_corrected.x2 = width_pt;
293+ bbox_corrected.y2 = height_pt;
294+
295+ // and generate corrected raw EPS
296+ correct_eps_bbox(rawepsdata, bbox_corrected, bbox, 1.0,
297+ &res.epsdata);
298+
299+ QFile epsgoodfile(fnBBCorrEps);
300+ r = epsgoodfile.open(dev_WRITEONLY);
301+ if ( ! r ) {
302+ res.status = KLFERR_EPSWRITEFAIL;
303+ res.errorstr = QObject::tr("Can't write to file '%1'!\n", "KLFBackend")
304+ .arg(fnBBCorrEps);
305+ return res;
306+ }
307+ epsgoodfile.dev_write(res.epsdata);
308+ }
309
310 qDebug("%s: %s: eps bbox set.", KLF_FUNC_NAME, KLF_SHORT_TIME) ;
311
312@@ -464,15 +536,48 @@
313 if (settings.outlineFonts) {
314 // run 'gs' to outline fonts
315 KLFBlockProcess proc;
316- QStringList args;
317- args << settings.gsexec << "-dNOCACHE" << "-dNOPAUSE" << "-dSAFER" << "-dEPSCrop"
318- << "-sDEVICE=pswrite" << "-sOutputFile="+dir_native_separators(fnOutlFontsEps)
319- << "-q" << "-dBATCH" << dir_native_separators(fnBBCorrEps);
320-
321- qDebug("%s: %s: about to gs (for outline fonts)...\n%s", KLF_FUNC_NAME, KLF_SHORT_TIME,
322- qPrintable(args.join(" ")));
323- bool r = proc.startProcess(args, execenv);
324- qDebug("%s: %s: gs returned (for outline fonts).", KLF_FUNC_NAME, KLF_SHORT_TIME) ;
325+
326+ // Very bad joke from ghostscript's guys: they deprecate pswrite device, which worked very well, and
327+ // so I had to adapt the code so that it works with the new ps2write device. The bounding boxes were
328+ // going like hell. Hopefully a backport of the new system in 3.3 seemed to fix the issue.
329+
330+ // So now we have to make sure we use ps2write on newer systems but make sure we still use pswrite on
331+ // old systems which don't support ps2write. THANKS A TON GS GUYS :(
332+
333+ // In 3.2 we don't query gs version so we have no idea. So just let the user define an environment
334+ // variable in case. KLFBACKEND_GS_PS_DEVICE="pswrite" or "epswrite" or "ps2write" (note: with epswrite
335+ // you can't expand the bbox)
336+
337+ QStringList try_ps_devices;
338+ const char *env_gs_device = getenv("KLFBACKEND_GS_PS_DEVICE");
339+ if (env_gs_device != NULL) {
340+ try_ps_devices << QString::fromLatin1(env_gs_device);
341+ } else {
342+ try_ps_devices << QLatin1String("pswrite") << QLatin1String("ps2write");
343+ }
344+
345+ bool r = false;
346+ int try_ps_dev_i = 0;
347+ for (try_ps_dev_i = 0; try_ps_dev_i < try_ps_devices.size(); try_ps_dev_i++) {
348+ QString psdev = try_ps_devices[try_ps_dev_i];
349+ qDebug("trying with gs device %s ...", qPrintable(psdev));
350+
351+ QStringList args;
352+ args << settings.gsexec << "-dNOCACHE" << "-dNOPAUSE" << "-dSAFER" << "-dEPSCrop"
353+ << QString("-sDEVICE=%1").arg(psdev)
354+ << "-sOutputFile="+dir_native_separators(fnOutlFontsEps)
355+ << "-q" << "-dBATCH" << dir_native_separators(fnBBCorrEps);
356+
357+ qDebug("%s: %s: about to gs (for outline fonts)...\n%s", KLF_FUNC_NAME, KLF_SHORT_TIME,
358+ qPrintable(args.join(" ")));
359+ r = proc.startProcess(args, execenv);
360+ qDebug("%s: %s: gs returned (for outline fonts).", KLF_FUNC_NAME, KLF_SHORT_TIME) ;
361+
362+ if (r && proc.processNormalExit() && proc.processExitStatus() == 0) {
363+ // successful run
364+ break;
365+ }
366+ }
367
368 if ( ! r ) {
369 res.status = KLFERR_NOGSPROG;
370@@ -653,6 +758,253 @@
371 }
372
373
374+
375+static bool s_starts_with(const char * x, int len_x, const char *test, int len_test)
376+{
377+ if (len_x < len_test)
378+ return false;
379+ return !strncmp(x, test, len_test);
380+}
381+
382+#define D_RX "([0-9eE.-]+)"
383+
384+static bool parse_bbox_values(const QString& str, klfbbox *bbox)
385+{
386+ // parse bbox values
387+ QRegExp rx_bbvalues("" D_RX "\\s+" D_RX "\\s+" D_RX "\\s+" D_RX "");
388+ int i = rx_bbvalues.rx_indexin(str);
389+ if (i < 0) {
390+ return false;
391+ }
392+ bbox->x1 = rx_bbvalues.cap(1).toDouble();
393+ bbox->y1 = rx_bbvalues.cap(2).toDouble();
394+ bbox->x2 = rx_bbvalues.cap(3).toDouble();
395+ bbox->y2 = rx_bbvalues.cap(4).toDouble();
396+ return true;
397+}
398+
399+static bool read_eps_bbox(const QByteArray& epsdata, klfbbox *bbox, KLFBackend::klfOutput * resError)
400+{
401+ static const char * hibboxtag = "%%HiResBoundingBox:";
402+ static const char * bboxtag = "%%BoundingBox:";
403+ static const int hibboxtaglen = strlen(hibboxtag);
404+ static const int bboxtaglen = strlen(bboxtag);
405+
406+ // Read dvips' bounding box.
407+ QBuffer buf;
408+ buf_setdata(buf, epsdata);
409+ bool r = buf.open(dev_READONLY);
410+ if (!r) {
411+ qWarning("What's going on!!?! can't open buffer for reading? Will Fail!!!") ;
412+ }
413+
414+ QString nobboxerrstr =
415+ QObject::tr("DVIPS did not provide parsable %%BoundingBox: in its output!", "KLFBackend");
416+
417+ char linebuffer[512];
418+ int n;
419+ bool gotepsbbox = false;
420+ int still_look_for_hiresbbox_lines = 5;
421+ while ((n = buf.readLine(linebuffer, sizeof(linebuffer)-1)) > 0) {
422+ if (gotepsbbox && still_look_for_hiresbbox_lines-- < 0) {
423+ // if we already got the %BoundingBox, and we've been looking at more than a certian number of lines
424+ // after that, abort because usually %BoundingBox and %HiResBoundingBox are together...
425+ klfDbg("stopped looking for hires-bbox.") ;
426+ break;
427+ }
428+ if (s_starts_with(linebuffer, n-1, hibboxtag, hibboxtaglen)) {
429+ // got hi-res bounding-box
430+ bool ok = parse_bbox_values(QString::fromLatin1(linebuffer+hibboxtaglen), bbox);
431+ if (!ok) {
432+ resError->status = KLFERR_BADEPSBBOX;
433+ resError->errorstr = nobboxerrstr;
434+ return false;
435+ }
436+ klfDbg("got hires-bbox.") ;
437+ // all ok, got hi-res bbox
438+ return true;
439+ }
440+ if (s_starts_with(linebuffer, n-1, bboxtag, bboxtaglen)) {
441+ // got bounding-box.
442+ bool ok = parse_bbox_values(QString::fromLatin1(linebuffer+bboxtaglen), bbox);
443+ if (!ok) {
444+ continue;
445+ }
446+ // stand by, continue in case we have a hi-res bbox.
447+ gotepsbbox = true;
448+ klfDbg("got normal bbox.") ;
449+ continue;
450+ }
451+ }
452+
453+ // didn't get a hi-res bbox. see if we still got a regular %BoundingBox: and return that.
454+ if (gotepsbbox) {
455+ // bbox pointer is already set
456+ return true;
457+ }
458+
459+ resError->status = KLFERR_BADEPSBBOX;
460+ resError->errorstr = nobboxerrstr;
461+ return false;
462+}
463+
464+// static int find_ba_in_ba(const QByteArray& haystack, const QByteArray& needle)
465+// {
466+// #ifdef KLFBACKEND_QT4
467+// return haystack.indexOf(needle);
468+// #else
469+// int k, j;
470+// for (k = 0; k < haystack.length()-needle.length(); ++k) {
471+// // locally compare haystack and needle
472+// for (j = 0; j < needle.length(); ++j) {
473+// if (haystack[k+j] != needle[j])
474+// break; // nope they're not the same
475+// }
476+// if (j == needle.length())
477+// // found the needle
478+// return k;
479+// }
480+// return -1;
481+// #endif
482+// }
483+
484+static void correct_eps_bbox(const QByteArray& rawepsdata, const klfbbox& bbox_corrected,
485+ const klfbbox& bbox_orig, double vectorscale,
486+ QByteArray * epsdatacorrected)
487+{
488+ static const char * bboxdecl = "%%BoundingBox:";
489+ static int bboxdecl_len = strlen(bboxdecl);
490+
491+ double offx = bbox_corrected.x1 - bbox_orig.x1;
492+ double offy = bbox_corrected.y1 - bbox_orig.y1;
493+
494+ // in raw EPS data, find '%%BoundingBox:' and length of the full BoundingBox instruction
495+ int i, len;
496+ char nl[] = "\0\0\0";
497+#ifdef KLFBACKEND_QT4
498+ i = rawepsdata.indexOf(bboxdecl);
499+#else
500+ QCString rawepsdata_s(rawepsdata.data(), rawepsdata.size());
501+ i = rawepsdata_s.find(bboxdecl);
502+#endif
503+ if (i < 0) {
504+ i = 0;
505+ len = 0;
506+ } else {
507+ int j = i+bboxdecl_len;
508+ while (j < (int)rawepsdata.size() && rawepsdata[j] != '\r' && rawepsdata[j] != '\n')
509+ ++j;
510+ len = j-i;
511+ // also determine what the newline is (\n, \r, \r\n?)
512+ if (rawepsdata[j] == '\r' && j < (int)rawepsdata.size()-1 && rawepsdata[j+1] == '\n') {
513+ nl[0] = '\r', nl[1] = '\n';
514+ } else {
515+ nl[0] = rawepsdata[j];
516+ }
517+ }
518+
519+ double dwi = bbox_corrected.x2 * vectorscale;
520+ double dhi = bbox_corrected.y2 * vectorscale;
521+ int wi = (int)(dwi + 0.99999) ;
522+ int hi = (int)(dhi + 0.99999) ;
523+ char buffer[1024];
524+ int buffer_len;
525+ // recall that '%%' in printf is replaced by a single '%'...
526+ snprintf(buffer, sizeof(buffer)-1,
527+ "%%%%BoundingBox: 0 0 %d %d%s"
528+ "%%%%HiResBoundingBox: 0 0 %.6g %.6g%s",
529+ wi, hi, nl,
530+ dwi, dhi, nl);
531+ buffer_len = strlen(buffer);
532+
533+ /*
534+ char backgroundfillps[1024] = "";
535+ if (qAlpha(bgcolor) > 0) {
536+ sprintf(backgroundfillps,
537+ // draw the background color, if any
538+ "newpath "
539+ "-2 -2 moveto "
540+ "%s -2 lineto "
541+ "%s %s lineto "
542+ "-2 %s lineto "
543+ "closepath "
544+ "gsave "
545+ "%s %s %s setrgbcolor "
546+ "fill "
547+ "grestore %s",
548+ klfFmtDoubleCC(dwi+1, 'g', 6),
549+ klfFmtDoubleCC(dwi+1, 'g', 6), klfFmtDoubleCC(dhi+1, 'g', 6),
550+ klfFmtDoubleCC(dhi+1, 'g', 6),
551+ // and the color, in RGB components:
552+ klfFmtDoubleCC(qRed(bgcolor)/255.0, 'f', 6),
553+ klfFmtDoubleCC(qGreen(bgcolor)/255.0, 'f', 6),
554+ klfFmtDoubleCC(qBlue(bgcolor)/255.0, 'f', 6),
555+ nl
556+ );
557+ }
558+ */
559+
560+ char buffer2[1024];
561+ int buffer2_len;
562+ snprintf(buffer2, sizeof(buffer2)-1,
563+ "%s"
564+ "%%%%Page 1 1%s"
565+ "%%%%PageBoundingBox 0 0 %d %d%s"
566+ "<< /PageSize [%d %d] >> setpagedevice%s"
567+ //"%s"
568+ "%f %f scale%s"
569+ "%f %f translate%s"
570+ ,
571+ nl,
572+ nl,
573+ wi, hi, nl,
574+ wi, hi, nl,
575+ //backgroundfillps,
576+ vectorscale, vectorscale, nl,
577+ offx, offy, nl);
578+ buffer2_len = strlen(buffer2);
579+
580+ // char buffer2[128];
581+ // snprintf(buffer2, 127, "%sgrestore%s", nl, nl);
582+
583+ //klfDbg("buffer is `"<<buffer<<"', length="<<buffer_len) ;
584+ //klfDbg("rawepsdata has length="<<rawepsdata.size()) ;
585+
586+ // and modify the raw EPS data, to replace "%%BoundingBox:" instruction by our stuff...
587+#ifdef KLFBACKEND_QT4
588+ QByteArray neweps;
589+ neweps = rawepsdata;
590+#else
591+ QCString neweps(rawepsdata.data(), rawepsdata.size()); // makes deep copy
592+#endif
593+ neweps.replace(i, len, buffer);
594+
595+ const char * endsetupstr = "%%EndSetup";
596+ int i2 = neweps.s_indexOf(endsetupstr);
597+ if (i2 < 0)
598+ i2 = i + buffer_len; // add our info after modified %%BoundingBox'es instructions if %%EndSetup not found
599+ else
600+ i2 += strlen(endsetupstr);
601+
602+ neweps.replace(i2, 0, buffer2);
603+
604+ qDebug("neweps has now length=%d",neweps.size());
605+ qDebug("New eps bbox is [0 0 %.6g %.6g] with translate [%.6g %.6g] and scale %.6g.",
606+ dwi, dhi, offx, offy, vectorscale);
607+
608+ epsdatacorrected->ba_assign(neweps);
609+}
610+
611+
612+
613+
614+
615+
616+
617+
618+
619+
620+
621 void KLFBackend::cleanup(QString tempfname)
622 {
623 const char *skipcleanup = getenv("KLFBACKEND_LEAVE_TEMP_FILES");
624@@ -674,9 +1026,14 @@
625 if (QFile::exists(tempfname+".pdf")) QFile::remove(tempfname+".pdf");
626 }
627
628+
629+
630+
631 // static private mutex object
632 QMutex KLFBackend::__mutex;
633
634+
635+
636 KLF_EXPORT bool operator==(const KLFBackend::klfInput& a, const KLFBackend::klfInput& b)
637 {
638 return a.latex == b.latex &&
639
640=== modified file 'src/klfbackend/klfblockprocess.cpp'
641--- src/klfbackend/klfblockprocess.cpp 2013-07-22 17:50:27 +0000
642+++ src/klfbackend/klfblockprocess.cpp 2014-03-24 20:24:05 +0000
643@@ -19,7 +19,7 @@
644 * Free Software Foundation, Inc., *
645 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
646 ***************************************************************************/
647-/* $Id: klfblockprocess.cpp 856 2013-06-23 10:38:35Z phfaist $ */
648+/* $Id: klfblockprocess.cpp 862 2013-11-23 11:10:54Z phfaist $ */
649
650 #include <ctype.h>
651
652@@ -70,7 +70,7 @@
653
654 bool KLFBlockProcess::startProcess(QStringList cmd, QByteArray stdindata, QStringList env)
655 {
656- klfDbg("Running: "<<cmd<<", stdindata/size="<<stdindata.size());
657+ // klfDbg("Running: "<<cmd<<", stdindata/size="<<stdindata.size());
658
659 _runstatus = 0;
660
661@@ -87,7 +87,7 @@
662 fn = klfSearchPath(cmd[0]);
663 QFile fpeek(fn);
664 if (!fpeek.open(QIODevice::ReadOnly)) {
665- klfDbg("cmd[0]="<<cmd[0]<<", Can't peek into file "<<fn<<"!") ;
666+ //klfDbg("cmd[0]="<<cmd[0]<<", Can't peek into file "<<fn<<"!") ;
667 } else {
668 QByteArray line;
669 int n = 0, j;
670@@ -114,8 +114,8 @@
671
672 QString program = cmd[0];
673
674- klfDbg("Running cmd="<<cmd);
675- klfDbg("env="<<env<<", curenv="<<environment());
676+ //klfDbg("Running cmd="<<cmd);
677+ //klfDbg("env="<<env<<", curenv="<<environment());
678
679 #ifdef KLFBACKEND_QT4
680 if (env.size() > 0) {
681@@ -124,17 +124,17 @@
682
683 QStringList args = cmd;
684 args.erase(args.begin());
685- klfDbg("Starting "<<program<<", "<<args) ;
686+ //klfDbg("Starting "<<program<<", "<<args) ;
687 start(program, args);
688 if ( ! waitForStarted() ) {
689- klfDbg("Can't wait for started! Error="<<error()) ;
690+ //klfDbg("Can't wait for started! Error="<<error()) ;
691 return false;
692 }
693
694 write(stdindata.constData(), stdindata.size());
695 closeWriteChannel();
696
697- klfDbg("wrote input data (size="<<stdindata.size()<<")") ;
698+ //klfDbg("wrote input data (size="<<stdindata.size()<<")") ;
699
700 #else
701 setArguments(cmd);
702@@ -168,7 +168,7 @@
703 #endif
704
705 if (_runstatus < 0) { // some error occurred somewhere
706- klfDbg("some error occurred, _runstatus="<<_runstatus) ;
707+ klfDbg("some error occurred, _runstatus="+QString("%1").arg(_runstatus)) ;
708 return false;
709 }
710
711
712=== modified file 'src/klfbackend/klfdebug.h'
713--- src/klfbackend/klfdebug.h 2012-01-02 20:23:27 +0000
714+++ src/klfbackend/klfdebug.h 2014-03-24 20:24:05 +0000
715@@ -19,7 +19,7 @@
716 * Free Software Foundation, Inc., *
717 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
718 ***************************************************************************/
719-/* $Id: klfdebug.h 748 2012-01-01 15:06:40Z phfaist $ */
720+/* $Id: klfdebug.h 862 2013-11-23 11:10:54Z phfaist $ */
721
722 #ifndef KLFDEBUG_H
723 #define KLFDEBUG_H
724@@ -235,7 +235,7 @@
725 #else
726 #define KLF_ASSERT_CONDITION(expr, msg, failaction) \
727 if ( !(expr) ) { \
728- qWarning("In function %s:\n\t%s", (QString("")+msg).local8Bit().data()); \
729+ qWarning("In function %s:\n\t%s", KLF_FUNC_NAME, (QString("")+msg).local8Bit().data()); \
730 failaction; \
731 }
732 #endif
733
734=== modified file 'src/klfbackend/klfqt34common.h'
735--- src/klfbackend/klfqt34common.h 2011-05-15 17:55:27 +0000
736+++ src/klfbackend/klfqt34common.h 2014-03-24 20:24:05 +0000
737@@ -19,7 +19,7 @@
738 * Free Software Foundation, Inc., *
739 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
740 ***************************************************************************/
741-/* $Id: klfqt34common.h 603 2011-02-26 23:14:55Z phfaist $ */
742+/* $Id: klfqt34common.h 862 2013-11-23 11:10:54Z phfaist $ */
743
744 #ifndef KLFQT34COMMON_H
745 #define KLFQT34COMMON_H
746@@ -30,6 +30,7 @@
747 #ifdef KLFBACKEND_QT4
748 #define dir_native_separators(x) QDir::toNativeSeparators(x)
749 #define ba_assign(otherba) operator=(otherba)
750+#define buf_setdata(buf, ba_ref) buf.setData(ba_ref)
751 #define dev_WRITEONLY QIODevice::WriteOnly
752 #define dev_READONLY QIODevice::ReadOnly
753 #define dev_write write
754@@ -54,6 +55,7 @@
755 #define QLatin1String QString::fromLatin1
756 #define dir_native_separators(x) QDir::convertSeparators(x)
757 #define ba_assign(otherba) duplicate((otherba).data(), (otherba).size())
758+#define buf_setdata(buf, ba_ref) buf.setBuffer(ba_ref)
759 #define dev_WRITEONLY IO_WriteOnly
760 #define dev_READONLY IO_ReadOnly
761 #define dev_write writeBlock

Subscribers

People subscribed via source and target branches

to all changes: