讀寫OpenType字體的JS庫:opentype.js
opentype.js是TrueType 和 OpenType 字體的javascript讀寫器。它可以讓你從瀏覽器或node.js中獲取文字的字母形式。

以下是一個示例。加載一個文字,然后將其展示在一個id="canvas"的畫布上Canvas。
opentype.load('fonts/Roboto-Black.ttf', function (err, font) {
if (err) {
alert('Font could not be loaded: ' + err);
} else {
var ctx = document.getElementById('canvas').getContext('2d');
// Construct a Path object containing the letter shapes of the given text.
// The other parameters are x, y and fontSize.
// Note that y is the position of the baseline.
var path = font.getPath('Hello, World!', 0, 150, 72);
// If you just want to draw the text you can also use font.draw(ctx, text, x, y, fontSize).
path.draw(ctx);
}
} 在線示例請查看: the project website
特性
- Create a bézier path out of a piece of text.
- Support for composite glyphs (accented letters).
- Support for OpenType (glyf) and PostScript (cff) shapes.
- Support for kerning (Using GPOS or the kern table).
- Very efficient.
- Runs in the browser and node.js.
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!