예제 #1
0
def test_001_empty():
    "Test for empty EMF, with only header and EOF"

    emf = EMF(*_size)
    data = emf.data()

    assert isinstance(data, type(b""))
    assert len(data) == _header_bytes + _EOF_bytes
예제 #2
0
def test_use_font():

    emf = EMF(*_size)

    with emf.use_font(Size("10pt", _dpi)) as font:
        assert font == 1
    data = emf.data()

    assert isinstance(data, type(b""))
    assert len(data) == _header_bytes + _EOF_bytes + _use_font_bytes
예제 #3
0
def test_use_pen():

    emf = EMF(*_size)

    with emf.use_pen("solid", Size("1pt", _dpi), 0) as pen:
        assert pen == 1
    data = emf.data()

    assert isinstance(data, type(b""))
    assert len(data) == _header_bytes + _EOF_bytes + _use_pen_bytes
예제 #4
0
def test_text_color():

    for color in [0, 0xffffff, 0xff00ff]:
        emf = EMF(*_size)

        emf.text_color(color)

        data = emf.data()
        assert isinstance(data, type(b""))
        assert len(data) == _header_bytes + _EOF_bytes + _text_color_bytes
예제 #5
0
def test_rectangle():

    emf = EMF(*_size)

    # it needs a pen
    with emf.use_pen("solid", Size("1pt", _dpi), 0):
        emf.rectangle(Size("0pt", _dpi), Size("0pt", _dpi),
                      Size("1000pt", _dpi), Size("1000pt", _dpi))

    data = emf.data()
    assert isinstance(data, type(b""))
    assert len(data) == _header_bytes + _EOF_bytes + _use_pen_bytes + \
        _rect_bytes
예제 #6
0
def test_text():

    emf = EMF(*_size)

    # it needs a font
    with emf.use_font(Size("16pt", _dpi)):
        text = "abcd"
        emf.text(Size("0pt", _dpi), Size("0pt", _dpi), text)

    data = emf.data()
    assert isinstance(data, type(b""))
    assert len(data) == _header_bytes + _EOF_bytes + _use_font_bytes + \
        _text_bytes(text)
예제 #7
0
def test_text_align():

    for align in "lrc":
        emf = EMF(*_size)

        emf.text_align(align)

        data = emf.data()
        assert isinstance(data, type(b""))
        assert len(data) == _header_bytes + _EOF_bytes + _text_align_bytes

    emf = EMF(*_size)
    with pytest.raises(TypeError):
        emf.text_align("X")
예제 #8
0
def test_polyline():

    emf = EMF(*_size)

    # it needs a pen
    with emf.use_pen("solid", Size("1pt", _dpi), 0):
        emf.polyline([
            (Size("1in", _dpi), Size("1in", _dpi)),
            (Size("1in", _dpi), Size("2in", _dpi)),
            (Size("2in", _dpi), Size("2in", _dpi)),
            (Size("2in", _dpi), Size("1in", _dpi)),
        ])

    data = emf.data()
    assert isinstance(data, type(b""))
    assert len(data) == _header_bytes + _EOF_bytes + _use_pen_bytes + \
        _polyline_bytes(4)
예제 #9
0
파일: emfgen.py 프로젝트: andy-z/ged2doc
"""Trivial script to debug content of EMF, just in case some poor schmuck
decides to repeat this futile exercise.
"""

from ged2doc.dumbemf import EMF
from ged2doc.size import Size

dpi = 300
width = Size("5in", dpi)
height = Size("2in", dpi)
emf = EMF(width, height)

# emf.text_color(0)

with emf.use_pen("solid", Size("1pt", dpi), 0x000000):
    emf.rectangle(
        Size("1in", dpi),
        Size(".5in", dpi),
        Size("4in", dpi),
        Size("1.5in", dpi),
    )

emf.text_align("c")
fontsize = Size("16pt", dpi)
with emf.use_font(fontsize):
    emf.text(Size("2.5in", dpi), Size("1.25in", dpi), "Test1 Проверка1")

with open("test.emf", "wb") as out:
    out.write(emf.data())