font js
1.0.0
브라우저에서 지금 Glyph 뷰어를 사용해보십시오!
글꼴 파일에서 글리프 및 메타 데이터를 추출하기위한 유틸리티 및 CLI.
현재 TrueType 또는 OpenType Fonts 또는 Font Collection을로드하고 메타 데이터 및 Glyph 기하학을 추출 할 수 있습니다.
명령 줄 인터페이스를 사용하면 흑백, 흰색, 그레이 스케일 및 서명 된 거리 필드 PNG 렌더링 및 JSON 메타 데이터를 추출 할 수 있습니다.
사용 가능한 모든 옵션을 확인하기 위해 인수없이 명령 줄 인터페이스를 실행하십시오.
npx : npx @hlorenzi/font 통해 실행하십시오
: npm install @hlorenzi/font 와 함께 설치하십시오
# Extracts all glyphs from "arial.ttf" into PNG and JSON files.
npx @hlorenzi/font arial.ttf -o " output/unicode_[unicode] "
# Set glyph range.
npx @hlorenzi/font arial.ttf -o " output/unicode_[unicode] " --glyphs= " u+30..u+39 "
# Set output mode.
npx @hlorenzi/font arial.ttf -o " output/unicode_[unicode] " --img-mode= " png-sdf " import { FontCollection , GlyphRenderer } from "@hlorenzi/font"
import fs from "fs"
// Load font file.
const fontBuffer = fs . readFileSync ( "arial.ttf" )
// Load font collection and get first font.
const fontCollection = FontCollection . fromBytes ( fontBuffer )
const font = fontCollection . fonts [ 0 ]
// Find glyph for Unicode character "a" and get its geometry,
// simplifying each bézier curve into 100 line segments.
const glyphIndex = font . getGlyphIndexForUnicode ( "a" . charCodeAt ( 0 ) )
const glyphGeometry = font . getGlyphGeometry ( glyphIndex , 100 )
// Render into a black-and-white buffer with scale factor 1 EM = 30 pixels,
// then crop empty borders and print to the console.
const glyphImage = GlyphRenderer . render ( glyphGeometry , 30 ) . cropped ( )
console . log ( glyphImage . printToString ( ) )