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

Side by Side Diff: ui/gfx/platform_font_linux.cc

Issue 1870873003: Remove screen dependency from font_render_params_linux (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/gfx/platform_font_linux.h" 5 #include "ui/gfx/platform_font_linux.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 SkString family_name; 189 SkString family_name;
190 typeface_->getFamilyName(&family_name); 190 typeface_->getFamilyName(&family_name);
191 return family_name.c_str(); 191 return family_name.c_str();
192 } 192 }
193 193
194 int PlatformFontLinux::GetFontSize() const { 194 int PlatformFontLinux::GetFontSize() const {
195 return font_size_pixels_; 195 return font_size_pixels_;
196 } 196 }
197 197
198 const FontRenderParams& PlatformFontLinux::GetFontRenderParams() { 198 const FontRenderParams& PlatformFontLinux::GetFontRenderParams() {
199 #if defined(OS_CHROMEOS)
200 float current_scale_factor = GetFontRenderParamsDeviceScaleFactor(); 199 float current_scale_factor = GetFontRenderParamsDeviceScaleFactor();
201 if (current_scale_factor != device_scale_factor_) { 200 if (current_scale_factor != device_scale_factor_) {
202 FontRenderParamsQuery query; 201 FontRenderParamsQuery query;
203 query.families.push_back(font_family_); 202 query.families.push_back(font_family_);
204 query.pixel_size = font_size_pixels_; 203 query.pixel_size = font_size_pixels_;
205 query.style = style_; 204 query.style = style_;
206 query.device_scale_factor = current_scale_factor; 205 query.device_scale_factor = current_scale_factor;
207 font_render_params_ = gfx::GetFontRenderParams(query, nullptr); 206 font_render_params_ = gfx::GetFontRenderParams(query, nullptr);
208 device_scale_factor_ = current_scale_factor; 207 device_scale_factor_ = current_scale_factor;
209 } 208 }
210 #endif
211 return font_render_params_; 209 return font_render_params_;
212 } 210 }
213 211
214 //////////////////////////////////////////////////////////////////////////////// 212 ////////////////////////////////////////////////////////////////////////////////
215 // PlatformFontLinux, private: 213 // PlatformFontLinux, private:
216 214
217 PlatformFontLinux::PlatformFontLinux(const skia::RefPtr<SkTypeface>& typeface, 215 PlatformFontLinux::PlatformFontLinux(const skia::RefPtr<SkTypeface>& typeface,
218 const std::string& family, 216 const std::string& family,
219 int size_pixels, 217 int size_pixels,
220 int style, 218 int style,
221 const FontRenderParams& render_params) { 219 const FontRenderParams& render_params) {
222 InitFromDetails(typeface, family, size_pixels, style, render_params); 220 InitFromDetails(typeface, family, size_pixels, style, render_params);
223 } 221 }
224 222
225 PlatformFontLinux::~PlatformFontLinux() {} 223 PlatformFontLinux::~PlatformFontLinux() {}
226 224
227 void PlatformFontLinux::InitFromDetails( 225 void PlatformFontLinux::InitFromDetails(
228 const skia::RefPtr<SkTypeface>& typeface, 226 const skia::RefPtr<SkTypeface>& typeface,
229 const std::string& font_family, 227 const std::string& font_family,
230 int font_size_pixels, 228 int font_size_pixels,
231 int style, 229 int style,
232 const FontRenderParams& render_params) { 230 const FontRenderParams& render_params) {
233 DCHECK_GT(font_size_pixels, 0); 231 DCHECK_GT(font_size_pixels, 0);
234 232
235 font_family_ = font_family; 233 font_family_ = font_family;
236 typeface_ = typeface ? typeface : CreateSkTypeface(style, &font_family_); 234 typeface_ = typeface ? typeface : CreateSkTypeface(style, &font_family_);
237 235
238 font_size_pixels_ = font_size_pixels; 236 font_size_pixels_ = font_size_pixels;
239 style_ = style; 237 style_ = style;
240 #if defined(OS_CHROMEOS)
241 device_scale_factor_ = GetFontRenderParamsDeviceScaleFactor(); 238 device_scale_factor_ = GetFontRenderParamsDeviceScaleFactor();
242 #endif
243 font_render_params_ = render_params; 239 font_render_params_ = render_params;
244 240
245 } 241 }
246 242
247 void PlatformFontLinux::InitFromPlatformFont(const PlatformFontLinux* other) { 243 void PlatformFontLinux::InitFromPlatformFont(const PlatformFontLinux* other) {
248 typeface_ = other->typeface_; 244 typeface_ = other->typeface_;
249 font_family_ = other->font_family_; 245 font_family_ = other->font_family_;
250 font_size_pixels_ = other->font_size_pixels_; 246 font_size_pixels_ = other->font_size_pixels_;
251 style_ = other->style_; 247 style_ = other->style_;
252 #if defined(OS_CHROMEOS)
253 device_scale_factor_ = other->device_scale_factor_; 248 device_scale_factor_ = other->device_scale_factor_;
254 #endif
255 font_render_params_ = other->font_render_params_; 249 font_render_params_ = other->font_render_params_;
256 250
257 if (!other->metrics_need_computation_) { 251 if (!other->metrics_need_computation_) {
258 metrics_need_computation_ = false; 252 metrics_need_computation_ = false;
259 ascent_pixels_ = other->ascent_pixels_; 253 ascent_pixels_ = other->ascent_pixels_;
260 height_pixels_ = other->height_pixels_; 254 height_pixels_ = other->height_pixels_;
261 cap_height_pixels_ = other->cap_height_pixels_; 255 cap_height_pixels_ = other->cap_height_pixels_;
262 average_width_pixels_ = other->average_width_pixels_; 256 average_width_pixels_ = other->average_width_pixels_;
263 } 257 }
264 } 258 }
(...skipping 27 matching lines...) Expand all
292 return new PlatformFontLinux; 286 return new PlatformFontLinux;
293 } 287 }
294 288
295 // static 289 // static
296 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, 290 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name,
297 int font_size) { 291 int font_size) {
298 return new PlatformFontLinux(font_name, font_size); 292 return new PlatformFontLinux(font_name, font_size);
299 } 293 }
300 294
301 } // namespace gfx 295 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698