gtkfont.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Header file for gtkfont.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 gtkfont.c.
  47. */
  48. struct unifont_vtable; /* contents internal to gtkfont.c */
  49. typedef struct unifont {
  50. const struct unifont_vtable *vt;
  51. /*
  52. * `Non-static data members' of the `class', accessible to
  53. * external code.
  54. */
  55. /*
  56. * public_charset is the charset used when the user asks for
  57. * `Use font encoding'.
  58. */
  59. int public_charset;
  60. /*
  61. * Font dimensions needed by clients.
  62. */
  63. int width, height, ascent, descent;
  64. /*
  65. * Indicates whether this font is capable of handling all glyphs
  66. * (Pango fonts can do this because Pango automatically supplies
  67. * missing glyphs from other fonts), or whether it would like a
  68. * fallback font to cope with missing glyphs.
  69. */
  70. int want_fallback;
  71. /*
  72. * Preferred drawing API to use when this class of font is active.
  73. * (See the enum below, in unifont_drawctx.)
  74. */
  75. int preferred_drawtype;
  76. } unifont;
  77. /* A default drawtype, for the case where no font exists to make the
  78. * decision with. */
  79. #ifdef DRAW_TEXT_CAIRO
  80. #define DRAW_DEFAULT_CAIRO
  81. #define DRAWTYPE_DEFAULT DRAWTYPE_CAIRO
  82. #elif defined DRAW_TEXT_GDK
  83. #define DRAW_DEFAULT_GDK
  84. #define DRAWTYPE_DEFAULT DRAWTYPE_GDK
  85. #else
  86. #error No drawtype available at all
  87. #endif
  88. /*
  89. * Drawing context passed in to unifont_draw_text, which contains
  90. * everything required to know where and how to draw the requested
  91. * text.
  92. */
  93. typedef struct unifont_drawctx {
  94. enum {
  95. #ifdef DRAW_TEXT_GDK
  96. DRAWTYPE_GDK,
  97. #endif
  98. #ifdef DRAW_TEXT_CAIRO
  99. DRAWTYPE_CAIRO,
  100. #endif
  101. DRAWTYPE_NTYPES
  102. } type;
  103. union {
  104. #ifdef DRAW_TEXT_GDK
  105. struct {
  106. GdkDrawable *target;
  107. GdkGC *gc;
  108. } gdk;
  109. #endif
  110. #ifdef DRAW_TEXT_CAIRO
  111. struct {
  112. /* Need an actual widget, in order to backtrack to its X
  113. * screen number when creating server-side pixmaps */
  114. GtkWidget *widget;
  115. cairo_t *cr;
  116. cairo_matrix_t origmatrix;
  117. } cairo;
  118. #endif
  119. } u;
  120. } unifont_drawctx;
  121. unifont *unifont_create(GtkWidget *widget, const char *name,
  122. int wide, int bold,
  123. int shadowoffset, int shadowalways);
  124. void unifont_destroy(unifont *font);
  125. void unifont_draw_text(unifont_drawctx *ctx, unifont *font,
  126. int x, int y, const wchar_t *string, int len,
  127. int wide, int bold, int cellwidth);
  128. /* Same as unifont_draw_text, but expects 'string' to contain one
  129. * normal char plus combining chars, and overdraws them all in the
  130. * same character cell. */
  131. void unifont_draw_combining(unifont_drawctx *ctx, unifont *font,
  132. int x, int y, const wchar_t *string, int len,
  133. int wide, int bold, int cellwidth);
  134. /*
  135. * This function behaves exactly like the low-level unifont_create,
  136. * except that as well as the requested font it also allocates (if
  137. * necessary) a fallback font for filling in replacement glyphs.
  138. *
  139. * Return value is usable with unifont_destroy and unifont_draw_text
  140. * as if it were an ordinary unifont.
  141. */
  142. unifont *multifont_create(GtkWidget *widget, const char *name,
  143. int wide, int bold,
  144. int shadowoffset, int shadowalways);
  145. /*
  146. * Unified font selector dialog. I can't be bothered to do a
  147. * proper GTK subclassing today, so this will just be an ordinary
  148. * data structure with some useful members.
  149. *
  150. * (Of course, these aren't the only members; this structure is
  151. * contained within a bigger one which holds data visible only to
  152. * the implementation.)
  153. */
  154. typedef struct unifontsel {
  155. void *user_data; /* settable by the user */
  156. GtkWindow *window;
  157. GtkWidget *ok_button, *cancel_button;
  158. } unifontsel;
  159. unifontsel *unifontsel_new(const char *wintitle);
  160. void unifontsel_destroy(unifontsel *fontsel);
  161. void unifontsel_set_name(unifontsel *fontsel, const char *fontname);
  162. char *unifontsel_get_name(unifontsel *fontsel);
  163. #endif /* PUTTY_GTKFONT_H */