1 | /* Hyphen - hyphenation library using converted TeX hyphenation patterns |
2 | * |
3 | * (C) 1998 Raph Levien |
4 | * (C) 2001 ALTLinux, Moscow |
5 | * (C) 2006, 2007, 2008 László Németh |
6 | * |
7 | * This was part of libHnj library by Raph Levien. |
8 | * |
9 | * Peter Novodvorsky from ALTLinux cut hyphenation part from libHnj |
10 | * to use it in OpenOffice.org. |
11 | * |
12 | * Non-standard and compound word hyphenation support by László Németh. |
13 | * |
14 | * License is the original LibHnj license: |
15 | * |
16 | * LibHnj is dual licensed under LGPL and MPL. Boilerplate for both |
17 | * licenses follows. |
18 | */ |
19 | |
20 | /* LibHnj - a library for high quality hyphenation and justification |
21 | * Copyright (C) 1998 Raph Levien |
22 | * |
23 | * This library is free software; you can redistribute it and/or |
24 | * modify it under the terms of the GNU Library General Public |
25 | * License as published by the Free Software Foundation; either |
26 | * version 2 of the License, or (at your option) any later version. |
27 | * |
28 | * This library is distributed in the hope that it will be useful, |
29 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
30 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
31 | * Library General Public License for more details. |
32 | * |
33 | * You should have received a copy of the GNU Library General Public |
34 | * License along with this library; if not, write to the |
35 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
36 | * Boston, MA 02111-1307 USA. |
37 | */ |
38 | |
39 | /* |
40 | * The contents of this file are subject to the Mozilla Public License |
41 | * Version 1.0 (the "MPL"); you may not use this file except in |
42 | * compliance with the MPL. You may obtain a copy of the MPL at |
43 | * http://www.mozilla.org/MPL/ |
44 | * |
45 | * Software distributed under the MPL is distributed on an "AS IS" basis, |
46 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the MPL |
47 | * for the specific language governing rights and limitations under the |
48 | * MPL. |
49 | * |
50 | */ |
51 | #ifndef __HYPHEN_H__ |
52 | #define __HYPHEN_H__ |
53 | |
54 | #ifdef __cplusplus |
55 | extern "C" { |
56 | #endif /* __cplusplus */ |
57 | |
58 | #include <stdio.h> |
59 | |
60 | typedef struct _HyphenDict HyphenDict; |
61 | typedef struct _HyphenState HyphenState; |
62 | typedef struct _HyphenTrans HyphenTrans; |
63 | #define MAX_CHARS 100 |
64 | #define MAX_NAME 20 |
65 | |
66 | struct _HyphenDict { |
67 | /* user options */ |
68 | char lhmin; /* lefthyphenmin: min. hyph. distance from the left side */ |
69 | char rhmin; /* righthyphenmin: min. hyph. distance from the right side */ |
70 | char clhmin; /* min. hyph. distance from the left compound boundary */ |
71 | char crhmin; /* min. hyph. distance from the right compound boundary */ |
72 | char * nohyphen; /* comma separated list of characters or character |
73 | sequences with forbidden hyphenation */ |
74 | int nohyphenl; /* count of elements in nohyphen */ |
75 | /* system variables */ |
76 | int num_states; |
77 | char cset[MAX_NAME]; |
78 | int utf8; |
79 | HyphenState *states; |
80 | HyphenDict *nextlevel; |
81 | }; |
82 | |
83 | struct _HyphenState { |
84 | char *match; |
85 | char *repl; |
86 | signed char replindex; |
87 | signed char replcut; |
88 | int fallback_state; |
89 | int num_trans; |
90 | HyphenTrans *trans; |
91 | }; |
92 | |
93 | struct _HyphenTrans { |
94 | char ch; |
95 | int new_state; |
96 | }; |
97 | |
98 | HyphenDict *hnj_hyphen_load (const char *fn); |
99 | HyphenDict *hnj_hyphen_load_file (FILE *f); |
100 | void hnj_hyphen_free (HyphenDict *dict); |
101 | |
102 | /* obsolete, use hnj_hyphen_hyphenate2() or *hyphenate3() functions) */ |
103 | int hnj_hyphen_hyphenate (HyphenDict *dict, |
104 | const char *word, int word_size, |
105 | char *hyphens); |
106 | |
107 | /* |
108 | |
109 | int hnj_hyphen_hyphenate2(): non-standard hyphenation. |
110 | |
111 | (It supports Catalan, Dutch, German, Hungarian, Norwegian, Swedish |
112 | etc. orthography, see documentation.) |
113 | |
114 | input data: |
115 | word: input word |
116 | word_size: byte length of the input word |
117 | |
118 | hyphens: allocated character buffer (size = word_size + 5) |
119 | hyphenated_word: allocated character buffer (size ~ word_size * 2) or NULL |
120 | rep, pos, cut: pointers (point to the allocated and _zeroed_ buffers |
121 | (size=word_size) or with NULL value) or NULL |
122 | |
123 | output data: |
124 | hyphens: hyphenation vector (hyphenation points signed with odd numbers) |
125 | hyphenated_word: hyphenated input word (hyphens signed with `='), |
126 | optional (NULL input) |
127 | rep: NULL (only standard hyph.), or replacements (hyphenation points |
128 | signed with `=' in replacements); |
129 | pos: NULL, or difference of the actual position and the beginning |
130 | positions of the change in input words; |
131 | cut: NULL, or counts of the removed characters of the original words |
132 | at hyphenation, |
133 | |
134 | Note: rep, pos, cut are complementary arrays to the hyphens, indexed with the |
135 | character positions of the input word. |
136 | |
137 | For example: |
138 | Schiffahrt -> Schiff=fahrt, |
139 | pattern: f1f/ff=f,1,2 |
140 | output: rep[5]="ff=f", pos[5] = 1, cut[5] = 2 |
141 | |
142 | Note: hnj_hyphen_hyphenate2() can allocate rep, pos, cut (word_size |
143 | length arrays): |
144 | |
145 | char ** rep = NULL; |
146 | int * pos = NULL; |
147 | int * cut = NULL; |
148 | char hyphens[MAXWORDLEN]; |
149 | hnj_hyphen_hyphenate2(dict, "example", 7, hyphens, NULL, &rep, &pos, &cut); |
150 | |
151 | See example in the source distribution. |
152 | |
153 | */ |
154 | |
155 | int hnj_hyphen_hyphenate2 (HyphenDict *dict, |
156 | const char *word, int word_size, char * hyphens, |
157 | char *hyphenated_word, char *** rep, int ** pos, int ** cut); |
158 | |
159 | /* like hnj_hyphen_hyphenate2, but with hyphenmin parameters */ |
160 | /* lhmin: lefthyphenmin |
161 | * rhmin: righthyphenmin |
162 | * clhmin: compoundlefthyphemin |
163 | * crhmin: compoundrighthyphenmin |
164 | * (see documentation) */ |
165 | |
166 | int hnj_hyphen_hyphenate3 (HyphenDict *dict, |
167 | const char *word, int word_size, char * hyphens, |
168 | char *hyphword, char *** rep, int ** pos, int ** cut, |
169 | int lhmin, int rhmin, int clhmin, int crhmin); |
170 | |
171 | #ifdef __cplusplus |
172 | } |
173 | #endif /* __cplusplus */ |
174 | |
175 | #endif /* __HYPHEN_H__ */ |
176 | |