Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
75812be3
E
engine
项目概览
sxychenjing
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
75812be3
编写于
7月 21, 2017
作者:
G
Gary Qian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add support for multiple break strategies to better support edge case situations.
Change-Id: I61fc4d95a57b34f59073e99ad834c9a0d7ec7c76
上级
b8e18a7a
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
59 addition
and
0 deletion
+59
-0
src/paragraph.cc
src/paragraph.cc
+8
-0
src/paragraph.h
src/paragraph.h
+1
-0
src/paragraph_style.h
src/paragraph_style.h
+7
-0
src/styled_runs.h
src/styled_runs.h
+1
-0
tests/txt/paragraph_unittests.cc
tests/txt/paragraph_unittests.cc
+42
-0
未找到文件。
src/paragraph.cc
浏览文件 @
75812be3
...
...
@@ -177,8 +177,16 @@ void Paragraph::Layout(double width, bool force) {
collection_map
;
breaker_
.
setLineWidths
(
0.0
f
,
0
,
width_
);
// TODO(garyq): Get hyphenator working. Hyphenator should be created with
// a pattern binary dataset. Should be something along these lines:
//
// minikin::Hyphenator* hyph =
// minikin::Hyphenator::loadBinary(<paramsgohere>);
// breaker_.setLocale(icu::Locale::getRoot(), &hyph);
//
AddRunsToLineBreaker
(
collection_map
);
breaker_
.
setJustified
(
paragraph_style_
.
text_align
==
TextAlign
::
justify
);
breaker_
.
setStrategy
(
paragraph_style_
.
break_strategy
);
size_t
breaks_count
=
breaker_
.
computeBreaks
();
const
int
*
breaks
=
breaker_
.
getBreaks
();
...
...
src/paragraph.h
浏览文件 @
75812be3
...
...
@@ -117,6 +117,7 @@ class Paragraph {
FRIEND_TEST
(
RenderTest
,
ChineseParagraph
);
FRIEND_TEST
(
RenderTest
,
DISABLED_ArabicParagraph
);
FRIEND_TEST
(
RenderTest
,
SpacingParagraph
);
FRIEND_TEST
(
RenderTest
,
LongWordParagraph
);
std
::
vector
<
uint16_t
>
text_
;
StyledRuns
runs_
;
...
...
src/paragraph_style.h
浏览文件 @
75812be3
...
...
@@ -20,6 +20,7 @@
#include <climits>
#include <string>
#include "lib/txt/include/minikin/LineBreaker.h"
#include "lib/txt/src/font_style.h"
#include "lib/txt/src/font_weight.h"
#include "lib/txt/src/text_align.h"
...
...
@@ -36,6 +37,12 @@ class ParagraphStyle {
size_t
max_lines
=
UINT_MAX
;
double
line_height
=
1.0
;
std
::
string
ellipsis
=
"..."
;
// Default strategy is kBreakStrategy_Greedy. Sometimes,
// kBreakStrategy_HighQuality will produce more desireable layouts (eg, very
// long words are more likely to be reasonably placed).
// kBreakStrategy_Balanced will balance between the two.
minikin
::
BreakStrategy
break_strategy
=
minikin
::
BreakStrategy
::
kBreakStrategy_Greedy
;
// TODO(garyq): Implement right to left.
// Right to left (Arabic, Hebrew, etc).
bool
rtl
=
false
;
...
...
src/styled_runs.h
浏览文件 @
75812be3
...
...
@@ -70,6 +70,7 @@ class StyledRuns {
FRIEND_TEST
(
RenderTest
,
ItalicsParagraph
);
FRIEND_TEST
(
RenderTest
,
ChineseParagraph
);
FRIEND_TEST
(
RenderTest
,
DISABLED_ArabicParagraph
);
FRIEND_TEST
(
RenderTest
,
LongWordParagraph
);
struct
IndexedRun
{
size_t
style_index
=
0
;
...
...
tests/txt/paragraph_unittests.cc
浏览文件 @
75812be3
...
...
@@ -1200,7 +1200,49 @@ TEST_F(RenderTest, SpacingParagraph) {
ASSERT_EQ
(
paragraph
->
records_
[
4
].
style
().
word_spacing
,
20
);
ASSERT_EQ
(
paragraph
->
records_
[
5
].
style
().
word_spacing
,
0
);
ASSERT_EQ
(
paragraph
->
records_
[
6
].
style
().
word_spacing
,
20
);
}
TEST_F
(
RenderTest
,
LongWordParagraph
)
{
const
char
*
text
=
"A "
"veryverylongwordtoseewherethiswillwraporifitwillatallandifitdoesthenthat"
"wouldbeagoodthingbecausethebreakingisworking."
;
auto
icu_text
=
icu
::
UnicodeString
::
fromUTF8
(
text
);
std
::
u16string
u16_text
(
icu_text
.
getBuffer
(),
icu_text
.
getBuffer
()
+
icu_text
.
length
());
txt
::
ParagraphStyle
paragraph_style
;
paragraph_style
.
break_strategy
=
minikin
::
kBreakStrategy_HighQuality
;
auto
font_collection
=
FontCollection
::
GetFontCollection
(
txt
::
GetFontDir
());
txt
::
ParagraphBuilder
builder
(
paragraph_style
,
&
font_collection
);
txt
::
TextStyle
text_style
;
text_style
.
font_size
=
30
;
text_style
.
letter_spacing
=
0
;
text_style
.
word_spacing
=
0
;
text_style
.
color
=
SK_ColorBLACK
;
text_style
.
height
=
1
;
builder
.
PushStyle
(
text_style
);
builder
.
AddText
(
u16_text
);
builder
.
Pop
();
auto
paragraph
=
builder
.
Build
();
paragraph
->
Layout
(
GetTestCanvasWidth
()
/
2
);
paragraph
->
Paint
(
GetCanvas
(),
0
,
0
);
ASSERT_TRUE
(
Snapshot
());
ASSERT_EQ
(
paragraph
->
text_
.
size
(),
std
::
string
{
text
}.
length
());
for
(
size_t
i
=
0
;
i
<
u16_text
.
length
();
i
++
)
{
ASSERT_EQ
(
paragraph
->
text_
[
i
],
u16_text
[
i
]);
}
ASSERT_EQ
(
paragraph
->
runs_
.
runs_
.
size
(),
1ull
);
ASSERT_EQ
(
paragraph
->
runs_
.
styles_
.
size
(),
1ull
);
ASSERT_TRUE
(
paragraph
->
runs_
.
styles_
[
0
].
equals
(
text_style
));
ASSERT_EQ
(
paragraph
->
records_
[
0
].
style
().
color
,
text_style
.
color
);
ASSERT_EQ
(
paragraph
->
GetLineCount
(),
4
);
ASSERT_TRUE
(
Snapshot
());
}
}
// namespace txt
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录