unifont.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * Header file for unifont.c. Has to be separate from unix.h
  3. * because it depends on GTK data types, hence can't be included
  4. * from cross-platform code (which doesn't go near GTK).
  5. */
  6. #ifndef PUTTY_GTKFONT_H
  7. #define PUTTY_GTKFONT_H
  8. /*
  9. * We support two entirely different drawing systems: the old
  10. * GDK1/GDK2 one which works on server-side X drawables, and the
  11. * new-style Cairo one. GTK1 only supports GDK drawing; GTK3 only
  12. * supports Cairo; GTK2 supports both, but deprecates GTK, so we only
  13. * enable it if we aren't trying on purpose to compile without the
  14. * deprecated functions.
  15. *
  16. * Our different font classes may prefer different drawing systems: X
  17. * server-side fonts are a lot faster to draw with GDK, but for
  18. * everything else we prefer Cairo, on general grounds of modernness
  19. * and also in particular because its matrix-based scaling system
  20. * gives much nicer results for double-width and double-height text
  21. * when a scalable font is in use.
  22. */
  23. #if !GTK_CHECK_VERSION(3,0,0) && !defined GDK_DISABLE_DEPRECATED
  24. #define DRAW_TEXT_GDK
  25. #endif
  26. #if GTK_CHECK_VERSION(2,8,0)
  27. #define DRAW_TEXT_CAIRO
  28. #endif
  29. #if GTK_CHECK_VERSION(3,0,0) || defined GDK_DISABLE_DEPRECATED
  30. /*
  31. * Where the facility is available, we prefer to render text on to a
  32. * persistent server-side pixmap, and redraw windows by simply
  33. * blitting rectangles of that pixmap into them as needed. This is
  34. * better for performance since we avoid expensive font rendering
  35. * calls where possible, and it's particularly good over a non-local X
  36. * connection because the response to an expose event can now be a
  37. * very simple rectangle-copy operation rather than a lot of fiddly
  38. * drawing or bitmap transfer.
  39. *
  40. * However, GTK is deprecating the use of server-side pixmaps, so we
  41. * have to disable this mode under some circumstances.
  42. */
  43. #define NO_BACKING_PIXMAPS
  44. #endif
  45. /*
  46. * Exports from unifont.c.
  47. */
  48. typedef struct UnifontVtable UnifontVtable; /* contents internal to
  49. * unifont.c */
  50. typedef struct unifont {
  51. const struct UnifontVtable *vt;
  52. /*
  53. * `Non-static data members' of the `class', accessible to
  54. * external code.
  55. */
  56. /*
  57. * public_charset is the charset used when the user asks for
  58. * `Use font encoding'.
  59. */
  60. int public_charset;
  61. /*
  62. * Font dimensions needed by clients.
  63. */
  64. int width, height, ascent, descent, strikethrough_y;
  65. /*
  66. * Indicates whether this font is capable of handling all glyphs
  67. * (Pango fonts can do this because Pango automatically supplies
  68. * missing glyphs from other fonts), or whether it would like a
  69. * fallback font to cope with missing glyphs.
  70. */
  71. bool want_fallback;
  72. /*
  73. * Preferred drawing API to use when this class of font is active.
  74. * (See the enum below, in unifont_drawctx.)
  75. */
  76. int preferred_drawtype;
  77. } unifont;
  78. /* A default drawtype, for the case where no font exists to make the
  79. * decision with. */
  80. #ifdef DRAW_TEXT_CAIRO
  81. #define DRAW_DEFAULT_CAIRO
  82. #define DRAWTYPE_DEFAULT DRAWTYPE_CAIRO
  83. #elif defined DRAW_TEXT_GDK
  84. #define DRAW_DEFAULT_GDK
  85. #define DRAWTYPE_DEFAULT DRAWTYPE_GDK
  86. #else
  87. #error No drawtype available at all
  88. #endif
  89. /*
  90. * Drawing context passed in to unifont_draw_text, which contains
  91. * everything required to know where and how to draw the requested
  92. * text.
  93. */
  94. typedef struct unifont_drawctx {
  95. enum {
  96. #ifdef DRAW_TEXT_GDK
  97. DRAWTYPE_GDK,
  98. #endif
  99. #ifdef DRAW_TEXT_CAIRO
  100. DRAWTYPE_CAIRO,
  101. #endif
  102. DRAWTYPE_NTYPES
  103. } type;
  104. union {
  105. #ifdef DRAW_TEXT_GDK
  106. struct {
  107. GdkDrawable *target;
  108. GdkGC *gc;
  109. } gdk;
  110. #endif
  111. #ifdef DRAW_TEXT_CAIRO
  112. struct {
  113. /* Need an actual widget, in order to backtrack to its X
  114. * screen number when creating server-side pixmaps */
  115. GtkWidget *widget;
  116. cairo_t *cr;
  117. cairo_matrix_t origmatrix;
  118. #if GTK_CHECK_VERSION(3,22,0)
  119. GdkWindow *gdkwin;
  120. GdkDrawingContext *drawctx;
  121. #endif
  122. } cairo;
  123. #endif
  124. } u;
  125. } unifont_drawctx;
  126. unifont *unifont_create(GtkWidget *widget, const char *name,
  127. bool wide, bool bold,
  128. int shadowoffset, bool shadowalways);
  129. void unifont_destroy(unifont *font);
  130. void unifont_draw_text(unifont_drawctx *ctx, unifont *font,
  131. int x, int y, const wchar_t *string, int len,
  132. bool wide, bool bold, int cellwidth);
  133. /* Same as unifont_draw_text, but expects 'string' to contain one
  134. * normal char plus combining chars, and overdraws them all in the
  135. * same character cell. */
  136. void unifont_draw_combining(unifont_drawctx *ctx, unifont *font,
  137. int x, int y, const wchar_t *string, int len,
  138. bool wide, bool bold, int cellwidth);
  139. /* Return a name that will select a bigger/smaller font than this one,
  140. * or NULL if no such name is available. */
  141. char *unifont_size_increment(unifont *font, int increment);
  142. /*
  143. * This function behaves exactly like the low-level unifont_create,
  144. * except that as well as the requested font it also allocates (if
  145. * necessary) a fallback font for filling in replacement glyphs.
  146. *
  147. * Return value is usable with unifont_destroy and unifont_draw_text
  148. * as if it were an ordinary unifont.
  149. */
  150. unifont *multifont_create(GtkWidget *widget, const char *name,
  151. bool wide, bool bold,
  152. int shadowoffset, bool shadowalways);
  153. /*
  154. * Unified font selector dialog. I can't be bothered to do a
  155. * proper GTK subclassing today, so this will just be an ordinary
  156. * data structure with some useful members.
  157. *
  158. * (Of course, these aren't the only members; this structure is
  159. * contained within a bigger one which holds data visible only to
  160. * the implementation.)
  161. */
  162. typedef struct unifontsel {
  163. void *user_data; /* settable by the user */
  164. GtkWindow *window;
  165. GtkWidget *ok_button, *cancel_button;
  166. } unifontsel;
  167. unifontsel *unifontsel_new(const char *wintitle);
  168. void unifontsel_destroy(unifontsel *fontsel);
  169. void unifontsel_set_name(unifontsel *fontsel, const char *fontname);
  170. char *unifontsel_get_name(unifontsel *fontsel);
  171. #endif /* PUTTY_GTKFONT_H */