本文整理汇总了Python中reportlab.lib.utils.rl_isfile函数的典型用法代码示例。如果您正苦于以下问题:Python rl_isfile函数的具体用法?Python rl_isfile怎么用?Python rl_isfile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rl_isfile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: findT1File
def findT1File(self, ext='.pfb'):
possible_exts = (ext.lower(), ext.upper())
if hasattr(self,'pfbFileName'):
r_basename = os.path.splitext(self.pfbFileName)[0]
for e in possible_exts:
if rl_isfile(r_basename + e):
return r_basename + e
try:
r = _fontdata.findT1File(self.name)
except:
afm = bruteForceSearchForAFM(self.name)
if afm:
if ext.lower() == '.pfb':
for e in possible_exts:
pfb = os.path.splitext(afm)[0] + e
if rl_isfile(pfb):
r = pfb
else:
r = None
elif ext.lower() == '.afm':
r = afm
else:
r = None
if r is None:
warnOnce("Can't find %s for face '%s'" % (ext, self.name))
return r
示例2: test2
def test2(self):
"try under a well known directory NOT on the path"
from reportlab.lib.testutils import testsFolder
D = os.path.join(testsFolder,'..','tools','pythonpoint')
fn = os.path.join(D,'stdparser.py')
if rl_isfile(fn) or rl_isfile(fn+'c') or rl_isfile(fn+'o'):
m1 = recursiveImport('stdparser', baseDir=D)
示例3: getTypeFace
def getTypeFace(faceName):
"""Lazily construct known typefaces if not found"""
try:
return _typefaces[faceName]
except KeyError:
# not found, construct it if known
if faceName in standardFonts:
face = TypeFace(faceName)
(face.familyName, face.bold, face.italic) = _fontdata.standardFontAttributes[faceName]
registerTypeFace(face)
## print 'auto-constructing type face %s with family=%s, bold=%d, italic=%d' % (
## face.name, face.familyName, face.bold, face.italic)
return face
else:
#try a brute force search
afm = bruteForceSearchForAFM(faceName)
if afm:
for e in ('.pfb', '.PFB'):
pfb = os.path.splitext(afm)[0] + e
if rl_isfile(pfb): break
assert rl_isfile(pfb), 'file %s not found!' % pfb
face = EmbeddedType1Face(afm, pfb)
registerTypeFace(face)
return face
else:
raise
示例4: test2
def test2(self):
"try under a well known directory NOT on the path"
from reportlab.lib.testutils import testsFolder
D = os.path.join(testsFolder, "..", "tools", "pythonpoint")
fn = os.path.join(D, "stdparser.py")
if rl_isfile(fn) or rl_isfile(fn + "c") or rl_isfile(fn + "o"):
m1 = recursiveImport("stdparser", baseDir=D)
示例5: bruteForceSearchForFile
def bruteForceSearchForFile(fn,searchPath=None):
if searchPath is None: from reportlab.rl_config import T1SearchPath as searchPath
if rl_isfile(fn): return fn
bfn = os.path.basename(fn)
for dirname in searchPath:
if not rl_isdir(dirname): continue
tfn = os.path.join(dirname,bfn)
if rl_isfile(tfn): return tfn
return fn
示例6: _processPackageDir
def _processPackageDir(p,dn,P,allowCompiled=True):
if _ofile: print('searching package', p, 'dn=',dn, file=_ofile)
from reportlab.lib.utils import rl_glob, rl_isfile, rl_isdir, isCompactDistro
if isCompactDistro():
ext = '.pyc'
init = '__init__'+ext
FN = [normpath(x) for x in rl_glob(path_join(dn,'*'))]
D = []
dn = normpath(dn)
for x in FN:
x = path_dirname(x)
if x not in D and rl_isdir(x) and path_dirname(x)==dn and rl_isfile(path_join(x,init)): D.append(x)
F = [x for x in FN if x.endswith(ext) and path_dirname(x)==dn and not path_basename(x).startswith('__init__.')]
else:
ext = '.py'
init = '__init__'+ext
FN = [path_join(dn,x) for x in os.listdir(dn)]
D = [x for x in FN if path_isdir(x) and isPyFile(path_join(x,init))]
F = [x for x in FN if (x.endswith(ext) or (allowCompiled and (x.endswith(ext+'c') or x.endswith(ext+'o')))) and not path_basename(x).startswith('__init__.')]
for f in F:
mn = path_splitext(path_basename(f))[0]
if p: mn = p+'.'+mn
if mn not in P:
if _ofile: print('appending 1',mn, file=_ofile)
P.append(mn)
for f in D:
mn = p+('.'+path_basename(f))
if mn not in P:
if _ofile: print('appending 2',mn, file=_ofile)
P.append(mn)
示例7: _searchT1Dirs
def _searchT1Dirs(n, rl_isfile=rl_isfile, T1SearchPath=T1SearchPath):
assert T1SearchPath != [], "No Type-1 font search path"
for d in T1SearchPath:
f = os.path.join(d, n)
if rl_isfile(f):
return f
return None
示例8: eoCB
def eoCB(s,targets=targets,dtdDirs=dtdDirs):
from reportlab.lib.utils import open_and_read, rl_isfile
bn = os.path.basename(s)
if bn in targets:
for d in dtdDirs:
fn = os.path.join(d,bn)
if rl_isfile(fn): return fn, open_and_read(fn,'t')
return s
示例9: validate
def validate(rawdata):
global _pyRXP_Parser
if not _pyRXP_Parser:
try:
import pyRXP
except ImportError:
return
from reportlab.lib.utils import open_and_read, rl_isfile
dtd = 'pythonpoint.dtd'
if not rl_isfile(dtd):
dtd = os.path.join(toolsDir(),'pythonpoint','pythonpoint.dtd')
if not rl_isfile(dtd): return
def eocb(URI,dtdText=open_and_read(dtd),dtd=dtd):
if os.path.basename(URI)=='pythonpoint.dtd': return dtd,dtdText
return URI
_pyRXP_Parser = pyRXP.Parser(eoCB=eocb)
return _pyRXP_Parser.parse(rawdata)
示例10: test
def test(self):
import reportlab.test
from reportlab.lib.utils import rl_isfile
imageFileName = os.path.dirname(reportlab.test.__file__) + os.sep + 'pythonpowered.gif'
assert rl_isfile(imageFileName), "%s not found!" % imageFileName
ir = ImageReader(imageFileName)
assert ir.getSize() == (110,44)
pixels = ir.getRGBData()
assert md5.md5(pixels).hexdigest() == '02e000bf3ffcefe9fc9660c95d7e27cf'
示例11: _loadGlyphs
def _loadGlyphs(self, pfbFileName):
"""Loads in binary glyph data, and finds the four length
measurements needed for the font descriptor"""
assert rl_isfile(pfbFileName), 'file %s not found' % pfbFileName
d = open_and_read(pfbFileName, 'b')
s1, l1 = _pfbCheck(0,d,PFB_ASCII,pfbFileName)
s2, l2 = _pfbCheck(l1,d,PFB_BINARY,pfbFileName)
s3, l3 = _pfbCheck(l2,d,PFB_ASCII,pfbFileName)
_pfbCheck(l3,d,PFB_EOF,pfbFileName)
self._binaryData = d[s1:l1]+d[s2:l2]+d[s3:l3]
self._length = len(self._binaryData)
self._length1 = l1-s1
self._length2 = l2-s2
self._length3 = l3-s3
示例12: TTFOpenFile
def TTFOpenFile(fn):
'''Opens a TTF file possibly after searching TTFSearchPath
returns (filename,file)
'''
from reportlab.lib.utils import rl_isfile, open_for_read
try:
f = open_for_read(fn,'rb')
return fn, f
except IOError:
import os
if not os.path.isabs(fn):
for D in rl_config.TTFSearchPath:
tfn = os.path.join(D,fn)
if rl_isfile(tfn):
f = open_for_read(tfn,'rb')
return tfn, f
raise TTFError('Can\'t open file "%s"' % fn)
示例13: rl_isfile
from reportlab.test import unittest
from reportlab.test.utils import makeSuiteForClasses, outputfile
from reportlab.pdfgen import canvas
from reportlab import platypus
from reportlab.platypus import BaseDocTemplate, PageTemplate, Flowable, FrameBreak
from reportlab.platypus import Paragraph, Preformatted
from reportlab.lib.units import inch, cm
from reportlab.lib.styles import PropertySet, getSampleStyleSheet, ParagraphStyle
from reportlab.lib import colors
from reportlab.rl_config import defaultPageSize
from reportlab.lib.utils import haveImages, _RL_DIR, rl_isfile, open_for_read
if haveImages:
_GIF = os.path.join(_RL_DIR,'test','pythonpowered.gif')
if not rl_isfile(_GIF): _GIF = None
else:
_GIF = None
_JPG = os.path.join(_RL_DIR,'docs','images','lj8100.jpg')
if not rl_isfile(_JPG): _JPG = None
def getFurl(fn):
furl = fn.replace(os.sep,'/')
if sys.platform=='win32' and furl[1]==':': furl = furl[0]+'|'+furl[2:]
if furl[0]!='/': furl = '/'+furl
return 'file://'+furl
PAGE_HEIGHT = defaultPageSize[1]
#################################################################
#
示例14: test2
def test2(self):
"try under a well known directory NOT on the path"
D = os.path.join(os.path.dirname(reportlab.__file__), "tools", "pythonpoint")
fn = os.path.join(D, "stdparser.py")
if rl_isfile(fn) or rl_isfile(fn + "c") or rl_isfile(fn + "o"):
m1 = recursiveImport("stdparser", baseDir=D)
示例15: makeDocument
#.........这里部分代码省略.........
c.drawText(t)
#now reset canvas to get rid of the clipping mask
c.restoreState()
c.showPage()
#########################################################################
#
# Page 7 - images
#
#########################################################################
framePage(c, "Images")
c.setFont('Times-Roman', 12)
t = c.beginText(inch, 10 * inch)
if not haveImages:
c.drawString(inch, 11*inch,
"Python Imaging Library not found! Below you see rectangles instead of images.")
t.textLines("""PDFgen uses the Python Imaging Library to process a very wide variety of image formats.
This page shows image capabilities. If I've done things right, the bitmap should have
its bottom left corner aligned with the crosshairs.
There are two methods for drawing images. The recommended use is to call drawImage.
This produces the smallest PDFs and the fastest generation times as each image's binary data is
only embedded once in the file. Also you can use advanced features like transparency masks.
You can also use drawInlineImage, which puts images in the page stream directly.
This is slightly faster for Acrobat to render or for very small images, but wastes
space if you use images more than once.""")
c.drawText(t)
gif = os.path.join(_RL_DIR,'test','pythonpowered.gif')
if haveImages and rl_isfile(gif):
c.drawInlineImage(gif,2*inch, 7*inch)
else:
c.rect(2*inch, 7*inch, 110, 44)
c.line(1.5*inch, 7*inch, 4*inch, 7*inch)
c.line(2*inch, 6.5*inch, 2*inch, 8*inch)
c.drawString(4.5 * inch, 7.25*inch, 'inline image drawn at natural size')
if haveImages and rl_isfile(gif):
c.drawInlineImage(gif,2*inch, 5*inch, inch, inch)
else:
c.rect(2*inch, 5*inch, inch, inch)
c.line(1.5*inch, 5*inch, 4*inch, 5*inch)
c.line(2*inch, 4.5*inch, 2*inch, 6*inch)
c.drawString(4.5 * inch, 5.25*inch, 'inline image distorted to fit box')
c.drawString(1.5 * inch, 4*inch, 'Image XObjects can be defined once in the file and drawn many times.')
c.drawString(1.5 * inch, 3.75*inch, 'This results in faster generation and much smaller files.')
for i in range(5):
if haveImages:
(w, h) = c.drawImage(gif, (1.5 + i)*inch, 3*inch)
else:
c.rect((1.5 + i)*inch, 3*inch, 110, 44)
myMask = [254,255,222,223,0,1]
c.drawString(1.5 * inch, 2.5*inch, "The optional 'mask' parameter lets you define transparent colors. We used a color picker")
c.drawString(1.5 * inch, 2.3*inch, "to determine that the yellow in the image above is RGB=(225,223,0). We then define a mask")
c.drawString(1.5 * inch, 2.1*inch, "spanning these RGB values: %s. The background vanishes!!" % myMask)
c.drawString(2.5*inch, 1.2*inch, 'This would normally be obscured')
if haveImages: