From a3f76d92720a9ec817f73b571ae3a8a1c683d19e 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 To: subsurface@subsurface-divelog.org This does the basic export as a TeX file including a template. It still lacks proper location parsing and saving of the profile. Signed-off-by: Robert C. Helling --- desktop-widgets/divelogexportdialog.cpp | 87 +++++++++++++++++++++++++++++++++ desktop-widgets/divelogexportdialog.h | 1 + desktop-widgets/divelogexportdialog.ui | 12 ++++- subsurfacetemplate.tex | 62 +++++++++++++++++++++++ 4 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 subsurfacetemplate.tex diff --git a/desktop-widgets/divelogexportdialog.cpp b/desktop-widgets/divelogexportdialog.cpp index 5b58d0c..f39cdc9 100644 --- a/desktop-widgets/divelogexportdialog.cpp +++ b/desktop-widgets/divelogexportdialog.cpp @@ -86,6 +86,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 +164,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 +229,84 @@ 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; + +// This used to work, but does not anymore, since Mainwindow.instance()->graphics() is no longer a ProfileGraphicsView. +// Probably similiar gymnasitics as in Printer::render(int Pages = 0) is needed, but I tried to immitate that without success. +// Giving up for now. +// Tomaz?!? +// ProfileGraphicsView *profile = MainWindow.instance()->graphics(); +// profile->plot(dive,true); +// QString fileName = "profile.png"; +// QPixmap pixmap = QPixmap::grabWidget(profile); +// pixMap.save(fileName); + + + + 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\\plot{\\relax}"); + 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 e7cde31..5d5ad14 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 4713bf0..d01f817 100644 --- a/desktop-widgets/divelogexportdialog.ui +++ b/desktop-widgets/divelogexportdialog.ui @@ -192,6 +192,16 @@ + + + TeX + + + exportGroup + + + + I&mage depths @@ -600,7 +610,7 @@ - + diff --git a/subsurfacetemplate.tex b/subsurfacetemplate.tex new file mode 100644 index 0000000..198a815 --- /dev/null +++ b/subsurfacetemplate.tex @@ -0,0 +1,62 @@ +\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}$$} + + + + + + + + -- 2.8.4 (Apple Git-73)