def autoEmbed(fname):
    log.info('Trying to embed %s'%fname)
    fontList = []
    variants=[]
    f = findFont(fname)
    if f : # We have this font located
        if f[0].lower()[-4:]=='.afm': #Type 1 font
            family = families[f[2]]

            # Register the whole family of faces
            faces = [pdfmetrics.EmbeddedType1Face(*fonts[fn.lower()][:2]) for fn in family]
            for face in faces:
                pdfmetrics.registerTypeFace(face)

            for face, name in zip(faces, family):
                fontList.append(name)
                font = pdfmetrics.Font(face, name, "WinAnsiEncoding")
                log.info('Registering font: %s from %s'%\
                            (face,name))
                pdfmetrics.registerFont(font)

            # Map the variants
            regular, italic, bold, bolditalic = family
            addMapping(fname, 0, 0, regular)
            addMapping(fname, 0, 1, italic)
            addMapping(fname, 1, 0, bold)
            addMapping(fname, 1, 1, bolditalic)
            addMapping(regular, 0, 0, regular)
            addMapping(regular, 0, 1, italic)
            addMapping(regular, 1, 0, bold)
            addMapping(regular, 1, 1, bolditalic)
            log.info('Embedding as %s'%fontList)
            return fontList
        else: # A TTF font
            variants = [fonts[f.lower()][0] for f in families[f[2]]]
    if not variants: # Try fc-match
        variants = findTTFont(fname)
    # It is a TT Font and we found it using fc-match (or found *something*)
    if variants:
        for variant in variants:
            vname = os.path.basename(variant)[:-4]
            try:
                if vname not in pdfmetrics._fonts:
                    _font=TTFont(vname, variant)
                    log.info('Registering font: %s from %s'%\
                            (vname,variant))
                    pdfmetrics.registerFont(_font)
            except TTFError:
                log.error('Error registering font: %s from %s'%(vname,variant))
            else:
                fontList.append(vname)
        regular, bold, italic, bolditalic = [
            os.path.basename(variant)[:-4] for variant in variants]
        addMapping(regular, 0, 0, regular)
        addMapping(regular, 0, 1, italic)
        addMapping(regular, 1, 0, bold)
        addMapping(regular, 1, 1, bolditalic)
        log.info('Embedding via findTTFont as %s'%fontList)
    return fontList
.. todo::
dataset/ETHPy150Open rst2pdf/rst2pdf/rst2pdf/findfonts.py/autoEmbed--crossover with--dataset/ETHPy150Open jfsantos/ift6266h14/old/pylearn2_timit/iteration.py/FiniteDatasetIterator.num_examples