pango-glyph.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /* Pango
  2. * pango-glyph.h: Glyph storage
  3. *
  4. * Copyright (C) 2000 Red Hat Software
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Library General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Library General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Library General Public
  17. * License along with this library; if not, write to the
  18. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. * Boston, MA 02111-1307, USA.
  20. */
  21. #ifndef __PANGO_GLYPH_H__
  22. #define __PANGO_GLYPH_H__
  23. #include <pango/pango-types.h>
  24. #include <pango/pango-item.h>
  25. #include <pango/pango-break.h>
  26. G_BEGIN_DECLS
  27. typedef struct _PangoGlyphGeometry PangoGlyphGeometry;
  28. typedef struct _PangoGlyphVisAttr PangoGlyphVisAttr;
  29. typedef struct _PangoGlyphInfo PangoGlyphInfo;
  30. typedef struct _PangoGlyphString PangoGlyphString;
  31. /* 1024ths of a device unit */
  32. /**
  33. * PangoGlyphUnit:
  34. *
  35. * The `PangoGlyphUnit` type is used to store dimensions within
  36. * Pango.
  37. *
  38. * Dimensions are stored in 1/PANGO_SCALE of a device unit.
  39. * (A device unit might be a pixel for screen display, or
  40. * a point on a printer.) PANGO_SCALE is currently 1024, and
  41. * may change in the future (unlikely though), but you should not
  42. * depend on its exact value.
  43. *
  44. * The PANGO_PIXELS() macro can be used to convert from glyph units
  45. * into device units with correct rounding.
  46. */
  47. typedef gint32 PangoGlyphUnit;
  48. /* Positioning information about a glyph
  49. */
  50. /**
  51. * PangoGlyphGeometry:
  52. * @width: the logical width to use for the the character.
  53. * @x_offset: horizontal offset from nominal character position.
  54. * @y_offset: vertical offset from nominal character position.
  55. *
  56. * The `PangoGlyphGeometry` structure contains width and positioning
  57. * information for a single glyph.
  58. *
  59. * Note that @width is not guaranteed to be the same as the glyph
  60. * extents. Kerning and other positioning applied during shaping will
  61. * affect both the @width and the @x_offset for the glyphs in the
  62. * glyph string that results from shaping.
  63. *
  64. * The information in this struct is intended for rendering the glyphs,
  65. * as follows:
  66. *
  67. * 1. Assume the current point is (x, y)
  68. * 2. Render the current glyph at (x + x_offset, y + y_offset),
  69. * 3. Advance the current point to (x + width, y)
  70. * 4. Render the next glyph
  71. */
  72. struct _PangoGlyphGeometry
  73. {
  74. PangoGlyphUnit width;
  75. PangoGlyphUnit x_offset;
  76. PangoGlyphUnit y_offset;
  77. };
  78. /* Visual attributes of a glyph
  79. */
  80. /**
  81. * PangoGlyphVisAttr:
  82. * @is_cluster_start: set for the first logical glyph in each cluster.
  83. * @is_color: set if the the font will render this glyph with color. Since 1.50
  84. *
  85. * A `PangoGlyphVisAttr` structure communicates information between
  86. * the shaping and rendering phases.
  87. *
  88. * Currently, it contains cluster start and color information.
  89. * More attributes may be added in the future.
  90. *
  91. * Clusters are stored in visual order, within the cluster, glyphs
  92. * are always ordered in logical order, since visual order is meaningless;
  93. * that is, in Arabic text, accent glyphs follow the glyphs for the
  94. * base character.
  95. */
  96. struct _PangoGlyphVisAttr
  97. {
  98. guint is_cluster_start : 1;
  99. guint is_color : 1;
  100. };
  101. /* A single glyph
  102. */
  103. /**
  104. * PangoGlyphInfo:
  105. * @glyph: the glyph itself.
  106. * @geometry: the positional information about the glyph.
  107. * @attr: the visual attributes of the glyph.
  108. *
  109. * A `PangoGlyphInfo` structure represents a single glyph with
  110. * positioning information and visual attributes.
  111. */
  112. struct _PangoGlyphInfo
  113. {
  114. PangoGlyph glyph;
  115. PangoGlyphGeometry geometry;
  116. PangoGlyphVisAttr attr;
  117. };
  118. /**
  119. * PangoGlyphString:
  120. * @num_glyphs: number of glyphs in this glyph string
  121. * @glyphs: (array length=num_glyphs): array of glyph information
  122. * @log_clusters: logical cluster info, indexed by the byte index
  123. * within the text corresponding to the glyph string
  124. *
  125. * A `PangoGlyphString` is used to store strings of glyphs with geometry
  126. * and visual attribute information.
  127. *
  128. * The storage for the glyph information is owned by the structure
  129. * which simplifies memory management.
  130. */
  131. struct _PangoGlyphString {
  132. int num_glyphs;
  133. PangoGlyphInfo *glyphs;
  134. int *log_clusters;
  135. /*< private >*/
  136. int space;
  137. };
  138. #define PANGO_TYPE_GLYPH_STRING (pango_glyph_string_get_type ())
  139. PANGO_AVAILABLE_IN_ALL
  140. GType pango_glyph_string_get_type (void) G_GNUC_CONST;
  141. PANGO_AVAILABLE_IN_ALL
  142. PangoGlyphString * pango_glyph_string_new (void);
  143. PANGO_AVAILABLE_IN_ALL
  144. void pango_glyph_string_set_size (PangoGlyphString *string,
  145. int new_len);
  146. PANGO_AVAILABLE_IN_ALL
  147. PangoGlyphString * pango_glyph_string_copy (PangoGlyphString *string);
  148. PANGO_AVAILABLE_IN_ALL
  149. void pango_glyph_string_free (PangoGlyphString *string);
  150. PANGO_AVAILABLE_IN_ALL
  151. void pango_glyph_string_extents (PangoGlyphString *glyphs,
  152. PangoFont *font,
  153. PangoRectangle *ink_rect,
  154. PangoRectangle *logical_rect);
  155. PANGO_AVAILABLE_IN_1_14
  156. int pango_glyph_string_get_width (PangoGlyphString *glyphs);
  157. PANGO_AVAILABLE_IN_ALL
  158. void pango_glyph_string_extents_range (PangoGlyphString *glyphs,
  159. int start,
  160. int end,
  161. PangoFont *font,
  162. PangoRectangle *ink_rect,
  163. PangoRectangle *logical_rect);
  164. PANGO_AVAILABLE_IN_ALL
  165. void pango_glyph_string_get_logical_widths (PangoGlyphString *glyphs,
  166. const char *text,
  167. int length,
  168. int embedding_level,
  169. int *logical_widths);
  170. PANGO_AVAILABLE_IN_ALL
  171. void pango_glyph_string_index_to_x (PangoGlyphString *glyphs,
  172. const char *text,
  173. int length,
  174. PangoAnalysis *analysis,
  175. int index_,
  176. gboolean trailing,
  177. int *x_pos);
  178. PANGO_AVAILABLE_IN_ALL
  179. void pango_glyph_string_x_to_index (PangoGlyphString *glyphs,
  180. const char *text,
  181. int length,
  182. PangoAnalysis *analysis,
  183. int x_pos,
  184. int *index_,
  185. int *trailing);
  186. PANGO_AVAILABLE_IN_1_50
  187. void pango_glyph_string_index_to_x_full (PangoGlyphString *glyphs,
  188. const char *text,
  189. int length,
  190. PangoAnalysis *analysis,
  191. PangoLogAttr *attrs,
  192. int index_,
  193. gboolean trailing,
  194. int *x_pos);
  195. /* Shaping */
  196. /**
  197. * PangoShapeFlags:
  198. * @PANGO_SHAPE_NONE: Default value
  199. * @PANGO_SHAPE_ROUND_POSITIONS: Round glyph positions and widths to whole device units
  200. * This option should be set if the target renderer can't do subpixel positioning of glyphs
  201. *
  202. * Flags influencing the shaping process.
  203. *
  204. * `PangoShapeFlags` can be passed to [func@Pango.shape_with_flags].
  205. *
  206. * Since: 1.44
  207. */
  208. typedef enum {
  209. PANGO_SHAPE_NONE = 0,
  210. PANGO_SHAPE_ROUND_POSITIONS = 1 << 0,
  211. } PangoShapeFlags;
  212. PANGO_AVAILABLE_IN_ALL
  213. void pango_shape (const char *text,
  214. int length,
  215. const PangoAnalysis *analysis,
  216. PangoGlyphString *glyphs);
  217. PANGO_AVAILABLE_IN_1_32
  218. void pango_shape_full (const char *item_text,
  219. int item_length,
  220. const char *paragraph_text,
  221. int paragraph_length,
  222. const PangoAnalysis *analysis,
  223. PangoGlyphString *glyphs);
  224. PANGO_AVAILABLE_IN_1_44
  225. void pango_shape_with_flags (const char *item_text,
  226. int item_length,
  227. const char *paragraph_text,
  228. int paragraph_length,
  229. const PangoAnalysis *analysis,
  230. PangoGlyphString *glyphs,
  231. PangoShapeFlags flags);
  232. PANGO_AVAILABLE_IN_1_50
  233. void pango_shape_item (PangoItem *item,
  234. const char *paragraph_text,
  235. int paragraph_length,
  236. PangoLogAttr *log_attrs,
  237. PangoGlyphString *glyphs,
  238. PangoShapeFlags flags);
  239. G_END_DECLS
  240. #endif /* __PANGO_GLYPH_H__ */