X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=pdf2swf%2Fswfoutput.cc;h=74c982dc1b1fd81bc939137e8d8361c92bbd4da2;hb=0e916263b32f4920c2f5581caa77985bf1992081;hp=6cef2e67cc00d3b02036f7a735f6832d9102d042;hpb=07b215b2a0b442a8f9b832b9ff94755bb6191d48;p=swftools.git diff --git a/pdf2swf/swfoutput.cc b/pdf2swf/swfoutput.cc index 6cef2e6..74c982d 100644 --- a/pdf2swf/swfoutput.cc +++ b/pdf2swf/swfoutput.cc @@ -27,10 +27,14 @@ extern "C" { #include "../lib/log.h" #include "../lib/rfxswf.h" } +#define standardEncodingSize 335 +extern char *standardEncodingNames[standardEncodingSize]; +int opennewwindow=0; int ignoredraworder=0; int drawonlyshapes=0; int jpegquality=85; +int storeallcharacters=0; static int flag_protected = 0; typedef unsigned char u8; @@ -417,7 +421,7 @@ void putcharacter(struct swfoutput*obj, int fontid, int charid, /* process a character. */ -void drawchar(struct swfoutput*obj, SWFFont*font, char*character, swfmatrix*m) +void drawchar(struct swfoutput*obj, SWFFont*font, char*character, int charnr, swfmatrix*m) { int usefonts=1; if(m->m12!=0 || m->m21!=0) @@ -427,7 +431,7 @@ void drawchar(struct swfoutput*obj, SWFFont*font, char*character, swfmatrix*m) if(usefonts && ! drawonlyshapes) { - int charid = font->getSWFCharID(character); + int charid = font->getSWFCharID(character, charnr); if(shapeid>=0) endshape(); if(textid<0) @@ -501,29 +505,45 @@ SWFFont::SWFFont(char*name, int id, char*filename) this->name = strdup(T1_GetFontFileName(id)); this->fontid = strdup(name); this->t1id = id; - + char**a= T1_GetAllCharNames(id); - int t=0, outlinepos=0; + int t, outlinepos=0; char*map[256]; + + t=0; while(a[t]) t++; - this->charnum = t; - if(!t) + + if(!charnum) return; - logf(" Font %s(%d): Storing %d outlines.\n", name, id, t); + logf(" Font %s(%d): Storing %d outlines.\n", name, id, charnum); + + this->standardtablesize = 256; + if(this->charnum < this->standardtablesize) + this->standardtablesize = this->charnum; + this->standardtable = (char**)malloc(standardtablesize*sizeof(char*)); + + for(t = 0; t < this->standardtablesize; t++) { + char*name = T1_GetCharName(id,t); + if(!name) + name = ""; + standardtable[t] = strdup(name); + } - outline = (T1_OUTLINE**)malloc(t*sizeof(T1_OUTLINE*)); - charname = (char**)malloc(t*sizeof(char*)); - used = (char*)malloc(t*sizeof(char)); - char2swfcharid = (U16*)malloc(t*2); - swfcharid2char = (U16*)malloc(t*2); + outline = (T1_OUTLINE**)malloc(charnum*sizeof(T1_OUTLINE*)); + charname = (char**)malloc(charnum*sizeof(char*)); + width = (int*)malloc(charnum*sizeof(int)); + memset(width, 0, charnum*sizeof(int)); + memset(charname, 0, charnum*sizeof(char*)); + used = (char*)malloc(charnum*sizeof(char)); + char2swfcharid = (U16*)malloc(charnum*2); + swfcharid2char = (U16*)malloc(charnum*2); swfcharpos = 0; - memset(used,0,t*sizeof(char)); + memset(used,0,charnum*sizeof(char)); this->swfid = ++currentswfid; - t=0; while(*a) @@ -548,8 +568,11 @@ SWFFont::SWFFont(char*name, int id, char*filename) // parsecharacters for(s=0;soutline[outlinepos] = T1_CopyOutline(T1_GetCharOutline(id, s, 100.0, 0)); - this->charname[outlinepos] = strdup(T1_GetCharName(id, s)); + this->width[outlinepos] = T1_GetCharWidth(id, s); + this->charname[outlinepos] = strdup(name); outlinepos++; } t=0; @@ -561,7 +584,19 @@ SWFFont::SWFFont(char*name, int id, char*filename) SWFFont::~SWFFont() { int t,usednum=0; - int*ptr = (int*)malloc(swfcharpos*sizeof(int)); + int*ptr; + + if(storeallcharacters) + { + int t; + for(t=0;tcharnum;t++) + { + if(this->charname[t]) + getSWFCharID(this->charname[t], -1); + } + } + + ptr = (int*)malloc(swfcharpos*sizeof(int)); for(t=0;tswfid); + if(this->fontid) { + swf_SetU8(ftag, strlen(this->fontid)); + swf_SetBlock(ftag, (U8*)this->fontid, strlen(this->fontid)); + } else { + swf_SetU8(ftag, 0); + } + swf_SetU8(ftag, 0); //flags + for(t=0;tcharname[this->swfcharid2char[t]]; + for(s=0;s<256;s++) { + if(standardEncodingNames[s] && + !strcmp(name,standardEncodingNames[s])) + break; + } + swf_SetU8(ftag, (U8)s); + } } free(ptr); free(outline); for(t=0;tcharnum;t++) { @@ -644,6 +706,9 @@ int SWFFont::getSWFCharID(char*name) return char2swfcharid[t]; } } + if(this->standardtable && charnr>=0 && charnr < this->standardtablesize) { + return getSWFCharID(this->standardtable[charnr], -1); + } logf(" Didn't find character '%s' in font '%s'", name, this->name); return 0; } @@ -725,7 +790,7 @@ void swfoutput_setfontmatrix(struct swfoutput*obj,double m11,double m12, } /* draws a character at x,y. */ -void swfoutput_drawchar(struct swfoutput* obj,double x,double y,char*character) +void swfoutput_drawchar(struct swfoutput* obj,double x,double y,char*character, int charnr) { swfmatrix m; m.m11 = obj->fontm11; @@ -734,7 +799,7 @@ void swfoutput_drawchar(struct swfoutput* obj,double x,double y,char*character) m.m22 = obj->fontm22; m.m13 = x; m.m23 = y; - drawchar(obj, obj->font, character, &m); + drawchar(obj, obj->font, character, charnr, &m); } /* initialize the swf writer */ @@ -1020,6 +1085,130 @@ void swfoutput_endclip(swfoutput*obj) swf_ObjectPlaceClip(cliptags[clippos],clipshapes[clippos],clipdepths[clippos],NULL,NULL,NULL,depth++); } +void drawlink(struct swfoutput*obj, ActionTAG*, swfcoord*points); + +void swfoutput_linktourl(struct swfoutput*obj, char*url, swfcoord*points) +{ + ActionTAG* actions; + + if(shapeid>=0) + endshape(); + if(textid>=0) + endtext(); + + actions = swf_ActionStart(); + if(opennewwindow) + action_GetUrl(url, "_parent"); + else + action_GetUrl(url, "_this"); + action_End(); + swf_ActionEnd(); + + drawlink(obj, actions, points); +} +void swfoutput_linktopage(struct swfoutput*obj, int page, swfcoord*points) +{ + ActionTAG* actions; + + if(shapeid>=0) + endshape(); + if(textid>=0) + endtext(); + + actions = swf_ActionStart(); + action_GotoFrame(page); + action_End(); + swf_ActionEnd(); + + drawlink(obj, actions, points); +} + +void drawlink(struct swfoutput*obj, ActionTAG*actions, swfcoord*points) +{ + RGBA rgb; + SRECT r; + int lsid=0; + int fsid; + struct plotxy p1,p2,p3,p4; + int myshapeid; + int myshapeid2; + double xmin,ymin; + double xmax=xmin=points[0].x,ymax=ymin=points[0].y; + int t; + int buttonid = ++currentswfid; + for(t=1;t<4;t++) + { + if(points[t].x>xmax) xmax=points[t].x; + if(points[t].y>ymax) ymax=points[t].y; + if(points[t].x