コード例 #1
0
 def test_different_kinds_of_tab_stops(self):
     # tab stops without prefix or numbers are left adjusted
     # tab stops, e.g 2 or '2'
     # prefix 'c' defines a center adjusted tab stop e.g. 'c3.5'
     # prefix 'r' defines a right adjusted tab stop e.g. 'r2.7'
     p = ParagraphProperties(tab_stops=(1, "c2", "r3.7"))
     assert p.tostring() == "\\pxt1,c2,r3.7;"
コード例 #2
0
 def test_reset_arguments(self):
     t0, t1 = list(
         MTextParser(r"\pi1,l2,r3,qc,t1,2,3;word\pi*,l*,r*,q*,t;word"))
     assert t0.ctx.paragraph == (
         1,
         2,
         3,
         MTextParagraphAlignment.CENTER,
         (1, 2, 3),
     )
     assert t1.ctx.paragraph == ParagraphProperties()  # reset to default
コード例 #3
0
def indent_first_line(msp, location):
    # Indentation is a multiple of the default text height (MTEXT char_height)
    attribs = dict(ATTRIBS)
    attribs["char_height"] = 0.25
    attribs["width"] = 7.5
    editor = MTextEditor("Indent the first line:" + NP)
    props = ParagraphProperties(
        indent=1,  # indent first line = 1x0.25 drawing units
        align=MTextParagraphAlignment.JUSTIFIED)
    editor.paragraph(props)
    editor.append(" ".join(lorem_ipsum(100)))
    msp.add_mtext(str(editor), attribs).set_location(insert=location)
コード例 #4
0
 def make_mtext_context(self, mtext: MText) -> MTextContext:
     ctx = MTextContext()
     ctx.paragraph = ParagraphProperties(
         align=ATTACHMENT_POINT_TO_ALIGN.get(  # type: ignore
             mtext.dxf.attachment_point, tl.ParagraphAlignment.LEFT
         )
     )
     ctx.font_face = self.get_font_face(mtext)
     ctx.cap_height = mtext.dxf.char_height
     ctx.aci = mtext.dxf.color
     rgb = mtext.rgb
     if rgb is not None:
         ctx.rgb = rgb
     return ctx
コード例 #5
0
def indent_except_fist_line(msp, location):
    # Indentation is a multiple of the default text height (MTEXT char_height)
    attribs = dict(ATTRIBS)
    attribs["char_height"] = 0.25
    attribs["width"] = 7.5
    editor = MTextEditor("Indent left paragraph side:" + NP)
    indent = 0.7  # 0.7 * 0.25 = 0.175 drawing units
    props = ParagraphProperties(
        # first line indentation is relative to "left", this reverses the
        # left indentation:
        indent=-indent,  # first line
        # indent left paragraph side:
        left=indent,
        align=MTextParagraphAlignment.JUSTIFIED)
    editor.paragraph(props)
    editor.append(" ".join(lorem_ipsum(100)))
    msp.add_mtext(str(editor), attribs).set_location(insert=location)
コード例 #6
0
 def test_justified_alignment_and_multiple_tab_stops(self):
     p = ParagraphProperties(align=MTextParagraphAlignment.JUSTIFIED,
                             tab_stops=(1, 2, 3))
     assert p.tostring() == "\\pxqj,t1,2,3;"
コード例 #7
0
 def test_indention_and_multiple_tab_stops(self):
     p = ParagraphProperties(indent=1, tab_stops=(1, 2, 3))
     # always a "," after indentations
     assert p.tostring() == "\\pxi1,t1,2,3;"
コード例 #8
0
 def test_multiple_tab_stops(self):
     p = ParagraphProperties(tab_stops=(1, 2, 3))
     assert p.tostring() == "\\pxt1,2,3;"
コード例 #9
0
 def test_one_tab_stop(self):
     p = ParagraphProperties(tab_stops=(1, ))
     assert p.tostring() == "\\pxt1;"
コード例 #10
0
 def test_center_alignment_with_indentation(self):
     # always a "," after indentations
     assert (ParagraphProperties(
         indent=2.5,
         align=MTextParagraphAlignment.CENTER).tostring() == "\\pxi2.5,qc;")
コード例 #11
0
 def test_center_alignment_without_indentation(self):
     assert (ParagraphProperties(
         align=MTextParagraphAlignment.CENTER).tostring() == "\\pxqc;")
コード例 #12
0
 def test_indent_paragraph_right(self):
     assert ParagraphProperties(right=4).tostring() == "\\pxr4;"
コード例 #13
0
 def test_indent_paragraph_left(self):
     assert ParagraphProperties(left=3).tostring() == "\\pxl3;"
コード例 #14
0
 def test_indent_first_line(self):
     assert ParagraphProperties(indent=2).tostring() == "\\pxi2;"
コード例 #15
0
 def test_default_properties(self):
     assert ParagraphProperties().tostring() == ""