[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] master 3f14e1c: [ftstring] Keep all advances together.
From: |
Alexei Podtelezhnikov |
Subject: |
[freetype2-demos] master 3f14e1c: [ftstring] Keep all advances together. |
Date: |
Tue, 11 Sep 2018 21:59:47 -0400 (EDT) |
branch: master
commit 3f14e1cd680a24c87bff573f0bd91d7ed766db32
Author: Alexei Podtelezhnikov <address@hidden>
Commit: Alexei Podtelezhnikov <address@hidden>
[ftstring] Keep all advances together.
* src/ftcommon.h (TGlyph): New `hadvance' field for kerned advance.
* src/ftcommon.c (string_load): Initialize it here.
(string_render_prepare): Modify it here.
(FTDemo_String_Draw): Use it here.
---
ChangeLog | 9 +++++
src/ftcommon.c | 108 +++++++++++++++++++++++----------------------------------
src/ftcommon.h | 1 +
3 files changed, 54 insertions(+), 64 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 427937c..acd2235 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2018-09-11 Alexei Podtelezhnikov <address@hidden>
+
+ [ftstring] Keep all advances together.
+
+ * src/ftcommon.h (TGlyph): New `hadvance' field for kerned advance.
+ * src/ftcommon.c (string_load): Initialize it here.
+ (string_render_prepare): Modify it here.
+ (FTDemo_String_Draw): Use it here.
+
2018-09-09 Alexei Podtelezhnikov <address@hidden>
[ftview] Draw warning box for zero-width glyphs.
diff --git a/src/ftcommon.c b/src/ftcommon.c
index 5beb011..a3c699e 100644
--- a/src/ftcommon.c
+++ b/src/ftcommon.c
@@ -1368,6 +1368,9 @@
glyph->vadvance.x = 0;
glyph->vadvance.y = -metrics->vertAdvance;
+ glyph->hadvance.x = metrics->horiAdvance;
+ glyph->hadvance.y = 0;
+
if ( handle->lcd_mode == LCD_MODE_LIGHT_SUBPIXEL )
glyph->delta = face->glyph->lsb_delta - face->glyph->rsb_delta;
else
@@ -1390,16 +1393,13 @@
static FT_Error
string_render_prepare( FTDemo_Handle* handle,
- FTDemo_String_Context* sc,
- FT_Vector* advances )
+ FTDemo_String_Context* sc )
{
FT_Face face;
FT_Size size;
- PGlyph glyph;
+ PGlyph glyph = handle->string;
+ PGlyph prev = handle->string + handle->string_length;
FT_Pos track_kern = 0;
- FT_UInt prev_index = 0;
- FT_Vector* prev_advance = NULL;
- FT_Vector extent = { 0, 0 };
FT_Int i;
@@ -1425,78 +1425,44 @@
for ( i = 0; i < handle->string_length; i++ )
{
- glyph = handle->string + i;
-
if ( !glyph->image )
continue;
- if ( sc->vertical )
- advances[i] = glyph->vadvance;
- else
+ if ( !sc->vertical )
{
- advances[i] = glyph->image->advance;
- advances[i].x >>= 10;
- advances[i].y >>= 10;
-
if ( handle->lcd_mode == LCD_MODE_LIGHT_SUBPIXEL )
- advances[i].x += glyph->delta;
-
- if ( prev_advance )
- {
- prev_advance->x += track_kern;
+ glyph->hadvance.x += glyph->delta;
- if ( sc->kerning_mode )
- {
- FT_Vector kern;
+ prev->hadvance.x += track_kern;
+ if ( sc->kerning_mode )
+ {
+ FT_Vector kern;
- FT_Get_Kerning( face, prev_index, glyph->glyph_index,
- FT_KERNING_UNFITTED, &kern );
- prev_advance->x += kern.x;
- prev_advance->y += kern.y;
+ FT_Get_Kerning( face, prev->glyph_index, glyph->glyph_index,
+ FT_KERNING_UNFITTED, &kern );
- if ( handle->lcd_mode != LCD_MODE_LIGHT_SUBPIXEL &&
- sc->kerning_mode > KERNING_MODE_NORMAL )
- prev_advance->x += glyph->delta;
- }
- }
- }
+ prev->hadvance.x += kern.x;
+ prev->hadvance.y += kern.y;
- if ( prev_advance )
- {
- if ( handle->lcd_mode != LCD_MODE_LIGHT_SUBPIXEL &&
- handle->hinted )
- {
- prev_advance->x = ROUND( prev_advance->x );
- prev_advance->y = ROUND( prev_advance->y );
+ if ( handle->lcd_mode != LCD_MODE_LIGHT_SUBPIXEL &&
+ sc->kerning_mode > KERNING_MODE_NORMAL )
+ prev->hadvance.x += glyph->delta;
}
-
- extent.x += prev_advance->x;
- extent.y += prev_advance->y;
}
- prev_index = glyph->glyph_index;
- prev_advance = advances + i;
- }
-
- if ( prev_advance )
- {
if ( handle->lcd_mode != LCD_MODE_LIGHT_SUBPIXEL &&
handle->hinted )
{
- prev_advance->x = ROUND( prev_advance->x );
- prev_advance->y = ROUND( prev_advance->y );
+ prev->hadvance.x = ROUND( prev->hadvance.x );
+ prev->hadvance.y = ROUND( prev->hadvance.y );
}
- extent.x += prev_advance->x;
- extent.y += prev_advance->y;
+ prev = glyph;
+ glyph++;;
}
- /* store the extent in the last slot */
- i = handle->string_length - 1;
- advances[i] = extent;
-
return FT_Err_Ok;
}
@@ -1509,7 +1475,8 @@
int y )
{
int n;
- FT_Vector pen, advances[MAX_GLYPHS];
+ FT_Vector pen = { 0, 0};
+ FT_Vector advance;
FT_Size size;
FT_Face face;
@@ -1536,15 +1503,26 @@
handle->string_reload = 0;
}
- error = string_render_prepare( handle, sc, advances );
+ error = string_render_prepare( handle, sc );
if ( error )
return error;
/* change to Cartesian coordinates */
y = display->bitmap->rows - y;
- /* get the extent, which we store in the last slot */
- pen = advances[handle->string_length - 1];
+ /* calculate the extent */
+ if ( sc->vertical )
+ for ( n = 0; n < handle->string_length; n++ )
+ {
+ pen.x += handle->string[n].vadvance.x;
+ pen.y += handle->string[n].vadvance.y;
+ }
+ else
+ for ( n = 0; n < handle->string_length; n++ )
+ {
+ pen.x += handle->string[n].hadvance.x;
+ pen.y += handle->string[n].hadvance.y;
+ }
pen.x = FT_MulFix( pen.x, sc->center );
pen.y = FT_MulFix( pen.y, sc->center );
@@ -1610,11 +1588,13 @@
}
}
+ advance = sc->vertical ? glyph->vadvance : glyph->hadvance;
+
if ( sc->matrix )
- FT_Vector_Transform( advances + n, sc->matrix );
+ FT_Vector_Transform( &advance, sc->matrix );
- pen.x += advances[n].x;
- pen.y += advances[n].y;
+ pen.x += advance.x;
+ pen.y += advance.y;
FT_Glyph_Get_CBox( image, FT_GLYPH_BBOX_PIXELS, &bbox );
diff --git a/src/ftcommon.h b/src/ftcommon.h
index 1bc4c33..dbb0cdd 100644
--- a/src/ftcommon.h
+++ b/src/ftcommon.h
@@ -117,6 +117,7 @@
FT_Glyph image; /* the glyph image */
FT_Pos delta; /* delta caused by hinting */
+ FT_Vector hadvance; /* kerned horizontal advance */
FT_Vector vvector; /* vert. origin => hori. origin */
FT_Vector vadvance; /* vertical advance */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] master 3f14e1c: [ftstring] Keep all advances together.,
Alexei Podtelezhnikov <=