Пример #1
0
def main(argv):
    gs = GS()

    document = dsc_document("My first textbox example and testbed")
    page = document.page()
    canvas = page.canvas(margin=mm(18), border=False)

    tr = gs.font("Times-Roman")
    tr = page.register_font(tr)

    he = gs.font("Helvetica")
    he = page.register_font(he)

    al = type1("Kerkis.pfa", "Kerkis.afm")
    al = page.register_font(al)

    ba = type1("BlackadderITC-Regular.pfa", "BlackadderITC-Regular.afm")
    ba = page.register_font(ba)
    
    for counter, bb in enumerate(eight_squares(canvas)):        
        func = globals().get("box%i" % counter, None)
        
        if func is None:
            break
        else:
            box = textbox.from_bounding_box(canvas, bb, border=True)
            canvas.append(box)
            func(**locals())

    fp = open(sys.argv[0] + ".ps", "w")
    document.write_to(fp)
    fp.close()
Пример #2
0
def main(argv):
    img = Image.open(argv[1])

    document = dsc_document("Raster Image Demo")
    page = document.page()
    canvas = page.canvas(margin=mm(18), border=True)

    eps = raster_image(canvas, img, document_level=False, border=True)
    page.append(eps)

    fp = open(sys.argv[1] + ".ps", "w")
    document.write_to(fp)
    fp.close()
Пример #3
0
def main(argv):

    document = dsc_document("EPS Demo")
    page = document.page()
    canvas = page.canvas(margin=mm(18), border=True)

    eps = eps_image(canvas, open(sys.argv[1]),
                    border=True, document_level=True)
    page.append(eps)

    fp = open(sys.argv[1] + ".ps", "w")
    document.write_to(fp)
    fp.close()
Пример #4
0
def main(argv):
    img = Image.open(argv[1])
    
    document = dsc_document("Raster Image Demo")
    page = document.page()
    canvas = page.canvas(margin=mm(18), border=True)

    eps = raster_image(canvas, img, document_level=False,
                       border=True)
    page.append(eps)

    fp = open(sys.argv[1] + ".ps", "w")
    document.write_to(fp)
    fp.close()
Пример #5
0
def main(argv):

    document = dsc_document("EPS Demo")
    page = document.page()
    canvas = page.canvas(margin=mm(18), border=True)

    eps = eps_image(canvas,
                    open(sys.argv[1]),
                    border=True,
                    document_level=True)
    page.append(eps)

    fp = open(sys.argv[1] + ".ps", "w")
    document.write_to(fp)
    fp.close()
Пример #6
0
def main():

    document = dsc_document("Hello, world!")
    page = document.page()
    canvas = page.canvas(margin=mm(18))

    print("/Helvetica findfont", file=canvas)
    print("20 scalefont", file=canvas)
    print( "setfont", file=canvas)
    print("0 0 moveto", file=canvas)
    print(ps_escape("Hello, world!"), " show", file=canvas)

    fp = open("ps_hello_world.ps", "w")
    document.write_to(fp)
    fp.close()
Пример #7
0
def main():

    document = dsc_document("Hello, world!")
    page = document.page()
    canvas = page.canvas(margin=mm(18))

    print("/Helvetica findfont", file=canvas)
    print("20 scalefont", file=canvas)
    print("setfont", file=canvas)
    print("0 0 moveto", file=canvas)
    print(ps_escape("Hello, world!"), " show", file=canvas)

    fp = open("ps_hello_world.ps", "w")
    document.write_to(fp)
    fp.close()
