Exemplo n.º 1
0
def test_main(argv=None):
    profile = jagpdf.create_profile()
    profile.set("doc.topdown", "1")
    #profile.set("doc.compressed", "0")
    doc = testlib.create_test_doc(argv, 'compressed_pattern.pdf', profile)
    img = doc.image_load_file(image_path('logo.png'))

    p = doc.canvas_create()
    p.image(img, 0, 0)
    pattern = doc.tiling_pattern_load("step=109, 32", p)

    
    doc.page_start(8.3 * 72.0, 11.7 * 72.0)
    canvas = doc.page().canvas()
    canvas.color_space_pattern('f')
    canvas.pattern('f', pattern)
    canvas.rectangle(0, 0, 200, 200)
    canvas.rectangle(200, 200, 200, 200)
    canvas.path_paint('f')
    doc.page_end()

    doc.page_start(400, 400)
    canvas = doc.page().canvas()
    canvas.color_space_pattern('f')
    canvas.pattern('f', pattern)
    canvas.rectangle(0, 0, 200, 200)
    canvas.path_paint('f')
    doc.page_end()

    doc.finalize()
Exemplo n.º 2
0
def test_main(argv=None):
    profile = jagpdf.create_profile()
    profile.set("doc.topdown", "1")
    #profile.set("doc.compressed", "0")
    doc = testlib.create_test_doc(argv, 'compressed_pattern.pdf', profile)
    img = doc.image_load_file(image_path('logo.png'))

    p = doc.canvas_create()
    p.image(img, 0, 0)
    pattern = doc.tiling_pattern_load("step=109, 32", p)

    doc.page_start(8.3 * 72.0, 11.7 * 72.0)
    canvas = doc.page().canvas()
    canvas.color_space_pattern('f')
    canvas.pattern('f', pattern)
    canvas.rectangle(0, 0, 200, 200)
    canvas.rectangle(200, 200, 200, 200)
    canvas.path_paint('f')
    doc.page_end()

    doc.page_start(400, 400)
    canvas = doc.page().canvas()
    canvas.color_space_pattern('f')
    canvas.pattern('f', pattern)
    canvas.rectangle(0, 0, 200, 200)
    canvas.path_paint('f')
    doc.page_end()

    doc.finalize()
Exemplo n.º 3
0
def test_main(argv=None):
    #http://www.lorem-ipsum.info/generator3
    def do_page(font, txt):
        media = 597.6, 848.68
        margin = 20
        rect = margin, margin, media[0]-2*margin, media[1]-2*margin
        doc.page_start(*media)
        canvas = doc.page().canvas()
        canvas.color('s', 0.9)
        canvas.rectangle(*rect)
        canvas.path_paint('s')
        textfmt.format_text(rect, txt, doc, font, align='justify', para_spacing=0.5)
        doc.page_end()
    dejavu = os.path.expandvars('${JAG_TEST_RESOURCES_DIR}/fonts/DejaVuSans.ttf')
    textdir = os.path.expandvars('${JAG_TEST_RESOURCES_DIR}/text/')
    cfg = jagpdf.create_profile()
    cfg.set('doc.compressed', '1')
    doc = testlib.create_test_doc(argv, 'justified.pdf', cfg)
    font_1252 = doc.font_load('file=%s;size=8' % dejavu) # western
    font_1251 = doc.font_load('file=%s;size=8;enc=windows-1251' % dejavu) # cyrillic
    font_1253 = doc.font_load('file=%s;size=8;enc=windows-1253' % dejavu) # greek
    for font, fname, enc in [[font_1252, 'lipsum.txt', 'windows-1252'],
                             [font_1251, 'russian-lipsum.txt', 'windows-1251'],
                             [font_1253, 'greek-lipsum.txt', 'windows-1253']]:
        text_file = os.path.join(textdir, fname)
        do_page(font, unicode(open(text_file).read(), 'utf-8').encode(enc))
    doc.finalize()
Exemplo n.º 4
0
def test_main(argv=None):
    #
    # typemanager with no default font set
    #
    cfg = jagpdf.create_profile()
    cfg.set('fonts.fallback', '')
    doc = jagpdf.create_stream(testlib.NoopStreamOut())
    test_suite_fail(doc, [
        'this-font-does-not-exist', 'FreeType call failed',
        '/this/file/does/not/exist'
    ])
    doc.finalize()
    #
    # typemanager with nonexisting default font
    #
    cfg = jagpdf.create_profile()
    cfg.set('fonts.fallback', 'file=nonexisting-default')
    doc = jagpdf.create_stream(testlib.NoopStreamOut(), cfg)
    default_typeface_failure = 'Default typeface not found'
    test_suite_fail(doc, [(default_typeface_failure, 'nonexisting-default',
                           'this-font-does-not-exist'),
                          (default_typeface_failure, 'nonexisting-default',
                           'FreeType call failed'),
                          (default_typeface_failure, 'nonexisting-default',
                           '/this/file/does/not/exist')])
    doc.finalize()
    #
    #
    #
    default_fonts = [
        ('file=' + dejavu_ttf, 'DejaVu Sans'),
        ('standard;name=Helvetica', 'Helvetica'),
    ]
    if testlib.is_windows():
        default_fonts.append(('name=Arial;enc=windows-1252', 'Arial'))
    for default_font, fullname in default_fonts:
        cfg = jagpdf.create_profile()
        cfg.set('fonts.fallback', default_font)
        doc = jagpdf.create_stream(testlib.NoopStreamOut(), cfg)
        test_suite_ok(doc, fullname)
        doc.finalize()
