Exemplo n.º 1
0
def get_revision(font, fname):
  if 'Armenian' in fname:
    # special case phase 2 version string >= 2.0
    return '2.040'

  # sometimes the fontRevision and version string don't match, and the
  # fontRevision is bad, so we prefer the version string.

  version_string = font_data.font_version(font)
  m = version_re.match(version_string)
  if not m:
    raise Exception('could not match "%s"' % version_string)
  revision = m.group(1)
  if float(revision) < 2.0:
    return '2.000'

  original_revision = revision
  chars = [cp for cp in revision]
  index = len(chars) - 1
  while index >= 0 and chars[index] != '.':
    if chars[index] < '9':
      chars[index] = chr(ord(revision[index]) + 1)
      return ''.join(chars)
    else:
      chars[index] = '0'
    index -= 1

  raise Exception('unable to increment revision "%s"' % original_revision)
Exemplo n.º 2
0
def _extract_version(font):
  # Sometimes the fontRevision and version string don't match, and the
  # fontRevision is bad, so we prefer the version string.
  version = font_data.font_version(font)
  m = _version_re.match(version)
  if not m:
    raise Exception('could not match existing version "%s"' % version)
  return m.group(1)
Exemplo n.º 3
0
def _extract_version(font):
  # Sometimes the fontRevision and version string don't match, and the
  # fontRevision is bad, so we prefer the version string.
  version = font_data.font_version(font)
  m = _version_re.match(version)
  if not m:
    raise Exception('could not match existing version "%s"' % version)
  return m.group(1)
Exemplo n.º 4
0
    def test_version_numbers(self):
        "Tests the two version numbers of the font to be correct." ""
        for font in self.fonts:
            version = font_data.font_version(font)
            usable_part_of_version = version.split(';')[0]
            self.assertEqual(usable_part_of_version,
                             'Version ' + self.expected_version)

            revision = font_data.printable_font_revision(font, accuracy=3)
            self.assertEqual(revision, self.expected_version)
Exemplo n.º 5
0
    def test_version_numbers(self):
        "Tests the two version numbers of the font to be correct."""
        for font in self.fonts:
            version = font_data.font_version(font)
            usable_part_of_version = version.split(';')[0]
            self.assertEqual(usable_part_of_version,
                             'Version ' + self.expected_version)

            revision = font_data.printable_font_revision(font, accuracy=3)
            self.assertEqual(revision, self.expected_version)
Exemplo n.º 6
0
    def test_version_numbers(self):
        "Tests the two version numbers of the font to be correct."""
        for font in self.fonts:
            build_number = roboto_data.get_build_number()
            expected_version = '2.' + build_number
            version = font_data.font_version(font)
            usable_part_of_version = version.split(';')[0]
            self.assertEqual(usable_part_of_version,
                             'Version ' + expected_version)

            revision = font_data.printable_font_revision(font, accuracy=5)
            self.assertEqual(revision, expected_version)
Exemplo n.º 7
0
    def test_version_numbers(self):
        "Tests the two version numbers of the font to be correct." ""
        for font in self.fonts:
            build_number = roboto_data.get_build_number()
            expected_version = '2.' + build_number
            version = font_data.font_version(font)
            usable_part_of_version = version.split(';')[0]
            self.assertEqual(usable_part_of_version,
                             'Version ' + expected_version)

            revision = font_data.printable_font_revision(font, accuracy=5)
            self.assertEqual(revision, expected_version)
Exemplo n.º 8
0
def fix_revision(font):
    """Fix the revision of the font to match its version."""
    version = font_data.font_version(font)
    match = re.match(r'Version (\d{1,5})\.(\d{1,5})', version)
    major_version = match.group(1)
    minor_version = match.group(2)

    accuracy = len(minor_version)
    font_revision = font_data.printable_font_revision(font, accuracy)
    expected_font_revision = major_version + '.' + minor_version
    if font_revision != expected_font_revision:
        font['head'].fontRevision = float(expected_font_revision)
        print 'Fixed fontRevision to %s' % expected_font_revision
        return True

    return False
Exemplo n.º 9
0
def fix_revision(font):
    """Fix the revision of the font to match its version."""
    version = font_data.font_version(font)
    match = re.match(r'Version (\d{1,5})\.(\d{1,5})', version)
    major_version = match.group(1)
    minor_version = match.group(2)

    accuracy = len(minor_version)
    font_revision = font_data.printable_font_revision(font, accuracy)
    expected_font_revision = major_version+'.'+minor_version
    if font_revision != expected_font_revision:
        font['head'].fontRevision = float(expected_font_revision)
        print 'Fixed fontRevision to %s' % expected_font_revision
        return True

    return False
Exemplo n.º 10
0
    def add_watermark(self, ttf):
        cmap = ttf.getBestCmap()
        gsub = ttf['GSUB'].table

        # Obtain Version string
        m = re.search('^Version (\d*)\.(\d*)', font_data.font_version(ttf))
        if not m:
            raise ValueError('The font does not have proper version string.')
        major = m.group(1)
        minor = m.group(2)
        # Replace the dot with space since NotoColorEmoji does not have glyph for dot.
        glyphs = [cmap[ord(x)] for x in '%s %s' % (major, minor)]

        # Update Glyph metrics
        ttf.getGlyphOrder().append(WATERMARK_NEW_GLYPH_ID)
        refGlyphId = cmap[WATERMARK_REF_CODE_POINT]
        ttf['hmtx'].metrics[WATERMARK_NEW_GLYPH_ID] = ttf['hmtx'].metrics[refGlyphId]
        ttf['vmtx'].metrics[WATERMARK_NEW_GLYPH_ID] = ttf['vmtx'].metrics[refGlyphId]

        # Add new Glyph to cmap
        font_data.add_to_cmap(ttf, { WATERMARK_NEW_CODE_POINT : WATERMARK_NEW_GLYPH_ID })

        # Add lookup table for the version string.
        lookups = gsub.LookupList.Lookup
        new_lookup = otTables.Lookup()
        new_lookup.LookupType = 2  # Multiple Substitution Subtable.
        new_lookup.LookupFlag = 0
        new_subtable = otTables.MultipleSubst()
        new_subtable.mapping = { WATERMARK_NEW_GLYPH_ID : tuple(glyphs) }
        new_lookup.SubTable = [ new_subtable ]
        new_lookup_index = len(lookups)
        lookups.append(new_lookup)

        # Add feature
        feature = next(x for x in gsub.FeatureList.FeatureRecord if x.FeatureTag == 'ccmp')
        if not feature:
            raise ValueError("Font doesn't contain ccmp feature.")

        feature.Feature.LookupListIndex.append(new_lookup_index)
Exemplo n.º 11
0
 def create_font_data(font, collection):
     cps = len(font_data.get_cmap(font))
     version = font_data.font_version(font)
     return GlyphImageFontData._make(collection.file_header +
                                     (cps, version))