-
Notifications
You must be signed in to change notification settings - Fork 946
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ios, android): support loading font dynamically
- Loading branch information
Showing
32 changed files
with
793 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
driver/js/packages/hippy-react/src/modules/font-loader-module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making | ||
* Hippy available. | ||
* | ||
* Copyright (C) 2017-2019 THL A29 Limited, a Tencent company. | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { Bridge } from '../global'; | ||
|
||
/** | ||
* Load font from remote url. | ||
* | ||
* @param {string} url - Remote font url. | ||
* @param {string} fontFamily - Remote fontFamily name. | ||
*/ | ||
function load(fontFamily: string, url: string) { | ||
return Bridge.callNativeWithPromise('FontLoaderModule', 'load', fontFamily, url); | ||
} | ||
|
||
export { | ||
load, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
driver/js/packages/hippy-vue-next/src/types/native-modules/font-loader-module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making | ||
* Hippy available. | ||
* | ||
* Copyright (C) 2022 THL A29 Limited, a Tencent company. | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
export interface FontLoaderModule { | ||
load: (fontFamily: string, url: string) => undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...roid/src/main/java/com/tencent/mtt/hippy/modules/nativemodules/font/FontLoaderModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* Tencent is pleased to support the open source community by making Hippy available. | ||
* Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.tencent.mtt.hippy.modules.nativemodules.font; | ||
|
||
import com.tencent.mtt.hippy.HippyEngineContext; | ||
import com.tencent.mtt.hippy.annotation.HippyMethod; | ||
import com.tencent.mtt.hippy.annotation.HippyNativeModule; | ||
import com.tencent.mtt.hippy.modules.Promise; | ||
import com.tencent.mtt.hippy.modules.nativemodules.HippyNativeModuleBase; | ||
import com.tencent.renderer.NativeRender; | ||
import com.tencent.renderer.NativeRendererManager; | ||
import com.tencent.renderer.component.text.FontLoader; | ||
|
||
@HippyNativeModule(name = "FontLoaderModule") | ||
public class FontLoaderModule extends HippyNativeModuleBase { | ||
|
||
private final FontLoader mFontLoader; | ||
private final NativeRender mNativeRender; | ||
private final int rootId; | ||
|
||
public FontLoaderModule(HippyEngineContext context) { | ||
super(context); | ||
mFontLoader = new FontLoader(context.getVfsManager()); | ||
mNativeRender = NativeRendererManager.getNativeRenderer(context.getRootView().getContext()); | ||
rootId = context.getRootView().getId(); | ||
} | ||
|
||
@HippyMethod(name = "load") | ||
public void load(final String fontFamily, final String fontUrl, final Promise promise) { | ||
mFontLoader.loadAndFresh(fontFamily, fontUrl, mNativeRender, rootId, promise); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/*! | ||
* iOS SDK | ||
* | ||
* Tencent is pleased to support the open source community by making | ||
* Hippy available. | ||
* | ||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "HippyBridgeModule.h" | ||
|
||
static NSString *const HippyLoadFontNotification = @"HippyLoadFontNotification"; | ||
|
||
@interface HippyFontLoaderModule : NSObject<HippyBridgeModule> | ||
|
||
@property (nonatomic, readonly) NSString *fontDir; | ||
@property (nonatomic, readonly) NSString *fontUrlCachePath; | ||
|
||
- (NSString *)getFontPath:(NSString *)url; | ||
- (BOOL)registerFontFromURL:(NSString *)urlString error:(NSError *)error; | ||
|
||
@end |
Oops, something went wrong.