From 648cede80925ea968d8eecba88181a449c65f17c Mon Sep 17 00:00:00 2001 From: Taco Hoekwater Date: Tue, 1 Apr 2008 12:40:17 +0000 Subject: [PATCH] move obj:fields() to mplib.fields(obj) and bugfixed, dash scales fixed, bumped version git-svn-id: svn+ssh://scm.foundry.supelec.fr/svn/metapost/mplib/trunk@456 b0617d17-b707-0410-b22c-fd2634e05cc4 --- src/texk/web2c/mpdir/lib/mp.w | 33 +++++++++++++++++++++++--------- src/texk/web2c/mpdir/lib/psout.w | 14 -------------- src/texk/web2c/mpdir/lmplib.c | 19 ++++++++++-------- 3 files changed, 35 insertions(+), 31 deletions(-) diff --git a/src/texk/web2c/mpdir/lib/mp.w b/src/texk/web2c/mpdir/lib/mp.w index 52f9bb2..3144116 100644 --- a/src/texk/web2c/mpdir/lib/mp.w +++ b/src/texk/web2c/mpdir/lib/mp.w @@ -75,8 +75,8 @@ undergoes any modifications, so that it will be clear which version of @d banner "This is MetaPost, Version 1.003" /* printed when \MP\ starts */ @d metapost_version "1.003" -@d mplib_version "0.30" -@d version_string " (Cweb version 0.30)" +@d mplib_version "0.40" +@d version_string " (Cweb version 0.40)" @d true 1 @d false 0 @@ -9525,27 +9525,39 @@ dash_y(hh)=dash_y(h) @ |h| is an edge structure @c -mp_dash_object *mp_export_dashes (MP mp, pointer h) { +mp_dash_object *mp_export_dashes (MP mp, pointer q, scaled *w) { mp_dash_object *d; - pointer p; + pointer p, h; + scaled scf; /* scale factor */ scaled *dashes = NULL; int num_dashes = 1; + h = dash_p(q); if (h==null || dash_list(h)==null_dash) return NULL; p = dash_list(h); + scf=mp_get_pen_scale(mp, pen_p(q)); + if (scf==0) { + if (*w==0) scf = dash_scale(q); else return NULL; + } else { + scf=mp_make_scaled(mp, *w,scf); + scf=mp_take_scaled(mp, scf,dash_scale(q)); + } + *w = scf; d = mp_xmalloc(mp,1,sizeof(mp_dash_object)); start_x(null_dash)=start_x(p)+dash_y(h); while (p != null_dash) { dashes = mp_xrealloc(mp, dashes, num_dashes+2, sizeof(scaled)); - dashes[(num_dashes-1)] = (stop_x(p)-start_x(p)); - dashes[(num_dashes)] = (start_x(link(p))-stop_x(p)); + dashes[(num_dashes-1)] = + mp_take_scaled(mp,(stop_x(p)-start_x(p)),scf); + dashes[(num_dashes)] = + mp_take_scaled(mp,(start_x(link(p))-stop_x(p)),scf); dashes[(num_dashes+1)] = -1; /* terminus */ num_dashes+=2; p=link(p); } d->array_field = dashes; - d->offset_field = mp_dash_offset(mp, h); - d->scale_field = dash_scale(h); + d->offset_field = + mp_take_scaled(mp,mp_dash_offset(mp, h),scf); return d; } @@ -25229,6 +25241,7 @@ void mp_ship_out (MP mp, pointer h) ; struct mp_edge_object *mp_gr_export(MP mp, pointer h) { pointer p; /* the current graphical object */ integer t; /* a temporary value */ + scaled d_width; /* the current pen width */ mp_edge_object *hh; /* the first graphical object */ struct mp_graphic_object *hq; /* something |hp| points to */ struct mp_text_object *tt; @@ -25255,6 +25268,7 @@ struct mp_edge_object *mp_gr_export(MP mp, pointer h) { case mp_fill_code: tf = (mp_fill_object *)hq; gr_pen_p(tf) = mp_export_knot_list(mp,pen_p(p)); + d_width = mp_get_pen_scale(mp, pen_p(p)); if ((pen_p(p)==null) || pen_is_elliptical(pen_p(p))) { gr_path_p(tf) = mp_export_knot_list(mp,path_p(p)); } else { @@ -25276,6 +25290,7 @@ struct mp_edge_object *mp_gr_export(MP mp, pointer h) { case mp_stroked_code: ts = (mp_stroked_object *)hq; gr_pen_p(ts) = mp_export_knot_list(mp,pen_p(p)); + d_width = mp_get_pen_scale(mp, pen_p(p)); if (pen_is_elliptical(pen_p(p))) { gr_path_p(ts) = mp_export_knot_list(mp,path_p(p)); } else { @@ -25297,7 +25312,7 @@ struct mp_edge_object *mp_gr_export(MP mp, pointer h) { gr_ljoin_val(ts) = ljoin_val(p); gr_miterlim_val(ts) = miterlim_val(p); gr_lcap_val(ts) = lcap_val(p); - gr_dash_p(ts) = mp_export_dashes(mp,dash_p(p)); + gr_dash_p(ts) = mp_export_dashes(mp,p,&d_width); break; case mp_text_code: tt = (mp_text_object *)hq; diff --git a/src/texk/web2c/mpdir/lib/psout.w b/src/texk/web2c/mpdir/lib/psout.w index 1a32e60..90cf692 100644 --- a/src/texk/web2c/mpdir/lib/psout.w +++ b/src/texk/web2c/mpdir/lib/psout.w @@ -4405,12 +4405,9 @@ format, it is closely modelled to the PostScript model. The array of dashes is ended by a single negative value, because this is not allowed in PostScript. -@d gr_dash_scale(A) (gr_dash_p(A))->scale_field - @= typedef struct { scaled offset_field; - scaled scale_field; scaled *array_field; } mp_dash_object ; @@ -4707,7 +4704,6 @@ void mp_gr_fix_graphics_state (MP mp, mp_graphic_object *p) { scaled wx,wy,ww; /* dimensions of pen bounding box */ boolean adj_wx; /* whether pixel rounding should be based on |wx| or |wy| */ integer tx,ty; /* temporaries for computing |adj_wx| */ - scaled scf; /* a scale factor for the dash pattern */ if ( gr_has_color(p) ) @; if ( (gr_type(p)==mp_fill_code)||(gr_type(p)==mp_stroked_code) ) { @@ -4980,13 +4976,6 @@ if ( gr_type(p)==mp_fill_code || gr_dash_p(p) == NULL) { hh=NULL; } else { hh=gr_dash_p(p); - scf=mp_gr_get_pen_scale(mp, gr_pen_p((mp_fill_object *)p)); - if ( scf==0 ) { - if ( gs_width==0 ) scf=hh->scale_field; else hh=NULL; - } else { - scf=mp_make_scaled(mp, gs_width,scf); - scf=mp_take_scaled(mp, scf, (hh == NULL ? unity : gr_dash_scale(p))); - } } if ( hh==NULL ) { if ( gs_dash_p!=NULL || gs_dash_init_done == false) { @@ -5038,9 +5027,6 @@ boolean mp_gr_same_dashes (mp_dash_object *h, mp_dash_object *hh) ; @ This function test if |h| and |hh| represent the same dash pattern. -The |scale_field| is ignored in this test because it is not really -a property of the PostScript format of a dash pattern. - @c boolean mp_gr_same_dashes (mp_dash_object *h, mp_dash_object *hh) { boolean ret=false; diff --git a/src/texk/web2c/mpdir/lmplib.c b/src/texk/web2c/mpdir/lmplib.c index c653ea7..e7e1f31 100644 --- a/src/texk/web2c/mpdir/lmplib.c +++ b/src/texk/web2c/mpdir/lmplib.c @@ -883,8 +883,7 @@ mplib_gr_tostring (lua_State *L) { static int mplib_gr_fields (lua_State *L) { const char **fields; - const char *f; - int i = 1; + int i ; struct mp_graphic_object **hh = is_gr_object(L,1); if (*hh) { switch ((*hh)->_type_field) { @@ -899,9 +898,9 @@ mplib_gr_fields (lua_State *L) { default: fields = no_fields; } lua_newtable(L); - for (f = *fields; f != NULL; f++) { - lua_pushstring(L,f); - lua_rawseti(L,-2,i); i++; + for (i=0;fields[i]!=NULL;i++) { + lua_pushstring(L,fields[i]); + lua_rawseti(L,-2,(i+1)); } } else { lua_pushnil(L); @@ -1012,6 +1011,7 @@ mplib_push_color (lua_State *L, struct mp_graphic_object *p ) { static void mplib_push_dash (lua_State *L, struct mp_stroked_object *h ) { mp_dash_object *d; + double ds; if (h!=NULL && h->dash_p_field != NULL) { d = h->dash_p_field; lua_newtable(L); @@ -1021,7 +1021,8 @@ mplib_push_dash (lua_State *L, struct mp_stroked_object *h ) { int i = 0; lua_newtable(L); while (*(d->array_field+i) != -1) { - mplib_push_number(L, *(d->array_field+1)); + ds = *(d->array_field+1) / 65536.0; + lua_pushnumber(L, ds); i++; lua_rawseti(L,-2,i); } @@ -1163,6 +1164,7 @@ mplib_gr_index (lua_State *L) { struct mp_graphic_object **hh = is_gr_object(L,1); if (*hh) { struct mp_graphic_object *h = *hh; + if (mplib_is_S(type,2)) { lua_rawgeti(L,LUA_REGISTRYINDEX,mplib_type_Ses[h->_type_field]); } else { @@ -1206,7 +1208,6 @@ static const struct luaL_reg mplib_gr_meta[] = { {"__gc", mplib_gr_collect }, {"__tostring", mplib_gr_tostring }, {"__index", mplib_gr_index }, - {"fields", mplib_gr_fields }, {NULL, NULL} /* sentinel */ }; @@ -1220,7 +1221,8 @@ static const struct luaL_reg mplib_d [] = { static const struct luaL_reg mplib_m[] = { - {"new", mplib_new}, + {"new", mplib_new }, + {"fields", mplib_gr_fields }, {NULL, NULL} /* sentinel */ }; @@ -1228,6 +1230,7 @@ static const struct luaL_reg mplib_m[] = { int luaopen_mp (lua_State *L) { mplib_init_Ses(L); + luaL_newmetatable(L,MPLIB_GR_METATABLE); lua_pushvalue(L, -1); /* push metatable */ lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */ -- 2.32.0.93.g670b81a890