1 /* Copyright (C) 2007-2012 by George Williams */
2 /*
3  * Redistribution and use in source and binary forms, with or without
4  * modification, are permitted provided that the following conditions are met:
5 
6  * Redistributions of source code must retain the above copyright notice, this
7  * list of conditions and the following disclaimer.
8 
9  * Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12 
13  * The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15 
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef FONTFORGE_FFPYTHON_H
29 #define FONTFORGE_FFPYTHON_H
30 
31 #include "flaglist.h"
32 
33 #pragma push_macro("real")
34 #undef real
35 #define real py_real
36 
37 #include <Python.h>
38 #include <structmember.h>
39 
40 #undef real
41 #pragma pop_macro("real")
42 
43 /*********** Common **********/
44 #ifndef Py_TYPE
45 #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
46 #endif
47 
48 #ifndef Py_TYPENAME
49 #define Py_TYPENAME(ob) (((PyObject*)(ob))->ob_type->tp_name)
50 #endif
51 
52 #define Py_RETURN(self)		return( Py_INCREF((PyObject *) (self)), (PyObject *) (self) )
53 
54 #ifndef PyMODINIT_FUNC	/* declarations for DLL import/export */
55 #define PyMODINIT_FUNC void
56 #endif
57 
58 #ifndef PyVarObject_HEAD_INIT
59     #define PyVarObject_HEAD_INIT(type, size) \
60         PyObject_HEAD_INIT(type) size,
61 #endif
62 
63 extern SplineChar *sc_active_in_ui;
64 extern FontViewBase *fv_active_in_ui;
65 extern int layer_active_in_ui;
66 
67 extern void FfPy_Replace_MenuItemStub(PyObject *(*func)(PyObject *,PyObject *));
68 extern int PyFF_ConvexNibID(const char *);
69 extern PyObject *PySC_From_SC(SplineChar *sc);
70 extern PyObject *PyFV_From_FV(FontViewBase *fv);
71 extern int FlagsFromTuple(PyObject *tuple,struct flaglist *flags,const char *flagkind);
72 extern void PyFF_Glyph_Set_Layer(SplineChar *sc,int layer);
73 
74 
75 /********************************************************************************/
76 /** Allow both python.c and pythonui.c to access the python objects.          ***/
77 /********************************************************************************/
78 
79 /* Other sentinel values for end-of-array initialization */
80 #define PYMETHODDEF_EMPTY  { NULL, NULL, 0, NULL }
81 #define PYGETSETDEF_EMPTY { NULL, NULL, NULL, NULL, NULL }
82 
83 typedef struct ff_point {
84     PyObject_HEAD
85     /* Type-specific fields go here. */
86     double x,y;
87     uint8 on_curve;
88     uint8 selected;
89     uint8 type;
90     uint8 interpolated;
91     char *name;
92 } PyFF_Point;
93 static PyTypeObject PyFF_PointType;
94 
95 typedef struct ff_contour {
96     PyObject_HEAD
97     /* Type-specific fields go here. */
98     int pt_cnt, pt_max;
99     struct ff_point **points;
100     short is_quadratic, closed;		/* bit flags, but access to short is faster */
101     spiro_cp *spiros;
102     int spiro_cnt;
103     char *name;
104 } PyFF_Contour;
105 extern PyTypeObject PyFF_ContourType;
106 
107 typedef struct ff_layer {
108     PyObject_HEAD
109     /* Type-specific fields go here. */
110     short cntr_cnt, cntr_max;
111     struct ff_contour **contours;
112     int is_quadratic;		/* bit flags, but access to int is faster */
113 } PyFF_Layer;
114 extern PyTypeObject PyFF_LayerType;
115 
116 typedef struct {
117     PyObject_HEAD
118     /* Type-specific fields go here. */
119     SplineChar *sc;
120     uint8 replace;
121     uint8 ended;
122     uint8 changed;
123     int layer;
124 } PyFF_GlyphPen;
125 static PyTypeObject PyFF_GlyphPenType;
126 
127 typedef struct {
128     PyObject_HEAD
129     /* Type-specific fields go here. */
130     SplineChar *sc;
131 } PyFF_LayerArray;
132 static PyTypeObject PyFF_LayerArrayType;
133 
134 typedef struct {
135     PyObject_HEAD
136     /* Type-specific fields go here. */
137     SplineChar *sc;
138 } PyFF_RefArray;
139 static PyTypeObject PyFF_RefArrayType;
140 
141 typedef struct glyphmathkernobject {
142     PyObject_HEAD
143     SplineChar *sc;
144 } PyFF_MathKern;
145 static PyTypeObject PyFF_MathKernType;
146 
147 typedef struct {
148     PyObject_HEAD
149     /* Type-specific fields go here. */
150     SplineChar *sc;
151     PyFF_LayerArray *layers;
152     PyFF_RefArray *refs;
153     PyFF_MathKern *mk;
154     int layer;
155 } PyFF_Glyph;
156 static PyTypeObject PyFF_GlyphType;
157 
158 typedef struct {
159     PyObject_HEAD
160     /* Type-specific fields go here. */
161     SplineFont *sf;
162     int layer;
163 } PyFF_LayerInfo;
164 static PyTypeObject PyFF_LayerInfoType;
165 
166 typedef struct {
167     PyObject_HEAD
168     /* Type-specific fields go here. */
169     SplineFont *sf;
170 } PyFF_LayerInfoArray;
171 static PyTypeObject PyFF_LayerInfoArrayType;
172 
173 typedef struct {
174     PyObject_HEAD
175     /* Type-specific fields go here. */
176     SplineFont *sf;
177     FontViewBase *fv;
178 } PyFF_Private;
179 static PyTypeObject PyFF_PrivateType;
180 
181 typedef struct {
182     PyObject_HEAD
183     /* Type-specific fields go here. */
184     FontViewBase *fv;
185     int by_glyphs;
186 } PyFF_Selection;
187 static PyTypeObject PyFF_SelectionType;
188 
189 typedef struct {
190     PyObject_HEAD
191     /* Type-specific fields go here. */
192     SplineFont *sf;
193     struct ttf_table *cvt;
194 } PyFF_Cvt;
195 static PyTypeObject PyFF_CvtType;
196 
197 typedef struct fontmathobject {
198     PyObject_HEAD
199     SplineFont *sf;
200 } PyFF_Math;
201 static PyTypeObject PyFF_MathType;
202 
203 typedef struct {
204     PyObject_HEAD
205     /* Type-specific fields go here. */
206     FontViewBase *fv;
207     PyFF_LayerInfoArray *layers;
208     PyFF_Private *private;
209     PyFF_Cvt *cvt;
210     PyFF_Selection *selection;
211     PyFF_Math *math;
212 } PyFF_Font;
213 static PyTypeObject PyFF_FontType;
214 
215 extern PyMethodDef PyFF_Font_methods[];
216 extern PyMethodDef module_fontforge_methods[];
217 
218 PyObject* PyFF_FontForFV(FontViewBase *fv);
219 PyObject* PyFF_FontForFV_I(FontViewBase *fv);
220 
221 #endif /* FONTFORGE_FFPYTHON_H */
222