OLD | NEW |
(Empty) | |
| 1 /* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */ |
| 2 /* vim:set et sts=4: */ |
| 3 /* ibus - The Input Bus |
| 4 * Copyright (C) 2017 Takao Fujiwara <takao.fujiwara1@gmail.com> |
| 5 * Copyright (C) 2017 Red Hat, Inc. |
| 6 * |
| 7 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Lesser General Public |
| 9 * License as published by the Free Software Foundation; either |
| 10 * version 2.1 of the License, or (at your option) any later version. |
| 11 * |
| 12 * This library is distributed in the hope that it will be useful, |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 * Lesser General Public License for more details. |
| 16 * |
| 17 * You should have received a copy of the GNU Lesser General Public |
| 18 * License along with this library; if not, write to the Free Software |
| 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 20 * USA |
| 21 */ |
| 22 |
| 23 #ifndef __IBUS_HARFBUZZ_H_ |
| 24 #define __IBUS_HARFBUZZ_H_ |
| 25 |
| 26 /** |
| 27 * SECTION: ibusfontset |
| 28 * @short_description: Object for HarfBuzz and Fontconfig. |
| 29 * @title: IBusFontSet |
| 30 * @stability: Unstable |
| 31 * |
| 32 * IBusFontSet offers FcFontSet, glyph info with HarfBuzz and rendering |
| 33 * on Cairo context. |
| 34 * Current Pango changes fonts by emoji variants and draws the separated |
| 35 * glyphs [1] but actually the emoji characters with variants can be drawn |
| 36 * as one glyph so this class manages Fontconfig fontsets to select a font, |
| 37 * HarfBuzz to get glyphs for emoji variants, Cairo to draw glyphs. |
| 38 * |
| 39 * [1]: https://bugzilla.gnome.org/show_bug.cgi?id=780669 |
| 40 * https://bugzilla.gnome.org/show_bug.cgi?id=781123 |
| 41 */ |
| 42 |
| 43 #include <ibus.h> |
| 44 #include <cairo.h> |
| 45 |
| 46 #define IBUS_TYPE_CAIRO_LINE (ibus_cairo_line_get_type ()) |
| 47 #define IBUS_TYPE_REQUISITION_EX (ibus_requisition_ex_get_type ()) |
| 48 #define IBUS_TYPE_FONTSET (ibus_fontset_get_type ()) |
| 49 #define IBUS_FONTSET(obj) (G_TYPE_CHECK_INSTANCE_CAST (\ |
| 50 (obj), \ |
| 51 IBUS_TYPE_FONTSET, \ |
| 52 IBusFontSet)) |
| 53 #define IBUS_FONTSET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST (\ |
| 54 (klass), \ |
| 55 IBUS_TYPE_FONTSET, \ |
| 56 IBusFontSetClass)) |
| 57 #define IBUS_IS_FONTSET(obj) (G_TYPE_CHECK_INSTANCE_TYPE (\ |
| 58 (obj), \ |
| 59 IBUS_TYPE_FONTSET)) |
| 60 #define IBUS_IS_FONTSET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE (\ |
| 61 (klass), \ |
| 62 IBUS_TYPE_FONTSET)) |
| 63 #define IBUS_FONTSET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS (\ |
| 64 (obj), \ |
| 65 IBUS_TYPE_FONTSET, \ |
| 66 IBusFontSetClass)) |
| 67 |
| 68 G_BEGIN_DECLS |
| 69 |
| 70 typedef struct _IBusGlyph IBusGlyph; |
| 71 typedef struct _IBusCairoLine IBusCairoLine; |
| 72 typedef struct _IBusRequisitionEx IBusRequisitionEx; |
| 73 typedef struct _IBusFontSet IBusFontSet; |
| 74 typedef struct _IBusFontSetPrivate IBusFontSetPrivate; |
| 75 typedef struct _IBusFontSetClass IBusFontSetClass; |
| 76 |
| 77 struct _IBusGlyph { |
| 78 unsigned long index; |
| 79 double x; |
| 80 double y; |
| 81 }; |
| 82 |
| 83 struct _IBusCairoLine { |
| 84 IBusGlyph *glyphs; |
| 85 guint num_glyphs; |
| 86 cairo_scaled_font_t *scaled_font; |
| 87 gpointer pdummy[5]; |
| 88 }; |
| 89 |
| 90 struct _IBusRequisitionEx { |
| 91 guint width; |
| 92 guint height; |
| 93 IBusCairoLine *cairo_lines; |
| 94 gpointer pdummy[5]; |
| 95 }; |
| 96 |
| 97 struct _IBusFontSet { |
| 98 IBusObject parent_instance; |
| 99 IBusFontSetPrivate *priv; |
| 100 }; |
| 101 |
| 102 struct _IBusFontSetClass { |
| 103 IBusObjectClass parent_class; |
| 104 /* signals */ |
| 105 /*< private >*/ |
| 106 /* padding */ |
| 107 gpointer pdummy[10]; |
| 108 }; |
| 109 |
| 110 GType ibus_cairo_line_get_type (void) G_GNUC_CONST; |
| 111 |
| 112 /** |
| 113 * ibus_cairo_line_copy: |
| 114 * @cairo_lines: #IBusCairoLine |
| 115 * |
| 116 * Creates a copy of @cairo_liens, which should be freed with |
| 117 * ibus_cairo_line_free(). Primarily used by language bindings, |
| 118 * not that useful otherwise (since @req can just be copied |
| 119 * by assignment in C). |
| 120 * |
| 121 * Returns: the newly allocated #IBusCairoLine, which should |
| 122 * be freed with ibus_cairo_line_free(), or %NULL |
| 123 * if @cairo_lines was %NULL. |
| 124 **/ |
| 125 IBusCairoLine * ibus_cairo_line_copy (IBusCairoLine *cairo_lines); |
| 126 |
| 127 /** |
| 128 * ibus_cairo_line_free: |
| 129 * @cairo_lines: #IBusCairoLine |
| 130 * |
| 131 * Free an #IBusCairoLine. |
| 132 */ |
| 133 void ibus_cairo_line_free (IBusCairoLine *cairo_lines); |
| 134 |
| 135 |
| 136 GType ibus_requisition_ex_get_type (void) G_GNUC_CONST; |
| 137 |
| 138 /** |
| 139 * ibus_requisition_ex_copy: |
| 140 * @req: #IBusRequisitionEx |
| 141 * |
| 142 * Creates a copy of @req, which should be freed with |
| 143 * ibus_requisition_ex_free(). Primarily used by language bindings, |
| 144 * not that useful otherwise (since @req can just be copied |
| 145 * by assignment in C). |
| 146 * |
| 147 * Returns: the newly allocated #IBusRequisitionEx, which should |
| 148 * be freed with ibus_requisition_ex_free(), or %NULL |
| 149 * if @req was %NULL. |
| 150 **/ |
| 151 IBusRequisitionEx * |
| 152 ibus_requisition_ex_copy (IBusRequisitionEx *req); |
| 153 |
| 154 /** |
| 155 * ibus_requisition_ex_free: |
| 156 * @req: #IBusRequisitionEx |
| 157 * |
| 158 * Free an #IBusRequisitionEx. |
| 159 */ |
| 160 void ibus_requisition_ex_free (IBusRequisitionEx *req); |
| 161 |
| 162 |
| 163 GType ibus_fontset_get_type (void); |
| 164 |
| 165 /** |
| 166 * ibus_fontset_new: |
| 167 * @first_property_name:· |
| 168 * |
| 169 * Creates a new #IBusFcFontSet. |
| 170 * |
| 171 * Returns: (transfer full): A newly allocated #IBusFontSet and includes |
| 172 * #FcFontSet internally. E.g. ibus_fontset_new ("family", |
| 173 * "Noto Emoji Color", "size", 16, "language", "ja-jp"); |
| 174 */ |
| 175 IBusFontSet * ibus_fontset_new (const gchar |
| 176 *first_property_name, |
| 177 ...); |
| 178 |
| 179 /** |
| 180 * ibus_fontset_new_with_font: |
| 181 * @family: font family |
| 182 * @size: font size |
| 183 * @language: font language |
| 184 * |
| 185 * Creates a new #IBusFcFontSet. |
| 186 * |
| 187 * Returns: (transfer full): A newly allocated #IBusFcFontSet and includes |
| 188 * #FcFontSet internally. |
| 189 */ |
| 190 IBusFontSet * ibus_fontset_new_with_font (const gchar *family, |
| 191 guint size, |
| 192 const gchar *language); |
| 193 /** |
| 194 * ibus_fontset_get_family: |
| 195 * @fontset: #IBusFcFontSet |
| 196 * |
| 197 * Return the base font family of #FcFontSet |
| 198 * |
| 199 * Returns: Base font family of #FcFontSet |
| 200 */ |
| 201 const gchar * ibus_fontset_get_family (IBusFontSet *fontset); |
| 202 |
| 203 /** |
| 204 * ibus_fontset_set_family: |
| 205 * @fontset: #IBusFcFontSet |
| 206 * @family: base font family for #FcFontSet |
| 207 * |
| 208 * Set the base font family for #FcFontSet |
| 209 */ |
| 210 void ibus_fontset_set_family (IBusFontSet *fontset, |
| 211 const gchar *family); |
| 212 /** |
| 213 * ibus_fontset_get_size: |
| 214 * @fontset: #IBusFcFontSet |
| 215 * |
| 216 * Return the font size of #FcFontSet |
| 217 * |
| 218 * Returns: Font size of #FcFontSet |
| 219 */ |
| 220 guint ibus_fontset_get_size (IBusFontSet *fontset); |
| 221 |
| 222 /** |
| 223 * ibus_fontset_set_size: |
| 224 * @fontset: #IBusFcFontSet |
| 225 * @size: font size for #FcFontSet |
| 226 * |
| 227 * Set the font size for #FcFontSet |
| 228 */ |
| 229 void ibus_fontset_set_size (IBusFontSet *fontset, |
| 230 guint size); |
| 231 /** |
| 232 * ibus_fontset_get_language: |
| 233 * @fontset: #IBusFcFontSet |
| 234 * |
| 235 * Return the font language of #FcFontSet |
| 236 * |
| 237 * Returns: Font language of #FcFontSet |
| 238 */ |
| 239 const gchar * ibus_fontset_get_language (IBusFontSet *fontset); |
| 240 |
| 241 /** |
| 242 * ibus_fontset_set_language: |
| 243 * @fontset: #IBusFcFontSet |
| 244 * @language: font langauge for #FcFontSet |
| 245 * |
| 246 * Set the font language for #FcFontSet |
| 247 */ |
| 248 void ibus_fontset_set_language (IBusFontSet *fontset, |
| 249 const gchar *language); |
| 250 |
| 251 /** |
| 252 * ibus_fontset_update_fcfontset: |
| 253 * @fontset: #IBusFcFontSet |
| 254 * |
| 255 * Update #FcFontSet from font family, size and langauge of @fontset. |
| 256 * Returns: %TRUE if #FcFontSet is updated. %FALSE otherwise. |
| 257 */ |
| 258 gboolean ibus_fontset_update_fcfontset (IBusFontSet *fontset); |
| 259 |
| 260 /** |
| 261 * ibus_fontset_get_preferred_size_hb: |
| 262 * @fontset: #IBusFcFontSet |
| 263 * @text: a string to be calculate the preferred rectangle size. |
| 264 * @widest: (out): #cairo_rectangle_int_t is updated. |
| 265 * |
| 266 * Calculate @widest for @text. |
| 267 * |
| 268 * Returns: #IBusRequisitionEx which includes the glyphs and coordinates. |
| 269 */ |
| 270 IBusRequisitionEx * |
| 271 ibus_fontset_get_preferred_size_hb |
| 272 (IBusFontSet *fontset, |
| 273 const gchar *text, |
| 274 cairo_rectangle_int_t |
| 275 *widest); |
| 276 |
| 277 /** |
| 278 * ibus_fontset_draw_cairo_lines: |
| 279 * @fontset: #IBusFcFontSet |
| 280 * @cr: #cairo_t in #GtkWidget.draw(). |
| 281 * @ex: #IBusRequisitionEx which includes glyph, x, y values, char width |
| 282 * and height. |
| 283 * |
| 284 * Draw glyphs in @ex using cairo @cr. |
| 285 */ |
| 286 void ibus_fontset_draw_cairo_with_requisition_ex |
| 287 (IBusFontSet *fontset, |
| 288 cairo_t *cr, |
| 289 IBusRequisitionEx |
| 290 *ex); |
| 291 |
| 292 /** |
| 293 * ibus_fontset_unref: |
| 294 * @fontset: #IBusFcFontSet |
| 295 * |
| 296 * Call g_object_unref(). |
| 297 * FIXME: Seems Vala needs this API. |
| 298 */ |
| 299 void ibus_fontset_unref (IBusFontSet *fontset); |
| 300 |
| 301 G_END_DECLS |
| 302 #endif |
OLD | NEW |