Exemplo n.º 5
0
def test_main(argv=None):
    cfg = jagpdf.create_profile()
    cfg.set('doc.compressed', '1')
    doc = testlib.create_test_doc(argv, 'text_spiral.pdf', cfg)

    def get_angle(r, d):
        c = (d / 2.0) / r
        return math.pi - (2 * math.acos(c))

    font = doc.font_load('standard;name=Helvetica;size=28')
    media = 500, 500
    center = [c / 2.0 for c in media]
    doc.page_start(*media)
    canvas = doc.page().canvas()
    canvas.text_font(font)
    n = 70
    r = 8
    radius = 180
    scale = 1.0
    color = 0.0
    # cross
    canvas.color('s', 0.9)
    canvas.move_to(0, center[1])
    canvas.line_to(media[0], center[1])
    canvas.move_to(center[0], 0)
    canvas.line_to(center[0], media[1])
    canvas.path_paint('s')
    canvas.color('s', 1.0)
    #text
    txt_file = os.path.expandvars('${JAG_TEST_RESOURCES_DIR}/text/lipsum.txt')
    data = open(txt_file).read()
    di = 0
    for j in range(r):
        for i in range(n):
            canvas.color('f', color)
            canvas.state_save()
            x = center[0] - (font.advance(data[0]) / 2.0)
            y = center[1] + radius
            canvas.translate(x, y)
            canvas.scale(scale, scale)
            canvas.text(0, 0, data[di])
            canvas.state_restore()
            canvas.translate(*center)
            radius -= 0.3
            scale -= 0.0015
            angle = get_angle(radius, scale * font.advance(data[di]))
            canvas.rotate(-angle)
            canvas.translate(-center[0], -center[1])
            color += 0.0015
            di += 1
    doc.page_end()
    doc.finalize()
Exemplo n.º 6
0
def test_main(argv=None):
    tux_svg = os.path.expandvars('${JAG_TEST_RESOURCES_DIR}/images/tux.svg')
    cfg = jagpdf.create_profile()
    cfg.set('doc.compressed', '1')
    doc = testlib.create_test_doc(argv, 'tux.pdf', cfg)
    media = 450, 500
    doc.page_start(*media)
    canvas = doc.page().canvas()
    canvas.translate(50, media[1]-50)
    canvas.scale(1.0, -1.0)
    svg.paint_to_canvas(canvas, tux_svg)
    doc.page_end()
    doc.finalize()
Exemplo n.º 7
0
def test_main(argv=None):
    tux_svg = os.path.expandvars('${JAG_TEST_RESOURCES_DIR}/images/tux.svg')
    cfg = jagpdf.create_profile()
    cfg.set('doc.compressed', '1')
    doc = testlib.create_test_doc(argv, 'tux.pdf', cfg)
    media = 450, 500
    doc.page_start(*media)
    canvas = doc.page().canvas()
    canvas.translate(50, media[1] - 50)
    canvas.scale(1.0, -1.0)
    svg.paint_to_canvas(canvas, tux_svg)
    doc.page_end()
    doc.finalize()
Exemplo n.º 8
0
def test_main(argv=None):
    cfg = jagpdf.create_profile()
    cfg.set("doc.compressed", "1")
    doc = testlib.create_test_doc(argv, 'transparent_cubes.pdf', cfg)
    img = doc.image_load_file(os.path.join(g_png_dir, 'cubes_transparent.png'))
    doc.page_start(*media)
    canvas = doc.page().canvas()
    canvas.color_space_pattern('f')
    canvas.pattern('f', get_pattern(doc))
    canvas.rectangle(0, 0, *media)
    canvas.path_paint('f')
    canvas.image(img, *image_pos(img))
    doc.page_end()
    doc.finalize()
Exemplo n.º 9
0
def test_main(argv=None):
    doc = jagpdf.create_stream(testlib.NoopStreamOut(),
                                    jagpdf.create_profile())
    doc.page_start(5.9*72, 3.5*72)
    writer = doc.page().canvas()
    # the following operations must fail as they require path construction
    # to be already started
    testlib.must_throw(writer.bezier_to, 1, 2, 3, 4, 5, 6)
    testlib.must_throw(writer.bezier_to_1st_ctrlpt, 0, 0, 0, 0)
    testlib.must_throw(writer.bezier_to_2nd_ctrlpt, 0, 0, 0, 0 )
    testlib.must_throw(writer.line_to, 0, 0)
    testlib.must_throw(writer.path_close)
    doc.page_end()
    doc.finalize()
Exemplo n.º 10
0
def test_main(argv=None):
    doc = jagpdf.create_stream(testlib.NoopStreamOut(),
                               jagpdf.create_profile())
    doc.page_start(5.9 * 72, 3.5 * 72)
    writer = doc.page().canvas()
    # the following operations must fail as they require path construction
    # to be already started
    testlib.must_throw(writer.bezier_to, 1, 2, 3, 4, 5, 6)
    testlib.must_throw(writer.bezier_to_1st_ctrlpt, 0, 0, 0, 0)
    testlib.must_throw(writer.bezier_to_2nd_ctrlpt, 0, 0, 0, 0)
    testlib.must_throw(writer.line_to, 0, 0)
    testlib.must_throw(writer.path_close)
    doc.page_end()
    doc.finalize()
