Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <gtest/gtest.h> |
| 18 | |
| 19 | #include <fcntl.h> |
| 20 | #include <sys/mman.h> |
| 21 | #include <sys/stat.h> |
| 22 | #include <utils/Log.h> |
| 23 | |
| 24 | #include "SkFontMgr.h" |
| 25 | #include "SkStream.h" |
| 26 | |
| 27 | #include "hwui/MinikinSkia.h" |
| 28 | #include "hwui/Typeface.h" |
| 29 | |
| 30 | using namespace android; |
| 31 | |
| 32 | namespace { |
| 33 | |
| 34 | constexpr char kRobotoRegular[] = "/system/fonts/Roboto-Regular.ttf"; |
| 35 | constexpr char kRobotoBold[] = "/system/fonts/Roboto-Bold.ttf"; |
| 36 | constexpr char kRobotoItalic[] = "/system/fonts/Roboto-Italic.ttf"; |
| 37 | constexpr char kRobotoBoldItalic[] = "/system/fonts/Roboto-BoldItalic.ttf"; |
| 38 | |
| 39 | void unmap(const void* ptr, void* context) { |
| 40 | void* p = const_cast<void*>(ptr); |
| 41 | size_t len = reinterpret_cast<size_t>(context); |
| 42 | munmap(p, len); |
| 43 | } |
| 44 | |
| 45 | std::shared_ptr<minikin::FontFamily> buildFamily(const char* fileName) { |
| 46 | int fd = open(fileName, O_RDONLY); |
| 47 | LOG_ALWAYS_FATAL_IF(fd == -1, "Failed to open file %s", fileName); |
| 48 | struct stat st = {}; |
| 49 | LOG_ALWAYS_FATAL_IF(fstat(fd, &st) == -1, "Failed to stat file %s", fileName); |
| 50 | void* data = mmap(nullptr, st.st_size, PROT_READ, MAP_SHARED, fd, 0); |
| 51 | sk_sp<SkData> skData = |
| 52 | SkData::MakeWithProc(data, st.st_size, unmap, reinterpret_cast<void*>(st.st_size)); |
| 53 | std::unique_ptr<SkStreamAsset> fontData(new SkMemoryStream(skData)); |
| 54 | sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault()); |
Mike Reed | 839a186 | 2017-09-26 16:06:34 -0400 | [diff] [blame] | 55 | sk_sp<SkTypeface> typeface(fm->makeFromStream(std::move(fontData))); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 56 | LOG_ALWAYS_FATAL_IF(typeface == nullptr, "Failed to make typeface from %s", fileName); |
| 57 | std::shared_ptr<minikin::MinikinFont> font = std::make_shared<MinikinFontSkia>( |
| 58 | std::move(typeface), data, st.st_size, 0, std::vector<minikin::FontVariation>()); |
Seigo Nonaka | 99d66f0 | 2018-01-30 15:01:26 -0800 | [diff] [blame] | 59 | std::vector<minikin::Font> fonts; |
Seigo Nonaka | 0606a88 | 2018-01-31 19:29:40 -0800 | [diff] [blame] | 60 | fonts.push_back(minikin::Font::Builder(font).build()); |
Seigo Nonaka | 99d66f0 | 2018-01-30 15:01:26 -0800 | [diff] [blame] | 61 | return std::make_shared<minikin::FontFamily>(std::move(fonts)); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | std::vector<std::shared_ptr<minikin::FontFamily>> makeSingleFamlyVector(const char* fileName) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 65 | return std::vector<std::shared_ptr<minikin::FontFamily>>({buildFamily(fileName)}); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | TEST(TypefaceTest, resolveDefault_and_setDefaultTest) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 69 | std::unique_ptr<Typeface> regular(Typeface::createFromFamilies( |
| 70 | makeSingleFamlyVector(kRobotoRegular), RESOLVE_BY_FONT_TABLE, RESOLVE_BY_FONT_TABLE)); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 71 | EXPECT_EQ(regular.get(), Typeface::resolveDefault(regular.get())); |
| 72 | |
Seigo Nonaka | 318ca04 | 2017-08-01 16:36:18 -0700 | [diff] [blame] | 73 | // Keep the original to restore it later. |
| 74 | const Typeface* old = Typeface::resolveDefault(nullptr); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 75 | ASSERT_NE(nullptr, old); |
| 76 | |
| 77 | Typeface::setDefault(regular.get()); |
| 78 | EXPECT_EQ(regular.get(), Typeface::resolveDefault(nullptr)); |
| 79 | |
| 80 | Typeface::setDefault(old); // Restore to the original. |
| 81 | } |
| 82 | |
| 83 | TEST(TypefaceTest, createWithDifferentBaseWeight) { |
| 84 | std::unique_ptr<Typeface> bold(Typeface::createWithDifferentBaseWeight(nullptr, 700)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 85 | EXPECT_EQ(700, bold->fStyle.weight()); |
| 86 | EXPECT_EQ(minikin::FontStyle::Slant::UPRIGHT, bold->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 87 | EXPECT_EQ(Typeface::kNormal, bold->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 88 | |
| 89 | std::unique_ptr<Typeface> light(Typeface::createWithDifferentBaseWeight(nullptr, 300)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 90 | EXPECT_EQ(300, light->fStyle.weight()); |
| 91 | EXPECT_EQ(minikin::FontStyle::Slant::UPRIGHT, light->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 92 | EXPECT_EQ(Typeface::kNormal, light->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | TEST(TypefaceTest, createRelativeTest_fromRegular) { |
| 96 | // In Java, Typeface.create(Typeface.DEFAULT, Typeface.NORMAL); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 97 | std::unique_ptr<Typeface> normal(Typeface::createRelative(nullptr, Typeface::kNormal)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 98 | EXPECT_EQ(400, normal->fStyle.weight()); |
| 99 | EXPECT_EQ(minikin::FontStyle::Slant::UPRIGHT, normal->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 100 | EXPECT_EQ(Typeface::kNormal, normal->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 101 | |
| 102 | // In Java, Typeface.create(Typeface.DEFAULT, Typeface.BOLD); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 103 | std::unique_ptr<Typeface> bold(Typeface::createRelative(nullptr, Typeface::kBold)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 104 | EXPECT_EQ(700, bold->fStyle.weight()); |
| 105 | EXPECT_EQ(minikin::FontStyle::Slant::UPRIGHT, bold->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 106 | EXPECT_EQ(Typeface::kBold, bold->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 107 | |
| 108 | // In Java, Typeface.create(Typeface.DEFAULT, Typeface.ITALIC); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 109 | std::unique_ptr<Typeface> italic(Typeface::createRelative(nullptr, Typeface::kItalic)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 110 | EXPECT_EQ(400, italic->fStyle.weight()); |
| 111 | EXPECT_EQ(minikin::FontStyle::Slant::ITALIC, italic->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 112 | EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 113 | |
| 114 | // In Java, Typeface.create(Typeface.DEFAULT, Typeface.BOLD_ITALIC); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 115 | std::unique_ptr<Typeface> boldItalic(Typeface::createRelative(nullptr, Typeface::kBoldItalic)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 116 | EXPECT_EQ(700, boldItalic->fStyle.weight()); |
| 117 | EXPECT_EQ(minikin::FontStyle::Slant::ITALIC, boldItalic->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 118 | EXPECT_EQ(Typeface::kBoldItalic, boldItalic->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | TEST(TypefaceTest, createRelativeTest_BoldBase) { |
| 122 | std::unique_ptr<Typeface> base(Typeface::createWithDifferentBaseWeight(nullptr, 700)); |
| 123 | |
Seigo Nonaka | 20866c1 | 2017-10-26 16:02:01 -0700 | [diff] [blame] | 124 | // In Java, Typeface.create(Typeface.create("sans-serif-bold"), |
| 125 | // Typeface.NORMAL); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 126 | std::unique_ptr<Typeface> normal(Typeface::createRelative(base.get(), Typeface::kNormal)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 127 | EXPECT_EQ(700, normal->fStyle.weight()); |
| 128 | EXPECT_EQ(minikin::FontStyle::Slant::UPRIGHT, normal->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 129 | EXPECT_EQ(Typeface::kNormal, normal->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 130 | |
Seigo Nonaka | 20866c1 | 2017-10-26 16:02:01 -0700 | [diff] [blame] | 131 | // In Java, Typeface.create(Typeface.create("sans-serif-bold"), |
| 132 | // Typeface.BOLD); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 133 | std::unique_ptr<Typeface> bold(Typeface::createRelative(base.get(), Typeface::kBold)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 134 | EXPECT_EQ(1000, bold->fStyle.weight()); |
| 135 | EXPECT_EQ(minikin::FontStyle::Slant::UPRIGHT, bold->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 136 | EXPECT_EQ(Typeface::kBold, bold->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 137 | |
Seigo Nonaka | 20866c1 | 2017-10-26 16:02:01 -0700 | [diff] [blame] | 138 | // In Java, Typeface.create(Typeface.create("sans-serif-bold"), |
| 139 | // Typeface.ITALIC); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 140 | std::unique_ptr<Typeface> italic(Typeface::createRelative(base.get(), Typeface::kItalic)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 141 | EXPECT_EQ(700, italic->fStyle.weight()); |
| 142 | EXPECT_EQ(minikin::FontStyle::Slant::ITALIC, italic->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 143 | EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 144 | |
Seigo Nonaka | 20866c1 | 2017-10-26 16:02:01 -0700 | [diff] [blame] | 145 | // In Java, Typeface.create(Typeface.create("sans-serif-bold"), |
| 146 | // Typeface.BOLD_ITALIC); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 147 | std::unique_ptr<Typeface> boldItalic( |
| 148 | Typeface::createRelative(base.get(), Typeface::kBoldItalic)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 149 | EXPECT_EQ(1000, boldItalic->fStyle.weight()); |
| 150 | EXPECT_EQ(minikin::FontStyle::Slant::ITALIC, boldItalic->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 151 | EXPECT_EQ(Typeface::kBoldItalic, boldItalic->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | TEST(TypefaceTest, createRelativeTest_LightBase) { |
| 155 | std::unique_ptr<Typeface> base(Typeface::createWithDifferentBaseWeight(nullptr, 300)); |
| 156 | |
Seigo Nonaka | 20866c1 | 2017-10-26 16:02:01 -0700 | [diff] [blame] | 157 | // In Java, Typeface.create(Typeface.create("sans-serif-light"), |
| 158 | // Typeface.NORMAL); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 159 | std::unique_ptr<Typeface> normal(Typeface::createRelative(base.get(), Typeface::kNormal)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 160 | EXPECT_EQ(300, normal->fStyle.weight()); |
| 161 | EXPECT_EQ(minikin::FontStyle::Slant::UPRIGHT, normal->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 162 | EXPECT_EQ(Typeface::kNormal, normal->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 163 | |
Seigo Nonaka | 20866c1 | 2017-10-26 16:02:01 -0700 | [diff] [blame] | 164 | // In Java, Typeface.create(Typeface.create("sans-serif-light"), |
| 165 | // Typeface.BOLD); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 166 | std::unique_ptr<Typeface> bold(Typeface::createRelative(base.get(), Typeface::kBold)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 167 | EXPECT_EQ(600, bold->fStyle.weight()); |
| 168 | EXPECT_EQ(minikin::FontStyle::Slant::UPRIGHT, bold->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 169 | EXPECT_EQ(Typeface::kBold, bold->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 170 | |
Seigo Nonaka | 20866c1 | 2017-10-26 16:02:01 -0700 | [diff] [blame] | 171 | // In Java, Typeface.create(Typeface.create("sans-serif-light"), |
| 172 | // Typeface.ITLIC); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 173 | std::unique_ptr<Typeface> italic(Typeface::createRelative(base.get(), Typeface::kItalic)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 174 | EXPECT_EQ(300, italic->fStyle.weight()); |
| 175 | EXPECT_EQ(minikin::FontStyle::Slant::ITALIC, italic->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 176 | EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 177 | |
Seigo Nonaka | 20866c1 | 2017-10-26 16:02:01 -0700 | [diff] [blame] | 178 | // In Java, Typeface.create(Typeface.create("sans-serif-light"), |
| 179 | // Typeface.BOLD_ITALIC); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 180 | std::unique_ptr<Typeface> boldItalic( |
| 181 | Typeface::createRelative(base.get(), Typeface::kBoldItalic)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 182 | EXPECT_EQ(600, boldItalic->fStyle.weight()); |
| 183 | EXPECT_EQ(minikin::FontStyle::Slant::ITALIC, boldItalic->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 184 | EXPECT_EQ(Typeface::kBoldItalic, boldItalic->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | TEST(TypefaceTest, createRelativeTest_fromBoldStyled) { |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 188 | std::unique_ptr<Typeface> base(Typeface::createRelative(nullptr, Typeface::kBold)); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 189 | |
Seigo Nonaka | 20866c1 | 2017-10-26 16:02:01 -0700 | [diff] [blame] | 190 | // In Java, Typeface.create(Typeface.create(Typeface.DEFAULT, Typeface.BOLD), |
| 191 | // Typeface.NORMAL); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 192 | std::unique_ptr<Typeface> normal(Typeface::createRelative(base.get(), Typeface::kNormal)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 193 | EXPECT_EQ(400, normal->fStyle.weight()); |
| 194 | EXPECT_EQ(minikin::FontStyle::Slant::UPRIGHT, normal->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 195 | EXPECT_EQ(Typeface::kNormal, normal->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 196 | |
Seigo Nonaka | 20866c1 | 2017-10-26 16:02:01 -0700 | [diff] [blame] | 197 | // In Java Typeface.create(Typeface.create(Typeface.DEFAULT, Typeface.BOLD), |
| 198 | // Typeface.BOLD); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 199 | std::unique_ptr<Typeface> bold(Typeface::createRelative(base.get(), Typeface::kBold)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 200 | EXPECT_EQ(700, bold->fStyle.weight()); |
| 201 | EXPECT_EQ(minikin::FontStyle::Slant::UPRIGHT, bold->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 202 | EXPECT_EQ(Typeface::kBold, bold->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 203 | |
Seigo Nonaka | 20866c1 | 2017-10-26 16:02:01 -0700 | [diff] [blame] | 204 | // In Java, Typeface.create(Typeface.create(Typeface.DEFAULT, Typeface.BOLD), |
| 205 | // Typeface.ITALIC); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 206 | std::unique_ptr<Typeface> italic(Typeface::createRelative(base.get(), Typeface::kItalic)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 207 | EXPECT_EQ(400, normal->fStyle.weight()); |
| 208 | EXPECT_EQ(minikin::FontStyle::Slant::ITALIC, italic->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 209 | EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 210 | |
| 211 | // In Java, |
Seigo Nonaka | 20866c1 | 2017-10-26 16:02:01 -0700 | [diff] [blame] | 212 | // Typeface.create(Typeface.create(Typeface.DEFAULT, Typeface.BOLD), |
| 213 | // Typeface.BOLD_ITALIC); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 214 | std::unique_ptr<Typeface> boldItalic( |
| 215 | Typeface::createRelative(base.get(), Typeface::kBoldItalic)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 216 | EXPECT_EQ(700, boldItalic->fStyle.weight()); |
| 217 | EXPECT_EQ(minikin::FontStyle::Slant::ITALIC, boldItalic->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 218 | EXPECT_EQ(Typeface::kBoldItalic, boldItalic->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | TEST(TypefaceTest, createRelativeTest_fromItalicStyled) { |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 222 | std::unique_ptr<Typeface> base(Typeface::createRelative(nullptr, Typeface::kItalic)); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 223 | |
| 224 | // In Java, |
Seigo Nonaka | 20866c1 | 2017-10-26 16:02:01 -0700 | [diff] [blame] | 225 | // Typeface.create(Typeface.create(Typeface.DEFAULT, Typeface.ITALIC), |
| 226 | // Typeface.NORMAL); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 227 | std::unique_ptr<Typeface> normal(Typeface::createRelative(base.get(), Typeface::kNormal)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 228 | EXPECT_EQ(400, normal->fStyle.weight()); |
| 229 | EXPECT_EQ(minikin::FontStyle::Slant::UPRIGHT, normal->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 230 | EXPECT_EQ(Typeface::kNormal, normal->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 231 | |
Seigo Nonaka | 20866c1 | 2017-10-26 16:02:01 -0700 | [diff] [blame] | 232 | // In Java, Typeface.create(Typeface.create(Typeface.DEFAULT, |
| 233 | // Typeface.ITALIC), Typeface.BOLD); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 234 | std::unique_ptr<Typeface> bold(Typeface::createRelative(base.get(), Typeface::kBold)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 235 | EXPECT_EQ(700, bold->fStyle.weight()); |
| 236 | EXPECT_EQ(minikin::FontStyle::Slant::UPRIGHT, bold->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 237 | EXPECT_EQ(Typeface::kBold, bold->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 238 | |
| 239 | // In Java, |
Seigo Nonaka | 20866c1 | 2017-10-26 16:02:01 -0700 | [diff] [blame] | 240 | // Typeface.create(Typeface.create(Typeface.DEFAULT, Typeface.ITALIC), |
| 241 | // Typeface.ITALIC); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 242 | std::unique_ptr<Typeface> italic(Typeface::createRelative(base.get(), Typeface::kItalic)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 243 | EXPECT_EQ(400, italic->fStyle.weight()); |
| 244 | EXPECT_EQ(minikin::FontStyle::Slant::ITALIC, italic->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 245 | EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 246 | |
| 247 | // In Java, |
Seigo Nonaka | 20866c1 | 2017-10-26 16:02:01 -0700 | [diff] [blame] | 248 | // Typeface.create(Typeface.create(Typeface.DEFAULT, Typeface.ITALIC), |
| 249 | // Typeface.BOLD_ITALIC); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 250 | std::unique_ptr<Typeface> boldItalic( |
| 251 | Typeface::createRelative(base.get(), Typeface::kBoldItalic)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 252 | EXPECT_EQ(700, boldItalic->fStyle.weight()); |
| 253 | EXPECT_EQ(minikin::FontStyle::Slant::ITALIC, boldItalic->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 254 | EXPECT_EQ(Typeface::kBoldItalic, boldItalic->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | TEST(TypefaceTest, createRelativeTest_fromSpecifiedStyled) { |
| 258 | std::unique_ptr<Typeface> base(Typeface::createAbsolute(nullptr, 400, false)); |
| 259 | |
| 260 | // In Java, |
| 261 | // Typeface typeface = new Typeface.Builder(invalid).setFallback("sans-serif") |
| 262 | // .setWeight(700).setItalic(false).build(); |
| 263 | // Typeface.create(typeface, Typeface.NORMAL); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 264 | std::unique_ptr<Typeface> normal(Typeface::createRelative(base.get(), Typeface::kNormal)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 265 | EXPECT_EQ(400, normal->fStyle.weight()); |
| 266 | EXPECT_EQ(minikin::FontStyle::Slant::UPRIGHT, normal->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 267 | EXPECT_EQ(Typeface::kNormal, normal->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 268 | |
| 269 | // In Java, |
| 270 | // Typeface typeface = new Typeface.Builder(invalid).setFallback("sans-serif") |
| 271 | // .setWeight(700).setItalic(false).build(); |
| 272 | // Typeface.create(typeface, Typeface.BOLD); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 273 | std::unique_ptr<Typeface> bold(Typeface::createRelative(base.get(), Typeface::kBold)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 274 | EXPECT_EQ(700, bold->fStyle.weight()); |
| 275 | EXPECT_EQ(minikin::FontStyle::Slant::UPRIGHT, bold->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 276 | EXPECT_EQ(Typeface::kBold, bold->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 277 | |
| 278 | // In Java, |
| 279 | // Typeface typeface = new Typeface.Builder(invalid).setFallback("sans-serif") |
| 280 | // .setWeight(700).setItalic(false).build(); |
| 281 | // Typeface.create(typeface, Typeface.ITALIC); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 282 | std::unique_ptr<Typeface> italic(Typeface::createRelative(base.get(), Typeface::kItalic)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 283 | EXPECT_EQ(400, italic->fStyle.weight()); |
| 284 | EXPECT_EQ(minikin::FontStyle::Slant::ITALIC, italic->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 285 | EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 286 | |
| 287 | // In Java, |
| 288 | // Typeface typeface = new Typeface.Builder(invalid).setFallback("sans-serif") |
| 289 | // .setWeight(700).setItalic(false).build(); |
| 290 | // Typeface.create(typeface, Typeface.BOLD_ITALIC); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 291 | std::unique_ptr<Typeface> boldItalic( |
| 292 | Typeface::createRelative(base.get(), Typeface::kBoldItalic)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 293 | EXPECT_EQ(700, boldItalic->fStyle.weight()); |
| 294 | EXPECT_EQ(minikin::FontStyle::Slant::ITALIC, boldItalic->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 295 | EXPECT_EQ(Typeface::kBoldItalic, boldItalic->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | TEST(TypefaceTest, createAbsolute) { |
| 299 | // In Java, |
Seigo Nonaka | 20866c1 | 2017-10-26 16:02:01 -0700 | [diff] [blame] | 300 | // new |
| 301 | // Typeface.Builder(invalid).setFallback("sans-serif").setWeight(400).setItalic(false) |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 302 | // .build(); |
| 303 | std::unique_ptr<Typeface> regular(Typeface::createAbsolute(nullptr, 400, false)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 304 | EXPECT_EQ(400, regular->fStyle.weight()); |
| 305 | EXPECT_EQ(minikin::FontStyle::Slant::UPRIGHT, regular->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 306 | EXPECT_EQ(Typeface::kNormal, regular->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 307 | |
| 308 | // In Java, |
Seigo Nonaka | 20866c1 | 2017-10-26 16:02:01 -0700 | [diff] [blame] | 309 | // new |
| 310 | // Typeface.Builder(invalid).setFallback("sans-serif").setWeight(700).setItalic(false) |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 311 | // .build(); |
| 312 | std::unique_ptr<Typeface> bold(Typeface::createAbsolute(nullptr, 700, false)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 313 | EXPECT_EQ(700, bold->fStyle.weight()); |
| 314 | EXPECT_EQ(minikin::FontStyle::Slant::UPRIGHT, bold->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 315 | EXPECT_EQ(Typeface::kBold, bold->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 316 | |
| 317 | // In Java, |
Seigo Nonaka | 20866c1 | 2017-10-26 16:02:01 -0700 | [diff] [blame] | 318 | // new |
| 319 | // Typeface.Builder(invalid).setFallback("sans-serif").setWeight(400).setItalic(true) |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 320 | // .build(); |
| 321 | std::unique_ptr<Typeface> italic(Typeface::createAbsolute(nullptr, 400, true)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 322 | EXPECT_EQ(400, italic->fStyle.weight()); |
| 323 | EXPECT_EQ(minikin::FontStyle::Slant::ITALIC, italic->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 324 | EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 325 | |
| 326 | // In Java, |
Seigo Nonaka | 20866c1 | 2017-10-26 16:02:01 -0700 | [diff] [blame] | 327 | // new |
| 328 | // Typeface.Builder(invalid).setFallback("sans-serif").setWeight(700).setItalic(true) |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 329 | // .build(); |
| 330 | std::unique_ptr<Typeface> boldItalic(Typeface::createAbsolute(nullptr, 700, true)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 331 | EXPECT_EQ(700, boldItalic->fStyle.weight()); |
| 332 | EXPECT_EQ(minikin::FontStyle::Slant::ITALIC, boldItalic->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 333 | EXPECT_EQ(Typeface::kBoldItalic, boldItalic->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 334 | |
| 335 | // In Java, |
Seigo Nonaka | 20866c1 | 2017-10-26 16:02:01 -0700 | [diff] [blame] | 336 | // new |
| 337 | // Typeface.Builder(invalid).setFallback("sans-serif").setWeight(1100).setItalic(true) |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 338 | // .build(); |
| 339 | std::unique_ptr<Typeface> over1000(Typeface::createAbsolute(nullptr, 1100, false)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 340 | EXPECT_EQ(1000, over1000->fStyle.weight()); |
| 341 | EXPECT_EQ(minikin::FontStyle::Slant::UPRIGHT, over1000->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 342 | EXPECT_EQ(Typeface::kBold, over1000->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | TEST(TypefaceTest, createFromFamilies_Single) { |
Seigo Nonaka | 20866c1 | 2017-10-26 16:02:01 -0700 | [diff] [blame] | 346 | // In Java, new |
| 347 | // Typeface.Builder("Roboto-Regular.ttf").setWeight(400).setItalic(false).build(); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 348 | std::unique_ptr<Typeface> regular( |
| 349 | Typeface::createFromFamilies(makeSingleFamlyVector(kRobotoRegular), 400, false)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 350 | EXPECT_EQ(400, regular->fStyle.weight()); |
| 351 | EXPECT_EQ(minikin::FontStyle::Slant::UPRIGHT, regular->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 352 | EXPECT_EQ(Typeface::kNormal, regular->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 353 | |
Seigo Nonaka | 20866c1 | 2017-10-26 16:02:01 -0700 | [diff] [blame] | 354 | // In Java, new |
| 355 | // Typeface.Builder("Roboto-Bold.ttf").setWeight(700).setItalic(false).build(); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 356 | std::unique_ptr<Typeface> bold( |
| 357 | Typeface::createFromFamilies(makeSingleFamlyVector(kRobotoBold), 700, false)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 358 | EXPECT_EQ(700, bold->fStyle.weight()); |
| 359 | EXPECT_EQ(minikin::FontStyle::Slant::UPRIGHT, bold->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 360 | EXPECT_EQ(Typeface::kBold, bold->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 361 | |
Seigo Nonaka | 20866c1 | 2017-10-26 16:02:01 -0700 | [diff] [blame] | 362 | // In Java, new |
| 363 | // Typeface.Builder("Roboto-Italic.ttf").setWeight(400).setItalic(true).build(); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 364 | std::unique_ptr<Typeface> italic( |
| 365 | Typeface::createFromFamilies(makeSingleFamlyVector(kRobotoItalic), 400, true)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 366 | EXPECT_EQ(400, italic->fStyle.weight()); |
| 367 | EXPECT_EQ(minikin::FontStyle::Slant::ITALIC, italic->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 368 | EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 369 | |
| 370 | // In Java, |
Seigo Nonaka | 20866c1 | 2017-10-26 16:02:01 -0700 | [diff] [blame] | 371 | // new |
| 372 | // Typeface.Builder("Roboto-BoldItalic.ttf").setWeight(700).setItalic(true).build(); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 373 | std::unique_ptr<Typeface> boldItalic( |
| 374 | Typeface::createFromFamilies(makeSingleFamlyVector(kRobotoBoldItalic), 700, true)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 375 | EXPECT_EQ(700, boldItalic->fStyle.weight()); |
| 376 | EXPECT_EQ(minikin::FontStyle::Slant::ITALIC, boldItalic->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 377 | EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 378 | |
| 379 | // In Java, |
Seigo Nonaka | 20866c1 | 2017-10-26 16:02:01 -0700 | [diff] [blame] | 380 | // new |
| 381 | // Typeface.Builder("Roboto-BoldItalic.ttf").setWeight(1100).setItalic(false).build(); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 382 | std::unique_ptr<Typeface> over1000( |
| 383 | Typeface::createFromFamilies(makeSingleFamlyVector(kRobotoBold), 1100, false)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 384 | EXPECT_EQ(1000, over1000->fStyle.weight()); |
| 385 | EXPECT_EQ(minikin::FontStyle::Slant::UPRIGHT, over1000->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 386 | EXPECT_EQ(Typeface::kBold, over1000->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | TEST(TypefaceTest, createFromFamilies_Single_resolveByTable) { |
| 390 | // In Java, new Typeface.Builder("Roboto-Regular.ttf").build(); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 391 | std::unique_ptr<Typeface> regular(Typeface::createFromFamilies( |
| 392 | makeSingleFamlyVector(kRobotoRegular), RESOLVE_BY_FONT_TABLE, RESOLVE_BY_FONT_TABLE)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 393 | EXPECT_EQ(400, regular->fStyle.weight()); |
| 394 | EXPECT_EQ(minikin::FontStyle::Slant::UPRIGHT, regular->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 395 | EXPECT_EQ(Typeface::kNormal, regular->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 396 | |
| 397 | // In Java, new Typeface.Builder("Roboto-Bold.ttf").build(); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 398 | std::unique_ptr<Typeface> bold(Typeface::createFromFamilies( |
| 399 | makeSingleFamlyVector(kRobotoBold), RESOLVE_BY_FONT_TABLE, RESOLVE_BY_FONT_TABLE)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 400 | EXPECT_EQ(700, bold->fStyle.weight()); |
| 401 | EXPECT_EQ(minikin::FontStyle::Slant::UPRIGHT, bold->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 402 | EXPECT_EQ(Typeface::kBold, bold->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 403 | |
| 404 | // In Java, new Typeface.Builder("Roboto-Italic.ttf").build(); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 405 | std::unique_ptr<Typeface> italic(Typeface::createFromFamilies( |
| 406 | makeSingleFamlyVector(kRobotoItalic), RESOLVE_BY_FONT_TABLE, RESOLVE_BY_FONT_TABLE)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 407 | EXPECT_EQ(400, italic->fStyle.weight()); |
| 408 | EXPECT_EQ(minikin::FontStyle::Slant::ITALIC, italic->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 409 | EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 410 | |
| 411 | // In Java, new Typeface.Builder("Roboto-BoldItalic.ttf").build(); |
| 412 | std::unique_ptr<Typeface> boldItalic( |
| 413 | Typeface::createFromFamilies(makeSingleFamlyVector(kRobotoBoldItalic), |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 414 | RESOLVE_BY_FONT_TABLE, RESOLVE_BY_FONT_TABLE)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 415 | EXPECT_EQ(700, boldItalic->fStyle.weight()); |
| 416 | EXPECT_EQ(minikin::FontStyle::Slant::ITALIC, boldItalic->fStyle.slant()); |
Ben Wagner | 2763fb7 | 2017-10-06 17:36:23 -0400 | [diff] [blame] | 417 | EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | TEST(TypefaceTest, createFromFamilies_Family) { |
| 421 | std::vector<std::shared_ptr<minikin::FontFamily>> families = { |
| 422 | buildFamily(kRobotoRegular), buildFamily(kRobotoBold), buildFamily(kRobotoItalic), |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 423 | buildFamily(kRobotoBoldItalic)}; |
| 424 | std::unique_ptr<Typeface> typeface(Typeface::createFromFamilies( |
| 425 | std::move(families), RESOLVE_BY_FONT_TABLE, RESOLVE_BY_FONT_TABLE)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 426 | EXPECT_EQ(400, typeface->fStyle.weight()); |
| 427 | EXPECT_EQ(minikin::FontStyle::Slant::UPRIGHT, typeface->fStyle.slant()); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | TEST(TypefaceTest, createFromFamilies_Family_withoutRegular) { |
| 431 | std::vector<std::shared_ptr<minikin::FontFamily>> families = { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 432 | buildFamily(kRobotoBold), buildFamily(kRobotoItalic), buildFamily(kRobotoBoldItalic)}; |
| 433 | std::unique_ptr<Typeface> typeface(Typeface::createFromFamilies( |
| 434 | std::move(families), RESOLVE_BY_FONT_TABLE, RESOLVE_BY_FONT_TABLE)); |
Seigo Nonaka | c52075e | 2017-11-17 15:40:06 -0800 | [diff] [blame] | 435 | EXPECT_EQ(700, typeface->fStyle.weight()); |
| 436 | EXPECT_EQ(minikin::FontStyle::Slant::UPRIGHT, typeface->fStyle.slant()); |
Seigo Nonaka | 1f9c461 | 2017-05-01 22:17:36 -0700 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | } // namespace |