Flash AS3 BitmapData.draw() 影响文本格式

发布于 2024-08-12 02:10:34 字数 911 浏览 3 评论 0原文

我需要显示抗锯齿系统字体(因为 swf 文件大小必须很小,因此我无法嵌入字体)。所以我编写了这个脚本,以便手动对文本进行抗锯齿

Code:

    public function renderTextField():BitmapData{
        var w:int = this["mainTextField"].textWidth+10;
        var h:int = this["mainTextField"].textHeight+10;
        var bitmapData:BitmapData = new BitmapData(w*3,h*3,false,0x000000);
        var antialiased:BitmapData = new BitmapData(w,h,false,0x000000);
        var transf:Matrix = new Matrix();
        transf.scale(3,3);
        bitmapData.draw(this["mainTextField"],transf);
        var bitmap:Bitmap = new Bitmap(bitmapData,"auto",true);
        transf = new Matrix();
        transf.scale(1.0/3.0,1.0/3.0);
        antialiased.draw(bitmap,transf,null,null,null,true);
        return antialiased;
    }

这工作得很好,但有一个令人讨厌的事情。有时,绘制调用的缩放会影响文本格式。例如,一行的最后一个单词将成为下一行的第一个单词。这绝不能发生!有谁知道为什么会发生以及我如何避免它?我希望文本完全按照文本框中显示的方式渲染到位图数据中,

谢谢!

I need to display antialiased systemfonts (because the swf filesize must be small, therefore i can't embedd fonts). So I wrote this script in order to manually antialias the text

Code:

    public function renderTextField():BitmapData{
        var w:int = this["mainTextField"].textWidth+10;
        var h:int = this["mainTextField"].textHeight+10;
        var bitmapData:BitmapData = new BitmapData(w*3,h*3,false,0x000000);
        var antialiased:BitmapData = new BitmapData(w,h,false,0x000000);
        var transf:Matrix = new Matrix();
        transf.scale(3,3);
        bitmapData.draw(this["mainTextField"],transf);
        var bitmap:Bitmap = new Bitmap(bitmapData,"auto",true);
        transf = new Matrix();
        transf.scale(1.0/3.0,1.0/3.0);
        antialiased.draw(bitmap,transf,null,null,null,true);
        return antialiased;
    }

this works pretty well, but there's a nasty thing. Sometimes the scaling of the draw call affects the texts formatting. for example, the last word of a line will be the first word of the next line instead. This must not happen! does anyone have an idea why it happens and how i can avoid it? i want the text to be rendered into the bitmapData exactly as it appears in the textbox

thanks!

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

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

发布评论

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

评论(2

蘑菇王子 2024-08-19 02:10:34

看看新的文本引擎(需要 Player 10.0,已推出一年多):http: //labs.adobe.com/technologies/textlayout/

Take a look at the new text engine (requires Player 10.0, out for more than one year): http://labs.adobe.com/technologies/textlayout/

病毒体 2024-08-19 02:10:34

显然,当放大 TextField 时,它的缩放方式与矢量绘图的方式不同。 TextField 的边界区域被放大,但实际文本内容的字体大小增加以填充新区域,这可能会导致垂直对齐稍微移动和/或将单词推到下一行。

Apparently, when a TextField is scaled up, it's not scaled the same way that a vector drawing would be. The TextField's bounding area is scaled up, but the actual text contents has its font size increased to fill that new area instead, which can cause the vertical alignment to shift slightly and/or push words to the next line.

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