From 9f4eef0a67a4ea9fd4a6188ec522e35d37c2ad36 Mon Sep 17 00:00:00 2001 From: Parth Wazurkar Date: Sun, 12 Aug 2018 23:17:03 +0530 Subject: [PATCH] [pk] Change `cmap' encoding scheme. * src/pk/pkdrivr.c(PK_Face_Init): - Change `pk_cmap_class' functions to use new encoding scheme. - Set charmap to `0: synthetic, platform 0, encoding 0 language 0' values. --- src/gf/gfdrivr.h | 3 +- src/pk/pkdrivr.c | 141 ++++++++++++++++++++++++++++++++++------------- src/pk/pkdrivr.h | 14 +++++ src/pk/pklib.c | 22 ++++++-- 4 files changed, 137 insertions(+), 43 deletions(-) diff --git a/src/gf/gfdrivr.h b/src/gf/gfdrivr.h index 5df04e9d6..122940d25 100644 --- a/src/gf/gfdrivr.h +++ b/src/gf/gfdrivr.h @@ -31,7 +31,7 @@ FT_BEGIN_HEADER typedef struct GF_EncodingRec_ { FT_Long enc; - FT_UShort glyph; + FT_UShort glyph; } GF_EncodingRec, *GF_Encoding; @@ -44,7 +44,6 @@ FT_BEGIN_HEADER FT_Byte *bitmap; FT_UInt raster; FT_UShort code; - FT_ULong nglyphs; } GF_BitmapRec, *GF_Bitmap; diff --git a/src/pk/pkdrivr.c b/src/pk/pkdrivr.c index 4baf616cf..bbb4b938d 100644 --- a/src/pk/pkdrivr.c +++ b/src/pk/pkdrivr.c @@ -43,9 +43,9 @@ typedef struct PK_CMapRec_ { - FT_CMapRec cmap; - FT_UInt32 bc; /* Beginning Character */ - FT_UInt32 ec; /* End Character */ + FT_CMapRec cmap; + FT_ULong num_encodings; + PK_Encoding encodings; } PK_CMapRec, *PK_CMap; @@ -57,8 +57,8 @@ PK_Face face = (PK_Face)FT_CMAP_FACE( cmap ); FT_UNUSED( init_data ); - cmap->bc = face->pk_glyph->code_min; - cmap->ec = face->pk_glyph->code_max; + cmap->num_encodings = face->pk_glyph->nencodings; + cmap->encodings = face->pk_glyph->encodings; return FT_Err_Ok; } @@ -69,54 +69,98 @@ { PK_CMap cmap = (PK_CMap)pkcmap; - cmap->bc = 0; - cmap->ec = -1; + cmap->encodings = NULL; + cmap->num_encodings = 0; } FT_CALLBACK_DEF( FT_UInt ) pk_cmap_char_index( FT_CMap pkcmap, - FT_UInt32 char_code ) + FT_UInt32 charcode ) { - FT_UInt gindex = 0; - PK_CMap cmap = (PK_CMap)pkcmap; + PK_CMap cmap = (PK_CMap)pkcmap; + PK_Encoding encodings = cmap->encodings; + FT_ULong min, max, mid; + FT_UInt result = 0; - char_code -= cmap->bc; + min = 0; + max = cmap->num_encodings; - if ( char_code < cmap->ec - cmap->bc + 1 ) - gindex = (FT_UInt)( char_code ); + while ( min < max ) + { + FT_ULong code; - return gindex; + + mid = ( min + max ) >> 1; + code = (FT_ULong)encodings[mid].enc; + + if ( charcode == code ) + { + result = encodings[mid].glyph; + break; + } + + if ( charcode < code ) + max = mid; + else + min = mid + 1; + } + + return result; } FT_CALLBACK_DEF( FT_UInt ) pk_cmap_char_next( FT_CMap pkcmap, - FT_UInt32 *achar_code ) + FT_UInt32 *acharcode ) { - PK_CMap cmap = (PK_CMap)pkcmap; - FT_UInt gindex = 0; - FT_UInt32 result = 0; - FT_UInt32 char_code = *achar_code + 1; + PK_CMap cmap = (PK_CMap)pkcmap; + PK_Encoding encodings = cmap->encodings; + FT_ULong min, max, mid; + FT_ULong charcode = *acharcode + 1; + FT_UInt result = 0; - if ( char_code <= cmap->bc ) + min = 0; + max = cmap->num_encodings; + + while ( min < max ) { - result = cmap->bc; - gindex = 1; + FT_ULong code; + + + mid = ( min + max ) >> 1; + code = (FT_ULong)encodings[mid].enc; + + if ( charcode == code ) + { + result = encodings[mid].glyph + 1; + goto Exit; + } + + if ( charcode < code ) + max = mid; + else + min = mid + 1; + } + + charcode = 0; + if ( min < cmap->num_encodings ) + { + charcode = (FT_ULong)encodings[min].enc; + result = encodings[min].glyph ; + } + + Exit: + if ( charcode > 0xFFFFFFFFUL ) + { + FT_TRACE1(( "gf_cmap_char_next: charcode 0x%x > 32bit API" )); + *acharcode = 0; + /* XXX: result should be changed to indicate an overflow error */ } else - { - char_code -= cmap->bc; - if ( char_code < cmap->ec - cmap->bc + 1 ) - { - result = char_code; - gindex = (FT_UInt)( char_code ); - } - } - - *achar_code = result; - return gindex; + *acharcode = (FT_UInt32)charcode; + return result; } @@ -268,15 +312,38 @@ y_res ); } + /* set up charmap */ + { + /* FT_Bool unicode_charmap ; */ + + /* + * XXX: TO-DO + * Currently the unicode_charmap is set to `0' + * The functionality of extracting coding scheme + * from `xxx' and `yyy' commands will be used to + * set the unicode_charmap. + */ + } + /* Charmaps */ { FT_CharMapRec charmap; + FT_Bool unicode_charmap = 0; - /* Unicode Charmap */ - charmap.encoding = FT_ENCODING_UNICODE; - charmap.platform_id = TT_PLATFORM_MICROSOFT; - charmap.encoding_id = TT_MS_ID_UNICODE_CS; charmap.face = FT_FACE( face ); + charmap.encoding = FT_ENCODING_NONE; + /* initial platform/encoding should indicate unset status? */ + charmap.platform_id = TT_PLATFORM_APPLE_UNICODE; + charmap.encoding_id = TT_APPLE_ID_DEFAULT; + + if( unicode_charmap ) + { + /* Unicode Charmap */ + charmap.encoding = FT_ENCODING_UNICODE; + charmap.platform_id = TT_PLATFORM_MICROSOFT; + charmap.encoding_id = TT_MS_ID_UNICODE_CS; + } + error = FT_CMap_New( &pk_cmap_class, NULL, &charmap, NULL ); diff --git a/src/pk/pkdrivr.h b/src/pk/pkdrivr.h index 7c8fb3841..da2b01cdb 100644 --- a/src/pk/pkdrivr.h +++ b/src/pk/pkdrivr.h @@ -27,6 +27,14 @@ FT_BEGIN_HEADER + + typedef struct PK_EncodingRec_ + { + FT_Long enc; + FT_UShort glyph; + + } PK_EncodingRec, *PK_Encoding; + typedef struct PK_BitmapRec_ { FT_Int bbx_width, bbx_height; @@ -34,6 +42,7 @@ FT_BEGIN_HEADER FT_Int mv_x, mv_y; FT_Byte *bitmap; FT_UInt raster; + FT_UShort code; } PK_BitmapRec, *PK_Bitmap; @@ -45,6 +54,11 @@ FT_BEGIN_HEADER FT_UInt font_bbx_w, font_bbx_h; FT_UInt font_bbx_xoff, font_bbx_yoff; + FT_ULong nencodings; + PK_Encoding encodings; + + FT_ULong nglyphs; + } PK_GlyphRec, *PK_Glyph; typedef struct PK_FaceRec_ diff --git a/src/pk/pklib.c b/src/pk/pklib.c index 05494b048..dd5a23bfb 100644 --- a/src/pk/pklib.c +++ b/src/pk/pklib.c @@ -307,6 +307,7 @@ FT_Byte bits_table[] = { FT_Int bc, ec, nchars, index, i; FT_Error error = FT_Err_Ok; FT_Memory memory = extmemory; /* needed for FT_NEW */ + PK_Encoding encoding = NULL; go = NULL; nchars = -1; @@ -388,15 +389,15 @@ FT_Byte bits_table[] = { ec = 255; #endif - nchars = ec - bc + 1; + nchars = ec - bc + 1; if( FT_ALLOC(go, sizeof(PK_GlyphRec)) ) goto Exit; if( FT_ALLOC_MULT(go->bm_table, sizeof(PK_BitmapRec), nchars) ) goto Exit; - for (i = 0; i < nchars; i++) - go->bm_table[i].bitmap = NULL; + if ( FT_NEW_ARRAY( encoding, nchars ) ) + return error; go->ds = (FT_UInt)ds/(1<<20); go->hppp = (FT_UInt)hppp/(1<<16); @@ -412,6 +413,8 @@ FT_Byte bits_table[] = { if( FT_STREAM_SEEK( gptr ) ) goto Exit; + index = 0; + go->nglyphs = 0; for (;;) { if ((instr = READ_UINT1( stream )) == PK_POST) @@ -497,7 +500,6 @@ FT_Byte bits_table[] = { goto Exit; } - index = cc - go->code_min; go->bm_table[index].bbx_width = w; go->bm_table[index].bbx_height = h; go->bm_table[index].raster = (w+7)/8; @@ -506,6 +508,12 @@ FT_Byte bits_table[] = { go->bm_table[index].mv_x = mv_x; go->bm_table[index].mv_y = mv_y; go->bm_table[index].bitmap = (unsigned char*)malloc(h*((w+7)/8)); + go->bm_table[index].code = cc ; /* For backward compatibility */ + go->nglyphs += 1; + + encoding[index].enc = cc ; + encoding[index].glyph = index; + if (go->bm_table[index].bitmap == NULL) { @@ -541,8 +549,14 @@ FT_Byte bits_table[] = { go->font_bbx_xoff = -hoff; if (go->font_bbx_yoff > (voff - h)) go->font_bbx_yoff = (voff - h); + + index++; } } + + go->nencodings = go->nglyphs; + go->encodings = encoding; + *goptr = go; return error;