1 /* This file is part of
2 * =================================================
4 * LyX, The Document Processor
5 * Copyright 1995 Matthias Ettrich.
6 * Copyright 1995-2001 The LyX Team.
8 * ================================================= */
11 #pragma implementation
15 #include "ImageLoaderXPM.h"
16 #include "frontends/support/LyXImage.h"
17 #include "frontends/GUIRunTime.h"
18 #include "support/filetools.h"
20 #include XPM_H_LOCATION
24 #include "support/LAssert.h"
30 bool ImageLoaderXPM::isImageFormatOK(string const & filename) const
32 std::ifstream is(filename.c_str(), ios::in);
34 // The signature of the file without the spaces.
35 static char const str[] = "/*XPM*/";
36 char const * ptr = str;
38 for (; *ptr != '\0'; ++ptr) {
49 ImageLoaderXPM::FormatList const
50 ImageLoaderXPM::loadableFormats() const
53 formats.push_back("xpm");
59 ImageLoaderXPM::runImageLoader(string const & filename)
61 Display * display = GUIRunTime::x11Display();
64 // This might be a dirty thing, but I dont know any other solution.
65 Screen * screen = ScreenOfDisplay(display, GUIRunTime::x11Screen());
71 attrib.valuemask = XpmCloseness;
72 attrib.closeness = 10000;
74 int status = XpmReadFileToPixmap(
76 XRootWindowOfScreen(screen),
77 const_cast<char *>(filename.c_str()),
78 &pixmap, &mask, &attrib);
80 if (status != XpmSuccess) {
81 lyxerr << "Error reading XPM file '"
82 << XpmGetErrorString(status) << "'"
84 return ErrorWhileLoading;
87 // This should have been set by the XpmReadFileToPixmap call!
88 lyx::Assert(attrib.valuemask & XpmSize);
90 setImage(new LyXImage(pixmap, attrib.width, attrib.height));
92 XpmFreeAttributes(&attrib);