Skip to content

Commit d98e897

Browse files
Added AppKit framework for MACOSX
Refactored to allow Cairo but no TK builds
1 parent 1ff0359 commit d98e897

File tree

5 files changed

+40
-32
lines changed

5 files changed

+40
-32
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ endif
7373
ifdef MAC_OSX_TK
7474
CXXFLAGS+=-DMAC_OSX_TK
7575
OBJS+=src/getContext.o
76+
LIBS+=-framework AppKit
7677
endif
7778

7879
CDHDRS=ref.cd random.cd random_basic.cd TCL_obj_base.cd RESTProcess_base.cd signature.cd netcomplexity.cd graph.cd cachedDBM.cd sparse_mat.cd analysis.cd analysisBLT.cd analysisCairo.cd plot.cd cairoSurfaceImage.cd polyRESTProcess.cd

include/cairoSurfaceImage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#ifndef CAIROSURFACEIMAGE_H
1010
#define CAIROSURFACEIMAGE_H
11-
#if defined(CAIRO) && defined(TK)
11+
#if defined(CAIRO)
1212
#include "cairo_base.h"
1313

1414
namespace ecolab

include/cairo_base.h

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,26 @@ namespace ecolab
168168
typedef std::tr1::shared_ptr<Surface> SurfacePtr;
169169
#endif
170170

171+
/// RAII object wrapping a cairo_path_t, along with its transformation
172+
class Path
173+
{
174+
cairo_path_t* m_path;
175+
cairo_matrix_t m_transformation;
176+
Path(const Path&);
177+
void operator=(const Path&);
178+
public:
179+
Path(cairo_t* cairo): m_path(cairo_copy_path(cairo))
180+
{cairo_get_matrix(cairo, &m_transformation);}
181+
~Path() {cairo_path_destroy(m_path);}
182+
void appendToCurrent(cairo_t* cairo) {
183+
// apply saved transformation along with path
184+
cairo_save(cairo);
185+
cairo_set_matrix(cairo,&m_transformation);
186+
cairo_append_path(cairo,m_path);
187+
cairo_restore(cairo);
188+
}
189+
};
190+
171191
#ifdef TK
172192
struct PhotoImageBlock: public Tk_PhotoImageBlock
173193
{
@@ -319,27 +339,6 @@ namespace ecolab
319339

320340
};
321341

322-
/// RAII object wrapping a cairo_path_t, along with its transformation
323-
class Path
324-
{
325-
cairo_path_t* m_path;
326-
cairo_matrix_t m_transformation;
327-
Path(const Path&);
328-
void operator=(const Path&);
329-
public:
330-
Path(cairo_t* cairo): m_path(cairo_copy_path(cairo))
331-
{cairo_get_matrix(cairo, &m_transformation);}
332-
~Path() {cairo_path_destroy(m_path);}
333-
void appendToCurrent(cairo_t* cairo) {
334-
// apply saved transformation along with path
335-
cairo_save(cairo);
336-
cairo_set_matrix(cairo,&m_transformation);
337-
cairo_append_path(cairo,m_path);
338-
cairo_restore(cairo);
339-
}
340-
};
341-
342-
343342
/// internal structure used for Tk Canvas cairo image items
344343
struct ImageItem {
345344
Tk_Item header; /* Generic stuff that's the same for all

src/cairoSurfaceImage.cc

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
Open source licensed under the MIT license. See LICENSE for details.
77
*/
88

9-
#if defined(CAIRO) && defined(TK)
9+
#ifdef CAIRO
1010
#include "cairoSurfaceImage.h"
11-
#include "tcl++.h"
1211
#include "pango.h"
1312

1413
#include "ecolab_epilogue.h"
@@ -20,12 +19,19 @@
2019
#include <cairo/cairo-pdf.h>
2120
#include <cairo/cairo-svg.h>
2221

22+
using namespace ecolab;
23+
using namespace std;
24+
25+
#ifdef TK
26+
#include "tcl++.h"
27+
2328
#ifdef _WIN32
2429
#undef Realloc
2530
#include <windows.h>
2631
#include <wingdi.h>
2732
#ifdef USE_WIN32_SURFACE
2833
#include <cairo/cairo-win32.h>
34+
2935
// undocumented internal function for extracting the HDC from a Drawable
3036
extern "C" HDC TkWinGetDrawableDC(Display*, Drawable, void*);
3137
extern "C" HDC TkWinReleaseDrawableDC(Drawable, HDC, void*);
@@ -47,9 +53,6 @@ extern "C" HDC TkWinReleaseDrawableDC(Drawable, HDC, void*);
4753
#define CONST86
4854
#endif
4955

50-
using namespace ecolab;
51-
using namespace std;
52-
5356
namespace
5457
{
5558
struct TkWinSurface: public ecolab::cairo::Surface
@@ -193,11 +196,14 @@ namespace
193196

194197
}
195198

199+
#endif // TK
196200
void CairoSurface::registerImage()
197201
{
202+
#ifdef TK
198203
// ensure Tk_Init is called.
199204
if (!Tk_MainWindow(interp())) Tk_Init(interp());
200205
Tk_CreateImageType(&canvasImage);
206+
#endif
201207
}
202208

203209
cairo::SurfacePtr CairoSurface::vectorRender(const char* filename, cairo_surface_t* (*s)(const char *,double,double))
@@ -293,4 +299,4 @@ void CairoSurface::renderToEMF(const string& filename)
293299

294300
#endif
295301

296-
#endif
302+
#endif //CAIRO

src/cairo_base.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
#include "ecolab_epilogue.h"
1313

1414
const char *ecolab::Pango::defaultFamily=NULL;
15+
double ecolab::Pango::scaleFactor=1;
1516

16-
#if defined(CAIRO) && defined(TK)
17+
#if defined(CAIRO)
1718

1819
#if CAIRO_VERSION_MAJOR <= 1 && CAIRO_VERSION_MINOR < 10
1920
//#error "Cairo 1.10.x minimum required"
@@ -22,6 +23,7 @@ bool cairo_in_clip(cairo_t*,double,double) {return true;}
2223
#endif
2324

2425
using namespace std;
26+
#if defined(TK)
2527

2628
namespace
2729
{
@@ -90,7 +92,6 @@ namespace
9092

9193
namespace ecolab
9294
{
93-
double Pango::scaleFactor=1;
9495

9596
namespace cairo
9697
{
@@ -136,7 +137,7 @@ namespace ecolab
136137
else
137138
throw error("image %s not found", imgName.c_str());
138139
}
139-
140+
140141
double CairoImage::distanceFrom(double x, double y) const
141142
{
142143
if (cairoSurface)
@@ -225,4 +226,5 @@ namespace ecolab
225226
}
226227
}
227228

228-
#endif
229+
#endif // TK
230+
#endif // CAIRO

0 commit comments

Comments
 (0)