Exemplo n.º 1
0
 def test_multiline_lr(self):
     font = ImageFont.load_default()
     td = TextDraw('Hello\nWorld', font, placement='lr')
     img = Image.new('RGB', (100, 100))
     draw = ImageDraw.Draw(img)
     total_box, boxes = td.text_boxes(draw, (100, 100))
     eq_(total_box, (65, 70, 95, 95))
     eq_(boxes, [(65, 70, 95, 81), (65, 84, 95, 95)])
Exemplo n.º 2
0
 def check_placement(self, x, y):
     font = ImageFont.load_default()
     td = TextDraw('Hello\nWorld\n%s %s' % (x, y), font, placement=x+y,
         padding=5, linespacing=2)
     img = Image.new('RGB', (100, 100))
     draw = ImageDraw.Draw(img)
     td.draw(draw, img.size)
     img.show()
Exemplo n.º 3
0
 def test_multiline_center(self):
     font = ImageFont.load_default()
     td = TextDraw('Hello\nWorld', font, placement='cc')
     img = Image.new('RGB', (100, 100))
     draw = ImageDraw.Draw(img)
     total_box, boxes = td.text_boxes(draw, (100, 100))
     eq_(total_box, (35, 38, 65, 63))
     eq_(boxes, [(35, 38, 65, 49), (35, 52, 65, 63)])
Exemplo n.º 4
0
 def test_ul(self):
     font = ImageFont.load_default()
     td = TextDraw('Hello', font)
     img = Image.new('RGB', (100, 100))
     draw = ImageDraw.Draw(img)
     total_box, boxes = td.text_boxes(draw, (100, 100))
     eq_(total_box, boxes[0])
     eq_(len(boxes), 1)
Exemplo n.º 5
0
 def test_multiline_ul(self):
     font = ImageFont.load_default()
     td = TextDraw('Hello\nWorld', font)
     img = Image.new('RGB', (100, 100))
     draw = ImageDraw.Draw(img)
     total_box, boxes = td.text_boxes(draw, (100, 100))
     eq_(total_box, (5, 5, 35, 30))
     eq_(boxes, [(5, 5, 35, 16), (5, 19, 35, 30)])
Exemplo n.º 6
0
 def test_multiline_lr(self):
     font = ImageFont.load_default()
     td = TextDraw('Hello\nWorld', font, placement='lr')
     img = Image.new('RGB', (100, 100))
     draw = ImageDraw.Draw(img)
     total_box, boxes = td.text_boxes(draw, (100, 100))
     eq_(total_box, (65, 70, 95, 95))
     eq_(boxes, [(65, 70, 95, 81), (65, 84, 95, 95)])
Exemplo n.º 7
0
 def test_multiline_center(self):
     font = ImageFont.load_default()
     td = TextDraw('Hello\nWorld', font, placement='cc')
     img = Image.new('RGB', (100, 100))
     draw = ImageDraw.Draw(img)
     total_box, boxes = td.text_boxes(draw, (100, 100))
     eq_(total_box, (35, 38, 65, 63))
     eq_(boxes, [(35, 38, 65, 49), (35, 52, 65, 63)])
Exemplo n.º 8
0
 def test_multiline_ul(self):
     font = ImageFont.load_default()
     td = TextDraw('Hello\nWorld', font)
     img = Image.new('RGB', (100, 100))
     draw = ImageDraw.Draw(img)
     total_box, boxes = td.text_boxes(draw, (100, 100))
     eq_(total_box, (5, 5, 35, 30))
     eq_(boxes, [(5, 5, 35, 16), (5, 19, 35, 30)])
Exemplo n.º 9
0
 def test_ul(self):
     font = ImageFont.load_default()
     td = TextDraw('Hello', font)
     img = Image.new('RGB', (100, 100))
     draw = ImageDraw.Draw(img)
     total_box, boxes = td.text_boxes(draw, (100, 100))
     eq_(total_box, boxes[0])
     eq_(len(boxes), 1)
