Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/tesseract/src/ccstruct/ocrpara.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: ocrpara.cpp | |
| 3 // Description: OCR Paragraph Output Type | |
| 4 // Author: David Eger | |
| 5 // | |
| 6 // (C) Copyright 2010, Google Inc. | |
| 7 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 8 // you may not use this file except in compliance with the License. | |
| 9 // You may obtain a copy of the License at | |
| 10 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 11 // Unless required by applicable law or agreed to in writing, software | |
| 12 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 // See the License for the specific language governing permissions and | |
| 15 // limitations under the License. | |
| 16 // | |
| 17 /////////////////////////////////////////////////////////////////////// | |
| 18 | |
| 19 #include "ocrpara.h" | |
| 20 | |
| 21 #include "host.h" // For NearlyEqual() | |
| 22 | |
| 23 #include <cstdio> | |
| 24 | |
| 25 namespace tesseract { | |
| 26 | |
| 27 using tesseract::JUSTIFICATION_CENTER; | |
| 28 using tesseract::JUSTIFICATION_LEFT; | |
| 29 using tesseract::JUSTIFICATION_RIGHT; | |
| 30 using tesseract::JUSTIFICATION_UNKNOWN; | |
| 31 | |
| 32 static const char *ParagraphJustificationToString(tesseract::ParagraphJustification justification) { | |
| 33 switch (justification) { | |
| 34 case JUSTIFICATION_LEFT: | |
| 35 return "LEFT"; | |
| 36 case JUSTIFICATION_RIGHT: | |
| 37 return "RIGHT"; | |
| 38 case JUSTIFICATION_CENTER: | |
| 39 return "CENTER"; | |
| 40 default: | |
| 41 return "UNKNOWN"; | |
| 42 } | |
| 43 } | |
| 44 | |
| 45 bool ParagraphModel::ValidFirstLine(int lmargin, int lindent, int rindent, int rmargin) const { | |
| 46 switch (justification_) { | |
| 47 case JUSTIFICATION_LEFT: | |
| 48 return NearlyEqual(lmargin + lindent, margin_ + first_indent_, tolerance_); | |
| 49 case JUSTIFICATION_RIGHT: | |
| 50 return NearlyEqual(rmargin + rindent, margin_ + first_indent_, tolerance_); | |
| 51 case JUSTIFICATION_CENTER: | |
| 52 return NearlyEqual(lindent, rindent, tolerance_ * 2); | |
| 53 default: | |
| 54 // shouldn't happen | |
| 55 return false; | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 bool ParagraphModel::ValidBodyLine(int lmargin, int lindent, int rindent, int rmargin) const { | |
| 60 switch (justification_) { | |
| 61 case JUSTIFICATION_LEFT: | |
| 62 return NearlyEqual(lmargin + lindent, margin_ + body_indent_, tolerance_); | |
| 63 case JUSTIFICATION_RIGHT: | |
| 64 return NearlyEqual(rmargin + rindent, margin_ + body_indent_, tolerance_); | |
| 65 case JUSTIFICATION_CENTER: | |
| 66 return NearlyEqual(lindent, rindent, tolerance_ * 2); | |
| 67 default: | |
| 68 // shouldn't happen | |
| 69 return false; | |
| 70 } | |
| 71 } | |
| 72 | |
| 73 bool ParagraphModel::Comparable(const ParagraphModel &other) const { | |
| 74 if (justification_ != other.justification_) { | |
| 75 return false; | |
| 76 } | |
| 77 if (justification_ == JUSTIFICATION_CENTER || justification_ == JUSTIFICATION_UNKNOWN) { | |
| 78 return true; | |
| 79 } | |
| 80 int tolerance = (tolerance_ + other.tolerance_) / 4; | |
| 81 return NearlyEqual(margin_ + first_indent_, other.margin_ + other.first_indent_, tolerance) && | |
| 82 NearlyEqual(margin_ + body_indent_, other.margin_ + other.body_indent_, tolerance); | |
| 83 } | |
| 84 | |
| 85 std::string ParagraphModel::ToString() const { | |
| 86 char buffer[200]; | |
| 87 const char *alignment = ParagraphJustificationToString(justification_); | |
| 88 snprintf(buffer, sizeof(buffer), "margin: %d, first_indent: %d, body_indent: %d, alignment: %s", | |
| 89 margin_, first_indent_, body_indent_, alignment); | |
| 90 return std::string(buffer); | |
| 91 } | |
| 92 | |
| 93 } // namespace tesseract |
