flags |= 4; //wide codecs
if(fontSize(f)>65535)
flags |= 8; //wide offsets
- flags |= 8; //FIXME: the above check doesn't work
+ flags |= 8|4; //FIXME: the above check doesn't work
if(f->encoding & FONT_ENCODING_ANSI)
flags |= 16; // ansi
if(f->glyphnames) {
int t;
for(t=0;t<f->numchars;t++) {
- free(f->glyphnames[t]);
+ if(f->glyphnames[t])
+ free(f->glyphnames[t]);
}
free(f->glyphnames);
}
return res;
}
+SRECT swf_TextCalculateBBoxUTF8(SWFFONT * font,U8 * s,int scale)
+{
+ int pos=0;
+ SRECT r;
+ swf_GetRect(0, &r);
+ while(*s) {
+ int c = readUTF8char(&s);
+ if(c < font->maxascii) {
+ int g = font->ascii2glyph[c];
+ if(g>=0) {
+ SRECT rn = font->layout->bounds[g];
+ rn.xmin = (rn.xmin * scale)/20/100 + pos;
+ rn.xmax = (rn.xmax * scale)/20/100 + pos;
+ rn.ymin = (rn.ymin * scale)/20/100;
+ rn.ymax = (rn.ymax * scale)/20/100;
+ swf_ExpandRect2(&r, &rn);
+ pos += (font->glyph[g].advance*scale)/20/100;
+ }
+ }
+ c++;
+ }
+ return r;
+}
+
+
SWFFONT* swf_ReadFont(char* filename)
{
int f;
swf_SetU16(t, WRITEFONTID);
swf_SetU16(t, font->numchars);
for(c=0;c<font->numchars;c++) {
- swf_SetString(t, font->glyphnames[c]);
+ if(font->glyphnames[c])
+ swf_SetString(t, font->glyphnames[c]);
+ else
+ swf_SetString(t, "");
}
}
U8 gbits, abits;
U8*c = (U8*)text;
int pos = 0;
- swf_GetRect(0, &r);
if(font->layout) {
- while(*c) {
- if(*c < font->maxascii) {
- int g = font->ascii2glyph[*c];
- if(g>=0) {
- SRECT rn = font->layout->bounds[g];
- rn.xmin = (rn.xmin * scale)/100 + pos;
- rn.xmax = (rn.xmax * scale)/100 + pos;
- rn.ymin = (rn.ymin * scale)/100;
- rn.ymax = (rn.ymax * scale)/100;
- swf_ExpandRect2(&r, &rn);
- pos += (font->glyph[g].advance*scale)/100;
- }
- }
- c++;
- }
+ r = swf_TextCalculateBBoxUTF8(font,text,scale*20);
} else {
+ fprintf(stderr, "No layout information- can't compute text bbox accurately");
/* Hm, without layout information, we can't compute a bounding
box. We could call swf_FontCreateLayout to create a layout,
but the caller probably doesn't want us to mess up his font
}
}
-void swf_DrawText(drawer_t*draw, SWFFONT*font, char*text)
+void swf_DrawText(drawer_t*draw, SWFFONT*font, int size, char*text)
{
U8*s = (U8*)text;
int advance = 0;
U32 c = readUTF8char(&s);
int g = font->ascii2glyph[c];
shape = font->glyph[g].shape;
+ if(((int)g)<0) {
+ fprintf(stderr, "No char %d in font %s\n", c, font->name?(char*)font->name:"?");
+ continue;
+ }
shape2 = swf_ShapeToShape2(shape);
l = shape2->lines;
while(l) {
if(l->type == moveTo) {
FPOINT to;
- to.x = l->x/20.0+advance;
- to.y = l->y/20.0;
+ to.x = l->x*size/100.0/20.0+advance;
+ to.y = l->y*size/100.0/20.0;
draw->moveTo(draw, &to);
} else if(l->type == lineTo) {
FPOINT to;
- to.x = l->x/20.0+advance;
- to.y = l->y/20.0;
+ to.x = l->x*size/100.0/20.0+advance;
+ to.y = l->y*size/100.0/20.0;
draw->lineTo(draw, &to);
} else if(l->type == splineTo) {
FPOINT mid,to;
- mid.x = l->sx/20.0+advance;
- mid.y = l->sy/20.0;
- to.x = l->x/20.0+advance;
- to.y = l->y/20.0;
+ mid.x = l->sx*size/100.0/20.0+advance;
+ mid.y = l->sy*size/100.0/20.0;
+ to.x = l->x*size/100.0/20.0+advance;
+ to.y = l->y*size/100.0/20.0;
draw->splineTo(draw, &mid, &to);
}
l = l->next;
}
swf_Shape2Free(shape2);
- advance += font->glyph[g].advance/20.0;
+ advance += font->glyph[g].advance*size/100.0/20.0;
}
}