In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

埋め込み8pxビットマップフォント

// forked from gyuque's ロックマン from ニコニコモンズ
package
{
	import flash.display.*;
	import flash.events.Event;
	import flash.text.*;
	import flash.geom.*;

	[SWF(width="465", height="465", backgroundColor="#604020", frameRate="30")]
	public class BitmapFontTest extends Sprite
	{
		private var buffer:BitmapData = new BitmapData(223, 136, false, 0x308040);
		private var font:BitmapFont;
		private var tx:TextField = new TextField();

		function BitmapFontTest()
		{
			var table:String = ""
			+ " ABCDEFGHIJKLMNOPQRSTUVWXYZabcde"
			+ "fghijklmnopqrstuvwxyz0123456789_"
			+ "-=+\\|[{]};:'\",<.>/?!@#$%^&*()~`㍗";
			font = new BitmapFont(new SpritePool(FONT), table, 8, 8);
			
			var screen:Bitmap = new Bitmap(buffer);
			screen.x = screen.y = 10;
			screen.scaleX = screen.scaleY = 2.0;
			addChild(screen);
			
			tx.type = TextFieldType.INPUT;
			tx.multiline = true;
			tx.defaultTextFormat = new TextFormat("MS Gothic", 10, 0x000000);
			tx.border = true;
			tx.background = true;
			tx.backgroundColor = 0xFFFFFF;
			tx.x = 10;
			tx.y = 284;
			tx.width = 445;
			tx.height = 171;
			tx.text = "(BitmapFont TEST)\r"+
			"\r"+
			"A-Z a-z 0-9 \r"+
			"_-=+\|[{]};:'\".<,\r"+
			">/?!@#$%^&*()~`㍗\r"+
			"\r"+
			" ==RANK===SCORE====DATE====\r"+
			"\r"+
			"    1st  100000  00/00/00\r"+
			"    2nd   50000  00/00/00\r"+
			"    3rd   30000  00/00/00\r"+
			"    4th   20000  00/00/00\r"+
			"    5th   10000  00/00/00\r"+
			"\r"+
			" ==========================";
			addChild(tx);
			
			tx.addEventListener(Event.CHANGE, function(e:Event):void{change();});
			change();
		}

		private function change():void
		{
			buffer.fillRect(buffer.rect, 0x308040);
			font.drawText(buffer, tx.text);
		}
	}
}

import flash.display.*;
import flash.geom.*;
import flash.utils.ByteArray;
import mx.utils.Base64Decoder;

class BitmapFont
{
	private var chip:Object = new Object();
	private var width:int;
	private var height:int;
	private var bmp:BitmapData;
	
	public function BitmapFont(bmp:BitmapData, texttable:String, width:int, height:int)
	{
		this.bmp = bmp;
		this.width = width;
		this.height = height;
		
		var num_x:int = bmp.width/width;
		var num_y:int = bmp.height/height;
		
		for(var i:int = 0; i < texttable.length; i++)
		{
			chip[texttable.charAt(i)] = new Rectangle(width*(i % num_x), height*(Math.floor(i / num_x)), width, height);
		}
	}
	
	public function drawText(surface:BitmapData, txt:String, x:int = 0, y:int = 0):void
	{
		var px:int = x;
		
		for(var i:int = 0; i < txt.length; i++)
		{
			var char:String = txt.charAt(i);
			
			if(char == "\r")
			{
				y += height;
				x = px;
				continue;
			}
			
			if(chip[char] == undefined) {char = " ";}
			
			surface.copyPixels(bmp, chip[char], new Point(x, y));
			x += width;
		}
	}
}

class SpritePool extends BitmapData
{
	function SpritePool(src:*)
	{
		var decoder = new Base64Decoder();
		decoder.decode(src.DATA);
		var ba:ByteArray = decoder.toByteArray();
		ba.uncompress();

		var w:int = ba.readUnsignedShort();
		var h:int = ba.readUnsignedShort();

		super(w, h, true, 0);

		var pal_length:int = ba.readUnsignedByte();
		var pal:Array = new Array(pal_length);
		for (var i:int = 0;i < pal_length;i++) {
			pal[i] = ba.readUnsignedInt();
		}

		lock();
		var x:int, y:int, k:uint;
		for (y = 0;y < h;y++) {
			for (x = 0;x < w;x += 2) {
				k = ba.readUnsignedByte();
				setPixel32(x  , y, uint(pal[k&0x0f]));
				setPixel32(x+1, y, uint(pal[(k&0xf0)>>4]));
			}
		}
		unlock();
	}
}

class FONT
{
	public static const DATA:String =
	'eNqdVrtu60YQHT2uPekEAQZcilDjklEh+DMk4BYpCbCgSlWEyzV5Tc2P3DJlyrQp8xv5hJTKOTNLSg6SFFn4eGZ3Z2e1j3OWM5HnHwTl+sf1ev0N/375/erlT+DnX6/X79+v1+L5R8ZIsZCvRS0H4GvgkfC6VI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