示例#1
0
文件: canvas.py 项目: bzaczynski/ogre
    def text(self,
             text,
             x,
             y,
             width=0,
             height=0,
             halign=HAlign.LEFT,
             valign=VAlign.TOP,
             word_wrap=False):
        """Draw multi-line text at (x, y) in millimeters and return new x."""

        assert isinstance(halign, HAlign)
        assert isinstance(valign, VAlign)
        assert halign == HAlign.LEFT or width > 0, 'width must be specified'
        assert valign == VAlign.TOP or height > 0, 'height must be specified'
        assert not (width <= 0 and word_wrap), 'width must be specified'

        text_lines = self._wrap(text, width) if word_wrap else text.split('\n')

        text_height_pts = self.font.size_pts * len(text_lines) + \
                          self.font.interline_pts * (len(text_lines) - 1)

        x_pts = normalize(x)
        y_pts = normalize(self.height - y) - self.font.ascent_pts

        if height:
            y_pts -= valign.offset(text_height_pts, normalize(height))

        obj = self._viewport.beginText(x_pts, y_pts)
        obj.setFont(self.font.name, self.font.size_pts, self.font.leading_pts)
        obj.setTextRenderMode(self.font.render_mode.value)
        obj.setCharSpace(self.font.char_space_pts)
        obj.setWordSpace(self.font.word_space_pts)
        obj.setRise(self.font.rise_pts)

        cursor_x = x_pts + self._get_text_width_pts(text_lines)
        for line in text_lines:
            if width:
                text_width_pts = self._get_text_width_pts(line)
                offset_pts = halign.offset(text_width_pts, normalize(width))
                x_pts = normalize(x) + offset_pts
                cursor_x = max(cursor_x, x_pts + text_width_pts)
                obj.setTextOrigin(x_pts, obj.getY())
            obj.textLine(line)

        self._viewport.drawText(obj)

        return denormalize(cursor_x)
示例#2
0
 def test_should_convert_points_to_millimeters(self):
     self.assertAlmostEqual(25.4, denormalize(72.0))
示例#3
0
文件: canvas.py 项目: bzaczynski/ogre
 def height(self):
     """Return height of document page in millimeters."""
     return denormalize(self._height)
示例#4
0
文件: canvas.py 项目: bzaczynski/ogre
 def width(self):
     """Return width of document page in millimeters."""
     return denormalize(self._width)
示例#5
0
文件: canvas.py 项目: bzaczynski/ogre
 def get_text_width_mm(self, text):
     """Return the width of text in mm determined by the font."""
     return denormalize(self._get_text_width_pts(text))
示例#6
0
 def miter_limit(self):
     """Return miter limit in millimeters."""
     return denormalize(self._miter_limit)
示例#7
0
文件: font.py 项目: bzaczynski/ogre
 def interline_mm(self):
     """Return interline height in millimeters."""
     return denormalize(self.interline_pts)
示例#8
0
 def line_width(self):
     """Return line width in millimeters."""
     return denormalize(self._line_width)
示例#9
0
文件: font.py 项目: bzaczynski/ogre
 def leading_mm(self):
     """Return text line spacing in millimeters."""
     return denormalize(self.leading_pts)
示例#10
0
文件: font.py 项目: bzaczynski/ogre
 def word_space_mm(self):
     """Return word spacing in millimeters."""
     return denormalize(self.word_space_pts)
示例#11
0
文件: font.py 项目: bzaczynski/ogre
 def char_space_mm(self):
     """Return character spacing in millimeters."""
     return denormalize(self.char_space_pts)
示例#12
0
文件: font.py 项目: bzaczynski/ogre
 def rise_mm(self):
     """Return font rise in millimeters."""
     return denormalize(self.rise_pts)
示例#13
0
文件: font.py 项目: bzaczynski/ogre
 def size_mm(self):
     """Return font size in millimeters."""
     return denormalize(self.size_pts)