Flash/AS3 中的字体规格

发布于 2024-08-16 15:07:38 字数 575 浏览 2 评论 0 原文

我有一个项目即将进行,我将在圆上渲染文本路径;文本必须是动态的,所以我不能只从 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

半寸时光 2024-08-23 15:07:38
import flash.text.TextLineMetrics;

Docs

并使用

flash.text.TextField.getLineMetrics();

因此,您将创建每个字母都有一个单独的动态文本字段(动态)。放置您的第一个字母(例如在 TextField letter_1 中)并调用:

var TLM:TextLineMetrics = letter_1.getLineMetrics(0);

这将为您提供第一行的 TextLineMetrics 对象(在您的情况下为单个字母)。然后使用 width 属性来确定下一个字母需要多少偏移量。

import flash.text.TextLineMetrics;

Docs

and use

flash.text.TextField.getLineMetrics();

So, you would create a separate dynamic TextField (dynamically) for each letter. Place your first letter (say in TextField letter_1) and call:

var TLM:TextLineMetrics = letter_1.getLineMetrics(0);

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.

梦情居士 2024-08-23 15:07:38

很久以前我就不得不做类似的事情。因为它是 AS2,所以我使用了 senlingual 的片段。

如果你想要字母一行,使用 textWidth

var theText:String = 'text on a path';
var letters:Array = [];
var lettersNum:int = theText.length;

for(var i:int = 0; i < lettersNum; i++){
    var t:TextField = new TextField();
    t.defaultTextFormat = new TextFormat('Verdana',12,0x000000);
    t.embedFonts = true;
    t.text = theText.charAt(i);
    t.selectable = false;
    letters.push(t);

    addChild(t);
    if(i > 0) t.x = letters[i-1].x + letters[i-1].textWidth;
}

我尝试使用 TweenMax 将事物快速而简单地放在路径上。

import com.greensock.*; 
import com.greensock.easing.*;
import com.greensock.plugins.*;

TweenPlugin.activate([BezierThroughPlugin, BezierPlugin]);

var theText:String = 'text on a path';
var letters:Array = [];
var lettersNum:int = theText.length;

for(var i:int = 0; i < lettersNum; i++){
    var t:TextField = new TextField();
    t.defaultTextFormat = new TextFormat('Verdana',12,0x000000);
    t.embedFonts = true;
    t.text = theText.charAt(i);
    t.selectable = false;
    letters.push(t);

    addChild(t);
    //if(i > 0) t.x = letters[i-1].x + letters[i-1].textWidth;

    var tween:TweenMax = TweenMax.to(t, 3, {bezierThrough:[{x:0, y:0},{x:50, y:50},{x:100, y:0}], orientToBezier:true, ease:Linear.easeNone});
    tween.complete(true,true);
    tween.currentProgress = i/lettersNum;
}

不是一个很好的。将 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:

var theText:String = 'text on a path';
var letters:Array = [];
var lettersNum:int = theText.length;

for(var i:int = 0; i < lettersNum; i++){
    var t:TextField = new TextField();
    t.defaultTextFormat = new TextFormat('Verdana',12,0x000000);
    t.embedFonts = true;
    t.text = theText.charAt(i);
    t.selectable = false;
    letters.push(t);

    addChild(t);
    if(i > 0) t.x = letters[i-1].x + letters[i-1].textWidth;
}

I've tried to put things on a path quick and hacky using TweenMax.

import com.greensock.*; 
import com.greensock.easing.*;
import com.greensock.plugins.*;

TweenPlugin.activate([BezierThroughPlugin, BezierPlugin]);

var theText:String = 'text on a path';
var letters:Array = [];
var lettersNum:int = theText.length;

for(var i:int = 0; i < lettersNum; i++){
    var t:TextField = new TextField();
    t.defaultTextFormat = new TextFormat('Verdana',12,0x000000);
    t.embedFonts = true;
    t.text = theText.charAt(i);
    t.selectable = false;
    letters.push(t);

    addChild(t);
    //if(i > 0) t.x = letters[i-1].x + letters[i-1].textWidth;

    var tween:TweenMax = TweenMax.to(t, 3, {bezierThrough:[{x:0, y:0},{x:50, y:50},{x:100, y:0}], orientToBezier:true, ease:Linear.easeNone});
    tween.complete(true,true);
    tween.currentProgress = i/lettersNum;
}

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

美胚控场 2024-08-23 15:07:38

Greensock 的 TextMetrics 在这些情况下可能很有用。描述:TextMetrics – 查找子字符串坐标、线宽等等

Greensock's TextMetrics could be useful in these situations. Description: TextMetrics – Find substring coordinates, line widths, and much more

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文