Flash AS3 BitmapData.draw() 影响文本格式
我需要显示抗锯齿系统字体(因为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看看新的文本引擎(需要 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/
显然,当放大
TextField
时,它的缩放方式与矢量绘图的方式不同。TextField
的边界区域被放大,但实际文本内容的字体大小增加以填充新区域,这可能会导致垂直对齐稍微移动和/或将单词推到下一行。Apparently, when a
TextField
is scaled up, it's not scaled the same way that a vector drawing would be. TheTextField
'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.