1 /* This file is only for testing purposes. it replaces swfoutput.cc, and dumps
2 the information it gets into an X11 Window, not into an swf.
4 Copyright (c) 2001 Matthias Kramm <kramm@quiss.org>
6 This file is distributed under the GPL, see file COPYING for details */
10 #include "kramm/xwindows.h"
16 void inline pp(int x,int y)
23 void circle(int mx,int my,int r)
53 void qspline(plotxy p0,plotxy p1,plotxy p2)
56 //vga->setcolor(0x0000ff);
57 for(d=0.00;d<=1.00;d+=0.001) {
58 int x = (int)(p0.x * d*d + p1.x * 2*(1-d)*d + p2.x * (1-d)*(1-d));
59 int y = (int)(p0.y * d*d + p1.y * 2*(1-d)*d + p2.y * (1-d)*(1-d));
63 void transform (plotxy*p0,struct swfmatrix*m)
66 x = m->m11*p0->x+m->m12*p0->y;
67 y = m->m21*p0->x+m->m22*p0->y;
74 void spline(plotxy p0,plotxy p1,plotxy p2,plotxy p3,struct swfmatrix*m)
84 //vga->setcolor(0xffff00);
85 //vga->drawline(p3.x,p3.y,p2.x,p2.y);
86 //vga->drawline(p2.x,p2.y,p1.x,p1.y);
87 //vga->drawline(p1.x,p1.y,p0.x,p0.y);
89 /* vga->setcolor(0x00ff00);
93 circle(p3.x,p3.y,5);*/
95 /* vga->setcolor(0xff00ff);
96 for(d=0.00;d<1.00;d+=0.001) {
97 int x = (int)(p0.x * d*d*d + p1.x * 3*(1-d)*d*d + p2.x * 3*(1-d)*(1-d)*d + p3.x * (1-d)*(1-d)*(1-d));
98 int y = (int)(p0.y * d*d*d + p1.y * 3*(1-d)*d*d + p2.y * 3*(1-d)*(1-d)*d + p3.y * (1-d)*(1-d)*(1-d));
102 num = approximate(p0,p1,p2,p3,q);
105 qspline(q[t].start,q[t].control,q[t].end);
108 void line(plotxy p0, plotxy p1, struct swfmatrix*m)
112 vga->drawline((int)p0.x,(int)p0.y,(int)p1.x,(int)p1.y);
115 void swfoutput_drawpath(swfoutput*output, T1_OUTLINE*outline, struct swfmatrix*m)
118 double lastx=0,lasty=0;
120 vga->setcolor(0xffffff);
123 logf("<debug> Pathtype:%s",outline->type == T1_PATHTYPE_MOVE?"MOVE":
124 (outline->type == T1_PATHTYPE_LINE?"LINE"
126 logf("<debug> relative coordinates: %08x,%08x", outline->dest.x, outline->dest.y);
127 x += (outline->dest.x/(float)0xffff);
128 y += (outline->dest.y/(float)0xffff);
129 logf("<debug> coordinates: %f,%f", x, y);
130 if(outline->type == T1_PATHTYPE_MOVE)
133 else if(outline->type == T1_PATHTYPE_LINE)
143 else if(outline->type == T1_PATHTYPE_BEZIER)
149 T1_BEZIERSEGMENT*o2 = (T1_BEZIERSEGMENT*)outline;
152 p1.x=o2->C.x/(float)0xffff+lastx;
153 p1.y=o2->C.y/(float)0xffff+lasty;
154 p2.x=o2->B.x/(float)0xffff+lastx;
155 p2.y=o2->B.y/(float)0xffff+lasty;
158 spline(p0,p1,p2,p3,m);
159 // vga->drawline(320+lastx, 240+lasty, 320+x, 240+y);
162 printf("outline type:%d\n", outline->type);
167 outline = outline->link;
172 void processchar(struct swfoutput*obj, int i, char c, swfmatrix*m)
175 int width = T1_GetCharWidth(i, c);
176 BBox bbox = T1_GetCharBBox(i, c);
177 char*charname= T1_GetCharName(i, c);
178 logf("<debug> Font name is %s", T1_GetFontFileName(i));
179 logf("<debug> char 0x%02x is named %s\n",c,charname);
180 logf("<debug> bbox: %d %d %d %d\n",bbox.llx,bbox.lly,bbox.urx,bbox.ury);
181 if(!charname || charname[0] == '.')
183 logf("<error> Char to set is not defined!");
184 logf("<error> - font file is %s\n", T1_GetFontFileName(i));
185 logf("<error> - char 0x%02x is named %s\n",c,charname);
192 outline = T1_GetCharOutline( i, c, 100.0, 0);
193 swfoutput_drawpath(obj, outline, &m2);
196 void swfoutput_init(struct swfoutput* obj, int sizex, int sizey)
201 logf("<verbose> initializing swf output for size %d*%d\n", sizex,sizey);
203 vga=new modexwindow(sizex,sizey,"");
205 if(!vga->on()) exit(1);
206 vga->setcolor(0xff00ff);
209 obj->t1fontsize = 0.0025;
212 int swfoutput_setfont(struct swfoutput*obj, int t1id)
217 void swfoutput_setfontsize(struct swfoutput* obj, double size)
219 obj->t1fontsize = size;
222 void swfoutput_setfontmatrix(struct swfoutput*obj,double m11,double m12,
223 double m21,double m22)
231 void swfoutput_drawchar(struct swfoutput* obj,double x,double y,char a)
234 m.m11 = obj->fontm11*obj->t1fontsize;
235 m.m12 = obj->fontm12*obj->t1fontsize;
236 m.m21 = obj->fontm21*obj->t1fontsize;
237 m.m22 = obj->fontm22*obj->t1fontsize;
240 processchar(obj, obj->t1font, a, &m);
243 void swfoutput_destroy(struct swfoutput* obj)