Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
evm-store
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wanli
evm-store
Commits
391a58ba
Commit
391a58ba
authored
Aug 19, 2021
by
wanli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
✨
feat: evuefonttool.py新增字段
parent
adc92e5a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
7 deletions
+14
-7
backend/utils/evuefonttool.py
backend/utils/evuefonttool.py
+14
-7
No files found.
backend/utils/evuefonttool.py
View file @
391a58ba
...
@@ -64,10 +64,9 @@ class EvueFontTool(object):
...
@@ -64,10 +64,9 @@ class EvueFontTool(object):
'advance'
:
self
.
face
.
glyph
.
advance
.
x
/
64
,
'advance'
:
self
.
face
.
glyph
.
advance
.
x
/
64
,
'cols'
:
self
.
face
.
glyph
.
bitmap
.
width
,
'cols'
:
self
.
face
.
glyph
.
bitmap
.
width
,
'rows'
:
self
.
face
.
glyph
.
bitmap
.
rows
,
'rows'
:
self
.
face
.
glyph
.
bitmap
.
rows
,
'bitmap'
:
self
.
face
.
glyph
.
bitmap
.
buffer
,
# list[]
'count'
:
len
(
self
.
face
.
glyph
.
bitmap
.
buffer
),
'count'
:
len
(
self
.
face
.
glyph
.
bitmap
.
buffer
),
}
}
return
char_info
return
char_info
,
self
.
face
.
glyph
.
bitmap
.
buffer
def
dump
(
self
,
used_string
):
def
dump
(
self
,
used_string
):
# 遍历每一个字体
# 遍历每一个字体
...
@@ -75,6 +74,7 @@ class EvueFontTool(object):
...
@@ -75,6 +74,7 @@ class EvueFontTool(object):
'name'
:
self
.
fontInfo
.
get
(
"family"
),
'name'
:
self
.
fontInfo
.
get
(
"family"
),
'info'
:
self
.
fontInfo
,
'info'
:
self
.
fontInfo
,
'text'
:
used_string
,
'text'
:
used_string
,
'charInfo'
:
{},
'size'
:
self
.
sizes
,
'size'
:
self
.
sizes
,
'bitmap'
:
{
'bitmap'
:
{
'total'
:
0
'total'
:
0
...
@@ -85,15 +85,22 @@ class EvueFontTool(object):
...
@@ -85,15 +85,22 @@ class EvueFontTool(object):
for
size
in
self
.
sizes
:
for
size
in
self
.
sizes
:
# 设置字体大小
# 设置字体大小
self
.
face
.
set_char_size
(
size
*
64
,
0
,
self
.
FONT_DPI
,
0
)
self
.
face
.
set_char_size
(
size
*
64
,
0
,
self
.
FONT_DPI
,
0
)
char_info
=
self
.
charInfo
(
cur_char
)
char_info
,
bitmap
=
self
.
charInfo
(
cur_char
)
self
.
infos
.
append
(
char_info
)
self
.
infos
.
append
(
char_info
)
size_key
=
str
(
size
)
if
size_key
not
in
dump_json
[
'charInfo'
]:
dump_json
[
'charInfo'
][
size_key
]
=
{}
else
:
dump_json
[
'charInfo'
][
size_key
]
.
update
({
str
(
char_info
.
get
(
'glyph'
)):
char_info
})
# 文件命名规则:./<output_dir>/<font-size>/<unicode-number>.bin
# 文件命名规则:./<output_dir>/<font-size>/<unicode-number>.bin
target_dir
=
self
.
output_dir
.
joinpath
(
str
(
size
))
.
joinpath
(
"{}.bin"
.
format
(
char_info
.
get
(
'glyph'
)))
target_dir
=
self
.
output_dir
.
joinpath
(
str
(
size
))
.
joinpath
(
"{}.bin"
.
format
(
char_info
.
get
(
'glyph'
)))
if
not
target_dir
.
parent
.
exists
():
if
not
target_dir
.
parent
.
exists
():
target_dir
.
parent
.
mkdir
()
target_dir
.
parent
.
mkdir
()
with
open
(
target_dir
.
resolve
()
.
as_posix
(),
'wb+'
)
as
f
:
with
open
(
target_dir
.
resolve
()
.
as_posix
(),
'wb+'
)
as
f
:
f
.
write
(
struct
.
pack
(
"
%
dB"
%
char_info
[
'count'
],
*
char_info
[
'bitmap'
]
))
f
.
write
(
struct
.
pack
(
"
%
dB"
%
char_info
[
'count'
],
*
bitmap
))
dump_json
[
'bitmap'
]
.
update
({
dump_json
[
'bitmap'
]
.
update
({
size
:
dump_json
.
get
(
'bitmap'
)
.
get
(
size
,
0
)
+
target_dir
.
stat
()
.
st_size
size
:
dump_json
.
get
(
'bitmap'
)
.
get
(
size
,
0
)
+
target_dir
.
stat
()
.
st_size
...
@@ -106,7 +113,7 @@ class EvueFontTool(object):
...
@@ -106,7 +113,7 @@ class EvueFontTool(object):
pprint
.
pprint
(
dump_json
)
pprint
.
pprint
(
dump_json
)
# 在输出目录下,生成一个json索引文件
# 在输出目录下,生成一个json索引文件
with
open
(
self
.
output_dir
.
joinpath
(
"fonts.json"
)
.
resolve
()
.
as_posix
(),
"wb+"
)
as
f
:
with
open
(
self
.
output_dir
.
joinpath
(
"fonts.json"
)
.
resolve
()
.
as_posix
(),
"wb+"
)
as
f
:
f
.
write
(
json
.
dumps
(
dump_json
,
ensure_ascii
=
False
,
indent
=
2
)
.
encode
(
'utf-8'
))
f
.
write
(
json
.
dumps
(
dump_json
,
ensure_ascii
=
False
)
.
encode
(
'utf-8'
))
def
load
(
self
,
file
):
def
load
(
self
,
file
):
pass
pass
...
@@ -131,9 +138,9 @@ class EvueFontTool(object):
...
@@ -131,9 +138,9 @@ class EvueFontTool(object):
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
print
(
mimetypes
.
guess_type
(
sys
.
argv
[
1
])[
0
])
#
print(mimetypes.guess_type(sys.argv[1])[0])
evueFontTool
=
EvueFontTool
(
sys
.
argv
[
1
],
sys
.
argv
[
2
])
evueFontTool
=
EvueFontTool
(
sys
.
argv
[
1
],
sys
.
argv
[
2
])
text
=
'中国'
text
=
'
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890
中国'
# evueFontTool.test(text)
# evueFontTool.test(text)
evueFontTool
.
dump
(
text
)
evueFontTool
.
dump
(
text
)
pprint
.
pprint
(
evueFontTool
.
fontInfo
)
pprint
.
pprint
(
evueFontTool
.
fontInfo
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment