[ Avaa Bypassed ]




Upload:

Command:

www-data@3.19.237.16: ~ $
#
"""
This is a utility to 'can' the widths data for certain CID fonts.
Now we're using Unicode, we don't need 20 CMAP files for each Asian
language, nor the widths of the non-normal characters encoded in each
font.  we just want a dictionary of the character widths in a given
font which are NOT 1000 ems wide, keyed on Unicode character (not CID).

Running off CMAP files we get the following widths...::

    >>> font = UnicodeCIDFont('HeiseiMin-W3')
    >>> font.stringWidth(unicode(','), 10)
    2.5
    >>> font.stringWidth(unicode('m'), 10)
    7.7800000000000002
    >>> font.stringWidth(u'\u6771\u4EAC', 10)
    20.0
    >>> 

"""

from pprint import pprint as pp

from reportlab.pdfbase._cidfontdata import defaultUnicodeEncodings
from reportlab.pdfbase.cidfonts import UnicodeCIDFont


def run():

    buf = []
    buf.append('widthsByUnichar = {}')
    for fontName, (language, encName) in defaultUnicodeEncodings.items():
        print('handling %s : %s : %s' % (fontName, language, encName))

        #this does just about all of it for us, as all the info
        #we need is present.
        font = UnicodeCIDFont(fontName)

        widthsByCID = font.face._explicitWidths
        cmap = font.encoding._cmap
        nonStandardWidthsByUnichar = {}
        for codePoint, cid in cmap.items():
            width = widthsByCID.get(cid, 1000)
            if width != 1000:
                nonStandardWidthsByUnichar[chr(codePoint)] = width
        

        
        print('created font width map (%d items).  ' % len(nonStandardWidthsByUnichar))

        buf.append('widthsByUnichar["%s"] = %s' % (fontName, repr(nonStandardWidthsByUnichar)))
        
        
    src = '\n'.join(buf) + '\n'
    open('canned_widths.py','w').write(src)
    print('wrote canned_widths.py')

if __name__=='__main__':
    run()
    

Filemanager

Name Type Size Permission Actions
__pycache__ Folder 0755
__init__.py File 275 B 0644
_can_cmap_data.py File 1.78 KB 0644
_cidfontdata.py File 31.29 KB 0644
_fontdata.py File 8.35 KB 0644
_fontdata_enc_macexpert.py File 2.99 KB 0644
_fontdata_enc_macroman.py File 2.87 KB 0644
_fontdata_enc_pdfdoc.py File 2.25 KB 0644
_fontdata_enc_standard.py File 1.79 KB 0644
_fontdata_enc_symbol.py File 3.11 KB 0644
_fontdata_enc_winansi.py File 2.93 KB 0644
_fontdata_enc_zapfdingbats.py File 2.17 KB 0644
_fontdata_widths_courier.py File 3.58 KB 0644
_fontdata_widths_courierbold.py File 3.58 KB 0644
_fontdata_widths_courierboldoblique.py File 3.58 KB 0644
_fontdata_widths_courieroblique.py File 3.58 KB 0644
_fontdata_widths_helvetica.py File 3.58 KB 0644
_fontdata_widths_helveticabold.py File 3.58 KB 0644
_fontdata_widths_helveticaboldoblique.py File 3.58 KB 0644
_fontdata_widths_helveticaoblique.py File 3.58 KB 0644
_fontdata_widths_symbol.py File 3.29 KB 0644
_fontdata_widths_timesbold.py File 3.59 KB 0644
_fontdata_widths_timesbolditalic.py File 3.58 KB 0644
_fontdata_widths_timesitalic.py File 3.58 KB 0644
_fontdata_widths_timesroman.py File 3.58 KB 0644
_fontdata_widths_zapfdingbats.py File 2.67 KB 0644
_glyphlist.py File 105.92 KB 0644
acroform.py File 44.59 KB 0644
cidfonts.py File 18.4 KB 0644
pdfdoc.py File 88.18 KB 0644
pdfform.py File 15.35 KB 0644
pdfmetrics.py File 29.95 KB 0644
pdfpattern.py File 3.71 KB 0644
pdfutils.py File 9.64 KB 0644
rl_codecs.py File 53.82 KB 0644
ttfonts.py File 51.7 KB 0644