Add monospace font variant
.gitignore
8 | 8 | __pycache__ | |
9 | 9 | offlate.spec | |
10 | 10 | whitespace.ttf | |
11 | + | whitespace-mono.ttf | |
12 | + | fontforge_whitespace |
Makefile
34 | 34 | update-data: | |
35 | 35 | python3 extractdata.py | |
36 | 36 | ||
37 | - | fonts: offlate/ui/data/whitespace.ttf | |
37 | + | fonts: offlate/ui/data/whitespace.ttf offlate/ui/data/whitespace-mono.ttf | |
38 | 38 | ||
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 | |
40 | 45 | fontforge -lang=ff -script fontforge_whitespace | |
41 | 46 | ||
42 | 47 | 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
271 | 271 | for k in data.msgstrs: | |
272 | 272 | form = SpellCheckEdit(self.project.lang) | |
273 | 273 | form.setFont(QFont(font)) | |
274 | + | form.setMonospace(self.monospace) | |
274 | 275 | form.setPlainText(data.msgstrs[k]) | |
275 | 276 | form.textChanged.connect(self.modify) | |
276 | 277 | self.msgstr.addTab(form, self.tr(k)) | |
… | |||
298 | 299 | for msgstr in data.msgstrs: | |
299 | 300 | form = SpellCheckEdit(self.project.lang) | |
300 | 301 | form.setFont(QFont(font)) | |
302 | + | form.setMonospace(self.monospace) | |
301 | 303 | form.setPlainText(msgstr) | |
302 | 304 | form.textChanged.connect(self.modify) | |
303 | 305 | self.msgstr.addTab(form, str(i)) | |
… | |||
320 | 322 | i = 0 | |
321 | 323 | for msgstr in data.msgstrs: | |
322 | 324 | form = SpellCheckEdit(self.project.lang) | |
325 | + | form.setMonospace(self.monospace) | |
323 | 326 | form.setFont(QFont(font)) | |
324 | 327 | form.setPlainText(msgstr) | |
325 | 328 | form.textChanged.connect(self.modify) | |
… | |||
335 | 338 | self.msgid.createLinks() | |
336 | 339 | self.msgid.anchorClicked.connect(self.copyTag) | |
337 | 340 | self.msgstr = SpellCheckEdit(self.project.lang) | |
341 | + | self.msgstr.setMonospace(self.monospace) | |
338 | 342 | self.msgstr.setFont(QFont(font)) | |
339 | 343 | self.msgstr.setPlainText(data.msgstrs[0]) | |
340 | 344 | self.msgstr.textChanged.connect(self.modify) |
offlate/ui/spellcheckedit.py
70 | 70 | ||
71 | 71 | cursor.endEditBlock() | |
72 | 72 | ||
73 | + | def setMonospace(self, monospace): | |
74 | + | Highlighter.setMonospace(monospace) | |
75 | + | ||
73 | 76 | class Highlighter(QSyntaxHighlighter): | |
74 | 77 | _spaceFontFamily = None | |
78 | + | _spaceMonoFontFamily = None | |
79 | + | _monospace = False | |
75 | 80 | ||
76 | 81 | def __init__(self, *args): | |
77 | 82 | QSyntaxHighlighter.__init__(self, *args) | |
… | |||
92 | 97 | self.setFormat(word_object.start(), word_object.end() - word_object.start(), format) | |
93 | 98 | ||
94 | 99 | format = QTextCharFormat() | |
95 | - | format.setFont(QFont(Highlighter.getSpaceFontFamily())) | |
100 | + | format.setFont(QFont(Highlighter.getFontFamily())) | |
96 | 101 | format.setForeground(Qt.gray) | |
97 | 102 | ||
98 | 103 | for word_object in re.finditer(r'\s+', text): | |
99 | 104 | self.setFormat(word_object.start(), word_object.end() - word_object.start(), format) | |
100 | 105 | ||
101 | 106 | @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 | |
102 | 118 | def getSpaceFontFamily(): | |
103 | 119 | font = Highlighter._spaceFontFamily | |
104 | 120 | if font is None: | |
105 | 121 | id = QFontDatabase.addApplicationFont(os.path.dirname(__file__) + '/data/whitespace.ttf') | |
106 | 122 | 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 | |
107 | 133 | return font | |
108 | 134 | ||
109 | 135 | if __name__ == '__main__': |