Repository navigation
feat(share): integrate native Rust rendering runtime #679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| Gen Shin Gothic Bold | ||
| [Source Han Sans] | ||
| Copyright © 2014, 2015 Adobe Systems Incorporated (http://www.adobe.com/), | ||
| with Reserved Font Name 'Source'. | ||
| [M+ OUTLINE FONTS] | ||
| Copyright(c) 2015 M+ FONTS PROJECT | ||
|
|
||
| Noto Sans TC Black | ||
| (c) 2014-2021 Adobe (http://www.adobe.com/), with Reserved Font Name 'Source'. | ||
|
|
||
| SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 | ||
| ----------------------------------------------------------- | ||
|
|
||
| PREAMBLE | ||
| The goals of the Open Font License (OFL) are to stimulate worldwide | ||
| development of collaborative font projects, to support the font creation | ||
| efforts of academic and linguistic communities, and to provide a free and | ||
| open framework in which fonts may be shared and improved in partnership | ||
| with others. | ||
|
|
||
| The OFL allows the licensed fonts to be used, studied, modified and | ||
| redistributed freely as long as they are not sold by themselves. The | ||
| fonts, including any derivative works, can be bundled, embedded, | ||
| redistributed and/or sold with any software provided that any reserved | ||
| names are not used by derivative works. The fonts and derivatives, | ||
| however, cannot be released under any other type of license. The | ||
| requirement for fonts to remain under this license does not apply | ||
| to any document created using the fonts or their derivatives. | ||
|
|
||
| DEFINITIONS | ||
| "Font Software" refers to the set of files released by the Copyright | ||
| Holder(s) under this license and clearly marked as such. This may | ||
| include source files, build scripts and documentation. | ||
|
|
||
| "Reserved Font Name" refers to any names specified as such after the | ||
| copyright statement(s). | ||
|
|
||
| "Original Version" refers to the collection of Font Software components as | ||
| distributed by the Copyright Holder(s). | ||
|
|
||
| "Modified Version" refers to any derivative made by adding to, deleting, | ||
| or substituting -- in part or in whole -- any of the components of the | ||
| Original Version, by changing formats or by porting the Font Software to a | ||
| new environment. | ||
|
|
||
| "Author" refers to any designer, engineer, programmer, technical | ||
| writer or other person who contributed to the Font Software. | ||
|
|
||
| PERMISSION & CONDITIONS | ||
| Permission is hereby granted, free of charge, to any person obtaining | ||
| a copy of the Font Software, to use, study, copy, merge, embed, modify, | ||
| redistribute, and sell modified and unmodified copies of the Font | ||
| Software, subject to the following conditions: | ||
|
|
||
| 1) Neither the Font Software nor any of its individual components, | ||
| in Original or Modified Versions, may be sold by itself. | ||
|
|
||
| 2) Original or Modified Versions of the Font Software may be bundled, | ||
| redistributed and/or sold with any software, provided that each copy | ||
| contains the above copyright notice and this license. These can be | ||
| included either as stand-alone text files, human-readable headers or | ||
| in the appropriate machine-readable metadata fields within text or | ||
| binary files as long as those fields can be easily viewed by the user. | ||
|
|
||
| 3) No Modified Version of the Font Software may use the Reserved Font | ||
| Name(s) unless explicit written permission is granted by the corresponding | ||
| Copyright Holder. This restriction only applies to the primary font name as | ||
| presented to the users. | ||
|
|
||
| 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font | ||
| Software shall not be used to promote, endorse or advertise any | ||
| Modified Version, except to acknowledge the contribution(s) of the | ||
| Copyright Holder(s) and the Author(s) or with their explicit written | ||
| permission. | ||
|
|
||
| 5) The Font Software, modified or unmodified, in part or in whole, | ||
| must be distributed entirely under this license, and must not be | ||
| distributed under any other license. The requirement for fonts to | ||
| remain under this license does not apply to any document created | ||
| using the Font Software. | ||
|
|
||
| TERMINATION | ||
| This license becomes null and void if any of the above conditions are | ||
| not met. | ||
|
|
||
| DISCLAIMER | ||
| THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF | ||
| MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT | ||
| OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE | ||
| COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
| INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL | ||
| DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM | ||
| OTHER DEALINGS IN THE FONT SOFTWARE. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Report-image fonts | ||
|
|
||
| `tool/dev/build_report_picture.sh` stages the fonts below from the pinned | ||
| eq-report-pic source. They are loaded from Flutter assets in fallback order | ||
| so the app carries one copy across all architectures. | ||
|
|
||
| | File | Family | Licence | | ||
| |---|---|---| | ||
| | `mplus-2p-bold.ttf` | M+ 2p Bold, Copyright (c) 2019 M+ FONTS PROJECT | Free software, unlimited permission to use, copy and distribute, with or without modification | | ||
| | `GenShinGothic-Bold.ttf` | Gen Shin Gothic Bold, based on Source Han Sans, Copyright © 2014, 2015 Adobe Systems Incorporated | SIL Open Font License 1.1 | | ||
| | `NotoSansTC-Black.ttf` | Noto Sans TC Black, Copyright (c) 2014–2021 Adobe | SIL Open Font License 1.1 | | ||
|
|
||
| The original notices remain in the TTF name tables. See `OFL.txt` for the | ||
| full text that accompanies the Gen Shin Gothic and Noto Sans TC fonts. | ||
|
|
||
| ### M+ 2p Bold | ||
|
|
||
| > Copyright(c) 2019 M+ FONTS PROJECT | ||
| > | ||
| > This font is free software. Unlimited permission is granted to use, copy, | ||
| > and distribute it, with or without modification, either commercially or | ||
| > noncommercially. THIS FONT IS PROVIDED "AS IS" WITHOUT WARRANTY. | ||
|
|
||
| The build also stages `third-party-notices.txt` for the Rust crates and | ||
| `rust-library-copyright.html` for the Rust standard library. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| #include "Generated.xcconfig" | ||
| #include? "../../native/eq_report_pic/ios/link.xcconfig" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| #include "Generated.xcconfig" | ||
| #include? "../../native/eq_report_pic/ios/link.xcconfig" |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,85 @@ | ||||||||||||||
| import 'dart:ffi'; | ||||||||||||||
| import 'dart:io'; | ||||||||||||||
|
|
||||||||||||||
| import 'package:dpip/core/error/failure.dart'; | ||||||||||||||
| import 'package:dpip/core/error/result.dart'; | ||||||||||||||
| import 'package:dpip/core/logging/log.dart'; | ||||||||||||||
|
|
||||||||||||||
| /// A platform whose packaging rules decide how a native library is opened. | ||||||||||||||
| enum NativeLibraryHost { android, ios, macos, windows, linux, fuchsia } | ||||||||||||||
|
|
||||||||||||||
| /// The file [name] is packaged as on [host], or null when there is no file. | ||||||||||||||
| /// | ||||||||||||||
| /// Null is the iOS case: the library is linked into the app as a static | ||||||||||||||
| /// library, so its symbols live in the process and are opened with | ||||||||||||||
| /// `DynamicLibrary.process`. Every other target ships a file the build copies | ||||||||||||||
| /// next to the app. | ||||||||||||||
| String? nativeLibraryFileName(String name, NativeLibraryHost host) => | ||||||||||||||
| switch (host) { | ||||||||||||||
| NativeLibraryHost.ios => null, | ||||||||||||||
| NativeLibraryHost.android || | ||||||||||||||
| NativeLibraryHost.linux || | ||||||||||||||
| NativeLibraryHost.fuchsia => 'lib$name.so', | ||||||||||||||
| NativeLibraryHost.macos => 'lib$name.dylib', | ||||||||||||||
| NativeLibraryHost.windows => '$name.dll', | ||||||||||||||
| }; | ||||||||||||||
|
Comment on lines
+17
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||
|
|
||||||||||||||
| /// Opens the native libraries this app ships over FFI. | ||||||||||||||
| /// | ||||||||||||||
| /// The app's C ABI lives in a separate repository (`ExpTechTW/eq-report-pic`) | ||||||||||||||
| /// and is compiled per platform rather than built by Flutter. That makes | ||||||||||||||
| /// "the library is missing" a normal state — a build that has not run the | ||||||||||||||
| /// native step, or an ABI the store stripped — so opening one is a [Result], | ||||||||||||||
| /// never a throw. A screen that cannot draw its share image still alerts | ||||||||||||||
| /// people about an earthquake. | ||||||||||||||
| /// | ||||||||||||||
| /// [openFile] and [openProcess] exist for tests, which run on a host that has | ||||||||||||||
| /// no native artifact; production callers omit them. | ||||||||||||||
| abstract final class NativeLibrary { | ||||||||||||||
| /// Opens [name] for this device. | ||||||||||||||
| /// | ||||||||||||||
| /// [host] overrides the detected platform for tests. On iOS the symbols are | ||||||||||||||
| /// already in the process, so [openProcess] is used and [openFile] is not | ||||||||||||||
| /// called; elsewhere [openFile] receives the packaged file name. | ||||||||||||||
| static Result<DynamicLibrary> open( | ||||||||||||||
| String name, { | ||||||||||||||
| NativeLibraryHost? host, | ||||||||||||||
| DynamicLibrary Function(String fileName)? openFile, | ||||||||||||||
| DynamicLibrary Function()? openProcess, | ||||||||||||||
| }) { | ||||||||||||||
| final resolvedHost = host ?? _host(); | ||||||||||||||
| if (resolvedHost == null) { | ||||||||||||||
| return Err( | ||||||||||||||
| UnexpectedFailure('FFI is not wired for ${Platform.operatingSystem}'), | ||||||||||||||
| ); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| final fileName = nativeLibraryFileName(name, resolvedHost); | ||||||||||||||
| try { | ||||||||||||||
| final library = fileName == null | ||||||||||||||
| ? (openProcess ?? DynamicLibrary.process)() | ||||||||||||||
| : (openFile ?? DynamicLibrary.open)(fileName); | ||||||||||||||
|
Comment on lines
+59
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Suggested change
|
||||||||||||||
| Log.debug('ffi: opened $name from ${fileName ?? 'the process'}'); | ||||||||||||||
| return Ok(library); | ||||||||||||||
| } catch (error) { | ||||||||||||||
| // The OS message names the file and the reason ("image not found", | ||||||||||||||
| // "cannot open shared object file"); keep it, it is the only clue a | ||||||||||||||
| // build step is missing. | ||||||||||||||
| Log.warning('ffi: $name unavailable on ${resolvedHost.name}: $error'); | ||||||||||||||
| return Err( | ||||||||||||||
| UnexpectedFailure('Native library "$name" is not available: $error'), | ||||||||||||||
| ); | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /// This device's host, or null when FFI has no mapping for it. | ||||||||||||||
| static NativeLibraryHost? _host() => switch (Platform.operatingSystem) { | ||||||||||||||
| 'android' => NativeLibraryHost.android, | ||||||||||||||
| 'ios' => NativeLibraryHost.ios, | ||||||||||||||
| 'macos' => NativeLibraryHost.macos, | ||||||||||||||
| 'windows' => NativeLibraryHost.windows, | ||||||||||||||
| 'linux' => NativeLibraryHost.linux, | ||||||||||||||
| 'fuchsia' => NativeLibraryHost.fuchsia, | ||||||||||||||
| _ => null, | ||||||||||||||
| }; | ||||||||||||||
| } | ||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ReportPictureFailure的設計與NativeLibrary.open回傳的錯誤類型存在斷層。NativeLibrary.open目前僅回傳通用的UnexpectedFailure,這使得業務層在捕獲錯誤時,難以精確地將其轉換為ReportPictureFailureReason(例如辨別是unavailable還是其他原因),建議在錯誤處理流程中加入更明確的錯誤分類機制。