Пример #8
0
def main(argv):
    gs = GS()

    sans = gs.font("FeGWitten-Bold")

    # for u, g in sans.metrics.items():
    #     print u, g.ps_name

    document = dsc_document("Hello, world!")
    page = document.page()
    canvas = page.canvas(margin=mm(18), border=True)
    canvas = canvas_with_lines(canvas, 30.0)

    # The regular say
    print >> canvas, "/%s findfont" % sans.ps_name
    print >> canvas, "20 scalefont"
    print >> canvas, "setfont"
    print >> canvas, ps_escape("Hello, world! (no Kerning at all)"), " show"
    canvas.newline()

    # Kerned say

    message = u"Hello, world! (Pair-wise Kerning on!) €  äöüÄÖÜß"  # äöüÄÖÜß

    offsets = []

    sans_wrapper = page.register_font(sans)
    print >> canvas, "/%s findfont" % sans_wrapper.ps_name()
    print >> canvas, "20 scalefont"
    print >> canvas, "setfont"

    for kerning_delta in glyph_iterator(sans_wrapper, 20, message):
        offsets.append(kerning_delta)

    offsets = map(str, offsets)
    tpl = (
        sans_wrapper.postscript_representation(message),
        join(offsets, " "),
    )
    print >> canvas, "(%s) [ %s ] xshow" % tpl

    fp = open("kerning.ps", "w")
    document.write_to(fp)
    fp.close()
Пример #9
0
def main(argv):
    gs = GS()

    sans = gs.font("FeGWitten-Bold")

    # for u, g in sans.metrics.items():
    #     print u, g.ps_name

    document = dsc_document("Hello, world!")
    page = document.page()
    canvas = page.canvas(margin=mm(18), border=True)
    canvas = canvas_with_lines(canvas, 30.0)

    # The regular say
    print >> canvas, "/%s findfont" % sans.ps_name
    print >> canvas, "20 scalefont"
    print >> canvas, "setfont"
    print >> canvas, ps_escape("Hello, world! (no Kerning at all)"), " show"
    canvas.newline()


    # Kerned say

    message = u"Hello, world! (Pair-wise Kerning on!) €  äöüÄÖÜß" # äöüÄÖÜß

    offsets = []

    sans_wrapper = page.register_font(sans)
    print >> canvas, "/%s findfont" % sans_wrapper.ps_name()
    print >> canvas, "20 scalefont"
    print >> canvas, "setfont"

    for kerning_delta in glyph_iterator(sans_wrapper, 20, message):
        offsets.append(kerning_delta)

    offsets = map(str, offsets)
    tpl = ( sans_wrapper.postscript_representation(message),
            join(offsets, " "), )
    print >> canvas, "(%s) [ %s ] xshow" % tpl

    fp = open("kerning.ps", "w")
    document.write_to(fp)
    fp.close()
Пример #10
0
def my_document(ds):
    document = dsc_document()

    dir = dirname(__file__)

    if dir == "": dir = "."

    print("Loading background", file=debug)
    background = eps_image(document, open(dir + "/conditions_background.eps", 'rb'))


    print("Loading fonts", file=debug)
    italic  = type1(open(pjoin(dir, "italic.pfb"), 'rb'),
                    open(pjoin(dir, "italic.afm"), 'rb'))

    bold    = type1(open(pjoin(dir, "bold.pfb"), 'rb'),
                    open(pjoin(dir, "bold.afm"), 'rb'))

    bolditalic = type1(open(pjoin(dir, "bolditalic.pfb"), 'rb'),
                       open(pjoin(dir, "bolditalic.afm"), 'rb'))

    # Define the relevant styles.
    h1 = style(font=bolditalic, font_size=9.2,
               color="0.98 0 0.48 0.63 setcmykcolor",
               margin_top=mm(2))

    h2 = style(font=bolditalic, font_size=8, color="0 setgray",
               margin_top=mm(2))

    description = style(font=italic, font_size=7, color="0 setgray",
               padding_top=2, padding_bottom=1, text_align="justify")

    tabelle_dunkel = style(font=italic, font_size=7, color="0 setgray",
                           background_color="1 0.24 sub setgray",
                           padding_top=2, padding_bottom=1,
                           padding_right=2)
    tabelle_hell   = style(font=italic, font_size=7, color="0 setgray",
                           background_color="1 0.12 sub setgray",
                           padding_top=2, padding_bottom=1,
                           padding_right=2)

    # Create the divs

    print("Making db requests", file=debug)
    divs = []
    pages = ds.select(schema.page, sql.order_by("rank"))
    tabcounter = 0

    for page in pages:
        ds = []
        ds.append(div(page.name, h1))

        entries = page.entries.select(sql.order_by("rank"))

        for entry in entries:
            if entry.type == "caption":
                if entry.value1 is not None and entry.value1.strip() != "":
                    ds.append(div(entry.value1, h2))

                if entry.value2 is not None and entry.value2.strip() != "":
                    ds.append(div(entry.value2, description))

            elif entry.type == "info":
                if entry.value2 is None or entry.value2.strip() == "":
                    ds.append(div(entry.value1, description))
                else:
                    cls = ( tabelle_dunkel, tabelle_hell, )[tabcounter%2]
                    tabcounter += 1
                    ds.append(lr_div(entry.value1, entry.value2, cls))

        divs.append(div_div(ds))

    # layout
    print("Starting layout process", file=debug)
    layout(divs, new_page(document, background, italic))

    return document
