intl/hyphenation/src/hyphen.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial