/* Copyright (C) 2001-2007 Peter Selinger and nitoyon.
Original code(Potrace v1.8) by Peter Selinger.
Ported to ActionScript 3.0 by nitoyon.
This file is part of PotrAs. It is free software and it is covered
by the GNU General Public License. See the file COPYING for details. */
package com.nitoyon.potras
{
import flash.display.Graphics;
import flash.display.BitmapData;
import flash.geom.Point;
import flash.text.TextField;
import flash.text.TextFormat;
/**
* The PotrAs class is an all-static class with methods for working with tracing BitmapData and letters.
*/
public class PotrAs
{
/**
* Traces the given BitmapData.
*
* @param sourceBitmapData The input image to use. The source image must be binarized
* (only 0xffffffff and 0xff000000 are allowed).
* @return A ClosedPathList object that represents trace result.
* @seealso ClosedPathList
*/
public static function traceBitmap(sourceBitmapData:BitmapData):ClosedPathList
{
var pathList:Array = PathList.create(sourceBitmapData);
return ProcessPath.processPath(pathList);
}
/**
* Traces the String with fontsize fontSize.
*/
public static function traceLetter(letter:String, fontSize:int):ClosedPathList
{
var tf:TextFormat = new TextFormat();
tf.size = fontSize;
var text:TextField = new TextField();
text.defaultTextFormat = tf;
text.autoSize = "left";
text.text = letter;
// We have to use threshold method to binarize, because Mac OS draws antialiased text.
var bmdtmp:BitmapData = new BitmapData(fontSize * letter.length, fontSize * 1.2, true);
var bitmapdata:BitmapData = bmdtmp.clone();
bmdtmp.draw(text);
bitmapdata.threshold(bmdtmp, bmdtmp.rect, new Point(), "<", 0xffdddddd, 0xff000000);
var pathList:Array = PathList.create(bitmapdata);
var c:ClosedPathList = ProcessPath.processPath(pathList);
bmdtmp.dispose();
bitmapdata.dispose();
return c;
}
}
}