File: test_254_get_font_name.py

package info (click to toggle)
ezdxf 1.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 104,528 kB
  • sloc: python: 182,341; makefile: 116; lisp: 20; ansic: 4
file content (38 lines) | stat: -rw-r--r-- 1,001 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#  Copyright (c) 2021, Manfred Moitzi
#  License: MIT License

import pytest
import ezdxf
from ezdxf.entities import get_font_name, DXFEntity
from ezdxf.lldxf import const


@pytest.fixture(scope="module")
def msp():
    doc = ezdxf.new()
    doc.styles.add("ARIAL", font="arial.ttf")
    return doc.modelspace()


def test_get_font_name_for_entity_without_font_support():
    e = DXFEntity()
    assert get_font_name(e) == const.DEFAULT_TEXT_FONT, "should return the default font"


def test_get_font_name_for_text(msp):
    text = msp.add_text("abc", dxfattribs={"style": "ARIAL"})
    assert get_font_name(text) == "arial.ttf"


def test_undefined_text_style(msp):
    text = msp.add_text("abc", dxfattribs={"style": "UNDEFINED"})
    assert get_font_name(text) == const.DEFAULT_TEXT_FONT


def test_get_font_name_for_mtext(msp):
    mtext = msp.add_mtext("abc", dxfattribs={"style": "ARIAL"})
    assert get_font_name(mtext) == "arial.ttf"


if __name__ == "__main__":
    pytest.main([__file__])