Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Harfbuzz
提交
058b1260
T
Third Party Harfbuzz
项目概览
OpenHarmony
/
Third Party Harfbuzz
1 年多 前同步成功
通知
0
Star
18
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Harfbuzz
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
058b1260
编写于
2月 01, 2018
作者:
G
Garret Rieger
提交者:
Rod Sheeter
2月 04, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Re-write hb-subset utility to use main-font-text driver.
上级
ede84ffa
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
82 addition
and
67 deletion
+82
-67
test/subset/run-tests.py
test/subset/run-tests.py
+9
-6
util/Makefile.sources
util/Makefile.sources
+3
-0
util/hb-subset.cc
util/hb-subset.cc
+70
-61
未找到文件。
test/subset/run-tests.py
浏览文件 @
058b1260
...
...
@@ -30,22 +30,25 @@ def fail_test(test, cli_args, message):
print
(
'Test State:'
)
print
(
' test.font_path %s'
%
os
.
path
.
abspath
(
test
.
font_path
))
print
(
' test.profile_path %s'
%
os
.
path
.
abspath
(
test
.
profile_path
))
print
(
' test.unicodes
%s'
%
test
.
unicodes
())
print
(
' test.unicodes
%s'
%
test
.
unicodes
())
expected_file
=
os
.
path
.
join
(
test_suite
.
get_output_directory
(),
test
.
get_font_name
())
print
(
' expected_file
%s'
%
os
.
path
.
abspath
(
expected_file
))
test
.
get_font_name
())
print
(
' expected_file
%s'
%
os
.
path
.
abspath
(
expected_file
))
return
1
def
run_test
(
test
):
out_file
=
os
.
path
.
join
(
tempfile
.
mkdtemp
(),
test
.
get_font_name
()
+
'-subset.ttf'
)
cli_args
=
[
hb_subset
,
test
.
font_path
,
out_file
,
"--unicodes=%s"
%
test
.
unicodes
()]
out_file
=
os
.
path
.
join
(
tempfile
.
mkdtemp
(),
test
.
get_font_name
()
+
'-subset.ttf'
)
cli_args
=
[
hb_subset
,
"--font-file="
+
test
.
font_path
,
"--output-file="
+
out_file
,
"--unicodes=%s"
%
test
.
unicodes
()]
_
,
return_code
=
cmd
(
cli_args
)
if
return_code
:
return
fail_test
(
test
,
cli_args
,
"%s returned %d"
%
(
' '
.
join
(
cli_args
),
return_code
))
expected
=
read_binary
(
os
.
path
.
join
(
test_suite
.
get_output_directory
(),
test
.
get_font_name
()))
test
.
get_font_name
()))
actual
=
read_binary
(
out_file
)
if
len
(
actual
)
!=
len
(
expected
):
...
...
util/Makefile.sources
浏览文件 @
058b1260
...
...
@@ -31,4 +31,7 @@ HB_OT_SHAPE_CLOSURE_sources = \
HB_SUBSET_sources
=
\
hb-subset.cc
\
options.cc
\
options.hh
\
main-font-text.hh
\
$(NULL)
util/hb-subset.cc
浏览文件 @
058b1260
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
/*
* Copyright © 2010 Behdad Esfahbod
* Copyright © 2011,2012 Google, Inc.
*
* This is part of HarfBuzz, a text shaping library.
*
* Permission is hereby granted, without written agreement and without
* license or royalty fees, to use, copy, modify, and distribute this
* software and its documentation for any purpose, provided that the
* above copyright notice and the following two paragraphs appear in
* all copies of this software.
*
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* Google Author(s): Garret Rieger, Rod Sheeter
*/
#include "hb-private.hh"
#include "hb-blob.h"
#include "main-font-text.hh"
int
main
(
int
argc
,
char
**
argv
)
{
int
exit_code
=
0
;
/*
* Command line interface to the harfbuzz font subsetter.
*/
if
(
argc
!=
4
)
{
fprintf
(
stderr
,
"Must have 4 args
\n
"
);
exit
(
1
);
}
struct
subset_consumer_t
{
subset_consumer_t
(
option_parser_t
*
parser
)
:
failed
(
false
),
options
(
parser
)
{
}
int
fd
=
open
(
argv
[
1
],
O_RDONLY
);
if
(
fd
==
-
1
)
{
perror
(
"Unable to open font file"
);
exit
(
1
);
void
init
(
hb_buffer_t
*
buffer_
,
const
font_options_t
*
font_opts
)
{
font
=
hb_font_reference
(
font_opts
->
get_font
()
);
}
void
*
mapped_file
=
MAP_FAILED
;
int
fd_out
=
-
1
;
struct
stat
stat
;
if
(
fstat
(
fd
,
&
stat
)
!=
-
1
)
{
mapped_file
=
mmap
(
NULL
,
stat
.
st_size
,
PROT_READ
,
MAP_PRIVATE
,
fd
,
0
);
if
(
mapped_file
==
MAP_FAILED
)
{
perror
(
"Failed to map file"
);
}
}
else
{
perror
(
"Unable to fstat"
);
void
consume_line
(
const
char
*
text
,
unsigned
int
text_len
,
const
char
*
text_before
,
const
char
*
text_after
)
{
}
if
(
mapped_file
!=
MAP_FAILED
)
{
hb_blob_t
*
font_blob
=
hb_blob_create
(
static_cast
<
const
char
*>
(
mapped_file
),
stat
.
st_size
,
HB_MEMORY_MODE_READONLY
,
nullptr
,
nullptr
);
void
finish
(
const
font_options_t
*
font_opts
)
{
hb_face_t
*
face
=
hb_font_get_face
(
font
);
hb_blob_t
*
result
=
hb_face_reference_blob
(
face
);
unsigned
int
data_length
;
const
char
*
data
=
hb_blob_get_data
(
result
,
&
data_length
);
fd_out
=
open
(
argv
[
2
]
,
O_CREAT
|
O_WRONLY
,
S_IRWXU
);
int
fd_out
=
open
(
options
.
output_file
,
O_CREAT
|
O_WRONLY
,
S_IRWXU
);
if
(
fd_out
!=
-
1
)
{
ssize_t
bytes_written
=
write
(
fd_out
,
mapped_file
,
stat
.
st_size
);
ssize_t
bytes_written
=
write
(
fd_out
,
data
,
data_length
);
if
(
bytes_written
==
-
1
)
{
perror
(
"Unable to write output file"
);
exit_code
=
1
;
}
else
if
(
bytes_written
!=
stat
.
st_size
)
{
fprintf
(
stderr
,
"Unable to write output file"
);
failed
=
true
;
}
else
if
(
bytes_written
!=
data_length
)
{
fprintf
(
stderr
,
"Wrong number of bytes written"
);
exit_code
=
1
;
failed
=
true
;
}
}
else
{
perror
(
"Unable to open output file"
);
exit_code
=
1
;
fprintf
(
stderr
,
"Unable to open output file"
);
failed
=
true
;
}
}
if
(
mapped_file
!=
MAP_FAILED
)
{
if
(
munmap
(
mapped_file
,
stat
.
st_size
)
==
-
1
)
{
perror
(
"Unable to unmap file"
);
exit_code
=
1
;
}
hb_blob_destroy
(
result
);
hb_font_destroy
(
font
);
}
if
(
fd_out
!=
-
1
&&
close
(
fd_out
)
==
-
1
)
{
perror
(
"Unable to close output file"
);
exit_code
=
1
;
}
public:
bool
failed
;
if
(
fd
!=
-
1
&&
close
(
fd
)
==
-
1
)
{
perror
(
"Unable to close file"
)
;
exit_code
=
1
;
}
private:
output_options_t
options
;
hb_font_t
*
font
;
};
return
exit_code
;
int
main
(
int
argc
,
char
**
argv
)
{
main_font_text_t
<
subset_consumer_t
,
10
,
0
>
driver
;
return
driver
.
main
(
argc
,
argv
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录