DIAVIS-wiki
 [[java/画像関連]]
 
 #contents
 ----
 
 
 *任意の文字の形を操作する [#f9194e68]
 
 **Glyphを取り出す。 [#d17a821d]
  GlyphVector glyph = font.createGlyphVector(new FontRenderContext(new AffineTransform(), false, false), str);
 **GlyphからShapeを取り出す。 [#s2a60117]
 //グリフを取得する文字を文字列の中からIndexで指定
  Shape outline = glyph.getGlyphOutline(m);
 **Shapeを複数の描画セグメントに分割する。 [#w3f4a378]
  AffineTransform at = new AffineTransform();
  at.translate(x,y);
  PathIterator iter = outline.getPathIterator(at);
  float coords[] = new float[6]; //取得用、PathIteratorのcurrentSegment()の引数として渡して中に値を入れてもらう。それを解析
  int type;
  int char_counter = 0;
  while ( !iter.isDone() ) {
 	/*
 	 * 個々の描画セグメントを1つずつ取り出し、その描画方法を特定している点列の座標値を得る。
 	 *
 	 * 描画方法の種類としては、
 	 * 	SEG_MOVETO	(ペンの移動)
 	 * 	SEG_LINETO	(線分の描画)
 	 * 	SEG_CUBICTO	(3点指定のベジエ曲線の描画)
 	 * 	SEG_QUADTO	(2点指定のベジエ曲線の描画)
 	 * 	SEG_CLOSE	(最初の点に戻る)
 	 * がある。
 	 */
 	type = iter.currentSegment(coords);
 	int z = 0;
 	Point p;
 	float[] fs = new float[6];
 	lists[m].add( new SegmentObject( this, type, coords.clone()) );
 	switch ( type ) {
 		case PathIterator.SEG_CLOSE:
 			paths[m].closePath();
 			break;
 		case PathIterator.SEG_CUBICTO:
 			for ( int i = 0 ; i < 6 ; i+=2 ) {
 				fs[i]   = coords[i];
 				fs[i+1] = coords[i+1];
 				//points.add(new Point3d((int)coords[i],(int)coords[i+1],z));
 			}
 			paths[m].curveTo(fs[0],fs[1],fs[2],fs[3],fs[4],fs[5]);
 			break;
 		case PathIterator.SEG_LINETO:
 			for ( int i = 0 ; i < 2 ; i+=2 ) {
 				fs[i]   = coords[i];
 				fs[i+1] = coords[i+1];
 			}
 			paths[m].lineTo(fs[0],fs[1]);
 			break;
 		case PathIterator.SEG_MOVETO:
 			for ( int i = 0 ; i < 2 ; i+=2 ) {
 				fs[i]   = coords[i];
 				fs[i+1] = coords[i+1];
 			}
 			paths[m].moveTo(fs[0],fs[1]);
 			break;
 		case PathIterator.SEG_QUADTO:
 			//System.out.println("QUADTO :");
 			for ( int i = 0 ; i < 4 ; i+=2 ) {
 				fs[i]   = coords[i];
 				fs[i+1] = coords[i+1];
 			}
 			paths[m].quadTo(fs[0],fs[1],fs[2],fs[3]);
 			break;
 	}
 	iter.next();
 }
 
 
 *サンプル [#vf1b315e]
 
 -[[044_Reconstruct_Typo[044_Reconstruct_Typo.zip]:http://diavis.info/programs/044_Reconstruct_Typo.zip]]
トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS