diff --git a/.gitignore b/.gitignore index 26e300d..fb08ae5 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ nimcache .* dist __pycache__ +pixie_python.egg-info/ +build/ diff --git a/setup.py b/setup.py index 60a2b39..946c296 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name = "pixie-python", - version = "4.0.1", + version = "4.3.0", author = "Andre von Houck", author_email = "starplant@gmail.com", description = "Python bindings for Pixie, a full-featured 2D graphics library", diff --git a/src/pixie/libpixie.dylib b/src/pixie/libpixie.dylib index ed054fd..0a4e69b 100755 Binary files a/src/pixie/libpixie.dylib and b/src/pixie/libpixie.dylib differ diff --git a/src/pixie/libpixie.so b/src/pixie/libpixie.so index 47a5e30..8381ddc 100755 Binary files a/src/pixie/libpixie.so and b/src/pixie/libpixie.so differ diff --git a/src/pixie/pixie.dll b/src/pixie/pixie.dll index 531e912..0199f03 100644 Binary files a/src/pixie/pixie.dll and b/src/pixie/pixie.dll differ diff --git a/src/pixie/pixie.py b/src/pixie/pixie.py index 9f427a4..01f3984 100644 --- a/src/pixie/pixie.py +++ b/src/pixie/pixie.py @@ -34,7 +34,7 @@ def __next__(self): FileFormat = c_byte PNG_FORMAT = 0 BMP_FORMAT = 1 -JPG_FORMAT = 2 +JPEG_FORMAT = 2 GIF_FORMAT = 3 QOI_FORMAT = 4 PPM_FORMAT = 5 @@ -280,11 +280,11 @@ def typeset(self, bounds = None, h_align = LEFT_ALIGN, v_align = TOP_ALIGN, wrap result = dll.pixie_seq_span_typeset(self, bounds, h_align, v_align, wrap) return result - def compute_bounds(self): + def layout_bounds(self): """ Computes the width and height of the spans in pixels. """ - result = dll.pixie_seq_span_compute_bounds(self) + result = dll.pixie_seq_span_layout_bounds(self) return result class Image(Structure): @@ -685,7 +685,7 @@ def apply_opacity(self, opacity): def invert(self): """ - Inverts all of the colors and alpha. + Inverts all of the values - creates a negative of the mask. """ dll.pixie_mask_invert(self) @@ -1087,8 +1087,11 @@ def circle(self, cx, cy, r): def polygon(self, x, y, size, sides): """ Adds an n-sided regular polygon at (x, y) with the parameter size. + Polygons "face" north. """ dll.pixie_path_polygon(self, x, y, size, sides) + if check_error(): + raise PixieError(take_error()) class Typeface(Structure): _fields_ = [("ref", c_ulonglong)] @@ -1306,11 +1309,11 @@ def typeset(self, text, bounds = None, h_align = LEFT_ALIGN, v_align = TOP_ALIGN result = dll.pixie_font_typeset(self, text.encode("utf8"), bounds, h_align, v_align, wrap) return result - def compute_bounds(self, text): + def layout_bounds(self, text): """ Computes the width and height of the text in pixels. """ - result = dll.pixie_font_compute_bounds(self, text.encode("utf8")) + result = dll.pixie_font_layout_bounds(self, text.encode("utf8")) return result class Span(Structure): @@ -1357,11 +1360,19 @@ def __eq__(self, obj): def __del__(self): dll.pixie_arrangement_unref(self) - def compute_bounds(self): + def layout_bounds(self): """ Computes the width and height of the arrangement in pixels. """ - result = dll.pixie_arrangement_compute_bounds(self) + result = dll.pixie_arrangement_layout_bounds(self) + return result + + def compute_bounds(self, transform = None): + if transform is None: + transform = Matrix3() + result = dll.pixie_arrangement_compute_bounds(self, transform) + if check_error(): + raise PixieError(take_error()) return result class Context(Structure): @@ -1703,6 +1714,8 @@ def polygon(self, x, y, size, sides): Adds an n-sided regular polygon at (x, y) of size to the current path. """ dll.pixie_context_polygon(self, x, y, size, sides) + if check_error(): + raise PixieError(take_error()) def clear_rect(self, x, y, width, height): """ @@ -1957,8 +1970,8 @@ def inverse(m): dll.pixie_seq_span_typeset.argtypes = [SeqSpan, Vector2, HorizontalAlignment, VerticalAlignment, c_bool] dll.pixie_seq_span_typeset.restype = Arrangement -dll.pixie_seq_span_compute_bounds.argtypes = [SeqSpan] -dll.pixie_seq_span_compute_bounds.restype = Vector2 +dll.pixie_seq_span_layout_bounds.argtypes = [SeqSpan] +dll.pixie_seq_span_layout_bounds.restype = Vector2 dll.pixie_image_unref.argtypes = [Image] dll.pixie_image_unref.restype = None @@ -2395,8 +2408,8 @@ def inverse(m): dll.pixie_font_typeset.argtypes = [Font, c_char_p, Vector2, HorizontalAlignment, VerticalAlignment, c_bool] dll.pixie_font_typeset.restype = Arrangement -dll.pixie_font_compute_bounds.argtypes = [Font, c_char_p] -dll.pixie_font_compute_bounds.restype = Vector2 +dll.pixie_font_layout_bounds.argtypes = [Font, c_char_p] +dll.pixie_font_layout_bounds.restype = Vector2 dll.pixie_span_unref.argtypes = [Span] dll.pixie_span_unref.restype = None @@ -2419,8 +2432,11 @@ def inverse(m): dll.pixie_arrangement_unref.argtypes = [Arrangement] dll.pixie_arrangement_unref.restype = None -dll.pixie_arrangement_compute_bounds.argtypes = [Arrangement] -dll.pixie_arrangement_compute_bounds.restype = Vector2 +dll.pixie_arrangement_layout_bounds.argtypes = [Arrangement] +dll.pixie_arrangement_layout_bounds.restype = Vector2 + +dll.pixie_arrangement_compute_bounds.argtypes = [Arrangement, Matrix3] +dll.pixie_arrangement_compute_bounds.restype = Rect dll.pixie_context_unref.argtypes = [Context] dll.pixie_context_unref.restype = None diff --git a/tests/images/mandrill.jpg b/tests/images/mandrill.jpg new file mode 100644 index 0000000..c2c215f Binary files /dev/null and b/tests/images/mandrill.jpg differ diff --git a/tests/images/mandrill.png b/tests/images/mandrill.png new file mode 100644 index 0000000..a8556f2 Binary files /dev/null and b/tests/images/mandrill.png differ diff --git a/tests/test_arrangement.py b/tests/test_arrangement.py index 1e1c4dc..40c20d6 100644 --- a/tests/test_arrangement.py +++ b/tests/test_arrangement.py @@ -6,4 +6,4 @@ def test_procs(): spans = pixie.SeqSpan() spans.append(span) arrangement = spans.typeset() - assert arrangement.compute_bounds() == pixie.Vector2(39, 14) + assert arrangement.layout_bounds() == pixie.Vector2(39, 14) diff --git a/tests/test_context.py b/tests/test_context.py index b10cae8..77c057b 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -113,7 +113,7 @@ def test_paths(): context.rounded_rect(0, 0, 0, 0, 0, 0, 0, 0) context.ellipse(0, 0, 0, 0) context.circle(0, 0, 0) - context.polygon(0, 0, 0, 0) + context.polygon(0, 0, 0, 3) context.close_path() assert not context.is_point_in_path(1, 1) assert not context.is_point_in_stroke(1, 1) diff --git a/tests/test_fileformats.py b/tests/test_fileformats.py new file mode 100644 index 0000000..1c168de --- /dev/null +++ b/tests/test_fileformats.py @@ -0,0 +1,7 @@ +import pixie + +def test_png(): + image = pixie.read_image("tests/images/mandrill.png") + +def test_jpeg(): + image = pixie.read_image("tests/images/mandrill.jpg") diff --git a/tests/test_font.py b/tests/test_font.py index 696a096..c1846c2 100644 --- a/tests/test_font.py +++ b/tests/test_font.py @@ -39,4 +39,4 @@ def test_procs(): assert font.default_line_height() == 14 arrangement = font.typeset("typeset") assert arrangement is not None - assert font.compute_bounds("typeset") == pixie.Vector2(39, 14) + assert font.layout_bounds("typeset") == pixie.Vector2(39, 14) diff --git a/tests/test_path.py b/tests/test_path.py index 58477d7..c46594d 100644 --- a/tests/test_path.py +++ b/tests/test_path.py @@ -13,7 +13,7 @@ def test(): path.rounded_rect(0, 0, 0, 0, 0, 0, 0, 0) path.ellipse(0, 0, 0, 0) path.circle(0, 0, 0) - path.polygon(0, 0, 0, 0) + path.polygon(0, 0, 0, 3) path.transform(pixie.Matrix3()) path.add_path(pixie.Path()) path.close_path() diff --git a/tests/test_span.py b/tests/test_span.py index 8eba9d1..e6b933e 100644 --- a/tests/test_span.py +++ b/tests/test_span.py @@ -12,4 +12,4 @@ def test_procs(): spans = pixie.SeqSpan() spans.append(span) assert spans.typeset() is not None - assert spans.compute_bounds() == pixie.Vector2(39, 14) + assert spans.layout_bounds() == pixie.Vector2(39, 14)