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 * This file Copyright 2000 Baruch Even
10 * ================================================= */
13 #pragma implementation
17 #include "XPM_Renderer.h"
19 #include FORMS_H_LOCATION
20 #include XPM_H_LOCATION
24 #include "support/LAssert.h"
27 XPM_Renderer::XPM_Renderer()
31 XPM_Renderer::~XPM_Renderer()
34 bool XPM_Renderer::renderImage()
41 Display * display = fl_get_display();
44 #warning This might be a dirty thing, but I dont know any other solution.
45 Screen * screen = DefaultScreenOfDisplay(display);
47 int status = XpmReadFileToPixmap(
49 XRootWindowOfScreen(screen),
50 const_cast<char *>(getFilename().c_str()),
51 &pixmap, &mask, &attrib);
53 if (status != XpmSuccess) {
54 lyxerr << "Error reading XPM file '"
55 << XpmGetErrorString(status)
60 // This should have been set by the XpmReadFileToPixmap call!
61 Assert(attrib.valuemask & XpmSize);
63 setPixmap(pixmap, attrib.width, attrib.height);
65 XpmFreeAttributes(&attrib);
70 bool XPM_Renderer::isImageFormatOK(string const & filename) const
72 std::ifstream is(filename.c_str(), ios::in | ios::nocreate);
74 // The signature of the file without the spaces.
75 static const char str[] = "/*XPM*/";
76 const char * ptr = str;
86 } while (*ptr != '\0');