·您当前的位置:首页 > 技术教程 > AS2与AS3技术 >

[AS3]as3使用中文字体黑体,隶书,楷体等的源码

时间:2016-04-19 17:19酷播
[AS3]as3使用中文字体黑体,隶书,楷体等的源码

[AS3]as3使用中文字体黑体,隶书,楷体等的源码

  1. package  
  2.         import flash.display.Bitmap; 
  3.         import flash.display.BitmapData; 
  4.         import flash.display.Sprite; 
  5.         import flash.events.Event; 
  6.         import flash.geom.Matrix; 
  7.         import flash.geom.Point; 
  8.         import flash.geom.Rectangle; 
  9.         import flash.text.TextField; 
  10.         import flash.text.TextFormat; 
  11.          
  12.         /** 
  13.          * ... 
  14.          * @author flashk 
  15.          */ 
  16.         public class TextTextAntiAliasingDemo extends Sprite  
  17.         { 
  18.                 public var a_txt:TextField; 
  19.                 private var bp:Bitmap; 
  20.                 private var bd:BitmapData; 
  21.                 private var quality:Number = 4
  22.                  
  23.                  
  24.                 public function TextTextAntiAliasingDemo() { 
  25.                         a_txt.addEventListener(Event.CHANGE, update); 
  26.                         bp = new Bitmap(); 
  27.                         bp.y = a_txt.y + a_txt.height + 10; 
  28.                         this.addChild(bp); 
  29.                         bd = new BitmapData(a_txt.width*quality, 400*quality); 
  30.                         bp.bitmapData = bd
  31.                         bpbp.scaleX = bp.scaleY = 1 / quality; 
  32.                         bp.smoothing = true
  33.                         bp.x = a_txt.x; 
  34.                         update(); 
  35.                 } 
  36.                 private function update(event:Event=null):void { 
  37.                         var tmpBD:BitmapData = new BitmapData(a_txt.width * quality, a_txt.height * quality, true, 0x00FFFFFF); 
  38.                         var mat:Matrix = new Matrix(); 
  39.                         mat.scale(quality, quality); 
  40.                         tmpBD.draw(a_txt, mat); 
  41.                         bd.fillRect(new Rectangle(0, 0, bd.width, bd.height), 0x00FFFFFF); 
  42.                         bd.draw(tmpBD); 
  43.                          
  44.                         var tf:TextFormat = new TextFormat(); 
  45.                         tf.font = "SimHei"
  46.                         a_txt.setTextFormat(tf); 
  47.                         tmpBD.fillRect(new Rectangle(0, 0, tmpBD.width, tmpBD.height), 0x00FFFFFF); 
  48.                         tmpBD.draw(a_txt, mat); 
  49.                         bd.copyPixels(tmpBD, new Rectangle(0, 0, tmpBD.width, tmpBD.height), new Point(0, 1 * a_txt.height * quality)); 
  50.                          
  51.                          
  52.                         tf.font = "YouYuan"
  53.                         a_txt.setTextFormat(tf); 
  54.                         tmpBD.fillRect(new Rectangle(0, 0, tmpBD.width, tmpBD.height), 0x00FFFFFF); 
  55.                         tmpBD.draw(a_txt, mat); 
  56.                         bd.copyPixels(tmpBD, new Rectangle(0, 0, tmpBD.width, tmpBD.height), new Point(0, 2 * a_txt.height * quality)); 
  57.                          
  58.                         tf.font = "STKaiti"
  59.                         a_txt.setTextFormat(tf); 
  60.                         tmpBD.fillRect(new Rectangle(0, 0, tmpBD.width, tmpBD.height), 0x00FFFFFF); 
  61.                         tmpBD.draw(a_txt, mat); 
  62.                         bd.copyPixels(tmpBD, new Rectangle(0, 0, tmpBD.width, tmpBD.height), new Point(0, 3 * a_txt.height * quality)); 
  63.                          
  64.                         tf.font = "LiSu"
  65.                         a_txt.setTextFormat(tf); 
  66.                         tmpBD.fillRect(new Rectangle(0, 0, tmpBD.width, tmpBD.height), 0x00FFFFFF); 
  67.                         tmpBD.draw(a_txt, mat); 
  68.                         bd.copyPixels(tmpBD, new Rectangle(0, 0, tmpBD.width, tmpBD.height), new Point(0, 4 * a_txt.height * quality)); 
  69.                          
  70.                          
  71.                         tf.font = "FZYaoTi"
  72.                         a_txt.setTextFormat(tf); 
  73.                         tmpBD.fillRect(new Rectangle(0, 0, tmpBD.width, tmpBD.height), 0x00FFFFFF); 
  74.                         tmpBD.draw(a_txt, mat); 
  75.                         bd.copyPixels(tmpBD, new Rectangle(0, 0, tmpBD.width, tmpBD.height), new Point(0, 5 * a_txt.height * quality)); 
  76.                          
  77.                         tf.font = "Microsoft YaHei"
  78.                         a_txt.setTextFormat(tf); 
  79.                         tmpBD.fillRect(new Rectangle(0, 0, tmpBD.width, tmpBD.height), 0x00FFFFFF); 
  80.                         tmpBD.draw(a_txt, mat); 
  81.                         bd.copyPixels(tmpBD, new Rectangle(0, 0, tmpBD.width, tmpBD.height), new Point(0, 6 * a_txt.height * quality)); 
  82.                          
  83.                          
  84.                          
  85.                         tf.font = "SimSun"
  86.                         a_txt.setTextFormat(tf); 
  87.                 } 
  88.         } 
  89.          

 

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器