Exemplo n.º 11
0
def test_main(argv=None):
    cfg = jagpdf.create_profile()
    cfg.set('doc.compressed', '1')
    doc = testlib.create_test_doc(argv, 'text_spiral.pdf', cfg)
    def get_angle(r, d):
        c = (d / 2.0) / r
        return math.pi - (2 * math.acos(c))
    font = doc.font_load('standard;name=Helvetica;size=28')
    media = 500, 500
    center = [c/2.0 for c in media]
    doc.page_start(*media)
    canvas = doc.page().canvas()
    canvas.text_font(font)
    n = 70
    r = 8
    radius = 180
    scale = 1.0
    color = 0.0
    # cross
    canvas.color('s', 0.9)
    canvas.move_to(0, center[1])
    canvas.line_to(media[0], center[1])
    canvas.move_to(center[0], 0)
    canvas.line_to(center[0], media[1])
    canvas.path_paint('s')
    canvas.color('s', 1.0)
    #text
    txt_file = os.path.expandvars('${JAG_TEST_RESOURCES_DIR}/text/lipsum.txt')
    data = open(txt_file).read()
    di = 0
    for j in range(r):
        for i in range(n):
            canvas.color('f', color)
            canvas.state_save()
            x = center[0] - (font.advance(data[0])/2.0)
            y = center[1] + radius
            canvas.translate(x, y)
            canvas.scale(scale, scale)
            canvas.text(0, 0, data[di])
            canvas.state_restore()
            canvas.translate(*center)
            radius -= 0.3
            scale -= 0.0015
            angle = get_angle(radius, scale * font.advance(data[di]))
            canvas.rotate(-angle)
            canvas.translate(-center[0], -center[1])
            color += 0.0015
            di += 1
    doc.page_end()
    doc.finalize()
Exemplo n.º 12
0
def test_main(argv=None):
    #
    # typemanager with no default font set
    #
    cfg = jagpdf.create_profile()
    cfg.set('fonts.fallback', '')
    doc = jagpdf.create_stream(testlib.NoopStreamOut())
    test_suite_fail(doc, ['this-font-does-not-exist',
                    'FreeType call failed',
                    '/this/file/does/not/exist'])
    doc.finalize()
    #
    # typemanager with nonexisting default font
    #
    cfg = jagpdf.create_profile()
    cfg.set('fonts.fallback', 'file=nonexisting-default')
    doc = jagpdf.create_stream(testlib.NoopStreamOut(), cfg)
    default_typeface_failure = 'Default typeface not found'
    test_suite_fail(doc, [(default_typeface_failure, 'nonexisting-default', 'this-font-does-not-exist'),
                           (default_typeface_failure, 'nonexisting-default', 'FreeType call failed'),
                           (default_typeface_failure, 'nonexisting-default', '/this/file/does/not/exist')])
    doc.finalize()
    #
    #
    #
    default_fonts = [('file=' + dejavu_ttf, 'DejaVu Sans'),
                      ('standard;name=Helvetica', 'Helvetica'),
                     ]
    if testlib.is_windows():
        default_fonts.append(('name=Arial;enc=windows-1252', 'Arial'))
    for default_font, fullname in default_fonts:
        cfg = jagpdf.create_profile()
        cfg.set('fonts.fallback', default_font)
        doc = jagpdf.create_stream(testlib.NoopStreamOut(), cfg)
        test_suite_ok(doc, fullname)
        doc.finalize()
Exemplo n.º 13
0
def get_legacy_doc(argv, name, cfg_=None):
    if None == argv:
        argv = sys.argv
    if not cfg_ or isinstance(cfg_, dict):
        cfg = jagpdf.create_profile()
        cfg.set('doc.compressed', "0")
    else:
        cfg = cfg_

    if isinstance(cfg_, dict):
        for opt, val in cfg_.iteritems():
            if isinstance(val, int):
                cfg.set(opt, str(val))
            else:
                cfg.set(opt, val)
    return jagpdf.create_file(os.path.join(argv[1], name), cfg), cfg
Exemplo n.º 14
0
def get_legacy_doc(argv, name, cfg_=None):
    if None==argv:
        argv=sys.argv
    if not cfg_ or isinstance(cfg_,dict):
        cfg = jagpdf.create_profile()
        cfg.set('doc.compressed', "0")
    else:
        cfg = cfg_

    if isinstance(cfg_,dict):
        for opt, val in cfg_.iteritems():
            if isinstance(val, int):
                cfg.set(opt, str(val))
            else:
                cfg.set(opt, val)
    return jagpdf.create_file(os.path.join(argv[1], name), cfg), cfg
