Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
587c023a
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,发现更多精彩内容 >>
未验证
提交
587c023a
编写于
11月 30, 2020
作者:
M
Mouad Debbar
提交者:
GitHub
11月 30, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[web] Add new line break type (prohibited) (#22771)
上级
609307de
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
34 addition
and
8 deletion
+34
-8
lib/web_ui/lib/src/engine/text/line_breaker.dart
lib/web_ui/lib/src/engine/text/line_breaker.dart
+16
-1
lib/web_ui/lib/src/engine/text/measurement.dart
lib/web_ui/lib/src/engine/text/measurement.dart
+3
-7
lib/web_ui/test/text/line_breaker_test.dart
lib/web_ui/test/text/line_breaker_test.dart
+15
-0
未找到文件。
lib/web_ui/lib/src/engine/text/line_breaker.dart
浏览文件 @
587c023a
...
...
@@ -10,6 +10,9 @@ enum LineBreakType {
/// Indicates that a line break is possible but not mandatory.
opportunity
,
/// Indicates that a line break isn't possible.
prohibited
,
/// Indicates that this is a hard line break that can't be skipped.
mandatory
,
...
...
@@ -74,6 +77,9 @@ class LineBreakResult {
/// to decide whether to take the line break or not.
final
LineBreakType
type
;
bool
get
isHard
=>
type
==
LineBreakType
.
mandatory
||
type
==
LineBreakType
.
endOfText
;
@override
int
get
hashCode
=>
ui
.
hashValues
(
index
,
...
...
@@ -160,7 +166,7 @@ bool _hasEastAsianWidthFWH(int charCode) {
///
/// * https://www.unicode.org/reports/tr14/tr14-45.html#Algorithm
/// * https://www.unicode.org/Public/11.0.0/ucd/LineBreak.txt
LineBreakResult
nextLineBreak
(
String
text
,
int
index
)
{
LineBreakResult
nextLineBreak
(
String
text
,
int
index
,
{
int
?
maxEnd
}
)
{
int
?
codePoint
=
getCodePoint
(
text
,
index
);
LineCharProperty
curr
=
lineLookup
.
findForChar
(
codePoint
);
...
...
@@ -199,6 +205,15 @@ LineBreakResult nextLineBreak(String text, int index) {
// Always break at the end of text.
// LB3: ! eot
while
(
index
<
text
.
length
)
{
if
(
index
==
maxEnd
)
{
return
LineBreakResult
(
index
,
lastNonNewlineIndex
,
lastNonSpaceIndex
,
LineBreakType
.
prohibited
,
);
}
// Keep count of the RI (regional indicator) sequence.
if
(
curr
==
LineCharProperty
.
RI
)
{
regionalIndicatorCount
++;
...
...
lib/web_ui/lib/src/engine/text/measurement.dart
浏览文件 @
587c023a
...
...
@@ -771,8 +771,6 @@ class LinesCalculator {
/// This method should be called for every line break. As soon as it reaches
/// the maximum number of lines required
void
update
(
LineBreakResult
brk
)
{
final
bool
isHardBreak
=
brk
.
type
==
LineBreakType
.
mandatory
||
brk
.
type
==
LineBreakType
.
endOfText
;
final
int
chunkEnd
=
brk
.
index
;
final
int
chunkEndWithoutNewlines
=
brk
.
indexWithoutTrailingNewlines
;
final
int
chunkEndWithoutSpace
=
brk
.
indexWithoutTrailingSpaces
;
...
...
@@ -855,7 +853,7 @@ class LinesCalculator {
return
;
}
if
(
isHardBreak
)
{
if
(
brk
.
isHard
)
{
_addLineBreak
(
brk
);
}
_lastBreak
=
brk
;
...
...
@@ -872,15 +870,13 @@ class LinesCalculator {
lineWidth:
lineWidth
,
maxWidth:
_maxWidth
,
);
final
bool
isHardBreak
=
brk
.
type
==
LineBreakType
.
mandatory
||
brk
.
type
==
LineBreakType
.
endOfText
;
final
EngineLineMetrics
metrics
=
EngineLineMetrics
.
withText
(
_text
!.
substring
(
_lineStart
,
brk
.
indexWithoutTrailingNewlines
),
startIndex:
_lineStart
,
endIndex:
brk
.
index
,
endIndexWithoutNewlines:
brk
.
indexWithoutTrailingNewlines
,
hardBreak:
isHardBreak
,
hardBreak:
brk
.
isHard
,
width:
lineWidth
,
widthWithTrailingSpaces:
lineWidthWithTrailingSpaces
,
left:
alignOffset
,
...
...
@@ -995,7 +991,7 @@ class MaxIntrinsicCalculator {
/// intrinsic width calculated so far. When the whole text is consumed,
/// [value] will contain the final maximum intrinsic width.
void
update
(
LineBreakResult
brk
)
{
if
(
brk
.
type
==
LineBreakType
.
opportunity
)
{
if
(
!
brk
.
isHard
)
{
return
;
}
...
...
lib/web_ui/test/text/line_breaker_test.dart
浏览文件 @
587c023a
...
...
@@ -252,6 +252,14 @@ void testMain() {
'"
$text
"
\n
'
'
\n
Expected line break at {
$lastLineBreak
-
$i
} but found line break at {
$lastLineBreak
-
${result.index}
}.'
,
);
// Since this is a line break, passing a `maxEnd` that's greater
// should return the same line break.
final
LineBreakResult
maxEndResult
=
nextLineBreak
(
text
,
lastLineBreak
,
maxEnd:
i
+
1
);
expect
(
maxEndResult
.
index
,
i
);
expect
(
maxEndResult
.
type
,
isNot
(
LineBreakType
.
prohibited
));
lastLineBreak
=
i
;
}
else
{
// This isn't a line break opportunity so the line break should be
...
...
@@ -264,6 +272,13 @@ void testMain() {
'"
$text
"
\n
'
'
\n
Unexpected line break found at {
$lastLineBreak
-
$i
}.'
,
);
// Since this isn't a line break, passing it as a `maxEnd` should
// return `maxEnd` as a prohibited line break type.
final
LineBreakResult
maxEndResult
=
nextLineBreak
(
text
,
lastLineBreak
,
maxEnd:
i
);
expect
(
maxEndResult
.
index
,
i
);
expect
(
maxEndResult
.
type
,
LineBreakType
.
prohibited
);
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录