From 9b8a04089db640b835787ab1bb871298d47e89bf Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Mon, 3 Oct 2016 17:08:02 +0200 Subject: [PATCH] Export to TeX file initialized This does the basic export as a TeX file including a template. It still lacks proper location parsing. Signed-off-by: Robert C. Helling Signed-off-by: Dirk Hohndel --- desktop-widgets/divelogexportdialog.cpp | 86 +++++++++++++++++++++++++ desktop-widgets/divelogexportdialog.h | 1 + desktop-widgets/divelogexportdialog.ui | 12 +++- subsurfacetemplate.tex | 54 ++++++++++++++++ 4 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 subsurfacetemplate.tex diff --git a/desktop-widgets/divelogexportdialog.cpp b/desktop-widgets/divelogexportdialog.cpp index 5b58d0c1d..9d3d27129 100644 --- a/desktop-widgets/divelogexportdialog.cpp +++ b/desktop-widgets/divelogexportdialog.cpp @@ -11,6 +11,8 @@ #include "core/worldmap-save.h" #include "core/save-html.h" #include "desktop-widgets/mainwindow.h" +#include "profile-widget/profilewidget2.h" + #define GET_UNIT(name, field, f, t) \ v = settings.value(QString(name)); \ @@ -86,6 +88,8 @@ void DiveLogExportDialog::showExplanation() ui->description->setText(tr("Subsurface native XML format.")); } else if (ui->exportImageDepths->isChecked()) { ui->description->setText(tr("Write depths of images to file.")); + } else if (ui->exportTeX->isChecked()) { + ui->description->setText(tr("Write dive as TeX macros to file.")); } } @@ -162,6 +166,10 @@ void DiveLogExportDialog::on_buttonBox_accepted() filename = QFileDialog::getSaveFileName(this, tr("Save image depths"), lastDir); if (!filename.isNull() && !filename.isEmpty()) export_depths(filename.toUtf8().data(), ui->exportSelected->isChecked()); + } else if (ui->exportTeX->isChecked()) { + filename = QFileDialog::getSaveFileName(this, tr("Export to TeX file"), lastDir, tr("TeX files (*.tex)")); + if (!filename.isNull() && !filename.isEmpty()) + export_TeX(filename.toUtf8().data(), ui->exportSelected->isChecked()); } break; case 1: @@ -223,3 +231,81 @@ void DiveLogExportDialog::export_depths(const char *filename, const bool selecte } free_buffer(&buf); } + +void DiveLogExportDialog::export_TeX(const char *filename, const bool selected_only) +{ + FILE *f; + struct dive *dive; + depth_t depth; + int i; + const char *unit = NULL; + bool need_pagebreak = false; + + struct membuffer buf = {}; + + put_format(&buf, "\\input subsurfacetemplate\n"); + put_format(&buf, "%% This is a plain TeX file. Compile with pdftex, not pdflatex!\n"); + put_format(&buf, "%% You will also need a subsurfacetemplate.tex in the current directory.\n"); + put_format(&buf, "%% You can downlaod an example from http://www.atdotde.de/~robert/subsurfacetemplate\n%%\n"); + for_each_dive (i, dive) { + if (selected_only && !dive->selected) + continue; + + QString filename = "profile%1.png"; + ProfileWidget2 *profile = MainWindow::instance()->graphics(); + profile->plotDive(dive, true); + profile->setToolTipVisibile(false); + QPixmap pix = QPixmap::grabWidget(profile); + profile->setToolTipVisibile(true); + pix.save(filename.arg(dive->number)); + + + + struct tm tm; + utc_mkdate(dive->when, &tm); + + dive_site *site = get_dive_site_by_uuid(dive->dive_site_uuid);; + + pressure_t delta_p = {.mbar = 0}; + + QString star = "*"; + QString viz = star.repeated(dive->visibility); + int i; + + for (i = 0; i < MAX_CYLINDERS; i++) + if (is_cylinder_used(dive, i)) + delta_p.mbar += dive->cylinder[i].start.mbar - dive->cylinder[i].end.mbar; + + if (need_pagebreak) + put_format(&buf, "\\vfill\\eject\n"); + need_pagebreak = true; + put_format(&buf, "\\def\\date{%04u-%02u-%02u}\n", + tm.tm_year, tm.tm_mon+1, tm.tm_mday); + put_format(&buf, "\\def\\number{%d}\n", dive->number); + put_format(&buf, "\\def\\place{%s}\n", site->name); + put_format(&buf, "\\def\\spot{}\n"); + put_format(&buf, "\\def\\country{}\n"); + put_format(&buf, "\\def\\entrance{}\n"); + put_format(&buf, "\\def\\time{%u:%02u}\n", FRACTION(dive->duration.seconds, 60)); + put_format(&buf, "\\def\\depth{%u.%01um}\n", FRACTION(dive->maxdepth.mm / 100, 10)); + put_format(&buf, "\\def\\gasuse{%u.%01ubar}\n", FRACTION(delta_p.mbar / 100, 10)); + put_format(&buf, "\\def\\sac{%u.%01u l/min}\n", FRACTION(dive->sac/100,10)); + put_format(&buf, "\\def\\type{%s}\n", dive->tag_list ? dive->tag_list->tag->name : ""); + put_format(&buf, "\\def\\viz{%s}\n", viz.toUtf8().data()); + put_format(&buf, "\\def\\plot{\\includegraphics[width=9cm,height=4cm]{profile%d}}\n", dive->number); + put_format(&buf, "\\def\\comment{%s}\n", dive->notes); + put_format(&buf, "\\def\\buddy{%s}\n", dive->buddy); + put_format(&buf, "\\page\n"); + } + + put_format(&buf, "\\bye\n"); + + f = subsurface_fopen(filename, "w+"); + if (!f) { + report_error(tr("Can't open file %s").toUtf8().data(), filename); + } else { + flush_buffer(&buf, f); /*check for writing errors? */ + fclose(f); + } + free_buffer(&buf); +} diff --git a/desktop-widgets/divelogexportdialog.h b/desktop-widgets/divelogexportdialog.h index e7cde318d..5d5ad146f 100644 --- a/desktop-widgets/divelogexportdialog.h +++ b/desktop-widgets/divelogexportdialog.h @@ -33,6 +33,7 @@ private: void showExplanation(); void exportHtmlInit(const QString &filename); void export_depths(const char *filename, const bool selected_only); + void export_TeX(const char *filename, const bool selected_only); }; #endif // DIVELOGEXPORTDIALOG_H diff --git a/desktop-widgets/divelogexportdialog.ui b/desktop-widgets/divelogexportdialog.ui index 4713bf0ba..d01f817c6 100644 --- a/desktop-widgets/divelogexportdialog.ui +++ b/desktop-widgets/divelogexportdialog.ui @@ -191,6 +191,16 @@ + + + + TeX + + + exportGroup + + + @@ -600,7 +610,7 @@ - + diff --git a/subsurfacetemplate.tex b/subsurfacetemplate.tex new file mode 100644 index 000000000..9662d9068 --- /dev/null +++ b/subsurfacetemplate.tex @@ -0,0 +1,54 @@ +\input graphicx +\nopagenumbers +\font\breit=cmr10 scaled \magstep3 +\font\klein=cmr9 +\font\winzig=cmr5 +\def\slinie{\hrulefill\hskip 3em} +\overfullrule=0pt +\def\p{\hskip 0.5cm} % typical horizontal room +\parindent=1cm +%\offinterlineskip +\long\def\page{ +$$\vbox{\hrule % upper cutting line +\vskip 2.0cm % upper whitespace +\vrule % left cutting line +$\vbox to 15cm{ % height of box +\vss\hbox to 3mm{\hrulefill}\vss}$ % middle line +\hskip 4.0cm % left white space +\vrule\vbox to 15cm{ % again height of box +\hrule depth 2pt % upper box boundary +\hbox to 10cm{ % width of box +\strut\p\date\slinie\vrule$\vcenter to 1.5cm{\vfil\hbox to +1.5cm{\hss\breit\strut\number\hss}\vfil\hrule}\vrule$} +% +\hbox{\p{\breit\strut\place} \country\hrulefill} +\medskip +\hbox{\p{\breit\strut\spot}\hrulefill} +\medskip +\hbox{\p\strut Entrance:\entrance\slinie} +\bigskip +\hbox to 10cm{\hss\breit\strut \time \p@\p\hbox to 1.5cm{\hss\depth}\hss} +\bigskip +\hbox to 10cm{\klein\p $\Delta p$:\hbox to 1cm{\hrulefill\gasuse}\hss +SAC:\hbox to 1.5cm{\hrulefill\sac}\hss +Type:\hbox to 1.2cm{\hrulefill\type}\hss Viz.: +\hbox to 0.8cm{\hrulefill\viz}\p} +\bigskip +\hbox{\p\hsize = 9cm +\vbox{\noindent +\comment +}\p\hss} +\leaders\vbox to 0.55cm{\vss\hbox to 10cm{\p\hrulefill\p}}\vfill +\hbox to 10cm{\hss\plot\hss} +\vskip 0.5cm +\hbox to 10cm{\p{\breit Buddy:} \buddy\hrulefill\p} + +\vskip 1ex % room above end of box +\hrule depth 2pt % lower boundary +}\vrule % right boundary +\hskip 1.0cm\vrule % right white space +\par +\hbox{\hskip 6cm +\winzig Subsurface dive log http://subsurface-divelog.org} +\vskip 2.0cm % lower white space +\hrule}$$}