+ PDF export (skia)
This commit is contained in:
parent
1ff1ed9b3e
commit
58833e23d4
5 changed files with 88 additions and 0 deletions
|
@ -263,6 +263,32 @@ void MainWindow::export_as()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::export_as_skia_pdf()
|
||||||
|
{
|
||||||
|
std::cerr << "Skia PDF" << std::endl;
|
||||||
|
|
||||||
|
QAction *action = qobject_cast<QAction *>(sender());
|
||||||
|
QByteArray fileFormat("pdf");
|
||||||
|
QString initialPath = QDir::currentPath() + "/map-skia." + fileFormat;
|
||||||
|
|
||||||
|
QString fileName = QFileDialog::getSaveFileName(this, tr("Export As Skia PDF"),
|
||||||
|
initialPath,
|
||||||
|
tr("%1 Files (*.%2);;All Files (*)")
|
||||||
|
.arg(QString(fileFormat.toUpper()))
|
||||||
|
.arg(QString(fileFormat)));
|
||||||
|
if (!fileName.isEmpty())
|
||||||
|
{
|
||||||
|
std::cerr << "Skia PDF" << std::endl;
|
||||||
|
mapWidget_->export_skia_pdf(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::export_as_cairo_pdf()
|
||||||
|
{
|
||||||
|
std::cerr << "Cairo PDF" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::print()
|
void MainWindow::print()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -335,6 +361,11 @@ void MainWindow::createActions()
|
||||||
exportAsActs.append(action);
|
exportAsActs.append(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exportSkiaPdf = new QAction("Skia",this);
|
||||||
|
connect(exportSkiaPdf, SIGNAL(triggered()), this, SLOT(export_as_skia_pdf()));
|
||||||
|
exportCairoPdf = new QAction("Cairo",this);
|
||||||
|
connect(exportCairoPdf, SIGNAL(triggered()), this, SLOT(export_as_cairo_pdf()));
|
||||||
|
|
||||||
printAct = new QAction(QIcon(":/images/print.png"),tr("&Print ..."),this);
|
printAct = new QAction(QIcon(":/images/print.png"),tr("&Print ..."),this);
|
||||||
printAct->setShortcut(tr("Ctrl+E"));
|
printAct->setShortcut(tr("Ctrl+E"));
|
||||||
connect(printAct, SIGNAL(triggered()), this, SLOT(print()));
|
connect(printAct, SIGNAL(triggered()), this, SLOT(print()));
|
||||||
|
@ -353,10 +384,15 @@ void MainWindow::createMenus()
|
||||||
foreach (QAction *action, exportAsActs)
|
foreach (QAction *action, exportAsActs)
|
||||||
exportMenu->addAction(action);
|
exportMenu->addAction(action);
|
||||||
|
|
||||||
|
exportPdfMenu = new QMenu(tr("&Export As PDF"), this);
|
||||||
|
exportPdfMenu->addAction(exportSkiaPdf);
|
||||||
|
exportPdfMenu->addAction(exportCairoPdf);
|
||||||
|
|
||||||
fileMenu = new QMenu(tr("&File"),this);
|
fileMenu = new QMenu(tr("&File"),this);
|
||||||
fileMenu->addAction(openAct);
|
fileMenu->addAction(openAct);
|
||||||
fileMenu->addAction(saveAct);
|
fileMenu->addAction(saveAct);
|
||||||
fileMenu->addMenu(exportMenu);
|
fileMenu->addMenu(exportMenu);
|
||||||
|
fileMenu->addMenu(exportPdfMenu);
|
||||||
fileMenu->addAction(printAct);
|
fileMenu->addAction(printAct);
|
||||||
fileMenu->addSeparator();
|
fileMenu->addSeparator();
|
||||||
fileMenu->addAction(exitAct);
|
fileMenu->addAction(exitAct);
|
||||||
|
|
|
@ -54,6 +54,8 @@ public slots:
|
||||||
void pan();
|
void pan();
|
||||||
void info();
|
void info();
|
||||||
void export_as();
|
void export_as();
|
||||||
|
void export_as_skia_pdf();
|
||||||
|
void export_as_cairo_pdf();
|
||||||
void open(QString const& path = QString());
|
void open(QString const& path = QString());
|
||||||
void reload();
|
void reload();
|
||||||
void save();
|
void save();
|
||||||
|
@ -96,11 +98,14 @@ private:
|
||||||
QAction *panDownAct;
|
QAction *panDownAct;
|
||||||
QAction *reloadAct;
|
QAction *reloadAct;
|
||||||
QAction *layerInfo;
|
QAction *layerInfo;
|
||||||
|
QAction *exportSkiaPdf;
|
||||||
|
QAction *exportCairoPdf;
|
||||||
//toolbars
|
//toolbars
|
||||||
QToolBar *fileToolBar;
|
QToolBar *fileToolBar;
|
||||||
QToolBar *editToolBar;
|
QToolBar *editToolBar;
|
||||||
//menus
|
//menus
|
||||||
QMenu *exportMenu;
|
QMenu *exportMenu;
|
||||||
|
QMenu *exportPdfMenu;
|
||||||
QMenu *fileMenu;
|
QMenu *fileMenu;
|
||||||
QMenu *helpMenu;
|
QMenu *helpMenu;
|
||||||
//status bar
|
//status bar
|
||||||
|
|
|
@ -45,6 +45,9 @@
|
||||||
#include <mapnik/skia/skia_renderer.hpp>
|
#include <mapnik/skia/skia_renderer.hpp>
|
||||||
#include <SkCanvas.h>
|
#include <SkCanvas.h>
|
||||||
#include <SkBitmap.h>
|
#include <SkBitmap.h>
|
||||||
|
#include <SkStream.h>
|
||||||
|
#include <SkPDFDevice.h>
|
||||||
|
#include <SkPDFDocument.h>
|
||||||
#include <SkGpuDevice.h>
|
#include <SkGpuDevice.h>
|
||||||
#include <gl/GrGLInterface.h>
|
#include <gl/GrGLInterface.h>
|
||||||
#if SK_SUPPORT_GPU
|
#if SK_SUPPORT_GPU
|
||||||
|
@ -625,6 +628,44 @@ void render_skia_gpu(GrGLInterface const * cur_interface, mapnik::Map const& map
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MapWidget::export_skia_pdf(QString const& filename)
|
||||||
|
{
|
||||||
|
unsigned width = map_->width();
|
||||||
|
unsigned height = map_->height();
|
||||||
|
SkISize pageSize = SkISize::Make(width,height);
|
||||||
|
|
||||||
|
|
||||||
|
SkPDFDevice dev(pageSize, pageSize, SkMatrix::I());
|
||||||
|
SkCanvas canvas(&dev);
|
||||||
|
mapnik::skia_renderer ren(*map_,canvas,scaling_factor_);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ren.apply();
|
||||||
|
}
|
||||||
|
catch (mapnik::config_error & ex)
|
||||||
|
{
|
||||||
|
std::cerr << "Skia:" << ex.what() << std::endl;
|
||||||
|
}
|
||||||
|
catch (const std::exception & ex)
|
||||||
|
{
|
||||||
|
std::cerr << "Skia:exception: " << ex.what() << std::endl;
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
std::cerr << "Skia:Unknown exception caught!\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
SkPDFDocument doc;
|
||||||
|
doc.appendPage(&dev);
|
||||||
|
std::cerr << filename.toStdString() << std::endl;
|
||||||
|
SkFILEWStream stream(filename.toStdString().c_str());
|
||||||
|
if (stream.isValid())
|
||||||
|
{
|
||||||
|
doc.emitPDF(&stream);
|
||||||
|
}
|
||||||
|
std::cerr << "Done" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
void render_grid(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
|
void render_grid(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
|
||||||
{
|
{
|
||||||
std::cerr << "Not supported" << std::endl;
|
std::cerr << "Not supported" << std::endl;
|
||||||
|
|
|
@ -90,6 +90,7 @@ public:
|
||||||
void panUp();
|
void panUp();
|
||||||
void panDown();
|
void panDown();
|
||||||
void set_scaling_factor(double);
|
void set_scaling_factor(double);
|
||||||
|
void export_skia_pdf(QString const& filename);
|
||||||
public slots:
|
public slots:
|
||||||
void zoomToLevel(int level);
|
void zoomToLevel(int level);
|
||||||
void updateMap();
|
void updateMap();
|
||||||
|
@ -110,6 +111,7 @@ protected:
|
||||||
unsigned height,
|
unsigned height,
|
||||||
std::string const& filename,
|
std::string const& filename,
|
||||||
std::string const& type);
|
std::string const& type);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAP_WIDGET_HPP
|
#endif // MAP_WIDGET_HPP
|
||||||
|
|
|
@ -9,10 +9,14 @@ QMAKE_CXX = $$system(mapnik-config --cxx)
|
||||||
QMAKE_LINK = $$system(mapnik-config --cxx)
|
QMAKE_LINK = $$system(mapnik-config --cxx)
|
||||||
QMAKE_CXXFLAGS += $$system(mapnik-config --cxxflags --defines)
|
QMAKE_CXXFLAGS += $$system(mapnik-config --cxxflags --defines)
|
||||||
QMAKE_CXXFLAGS += $$system(mapnik-config --includes --dep-includes)
|
QMAKE_CXXFLAGS += $$system(mapnik-config --includes --dep-includes)
|
||||||
|
QMAKE_CXXFLAGS += "-I/Users/artem/Projects/skia/trunk/include/gpu"
|
||||||
|
QMAKE_CXXFLAGS += "-I/Users/artem/Projects/skia/trunk/include/pdf"
|
||||||
|
|
||||||
QMAKE_LFLAGS += $$system(mapnik-config --libs)
|
QMAKE_LFLAGS += $$system(mapnik-config --libs)
|
||||||
QMAKE_LFLAGS += $$system(mapnik-config --ldflags --dep-libs)
|
QMAKE_LFLAGS += $$system(mapnik-config --ldflags --dep-libs)
|
||||||
QMAKE_LFLAGS += -lboost_timer
|
QMAKE_LFLAGS += -lboost_timer
|
||||||
|
QMAKE_LFLAGS += -lskia_pdf
|
||||||
|
QMAKE_LFLAGS += -lzlib
|
||||||
QMAKE_LFLAGS += "-framework Cocoa"
|
QMAKE_LFLAGS += "-framework Cocoa"
|
||||||
|
|
||||||
# Input
|
# Input
|
||||||
|
|
Loading…
Add table
Reference in a new issue