Ejemplo n.º 1
0
 def test_list06(self):
     # weight: bold
     # slant: oblique
     pattern = 'DejaVu Sans:weight=bold:slant=oblique'
     s = FontConfig.list(pattern)
     self.assertTrue(len(s) >= 2,
                     msg='"{}" is not installed.'.format(pattern))
Ejemplo n.º 2
0
 def test_match01(self):
     if sys.platform == 'win32' or sys.platform == 'darwin':
         pattern = 'Verdana'
     else:
         pattern = 'DejaVu Sans'
     s = FontConfig.match(pattern)
     self.assertTrue(len(s) > 0,
                     msg='"{}" is not installed.'.format(pattern))
Ejemplo n.º 3
0
 def test_list07(self):
     # weight: bold
     # slant: oblique
     # width: semi-condensed
     pattern = 'DejaVu Sans:weight=bold:slant=oblique:width=semicondensed'
     s = FontConfig.list(pattern)
     self.assertTrue(len(s) >= 1,
                     msg='"{}" is not installed.'.format(pattern))
Ejemplo n.º 4
0
    def test_list08(self):
        # weight: bold
        pattern = 'DejaVu Sans:weight=bold'
        fc_elements = [FontConfig.FC_FAMILY, FontConfig.FC_WEIGHT]
        # '%{family}\t%{weight}'
        fc_format = '\t'.join(['%{{{}}}'.format(x) for x in fc_elements])
        s = FontConfig.list(pattern, fc_elements, fc_format)
        self.assertTrue(len(s) > 0,
                        msg='"{}" is not installed.'.format(pattern))

        expected = '200'  # bold
        for matched in iter(s):
            items = matched.split('\t')
            self.assertEqual(expected, items[1])
Ejemplo n.º 5
0
 def test_match02(self):
     for pattern in ['serif', 'sans-serif', 'monospace']:
         s = FontConfig.match(pattern)
         self.assertTrue(
             len(s) > 0,
             msg='fontconfig: "{}" is not configured.'.format(pattern))
Ejemplo n.º 6
0
 def test_list04(self):
     # slant: oblique
     pattern = 'DejaVu Sans:slant=oblique'
     s = FontConfig.list(pattern)
     self.assertTrue(len(s) > 0,
                     msg='"{}" is not installed.'.format(pattern))
Ejemplo n.º 7
0
 def test_list05(self):
     # slant: italic
     pattern = 'DejaVu Sans:slant=italic'
     s = FontConfig.list(pattern)
     self.assertTrue(len(s) == 0,
                     msg='"{}" is not installed.'.format(pattern))
Ejemplo n.º 8
0
 def test_list03(self):
     # weight: bold
     pattern = 'DejaVu Sans:weight=bold'
     s = FontConfig.list(pattern)
     self.assertTrue(len(s) > 0,
                     msg='"{}" is not installed.'.format(pattern))
Ejemplo n.º 9
0
 def test_list02(self):
     # "DejaVu Sans"
     pattern = 'DejaVu Sans'
     s = FontConfig.list(pattern)
     self.assertTrue(len(s) > 0,
                     msg='"{}" is not installed.'.format(pattern))
Ejemplo n.º 10
0
 def test_list01(self):
     s = FontConfig.list()
     self.assertTrue(len(s) > 0)
Ejemplo n.º 11
0
 def test_config_list(self):
     files = FontConfig.get_config_files()
     # for file in files:
     #     print(file)
     self.assertTrue(len(files) > 0)
Ejemplo n.º 12
0
def main():
    font_family = 'DejaVu Sans'
    result = FontConfig.match(font_family,
                              '%{{{}}}'.format(FontConfig.FC_FILE))
    if len(result) == 0:
        print('font file not found: "{}"'.format(font_family))
        sys.exit(1)
    face = FTFace.new_face(result[0])
    font_size = 36
    dpi = 96
    face.set_char_size(0, int(font_size * 3 / 4 * 64), dpi, dpi)
    outline = face.glyph.outline

    formatter.precision = 2
    document = window.document

    view_box_width = 800
    tx = 30
    ty = 50
    gap_height = 10
    text_content = 'M'

    transform = ''
    face.load_char(text_content[0])
    matrix = FTMatrix().flip_y()
    outline.transform(matrix)
    path_data = list()
    outline.decompose(_move_to, _line_to, _conic_to, _cubic_to, user=path_data)
    bbox = _add_group(document, tx, ty, text_content, transform, path_data,
                      font_family, font_size)
    ty += int(bbox.height) + gap_height

    transform = 'scale(1.5, 0.8)'
    face.load_char(text_content[0])
    matrix = FTMatrix().flip_y()
    matrix.scale_self(1.5, 0.8)
    outline.transform(matrix)
    path_data = list()
    outline.decompose(_move_to, _line_to, _conic_to, _cubic_to, user=path_data)
    bbox = _add_group(document, tx, ty, text_content, transform, path_data,
                      font_family, font_size)
    ty += int(bbox.height) + gap_height

    transform = 'rotate(30)'
    face.load_char(text_content[0])
    matrix = FTMatrix().flip_y()
    matrix.rotate_self(30)
    outline.transform(matrix)
    path_data = list()
    outline.decompose(_move_to, _line_to, _conic_to, _cubic_to, user=path_data)
    bbox = _add_group(document, tx, ty, text_content, transform, path_data,
                      font_family, font_size)
    ty += int(bbox.height) + gap_height

    transform = 'skewX(45)'
    face.load_char(text_content[0])
    matrix = FTMatrix().flip_y()
    matrix.skew_x_self(45)
    outline.transform(matrix)
    path_data = list()
    outline.decompose(_move_to, _line_to, _conic_to, _cubic_to, user=path_data)
    bbox = _add_group(document, tx, ty, text_content, transform, path_data,
                      font_family, font_size)
    ty += int(bbox.height) + gap_height

    transform = 'skewY(45)'
    face.load_char(text_content[0])
    matrix = FTMatrix().flip_y()
    matrix.skew_y_self(45)
    outline.transform(matrix)
    path_data = list()
    outline.decompose(_move_to, _line_to, _conic_to, _cubic_to, user=path_data)
    bbox = _add_group(document, tx, ty, text_content, transform, path_data,
                      font_family, font_size)
    ty += int(bbox.height) + gap_height

    transform = 'scale(1.5, 0.8) rotate(30) skewX(45) skewY(45)'
    face.load_char(text_content[0])
    matrix = FTMatrix().flip_y()
    matrix.scale_self(1.5, 0.8)
    matrix.rotate_self(30)
    matrix.skew_x_self(45)
    matrix.skew_y_self(45)
    outline.transform(matrix)
    path_data = list()
    outline.decompose(_move_to, _line_to, _conic_to, _cubic_to, user=path_data)
    bbox = _add_group(document, tx, ty, text_content, transform, path_data,
                      font_family, font_size)
    ty += int(bbox.height) + gap_height

    view_box_height = ty

    root = document.document_element
    root.attributes['width'] = str(view_box_width)
    root.attributes['height'] = str(view_box_height)
    root.attributes['viewBox'] = '0 0 {} {}'.format(view_box_width,
                                                    view_box_height)

    print(document.tostring(pretty_print=True).decode())