Exemplo n.º 15
0
def test_main(argv=None):
    doc = jagpdf.create_stream(testlib.NoopStreamOut(), jagpdf.create_profile())
    #doc.finalize()

    patt_canvas = doc.canvas_create()
    testlib.must_throw(doc.tiling_pattern_load,
                       "step=0, 0",
                       patt_canvas) # empty canvas
    patt_canvas.move_to(5, 5)
    patt_canvas.line_to(15, 15)
    patt_canvas.path_paint("fs")
    testlib.must_throw(doc.tiling_pattern_load,
                       "matrix=1, 0, 0, 1, 0, 0",
                       patt_canvas) # no step
    patt_id = doc.tiling_pattern_load("step=20, 20", patt_canvas)

    # use pattern
    doc.page_start(5.9*72, 3.5*72)
    writer = doc.page().canvas()
    writer.color_space_pattern_uncolored("f", jagpdf.CS_DEVICE_GRAY)
    writer.pattern("f", patt_id, .5)
    writer.rectangle(36, 36, 144, 144)
    writer.path_paint("sf")

    #try to write to pattern that is already registered
    patt_canvas.rectangle(7, 7, 6, 6)
    patt_canvas.path_paint("fs")
    writer.rectangle(36+144+4, 36, 144, 144)
    writer.path_paint("sf")


    doc.page_end()

    # !!!! suprising - try to write to pattern that is already outputted
    patt_canvas.circle(10, 10, 5)
    patt_canvas.path_paint("s")


    # !!!! this is wild -> this caused abort
    try:
        patt_canvas.paint("fs")
    except AttributeError:
        pass
    else:
        assert 0

    doc.finalize()
Exemplo n.º 16
0
def test_main(argv=None):
    cfg = jagpdf.create_profile()
    cfg.set('doc.compressed', '1')
    #    cfg.set("doc.viewer_preferences", "FitWindow; DisplayDocTitle")
    cfg.set("doc.initial_destination", "mode=XYZ; zoom=1.0")

    doc = testlib.create_test_doc(argv, 'imageclip.pdf', cfg)
    img_file = os.path.expandvars(
        '${JAG_TEST_RESOURCES_DIR}/images/mandrill.jpg')
    img = doc.image_load_file(img_file, jagpdf.IMAGE_FORMAT_JPEG)
    media = 500, 500
    doc.page_start(*media)
    canvas = doc.page().canvas()
    center = [c / 2.0 for c in media]
    n = 14
    canvas.color('s', 0.8)
    canvas.state_save()
    canvas.circle(center[0], center[1], 210)
    canvas.circle(center[0], center[1], 120)
    canvas.path_paint('Ws')
    for i in range(n + 1):
        canvas.translate(*center)
        canvas.rotate(2.0 * math.pi / n)
        canvas.translate(-center[0], -center[1])
        canvas.state_save()
        canvas.translate(80, 80)
        canvas.scale(0.35, 0.35)
        canvas.image(img, 0, 0)
        canvas.state_restore()
    canvas.state_restore()
    center_scale = .65
    img_width = center_scale * img.width() / img.dpi_x() * 72
    img_height = center_scale * img.height() / img.dpi_y() * 72
    canvas.state_save()
    canvas.translate(center[0] - img_width / 2.0, center[1] - img_height / 2.0)
    canvas.scale(center_scale, center_scale)
    canvas.image(img, 0, 0)
    canvas.state_restore()
    doc.page_end()
    doc.finalize()
Exemplo n.º 17
0
def test_main(argv=None):
    cfg = jagpdf.create_profile()
    cfg.set('doc.compressed', '1')
#    cfg.set("doc.viewer_preferences", "FitWindow; DisplayDocTitle")
    cfg.set("doc.initial_destination", "mode=XYZ; zoom=1.0")
    
    doc = testlib.create_test_doc(argv, 'imageclip.pdf', cfg)
    img_file = os.path.expandvars('${JAG_TEST_RESOURCES_DIR}/images/mandrill.jpg')
    img = doc.image_load_file(img_file, jagpdf.IMAGE_FORMAT_JPEG)
    media = 500, 500
    doc.page_start(*media)
    canvas = doc.page().canvas()
    center = [c/2.0 for c in media]
    n = 14
    canvas.color('s', 0.8)
    canvas.state_save()
    canvas.circle(center[0], center[1], 210)
    canvas.circle(center[0], center[1], 120)
    canvas.path_paint('Ws')
    for i in range(n + 1):
        canvas.translate(*center)
        canvas.rotate(2.0 * math.pi / n)
        canvas.translate(-center[0], -center[1])
        canvas.state_save()
        canvas.translate(80, 80)
        canvas.scale(0.35, 0.35)
        canvas.image(img, 0, 0)
        canvas.state_restore()
    canvas.state_restore()
    center_scale = .65
    img_width = center_scale * img.width() / img.dpi_x() * 72
    img_height = center_scale * img.height() / img.dpi_y() * 72
    canvas.state_save()
    canvas.translate(center[0]-img_width/2.0, center[1]-img_height/2.0)
    canvas.scale(center_scale, center_scale)
    canvas.image(img, 0, 0)
    canvas.state_restore()
    doc.page_end()
    doc.finalize()
