fontlist_t*next;
};
+double config_dumpfonts=0;
double config_ppmsubpixels=0;
double config_jpegsubpixels=0;
-int config_opennewwindow=0;
+int config_opennewwindow=1;
int config_ignoredraworder=0;
int config_drawonlyshapes=0;
int config_jpegquality=85;
int config_fontsplinemaxerror=1;
int config_filloverlap=0;
int config_protect=0;
+int config_bboxvars=0;
float config_minlinewidth=0.05;
double config_caplinewidth=1;
int firstpage;
char pagefinished;
+ char overflow;
+
/* during the transition to the gfxdevice interface:
a device which uses this swfoutput as target */
gfxdevice_t device;
void swf_stroke(gfxdevice_t*dev, gfxline_t*line, gfxcoord_t width, gfxcolor_t*color, gfx_capType cap_style, gfx_joinType joint_style, gfxcoord_t miterLimit);
void swf_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color);
void swf_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform);
-void swf_fillgradient(gfxdevice_t*dev, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix);
+void swf_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix);
+void swf_drawchar(gfxdevice_t*dev, char*fontid, int glyph, gfxcolor_t*color, gfxmatrix_t*matrix);
+void swf_addfont(gfxdevice_t*dev, char*fontid, gfxfont_t*font);
+
+int getCharID(SWFFONT *font, int charnr, char *charname, int u);
static swfoutput_internal* init_internal_struct()
{
i->storefont = 0;
i->currentswfid = 0;
- i->depth = 1;
- i->startdepth = 1;
+ i->depth = 0;
+ i->overflow = 0;
+ i->startdepth = 0;
i->linewidth = 0;
i->shapeid = -1;
i->textid = -1;
i->device.fill = swf_fill;
i->device.fillbitmap = swf_fillbitmap;
i->device.fillgradient = swf_fillgradient;
+ i->device.addfont = swf_addfont;
+ i->device.drawchar = swf_drawchar;
return i;
};
+static int id_error = 0;
+
+static U16 getNewID(struct swfoutput* obj)
+{
+ swfoutput_internal*i = (swfoutput_internal*)obj->internal;
+ if(i->currentswfid == 65535) {
+ if(!id_error)
+ msg("<error> ID Table overflow");
+ id_error=1;
+ i->overflow = 1;
+ }
+ return ++i->currentswfid;
+}
+static U16 getNewDepth(struct swfoutput* obj)
+{
+ swfoutput_internal*i = (swfoutput_internal*)obj->internal;
+ if(i->depth == 65535) {
+ if(!id_error)
+ msg("<error> Depth Table overflow");
+ id_error=1;
+ i->overflow = 1;
+ }
+ return ++i->depth;
+}
+
static void startshape(struct swfoutput* obj);
static void starttext(struct swfoutput* obj);
static void endshape(struct swfoutput* obj);
double x,y;
x = m->m11*p0->x+m->m12*p0->y;
y = m->m21*p0->x+m->m22*p0->y;
- p0->x = x + m->m13;
- p0->y = y + m->m23;
+ p0->x = x + m->m31;
+ p0->y = y + m->m32;
}
// write a move-to command into the swf
}
return 0;
}
-static int moveto(struct swfoutput*obj, TAG*tag, float x, float y)
+static int moveto(struct swfoutput*obj, TAG*tag, double x, double y)
{
swfoutput_internal*i = (swfoutput_internal*)obj->internal;
plotxy p;
}
}
-static void plot(struct swfoutput*obj, int x, int y, TAG*tag)
+/*static void plot(struct swfoutput*obj, int x, int y, TAG*tag)
{
swfoutput_internal*i = (swfoutput_internal*)obj->internal;
- int width = 3;
- swf_ShapeSetLine(tag, i->shape,-width,-width);
- swf_ShapeSetLine(tag, i->shape,width*2,0);
- swf_ShapeSetLine(tag, i->shape,0,width*2);
- swf_ShapeSetLine(tag, i->shape,-width*2,0);
- swf_ShapeSetLine(tag, i->shape,0,-width*2);
+ int width = i->linewidth/4;
+ if(width > 5)
+ width = 5;
+ ////square
+ //swf_ShapeSetLine(tag, i->shape,-width,-width);
+ //swf_ShapeSetLine(tag, i->shape,width*2,0);
+ //swf_ShapeSetLine(tag, i->shape,0,width*2);
+ //swf_ShapeSetLine(tag, i->shape,-width*2,0);
+ //swf_ShapeSetLine(tag, i->shape,0,-width*2);
+ //swf_ShapeSetLine(tag, i->shape,width,width);
+
+ // diamond
+ swf_ShapeSetLine(tag, i->shape,-width,0);
+ swf_ShapeSetLine(tag, i->shape,width,-width);
swf_ShapeSetLine(tag, i->shape,width,width);
- addPointToBBox(obj, x ,y );
- addPointToBBox(obj, x+1 ,y+1 );
-}
+ swf_ShapeSetLine(tag, i->shape,-width,width);
+ swf_ShapeSetLine(tag, i->shape,-width,-width);
+ swf_ShapeSetLine(tag, i->shape,width,0);
+
+ addPointToBBox(obj, x-width ,y-width);
+ addPointToBBox(obj, x+width ,y+width);
+}*/
// write a line-to command into the swf
-static void lineto(struct swfoutput*obj, TAG*tag, plotxy p0, char issolesegment)
+static void lineto(struct swfoutput*obj, TAG*tag, plotxy p0)
{
swfoutput_internal*i = (swfoutput_internal*)obj->internal;
int px = (int)(p0.x*20);
swf_ShapeSetLine (tag, i->shape, rx,ry);
addPointToBBox(obj, i->swflastx,i->swflasty);
addPointToBBox(obj, px,py);
- } else if(issolesegment && !i->fill) {
- /* treat lines of length 0 as plots, making them
- at least 1 twip wide so Flash will display them */
+ }/* else if(!i->fill) {
+ // treat lines of length 0 as plots, making them
+ // at least 1 twip wide so Flash will display them
plot(obj, i->swflastx, i->swflasty, tag);
- }
+ }*/
i->shapeisempty = 0;
i->swflastx+=rx;
i->swflasty+=ry;
}
-static void lineto(struct swfoutput*obj, TAG*tag, double x, double y, char issolesegment)
+static void lineto(struct swfoutput*obj, TAG*tag, double x, double y)
{
plotxy p;
p.x = x;
p.y = y;
- lineto(obj,tag, p, issolesegment);
+ lineto(obj,tag, p);
}
// write a spline-to command into the swf
-static void splineto(struct swfoutput*obj, TAG*tag, plotxy control,plotxy end, char issolesegment)
+static void splineto(struct swfoutput*obj, TAG*tag, plotxy control,plotxy end)
{
swfoutput_internal*i = (swfoutput_internal*)obj->internal;
int lastlastx = i->swflastx;
addPointToBBox(obj, lastlastx ,lastlasty );
addPointToBBox(obj, lastlastx+cx,lastlasty+cy);
addPointToBBox(obj, lastlastx+cx+ex,lastlasty+cy+ey);
- } else if(issolesegment && !i->fill) {
- /* treat splines of length 0 as plots */
+ }/* else if(!i->fill) {
+ // treat splines of length 0 as plots
plot(obj, lastlastx, lastlasty, tag);
- }
+ }*/
i->shapeisempty = 0;
}
/*static void line(struct swfoutput*obj, TAG*tag, plotxy p0, plotxy p1)
{
moveto(obj, tag, p0);
- lineto(obj, tag, p1, 0);
+ lineto(obj, tag, p1);
}*/
void resetdrawer(struct swfoutput*obj)
If we set it to low, however, the char positions will be inaccurate */
#define FONT_INTERNAL_SIZE 4
+static int font_active = 0;
+static char* font_active_filename = 0;
+
/* process a character. */
static int drawchar(struct swfoutput*obj, SWFFONT *swffont, char*character, int charnr, int u, swfmatrix*m, gfxcolor_t*col)
{
}
int charid = getCharID(swffont, charnr, character, u);
+ if(font_active) {
+ char buf[1024];
+ sprintf(buf, "%s.usage", font_active_filename);
+ FILE*fi = fopen(buf, "ab+");
+ if(fi) {
+ fprintf(fi, "%d %d %d %s\n", charnr, u, charid, character);
+ fclose(fi);
+ } else
+ msg("<error> Couldn't write to %s", buf);
+ }
if(charid<0) {
msg("<warning> Didn't find character '%s' (c=%d,u=%d) in current charset (%s, %d characters)",
FIXNULL(character),charnr, u, FIXNULL((char*)swffont->name), swffont->numchars);
return 0;
}
+ /*if(swffont->glyph[charid].shape->bitlen <= 16) {
+ msg("<warning> Character '%s' (c=%d,u=%d), glyph %d in current charset (%s, %d characters) is empty",
+ FIXNULL(character),charnr, u, charid, FIXNULL((char*)swffont->name), swffont->numchars);
+ return 0;
+ }*/
+
if(i->shapeid>=0)
endshape(obj);
if(i->textid<0)
starttext(obj);
- float x = m->m13;
- float y = m->m23;
+ float x = m->m31;
+ float y = m->m32;
float det = ((m->m11*m->m22)-(m->m21*m->m12));
if(fabs(det) < 0.0005) {
/* x direction equals y direction- the text is invisible */
swf_GetMatrix(0, &m); /* set unit matrix- the real matrix is in the placeobject */
swf_SetMatrix(i->tag,&m);
+ msg("<trace> Placing text (%d characters) as ID %d", i->chardatapos, i->textid);
+
putcharacters(obj, i->tag);
swf_SetU8(i->tag,0);
i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
- //swf_ObjectPlace(i->tag,i->textid,/*depth*/i->depth++,&i->page_matrix,NULL,NULL);
MATRIX m2;
swf_MatrixJoin(&m2,&obj->fontmatrix, &i->page_matrix);
- swf_ObjectPlace(i->tag,i->textid,/*depth*/i->depth++,&m2,NULL,NULL);
+ swf_ObjectPlace(i->tag,i->textid,getNewDepth(obj),&m2,NULL,NULL);
i->textid = -1;
}
return -1;
}
-
/* set's the t1 font index of the font to use for swfoutput_drawchar(). */
void swfoutput_setfont(struct swfoutput*obj, char*fontid, char*filename)
{
swfoutput_internal*i = (swfoutput_internal*)obj->internal;
+ font_active = 0;
fontlist_t*last=0,*iterator;
if(!fontid) {
msg("<error> No fontid");
swf_SetLoadFontParameters(64,/*skip unused*/0,/*full unicode*/1);
SWFFONT*swffont = swf_LoadFont(filename);
+ if(config_dumpfonts) {
+ font_active = 1;
+ font_active_filename = strdup(filename);
+ }
+
if(swffont == 0) {
msg("<warning> Couldn't load font %s (%s)", fontid, filename);
swffont = swf_LoadFont(0);
swffont->encoding = 255;
}
}
+
+ if(swffont->encoding != FONT_ENCODING_UNICODE && swffont->encoding != 255) {
+ msg("<warning> Non-unicode mapping for font %s (%s)", fontid, filename);
+ }
- swf_FontSetID(swffont, ++i->currentswfid);
+ swf_FontSetID(swffont, getNewID(obj));
if(getScreenLogLevel() >= LOGLEVEL_DEBUG) {
// print font information
- msg("<debug> Font %s (%s)",swffont->name, filename);
+ msg("<debug> Font %s (%s)",fontid, filename);
msg("<debug> | ID: %d", swffont->id);
msg("<debug> | Version: %d", swffont->version);
- msg("<debug> | Name: %s", fontid);
+ msg("<debug> | Name: %s", swffont->name);
msg("<debug> | Numchars: %d", swffont->numchars);
msg("<debug> | Maxascii: %d", swffont->maxascii);
msg("<debug> | Style: %d", swffont->style);
/* set's the matrix which is to be applied to characters drawn by
swfoutput_drawchar() */
-void swfoutput_setfontmatrix(struct swfoutput*obj,double m11,double m12,
- double m21,double m22)
+void swfoutput_setfontmatrix(struct swfoutput*obj,double m11,double m21,
+ double m12,double m22)
{
+ m11 *= 1024;
+ m12 *= 1024;
+ m21 *= 1024;
+ m22 *= 1024;
swfoutput_internal*i = (swfoutput_internal*)obj->internal;
if(obj->fontm11 == m11 &&
obj->fontm12 == m12 &&
m.m12 = obj->fontm12;
m.m21 = obj->fontm21;
m.m22 = obj->fontm22;
- m.m13 = x;
- m.m23 = y;
+ m.m31 = x;
+ m.m32 = y;
return drawchar(obj, obj->swffont, character, charnr, u, &m, color);
}
i->tag = swf_InsertTag(i->tag,ST_SHOWFRAME);
i->frameno ++;
- for(i->depth--;i->depth>=i->startdepth;i->depth--) {
+ for(i->depth;i->depth>i->startdepth;i->depth--) {
i->tag = swf_InsertTag(i->tag,ST_REMOVEOBJECT2);
swf_SetU16(i->tag,i->depth);
}
SRECT r;
SHAPE* s;
int ls1=0,fs1=0;
- int shapeid = ++i->currentswfid;
+ int shapeid = getNewID(obj);
r.xmin = x1;
r.ymin = y1;
r.xmax = x2;
swf_ShapeSetEnd(i->tag);
swf_ShapeFree(s);
i->tag = swf_InsertTag(i->tag, ST_PLACEOBJECT2);
- swf_ObjectPlace(i->tag,shapeid,i->depth++,0,0,0);
+ swf_ObjectPlace(i->tag,shapeid,getNewDepth(obj),0,0,0);
i->tag = swf_InsertTag(i->tag, ST_PLACEOBJECT2);
- swf_ObjectPlaceClip(i->tag,shapeid,i->depth++,0,0,0,65535);
+ swf_ObjectPlaceClip(i->tag,shapeid,getNewDepth(obj),0,0,0,65535);
i->cliptag = i->tag;
}
if(i->cliptag && i->frameno == i->lastframeno) {
SWFPLACEOBJECT obj;
swf_GetPlaceObject(i->cliptag, &obj);
- obj.clipdepth = i->depth++;
+ obj.clipdepth = i->depth;
swf_ResetTag(i->cliptag, i->cliptag->id);
swf_SetPlaceObject(i->cliptag, &obj);
swf_PlaceObjectFree(&obj);
rgb.a = rgb.r = rgb.g = rgb.b = 0xff;
swf_SetRGB(i->tag,&rgb);
- i->startdepth = i->depth = 3; /* leave room for clip and background rectangle */
+ i->startdepth = i->depth = 0;
if(config_protect)
i->tag = swf_InsertTag(i->tag, ST_PROTECT);
i->linestyleid = swf_ShapeAddLineStyle(i->shape,i->linewidth,&obj->strokergb);
i->fillstyleid = swf_ShapeAddSolidFillStyle(i->shape,&obj->fillrgb);
- i->shapeid = ++i->currentswfid;
+ i->shapeid = getNewID(obj);
msg("<debug> Using shape id %d", i->shapeid);
if(i->shapeid>=0)
endshape(obj);
- i->textid = ++i->currentswfid;
+ i->textid = getNewID(obj);
i->swflastx=i->swflasty=0;
}
startshape(obj);
moveto(obj, i->tag, r.xmin/20.0,r.ymin/20.0);
- lineto(obj, i->tag, r.xmax/20.0,r.ymax/20.0, 0);
+ lineto(obj, i->tag, r.xmax/20.0,r.ymax/20.0);
obj->strokergb = save_col;
i->linewidth = save_width;
msg("<trace> Placing shape id %d", i->shapeid);
i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
- swf_ObjectPlace(i->tag,i->shapeid,/*depth*/i->depth++,&i->page_matrix,NULL,NULL);
+ swf_ObjectPlace(i->tag,i->shapeid,getNewDepth(obj),&i->page_matrix,NULL,NULL);
swf_ShapeFree(i->shape);
i->shape = 0;
}*/
}
+void wipeSWF(SWF*swf)
+{
+ TAG*tag = swf->firstTag;
+ while(tag) {
+ TAG*next = tag->next;
+ if(tag->id != ST_SETBACKGROUNDCOLOR &&
+ tag->id != ST_END &&
+ tag->id != ST_DOACTION &&
+ tag->id != ST_SHOWFRAME) {
+ swf_DeleteTag(tag);
+ }
+ tag = next;
+ }
+}
+
+
void swfoutput_finalize(struct swfoutput*obj)
{
swfoutput_internal*i = (swfoutput_internal*)obj->internal;
if(i->tag && i->tag->id == ST_END)
return; //already done
+ if(config_bboxvars) {
+ TAG* tag = swf_InsertTag(i->swf.firstTag, ST_DOACTION);
+ ActionTAG*a = 0;
+ a = action_PushString(a, "xmin");
+ a = action_PushFloat(a, i->swf.movieSize.xmin / 20.0);
+ a = action_SetVariable(a);
+ a = action_PushString(a, "ymin");
+ a = action_PushFloat(a, i->swf.movieSize.ymin / 20.0);
+ a = action_SetVariable(a);
+ a = action_PushString(a, "xmax");
+ a = action_PushFloat(a, i->swf.movieSize.xmax / 20.0);
+ a = action_SetVariable(a);
+ a = action_PushString(a, "ymax");
+ a = action_PushFloat(a, i->swf.movieSize.ymax / 20.0);
+ a = action_SetVariable(a);
+ a = action_PushString(a, "width");
+ a = action_PushFloat(a, (i->swf.movieSize.xmax - i->swf.movieSize.xmin) / 20.0);
+ a = action_SetVariable(a);
+ a = action_PushString(a, "height");
+ a = action_PushFloat(a, (i->swf.movieSize.ymax - i->swf.movieSize.ymin) / 20.0);
+ a = action_SetVariable(a);
+ a = action_End(a);
+ swf_ActionSet(tag, a);
+ swf_ActionFree(a);
+ }
+
if(i->frameno == i->lastframeno) // fix: add missing pagefeed
swfoutput_pagefeed(obj);
TAG*mtag = i->swf.firstTag;
if(iterator->swffont) {
mtag = swf_InsertTag(mtag, ST_DEFINEFONT2);
- /*if(!storeallcharacters)
- swf_FontReduce(iterator->swffont);*/
+ if(!config_storeallcharacters)
+ swf_FontReduce(iterator->swffont);
swf_FontSetDefine2(mtag, iterator->swffont);
}
swf_DeleteTag(tag);
tag = prev;
}
+
+ if(i->overflow) {
+ wipeSWF(&i->swf);
+ }
}
SWF* swfoutput_get(struct swfoutput*obj)
if(filename)
close(fi);
- msg("<notice> SWF written\n");
return 1;
}
if(i->textid>=0)
endtext(obj);
- if(config_opennewwindow)
+ if(!config_opennewwindow)
actions = action_GetUrl(0, url, "_parent");
else
actions = action_GetUrl(0, url, "_this");
double posx = 0;
double posy = 0;
int t;
- int buttonid = ++i->currentswfid;
+ int buttonid = getNewID(obj);
for(t=1;t<4;t++)
{
if(points[t].x>xmax) xmax=points[t].x;
xmax -= posx; ymax -= posy;
/* shape */
- myshapeid = ++i->currentswfid;
+ myshapeid = getNewID(obj);
i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE3);
swf_ShapeNew(&i->shape);
rgb.r = rgb.b = rgb.a = rgb.g = 0;
swf_ShapeSetAll(i->tag,i->shape,/*x*/0,/*y*/0,0,fsid,0);
i->swflastx = i->swflasty = 0;
moveto(obj, i->tag, p1);
- lineto(obj, i->tag, p2, 0);
- lineto(obj, i->tag, p3, 0);
- lineto(obj, i->tag, p4, 0);
- lineto(obj, i->tag, p1, 0);
+ lineto(obj, i->tag, p2);
+ lineto(obj, i->tag, p3);
+ lineto(obj, i->tag, p4);
+ lineto(obj, i->tag, p1);
swf_ShapeSetEnd(i->tag);
/* shape2 */
- myshapeid2 = ++i->currentswfid;
+ myshapeid2 = getNewID(obj);
i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE3);
swf_ShapeNew(&i->shape);
rgb.r = rgb.b = rgb.a = rgb.g = 255;
swf_ShapeSetAll(i->tag,i->shape,/*x*/0,/*y*/0,0,fsid,0);
i->swflastx = i->swflasty = 0;
moveto(obj, i->tag, p1);
- lineto(obj, i->tag, p2, 0);
- lineto(obj, i->tag, p3, 0);
- lineto(obj, i->tag, p4, 0);
- lineto(obj, i->tag, p1, 0);
+ lineto(obj, i->tag, p2);
+ lineto(obj, i->tag, p3);
+ lineto(obj, i->tag, p4);
+ lineto(obj, i->tag, p1);
swf_ShapeSetEnd(i->tag);
if(!mouseover)
m = i->page_matrix;
m.tx = p.x;
m.ty = p.y;
- swf_ObjectPlace(i->tag, buttonid, i->depth++,&m,0,0);
- }
- else {
- swf_ObjectPlace(i->tag, buttonid, i->depth++,&i->page_matrix,0,0);
+ swf_ObjectPlace(i->tag, buttonid, getNewDepth(obj),&m,0,0);
+ } else {
+ swf_ObjectPlace(i->tag, buttonid, getNewDepth(obj),&i->page_matrix,0,0);
}
}
if(!line)
break;
/* check whether the next segment is zero */
- char issolesegment = 0;
- if(lastwasmoveto)
- if(!line->next ||
- (line->next->type == gfx_moveTo) ||
- (line->next->type == gfx_lineTo && fabs(line->next->x - line->x) + fabs(line->next->y - line->y) < 0.01) ||
- (line->next->type == gfx_splineTo && fabs(line->next->x - line->x) + fabs(line->next->y - line->y) + fabs(line->next->sx - line->x) + fabs(line->next->sy - line->y) < 0.01)
- ) {
- issolesegment = 1;
- msg("<trace> is sole segment!");
- }
if(line->type == gfx_moveTo) {
msg("<trace> ======== moveTo %.2f %.2f", line->x, line->y);
moveto(obj, i->tag, line->x, line->y);
lastwasmoveto = 1;
} if(line->type == gfx_lineTo) {
msg("<trace> ======== lineTo %.2f %.2f", line->x, line->y);
- lineto(obj, i->tag, line->x, line->y, issolesegment);
+ lineto(obj, i->tag, line->x, line->y);
px = line->x;
py = line->y;
lastwasmoveto = 0;
plotxy s,p;
s.x = line->sx;p.x = line->x;
s.y = line->sy;p.y = line->y;
- splineto(obj, i->tag, s, p, issolesegment);
+ splineto(obj, i->tag, s, p);
px = line->x;
py = line->y;
lastwasmoveto = 0;
gfxdevice_t*dev = &i->device;
dev->endclip(dev);
}
+void swfoutput_gfxaddfont(struct swfoutput*obj, char*fontid, gfxfont_t*font)
+{
+ swfoutput_internal*i = (swfoutput_internal*)obj->internal;
+ gfxdevice_t*dev = &i->device;
+ dev->addfont(dev, fontid, font);
+}
+void swfoutput_gfxdrawchar(struct swfoutput*obj, char*fontid, int glyph, gfxcolor_t*c, gfxmatrix_t*m)
+{
+ swfoutput_internal*i = (swfoutput_internal*)obj->internal;
+ gfxdevice_t*dev = &i->device;
+ dev->drawchar(dev, fontid, glyph, c, m);
+}
#define IMAGE_TYPE_JPEG 0
#define IMAGE_TYPE_LOSSLESS 1
config_storeallcharacters = atoi(value);
} else if(!strcmp(name, "enablezlib")) {
config_enablezlib = atoi(value);
+ } else if(!strcmp(name, "bboxvars")) {
+ config_bboxvars = atoi(value);
} else if(!strcmp(name, "insertstop")) {
config_insertstoptag = atoi(value);
} else if(!strcmp(name, "protected")) {
config_minlinewidth = atof(value);
} else if(!strcmp(name, "caplinewidth")) {
config_caplinewidth = atof(value);
+ } else if(!strcmp(name, "dumpfonts")) {
+ config_dumpfonts = atoi(value);
} else if(!strcmp(name, "jpegquality")) {
int val = atoi(value);
if(val<0) val=0;
}
}
-
-
+/* TODO */
+static int imageInCache(swfoutput*obj, void*data, int width, int height)
+{
+ return -1;
+}
+static void addImageToCache(swfoutput*obj, void*data, int width, int height)
+{
+}
+
static int add_image(swfoutput_internal*i, gfximage_t*img, int targetwidth, int targetheight, int* newwidth, int* newheight)
{
+ swfoutput*obj = i->obj;
RGBA*newpic = 0;
RGBA*mem = (RGBA*)img->data;
- int bitid = ++i->currentswfid;
int sizex = img->width;
int sizey = img->height;
*newheight = sizey;
if(newsizex<sizex || newsizey<sizey) {
+ msg("<verbose> Scaling %dx%d image to %dx%d", sizex, sizey, newsizex, newsizey);
newpic = swf_ImageScale(mem, sizex, sizey, newsizex, newsizey);
*newwidth = sizex = newsizex;
*newheight = sizey = newsizey;
/*newsizex, newsizey,*/
num_colors>256?">":"", num_colors>256?256:num_colors);
- if(has_alpha) {
- if(num_colors<=256 || sizex<8 || sizey<8) {
- i->tag = swf_InsertTag(i->tag,ST_DEFINEBITSLOSSLESS2);
- swf_SetU16(i->tag, bitid);
- swf_SetLosslessImage(i->tag,mem,sizex,sizey);
- } else {
- /*TODO: check what is smaller */
- i->tag = swf_InsertTag(i->tag,ST_DEFINEBITSJPEG3);
- swf_SetU16(i->tag, bitid);
- swf_SetJPEGBits3(i->tag,sizex,sizey,mem,config_jpegquality);
- //swf_SetLosslessImage(i->tag,mem,sizex,sizey);
- }
+ /*RGBA* pal = (RGBA*)rfx_alloc(sizeof(RGBA)*num_colors);
+ swf_ImageGetNumberOfPaletteEntries(mem,sizex,sizey,pal);
+ int t;
+ for(t=0;t<num_colors;t++) {
+ printf("%02x%02x%02x%02x ",
+ pal[t].r, pal[t].g, pal[t].b, pal[t].a);
+ if((t&7)==7)
+ printf("\n");
+ }
+ printf("\n");*/
+
+ int bitid = -1;
+ int cacheid = imageInCache(obj, mem, sizex, sizey);
+
+ if(cacheid<=0) {
+ bitid = getNewID(obj);
+ i->tag = swf_AddImage(i->tag, bitid, mem, sizex, sizey, config_jpegquality);
+ addImageToCache(obj, mem, sizex, sizey);
} else {
- if(num_colors<=256 || sizex<8 || sizey<8) {
- i->tag = swf_InsertTag(i->tag,ST_DEFINEBITSLOSSLESS);
- swf_SetU16(i->tag, bitid);
- swf_SetLosslessImage(i->tag,mem,sizex,sizey);
- } else {
- /*TODO: check what is smaller */
- i->tag = swf_InsertTag(i->tag,ST_DEFINEBITSJPEG2);
- swf_SetU16(i->tag, bitid);
- swf_SetJPEGBits2(i->tag,sizex,sizey,mem,config_jpegquality);
- //swf_SetLosslessImage(i->tag,mem,sizex,sizey);
- }
+ bitid = cacheid;
}
-
+
if(newpic)
free(newpic);
-
return bitid;
}
m.ty = (int)(matrix->ty*20);
/* shape */
- int myshapeid = ++i->currentswfid;
+ int myshapeid = getNewID(obj);
i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE);
SHAPE*shape;
swf_ShapeNew(&shape);
i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
CXFORM cxform2 = gfxcxform_to_cxform(cxform);
- swf_ObjectPlace(i->tag,myshapeid,/*depth*/i->depth++,&i->page_matrix,&cxform2,NULL);
+ swf_ObjectPlace(i->tag,myshapeid,getNewDepth(obj),&i->page_matrix,&cxform2,NULL);
}
void swf_startclip(gfxdevice_t*dev, gfxline_t*line)
i->clippos --;
}
- int myshapeid = ++i->currentswfid;
+ int myshapeid = getNewID(obj);
i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE);
RGBA col;
memset(&col, 0, sizeof(RGBA));
i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
i->cliptags[i->clippos] = i->tag;
i->clipshapes[i->clippos] = myshapeid;
- i->clipdepths[i->clippos] = i->depth++;
+ i->clipdepths[i->clippos] = getNewDepth(obj);
i->clippos++;
}
return;
}
i->clippos--;
- swf_ObjectPlaceClip(i->cliptags[i->clippos],i->clipshapes[i->clippos],i->clipdepths[i->clippos],&i->page_matrix,NULL,NULL,i->depth++);
+ /*swf_ObjectPlaceClip(i->cliptags[i->clippos],i->clipshapes[i->clippos],i->clipdepths[i->clippos],&i->page_matrix,NULL,NULL,
+ / * clip to depth: * / i->depth <= i->clipdepths[i->clippos]? i->depth : i->depth - 1);
+ i->depth ++;*/
+ swf_ObjectPlaceClip(i->cliptags[i->clippos],i->clipshapes[i->clippos],i->clipdepths[i->clippos],&i->page_matrix,NULL,NULL,i->depth);
}
int swf_setparameter(gfxdevice_t*dev, const char*key, const char*value)
{
else return 4;
}
+int gfxline_has_dots(gfxline_t*line)
+{
+ int tmplines=0;
+ double x,y;
+ double dist = 0;
+ int isline = 0;
+ while(line) {
+ if(line->type == gfx_moveTo) {
+ if(isline && dist < 1) {
+ return 1;
+ }
+ dist = 0;
+ isline = 0;
+ } else if(line->type == gfx_lineTo) {
+ dist += fabs(line->x - x) + fabs(line->y - y);
+ isline = 1;
+ } else if(line->type == gfx_splineTo) {
+ dist += fabs(line->sx - x) + fabs(line->sy - y) +
+ fabs(line->x - line->sx) + fabs(line->y - line->sy);
+ isline = 1;
+ }
+ x = line->x;
+ y = line->y;
+ line = line->next;
+ }
+ if(isline && dist < 1) {
+ return 1;
+ }
+ return 0;
+}
+
+int gfxline_fix_short_edges(gfxline_t*line)
+{
+ double x,y;
+ while(line) {
+ if(line->type == gfx_lineTo) {
+ if(fabs(line->x - x) + fabs(line->y - y) < 0.01) {
+ line->x += 0.01;
+ }
+ } else if(line->type == gfx_splineTo) {
+ if(fabs(line->sx - x) + fabs(line->sy - y) +
+ fabs(line->x - line->sx) + fabs(line->y - line->sy) < 0.01) {
+ line->x += 0.01;
+ }
+ }
+ x = line->x;
+ y = line->y;
+ line = line->next;
+ }
+ return 0;
+}
+
int shapenr = 0;
void swf_stroke(gfxdevice_t*dev, gfxline_t*line, gfxcoord_t width, gfxcolor_t*color, gfx_capType cap_style, gfx_joinType joint_style, gfxcoord_t miterLimit)
swfoutput_internal*i = (swfoutput_internal*)dev->internal;
swfoutput*obj = i->obj;
int type = gfxline_type(line);
+ int has_dots = gfxline_has_dots(line);
/* TODO: * split line into segments, and perform this check for all segments */
- if(width <= config_caplinewidth
- || (cap_style == gfx_capRound && joint_style == gfx_joinRound)
- || (cap_style == gfx_capRound && type<=2)) {
- msg("<trace> draw as stroke, type=%d", type);
+ if(!has_dots &&
+ (width <= config_caplinewidth
+ || (cap_style == gfx_capRound && joint_style == gfx_joinRound)
+ || (cap_style == gfx_capRound && type<=2))) {
+ msg("<trace> draw as stroke, type=%d dots=%d", type, has_dots);
endtext(obj);
swfoutput_setstrokecolor(obj, color->r, color->g, color->b, color->a);
swfoutput_setlinewidth(obj, width);
startshape(obj);
stopFill(obj);
drawgfxline(obj, line);
- msg("<trace > shape bbox is (%f,%f,%f,%f)",
- i->bboxrect.xmin /20.0,
- i->bboxrect.ymin /20.0,
- i->bboxrect.xmax /20.0,
- i->bboxrect.ymax /20.0
- );
} else {
- msg("<trace> draw as polygon, type=%d", type);
+ msg("<trace> draw as polygon, type=%d dots=%d", type, has_dots);
+ if(has_dots)
+ gfxline_fix_short_edges(line);
/* we need to convert the line into a polygon */
ArtSVP* svp = gfxstrokeToSVP(line, width, cap_style, joint_style, miterLimit);
gfxline_t*gfxline = SVPtogfxline(svp);
dev->fill(dev, gfxline, color);
+ free(gfxline);
+ art_svp_free(svp);
}
}
void swf_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color)
drawgfxline(obj, line);
msg("<trace> end of swf_fill (shapeid=%d)", i->shapeid);
}
-void swf_fillgradient(gfxdevice_t*dev, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix)
+void swf_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix)
{
msg("<error> Gradient filling not implemented yet");
}
+
+static SWFFONT* gfxfont_to_swffont(gfxfont_t*font, char* id)
+{
+ SWFFONT*swffont = (SWFFONT*)rfx_calloc(sizeof(SWFFONT));
+ int t;
+ swffont->id = -1;
+ swffont->version = 2;
+ swffont->name = (U8*)strdup(id);
+ swffont->layout = (SWFLAYOUT*)rfx_calloc(sizeof(SWFLAYOUT));
+ swffont->layout->ascent = 0; /* ? */
+ swffont->layout->descent = 0;
+ swffont->layout->leading = 0;
+ swffont->layout->bounds = (SRECT*)rfx_calloc(sizeof(SRECT)*font->num_glyphs);
+ swffont->encoding = FONT_ENCODING_UNICODE;
+ swffont->numchars = font->num_glyphs;
+ swffont->maxascii = font->max_unicode;
+ swffont->ascii2glyph = (int*)rfx_calloc(sizeof(int)*swffont->maxascii);
+ swffont->glyph2ascii = (U16*)rfx_calloc(sizeof(U16)*swffont->numchars);
+ swffont->glyph = (SWFGLYPH*)rfx_calloc(sizeof(SWFGLYPH)*swffont->numchars);
+ swffont->glyphnames = (char**)rfx_calloc(sizeof(char*)*swffont->numchars);
+ for(t=0;t<font->max_unicode;t++) {
+ swffont->ascii2glyph[t] = font->unicode2glyph[t];
+ }
+ for(t=0;t<font->num_glyphs;t++) {
+ drawer_t draw;
+ gfxline_t*line;
+ swffont->glyph2ascii[t] = font->glyphs[t].unicode;
+ if(font->glyphs[t].name) {
+ swffont->glyphnames[t] = strdup(font->glyphs[t].name);
+ } else {
+ swffont->glyphnames[t] = 0;
+ }
+ swffont->glyph[t].advance = (int)(font->glyphs[t].advance * 20);
+
+ swf_Shape01DrawerInit(&draw, 0);
+ line = font->glyphs[t].line;
+ while(line) {
+ FPOINT c,to;
+ c.x = line->sx; c.y = line->sy;
+ to.x = line->x; to.y = line->y;
+ if(line->type == gfx_moveTo) {
+ draw.moveTo(&draw, &to);
+ } else if(line->type == gfx_lineTo) {
+ draw.lineTo(&draw, &to);
+ } else if(line->type == gfx_splineTo) {
+ draw.splineTo(&draw, &c, &to);
+ }
+ line = line->next;
+ }
+ draw.finish(&draw);
+ swffont->glyph[t].shape = swf_ShapeDrawerToShape(&draw);
+ draw.dealloc(&draw);
+ }
+ return swffont;
+}
+
+void swf_addfont(gfxdevice_t*dev, char*fontid, gfxfont_t*font)
+{
+ swfoutput_internal*i = (swfoutput_internal*)dev->internal;
+
+ if(i->obj->swffont && i->obj->swffont->name && !strcmp((char*)i->obj->swffont->name,fontid))
+ return; // the requested font is the current font
+
+ fontlist_t*last=0,*l = i->fontlist;
+ while(l) {
+ last = l;
+ if(!strcmp((char*)l->swffont->name, fontid)) {
+ return; // we already know this font
+ }
+ l = l->next;
+ }
+ l = (fontlist_t*)rfx_calloc(sizeof(fontlist_t));
+ l->swffont = gfxfont_to_swffont(font, fontid);
+ l->next = 0;
+ if(last) {
+ last->next = l;
+ } else {
+ i->fontlist = l;
+ }
+ swf_FontSetID(l->swffont, getNewID(i->obj));
+
+ if(getScreenLogLevel() >= LOGLEVEL_DEBUG) {
+ // print font information
+ msg("<debug> Font %s",fontid);
+ msg("<debug> | ID: %d", l->swffont->id);
+ msg("<debug> | Version: %d", l->swffont->version);
+ msg("<debug> | Name: %s", l->swffont->name);
+ msg("<debug> | Numchars: %d", l->swffont->numchars);
+ msg("<debug> | Maxascii: %d", l->swffont->maxascii);
+ msg("<debug> | Style: %d", l->swffont->style);
+ msg("<debug> | Encoding: %d", l->swffont->encoding);
+ for(int iii=0; iii<l->swffont->numchars;iii++) {
+ msg("<debug> | Glyph %d) name=%s, unicode=%d size=%d bbox=(%.2f,%.2f,%.2f,%.2f)\n", iii, l->swffont->glyphnames?l->swffont->glyphnames[iii]:"<nonames>", l->swffont->glyph2ascii[iii], l->swffont->glyph[iii].shape->bitlen,
+ l->swffont->layout->bounds[iii].xmin/20.0,
+ l->swffont->layout->bounds[iii].ymin/20.0,
+ l->swffont->layout->bounds[iii].xmax/20.0,
+ l->swffont->layout->bounds[iii].ymax/20.0
+ );
+ int t;
+ for(t=0;t<l->swffont->maxascii;t++) {
+ if(l->swffont->ascii2glyph[t] == iii)
+ msg("<debug> | - maps to %d",t);
+ }
+ }
+ }
+}
+
+static void swf_switchfont(gfxdevice_t*dev, char*fontid)
+{
+ swfoutput_internal*i = (swfoutput_internal*)dev->internal;
+ swfoutput*obj = i->obj;
+
+ if(obj->swffont && obj->swffont->name && !strcmp((char*)obj->swffont->name,fontid))
+ return; // the requested font is the current font
+
+ fontlist_t*l = i->fontlist;
+ while(l) {
+ if(!strcmp((char*)l->swffont->name, fontid)) {
+ obj->swffont = l->swffont;
+ return; //done!
+ }
+ l = l->next;
+ }
+ msg("<error> Unknown font id: %s", fontid);
+ return;
+}
+
+void swf_drawchar(gfxdevice_t*dev, char*fontid, int glyph, gfxcolor_t*color, gfxmatrix_t*matrix)
+{
+ swfoutput_internal*i = (swfoutput_internal*)dev->internal;
+ swfoutput*obj = i->obj;
+
+ if(!obj->swffont || !obj->swffont->name || strcmp((char*)obj->swffont->name,fontid)) // not equal to current font
+ {
+ /* TODO: remove the need for this (enhance getcharacterbbox so that it can cope
+ with multiple fonts */
+ endtext(obj);
+
+ swf_switchfont(dev, fontid); // set the current font
+ }
+ swfoutput_setfontmatrix(obj, matrix->m00, matrix->m01, matrix->m10, matrix->m11);
+
+ swfmatrix m;
+ m.m11 = obj->fontm11;
+ m.m12 = obj->fontm12;
+ m.m21 = obj->fontm21;
+ m.m22 = obj->fontm22;
+ m.m31 = matrix->tx;
+ m.m32 = matrix->ty;
+ drawchar(obj, obj->swffont, 0, glyph, -1, &m, color);
+}