font_face_observer
所属分类:多国语言处理
开发工具:Dart
文件大小:0KB
下载次数:0
上传日期:2023-09-02 04:27:21
上 传 者:
sh-1993
说明: 使用基于Promise的API在浏览器中加载和卸载字体。简单、小巧、高效。它将使用FontFace api(如果可用),或者...,
(Load and unload fonts in the browser with a Promise based API. Simple, small and efficient. It will use the FontFace api if available, otherwise it falls back to a Dart port of https://github.com/bramstein/fontfaceobserver)
文件列表:
.travis.yml (327, 2023-09-01)
CHANGELOG.md (1642, 2023-09-01)
Dockerfile (89, 2023-09-01)
LICENSE (3293, 2023-09-01)
NOTICE (3293, 2023-09-01)
analysis_options.yaml (50, 2023-09-01)
aviary.yaml (166, 2023-09-01)
dart_test.yaml (22, 2023-09-01)
example/ (0, 2023-09-01)
example/favicon.ico (15086, 2023-09-01)
example/fonts/ (0, 2023-09-01)
example/fonts/Roboto.ttf (162420, 2023-09-01)
example/fonts/W.ttf (1676, 2023-09-01)
example/fonts/Wdesk_Doctype-Icons.ttf (23208, 2023-09-01)
example/fonts/Wdesk_Icons.ttf (49292, 2023-09-01)
example/fonts/empty.otf (0, 2023-09-01)
example/fonts/subset.ttf (2196, 2023-09-01)
example/index.html (758, 2023-09-01)
example/main.dart (6318, 2023-09-01)
example/unload.dart (6033, 2023-09-01)
example/unload.html (1477, 2023-09-01)
lib/ (0, 2023-09-01)
lib/data_uri.dart (4982, 2023-09-01)
lib/font_face_observer.dart (17523, 2023-09-01)
lib/support.dart (4694, 2023-09-01)
pubspec.yaml (398, 2023-09-01)
skynet.yaml (241, 2023-09-01)
test/ (0, 2023-09-01)
test/data_uri_test.dart (4203, 2023-09-01)
test/font_face_observer_test.dart (13610, 2023-09-01)
# Overview
Font load events, simple, small and efficient.
It wil use the FontFace api if available, otherwise it falls back to a Dart port of https://github.com/bramstein/fontfaceobserver
# Usage Example
```dart
import 'package:font_face_observer/font_face_observer.dart';
import 'package:font_face_observer/data_uri.dart';
FontFaceObserver ffo = new FontFaceObserver('Arial', weight: 'bold');
FontLoadResult result = await ffo.load('/url/to/arial.ttf');
if (result.isLoaded) {
// at this point we're absolutely sure that the font has loaded
}
if (result.didTimeout) {
// We've timed out and are not sure if the font has loaded.
// You can reissue a ffo.check() call to check again if you want
}
// Build a base64 encoded data URI
DataUri di = new DataUri();
..data = DataUri.base64EncodeString('test');
..mimeType = 'text/plain';
..encoding = 'utf-8';
di.toString(); # data:text/plain;charset=utf-8;base64,dGVzdA==
```
# Run the demo
To run the demo, just install dependencies and run `pub serve test`.
Then open http://localhost:8080
```
pub get
pub serve test
```
# Public API
```dart
// Constructing a new FontFaceObserver (with default values)
FontFaceObserver(
String family,
{
String style: 'normal',
String weight: 'normal',
String stretch: 'normal',
String testString: 'BESbswy',
int timeout: 3000,
bool useSimulatedLoadEvents: false
}
);
// Check if the font face is loaded successfully
Future check() async
// Load a font from the given URL by adding a font-face rule
// returns the same Future from check()
Future load(String url) async
// Unload a group of fonts (static call)
Future FontFaceObserver.unloadGroup(String group);
// Unload a specific font by key and group
Future FontFaceObserver.unload(String key, String group);
```
# Notes
Font Face Observer will use the FontFace API
https://developer.mozilla.org/en-US/docs/Web/API/FontFace to detect
when a font has loaded.
近期下载者:
相关文件:
收藏者: