Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -4032,6 +4032,7 @@ ORIGIN: ../../../flutter/third_party/txt/src/txt/platform.h + ../../../flutter/L
ORIGIN: ../../../flutter/third_party/txt/src/txt/platform_android.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/third_party/txt/src/txt/platform_fuchsia.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/third_party/txt/src/txt/platform_linux.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/third_party/txt/src/txt/platform_mac.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/third_party/txt/src/txt/platform_mac.mm + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/third_party/txt/src/txt/platform_windows.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/third_party/web_test_fonts/lib/web_test_fonts.dart + ../../../flutter/LICENSE
Expand Down Expand Up @@ -6819,6 +6820,7 @@ FILE: ../../../flutter/third_party/txt/src/txt/platform.h
FILE: ../../../flutter/third_party/txt/src/txt/platform_android.cc
FILE: ../../../flutter/third_party/txt/src/txt/platform_fuchsia.cc
FILE: ../../../flutter/third_party/txt/src/txt/platform_linux.cc
FILE: ../../../flutter/third_party/txt/src/txt/platform_mac.h
FILE: ../../../flutter/third_party/txt/src/txt/platform_mac.mm
FILE: ../../../flutter/third_party/txt/src/txt/platform_windows.cc
FILE: ../../../flutter/third_party/web_test_fonts/lib/web_test_fonts.dart
Expand Down
6 changes: 6 additions & 0 deletions lib/ui/text/font_collection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#include "third_party/tonic/typed_data/typed_list.h"
#include "txt/asset_font_manager.h"
#include "txt/test_font_manager.h"
#if FML_OS_MACOSX || FML_OS_IOS
#include "txt/platform_mac.h"
#endif

