Пример #1
0
    def test_find_font_match_italic(self):
        font_match = get_fontconfig().find_font('arial', size=12.0, italic=True)

        self.assertIsNotNone(font_match)
        self.assertEqual(font_match.name.lower(), 'arial')
        self.assertIn('arial', font_match.file.lower())
        self.assertEqual(font_match.size, 12.0)
        self.assertFalse(font_match.bold)
        self.assertTrue(font_match.italic)
Пример #2
0
    def test_find_font_no_match(self):
        """Even if the font does not exist we get a default result."""
        font_match = get_fontconfig().find_font('unknown')

        self.assertIsNotNone(font_match)
        self.assertIsNotNone(font_match.name)
        self.assertIsNotNone(font_match.file)
        self.assertNotEqual(font_match.name.lower(), 'unknown')
        self.assertNotIn('unknown', font_match.file.lower())
Пример #3
0
    def test_find_font_match_bold(self):
        font_match = get_fontconfig().find_font('arial', size=12.0, bold=True)

        self.assertIsNotNone(font_match)
        self.assertEqual(font_match.name.lower(), 'arial')
        self.assertIn('arial', font_match.file.lower())
        self.assertEqual(font_match.size, 12.0)
        self.assertTrue(font_match.bold)
        self.assertFalse(font_match.italic)
Пример #4
0
    def test_find_font_no_match(self):
        """Even if the font does not exist we get a default result."""
        font_match = get_fontconfig().find_font('unknown')

        self.assertIsNotNone(font_match)
        self.assertIsNotNone(font_match.name)
        self.assertIsNotNone(font_match.file)
        self.assertNotEqual(font_match.name.lower(), 'unknown')
        self.assertNotIn('unknown', font_match.file.lower())
Пример #5
0
    def _get_font_metrics_workaround(self):
        # Workaround broken fonts with no metrics.  Has been observed with
        # courR12-ISO8859-1.pcf.gz: "Courier" "Regular"
        #
        # None of the metrics fields are filled in, so render a glyph and
        # grab its height as the ascent, and make up an arbitrary
        # descent.
        i = get_fontconfig().char_index(self.face, 'X')
        error = FT_Load_Glyph(self.face, i, FT_LOAD_RENDER)
        FreeTypeError.check_and_raise_on_error('Could load glyph for "X"', error)

        self.ascent = self.face.available_sizes.contents.height
        self.descent = -self.ascent // 4  # arbitrary.
Пример #6
0
def test_face_from_fontconfig(font_name, bold, italic):
    """Test loading a font face from the system using font config."""
    match = get_fontconfig().find_font(font_name, 16, bold, italic)
    assert match is not None

    face = FreeTypeFace.from_fontconfig(match)

    assert face.name == font_name
    assert face.family_name == font_name
    assert face.bold == bold
    assert face.italic == italic

    del face
Пример #7
0
    def _load_font_face_from_system(self):
        match = get_fontconfig().find_font(self.name, self.size, self.bold, self.italic)
        if not match:
            raise base.FontException('Could not match font "%s"' % self.name)

        font_face = match.face
        if not font_face:
            # Try to load from file directly
            if not match.file:
                raise base.FontException('No filename for "%s"' % self.name)

            font_face = self._load_font_face_from_file(match.file)

        return font_face
Пример #8
0
    def _get_font_metrics_workaround(self):
        # Workaround broken fonts with no metrics.  Has been observed with
        # courR12-ISO8859-1.pcf.gz: "Courier" "Regular"
        #
        # None of the metrics fields are filled in, so render a glyph and
        # grab its height as the ascent, and make up an arbitrary
        # descent.
        i = get_fontconfig().char_index(self.face, 'X')
        error = FT_Load_Glyph(self.face, i, FT_LOAD_RENDER)
        FreeTypeError.check_and_raise_on_error('Could load glyph for "X"',
                                               error)

        self.ascent = self.face.available_sizes.contents.height
        self.descent = -self.ascent // 4  # arbitrary.
