Rename glyphs using ufo.lib.public.postscriptNames in UFO.
501026
def _rename_glyphs_from_ufo(self):
        """"""
        rename_map = self._build_production_names()

        otf = self.otf
        otf.setGlyphOrder([rename_map.get(n, n) for n in otf.getGlyphOrder()])

        # we need to compile format 2 'post' table so that the 'extraNames'
        # attribute is updated with the list of the names outside the
        # standard Macintosh glyph order; otherwise, if one dumps the font
        # to TTX directly before compiling first, the post table will not
        # contain the extraNames.
        if 'post' in otf and otf['post'].formatType == 2.0:
            otf['post'].compile(self.otf)

        if 'CFF ' in otf:
            cff = otf['CFF '].cff.topDictIndex[0]
            char_strings = cff.CharStrings.charStrings
            cff.CharStrings.charStrings = {
                rename_map.get(n, n): v for n, v in char_strings.items()}
            cff.charset = [rename_map.get(n, n) for n in cff.charset]
721105
def _renameClasses(classes, prefix):
    
    renameMap = {}
    for classID, glyphList in classes.items():
        if len(glyphList) == 0:
            groupName = "%s_empty_lu.%d_st.%d_cl.%d" % (prefix, classID[0], classID[1], classID[2])
        elif len(glyphList) == 1:
            groupName = list(glyphList)[0]
        else:
            glyphList = list(sorted(glyphList))
            groupName = prefix + glyphList[0]
        renameMap[classID] = groupName
    return renameMap
289452
def ReplaceHomoglyphs(s):
    """"""
    homoglyphs = {
        '\xa0': ' ',  # &nbsp; ?
        '\u00e3': '',  # TODO(gsfowler) drop after .proto spurious char elided
        '\u00a0': ' ',  # &nbsp; ?
        '\u00a9': '(C)',  # COPYRIGHT SIGN (would you believe "asciiglyph"?)
        '\u00ae': '(R)',  # REGISTERED SIGN (would you believe "asciiglyph"?)
        '\u2014': '-',  # EM DASH
        '\u2018': "'",  # LEFT SINGLE QUOTATION MARK
        '\u2019': "'",  # RIGHT SINGLE QUOTATION MARK
        '\u201c': '"',  # LEFT DOUBLE QUOTATION MARK
        '\u201d': '"',  # RIGHT DOUBLE QUOTATION MARK
        '\u2026': '...',  # HORIZONTAL ELLIPSIS
        '\u2e3a': '-',  # TWO-EM DASH
    }

    def _ReplaceOne(c):
        """Returns the homoglyph or escaped replacement for c."""
        equiv = homoglyphs.get(c)
        if equiv is not None:
            return equiv
        try:
            c.encode('ascii')
            return c
        except UnicodeError:
            pass
        try:
            return c.encode('unicode-escape').decode('ascii')
        except UnicodeError:
            return '?'

    return ''.join([_ReplaceOne(c) for c in s])
1293516
def _replaceRenamedPairMembers(kerning, leftRename, rightRename):
    
    renamedKerning = {}
    for (left, right), value in kerning.items():
        left = leftRename.get(left, left)
        right = rightRename.get(right, right)
        renamedKerning[left, right] = value
    return renamedKerning
905990
def path_mapped(script_name, *args)
    return cleanup_paths("/#{script_name}/#{@locations[:root]}") if args.empty?
    a = replace_symbols(script_name, *args)
    cleanup_paths("/#{script_name}/#{@locations[:root]}/#{a.join('/')}")
  end
675030
def to_ufo_background_image(self, ufo_glyph, layer):
    """"""
    image = layer.backgroundImage
    if image is None:
        return
    ufo_image = ufo_glyph.image
    ufo_image.fileName = image.path
    ufo_image.transformation = image.transform
    ufo_glyph.lib[CROP_KEY] = list(image.crop)
    ufo_glyph.lib[LOCKED_KEY] = image.locked
    ufo_glyph.lib[ALPHA_KEY] = image.alpha
193074
def change_font_name(new_font_name = 'Verdana')
      validate_worksheet

      font = get_cell_font.dup
      font.set_name(new_font_name)
      update_font_references(font)
    end
275566
def rename_aesthetics(obj):
    
    if isinstance(obj, dict):
        for name in obj:
            new_name = name.replace('colour', 'color')
            if name != new_name:
                obj[new_name] = obj.pop(name)
    else:
        obj = [name.replace('colour', 'color') for name in obj]

    return obj
