Skip to content

Commit 822d6cd

Browse files
committed
Merge pull request #4 from mdboom/add-travis
Add Travis-CI support
2 parents 7d7e4bc + b7ba314 commit 822d6cd

9 files changed

+84
-59
lines changed

.travis.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
sudo: false
2+
3+
language: python
4+
python:
5+
- "2.7"
6+
- "3.3"
7+
- "3.4"
8+
- "3.5"
9+
- "3.5-dev" # 3.5 development branch
10+
11+
# command to install dependencies
12+
install: "pip install ."
13+
# command to run tests
14+
script: |
15+
mkdir test
16+
cd test
17+
nosetests freetypy.tests

lib/freetypy/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@
3131
# as representing official policies, either expressed or implied, of
3232
# the FreeBSD Project.
3333

34+
from __future__ import absolute_import
35+
3436
from . import codecs
3537

3638
from ._freetypy import *
3739

40+
from ._freetypy import __freetype_version__
41+
3842
from . import util

lib/freetypy/tests/test_face.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def test_face_set_transform():
102102
face.set_transform([[2, 0], [0, 2]], [20, 20])
103103

104104
face.set_char_size(12, 12, 300, 300)
105-
glyph = face.load_char(65, ft.LOAD.RENDER)
105+
glyph = face.load_char(65, 0)
106106

107107
assert glyph.advance == (4352, 0)
108108
assert glyph.advance.x == 4352

lib/freetypy/tests/test_layout.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_layout():
4545
assert layout.ink_bbox.ascent == 18.0
4646
assert layout.ink_bbox.depth == -5.0
4747

48-
assert tuple(layout.layout_bbox) == (0.0, -6.0, 555.984375, 22.0)
48+
assert tuple(layout.layout_bbox)[:3] == (0.0, -6.0, 555.984375)
4949

