Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
8591bd32
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,发现更多精彩内容 >>
未验证
提交
8591bd32
编写于
6月 26, 2019
作者:
G
Gary Qian
提交者:
GitHub
6月 26, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Handle ambiguous directionality of final trailing whitespace in mixed bidi text (#9489)
上级
3aff2e35
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
163 addition
and
1 deletion
+163
-1
third_party/txt/src/txt/paragraph.cc
third_party/txt/src/txt/paragraph.cc
+32
-1
third_party/txt/tests/paragraph_unittests.cc
third_party/txt/tests/paragraph_unittests.cc
+131
-0
未找到文件。
third_party/txt/src/txt/paragraph.cc
浏览文件 @
8591bd32
...
...
@@ -402,6 +402,33 @@ bool Paragraph::ComputeBidiRuns(std::vector<BidiRun>* result) {
if
(
!
U_SUCCESS
(
status
))
return
false
;
// Detect if final trailing run is a single ambiguous whitespace.
// We want to bundle the final ambiguous whitespace with the preceding
// run in order to maintain logical typing behavior when mixing RTL and LTR
// text. We do not want this to be a true ghost run since the contrasting
// directionality causes the trailing space to not render at the visual end of
// the paragraph.
//
// This only applies to the final whitespace at the end as other whitespace is
// no longer ambiguous when surrounded by additional text.
bool
has_trailing_whitespace
=
false
;
int32_t
bidi_run_start
,
bidi_run_length
;
if
(
bidi_run_count
>
1
)
{
ubidi_getVisualRun
(
bidi
.
get
(),
bidi_run_count
-
1
,
&
bidi_run_start
,
&
bidi_run_length
);
if
(
!
U_SUCCESS
(
status
))
return
false
;
if
(
bidi_run_length
==
1
)
{
UChar32
last_char
;
U16_GET
(
text_
.
data
(),
0
,
bidi_run_start
+
bidi_run_length
-
1
,
static_cast
<
int
>
(
text_
.
size
()),
last_char
);
if
(
u_hasBinaryProperty
(
last_char
,
UCHAR_WHITE_SPACE
))
{
has_trailing_whitespace
=
true
;
bidi_run_count
--
;
}
}
}
// Build a map of styled runs indexed by start position.
std
::
map
<
size_t
,
StyledRuns
::
Run
>
styled_run_map
;
for
(
size_t
i
=
0
;
i
<
runs_
.
size
();
++
i
)
{
...
...
@@ -411,7 +438,6 @@ bool Paragraph::ComputeBidiRuns(std::vector<BidiRun>* result) {
for
(
int32_t
bidi_run_index
=
0
;
bidi_run_index
<
bidi_run_count
;
++
bidi_run_index
)
{
int32_t
bidi_run_start
,
bidi_run_length
;
UBiDiDirection
direction
=
ubidi_getVisualRun
(
bidi
.
get
(),
bidi_run_index
,
&
bidi_run_start
,
&
bidi_run_length
);
if
(
!
U_SUCCESS
(
status
))
...
...
@@ -438,6 +464,11 @@ bool Paragraph::ComputeBidiRuns(std::vector<BidiRun>* result) {
if
(
bidi_run_length
==
0
)
continue
;
// Attach the final trailing whitespace as part of this run.
if
(
has_trailing_whitespace
&&
bidi_run_index
==
bidi_run_count
-
1
)
{
bidi_run_length
++
;
}
size_t
bidi_run_end
=
bidi_run_start
+
bidi_run_length
;
TextDirection
text_direction
=
direction
==
UBIDI_RTL
?
TextDirection
::
rtl
:
TextDirection
::
ltr
;
...
...
third_party/txt/tests/paragraph_unittests.cc
浏览文件 @
8591bd32
...
...
@@ -2100,6 +2100,137 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(ArabicRectsParagraph)) {
ASSERT_TRUE
(
Snapshot
());
}
// Trailing space at the end of the arabic rtl run should be at the left end of
// the arabic run.
TEST_F
(
ParagraphTest
,
DISABLE_ON_WINDOWS
(
ArabicRectsLTRLeftAlignParagraph
))
{
const
char
*
text
=
"Helloبمباركة التقليدية قام عن. تصفح يد "
;
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
=
14
;
paragraph_style
.
text_align
=
TextAlign
::
left
;
paragraph_style
.
text_direction
=
TextDirection
::
ltr
;
txt
::
ParagraphBuilder
builder
(
paragraph_style
,
GetTestFontCollection
());
txt
::
TextStyle
text_style
;
text_style
.
font_families
=
std
::
vector
<
std
::
string
>
(
1
,
"Noto Naskh Arabic"
);
text_style
.
font_size
=
26
;
text_style
.
letter_spacing
=
1
;
text_style
.
word_spacing
=
5
;
text_style
.
color
=
SK_ColorBLACK
;
text_style
.
height
=
1
;
text_style
.
decoration
=
TextDecoration
::
kUnderline
;
text_style
.
decoration_color
=
SK_ColorBLACK
;
builder
.
PushStyle
(
text_style
);
builder
.
AddText
(
u16_text
);
builder
.
Pop
();
auto
paragraph
=
builder
.
Build
();
paragraph
->
Layout
(
GetTestCanvasWidth
()
-
100
);
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
(
36
,
40
,
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
(),
89.40625
);
EXPECT_FLOAT_EQ
(
boxes
[
0
].
rect
.
top
(),
-
0.26855469
);
EXPECT_FLOAT_EQ
(
boxes
[
0
].
rect
.
right
(),
121.87891
);
EXPECT_FLOAT_EQ
(
boxes
[
0
].
rect
.
bottom
(),
44
);
ASSERT_EQ
(
paragraph_style
.
text_align
,
paragraph
->
GetParagraphStyle
().
text_align
);
ASSERT_TRUE
(
Snapshot
());
}
// Trailing space at the end of the arabic rtl run should be at the left end of
// the arabic run and be a ghost space.
TEST_F
(
ParagraphTest
,
DISABLE_ON_WINDOWS
(
ArabicRectsLTRRightAlignParagraph
))
{
const
char
*
text
=
"Helloبمباركة التقليدية قام عن. تصفح يد "
;
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
=
14
;
paragraph_style
.
text_align
=
TextAlign
::
right
;
paragraph_style
.
text_direction
=
TextDirection
::
ltr
;
txt
::
ParagraphBuilder
builder
(
paragraph_style
,
GetTestFontCollection
());
txt
::
TextStyle
text_style
;
text_style
.
font_families
=
std
::
vector
<
std
::
string
>
(
1
,
"Noto Naskh Arabic"
);
text_style
.
font_size
=
26
;
text_style
.
letter_spacing
=
1
;
text_style
.
word_spacing
=
5
;
text_style
.
color
=
SK_ColorBLACK
;
text_style
.
height
=
1
;
text_style
.
decoration
=
TextDecoration
::
kUnderline
;
text_style
.
decoration_color
=
SK_ColorBLACK
;
builder
.
PushStyle
(
text_style
);
builder
.
AddText
(
u16_text
);
builder
.
Pop
();
auto
paragraph
=
builder
.
Build
();
paragraph
->
Layout
(
GetTestCanvasWidth
()
-
100
);
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
(
36
,
40
,
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
(),
2ull
);
EXPECT_FLOAT_EQ
(
boxes
[
0
].
rect
.
left
(),
556.54688
);
EXPECT_FLOAT_EQ
(
boxes
[
0
].
rect
.
top
(),
-
0.26855469
);
EXPECT_FLOAT_EQ
(
boxes
[
0
].
rect
.
right
(),
577.78125
);
EXPECT_FLOAT_EQ
(
boxes
[
0
].
rect
.
bottom
(),
44
);
EXPECT_FLOAT_EQ
(
boxes
[
1
].
rect
.
left
(),
545.30859
);
EXPECT_FLOAT_EQ
(
boxes
[
1
].
rect
.
top
(),
-
0.26855469
);
EXPECT_FLOAT_EQ
(
boxes
[
1
].
rect
.
right
(),
557.04688
);
EXPECT_FLOAT_EQ
(
boxes
[
1
].
rect
.
bottom
(),
44
);
ASSERT_EQ
(
paragraph_style
.
text_align
,
paragraph
->
GetParagraphStyle
().
text_align
);
ASSERT_TRUE
(
Snapshot
());
}
TEST_F
(
ParagraphTest
,
GetGlyphPositionAtCoordinateParagraph
)
{
const
char
*
text
=
"12345 67890 12345 67890 12345 67890 12345 67890 12345 67890 12345 "
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录