コード例 #1
0
 def handle_entityref(self, name):
     "Handles a named entity.  "
     try:
         v = uniChr(known_entities[name])
     except:
         v = u'&%s;' % name
     self.handle_data(v)
コード例 #2
0
 def handle_entityref(self, name):
     "Handles a named entity.  "
     try:
         v = uniChr(known_entities[name])
     except:
         v = u'&%s;' % name
     self.handle_data(v)
コード例 #3
0
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]
コード例 #4
0
def show_all_glyphs(fn, fontName='Vera'):
    c = Canvas(outputfile(fn))
    c.setFont('Helvetica', 20)
    c.drawString(72, c._pagesize[1] - 30,
                 'Unicode TrueType Font Test %s' % fontName)
    from reportlab.pdfbase.pdfmetrics import _fonts
    from reportlab.lib.utils import uniChr
    font = _fonts[fontName]
    doc = c._doc
    kfunc = font.face.charToGlyph.keys if isPy3 else font.face.charToGlyph.iterkeys
    for s in kfunc():
        if s < 0x10000:
            font.splitString(uniChr(s), doc)
    state = font.state[doc]
    cn = {}
    #print('len(assignments)=%d'%  len(state.assignments))
    nzero = 0
    ifunc = state.assignments.items if isPy3 else state.assignments.iteritems
    for code, n in ifunc():
        if code == 0: nzero += 1
        cn[n] = uniChr(code)
    if nzero > 1: print('%s there were %d zero codes' % (fontName, nzero))

    ymin = 10 * 12
    y = y0 = c._pagesize[1] - 72
    for nss, subset in enumerate(state.subsets):
        if y < ymin:
            c.showPage()
            y = y0
        c.setFont('Helvetica', 10)
        x = 72
        c.drawString(x, y, 'Subset %d len=%d' % (nss, len(subset)))
        #print('Subset %d len=%d' % (nss,len(subset)))
        c.setFont(fontName, 10)
        for i, code in enumerate(subset):
            if i % 32 == 0:
                y -= 12
                x = 72
            c.drawString(x, y, uniChr(code))
            x += 13
        y -= 18

    c.showPage()
    c.save()
コード例 #5
0
ファイル: paraparser.py プロジェクト: anantram/mycommunity
 def handle_charref(self, name):
     try:
         if name[0] == 'x':
             n = int(name[1:], 16)
         else:
             n = int(name)
     except ValueError:
         self.unknown_charref(name)
         return
     self.handle_data(uniChr(n))  #.encode('utf8'))
コード例 #6
0
 def handle_charref(self, name):
     try:
         if name[0]=='x':
             n = int(name[1:],16)
         else:
             n = int(name)
     except ValueError:
         self.unknown_charref(name)
         return
     self.handle_data(uniChr(n))   #.encode('utf8'))
コード例 #7
0
ファイル: tagstripper.py プロジェクト: Xhiffer/Lama-projet-l2
 def handle_charref(self, ref):
     try:
         if ref.startswith(u'x'):
             v = int(ref[1:], 16)
         else:
             v = int(ref)
         v = uniChr(v)
     except:
         v = u'&#%s;' % ref
     self.handle_data(v)
コード例 #8
0
ファイル: tagstripper.py プロジェクト: AndyKovv/hostel
 def handle_charref(self, ref):
     try:
         if ref.startswith(u'x'):
             v = int(ref[1:],16)
         else:
             v = int(ref)
         v = uniChr(v)
     except:
         v = u'&#%s;' % ref
     self.handle_data(v)
コード例 #9
0
ファイル: ttf2ps.py プロジェクト: AndyKovv/hostel
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]
コード例 #10
0
ファイル: paraparser.py プロジェクト: anantram/mycommunity
    'uuml': u'\xfc',
    'weierp': u'\u2118',
    'Xi': u'\u039e',
    'xi': u'\u03be',
    'Yacute': u'\xdd',
    'yacute': u'\xfd',
    'yen': u'\xa5',
    'yuml': u'\xff',
    'Yuml': u'\u0178',
    'Zeta': u'\u0396',
    'zeta': u'\u03b6',
    'zwj': u'\u200d',
    'zwnj': u'\u200c',
}

known_entities = dict([(k, uniChr(v)) for k, v in name2codepoint.items()])
for k in greeks:
    if k not in known_entities:
        known_entities[k] = greeks[k]
f = isPy3 and asBytes or asUnicode
K = list(known_entities.keys())
for k in K:
    known_entities[f(k)] = known_entities[k]
del k, f, K


#------------------------------------------------------------------------
class ParaFrag(ABag):
    """class ParaFrag contains the intermediate representation of string
    segments as they are being parsed by the ParaParser.
    fontname, fontSize, rise, textColor, cbDefn
コード例 #11
0
def utf8(code):
    "Convert a given UCS character index into UTF-8"
    return uniChr(code).encode('utf8')
コード例 #12
0
    'uuml': u'\xfc',
    'weierp': u'\u2118',
    'Xi': u'\u039e',
    'xi': u'\u03be',
    'Yacute': u'\xdd',
    'yacute': u'\xfd',
    'yen': u'\xa5',
    'yuml': u'\xff',
    'Yuml': u'\u0178',
    'Zeta': u'\u0396',
    'zeta': u'\u03b6',
    'zwj': u'\u200d',
    'zwnj': u'\u200c',
    }

known_entities = dict([(k,uniChr(v)) for k,v in name2codepoint.items()])
for k in greeks:
    if k not in known_entities:
        known_entities[k] = greeks[k]
f = isPy3 and asBytes or asUnicode
K = list(known_entities.keys())
for k in K:
    known_entities[f(k)] = known_entities[k]
del k, f, K

#------------------------------------------------------------------------
class ParaFrag(ABag):
    """class ParaFrag contains the intermediate representation of string
    segments as they are being parsed by the ParaParser.
    fontname, fontSize, rise, textColor, cbDefn
    """
コード例 #13
0
def utf8(code):
    "Convert a given UCS character index into UTF-8"
    return uniChr(code).encode('utf8')