ReactOS  0.4.15-dev-3331-g8ebe441
ftsnames.c
Go to the documentation of this file.
1 /***************************************************************************/
2 /* */
3 /* ftsnames.c */
4 /* */
5 /* Simple interface to access SFNT name tables (which are used */
6 /* to hold font names, copyright info, notices, etc.) (body). */
7 /* */
8 /* This is _not_ used to retrieve glyph names! */
9 /* */
10 /* Copyright 1996-2018 by */
11 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
12 /* */
13 /* This file is part of the FreeType project, and may only be used, */
14 /* modified, and distributed under the terms of the FreeType project */
15 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
16 /* this file you indicate that you have read the license and */
17 /* understand and accept it fully. */
18 /* */
19 /***************************************************************************/
20 
21 
22 #include <ft2build.h>
23 #include FT_INTERNAL_DEBUG_H
24 
25 #include FT_SFNT_NAMES_H
26 #include FT_INTERNAL_TRUETYPE_TYPES_H
27 #include FT_INTERNAL_STREAM_H
28 
29 
30 #ifdef TT_CONFIG_OPTION_SFNT_NAMES
31 
32 
33  /* documentation is in ftsnames.h */
34 
37  {
38  return ( face && FT_IS_SFNT( face ) ) ? ((TT_Face)face)->num_names : 0;
39  }
40 
41 
42  /* documentation is in ftsnames.h */
43 
46  FT_UInt idx,
47  FT_SfntName *aname )
48  {
49  FT_Error error = FT_ERR( Invalid_Argument );
50 
51 
52  if ( aname && face && FT_IS_SFNT( face ) )
53  {
54  TT_Face ttface = (TT_Face)face;
55 
56 
57  if ( idx < (FT_UInt)ttface->num_names )
58  {
59  TT_Name entry = ttface->name_table.names + idx;
60 
61 
62  /* load name on demand */
63  if ( entry->stringLength > 0 && !entry->string )
64  {
65  FT_Memory memory = face->memory;
66  FT_Stream stream = face->stream;
67 
68 
69  if ( FT_NEW_ARRAY ( entry->string, entry->stringLength ) ||
70  FT_STREAM_SEEK( entry->stringOffset ) ||
71  FT_STREAM_READ( entry->string, entry->stringLength ) )
72  {
73  FT_FREE( entry->string );
74  entry->stringLength = 0;
75  }
76  }
77 
78  aname->platform_id = entry->platformID;
79  aname->encoding_id = entry->encodingID;
80  aname->language_id = entry->languageID;
81  aname->name_id = entry->nameID;
82  aname->string = (FT_Byte*)entry->string;
83  aname->string_len = entry->stringLength;
84 
85  error = FT_Err_Ok;
86  }
87  }
88 
89  return error;
90  }
91 
92 
93  /* documentation is in ftsnames.h */
94 
97  FT_UInt langID,
98  FT_SfntLangTag *alangTag )
99  {
100  FT_Error error = FT_ERR( Invalid_Argument );
101 
102 
103  if ( alangTag && face && FT_IS_SFNT( face ) )
104  {
105  TT_Face ttface = (TT_Face)face;
106 
107 
108  if ( ttface->name_table.format != 1 )
109  return FT_THROW( Invalid_Table );
110 
111  if ( langID > 0x8000U &&
112  langID - 0x8000U < ttface->name_table.numLangTagRecords )
113  {
114  TT_LangTag entry = ttface->name_table.langTags +
115  ( langID - 0x8000U );
116 
117 
118  /* load name on demand */
119  if ( entry->stringLength > 0 && !entry->string )
120  {
121  FT_Memory memory = face->memory;
122  FT_Stream stream = face->stream;
123 
124 
125  if ( FT_NEW_ARRAY ( entry->string, entry->stringLength ) ||
126  FT_STREAM_SEEK( entry->stringOffset ) ||
127  FT_STREAM_READ( entry->string, entry->stringLength ) )
128  {
129  FT_FREE( entry->string );
130  entry->stringLength = 0;
131  }
132  }
133 
134  alangTag->string = (FT_Byte*)entry->string;
135  alangTag->string_len = entry->stringLength;
136 
137  error = FT_Err_Ok;
138  }
139  }
140 
141  return error;
142  }
143 
144 
145 #endif /* TT_CONFIG_OPTION_SFNT_NAMES */
146 
147 
148 /* END */
int FT_Error
Definition: fttypes.h:300
#define error(str)
Definition: mkdosfs.c:1605
#define U(x)
Definition: wordpad.c:45
TT_NameTableRec name_table
Definition: tttypes.h:1410
return FT_Err_Ok
Definition: ftbbox.c:511
FT_UShort num_names
Definition: tttypes.h:1409
static char memory[1024 *256]
Definition: process.c:116
TT_LangTagRec * langTags
Definition: tttypes.h:348
TT_NameRec * names
Definition: tttypes.h:346
FT_UInt string_len
Definition: ftsnames.h:199
unsigned char FT_Byte
Definition: fttypes.h:154
#define FT_THROW(e)
Definition: ftdebug.h:213
unsigned int idx
Definition: utils.c:41
FT_UShort format
Definition: tttypes.h:343
#define FT_FREE(ptr)
Definition: ftmemory.h:329
struct TT_FaceRec_ * TT_Face
Definition: tttypes.h:973
#define FT_ERR(e)
Definition: fttypes.h:586
#define FT_IS_SFNT(face)
Definition: freetype.h:1331
FT_Byte * string
Definition: ftsnames.h:198
FT_Get_Sfnt_Name(FT_Face face, FT_UInt idx, FT_SfntName *aname)
Definition: parse.h:22
uint32_t entry
Definition: isohybrid.c:63
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
Definition: ftsystem.h:66
#define FT_NEW_ARRAY(ptr, count)
Definition: ftmemory.h:333
#define FT_STREAM_SEEK(position)
Definition: ftstream.h:489
FT_BEGIN_HEADER struct FT_SfntName_ FT_SfntName
#define FT_EXPORT_DEF(x)
Definition: ftconfig.h:483
unsigned int FT_UInt
Definition: fttypes.h:231
FT_Get_Sfnt_Name_Count(FT_Face face)
#define FT_STREAM_READ(buffer, count)
Definition: ftstream.h:497
GLenum GLuint GLint GLenum face
Definition: glext.h:7025
FT_Get_Sfnt_LangTag(FT_Face face, FT_UInt langID, FT_SfntLangTag *alangTag)