def test_get_pos_handles_missing_align_point(): """Any text alignment except LEFT requires and uses the align_point attribute as text location point. But there are real world example from AutoCAD which do not provide the align_point even it is required. In this case the get_pos() method returns the insert attribute. """ text = Text() text.dxf.halign = 1 # center text.dxf.valign = 1 # bottom text.dxf.insert = (1, 2) text.dxf.align_point = (3, 4) # the real alignment point # the expected and correct align point: alignment, p1, p2 = text.get_placement() assert p1 == (3, 4) assert p2 is None # only used for FIT and ALIGNED # remove the align point del text.dxf.align_point alignment, p1, p2 = text.get_placement() assert p1 == (1, 2) # use the insert point instead assert p2 is None # only used for FIT and ALIGNED
def text2(): return Text.new(dxfattribs={ 'text': 'TEXT', 'height': 1.0, 'width': 1.0, 'rotation': 0, 'layer': 'text', }).set_pos((0, 0, 0), align='LEFT')
def test_do_not_write_line_endings(): txt = Text() txt.dxf.text = 'test\ntext\r' collector = TagCollector(optional=True) txt.export_dxf(collector) for tag in collector.tags: if tag[0] == 1: assert tag[1] == 'testtext'
def text2(): return Text.new( dxfattribs={ "text": "TEXT", "height": 1.0, "width": 1.0, "rotation": 0, "layer": "text", }).set_placement((0, 0, 0), align=TextEntityAlignment.LEFT)
def test_plain_text(): assert plain_text('%%d') == '°' # underline assert plain_text('%%u') == '' assert plain_text('%%utext%%u') == 'text' # single % assert plain_text('%u%d%') == '%u%d%' t = Text.new(dxfattribs={'text': '45%%d'}) assert t.plain_text() == '45°'
def test_text_to_code(): from ezdxf.entities.text import Text entity = Text.new(handle='ABBA', owner='0', dxfattribs={ 'color': '7', 'text': 'xyz', 'insert': (2, 3, 4), }) new_entity = translate_to_code_and_execute(entity) for name in ('color', 'text', 'insert'): assert new_entity.get_dxf_attrib(name) == entity.get_dxf_attrib(name)
def test_malformed_text(): line = Text.from_text(MALFORMED_TEXT) assert line.dxf.layer == "LY_EZDXF" assert line.dxf.linetype == "LT_EZDXF" assert line.dxf.style == "STY_EZDXF" assert line.dxf.color == 7 assert line.dxf.text == "TEXTCONTENT" assert line.dxf.insert.isclose((1, 2, 3)) assert line.dxf.align_point.isclose((3, 4, 5)) assert line.dxf.halign == 3 assert line.dxf.valign == 1
def test_transform_interface(): text = Text() text.dxf.insert = (1, 0, 0) text.transform(Matrix44.translate(1, 2, 3)) assert text.dxf.insert == (2, 2, 3) # optimized translate text.dxf.align_point = (3, 2, 1) text.translate(1, 2, 3) assert text.dxf.insert == (3, 4, 6) assert text.dxf.align_point == (4, 4, 4)
def test_text_to_code(): from ezdxf.entities.text import Text entity = Text.new( handle="ABBA", owner="0", dxfattribs={ "color": "7", "text": "xyz", "insert": (2, 3, 4), }, ) new_entity = translate_to_code_and_execute(entity) for name in ("color", "text", "insert"): assert new_entity.get_dxf_attrib(name) == entity.get_dxf_attrib(name)
def text(): return Text.new(handle="ABBA", owner="0")
def test_removing_invalid_chars_at_setting_content(invalid_text): txt = Text() txt.dxf.text = invalid_text assert txt.dxf.text == "testtext"
def text(): return Text.new(handle='ABBA', owner='0')