我必须使用包含字距调整信息的给定字体计算给定文本的水平宽度。
字形名称和宽度以及他的字距对信息应该可以通过 texts 字符的 unicode 值访问,如下所示:
// GLYPHS[ unicode ] = [ "name", width ];
// KERNS [ unicode ] = { "nextGlyphName" : horizontalAdjustment };
// = { GLYPHS[ unicode ][ 0 ] : horizontalAdjustment };
Run Code Online (Sandbox Code Playgroud)
因此,如果您有如下文件,其中包含这些数据对象,您可以将其复制并粘贴到您的源代码中,或者在运行时打开并导入它们(每个字体的超长文件的第一页):
// Family Name
// 'Times New Roman'
// EM size
// '2048'
// is_quadratic
// '1'
//
// GLYPHS[ unicode ] = [ "name", width ];
// KERNS [ unicode ] = { "nextGlyphName" : horizontalAdjustment };
// = { GLYPHS[ unicode …Run Code Online (Sandbox Code Playgroud)