Skip to content

Commit

Permalink
Add per platform default font family detection. (flutter#4053)
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmaygarde authored Sep 1, 2017
1 parent 6e2d67f commit 8b3e746
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 8 deletions.
9 changes: 9 additions & 0 deletions third_party/txt/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 = [
Expand Down
3 changes: 2 additions & 1 deletion third_party/txt/src/txt/font_collection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down
13 changes: 13 additions & 0 deletions third_party/txt/src/txt/platform.cc
Original file line number Diff line number Diff line change
@@ -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 changes: 17 additions & 0 deletions third_party/txt/src/txt/platform.h
Original file line number Diff line number Diff line change
@@ -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 changes: 22 additions & 0 deletions third_party/txt/src/txt/platform_mac.mm
Original file line number Diff line number Diff line change
@@ -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
7 changes: 2 additions & 5 deletions third_party/txt/src/txt/text_style.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions third_party/txt/src/txt/text_style.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions travis/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,9 @@ FILE: ../../../flutter/third_party/txt/src/txt/asset_font_style_set.cc
FILE: ../../../flutter/third_party/txt/src/txt/asset_font_style_set.h
FILE: ../../../flutter/third_party/txt/src/txt/directory_asset_data_provider.cc
FILE: ../../../flutter/third_party/txt/src/txt/directory_asset_data_provider.h
FILE: ../../../flutter/third_party/txt/src/txt/platform.cc
FILE: ../../../flutter/third_party/txt/src/txt/platform.h
FILE: ../../../flutter/third_party/txt/src/txt/platform_mac.mm
FILE: ../../../flutter/vulkan/vulkan_native_surface_magma.cc
FILE: ../../../flutter/vulkan/vulkan_native_surface_magma.h
----------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 8b3e746

Please sign in to comment.