Exemplo n.º 18
0
def test_main(argv=None):
    if None == argv:
        argv = sys.argv
    out_file = os.path.abspath(os.path.join(argv[1], 'config.pdf'))
    cfg_file = os.path.abspath(os.path.join(argv[1], 'config.ini'))
    doc = jagpdf.create_stream(testlib.FileStreamOut(out_file))
    doc = None
    doc = jagpdf.create_file(out_file)
    doc = None
    cfg = jagpdf.create_profile()
    cfg.set("doc.compressed", "blue-foundation")
    cfg.save_to_file(out_file)
    cfg_str = open(out_file).read()
    cfg3 = jagpdf.create_profile_from_file(out_file)
    cfg2 = jagpdf.create_profile_from_string(cfg_str)
    cfg3.save_to_file(cfg_file)
    cfg3_str = open(cfg_file).read()
    cfg2.save_to_file(cfg_file)
    cfg2_str = open(cfg_file).read()
    os.unlink(out_file)
    os.unlink(cfg_file)
    assert cfg3_str == cfg2_str
Exemplo n.º 19
0
def test_main(argv=None):
    if None==argv:
        argv = sys.argv
    out_file = os.path.abspath(os.path.join(argv[1], 'config.pdf'))
    cfg_file = os.path.abspath(os.path.join(argv[1], 'config.ini'))
    doc = jagpdf.create_stream(testlib.FileStreamOut(out_file))
    doc = None
    doc = jagpdf.create_file(out_file)
    doc = None
    cfg = jagpdf.create_profile()
    cfg.set("doc.compressed", "blue-foundation")
    cfg.save_to_file(out_file)
    cfg_str = open(out_file).read()
    cfg3 = jagpdf.create_profile_from_file(out_file)
    cfg2 = jagpdf.create_profile_from_string(cfg_str)
    cfg3.save_to_file(cfg_file)
    cfg3_str = open(cfg_file).read()
    cfg2.save_to_file(cfg_file)
    cfg2_str = open(cfg_file).read()
    os.unlink(out_file)
    os.unlink(cfg_file)
    assert cfg3_str == cfg2_str
Exemplo n.º 20
0
def test_main(argv=None):
    #http://www.lorem-ipsum.info/generator3
    def do_page(font, txt):
        media = 597.6, 848.68
        margin = 20
        rect = margin, margin, media[0] - 2 * margin, media[1] - 2 * margin
        doc.page_start(*media)
        canvas = doc.page().canvas()
        canvas.color('s', 0.9)
        canvas.rectangle(*rect)
        canvas.path_paint('s')
        textfmt.format_text(rect,
                            txt,
                            doc,
                            font,
                            align='justify',
                            para_spacing=0.5)
        doc.page_end()

    dejavu = os.path.expandvars(
        '${JAG_TEST_RESOURCES_DIR}/fonts/DejaVuSans.ttf')
    textdir = os.path.expandvars('${JAG_TEST_RESOURCES_DIR}/text/')
    cfg = jagpdf.create_profile()
    cfg.set('doc.compressed', '1')
    doc = testlib.create_test_doc(argv, 'justified.pdf', cfg)
    font_1252 = doc.font_load('file=%s;size=8' % dejavu)  # western
    font_1251 = doc.font_load('file=%s;size=8;enc=windows-1251' %
                              dejavu)  # cyrillic
    font_1253 = doc.font_load('file=%s;size=8;enc=windows-1253' %
                              dejavu)  # greek
    for font, fname, enc in [[font_1252, 'lipsum.txt', 'windows-1252'],
                             [font_1251, 'russian-lipsum.txt', 'windows-1251'],
                             [font_1253, 'greek-lipsum.txt', 'windows-1253']]:
        text_file = os.path.join(textdir, fname)
        do_page(font, unicode(open(text_file).read(), 'utf-8').encode(enc))
    doc.finalize()
