Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
b4a5a47d
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,发现更多精彩内容 >>
提交
b4a5a47d
编写于
6月 19, 2017
作者:
G
Gary Qian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add preliminary support for letter-spacing and word-spacing
Change-Id: If3f64cf0c18ff0aa087091626532bcd983f6b54c
上级
2876b631
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
20 addition
and
20 deletion
+20
-20
src/paragraph.cc
src/paragraph.cc
+10
-10
tests/txt/paragraph_unittests.cc
tests/txt/paragraph_unittests.cc
+10
-10
未找到文件。
src/paragraph.cc
浏览文件 @
b4a5a47d
...
...
@@ -149,7 +149,7 @@ void Paragraph::Layout(double width,
// Reset member variables so Layout still works when called more than once
max_intrinsic_width_
=
0.0
f
;
lines_
=
1
;
lines_
=
0
;
minikin
::
Layout
layout
;
SkScalar
x
=
x_offset
;
...
...
@@ -170,8 +170,7 @@ void Paragraph::Layout(double width,
size_t
layout_start
=
run
.
start
;
while
(
layout_start
<
run
.
end
&&
GetLineCount
()
<=
paragraph_style_
.
max_lines
)
{
while
(
layout_start
<
run
.
end
&&
lines_
<
paragraph_style_
.
max_lines
)
{
const
size_t
next_break
=
(
break_index
>
breaks_count
-
1
)
?
std
::
numeric_limits
<
size_t
>::
max
()
:
breaks
[
break_index
];
...
...
@@ -194,14 +193,15 @@ void Paragraph::Layout(double width,
const
size_t
glyph_index
=
blob_start
+
blob_index
;
buffer
.
glyphs
[
blob_index
]
=
layout
.
getGlyphId
(
glyph_index
);
const
size_t
pos_index
=
2
*
blob_index
;
letter_spacing_offset
+=
run
.
style
.
letter_spacing
;
buffer
.
pos
[
pos_index
]
=
layout
.
getX
(
glyph_index
)
+
letter_spacing_offset
+
word_spacing_offset
;
letter_spacing_offset
+=
run
.
style
.
letter_spacing
;
buffer
.
pos
[
pos_index
+
1
]
=
layout
.
getY
(
glyph_index
);
}
blob_start
+=
blob_length
;
// Subtract letter offset to avoid big gap at end of run.
// Subtract letter offset to avoid big gap at end of run. This my be
// removed depending on the specificatins for letter spacing.
letter_spacing_offset
-=
run
.
style
.
letter_spacing
;
word_spacing_offset
+=
run
.
style
.
word_spacing
;
...
...
@@ -210,6 +210,10 @@ void Paragraph::Layout(double width,
layout
.
getX
(
blob_start
-
1
)
+
letter_spacing_offset
;
}
// Subtract word offset to avoid big gap at end of run. This my be
// removed depending on the specificatins for word spacing.
word_spacing_offset
-=
run
.
style
.
word_spacing
;
// TODO(abarth): We could keep the same SkTextBlobBuilder as long as the
// color stayed the same.
records_
.
push_back
(
...
...
@@ -224,8 +228,6 @@ void Paragraph::Layout(double width,
y_
+=
run
.
style
.
font_size
*
run
.
style
.
height
;
break_index
+=
1
;
lines_
++
;
if
(
lines_
>
paragraph_style_
.
max_lines
)
lines_
--
;
}
else
{
x
+=
layout
.
getAdvance
();
}
...
...
@@ -259,8 +261,7 @@ double Paragraph::GetMinIntrinsicWidth() const {
}
double
Paragraph
::
GetHeight
()
const
{
return
paragraph_style_
.
font_size
*
paragraph_style_
.
line_height
*
paragraph_style_
.
max_lines
;
return
y_
;
}
void
Paragraph
::
SetParagraphStyle
(
const
ParagraphStyle
&
style
)
{
...
...
@@ -277,7 +278,6 @@ void Paragraph::Paint(SkCanvas* canvas, double x, double y) {
}
int
Paragraph
::
GetLineCount
()
const
{
// FTL_LOG(INFO) << "Lines: " << lines_;
return
lines_
;
}
...
...
tests/txt/paragraph_unittests.cc
浏览文件 @
b4a5a47d
...
...
@@ -92,25 +92,25 @@ TEST_F(RenderTest, SimpleRedParagraph) {
}
TEST_F
(
RenderTest
,
RainbowParagraph
)
{
const
char
*
text1
=
"Red
Roboto
"
;
const
char
*
text1
=
"Red
Roboto
"
;
auto
icu_text1
=
icu
::
UnicodeString
::
fromUTF8
(
text1
);
std
::
u16string
u16_text1
(
icu_text1
.
getBuffer
(),
icu_text1
.
getBuffer
()
+
icu_text1
.
length
());
const
char
*
text2
=
"Big Green Default
"
;
const
char
*
text2
=
"Big Green Default"
;
auto
icu_text2
=
icu
::
UnicodeString
::
fromUTF8
(
text2
);
std
::
u16string
u16_text2
(
icu_text2
.
getBuffer
(),
icu_text2
.
getBuffer
()
+
icu_text2
.
length
());
const
char
*
text3
=
"Defcolor
HomemadeApple
"
;
const
char
*
text3
=
"Defcolor
Homemade Apple
"
;
auto
icu_text3
=
icu
::
UnicodeString
::
fromUTF8
(
text3
);
std
::
u16string
u16_text3
(
icu_text3
.
getBuffer
(),
icu_text3
.
getBuffer
()
+
icu_text3
.
length
());
const
char
*
text4
=
"Small
BlueRoboto
"
;
const
char
*
text4
=
"Small
Blue Roboto
"
;
auto
icu_text4
=
icu
::
UnicodeString
::
fromUTF8
(
text4
);
std
::
u16string
u16_text4
(
icu_text4
.
getBuffer
(),
icu_text4
.
getBuffer
()
+
icu_text4
.
length
());
const
char
*
text5
=
"Continue Last Style With lots of words to check if it overlaps
properly
"
"or not"
;
"Continue Last Style With lots of words to check if it overlaps "
"
properly
or not"
;
auto
icu_text5
=
icu
::
UnicodeString
::
fromUTF8
(
text5
);
std
::
u16string
u16_text5
(
icu_text5
.
getBuffer
(),
icu_text5
.
getBuffer
()
+
icu_text5
.
length
());
...
...
@@ -281,13 +281,13 @@ TEST_F(RenderTest, LinebreakParagraph) {
icu_text
.
getBuffer
()
+
icu_text
.
length
());
txt
::
ParagraphStyle
paragraph_style
;
paragraph_style
.
max_lines
=
1
000
;
paragraph_style
.
max_lines
=
1
4
;
txt
::
ParagraphBuilder
builder
(
paragraph_style
);
txt
::
TextStyle
text_style
;
text_style
.
font_size
=
26
;
// Letter spacing not yet implemented
text_style
.
letter_spacing
=
1
0
;
text_style
.
letter_spacing
=
0
;
text_style
.
color
=
SK_ColorBLACK
;
text_style
.
height
=
1.15
;
builder
.
PushStyle
(
text_style
);
...
...
@@ -297,9 +297,9 @@ TEST_F(RenderTest, LinebreakParagraph) {
builder
.
Pop
();
auto
paragraph
=
builder
.
Build
();
paragraph
->
Layout
(
GetTestCanvasWidth
(),
txt
::
GetFontDir
());
paragraph
->
Layout
(
GetTestCanvasWidth
()
-
100
,
txt
::
GetFontDir
());
paragraph
->
Paint
(
GetCanvas
(),
5.
0
,
30.0
);
paragraph
->
Paint
(
GetCanvas
(),
0
,
30.0
);
ASSERT_EQ
(
paragraph
->
text_
.
size
(),
std
::
string
{
text
}.
length
());
for
(
size_t
i
=
0
;
i
<
u16_text
.
length
();
i
++
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录