From: matz@... (Yukihiro Matsumoto) Date: 1997-01-23T12:43:36+09:00 Subject: [ruby-list:1841] Re: GD.c revised まつもと ゆきひろです In message "[ruby-list:1834] Re: GD.c revised" on 97/01/23, Noritugu Nakamura writes: |中村です。 |□□□ うまく動かないところ □□□ | | |im.setStyle(green,green,green,GD::Transparent,red,red,red,GD::Transparent) |を入れると |./brushes.rb:29: Uninitialized constant GD::Transparent |と言われてしまう。 定数の定義忘れですね.追加しました. | |poly.map(50,50,100,100,10,10,110,60) |poly.map($poly->bounds,50,20,80,160) |を入れると |./polys.rb:28: [BUG] Segmentation fault |Abort |と言われてしまう。 これは問題が三つあります.まず,offsetとmapの計算結果が不正 な値になっていました.これが原因でSEGVが起きます. 次に,perlと違ってrubyでは配列は引数に展開されないので, b = $poly->bounds poly.map(b[0],b[1],b[2],b[3],50,20,80,160) または poly.map(*($poly->bounds+[50,20,80,160])) などとする必要があります.しかし,この場合はもとのpolygonの 大きさを使っていますので, poly.map(50,20,80,160) としても同じ動作をします. で,二つ目の問題は引数が5つ以上,8つ未満の時(今回は5つだった) SEGVすることです.引数が4つの場合と8つの場合しかチェックして いませんでした. | |im.charUp(GD::Font::MediumBoldFont,280,280,"Q",black) |を入れると |./shapes.rb:29: Uninitialized constant GD::Font::MediumBoldFont |と言われてしまう。 これも定義忘れです. んで,修正後は実行できたんですけど,手元にGD.pmを持って来て いないので,正しい動作かどうかわかりません.GD.cのパッチを付 けておきますので,確認してみてください. # 新幹線の中なので. まつもと ゆきひろ /:|) --- ext/GD/GD.c~ Thu Jan 23 09:56:30 1997 +++ ext/GD/GD.c Thu Jan 23 09:51:12 1997 @@ -561,6 +561,30 @@ } static VALUE +img_width(img) + VALUE img; +{ + gdImagePtr im; + int i; + + Get_Data_Struct(img, gdImage, im); + i = gdImageSX(im); + return INT2FIX(i); +} + +static VALUE +img_height(img) + VALUE img; +{ + gdImagePtr im; + int i; + + Get_Data_Struct(img, gdImage, im); + i = gdImageSY(im); + return INT2FIX(i); +} + +static VALUE img_gif(img, out) VALUE img, out; { @@ -711,14 +735,16 @@ struct RArray *ply; VALUE vx, vy; { - int i, x, y; + int i, x, y, c; x = NUM2INT(vx); y = NUM2INT(vy); for (i = 0; ilen; i+=2) { - ply->ptr[i] += x; - ply->ptr[i+1] += y; + c = NUM2INT(ply->ptr[i]) + x; + ply->ptr[i] = INT2FIX(c); + c = NUM2INT(ply->ptr[i+1]) + y; + ply->ptr[i+1] = INT2FIX(c); } return (VALUE)ply; @@ -733,9 +759,11 @@ VALUE sl, st, sr, sb, dl, dt, dr, db; int sx, sy, dx, dy; double xmag, ymag; - int i; + int i, c; + + i = rb_scan_args(argc,argv,"44",&sl,&st,&sr,&sb, &dl,&dt,&dr,&db); - if (rb_scan_args(argc,argv,"44",&sl,&st,&sr,&sb, &dl,&dt,&dr,&db) == 4) { + if (i == 4) { int i, l, t, r, b; int nx, ny; @@ -762,7 +790,7 @@ xmag = (double)(NUM2INT(sr) - NUM2INT(sl))/(double)(r - l); ymag = (double)(NUM2INT(sb) - NUM2INT(st))/(double)(b - t); } - else { + else if (i == 8) { sx = NUM2INT(sl); sy = NUM2INT(st); dx = NUM2INT(dl); @@ -772,10 +800,18 @@ ymag = (double)(NUM2INT(db) - NUM2INT(dt))/ (double)(NUM2INT(sb) - NUM2INT(st)); } + else { + ArgError("wrong # of arguments (%d for 4 or 8)", argc); + } for (i = 0; ilen; i+=2) { - ply->ptr[i] = (ply->ptr[i]-sx)*xmag+dx; - ply->ptr[i+1] = (ply->ptr[i+1]-sy)*ymag+dy; + c = NUM2INT(ply->ptr[i]); + c = (c-sx)*xmag+dx; + ply->ptr[i] = INT2FIX(c); + + c = NUM2INT(ply->ptr[i+1]); + c = (c-sy)*ymag+dy; + ply->ptr[i+1] = INT2FIX(c); } return (VALUE)ply; @@ -881,15 +917,12 @@ rb_define_method(cImage, "setBrush", img_set_blush, 1); rb_define_const(mGD, "Brushed", INT2FIX(gdBrushed)); - rb_define_const(cImage, "Brushed", INT2FIX(gdBrushed)); rb_define_method(cImage, "setStyle", img_set_style, -1); rb_define_const(mGD, "Styled", INT2FIX(gdStyled)); - rb_define_const(cImage, "Styled", INT2FIX(gdStyled)); - rb_define_const(cImage, "StyledBrushed", INT2FIX(gdStyledBrushed)); rb_define_const(mGD, "StyledBrushed", INT2FIX(gdStyledBrushed)); rb_define_method(cImage, "setTile", img_set_tile, 1); rb_define_const(mGD, "Tiled", INT2FIX(gdTiled)); - rb_define_const(cImage, "Tiled", INT2FIX(gdTiled)); + rb_define_const(mGD, "Transparent", INT2FIX(gdTransparent)); rb_define_method(cImage, "setPixel", img_set_pixel, 3); rb_define_method(cImage, "line", img_line, 5); @@ -915,6 +948,8 @@ rb_define_method(cImage, "interlace=", img_set_interlace, 1); rb_define_method(cImage, "bounds", img_bounds, 0); + rb_define_method(cImage, "width", img_width, 0); + rb_define_method(cImage, "height", img_height, 0); rb_define_method(cImage, "gif", img_gif, 1); rb_define_method(cImage, "gd", img_gd, 1); @@ -939,6 +974,7 @@ rb_define_const(cFont, "SmallFont", fnt_new("Small")); rb_define_const(cFont, "LargeFont", fnt_new("Large")); rb_define_const(cFont, "MediumFont", fnt_new("Medium")); + rb_define_const(cFont, "MediumBoldFont", fnt_new("Medium")); rb_define_const(cFont, "TinyFont", fnt_new("Tiny")); rb_define_method(cFont, "nchars", fnt_nchars, 0);