Exemplo n.º 21
0
def test_main(argv=None):
    doc = testlib.create_test_doc(argv, 'invoice.pdf', jagpdf.create_profile())
    table_fnt = doc.font_load("standard; name=Helvetica; size=10; enc=windows-1250")
    table_fnt_bold = doc.font_load("standard; name=Helvetica-Bold; size=10; enc=windows-1250")
    header_fnt = doc.font_load("standard; name=Helvetica-Bold; size=10; enc=windows-1250")
    invoice_fnt = doc.font_load("standard; name=Helvetica-Bold; size=16; enc=windows-1250")
    offer_fnt = doc.font_load("standard; name=Helvetica-Bold; size=12; enc=windows-1250")
    table_title_fnt = doc.font_load("standard; name=Helvetica-Bold; size=14; enc=windows-1250")
    dingbats_fnt = doc.font_load("standard; name=ZapfDingbats; size=10")
    dingbats_fnt = header_fnt

    doc.page_start(597.6, 848.68)
    canvas = doc.page().canvas()
    canvas.color_space("fs", jagpdf.CS_DEVICE_RGB)
    #
    widths = [110, 90, 80, 80, 40, 80]
    style = TableStyle(doc)
    tbl = SimpleTable(doc, widths, font = table_fnt, style = style, header=1, footer=1)
    tbl.set_table_prop("halign", "center")

    # header
    tbl.add_line(('Number', 'Date', 'Time', 'Duration', 'Wiretap', 'Price'))
    tbl.set_line_prop("halign", 0, "center")
    tbl.set_line_prop("font", 0, header_fnt)
    tbl.set_line_prop("text_col", 0, (1, 1, 1))
    tbl.set_line_prop("cell_pad", 0, {'top': 4, 'bottom': 4})
    # body - add records and formatting style
    for rec, inf in record_iter():
        tbl.add_line(rec)
    tbl.set_column_prop("halign", 5, "right")
    tbl.set_column_prop("cell_pad", 5, {'right': 25})
    tbl.set_column_prop("halign", 4, "center")
    tbl.set_column_prop("text_col", 4, (0, .525, 0.086))
    tbl.set_column_prop("font", 4, dingbats_fnt)
    tbl.set_column_prop("halign", 3, "right")
    tbl.set_column_prop("cell_pad", 3, {'right': 25})
    tbl.set_column_prop("cell_pad", 0, {'left': 10})
    # footer
    dur = "%02d:%02d:%02d" % (inf.sec/3600, (inf.sec%3600)/60, inf.sec%60)
    price_str = "\x80 %.2f" % inf.price
    footer_id = tbl.add_line(('Total', '', '', dur, str(inf.nr_wire), price_str))
    tbl.set_line_prop("font", footer_id, header_fnt)
    tbl.set_line_prop("text_col", footer_id, (1, 1, 1))
    tbl.set_line_prop("cell_pad", footer_id, {'top': 4, 'bottom': 4})
    # render table
    tbl_width = sum(widths)
    tbl_x = (597.6 - tbl_width) / 2
    tbl.render(tbl_x, 670, canvas)
    #
    # render rest
    #
    # add customer, company, ...
    write_block(canvas, tbl_x, 765, billing_addres, table_fnt, table_fnt_bold)
    write_block(canvas, 400, 765, metelco_addres, table_fnt, table_fnt_bold)
    write_block(canvas, 205, 765, billing_info, table_fnt, table_fnt_bold)
    # invoice top
    png = os.path.expandvars('${JAG_TEST_RESOURCES_DIR}/images/metelco.png')
    logo = doc.image_load_file(png)
    canvas.image(logo, 390, 785)
    canvas.color("fs", *style.col_dark)
    canvas.text_font(table_title_fnt)
    canvas.text(260, 678, "Call Details")
    canvas.text_font(invoice_fnt)
    canvas.text(tbl_x, 790, "Invoice #3922094839")
    canvas.move_to(tbl_x, 780)
    canvas.line_to(tbl_x + tbl_width, 780)
    canvas.move_to(tbl_x, 695)
    canvas.line_to(tbl_x + tbl_width, 695)
    canvas.move_to(197, 775)
    canvas.line_to(197, 700)
    canvas.move_to(392, 775)
    canvas.line_to(392, 700)
    canvas.path_paint("s")
    # special offer
    jpg = os.path.expandvars('${JAG_TEST_RESOURCES_DIR}/images/oldphone.jpg')
    phone = doc.image_load_file(jpg)
    canvas.image(phone, tbl_x, 25)
    special_offer(doc, canvas, offer_fnt, tbl_x + 30, 110, 3.14/8)
    canvas.color('f', 0, 0, 0)
    rect = tbl_x + 130, 50, 340, 70
    textfmt.format_text(rect, ad, doc, table_fnt, align='justify', para_spacing=0.5)
    #
    doc.page_end()
    doc.finalize()
Exemplo n.º 22
0
def test_main(argv=None):
    profile = jagpdf.create_profile()
    profile.set('doc.encryption', 'standard')
    profile.set("info.static_producer", "1")
    profile.set("doc.static_file_id", "1")
    profile.set("info.creation_date", "0")
    profile.set('stdsh.pwd_user', 'user')
    profile.set('stdsh.pwd_owner', 'owner')
    profile.set("stdsh.permissions", "no_print; no_copy")
    doc = testlib.create_test_doc(argv, 'topsecret.pdf', profile)
    fnt = doc.font_load("standard; name=Helvetica; size=10; enc=windows-1252")
    fnt_b = doc.font_load(
        "standard; name=Helvetica-Bold; size=10; enc=windows-1252")
    doc.page_start(597.6, 848.68)
    canvas = doc.page().canvas()
    canvas.color_space("fs", jagpdf.CS_DEVICE_RGB)
    # confidential
    canvas.state_save()
    cx, cy = 597.6 / 2, 848.68 / 2
    cfnt = doc.font_load(
        "standard; name=Helvetica-Bold; size=120; enc=windows-1252")
    canvas.text_font(cfnt)
    cf_w = cfnt.advance("TOP SECRET")
    cf_x = (597.6 - cf_w) / 2
    canvas.translate(cx, cy)
    canvas.rotate(3.14 / 3)
    canvas.translate(-cx, -cy)
    #canvas.text_rendering_mode('s')
    canvas.color('f', 0.8, 0.8, 0.8)
    canvas.text(cf_x, cy - 20, "TOP SECRET")
    canvas.state_restore()
    # page header
    fnt_clients = doc.font_load(
        "standard; name=Helvetica-Bold; size=13; enc=windows-1252")
    top_str = "Top 50 Clients"
    top_w = fnt_clients.advance(top_str)
    top_x = (597.6 - top_w) / 2
    canvas.text_font(fnt_clients)
    canvas.text(top_x, 785, top_str)
    # table
    widths = [150, 100, 100, 120]
    tbl = SimpleTable(doc, widths, font=fnt, header=1, footer=1, style=Style())
    # table header
    tbl.add_line(('Name', 'Account Nr.', 'Opened', 'Balance'))
    tbl.set_line_prop("font", 0, fnt_b)
    tbl.set_line_prop("halign", 0, "center")
    tbl.set_line_prop("cell_pad", 0, {'top': 4, 'bottom': 4})
    # table body
    for rec in records.split('\n')[:50]:
        tbl.add_line(rec.split('|'))
    tbl.set_column_prop("cell_pad", 0, {'left': 15})
    tbl.set_column_prop("cell_pad", 3, {'right': 15})
    tbl.set_column_prop("halign", 1, "center")
    tbl.set_column_prop("halign", 2, "center")
    tbl.set_column_prop("halign", 3, "right")
    # table footer
    tbl.add_line(4 * [])
    # table render
    tbl_width = sum(widths)
    tbl_x = (597.6 - tbl_width) / 2
    tbl.render(tbl_x, 780, canvas)
    # page footer
    fnt_clients = doc.font_load(
        "standard; name=Helvetica-Oblique; size=10; enc=windows-1252")
    canvas.text_font(fnt_clients)
    canvas.text(tbl_x, 40, "Classification: TOP SECRET")
    testlib.paint_image('/images/GWBush-signature.png', doc, tbl_x + 340, 10)
    # stamp
    testlib.paint_image('/images/topsecret.png', doc, 450, 20)
    #
    testlib.paint_image('/images/greedybank.png', doc, tbl_x, 790)
    #
    doc.page_end()
    doc.finalize()
