From cee83d40324b1f3b8e113eb8c9eda8e12ef36923 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Thu, 3 Mar 2016 15:33:33 -0800 Subject: Suppress log span due to returning null for itemize result. Bug: 26808815 Change-Id: I2a5a52f2c441d27c7ef270342b4ef93c3de9e56e --- include/minikin/FontCollection.h | 2 ++ libs/minikin/FontCollection.cpp | 14 ++++---------- tests/FontCollectionItemizeTest.cpp | 28 ++++++++++++++++++++++++---- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/include/minikin/FontCollection.h b/include/minikin/FontCollection.h index 5b9424c..c3c183d 100644 --- a/include/minikin/FontCollection.h +++ b/include/minikin/FontCollection.h @@ -84,9 +84,11 @@ private: uint32_t mMaxChar; // This vector has ownership of the bitsets and typeface objects. + // This vector can't be empty. std::vector mFamilies; // This vector contains pointers into mInstances + // This vector can't be empty. std::vector mFamilyVec; // This vector has pointers to the font family instance which has cmap 14 subtable. diff --git a/libs/minikin/FontCollection.cpp b/libs/minikin/FontCollection.cpp index 4541af8..e258250 100644 --- a/libs/minikin/FontCollection.cpp +++ b/libs/minikin/FontCollection.cpp @@ -230,10 +230,11 @@ uint32_t FontCollection::calcVariantMatchingScore(int variant, const FontFamily& // 1. If first font in the collection has the character, it wins. // 2. Calculate a score for the font family. See comments in calcFamilyScore for the detail. // 3. Highest score wins, with ties resolved to the first font. +// This method never returns nullptr. FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, uint32_t langListId, int variant) const { if (ch >= mMaxChar) { - return NULL; + return mFamilies[0]; } const std::vector* familyVec = &mFamilyVec; @@ -272,7 +273,7 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, bestFamily = family; } } - if (bestFamily == nullptr && !mFamilyVec.empty()) { + if (bestFamily == nullptr) { UErrorCode errorCode = U_ZERO_ERROR; const UNormalizer2* normalizer = unorm2_getNFDInstance(&errorCode); if (U_SUCCESS(errorCode)) { @@ -396,11 +397,7 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty Run dummy; result->push_back(dummy); run = &result->back(); - if (family == NULL) { - run->fakedFont.font = NULL; - } else { - run->fakedFont = family->getClosestMatch(style); - } + run->fakedFont = family->getClosestMatch(style); lastFamily = family; run->start = start; } @@ -415,9 +412,6 @@ MinikinFont* FontCollection::baseFont(FontStyle style) { } FakedFont FontCollection::baseFontFaked(FontStyle style) { - if (mFamilies.empty()) { - return FakedFont(); - } return mFamilies[0]->getClosestMatch(style); } diff --git a/tests/FontCollectionItemizeTest.cpp b/tests/FontCollectionItemizeTest.cpp index 031f3f9..22971c8 100644 --- a/tests/FontCollectionItemizeTest.cpp +++ b/tests/FontCollectionItemizeTest.cpp @@ -1156,7 +1156,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_TRUE(runs[0].fakedFont.font == NULL || kNoGlyphFont == getFontPath(runs[0])); + EXPECT_EQ(kNoGlyphFont, getFontPath(runs[0])); // U+231A is a emoji default emoji which is available only in TextEmojifFont. // TextEmojiFont.ttf sohuld be selected. @@ -1190,7 +1190,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_TRUE(runs[0].fakedFont.font == NULL || kNoGlyphFont == getFontPath(runs[0])); + EXPECT_EQ(kNoGlyphFont, getFontPath(runs[0])); // U+26FA U+FE0E is specified but ColorTextMixedEmojiFont has a variation sequence U+26F9 U+FE0F // in its cmap, so ColorTextMixedEmojiFont should be selected instaed of ColorEmojiFont. @@ -1239,7 +1239,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_TRUE(runs[0].fakedFont.font == NULL || kNoGlyphFont == getFontPath(runs[0])); + EXPECT_EQ(kNoGlyphFont, getFontPath(runs[0])); // U+231A is a emoji default emoji which is available only in TextEmojiFont.ttf. // TextEmojiFont.ttf should be selected. @@ -1272,7 +1272,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_TRUE(runs[0].fakedFont.font == NULL || kNoGlyphFont == getFontPath(runs[0])); + EXPECT_EQ(kNoGlyphFont, getFontPath(runs[0])); // U+26F9 U+FE0F is specified but ColorTextMixedEmojiFont has a variation sequence U+26F9 U+FE0F // in its cmap, so ColorTextMixedEmojiFont should be selected instaed of ColorEmojiFont. @@ -1321,3 +1321,23 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_with_skinTone) { EXPECT_EQ(4, runs[1].end); EXPECT_EQ(kColorEmojiFont, getFontPath(runs[1])); } + +TEST_F(FontCollectionItemizeTest, itemize_PrivateUseArea) { + std::unique_ptr collection = getFontCollection(kTestFontDir, kEmojiXmlFile); + std::vector runs; + + const FontStyle kDefaultFontStyle; + + // Should not set nullptr to the result run. (Issue 26808815) + itemize(collection.get(), "U+FEE10", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kNoGlyphFont, getFontPath(runs[0])); + + itemize(collection.get(), "U+FEE40 U+FE4C5", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(4, runs[0].end); + EXPECT_EQ(kNoGlyphFont, getFontPath(runs[0])); +} -- cgit v1.2.3