Exemplo n.º 1
0
    assert round(ttf.capHeight, 0) == 928, "Chech capHeight"
    assert ttf.flags == 4, "Check flags"
    assert [round(i, 0) for i in ttf.bbox] == [-918, -415, 1513, 1167], "Check bbox"
    assert ttf.italicAngle == 0, "Check italicAngle==0"
    assert ttf.stemV == 87, "Check stemV"
    assert round(ttf.defaultWidth, 0) == 540, "Check defaultWidth"
    assert round(ttf.underlinePosition, 0) == -63, "Check underlinePosition"
    assert round(ttf.underlineThickness, 0) == 44, "Check underlineThickness"
    # test char widths (against binary file generated by tfpdf.php):
    # note: after fixing issue 82 this raw data started to be wrong
    #  1. total length - 65536, DejaVuSansCondensed.ttf maximal char is 65533, round to nearest 1024 size
    #  2. missing char width should be 540 instead of zero
    with open(os.path.join(common.basepath, "dejavusanscondensed.cw.dat"),\
            "rb") as file:
        data = file.read()
    char_widths = struct.unpack(">%dH" % (len(data) // 2), data)
    assert len(char_widths) == 65536, "Check cw.dat char_widths 65536"
    assert len(ttf.charWidths) == 65536, "Check ttf char_widths 65536"
    diff = []
    for i, (x, y) in enumerate(zip(char_widths, ttf.charWidths)):
        if x == 0 and y == ttf.defaultWidth: continue
        if x != y:# compare each char width, but not 0
            diff.append(i)
    assert not diff, "Check char widths"
    # for checking assertion works ttf.charWidths[1] = 600
    ## assert tuple(ttf.charWidths) == tuple(char_widths)
    
if __name__ == "__main__":
    common.testmain(__file__, dotest)

Exemplo n.º 2
0
import common
from fpdf import FPDF

import os, struct


@common.add_unittest
def dotest(outputname, nostamp):
    try:
        # Portrait, millimeter units, A4 page size
        pdf = FPDF("P", "mm", "A4")
        # Set font: Times, normal, size 10
        pdf.set_font('Times', '', 12)
        ##pdf.add_page()
        # Layout cell: 0 x 5 mm, text, no border, Left
        pdf.cell(0, 5, 'Input 1 : ', border=0, align="L")
        pdf.cell(0, 5, 'Input 2 : ', border=0, align="L")
        pdf.cell(0, 5, 'Recomendation : ', border=0, align="L")
        pdf.cell(0, 5, 'Data 1 :', border=0, align="L")
        pdf.cell(0, 5, 'Data 2 :', border=0, align="L")
        pdf.output(outputname, 'F')
    except RuntimeError as e:
        assert e.args[
            0] == "FPDF error: No page open, you need to call add_page() first"
    else:
        raise RuntimeError("Exception not raised!")


if __name__ == "__main__":
    common.testmain(__file__, dotest)
Exemplo n.º 3
0
def main():
    return common.testmain(__file__, dotest)
Exemplo n.º 4
0
def main():
    return common.testmain(__file__, dotest)