Skip to content
Snippets Groups Projects
Commit e526522a authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

treat bg image/pdf the same

parent d7fba016
No related branches found
No related tags found
No related merge requests found
...@@ -125,6 +125,7 @@ std::vector<std::pair<std::string, std::string> > GetUsage() ...@@ -125,6 +125,7 @@ std::vector<std::pair<std::string, std::string> > GetUsage()
s.push_back(mp("-pid", "Print process id on stdout")); s.push_back(mp("-pid", "Print process id on stdout"));
s.push_back(mp("-listen", "Always listen to incoming connection requests")); s.push_back(mp("-listen", "Always listen to incoming connection requests"));
s.push_back(mp("-watch pattern", "Pattern of files to merge as they become available")); s.push_back(mp("-watch pattern", "Pattern of files to merge as they become available"));
s.push_back(mp("-bg file", "Load background (image or PDF) file"));
s.push_back(mp("-v int", "Set verbosity level")); s.push_back(mp("-v int", "Set verbosity level"));
s.push_back(mp("-nopopup", "Don't popup dialog windows in scripts")); s.push_back(mp("-nopopup", "Don't popup dialog windows in scripts"));
s.push_back(mp("-string \"string\"", "Parse command string at startup")); s.push_back(mp("-string \"string\"", "Parse command string at startup"));
...@@ -906,6 +907,13 @@ void GetOptions(int argc, char *argv[]) ...@@ -906,6 +907,13 @@ void GetOptions(int argc, char *argv[])
CTX::instance()->solver.listen = 1; CTX::instance()->solver.listen = 1;
i++; i++;
} }
else if(!strcmp(argv[i] + 1, "bg")){
i++;
if(argv[i])
CTX::instance()->bgImageFileName = argv[i++];
else
Msg::Fatal("Missing filename");
}
else if(!strcmp(argv[i] + 1, "version") || !strcmp(argv[i] + 1, "-version")) { else if(!strcmp(argv[i] + 1, "version") || !strcmp(argv[i] + 1, "-version")) {
fprintf(stderr, "%s\n", GMSH_VERSION); fprintf(stderr, "%s\n", GMSH_VERSION);
Msg::Exit(0); Msg::Exit(0);
......
...@@ -349,14 +349,6 @@ int MergeFile(const std::string &fileName, bool warnIfMissing, bool setWindowTit ...@@ -349,14 +349,6 @@ int MergeFile(const std::string &fileName, bool warnIfMissing, bool setWindowTit
else if(ext == ".diff" || ext == ".DIFF"){ else if(ext == ".diff" || ext == ".DIFF"){
status = GModel::current()->readDIFF(fileName); status = GModel::current()->readDIFF(fileName);
} }
else if(ext == ".pdf" || ext == ".PDF"){
#if defined(HAVE_POPPLER)
status = gmshPopplerWrapper::instance()->load_from_file(fileName);
#else
Msg::Error("Gmsh has to be compiled with POPPLER for displaying PDF documents");
status = 0;
#endif
}
else if(ext == ".med" || ext == ".MED" || ext == ".mmed" || ext == ".MMED" || else if(ext == ".med" || ext == ".MED" || ext == ".mmed" || ext == ".MMED" ||
ext == ".rmed" || ext == ".RMED"){ ext == ".rmed" || ext == ".RMED"){
status = GModel::readMED(fileName); status = GModel::readMED(fileName);
......
...@@ -20,14 +20,16 @@ int gmshPopplerWrapper::_h = -1; ...@@ -20,14 +20,16 @@ int gmshPopplerWrapper::_h = -1;
int gmshPopplerWrapper::_current_page = 0; int gmshPopplerWrapper::_current_page = 0;
#endif #endif
gmshPopplerWrapper *gmshPopplerWrapper::instance() { gmshPopplerWrapper *gmshPopplerWrapper::instance()
{
if(!_instance) _instance = new gmshPopplerWrapper; if(!_instance) _instance = new gmshPopplerWrapper;
return _instance; return _instance;
} }
int gmshPopplerWrapper::load_from_file (const std::string &file_name, int gmshPopplerWrapper::loadFromFile(const std::string &file_name,
const std::string &owner_password, const std::string &owner_password,
const std::string &user_password){ const std::string &user_password)
{
if (_current_doc) delete _current_doc; if (_current_doc) delete _current_doc;
_current_doc = poppler::document::load_from_file(file_name, owner_password, _current_doc = poppler::document::load_from_file(file_name, owner_password,
user_password); user_password);
...@@ -39,7 +41,8 @@ int gmshPopplerWrapper::load_from_file (const std::string &file_name, ...@@ -39,7 +41,8 @@ int gmshPopplerWrapper::load_from_file (const std::string &file_name,
#if defined(HAVE_OPENGL) #if defined(HAVE_OPENGL)
GLuint gmshPopplerWrapper::getTextureForPage(double xres, GLuint gmshPopplerWrapper::getTextureForPage(double xres,
double yres) { double yres)
{
int iPage = _current_page; int iPage = _current_page;
std::map<int,GLuint>::iterator it = _pages2textures.find(iPage); std::map<int,GLuint>::iterator it = _pages2textures.find(iPage);
if (it != _pages2textures.end())return it->second; if (it != _pages2textures.end())return it->second;
...@@ -63,6 +66,4 @@ GLuint gmshPopplerWrapper::getTextureForPage(double xres, ...@@ -63,6 +66,4 @@ GLuint gmshPopplerWrapper::getTextureForPage(double xres,
} }
#endif #endif
#endif #endif
...@@ -34,7 +34,8 @@ private: ...@@ -34,7 +34,8 @@ private:
public: public:
static gmshPopplerWrapper *instance(); static gmshPopplerWrapper *instance();
static int load_from_file (const std::string &file_name, static bool hasFile(){ return _current_doc ? true : false; }
static int loadFromFile(const std::string &file_name,
const std::string &owner_password=std::string(), const std::string &owner_password=std::string(),
const std::string &user_password=std::string()); const std::string &user_password=std::string());
static int width() { return _w; } static int width() { return _w; }
...@@ -42,8 +43,7 @@ public: ...@@ -42,8 +43,7 @@ public:
static void setCurrentPageUp () { _current_page++; } static void setCurrentPageUp () { _current_page++; }
static void setCurrentPageDown () { if(_current_page > 0) _current_page--; } static void setCurrentPageDown () { if(_current_page > 0) _current_page--; }
#if defined(HAVE_OPENGL) #if defined(HAVE_OPENGL)
static GLuint getTextureForPage(double xres, static GLuint getTextureForPage(double xres, double yres);
double yres) ;
#endif #endif
}; };
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "PView.h" #include "PView.h"
#include "PViewOptions.h" #include "PViewOptions.h"
#include "VertexArray.h" #include "VertexArray.h"
#include "StringUtils.h"
#include "gl2ps.h" #include "gl2ps.h"
#if defined(HAVE_FLTK) #if defined(HAVE_FLTK)
...@@ -29,7 +30,6 @@ ...@@ -29,7 +30,6 @@
#include "gmshPopplerWrapper.h" #include "gmshPopplerWrapper.h"
#endif #endif
drawContextGlobal *drawContext::_global = 0; drawContextGlobal *drawContext::_global = 0;
drawContext::drawContext(drawTransform *transform) drawContext::drawContext(drawTransform *transform)
...@@ -353,25 +353,35 @@ void drawContext::drawBackgroundGradient() ...@@ -353,25 +353,35 @@ void drawContext::drawBackgroundGradient()
} }
glEnd(); glEnd();
} }
}
void drawContext::drawBackgroundImage()
{
if(CTX::instance()->bgImageFileName.empty()) return;
std::string name = CTX::instance()->bgImageFileName;
std::string ext = SplitFileName(CTX::instance()->bgImageFileName)[2];
if(ext == ".pdf" || ext == ".PDF"){
#if defined(HAVE_POPPLER) #if defined(HAVE_POPPLER)
else if(CTX::instance()->bgGradient == 4){ // PDF @ background if(!gmshPopplerWrapper::instance()->hasFile()){
// FIXME: this should move to drawBackgroundImage below! if(!gmshPopplerWrapper::instance()->loadFromFile(name)){
Msg::Error("Could not load PDF file '%s'", name.c_str());
CTX::instance()->bgImageFileName.clear();
}
}
GLuint texture = gmshPopplerWrapper::getTextureForPage(800,600); GLuint texture = gmshPopplerWrapper::getTextureForPage(800,600);
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture); glBindTexture(GL_TEXTURE_2D, texture);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glColor4ubv((GLubyte *) & CTX::instance()->color.bg); glColor4ubv((GLubyte *) & CTX::instance()->color.bg);
int dw = viewport[2] - viewport[0]; int dw = viewport[2] - viewport[0];
int dh = viewport[3] - viewport[1]; int dh = viewport[3] - viewport[1];
int dw_im = gmshPopplerWrapper::width(); int dw_im = gmshPopplerWrapper::width();
int dh_im = gmshPopplerWrapper::height(); int dh_im = gmshPopplerWrapper::height();
// conserve aspect ratio : dw / dh = dw_im / dh_im // conserve aspect ratio : dw / dh = dw_im / dh_im
// dw = dh * dw_im / dh_im; // dw = dh * dw_im / dh_im;
dh = dw * dh_im / dw_im; dh = dw * dh_im / dw_im;
glTexCoord2f(1.0f, 1.0f); glVertex2i(viewport[2], viewport[3]-dh); glTexCoord2f(1.0f, 1.0f); glVertex2i(viewport[2], viewport[3]-dh);
glTexCoord2f(1.0f, 0.0f); glVertex2i(viewport[2], viewport[3]); glTexCoord2f(1.0f, 0.0f); glVertex2i(viewport[2], viewport[3]);
glTexCoord2f(0.0f, 0.0f); glVertex2i(viewport[2]-dw, viewport[3]); glTexCoord2f(0.0f, 0.0f); glVertex2i(viewport[2]-dw, viewport[3]);
...@@ -379,24 +389,14 @@ void drawContext::drawBackgroundGradient() ...@@ -379,24 +389,14 @@ void drawContext::drawBackgroundGradient()
glEnd(); glEnd();
} }
#endif #endif
else{
}
void drawContext::drawBackgroundImage()
{
#if defined(HAVE_FLTK) #if defined(HAVE_FLTK)
if(CTX::instance()->bgImageFileName.empty()) return;
if(_bgImage.empty()){ if(_bgImage.empty()){
int idot = CTX::instance()->bgImageFileName.find_last_of('.');
std::string ext;
if(idot > 0 && idot < (int)CTX::instance()->bgImageFileName.size())
ext = CTX::instance()->bgImageFileName.substr(idot + 1);
Fl_RGB_Image *img = 0; Fl_RGB_Image *img = 0;
if(ext == "jpg" || ext == "JPG" || ext == "jpeg" || ext == "JPEG") if(ext == ".jpg" || ext == ".JPG" || ext == ".jpeg" || ext == ".JPEG")
img = new Fl_JPEG_Image(CTX::instance()->bgImageFileName.c_str()); img = new Fl_JPEG_Image(name.c_str());
else if(ext == "png" || ext == "PNG") else if(ext == ".png" || ext == ".PNG")
img = new Fl_PNG_Image(CTX::instance()->bgImageFileName.c_str()); img = new Fl_PNG_Image(name.c_str());
if(img && img->d() >= 3){ if(img && img->d() >= 3){
const unsigned char *data = img->array; const unsigned char *data = img->array;
for(int j = img->h() - 1; j >= 0; j--) { for(int j = img->h() - 1; j >= 0; j--) {
...@@ -410,15 +410,12 @@ void drawContext::drawBackgroundImage() ...@@ -410,15 +410,12 @@ void drawContext::drawBackgroundImage()
_bgImageSize[0] = img->w(); _bgImageSize[0] = img->w();
_bgImageSize[1] = img->h(); _bgImageSize[1] = img->h();
} }
if(img) delete img;
if(!_bgImageSize[0] || !_bgImageSize[1]){ if(!_bgImageSize[0] || !_bgImageSize[1]){
Msg::Error("Could not load valid background image"); Msg::Error("Could not load background image '%s'", name.c_str());
// make sure we don't try to load it again CTX::instance()->bgImageFileName.clear();
for(int i = 0; i < 3; i++) _bgImage.push_back(0);
_bgImageSize[0] = _bgImageSize[1] = 1;
} }
if(img) delete img;
} }
double x = CTX::instance()->bgImagePosition[0]; double x = CTX::instance()->bgImagePosition[0];
double y = CTX::instance()->bgImagePosition[1]; double y = CTX::instance()->bgImagePosition[1];
int c = fix2dCoordinates(&x, &y); int c = fix2dCoordinates(&x, &y);
...@@ -433,6 +430,7 @@ void drawContext::drawBackgroundImage() ...@@ -433,6 +430,7 @@ void drawContext::drawBackgroundImage()
(void*)&_bgImage[0]); (void*)&_bgImage[0]);
gl2psDrawPixels(_bgImageSize[0], _bgImageSize[1], 0, 0, GL_RGB, GL_FLOAT, gl2psDrawPixels(_bgImageSize[0], _bgImageSize[1], 0, 0, GL_RGB, GL_FLOAT,
(void*)&_bgImage[0]); (void*)&_bgImage[0]);
}
#endif #endif
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment