Exemplo n.º 1
0
def changing_text_height_absolute(msp, location):
    attribs = dict(ATTRIBS)
    attribs["width"] = 40.0  # need mor space to avoid text wrapping
    editor = MTextEditor(
        "changing text height absolute: default height is 0.7" + NP)
    # doubling the default height = 1.4
    editor.height(1.4)
    editor.append("text height: 1.4" + NP)
    editor.height(3.5).append("text height: 3.5" + NP)
    editor.height(0.7).append("back to default height: 0.7" + NP)
    msp.add_mtext(str(editor), attribs).set_location(insert=location)
Exemplo n.º 2
0
def changing_text_height_absolute(msp, location):
    attribs = dict(ATTRIBS)
    attribs["width"] = 40.0  # need mor space to avoid text wrapping
    editor = MTextEditor(
        "changing text height absolute: default height is 0.7" + NP)
    # this is the default text height in the beginning:
    # The text height can only be changed by a factor:
    editor.height(1.4)  # scale by 2 = 1.4
    editor.append("text height: 1.4" + NP)
    editor.height(3.5).append("text height: 3.5" + NP)
    editor.height(0.7).append("back to default height: 0.7" + NP)
    msp.add_mtext(str(editor), attribs).set_location(insert=location)
Exemplo n.º 3
0
def using_colors(msp, location):
    attribs = dict(ATTRIBS)
    attribs["width"] = 10.0
    editor = MTextEditor("using colors:" + NP)
    # Change colors by name: red, green, blue, yellow, cyan, magenta, white
    editor.color("red").append("RED" + NP)
    # The color stays the same until changed
    editor.append("also RED" + NP)
    # Change color by ACI (AutoCAD Color Index)
    editor.aci(3).append("GREEN" + NP)
    # Change color by RGB tuples
    editor.rgb((0, 0, 255)).append("BLUE" + NP)
    msp.add_mtext(str(editor), attribs).set_location(insert=location)
Exemplo n.º 4
0
def test_change_color_name():
    m = MTextEditor()
    m.color("red")
    assert str(m) == r"\C1;"
    m.clear()
    m.aci(0)
    assert str(m) == r"\C0;"
Exemplo n.º 5
0
def test_bullet_lists():
    result = MTextEditor().bullet_list(
        indent=4,  # left indentation of the list items
        bullets=["-", "+"],  # bullets - mark in front of the list item
        content=["first", "second"],  # list items
    )
    assert str(result) == r"{\pxi-3,l4,t4;-^Ifirst\P+^Isecond\P}"
Exemplo n.º 6
0
def recreate_mtext_py_example(msp, location):
    # replicate example "mtext.py":
    attribs = dict(ATTRIBS)
    attribs["width"] = 15.0
    editor = MTextEditor(f"recreate mtext.py result:{NP}normal ").overline(
        "over line").append(" normal" + NP + "normal ").strike_through(
        "strike through").append(" normal" + NP).underline(
        "under line").append(" normal")
    msp.add_mtext(str(editor), attribs).set_location(insert=location)
Exemplo n.º 7
0
def numbered_list(msp, location):
    attribs = dict(ATTRIBS)
    attribs["char_height"] = 0.25
    attribs["width"] = 7.5
    # There are no special commands to build numbered list, the list is build of
    # indentation and a tabulator stop. There is no automatic numbering,
    # but therefore the absolute freedom for using any string as list marker:
    editor = MTextEditor("Numbered List:" + NP)
    editor.bullet_list(indent=1,
                       bullets=["1.", "2.", "3."],
                       content=[
                           "First item",
                           "Second item",
                           " ".join(lorem_ipsum(30)),
                       ])
    # Indentation and tab stops are multiples of the default text height (MTEXT
    # char_height)!
    msp.add_mtext(str(editor), attribs).set_location(insert=location)
Exemplo n.º 8
0
def bullet_list(msp, location):
    attribs = dict(ATTRIBS)
    attribs["char_height"] = 0.25
    attribs["width"] = 7.5
    # There are no special commands to build bullet list, the list is build of
    # indentation and a tabulator stop. Each list item needs a marker as an
    # arbitrary string.
    bullet = "•"  # alt + numpad 7
    editor = MTextEditor("Bullet List:" + NP)
    editor.bullet_list(
        indent=1,
        bullets=[bullet] * 3,  # each list item needs a marker
        content=[
            "First item",
            "Second item",
            " ".join(lorem_ipsum(30)),
        ])
    msp.add_mtext(str(editor), attribs).set_location(insert=location)
