我有一个项目即将进行,我将在圆上渲染文本路径;文本必须是动态的,所以我不能只从 illustrator 中引入预先计算的集合。
现在,将文本放在圆圈上应该不会太难,我将按每个字符旋转来完成此操作。问题是,我似乎不知道如何从 Flash 的字体引擎获得每个字符的前进。 99% 的可能性是我只是忽略了一些显而易见的事情。但据我所知,获取 Flash 字体指标的唯一方法是通过 flash.text.engine.FontMetrics 表面上是每个字体,而不是每个字符。
有什么想法吗?
我不希望实现的一个后备方案是自行预先计算每个字符(因为该项目将使用预先已知的嵌入字体)。我有 ObjC 代码用于为 opengl 生成字形映射,因此我可以离线生成该数据并使其可用于我的 flash 代码(可能作为静态常量或一些胡言乱语)。
PS 这是我在 StackOverflow 上的第一个问题,如果我问得不好,请告诉我。
I have a project coming up where I'll be rendering text paths on a circle; the text has to be dynamic, so I can't just bring in a precomputed set from illustrator.
Now, laying text on a circle ought not be too hard, I'll do it per character with per character rotation. The trouble is, I can't seem to figure out how to get per-character advance from flash's font engine. It's 99% probable that I'm just overlooking something obvious. But as far as I can tell, the only way to get flash font metrics is via flash.text.engine.FontMetrics which ostensibly is per-font, not per-character.
Any ideas?
A fallback that I'm not looking forward to implementing is pre-computing per-char advance on my own ( since this project will be using embedded fonts known in advance ). I've got ObjC code lying around for generating glyph maps for opengl, so I could generate that data offline and make it available to my flash code ( probably as static constants or some malarkey ).
P.S. This is my first question on StackOverflow, if I've asked the question poorly, please let me know.
发布评论
评论(4)
Docs
并使用
因此,您将创建每个字母都有一个单独的动态文本字段(动态)。放置您的第一个字母(例如在 TextField letter_1 中)并调用:
这将为您提供第一行的 TextLineMetrics 对象(在您的情况下为单个字母)。然后使用 width 属性来确定下一个字母需要多少偏移量。
Docs
and use
So, you would create a separate dynamic TextField (dynamically) for each letter. Place your first letter (say in TextField letter_1) and call:
This will give you the TextLineMetrics object for the first line (in your case a single letter.) Then use the width property to determine how much offset is needed for the next letter.
很久以前我就不得不做类似的事情。因为它是 AS2,所以我使用了 senlingual 的片段。
如果你想要字母一行,使用 textWidth:
我尝试使用 TweenMax 将事物快速而简单地放在路径上。
不是一个很好的。将 TextFields 嵌套在某些精灵中,调整字母在路径上的位置(垂直偏移)会很方便,而且,间距也是一个问题,因为我认为 BezierThrough 使用的是二次贝塞尔曲线。 Hermite 曲线应该更精确。
Jim Armstrong 是数学。他在 Degrafa 上的工作非常出色,如果你不受限制,Degrafa 已经有很多此类功能的功能。
华泰
I had to do something similar a long time ago. Since it was AS2 I used a snippet by senocular.
If you want letters in a line, that should easy enough using textWidth:
I've tried to put things on a path quick and hacky using TweenMax.
Not a very good one. Nesting the TextFields in some sprites, to adjust the position of the letter on the path(vertical offset) would be handy, also, spacing is an issue as the BezierThrough is using Quadratic Beziers I think. Hermite Curves should be more precise.
Jim Armstrong is the man for the Math. His work on Degrafa is amazing, if you're not constrained, Degrafa already had plenty of features for this kind of things.
HTH
您需要 TextLine。 getAtomBounds() 和/或 TextLine.getAtomGraphic()。
You want TextLine.getAtomBounds(), and/or TextLine.getAtomGraphic().
Greensock 的 TextMetrics 在这些情况下可能很有用。描述:TextMetrics – 查找子字符串坐标、线宽等等
Greensock's TextMetrics could be useful in these situations. Description: TextMetrics – Find substring coordinates, line widths, and much more