root/as3/PotrAs/src/com/nitoyon/potras/PotrAs.as

リビジョン 89, 2.0 kB (コミッタ: nitoyon, コミット時期: 4 年 前)

Mac OS で traceLetter の幅が小さくなるバグを修正した

Line 
1 /* Copyright (C) 2001-2007 Peter Selinger and nitoyon.
2    Original code(Potrace v1.8) by Peter Selinger.
3    Ported to ActionScript 3.0 by nitoyon.
4    This file is part of PotrAs. It is free software and it is covered
5    by the GNU General Public License. See the file COPYING for details. */
6
7 package com.nitoyon.potras
8 {
9 import flash.display.Graphics;
10 import flash.display.BitmapData;
11 import flash.geom.Point;
12 import flash.text.TextField;
13 import flash.text.TextFormat;
14
15 /**
16  *  The PotrAs class is an all-static class with methods for working with tracing <code>BitmapData</code> and letters.
17  */
18 public class PotrAs
19 {
20         /**
21          *  Traces the given BitmapData.
22          *
23          *  @param sourceBitmapData The input image to use. The source image must be binarized
24          *  (only 0xffffffff and 0xff000000 are allowed).
25          *  @return A ClosedPathList object that represents trace result.
26          *  @seealso ClosedPathList
27          */
28         public static function traceBitmap(sourceBitmapData:BitmapData):ClosedPathList
29         {
30                 var pathList:Array = PathList.create(sourceBitmapData);
31                 return ProcessPath.processPath(pathList);
32         }
33
34         /**
35          *  Traces the String with fontsize <code>fontSize</code>.
36          */
37         public static function traceLetter(letter:String, fontSize:int):ClosedPathList
38         {
39                 var tf:TextFormat = new TextFormat();
40                 tf.size = fontSize;
41
42                 var text:TextField = new TextField();
43                 text.defaultTextFormat = tf;
44                 text.autoSize = "left";
45                 text.text = letter;
46
47                 // We have to use threshold method to binarize, because Mac OS draws antialiased text.
48                 var bmdtmp:BitmapData = new BitmapData(fontSize * letter.length, fontSize * 1.2, true);
49                 var bitmapdata:BitmapData = bmdtmp.clone();
50                 bmdtmp.draw(text);
51                 bitmapdata.threshold(bmdtmp, bmdtmp.rect, new Point(), "<", 0xffdddddd, 0xff000000);
52
53                 var pathList:Array = PathList.create(bitmapdata);
54                 var c:ClosedPathList = ProcessPath.processPath(pathList);
55
56                 bmdtmp.dispose();
57                 bitmapdata.dispose();
58                 return c;
59         }
60 }
61 }
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。