def __init__(self, font, chars, registry): if font.filename: registry.add( PSfontfile(font.basefontname, font.filename, font.encoding, chars)) if font.encoding and font.slant: assert font.encname # do first the reencoding and then the slanting: enc_basename, enc_finalname = font.basefontname, font.encname slt_basename, slt_finalname = tfont.encname, font.name elif font.encoding: enc_basename, enc_finalname = font.basefontname, font.name elif font.slant: slt_basename, slt_finalname = font.basefontname, font.name if font.encoding: registry.add(_ReEncodeFont) registry.add(PSfontencoding(font.encoding)) registry.add( PSfontreencoding(enc_finalname, enc_basename, font.encoding.name)) if font.slant: # we need the current fontmatrix in order to manipulate it: # for this we need to re-read the fontfile as below in # PSfontfile.ouput: # XXX Is there a better way to do this? t = trafo.trafo_pt(matrix=((1, font.slant), (0, 1))) if font.filename: # for the builtin fonts, we assume a trivial fontmatrix import font.t1font as t1fontmodule t1font = t1fontmodule.T1pfbfont(font.filename) m = t1font.fontmatrixpattern.search(t1font.data1) m11, m12, m21, m22, v1, v2 = map(float, m.groups()[:6]) t *= trafo.trafo_pt(matrix=((m11, m12), (m21, m22)), vector=(v1, v2)) else: raise NotImplementedError( "cannot slant unembedded fonts -- try to include \"download35.map\" in fontmaps" ) registry.add( PSfontslanting(slt_finalname, slt_basename, t.__str__()))
def __init__(self, font, chars, registry): if font.filename: registry.add(PSfontfile(font.basefontname, font.filename, font.encoding, chars)) if font.encoding and font.slant: assert font.encname # do first the reencoding and then the slanting: enc_basename, enc_finalname = font.basefontname, font.encname slt_basename, slt_finalname = tfont.encname, font.name elif font.encoding: enc_basename, enc_finalname = font.basefontname, font.name elif font.slant: slt_basename, slt_finalname = font.basefontname, font.name if font.encoding: registry.add(_ReEncodeFont) registry.add(PSfontencoding(font.encoding)) registry.add(PSfontreencoding(enc_finalname, enc_basename, font.encoding.name)) if font.slant: # we need the current fontmatrix in order to manipulate it: # for this we need to re-read the fontfile as below in # PSfontfile.ouput: # XXX Is there a better way to do this? t = trafo.trafo_pt(matrix=((1, font.slant), (0, 1))) if font.filename: # for the builtin fonts, we assume a trivial fontmatrix import font.t1font as t1fontmodule t1font = t1fontmodule.T1pfbfont(font.filename) m = t1font.fontmatrixpattern.search(t1font.data1) m11, m12, m21, m22, v1, v2 = map(float, m.groups()[:6]) t *= trafo.trafo_pt(matrix=((m11, m12), (m21, m22)), vector=(v1, v2)) else: raise NotImplementedError( "cannot slant unembedded fonts -- try to include \"download35.map\" in fontmaps") registry.add(PSfontslanting(slt_finalname, slt_basename, t.__str__()))
def __init__(self, xpos_pt, ypos_pt, image, width_pt=None, height_pt=None, ratio=None, **kwargs): imagewidth, imageheight = image.size if width_pt is not None or height_pt is not None: if width_pt is None: if ratio is None: width_pt = height_pt * imagewidth / float(imageheight) else: width_pt = ratio * height_pt elif height_pt is None: if ratio is None: height_pt = width_pt * imageheight / float(imagewidth) else: height_pt = (1.0/ratio) * width_pt elif ratio is not None: raise ValueError("can't specify a ratio when setting width_pt and height_pt") else: if ratio is not None: raise ValueError("must specify width_pt or height_pt to set a ratio") widthdpi, heightdpi = image.info["dpi"] # fails when no dpi information available width_pt = 72.0 * imagewidth / float(widthdpi) height_pt = 72.0 * imageheight / float(heightdpi) bitmap_trafo.__init__(self, trafo.trafo_pt(((float(width_pt), 0.0), (0.0, float(height_pt))), (float(xpos_pt), float(ypos_pt))), image, **kwargs)
def __init__(self, xpos_pt, ypos_pt, image, width_pt=None, height_pt=None, ratio=None, **kwargs): imagewidth, imageheight = image.size if width_pt is not None or height_pt is not None: if width_pt is None: if ratio is None: width_pt = height_pt * imagewidth / float(imageheight) else: width_pt = ratio * height_pt elif height_pt is None: if ratio is None: height_pt = width_pt * imageheight / float(imagewidth) else: height_pt = (1.0 / ratio) * width_pt elif ratio is not None: raise ValueError( "can't specify a ratio when setting width_pt and height_pt" ) else: if ratio is not None: raise ValueError( "must specify width_pt or height_pt to set a ratio") widthdpi, heightdpi = image.info[ "dpi"] # fails when no dpi information available width_pt = 72.0 * imagewidth / float(widthdpi) height_pt = 72.0 * imageheight / float(heightdpi) bitmap_trafo.__init__( self, trafo.trafo_pt(((float(width_pt), 0.0), (0.0, float(height_pt))), (float(xpos_pt), float(ypos_pt))), image, **kwargs)