Beispiel #1
0
def do_main(argv):
    out_files = ["customsmask15.pdf",
                  "customsmask14.pdf",
                  "customsmask13.pdf"]
    # (2,3,1) - removed
    for index, version, strict in [(1,4,1), (0,5,1), (2,3,0)]:
        if version < 4 and strict:
            checker = testlib.must_throw
            cfg = testlib.test_config()
            cfg.set("doc.version", str(version))
            cfg.set("doc.strict_mode", str(strict))
            cfg.set("images.softmask_16_to_8", str(0))
            doc = jagpdf.create_stream(testlib.NoopStreamOut(), cfg)
        else:
            checker = lambda fn, *args: fn(*args)
        doc, cfg = testlib.get_legacy_doc(argv,
                                           out_files[index],
                                           { 'doc.version' : version,
                                             'doc.strict_mode' : strict,
                                             'images.softmask_16_to_8' : 0 })
        g_font.set_writer(doc)
        g_softmask.set_doc(doc)
        checker(do_grayscale, doc)
        checker(do_rgb, doc)
        checker(do_cmyk, doc)
        doc.finalize()
Beispiel #2
0
def do_main(argv=None):
    out_files = ["customimage15.pdf",\
                  "customimage14.pdf",\
                  "customimage13.pdf",\
                  "customimage12.pdf"]
    # (0,2,1) - removed
    for index, version, strict in [(3, 2, 0), (2, 3, 1), (1, 4, 1), (0, 5, 1)]:
        if strict and version == 2:
            # it seems that this test branch is flawed as the
            # exceptions are raised in different places then
            # originally inteded
            checker = testlib.must_throw
            cfg = testlib.test_config()
            cfg.set("doc.version", str(version))
            cfg.set("doc.strict_mode", str(strict))
            doc = jagpdf.create_as_stream(testlib.NoopStreamOut(), cfg)
        else:
            checker = lambda fn, *args: fn(*args)
            doc, cfg = testlib.get_legacy_doc(argv, out_files[index], {
                'doc.version': version,
                'doc.strict_mode': strict
            })
        g_font.set_writer(doc)
        checker(g_hardmask.set_doc, doc)
        checker(do_grayscale, doc)
        checker(do_rgb, doc)
        checker(do_cmyk, doc)
        checker(do_cielab, doc)
        checker(do_indexed, doc)
        check_errors(doc)
        doc.finalize()
Beispiel #3
0
def do_it():
    prof = jagpdf.create_profile_from_string(s_profile)
    stream = testlib.NoopStreamOut()
    doc = jagpdf.create_stream(stream)
    doc.page_start(5.9*72, 3.5*72)
    canvas = doc.page().canvas()
    # meat
    img = doc.image_load_file(s_jpeg_file)
    canvas.image(img, 50, 50)
    canvas.text(10, 10, 200 * 'a')
    canvas.move_to(10, 10)
    canvas.line_to(20, 20)
    canvas.path_paint("fs")
    font_ttf = testlib.EasyFontTTF(doc)(10)
    font_core = testlib.EasyFont(doc)(10)
    canvas.text_font(font_ttf)
    canvas.text(10, 10, 50 * 'x')
    font_ttf.advance('abcdefghijklmnopqrstuvwxyz')
    canvas.text_font(font_core)
    canvas.text(10, 10, 50 * 'y')
    font_core.advance('abcdefghijklmnopqrstuvwxyz')
    # finalize
    doc.page_end()
    doc.finalize()
    # touch the result
    s = 0
    for b in stream.content():
        s = s + ord(b)
Beispiel #4
0
def cannot_output_font(easy_font, enc=None):
    doc = jagpdf.create_stream(testlib.NoopStreamOut())
    fnt = easy_font(doc, enc)
    doc.page_start(*testlib.paperA5)
    canvas = doc.page().canvas()
    canvas.text_font(fnt())
    canvas.state_save()
    canvas.state_restore()
    doc.page_end()
    testlib.must_throw_ex("font", doc.finalize)
Beispiel #5
0
def error_injection():
    # reject non-roman alphabet
    doc = jagpdf.create_stream(testlib.NoopStreamOut())
    fnt = doc.font_load("standard; name=Helvetica; size=12; enc=utf-8")
    doc.page_start(500, 500)
    canvas = doc.page().canvas()
    canvas.text_font(fnt)
    #testlib.must_throw(canvas.text, 10, 10, "\xd0\x96\xd1\x86\xd0\xba")
    doc.page_end()
    doc.finalize()
