| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/font_service/font_service_app.h" | 5 #include "components/font_service/font_service_app.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "mojo/application/public/cpp/application_connection.h" | 11 #include "mojo/application/public/cpp/application_connection.h" |
| 12 #include "mojo/platform_handle/platform_handle_functions.h" | 12 #include "mojo/platform_handle/platform_handle_functions.h" |
| 13 | 13 |
| 14 static_assert(static_cast<uint32_t>(SkTypeface::kNormal) == | 14 static_assert(static_cast<uint32_t>(SkTypeface::kNormal) == |
| 15 static_cast<uint32_t>(font_service::TYPEFACE_STYLE_NORMAL), | 15 static_cast<uint32_t>(font_service::TypefaceStyle::NORMAL), |
| 16 "Skia and font service flags must match"); | 16 "Skia and font service flags must match"); |
| 17 static_assert(static_cast<uint32_t>(SkTypeface::kBold) == | 17 static_assert(static_cast<uint32_t>(SkTypeface::kBold) == |
| 18 static_cast<uint32_t>(font_service::TYPEFACE_STYLE_BOLD), | 18 static_cast<uint32_t>(font_service::TypefaceStyle::BOLD), |
| 19 "Skia and font service flags must match"); | 19 "Skia and font service flags must match"); |
| 20 static_assert(static_cast<uint32_t>(SkTypeface::kItalic) == | 20 static_assert(static_cast<uint32_t>(SkTypeface::kItalic) == |
| 21 static_cast<uint32_t>(font_service::TYPEFACE_STYLE_ITALIC), | 21 static_cast<uint32_t>(font_service::TypefaceStyle::ITALIC), |
| 22 "Skia and font service flags must match"); | 22 "Skia and font service flags must match"); |
| 23 static_assert( | 23 static_assert( |
| 24 static_cast<uint32_t>(SkTypeface::kBoldItalic) == | 24 static_cast<uint32_t>(SkTypeface::kBoldItalic) == |
| 25 static_cast<uint32_t>(font_service::TYPEFACE_STYLE_BOLD_ITALIC), | 25 static_cast<uint32_t>(font_service::TypefaceStyle::BOLD_ITALIC), |
| 26 "Skia and font service flags must match"); | 26 "Skia and font service flags must match"); |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 mojo::ScopedHandle GetHandleForPath(const base::FilePath& path) { | 30 mojo::ScopedHandle GetHandleForPath(const base::FilePath& path) { |
| 31 if (path.empty()) | 31 if (path.empty()) |
| 32 return mojo::ScopedHandle(); | 32 return mojo::ScopedHandle(); |
| 33 | 33 |
| 34 mojo::ScopedHandle to_pass; | 34 mojo::ScopedHandle to_pass; |
| 35 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ); | 35 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 SkFontConfigInterface::FontIdentity result_identity; | 79 SkFontConfigInterface::FontIdentity result_identity; |
| 80 SkString result_family; | 80 SkString result_family; |
| 81 SkTypeface::Style result_style; | 81 SkTypeface::Style result_style; |
| 82 SkFontConfigInterface* fc = | 82 SkFontConfigInterface* fc = |
| 83 SkFontConfigInterface::GetSingletonDirectInterface(); | 83 SkFontConfigInterface::GetSingletonDirectInterface(); |
| 84 const bool r = fc->matchFamilyName( | 84 const bool r = fc->matchFamilyName( |
| 85 family_name.data(), static_cast<SkTypeface::Style>(requested_style), | 85 family_name.data(), static_cast<SkTypeface::Style>(requested_style), |
| 86 &result_identity, &result_family, &result_style); | 86 &result_identity, &result_family, &result_style); |
| 87 | 87 |
| 88 if (!r) { | 88 if (!r) { |
| 89 callback.Run(nullptr, "", TYPEFACE_STYLE_NORMAL); | 89 callback.Run(nullptr, "", TypefaceStyle::NORMAL); |
| 90 return; | 90 return; |
| 91 } | 91 } |
| 92 | 92 |
| 93 // Stash away the returned path, so we can give it an ID (index) | 93 // Stash away the returned path, so we can give it an ID (index) |
| 94 // which will later be given to us in a request to open the file. | 94 // which will later be given to us in a request to open the file. |
| 95 int index = FindOrAddPath(result_identity.fString); | 95 int index = FindOrAddPath(result_identity.fString); |
| 96 | 96 |
| 97 FontIdentityPtr identity(FontIdentity::New()); | 97 FontIdentityPtr identity(FontIdentity::New()); |
| 98 identity->id = static_cast<uint32_t>(index); | 98 identity->id = static_cast<uint32_t>(index); |
| 99 identity->ttc_index = result_identity.fTTCIndex; | 99 identity->ttc_index = result_identity.fTTCIndex; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 117 int count = paths_.count(); | 117 int count = paths_.count(); |
| 118 for (int i = 0; i < count; ++i) { | 118 for (int i = 0; i < count; ++i) { |
| 119 if (path == *paths_[i]) | 119 if (path == *paths_[i]) |
| 120 return i; | 120 return i; |
| 121 } | 121 } |
| 122 *paths_.append() = new SkString(path); | 122 *paths_.append() = new SkString(path); |
| 123 return count; | 123 return count; |
| 124 } | 124 } |
| 125 | 125 |
| 126 } // namespace font_service | 126 } // namespace font_service |
| OLD | NEW |