5050
assert layout.glyph_indices.to_list() == [
5151
55, 75, 72, 3, 84, 88, 76, 70, 78, 3, 69, 85, 82, 90, 81, 3,

lib/freetypy/tests/test_size.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ def test_size():
4444
assert face.size.metrics.y_ppem == 50
4545
assert face.size.metrics.x_scale == 1.5625
4646
assert face.size.metrics.y_scale == 1.5625
47-
assert face.size.metrics.ascender == 46.0
47+
assert 46.0 <= face.size.metrics.ascender <= 47.0
4848
assert face.size.metrics.descender == -12.0
4949
assert face.size.metrics.max_advance == 67.0

src/face.c

+46-28
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ static int _py_file_to_open_args(
130130
py_file_def *stream_info = NULL;
131131
long file_size;
132132
void *new_memory;
133+
PyObject *read_string = NULL;
133134

134135
int result = -1;
135136

@@ -169,40 +170,57 @@ static int _py_file_to_open_args(
169170

170171
open_args->flags = FT_OPEN_STREAM;
171172
open_args->stream = &face->stream;
172-
} else {
173-
if (PyObject_HasAttrString(py_file_arg, "read") &&
174-
(data = PyObject_CallMethod(py_file_arg, "read", ""))) {
175-
if (PyBytes_AsStringAndSize(data, &data_ptr, &data_len)) {
176-
goto exit;
177-
}
178-
179-
if (face->mem) {
180-
free(face->mem);
181-
}
182-
face->mem = PyMem_Malloc(face->mem_size + data_len);
183-
if (face->mem == NULL) {
184-
goto exit;
185-
}
186-
new_memory = face->mem + face->mem_size;
187-
face->mem_size += data_len;
188-
189-
memcpy(new_memory, data_ptr, data_len);
190-
open_args->flags = FT_OPEN_MEMORY;
191-
open_args->memory_base = new_memory;
192-
open_args->memory_size = data_len;
193-
open_args->stream = NULL;
194-
} else {
195-
PyErr_SetString(
196-
PyExc_TypeError,
197-
"First argument must be a path or file object reading bytes");
173+
174+
result = 0;
175+
goto exit;
176+
}
177+
178+
PyErr_Clear();
179+
180+
read_string = PyUnicode_FromString("read");
181+
if (read_string == NULL) {
182+
goto exit;
183+
}
184+
185+
if (PyObject_HasAttrString(py_file_arg, "read")) {
186+
data = PyObject_CallMethodObjArgs(py_file_arg, read_string, NULL);
187+
if (data == NULL) {
198188
goto exit;
199189
}
200-
}
201190

202-
result = 0;
191+
if (PyBytes_AsStringAndSize(data, &data_ptr, &data_len)) {
192+
goto exit;
193+
}
194+
195+
if (face->mem) {
196+
free(face->mem);
197+
}
198+
face->mem = PyMem_Malloc(face->mem_size + data_len);
199+
if (face->mem == NULL) {
200+
goto exit;
201+
}
202+
new_memory = face->mem + face->mem_size;
203+
face->mem_size += data_len;
204+
205+
memcpy(new_memory, data_ptr, data_len);
206+
open_args->flags = FT_OPEN_MEMORY;
207+
open_args->memory_base = new_memory;
208+
open_args->memory_size = data_len;
209+
open_args->stream = NULL;
210+
211+
result = 0;
212+
goto exit;
213+
}
203214

204215
exit:
205216

217+
if (result && !PyErr_Occurred()) {
218+
PyErr_SetString(
219+
PyExc_TypeError,
220+
"First argument must be a path or file object reading bytes");
221+
}
222+
223+
Py_XDECREF(read_string);
206224
Py_XDECREF(py_file);
207225
Py_XDECREF(data);
208226

src/freetypy.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,23 @@ static PyMethodDef module_methods[] = {
115115
m = Py_InitModule3(
116116
"_freetypy", module_methods,
117117
"Freetype bindings");
118-
_state.dummy = 0;
119118
#endif
120119

121120
if (m == NULL) {
122121
INITERROR;
123122
}
124123

124+
{
125+
FT_Int major, minor, patch;
126+
char version_string[64];
127+
128+
FT_Library_Version(ft_library, &major, &minor, &patch);
129+
sprintf(version_string, "%d.%d.%d", major, minor, patch);
130+
if (PyModule_AddStringConstant(m, "__freetype_version__", version_string)) {
131+
INITERROR;
132+
}
133+
}
134+
125135
if (setup_pyutil(m) ||
126136
setup_constants(m) ||
127137
setup_version(m) ||

src/freetypy_error.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ int setup_errors(void) {
7878
DEF_ERROR(FT_Err_Invalid_Table, 0x08, "broken table", PyExc_ValueError);
7979
DEF_ERROR(FT_Err_Invalid_Offset, 0x09, "broken offset within table", PyExc_ValueError);
8080
DEF_ERROR(FT_Err_Array_Too_Large, 0x0A, "array allocation size too large", PyExc_MemoryError);
81-
DEF_ERROR(FT_Err_Missing_Module, 0x0B, "missing module", PyExc_RuntimeError);
82-
DEF_ERROR(FT_Err_Missing_Property, 0x0C, "missing property", PyExc_KeyError);
81+
/* DEF_ERROR(FT_Err_Missing_Module, 0x0B, "missing module", PyExc_RuntimeError); */
82+
/* DEF_ERROR(FT_Err_Missing_Property, 0x0C, "missing property", PyExc_KeyError); */
8383

8484
/* glyph/character errors */
8585

@@ -173,7 +173,7 @@ int setup_errors(void) {
173173
DEF_ERROR(FT_Err_Stack_Underflow, 0xA1, "argument stack underflow", PyExc_ValueError);
174174
DEF_ERROR(FT_Err_Ignore, 0xA2, "ignore", PyExc_ValueError);
175175
DEF_ERROR(FT_Err_No_Unicode_Glyph_Name, 0xA3, "no Unicode glyph name found", PyExc_ValueError);
176-
DEF_ERROR(FT_Err_Glyph_Too_Big, 0xA4, "glyph to big for hinting", PyExc_ValueError);
176+
/* DEF_ERROR(FT_Err_Glyph_Too_Big, 0xA4, "glyph to big for hinting", PyExc_ValueError); */
177177

178178
/* BDF errors */
179179

src/outline.c

-24
Original file line numberDiff line numberDiff line change
@@ -549,29 +549,6 @@ Py_Outline_embolden(Py_Outline* self, PyObject* args, PyObject* kwds)
549549
};
550550

551551

552-
static PyObject*
553-
Py_Outline_embolden_xy(Py_Outline* self, PyObject* args, PyObject* kwds) {
554-
double xstrength;
555-
double ystrength;
556-
557-
const char* keywords[] = {"xstrength", "ystrength", NULL};
558-
559-
if (!PyArg_ParseTupleAndKeywords(
560-
args, kwds, "d:embolden", (char **)keywords,
561-
&xstrength, &ystrength)) {
562-
return NULL;
563-
}
564-
565-
if (ftpy_exc(
566-
FT_Outline_EmboldenXY(&self->x,
567-
TO_F26DOT6(xstrength), TO_F26DOT6(ystrength)))) {
568-
return NULL;
569-
}
570-
571-
Py_RETURN_NONE;
572-
};
573-
574-
575552
static PyObject*
576553
Py_Outline_get_bbox(Py_Outline* self, PyObject* args, PyObject* kwds)
577554
{
@@ -730,7 +707,6 @@ static PyMethodDef Py_Outline_methods[] = {
730707
OUTLINE_METHOD_NOARGS(check),
731708
OUTLINE_METHOD(decompose),
732709
OUTLINE_METHOD(embolden),
733-
OUTLINE_METHOD(embolden_xy),
734710
OUTLINE_METHOD_NOARGS(get_bbox),
735711
OUTLINE_METHOD_NOARGS(get_cbox),
736712
OUTLINE_METHOD_NOARGS(get_orientation),

0 commit comments

Comments
 (0)