{
double l1 = sqrt(in->m00 * in->m00 + in->m01 * in->m01);
double l2 = sqrt(in->m10 * in->m10 + in->m11 * in->m11);
- double l = l1+l2;
+ double l = (l1+l2)/2.0;
if(l < 1e-10) {
memset(out, 0, sizeof(*out));
return;
gfxfont_t*font;
mymatrix_t matrix;
int*used;
- double dx,dy;
+ double dx;
} transformedfont_t;
static transformedfont_t* transformedfont_new(gfxfont_t*orig, mymatrix_t*m)
transformedfont_t*f = rfx_calloc(sizeof(transformedfont_t));
f->orig = orig;
f->matrix = *m;
- f->used = malloc(sizeof(f->used[0])*orig->num_glyphs);
+ 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)
+ f->used[t]=1; //always preserve the space char in fonts
+ }
return f;
}
{
internal_t*i = (internal_t*)f->internal;
mymatrix_t m;
- matrix_convert(matrix, font->id, &m, 0);
+ if(!font->id)
+ msg("<error> Font has no ID");
+ matrix_convert(matrix, font->id?font->id:"unknown", &m, 0);
transformedfont_t*fd = dict_lookup(i->matrices, &m);
if(!fd) {
fd = transformedfont_new(font, &m);
m.ty = 0;
g->line = gfxline_clone(g->line);
gfxline_transform(g->line, &m);
+ if(m.m00>0)
+ g->advance *= m.m00;
}
static gfxresult_t* pass1_finish(gfxfilter_t*f, gfxdevice_t*out)
gfxline_t*line = font->glyphs[t].line;
gfxbbox_t b = gfxline_getbbox(line);
total = gfxbbox_expand_to_bbox(total, b);
- if(b.xmax > 0)
- font->glyphs[t].advance = b.xmax;
}
if(count)
average_xmax /= count;
fd->dx = -total.xmin;
- fd->dy = 0;
- double adx = fd->dx>0?fd->dx:0;
-
+ font->ascent = total.ymax;
+ font->descent = -total.ymin;
+
for(t=0;t<count;t++) {
gfxline_t*line = font->glyphs[t].line;
- font->glyphs[t].advance += adx;
while(line) {
line->x += fd->dx;
- line->y += fd->dy;
line->sx += fd->dx;
- line->sy += fd->dy;
line = line->next;
}
}
return out->finish(out);
}
+static void pass2_addfont(gfxfilter_t*f, gfxfont_t*font, gfxdevice_t*out)
+{
+ /* we throw away original fonts, and do the addfont() for the transformed
+ fonts in the first drawchar() */
+}
+
static void pass2_drawchar(gfxfilter_t*f, gfxfont_t*font, int glyphnr, gfxcolor_t*color, gfxmatrix_t*matrix, gfxdevice_t*out)
{
internal_t*i = (internal_t*)f->internal;
mymatrix_t m;
gfxmatrix_t scalematrix;
- matrix_convert(matrix, font->id, &m, &scalematrix);
+ matrix_convert(matrix, font->id?font->id:"unknown", &m, &scalematrix);
transformedfont_t*d = dict_lookup(i->matrices, &m);
- scalematrix.tx -= d->dx;
- scalematrix.ty -= d->dy;
+ scalematrix.tx -= d->dx*scalematrix.m00;
out->drawchar(out, d->font, d->used[glyphnr], color, &scalematrix);
}
f->pass1.internal = i;
f->pass2.name = "remove font transforms pass 2";
+ f->pass2.addfont = pass2_addfont;
f->pass2.drawchar = pass2_drawchar;
f->pass2.internal = i;