git.asbjorn.biz
/
swftools.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
added .bbox method to glyph in ruby interface
[swftools.git]
/
lib
/
devices
/
swf.c
diff --git
a/lib/devices/swf.c
b/lib/devices/swf.c
index
6d66409
..
3be81d5
100644
(file)
--- a/
lib/devices/swf.c
+++ b/
lib/devices/swf.c
@@
-42,7
+42,7
@@
#include "../gfxtools.h"
#include "swf.h"
#include "../gfxpoly.h"
#include "../gfxtools.h"
#include "swf.h"
#include "../gfxpoly.h"
-#include "../png.h"
+#include "../gfximage.h"
#define CHARDATAMAX 1024
#define CHARMIDX 0
#define CHARDATAMAX 1024
#define CHARMIDX 0
@@
-114,6
+114,7
@@
typedef struct _swfoutput_internal
int config_bboxvars;
int config_disable_polygon_conversion;
int config_normalize_polygon_positions;
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 config_disablelinks;
RGBA config_linkcolor;
float config_minlinewidth;
@@
-623,6
+624,7
@@
static void chararray_writetotag(chararray_t*_chardata, TAG*tag)
int lastx;
int lasty;
int lastsize;
int lastx;
int lasty;
int lastsize;
+ int lastchar;
int charids[128];
int charadvance[128];
int charstorepos;
int charids[128];
int charadvance[128];
int charstorepos;
@@
-646,6
+648,7
@@
static void chararray_writetotag(chararray_t*_chardata, TAG*tag)
lastx = CHARMIDX;
lasty = CHARMIDY;
lastsize = -1;
lastx = CHARMIDX;
lasty = CHARMIDY;
lastsize = -1;
+ lastchar = -1;
if(pass==1)
{
if(pass==1)
{
@@
-670,9
+673,9
@@
static void chararray_writetotag(chararray_t*_chardata, TAG*tag)
charatposition_t*chr = &chardata->chr[t];
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 ||
!colorcompare(&color, &chardata->chr[t].color) ||
charstorepos==127 ||
lastsize != chardata->chr[t].size ||
@@
-745,7
+748,7
@@
static void chararray_writetotag(chararray_t*_chardata, TAG*tag)
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;
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;
int advance;
if(dx>=0 && (dx<(1<<(advancebits-1)) || pass==0)) {
advance = dx;
@@
-754,8
+757,10
@@
static void chararray_writetotag(chararray_t*_chardata, TAG*tag)
advance = 0;
lastx=chr->x;
}
advance = 0;
lastx=chr->x;
}
+
charids[charstorepos] = chr->charid;
charadvance[charstorepos] = advance;
charids[charstorepos] = chr->charid;
charadvance[charstorepos] = advance;
+ lastchar = chr->charid;
charstorepos ++;
}
chardata = chardata->next;
charstorepos ++;
}
chardata = chardata->next;
@@
-1465,6
+1470,8
@@
void swfoutput_finalize(gfxdevice_t*dev)
endpage(dev);
fontlist_t *iterator = i->fontlist;
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) {
while(iterator) {
TAG*mtag = i->swf->firstTag;
if(iterator->swffont) {
@@
-1474,29
+1481,25
@@
void swfoutput_finalize(gfxdevice_t*dev)
}
int used = iterator->swffont->use && iterator->swffont->use->used_glyphs;
if(used) {
}
int used = iterator->swffont->use && iterator->swffont->use->used_glyphs;
if(used) {
- if(i->config_flashversion<8 || NO_FONT3) {
+ 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);
mtag = swf_InsertTag(mtag, ST_DEFINEFONT2);
swf_FontSetDefine2(mtag, iterator->swffont);
} else {
mtag = swf_InsertTag(mtag, ST_DEFINEFONT3);
swf_FontSetDefine2(mtag, iterator->swffont);
-
- if(i->config_flashversion>=10)
- swf_FontCreateAlignZones(iterator->swffont);
-
- if(iterator->swffont->alignzones) {
- mtag = swf_InsertTag(mtag, ST_DEFINEFONTALIGNZONES);
- swf_FontSetAlignZones(mtag, iterator->swffont);
- }
}
}
}
iterator = iterator->next;
}
}
}
}
iterator = iterator->next;
}
-
+
i->tag = swf_InsertTag(i->tag,ST_END);
TAG* tag = i->tag->prev;
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 */
/* remove the removeobject2 tags between the last ST_SHOWFRAME
and the ST_END- they confuse the flash player */
@@
-2252,7
+2255,9
@@
static int add_image(swfoutput_internal*i, gfximage_t*img, int targetwidth, int
if(newsizex<sizex || newsizey<sizey) {
msg("<verbose> Scaling %dx%d image to %dx%d", sizex, sizey, newsizex, newsizey);
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;
*newwidth = sizex = newsizex;
*newheight = sizey = newsizey;
mem = newpic;
@@
-2810,21
+2815,26
@@
static SWFFONT* gfxfont_to_swffont(gfxfont_t*font, const char* id, int version)
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);
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;
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 */
/* 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);
if(font->glyphs[t].name) {
swffont->glyphnames[t] = strdup(font->glyphs[t].name);
@@
-2842,6
+2852,11
@@
static SWFFONT* gfxfont_to_swffont(gfxfont_t*font, const char* id, int version)
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;
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) {
if(line->type == gfx_moveTo) {
draw.moveTo(&draw, &to);
} else if(line->type == gfx_lineTo) {
@@
-2870,6
+2885,7
@@
static SWFFONT* gfxfont_to_swffont(gfxfont_t*font, const char* id, int version)
swf_ExpandRect2(&bounds, &swffont->layout->bounds[t]);
}
swf_ExpandRect2(&bounds, &swffont->layout->bounds[t]);
}
+
for(t=0;t<font->num_glyphs;t++) {
SRECT bbox = swffont->layout->bounds[t];
for(t=0;t<font->num_glyphs;t++) {
SRECT bbox = swffont->layout->bounds[t];
@@
-2909,6
+2925,7
@@
static SWFFONT* gfxfont_to_swffont(gfxfont_t*font, const char* id, int version)
if(font->descent*20 > swffont->layout->descent)
swffont->layout->descent = font->descent*20;
if(font->descent*20 > swffont->layout->descent)
swffont->layout->descent = font->descent*20;
+ swf_FontSort(swffont);
return swffont;
}
return swffont;
}
@@
-2955,11
+2972,6
@@
static void swf_addfont(gfxdevice_t*dev, gfxfont_t*font)
l->swffont->layout->bounds[iii].xmax/20.0,
l->swffont->layout->bounds[iii].ymax/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);
- }
}
}
}
}
}
}
@@
-3063,6
+3075,7
@@
static void swf_drawchar(gfxdevice_t*dev, gfxfont_t*font, int glyph, gfxcolor_t*
msg("<warning> No character %d in font %s (%d chars)", glyph, FIXNULL((char*)i->swffont->name), i->swffont->numchars);
return;
}
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);
setfontscale(dev, matrix->m00, matrix->m01, matrix->m10, matrix->m11, matrix->tx, matrix->ty, 0);
@@
-3116,6
+3129,6
@@
static void swf_drawchar(gfxdevice_t*dev, gfxfont_t*font, int glyph, gfxcolor_t*
} else {
i->chardata = charbuffer_append(i->chardata, i->swffont, glyph, x, y, i->current_font_size, *(RGBA*)color, &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;
}
return;
}