#ifdef __GNUC__
-void __attribute__((noinline))
+int __attribute__((noinline))
matrix_convert(gfxmatrix_t*in, const char*id, mymatrix_t*out, gfxmatrix_t*scalematrix, unsigned char alpha)
#else
-void matrix_convert(gfxmatrix_t*in, const char*id, mymatrix_t*out, gfxmatrix_t*scalematrix, unsigned char alpha)
+int matrix_convert(gfxmatrix_t*in, const char*id, mymatrix_t*out, gfxmatrix_t*scalematrix, unsigned char alpha)
#endif
{
double l1 = sqrt(in->m00 * in->m00 + in->m01 * in->m01);
double l = (l1+l2)/2.0;
if(l < 1e-10) {
memset(out, 0, sizeof(*out));
- return;
+ return 0;
}
out->m00 = in->m00 / l;
out->m10 = in->m10 / l;
scalematrix->tx = in->tx;
scalematrix->ty = in->ty;
}
+ return 1;
}
typedef struct _matrixdata {
f->used = rfx_calloc(sizeof(f->used[0])*orig->num_glyphs);
int t;
for(t=0;t<orig->num_glyphs;t++) {
- if(orig->glyphs[t].unicode==32)
+ if(orig->glyphs[t].unicode==32 &&
+ (!orig->glyphs[t].line ||
+ !orig->glyphs[t].line->next ||
+ !orig->glyphs[t].line->next->next))
f->used[t]=1; //always preserve the space char in fonts
}
return f;
mymatrix_t m;
if(!font->id)
msg("<error> Font has no ID");
- matrix_convert(matrix, font->id?font->id:"unknown", &m, 0, color->a);
+ if(!matrix_convert(matrix, font->id?font->id:"unknown", &m, 0, color->a))
+ return;
transformedfont_t*fd = dict_lookup(i->matrices, &m);
if(!fd) {
fd = transformedfont_new(font, &m);
if(fd->used[t]) {
font->glyphs[count] = fd->orig->glyphs[t];
glyph_transform(&font->glyphs[count], &fd->matrix);
- fd->used[t] = count;
+ fd->used[t] = count + 1;
count++;
}
}
if(count)
average_xmax /= count;
- fd->dx = -total.xmin;
+ fd->dx = 0;//-total.xmin;
font->ascent = total.ymax;
font->descent = -total.ymin;
g->line->x = g->advance;
}
}
+
+ if(fd->matrix.m00>0) {
+ /* subset kerning table */
+ count = 0;
+ for(t=0;t<fd->orig->kerning_size;t++) {
+ int char1 = fd->used[fd->orig->kerning[t].c1]-1;
+ int char2 = fd->used[fd->orig->kerning[t].c2]-1;
+ if(char1>=0 && char2>=0) {
+ count++;
+ }
+ }
+ font->kerning = malloc(sizeof(font->kerning[0])*count);
+ font->kerning_size = count;
+ count = 0;
+ for(t=0;t<fd->orig->kerning_size;t++) {
+ int char1 = fd->used[fd->orig->kerning[t].c1]-1;
+ int char2 = fd->used[fd->orig->kerning[t].c2]-1;
+ if(char1>=0 && char2>=0) {
+ font->kerning[count].c1 = char1;
+ font->kerning[count].c2 = char2;
+ font->kerning[count].advance = fd->orig->kerning[t].advance * fd->matrix.m00;
+ count++;
+ }
+ }
+ }
gfxfont_fix_unicode(font);
}
return out->finish(out);
if(!m.alpha)
color.a = 255;
- out->drawchar(out, d->font, d->used[glyphnr], &color, &scalematrix);
+ out->drawchar(out, d->font, d->used[glyphnr]-1, &color, &scalematrix);
+}
+
+static gfxresult_t* pass2_finish(gfxfilter_t*f, gfxdevice_t*out)
+{
+ internal_t*i = (internal_t*)f->internal;
+ DICT_ITERATE_DATA(i->matrices, transformedfont_t*, fd) {
+ if(fd->used) {
+ free(fd->used);fd->used=0;
+ }
+ free(fd);
+ }
+ dict_destroy(i->matrices);i->matrices=0;
+ return out->finish(out);
}
void gfxtwopassfilter_remove_font_transforms_init(gfxtwopassfilter_t*f)
f->pass2.name = "remove font transforms pass 2";
f->pass2.addfont = pass2_addfont;
f->pass2.drawchar = pass2_drawchar;
+ f->pass2.finish = pass2_finish;
f->pass2.internal = i;
i->matrices = dict_new2(&mymatrix_type);