//
/* ----------------------------------------------------------------------------------------------
	outlinefont.java	アウトラインフォント					ver. 4.00 (JDK 1.02)  
																ueyama@infonet.co.jp  2001.07.21
																update: 2011.03.16
---------------------------------------------------------------------------------------------- */
import java.applet.*;
import java.awt.*;

public class outlinefont extends Applet
{
	int		Cd[][]  = new int[256][6];									// 端点座標値(編集)
	int		Cbk[][] = new int[256][6];									// 端点座標値 (for backup)
	int		Corg[][]= new int[256][6];									// 端点座標値(初期値)
	// サンプルフォント(B) データ (端点X,Y、 制御点X,Y、 端点X,Y  座標値) (直線の制御点座標値は 0,0)
	int 	CdB[][] = {{-102,-122,   0,   0,  16,-122},					// 外側アウトライン
					   {  16,-122,  88,-116,  90, -62},
					   {  90, -62,  95, -22,  55,  -7},
					   {  55,  -7, 105,   9, 102,  53},
					   { 102,  53, 106, 122,  16, 123},
					   {  16, 123,   0,   0,-102, 123},
					   {-102, 123,   0,   0,-102,-122},
					   { -54, -82,   0,   0,  10, -82},					// 内側上アウトライン
					   {  10, -82,  44, -76,  41, -54},
					   {  41, -54,  42, -30,  10, -25},
					   {  10, -25,   0,   0, -54, -25},
					   { -54, -25,   0,   0, -54, -82},
					   { -54,  16,   0,   0,  10,  16},					// 内側下アウトライン
					   {  10,  16,  50,  20,  51,  48},
					   {  51,  48,  52,  76,  17,  81},
					   {  17,  81,   0,   0, -54,  81},
					   { -54,  81,   0,   0, -54,  16}};

	int		Lq = 17;													// 全アウトライン本数
	int		En = 0;														// アウトライン毎の端点No.
	int		Cx=400, Cy=240;												// 文字の中心の座標値
	double	Dx=1.0, Dy=1.0;												// 拡大・縮小率
	double	It=0.0, Ra=0.0;												// 傾斜、回転
	int		Bx[]={78,114,156,192,234,276,312,354,390, 446, 486, 528, 564, 604, 644, 688};	// ボタン表示 X 座標値
	int		Tx[]={100, 177, 239, 298, 375, 452, 491, 533, 570, 608, 648, 692};
	int		Bq = 16;													// 
	int		By=492;														// ボタン表示 Y 座標値
	int		Mb=99;														// クリックされたボタン No. (0〜8)
	int		Mj, Ml;														// クリックされた端点・制御点の No.
	int		Em = -1;													// 編集モード  -1: 非編集  0: 直線  1:曲線
	boolean	Dd = true;
	boolean	Dg = false;
	Image	Img, Buf;
	
	public void init()
	{
		String bg=getParameter("bgcolor");								// 背景色の読み込み
		int bgc=Integer.valueOf(bg,16).intValue();
		setBackground(new Color(bgc)); 
		MediaTracker mt=new MediaTracker(this);
		Img=getImage(getCodeBase(), getParameter("figure"));			// gif ファイルの読み込み
		mt.addImage(Img, 0);
		try
		{
			mt.waitForID(0);
		}
		catch(InterruptedException e){};
		Buf=createImage(800,540);
		set_B();														// 文字「B」のサンプルデータを読み込む
	}
	
	public boolean inside(int x, int a, int b)
	{
		return (x<=Math.max(a,b) && x>=Math.min(a,b)) ? true:false;
	}

	public void dsp_fig(int x, int y, int m, int n, int c)				// 図や文字を描く
	{
		int w=0, h=0, oy=0;
		switch(c)
		{
			case 0: w=34; h=26; oy= 0;	break;							// ボタンの表示
			case 1: w=27; h=12; oy=52;	break;							// 文字の表示
		}
		Graphics gx=getGraphics();
		gx.clipRect(x,y,w,h);
		gx.drawImage(Img,x-(m*w),y-(oy+n*h),this);
		gx.dispose();
	}

	public void dsp_font(Graphics g)									// フォントの表示
	{
		int i,j;
		double t, x0,y0, x1,y1;
		g.clearRect(0,0,800,540);
		g.setColor(new Color(0xf0f7f0));								// 格子を描く
		for(i=0;i<800;i+=20) g.drawLine(i,0,i,500);
		for(i=0;i<500;i+=20) g.drawLine(0,i,800,i);
		g.setColor(new Color(0xe0e7e0));
		for(i=0;i<2;i++) for(j=0;j<2;j++) g.drawRect(220+180*i,60+180*j,180,180);
		g.setColor(Color.blue);
		if(En==1) g.drawRect(Cd[Lq][0]-4+Cx, Cd[Lq][1]-4+Cy, 8,8);		// 最初の端点の表示
		for(i=0; i=0)													// 編集モード(端点入力)
			{
				if(En>0) Lq++;
				Cd[Lq][0]=x0; Cd[Lq][1]=y0;
				if(En>0)
				{
					Cd[Lq-1][4]=x0; Cd[Lq-1][5]=y0;
					if(Em==0) { Cd[Lq-1][2]=0; Cd[Lq-1][3]=0; }			// 直線
					else												// 曲線
					{
						Cd[Lq-1][2]=(Cd[Lq-1][0]+Cd[Lq-1][4])/2;
						Cd[Lq-1][3]=(Cd[Lq-1][1]+Cd[Lq-1][5])/2;
					}
				}
				En++;
				if(En>1)
				{
					lx=Cd[Lq-En+1][0]; ly=Cd[Lq-En+1][1];				// 最初の端点の座標
					if(((x0-lx)*(x0-lx) + (y0-ly)*(y0-ly))<80)			// 最初の端点が再クリックされたら
					{
						Cd[Lq-1][4]=lx; Cd[Lq-1][5]=ly;					// アウトラインを閉じる
						En=0;
					}
				}
				for(j=0; j<2; j++) {Cbk[Lq][j]=Cd[Lq][j]; Corg[Lq][j]=Cd[Lq][j];}
				if(Lq>0 && En>0) for(  ; j<6; j++) {Cbk[Lq-1][j]=Cd[Lq-1][j]; Corg[Lq-1][j]=Cd[Lq-1][j];}
				repaint();
			}
			else														// 端点のドラッグか?
			{
				for(i=0;i=0) repaint();
			}
		}
		else															// ボタンをクリック?
		{
			for(i=0;i=0 && Lq>0 && En>0) {if(En>1) Lq--; En--; } break;	// 訂正
				case 14: Em=-1; backup();								// 編集終了
						 for(i=0;i=0) upd_font();
		Graphics gr=getGraphics();
		if(Dg) dsp_point(false, gr);
		Mb=99;
		Dg=false;
		return true;
	}

	public boolean mouseDrag(Event e, int x, int y)						// マウスがドラッグされたときの処理
	{
		int i,j;
		if(Ml>=0)														// 端点・制御点のドラッグ
		{
			Dg=true;													// true: ドラッグ中
			if(Mj<2)													// 端点をドラッグ
			{
				for(i=0;i戻る