Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c5b85ad

Browse files
committed
Include Face in the layout
1 parent 2ffb1d7 commit c5b85ad

File tree

2 files changed

+39
-129
lines changed

2 files changed

+39
-129
lines changed

docstrings/layout.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@
6060
pixels.
6161
"""
6262

63-
Layout_glyph_indices = """
64-
The glyph indices of each glyph in the layout.
65-
"""
63+
Layout_layout = """
64+
Returns a list of tuples describing the layout.
65+
66+
Each tuple is of the form:
6667
67-
Layout_points = """
68-
The (x, y) location of each glyph in the layout.
68+
- `Face`: The `Face` object containing the glyph
69+
- `glyph_index`: The glyph index within the `Face`
70+
- `(x, y)`: The x, y position of the glyph
6971
"""

src/layout.c

Lines changed: 32 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,6 @@ either expressed or implied, of the FreeBSD Project.
4343
*/
4444

4545

46-
static PyTypeObject Py_Layout_Points_Buffer_Type;
47-
static PyTypeObject Py_Layout_Glyph_Indices_Buffer_Type;
48-
49-
50-
static PyObject *Py_Layout_Points_Buffer_cnew(PyObject *owner);
51-
static PyObject *Py_Layout_Glyph_Indices_Buffer_cnew(PyObject *owner);
52-
53-
5446
static void
5547
Py_Layout_dealloc(Py_Layout* self)
5648
{
@@ -159,116 +151,50 @@ static PyObject *layout_bbox_get(Py_Layout *self, PyObject *closure)
159151
return Py_BBox_cnew(&self->x.layout_bbox, 1.0 / (double)(1 << 6));
160152
}
161153

162-
163-
static PyObject *glyph_indices_get(Py_Layout *self, PyObject *closure)
154+
static PyObject *layout_get(Py_Layout *self, PyObject *closure)
164155
{
165-
return Py_Layout_Glyph_Indices_Buffer_cnew((PyObject *)self);
166-
}
156+
PyObject *result;
157+
PyObject *subresult;
158+
ftpy_Layout *layout;
159+
size_t i;
167160

161+
layout = &self->x;
168162

169-
static PyObject *points_get(Py_Layout *self, PyObject *closure)
170-
{
171-
return Py_Layout_Points_Buffer_cnew((PyObject *)self);
172-
}
163+
result = PyList_New(layout->size);
164+
165+
if (result == NULL) {
166+
return NULL;
167+
}
168+
169+
for (i = 0; i < layout->size; ++i) {
170+
subresult = Py_BuildValue(
171+
"(Ok(dd))",
172+
self->base.owner,
173+
layout->glyph_indices[i],
174+
layout->xys[i].x,
175+
layout->xys[i].y);
176+
if (subresult == NULL) {
177+
Py_DECREF(result);
178+
return NULL;
179+
}
180+
if (PyList_SetItem(result, i, subresult)) {
181+
Py_DECREF(subresult);
182+
Py_DECREF(result);
183+
return NULL;
184+
}
185+
}
173186

187+
return result;
188+
}
174189

175190
static PyGetSetDef Py_Layout_getset[] = {
176191
DEF_LAYOUT_GETTER(ink_bbox),
177192
DEF_LAYOUT_GETTER(layout_bbox),
178-
DEF_LAYOUT_GETTER(glyph_indices),
179-
DEF_LAYOUT_GETTER(points),
193+
DEF_LAYOUT_GETTER(layout),
180194
{NULL}
181195
};
182196

183197

