def set_font(self, font): """ Set the font for the current graphics context. """ if sys.platform in ('win32', 'cygwin'): # Have to pass weight and italic on Win32 weight = font_weights.get(font._get_weight(), agg.FontWeight.Regular) italic = (font.style in constants.italic_styles) # Win32 font selection is handled by the OS self.font = agg.Font(font.findfontname(), font.size, weight, italic) else: # FreeType font selection is handled by kiva spec = font.findfont() self.font = agg.Font(spec.filename, font.size, spec.face_index)
def test_bad_method_args(): canvas = agg.CanvasG8(np.zeros((1, 1), dtype=np.uint8)) pix_format = agg.PixelFormat.Gray8 gs = agg.GraphicsState() path = agg.Path() transform = agg.Transform() with pytest.raises(TypeError): canvas.draw_image(None, pix_format, transform, gs) with pytest.raises(TypeError): canvas.draw_image(canvas.array, None, transform, gs) with pytest.raises(TypeError): canvas.draw_image(canvas.array, pix_format, None, gs) with pytest.raises(TypeError): canvas.draw_image(canvas.array, pix_format, transform, None) # But this version should work canvas.draw_image(canvas.image, None, transform, gs) with pytest.raises(TypeError): canvas.draw_shape(None, transform, gs) with pytest.raises(TypeError): canvas.draw_shape(path, None, gs) with pytest.raises(TypeError): canvas.draw_shape(path, transform, None) text = "Hello!" font = agg.Font("Times New Roman", 12.0, agg.FontCacheType.RasterFontCache) with pytest.raises(TypeError): canvas.draw_text(text, None, transform, gs) with pytest.raises(TypeError): canvas.draw_text(text, font, None, gs) with pytest.raises(TypeError): canvas.draw_text(text, font, transform, None)
def select_font(self, name, size, textEncoding): """ Set the font for the current graphics context. """ self.font = agg.Font(name, size, agg.FontCacheType.RasterFontCache)
def test_no_text_font_failure(): if agg.HAS_TEXT: return with pytest.raises(RuntimeError): agg.Font()
import celiagg as agg import numpy as np from skimage.io import imsave canvas = agg.CanvasRGB24(np.ones((400, 400, 3), dtype=np.uint8)) state = agg.GraphicsState(drawing_mode=agg.DrawingMode.DrawStroke, line_width=10.0) transform = agg.Transform() red_paint = agg.SolidPaint(1.0, 0.0, 0.0) black_paint = agg.SolidPaint(0.0, 0.0, 0.0) font = agg.Font("/Library/Fonts/Verdana.ttf", 96.0, agg.FontCacheType.RasterFontCache) path = agg.Path() path.ellipse(200, 200, 190, 190) canvas.clear(1.0, 1.0, 1.0) canvas.draw_shape(path, transform, state, stroke=red_paint) transform.translate(30.0, 220.0) canvas.draw_text("celiagg", font, transform, state, stroke=black_paint) imsave("example.png", canvas.array)