Exemplo n.º 10
0
 def font(self):
     global _pil_ttf_support
     if self._font is None:
         if self.font_name != 'default' and _pil_ttf_support:
             try:
                 self._font = ImageFont.truetype(font_file(self.font_name),
                     self.font_size)
             except ImportError:
                 _pil_ttf_support = False
                 log_system.warn("Couldn't load TrueType fonts, "
                     "PIL needs to be build with freetype support.")
             except IOError:
                 _pil_ttf_support = False
                 log_system.warn("Couldn't load find TrueType font ", self.font_name)
         if self._font is None:
             self._font = ImageFont.load_default()
     return self._font
Exemplo n.º 11
0
 def test_transparent(self):
     font = ImageFont.load_default()
     td = TextDraw('Hello\nWorld', font, placement='cc')
     img = Image.new('RGBA', (100, 100), (0, 0, 0, 0))
     draw = ImageDraw.Draw(img)
     td.draw(draw, img.size)
     eq_(len(img.getcolors()), 2)
     # top color (bg) is transparent
     eq_(sorted(img.getcolors())[1][1], (0, 0, 0, 0))
Exemplo n.º 12
0
 def test_transparent(self):
     font = ImageFont.load_default()
     td = TextDraw('Hello\nWorld', font, placement='cc')
     img = Image.new('RGBA', (100, 100), (0, 0, 0, 0))
     draw = ImageDraw.Draw(img)
     td.draw(draw, img.size)
     eq_(len(img.getcolors()), 2)
     # top color (bg) is transparent
     eq_(sorted(img.getcolors())[1][1], (0, 0, 0, 0))
Exemplo n.º 13
0
 def test_unicode(self):
     font = ImageFont.load_default()
     td = TextDraw(u'Héllö\nWørld', font, placement='cc')
     img = Image.new('RGB', (100, 100))
     draw = ImageDraw.Draw(img)
     total_box, boxes = td.text_boxes(draw, (100, 100))
     if PY3:
         raise SkipTest('unicode handling for default font differs on PY3')
     eq_(total_box, (35, 38, 65, 63))
     eq_(boxes, [(35, 38, 65, 49), (35, 52, 65, 63)])
Exemplo n.º 14
0
 def test_unicode(self):
     font = ImageFont.load_default()
     td = TextDraw(u'Héllö\nWørld', font, placement='cc')
     img = Image.new('RGB', (100, 100))
     draw = ImageDraw.Draw(img)
     total_box, boxes = td.text_boxes(draw, (100, 100))
     if PY3:
         raise SkipTest('unicode handling for default font differs on PY3')
     eq_(total_box, (35, 38, 65, 63))
     eq_(boxes, [(35, 38, 65, 49), (35, 52, 65, 63)])
Exemplo n.º 15
0
 def font(self):
     global _pil_ttf_support
     if self._font is None:
         if self.font_name != 'default' and _pil_ttf_support:
             try:
                 self._font = ImageFont.truetype(font_file(self.font_name),
                                                 self.font_size)
             except ImportError:
                 _pil_ttf_support = False
                 log_system.warn(
                     "Couldn't load TrueType fonts, "
                     "PIL needs to be build with freetype support.")
             except IOError:
                 _pil_ttf_support = False
                 log_system.warn("Couldn't load find TrueType font ",
                                 self.font_name)
         if self._font is None:
             self._font = ImageFont.load_default()
     return self._font
Exemplo n.º 16
0
 def check_placement(self, x, y):
     font = ImageFont.load_default()
     td = TextDraw('Hello\nWorld\n%s %s' % (x, y),
                   font,
                   placement=x + y,
                   padding=5,
                   linespacing=2)
     img = Image.new('RGB', (100, 100))
     draw = ImageDraw.Draw(img)
     td.draw(draw, img.size)
     img.show()