comparison mupdf-source/thirdparty/tesseract/src/dict/hyphen.cpp @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 /******************************************************************************
2 * File: hyphen.cpp (Formerly hyphen.c)
3 * Description: Functions for maintaining information about hyphenated words.
4 * Author: Mark Seaman, OCR Technology
5 * Status: Reusable Software Component
6 *
7 * (c) Copyright 1987, Hewlett-Packard Company.
8 ** Licensed under the Apache License, Version 2.0 (the "License");
9 ** you may not use this file except in compliance with the License.
10 ** You may obtain a copy of the License at
11 ** http://www.apache.org/licenses/LICENSE-2.0
12 ** Unless required by applicable law or agreed to in writing, software
13 ** distributed under the License is distributed on an "AS IS" BASIS,
14 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 ** See the License for the specific language governing permissions and
16 ** limitations under the License.
17 *
18 *****************************************************************************/
19
20 #include "dict.h"
21
22 namespace tesseract {
23
24 // Unless the previous word was the last one on the line, and the current
25 // one is not (thus it is the first one on the line), erase hyphen_word_,
26 // clear hyphen_active_dawgs_, hyphen_constraints_ update last_word_on_line_.
27 void Dict::reset_hyphen_vars(bool last_word_on_line) {
28 if (!(last_word_on_line_ == true && last_word_on_line == false)) {
29 if (hyphen_word_ != nullptr) {
30 delete hyphen_word_;
31 hyphen_word_ = nullptr;
32 hyphen_active_dawgs_.clear();
33 }
34 }
35 if (hyphen_debug_level) {
36 tprintf("reset_hyphen_vars: last_word_on_line %d -> %d\n", last_word_on_line_,
37 last_word_on_line);
38 }
39 last_word_on_line_ = last_word_on_line;
40 }
41
42 // Update hyphen_word_, and copy the given DawgPositionVectors into
43 // hyphen_active_dawgs_.
44 void Dict::set_hyphen_word(const WERD_CHOICE &word, const DawgPositionVector &active_dawgs) {
45 if (hyphen_word_ == nullptr) {
46 hyphen_word_ = new WERD_CHOICE(word.unicharset());
47 hyphen_word_->make_bad();
48 }
49 if (hyphen_word_->rating() > word.rating()) {
50 *hyphen_word_ = word;
51 // Remove the last unichar id as it is a hyphen, and remove
52 // any unichar_string/lengths that are present.
53 hyphen_word_->remove_last_unichar_id();
54 hyphen_active_dawgs_ = active_dawgs;
55 }
56 if (hyphen_debug_level) {
57 hyphen_word_->print("set_hyphen_word: ");
58 }
59 }
60 } // namespace tesseract