Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_43355755
engine
提交
bcb024df
E
engine
项目概览
weixin_43355755
/
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,体验更适合开发者的 AI 搜索 >>
提交
bcb024df
编写于
2月 18, 2016
作者:
S
Seigo Nonaka
提交者:
Android (Google) Code Review
2月 18, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge "Improve Paint.measureText and Paint.hasGlyph for variation sequences." into nyc-dev
上级
7f9834ae
6b1c227d
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
91 addition
and
18 deletion
+91
-18
include/minikin/CmapCoverage.h
include/minikin/CmapCoverage.h
+2
-1
include/minikin/FontCollection.h
include/minikin/FontCollection.h
+3
-0
include/minikin/FontFamily.h
include/minikin/FontFamily.h
+9
-1
libs/minikin/CmapCoverage.cpp
libs/minikin/CmapCoverage.cpp
+12
-1
libs/minikin/FontCollection.cpp
libs/minikin/FontCollection.cpp
+27
-14
libs/minikin/FontFamily.cpp
libs/minikin/FontFamily.cpp
+11
-1
tests/FontFamilyTest.cpp
tests/FontFamilyTest.cpp
+27
-0
未找到文件。
include/minikin/CmapCoverage.h
浏览文件 @
bcb024df
...
...
@@ -23,7 +23,8 @@ namespace android {
class
CmapCoverage
{
public:
static
bool
getCoverage
(
SparseBitSet
&
coverage
,
const
uint8_t
*
cmap_data
,
size_t
cmap_size
);
static
bool
getCoverage
(
SparseBitSet
&
coverage
,
const
uint8_t
*
cmap_data
,
size_t
cmap_size
,
bool
*
has_cmap_format14_subtable
);
};
}
// namespace android
...
...
include/minikin/FontCollection.h
浏览文件 @
bcb024df
...
...
@@ -89,6 +89,9 @@ private:
// This vector contains pointers into mInstances
std
::
vector
<
FontFamily
*>
mFamilyVec
;
// This vector has pointers to the font family instance which has cmap 14 subtable.
std
::
vector
<
FontFamily
*>
mVSFamilyVec
;
// These are offsets into mInstanceVec, one range per page
std
::
vector
<
Range
>
mRanges
;
};
...
...
include/minikin/FontFamily.h
浏览文件 @
bcb024df
...
...
@@ -104,7 +104,11 @@ public:
FontFamily
(
int
variant
);
FontFamily
(
uint32_t
langId
,
int
variant
)
:
mLangId
(
langId
),
mVariant
(
variant
)
{
FontFamily
(
uint32_t
langId
,
int
variant
)
:
mLangId
(
langId
),
mVariant
(
variant
),
mHasVSTable
(
false
),
mCoverageValid
(
false
)
{
}
~
FontFamily
();
...
...
@@ -131,6 +135,9 @@ public:
// Caller should acquire a lock before calling the method.
bool
hasVariationSelector
(
uint32_t
codepoint
,
uint32_t
variationSelector
);
// Returns true if this font family has a variaion sequence table (cmap format 14 subtable).
bool
hasVSTable
()
const
;
private:
void
addFontLocked
(
MinikinFont
*
typeface
,
FontStyle
style
);
...
...
@@ -146,6 +153,7 @@ private:
std
::
vector
<
Font
>
mFonts
;
SparseBitSet
mCoverage
;
bool
mHasVSTable
;
bool
mCoverageValid
;
};
...
...
libs/minikin/CmapCoverage.cpp
浏览文件 @
bcb024df
...
...
@@ -131,7 +131,8 @@ static bool getCoverageFormat12(vector<uint32_t>& coverage, const uint8_t* data,
return
true
;
}
bool
CmapCoverage
::
getCoverage
(
SparseBitSet
&
coverage
,
const
uint8_t
*
cmap_data
,
size_t
cmap_size
)
{
bool
CmapCoverage
::
getCoverage
(
SparseBitSet
&
coverage
,
const
uint8_t
*
cmap_data
,
size_t
cmap_size
,
bool
*
has_cmap_format14_subtable
)
{
vector
<
uint32_t
>
coverageVec
;
const
size_t
kHeaderSize
=
4
;
const
size_t
kNumTablesOffset
=
2
;
...
...
@@ -139,8 +140,10 @@ bool CmapCoverage::getCoverage(SparseBitSet& coverage, const uint8_t* cmap_data,
const
size_t
kPlatformIdOffset
=
0
;
const
size_t
kEncodingIdOffset
=
2
;
const
size_t
kOffsetOffset
=
4
;
const
uint16_t
kUnicodePlatformId
=
0
;
const
uint16_t
kMicrosoftPlatformId
=
3
;
const
uint16_t
kUnicodeBmpEncodingId
=
1
;
const
uint16_t
kVariationSequencesEncodingId
=
5
;
const
uint16_t
kUnicodeUcs4EncodingId
=
10
;
const
uint32_t
kNoTable
=
UINT32_MAX
;
if
(
kHeaderSize
>
cmap_size
)
{
...
...
@@ -151,6 +154,7 @@ bool CmapCoverage::getCoverage(SparseBitSet& coverage, const uint8_t* cmap_data,
return
false
;
}
uint32_t
bestTable
=
kNoTable
;
bool
hasCmapFormat14Subtable
=
false
;
for
(
uint32_t
i
=
0
;
i
<
numTables
;
i
++
)
{
uint16_t
platformId
=
readU16
(
cmap_data
,
kHeaderSize
+
i
*
kTableSize
+
kPlatformIdOffset
);
uint16_t
encodingId
=
readU16
(
cmap_data
,
kHeaderSize
+
i
*
kTableSize
+
kEncodingIdOffset
);
...
...
@@ -159,8 +163,15 @@ bool CmapCoverage::getCoverage(SparseBitSet& coverage, const uint8_t* cmap_data,
break
;
}
else
if
(
platformId
==
kMicrosoftPlatformId
&&
encodingId
==
kUnicodeBmpEncodingId
)
{
bestTable
=
i
;
}
else
if
(
platformId
==
kUnicodePlatformId
&&
encodingId
==
kVariationSequencesEncodingId
)
{
uint32_t
offset
=
readU32
(
cmap_data
,
kHeaderSize
+
i
*
kTableSize
+
kOffsetOffset
);
if
(
offset
<=
cmap_size
-
2
&&
readU16
(
cmap_data
,
offset
)
==
14
)
{
hasCmapFormat14Subtable
=
true
;
}
}
}
*
has_cmap_format14_subtable
=
hasCmapFormat14Subtable
;
#ifdef VERBOSE_DEBUG
ALOGD
(
"best table = %d
\n
"
,
bestTable
);
#endif
...
...
libs/minikin/FontCollection.cpp
浏览文件 @
bcb024df
...
...
@@ -62,6 +62,9 @@ FontCollection::FontCollection(const vector<FontFamily*>& typefaces) :
continue
;
}
mFamilies
.
push_back
(
family
);
// emplace_back would be better
if
(
family
->
hasVSTable
())
{
mVSFamilyVec
.
push_back
(
family
);
}
mMaxChar
=
max
(
mMaxChar
,
coverage
->
length
());
lastChar
.
push_back
(
coverage
->
nextSetBit
(
0
));
}
...
...
@@ -233,15 +236,22 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs,
return
NULL
;
}
// Even if the font supports variation sequence, mRanges isn't aware of the base character of
// the sequence. Search all FontFamilies if variation sequence is specified.
// TODO: Always use mRanges for font search.
const
std
::
vector
<
FontFamily
*>&
familyVec
=
(
vs
==
0
)
?
mFamilyVec
:
mFamilies
;
Range
range
;
if
(
vs
==
0
)
{
range
=
mRanges
[
ch
>>
kLogCharsPerPage
];
}
else
{
range
=
{
0
,
mFamilies
.
size
()
};
const
std
::
vector
<
FontFamily
*>*
familyVec
=
&
mFamilyVec
;
Range
range
=
mRanges
[
ch
>>
kLogCharsPerPage
];
std
::
vector
<
FontFamily
*>
familyVecForVS
;
if
(
vs
!=
0
)
{
// If variation selector is specified, need to search for both the variation sequence and
// its base codepoint. Compute the union vector of them.
familyVecForVS
=
mVSFamilyVec
;
familyVecForVS
.
insert
(
familyVecForVS
.
end
(),
mFamilyVec
.
begin
()
+
range
.
start
,
mFamilyVec
.
begin
()
+
range
.
end
);
std
::
sort
(
familyVecForVS
.
begin
(),
familyVecForVS
.
end
());
auto
last
=
std
::
unique
(
familyVecForVS
.
begin
(),
familyVecForVS
.
end
());
familyVecForVS
.
erase
(
last
,
familyVecForVS
.
end
());
familyVec
=
&
familyVecForVS
;
range
=
{
0
,
familyVecForVS
.
size
()
};
}
#ifdef VERBOSE_DEBUG
...
...
@@ -250,7 +260,7 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs,
FontFamily
*
bestFamily
=
nullptr
;
uint32_t
bestScore
=
kUnsupportedFontScore
;
for
(
size_t
i
=
range
.
start
;
i
<
range
.
end
;
i
++
)
{
FontFamily
*
family
=
familyVec
[
i
];
FontFamily
*
family
=
(
*
familyVec
)
[
i
];
const
uint32_t
score
=
calcFamilyScore
(
ch
,
vs
,
variant
,
langListId
,
family
);
if
(
score
==
kFirstFontScore
)
{
// If the first font family supports the given character or variation sequence, always
...
...
@@ -310,12 +320,15 @@ bool FontCollection::hasVariationSelector(uint32_t baseCodepoint,
if
(
baseCodepoint
>=
mMaxChar
)
{
return
false
;
}
if
(
variationSelector
==
0
)
{
return
false
;
}
// Currently mRanges can not be used here since it isn't aware of the variation sequence.
// TODO: Use mRanges for narrowing down the search range.
for
(
size_t
i
=
0
;
i
<
mFamilies
.
size
();
i
++
)
{
for
(
size_t
i
=
0
;
i
<
mVSFamilyVec
.
size
();
i
++
)
{
AutoMutex
_l
(
gMinikinLock
);
if
(
m
Families
[
i
]
->
hasVariationSelector
(
baseCodepoint
,
variationSelector
))
{
return
true
;
if
(
m
VSFamilyVec
[
i
]
->
hasVariationSelector
(
baseCodepoint
,
variationSelector
))
{
return
true
;
}
}
return
false
;
...
...
libs/minikin/FontFamily.cpp
浏览文件 @
bcb024df
...
...
@@ -177,7 +177,8 @@ const SparseBitSet* FontFamily::getCoverage() {
ALOGE
(
"Unexpected failure to read cmap table!
\n
"
);
return
nullptr
;
}
CmapCoverage
::
getCoverage
(
mCoverage
,
cmapData
.
get
(),
cmapSize
);
// TODO: Error check?
// TODO: Error check?
CmapCoverage
::
getCoverage
(
mCoverage
,
cmapData
.
get
(),
cmapSize
,
&
mHasVSTable
);
#ifdef VERBOSE_DEBUG
ALOGD
(
"font coverage length=%d, first ch=%x
\n
"
,
mCoverage
.
length
(),
mCoverage
.
nextSetBit
(
0
));
...
...
@@ -189,6 +190,10 @@ const SparseBitSet* FontFamily::getCoverage() {
bool
FontFamily
::
hasVariationSelector
(
uint32_t
codepoint
,
uint32_t
variationSelector
)
{
assertMinikinLocked
();
if
(
!
mHasVSTable
)
{
return
false
;
}
const
FontStyle
defaultStyle
;
MinikinFont
*
minikinFont
=
getClosestMatch
(
defaultStyle
).
font
;
hb_font_t
*
font
=
getHbFontLocked
(
minikinFont
);
...
...
@@ -196,4 +201,9 @@ bool FontFamily::hasVariationSelector(uint32_t codepoint, uint32_t variationSele
return
hb_font_get_glyph
(
font
,
codepoint
,
variationSelector
,
&
unusedGlyph
);
}
bool
FontFamily
::
hasVSTable
()
const
{
LOG_ALWAYS_FATAL_IF
(
!
mCoverageValid
,
"Do not call this method before getCoverage() call"
);
return
mHasVSTable
;
}
}
// namespace android
tests/FontFamilyTest.cpp
浏览文件 @
bcb024df
...
...
@@ -378,4 +378,31 @@ TEST_F(FontFamilyTest, hasVariationSelectorTest) {
expectVSGlyphs
(
&
family
,
kNotSupportedChar
,
std
::
set
<
uint32_t
>
());
}
TEST_F
(
FontFamilyTest
,
hasVSTableTest
)
{
struct
TestCase
{
const
std
::
string
fontPath
;
bool
hasVSTable
;
}
testCases
[]
=
{
{
kTestFontDir
"Ja.ttf"
,
true
},
{
kTestFontDir
"ZhHant.ttf"
,
true
},
{
kTestFontDir
"ZhHans.ttf"
,
true
},
{
kTestFontDir
"Italic.ttf"
,
false
},
{
kTestFontDir
"Bold.ttf"
,
false
},
{
kTestFontDir
"BoldItalic.ttf"
,
false
},
};
for
(
auto
testCase
:
testCases
)
{
SCOPED_TRACE
(
testCase
.
hasVSTable
?
"Font "
+
testCase
.
fontPath
+
" should have a variation sequence table."
:
"Font "
+
testCase
.
fontPath
+
" shouldn't have a variation sequence table."
);
MinikinFontForTest
minikinFont
(
testCase
.
fontPath
);
FontFamily
family
;
family
.
addFont
(
&
minikinFont
);
family
.
getCoverage
();
EXPECT_EQ
(
testCase
.
hasVSTable
,
family
.
hasVSTable
());
}
}
}
// namespace android
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录