Add per platform default font family detection. (flutter/engine#4053)

This commit is contained in:
Chinmay Garde
2017-09-01 14:10:15 -07:00
committed by GitHub
parent 814847ec3c
commit 2f758c5e95
7 changed files with 65 additions and 8 deletions

View File

@@ -86,6 +86,7 @@ source_set("txt") {
"src/txt/paragraph_builder.h",
"src/txt/paragraph_style.cc",
"src/txt/paragraph_style.h",
"src/txt/platform.h",
"src/txt/styled_runs.cc",
"src/txt/styled_runs.h",
"src/txt/text_align.h",
@@ -100,6 +101,14 @@ source_set("txt") {
"src/utils/TypeHelpers.h",
]
if (is_mac || is_ios) {
set_sources_assignment_filter([])
sources += [ "src/txt/platform_mac.mm" ]
set_sources_assignment_filter(sources_assignment_filter)
} else {
sources += [ "src/txt/platform.cc" ]
}
public_configs = [ ":txt_config" ]
public_deps = [

View File

@@ -25,6 +25,7 @@
#include <vector>
#include "font_skia.h"
#include "lib/ftl/logging.h"
#include "txt/platform.h"
#include "txt/text_style.h"
namespace txt {
@@ -107,7 +108,7 @@ FontCollection::GetMinikinFontCollectionForFamily(const std::string& family) {
return font_collection;
}
const auto default_font_family = TextStyle::GetDefaultFontFamily();
const auto default_font_family = GetDefaultFontFamily();
if (family != default_font_family) {
return GetMinikinFontCollectionForFamily(default_font_family);
}

View File

@@ -0,0 +1,13 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "txt/platform.h"
namespace txt {
std::string GetDefaultFontFamily() {
return "Roboto";
}
} // namespace txt

View File

@@ -0,0 +1,17 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef TXT_PLATFORM_H_
#define TXT_PLATFORM_H_
#include <string>
#include "lib/ftl/macros.h"
namespace txt {
std::string GetDefaultFontFamily();
} // namespace txt
#endif // TXT_PLATFORM_H_

View File

@@ -0,0 +1,22 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <TargetConditionals.h>
#include "txt/platform.h"
#if TARGET_OS_EMBEDDED
#include <UIKit/UIKit.h>
#define FONT_CLASS UIFont
#else // TARGET_OS_EMBEDDED
#include <AppKit/AppKit.h>
#define FONT_CLASS NSFont
#endif // TARGET_OS_EMBEDDED
namespace txt {
std::string GetDefaultFontFamily() {
return [FONT_CLASS systemFontOfSize:14].familyName.UTF8String;
}
} // namespace txt

View File

@@ -14,17 +14,14 @@
* limitations under the License.
*/
#include "text_style.h"
#include "font_style.h"
#include "font_weight.h"
#include "text_style.h"
#include "third_party/skia/include/core/SkColor.h"
#include "txt/platform.h"
namespace txt {
std::string TextStyle::GetDefaultFontFamily() {
return "Roboto";
}
TextStyle::TextStyle() : font_family(GetDefaultFontFamily()) {}
bool TextStyle::equals(const TextStyle& other) const {

View File

@@ -46,8 +46,6 @@ class TextStyle {
double word_spacing = 0.0;
double height = 1.0;
static std::string GetDefaultFontFamily();
TextStyle();
bool equals(const TextStyle& other) const;