gsgdata.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* Copyright (C) 2001 Aladdin Enterprises. All rights reserved.
  2. This software is provided AS-IS with no warranty, either express or
  3. implied.
  4. This software is distributed under license and may not be copied,
  5. modified or distributed except as expressly authorized under the terms
  6. of the license contained in the file LICENSE in this distribution.
  7. For more information about licensing, please refer to
  8. http://www.ghostscript.com/licensing/. For information on
  9. commercial licensing, go to http://www.artifex.com/licensing/ or
  10. contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  12. */
  13. /* $Id: gsgdata.h,v 1.5 2004/11/15 01:12:06 ray Exp $ */
  14. /* Interface for glyph data access */
  15. #ifndef gsgdata_INCLUDED
  16. # define gsgdata_INCLUDED
  17. #include "gsstype.h" /* for extern_st */
  18. /*
  19. * Define the structure used to return the data for a glyph upon
  20. * request. "Data" currently means the bytes of a Type 1, TrueType, or
  21. * similar scalable outline, or the bits of a bitmap (not currently used).
  22. */
  23. /* ------ Information for clients ------ */
  24. /*
  25. * Clients that get glyph data (for example, using the get_outline procedure
  26. * of a Type 42 or a CIDFontType 2 font) do so as follows:
  27. gs_glyph_data_t gdata;
  28. int code;
  29. ...
  30. code = ...get_outline(...&gdata...);
  31. *
  32. * If code >= 0 (no error), gdata.bits.{data,size} point to the outline data.
  33. *
  34. * Since the data may have been allocated in response to the request,
  35. * when the client is finished with the data, it should call:
  36. gs_glyph_data_free(&gdata, "client name");
  37. * This is a no-op if the data are stored in the font, but an actual freeing
  38. * procedure if they were allocated by get_outline.
  39. */
  40. /* ------ Structure declaration ------ */
  41. typedef struct gs_glyph_data_procs_s gs_glyph_data_procs_t;
  42. #ifndef gs_glyph_data_DEFINED
  43. # define gs_glyph_data_DEFINED
  44. typedef struct gs_glyph_data_s gs_glyph_data_t;
  45. #endif
  46. struct gs_glyph_data_s {
  47. gs_const_bytestring bits; /* pointer to actual data returned here */
  48. const gs_glyph_data_procs_t *procs;
  49. void *proc_data;
  50. gs_memory_t *memory; /* allocator to use (may be different than font) */
  51. };
  52. extern_st(st_glyph_data);
  53. #define ST_GLYPH_DATA_NUM_PTRS 2
  54. /*
  55. * NOTE: Clients must not call these procedures directly. Use the
  56. * gs_glyph_data_{substring,free} procedures declared below.
  57. */
  58. struct gs_glyph_data_procs_s {
  59. #define GS_PROC_GLYPH_DATA_FREE(proc)\
  60. void proc(gs_glyph_data_t *pgd, client_name_t cname)
  61. GS_PROC_GLYPH_DATA_FREE((*free));
  62. #define GS_PROC_GLYPH_DATA_SUBSTRING(proc)\
  63. int proc(gs_glyph_data_t *pgd, uint offset, uint size)
  64. GS_PROC_GLYPH_DATA_SUBSTRING((*substring));
  65. };
  66. /*
  67. * Replace glyph data by a substring. If the data were allocated by
  68. * get_outline et al, this frees the part of the data outside the substring.
  69. */
  70. int gs_glyph_data_substring(gs_glyph_data_t *pgd, uint offset, uint size);
  71. /*
  72. * Free the data for a glyph if they were allocated by get_outline et al.
  73. * This also does the equivalent of a from_null (see below) so that
  74. * multiple calls of this procedure are harmless.
  75. */
  76. void gs_glyph_data_free(gs_glyph_data_t *pgd, client_name_t cname);
  77. /* ------ Information for implementors of get_outline et al ------ */
  78. /*
  79. * The implementor of get_outline or similar procedures should set the
  80. * client's glyph_data_t structure as follows:
  81. ...get_outline...(...gs_font *pfont...gs_glyph_data_t *pgd...)
  82. {
  83. ...
  84. gs_glyph_data_from_string(pgd, odata, osize, NULL);
  85. (or) gs_glyph_data_from_string(pgd, odata, osize, pfont);
  86. }
  87. * If the data are in an object rather then a string, use
  88. gs_glyph_data_from_bytes(pgd, obase, ooffset, osize, <NULL|pfont>);
  89. * The last argument of gs_glyph_data_from_{string|bytes} should be pfont
  90. * iff odata/osize were allocated by this call and will not be retained
  91. * by the implementor (i.e., should be freed when the client calls
  92. * gs_glyph_data_free), NULL otherwise.
  93. */
  94. /*
  95. * Initialize glyph data from a string or from bytes.
  96. */
  97. #ifndef gs_font_DEFINED
  98. # define gs_font_DEFINED
  99. typedef struct gs_font_s gs_font;
  100. #endif
  101. void gs_glyph_data_from_string(gs_glyph_data_t *pgd, const byte *data,
  102. uint size, gs_font *font);
  103. void gs_glyph_data_from_bytes(gs_glyph_data_t *pgd, const byte *bytes,
  104. uint offset, uint size, gs_font *font);
  105. /* from_null(pgd) is a shortcut for from_string(pgd, NULL, 0, NULL). */
  106. void gs_glyph_data_from_null(gs_glyph_data_t *pgd);
  107. #endif /* gsgdata_INCLUDED */