namespace flutter {

Expand Down Expand Up @@ -63,6 +66,9 @@ void FontCollection::SetupDefaultFontManager(
// Structure described in https://docs.flutter.dev/cookbook/design/fonts
void FontCollection::RegisterFonts(
const std::shared_ptr<AssetManager>& asset_manager) {
#if FML_OS_MACOSX || FML_OS_IOS
RegisterSystemFonts(*dynamic_font_manager_);
#endif
std::unique_ptr<fml::Mapping> manifest_mapping =
asset_manager->GetAsMapping("FontManifest.json");
if (manifest_mapping == nullptr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
686383152AC2175100E27AAD /* ../../Flutter.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 246B4E4522E3B61000073EBF /* ../../Flutter.xcframework */; };
686383162AC2175100E27AAD /* ../../Flutter.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 246B4E4522E3B61000073EBF /* ../../Flutter.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
68A5B63423EB71D300BDBCDB /* PlatformViewGestureRecognizerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 68A5B63323EB71D300BDBCDB /* PlatformViewGestureRecognizerTests.m */; };
68C9D8012AD9B0EF00DF9D79 /* DarwinSystemFontTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 68C9D8002AD9B0EF00DF9D79 /* DarwinSystemFontTests.m */; };
68C9D8092AD9B6C800DF9D79 /* golden_darwin_system_font_iPhone SE (3rd generation)_16.2_simulator.png in Resources */ = {isa = PBXBuildFile; fileRef = 68C9D8082AD9B6C800DF9D79 /* golden_darwin_system_font_iPhone SE (3rd generation)_16.2_simulator.png */; };
68D4017D2564859300ECD91A /* ContinuousTexture.m in Sources */ = {isa = PBXBuildFile; fileRef = 68D4017C2564859300ECD91A /* ContinuousTexture.m */; };
68D93AEE2A46097E0054AB6D /* golden_platform_view_with_negative_backdrop_filter_iPhone SE (3rd generation)_16.2_simulator.png in Resources */ = {isa = PBXBuildFile; fileRef = 68D93AED2A46097E0054AB6D /* golden_platform_view_with_negative_backdrop_filter_iPhone SE (3rd generation)_16.2_simulator.png */; };
F26F15B8268B6B5600EC54D3 /* iPadGestureTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F26F15B7268B6B5500EC54D3 /* iPadGestureTests.m */; };
Expand Down Expand Up @@ -242,6 +244,8 @@
686383052AC2024200E27AAD /* FlutterAppExtensionTestHost.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = FlutterAppExtensionTestHost.xcodeproj; path = ../FlutterAppExtensionTestHost/FlutterAppExtensionTestHost.xcodeproj; sourceTree = "<group>"; };
686383122AC202B700E27AAD /* AppExtensionTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppExtensionTests.m; sourceTree = "<group>"; };
68A5B63323EB71D300BDBCDB /* PlatformViewGestureRecognizerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PlatformViewGestureRecognizerTests.m; sourceTree = "<group>"; };
68C9D8002AD9B0EF00DF9D79 /* DarwinSystemFontTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DarwinSystemFontTests.m; sourceTree = "<group>"; };
68C9D8082AD9B6C800DF9D79 /* golden_darwin_system_font_iPhone SE (3rd generation)_16.2_simulator.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "golden_darwin_system_font_iPhone SE (3rd generation)_16.2_simulator.png"; sourceTree = "<group>"; };
68D4017B2564859300ECD91A /* ContinuousTexture.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ContinuousTexture.h; sourceTree = "<group>"; };
68D4017C2564859300ECD91A /* ContinuousTexture.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ContinuousTexture.m; sourceTree = "<group>"; };
68D93AED2A46097E0054AB6D /* golden_platform_view_with_negative_backdrop_filter_iPhone SE (3rd generation)_16.2_simulator.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "golden_platform_view_with_negative_backdrop_filter_iPhone SE (3rd generation)_16.2_simulator.png"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -366,6 +370,7 @@
0DDEBC88258830B40065D0E8 /* SpawnEngineTest.m */,
F26F15B7268B6B5500EC54D3 /* iPadGestureTests.m */,
686383122AC202B700E27AAD /* AppExtensionTests.m */,
68C9D8002AD9B0EF00DF9D79 /* DarwinSystemFontTests.m */,
);
path = ScenariosUITests;
sourceTree = "<group>";
Expand Down Expand Up @@ -401,6 +406,7 @@
F7B464DC2759D02B00079189 /* Goldens */ = {
isa = PBXGroup;
children = (
68C9D8082AD9B6C800DF9D79 /* golden_darwin_system_font_iPhone SE (3rd generation)_16.2_simulator.png */,
3BFD971E2A990CF40094F51B /* golden_bogus_font_text_impeller_iPhone SE (3rd generation)_16.2_simulator.png */,
3BFD971F2A990CF40094F51B /* golden_spawn_engine_works_impeller_iPhone SE (3rd generation)_16.2_simulator.png */,
68D93AED2A46097E0054AB6D /* golden_platform_view_with_negative_backdrop_filter_iPhone SE (3rd generation)_16.2_simulator.png */,
Expand Down Expand Up @@ -617,6 +623,7 @@
684FFF8729F9C10700281002 /* golden_platform_view_multiple_iPhone SE (3rd generation)_16.2_simulator.png in Resources */,
68D93AEE2A46097E0054AB6D /* golden_platform_view_with_negative_backdrop_filter_iPhone SE (3rd generation)_16.2_simulator.png in Resources */,
3BFD97202A990CF50094F51B /* golden_bogus_font_text_impeller_iPhone SE (3rd generation)_16.2_simulator.png in Resources */,
68C9D8092AD9B6C800DF9D79 /* golden_darwin_system_font_iPhone SE (3rd generation)_16.2_simulator.png in Resources */,
684FFF8D29F9C10700281002 /* golden_platform_view_large_cliprrect_iPhone SE (3rd generation)_16.2_simulator.png in Resources */,
684FFF8329F9C10700281002 /* golden_platform_view_transform_iPhone SE (3rd generation)_16.2_simulator.png in Resources */,
684FFF8B29F9C10700281002 /* golden_platform_view_clippath_iPhone SE (3rd generation)_16.2_simulator.png in Resources */,
Expand Down Expand Up @@ -666,6 +673,7 @@
files = (
6402EBD124147BDA00987DCB /* UnobstructedPlatformViewTests.m in Sources */,
68A5B63423EB71D300BDBCDB /* PlatformViewGestureRecognizerTests.m in Sources */,
68C9D8012AD9B0EF00DF9D79 /* DarwinSystemFontTests.m in Sources */,
6816DBA12317573300A51400 /* GoldenImage.m in Sources */,
0A02E8F724EFAD27002D54E5 /* BogusFontTextTest.m in Sources */,
6816DB9E231750ED00A51400 /* GoldenPlatformViewTests.m in Sources */,
Expand Down
1 change: 1 addition & 0 deletions testing/scenario_app/ios/Scenarios/Scenarios/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ - (BOOL)application:(UIApplication*)application
@"--two-platform-view-clip-rect" : @"two_platform_view_clip_rect",
@"--two-platform-view-clip-rrect" : @"two_platform_view_clip_rrect",
@"--two-platform-view-clip-path" : @"two_platform_view_clip_path",
@"--darwin-system-font" : @"darwin_system_font",
};
__block NSString* flutterViewControllerTestName = nil;
[launchArgsMap
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import <Flutter/Flutter.h>
#import <XCTest/XCTest.h>
#import "GoldenTestManager.h"

@interface DarwinSystemFontTests : XCTestCase

@end

@implementation DarwinSystemFontTests

- (void)testFontRendering {
self.continueAfterFailure = NO;

XCUIApplication* application = [[XCUIApplication alloc] init];
application.launchArguments = @[ @"--darwin-system-font" ];
[application launch];

XCUIElement* addTextField = application.textFields[@"ready"];
XCTAssertTrue([addTextField waitForExistenceWithTimeout:30]);

GoldenTestManager* manager =
[[GoldenTestManager alloc] initWithLaunchArg:@"--darwin-system-font"];
[manager checkGoldenForTest:self rmesThreshold:kDefaultRmseThreshold];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ - (instancetype)initWithLaunchArg:(NSString*)launchArg {
@"--two-platform-view-clip-rrect" : @"two_platform_view_clip_rrect",
@"--two-platform-view-clip-path" : @"two_platform_view_clip_path",
@"--app-extension" : @"app_extension",
@"--darwin-system-font" : @"darwin_system_font",
};
});
_identifier = launchArgsMap[launchArg];
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 62 additions & 0 deletions testing/scenario_app/lib/src/darwin_system_font.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:ui';

import 'channel_util.dart';
import 'scenario.dart';

/// Tries to draw darwin system font: CupertinoSystemDisplay, CupertinoSystemText
class DarwinSystemFont extends Scenario {
/// Creates the DarwinSystemFont scenario.
DarwinSystemFont(super.view);

// Semi-arbitrary.
final double _screenWidth = 700;

@override
void onBeginFrame(Duration duration) {
final SceneBuilder builder = SceneBuilder();
final PictureRecorder recorder = PictureRecorder();
final Canvas canvas = Canvas(recorder);

final ParagraphBuilder paragraphBuilderDisplay =
ParagraphBuilder(ParagraphStyle(fontFamily: 'CupertinoSystemDisplay'))
..pushStyle(TextStyle(fontSize: 50))
..addText('Cupertino System Display\n')
..pop();
final ParagraphBuilder paragraphBuilderText =
ParagraphBuilder(ParagraphStyle(fontFamily: 'CupertinoSystemText'))
..pushStyle(TextStyle(fontSize: 50))
..addText('Cupertino System Text\n')
..pop();

final Paragraph paragraphPro = paragraphBuilderDisplay.build();
paragraphPro.layout(ParagraphConstraints(width: _screenWidth));
canvas.drawParagraph(paragraphPro, const Offset(50, 80));

final Paragraph paragraphText = paragraphBuilderText.build();
paragraphText.layout(ParagraphConstraints(width: _screenWidth));
canvas.drawParagraph(paragraphText, const Offset(50, 200));

final Picture picture = recorder.endRecording();

builder.addPicture(
Offset.zero,
picture,
willChangeHint: true,
);
final Scene scene = builder.build();
view.render(scene);
scene.dispose();

sendJsonMessage(
dispatcher: view.platformDispatcher,
channel: 'display_data',
json: <String, dynamic>{
'data': 'ready',
},
);
}
}
2 changes: 2 additions & 0 deletions testing/scenario_app/lib/src/scenarios.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'dart:ui';
import 'animated_color_square.dart';
import 'bogus_font_text.dart';
import 'darwin_app_extension_scenario.dart';
import 'darwin_system_font.dart';
import 'get_bitmap_scenario.dart';
import 'initial_route_reply.dart';
import 'locale_initialization.dart';
Expand Down Expand Up @@ -68,6 +69,7 @@ Map<String, _ScenarioFactory> _scenarios = <String, _ScenarioFactory>{
'display_texture': (FlutterView view) => DisplayTexture(view),
'get_bitmap': (FlutterView view) => GetBitmapScenario(view),
'app_extension': (FlutterView view) => DarwinAppExtensionScenario(view),
'darwin_system_font': (FlutterView view) => DarwinSystemFont(view),
};

Map<String, dynamic> _currentScenarioParams = <String, dynamic>{};
Expand Down
9 changes: 8 additions & 1 deletion third_party/txt/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ source_set("txt") {
}

if (is_mac || is_ios) {
sources += [ "src/txt/platform_mac.mm" ]
sources += [
"src/txt/platform_mac.h",
"src/txt/platform_mac.mm",
]
deps += [ "//flutter/fml" ]
} else if (is_android) {
sources += [ "src/txt/platform_android.cc" ]
Expand Down Expand Up @@ -148,6 +151,10 @@ if (enable_unittests) {
"tests/txt_run_all_unittests.cc",
]

if (is_mac || is_ios) {
sources += [ "tests/platform_mac_tests.cc" ]
}

public_configs = [ ":txt_config" ]

configs += [ ":allow_posix_names" ]
Expand Down
2 changes: 1 addition & 1 deletion third_party/txt/src/txt/asset_font_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class DynamicFontManager : public AssetFontManager {
DynamicFontManager()
: AssetFontManager(std::make_unique<TypefaceFontAssetProvider>()) {}

TypefaceFontAssetProvider& font_provider() {
TypefaceFontAssetProvider& font_provider() const {
return static_cast<TypefaceFontAssetProvider&>(*font_provider_);
}
};
Expand Down
17 changes: 17 additions & 0 deletions third_party/txt/src/txt/platform_mac.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2013 The Flutter 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_MAC_H_
#define TXT_PLATFORM_MAC_H_

#include "txt/asset_font_manager.h"

namespace txt {

// Register additional system font for MacOS and iOS.
void RegisterSystemFonts(const DynamicFontManager& dynamic_font_manager);

} // namespace txt

#endif // TXT_PLATFORM_MAC_H_
41 changes: 41 additions & 0 deletions third_party/txt/src/txt/platform_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include <TargetConditionals.h>

#include "flutter/fml/platform/darwin/platform_version.h"
#include "third_party/skia/include/ports/SkTypeface_mac.h"
#include "txt/platform.h"
#include "txt/platform_mac.h"

#if TARGET_OS_EMBEDDED || TARGET_OS_SIMULATOR
#include <UIKit/UIKit.h>
Expand All @@ -15,6 +17,15 @@
#define FONT_CLASS NSFont
#endif // TARGET_OS_EMBEDDED

// Apple system font larger than size 29 returns SFProDisplay typeface.
static const CGFloat kSFProDisplayBreakPoint = 29;
// Apple system font smaller than size 16 returns SFProText typeface.
static const CGFloat kSFProTextBreakPoint = 16;
// Font name represents the "SF Pro Display" system font on Apple platforms.
static const std::string kSFProDisplayName = "CupertinoSystemDisplay";
// Font name represents the "SF Pro Text" system font on Apple platforms.
static const std::string kSFProTextName = "CupertinoSystemText";

namespace txt {

std::vector<std::string> GetDefaultFontFamilies() {
Expand All @@ -29,4 +40,34 @@
return SkFontMgr::RefDefault();
}

void RegisterSystemFonts(const DynamicFontManager& dynamic_font_manager) {
// iOS loads different system fonts when size is greater than 28 or lower
// than 17. The "familyName" property returned from CoreText stays the same
// despite the typeface is different.
//
// Below code manually loads and registers them as two different fonts
// so Flutter app can access them on macOS and iOS.
//
// Darwin system fonts from 17 to 28 also have dynamic spacing based on sizes.
// These two fonts do not match the spacings when sizes are from 17 to 28.
// The spacing should be handled by the app or the framework.
//
// See https://www.wwdcnotes.com/notes/wwdc20/10175/ for Apple's document on
// this topic.
sk_sp<SkTypeface> large_system_font = SkMakeTypefaceFromCTFont(
(CTFontRef)CFAutorelease(CTFontCreateUIFontForLanguage(
kCTFontUIFontSystem, kSFProDisplayBreakPoint, NULL)));
if (large_system_font) {
dynamic_font_manager.font_provider().RegisterTypeface(large_system_font,
kSFProDisplayName);
}
sk_sp<SkTypeface> regular_system_font = SkMakeTypefaceFromCTFont(
(CTFontRef)CFAutorelease(CTFontCreateUIFontForLanguage(
kCTFontUIFontSystem, kSFProTextBreakPoint, NULL)));
if (regular_system_font) {
dynamic_font_manager.font_provider().RegisterTypeface(regular_system_font,
kSFProTextName);
}
}

} // namespace txt
34 changes: 34 additions & 0 deletions third_party/txt/tests/platform_mac_tests.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2013 The Flutter 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 "gtest/gtest.h"

#include <sstream>

#include "txt/platform_mac.h"

namespace txt {
namespace testing {

class PlatformMacTests : public ::testing::Test {
public:
PlatformMacTests() {}

void SetUp() override {}
};

TEST_F(PlatformMacTests, RegisterSystemFonts) {
DynamicFontManager dynamic_font_manager;
RegisterSystemFonts(dynamic_font_manager);
ASSERT_EQ(dynamic_font_manager.font_provider().GetFamilyCount(), 2ul);
ASSERT_NE(dynamic_font_manager.font_provider().MatchFamily(
"CupertinoSystemDisplay"),
nullptr);
ASSERT_NE(
dynamic_font_manager.font_provider().MatchFamily("CupertinoSystemText"),
nullptr);
}

} // namespace testing
} // namespace txt