new comdraw funcs submitted by Secil Ugurel
[email protected] Tue, 8 Oct 2002 12:07:50 -0700
| Newsgroups | gmane.comp.lib.ivtools.patches |
|---|---|
| Message-ID | <a04320401b9c8dd265712@[12.236.237.8]> |
Patch: ivtools-020913-johnston-066 For: ivtools-1.0.6 Author: [email protected] Subject: new comdraw funcs submitted by Secil Ugurel Requires: This is an intermediate patch to ivtools-1.0.6. To apply, cd to the top-level directory of the ivtools source tree (the directory with src and config subdirs), and apply like this: patch -p0 <ThisFile Summary of Changes: - new comdraw funcs submitted by Secil Ugurel: help(fontbyname colorsrgb pokeline) "fontbyname(fontname) -- set current font by X font name", "colorsrgb(fgcolorname bgcolorname) -- set current colors by RGB name. The colorname format is \"#RGB\" for 4 bits, \"#RRGGBB\" for 8 bits,\"#RRRGGGBBB\" for 12 bits,\"#RRRRGGGGBBBB\" for 16 bits", "pokeline(compview x y w vallist) -- poke pixel values of a line listed in vallist into raster. w is the width of the line(length of the list)" Index: ComUnidraw/comeditor.c diff -c ComUnidraw/comeditor.c:1.1 ComUnidraw/comeditor.c:1.2 *** ComUnidraw/comeditor.c:1.1 Fri Sep 13 09:51:33 2002 --- src/ComUnidraw/comeditor.c Fri Sep 13 12:19:22 2002 *************** *** 149,155 **** comterp->add_command("brush", new BrushFunc(comterp, this)); comterp->add_command("pattern", new PatternFunc(comterp, this)); comterp->add_command("colors", new ColorFunc(comterp, this)); ! comterp->add_command("nfonts", new NFontsFunc(comterp, this)); comterp->add_command("nbrushes", new NBrushesFunc(comterp, this)); comterp->add_command("npatterns", new NPatternsFunc(comterp, this)); --- 149,158 ---- comterp->add_command("brush", new BrushFunc(comterp, this)); comterp->add_command("pattern", new PatternFunc(comterp, this)); comterp->add_command("colors", new ColorFunc(comterp, this)); ! //SECIL ! comterp->add_command("fontbyname", new FontByNameFunc(comterp, this)); ! comterp->add_command("colorsrgb", new ColorRgbFunc(comterp, this)); ! //SECIL comterp->add_command("nfonts", new NFontsFunc(comterp, this)); comterp->add_command("nbrushes", new NBrushesFunc(comterp, this)); comterp->add_command("npatterns", new NPatternsFunc(comterp, this)); *************** *** 218,223 **** --- 221,229 ---- comterp->add_command("poke", new PixelPokeFunc(comterp, this)); comterp->add_command("peek", new PixelPeekFunc(comterp, this)); + //SECIL + comterp->add_command("pokeline", new PixelPokeLineFunc(comterp, this)); + //SECIL comterp->add_command("pcols", new PixelColsFunc(comterp, this)); comterp->add_command("prows", new PixelRowsFunc(comterp, this)); comterp->add_command("pflush", new PixelFlushFunc(comterp, this)); Index: ComUnidraw/grfunc.c diff -c ComUnidraw/grfunc.c:1.1 ComUnidraw/grfunc.c:1.2 *** ComUnidraw/grfunc.c:1.1 Fri Sep 13 09:51:34 2002 --- src/ComUnidraw/grfunc.c Fri Sep 13 12:19:22 2002 *************** *** 62,67 **** --- 62,74 ---- #include <Unidraw/Graphic/ellipses.h> #include <InterViews/transformer.h> + //SECIL + #include <IV-2_6/InterViews/world.h> + #include <IV-X11/Xlib.h> + #include <IV-X11/xdisplay.h> + #include <IV-X11/xfont.h> + #include <X11/Xatom.h> + //SECIL #include <Attribute/aliterator.h> #include <Attribute/attrlist.h> *************** *** 673,678 **** --- 680,822 ---- } /*****************************************************************************/ + //SECIL + FontByNameFunc::FontByNameFunc(ComTerp* comterp, Editor* ed) : UnidrawFunc(comterp, ed) { + } + + static char *psfonttoxfont(char* f) + { + /* convert a PS name to a X... */ + char type[10]; + int size=0; + static char copy[256]; + static char name[256]; + static char *wght[] = { "bold","demi","light","demibold","book",0 }; + char *s; + + if (*f=='-') + return f; + + strcpy(copy,f); + s = copy; + while (*s) { + *s = tolower(*s); + s++; + } + f = copy+strlen(copy); + + s = strchr(copy,'-'); + if (!s) { + strcpy(type,"medium-r"); + } else { + *s=0; + s++; + for (size=0;wght[size];size++) + if (!strncmp(s,wght[size],strlen(wght[size]))) { + strcpy(type,wght[size]); + strcat(type,"-"); + s+=strlen(wght[size]); + break; + } + if (!wght[size]) + strcpy(type,"medium-"); + switch (*s) { + case 'i': + strcat(type,"i"); + break; + case 'o': + strcat(type,"o"); + break; + default: + strcat(type,"r"); + break; + } + } + + size = 11; + while (f[-1]>='0' && f[-1]<='9') + f--; + + if (*f) + size = atoi(f); + f[0] = 0; + if (f[-1]=='-') + f[-1] = 0; + sprintf(name,"-*-%s-%s-normal-*-%d-*", + copy, type, size ); + return name; + } + /*****************************************************************************/ + void FontByNameFunc::execute() { + ComValue& fontarg = stack_arg(0); + const char* fontval = fontarg.string_ptr(); + reset_stack(); + + char* fontvaldup=strdup(fontval); + Catalog* catalog = unidraw->GetCatalog(); + XDisplay* dpy =World::current()->display()->rep()->display_; + XFontStruct* xfs = XLoadQueryFont(dpy, fontvaldup); + PSFont* font = nil; + + if (!xfs){ + char* xfontval=psfonttoxfont(fontvaldup); + fontvaldup = strdup(xfontval); + xfs = XLoadQueryFont(dpy,xfontval); + if (!xfs){ + fprintf(stderr, "Can not load font: %s, \n", fontval); + fprintf(stderr, "Keeping the current font.\n"); + } + } + if (xfs){ + unsigned long value; + char fontname[CHARBUFSIZE]; + char fontsizeptr[CHARBUFSIZE]; + char fontfullname[CHARBUFSIZE]; + + XGetFontProperty(xfs, XA_FULL_NAME, &value); + strcpy(fontfullname, XGetAtomName(dpy, (Atom)value)); + + XGetFontProperty(xfs, XA_FONT_NAME, &value); + strcpy(fontname, XGetAtomName(dpy, (Atom)value)); + + XGetFontProperty(xfs,XA_POINT_SIZE, &value); + sprintf(fontsizeptr,"%d",(unsigned int)(value/10)); + + font = catalog->FindFont(fontvaldup,fontname,fontsizeptr); + delete fontvaldup; + } + FontCmd* cmd = nil; + + if (font) { + cmd = new FontCmd(_ed, font); + } + + execute_log(cmd); + } + /*****************************************************************************/ + ColorRgbFunc::ColorRgbFunc(ComTerp* comterp, Editor* ed) : UnidrawFunc(comterp, ed) { + } + + void ColorRgbFunc::execute() { + ComValue& fgarg = stack_arg(0); + ComValue& bgarg = stack_arg(1); + const char* fgname = fgarg.string_ptr(); + const char* bgname = bgarg.string_ptr(); + reset_stack(); + PSColor* fgcolor=nil; + PSColor* bgcolor=nil; + Catalog* catalog = unidraw->GetCatalog(); + fgcolor = catalog->FindColor(fgname); + //This comparison is made because the user can set only the foreground color by calling + //colorsrgb with one argument. + if (strcmp(bgname,"sym")!=0){ + bgcolor = catalog->FindColor(bgname); + } + ColorCmd* cmd = new ColorCmd(_ed, fgcolor, bgcolor); + execute_log(cmd); + } + /*****************************************************************************/ + //SECIL BrushFunc::BrushFunc(ComTerp* comterp, Editor* ed) : UnidrawFunc(comterp, ed) { } Index: ComUnidraw/grfunc.h diff -c ComUnidraw/grfunc.h:1.1 ComUnidraw/grfunc.h:1.2 *** ComUnidraw/grfunc.h:1.1 Fri Sep 13 09:51:34 2002 --- src/ComUnidraw/grfunc.h Fri Sep 13 12:19:22 2002 *************** *** 131,136 **** --- 131,147 ---- return "%s(fontnum) -- set current font from menu order"; } }; + //SECIL + //: command for setting font state variable by font name in comdraw. + // fontbyname(fontname) -- set current font by name + class FontByNameFunc : public UnidrawFunc { + public: + FontByNameFunc(ComTerp*,Editor*); + virtual void execute(); + virtual const char* docstring() { + return "%s(fontname) -- set current font by X font name"; } + }; + //: command for setting brush state variable in comdraw. // brush(brushnum) -- set current brush from menu order class BrushFunc : public UnidrawFunc { *************** *** 160,165 **** --- 171,188 ---- virtual const char* docstring() { return "%s(fgcolornum bgcolornum) -- set current colors from menu order"; } }; + + //SECIL + //:comand for setting color state variables by RGB name in comdraw. + // colors(fgcolorname bgcolorname). The colorname format is "#RRGGBB" + class ColorRgbFunc : public UnidrawFunc { + public: + ColorRgbFunc(ComTerp*,Editor*); + virtual void execute(); + virtual const char* docstring() { + return "%s(fgcolorname bgcolorname) -- set current colors by RGB name. The colorname format is \"#RGB\" for 4 bits, \"#RRGGBB\" for 8 bits,\"#RRRGGGBBB\" for 12 bits,\"#RRRRGGGGBBBB\" for 16 bits"; } + }; + //SECIL //: command to select graphics in comdraw. // select([compview ...] :all :clear) -- make these graphics the current selection, Index: ComUnidraw/pixelfunc.c diff -c ComUnidraw/pixelfunc.c:1.1 ComUnidraw/pixelfunc.c:1.2 *** ComUnidraw/pixelfunc.c:1.1 Fri Sep 13 09:51:34 2002 --- src/ComUnidraw/pixelfunc.c Fri Sep 13 12:19:22 2002 *************** *** 28,33 **** --- 28,86 ---- #include <Unidraw/iterator.h> #include <Unidraw/viewer.h> #include <Attribute/attrlist.h> + //SECIL + #include <IV-2_6/InterViews/world.h> + /*****************************************************************************/ + PixelPokeLineFunc::PixelPokeLineFunc(ComTerp* comterp, Editor* ed) : UnidrawFunc(comterp, ed) { + } + + void PixelPokeLineFunc::execute() { + Viewer* viewer = _ed->GetViewer(); + + ComValue rastcompv(stack_arg(0)); + ComValue xv(stack_arg(1)); + ComValue yv(stack_arg(2)); + ComValue wv(stack_arg(3)); + ComValue vallistv(stack_arg(4)); + int xval = xv.int_val(); + int yval = yv.int_val(); + int wval = wv.int_val(); + int pixelvals[wval]; + + if(!vallistv.is_type(ComValue::ArrayType) || vallistv.array_len() != wval){ + reset_stack(); + push_stack(ComValue::nullval()); + return; + } + + ALIterator i; + AttributeValueList* avl = vallistv.array_val(); + avl->First(i); + for (int j=0; j<wval && !avl->Done(i); j++){ + pixelvals[j]= avl->GetAttrVal(i)->int_val(); + avl->Next(i); + } + reset_stack(); + + RasterOvComp* rastcomp = (RasterOvComp*) rastcompv.geta(RasterOvComp::class_symid()); + OverlayRasterRect* rastrect = rastcomp ? rastcomp->GetOverlayRasterRect() : nil; + OverlayRaster* raster = rastrect ? rastrect->GetOriginal() : nil; + + if (raster) { + for(int j=0; j<wval; j++){ + ColorIntensity r,g,b; + int pixelcolor = pixelvals[j]; + char colorname[7]; + sprintf(colorname,"#%06x",pixelcolor); + Color::find(World::current()->display(),colorname, r, g, b); + raster->poke(xval+j, yval, r, g, b, 1.0); + } + push_stack(rastcompv); + } + else + push_stack(ComValue::nullval()); + } + //SECIL /*****************************************************************************/ Index: ComUnidraw/pixelfunc.h diff -c ComUnidraw/pixelfunc.h:1.1 ComUnidraw/pixelfunc.h:1.2 *** ComUnidraw/pixelfunc.h:1.1 Fri Sep 13 09:51:34 2002 --- src/ComUnidraw/pixelfunc.h Fri Sep 13 12:19:23 2002 *************** *** 26,31 **** --- 26,46 ---- #include <ComUnidraw/unifunc.h> + //SECIL + //: command to poke a line of pixel values into raster + // pokeline(compview x y w vallist) -- poke pixel values of a line listed in vallist into raster. w is the width of the line(length of the list). + + class PixelPokeLineFunc : public UnidrawFunc { + public: + PixelPokeLineFunc(ComTerp*,Editor*); + virtual void execute(); + virtual const char* docstring() { + return "%s(compview x y w vallist) -- poke pixel values of a line listed in vallist into raster. w is the width of the line(length of the list)"; + } + }; + + //SECIL + //: command to poke pixel values into raster // poke(compview x y val) -- poke pixel value into raster class PixelPokeFunc : public UnidrawFunc { *** /dev/null Fri Sep 13 12:19:52 PDT 2002 --- patches/ivtools-020913-johnston-066 *************** patches/ivtools-020913-johnston-066 *** 0 **** --- 1 ---- + ivtools-020913-johnston-066 ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf