Add monospace font variant

Julien LepillerFri Aug 27 14:09:49+0200 2021

976113f

Add monospace font variant

.gitignore

88
__pycache__
99
offlate.spec
1010
whitespace.ttf
11+
whitespace-mono.ttf
12+
fontforge_whitespace

Makefile

3434
update-data:
3535
	python3 extractdata.py
3636
37-
fonts: offlate/ui/data/whitespace.ttf
37+
fonts: offlate/ui/data/whitespace.ttf offlate/ui/data/whitespace-mono.ttf
3838
39-
offlate/ui/data/whitespace.ttf: offlate/ui/data/whitespace.sfd
39+
# prevent sphinx from taking over this target
40+
%.sfd:
41+
42+
%.ttf: %.sfd
43+
	echo 'Open("$<")' > fontforge_whitespace
44+
	echo 'Generate("$@")' >> fontforge_whitespace
4045
	fontforge -lang=ff -script fontforge_whitespace
4146
4247
LANGS=en fr

fontforge_whitespace unknown status 2

1-
Open("offlate/ui/data/whitespace.sfd")
2-
Generate("offlate/ui/data/whitespace.ttf")

offlate/ui/data/whitespace-mono.sfd unknown status 1

1+
SplineFontDB: 3.2
2+
FontName: WhitespaceMono
3+
FullName: WhitespaceMono
4+
FamilyName: WhitespaceMono
5+
Weight: Regular
6+
Copyright: Copyright (c) 2020, Julien Lepiller
7+
UComments: "2020-11-13: Created with FontForge (http://fontforge.org)"
8+
Version: 001.000
9+
ItalicAngle: 0
10+
UnderlinePosition: -99
11+
UnderlineWidth: 49
12+
Ascent: 1638
13+
Descent: 410
14+
InvalidEm: 0
15+
LayerCount: 2
16+
Layer: 0 0 "Arri+AOgA-re" 1
17+
Layer: 1 0 "Avant" 0
18+
XUID: [1021 976 1692031623 15344048]
19+
StyleMap: 0x0000
20+
FSType: 0
21+
OS2Version: 0
22+
OS2_WeightWidthSlopeOnly: 0
23+
OS2_UseTypoMetrics: 1
24+
CreationTime: 1605296929
25+
ModificationTime: 1630066041
26+
OS2TypoAscent: 0
27+
OS2TypoAOffset: 1
28+
OS2TypoDescent: 0
29+
OS2TypoDOffset: 1
30+
OS2TypoLinegap: 90
31+
OS2WinAscent: 0
32+
OS2WinAOffset: 1
33+
OS2WinDescent: 0
34+
OS2WinDOffset: 1
35+
HheadAscent: 0
36+
HheadAOffset: 1
37+
HheadDescent: 0
38+
HheadDOffset: 1
39+
OS2Vendor: 'PfEd'
40+
MarkAttachClasses: 1
41+
DEI: 91125
42+
Encoding: UnicodeFull
43+
UnicodeInterp: none
44+
NameList: AGL For New Fonts
45+
DisplaySize: -48
46+
AntiAlias: 1
47+
FitToEm: 0
48+
WinInfo: 0 38 15
49+
BeginPrivate: 0
50+
EndPrivate
51+
Grid
52+
-1000 393 m 0
53+
 2000 393 l 1024
54+
EndSplineSet
55+
BeginChars: 1114112 4
56+
57+
StartChar: space
58+
Encoding: 32 32 0
59+
Width: 870
60+
VWidth: 1000
61+
Flags: HW
62+
HStem: 211 90
63+
VStem: 389.5 91
64+
LayerCount: 2
65+
Fore
66+
SplineSet
67+
402.5 290 m 5
68+
 448.5 301 l 5
69+
 480.5 267 l 5
70+
 466.5 222 l 5
71+
 420.5 211 l 5
72+
 389.5 245 l 5
73+
 402.5 290 l 5
74+
EndSplineSet
75+
EndChar
76+
77+
StartChar: uni00A0
78+
Encoding: 160 160 1
79+
Width: 870
80+
VWidth: 1000
81+
InSpiro: 1
82+
Flags: HW
83+
HStem: 53 53<317 553>
84+
VStem: 287 30<108 225> 553 30<103 234>
85+
LayerCount: 2
86+
Fore
87+
SplineSet
88+
287 225 m 1
89+
 317 225 l 0
90+
 317 108 l 1
91+
 552.999023438 104 l 25
92+
 552.999023438 234 l 0
93+
 583 234 l 0
94+
 583 54 l 0
95+
 287 54 l 0
96+
 287 225 l 1
97+
EndSplineSet
98+
EndChar
99+
100+
StartChar: uni0009
101+
Encoding: 9 9 2
102+
Width: 870
103+
VWidth: 1000
104+
Flags: HW
105+
HStem: 174 52<364.5 698.5> 506 52<557.5 891.5>
106+
VStem: 375.5 56<422 528 536 659> 825.5 56<91 195 204 328>
107+
LayerCount: 2
108+
Fore
109+
SplineSet
110+
688.5 328 m 1
111+
 688.5 91 l 0
112+
 631.5 91 l 0
113+
 631.5 195 l 25
114+
 505.5 91 l 0
