From d3c1c8d663e46c5cffed480115902d82e5cf5645 Mon Sep 17 00:00:00 2001 From: boehme Date: Thu, 15 Nov 2001 21:01:53 +0000 Subject: [PATCH] new example: glyphshape.c --- lib/example/Makefile | 13 ++-- lib/example/glyphshape.c | 162 ++++++++++++++++++++++++++++++++++++++++++++++ release.in | 1 + 3 files changed, 172 insertions(+), 4 deletions(-) create mode 100644 lib/example/glyphshape.c diff --git a/lib/example/Makefile b/lib/example/Makefile index 896d783..e12c49b 100644 --- a/lib/example/Makefile +++ b/lib/example/Makefile @@ -12,11 +12,12 @@ DBFLAGS = -g2 %.o: %.cc $(CXX) -c $(CFLAGS) $(DBFLAGS) -o $@ $< -all: jpegtest box shape1 transtest zlibtest sprites buttontest dumpfont text makefonts +all: jpegtest box shape1 transtest zlibtest sprites buttontest dumpfont text makefonts glyphshape -movies: jpegtest box shape1 transtest zlibtest sprites buttontest dumpfont text +movies: jpegtest box shape1 transtest zlibtest sprites buttontest dumpfont text glyphshape ./jpegtest ./box + ./glyphshape ./shape1 ./transtest ./zlibtest @@ -34,6 +35,9 @@ buttontest: $(RFXSWF) buttontest.o dumpfont: $(RFXSWF) dumpfont.o $(CC) -o dumpfont dumpfont.o $(RFXSWF) $(LDLIBS) $(DBFLAGS) +glyphshape: $(RFXSWF) glyphshape.o + $(CC) -o glyphshape glyphshape.o $(RFXSWF) $(LDLIBS) $(DBFLAGS) + jpegtest: $(RFXSWF) jpegtest.o $(CC) -o jpegtest jpegtest.o $(RFXSWF) $(LDLIBS) $(DBFLAGS) @@ -58,9 +62,10 @@ makefonts: $(RFXSWF) makefonts.o ../../pdf2swf/swfoutput.o ../../pdf2swf/xpdf/libpdf.a $(DBFLAGS) clean: - rm -f jpegtest.o box.o shape1.o transtest.o zlibtest.o sprites.o\ + rm -f jpegtest.o box.o shape1.o transtest.o zlibtest.o \ + sprites.o glyphshape.o \ buttontest.o dumpfont.o text.o makefonts.o\ jpegtest.swf box.swf shape1.swf trastest.swf zlibtest.swf \ - sprites.swf buttontest.swf text.swf + sprites.swf buttontest.swf text.swf glyphshape.swf diff --git a/lib/example/glyphshape.c b/lib/example/glyphshape.c new file mode 100644 index 0000000..0263ca0 --- /dev/null +++ b/lib/example/glyphshape.c @@ -0,0 +1,162 @@ +/* glyphshape.c + + Part of the swftools package. + + Copyright (c) 2001 Rainer Böhme + + This file is distributed under the GPL, see file COPYING for details + +*/ + +#include +#include +#include +#include "../rfxswf.h" + +#include "demofont.c" // six glyphs only: f, l, o, s, t, w +//#include "stdfonts.c" + +#define BANNER_TEXT "swftools" +#define ID_FONT 1000 +#define ID_SHAPES 2000 // to 2255 + +TAG * PlaceGlyph(TAG * t,SWFFONT * font,U8 glyph,U16 depth,int x,int y,int angle) +{ MATRIX m; + t = swf_InsertTag(t,ST_PLACEOBJECT2); + + swf_GetMatrix(NULL,&m); + + if (angle) + { m.sy = m.sx = (int)(cos(((double)(angle))/128*3.14159)*0x10000); + m.r0 = (int)(sin(((double)(angle))/128*3.14159)*0x10000); + m.r1 = -m.r0; + } + else m.sx = m.sy = 0x10000; + + // move origin + + m.tx = x+((m.r1-m.sx)/0x100); // this is correct + m.ty = y+((m.sx-m.r0)/0x100); + +// m.tx = x+((m.r1-m.sx)/0x40); // this looks crazier ;-) +// m.ty = y+((m.sx-m.r0)/0x40); + + + if (font) + swf_ObjectPlace(t,ID_SHAPES+glyph,depth,&m,NULL,NULL); + else swf_ObjectMove(t,depth,&m,NULL); + + return t; +} + +// some helper functions which define the figure + +int posX(int count) +{ return (int)(-sin(((double)count)/1024*3.14159)*3000); +} +int posY(int count) +{ return (int)(sin(((double)count)/2048*3.14159)*3200); +} +int angle(int count) +{ return (int)(pow(cos(((double)count)/2048*3.14159),3)*110); + // this is not the mathematical correct solution, but it works & looks nice +} + +int main(int argc, char ** argv) +{ SWF swf; + TAG * t; + SRECT r; + RGBA rgb; + MATRIX m; + U8 abits, gbits; + + int f,i,frame; + int width = 400; + int height = 400; + char * s = BANNER_TEXT; + + FONTUSAGE use; + SWFFONT * font = Font_Demo_Font(ID_FONT); // change font name here + + swf_FontInitUsage(&use); + swf_FontUse(&use,s); + swf_FontReduce(font,&use); // make sure that gid's point to the specific glyphs + + memset(&swf,0x00,sizeof(SWF)); + + swf.fileVersion = 4; + swf.frameRate = 0x1000; + swf.movieSize.xmax = 20*width; + swf.movieSize.ymax = 20*height; + + swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR); + t = swf.firstTag; + + rgb.r = 0xff; + rgb.g = 0xff; + rgb.b = 0xff; + swf_SetRGB(t,&rgb); + + // define Glyph Shapes + + for (i=0;inumchars;i++) + { if (font->glyph[i].shape) + { SHAPE * s; + int fs; + + t = swf_InsertTag(t,ST_DEFINESHAPE); + + swf_ShapeNew(&s); + + rgb.r = rgb.g = rgb.b = i; + + swf_ShapeAddSolidFillStyle(s,&rgb); + + swf_SetU16(t,ID_SHAPES+i); + + r.xmin = -50*20; r.ymin = -50*20; // Glyph Shapes are placed into a 2000*2000 box + r.ymax = 50*20; r.xmax = 50*20; // where (1000,1000) is the origin + + swf_SetRect(t,&r); + + swf_SetShapeStyles(t,s); // rest of header is set by swf_SetSimpleShape + swf_SetSimpleShape(t,font->glyph[i].shape); + swf_ShapeFree(s); + + } + } + + for (frame=0;frame<128;frame++) + { int cnt = 4096-frame*32; + for (i=0;iascii2glyph[s[i]]; + int advance = font->glyph[glyph].advance/2; + int cnt2 = cnt+=advance/2; + t = PlaceGlyph(t,frame?NULL:font,glyph,i+1, + 200*20+posX(cnt2), + 200*20+posY(cnt2), + angle(cnt2)); + cnt+=advance; + } + t = swf_InsertTag(t,ST_SHOWFRAME); + } + + + t = swf_InsertTag(t,ST_END); + +// swf_WriteCGI(&swf); + + f = open("glyphshape.swf",O_RDWR|O_CREAT|O_TRUNC,0644); + if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n"); + close(f); + + swf_FreeTags(&swf); + +#ifdef __NT__ + system("start ..\\glyphshape.swf"); +#endif + + return 0; +} + + diff --git a/release.in b/release.in index 1eed199..a9c5def 100644 --- a/release.in +++ b/release.in @@ -37,6 +37,7 @@ ${name}/lib/example/sprites.c \ ${name}/lib/example/transtest.c \ ${name}/lib/example/zlibtest.c \ ${name}/lib/example/makefonts.cc \ +${name}/lib/example/glyphshape.c \ ${name}/lib/example/Makefile \ ${name}/lib/modules/swfaction.c \ ${name}/lib/modules/swfdump.c \ -- 1.7.10.4