提交 160fdd1f 编写于 作者: S Seigo Nonaka 提交者: Android (Google) Code Review

Merge "Fix lookup order for VS in itemization."

......@@ -281,22 +281,11 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs,
return mFamilies[0];
}
const std::vector<FontFamily*>* familyVec = &mFamilyVec;
const std::vector<FontFamily*>& familyVec = (vs == 0) ? mFamilyVec : mFamilies;
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() };
range = { 0, mFamilies.size() };
}
#ifdef VERBOSE_DEBUG
......@@ -305,7 +294,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
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (C) 2016 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="3.0">
<GlyphOrder>
<!-- The 'id' attribute is only for humans; it is ignored when parsed. -->
<GlyphID id="0" name=".notdef"/>
<GlyphID id="1" name="defaultGlyph"/>
</GlyphOrder>
<head>
<!-- Most of this table will be recalculated by the compiler -->
<tableVersion value="1.0"/>
<fontRevision value="1.0"/>
<checkSumAdjustment value="0x640cdb2f"/>
<magicNumber value="0x5f0f3cf5"/>
<flags value="00000000 00000011"/>
<unitsPerEm value="1000"/>
<created value="Wed Sep 9 08:01:17 2015"/>
<modified value="Wed Sep 9 08:48:07 2015"/>
<xMin value="30"/>
<yMin value="-200"/>
<xMax value="629"/>
<yMax value="800"/>
<macStyle value="00000000 00000000"/>
<lowestRecPPEM value="7"/>
<fontDirectionHint value="2"/>
<indexToLocFormat value="0"/>
<glyphDataFormat value="0"/>
</head>
<hhea>
<tableVersion value="1.0"/>
<ascent value="1000"/>
<descent value="-200"/>
<lineGap value="0"/>
<advanceWidthMax value="659"/>
<minLeftSideBearing value="0"/>
<minRightSideBearing value="30"/>
<xMaxExtent value="629"/>
<caretSlopeRise value="1"/>
<caretSlopeRun value="0"/>
<caretOffset value="0"/>
<reserved0 value="0"/>
<reserved1 value="0"/>
<reserved2 value="0"/>
<reserved3 value="0"/>
<metricDataFormat value="0"/>
<numberOfHMetrics value="18"/>
</hhea>
<maxp>
<!-- Most of this table will be recalculated by the compiler -->
<tableVersion value="0x10000"/>
<numGlyphs value="54"/>
<maxPoints value="73"/>
<maxContours value="10"/>
<maxCompositePoints value="0"/>
<maxCompositeContours value="0"/>
<maxZones value="2"/>
<maxTwilightPoints value="12"/>
<maxStorage value="28"/>
<maxFunctionDefs value="119"/>
<maxInstructionDefs value="0"/>
<maxStackElements value="61"/>
<maxSizeOfInstructions value="2967"/>
<maxComponentElements value="0"/>
<maxComponentDepth value="0"/>
</maxp>
<OS_2>
<!-- The fields 'usFirstCharIndex' and 'usLastCharIndex'
will be recalculated by the compiler -->
<version value="3"/>
<xAvgCharWidth value="594"/>
<usWeightClass value="400"/>
<usWidthClass value="5"/>
<fsType value="00000000 00001000"/>
<ySubscriptXSize value="650"/>
<ySubscriptYSize value="600"/>
<ySubscriptXOffset value="0"/>
<ySubscriptYOffset value="75"/>
<ySuperscriptXSize value="650"/>
<ySuperscriptYSize value="600"/>
<ySuperscriptXOffset value="0"/>
<ySuperscriptYOffset value="350"/>
<yStrikeoutSize value="50"/>
<yStrikeoutPosition value="300"/>
<sFamilyClass value="0"/>
<panose>
<bFamilyType value="0"/>
<bSerifStyle value="0"/>
<bWeight value="5"/>
<bProportion value="0"/>
<bContrast value="0"/>
<bStrokeVariation value="0"/>
<bArmStyle value="0"/>
<bLetterForm value="0"/>
<bMidline value="0"/>
<bXHeight value="0"/>
</panose>
<ulUnicodeRange1 value="00000000 00000000 00000000 00000001"/>
<ulUnicodeRange2 value="00000000 00000000 00000000 00000000"/>
<ulUnicodeRange3 value="00000000 00000000 00000000 00000000"/>
<ulUnicodeRange4 value="00000000 00000000 00000000 00000000"/>
<achVendID value="UKWN"/>
<fsSelection value="00000000 01000000"/>
<usFirstCharIndex value="32"/>
<usLastCharIndex value="122"/>
<sTypoAscender value="800"/>
<sTypoDescender value="-200"/>
<sTypoLineGap value="200"/>
<usWinAscent value="1000"/>
<usWinDescent value="200"/>
<ulCodePageRange1 value="00000000 00000000 00000000 00000001"/>
<ulCodePageRange2 value="00000000 00000000 00000000 00000000"/>
<sxHeight value="500"/>
<sCapHeight value="700"/>
<usDefaultChar value="0"/>
<usBreakChar value="32"/>
<usMaxContext value="0"/>
</OS_2>
<hmtx>
<mtx name=".notdef" width="500" lsb="93"/>
<mtx name="defaultGlyph" width="500" lsb="93"/>
</hmtx>
<cmap>
<tableVersion version="0"/>
<cmap_format_4 platformID="3" platEncID="10" language="0">
<map code="0x5380" name="defaultGlyph" />
</cmap_format_4>
<!-- Do not add cmap_format_14 here since this font is desinged for testing purpose. -->
</cmap>
<loca>
<!-- The 'loca' table will be calculated by the compiler -->
</loca>
<glyf>
<!-- The xMin, yMin, xMax and yMax values
will be recalculated by the compiler. -->
<TTGlyph name=".notdef" xMin="0" yMin="0" xMax="0" yMax="0">
<contour></contour><instructions><assembly></assembly></instructions>
</TTGlyph>
<TTGlyph name="defaultGlyph" xMin="0" yMin="0" xMax="0" yMax="0">
<contour></contour><instructions><assembly></assembly></instructions>
</TTGlyph>
</glyf>
<name>
<namerecord nameID="1" platformID="1" platEncID="0" langID="0x0" unicode="True">
No Cmap Format 14 Subtable Test
</namerecord>
<namerecord nameID="2" platformID="1" platEncID="0" langID="0x0" unicode="True">
Regular
</namerecord>
<namerecord nameID="4" platformID="1" platEncID="0" langID="0x0" unicode="True">
No Cmap Format 14 Subtable Test
</namerecord>
<namerecord nameID="6" platformID="1" platEncID="0" langID="0x0" unicode="True">
No Cmap Format 14 SubtableTest-Regular
</namerecord>
<namerecord nameID="1" platformID="3" platEncID="1" langID="0x409">
No Cmap Format 14 Subtable Test
</namerecord>
<namerecord nameID="2" platformID="3" platEncID="1" langID="0x409">
Regular
</namerecord>
<namerecord nameID="4" platformID="3" platEncID="1" langID="0x409">
No Cmap Format 14 Subtable Test
</namerecord>
<namerecord nameID="6" platformID="3" platEncID="1" langID="0x409">
No Cmap Format 14 SubtableTest-Regular
</namerecord>
</name>
<post>
<formatType value="3.0"/>
<italicAngle value="0.0"/>
<underlinePosition value="-75"/>
<underlineThickness value="50"/>
<isFixedPitch value="0"/>
<minMemType42 value="0"/>
<maxMemType42 value="0"/>
<minMemType1 value="0"/>
<maxMemType1 value="0"/>
</post>
</ttFont>
......@@ -18,18 +18,7 @@
<GlyphOrder>
<!-- The 'id' attribute is only for humans; it is ignored when parsed. -->
<GlyphID id="0" name=".notdef"/>
<GlyphID id="1" name="BaseChar1"/>
<GlyphID id="2" name="BaseChar1_VS1"/>
<GlyphID id="3" name="BaseChar1_VS17"/>
<GlyphID id="4" name="BaseChar1_VS18"/>
<GlyphID id="5" name="BaseChar2"/>
<GlyphID id="6" name="BaseChar2_VS2"/>
<GlyphID id="7" name="BaseChar2_VS18"/>
<GlyphID id="8" name="BaseChar2_VS19"/>
<GlyphID id="9" name="BaseChar3"/>
<GlyphID id="10" name="BaseChar4_VS3"/>
<GlyphID id="11" name="BaseChar4_VS19"/>
<GlyphID id="12" name="BaseChar4_VS20"/>
<GlyphID id="1" name="defaultGlyph"/>
</GlyphOrder>
<head>
......@@ -147,45 +136,36 @@
<hmtx>
<mtx name=".notdef" width="500" lsb="93"/>
<mtx name="BaseChar1" width="500" lsb="93"/>
<mtx name="BaseChar1_VS1" width="500" lsb="93"/>
<mtx name="BaseChar1_VS17" width="500" lsb="93"/>
<mtx name="BaseChar1_VS18" width="500" lsb="93"/>
<mtx name="BaseChar2" width="500" lsb="93"/>
<mtx name="BaseChar2_VS2" width="500" lsb="93"/>
<mtx name="BaseChar2_VS18" width="500" lsb="93"/>
<mtx name="BaseChar2_VS19" width="500" lsb="93"/>
<mtx name="BaseChar3" width="500" lsb="93"/>
<mtx name="BaseChar4_VS3" width="500" lsb="93"/>
<mtx name="BaseChar4_VS19" width="500" lsb="93"/>
<mtx name="BaseChar4_VS20" width="500" lsb="93"/>
<mtx name="defaultGlyph" width="500" lsb="93"/>
</hmtx>
<cmap>
<tableVersion version="0"/>
<cmap_format_4 platformID="3" platEncID="10" language="0">
<map code="0x82A6" name="BaseChar1" />
<map code="0x845B" name="BaseChar2" />
<map code="0x537F" name="BaseChar3" />
<map code="0x82A6" name="defaultGlyph" />
<map code="0x845B" name="defaultGlyph" />
<map code="0x537F" name="defaultGlyph" />
<map code="0x5380" name="defaultGlyph" />
</cmap_format_4>
<cmap_format_14 format="14" platformID="0" platEncID="5" length="40" numVarSelectorRecords="3">
<map uvs="0xFE00" uv="0x82A6" name="BaseChar1_VS1" />
<map uvs="0xE0100" uv="0x82A6" name="BaseChar1_VS17" />
<map uvs="0xE0101" uv="0x82A6" name="BaseChar1_VS18" />
<map uvs="0xFE00" uv="0x82A6" name="None" />
<map uvs="0xE0100" uv="0x82A6" name="None" />
<map uvs="0xE0101" uv="0x82A6" name="None" />
<map uvs="0xE0102" uv="0x82A6" name="None" />
<map uvs="0xFE01" uv="0x845B" name="BaseChar2_VS2" />
<map uvs="0xE0101" uv="0x845B" name="BaseChar2_VS18" />
<map uvs="0xE0102" uv="0x845B" name="BaseChar2_VS19" />
<map uvs="0xFE01" uv="0x845B" name="None" />
<map uvs="0xE0101" uv="0x845B" name="None" />
<map uvs="0xE0102" uv="0x845B" name="None" />
<map uvs="0xE0103" uv="0x845B" name="None" />
<map uvs="0xFE02" uv="0x717D" name="BaseChar4_VS3" />
<map uvs="0xE0102" uv="0x717D" name="BaseChar4_VS19" />
<map uvs="0xE0103" uv="0x717D" name="BaseChar4_VS20" />
<map uvs="0xFE02" uv="0x717D" name="defaultGlyph" />
<map uvs="0xE0102" uv="0x717D" name="defaultGlyph" />
<map uvs="0xE0103" uv="0x717D" name="defaultGlyph" />
<!-- There is no default glyph for U+717D U+E0104 but there is a entry for
default UVS entry. hasVariationSelector should return false in this
case. -->
<map uvs="0xE0104" uv="0x717D" name="None" />
<!-- Do not add entry for U+5380. -->
</cmap_format_14>
</cmap>
......@@ -202,40 +182,7 @@
<contour></contour><instructions><assembly></assembly></instructions>
</TTGlyph>
<TTGlyph name="BaseChar1" xMin="0" yMin="0" xMax="0" yMax="0">
<contour></contour><instructions><assembly></assembly></instructions>
</TTGlyph>
<TTGlyph name="BaseChar1_VS1" xMin="0" yMin="0" xMax="0" yMax="0">
<contour></contour><instructions><assembly></assembly></instructions>
</TTGlyph>
<TTGlyph name="BaseChar1_VS17" xMin="0" yMin="0" xMax="0" yMax="0">
<contour></contour><instructions><assembly></assembly></instructions>
</TTGlyph>
<TTGlyph name="BaseChar1_VS18" xMin="0" yMin="0" xMax="0" yMax="0">
<contour></contour><instructions><assembly></assembly></instructions>
</TTGlyph>
<TTGlyph name="BaseChar2" xMin="0" yMin="0" xMax="0" yMax="0">
<contour></contour><instructions><assembly></assembly></instructions>
</TTGlyph>
<TTGlyph name="BaseChar2_VS2" xMin="0" yMin="0" xMax="0" yMax="0">
<contour></contour><instructions><assembly></assembly></instructions>
</TTGlyph>
<TTGlyph name="BaseChar2_VS18" xMin="0" yMin="0" xMax="0" yMax="0">
<contour></contour><instructions><assembly></assembly></instructions>
</TTGlyph>
<TTGlyph name="BaseChar2_VS19" xMin="0" yMin="0" xMax="0" yMax="0">
<contour></contour><instructions><assembly></assembly></instructions>
</TTGlyph>
<TTGlyph name="BaseChar3" xMin="0" yMin="0" xMax="0" yMax="0">
<contour></contour><instructions><assembly></assembly></instructions>
</TTGlyph>
<TTGlyph name="BaseChar4_VS3" xMin="0" yMin="0" xMax="0" yMax="0">
<contour></contour><instructions><assembly></assembly></instructions>
</TTGlyph>
<TTGlyph name="BaseChar4_VS19" xMin="0" yMin="0" xMax="0" yMax="0">
<contour></contour><instructions><assembly></assembly></instructions>
</TTGlyph>
<TTGlyph name="BaseChar4_VS20" xMin="0" yMin="0" xMax="0" yMax="0">
<TTGlyph name="defaultGlyph" xMin="0" yMin="0" xMax="0" yMax="0">
<contour></contour><instructions><assembly></assembly></instructions>
</TTGlyph>
</glyf>
......
......@@ -32,6 +32,7 @@ font_src_files := \
data/Italic.ttf \
data/Ja.ttf \
data/Ko.ttf \
data/NoCmapFormat14.ttf \
data/NoGlyphFont.ttf \
data/Regular.ttf \
data/TextEmojiFont.ttf \
......
......@@ -44,6 +44,9 @@ const char kColorEmojiFont[] = kTestFontDir "ColorEmojiFont.ttf";
const char kTextEmojiFont[] = kTestFontDir "TextEmojiFont.ttf";
const char kMixedEmojiFont[] = kTestFontDir "ColorTextMixedEmojiFont.ttf";
const char kHasCmapFormat14Font[] = kTestFontDir "NoCmapFormat14.ttf";
const char kNoCmapFormat14Font[] = kTestFontDir "VarioationSelectorTest-Regular.ttf";
typedef ICUTestBase FontCollectionItemizeTest;
// Utility function for calling itemize function.
......@@ -1392,4 +1395,74 @@ TEST_F(FontCollectionItemizeTest, itemize_genderBalancedEmoji) {
EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0]));
}
// For b/29585939
TEST_F(FontCollectionItemizeTest, itemizeShouldKeepOrderForVS) {
const FontStyle kDefaultFontStyle;
MinikinAutoUnref<MinikinFont> dummyFont(MinikinFontForTest::createFromFile(kNoGlyphFont));
MinikinAutoUnref<MinikinFont> fontA(MinikinFontForTest::createFromFile(kZH_HansFont));
MinikinAutoUnref<MinikinFont> fontB(MinikinFontForTest::createFromFile(kZH_HansFont));
MinikinAutoUnref<FontFamily> dummyFamily(new FontFamily());
MinikinAutoUnref<FontFamily> familyA(new FontFamily());
MinikinAutoUnref<FontFamily> familyB(new FontFamily());
dummyFamily->addFont(dummyFont.get());
familyA->addFont(fontA.get());
familyB->addFont(fontB.get());
std::vector<FontFamily*> families =
{ dummyFamily.get(), familyA.get(), familyB.get() };
std::vector<FontFamily*> reversedFamilies =
{ dummyFamily.get(), familyB.get(), familyA.get() };
MinikinAutoUnref<FontCollection> collection(new FontCollection(families));
MinikinAutoUnref<FontCollection> reversedCollection(new FontCollection(reversedFamilies));
// Both fontA/fontB support U+35A8 but don't support U+35A8 U+E0100. The first font should be
// selected.
std::vector<FontCollection::Run> runs;
itemize(collection.get(), "U+35A8 U+E0100", kDefaultFontStyle, &runs);
EXPECT_EQ(fontA.get(), runs[0].fakedFont.font);
itemize(reversedCollection.get(), "U+35A8 U+E0100", kDefaultFontStyle, &runs);
EXPECT_EQ(fontB.get(), runs[0].fakedFont.font);
}
// For b/29585939
TEST_F(FontCollectionItemizeTest, itemizeShouldKeepOrderForVS2) {
const FontStyle kDefaultFontStyle;
MinikinAutoUnref<MinikinFont> dummyFont(MinikinFontForTest::createFromFile(kNoGlyphFont));
MinikinAutoUnref<MinikinFont> hasCmapFormat14Font(
MinikinFontForTest::createFromFile(kHasCmapFormat14Font));
MinikinAutoUnref<MinikinFont> noCmapFormat14Font(
MinikinFontForTest::createFromFile(kNoCmapFormat14Font));
MinikinAutoUnref<FontFamily> dummyFamily(new FontFamily());
MinikinAutoUnref<FontFamily> hasCmapFormat14Family(new FontFamily());
MinikinAutoUnref<FontFamily> noCmapFormat14Family(new FontFamily());
dummyFamily->addFont(dummyFont.get());
hasCmapFormat14Family->addFont(hasCmapFormat14Font.get());
noCmapFormat14Family->addFont(noCmapFormat14Font.get());
std::vector<FontFamily*> families =
{ dummyFamily.get(), hasCmapFormat14Family.get(), noCmapFormat14Family.get() };
std::vector<FontFamily*> reversedFamilies =
{ dummyFamily.get(), noCmapFormat14Family.get(), hasCmapFormat14Family.get() };
MinikinAutoUnref<FontCollection> collection(new FontCollection(families));
MinikinAutoUnref<FontCollection> reversedCollection(new FontCollection(reversedFamilies));
// Both hasCmapFormat14Font/noCmapFormat14Font support U+5380 but don't support U+5380 U+E0100.
// The first font should be selected.
std::vector<FontCollection::Run> runs;
itemize(collection.get(), "U+5380 U+E0100", kDefaultFontStyle, &runs);
EXPECT_EQ(hasCmapFormat14Font.get(), runs[0].fakedFont.font);
itemize(reversedCollection.get(), "U+5380 U+E0100", kDefaultFontStyle, &runs);
EXPECT_EQ(noCmapFormat14Font.get(), runs[0].fakedFont.font);
}
} // namespace minikin
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册