diff options
author | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2016-07-24 22:43:11 +0000 |
---|---|---|
committer | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2016-07-24 22:43:11 +0000 |
commit | 7b14b75626befe976530136bcf3158a16bd95df0 (patch) | |
tree | 9aefff9670d456ac7402074ffddb1a7f2d7b036d /Build/source/texk/web2c/luatexdir/lang | |
parent | b7f40e4f685e941ac062cac36728a4cad0faab6c (diff) |
luatexdir: Sync with the upstream
git-svn-id: svn://tug.org/texlive/trunk@41755 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/lang')
-rw-r--r-- | Build/source/texk/web2c/luatexdir/lang/hyphen.w | 10 | ||||
-rw-r--r-- | Build/source/texk/web2c/luatexdir/lang/texlang.h | 4 | ||||
-rw-r--r-- | Build/source/texk/web2c/luatexdir/lang/texlang.w | 211 |
3 files changed, 138 insertions, 87 deletions
diff --git a/Build/source/texk/web2c/luatexdir/lang/hyphen.w b/Build/source/texk/web2c/luatexdir/lang/hyphen.w index c661b6c8213..8e13896090d 100644 --- a/Build/source/texk/web2c/luatexdir/lang/hyphen.w +++ b/Build/source/texk/web2c/luatexdir/lang/hyphen.w @@ -805,10 +805,14 @@ void hnj_hyphen_hyphenate(HyphenDict * dict, here = get_vlink(here)) { int ch; - if (here == begin_point || here == end_point) + if (here == begin_point || here == end_point) { ch = '.'; - else - ch = get_lc_code(get_character(here)); + } else { + ch = get_hj_code(char_lang(here),get_character(here)); + if (ch <= 32) { + ch = get_character(here); + } + } while (state != -1) { #if 0 printf("%*s%s%c",char_num-strlen(get_state_str(state)),"",get_state_str(state),(char)ch); diff --git a/Build/source/texk/web2c/luatexdir/lang/texlang.h b/Build/source/texk/web2c/luatexdir/lang/texlang.h index 0920dc9f740..5e7a046195f 100644 --- a/Build/source/texk/web2c/luatexdir/lang/texlang.h +++ b/Build/source/texk/web2c/luatexdir/lang/texlang.h @@ -17,7 +17,6 @@ You should have received a copy of the GNU General Public License along with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */ - #ifndef TEXLANG_H # define TEXLANG_H @@ -46,8 +45,7 @@ struct tex_language { extern struct tex_language *new_language(int n); extern struct tex_language *get_language(int n); extern void load_patterns(struct tex_language *lang, const unsigned char *buf); -extern void load_hyphenation(struct tex_language *lang, - const unsigned char *buf); +extern void load_hyphenation(struct tex_language *lang, const unsigned char *buf); extern int hyphenate_string(struct tex_language *lang, char *w, char **ret); extern void new_hyphenation(halfword h, halfword t); diff --git a/Build/source/texk/web2c/luatexdir/lang/texlang.w b/Build/source/texk/web2c/luatexdir/lang/texlang.w index 68cb0581cd2..f89ca5d4a33 100644 --- a/Build/source/texk/web2c/luatexdir/lang/texlang.w +++ b/Build/source/texk/web2c/luatexdir/lang/texlang.w @@ -30,8 +30,6 @@ #define MAX_TEX_LANGUAGES 16384 -#define ex_hyphen_char int_par(ex_hyphen_char_code) - static struct tex_language *tex_languages[MAX_TEX_LANGUAGES] = { NULL }; static int next_lang_id = 0; @@ -61,7 +59,7 @@ struct tex_language *new_language(int n) lang->pre_exhyphen_char = 0; lang->post_exhyphen_char = 0; lang->hyphenation_min = -1; - if (int_par(saving_hyph_codes_code)) { + if (saving_hyph_codes_par) { hj_codes_from_lc_codes(l); /* for now, we might just use specific value for whatever task */ } return lang; @@ -187,7 +185,7 @@ void load_tex_patterns(int curlang, halfword head) @ @c #define STORE_CHAR(l,x) do { \ unsigned xx = get_hj_code(l,x); \ - if (!xx) { \ + if (!xx || xx <= 32) { \ xx = x; \ } \ uindex = uni2string(uindex, xx); \ @@ -212,7 +210,7 @@ const char *clean_hyphenation(int id, const char *buff, char **cleaned) s++; if ((s-buff)>MAX_WORD_LEN) { /* todo: this is too strict, should count unicode, not bytes */ - *cleaned = NULL; + *cleaned = NULL; tex_error("exception too long", NULL); return s; } @@ -224,7 +222,7 @@ const char *clean_hyphenation(int id, const char *buff, char **cleaned) /* build the new word string */ i = 0; while (uword[i]>0) { - u = uword[i++]; + u = uword[i++]; if (u == '-') { /* skip */ } else if (u == '=') { STORE_CHAR(id,'-'); @@ -276,14 +274,13 @@ void load_hyphenation(struct tex_language *lang, const unsigned char *buff) const char *value; char *cleaned; int id ; - lua_State *L = Luas; if (lang == NULL) return; if (lang->exceptions == 0) { - lua_newtable(L); - lang->exceptions = luaL_ref(L, LUA_REGISTRYINDEX); + lua_newtable(Luas); + lang->exceptions = luaL_ref(Luas, LUA_REGISTRYINDEX); } - lua_rawgeti(L, LUA_REGISTRYINDEX, lang->exceptions); + lua_rawgeti(Luas, LUA_REGISTRYINDEX, lang->exceptions); s = (const char *) buff; id = lang->id; while (*s) { @@ -294,9 +291,9 @@ void load_hyphenation(struct tex_language *lang, const unsigned char *buff) s = clean_hyphenation(id, s, &cleaned); if (cleaned != NULL) { if ((s - value) > 0) { - lua_pushstring(L, cleaned); - lua_pushlstring(L, value, (size_t) (s - value)); - lua_rawset(L, -3); + lua_pushstring(Luas, cleaned); + lua_pushlstring(Luas, value, (size_t) (s - value)); + lua_rawset(Luas, -3); } free(cleaned); } else { @@ -381,7 +378,7 @@ halfword insert_syllable_discretionary(halfword t, lang_variables * lan) { halfword g, n; n = new_node(disc_node, syllable_disc); - disc_penalty(n) = int_par(hyphen_penalty_code); + disc_penalty(n) = hyphen_penalty_par; couple_nodes(n, vlink(t)); couple_nodes(t, n); delete_attribute_ref(node_attr(n)); @@ -427,7 +424,7 @@ halfword insert_word_discretionary(halfword t, lang_variables * lan) pre = insert_character(null, lan->pre_exhyphen_char); if (lan->post_exhyphen_char > 0) pos = insert_character(null, lan->post_exhyphen_char); - return insert_discretionary(t, pre, pos, null,int_par(ex_hyphen_penalty_code)); + return insert_discretionary(t, pre, pos, null,ex_hyphen_penalty_par); } @ @c @@ -446,7 +443,7 @@ halfword insert_complex_discretionary(halfword t, lang_variables * lan, halfword replace) { (void) lan; - return insert_discretionary(t, pre, pos, replace,int_par(hyphen_penalty_code)); + return insert_discretionary(t, pre, pos, replace,hyphen_penalty_par); } halfword insert_character(halfword t, int c) @@ -477,18 +474,17 @@ void set_disc_field(halfword f, halfword t) static char *hyphenation_exception(int exceptions, char *w) { char *ret = NULL; - lua_State *L = Luas; - lua_checkstack(L, 2); - lua_rawgeti(L, LUA_REGISTRYINDEX, exceptions); - if (lua_istable(L, -1)) { /* ?? */ - lua_pushstring(L, w); /* word table */ - lua_rawget(L, -2); - if (lua_type(L, -1) == LUA_TSTRING) { - ret = xstrdup(lua_tostring(L, -1)); + lua_checkstack(Luas, 2); + lua_rawgeti(Luas, LUA_REGISTRYINDEX, exceptions); + if (lua_istable(Luas, -1)) { /* ?? */ + lua_pushstring(Luas, w); /* word table */ + lua_rawget(Luas, -2); + if (lua_type(Luas, -1) == LUA_TSTRING) { + ret = xstrdup(lua_tostring(Luas, -1)); } - lua_pop(L, 2); + lua_pop(Luas, 2); } else { - lua_pop(L, 1); + lua_pop(Luas, 1); } return ret; } @@ -500,16 +496,15 @@ char *exception_strings(struct tex_language *lang) size_t size = 0, current = 0; size_t l = 0; char *ret = NULL; - lua_State *L = Luas; if (lang->exceptions == 0) return NULL; - lua_checkstack(L, 2); - lua_rawgeti(L, LUA_REGISTRYINDEX, lang->exceptions); - if (lua_istable(L, -1)) { + lua_checkstack(Luas, 2); + lua_rawgeti(Luas, LUA_REGISTRYINDEX, lang->exceptions); + if (lua_istable(Luas, -1)) { /* iterate and join */ - lua_pushnil(L); /* first key */ - while (lua_next(L, -2) != 0) { - value = lua_tolstring(L, -1, &l); + lua_pushnil(Luas); /* first key */ + while (lua_next(Luas, -2) != 0) { + value = lua_tolstring(Luas, -1, &l); if (current + 2 + l > size) { ret = xrealloc(ret, (unsigned) ((size + size / 5) + current + l + 1024)); size = (size + size / 5) + current + l + 1024; @@ -517,7 +512,7 @@ char *exception_strings(struct tex_language *lang) *(ret + current) = ' '; strcpy(ret + current + 1, value); current += l + 1; - lua_pop(L, 1); + lua_pop(Luas, 1); } } return ret; @@ -629,7 +624,7 @@ static void do_exception(halfword wordstart, halfword r, char *replacement) try_couple_nodes(t, vlink(q)); vlink(q) = null; } - t = insert_discretionary(t, gg, hh, replace,int_par(hyphen_penalty_code)); + t = insert_discretionary(t, gg, hh, replace, hyphen_penalty_par); t = vlink(t); /* skip the new disc */ } else { t = vlink(t); @@ -699,7 +694,30 @@ hyphenated, but most european users seem to agree that prohibiting hyphenation there was not the best idea ever. @c -static halfword find_next_wordstart(halfword r, halfword first_language) +/* + More strict: \hyphenationbounds + + 0 = not strict + 1 = strict start + 2 = strict end + 3 = strict start and strict end + + \parindent0pt \hsize=1.1cm + 12-34-56 \par + 12-34-\hbox{56} \par + 12-34-\vrule width 1em height 1.5ex \par + 12-\hbox{34}-56 \par + 12-\vrule width 1em height 1.5ex-56 \par + \hjcode`\1=`\1 \hjcode`\2=`\2 \hjcode`\3=`\3 \hjcode`\4=`\4 \vskip.5cm + 12-34-56 \par + 12-34-\hbox{56} \par + 12-34-\vrule width 1em height 1.5ex \par + 12-\hbox{34}-56 \par + 12-\vrule width 1em height 1.5ex-56 \par + +*/ + +static halfword find_next_wordstart(halfword r, halfword first_language, halfword strict_bound) { register int l; register int start_ok = 1; @@ -713,7 +731,14 @@ static halfword find_next_wordstart(halfword r, halfword first_language) start_ok = 1; } break; + case hlist_node: /* new > 0.95 */ + case vlist_node: /* new > 0.95 */ + case rule_node: /* new > 0.95 */ + case dir_node: case whatsit_node: + if (strict_bound == 1 || strict_bound == 3) { + start_ok = 0; + } break; case glue_node: start_ok = 1; @@ -735,7 +760,7 @@ static halfword find_next_wordstart(halfword r, halfword first_language) case glyph_node: if (is_simple_character(r)) { chr = character(r) ; - if (chr == ex_hyphen_char) { + if (chr == ex_hyphen_char_par) { /* We only accept an explicit hyphen when there is a preceding glyph and we skip a sequence of explicit hyphens as that normally indicates a @@ -745,7 +770,7 @@ static halfword find_next_wordstart(halfword r, halfword first_language) hyphenation, ligaturing and kerning steps. A test is cmr with ------. */ t = vlink(r) ; - if ((start_ok > 0) && (t!=null) && (type(t) == glyph_node) && (character(t) != ex_hyphen_char)) { + if ((start_ok == 0) && (t!=null) && (type(t) == glyph_node) && (character(t) != ex_hyphen_char_par)) { t = compound_word_break(r, char_lang(r)); subtype(t) = automatic_disc; start_ok = 1 ; @@ -753,7 +778,7 @@ static halfword find_next_wordstart(halfword r, halfword first_language) start_ok = 0; } } else if (start_ok && (char_lang(r)>=first_language) && ((l = get_hj_code(char_lang(r),chr)) > 0)) { - if (char_uchyph(r) || l == chr) { + if (char_uchyph(r) || l == chr || l <= 32) { return r; } else { start_ok = 0; @@ -771,27 +796,35 @@ static halfword find_next_wordstart(halfword r, halfword first_language) } @ @c -static int valid_wordend(halfword s) +static int valid_wordend(halfword s, halfword strict_bound) { register halfword r = s; register int clang = char_lang(s); if (r == null) return 1; - while ((r != null) && ( (type(r) == glyph_node && is_simple_character(r) && clang == char_lang(r)) - || (type(r) == kern_node && (subtype(r) == normal)) - )) { + while ( (r != null) && + ( (type(r) == glyph_node && is_simple_character(r) && clang == char_lang(r)) + || (type(r) == kern_node && (subtype(r) == normal)) + ) + ) { r = vlink(r); } if (r == null || (type(r) == glyph_node && is_simple_character(r) && clang != char_lang(r)) || type(r) == glue_node - || type(r) == boundary_node - || type(r) == whatsit_node - || type(r) == ins_node - || type(r) == adjust_node || type(r) == penalty_node - || (type(r) == kern_node && (subtype(r) == explicit_kern || + || (type(r) == kern_node && (subtype(r) == explicit_kern || /* so why not italic correction ? */ subtype(r) == italic_kern || - subtype(r) == accent_kern ))) + subtype(r) == accent_kern )) + || ((type(r) == hlist_node || /* new > 0.95 */ + type(r) == vlist_node || /* new > 0.95 */ + type(r) == rule_node || /* new > 0.95 */ + type(r) == dir_node || /* new > 0.97 */ + type(r) == whatsit_node || + type(r) == ins_node || /* yes or no strict test */ + type(r) == adjust_node /* yes or no strict test */ + ) && ! (strict_bound == 2 || strict_bound == 3)) + || type(r) == boundary_node + ) return 1; return 0; } @@ -807,7 +840,8 @@ void hnj_hyphenation(halfword head, halfword tail) char *hy = utf8word; char *replacement = NULL; boolean explicit_hyphen = false; - halfword first_language = int_par(first_valid_language_code); + halfword first_language = first_valid_language_par; + halfword strict_bound = hyphenation_bounds_par; halfword s, r = head, wordstart = null, save_tail1 = null, left = null, right = null; /* this first movement assures two things: @@ -822,7 +856,7 @@ void hnj_hyphenation(halfword head, halfword tail) r = vlink(r); } /* this will make |r| a glyph node with subtype character */ - r = find_next_wordstart(r,first_language); + r = find_next_wordstart(r,first_language,strict_bound); if (r == null) return; @@ -853,21 +887,35 @@ void hnj_hyphenation(halfword head, halfword tail) && ( ( (clang >= first_language) && (lchar = get_hj_code(clang,character(r))) > 0 ) - || ( character(r) == ex_hyphen_char - && (lchar = ex_hyphen_char) + || ( character(r) == ex_hyphen_char_par + && (lchar = ex_hyphen_char_par) ) ) ) { - if (character(r) == ex_hyphen_char) - explicit_hyphen = true; + if (character(r) == ex_hyphen_char_par) { + explicit_hyphen = true; + } wordlen++; + if (lchar <= 32) { + if (lchar == 32) { + lchar = 0 ; + } + if (wordlen <= lhmin) { + lhmin = lhmin - lchar + 1 ; + } + if (wordlen >= rhmin) { + rhmin = rhmin - lchar + 1 ; + } + hmin = hmin - lchar + 1 ; + lchar = character(r) ; + } hy = uni2string(hy, (unsigned) lchar); /* this should not be needed any more */ /*if (vlink(r)!=null) alink(vlink(r))=r; */ end_word = r; r = vlink(r); } - if ( valid_wordend(r) + if ( valid_wordend(r,strict_bound) && clang >= first_language && wordlen >= lhmin + rhmin && (hmin <= 0 || wordlen >= hmin) @@ -884,19 +932,21 @@ void hnj_hyphenation(halfword head, halfword tail) do_exception(wordstart, r, replacement); free(replacement); } else if (explicit_hyphen == true) { - /* insert an explicit discretionary after each of the last in a - set of explicit hyphens */ + /* + insert an explicit discretionary after each of the last in a + set of explicit hyphens + */ halfword rr = r; halfword t = null; #ifdef VERBOSE formatted_warning("hyphenation","explicit hyphen(s) found in %s (c=%d)", utf8word, clang); #endif while (rr != wordstart) { - if (is_simple_character(rr)) { - if (character(rr) == ex_hyphen_char) { + if (is_simple_character(rr)) { + if (character(rr) == ex_hyphen_char_par) { t = compound_word_break(rr, clang); subtype(t) = automatic_disc; - while (character(alink(rr)) == ex_hyphen_char) + while (character(alink(rr)) == ex_hyphen_char_par) rr = alink(rr); if (rr == wordstart) break; @@ -924,12 +974,12 @@ void hnj_hyphenation(halfword head, halfword tail) (void) hnj_hyphen_hyphenate(lang->patterns, wordstart, end_word, wordlen, left, right, &langdata); } } - explicit_hyphen = false; + explicit_hyphen = false; wordlen = 0; hy = utf8word; if (r == null) break; - r = find_next_wordstart(r,first_language); + r = find_next_wordstart(r,first_language,strict_bound); } flush_node(vlink(tail)); vlink(tail) = save_tail1; @@ -944,20 +994,19 @@ void new_hyphenation(halfword head, halfword tail) fix_node_list(head); callback_id = callback_defined(hyphenate_callback); if (callback_id > 0) { - lua_State *L = Luas; - if (!get_callback(L, callback_id)) { - lua_pop(L, 2); + if (!get_callback(Luas, callback_id)) { + lua_pop(Luas, 2); return; } - nodelist_to_lua(L, head); - nodelist_to_lua(L, tail); - if (lua_pcall(L, 2, 0, 0) != 0) { - formatted_warning("hyphenation","bad specification: %s",lua_tostring(L, -1)); - lua_pop(L, 2); - lua_error(L); + nodelist_to_lua(Luas, head); + nodelist_to_lua(Luas, tail); + if (lua_pcall(Luas, 2, 0, 0) != 0) { + formatted_warning("hyphenation","bad specification: %s",lua_tostring(Luas, -1)); + lua_pop(Luas, 2); + lua_error(Luas); return; } - lua_pop(L, 1); + lua_pop(Luas, 1); } else if (callback_id == 0) { hnj_hyphenation(head, tail); } @@ -1072,7 +1121,7 @@ void undump_language_data(void) void new_hyph_exceptions(void) { /* enters new exceptions */ (void) scan_toks(false, true); - load_tex_hyphenation(int_par(language_code), def_ref); + load_tex_hyphenation(language_par, def_ref); flush_list(def_ref); } @@ -1083,7 +1132,7 @@ procedure named |new_patterns|. void new_patterns(void) { /* initializes the hyphenation pattern data */ (void) scan_toks(false, true); - load_tex_patterns(int_par(language_code), def_ref); + load_tex_patterns(language_par, def_ref); flush_list(def_ref); } @@ -1096,14 +1145,14 @@ void new_pre_hyphen_char(void) { scan_optional_equals(); scan_int(); - set_pre_hyphen_char(int_par(language_code), cur_val); + set_pre_hyphen_char(language_par, cur_val); } void new_post_hyphen_char(void) { scan_optional_equals(); scan_int(); - set_post_hyphen_char(int_par(language_code), cur_val); + set_post_hyphen_char(language_par, cur_val); } @ `\.{\\preexhyphenchar}', sets the |pre_break| character, and @@ -1115,21 +1164,21 @@ void new_pre_exhyphen_char(void) { scan_optional_equals(); scan_int(); - set_pre_exhyphen_char(int_par(language_code), cur_val); + set_pre_exhyphen_char(language_par, cur_val); } void new_post_exhyphen_char(void) { scan_optional_equals(); scan_int(); - set_post_exhyphen_char(int_par(language_code), cur_val); + set_post_exhyphen_char(language_par, cur_val); } void new_hyphenation_min(void) { scan_optional_equals(); scan_int(); - set_hyphenation_min(int_par(language_code), cur_val); + set_hyphenation_min(language_par, cur_val); } void new_hj_code(void) @@ -1139,5 +1188,5 @@ void new_hj_code(void) i = cur_val; scan_optional_equals(); scan_int(); - set_hj_code(int_par(language_code), i, cur_val, -1); + set_hj_code(language_par, i, cur_val, -1); } |