Exemplo n.º 23
0
def test_main(argv=None):
    profile = jagpdf.create_profile()
    profile.set("doc.encryption", "standard")
    profile.set("info.static_producer", "1")
    profile.set("doc.static_file_id", "1")
    profile.set("info.creation_date", "0")
    profile.set("stdsh.pwd_user", "user")
    profile.set("stdsh.pwd_owner", "owner")
    profile.set("stdsh.permissions", "no_print; no_copy")
    doc = testlib.create_test_doc(argv, "topsecret.pdf", profile)
    fnt = doc.font_load("standard; name=Helvetica; size=10; enc=windows-1252")
    fnt_b = doc.font_load("standard; name=Helvetica-Bold; size=10; enc=windows-1252")
    doc.page_start(597.6, 848.68)
    canvas = doc.page().canvas()
    canvas.color_space("fs", jagpdf.CS_DEVICE_RGB)
    # confidential
    canvas.state_save()
    cx, cy = 597.6 / 2, 848.68 / 2
    cfnt = doc.font_load("standard; name=Helvetica-Bold; size=120; enc=windows-1252")
    canvas.text_font(cfnt)
    cf_w = cfnt.advance("TOP SECRET")
    cf_x = (597.6 - cf_w) / 2
    canvas.translate(cx, cy)
    canvas.rotate(3.14 / 3)
    canvas.translate(-cx, -cy)
    # canvas.text_rendering_mode('s')
    canvas.color("f", 0.8, 0.8, 0.8)
    canvas.text(cf_x, cy - 20, "TOP SECRET")
    canvas.state_restore()
    # page header
    fnt_clients = doc.font_load("standard; name=Helvetica-Bold; size=13; enc=windows-1252")
    top_str = "Top 50 Clients"
    top_w = fnt_clients.advance(top_str)
    top_x = (597.6 - top_w) / 2
    canvas.text_font(fnt_clients)
    canvas.text(top_x, 785, top_str)
    # table
    widths = [150, 100, 100, 120]
    tbl = SimpleTable(doc, widths, font=fnt, header=1, footer=1, style=Style())
    # table header
    tbl.add_line(("Name", "Account Nr.", "Opened", "Balance"))
    tbl.set_line_prop("font", 0, fnt_b)
    tbl.set_line_prop("halign", 0, "center")
    tbl.set_line_prop("cell_pad", 0, {"top": 4, "bottom": 4})
    # table body
    for rec in records.split("\n")[:50]:
        tbl.add_line(rec.split("|"))
    tbl.set_column_prop("cell_pad", 0, {"left": 15})
    tbl.set_column_prop("cell_pad", 3, {"right": 15})
    tbl.set_column_prop("halign", 1, "center")
    tbl.set_column_prop("halign", 2, "center")
    tbl.set_column_prop("halign", 3, "right")
    # table footer
    tbl.add_line(4 * [])
    # table render
    tbl_width = sum(widths)
    tbl_x = (597.6 - tbl_width) / 2
    tbl.render(tbl_x, 780, canvas)
    # page footer
    fnt_clients = doc.font_load("standard; name=Helvetica-Oblique; size=10; enc=windows-1252")
    canvas.text_font(fnt_clients)
    canvas.text(tbl_x, 40, "Classification: TOP SECRET")
    testlib.paint_image("/images/GWBush-signature.png", doc, tbl_x + 340, 10)
    # stamp
    testlib.paint_image("/images/topsecret.png", doc, 450, 20)
    #
    testlib.paint_image("/images/greedybank.png", doc, tbl_x, 790)
    #
    doc.page_end()
    doc.finalize()
