Add per platform default font family detection. (flutter/engine#4053)
This commit is contained in:
9
engine/src/flutter/third_party/txt/BUILD.gn
vendored
9
engine/src/flutter/third_party/txt/BUILD.gn
vendored
@@ -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 = [
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
13
engine/src/flutter/third_party/txt/src/txt/platform.cc
vendored
Normal file
13
engine/src/flutter/third_party/txt/src/txt/platform.cc
vendored
Normal 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
|
||||
17
engine/src/flutter/third_party/txt/src/txt/platform.h
vendored
Normal file
17
engine/src/flutter/third_party/txt/src/txt/platform.h
vendored
Normal 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_
|
||||
22
engine/src/flutter/third_party/txt/src/txt/platform_mac.mm
vendored
Normal file
22
engine/src/flutter/third_party/txt/src/txt/platform_mac.mm
vendored
Normal 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
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user