[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] master d6cfeda: [ftview] Report the last available ind
From: |
Werner Lemberg |
Subject: |
[freetype2-demos] master d6cfeda: [ftview] Report the last available index or charcode. |
Date: |
Tue, 16 Nov 2021 22:50:51 -0500 (EST) |
branch: master
commit d6cfeda4a85322077de180e5c7ed9f505b78b90d
Author: Alexei Podtelezhnikov <apodtele@gmail.com>
Commit: Alexei Podtelezhnikov <apodtele@gmail.com>
[ftview] Report the last available index or charcode.
* src/ftcommon.c (get_last_char): Implement the binary search for
the last charcode using `FT_Get_Next_Char`.
(FTDemo_Set_Current_Font): Set the number of indices accordingly.
* src/ftview.c (write_header): Display the last charcode or index.
---
src/ftcommon.c | 41 +++++++++++++++++++++++++++++++++++------
src/ftview.c | 9 +++++++++
2 files changed, 44 insertions(+), 6 deletions(-)
diff --git a/src/ftcommon.c b/src/ftcommon.c
index 6e4f03e..45598a6 100644
--- a/src/ftcommon.c
+++ b/src/ftcommon.c
@@ -671,11 +671,40 @@
}
+ /* binary search for the last charcode */
+ static int
+ get_last_char( FT_Face face,
+ FT_Int idx,
+ FT_ULong max )
+ {
+ FT_ULong res, mid, min = 0;
+ FT_UInt gidx;
+
+
+ /* activate charmap */
+ face->charmap = face->charmaps[idx];
+
+ do
+ {
+ mid = ( min + max ) >> 1;
+ res = FT_Get_Next_Char( face, mid, &gidx );
+
+ if ( gidx )
+ min = res;
+ else
+ max = mid;
+ } while ( max > min );
+
+ return (int)max;
+ }
+
+
void
FTDemo_Set_Current_Font( FTDemo_Handle* handle,
PFont font )
{
FT_Face face;
+ int index = font->cmap_index;
handle->current_font = font;
@@ -684,8 +713,8 @@
error = FTC_Manager_LookupFace( handle->cache_manager,
handle->scaler.face_id, &face );
- if ( font->cmap_index < face->num_charmaps )
- handle->encoding = face->charmaps[font->cmap_index]->encoding;
+ if ( index < face->num_charmaps )
+ handle->encoding = face->charmaps[index]->encoding;
else
handle->encoding = FT_ENCODING_ORDER;
@@ -696,7 +725,7 @@
break;
case FT_ENCODING_UNICODE:
- font->num_indices = 0x110000L;
+ font->num_indices = get_last_char( face, index, 0x110000 ) + 1;
break;
case FT_ENCODING_ADOBE_LATIN_1:
@@ -704,16 +733,16 @@
case FT_ENCODING_ADOBE_EXPERT:
case FT_ENCODING_ADOBE_CUSTOM:
case FT_ENCODING_APPLE_ROMAN:
- font->num_indices = 0x100L;
+ font->num_indices = 0x100;
break;
/* some fonts use range 0x00-0x100, others have 0xF000-0xF0FF */
case FT_ENCODING_MS_SYMBOL:
- font->num_indices = 0x10000L;
+ font->num_indices = get_last_char( face, index, 0x10000 ) + 1;
break;
default:
- font->num_indices = 0x10000L;
+ font->num_indices = get_last_char( face, index, 0x10000 ) + 1;
}
}
diff --git a/src/ftview.c b/src/ftview.c
index 94f8137..cee406d 100644
--- a/src/ftview.c
+++ b/src/ftview.c
@@ -1573,6 +1573,15 @@
}
}
+ /* Last index or charcode */
+ snprintf( buf, sizeof ( buf ),
+ handle->encoding == FT_ENCODING_ORDER ? "last: %d" :
+ handle->encoding == FT_ENCODING_UNICODE ? "last: U+%04X" :
+ "last: 0x%X",
+ handle->current_font->num_indices - 1 );
+ grWriteCellString( display->bitmap, 0, display->bitmap->rows -
GR_FONT_SIZE,
+ buf, display->fore_color );
+
grRefreshSurface( display->surface );
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] master d6cfeda: [ftview] Report the last available index or charcode.,
Werner Lemberg <=