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()
def main(): if len(sys.argv) < 3: print "Usage: %s <outline file> <metrics file>" % sys.argv[0] sys.exit(-1) margin = mm(3) font_size = 20 outline_file = open(sys.argv[1]) metrics_file = open(sys.argv[2]) # Load the font font = type1(outline_file, metrics_file) # The text to be set # text = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" text = font.full_name # Create the EPS document eps = eps_document(title=font.full_name) page = eps.page # Register the font with the document font_wrapper = page.register_font(font) # The actual string sits in its own textbox # width = the width of the string width = font.metrics.stringwidth(text, font_size) tb = textbox(page, margin, margin, width, font_size) tb.set_font(font_wrapper, font_size) tb.typeset(unicode(text, "iso-8859-1")) page.append(tb) # Page height = the height of the largest character (=font bbox height). fontbb = font.metrics.font_bounding_box() page_height = fontbb.ury * float(font_size) # scale to font size, too page_bb = bounding_box(0, 0, tb.w() + 2*margin, page_height + 2*margin) eps.header.bounding_box = page_bb.as_tuple() eps.header.hires_bounding_box = page_bb.as_tuple() eps.write_to(sys.stdout)
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
fm = open("FeGWitten-Bold.afm") from psg.fonts.type1 import type1 t = type1(None, afm)
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
def main(): if len(sys.argv) < 3: print "Usage: %s <outline file> <metrics file>" % sys.argv[0] sys.exit(-1) cellpadding = mm(1) page_margin = mm(16) font_size = 10 chars = u"""ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz äöüÄÖÜß 0123456789 !\"§$%&/()=?€@ „“ “” »«""" outline_file = open(sys.argv[1]) metrics_file = open(sys.argv[2]) # Load the font font = type1(outline_file, metrics_file) # Create the EPS document eps = eps_document(title=font.full_name) page = eps.page # Register the font with the document font_wrapper = page.register_font(font) # Ok, we got to find out a number of things: Dimensions of the cells, # dimensions of the table m = 0 for char in chars: m = max(m, font.metrics.stringwidth(char, font_size)) td_width = m + 2*cellpadding td_height = font_size + 2*cellpadding lines = map(strip, split(chars, "\n")) lines.reverse() m = 0 for line in lines: m = max(m, len(line)) cols = m rows = len(lines) table_width = cols * td_width table_height = rows * td_height # Create a canvas at the coordinates of the page_margins and width # the table's size. table = canvas(page, page_margin, page_margin, table_width, table_height, border=True) # Draw the table grid by drawing row and column boundaries. print >> table, "gsave" print >> table, "0.4 setgray [] 0.5 setdash" for a in range(1, cols): print >> table, "newpath" print >> table, "%f %f moveto" % ( a * td_width, 0, ) print >> table, "%f %f lineto" % ( a * td_width, table_height, ) print >> table, "stroke" for a in range(1, rows): print >> table, "newpath" print >> table, "%f %f moveto" % ( 0, a * td_height, ) print >> table, "%f %f lineto" % ( table_width, a * td_height, ) print >> table, "stroke" print >> table, "grestore" print >> table, "/%s findfont" % font_wrapper.ps_name() print >> table, "%f scalefont" % font_size print >> table, "setfont" for lc, line in enumerate(lines): for cc, char in enumerate(line): x = cc * td_width + cellpadding y = lc * td_height + cellpadding psrep = font_wrapper.postscript_representation(char) print >> table, "%f %f moveto" % ( x, y, ) print >> table, "(%s) show" % psrep page.append(table) page_bb = table.bounding_box() eps.header.bounding_box = page_bb.as_tuple() eps.header.hires_bounding_box = page_bb.as_tuple() eps.write_to(sys.stdout)