Beispiel #6
0
def test_faults():
    doc = jagpdf.create_stream(testlib.NoopStreamOut())
    doc.page_start(72, 72)
    canvas = doc.page().canvas()
    # cannot use simple text inside a text object
    canvas.text_start(0, 0)
    testlib.must_throw(canvas.text, 10, 10, "No!")
    canvas.text_end()
    canvas.text(10, 10, "Yes")
    doc.page_end()
    doc.finalize()
Beispiel #7
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()
Beispiel #8
0
def fault_injection():
    doc = jagpdf.create_stream(testlib.NoopStreamOut())
    outline = doc.outline()
    testlib.must_throw(outline.item, "Invalid bookmark")
    outline.state_save()
    doc.page_start(5.9 * 72, g_page_height)
    testlib.must_throw(outline.level_down)
    testlib.must_throw(outline.level_up)
    doc.page_end()
    outline.state_restore()
    testlib.must_throw(outline.state_restore)
    doc.finalize()
Beispiel #9
0
def test_main(argv=None):
    doc = jagpdf.create_stream(testlib.NoopStreamOut())
    doc.page_start(*dim)
    canvas = doc.page().canvas()
    testlib.must_throw(canvas.line_to, 20, 20)
    testlib.must_throw(canvas.path_paint, 'f')
    canvas.text_start(0, 0)
    testlib.must_throw(canvas.text, 10, 10, "Not allowed here!")
    canvas.text("This is OK")
    canvas.text_end()
    doc.page_end()
    doc.finalize()
Beispiel #10
0
def test_main(argv=None):
    doc = jagpdf.create_stream(testlib.NoopStreamOut())
    doc.page_start(597.6, 848.68)
    canvas = doc.page().canvas()
    #
    gradient = doc.function_2_load("domain=0, 1; c0=0; c1=1")
    p = doc.shading_pattern_load("axial; coords=0, 0, 400, 400",
                                 jagpdf.CS_DEVICE_GRAY, gradient)
    # cannot set pattern because the pattern color space has not been set
    testlib.must_throw(canvas.pattern, "f", p)
    #
    doc.page_end()
    doc.finalize()
Beispiel #11
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()
Beispiel #12
0
def test_main(argv=None):
    cfg = testlib.test_config()

    # normal functionality
    cfg.set('doc.version', "3")
    writer = testlib.create_test_doc(argv, 'color-space-str-def.pdf', cfg)
    g_font.set_writer(writer)
    do_page(writer)
    writer.finalize()

    # expected failures
    cfg.set('doc.version', "2")
    writer = jagpdf.create_stream(testlib.NoopStreamOut(), cfg)
    g_font.set_writer(writer)
    do_failures_v2(writer)
    writer.finalize()
Beispiel #13
0
def check_errors():
    doc = jagpdf.create_stream(testlib.NoopStreamOut())
    doc.page_start(1, 1)
    canvas = doc.page().canvas()
    colored = create_col_pattern(doc, 1)
    uncolored = create_uncol_pattern(doc, 1)
    #
    canvas.color_space_pattern('fs')
    testlib.must_throw(canvas.pattern, 'fs', colored, 1)
    canvas.pattern('fs', uncolored, 1)  # should throw
    #
    canvas.color_space_pattern_uncolored('fs', jagpdf.CS_DEVICE_CMYK)
    testlib.must_throw(canvas.pattern, 'fs', uncolored)
    canvas.pattern('fs', colored)  # should throw
    doc.page_end()
    doc.finalize()
Beispiel #14
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()
Beispiel #15
0
def check_errors():
    doc = jagpdf.create_stream(testlib.NoopStreamOut())
    doc.page_start(1, 1)
    fn = function(doc, 'double_dot')
    sh = doc.shading_pattern_load(
        "function; matrix_fun=100, 0, 0, 100, 50, 50", jagpdf.CS_DEVICE_GRAY,
        fn)
    canvas = doc.page().canvas()
    canvas.color_space_pattern('fs')
    testlib.must_throw(canvas.pattern, 'fs', sh, 1)
    canvas.color_space_pattern_uncolored('fs', jagpdf.CS_DEVICE_GRAY)
    canvas.pattern('fs', sh)  # should throw
    # indexed not allowed pattern spaces
    indexed_cs = doc.color_space_load("adobe-rgb; palette=77, 179, 102")
    fn = doc.function_2_load("c0=1.0, 0.0, 0.0; c1=0.0, 0.0, 1.0")
    testlib.must_throw(doc.shading_pattern_load,
                       "axial; coords=50, 50, 150, 150", indexed_cs, fn)
    doc.page_end()
    doc.finalize()
Beispiel #16
0
 def __init__(self, option, value):
     CreatorBase.__init__(self, option, value)
     self.doc = jagpdf.create_stream(testlib.NoopStreamOut(), self.profile)