Пример #11
0
 def __init__(self, rinoh_document, title):
     self.rinoh_document = rinoh_document
     self.psg_doc = dsc_document(title)
Пример #12
0
 def __init__(self, rinoh_document, title):
     self.rinoh_document = rinoh_document
     self.psg_doc = dsc_document(title)
Пример #13
0
def my_document(ds):
    document = dsc_document()

    dir = dirname(__file__)

    if dir == "": dir = "."

    print("Loading background", file=debug)
    background = eps_image(document,
                           open(dir + "/conditions_background.eps", 'rb'))

    print("Loading fonts", file=debug)
    italic = type1(open(pjoin(dir, "italic.pfb"), 'rb'),
                   open(pjoin(dir, "italic.afm"), 'rb'))

    bold = type1(open(pjoin(dir, "bold.pfb"), 'rb'),
                 open(pjoin(dir, "bold.afm"), 'rb'))

    bolditalic = type1(open(pjoin(dir, "bolditalic.pfb"), 'rb'),
                       open(pjoin(dir, "bolditalic.afm"), 'rb'))

    # Define the relevant styles.
    h1 = style(font=bolditalic,
               font_size=9.2,
               color="0.98 0 0.48 0.63 setcmykcolor",
               margin_top=mm(2))

    h2 = style(font=bolditalic,
               font_size=8,
               color="0 setgray",
               margin_top=mm(2))

    description = style(font=italic,
                        font_size=7,
                        color="0 setgray",
                        padding_top=2,
                        padding_bottom=1,
                        text_align="justify")

    tabelle_dunkel = style(font=italic,
                           font_size=7,
                           color="0 setgray",
                           background_color="1 0.24 sub setgray",
                           padding_top=2,
                           padding_bottom=1,
                           padding_right=2)
    tabelle_hell = style(font=italic,
                         font_size=7,
                         color="0 setgray",
                         background_color="1 0.12 sub setgray",
                         padding_top=2,
                         padding_bottom=1,
                         padding_right=2)

    # Create the divs

    print("Making db requests", file=debug)
    divs = []
    pages = ds.select(schema.page, sql.order_by("rank"))
    tabcounter = 0

    for page in pages:
        ds = []
        ds.append(div(page.name, h1))

        entries = page.entries.select(sql.order_by("rank"))

        for entry in entries:
            if entry.type == "caption":
                if entry.value1 is not None and entry.value1.strip() != "":
                    ds.append(div(entry.value1, h2))

                if entry.value2 is not None and entry.value2.strip() != "":
                    ds.append(div(entry.value2, description))

            elif entry.type == "info":
                if entry.value2 is None or entry.value2.strip() == "":
                    ds.append(div(entry.value1, description))
                else:
                    cls = (
                        tabelle_dunkel,
                        tabelle_hell,
                    )[tabcounter % 2]
                    tabcounter += 1
                    ds.append(lr_div(entry.value1, entry.value2, cls))

        divs.append(div_div(ds))

    # layout
    print("Starting layout process", file=debug)
    layout(divs, new_page(document, background, italic))

    return document