From 265b37457926befea52ffc34a35b9aea510f4887 Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Fri, 10 Jan 2003 11:06:02 +0000 Subject: Initial version. --- src/XPM.cxx | 297 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/XPM.h | 67 ++++++++++++++ 2 files changed, 364 insertions(+) create mode 100644 src/XPM.cxx create mode 100644 src/XPM.h (limited to 'src') diff --git a/src/XPM.cxx b/src/XPM.cxx new file mode 100644 index 000000000..5758b7810 --- /dev/null +++ b/src/XPM.cxx @@ -0,0 +1,297 @@ +// Scintilla source code edit control +/** @file XPM.cxx + ** Define a class that holds data in the X Pixmap (XPM) format, + **/ +// Copyright 1998-2003 by Neil Hodgson +// The License.txt file describes the conditions under which this software may be distributed. + +#include +#include + +#include "Platform.h" + +#include "XPM.h" + +static const char *NextField(const char *s) { + while (*s && *s != ' ') { + s++; + } + while (*s && *s == ' ') { + s++; + } + return s; +} + +// Data lines in XPM can be terminated either with NUL or " +static size_t MeasureLength(const char *s) { + size_t i = 0; + while (s[i] && (s[i] != '\"')) + i++; + return i; +} + +ColourAllocated XPM::ColourFromCode(int ch) { + return colourCodeTable[ch]->allocated; +#ifdef SLOW + for (int i=0;iFillRectangle(rc, ColourFromCode(code)); + } +} + +XPM::XPM(const char *textForm) : + data(0), codes(0), colours(0), lines(0) { + Init(textForm); +} + +XPM::XPM(const char * const *linesForm) : + data(0), codes(0), colours(0), lines(0) { + Init(linesForm); +} + +XPM::~XPM() { + Clear(); +} + +void XPM::Init(const char *textForm) { + Clear(); + // Test done is two parts to avoid possibility of overstepping the memory + // if memcmp implemented strangely. Must be 4 bytes at least at destination. + if ((0 == memcmp(textForm, "/* X", 4)) && (0 == memcmp(textForm, "/* XPM */", 9))) { + // Build the lines form out of the text form + const char **linesForm = LinesFormFromTextForm(textForm); + Init(linesForm); + delete []linesForm; + } else { + // It is really in line form + Init(reinterpret_cast(textForm)); + } +} + +void XPM::Init(const char * const *linesForm) { + Clear(); + height = 1; + width = 1; + nColours = 1; + data = NULL; + codeTransparent = ' '; + codes = NULL; + colours = NULL; + lines = NULL; + if (!linesForm) + return; + + const char *line0 = linesForm[0]; + width = atoi(line0); + line0 = NextField(line0); + height = atoi(line0); + line0 = NextField(line0); + nColours = atoi(line0); + codes = new char[nColours]; + colours = new ColourPair[nColours]; + + int strings = 1+height+nColours; + lines = new char *[strings]; + int allocation = 0; + for (int i=0; i(codes[c])] = &(colours[c]); + } +} + +void XPM::Clear() { + delete []data; + data = 0; + delete []codes; + codes = 0; + delete []colours; + colours = 0; + delete []lines; + lines = 0; +} + +void XPM::RefreshColourPalette(Palette &pal, bool want) { + if (!data || !codes || !colours || !lines) { + return; + } + for (int i=0;iGetId() == id) { + set[i]->Init(textForm); + return; + } + } + + // No present, so add to end + XPM *pxpm = new XPM(textForm); + if (pxpm) { + pxpm->SetId(id); + pxpm->CopyDesiredColours(); + if (len == maximum) { + int lenNew = len + 100; + XPM **setNew = new XPM *[lenNew]; + for (int i=0; iGetId() == id) { + return set[i]; + } + } + return 0; +} + +int XPMSet::GetHeight() { + if (height < 0) { + for (int i=0; iGetHeight()) { + height = set[i]->GetHeight(); + } + } + } + return (height > 0) ? height : 0; +} + +int XPMSet::GetWidth() { + if (width < 0) { + for (int i=0; iGetWidth()) { + width = set[i]->GetWidth(); + } + } + } + return (width > 0) ? width : 0; +} diff --git a/src/XPM.h b/src/XPM.h new file mode 100644 index 000000000..948e557a9 --- /dev/null +++ b/src/XPM.h @@ -0,0 +1,67 @@ +// Scintilla source code edit control +/** @file XPM.h + ** Define a class that holds data in the X Pixmap (XPM) format, + **/ +// Copyright 1998-2003 by Neil Hodgson +// The License.txt file describes the conditions under which this software may be distributed. + +#ifndef XPM_H +#define XPM_H + +/** + * Hold a pixmap in XPM format. + */ +class XPM { + int id; // Assigned by container + int height; + int width; + int nColours; + char *data; + char codeTransparent; + char *codes; + ColourPair *colours; + ColourAllocated ColourFromCode(int ch); + void FillRun(Surface *surface, int code, int startX, int y, int x); + char **lines; + ColourPair *colourCodeTable[256]; +public: + XPM(const char *textForm); + XPM(const char * const *linesForm); + ~XPM(); + void Init(const char *textForm); + void Init(const char * const *linesForm); + void Clear(); + // Similar to same named method in ViewStyle: + void RefreshColourPalette(Palette &pal, bool want); + // No palette used, so just copy the desired colours to the allocated colours: + void CopyDesiredColours(); + // Decompose image into runs and use FillRectangle for each run: + void Draw(Surface *surface, PRectangle &rc); + char **InLinesForm() { return lines; } + void SetId(int id_) { id = id_; } + int GetId() { return id; } + int GetHeight() { return height; } + int GetWidth() { return width; } + static const char **LinesFormFromTextForm(const char *textForm); +}; + +/** + * A collection of pixmaps indexed by integer id. + */ +class XPMSet { + XPM **set; + int len; + int maximum; + int height; + int width; +public: + XPMSet(); + ~XPMSet(); + void Clear(); + void Add(int id, const char *textForm); + XPM *Get(int id); + int GetHeight(); + int GetWidth(); +}; + +#endif -- cgit v1.2.3