From 30fe91ce1c122f1a2ce5dfb742b7862474db826e Mon Sep 17 00:00:00 2001 From: Steve Chaplin <> Date: Wed, 15 Sep 2010 09:37:32 +0800 Subject: Add/update tests for unicode filenames and unicode text. --- test/unicode.py | 28 ---------------------------- test/unicodeFilenames.py | 31 +++++++++++++++++++++++++++++++ test/unicodeText.py | 31 +++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 28 deletions(-) delete mode 100755 test/unicode.py create mode 100755 test/unicodeFilenames.py create mode 100755 test/unicodeText.py diff --git a/test/unicode.py b/test/unicode.py deleted file mode 100755 index a9c89f3..0000000 --- a/test/unicode.py +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# test unicode filenames - -import math -import cairo - -WIDTH, HEIGHT = 256, 256 - -#f = open(u"ēxāmple.pdf","w") -#surface = cairo.PDFSurface (f, WIDTH, HEIGHT) - -surface = cairo.PDFSurface (u"a1ēxāmple.pdf", WIDTH, HEIGHT) - -ctx = cairo.Context (surface) -ctx.scale (WIDTH, HEIGHT) -pat = cairo.LinearGradient (0.0, 0.0, 0.0, 1.0) -pat.add_color_stop_rgba (1, 0.7, 0, 0, 0.5) -pat.add_color_stop_rgba (0, 0.9, 0.7, 0.2, 1) -ctx.rectangle (0, 0, 1, 1) -ctx.set_source (pat) -ctx.fill () -ctx.translate (0.1, 0.1) - -surface.write_to_png (u"a2ēxāmple.png") -surface.show_page() -surface.flush() -surface.finish() diff --git a/test/unicodeFilenames.py b/test/unicodeFilenames.py new file mode 100755 index 0000000..4378449 --- /dev/null +++ b/test/unicodeFilenames.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" +Test unicode filenames + +Functions/methods using unicode filenames: + cairo.PDFSurface() + cairo.PSSurface() + cairo.SVGSurface() + surface.write_to_png() + surface.create_from_png() +""" + +import cairo + +WIDTH, HEIGHT = 256, 256 + +#f = open(u"a1ēxāmple.pdf","w") +#surface = cairo.PDFSurface (f, WIDTH, HEIGHT) + +surface = cairo.PDFSurface(u"a1ēxāmple.pdf", WIDTH, HEIGHT) + +ctx = cairo.Context(surface) +ctx.set_source_rgb(1,0,0) +ctx.set_operator(cairo.OPERATOR_SOURCE) +ctx.paint() + +surface.write_to_png(u"a2ēxāmple.png") +surface.show_page() +surface.flush() +surface.finish() diff --git a/test/unicodeText.py b/test/unicodeText.py new file mode 100755 index 0000000..5ad50c7 --- /dev/null +++ b/test/unicodeText.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" +Test unicode text + +Functions/methods which accept unicode text: + Context.select_font_face() + Context.show_text() + Context.text_extents() + Context.text_path() + ToyFontFace() + ScaledFont.text_extents() +""" + +import cairo + +width, height = 300,300 +surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) +ctx = cairo.Context(surface) + +ctx.scale(width, height) +ctx.set_line_width(0.04) + +ctx.select_font_face("Sans", + cairo.FONT_SLANT_NORMAL, + cairo.FONT_WEIGHT_NORMAL) +ctx.set_font_size(0.20) +ctx.move_to(0.05, 0.5) +ctx.show_text("ēxāmple.") + +surface.write_to_png("test-out.png") -- cgit v1.2.3