diff options
| author | pinky <> | 2007-01-07 21:41:39 +0000 |
|---|---|---|
| committer | pinky <> | 2007-01-07 21:41:39 +0000 |
| commit | 05bb5d58295cd959c34f1fbcd5b605cd6dafaacc (patch) | |
| tree | 3b3651037037c1617a54ef3d216e8c11ea8cdddf /bin/reportlab/tools/utils | |
| parent | 62524af2f41454a2302efb21f15a95318d257a76 (diff) | |
Repotrlab 2.0
bzr revid: pinky-b8333ccaab5dad8ff965b6c380fadadf30d5212a
Diffstat (limited to 'bin/reportlab/tools/utils')
| -rw-r--r-- | bin/reportlab/tools/utils/add_bleed.py | 28 | ||||
| -rw-r--r-- | bin/reportlab/tools/utils/dumpttf.py | 60 |
2 files changed, 88 insertions, 0 deletions
diff --git a/bin/reportlab/tools/utils/add_bleed.py b/bin/reportlab/tools/utils/add_bleed.py new file mode 100644 index 00000000000..ab4a7824628 --- /dev/null +++ b/bin/reportlab/tools/utils/add_bleed.py @@ -0,0 +1,28 @@ +#How to add bleed to a page in this case 6mm to a landscape A4 +from reportlab.lib import units, pagesizes +from reportlab.pdfgen.canvas import Canvas +import sys, os, glob, time +bleedX = 6*units.mm +bleedY = 6*units.mm +pageWidth, pageHeight = pagesizes.landscape(pagesizes.A4) +def process_pdf(c,infn,prefix='PageForms'): + from rlextra.pageCatcher import pageCatcher + names, data = pageCatcher.storeFormsInMemory(open(infn,'rb').read(),prefix=prefix,all=1) + names = pageCatcher.restoreFormsInMemory(data,c) + del data + for i in xrange(len(names)): + thisname = names[i] + c.saveState() + c.translate(bleedX,bleedY) + c.doForm(thisname) + c.restoreState() + c.showPage() + +def main(): + for infn in sys.argv[1:]: + outfn = 'bleeding_'+os.path.basename(infn) + c = Canvas(outfn,pagesize=(pageWidth+2*bleedX,pageHeight+2*bleedY)) + process_pdf(c,infn) + c.save() +if __name__=='__main__': + main() diff --git a/bin/reportlab/tools/utils/dumpttf.py b/bin/reportlab/tools/utils/dumpttf.py new file mode 100644 index 00000000000..8cb4610c5af --- /dev/null +++ b/bin/reportlab/tools/utils/dumpttf.py @@ -0,0 +1,60 @@ +__all__=('dumpttf',) +def dumpttf(fn,fontName=None, verbose=0): + '''dump out known glyphs from a ttf file''' + import os + if not os.path.isfile(fn): + raise IOError('No such file "%s"' % fn) + from reportlab.pdfbase.pdfmetrics import registerFont, stringWidth + from reportlab.pdfbase.ttfonts import TTFont + from reportlab.pdfgen.canvas import Canvas + if fontName is None: + fontName = os.path.splitext(os.path.basename(fn))[0] + dmpfn = '%s-ttf-dump.pdf' % fontName + ttf = TTFont(fontName, fn) + K = ttf.face.charToGlyph.keys() + registerFont(ttf) + c = Canvas(dmpfn) + W,H = c._pagesize + titleFontSize = 30 # title font size + titleFontName = 'Helvetica' + labelFontName = 'Courier' + fontSize = 10 + border = 36 + dx0 = stringWidth('12345: ', fontName, fontSize) + dx = dx0+20 + dy = 20 + K.sort() + y = 0 + page = 0 + for i, k in enumerate(K): + if y<border: + if page: c.showPage() + page += 1 + y = H - border - titleFontSize + c.setFont(titleFontName, titleFontSize) + c.drawCentredString(W/2.0,y, 'TrueType Font %s Page %d' %(fontName,page)) + y -= 0.2*titleFontSize + dy + x = border + c.setFont(labelFontName, 10) + c.drawString(x,y,'%5.5x:' % k ) + c.setFont(fontName, 10) + c.drawString(x+dx0,y,unichr(k).encode('utf8')) + x += dx + if x+dx>W-border: + x = border + y -= dy + c.showPage() + c.save() + if verbose: + print 'Font %s("%s") has %d glyphs\ndumped to "%s"' % (fontName,fn,len(K),dmpfn) + +if __name__=='__main__': + import sys, glob + if '--verbose' in sys.argv: + sys.argv.remove('--verbose') + verbose = 1 + else: + verbose = 0 + for a in sys.argv[1:]: + for fn in glob.glob(a): + dumpttf(fn, verbose=verbose) |