650248
def _unset_default_params(glyphs):
    
    for glyphs_name, _, default_value in DEFAULT_PARAMETERS:
        if (
            glyphs_name in glyphs.customParameters
            and glyphs.customParameters[glyphs_name] == default_value
        ):
            del (glyphs.customParameters[glyphs_name])
        # These parameters can be referred to with the two names in Glyphs
        if (
            glyphs_name in glyphs.customParameters
            and glyphs.customParameters[glyphs_name] == default_value
        ):
            del (glyphs.customParameters[glyphs_name])
595418
def makeUnicodeToGlyphNameMapping(self):
        
        # Try to get the "best" Unicode cmap subtable if this writer is running
        # in the context of a FeatureCompiler, else create a new mapping from
        # the UFO glyphs
        compiler = self.context.compiler
        cmap = None
        if compiler is not None:
            table = compiler.ttFont.get("cmap")
            if table is not None:
                cmap = table.getBestCmap()
        if cmap is None:
            from ufo2ft.util import makeUnicodeToGlyphNameMapping

            if compiler is not None:
                glyphSet = compiler.glyphSet
            else:
                glyphSet = self.context.font
            cmap = makeUnicodeToGlyphNameMapping(glyphSet)
        return cmap
104738
def _agl_compliant_name(glyph_name):
    """"""
    MAX_GLYPH_NAME_LENGTH = 63
    clean_name = re.sub("[^0-9a-zA-Z_.]", "", glyph_name)
    if len(clean_name) > MAX_GLYPH_NAME_LENGTH:
        return None
    return clean_name
94391
function(files, name){
        var reg = /(_STYLE_NAME_|_SCRIPT_NAME_)/gi;
        var tpl = files.replace(reg, function(m,$1,$2){
            if(m == "_STYLE_NAME_"){
                return name;
            }else if(m == "_SCRIPT_NAME_"){
                return name;
            }else{
                return m;
            }
        });
        return tpl;
    }
1117033
def to_glyphs_family_user_data_from_designspace(self):
    """"""
    target_user_data = self.font.userData
    for key, value in self.designspace.lib.items():
        if key == UFO2FT_FEATURE_WRITERS_KEY and value == DEFAULT_FEATURE_WRITERS:
            # if the designspace contains featureWriters settings that are the
            # same as glyphsLib default settings, there's no need to store them
            continue
        if _user_data_has_no_special_meaning(key):
            target_user_data[key] = value
744907
def getOrderedGlyphSet(self):
        
        compiler = self.context.compiler
        if compiler is not None:
            return compiler.glyphSet

        from ufo2ft.util import makeOfficialGlyphOrder

        glyphSet = self.context.font
        glyphOrder = makeOfficialGlyphOrder(self.context.font)
        return OrderedDict((gn, glyphSet[gn]) for gn in glyphOrder)
57671
def makeUnicodeToGlyphNameMapping(font, glyphOrder=None):
    
    if glyphOrder is None:
        glyphOrder = makeOfficialGlyphOrder(font)
    mapping = {}
    for glyphName in glyphOrder:
        glyph = font[glyphName]
        unicodes = glyph.unicodes
        for uni in unicodes:
            if uni not in mapping:
                mapping[uni] = glyphName
            else:
                from ufo2ft.errors import InvalidFontData

                InvalidFontData(
                    "cannot map '%s' to U+%04X; already mapped to '%s'"
                    % (glyphName, uni, mapping[uni])
                )
    return mapping
228828
def to_glyphs_blue_values(self, ufo, master):
    """"""

    zones = []
    blue_values = _pairs(ufo.info.postscriptBlueValues)
    other_blues = _pairs(ufo.info.postscriptOtherBlues)
    for y1, y2 in blue_values:
        size = y2 - y1
        if y2 == 0:
            pos = 0
            size = -size
        else:
            pos = y1
        zones.append(self.glyphs_module.GSAlignmentZone(pos, size))
    for y1, y2 in other_blues:
        size = y1 - y2
        pos = y2
        zones.append(self.glyphs_module.GSAlignmentZone(pos, size))

    master.alignmentZones = sorted(zones, key=lambda zone: -zone.position)
1275260
def rename_in_module(occurrences_finder, new_name, resource=None,
                     pymodule=None, replace_primary=False, region=None,
                     reads=True, writes=True):
    """"""
    if resource is not None:
        source_code = resource.read()
    else:
        source_code = pymodule.source_code
    change_collector = codeanalyze.ChangeCollector(source_code)
    for occurrence in occurrences_finder.find_occurrences(resource, pymodule):
        if replace_primary and occurrence.is_a_fixed_primary():
            continue
        if replace_primary:
            start, end = occurrence.get_primary_range()
        else:
            start, end = occurrence.get_word_range()
        if (not reads and not occurrence.is_written()) or \
           (not writes and occurrence.is_written()):
            continue
        if region is None or region[0] <= start < region[1]:
            change_collector.add_change(start, end, new_name)
    return change_collector.get_changed()