Exemplo n.º 9
0
def changing_text_height_relative(msp, location):
    attribs = dict(ATTRIBS)
    attribs["width"] = 40.0  # need mor space to avoid text wrapping
    editor = MTextEditor(
        "changing text height relative: default height is 0.7" + NP)
    # this is the default text height in the beginning:
    current_height = attribs["char_height"]
    # The text height can only be changed by a factor:
    editor.scale_height(2)  # scale by 2 = 1.4
    # keep track of the actual height:
    current_height *= 2
    editor.append("text height: 1.4" + NP)
    # to set an absolute height, calculate the required factor:
    desired_height = 3.5
    factor = desired_height / current_height
    editor.scale_height(factor).append("text height: 3.5" + NP)
    current_height = desired_height
    # and back to 0.7
    editor.scale_height(
        0.7 / current_height).append("back to default height: 0.7" + NP)
    msp.add_mtext(str(editor), attribs).set_location(insert=location)
Exemplo n.º 10
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)
Exemplo n.º 11
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)
Exemplo n.º 12
0
def test_change_font():
    m = MTextEditor()
    m.font("Arial", bold=False, italic=False)
    assert str(m) == r"\fArial|b0|i0;"
Exemplo n.º 13
0
def test_change_to_blue_by_rgb():
    m = MTextEditor().rgb((0, 0, 255))
    assert str(m) == r"\c16711680;"
Exemplo n.º 14
0
def test_append_text():
    m = MTextEditor()
    m.append("TEXT")
    assert str(m) == "TEXT"
Exemplo n.º 15
0
def test_change_to_green_by_rgb():
    m = MTextEditor().rgb((0, 255, 0))
    assert str(m) == r"\c65280;"
Exemplo n.º 16
0
def test_change_to_red_by_rgb():
    m = MTextEditor().rgb((255, 0, 0))
    assert str(m) == r"\c255;"
Exemplo n.º 17
0
def test_aci_color_raises_value_error(aci):
    with pytest.raises(ValueError):
        MTextEditor().aci(aci)
Exemplo n.º 18
0
def test_change_aci_color():
    m = MTextEditor()
    m.aci(0).aci(256)
    assert str(m) == r"\C0;\C256;"
Exemplo n.º 19
0
def test_underline_text():
    assert str(MTextEditor().underline("TEXT")) == r"\LTEXT\l"
Exemplo n.º 20
0
def test_invalid_divider_char_raises_value_error():
    m = MTextEditor()
    pytest.raises(ValueError, m.stack, "1", "2", "x")
Exemplo n.º 21
0
def test_stacked_text_with_slanted_divider_line():
    m = MTextEditor().stack("1", "2", "#")
    assert str(m) == r"\S1#2;"  # no space after "#" required
Exemplo n.º 22
0
def test_change_width_factor():
    assert str(MTextEditor().width_factor(2)) == r"\W2;"
    assert str(MTextEditor().width_factor(1.6666)) == r"\W1.667;"
Exemplo n.º 23
0
def test_scale_height_factor():
    assert str(MTextEditor().scale_height(2)) == r"\H2x;"
    assert str(MTextEditor().scale_height(1.6666)) == r"\H1.667x;"
Exemplo n.º 24
0
def test_iadd_text():
    m = MTextEditor()
    m += "TEXT"
    assert str(m) == "TEXT"
Exemplo n.º 25
0
def test_strike_through_text():
    assert str(MTextEditor().strike_through("TEXT")) == r"\KTEXT\k"
Exemplo n.º 26
0
def test_overline_text():
    assert str(MTextEditor().overline("TEXT")) == r"\OTEXT\o"
Exemplo n.º 27
0
def test_absolute_text_height():
    assert str(MTextEditor().height(2)) == r"\H2;"
    assert str(MTextEditor().height(1.6666)) == r"\H1.667;"
Exemplo n.º 28
0
def test_stacked_text_limits_style():
    m = MTextEditor().stack("1", "2")
    assert str(m) == r"\S1^ 2;"
Exemplo n.º 29
0
def test_change_char_tracking_factor():
    assert str(MTextEditor().char_tracking_factor(2)) == r"\T2;"
    assert str(MTextEditor().char_tracking_factor(1.6666)) == r"\T1.667;"
Exemplo n.º 30
0
def test_stacked_text_with_horizontal_divider_line():
    m = MTextEditor().stack("1", "2", "/")
    assert str(m) == r"\S1/2;"  # no space after "/" required