Example #1
0
    def mtext(text, insert, linespacing=1.5, **kwargs):
        """ Create a multi-line text buildup **MText** with simple :ref:`TEXT`
        entities.

        Mostly the same kwargs like :ref:`TEXT`.

        .. caution::
           **alignpoint** is always the insert point, I don't need a
           second alignpoint because horizontal alignment FIT, ALIGN,
           BASELINE_MIDDLE is not supported.

        :param str text: the text to display
        :param insert: insert point (xy- or xyz-tuple), z-axis is 0 by default
        :param float linespacing: linespacing in percent of height, 1.5 = 150% =
            1+1/2 lines
        :param float height: text height in drawing-units
        :param float rotation: text rotion in dregree, default=0
        :param float xscale: text width factor, default=1
        :param float oblique: text oblique angle in degree, default=0
        :param str style: text style name, default=STANDARD
        :param int mirror: text generation flags, bit-coded, default=0
        :param int halign: horizontal justification type
        :param int valign: vertical justification type
        :param str layer: layer name
        :param int color: range [1..255], 0 = **BYBLOCK**, 256 = **BYLAYER**

        any combination of **valign** (TOP, MIDDLE, BOTTOM) and **halign** (LEFT,
        CENTER, RIGHT) is valid.

        """
        return MText(text, insert, linespacing, **kwargs)
Example #2
0
    def test_45deg_top(self):
        text = "lineA\nlineB\nlineC"
        valign = dxfwrite.TOP
        rotation = 45.
        mtext = MText(text, (0., 0., 0.), 1.0, rotation=rotation)
        line1 = self.expected_line_rot.substitute(text='lineA',
                                                  px='0.0',
                                                  py='0.0',
                                                  pz='0.0',
                                                  valign=str(valign),
                                                  rot=str(rotation))
        line2 = self.expected_line_rot.substitute(text='lineB',
                                                  px='0.707107',
                                                  py='-0.707107',
                                                  pz='0.0',
                                                  valign=str(valign),
                                                  rot=str(rotation))
        line3 = self.expected_line_rot.substitute(text='lineC',
                                                  px='1.414214',
                                                  py='-1.414214',
                                                  pz='0.0',
                                                  valign=str(valign),
                                                  rot=str(rotation))

        self.assertEqual(dxfstr(mtext), line1 + line2 + line3)
Example #3
0
    def get_dxf_entity(self, coords, layer):
        """ Create the cell content as MText-object.

        :param coords: tuple of border-coordinates : left, right, top, bottom
        :param layer: layer, which should be used for dxf entities
        """
        if not len(self.text):
            return DXFList()
        left, right, top, bottom = self.get_workspace_coords(coords)
        style = self.style
        halign = style['halign']
        valign = style['valign']
        rotated = self.style['rotation']
        text = self.text
        if style['stacked']:
            rotated = 0.
            text = '\n'.join((char for char in self.text.replace('\n', ' ')))
        xpos = (left, float(left + right) / 2., right)[halign]
        ypos = (bottom, float(bottom + top) / 2., top)[valign - 1]
        return MText(text, (xpos, ypos),
                     linespacing=self.style['linespacing'],
                     style=self.style['textstyle'],
                     height=self.style['textheight'],
                     rotation=rotated,
                     xscale=self.style['xscale'],
                     halign=halign,
                     valign=valign,
                     color=self.style['textcolor'],
                     layer=layer)
Example #4
0
    def test_one_liner(self):
        text = "OneLine"
        valign = dxfwrite.TOP

        mtext = MText(text, (0., 0., 0.))
        expected = self.expected_line.substitute(text=text,
                                                 px='0.0',
                                                 py='0.0',
                                                 pz='0.0',
                                                 valign=str(valign))
        self.assertEqual(dxfstr(mtext), expected)
Example #5
0
 def test_horiz_middle(self):
     text = "lineA\nlineB"
     valign = dxfwrite.MIDDLE
     mtext = MText(text, (0., 0., 0.), 1.0, valign=valign)
     line1 = self.expected_line.substitute(text='lineA',
                                           px='0.0',
                                           py='0.5',
                                           pz='0.0',
                                           valign=str(valign))
     line2 = self.expected_line.substitute(text='lineB',
                                           px='0.0',
                                           py='-0.5',
                                           pz='0.0',
                                           valign=str(valign))
     self.assertEqual(dxfstr(mtext), line1 + line2)
Example #6
0
 def test_baseline(self):
     mtext = MText("lineA\nlineB", (0., 0., 0.),
                   1.0,
                   valign=dxfwrite.BASELINE)
     self.assertEqual(mtext.valign, dxfwrite.BOTTOM)
Example #7
0
 def test_set_attribute_by_subscript(self):
     mtext = MText("Test\nTest", (0, 0))
     mtext['layer'] = "modified"
     self.assertEqual(mtext.layer, "modified")
Example #8
0
 def test_get_attribute_by_subscript(self):
     mtext = MText("Test\nTest", (0, 0))
     layer = mtext['layer']
     self.assertEqual(layer, mtext.layer)