#include "../gfxtools.h"
#include "swf.h"
#include "../gfxpoly.h"
-#include "../png.h"
+#include "../gfximage.h"
#define CHARDATAMAX 1024
#define CHARMIDX 0
int config_storeallcharacters;
int config_enablezlib;
int config_insertstoptag;
+ int config_showimages;
int config_watermark;
int config_noclips;
int config_flashversion;
int config_bboxvars;
int config_disable_polygon_conversion;
int config_normalize_polygon_positions;
+ int config_alignfonts;
char config_disablelinks;
RGBA config_linkcolor;
float config_minlinewidth;
char* mark;
} swfoutput_internal;
+
+static const int NO_FONT3=0;
static void swf_fillbitmap(gfxdevice_t*driver, gfxline_t*line, gfximage_t*img, gfxmatrix_t*move, gfxcxform_t*cxform);
static int swf_setparameter(gfxdevice_t*driver, const char*key, const char*value);
return 1;
}
-static SRECT getcharacterbbox(chararray_t*chardata, MATRIX* m)
+static SRECT getcharacterbbox(chararray_t*chardata, MATRIX* m, int flashversion)
{
SRECT r;
char debug = 0;
int t;
if(debug) printf("\n");
+ double div = 1.0 / 1024.0;
+ if(flashversion>=8 && !NO_FONT3) {
+ div = 1.0 / 20480.0;
+ }
+
while(chardata) {
for(t=0;t<chardata->pos;t++) {
charatposition_t*chr = &chardata->chr[t];
SRECT b = chr->font->layout->bounds[chr->charid];
- b.xmin *= chr->size;
- b.ymin *= chr->size;
- b.xmax *= chr->size;
- b.ymax *= chr->size;
-
- /* divide by 1024, rounding xmax/ymax up */
- b.xmax += 1023; b.ymax += 1023; b.xmin /= 1024; b.ymin /= 1024; b.xmax /= 1024; b.ymax /= 1024;
+ b.xmin = floor((b.xmin*(double)chr->size) *div);
+ b.ymin = floor((b.ymin*(double)chr->size) *div);
+ b.xmax = ceil((b.xmax*(double)chr->size) *div);
+ b.ymax = ceil((b.ymax*(double)chr->size) *div);
b.xmin += chr->x;
b.ymin += chr->y;
int lastx;
int lasty;
int lastsize;
+ int lastchar;
int charids[128];
int charadvance[128];
int charstorepos;
lastx = CHARMIDX;
lasty = CHARMIDY;
lastsize = -1;
+ lastchar = -1;
if(pass==1)
{
charatposition_t*chr = &chardata->chr[t];
- if(lastfont != chardata->chr[t].font ||
- lastx!=chardata->chr[t].x ||
- lasty!=chardata->chr[t].y ||
+ if(lastfont != chr->font ||
+ lastx!=chr->x ||
+ lasty!=chr->y ||
!colorcompare(&color, &chardata->chr[t].color) ||
charstorepos==127 ||
lastsize != chardata->chr[t].size ||
newfont = &font;
tag->writeBit = 0; // Q&D
- swf_TextSetInfoRecord(tag, newfont, chr->size, newcolor, newx,newy);
+ swf_TextSetInfoRecord(tag, newfont, chr->size, newcolor, newx, newy);
}
lastfont = chr->font;
if(t<chardata->pos-1) nextx = chardata->chr[t+1].x;
if(t==chardata->pos-1 && chardata->next) nextx = chardata->next->chr[0].x;
int dx = nextx-chr->x;
-
+
int advance;
if(dx>=0 && (dx<(1<<(advancebits-1)) || pass==0)) {
advance = dx;
advance = 0;
lastx=chr->x;
}
+
charids[charstorepos] = chr->charid;
charadvance[charstorepos] = advance;
+ lastchar = chr->charid;
charstorepos ++;
}
chardata = chardata->next;
i->tag = swf_InsertTag(i->tag,ST_DEFINETEXT2);
swf_SetU16(i->tag, textid);
SRECT r;
- r = getcharacterbbox(array, matrix);
+ r = getcharacterbbox(array, matrix, i->config_flashversion);
r = swf_ClipRect(i->pagebbox, r);
swf_SetRect(i->tag,&r);
swf_SetMatrix(i->tag, matrix);
swf_SetU32(i->tag, 0);//thickness
swf_SetU32(i->tag, 0);//sharpness
+ //swf_SetU32(i->tag, 0x20000);//thickness
+ //swf_SetU32(i->tag, 0x800000);//sharpness
swf_SetU8(i->tag, 0);//reserved
}
if(invisible && i->config_flashversion>=8) {
i->textmode = 0;
}
-/* sets the matrix which is to be applied to characters drawn by swfoutput_drawchar() */
-static void setfontscale(gfxdevice_t*dev,double m11,double m12, double m21,double m22,double x, double y, char force)
-{
- m11 *= 1024;
- m12 *= 1024;
- m21 *= 1024;
- m22 *= 1024;
- swfoutput_internal*i = (swfoutput_internal*)dev->internal;
- if(i->lastfontm11 == m11 &&
- i->lastfontm12 == m12 &&
- i->lastfontm21 == m21 &&
- i->lastfontm22 == m22 && !force)
- return;
- if(i->textmode)
- endtext(dev);
-
- i->lastfontm11 = m11;
- i->lastfontm12 = m12;
- i->lastfontm21 = m21;
- i->lastfontm22 = m22;
-
- double xsize = sqrt(m11*m11 + m12*m12);
- double ysize = sqrt(m21*m21 + m22*m22);
- i->current_font_size = (xsize>ysize?xsize:ysize)*1;
- if(i->current_font_size < 1)
- i->current_font_size = 1;
- double ifs = 1.0 / (i->current_font_size*GLYPH_SCALE);
-
- MATRIX m;
- m.sx = (S32)((m11*ifs)*65536); m.r1 = (S32)((m21*ifs)*65536);
- m.r0 = (S32)((m12*ifs)*65536); m.sy = (S32)((m22*ifs)*65536);
- /* this is the position of the first char to set a new fontmatrix-
- we hope that it's close enough to all other characters using the
- font, so we use its position as origin for the matrix */
- m.tx = x*20;
- m.ty = y*20;
- i->fontmatrix = m;
-}
-
static int watermark2_width=47;
static int watermark2_height=11;
static int watermark2[47] = {95,1989,71,0,2015,337,1678,0,2015,5,1921,320,1938,25,2006,1024,
endpage(dev);
fontlist_t *iterator = i->fontlist;
+ char use_font3 = i->config_flashversion>=8 && !NO_FONT3;
+
while(iterator) {
TAG*mtag = i->swf->firstTag;
if(iterator->swffont) {
}
int used = iterator->swffont->use && iterator->swffont->use->used_glyphs;
if(used) {
- mtag = swf_InsertTag(mtag, ST_DEFINEFONT2);
- swf_FontSetDefine2(mtag, iterator->swffont);
+ if(!use_font3) {
+ mtag = swf_InsertTag(mtag, ST_DEFINEFONT2);
+ swf_FontSetDefine2(mtag, iterator->swffont);
+ } else {
+ mtag = swf_InsertTag(mtag, ST_DEFINEFONT3);
+ swf_FontSetDefine2(mtag, iterator->swffont);
+ }
}
}
iterator = iterator->next;
}
-
+
i->tag = swf_InsertTag(i->tag,ST_END);
TAG* tag = i->tag->prev;
+
+ if(use_font3 && i->config_storeallcharacters && i->config_alignfonts) {
+ swf_FontPostprocess(i->swf); // generate alignment information
+ }
/* remove the removeobject2 tags between the last ST_SHOWFRAME
and the ST_END- they confuse the flash player */
swf_ButtonPostProcess(i->tag, 1);
}
}
+
char buf[80];
+ char*buf2 = 0;
const char* name = 0;
if(i->config_linknameurl) {
- name = url;
+ buf2 = malloc(strlen(type)+strlen(url)+2);
+ sprintf(buf2, "%s:%s", type, url);
+ name = buf2;
} else {
name = buf;
sprintf(buf, "button%d", buttonid);
} else {
swf_ObjectPlace(i->tag, buttonid, getNewDepth(dev),&i->page_matrix,0,(U8*)name);
}
+
+ if(buf2)
+ free(buf2);
}
i->config_dumpfonts = atoi(value);
} else if(!strcmp(name, "animate")) {
i->config_animate = atoi(value);
+ } else if(!strcmp(name, "linknameurl")) {
+ i->config_linknameurl = atoi(value);
+ } else if(!strcmp(name, "showimages")) {
+ i->config_showimages = atoi(value);
} else if(!strcmp(name, "disablelinks")) {
i->config_disablelinks = atoi(value);
} else if(!strcmp(name, "simpleviewer")) {
printf("linkcolor=<color) color of links (format: RRGGBBAA)\n");
printf("linknameurl Link buttons will be named like the URL they refer to (handy for iterating through links with actionscript)\n");
printf("storeallcharacters don't reduce the fonts to used characters in the output file\n");
- printf("enablezlib switch on zlib compression (also done if flashversion>=7)\n");
+ printf("enablezlib switch on zlib compression (also done if flashversion>=6)\n");
printf("bboxvars store the bounding box of the SWF file in actionscript variables\n");
printf("dots Take care to handle dots correctly\n");
printf("reordertags=0/1 (default: 1) perform some tag optimizations\n");
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);
+ gfximage_t*ni = gfximage_rescale(img, newsizex, newsizey);
+ newpic = (RGBA*)ni->data;
+ free(ni);
*newwidth = sizex = newsizex;
*newheight = sizey = newsizey;
mem = newpic;
SHAPE*shape;
swf_ShapeNew(&shape);
int fsid = swf_ShapeAddBitmapFillStyle(shape,&m,bitid,1);
+ int lsid = 0;
+ if(i->config_showimages) {
+ RGBA pink = {255,255,0,255};
+ lsid = swf_ShapeAddLineStyle(shape, 20, &pink);
+ }
swf_SetU16(i->tag, myshapeid);
SRECT r = gfxline_getSWFbbox(line);
r = swf_ClipRect(i->pagebbox, r);
swf_SetShapeStyles(i->tag,shape);
swf_ShapeCountBits(shape,NULL,NULL);
swf_SetShapeBits(i->tag,shape);
- swf_ShapeSetAll(i->tag,shape,UNDEFINED_COORD,UNDEFINED_COORD,0,fsid,0);
+ swf_ShapeSetAll(i->tag,shape,UNDEFINED_COORD,UNDEFINED_COORD,lsid,fsid,0);
i->swflastx = i->swflasty = UNDEFINED_COORD;
drawgfxline(dev, line, 1);
swf_ShapeSetEnd(i->tag);
swf_FreeGradient(swfgradient);free(swfgradient);
}
-static SWFFONT* gfxfont_to_swffont(gfxfont_t*font, const char* id)
+static SWFFONT* gfxfont_to_swffont(gfxfont_t*font, const char* id, int version)
{
SWFFONT*swffont = (SWFFONT*)rfx_calloc(sizeof(SWFFONT));
int t;
SRECT bounds = {0,0,0,0};
swffont->id = -1;
- swffont->version = 2;
+ swffont->version = version;
swffont->name = (U8*)strdup(id);
swffont->layout = (SWFLAYOUT*)rfx_calloc(sizeof(SWFLAYOUT));
swffont->layout->ascent = 0;
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];
- }
+
SRECT max = {0,0,0,0};
for(t=0;t<font->num_glyphs;t++) {
drawer_t draw;
gfxline_t*line;
double advance = 0;
- swffont->glyph2ascii[t] = font->glyphs[t].unicode;
- if(swffont->glyph2ascii[t] == 0xffff || swffont->glyph2ascii[t] == 0x0000) {
+ int u = font->glyphs[t].unicode;
+ int s;
+ char twice=0;
+ for(s=0;s<font->num_glyphs;s++) {
+ if(swffont->glyph2ascii[s]==u)
+ twice=1;
+ }
+ if(u >= 0xe000 || u == 0x0000 || twice) {
/* flash 8 flashtype requires unique unicode IDs for each character.
We use the Unicode private user area to assign characters, hoping that
the font doesn't contain more than 2048 glyphs */
- swffont->glyph2ascii[t] = 0xe000 + (t&0x1fff);
+ u = 0xe000 + (t&0x1fff);
}
+ swffont->glyph2ascii[t] = u;
if(font->glyphs[t].name) {
swffont->glyphnames[t] = strdup(font->glyphs[t].name);
swf_Shape01DrawerInit(&draw, 0);
line = font->glyphs[t].line;
+ const double scale = GLYPH_SCALE;
while(line) {
FPOINT c,to;
- c.x = line->sx * GLYPH_SCALE; c.y = line->sy * GLYPH_SCALE;
- to.x = line->x * GLYPH_SCALE; to.y = line->y * GLYPH_SCALE;
+ c.x = line->sx * scale; c.y = -line->sy * scale;
+ //to.x = floor(line->x * scale); to.y = floor(-line->y * scale);
+ to.x = line->x * scale; to.y = -line->y * scale;
+
+ /*if(strstr(swffont->name, "BIRNU") && t==90) {
+ to.x += 1;
+ }*/
+
if(line->type == gfx_moveTo) {
draw.moveTo(&draw, &to);
} else if(line->type == gfx_lineTo) {
swf_ExpandRect2(&bounds, &swffont->layout->bounds[t]);
}
+
for(t=0;t<font->num_glyphs;t++) {
SRECT bbox = swffont->layout->bounds[t];
The baseline is defined as the y-position zero
*/
- swffont->layout->ascent = -bounds.ymin;
- if(swffont->layout->ascent < 0)
- swffont->layout->ascent = 0;
- swffont->layout->descent = bounds.ymax;
- if(swffont->layout->descent < 0)
- swffont->layout->descent = 0;
+ swffont->layout->ascent = bounds.ymin<0?-bounds.ymin:0;
+ swffont->layout->descent = bounds.ymax>0?bounds.ymax:0;
swffont->layout->leading = bounds.ymax - bounds.ymin;
/* if the font has proper ascent/descent values (>0) and those define
if(font->descent*20 > swffont->layout->descent)
swffont->layout->descent = font->descent*20;
+ swf_FontSort(swffont);
return swffont;
}
l = l->next;
}
l = (fontlist_t*)rfx_calloc(sizeof(fontlist_t));
- l->swffont = gfxfont_to_swffont(font, font->id);
+ l->swffont = gfxfont_to_swffont(font, font->id, (i->config_flashversion>=8 && !NO_FONT3)?3:2);
l->next = 0;
if(last) {
last->next = l;
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);
- }
}
}
}
return;
}
+/* sets the matrix which is to be applied to characters drawn by swfoutput_drawchar() */
+static void setfontscale(gfxdevice_t*dev,double m11,double m12, double m21,double m22,double x, double y, char force)
+{
+ m11 *= 1024;
+ m12 *= 1024;
+ m21 *= 1024;
+ m22 *= 1024;
+ swfoutput_internal*i = (swfoutput_internal*)dev->internal;
+ if(i->lastfontm11 == m11 &&
+ i->lastfontm12 == m12 &&
+ i->lastfontm21 == m21 &&
+ i->lastfontm22 == m22 && !force)
+ return;
+ if(i->textmode)
+ endtext(dev);
+
+ i->lastfontm11 = m11;
+ i->lastfontm12 = m12;
+ i->lastfontm21 = m21;
+ i->lastfontm22 = m22;
+
+ double xsize = sqrt(m11*m11 + m12*m12);
+ double ysize = sqrt(m21*m21 + m22*m22);
+
+ int extrazoom = 1;
+ if(i->config_flashversion>=8 && !NO_FONT3)
+ extrazoom = 20;
+
+ i->current_font_size = (xsize>ysize?xsize:ysize)*extrazoom;
+ if(i->current_font_size < 1)
+ i->current_font_size = 1;
+
+ MATRIX m;
+ swf_GetMatrix(0, &m);
+
+ if(m21 || m12 || fabs(m11+m22)>0.001) {
+ double ifs = (double)extrazoom/(i->current_font_size);
+ m.sx = (S32)((m11*ifs)*65536); m.r1 = -(S32)((m21*ifs)*65536);
+ m.r0 = (S32)((m12*ifs)*65536); m.sy = -(S32)((m22*ifs)*65536);
+ }
+
+ /* this is the position of the first char to set a new fontmatrix-
+ we hope that it's close enough to all other characters using the
+ font, so we use its position as origin for the matrix */
+ m.tx = x*20;
+ m.ty = y*20;
+ i->fontmatrix = m;
+}
+
+
static void swf_drawchar(gfxdevice_t*dev, gfxfont_t*font, int glyph, gfxcolor_t*color, gfxmatrix_t*matrix)
{
swfoutput_internal*i = (swfoutput_internal*)dev->internal;
msg("<warning> No character %d in font %s (%d chars)", glyph, FIXNULL((char*)i->swffont->name), i->swffont->numchars);
return;
}
+ glyph = i->swffont->glyph2glyph[glyph];
setfontscale(dev, matrix->m00, matrix->m01, matrix->m10, matrix->m11, matrix->tx, matrix->ty, 0);
glyph, i->swffont->id, x, y, color->r, color->g, color->b, color->a);
if(color->a == 0 && i->config_invisibletexttofront) {
+ RGBA color2 = *(RGBA*)color;
if(i->config_flashversion>=8) {
// use "multiply" blend mode
- color->a = color->r = color->g = color->b = 255;
+ color2.a = color2.r = color2.g = color2.b = 255;
}
- i->topchardata = charbuffer_append(i->topchardata, i->swffont, glyph, x, y, i->current_font_size, *(RGBA*)color, &i->fontmatrix);
+ i->topchardata = charbuffer_append(i->topchardata, i->swffont, glyph, x, y, i->current_font_size, color2, &i->fontmatrix);
} else {
i->chardata = charbuffer_append(i->chardata, i->swffont, glyph, x, y, i->current_font_size, *(RGBA*)color, &i->fontmatrix);
}
- swf_FontUseGlyph(i->swffont, glyph);
+ swf_FontUseGlyph(i->swffont, glyph, i->current_font_size);
return;
}