Exemplo n.º 24
0
def test_main(argv=None):
    profile = jagpdf.create_profile()
    profile.set("doc.topdown", "1")
    profile.set("doc.compressed", "0")
    doc = testlib.create_test_doc(argv, 'dark_reader.pdf', profile)

    #http://www.microsoft.com/prophoto/downloads/colorcontrol.aspx
    icc_str = 'sRGB'
    doc.add_output_intent(icc_str, icc_path('sRGB Color Space Profile.icm'), icc_str, 3, None)
    
    img = doc.image_load_file(image_path('logo.png'))
    doc.page_start(8.3 * 72.0, 11.7 * 72.0)
    canvas = doc.page().canvas()

    srgb = doc.color_space_load('srgb')
    img_def = doc.image_definition()
    img_def.file_name(image_path('logo.png'))
    # - no effect
    #img_def.rendering_intent(jagpdf.RI_PERCEPTUAL)
    # - srgb makes it worse
    #img_def.color_space(srgb)
    img_srgb = doc.image_load(img_def)

    # 1 0 0 -1 0 842.4 cm 
    # 1 0 0 1 14.4 14.4 cm
    canvas.translate(14.4, 14.4)
    # 0.24 0 0 0.24 0 0 cm 
    canvas.scale(0.24, 0.24)
    # /DeviceRGB CS 
    # /DeviceRGB cs
    canvas.color_space('fs', jagpdf.CS_DEVICE_RGB)
    # q
    canvas.state_save()
    #  0.79987 0 0 0.79987 0 0 cm
    canvas.scale(0.79987, 0.79987)
    
    #   0.27451 0.44314 0.83529 sc
    canvas.color('f', 0.27451, 0.44314, 0.83529)
    #   0 0 2963 159 re
    canvas.rectangle(0, 0, 2963, 159)
    #   f
    canvas.path_paint('f')

    for i, c in enumerate([(1,0,0), (0,1,0), (0,0,1)]):
        canvas.color('f', *c)
        canvas.rectangle((i+2) * 170, 10, 160, 160)
        canvas.path_paint('f')
    
    #  q
    canvas.state_save()
    #   3.125 0 0 3.06667 0 159 cm
    canvas.transform(3.125, 0, 0, 3.06667, 0, 159)
    #   q
    #    80 0 0 -15 0 15 cm 
    #    /im1 Do
    #   Q
    #  Q
    canvas.image(img_srgb, 0, 0)
    canvas.state_restore()
    # Q
    canvas.state_restore()

    doc.page_end()
    doc.finalize()
Exemplo n.º 25
0
def test_config():
    """returns a standard test configuration"""
    cfg = jagpdf.create_profile()
    cfg.set("doc.compressed", "0")
    return cfg
Exemplo n.º 26
0
def test_config():
    """returns a standard test configuration"""
    cfg = jagpdf.create_profile()
    cfg.set("doc.compressed", "0")
    return cfg
Exemplo n.º 27
0
def test_main(argv=None):
    profile = jagpdf.create_profile()
    profile.set("doc.topdown", "1")
    profile.set("doc.compressed", "0")
    doc = testlib.create_test_doc(argv, 'dark_reader.pdf', profile)

    #http://www.microsoft.com/prophoto/downloads/colorcontrol.aspx
    icc_str = 'sRGB'
    doc.add_output_intent(icc_str, icc_path('sRGB Color Space Profile.icm'),
                          icc_str, 3, None)

    img = doc.image_load_file(image_path('logo.png'))
    doc.page_start(8.3 * 72.0, 11.7 * 72.0)
    canvas = doc.page().canvas()

    srgb = doc.color_space_load('srgb')
    img_def = doc.image_definition()
    img_def.file_name(image_path('logo.png'))
    # - no effect
    #img_def.rendering_intent(jagpdf.RI_PERCEPTUAL)
    # - srgb makes it worse
    #img_def.color_space(srgb)
    img_srgb = doc.image_load(img_def)

    # 1 0 0 -1 0 842.4 cm
    # 1 0 0 1 14.4 14.4 cm
    canvas.translate(14.4, 14.4)
    # 0.24 0 0 0.24 0 0 cm
    canvas.scale(0.24, 0.24)
    # /DeviceRGB CS
    # /DeviceRGB cs
    canvas.color_space('fs', jagpdf.CS_DEVICE_RGB)
    # q
    canvas.state_save()
    #  0.79987 0 0 0.79987 0 0 cm
    canvas.scale(0.79987, 0.79987)

    #   0.27451 0.44314 0.83529 sc
    canvas.color('f', 0.27451, 0.44314, 0.83529)
    #   0 0 2963 159 re
    canvas.rectangle(0, 0, 2963, 159)
    #   f
    canvas.path_paint('f')

    for i, c in enumerate([(1, 0, 0), (0, 1, 0), (0, 0, 1)]):
        canvas.color('f', *c)
        canvas.rectangle((i + 2) * 170, 10, 160, 160)
        canvas.path_paint('f')

    #  q
    canvas.state_save()
    #   3.125 0 0 3.06667 0 159 cm
    canvas.transform(3.125, 0, 0, 3.06667, 0, 159)
    #   q
    #    80 0 0 -15 0 15 cm
    #    /im1 Do
    #   Q
    #  Q
    canvas.image(img_srgb, 0, 0)
    canvas.state_restore()
    # Q
    canvas.state_restore()

    doc.page_end()
    doc.finalize()