Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
1263d28a
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,发现更多精彩内容 >>
未验证
提交
1263d28a
编写于
2月 19, 2019
作者:
G
Gary Qian
提交者:
GitHub
2月 19, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix caret being at left edge when newline pressed on centered text (#7875)
上级
f45572e9
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
82 addition
and
0 deletion
+82
-0
third_party/txt/src/txt/paragraph.cc
third_party/txt/src/txt/paragraph.cc
+5
-0
third_party/txt/tests/paragraph_unittests.cc
third_party/txt/tests/paragraph_unittests.cc
+77
-0
未找到文件。
third_party/txt/src/txt/paragraph.cc
浏览文件 @
1263d28a
...
...
@@ -1302,6 +1302,11 @@ std::vector<Paragraph::TextBox> Paragraph::GetRectsForRange(
if
(
line
.
end
!=
line
.
end_including_newline
&&
line
.
end
>=
start
&&
line
.
end_including_newline
<=
end
)
{
SkScalar
x
=
line_widths_
[
line_number
];
// Move empty box to center if center aligned and is an empty line.
if
(
x
==
0
&&
!
isinf
(
width_
)
&&
paragraph_style_
.
effective_align
()
==
TextAlign
::
center
)
{
x
=
width_
/
2
;
}
SkScalar
top
=
(
line_number
>
0
)
?
line_heights_
[
line_number
-
1
]
:
0
;
SkScalar
bottom
=
line_heights_
[
line_number
];
line_metrics
[
line_number
].
boxes
.
emplace_back
(
...
...
third_party/txt/tests/paragraph_unittests.cc
浏览文件 @
1263d28a
...
...
@@ -1780,6 +1780,83 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(GetRectsForRangeCenterParagraph)) {
ASSERT_TRUE
(
Snapshot
());
}
TEST_F
(
ParagraphTest
,
DISABLE_ON_WINDOWS
(
GetRectsForRangeCenterParagraphNewlineCentered
))
{
const
char
*
text
=
"01234
\n
"
;
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
.
max_lines
=
10
;
paragraph_style
.
text_align
=
TextAlign
::
center
;
txt
::
ParagraphBuilder
builder
(
paragraph_style
,
GetTestFontCollection
());
txt
::
TextStyle
text_style
;
text_style
.
font_families
=
std
::
vector
<
std
::
string
>
(
1
,
"Roboto"
);
text_style
.
font_size
=
50
;
text_style
.
letter_spacing
=
0
;
text_style
.
font_weight
=
FontWeight
::
w500
;
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
(
550
);
paragraph
->
Paint
(
GetCanvas
(),
0
,
0
);
SkPaint
paint
;
paint
.
setStyle
(
SkPaint
::
kStroke_Style
);
paint
.
setAntiAlias
(
true
);
paint
.
setStrokeWidth
(
1
);
// Tests for GetRectsForRange()
Paragraph
::
RectHeightStyle
rect_height_style
=
Paragraph
::
RectHeightStyle
::
kMax
;
Paragraph
::
RectWidthStyle
rect_width_style
=
Paragraph
::
RectWidthStyle
::
kTight
;
paint
.
setColor
(
SK_ColorRED
);
std
::
vector
<
txt
::
Paragraph
::
TextBox
>
boxes
=
paragraph
->
GetRectsForRange
(
0
,
0
,
rect_height_style
,
rect_width_style
);
for
(
size_t
i
=
0
;
i
<
boxes
.
size
();
++
i
)
{
GetCanvas
()
->
drawRect
(
boxes
[
i
].
rect
,
paint
);
}
EXPECT_EQ
(
boxes
.
size
(),
0ull
);
boxes
=
paragraph
->
GetRectsForRange
(
0
,
1
,
rect_height_style
,
rect_width_style
);
for
(
size_t
i
=
0
;
i
<
boxes
.
size
();
++
i
)
{
GetCanvas
()
->
drawRect
(
boxes
[
i
].
rect
,
paint
);
}
EXPECT_EQ
(
boxes
.
size
(),
1ull
);
EXPECT_FLOAT_EQ
(
boxes
[
0
].
rect
.
left
(),
203.95508
);
EXPECT_FLOAT_EQ
(
boxes
[
0
].
rect
.
top
(),
0.40625
);
EXPECT_FLOAT_EQ
(
boxes
[
0
].
rect
.
right
(),
232.37305
);
EXPECT_FLOAT_EQ
(
boxes
[
0
].
rect
.
bottom
(),
59
);
paint
.
setColor
(
SK_ColorGREEN
);
boxes
=
paragraph
->
GetRectsForRange
(
6
,
7
,
rect_height_style
,
rect_width_style
);
for
(
size_t
i
=
0
;
i
<
boxes
.
size
();
++
i
)
{
GetCanvas
()
->
drawRect
(
boxes
[
i
].
rect
,
paint
);
}
EXPECT_EQ
(
boxes
.
size
(),
1ull
);
EXPECT_FLOAT_EQ
(
boxes
[
0
].
rect
.
left
(),
275
);
EXPECT_FLOAT_EQ
(
boxes
[
0
].
rect
.
right
(),
275
);
EXPECT_FLOAT_EQ
(
boxes
[
0
].
rect
.
bottom
(),
75
);
// TODO(garyq): This value can be improved... Should be
// taller, but we need a good way to obtain a height
// without any glyphs on the line.
ASSERT_TRUE
(
Snapshot
());
}
TEST_F
(
ParagraphTest
,
DISABLE_ON_WINDOWS
(
GetRectsForRangeCenterMultiLineParagraph
))
{
const
char
*
text
=
"01234
\n
0123 "
;
// includes ideographic
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录