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
=== modified file 'VERSION'
--- VERSION 2013-07-22 17:50:27 +0000
+++ VERSION 2014-03-24 20:24:05 +0000
@@ -1,1 +1,1 @@
13.2.713.2.8
22
=== modified file 'debian/changelog'
--- debian/changelog 2013-07-22 17:50:27 +0000
+++ debian/changelog 2014-03-24 20:24:05 +0000
@@ -1,3 +1,10 @@
1klatexformula (3.2.8-0ubuntu1) trusty; urgency=medium
2
3 * New upstream release. LP: #1296902
4 - fixes a bug caused by recent versions of ghostscript
5
6 -- Jackson Doak <noskcaj@ubuntu.com> Tue, 25 Mar 2014 07:03:05 +1100
7
1klatexformula (3.2.7-1) unstable; urgency=low8klatexformula (3.2.7-1) unstable; urgency=low
29
3 * New upstream release10 * New upstream release
411
=== modified file 'debian/control'
--- debian/control 2013-07-22 17:50:27 +0000
+++ debian/control 2014-03-24 20:24:05 +0000
@@ -1,7 +1,8 @@
1Source: klatexformula1Source: klatexformula
2Section: tex2Section: tex
3Priority: extra3Priority: extra
4Maintainer: Tobias Winchen <winchen@physik.rwth-aachen.de> 4Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
5XSBC-Original-Maintainer: Tobias Winchen <winchen@physik.rwth-aachen.de>
5Build-Depends: cdbs, debhelper (>= 7), docbook-to-man, cmake, libqt4-dev, pkg-kde-tools, kdelibs5-dev, libx11-dev6Build-Depends: cdbs, debhelper (>= 7), docbook-to-man, cmake, libqt4-dev, pkg-kde-tools, kdelibs5-dev, libx11-dev
6Standards-Version: 3.9.47Standards-Version: 3.9.4
7Vcs-git: git://github.com/winchen/klatexformula_debian.git8Vcs-git: git://github.com/winchen/klatexformula_debian.git
89
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2012-01-02 20:23:27 +0000
+++ src/CMakeLists.txt 2014-03-24 20:24:05 +0000
@@ -1,7 +1,7 @@
1# ######################################## #1# ######################################## #
2# CMake project file for klatexformula/src #2# CMake project file for klatexformula/src #
3# ######################################## #3# ######################################## #
4# $Id: CMakeLists.txt 742 2011-10-09 11:02:08Z phfaist $4# $Id: CMakeLists.txt 864 2013-11-23 13:52:28Z phfaist $
5# ######################################## #5# ######################################## #
66
7if(KLF_MACOSX_BUNDLES)7if(KLF_MACOSX_BUNDLES)
@@ -503,9 +503,12 @@
503if(WIN32 AND KLF_INSTALL_QTLIBS)503if(WIN32 AND KLF_INSTALL_QTLIBS)
504 # Install Qt libs504 # Install Qt libs
505 # QT_BINARY_DIR and QT_PLUGINS_DIR are set by FindQt4 CMake module505 # QT_BINARY_DIR and QT_PLUGINS_DIR are set by FindQt4 CMake module
506 install(DIRECTORY "${QT_BINARY_DIR}/" DESTINATION "${KLF_INSTALL_LIB_DIR}"506 #message(STATUS "QT_BINARY_DIR is ${QT_BINARY_DIR}")
507 FILES_MATCHING REGEX "/Qt(Core|Gui|Sql|Xml)4?\\.dll$" REGEX "/libgcc.*\\.dll" REGEX "/mingw.*\\.dll"507 install(DIRECTORY "${QT_BINARY_DIR}/" DESTINATION "${KLF_INSTALL_LIB_DIR}" FILES_MATCHING
508 )508 PATTERN "libgcc*.dll"
509 PATTERN "mingw*.dll"
510 REGEX "/Qt(Core|Gui|Sql|Xml)4?\\.dll$"
511 )
509 set(qtplugin_list ${KLF_INSTALL_QTPLUGINS_LIST})512 set(qtplugin_list ${KLF_INSTALL_QTPLUGINS_LIST})
510 set(qtplugin_list "dummyitem" ${qtplugin_list})513 set(qtplugin_list "dummyitem" ${qtplugin_list})
511 string(REGEX REPLACE ";" ";${QT_PLUGINS_DIR}/" qtplugin_list_temp "${qtplugin_list}")514 string(REGEX REPLACE ";" ";${QT_PLUGINS_DIR}/" qtplugin_list_temp "${qtplugin_list}")
512515
=== modified file 'src/klfbackend/klfbackend.cpp'
--- src/klfbackend/klfbackend.cpp 2012-01-02 20:23:27 +0000
+++ src/klfbackend/klfbackend.cpp 2014-03-24 20:24:05 +0000
@@ -19,7 +19,7 @@
19 * Free Software Foundation, Inc., *19 * Free Software Foundation, Inc., *
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21 ***************************************************************************/21 ***************************************************************************/
22/* $Id: klfbackend.cpp 748 2012-01-01 15:06:40Z phfaist $ */22/* $Id: klfbackend.cpp 863 2013-11-23 13:14:34Z phfaist $ */
2323
24#include <stdio.h>24#include <stdio.h>
25#include <stdlib.h>25#include <stdlib.h>
@@ -33,7 +33,6 @@
33#include <qbuffer.h>33#include <qbuffer.h>
34#include <qdir.h>34#include <qdir.h>
3535
36
37#include "klfblockprocess.h"36#include "klfblockprocess.h"
38#include "klfbackend.h"37#include "klfbackend.h"
3938
@@ -205,6 +204,22 @@
205204
206205
207206
207// utilities for dealing with bounding boxes in EPS file
208// (backported from 3.3)
209
210// A Bounding Box
211struct klfbbox {
212 double x1, x2, y1, y2;
213};
214static bool read_eps_bbox(const QByteArray& epsdata, klfbbox *bbox, KLFBackend::klfOutput * resError);
215static void correct_eps_bbox(const QByteArray& epsdata, const klfbbox& bbox_corrected, const klfbbox& bbox_orig,
216 double vectorscale, QByteArray * epsdatacorrected);
217
218
219
220
221
222
208KLFBackend::klfOutput KLFBackend::getLatexFormula(const klfInput& in, const klfSettings& settings)223KLFBackend::klfOutput KLFBackend::getLatexFormula(const klfInput& in, const klfSettings& settings)
209{224{
210 // ALLOW ONLY ONE RUNNING getLatexFormula() AT A TIME 225 // ALLOW ONLY ONE RUNNING getLatexFormula() AT A TIME
@@ -254,7 +269,13 @@
254 // - if epstopdfexec is not empty, run epstopdf and get PDF file.269 // - if epstopdfexec is not empty, run epstopdf and get PDF file.
255270
256 QString tempfname = settings.tempdir + "/klatexformulatmp" KLF_VERSION_STRING "-"271 QString tempfname = settings.tempdir + "/klatexformulatmp" KLF_VERSION_STRING "-"
257 + QDateTime::currentDateTime().toString("hh-mm-ss");272 + QDateTime::currentDateTime().toString("hh-mm-ss")
273#ifdef KLFBACKEND_QT4
274 + "-p"+ QString("%1").arg(QApplication::applicationPid(), 0, 26)
275#else
276 + "-p" + QString("%1").arg(rand()%100000, 0, 26)
277#endif
278 ;
258279
259 QString fnTex = tempfname + ".tex";280 QString fnTex = tempfname + ".tex";
260 QString fnDvi = tempfname + ".dvi";281 QString fnDvi = tempfname + ".dvi";
@@ -391,71 +412,122 @@
391 return res;412 return res;
392 }413 }
393414
394 // add some space on bounding-box to avoid some too tight bounding box bugs415// { // DEAL WITH BOUNDING BOX
395 // read eps file416
396 QFile epsfile(fnRawEps);417// // add some space on bounding-box to avoid some too tight bounding box bugs
397 r = epsfile.open(dev_READONLY);418// // read eps file
398 if ( ! r ) {419// QFile epsfile(fnRawEps);
399 res.status = KLFERR_EPSREADFAIL;420// r = epsfile.open(dev_READONLY);
400 res.errorstr = QObject::tr("Can't read file '%1'!\n", "KLFBackend").arg(fnRawEps);421// if ( ! r ) {
401 return res;422// res.status = KLFERR_EPSREADFAIL;
402 }423// res.errorstr = QObject::tr("Can't read file '%1'!\n", "KLFBackend").arg(fnRawEps);
403 /** \todo Hi-Res bounding box adjustment. Shouldn't be too hard to do, but needs tests to see424// return res;
404 * how this works... [ Currently: only integer-valued BoundingBox: is adjusted. ] */425// }
405 QByteArray epscontent = epsfile.readAll();426// /** \todo Hi-Res bounding box adjustment. Shouldn't be too hard to do, but needs tests to see
406#ifdef KLFBACKEND_QT4427// * how this works... [ Currently: only integer-valued BoundingBox: is adjusted. ] */
407 QByteArray epscontent_s = epscontent;428// QByteArray epscontent = epsfile.readAll();
408 int i = epscontent_s.indexOf("%%BoundingBox: ");429// #ifdef KLFBACKEND_QT4
409#else430// QByteArray epscontent_s = epscontent;
410 QCString epscontent_s(epscontent.data(), epscontent.size());431// int i = epscontent_s.indexOf("%%BoundingBox: ");
411 int i = epscontent_s.find("%%BoundingBox: ");432// #else
412#endif433// QCString epscontent_s(epscontent.data(), epscontent.size());
413 // process file data and transform it434// int i = epscontent_s.find("%%BoundingBox: ");
414 if ( i == -1 ) {435// #endif
415 res.status = KLFERR_NOEPSBBOX;436// // process file data and transform it
416 res.errorstr = QObject::tr("File '%1' does not contain line \"%%BoundingBox: ... \" !",437// if ( i == -1 ) {
417 "KLFBackend").arg(fnRawEps);438// res.status = KLFERR_NOEPSBBOX;
418 return res;439// res.errorstr = QObject::tr("File '%1' does not contain line \"%%BoundingBox: ... \" !",
419 }440// "KLFBackend").arg(fnRawEps);
420 int ax, ay, bx, by;441// return res;
421 char temp[250];442// }
422 const int k = i;443// int ax, ay, bx, by;
423 i += strlen("%%BoundingBox:");444// char temp[250];
424 int n = sscanf(epscontent_s.data()+i, "%d %d %d %d", &ax, &ay, &bx, &by);445// const int k = i;
425 if ( n != 4 ) {446// i += strlen("%%BoundingBox:");
426 res.status = KLFERR_BADEPSBBOX;447// int n = sscanf(epscontent_s.data()+i, "%d %d %d %d", &ax, &ay, &bx, &by);
427 res.errorstr = QObject::tr("file %1: Line %%BoundingBox: can't read values!\n", "KLFBackend")448// if ( n != 4 ) {
428 .arg(fnRawEps);449// res.status = KLFERR_BADEPSBBOX;
429 return res;450// res.errorstr = QObject::tr("file %1: Line %%BoundingBox: can't read values!\n", "KLFBackend")
430 }451// .arg(fnRawEps);
431 // grow bbox by settings.Xborderoffset points452// return res;
432 // Don't forget: '%' in printf has special meaning (!) -> double percent signs '%'->'%%'453// }
433 sprintf(temp, "%%%%BoundingBox: %d %d %d %d",454// // grow bbox by settings.Xborderoffset points
434 (int)(ax-settings.lborderoffset+0.5),455// // Don't forget: '%' in printf has special meaning (!) -> double percent signs '%'->'%%'
435 (int)(ay-settings.bborderoffset+0.5),456// sprintf(temp, "%%%%BoundingBox: %d %d %d %d",
436 (int)(bx+settings.rborderoffset+0.5),457// (int)(ax-settings.lborderoffset+0.5),
437 (int)(by+settings.tborderoffset+0.5));458// (int)(ay-settings.bborderoffset+0.5),
438 QString chunk = QString::fromLocal8Bit(epscontent_s.data()+k);459// (int)(bx+settings.rborderoffset+0.5),
439 QRegExp rx("^%%BoundingBox: [0-9]+ [0-9]+ [0-9]+ [0-9]+");460// (int)(by+settings.tborderoffset+0.5));
440 rx.rx_indexin(chunk);461// QString chunk = QString::fromLocal8Bit(epscontent_s.data()+k);
441 int l = rx.matchedLength();462// QRegExp rx("^%%BoundingBox: [0-9]+ [0-9]+ [0-9]+ [0-9]+");
442 epscontent_s.replace(k, l, temp);463// rx.rx_indexin(chunk);
443464// int l = rx.matchedLength();
444 // write content back to second file465// epscontent_s.replace(k, l, temp);
445 QFile epsgoodfile(fnBBCorrEps);466
446 r = epsgoodfile.open(dev_WRITEONLY);467// // write content back to second file
447 if ( ! r ) {468// QFile epsgoodfile(fnBBCorrEps);
448 res.status = KLFERR_EPSWRITEFAIL;469// r = epsgoodfile.open(dev_WRITEONLY);
449 res.errorstr = QObject::tr("Can't write to file '%1'!\n", "KLFBackend")470// if ( ! r ) {
450 .arg(fnBBCorrEps);471// res.status = KLFERR_EPSWRITEFAIL;
451 return res;472// res.errorstr = QObject::tr("Can't write to file '%1'!\n", "KLFBackend")
452 }473// .arg(fnBBCorrEps);
453 epsgoodfile.dev_write(epscontent_s);474// return res;
454475// }
455 if ( ! settings.outlineFonts ) {476// epsgoodfile.dev_write(epscontent_s);
456 res.epsdata.ba_assign(epscontent_s);477
457 }478// if ( ! settings.outlineFonts ) {
458 // res.epsdata is now set.479// res.epsdata.ba_assign(epscontent_s);
480// }
481// // res.epsdata is now set.
482
483// }
484
485 { // DEAL WITH BBOX: BACKPORT FROM 3.3
486
487 // read eps file
488 QFile epsfile(fnRawEps);
489 r = epsfile.open(dev_READONLY);
490 if ( ! r ) {
491 res.status = KLFERR_EPSREADFAIL;
492 res.errorstr = QObject::tr("Can't read file '%1'!\n", "KLFBackend").arg(fnRawEps);
493 return res;
494 }
495 QByteArray rawepsdata = epsfile.readAll();
496
497 klfbbox bbox, bbox_corrected;
498 bool ok = read_eps_bbox(rawepsdata, &bbox, &res);
499 if (!ok)
500 return res; // res was set by the function
501
502 bbox.x1 -= settings.lborderoffset;
503 bbox.y1 -= settings.bborderoffset;
504 bbox.x2 += settings.rborderoffset;
505 bbox.y2 += settings.tborderoffset;
506
507 int width_pt = bbox.x2 - bbox.x1;
508 int height_pt = bbox.y2 - bbox.y1;
509
510 // now correct the bbox to (0,0,width,height)
511
512 bbox_corrected.x1 = 0;
513 bbox_corrected.y1 = 0;
514 bbox_corrected.x2 = width_pt;
515 bbox_corrected.y2 = height_pt;
516
517 // and generate corrected raw EPS
518 correct_eps_bbox(rawepsdata, bbox_corrected, bbox, 1.0,
519 &res.epsdata);
520
521 QFile epsgoodfile(fnBBCorrEps);
522 r = epsgoodfile.open(dev_WRITEONLY);
523 if ( ! r ) {
524 res.status = KLFERR_EPSWRITEFAIL;
525 res.errorstr = QObject::tr("Can't write to file '%1'!\n", "KLFBackend")
526 .arg(fnBBCorrEps);
527 return res;
528 }
529 epsgoodfile.dev_write(res.epsdata);
530 }
459531
460 qDebug("%s: %s: eps bbox set.", KLF_FUNC_NAME, KLF_SHORT_TIME) ; 532 qDebug("%s: %s: eps bbox set.", KLF_FUNC_NAME, KLF_SHORT_TIME) ;
461533
@@ -464,15 +536,48 @@
464 if (settings.outlineFonts) {536 if (settings.outlineFonts) {
465 // run 'gs' to outline fonts537 // run 'gs' to outline fonts
466 KLFBlockProcess proc;538 KLFBlockProcess proc;
467 QStringList args;539
468 args << settings.gsexec << "-dNOCACHE" << "-dNOPAUSE" << "-dSAFER" << "-dEPSCrop"540 // Very bad joke from ghostscript's guys: they deprecate pswrite device, which worked very well, and
469 << "-sDEVICE=pswrite" << "-sOutputFile="+dir_native_separators(fnOutlFontsEps)541 // so I had to adapt the code so that it works with the new ps2write device. The bounding boxes were
470 << "-q" << "-dBATCH" << dir_native_separators(fnBBCorrEps);542 // going like hell. Hopefully a backport of the new system in 3.3 seemed to fix the issue.
471543
472 qDebug("%s: %s: about to gs (for outline fonts)...\n%s", KLF_FUNC_NAME, KLF_SHORT_TIME,544 // So now we have to make sure we use ps2write on newer systems but make sure we still use pswrite on
473 qPrintable(args.join(" ")));545 // old systems which don't support ps2write. THANKS A TON GS GUYS :(
474 bool r = proc.startProcess(args, execenv);546
475 qDebug("%s: %s: gs returned (for outline fonts).", KLF_FUNC_NAME, KLF_SHORT_TIME) ; 547 // In 3.2 we don't query gs version so we have no idea. So just let the user define an environment
548 // variable in case. KLFBACKEND_GS_PS_DEVICE="pswrite" or "epswrite" or "ps2write" (note: with epswrite
549 // you can't expand the bbox)
550
551 QStringList try_ps_devices;
552 const char *env_gs_device = getenv("KLFBACKEND_GS_PS_DEVICE");
553 if (env_gs_device != NULL) {
554 try_ps_devices << QString::fromLatin1(env_gs_device);
555 } else {
556 try_ps_devices << QLatin1String("pswrite") << QLatin1String("ps2write");
557 }
558
559 bool r = false;
560 int try_ps_dev_i = 0;
561 for (try_ps_dev_i = 0; try_ps_dev_i < try_ps_devices.size(); try_ps_dev_i++) {
562 QString psdev = try_ps_devices[try_ps_dev_i];
563 qDebug("trying with gs device %s ...", qPrintable(psdev));
564
565 QStringList args;
566 args << settings.gsexec << "-dNOCACHE" << "-dNOPAUSE" << "-dSAFER" << "-dEPSCrop"
567 << QString("-sDEVICE=%1").arg(psdev)
568 << "-sOutputFile="+dir_native_separators(fnOutlFontsEps)
569 << "-q" << "-dBATCH" << dir_native_separators(fnBBCorrEps);
570
571 qDebug("%s: %s: about to gs (for outline fonts)...\n%s", KLF_FUNC_NAME, KLF_SHORT_TIME,
572 qPrintable(args.join(" ")));
573 r = proc.startProcess(args, execenv);
574 qDebug("%s: %s: gs returned (for outline fonts).", KLF_FUNC_NAME, KLF_SHORT_TIME) ;
575
576 if (r && proc.processNormalExit() && proc.processExitStatus() == 0) {
577 // successful run
578 break;
579 }
580 }
476 581
477 if ( ! r ) {582 if ( ! r ) {
478 res.status = KLFERR_NOGSPROG;583 res.status = KLFERR_NOGSPROG;
@@ -653,6 +758,253 @@
653}758}
654759
655760
761
762static bool s_starts_with(const char * x, int len_x, const char *test, int len_test)
763{
764 if (len_x < len_test)
765 return false;
766 return !strncmp(x, test, len_test);
767}
768
769#define D_RX "([0-9eE.-]+)"
770
771static bool parse_bbox_values(const QString& str, klfbbox *bbox)
772{
773 // parse bbox values
774 QRegExp rx_bbvalues("" D_RX "\\s+" D_RX "\\s+" D_RX "\\s+" D_RX "");
775 int i = rx_bbvalues.rx_indexin(str);
776 if (i < 0) {
777 return false;
778 }
779 bbox->x1 = rx_bbvalues.cap(1).toDouble();
780 bbox->y1 = rx_bbvalues.cap(2).toDouble();
781 bbox->x2 = rx_bbvalues.cap(3).toDouble();
782 bbox->y2 = rx_bbvalues.cap(4).toDouble();
783 return true;
784}
785
786static bool read_eps_bbox(const QByteArray& epsdata, klfbbox *bbox, KLFBackend::klfOutput * resError)
787{
788 static const char * hibboxtag = "%%HiResBoundingBox:";
789 static const char * bboxtag = "%%BoundingBox:";
790 static const int hibboxtaglen = strlen(hibboxtag);
791 static const int bboxtaglen = strlen(bboxtag);
792
793 // Read dvips' bounding box.
794 QBuffer buf;
795 buf_setdata(buf, epsdata);
796 bool r = buf.open(dev_READONLY);
797 if (!r) {
798 qWarning("What's going on!!?! can't open buffer for reading? Will Fail!!!") ;
799 }
800
801 QString nobboxerrstr =
802 QObject::tr("DVIPS did not provide parsable %%BoundingBox: in its output!", "KLFBackend");
803
804 char linebuffer[512];
805 int n;
806 bool gotepsbbox = false;
807 int still_look_for_hiresbbox_lines = 5;
808 while ((n = buf.readLine(linebuffer, sizeof(linebuffer)-1)) > 0) {
809 if (gotepsbbox && still_look_for_hiresbbox_lines-- < 0) {
810 // if we already got the %BoundingBox, and we've been looking at more than a certian number of lines
811 // after that, abort because usually %BoundingBox and %HiResBoundingBox are together...
812 klfDbg("stopped looking for hires-bbox.") ;
813 break;
814 }
815 if (s_starts_with(linebuffer, n-1, hibboxtag, hibboxtaglen)) {
816 // got hi-res bounding-box
817 bool ok = parse_bbox_values(QString::fromLatin1(linebuffer+hibboxtaglen), bbox);
818 if (!ok) {
819 resError->status = KLFERR_BADEPSBBOX;
820 resError->errorstr = nobboxerrstr;
821 return false;
822 }
823 klfDbg("got hires-bbox.") ;
824 // all ok, got hi-res bbox
825 return true;
826 }
827 if (s_starts_with(linebuffer, n-1, bboxtag, bboxtaglen)) {
828 // got bounding-box.
829 bool ok = parse_bbox_values(QString::fromLatin1(linebuffer+bboxtaglen), bbox);
830 if (!ok) {
831 continue;
832 }
833 // stand by, continue in case we have a hi-res bbox.
834 gotepsbbox = true;
835 klfDbg("got normal bbox.") ;
836 continue;
837 }
838 }
839
840 // didn't get a hi-res bbox. see if we still got a regular %BoundingBox: and return that.
841 if (gotepsbbox) {
842 // bbox pointer is already set
843 return true;
844 }
845
846 resError->status = KLFERR_BADEPSBBOX;
847 resError->errorstr = nobboxerrstr;
848 return false;
849}
850
851// static int find_ba_in_ba(const QByteArray& haystack, const QByteArray& needle)
852// {
853// #ifdef KLFBACKEND_QT4
854// return haystack.indexOf(needle);
855// #else
856// int k, j;
857// for (k = 0; k < haystack.length()-needle.length(); ++k) {
858// // locally compare haystack and needle
859// for (j = 0; j < needle.length(); ++j) {
860// if (haystack[k+j] != needle[j])
861// break; // nope they're not the same
862// }
863// if (j == needle.length())
864// // found the needle
865// return k;
866// }
867// return -1;
868// #endif
869// }
870
871static void correct_eps_bbox(const QByteArray& rawepsdata, const klfbbox& bbox_corrected,
872 const klfbbox& bbox_orig, double vectorscale,
873 QByteArray * epsdatacorrected)
874{
875 static const char * bboxdecl = "%%BoundingBox:";
876 static int bboxdecl_len = strlen(bboxdecl);
877
878 double offx = bbox_corrected.x1 - bbox_orig.x1;
879 double offy = bbox_corrected.y1 - bbox_orig.y1;
880
881 // in raw EPS data, find '%%BoundingBox:' and length of the full BoundingBox instruction
882 int i, len;
883 char nl[] = "\0\0\0";
884#ifdef KLFBACKEND_QT4
885 i = rawepsdata.indexOf(bboxdecl);
886#else
887 QCString rawepsdata_s(rawepsdata.data(), rawepsdata.size());
888 i = rawepsdata_s.find(bboxdecl);
889#endif
890 if (i < 0) {
891 i = 0;
892 len = 0;
893 } else {
894 int j = i+bboxdecl_len;
895 while (j < (int)rawepsdata.size() && rawepsdata[j] != '\r' && rawepsdata[j] != '\n')
896 ++j;
897 len = j-i;
898 // also determine what the newline is (\n, \r, \r\n?)
899 if (rawepsdata[j] == '\r' && j < (int)rawepsdata.size()-1 && rawepsdata[j+1] == '\n') {
900 nl[0] = '\r', nl[1] = '\n';
901 } else {
902 nl[0] = rawepsdata[j];
903 }
904 }
905
906 double dwi = bbox_corrected.x2 * vectorscale;
907 double dhi = bbox_corrected.y2 * vectorscale;
908 int wi = (int)(dwi + 0.99999) ;
909 int hi = (int)(dhi + 0.99999) ;
910 char buffer[1024];
911 int buffer_len;
912 // recall that '%%' in printf is replaced by a single '%'...
913 snprintf(buffer, sizeof(buffer)-1,
914 "%%%%BoundingBox: 0 0 %d %d%s"
915 "%%%%HiResBoundingBox: 0 0 %.6g %.6g%s",
916 wi, hi, nl,
917 dwi, dhi, nl);
918 buffer_len = strlen(buffer);
919
920 /*
921 char backgroundfillps[1024] = "";
922 if (qAlpha(bgcolor) > 0) {
923 sprintf(backgroundfillps,
924 // draw the background color, if any
925 "newpath "
926 "-2 -2 moveto "
927 "%s -2 lineto "
928 "%s %s lineto "
929 "-2 %s lineto "
930 "closepath "
931 "gsave "
932 "%s %s %s setrgbcolor "
933 "fill "
934 "grestore %s",
935 klfFmtDoubleCC(dwi+1, 'g', 6),
936 klfFmtDoubleCC(dwi+1, 'g', 6), klfFmtDoubleCC(dhi+1, 'g', 6),
937 klfFmtDoubleCC(dhi+1, 'g', 6),
938 // and the color, in RGB components:
939 klfFmtDoubleCC(qRed(bgcolor)/255.0, 'f', 6),
940 klfFmtDoubleCC(qGreen(bgcolor)/255.0, 'f', 6),
941 klfFmtDoubleCC(qBlue(bgcolor)/255.0, 'f', 6),
942 nl
943 );
944 }
945 */
946
947 char buffer2[1024];
948 int buffer2_len;
949 snprintf(buffer2, sizeof(buffer2)-1,
950 "%s"
951 "%%%%Page 1 1%s"
952 "%%%%PageBoundingBox 0 0 %d %d%s"
953 "<< /PageSize [%d %d] >> setpagedevice%s"
954 //"%s"
955 "%f %f scale%s"
956 "%f %f translate%s"
957 ,
958 nl,
959 nl,
960 wi, hi, nl,
961 wi, hi, nl,
962 //backgroundfillps,
963 vectorscale, vectorscale, nl,
964 offx, offy, nl);
965 buffer2_len = strlen(buffer2);
966
967 // char buffer2[128];
968 // snprintf(buffer2, 127, "%sgrestore%s", nl, nl);
969
970 //klfDbg("buffer is `"<<buffer<<"', length="<<buffer_len) ;
971 //klfDbg("rawepsdata has length="<<rawepsdata.size()) ;
972
973 // and modify the raw EPS data, to replace "%%BoundingBox:" instruction by our stuff...
974#ifdef KLFBACKEND_QT4
975 QByteArray neweps;
976 neweps = rawepsdata;
977#else
978 QCString neweps(rawepsdata.data(), rawepsdata.size()); // makes deep copy
979#endif
980 neweps.replace(i, len, buffer);
981
982 const char * endsetupstr = "%%EndSetup";
983 int i2 = neweps.s_indexOf(endsetupstr);
984 if (i2 < 0)
985 i2 = i + buffer_len; // add our info after modified %%BoundingBox'es instructions if %%EndSetup not found
986 else
987 i2 += strlen(endsetupstr);
988
989 neweps.replace(i2, 0, buffer2);
990
991 qDebug("neweps has now length=%d",neweps.size());
992 qDebug("New eps bbox is [0 0 %.6g %.6g] with translate [%.6g %.6g] and scale %.6g.",
993 dwi, dhi, offx, offy, vectorscale);
994
995 epsdatacorrected->ba_assign(neweps);
996}
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
656void KLFBackend::cleanup(QString tempfname)1008void KLFBackend::cleanup(QString tempfname)
657{1009{
658 const char *skipcleanup = getenv("KLFBACKEND_LEAVE_TEMP_FILES");1010 const char *skipcleanup = getenv("KLFBACKEND_LEAVE_TEMP_FILES");
@@ -674,9 +1026,14 @@
674 if (QFile::exists(tempfname+".pdf")) QFile::remove(tempfname+".pdf");1026 if (QFile::exists(tempfname+".pdf")) QFile::remove(tempfname+".pdf");
675}1027}
6761028
1029
1030
1031
677// static private mutex object1032// static private mutex object
678QMutex KLFBackend::__mutex;1033QMutex KLFBackend::__mutex;
6791034
1035
1036
680KLF_EXPORT bool operator==(const KLFBackend::klfInput& a, const KLFBackend::klfInput& b)1037KLF_EXPORT bool operator==(const KLFBackend::klfInput& a, const KLFBackend::klfInput& b)
681{1038{
682 return a.latex == b.latex &&1039 return a.latex == b.latex &&
6831040
=== modified file 'src/klfbackend/klfblockprocess.cpp'
--- src/klfbackend/klfblockprocess.cpp 2013-07-22 17:50:27 +0000
+++ src/klfbackend/klfblockprocess.cpp 2014-03-24 20:24:05 +0000
@@ -19,7 +19,7 @@
19 * Free Software Foundation, Inc., *19 * Free Software Foundation, Inc., *
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21 ***************************************************************************/21 ***************************************************************************/
22/* $Id: klfblockprocess.cpp 856 2013-06-23 10:38:35Z phfaist $ */22/* $Id: klfblockprocess.cpp 862 2013-11-23 11:10:54Z phfaist $ */
2323
24#include <ctype.h>24#include <ctype.h>
2525
@@ -70,7 +70,7 @@
7070
71bool KLFBlockProcess::startProcess(QStringList cmd, QByteArray stdindata, QStringList env)71bool KLFBlockProcess::startProcess(QStringList cmd, QByteArray stdindata, QStringList env)
72{72{
73 klfDbg("Running: "<<cmd<<", stdindata/size="<<stdindata.size());73 // klfDbg("Running: "<<cmd<<", stdindata/size="<<stdindata.size());
7474
75 _runstatus = 0;75 _runstatus = 0;
7676
@@ -87,7 +87,7 @@
87 fn = klfSearchPath(cmd[0]);87 fn = klfSearchPath(cmd[0]);
88 QFile fpeek(fn);88 QFile fpeek(fn);
89 if (!fpeek.open(QIODevice::ReadOnly)) {89 if (!fpeek.open(QIODevice::ReadOnly)) {
90 klfDbg("cmd[0]="<<cmd[0]<<", Can't peek into file "<<fn<<"!") ;90 //klfDbg("cmd[0]="<<cmd[0]<<", Can't peek into file "<<fn<<"!") ;
91 } else {91 } else {
92 QByteArray line;92 QByteArray line;
93 int n = 0, j;93 int n = 0, j;
@@ -114,8 +114,8 @@
114114
115 QString program = cmd[0];115 QString program = cmd[0];
116116
117 klfDbg("Running cmd="<<cmd);117 //klfDbg("Running cmd="<<cmd);
118 klfDbg("env="<<env<<", curenv="<<environment());118 //klfDbg("env="<<env<<", curenv="<<environment());
119119
120#ifdef KLFBACKEND_QT4120#ifdef KLFBACKEND_QT4
121 if (env.size() > 0) {121 if (env.size() > 0) {
@@ -124,17 +124,17 @@
124124
125 QStringList args = cmd;125 QStringList args = cmd;
126 args.erase(args.begin());126 args.erase(args.begin());
127 klfDbg("Starting "<<program<<", "<<args) ;127 //klfDbg("Starting "<<program<<", "<<args) ;
128 start(program, args);128 start(program, args);
129 if ( ! waitForStarted() ) {129 if ( ! waitForStarted() ) {
130 klfDbg("Can't wait for started! Error="<<error()) ;130 //klfDbg("Can't wait for started! Error="<<error()) ;
131 return false;131 return false;
132 }132 }
133133
134 write(stdindata.constData(), stdindata.size());134 write(stdindata.constData(), stdindata.size());
135 closeWriteChannel();135 closeWriteChannel();
136136
137 klfDbg("wrote input data (size="<<stdindata.size()<<")") ;137 //klfDbg("wrote input data (size="<<stdindata.size()<<")") ;
138138
139#else139#else
140 setArguments(cmd);140 setArguments(cmd);
@@ -168,7 +168,7 @@
168#endif168#endif
169169
170 if (_runstatus < 0) { // some error occurred somewhere170 if (_runstatus < 0) { // some error occurred somewhere
171 klfDbg("some error occurred, _runstatus="<<_runstatus) ;171 klfDbg("some error occurred, _runstatus="+QString("%1").arg(_runstatus)) ;
172 return false;172 return false;
173 }173 }
174174
175175
=== modified file 'src/klfbackend/klfdebug.h'
--- src/klfbackend/klfdebug.h 2012-01-02 20:23:27 +0000
+++ src/klfbackend/klfdebug.h 2014-03-24 20:24:05 +0000
@@ -19,7 +19,7 @@
19 * Free Software Foundation, Inc., *19 * Free Software Foundation, Inc., *
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21 ***************************************************************************/21 ***************************************************************************/
22/* $Id: klfdebug.h 748 2012-01-01 15:06:40Z phfaist $ */22/* $Id: klfdebug.h 862 2013-11-23 11:10:54Z phfaist $ */
2323
24#ifndef KLFDEBUG_H24#ifndef KLFDEBUG_H
25#define KLFDEBUG_H25#define KLFDEBUG_H
@@ -235,7 +235,7 @@
235#else235#else
236#define KLF_ASSERT_CONDITION(expr, msg, failaction) \236#define KLF_ASSERT_CONDITION(expr, msg, failaction) \
237 if ( !(expr) ) { \237 if ( !(expr) ) { \
238 qWarning("In function %s:\n\t%s", (QString("")+msg).local8Bit().data()); \238 qWarning("In function %s:\n\t%s", KLF_FUNC_NAME, (QString("")+msg).local8Bit().data()); \
239 failaction; \239 failaction; \
240 }240 }
241#endif241#endif
242242
=== modified file 'src/klfbackend/klfqt34common.h'
--- src/klfbackend/klfqt34common.h 2011-05-15 17:55:27 +0000
+++ src/klfbackend/klfqt34common.h 2014-03-24 20:24:05 +0000
@@ -19,7 +19,7 @@
19 * Free Software Foundation, Inc., *19 * Free Software Foundation, Inc., *
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21 ***************************************************************************/21 ***************************************************************************/
22/* $Id: klfqt34common.h 603 2011-02-26 23:14:55Z phfaist $ */22/* $Id: klfqt34common.h 862 2013-11-23 11:10:54Z phfaist $ */
2323
24#ifndef KLFQT34COMMON_H24#ifndef KLFQT34COMMON_H
25#define KLFQT34COMMON_H25#define KLFQT34COMMON_H
@@ -30,6 +30,7 @@
30#ifdef KLFBACKEND_QT430#ifdef KLFBACKEND_QT4
31#define dir_native_separators(x) QDir::toNativeSeparators(x)31#define dir_native_separators(x) QDir::toNativeSeparators(x)
32#define ba_assign(otherba) operator=(otherba)32#define ba_assign(otherba) operator=(otherba)
33#define buf_setdata(buf, ba_ref) buf.setData(ba_ref)
33#define dev_WRITEONLY QIODevice::WriteOnly34#define dev_WRITEONLY QIODevice::WriteOnly
34#define dev_READONLY QIODevice::ReadOnly35#define dev_READONLY QIODevice::ReadOnly
35#define dev_write write36#define dev_write write
@@ -54,6 +55,7 @@
54#define QLatin1String QString::fromLatin155#define QLatin1String QString::fromLatin1
55#define dir_native_separators(x) QDir::convertSeparators(x)56#define dir_native_separators(x) QDir::convertSeparators(x)
56#define ba_assign(otherba) duplicate((otherba).data(), (otherba).size())57#define ba_assign(otherba) duplicate((otherba).data(), (otherba).size())
58#define buf_setdata(buf, ba_ref) buf.setBuffer(ba_ref)
57#define dev_WRITEONLY IO_WriteOnly59#define dev_WRITEONLY IO_WriteOnly
58#define dev_READONLY IO_ReadOnly60#define dev_READONLY IO_ReadOnly
59#define dev_write writeBlock61#define dev_write writeBlock

Subscribers

People subscribed via source and target branches

to all changes: