ftnames.c 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /***************************************************************************/
  2. /* */
  3. /* ftnames.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-2001, 2002 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. #include <ft2build.h>
  21. #include FT_SFNT_NAMES_H
  22. #include FT_INTERNAL_TRUETYPE_TYPES_H
  23. #include FT_INTERNAL_STREAM_H
  24. #ifdef TT_CONFIG_OPTION_SFNT_NAMES
  25. /* documentation is in ftnames.h */
  26. FT_EXPORT_DEF( FT_UInt )
  27. FT_Get_Sfnt_Name_Count( FT_Face face )
  28. {
  29. return (face && FT_IS_SFNT( face )) ? ((TT_Face)face)->num_names : 0;
  30. }
  31. /* documentation is in ftnames.h */
  32. FT_EXPORT_DEF( FT_Error )
  33. FT_Get_Sfnt_Name( FT_Face face,
  34. FT_UInt idx,
  35. FT_SfntName *aname )
  36. {
  37. FT_Error error = FT_Err_Invalid_Argument;
  38. if ( aname && face && FT_IS_SFNT( face ) )
  39. {
  40. TT_Face ttface = (TT_Face)face;
  41. if ( idx < (FT_UInt)ttface->num_names )
  42. {
  43. TT_NameEntryRec* entry = ttface->name_table.names + idx;
  44. /* load name on demand */
  45. if ( entry->stringLength > 0 && entry->string == NULL )
  46. {
  47. FT_Memory memory = face->memory;
  48. FT_Stream stream = face->stream;
  49. if ( FT_NEW_ARRAY ( entry->string, entry->stringLength ) ||
  50. FT_STREAM_SEEK( entry->stringOffset ) ||
  51. FT_STREAM_READ( entry->string, entry->stringLength ) )
  52. {
  53. FT_FREE( entry->string );
  54. entry->stringLength = 0;
  55. }
  56. }
  57. aname->platform_id = entry->platformID;
  58. aname->encoding_id = entry->encodingID;
  59. aname->language_id = entry->languageID;
  60. aname->name_id = entry->nameID;
  61. aname->string = (FT_Byte*)entry->string;
  62. aname->string_len = entry->stringLength;
  63. error = FT_Err_Ok;
  64. }
  65. }
  66. return error;
  67. }
  68. #endif /* TT_CONFIG_OPTION_SFNT_NAMES */
  69. /* END */