[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] master 3659e83 1/2: Teach `FT_String_Draw' to recycle
From: |
Alexei Podtelezhnikov |
Subject: |
[freetype2-demos] master 3659e83 1/2: Teach `FT_String_Draw' to recycle glyphs. |
Date: |
Thu, 13 Sep 2018 23:24:05 -0400 (EDT) |
branch: master
commit 3659e839ed0594d9379d14e86e03af46f8954ab1
Author: Alexei Podtelezhnikov <address@hidden>
Commit: Alexei Podtelezhnikov <address@hidden>
Teach `FT_String_Draw' to recycle glyphs.
* src/ftcommon.h (FTDemo_String_Context): New fields for offset glyph
and extent to fill.
(FTDemo_String_Draw): Return the number of glyphs drawn.
* src/ftcommon.c (FTDemo_String_Draw): Implement glyph recycling until
the extent is full.
---
ChangeLog | 10 ++++++++++
src/ftcommon.c | 35 ++++++++++++++++++++++++-----------
src/ftcommon.h | 7 ++++++-
3 files changed, 40 insertions(+), 12 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 82f35ce..0b52588 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2018-09-13 Alexei Podtelezhnikov <address@hidden>
+
+ Teach `FT_String_Draw' to recycle glyphs.
+
+ * src/ftcommon.h (FTDemo_String_Context): New fields for offset glyph
+ and extent to fill.
+ (FTDemo_String_Draw): Return the number of glyphs drawn.
+ * src/ftcommon.c (FTDemo_String_Draw): Implement glyph recycling until
+ the extent is full.
+
2018-09-12 Alexei Podtelezhnikov <address@hidden>
[ftstring] Load glyphs and advances explicitly.
diff --git a/src/ftcommon.c b/src/ftcommon.c
index c0149bd..b803d70 100644
--- a/src/ftcommon.c
+++ b/src/ftcommon.c
@@ -1423,37 +1423,50 @@
}
- FT_Error
+ int
FTDemo_String_Draw( FTDemo_Handle* handle,
FTDemo_Display* display,
FTDemo_String_Context* sc,
int x,
int y )
{
- int n;
+ int first = sc->offset;
+ int last = handle->string_length;
+ int m, n;
FT_Vector pen = { 0, 0};
FT_Vector advance;
- if ( !sc ||
- x < 0 ||
+ if ( x < 0 ||
y < 0 ||
x > display->bitmap->width ||
y > display->bitmap->rows )
- return FT_Err_Invalid_Argument;
+ return 0;
/* change to Cartesian coordinates */
y = display->bitmap->rows - y;
/* calculate the extent */
- if ( sc->vertical )
- for ( n = 0; n < handle->string_length; n++ )
+ if ( sc->extent )
+ for( n = first; ; n++ )
+ {
+ m = n % handle->string_length; /* recycling */
+ if ( pen.x + handle->string[m].hadvance.x > sc->extent )
+ {
+ last = n;
+ break;
+ }
+ pen.x += handle->string[m].hadvance.x;
+ pen.y += handle->string[m].hadvance.y;
+ }
+ else if ( sc->vertical )
+ for ( n = first; n < last; n++ )
{
pen.x += handle->string[n].vadvance.x;
pen.y += handle->string[n].vadvance.y;
}
else
- for ( n = 0; n < handle->string_length; n++ )
+ for ( n = first; n < last; n++ )
{
pen.x += handle->string[n].hadvance.x;
pen.y += handle->string[n].hadvance.y;
@@ -1469,9 +1482,9 @@
pen.x = ( x << 6 ) - pen.x;
pen.y = ( y << 6 ) - pen.y;
- for ( n = 0; n < handle->string_length; n++ )
+ for ( n = first; n < last; n++ )
{
- PGlyph glyph = handle->string + n;
+ PGlyph glyph = handle->string + n % handle->string_length;
FT_Glyph image;
FT_BBox bbox;
@@ -1564,7 +1577,7 @@
FT_Done_Glyph( image );
}
- return error;
+ return last - first;
}
diff --git a/src/ftcommon.h b/src/ftcommon.h
index 3a3b04c..3e8f5b5 100644
--- a/src/ftcommon.h
+++ b/src/ftcommon.h
@@ -168,10 +168,14 @@
{
int kerning_mode;
int kerning_degree;
+
FT_Fixed center; /* 0..1 */
int vertical; /* displayed vertically? */
FT_Matrix* matrix; /* string transformation */
+ FT_Pos extent; /* extent to fill, glyphs recycled */
+ int offset; /* initial glyph */
+
} FTDemo_String_Context;
typedef struct
@@ -345,8 +349,9 @@
/* draw a string centered at (center_x, center_y) -- */
+ /* returns the number of rendered glyphs */
/* note that handle->use_sbits_cache is not supported */
- FT_Error
+ int
FTDemo_String_Draw( FTDemo_Handle* handle,
FTDemo_Display* display,
FTDemo_String_Context* sc,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] master 3659e83 1/2: Teach `FT_String_Draw' to recycle glyphs.,
Alexei Podtelezhnikov <=