Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(628)

Side by Side Diff: components/font_service/font_service_app.cc

Issue 1877673002: Move legacyCreateTypeface to SkFontStyle. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove DEPS change now that Skia change has landed. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/platform_handle/platform_handle_functions.h" 11 #include "mojo/platform_handle/platform_handle_functions.h"
12 #include "mojo/shell/public/cpp/connection.h" 12 #include "mojo/shell/public/cpp/connection.h"
13 13
14 static_assert(static_cast<uint32_t>(SkTypeface::kNormal) == 14 static_assert(static_cast<uint32_t>(SkFontStyle::kUpright_Slant) ==
15 static_cast<uint32_t>(font_service::TypefaceStyle::NORMAL), 15 static_cast<uint32_t>(font_service::TypefaceSlant::ROMAN),
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>(SkFontStyle::kItalic_Slant) ==
18 static_cast<uint32_t>(font_service::TypefaceStyle::BOLD), 18 static_cast<uint32_t>(font_service::TypefaceSlant::ITALIC),
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) ==
21 static_cast<uint32_t>(font_service::TypefaceStyle::ITALIC),
22 "Skia and font service flags must match");
23 static_assert(
24 static_cast<uint32_t>(SkTypeface::kBoldItalic) ==
25 static_cast<uint32_t>(font_service::TypefaceStyle::BOLD_ITALIC),
26 "Skia and font service flags must match");
27 20
28 namespace { 21 namespace {
29 22
30 mojo::ScopedHandle GetHandleForPath(const base::FilePath& path) { 23 mojo::ScopedHandle GetHandleForPath(const base::FilePath& path) {
31 if (path.empty()) 24 if (path.empty())
32 return mojo::ScopedHandle(); 25 return mojo::ScopedHandle();
33 26
34 mojo::ScopedHandle to_pass; 27 mojo::ScopedHandle to_pass;
35 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ); 28 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ);
36 if (!file.IsValid()) { 29 if (!file.IsValid()) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 connection->AddInterface(this); 61 connection->AddInterface(this);
69 return true; 62 return true;
70 } 63 }
71 64
72 void FontServiceApp::Create(mojo::Connection* connection, 65 void FontServiceApp::Create(mojo::Connection* connection,
73 mojo::InterfaceRequest<FontService> request) { 66 mojo::InterfaceRequest<FontService> request) {
74 bindings_.AddBinding(this, std::move(request)); 67 bindings_.AddBinding(this, std::move(request));
75 } 68 }
76 69
77 void FontServiceApp::MatchFamilyName(const mojo::String& family_name, 70 void FontServiceApp::MatchFamilyName(const mojo::String& family_name,
78 TypefaceStyle requested_style, 71 TypefaceStylePtr requested_style,
79 const MatchFamilyNameCallback& callback) { 72 const MatchFamilyNameCallback& callback) {
80 SkFontConfigInterface::FontIdentity result_identity; 73 SkFontConfigInterface::FontIdentity result_identity;
81 SkString result_family; 74 SkString result_family;
82 SkTypeface::Style result_style; 75 SkFontStyle result_style;
83 SkFontConfigInterface* fc = 76 SkFontConfigInterface* fc =
84 SkFontConfigInterface::GetSingletonDirectInterface(); 77 SkFontConfigInterface::GetSingletonDirectInterface();
85 const bool r = fc->matchFamilyName( 78 const bool r = fc->matchFamilyName(
86 family_name.data(), static_cast<SkTypeface::Style>(requested_style), 79 family_name.data(),
80 SkFontStyle(requested_style->weight,
81 requested_style->width,
82 static_cast<SkFontStyle::Slant>(requested_style->slant)),
87 &result_identity, &result_family, &result_style); 83 &result_identity, &result_family, &result_style);
88 84
89 if (!r) { 85 if (!r) {
90 callback.Run(nullptr, "", TypefaceStyle::NORMAL); 86 TypefaceStylePtr style(TypefaceStyle::New());
87 style->weight = SkFontStyle().weight();
88 style->width = SkFontStyle().width();
89 style->slant = static_cast<TypefaceSlant>(SkFontStyle().slant());
90 callback.Run(nullptr, "", std::move(style));
91 return; 91 return;
92 } 92 }
93 93
94 // Stash away the returned path, so we can give it an ID (index) 94 // Stash away the returned path, so we can give it an ID (index)
95 // which will later be given to us in a request to open the file. 95 // which will later be given to us in a request to open the file.
96 int index = FindOrAddPath(result_identity.fString); 96 int index = FindOrAddPath(result_identity.fString);
97 97
98 FontIdentityPtr identity(FontIdentity::New()); 98 FontIdentityPtr identity(FontIdentity::New());
99 identity->id = static_cast<uint32_t>(index); 99 identity->id = static_cast<uint32_t>(index);
100 identity->ttc_index = result_identity.fTTCIndex; 100 identity->ttc_index = result_identity.fTTCIndex;
101 identity->str_representation = result_identity.fString.c_str(); 101 identity->str_representation = result_identity.fString.c_str();
102 102
103 callback.Run(std::move(identity), result_family.c_str(), 103 TypefaceStylePtr style(TypefaceStyle::New());
104 static_cast<TypefaceStyle>(result_style)); 104 style->weight = result_style.weight();
105 style->width = result_style.width();
106 style->slant = static_cast<TypefaceSlant>(result_style.slant());
107
108 callback.Run(std::move(identity), result_family.c_str(), std::move(style));
105 } 109 }
106 110
107 void FontServiceApp::OpenStream(uint32_t id_number, 111 void FontServiceApp::OpenStream(uint32_t id_number,
108 const OpenStreamCallback& callback) { 112 const OpenStreamCallback& callback) {
109 mojo::ScopedHandle handle; 113 mojo::ScopedHandle handle;
110 if (id_number < static_cast<uint32_t>(paths_.size())) { 114 if (id_number < static_cast<uint32_t>(paths_.size())) {
111 handle = GetHandleForPath(base::FilePath(paths_[id_number].c_str())); 115 handle = GetHandleForPath(base::FilePath(paths_[id_number].c_str()));
112 } 116 }
113 117
114 callback.Run(std::move(handle)); 118 callback.Run(std::move(handle));
115 } 119 }
116 120
117 int FontServiceApp::FindOrAddPath(const SkString& path) { 121 int FontServiceApp::FindOrAddPath(const SkString& path) {
118 int count = paths_.size(); 122 int count = paths_.size();
119 for (int i = 0; i < count; ++i) { 123 for (int i = 0; i < count; ++i) {
120 if (path == paths_[i]) 124 if (path == paths_[i])
121 return i; 125 return i;
122 } 126 }
123 paths_.emplace_back(path); 127 paths_.emplace_back(path);
124 return count; 128 return count;
125 } 129 }
126 130
127 } // namespace font_service 131 } // namespace font_service
OLDNEW
« no previous file with comments | « components/font_service/font_service_app.h ('k') | components/font_service/public/cpp/font_loader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698