1 | /* GTK - The GIMP Toolkit |
2 | * Copyright (C) 2015 Takao Fujiwara <takao.fujiwara1@gmail.com> |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Lesser General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License, or (at your option) any later version. |
8 | * |
9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Lesser General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Lesser General Public |
15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
16 | */ |
17 | |
18 | #ifndef __GTK_COMPOSETABLE_H__ |
19 | #define __GTK_COMPOSETABLE_H__ |
20 | |
21 | #include <glib.h> |
22 | |
23 | |
24 | G_BEGIN_DECLS |
25 | |
26 | typedef struct _GtkComposeTable GtkComposeTable; |
27 | typedef struct _GtkComposeTableCompact GtkComposeTableCompact; |
28 | |
29 | /* The layout of the data is as follows: |
30 | * |
31 | * The first part of the data contains rows of length max_seq_len + 1, |
32 | * where the first element is the item of the sequence, and the |
33 | * following elements are offsets to the data for sequences that |
34 | * start with the first item of length 2, ..., max_seq_len. |
35 | * |
36 | * The second part of the data contains the rest of the sequence |
37 | * data. It does not have a fixed stride. For each sequence, we |
38 | * put seq[2], ..., seq[len - 1], followed by the encoded value |
39 | * for this sequence. |
40 | * |
41 | * The values are encoded as follows: |
42 | * |
43 | * If the value is a single Unicode character smaler than 0x8000, |
44 | * then we place it directly. Otherwise, we put the UTF8-encoded |
45 | * value in the char_data array, and use offset | 0x8000 as the |
46 | * encoded value. |
47 | */ |
48 | struct _GtkComposeTable |
49 | { |
50 | guint16 *data; |
51 | char *char_data; |
52 | int max_seq_len; |
53 | int n_index_size; |
54 | int data_size; |
55 | int n_chars; |
56 | int n_sequences; |
57 | guint32 id; |
58 | }; |
59 | |
60 | GtkComposeTable * gtk_compose_table_new_with_file (const char *compose_file); |
61 | GtkComposeTable * gtk_compose_table_parse (const char *compose_file, |
62 | gboolean *found_include); |
63 | GtkComposeTable * gtk_compose_table_new_with_data (const guint16 *data, |
64 | int max_seq_len, |
65 | int n_seqs); |
66 | |
67 | typedef void (* GtkComposeSequenceCallback) (gunichar *sequence, |
68 | int len, |
69 | const char *value, |
70 | gpointer data); |
71 | |
72 | void gtk_compose_table_foreach (const GtkComposeTable *table, |
73 | GtkComposeSequenceCallback callback, |
74 | gpointer data); |
75 | |
76 | gboolean gtk_compose_table_check (const GtkComposeTable *table, |
77 | const guint *compose_buffer, |
78 | int n_compose, |
79 | gboolean *compose_finish, |
80 | gboolean *compose_match, |
81 | GString *output); |
82 | |
83 | void gtk_compose_table_get_prefix (const GtkComposeTable *table, |
84 | const guint *compose_buffer, |
85 | int n_compose, |
86 | int *prefix); |
87 | |
88 | gboolean gtk_check_algorithmically (const guint *compose_buffer, |
89 | int n_compose, |
90 | GString *output); |
91 | |
92 | guint32 gtk_compose_table_data_hash (const guint16 *data, |
93 | int max_seq_len, |
94 | int n_seqs); |
95 | |
96 | G_END_DECLS |
97 | |
98 | #endif /* __GTK_COMPOSETABLE_H__ */ |
99 | |