Krita Source Code Documentation
Loading...
Searching...
No Matches
generateKoUnicodeBlockData.py
Go to the documentation of this file.
1
'''
2
SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
3
4
SPDX-License-Identifier: GPL-2.0-or-later
5
6
This python3 script generates the KoUnicodeBlockData.cpp file from the
7
unicode character database "Blocks.txt" file. This is so that we don't have to
8
manually add new entries everytime a new version of unicode is released.
9
'''
10
import
urllib.request
11
12
outPath =
"KoUnicodeBlockData.cpp"
13
outFile = open(outPath,
'w'
);
14
15
url =
'https://www.unicode.org/Public/16.0.0/ucd/Blocks.txt'
;
16
17
blocks = []
18
with
urllib.request.urlopen(url)
as
f:
19
blocksFile = f.read().decode(
'utf-8'
).split(
"\n"
)
20
for
line
in
blocksFile:
21
if
line.startswith(
"#"
)
or
len(line) == 0:
22
continue
23
else
:
24
block = {}
25
block[
"name"
] = line.split(
";"
)[-1].strip()
26
codes = line.split(
";"
)[0];
27
block[
"start"
] = codes.split(
".."
)[0].strip()
28
block[
"end"
] = codes.split(
".."
)[-1].strip()
29
blocks.append(block)
30
31
print(blocks)
32
33
outFile.writelines(
34
[
"/*"
35
,
"\n * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>"
36
,
"\n *"
37
,
"\n * SPDX-License-Identifier: GPL-2.0-or-later"
38
,
"\n * This file is AUTOGENERATED by generateKoUnicodeBlockData.py from:"
39
,
"\n * "
, url
40
,
"\n */"
])
41
42
outFile.writelines([
43
"\n\n#include \"KoUnicodeBlockData.h\""
44
,
"\n#include <QVector>"
45
])
46
outFile.write(
"\n"
)
47
outFile.writelines(
48
[
"\nstruct Q_DECL_HIDDEN KoUnicodeBlockDataFactory::Private"
,
49
"\n{"
,
50
"\n QVector<KoUnicodeBlockData> blockMap;"
,
51
"\n};"
])
52
outFile.write(
"\n"
)
53
outFile.writelines([
"\nKoUnicodeBlockDataFactory::KoUnicodeBlockDataFactory()"
,
"\n : d(new Private)"
,
"\n{"
,])
54
55
56
57
outFile.write(
"\n"
)
58
for
block
in
blocks:
59
outFile.writelines([
"\n d->blockMap.append(KoUnicodeBlockData(i18nc(\"@title\", \""
+ block[
"name"
] +
"\"), 0x"
+ block[
"start"
] +
", 0x"
+ block[
"end"
] +
"));"
])
60
61
outFile.writelines(
"\n}"
)
62
63
# Destructor
64
outFile.write(
"\n"
)
65
outFile.writelines([
"\nKoUnicodeBlockDataFactory::~KoUnicodeBlockDataFactory()"
,
"\n{"
,
"\n}"
])
66
67
outFile.write(
"\n"
)
68
outFile.writelines([
"\nKoUnicodeBlockData KoUnicodeBlockDataFactory::blockForUCS(const uint &codepoint)"
,
"\n{"
])
69
outFile.writelines([
"\n for (int i = 0; i < d->blockMap.size(); i++) {"
,
"\n KoUnicodeBlockData block = d->blockMap.at(i);"
,
"\n if (block.match(codepoint)) {"
,
"\n return block;"
,
"\n }"
,
"\n }\n return noBlock();"
,
"\n}"
])
70
71
outFile.close()
libs
flake
text
data
generateKoUnicodeBlockData.py
Generated at
2025-11-04 02:30:02+01:00
from
Krita
branch
master
, commit
c9dde2e79561a8aea4a7e8d9ac99c98a7bac9e52