summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDr.Smile <vabnick@gmail.com>2017-10-22 05:58:24 +0300
committerDr.Smile <vabnick@gmail.com>2019-05-19 20:25:09 +0300
commit7e7182a0b397243f2c4a8fa42a5a057c82452a73 (patch)
treed174f1d53708a6df75374b9c07e545a8255f3f47
parentf4b0721d815de8df1e6d95be4769ffc57fe4da1d (diff)
downloadlibass-7e7182a0b397243f2c4a8fa42a5a057c82452a73.tar.bz2
libass-7e7182a0b397243f2c4a8fa42a5a057c82452a73.tar.xz
font: extract transformation from ass_font_get_glyph()
-rw-r--r--libass/ass_font.c17
-rw-r--r--libass/ass_font.h2
-rw-r--r--libass/ass_render.c18
3 files changed, 9 insertions, 28 deletions
diff --git a/libass/ass_font.c b/libass/ass_font.c
index 2c488cc..480d5f9 100644
--- a/libass/ass_font.c
+++ b/libass/ass_font.c
@@ -250,7 +250,6 @@ size_t ass_font_construct(void *key, void *value, void *priv)
font->desc.italic = desc->italic;
font->desc.vertical = desc->vertical;
- font->scale_x = font->scale_y = 1.;
font->size = 0.;
int error = add_face(render_priv->fontselect, font, 0);
@@ -259,15 +258,6 @@ size_t ass_font_construct(void *key, void *value, void *priv)
return 1;
}
-/**
- * \brief Set font transformation matrix
- **/
-void ass_font_set_transform(ASS_Font *font, double scale_x, double scale_y)
-{
- font->scale_x = scale_x;
- font->scale_y = scale_y;
-}
-
void ass_face_set_size(FT_Face face, double size)
{
TT_HoriHeader *hori = FT_Get_Sfnt_Table(face, ft_sfnt_hhea);
@@ -580,13 +570,6 @@ FT_Glyph ass_font_get_glyph(ASS_Font *font, int face_index, int index,
ass_strike_outline_glyph(face, font, glyph, deco & DECO_UNDERLINE,
deco & DECO_STRIKETHROUGH);
- // Apply scaling
- FT_Matrix scale = { double_to_d16(font->scale_x), 0, 0,
- double_to_d16(font->scale_y) };
- FT_Outline *outl = &((FT_OutlineGlyph) glyph)->outline;
- FT_Outline_Transform(outl, &scale);
- glyph->advance.x *= font->scale_x;
-
return glyph;
}
diff --git a/libass/ass_font.h b/libass/ass_font.h
index 6aa76ef..9bf418d 100644
--- a/libass/ass_font.h
+++ b/libass/ass_font.h
@@ -54,13 +54,11 @@ struct ass_font {
FT_Face faces[ASS_FONT_MAX_FACES];
ASS_ShaperFontData *shaper_priv;
int n_faces;
- double scale_x, scale_y; // current transform
double size;
};
void charmap_magic(ASS_Library *library, FT_Face face);
ASS_Font *ass_font_new(ASS_Renderer *render_priv, ASS_FontDesc *desc);
-void ass_font_set_transform(ASS_Font *font, double scale_x, double scale_y);
void ass_face_set_size(FT_Face face, double size);
void ass_font_set_size(ASS_Font *font, double size);
void ass_font_get_asc_desc(ASS_Font *font, int face_index,
diff --git a/libass/ass_render.c b/libass/ass_render.c
index f8dee8e..dbfa00b 100644
--- a/libass/ass_render.c
+++ b/libass/ass_render.c
@@ -1022,6 +1022,7 @@ size_t ass_outline_construct(void *key, void *value, void *priv)
double scale_x = d16_to_double(common->scale_x);
double scale_y = d16_to_double(common->scale_y);
+ ASS_DVector scale, offset = {0};
if (outline_key->type == OUTLINE_DRAWING) {
DrawingHashKey *k = &outline_key->u.drawing;
@@ -1029,7 +1030,6 @@ size_t ass_outline_construct(void *key, void *value, void *priv)
if (!ass_drawing_parse(&v->outline, &bbox, k->text, render_priv->library))
return 1;
- ASS_DVector scale, offset = {0};
double w = render_priv->font_scale / (1 << (k->scale - 1));
scale.x = scale_x * w;
scale.y = scale_y * w;
@@ -1040,16 +1040,9 @@ size_t ass_outline_construct(void *key, void *value, void *priv)
v->desc = double_to_d6(pbo * scale_y * render_priv->font_scale);
v->asc = (bbox.y_max - bbox.y_min) * scale.y - v->desc;
offset.y = -v->asc;
-
- ASS_Outline *ol = &v->outline;
- for (size_t i = 0; i < ol->n_points; i++) {
- ol->points[i].x = lrint(ol->points[i].x * scale.x + offset.x);
- ol->points[i].y = lrint(ol->points[i].y * scale.y + offset.y);
- }
} else {
GlyphHashKey *k = &outline_key->u.glyph;
ass_face_set_size(k->font->faces[k->face_index], k->size);
- ass_font_set_transform(k->font, scale_x, scale_y);
FT_Glyph glyph =
ass_font_get_glyph(k->font, k->face_index, k->glyph_index,
render_priv->settings.hinting, k->flags);
@@ -1058,16 +1051,23 @@ size_t ass_outline_construct(void *key, void *value, void *priv)
if (!outline_convert(&v->outline, src))
return 1;
if (render_priv->settings.shaper == ASS_SHAPING_SIMPLE)
- v->advance = d16_to_d6(glyph->advance.x);
+ v->advance = d16_to_d6(glyph->advance.x * scale_x);
FT_Done_Glyph(glyph);
ass_font_get_asc_desc(k->font, k->face_index,
&v->asc, &v->desc);
v->asc *= scale_y;
v->desc *= scale_y;
}
+ scale.x = scale_x;
+ scale.y = scale_y;
}
v->valid = true;
+ ASS_Outline *ol = &v->outline;
+ for (size_t i = 0; i < ol->n_points; i++) {
+ ol->points[i].x = lrint(ol->points[i].x * scale.x + offset.x);
+ ol->points[i].y = lrint(ol->points[i].y * scale.y + offset.y);
+ }
outline_get_cbox(&v->outline, &v->bbox_scaled);
if (common->border_style == 3) {