本文整理汇总了Python中reportlab.lib.rl_accel.fp_str函数的典型用法代码示例。如果您正苦于以下问题:Python fp_str函数的具体用法?Python fp_str怎么用?Python fp_str使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fp_str函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _issueT1String
def _issueT1String(self,fontObj,x,y,s):
fc = fontObj
code_append = self.code_append
fontSize = self._fontSize
fontsUsed = self._fontsUsed
escape = self._escape
if not isUnicode(s):
try:
s = s.decode('utf8')
except UnicodeDecodeError as e:
i,j = e.args[2:4]
raise UnicodeDecodeError(*(e.args[:4]+('%s\n%s-->%s<--%s' % (e.args[4],s[i-10:i],s[i:j],s[j:j+10]),)))
for f, t in unicode2T1(s,[fontObj]+fontObj.substitutionFonts):
if f!=fc:
psName = asNative(f.face.name)
code_append('(%s) findfont %s scalefont setfont' % (psName,fp_str(fontSize)))
if psName not in fontsUsed:
fontsUsed.append(psName)
fc = f
code_append('%s m (%s) show ' % (fp_str(x,y),escape(t)))
x += f.stringWidth(t.decode(f.encName),fontSize)
if fontObj!=fc:
self._font = None
self.setFont(fontObj.face.name,fontSize)
开发者ID:CometHale,项目名称:lphw,代码行数:25,代码来源:renderPS.py
示例2: setFillColor
def setFillColor(self, aColor, alpha=None):
"""Takes a color object, allowing colors to be referred to by name"""
if self._enforceColorSpace:
aColor = self._enforceColorSpace(aColor)
if isinstance(aColor, CMYKColor):
d = aColor.density
c,m,y,k = (d*aColor.cyan, d*aColor.magenta, d*aColor.yellow, d*aColor.black)
self._fillColorObj = aColor
name = self._checkSeparation(aColor)
if name:
self._code.append('/%s cs %s scn' % (name,fp_str(d)))
else:
self._code.append('%s k' % fp_str(c, m, y, k))
elif isinstance(aColor, Color):
rgb = (aColor.red, aColor.green, aColor.blue)
self._fillColorObj = aColor
self._code.append('%s rg' % fp_str(rgb) )
elif isinstance(aColor,(tuple,list)):
l = len(aColor)
if l==3:
self._fillColorObj = aColor
self._code.append('%s rg' % fp_str(aColor) )
elif l==4:
self._fillColorObj = aColor
self._code.append('%s k' % fp_str(aColor))
else:
raise ValueError('Unknown color %r' % aColor)
elif isStr(aColor):
self.setFillColor(toColor(aColor))
else:
raise ValueError('Unknown color %r' % aColor)
if alpha is not None:
self.setFillAlpha(alpha)
elif getattr(aColor, 'alpha', None) is not None:
self.setFillAlpha(aColor.alpha)
开发者ID:abdounasser202,项目名称:Achouka,代码行数:35,代码来源:textobject.py
示例3: setColor
def setColor(self, color):
if self._color!=color:
self._color = color
if color:
if hasattr(color, "cyan"):
self.code_append('%s setcmykcolor' % fp_str(color.cyan, color.magenta, color.yellow, color.black))
else:
self.code_append('%s setrgbcolor' % fp_str(color.red, color.green, color.blue))
开发者ID:CometHale,项目名称:lphw,代码行数:8,代码来源:renderPS.py
示例4: __repr__
def __repr__(self):
return "%s(%s%s%s%s%s)" % (self.__class__.__name__,
fp_str(self.cyan*100, self.magenta*100, self.yellow*100, self.black*100).replace(' ',','),
(self.spotName and (',spotName='+repr(self.spotName)) or ''),
(self.density!=1 and (',density='+fp_str(self.density*100)) or ''),
(self.knockout is not None and (',knockout=%d' % self.knockout) or ''),
(self.alpha is not None and (',alpha=%s' % (fp_str(self.alpha*100))) or ''),
)
开发者ID:pavgup,项目名称:ubertool_cts,代码行数:8,代码来源:colors.py
示例5: setTextOrigin
def setTextOrigin(self, x, y):
if self._canvas.bottomup:
self._code.append('1 0 0 1 %s Tm' % fp_str(x, y)) #bottom up
else:
self._code.append('1 0 0 -1 %s Tm' % fp_str(x, y)) #top down
# The current cursor position is at the text origin
self._x0 = self._x = x
self._y0 = self._y = y
开发者ID:abdounasser202,项目名称:Achouka,代码行数:9,代码来源:textobject.py
示例6: lines
def lines(self, lineList, color=None, width=None):
# print "### lineList", lineList
return
if self._strokeColor != None:
self._setColor(self._strokeColor)
codeline = '%s m %s l stroke'
for line in lineList:
self.code.append(codeline % (fp_str(line[0]), fp_str(line[1])))
开发者ID:Aeium,项目名称:dotStudio,代码行数:9,代码来源:renderSVG.py
示例7: ttf2ps
def ttf2ps(font, doc):
"""
create analytic fonts for inclusion in a postscript document
"""
state = font._assignState(doc,asciiReadable=False,namePrefix='.RLF')
state.frozen = 1
PS = []
unitsPerEm = font.face.unitsPerEm
scale = lambda x: int(x*unitsPerEm/1000. + 0.1)
_fontBBox = list(map(scale,font.face.bbox))
fontBBox = fp_str(*_fontBBox)
for i,subset in enumerate(state.subsets):
n = len(subset)
psName = font.getSubsetInternalName(i,doc)[1:]
metrics = []
bboxes = []
chardefs = []
charmaps = []
nglyphs = 0
for c in range(n):
g = subset[c]
if g==32 and g!=c: continue
u = uniChr(g).encode('utf8')
try:
P = u2P(font,u)
except:
P = []
nglyphs += 1
#if c==0 and g==0:
# P=[('moveTo', 30, 1473), ('lineTo', 30, 0), ('lineTo', 603, 0),('lineTo',603,1473), 'closePath',('moveTo',40,1463),('lineTo',593,1463),('lineTo',593,10),('lineTo',40,10),'closePath']
#else:
# continue
gn = glyphName(c)
if g==0 and c==0:
uw = 633
else:
uw = font.stringWidth(u,unitsPerEm)
if P:
bb = definePath(P).getBounds()
else:
bb = [0,0,uw,0]
bboxes.append('/%s [%s] def' % (gn,fp_str(*bb)))
metrics.append('/%s %s def' % (gn, fp_str(uw)))
chardefs.append(P2PSDef(c,P))
charmaps.append(char2glyph(c,c==n-1))
if nglyphs<=0: continue
metrics = '\n'.join(metrics)
chardefs = '\n'.join(chardefs)
charmaps = '\n'.join(charmaps)
bboxes = '\n'.join(bboxes)
uid = rl_config.eps_ttf_embed_uid and getUID(doc,metrics+chardefs+charmaps+bboxes+str(unitsPerEm)+fontBBox) or ''
PS.append(_template % locals())
return '\n'.join(PS)
del font.state[doc]
开发者ID:AndyKovv,项目名称:hostel,代码行数:55,代码来源:ttf2ps.py
示例8: drawCurve
def drawCurve(self, x1, y1, x2, y2, x3, y3, x4, y4, closed=0):
codeline = '%s m %s curveto'
data = (fp_str(x1, y1), fp_str(x2, y2, x3, y3, x4, y4))
if self._fillColor != None:
self.setColor(self._fillColor)
self.code_append((codeline % data) + ' eofill')
if self._strokeColor != None:
self.setColor(self._strokeColor)
self.code_append((codeline % data)
+ ((closed and ' closepath') or '')
+ ' stroke')
开发者ID:CometHale,项目名称:lphw,代码行数:11,代码来源:renderPS.py
示例9: polygon
def polygon(self, p, closed=0, stroke=1, fill=1):
assert len(p) >= 2, 'Polygon must have 2 or more points'
start = p[0]
p = p[1:]
poly = []
a = poly.append
a("%s m" % fp_str(start))
for point in p:
a("%s l" % fp_str(point))
if closed:
a("closepath")
self._fillAndStroke(poly,stroke=stroke,fill=fill)
开发者ID:CometHale,项目名称:lphw,代码行数:15,代码来源:renderPS.py
示例10: setFont
def setFont(self, psfontname, size, leading = None):
"""Sets the font. If leading not specified, defaults to 1.2 x
font size. Raises a readable exception if an illegal font
is supplied. Font names are case-sensitive! Keeps track
of font anme and size for metrics."""
self._fontname = psfontname
self._fontsize = size
if leading is None:
leading = size * 1.2
self._leading = leading
font = pdfmetrics.getFont(self._fontname)
if font._dynamicFont:
self._curSubset = -1
else:
pdffontname = self._canvas._doc.getInternalFontName(psfontname)
self._code.append('%s %s Tf %s TL' % (pdffontname, fp_str(size), fp_str(leading)))
开发者ID:abdounasser202,项目名称:Achouka,代码行数:16,代码来源:textobject.py
示例11: _rgbFind
def _rgbFind(self,color):
"see if it matches any existing color in my list"
C = self.cmykColors
if isinstance(color,(list,tuple)):
if len(color)==3: color = Color(color[0],color[1],color[2])
elif len(color)==4: color = CMYKColor(color[0],color[1],color[2],color[3])
else: raise ValueError("bad color %s"%repr(color))
isCMYK = isinstance(color, CMYKColor)
if not isCMYK:
if isinstance(color,str):
color = toColor(color)
if colorDistance(color,black)<1e-8:
isCMYK = 1
color = PCMYKColor(0,0,0,100,100)
elif colorDistance(color,white)<1e-8:
isCMYK = 1
color = PCMYKColor(0,0,0,0,100)
rgb = color.red, color.green, color.blue
if isCMYK:
if color not in C: C.append(color)
return self._setCMYKColor(color)
else:
for c in C:
if (c.red, c.green, c.blue) == rgb:
return self._setCMYKColor(c)
return '%s setrgbcolor' % fp_str(rgb)
开发者ID:AndyKovv,项目名称:hostel,代码行数:27,代码来源:renderPS_SEP.py
示例12: drawInlineImage
def drawInlineImage(self, canvas, preserveAspectRatio=False,anchor='sw'):
"""Draw an Image into the specified rectangle. If width and
height are omitted, they are calculated from the image size.
Also allow file names as well as images. This allows a
caching mechanism"""
width = self.width
height = self.height
if width<1e-6 or height<1e-6: return False
x,y,self.width,self.height, scaled = aspectRatioFix(preserveAspectRatio,anchor,self.x,self.y,width,height,self.imgwidth,self.imgheight)
# this says where and how big to draw it
if not canvas.bottomup: y = y+height
canvas._code.append('q %s 0 0 %s cm' % (fp_str(self.width), fp_str(self.height, x, y)))
# self._code.extend(imagedata) if >=python-1.5.2
for line in self.imageData:
canvas._code.append(line)
canvas._code.append('Q')
return True
开发者ID:AlonsoAyelen,项目名称:Voluntariado_veterinaria,代码行数:17,代码来源:pdfimages.py
示例13: drawString
def drawString(self, x, y, s, angle=0):
if self._fillColor != None:
fontObj = getFont(self._font)
if not self.code[self._fontCodeLoc]:
psName = asNative(fontObj.face.name)
self.code[self._fontCodeLoc]='(%s) findfont %s scalefont setfont' % (psName,fp_str(self._fontSize))
if psName not in self._fontsUsed:
self._fontsUsed.append(psName)
self.setColor(self._fillColor)
if angle!=0:
self.code_append('gsave %s translate %s rotate' % (fp_str(x,y),fp_str(angle)))
x = y = 0
if fontObj._dynamicFont:
s = self._escape(s)
self.code_append('%s m (%s) show ' % (fp_str(x,y),s))
else:
self._issueT1String(fontObj,x,y,s)
if angle!=0:
self.code_append('grestore')
开发者ID:CometHale,项目名称:lphw,代码行数:19,代码来源:renderPS.py
示例14: _setCMYKColor
def _setCMYKColor(self,c):
KO = getattr(c,'knockout',None)
if KO is None: KO = getattr(rl_config,'PS_SEP_KNOCKOUT',1)
over = KO and 'false' or 'true'
spotName = getattr(c,'spotName',None)
if spotName:
return '%s (%s) 0\n/tint exch def\nfindcmykcustomcolor %s setoverprint\ntint %s exch sub setcustomcolor' % (fp_str(c.cmyk()),spotName,over,c._density_str())
else:
d = c.density
return '%s setcmykcolor %s setoverprint' % (fp_str(c.cyan*d,c.magenta*d,c.yellow*d,c.black*d),over)
开发者ID:AndyKovv,项目名称:hostel,代码行数:10,代码来源:renderPS_SEP.py
示例15: _formatText
def _formatText(self, text):
"Generates PDF text output operator(s)"
if log2vis and self.direction in ('LTR','RTL'):
# Use pyfribidi to write the text in the correct visual order.
text = log2vis(text, directionsMap.get(self.direction.upper(),DIR_ON),clean=True)
canv = self._canvas
font = pdfmetrics.getFont(self._fontname)
R = []
if font._dynamicFont:
#it's a truetype font and should be utf8. If an error is raised,
for subset, t in font.splitString(text, canv._doc):
if subset!=self._curSubset:
pdffontname = font.getSubsetInternalName(subset, canv._doc)
R.append("%s %s Tf %s TL" % (pdffontname, fp_str(self._fontsize), fp_str(self._leading)))
self._curSubset = subset
R.append("(%s) Tj" % canv._escape(t))
elif font._multiByte:
#all the fonts should really work like this - let them know more about PDF...
R.append("%s %s Tf %s TL" % (
canv._doc.getInternalFontName(font.fontName),
fp_str(self._fontsize),
fp_str(self._leading)
))
R.append("(%s) Tj" % font.formatForPdf(text))
else:
#convert to T1 coding
fc = font
if isBytes(text):
try:
text = text.decode('utf8')
except UnicodeDecodeError as e:
i,j = e.args[2:4]
raise UnicodeDecodeError(*(e.args[:4]+('%s\n%s-->%s<--%s' % (e.args[4],text[max(i-10,0):i],text[i:j],text[j:j+10]),)))
for f, t in pdfmetrics.unicode2T1(text,[font]+font.substitutionFonts):
if f!=fc:
R.append("%s %s Tf %s TL" % (canv._doc.getInternalFontName(f.fontName), fp_str(self._fontsize), fp_str(self._leading)))
fc = f
R.append("(%s) Tj" % canv._escape(t))
if font!=fc:
R.append("%s %s Tf %s TL" % (canv._doc.getInternalFontName(self._fontname), fp_str(self._fontsize), fp_str(self._leading)))
return ' '.join(R)
开发者ID:abdounasser202,项目名称:Achouka,代码行数:42,代码来源:textobject.py
示例16: drawFigure
def drawFigure(self, partList, closed=0):
figureCode = []
a = figureCode.append
first = 1
for part in partList:
op = part[0]
args = list(part[1:])
if op == figureLine:
if first:
first = 0
a("%s m" % fp_str(args[:2]))
else:
a("%s l" % fp_str(args[:2]))
a("%s l" % fp_str(args[2:]))
elif op == figureArc:
first = 0
x1,y1,x2,y2,startAngle,extent = args[:6]
a(self._genArcCode(x1,y1,x2,y2,startAngle,extent))
elif op == figureCurve:
if first:
first = 0
a("%s m" % fp_str(args[:2]))
else:
a("%s l" % fp_str(args[:2]))
a("%s curveto" % fp_str(args[2:]))
else:
raise TypeError("unknown figure operator: "+op)
if closed:
a("closepath")
self._fillAndStroke(figureCode)
开发者ID:CometHale,项目名称:lphw,代码行数:35,代码来源:renderPS.py
示例17: setTextTransform
def setTextTransform(self, a, b, c, d, e, f):
"Like setTextOrigin, but does rotation, scaling etc."
if not self._canvas.bottomup:
c = -c #reverse bottom row of the 2D Transform
d = -d
self._code.append('%s Tm' % fp_str(a, b, c, d, e, f))
# The current cursor position is at the text origin Note that
# we aren't keeping track of all the transform on these
# coordinates: they are relative to the rotations/sheers
# defined in the matrix.
self._x0 = self._x = e
self._y0 = self._y = f
开发者ID:abdounasser202,项目名称:Achouka,代码行数:13,代码来源:textobject.py
示例18: drawString
def drawString(self, x, y, s, angle=0):
if self._fillColor != None:
fontSize = self._fontSize
fontObj = getFont(self._font)
dynamicFont = fontObj._dynamicFont
embedding = self._ttf_embed and dynamicFont
if not embedding and not self.code[self._fontCodeLoc]:
psName = fontObj.face.name
self.code[self._fontCodeLoc]='(%s) findfont %s scalefont setfont' % (psName,fp_str(fontSize))
if psName not in self._fontsUsed:
self._fontsUsed.append(psName)
self.setColor(self._fillColor)
if angle!=0:
self.code_append('gsave %s translate %s rotate' % (fp_str(x,y),fp_str(angle)))
x = y = 0
if embedding:
i = 0
s = asUnicode(s)
for subset, t in fontObj.splitString(s, self):
if subset!=self._curSubset:
psName = fontObj.getSubsetInternalName(subset, self)[1:]
sf = '(%s) findfont %s scalefont setfont' % (psName,fp_str(fontSize))
if not self.code[self._fontCodeLoc]:
self.code[self._fontCodeLoc] = sf
else:
self.code_append(sf)
self._curSubset = subset
self.code_append('%s m (%s) show ' % (fp_str(x,y),self._escape(t)))
j = i + len(t)
x += fontObj.stringWidth(s[i:j],fontSize)
i = j
elif dynamicFont:
s = self._escape(s)
self.code_append('%s m (%s) show ' % (fp_str(x,y),s))
else:
self._issueT1String(fontObj,x,y,s)
if angle!=0:
self.code_append('grestore')
开发者ID:AndyKovv,项目名称:hostel,代码行数:38,代码来源:renderPS_SEP.py
示例19: _setFont
def _setFont(self, psfontname, size):
"""Sets the font and fontSize
Raises a readable exception if an illegal font
is supplied. Font names are case-sensitive! Keeps track
of font anme and size for metrics."""
self._fontname = psfontname
self._fontsize = size
font = pdfmetrics.getFont(self._fontname)
if font._dynamicFont:
self._curSubset = -1
else:
pdffontname = self._canvas._doc.getInternalFontName(psfontname)
self._code.append('%s %s Tf' % (pdffontname, fp_str(size)))
开发者ID:abdounasser202,项目名称:Achouka,代码行数:14,代码来源:textobject.py
示例20: P2PSC
def P2PSC(P):
C = []
aC = C.append
n = 0
for p in P:
if n>=80:
aC('\n')
n = 0
if isinstance(p,tuple):
aC(fp_str(*p[1:]))
aC(p[0][0].lower())
n += 2+sum(map(len,C[-2:]))
else:
aC(p.lower())
n += 1+len(C[-1])
return C
开发者ID:AndyKovv,项目名称:hostel,代码行数:16,代码来源:ttf2ps.py
注:本文中的reportlab.lib.rl_accel.fp_str函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论