summaryrefslogtreecommitdiff
path: root/gtk/gtkcomposetable.h
blob: 1398559a66044a0675bc966f7dfa6ae6ae2dee12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* GTK - The GIMP Toolkit
 * Copyright (C) 2015 Takao Fujiwara <takao.fujiwara1@gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __GTK_COMPOSETABLE_H__
#define __GTK_COMPOSETABLE_H__

#include <glib.h>


G_BEGIN_DECLS

typedef struct _GtkComposeTable GtkComposeTable;
typedef struct _GtkComposeTableCompact GtkComposeTableCompact;

/* The layout of the data is as follows:
 *
 * The first part of the data contains rows of length max_seq_len + 1,
 * where the first element is the item of the sequence, and the
 * following elements are offsets to the data for sequences that
 * start with the first item of length 2, ..., max_seq_len.
 *
 * The second part of the data contains the rest of the sequence
 * data. It does not have a fixed stride. For each sequence, we
 * put seq[2], ..., seq[len - 1], followed by the encoded value
 * for this sequence.
 *
 * The values are encoded as follows:
 *
 * If the value is a single Unicode character smaler than 0x8000,
 * then we place it directly. Otherwise, we put the UTF8-encoded
 * value in the char_data array, and use offset | 0x8000 as the
 * encoded value.
 */
struct _GtkComposeTable
{
  guint16 *data;
  char *char_data;
  int max_seq_len;
  int n_index_size;
  int data_size;
  int n_chars;
  int n_sequences;
  guint32 id;
};

GtkComposeTable * gtk_compose_table_new_with_file (const char    *compose_file);
GtkComposeTable * gtk_compose_table_parse         (const char    *compose_file,
                                                   gboolean      *found_include);
GtkComposeTable * gtk_compose_table_new_with_data (const guint16 *data,
                                                   int            max_seq_len,
                                                   int            n_seqs);

typedef void (* GtkComposeSequenceCallback) (gunichar   *sequence,
                                             int         len,
                                             const char *value,
                                             gpointer    data);

void              gtk_compose_table_foreach (const GtkComposeTable      *table,
                                             GtkComposeSequenceCallback  callback,
                                             gpointer                    data);

gboolean          gtk_compose_table_check   (const GtkComposeTable *table,
                                             const guint16         *compose_buffer,
                                             int                    n_compose,
                                             gboolean              *compose_finish,
                                             gboolean              *compose_match,
                                             GString               *output);

gboolean          gtk_check_algorithmically (const guint16         *compose_buffer,
                                             int                    n_compose,
                                             gunichar              *output);

guint32           gtk_compose_table_data_hash (const guint16 *data,
                                               int            max_seq_len,
                                               int            n_seqs);

G_END_DECLS

#endif /* __GTK_COMPOSETABLE_H__ */