Browse Source

ComPDFKit(flutter) - ios端定义导入字体接口(未实现)

liuxiaolong 2 months ago
parent
commit
a7cc6c7103
3 changed files with 26 additions and 1 deletions
  1. 17 1
      example/lib/main.dart
  2. 1 0
      example/pubspec.yaml
  3. 8 0
      ios/Classes/CompdfkitFlutterPlugin.swift

+ 17 - 1
example/lib/main.dart

@@ -53,7 +53,23 @@ class _HomePageState extends State<HomePage> {
   }
 
   void _init() async {
-    // await ComPDFKit.setImportFontDir('fonts directory',addSysFont: true);
+    final tempDir = await ComPDFKit.getTemporaryDirectory();
+
+    await extractAsset(context, 'extraFonts/arial.ttf');
+    await extractAsset(context, 'extraFonts/Arial Bold.ttf');
+    await extractAsset(context, 'extraFonts/Arial_Italic.ttf');
+    await extractAsset(context, 'extraFonts/arialmt.ttf');
+    await extractAsset(context, 'extraFonts/ArialUnicode.ttf');
+    await extractAsset(context, 'extraFonts/PlaywriteAUSA-ExtraLight.ttf');
+    await extractAsset(context, 'extraFonts/PlaywriteAUSA-Light.ttf');
+    await extractAsset(context, 'extraFonts/PlaywriteAUSA-Regular.ttf');
+    await extractAsset(context, 'extraFonts/PlaywriteAUSA-Thin.ttf');
+    await extractAsset(context, 'extraFonts/字魂白鸽天行体(商用需授权).ttf');
+    await ComPDFKit.setImportFontDir('${tempDir.path}/extraFonts/',addSysFont: false);
+    print('path:${tempDir.path}/extraFonts/');
+    // online license auth
+    // Please replace it with your ComPDFKit license
+    // ComPDFKit.initialize(androidOnlineLicense: 'IVTAsbJCW0X45qIy5cTEuzxZzKpYIpJe6WPY7uCPIiI=',iosOnlineLicense: 'lkw3Gr0HuD5pV1/+DVRSxp7qBlvK+Izo3mOKyAEHXz4=');
 
     // offline license auth
     ComPDFKit.init(Platform.isAndroid ? androidLicenseKey : iosLicenseKey);

+ 1 - 0
example/pubspec.yaml

@@ -60,6 +60,7 @@ flutter:
   assets:
     - pdfs/
     - images/
+    - extraFonts/
   # To add assets to your application, add an assets section, like this:
   # assets:
   #   - images/a_dot_burr.jpeg

+ 8 - 0
ios/Classes/CompdfkitFlutterPlugin.swift

@@ -101,6 +101,14 @@ public class CompdfkitFlutterPlugin: NSObject, FlutterPlugin, CPDFViewBaseContro
         case "remove_sign_file_list":
             CSignatureManager.sharedManager.removeAllSignatures()
             result(true)
+        case "set_import_font_directory":
+            // TODO: 导入字体
+            let initInfo = call.arguments as? [String: Any]
+            // 字体文件夹路径
+            let dirPath = initInfo?["dir_path"] as? String ?? ""
+            // 是否包含系统字体
+            let addSysFont = initInfo?["add_sys_path"] as? Bool ?? true
+            
         default:
             result(FlutterMethodNotImplemented)
         }