Core Text glyph placement and em values

ⅰ亾dé卋堺 提交于 2019-12-24 19:11:36

问题


I am trying to draw some musical notes using the Bravura font from http://blog.steinberg.net/2013/05/introducing-bravura-music-font/ using core text functions.

A metadata json file accompanying this font has an "attach" coordinate in em unit fractions for where stems should be attached to certain musical notes. This attachment point is relative to a bounding box around the note glyph again with the dimensions in fractions of em unit.

My crude ASCII picture shows the attach point of the stem to the musical note:

      |
      |
      |
 /---\* <- attach point here
|     |
 \---/

From wikipedia: "An em is a unit of width in the field of typography, equal to the currently specified point size. For example, one em in a 16-point typeface is 16 points wide. Therefore, this unit is the same for all typefaces at a given point size."

I would like to use the Core Text function CTFontDrawGlyphs which takes a coordinate in pixels to use for the glyph placement.

I would also like to use the Core Graphics functions CGContextMoveToPoint, CGContextAddLineToPoint to draw the stems that attach to the musical note glyphs.

I'm a bit unclear how to go from a coordinate in em unit fractions to a particular coordinate in pixels for a glyph of a particular point size so that I can accurately place these stems to the musical note glyph.

I hope I have made my question clear.

Thanks for any help


回答1:


In the absence of a text transformation matrix (CGContextSetTextMatrix), 1 em will the be the same number of points as the font size. So for a 12 point font with the default identity text matrix, 1 em = 12 pt.

Note that almost nothing in Core Graphics is given in pixels. They're in points (Core Graphics points, not PostScript points). For a retina display, 1 point contains 4 pixels (2x2). This is probably what you mean anyway, but if you interact with images, the point/pixel conversion is very important.

(I kind of feel like I've repeated what you already know; is there more to the question? From a given origin, you would compute the coordinate by multiplying the em unit offset by the font size.)



来源:https://stackoverflow.com/questions/20545703/core-text-glyph-placement-and-em-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!