- UID
- 2
- 积分
- 8682
- 帖子
- 2905
- 主题
- 199
- 论坛币
- 11740
- 威望
- 16
- EP值
- 2349
- MP值
- 15
- 阅读权限
- 200
- 注册时间
- 2011-8-3
- 在线时间
- 2597 小时
- 最后登录
- 2024-8-28
|
Alex 发表于 2013-11-12 18:28
milky!
How can I use width & height to get metrics of text?
if you have a PIX object, there is a quick way to get width and height- width = PIX[1][0]
- height = PIX[1][1]
复制代码 if you want to get the pre-calculated metrics of texts, use- # tm info (horizontal)
- val_Ascender = 33 # 字体上行高度
- val_Descender = 34 # 字体下行高度 通常为负数
- val_TextWidth = 35 # 第i句卡拉OK歌词的j个字符的宽度
- val_TextHeight = 36 # 第i句卡拉OK歌词的j个字符的高度
- val_TextKerning = 37 # 第i句卡拉OK歌词的j个字符与之前一个字符的kerning 一句歌词第一个字符的kerning为0
- val_TextAdvance = 38 # 第i句卡拉OK歌词的j个字符的水平步距
- val_TextAdvanceDiff = 39 # 从初始位置到第i句卡拉OK歌词的j个字符的水平步距
- val_TextLength = 40 # 第i句卡拉OK歌词的文字总长度
- val_TextInitX = 41 # 第i句卡拉OK歌词的j个字符的左上角X轴坐标
- val_TextInitY = 42 # 第i句卡拉OK歌词的j个字符的左上角Y轴坐标
- val_TextBearingY = 43 # 第i句卡拉OK歌词的j个字符的Y轴bearing
复制代码 e.g.width of the text in the i(th) line j(th) \k tag,- width = GetVal(val_TextWidth)[i][j]
复制代码 the last but least common way is to use
## Initialize a font and retrieves the metrics of the specified text from the font.
# @param font_file a string, filename of the target font file
# @param face_id an integer, font face id, should always be 1 in TTF files
# @param font_size an integer, font size, in em height
# @param spacing an integer, spacing between texts, can be negative
# @param space_scale a float, scale of white spaces
# @param text a string, the text that is going to be measured
# @return (0 width, 1 height, 2 horiBearingX, 3 horiBearingY, 4 horiAdvance, 5 vertBearingX, 6 vertBearingY, 7 vertAdvance, 8 x_ppem, 9 y_ppem, 10 x_scale, 11 y_scale, 12 ascender, 13 descender, 14 px_height, 15 max_advance)
def TextMetrics(font_file, face_id, font_size, spacing, space_scale, text):
## Retrieve the metrics of the specified text from a font.
# @param font a handler, the handler to the font
# @param text a string, the text that is going to generate a PIX
# @return (0 width, 1 height, 2 horiBearingX, 3 horiBearingY, 4 horiAdvance, 5 vertBearingX, 6 vertBearingY, 7 vertAdvance, 8 x_ppem, 9 y_ppem, 10 x_scale, 11 y_scale, 12 ascender, 13 descender, 14 px_height, 15 max_advance)
def TextMetrics(font, text):
APIs from tcaxLib module can be found on http://www.tcax.org/docs/tcaxLib/namespacemembers_func.html
mofe info about PIX, and TCAS FX, http://www.tcax.org/forum.php?mod=viewthread&tid=220, if I not showed you this link before |
|