File: create_font.py

package info (click to toggle)
goxel 0.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 13,232 kB
  • sloc: ansic: 87,714; cpp: 87,537; python: 128; makefile: 74; xml: 55
file content (50 lines) | stat: -rwxr-xr-x 1,513 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/python
#encoding: utf-8

# Goxel 3D voxels editor
#
# copyright (c) 2018 Guillaume Chereau <guillaume@noctua-software.com>
#
# Goxel is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# Goxel is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# goxel.  If not, see <http://www.gnu.org/licenses/>.


# ************************************************************************
# Generate a small font file by removing all unwanted characters from a base
# font.

import fontforge
import unicodedata

PATH = "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"

CHARS = (u"abcdefghijklmnopqrstuvwxyz"
         u"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
         u"0123456789"
         u" ?!\"#$%&'()*+,-./°¯[]^:<>{}@_=±"
         u"◀▶▲▼▴▾●©"
         )

font = fontforge.open(PATH)
for g in font:
    u = font[g].unicode
    if u == -1: continue
    u = unichr(u)
    if u not in CHARS: continue
    font.selection[ord(u)] = True

font.selection.invert()
for i in font.selection.byGlyphs:
    font.removeGlyph(i)

font.generate("data/fonts/DejaVuSans-light.ttf")