def main(argv): document = dsc_document("My first textbox example and testbed") page = document.page() canvas = page.canvas(margin=mm(18), border=False) tr = cmu.serif_roman() tr = page.register_font(tr) he = cmu.sansserif() 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(): document = dsc_document() dir = op.dirname(__file__) if dir == "": dir = "." regular = type1(open(op.join(dir, "regular.pfb")), open(op.join(dir, "regular.afm"))) bold = type1(open(op.join(dir, "bold.pfb")), open(op.join(dir, "bold.afm"))) ue = style(font=bold, font_size=15, color="0 setgray", border_color=colors.rgb(1,0,0), name="ue") ga = style(font=regular, font_size=10, color="0 setgray", name="ga") section_fringes = style( margin_bottom=10, name="section_fringes") text = lorem_ipsum.ipsum paragraphs = split(text, "\n\n") paragraphs = map(strip, paragraphs) paragraphs = map(lambda s: splitfields(s), paragraphs) for counter, p in enumerate(paragraphs): p.insert(0, unicode(str(counter+1))) #sections = map(lambda words: paragraph(words, ga), paragraphs) def make_paragraph(words): header = words[:6] return fringes(section_fringes, headed_section( paragraph(ue, header), paragraph(ga, words), paragraph(ue, header + [u"(cont.)"]) )) sections = [] image = Image.open("dog.jpg") sections.append(simple_raster_image(image)) sections += map(make_paragraph, paragraphs) t = time.time() run_the_engine(column_factory(document), sections.__iter__()) print time.time() - t document.write_to(open("out.ps", "w"))
def main(argv): gs = GS() if len(sys.argv) < 3: print "Usage: %s <outline file> <metrics file>" % sys.argv[0] sys.exit(-1) outline_file = open(sys.argv[1]) metrics_file = open(sys.argv[2]) # Load the font font = type1(outline_file, metrics_file) #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" % font.ps_name print >> canvas, "20 scalefont" print >> canvas, "setfont" print >> canvas, ps_escape(u"Hello, world! with no Kerning at all") print >> canvas, " show" canvas.newline() # Kerned say message = u"Hello, world! (Pair-wise Kerning on!) € äöüÄÖÜß" # äöüÄÖÜß offsets = [] font_wrapper = page.register_font(font) print >> canvas, "/%s findfont" % font_wrapper.ps_name() print >> canvas, "20 scalefont" print >> canvas, "setfont" for kerning_delta in glyph_iterator(font_wrapper, 20, message): offsets.append(kerning_delta) offsets = map(str, offsets) tpl = ( font_wrapper.postscript_representation(message), join(offsets, " "), ) print >> canvas, "(%s) [ %s ] xshow" % tpl fp = open("kerning.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 = unicode(font.full_name) + u" € üäöÜÄÖß" # 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) font_wrapper = eps.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+5, font_size) tb.set_font(font_wrapper, font_size) tb.typeset(text) 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 >> debug, "Loading background" background = eps_image(document, open(dir + "/conditions_background.eps")) print >> debug, "Loading fonts" italic = type1(open(pjoin(dir, "italic.pfb")), open(pjoin(dir, "italic.afm"))) bold = type1(open(pjoin(dir, "bold.pfb")), open(pjoin(dir, "bold.afm"))) bolditalic = type1(open(pjoin(dir, "bolditalic.pfb")), open(pjoin(dir, "bolditalic.afm"))) # 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 >> debug, "Making db requests" divs = [] pages = ds.select(schema.page) tabcounter = 0 for page in pages: ds = [] ds.append(div(page.name, h1)) entries = page.entries.select() for entry in entries: if entry.type == "caption": if entry.value1 is not None and strip(entry.value1) != "": ds.append(div(entry.value1, h2)) if entry.value2 is not None and strip(entry.value2) != "": ds.append(div(entry.value2, description)) elif entry.type == "info": if entry.value2 is None or strip(entry.value2) == "": 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 >> debug, "Starting layout process" layout(divs, new_page(document, background, italic)) return document
def main(): document = dsc_document() dir = op.dirname(__file__) if dir == "": dir = "." regular = type1(open(op.join(dir, "regular.pfb")), open(op.join(dir, "regular.afm"))) bold = type1(open(op.join(dir, "bold.pfb")), open(op.join(dir, "bold.afm"))) ue = engine.style(font=bold, font_size=15, color="0 setgray", border_color=colors.rgb(1,0,0), name="ue") ga = engine.style(font=regular, font_size=10, color="0 setgray", name="ga") head_style = engine.style(background_color = colors.grey(0.5), margin_bottom=10) table_style = engine.style(margin_bottom=10, border = (0.5, 0.5, 0.5, 0.5,), border_color = colors.grey(0), #background_color=colors.gray(0.5) ) row_style = engine.style() cell_style = engine.style(border = (0.5, 0.5, 0.5, 0.5,), border_color = colors.grey(0), padding = (10,10,10,10), #background_color=grey(0.5) ) table = engine.table( table_style, ( mm(20), mm(20), ), engine.row(head_style, engine.cell(cell_style, engine.simple_paragraph(ga, [u"Links"])), engine.cell(cell_style, engine.simple_paragraph(ga, [u"Rechts"])))) for a in range(50): table.append(engine.row(row_style, engine.cell(cell_style + bg(0), engine.simple_paragraph(ga, [str(a)])), engine.cell(cell_style + bg(1), engine.simple_paragraph(ga, str(a*2))))) table2 = engine.table( table_style, ( mm(20), ), None, engine.row(row_style, engine.cell(cell_style + bg(4), engine.simple_paragraph(ga, [u"Stephi",])))) p = engine.paragraph(cell_style + ga + bg(3) + engine.style(margin_top=30), [u"Hello", u"World!"]) sections = [table, table2, p] t = time.time() engine.run_the_engine(column_factory(document), sections.__iter__()) print time.time() - t document.write_to(open("out.ps", "w"))
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)