[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] master 42ff129: [ftcommon] Support named instances of
From: |
Werner LEMBERG |
Subject: |
[freetype2-demos] master 42ff129: [ftcommon] Support named instances of GX variation fonts. |
Date: |
Thu, 13 Aug 2015 18:37:42 +0000 |
branch: master
commit 42ff129b76947a98f0318fae67ed15fc8af9b472
Author: Werner Lemberg <address@hidden>
Commit: Werner Lemberg <address@hidden>
[ftcommon] Support named instances of GX variation fonts.
* src/ftcommon.c (FTDemo_Install_Font): Add inner loop for named
instances.
---
ChangeLog | 7 ++
src/ftcommon.c | 197 +++++++++++++++++++++++++++++++-------------------------
2 files changed, 116 insertions(+), 88 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 0ac9234..89df45c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2015-08-13 Werner Lemberg <address@hidden>
+
+ [ftcommon] Support named instances of GX variation fonts.
+
+ * src/ftcommon.c (FTDemo_Install_Font): Add inner loop for named
+ instances.
+
2015-08-05 Werner Lemberg <address@hidden>
[ftgrid] Avoid invalid left-shift of negative values.
diff --git a/src/ftcommon.c b/src/ftcommon.c
index 5940a26..291d251 100644
--- a/src/ftcommon.c
+++ b/src/ftcommon.c
@@ -367,6 +367,13 @@
strncpy( filename, filepath, len );
filename[len] = 0;
+ /* We use a conservative approach here, at the cost of calling */
+ /* `FT_New_Face' quite often. The idea is that our demo programs */
+ /* should be able to try all faces and named instances of a font, */
+ /* expecting that some faces don't work for various reasons, e.g., */
+ /* a broken subfont, or an unsupported NFNT bitmap font in a Mac */
+ /* dfont resource that holds more than a single font. */
+
error = FT_New_Face( handle->library, filename, -1, &face );
if ( error )
return error;
@@ -377,120 +384,134 @@
for ( i = 0; i < num_faces; i++ )
{
PFont font;
+ long j, instance_count;
- error = FT_New_Face( handle->library, filename, i, &face );
+ error = FT_New_Face( handle->library, filename, -( i + 1 ), &face );
if ( error )
continue;
+ instance_count = face->style_flags >> 16;
+ FT_Done_Face( face );
- if ( outline_only && !FT_IS_SCALABLE( face ) )
+ /* load face with and without named instances */
+ for ( j = 0; j < instance_count + 1; j++ )
{
- FT_Done_Face( face );
- continue;
- }
-
- if ( handle->encoding != FT_ENCODING_NONE )
- {
- error = FT_Select_Charmap( face, handle->encoding );
+ error = FT_New_Face( handle->library,
+ filename,
+ ( j << 16 ) + i,
+ &face );
if ( error )
+ continue;
+
+ if ( outline_only && !FT_IS_SCALABLE( face ) )
{
FT_Done_Face( face );
continue;
}
- }
-
- font = (PFont)malloc( sizeof ( *font ) );
- /* We allocate four more bytes since we want to attach an AFM */
- /* or PFM file for Type 1 fonts (if available). Such fonts */
- /* always have the extension `.afm' or `.pfm'. */
- font->filepathname = (char*)malloc( strlen( filename ) + 4 + 1 );
- strcpy( (char*)font->filepathname, filename );
+ if ( handle->encoding != FT_ENCODING_NONE )
+ {
+ error = FT_Select_Charmap( face, handle->encoding );
+ if ( error )
+ {
+ FT_Done_Face( face );
+ continue;
+ }
+ }
- font->face_index = i;
- font->cmap_index = face->charmap ? FT_Get_Charmap_Index( face->charmap )
- : 0;
+ font = (PFont)malloc( sizeof ( *font ) );
- if ( handle->preload )
- {
- FILE* file = fopen( filename, "rb" );
- int file_size;
+ /* We allocate four more bytes since we want to attach an AFM */
+ /* or PFM file for Type 1 fonts (if available). Such fonts */
+ /* always have the extension `.afm' or `.pfm'. */
+ font->filepathname = (char*)malloc( strlen( filename ) + 4 + 1 );
+ strcpy( (char*)font->filepathname, filename );
+ font->face_index = ( j << 16 ) + i;
+ font->cmap_index = face->charmap ? FT_Get_Charmap_Index( face->charmap
)
+ : 0;
- if ( file == NULL ) /* shouldn't happen */
+ if ( handle->preload )
{
- free( font );
- return FT_Err_Invalid_Argument;
- }
+ FILE* file = fopen( filename, "rb" );
+ int file_size;
- fseek( file, 0, SEEK_END );
- file_size = ftell( file );
- fseek( file, 0, SEEK_SET );
- if ( file_size <= 0 )
- return FT_Err_Invalid_Stream_Operation;
+ if ( file == NULL ) /* shouldn't happen */
+ {
+ free( font );
+ return FT_Err_Invalid_Argument;
+ }
- font->file_address = malloc( (size_t)file_size );
- fread( font->file_address, 1, (size_t)file_size, file );
+ fseek( file, 0, SEEK_END );
+ file_size = ftell( file );
+ fseek( file, 0, SEEK_SET );
- font->file_size = (size_t)file_size;
+ if ( file_size <= 0 )
+ return FT_Err_Invalid_Stream_Operation;
- fclose( file );
- }
- else
- {
- font->file_address = NULL;
- font->file_size = 0;
- }
+ font->file_address = malloc( (size_t)file_size );
+ fread( font->file_address, 1, (size_t)file_size, file );
- switch ( handle->encoding )
- {
- case FT_ENCODING_NONE:
- font->num_indices = face->num_glyphs;
- break;
+ font->file_size = (size_t)file_size;
- case FT_ENCODING_UNICODE:
- font->num_indices = 0x110000L;
- break;
+ fclose( file );
+ }
+ else
+ {
+ font->file_address = NULL;
+ font->file_size = 0;
+ }
- case FT_ENCODING_ADOBE_LATIN_1:
- case FT_ENCODING_ADOBE_STANDARD:
- case FT_ENCODING_ADOBE_EXPERT:
- case FT_ENCODING_ADOBE_CUSTOM:
- case FT_ENCODING_APPLE_ROMAN:
- font->num_indices = 0x100L;
- break;
+ switch ( handle->encoding )
+ {
+ case FT_ENCODING_NONE:
+ font->num_indices = face->num_glyphs;
+ break;
- /* some fonts use range 0x00-0x100, others have 0xF000-0xF0FF */
- case FT_ENCODING_MS_SYMBOL:
- font->num_indices = 0x10000L;
+ case FT_ENCODING_UNICODE:
+ font->num_indices = 0x110000L;
+ break;
- default:
- font->num_indices = 0x10000L;
- }
+ case FT_ENCODING_ADOBE_LATIN_1:
+ case FT_ENCODING_ADOBE_STANDARD:
+ case FT_ENCODING_ADOBE_EXPERT:
+ case FT_ENCODING_ADOBE_CUSTOM:
+ case FT_ENCODING_APPLE_ROMAN:
+ font->num_indices = 0x100L;
+ break;
- FT_Done_Face( face );
- face = NULL;
+ /* some fonts use range 0x00-0x100, others have 0xF000-0xF0FF */
+ case FT_ENCODING_MS_SYMBOL:
+ font->num_indices = 0x10000L;
- if ( handle->max_fonts == 0 )
- {
- handle->max_fonts = 16;
- handle->fonts = (PFont*)calloc( (size_t)handle->max_fonts,
- sizeof ( PFont ) );
- }
- else if ( handle->num_fonts >= handle->max_fonts )
- {
- handle->max_fonts *= 2;
- handle->fonts = (PFont*)realloc( handle->fonts,
- (size_t)handle->max_fonts *
- sizeof ( PFont ) );
-
- memset( &handle->fonts[handle->num_fonts], 0,
- (size_t)( handle->max_fonts - handle->num_fonts ) *
- sizeof ( PFont ) );
- }
+ default:
+ font->num_indices = 0x10000L;
+ }
+
+ FT_Done_Face( face );
+ face = NULL;
- handle->fonts[handle->num_fonts++] = font;
+ if ( handle->max_fonts == 0 )
+ {
+ handle->max_fonts = 16;
+ handle->fonts = (PFont*)calloc( (size_t)handle->max_fonts,
+ sizeof ( PFont ) );
+ }
+ else if ( handle->num_fonts >= handle->max_fonts )
+ {
+ handle->max_fonts *= 2;
+ handle->fonts = (PFont*)realloc( handle->fonts,
+ (size_t)handle->max_fonts *
+ sizeof ( PFont ) );
+
+ memset( &handle->fonts[handle->num_fonts], 0,
+ (size_t)( handle->max_fonts - handle->num_fonts ) *
+ sizeof ( PFont ) );
+ }
+
+ handle->fonts[handle->num_fonts++] = font;
+ }
}
return FT_Err_Ok;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] master 42ff129: [ftcommon] Support named instances of GX variation fonts.,
Werner LEMBERG <=