Пример #9
0
    def _load_font_face_from_system(self):
        match = get_fontconfig().find_font(self.name, self.size, self.bold,
                                           self.italic)
        if not match:
            raise base.FontException('Could not match font "%s"' % self.name)

        font_face = match.face
        if not font_face:
            # Try to load from file directly
            if not match.file:
                raise base.FontException('No filename for "%s"' % self.name)

            font_face = self._load_font_face_from_file(match.file)

        return font_face
Пример #10
0
    def have_font(cls, name):
        # Check memory cache first
        name = name.lower()
        for font in list(cls._memory_fonts.values()):
            if font.name.lower() == name:
                return True

        # Check system
        match = get_fontconfig().find_font(name, 12, False, False)
        if match:
            # Check the name matches, fontconfig can return a default
            if name and match.name and match.name.lower() != name.lower():
                return False
            return True
        else:
            return False
Пример #11
0
    def have_font(cls, name):
        # Check memory cache first
        name = name.lower()
        for font in cls._memory_fonts.values():
            if font.name.lower() == name:
                return True

        # Check system
        match = get_fontconfig().find_font(name, 12, False, False)
        if match:
            # Check the name matches, fontconfig can return a default
            if name and match.name and match.name.lower() != name.lower():
                return False
            return True
        else:
            return False
Пример #12
0
    def test_find_font_match_name(self):
        font_match = get_fontconfig().find_font('arial')

        self.assertIsNotNone(font_match)
        self.assertEqual(font_match.name.lower(), 'arial')
        self.assertIn('arial', font_match.file.lower())
Пример #13
0
    def test_find_font_existing(self):
        font_match = get_fontconfig().find_font('arial')

        self.assertIsNotNone(font_match)
        self.assertIsNotNone(font_match.name)
        self.assertIsNotNone(font_match.file)
Пример #14
0
    def test_find_font_default(self):
        font_match = get_fontconfig().find_font(None)

        self.assertIsNotNone(font_match)
        self.assertIsNotNone(font_match.name)
        self.assertIsNotNone(font_match.file)
Пример #15
0
 def get_character_index(self, character):
     assert self.face
     return get_fontconfig().char_index(self.face, character)
Пример #16
0
 def get_character_index(self, character):
     assert self.face
     return get_fontconfig().char_index(self.face, character)
Пример #17
0
    def test_find_font_match_name(self):
        font_match = get_fontconfig().find_font('arial')

        self.assertIsNotNone(font_match)
        self.assertEqual(font_match.name.lower(), 'arial')
        self.assertIn('arial', font_match.file.lower())
Пример #18
0
 def have_font(cls, name):
     if cls._memory_faces.contains(name):
         return True
     else:
         return get_fontconfig().have_font(name)
Пример #19
0
    def test_find_font_default(self):
        font_match = get_fontconfig().find_font(None)

        self.assertIsNotNone(font_match)
        self.assertIsNotNone(font_match.name)
        self.assertIsNotNone(font_match.file)
Пример #20
0
 def _load_font_face_from_system(self):
     match = get_fontconfig().find_font(self.name, self.size, self.bold, self.italic)
     if not match:
         raise base.FontException('Could not match font "%s"' % self.name)
     self.face = FreeTypeFace.from_fontconfig(match)
Пример #21
0
 def have_font(cls, name):
     if cls._memory_faces.contains(name):
         return True
     else:
         return get_fontconfig().have_font(name)
Пример #22
0
 def _load_font_face_from_system(self):
     match = get_fontconfig().find_font(self.name, self.size, self.bold,
                                        self.italic)
     if not match:
         raise base.FontException('Could not match font "%s"' % self.name)
     self.face = FreeTypeFace.from_fontconfig(match)
Пример #23
0
 def get_character_index(self, character):
     return get_fontconfig().char_index(self.ft_face, character)
Пример #24
0
 def get_character_index(self, character):
     return get_fontconfig().char_index(self.ft_face, character)
Пример #25
0
    def test_find_font_existing(self):
        font_match = get_fontconfig().find_font('arial')

        self.assertIsNotNone(font_match)
        self.assertIsNotNone(font_match.name)
        self.assertIsNotNone(font_match.file)