184-
185-
/****************************************************************************
186-
Ancillary buffers
187-
*/
188-
189-
190-
static PyObject *
191-
Py_Layout_Points_Buffer_cnew(PyObject *owner)
192-
{
193-
ftpy_Buffer *self;
194-
self = (ftpy_Buffer *)(&Py_Layout_Points_Buffer_Type)->tp_alloc(
195-
&Py_Layout_Points_Buffer_Type, 0);
196-
Py_INCREF(owner);
197-
self->base.owner = owner;
198-
return (PyObject *)self;
199-
}
200-
201-
202-
static int Py_Layout_Points_Buffer_get_buffer(
203-
ftpy_Buffer *self, Py_buffer *view, int flags)
204-
{
205-
ftpy_Layout *layout = &((Py_Layout *)self->base.owner)->x;
206-
size_t itemsize = sizeof(double);
207-
208-
Py_INCREF(self);
209-
view->obj = (PyObject *)self;
210-
view->buf = layout->xys;
211-
view->readonly = 1;
212-
view->itemsize = itemsize;
213-
view->format = "d";
214-
view->len = layout->size * 2 * itemsize;
215-
view->internal = NULL;
216-
view->ndim = 2;
217-
view->shape = self->shape;
218-
self->shape[0] = layout->size;
219-
self->shape[1] = 2;
220-
view->strides = self->strides;
221-
self->strides[0] = itemsize * 2;
222-
self->strides[1] = itemsize;
223-
view->suboffsets = NULL;
224-
225-
return 0;
226-
}
227-
228-
229-
static PyBufferProcs Py_Layout_Points_Buffer_procs;
230-
231-
232-
static PyObject *
233-
Py_Layout_Glyph_Indices_Buffer_cnew(PyObject *owner)
234-
{
235-
ftpy_Buffer *self;
236-
self = (ftpy_Buffer *)(&Py_Layout_Glyph_Indices_Buffer_Type)->tp_alloc(
237-
&Py_Layout_Glyph_Indices_Buffer_Type, 0);
238-
Py_INCREF(owner);
239-
self->base.owner = owner;
240-
return (PyObject *)self;
241-
}
242-
243-
244-
static int Py_Layout_Glyph_Indices_Buffer_get_buffer(
245-
ftpy_Buffer *self, Py_buffer *view, int flags)
246-
{
247-
ftpy_Layout *layout = &((Py_Layout *)self->base.owner)->x;
248-
size_t itemsize = sizeof(FT_ULong);
249-
250-
Py_INCREF(self);
251-
view->obj = (PyObject *)self;
252-
view->buf = layout->glyph_indices;
253-
view->readonly = 1;
254-
view->itemsize = itemsize;
255-
view->format = "L";
256-
view->len = layout->size * itemsize;
257-
view->internal = NULL;
258-
view->ndim = 1;
259-
view->shape = self->shape;
260-
self->shape[0] = layout->size;
261-
view->strides = self->strides;
262-
self->strides[0] = itemsize;
263-
view->suboffsets = NULL;
264-
265-
return 0;
266-
}
267-
268-
269-
static PyBufferProcs Py_Layout_Glyph_Indices_Buffer_procs;
270-
271-
272198
/****************************************************************************
273199
Setup
274200
*/
@@ -293,23 +219,5 @@ int setup_Layout(PyObject *m)
293219

294220
ftpy_setup_type(m, &Py_Layout_Type);
295221

296-
if (ftpy_setup_buffer_type(
297-
&Py_Layout_Points_Buffer_Type,
298-
"freetypy.Layout.PointsBuffer",
299-
doc_Layout_points,
300-
&Py_Layout_Points_Buffer_procs,
301-
(getbufferproc)Py_Layout_Points_Buffer_get_buffer)) {
302-
return -1;
303-
}
304-
305-
if (ftpy_setup_buffer_type(
306-
&Py_Layout_Glyph_Indices_Buffer_Type,
307-
"freetypy.Layout.Glyph_Indices_Buffer",
308-
doc_Layout_glyph_indices,
309-
&Py_Layout_Glyph_Indices_Buffer_procs,
310-
(getbufferproc)Py_Layout_Glyph_Indices_Buffer_get_buffer)) {
311-
return -1;
312-
}
313-
314222
return 0;
315223
}

0 commit comments

Comments
 (0)