def test_instanceStringWidth(self):
        from reportlab.pdfbase.pdfmetrics import registerFont, getFont, _fonts, unicode2T1
        from reportlab.pdfbase.ttfonts import TTFont
        ttfn = 'Vera'
        t1fn = 'Times-Roman'
        registerFont(TTFont(ttfn, "Vera.ttf"))
        ttf = getFont(ttfn)
        t1f = getFont(t1fn)
        testCp1252 = 'copyright %s trademark %s registered %s ReportLab! Ol%s!' % (chr(169), chr(153),chr(174), chr(0xe9))
        enc='cp1252'
        senc = 'utf8'
        ts = 'ABCDEF\xce\x91\xce\xb2G'
        utext = 'ABCDEF\xce\x91\xce\xb2G'.decode(senc)
        fontSize = 12
        defns="ttfn t1fn ttf t1f testCp1252 enc senc ts utext fontSize ttf.face ttf.face.charWidths ttf.face.defaultWidth t1f.widths t1f.encName t1f.substitutionFonts _fonts"
        rcv = getrc(defns)
        def tfunc(f,ts,fontSize,enc):
            w1 = f.stringWidth(ts,fontSize,enc)
            w2 = f._py_stringWidth(ts,fontSize,enc)
            assert abs(w1-w2)<1e-10,"f(%r).stringWidthU(%r,%s,%r)-->%r != f._py_stringWidth(...)-->%r" % (f,ts,fontSize,enc,w1,w2)
        tfunc(t1f,testCp1252,fontSize,enc)
        tfunc(t1f,ts,fontSize,senc)
        tfunc(t1f,utext,fontSize,senc)
        tfunc(ttf,ts,fontSize,senc)
        tfunc(ttf,testCp1252,fontSize,enc)
        tfunc(ttf,utext,fontSize,senc)
        rcc = checkrc(defns,rcv)
        assert not rcc, "rc diffs (%s)" % rcc