Exemplo n.º 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)
Exemplo n.º 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())
Exemplo n.º 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)
Exemplo n.º 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())
Exemplo n.º 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.
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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.
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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())
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 15
0
 def get_character_index(self, character):
     assert self.face
     return get_fontconfig().char_index(self.face, character)
Exemplo n.º 16
0
 def get_character_index(self, character):
     assert self.face
     return get_fontconfig().char_index(self.face, character)
Exemplo n.º 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())
Exemplo n.º 18
0
 def have_font(cls, name):
     if cls._memory_faces.contains(name):
         return True
     else:
         return get_fontconfig().have_font(name)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 21
0
 def have_font(cls, name):
     if cls._memory_faces.contains(name):
         return True
     else:
         return get_fontconfig().have_font(name)
Exemplo n.º 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)
Exemplo n.º 23
0
 def get_character_index(self, character):
     return get_fontconfig().char_index(self.ft_face, character)
Exemplo n.º 24
0
 def get_character_index(self, character):
     return get_fontconfig().char_index(self.ft_face, character)
Exemplo n.º 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)