8 #if defined(HAVE_POPPLER)
12 #include <poppler/cpp/poppler-image.h>
13 #include <poppler/cpp/poppler-page-renderer.h>
14 #if defined(HAVE_FLTK)
15 #include <FL/Fl_JPEG_Image.H>
18 gmshPopplerWrapper *gmshPopplerWrapper::_instance = 0;
19 std::map<int, std::pair<GModel *, std::string> > gmshPopplerWrapper::_macros;
20 poppler::document *gmshPopplerWrapper::_currentDoc = 0;
21 #if defined(HAVE_OPENGL)
22 std::map<int, GLuint> gmshPopplerWrapper::_pages2textures;
23 int gmshPopplerWrapper::_w = -1;
24 int gmshPopplerWrapper::_h = -1;
25 int gmshPopplerWrapper::_currentPage = 0;
28 gmshPopplerWrapper *gmshPopplerWrapper::instance()
30 if(!_instance) _instance =
new gmshPopplerWrapper;
34 int gmshPopplerWrapper::loadFromFile(
const std::string &fileName,
35 const std::string &ownerPassword,
36 const std::string &userPassword)
38 if(_currentDoc)
delete _currentDoc;
40 Msg::Info(
"Loading PDF file `%s'...", fileName.c_str());
42 poppler::document::load_from_file(fileName, ownerPassword, userPassword);
43 if(!_currentDoc)
return 0;
45 Msg::Info(
"Loaded PDF file `%s'", fileName.c_str());
50 int gmshPopplerWrapper::getNumPages()
52 if(!_currentDoc)
return 0;
53 return _currentDoc->pages();
56 #if defined(HAVE_OPENGL)
57 GLuint gmshPopplerWrapper::getTextureForPage(
double xres,
double yres)
59 int iPage = _currentPage;
60 int numPages = getNumPages();
61 if(iPage < 0) iPage = 0;
62 if(iPage > numPages - 1) iPage = numPages - 1;
63 auto it = _pages2textures.find(iPage);
64 if(it != _pages2textures.end())
return it->second;
65 if(!_currentDoc)
return 0;
67 poppler::page *page = _currentDoc->create_page(iPage);
68 poppler::page_renderer pr;
69 pr.set_render_hint(poppler::page_renderer::text_antialiasing,
true);
70 pr.set_render_hint(poppler::page_renderer::antialiasing,
true);
71 poppler::image im = pr.render_page(page, xres, yres, -1, -1, -1);
72 im.save(
"hop.jpeg",
"jpeg");
73 Fl_RGB_Image *img =
new Fl_JPEG_Image(
"hop.jpeg");
75 glPixelStorei(GL_UNPACK_ROW_LENGTH, img->w());
77 glGenTextures(1, &texture);
78 glBindTexture(GL_TEXTURE_2D, texture);
79 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
80 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
81 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img->w(), img->h(), 0,
82 (img->d() == 4) ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE,
84 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
91 _pages2textures[iPage] = texture;