2 /* This file is part of
3 * =================================================
5 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich.
7 * Copyright 1995-2000 The LyX Team.
9 * ================================================= */
12 #pragma implementation
16 #include "ImageLoaderXPM.h"
17 #include "frontends/support/LyXImage.h"
18 #include "support/filetools.h"
20 #include FORMS_H_LOCATION
21 #include XPM_H_LOCATION
25 #include "support/LAssert.h"
31 bool ImageLoaderXPM::isImageFormatOK(string const & filename) const
33 std::ifstream is(filename.c_str(), ios::in);
35 // The signature of the file without the spaces.
36 static char const str[] = "/*XPM*/";
37 char const * ptr = str;
39 for (; *ptr != '\0'; ++ptr) {
50 ImageLoaderXPM::FormatList const
51 ImageLoaderXPM::loadableFormats() const
54 formats.push_back("xpm");
60 ImageLoaderXPM::runImageLoader(string const & filename)
62 Display * display = fl_get_display();
65 #warning This might be a dirty thing, but I dont know any other solution.
66 Screen * screen = ScreenOfDisplay(display, fl_screen);
73 int status = XpmReadFileToPixmap(
75 XRootWindowOfScreen(screen),
76 const_cast<char *>(filename.c_str()),
77 &pixmap, &mask, &attrib);
79 if (status != XpmSuccess) {
80 lyxerr << "Error reading XPM file '"
81 << XpmGetErrorString(status)
83 return ErrorWhileLoading;
86 // This should have been set by the XpmReadFileToPixmap call!
87 Assert(attrib.valuemask & XpmSize);
89 setImage(new LyXImage(pixmap, attrib.width, attrib.height));
91 XpmFreeAttributes(&attrib);