[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] master f4f64fa: [ftstring, ftview] Loosely match bitma
From: |
Alexei Podtelezhnikov |
Subject: |
[freetype2-demos] master f4f64fa: [ftstring, ftview] Loosely match bitmap font sizes. |
Date: |
Sun, 14 May 2017 23:53:01 -0400 (EDT) |
branch: master
commit f4f64fa9fb824a9ad2a2c083da42e33270b40759
Author: Alexei Podtelezhnikov <address@hidden>
Commit: Alexei Podtelezhnikov <address@hidden>
[ftstring, ftview] Loosely match bitmap font sizes.
* src/ftcommon.c (FTDemo_Set_Current_Size,
FTDemo_Set_Current_Charsize): Round requested size to the closest
available ppem for bitmap fonts.
* src/ftview.c (Render_Waterfall): Simplify accordingly.
(write_header): Highlight ppem that does not match the point size.
* src/ftstring.c (write_header): Report ppem.
---
ChangeLog | 13 +++++++++++++
src/ftcommon.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
src/ftstring.c | 13 +++++++++++--
src/ftview.c | 34 ++++++++++------------------------
4 files changed, 87 insertions(+), 26 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index adf9fea..89debc1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
2017-05-14 Alexei Podtelezhnikov <address@hidden>
+ [ftstring, ftview] Loosely match bitmap font sizes.
+
+ * src/ftcommon.c (FTDemo_Set_Current_Size,
+ FTDemo_Set_Current_Charsize): Round requested size to the closest
+ available ppem for bitmap fonts.
+
+ * src/ftview.c (Render_Waterfall): Simplify accordingly.
+ (write_header): Highlight ppem that does not match the point size.
+
+ * src/ftstring.c (write_header): Report ppem.
+
+2017-05-14 Alexei Podtelezhnikov <address@hidden>
+
* src/ftview.c (Render_Stroke): Fix segmentation fault.
2017-05-13 Werner Lemberg <address@hidden>
diff --git a/src/ftcommon.c b/src/ftcommon.c
index 68c9b33..0c19127 100644
--- a/src/ftcommon.c
+++ b/src/ftcommon.c
@@ -554,9 +554,35 @@
FTDemo_Set_Current_Size( FTDemo_Handle* handle,
int pixel_size )
{
+ FT_Face face;
+
+
if ( pixel_size > 0xFFFF )
pixel_size = 0xFFFF;
+ error = FTC_Manager_LookupFace( handle->cache_manager,
+ handle->scaler.face_id, &face );
+
+ if ( !error && !FT_IS_SCALABLE ( face ) )
+ {
+ int i, j = 0;
+ int c, d = abs( (int)face->available_sizes[j].y_ppem - pixel_size * 64
);
+
+
+ for ( i = 1; i < face->num_fixed_sizes; i++ )
+ {
+ c = abs( (int)face->available_sizes[i].y_ppem - pixel_size * 64 );
+
+ if ( c < d )
+ {
+ d = c;
+ j = i;
+ }
+ }
+
+ pixel_size = face->available_sizes[j].y_ppem / 64 ;
+ }
+
handle->scaler.width = (FT_UInt)pixel_size;
handle->scaler.height = (FT_UInt)pixel_size;
handle->scaler.pixel = 1; /* activate integer format */
@@ -572,10 +598,37 @@
int char_size,
int resolution )
{
+ FT_Face face;
+
+
/* in 26.6 format, corresponding to (almost) 0x4000ppem */
if ( char_size > 0xFFFFF )
char_size = 0xFFFFF;
+ error = FTC_Manager_LookupFace( handle->cache_manager,
+ handle->scaler.face_id, &face );
+
+ if ( !error && !FT_IS_SCALABLE ( face ) )
+ {
+ int pixel_size = char_size * resolution / 72;
+ int i, j = 0;
+ int c, d = abs( (int)face->available_sizes[j].y_ppem - pixel_size );
+
+
+ for ( i = 1; i < face->num_fixed_sizes; i++ )
+ {
+ c = abs( (int)face->available_sizes[i].y_ppem - pixel_size );
+
+ if ( c < d )
+ {
+ d = c;
+ j = i;
+ }
+ }
+
+ char_size = face->available_sizes[j].y_ppem * 72 / resolution;
+ }
+
handle->scaler.width = (FT_UInt)char_size;
handle->scaler.height = (FT_UInt)char_size;
handle->scaler.pixel = 0; /* activate 26.6 format */
diff --git a/src/ftstring.c b/src/ftstring.c
index 6f89e05..4d46a7a 100644
--- a/src/ftstring.c
+++ b/src/ftstring.c
@@ -526,6 +526,7 @@
{
FT_Face face;
const char* basename;
+ double ppem = 0.0;
error = FTC_Manager_LookupFace( handle->cache_manager,
@@ -543,6 +544,13 @@
sprintf( status.header_buffer,
"%.50s %.50s (file `%.100s')", face->family_name,
face->style_name, basename );
+
+ if ( FT_IS_SCALABLE( face ) )
+ ppem = FT_MulFix( face->units_per_EM,
+ face->size->metrics.y_scale ) / 64.0;
+ else
+ ppem = (double)face->size->metrics.y_ppem;
+
break;
case FT_Err_Invalid_Pixel_Size:
@@ -567,8 +575,9 @@
grWriteCellString( display->bitmap, 0, 0,
status.header, display->fore_color );
- sprintf( status.header_buffer, "at %g points, angle = %d, gamma = %g",
- status.ptsize / 64.0, status.angle, status.gamma );
+ sprintf( status.header_buffer,
+ "at %g points (%.4g ppem), angle = %d, gamma = %g",
+ status.ptsize / 64.0, ppem, status.angle, status.gamma );
grWriteCellString( display->bitmap, 0, CELLSTRING_HEIGHT,
status.header_buffer, display->fore_color );
diff --git a/src/ftview.c b/src/ftview.c
index d377f9d..0809d31 100644
--- a/src/ftview.c
+++ b/src/ftview.c
@@ -579,7 +579,6 @@
int start_x, start_y, step_y, x, y;
int pt_size, max_size = 100000;
FT_Size size;
- FT_Face face;
int have_topleft, start;
char text[256];
@@ -587,27 +586,6 @@
const char* pEnd;
- error = FTC_Manager_LookupFace( handle->cache_manager,
- handle->scaler.face_id, &face );
- if ( error )
- {
- /* can't access the font file: do not render anything */
- fprintf( stderr, "can't access font file %p\n",
- (void*)handle->scaler.face_id );
- return 0;
- }
-
- if ( !FT_IS_SCALABLE( face ) )
- {
- int i;
-
-
- max_size = 0;
- for ( i = 0; i < face->num_fixed_sizes; i++ )
- if ( face->available_sizes[i].height >= max_size / 64 )
- max_size = face->available_sizes[i].height * 64;
- }
-
start_x = START_X;
start_y = START_Y;
@@ -699,6 +677,7 @@
}
FTDemo_Set_Current_Charsize( handle, first_size, status.res );
+ FTDemo_Get_Size( handle, &size );
return FT_Err_Ok;
}
@@ -1421,8 +1400,14 @@
if ( error_code == FT_Err_Ok )
{
+ int highlight;
+
+
+ highlight = abs( status.ptsize * status.res -
+ face->size->metrics.y_ppem * 72 * 64 ) > 36 * 64;
+
/* ppem */
- if ( face->face_flags & FT_FACE_FLAG_SCALABLE )
+ if ( FT_IS_SCALABLE( face ) )
sprintf( buf, "(%.4gppem)",
FT_MulFix( face->units_per_EM,
face->size->metrics.y_scale ) / 64.0 );
@@ -1430,7 +1415,8 @@
sprintf( buf, "(%dppem)",
face->size->metrics.y_ppem );
grWriteCellString( display->bitmap, 8 * x , (line++) * HEADER_HEIGHT,
- buf, display->fore_color );
+ buf, highlight ? display->warn_color
+ : display->fore_color );
}
else
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] master f4f64fa: [ftstring, ftview] Loosely match bitmap font sizes.,
Alexei Podtelezhnikov <=