Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_34031325
engine
提交
81f56588
E
engine
项目概览
qq_34031325
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,发现更多精彩内容 >>
提交
81f56588
编写于
12月 30, 2015
作者:
I
Ian Hickson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement wordSpacing and per-inline lineHeight.
Change line-height to use percentages rather than pixels.
上级
1958e3f8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
111 addition
and
60 deletion
+111
-60
sky/engine/core/dart/text.dart
sky/engine/core/dart/text.dart
+52
-12
sky/engine/core/text/ParagraphBuilder.cpp
sky/engine/core/text/ParagraphBuilder.cpp
+58
-47
sky/engine/core/text/ParagraphBuilder.h
sky/engine/core/text/ParagraphBuilder.h
+1
-1
未找到文件。
sky/engine/core/dart/text.dart
浏览文件 @
81f56588
...
...
@@ -170,8 +170,9 @@ enum TextDecorationStyle {
// The encoded array buffer has 7 elements.
//
// - Element 0: A bit field where the ith bit indicates wheter the ith element
// has a non-null value. Bits 7 and 8 indicate whether |fontFamily| and
// |fontSize| are non-null, respectively. Bit 0 is unused.
// has a non-null value. Bits 7 to 11 indicate whether |fontFamily|,
// |fontSize|, |letterSpacing|, |wordSpacing|, and |lineHeight| are non-null,
// respectively. Bit 0 is unused.
//
// - Element 1: The |color| in ARGB with 8 bits per channel.
//
...
...
@@ -195,7 +196,9 @@ Int32List _encodeTextStyle(Color color,
FontStyle
fontStyle
,
String
fontFamily
,
double
fontSize
,
double
letterSpacing
)
{
double
letterSpacing
,
double
wordSpacing
,
double
lineHeight
)
{
Int32List
result
=
new
Int32List
(
7
);
if
(
color
!=
null
)
{
result
[
0
]
|=
1
<<
1
;
...
...
@@ -233,6 +236,14 @@ Int32List _encodeTextStyle(Color color,
result
[
0
]
|=
1
<<
9
;
// Passed separately to native.
}
if
(
wordSpacing
!=
null
)
{
result
[
0
]
|=
1
<<
10
;
// Passed separately to native.
}
if
(
lineHeight
!=
null
)
{
result
[
0
]
|=
1
<<
11
;
// Passed separately to native.
}
return
result
;
}
...
...
@@ -246,7 +257,9 @@ class TextStyle {
FontStyle
fontStyle
,
String
fontFamily
,
double
fontSize
,
double
letterSpacing
double
letterSpacing
,
double
wordSpacing
,
double
lineHeight
})
:
_encoded
=
_encodeTextStyle
(
color
,
decoration
,
decorationColor
,
...
...
@@ -255,15 +268,37 @@ class TextStyle {
fontStyle
,
fontFamily
,
fontSize
,
letterSpacing
),
letterSpacing
,
wordSpacing
,
lineHeight
),
_fontFamily
=
fontFamily
??
''
,
_fontSize
=
fontSize
,
_letterSpacing
=
letterSpacing
;
_letterSpacing
=
letterSpacing
,
_wordSpacing
=
wordSpacing
,
_lineHeight
=
lineHeight
;
final
Int32List
_encoded
;
final
String
_fontFamily
;
final
double
_fontSize
;
final
double
_letterSpacing
;
final
double
_wordSpacing
;
final
double
_lineHeight
;
String
toString
()
{
return
'TextStyle(
${_encoded[0]}
|'
'color:
${ _encoded[0] & 0x001 == 0x001 ? new Color(_encoded[1]) : "unspecified"}
, '
'decoration:
${ _encoded[0] & 0x002 == 0x002 ? new TextDecoration._(_encoded[2]) : "unspecified"}
, '
'decorationColor:
${_encoded[0] & 0x004 == 0x004 ? new Color(_encoded[3]) : "unspecified"}
, '
'decorationStyle:
${_encoded[0] & 0x008 == 0x008 ? TextDecorationStyle.values[_encoded[4]] : "unspecified"}
, '
'fontWeight:
${ _encoded[0] & 0x010 == 0x010 ? FontWeight.values[_encoded[5]] : "unspecified"}
, '
'fontStyle:
${ _encoded[0] & 0x020 == 0x020 ? FontStyle.values[_encoded[6]] : "unspecified"}
, '
'fontFamily:
${ _encoded[0] & 0x040 == 0x040 ? _fontFamily : "unspecified"}
, '
'fontSize:
${ _encoded[0] & 0x080 == 0x080 ? _fontSize : "unspecified"}
, '
'letterSpacing:
${ _encoded[0] & 0x100 == 0x100 ? "${_letterSpacing}
x" : "unspecified"}, '
'wordSpacing:
${ _encoded[0] & 0x200 == 0x200 ? "${_wordSpacing}
x" : "unspecified"}, '
'lineHeight:
${ _encoded[0] & 0x400 == 0x400 ? "${_lineHeight}
x" : "unspecified"}'
')'
;
}
}
// This encoding must match the C++ version ParagraphBuilder::build.
...
...
@@ -307,6 +342,14 @@ class ParagraphStyle {
final
Int32List
_encoded
;
final
double
_lineHeight
;
String
toString
()
{
return
'ParagraphStyle('
'textAlign:
${ _encoded[0] & 0x1 == 0x1 ? TextAlign.values[_encoded[1]] : "unspecified"}
, '
'textBaseline:
${_encoded[0] & 0x2 == 0x2 ? TextBaseline.values[_encoded[2]] : "unspecified"}
, '
'lineHeight:
${ _encoded[0] & 0x3 == 0x3 ? "${_lineHeight}
x" : "unspecified"}'
')'
;
}
}
abstract
class
Paragraph
extends
NativeFieldWrapperClass2
{
...
...
@@ -333,17 +376,14 @@ class ParagraphBuilder extends NativeFieldWrapperClass2 {
void
_constructor
()
native
"ParagraphBuilder_constructor"
;
ParagraphBuilder
()
{
_constructor
();
}
void
_pushStyle
(
Int32List
encoded
,
String
fontFamily
,
double
fontSize
,
double
letterSpacing
)
native
"ParagraphBuilder_pushStyle"
;
void
pushStyle
(
TextStyle
style
)
{
_pushStyle
(
style
.
_encoded
,
style
.
_fontFamily
,
style
.
_fontSize
,
style
.
_letterSpacing
);
}
void
_pushStyle
(
Int32List
encoded
,
String
fontFamily
,
double
fontSize
,
double
letterSpacing
,
double
wordSpacing
,
double
lineHeight
)
native
"ParagraphBuilder_pushStyle"
;
void
pushStyle
(
TextStyle
style
)
=>
_pushStyle
(
style
.
_encoded
,
style
.
_fontFamily
,
style
.
_fontSize
,
style
.
_letterSpacing
,
style
.
_wordSpacing
,
style
.
_lineHeight
);
void
pop
()
native
"ParagraphBuilder_pop"
;
void
addText
(
String
text
)
native
"ParagraphBuilder_addText"
;
Paragraph
_build
(
Int32List
encoded
,
double
lineHeight
)
native
"ParagraphBuilder_build"
;
Paragraph
build
(
ParagraphStyle
style
)
=>
_build
(
style
.
_encoded
,
style
.
_lineHeight
);
}
sky/engine/core/text/ParagraphBuilder.cpp
浏览文件 @
81f56588
...
...
@@ -67,35 +67,39 @@ Color getColorFromARGB(int argb) {
// TextStyle
const
int
kColorIndex
=
1
;
const
int
kTextDecorationIndex
=
2
;
const
int
kTextDecorationColorIndex
=
3
;
const
int
kTextDecorationStyleIndex
=
4
;
const
int
kFontWeightIndex
=
5
;
const
int
kFontStyleIndex
=
6
;
const
int
kFontFamilyIndex
=
7
;
const
int
kFontSizeIndex
=
8
;
const
int
kLetterSpacingIndex
=
9
;
const
int
kColorMask
=
1
<<
kColorIndex
;
const
int
kTextDecorationMask
=
1
<<
kTextDecorationIndex
;
const
int
kTextDecorationColorMask
=
1
<<
kTextDecorationColorIndex
;
const
int
kTextDecorationStyleMask
=
1
<<
kTextDecorationStyleIndex
;
const
int
kFontWeightMask
=
1
<<
kFontWeightIndex
;
const
int
kFontStyleMask
=
1
<<
kFontStyleIndex
;
const
int
kFontFamilyMask
=
1
<<
kFontFamilyIndex
;
const
int
kFontSizeMask
=
1
<<
kFontSizeIndex
;
const
int
kLetterSpacingMask
=
1
<<
kLetterSpacingIndex
;
const
int
tsColorIndex
=
1
;
const
int
tsTextDecorationIndex
=
2
;
const
int
tsTextDecorationColorIndex
=
3
;
const
int
tsTextDecorationStyleIndex
=
4
;
const
int
tsFontWeightIndex
=
5
;
const
int
tsFontStyleIndex
=
6
;
const
int
tsFontFamilyIndex
=
7
;
const
int
tsFontSizeIndex
=
8
;
const
int
tsLetterSpacingIndex
=
9
;
const
int
tsWordSpacingIndex
=
10
;
const
int
tsLineHeightIndex
=
11
;
const
int
tsColorMask
=
1
<<
tsColorIndex
;
const
int
tsTextDecorationMask
=
1
<<
tsTextDecorationIndex
;
const
int
tsTextDecorationColorMask
=
1
<<
tsTextDecorationColorIndex
;
const
int
tsTextDecorationStyleMask
=
1
<<
tsTextDecorationStyleIndex
;
const
int
tsFontWeightMask
=
1
<<
tsFontWeightIndex
;
const
int
tsFontStyleMask
=
1
<<
tsFontStyleIndex
;
const
int
tsFontFamilyMask
=
1
<<
tsFontFamilyIndex
;
const
int
tsFontSizeMask
=
1
<<
tsFontSizeIndex
;
const
int
tsLetterSpacingMask
=
1
<<
tsLetterSpacingIndex
;
const
int
tsWordSpacingMask
=
1
<<
tsWordSpacingIndex
;
const
int
tsLineHeightMask
=
1
<<
tsLineHeightIndex
;
// ParagraphStyle
const
int
k
TextAlignIndex
=
1
;
const
int
k
TextBaselineIndex
=
2
;
const
int
k
LineHeightIndex
=
3
;
const
int
ps
TextAlignIndex
=
1
;
const
int
ps
TextBaselineIndex
=
2
;
const
int
ps
LineHeightIndex
=
3
;
const
int
kTextAlignMask
=
1
<<
k
TextAlignIndex
;
const
int
kTextBaselineMask
=
1
<<
k
TextBaselineIndex
;
const
int
kLineHeightMask
=
1
<<
k
LineHeightIndex
;
const
int
psTextAlignMask
=
1
<<
ps
TextAlignIndex
;
const
int
psTextBaselineMask
=
1
<<
ps
TextBaselineIndex
;
const
int
psLineHeightMask
=
1
<<
ps
LineHeightIndex
;
}
// namespace
...
...
@@ -132,7 +136,7 @@ ParagraphBuilder::~ParagraphBuilder()
{
}
void
ParagraphBuilder
::
pushStyle
(
Int32List
&
encoded
,
const
String
&
fontFamily
,
double
fontSize
,
double
letterSpacing
)
void
ParagraphBuilder
::
pushStyle
(
Int32List
&
encoded
,
const
String
&
fontFamily
,
double
fontSize
,
double
letterSpacing
,
double
wordSpacing
,
double
lineHeight
)
{
DCHECK
(
encoded
.
num_elements
()
==
7
);
RefPtr
<
RenderStyle
>
style
=
RenderStyle
::
create
();
...
...
@@ -140,48 +144,55 @@ void ParagraphBuilder::pushStyle(Int32List& encoded, const String& fontFamily, d
int32_t
mask
=
encoded
[
0
];
if
(
mask
&
k
ColorMask
)
style
->
setColor
(
getColorFromARGB
(
encoded
[
k
ColorIndex
]));
if
(
mask
&
ts
ColorMask
)
style
->
setColor
(
getColorFromARGB
(
encoded
[
ts
ColorIndex
]));
if
(
mask
&
k
TextDecorationMask
)
{
style
->
setTextDecoration
(
static_cast
<
TextDecoration
>
(
encoded
[
k
TextDecorationIndex
]));
if
(
mask
&
ts
TextDecorationMask
)
{
style
->
setTextDecoration
(
static_cast
<
TextDecoration
>
(
encoded
[
ts
TextDecorationIndex
]));
style
->
applyTextDecorations
();
}
if
(
mask
&
k
TextDecorationColorMask
)
style
->
setTextDecorationColor
(
StyleColor
(
getColorFromARGB
(
encoded
[
k
TextDecorationColorIndex
])));
if
(
mask
&
ts
TextDecorationColorMask
)
style
->
setTextDecorationColor
(
StyleColor
(
getColorFromARGB
(
encoded
[
ts
TextDecorationColorIndex
])));
if
(
mask
&
k
TextDecorationStyleMask
)
style
->
setTextDecorationStyle
(
static_cast
<
TextDecorationStyle
>
(
encoded
[
k
TextDecorationStyleIndex
]));
if
(
mask
&
ts
TextDecorationStyleMask
)
style
->
setTextDecorationStyle
(
static_cast
<
TextDecorationStyle
>
(
encoded
[
ts
TextDecorationStyleIndex
]));
if
(
mask
&
(
kFontWeightMask
|
kFontStyleMask
|
kFontFamilyMask
|
kFontSizeMask
|
kLetter
SpacingMask
))
{
if
(
mask
&
(
tsFontWeightMask
|
tsFontStyleMask
|
tsFontFamilyMask
|
tsFontSizeMask
|
tsLetterSpacingMask
|
tsWord
SpacingMask
))
{
FontDescription
fontDescription
=
style
->
fontDescription
();
if
(
mask
&
k
FontWeightMask
)
fontDescription
.
setWeight
(
static_cast
<
FontWeight
>
(
encoded
[
k
FontWeightIndex
]));
if
(
mask
&
ts
FontWeightMask
)
fontDescription
.
setWeight
(
static_cast
<
FontWeight
>
(
encoded
[
ts
FontWeightIndex
]));
if
(
mask
&
k
FontStyleMask
)
fontDescription
.
setStyle
(
static_cast
<
FontStyle
>
(
encoded
[
k
FontStyleIndex
]));
if
(
mask
&
ts
FontStyleMask
)
fontDescription
.
setStyle
(
static_cast
<
FontStyle
>
(
encoded
[
ts
FontStyleIndex
]));
if
(
mask
&
k
FontFamilyMask
)
{
if
(
mask
&
ts
FontFamilyMask
)
{
FontFamily
family
;
family
.
setFamily
(
fontFamily
);
fontDescription
.
setFamily
(
family
);
}
if
(
mask
&
k
FontSizeMask
)
{
if
(
mask
&
ts
FontSizeMask
)
{
fontDescription
.
setSpecifiedSize
(
fontSize
);
fontDescription
.
setIsAbsoluteSize
(
true
);
fontDescription
.
setComputedSize
(
getComputedSizeFromSpecifiedSize
(
fontSize
));
}
if
(
mask
&
k
LetterSpacingMask
)
if
(
mask
&
ts
LetterSpacingMask
)
fontDescription
.
setLetterSpacing
(
letterSpacing
);
if
(
mask
&
tsWordSpacingMask
)
fontDescription
.
setWordSpacing
(
wordSpacing
);
style
->
setFontDescription
(
fontDescription
);
style
->
font
().
update
(
nullptr
);
}
if
(
mask
&
tsLineHeightMask
)
{
style
->
setLineHeight
(
Length
(
lineHeight
*
100.0
,
Percent
));
}
encoded
.
Release
();
RenderObject
*
span
=
new
RenderInline
();
...
...
@@ -215,16 +226,16 @@ PassRefPtr<Paragraph> ParagraphBuilder::build(Int32List& encoded, double lineHei
if
(
mask
)
{
RefPtr
<
RenderStyle
>
style
=
RenderStyle
::
clone
(
m_renderParagraph
->
style
());
if
(
mask
&
k
TextAlignMask
)
style
->
setTextAlign
(
static_cast
<
ETextAlign
>
(
encoded
[
k
TextAlignIndex
]));
if
(
mask
&
ps
TextAlignMask
)
style
->
setTextAlign
(
static_cast
<
ETextAlign
>
(
encoded
[
ps
TextAlignIndex
]));
if
(
mask
&
k
TextBaselineMask
)
{
if
(
mask
&
ps
TextBaselineMask
)
{
// TODO(abarth): Implement TextBaseline. The CSS version of this
// property wasn't wired up either.
}
if
(
mask
&
k
LineHeightMask
)
style
->
setLineHeight
(
Length
(
lineHeight
,
Fixed
));
if
(
mask
&
ps
LineHeightMask
)
style
->
setLineHeight
(
Length
(
lineHeight
*
100.0
,
Percent
));
m_renderParagraph
->
setStyle
(
style
.
release
());
}
...
...
sky/engine/core/text/ParagraphBuilder.h
浏览文件 @
81f56588
...
...
@@ -23,7 +23,7 @@ public:
~
ParagraphBuilder
()
override
;
void
pushStyle
(
Int32List
&
encoded
,
const
String
&
fontFamily
,
double
fontSize
,
double
letterSpacing
);
void
pushStyle
(
Int32List
&
encoded
,
const
String
&
fontFamily
,
double
fontSize
,
double
letterSpacing
,
double
wordSpacing
,
double
lineHeight
);
void
pop
();
void
addText
(
const
String
&
text
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录