115+
 505.5 174 l 0
116+
 171.5 176 l 0
117+
 171.5 228 l 0
118+
 505.5 226 l 0
119+
 505.5 328 l 0
120+
 631.5 204 l 25
121+
 631.5 328 l 0
122+
 688.5 328 l 1
123+
181.5 659 m 1
124+
 236.5 659 l 0
125+
 238.5 536 l 25
126+
 364.5 659 l 0
127+
 364.5 558 l 0
128+
 698.5 559 l 0
129+
 698.5 508 l 0
130+
 364.5 506 l 0
131+
 363.5 422 l 0
132+
 236.5 528 l 25
133+
 236.5 422 l 0
134+
 181.5 422 l 0
135+
 181.5 659 l 1
136+
EndSplineSet
137+
EndChar
138+
139+
StartChar: uni202F
140+
Encoding: 8239 8239 3
141+
Width: 870
142+
VWidth: 1000
143+
Flags: HW
144+
HStem: 53 53<578 676>
145+
VStem: 549 30<108 225> 676 30<108 223>
146+
LayerCount: 2
147+
Fore
148+
SplineSet
149+
357 225 m 1
150+
 386 225 l 0
151+
 386 108 l 1
152+
 484 108 l 25
153+
 484 223 l 0
154+
 513 223 l 0
155+
 513 53 l 0
156+
 357 53 l 0
157+
 357 225 l 1
158+
EndSplineSet
159+
EndChar
160+
EndChars
161+
EndSplineFont

offlate/ui/editor.py

271271
            for k in data.msgstrs:
272272
                form = SpellCheckEdit(self.project.lang)
273273
                form.setFont(QFont(font))
274+
                form.setMonospace(self.monospace)
274275
                form.setPlainText(data.msgstrs[k])
275276
                form.textChanged.connect(self.modify)
276277
                self.msgstr.addTab(form, self.tr(k))

298299
            for msgstr in data.msgstrs:
299300
                form = SpellCheckEdit(self.project.lang)
300301
                form.setFont(QFont(font))
302+
                form.setMonospace(self.monospace)
301303
                form.setPlainText(msgstr)
302304
                form.textChanged.connect(self.modify)
303305
                self.msgstr.addTab(form, str(i))

320322
            i = 0
321323
            for msgstr in data.msgstrs:
322324
                form = SpellCheckEdit(self.project.lang)
325+
                form.setMonospace(self.monospace)
323326
                form.setFont(QFont(font))
324327
                form.setPlainText(msgstr)
325328
                form.textChanged.connect(self.modify)

335338
            self.msgid.createLinks()
336339
            self.msgid.anchorClicked.connect(self.copyTag)
337340
            self.msgstr = SpellCheckEdit(self.project.lang)
341+
            self.msgstr.setMonospace(self.monospace)
338342
            self.msgstr.setFont(QFont(font))
339343
            self.msgstr.setPlainText(data.msgstrs[0])
340344
            self.msgstr.textChanged.connect(self.modify)

offlate/ui/spellcheckedit.py

7070
7171
        cursor.endEditBlock()
7272
73+
    def setMonospace(self, monospace):
74+
        Highlighter.setMonospace(monospace)
75+
7376
class Highlighter(QSyntaxHighlighter):
7477
    _spaceFontFamily = None
78+
    _spaceMonoFontFamily = None
79+
    _monospace = False
7580
7681
    def __init__(self, *args):
7782
        QSyntaxHighlighter.__init__(self, *args)

9297
                self.setFormat(word_object.start(), word_object.end() - word_object.start(), format)
9398
9499
        format = QTextCharFormat()
95-
        format.setFont(QFont(Highlighter.getSpaceFontFamily()))
100+
        format.setFont(QFont(Highlighter.getFontFamily()))
96101
        format.setForeground(Qt.gray)
97102
98103
        for word_object in re.finditer(r'\s+', text):
99104
            self.setFormat(word_object.start(), word_object.end() - word_object.start(), format)
100105
101106
    @staticmethod
107+
    def setMonospace(monospace):
108+
        Highlighter._monospace = monospace
109+
110+
    @staticmethod
111+
    def getFontFamily():
112+
        if Highlighter._monospace:
113+
            return Highlighter.getSpaceMonoFontFamily()
114+
        else:
115+
            return Highlighter.getSpaceFontFamily()
116+
117+
    @staticmethod
102118
    def getSpaceFontFamily():
103119
        font = Highlighter._spaceFontFamily
104120
        if font is None:
105121
            id = QFontDatabase.addApplicationFont(os.path.dirname(__file__) + '/data/whitespace.ttf')
106122
            font = QFontDatabase.applicationFontFamilies(id)[0]
123+
            Highlighter._spaceFontFamily = font
124+
        return font
125+
126+
    @staticmethod
127+
    def getSpaceMonoFontFamily():
128+
        font = Highlighter._spaceMonoFontFamily
129+
        if font is None:
130+
            id = QFontDatabase.addApplicationFont(os.path.dirname(__file__) + '/data/whitespace-mono.ttf')
131+
            font = QFontDatabase.applicationFontFamilies(id)[0]
132+
            Highlighter._spaceMonoFontFamily = font
107133
        return font
108134
109135
if __name__ == '__main__':