mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-11-27 20:59:36 +08:00
Move function ExtractFontName to baseapi.cpp
It is only used there, so now a local function. This also allows removing blobclass.h. Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
parent
a847e0f9b5
commit
7fdf79aff4
@ -387,7 +387,6 @@ endif
|
|||||||
noinst_HEADERS += src/classify/classify.h
|
noinst_HEADERS += src/classify/classify.h
|
||||||
if !DISABLED_LEGACY_ENGINE
|
if !DISABLED_LEGACY_ENGINE
|
||||||
noinst_HEADERS += src/classify/adaptive.h
|
noinst_HEADERS += src/classify/adaptive.h
|
||||||
noinst_HEADERS += src/classify/blobclass.h
|
|
||||||
noinst_HEADERS += src/classify/cluster.h
|
noinst_HEADERS += src/classify/cluster.h
|
||||||
noinst_HEADERS += src/classify/clusttool.h
|
noinst_HEADERS += src/classify/clusttool.h
|
||||||
noinst_HEADERS += src/classify/featdefs.h
|
noinst_HEADERS += src/classify/featdefs.h
|
||||||
|
@ -23,9 +23,6 @@
|
|||||||
# include "config_auto.h"
|
# include "config_auto.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef DISABLED_LEGACY_ENGINE
|
|
||||||
# include "blobclass.h" // for ExtractFontName
|
|
||||||
#endif
|
|
||||||
#include "boxword.h" // for BoxWord
|
#include "boxword.h" // for BoxWord
|
||||||
#include "coutln.h" // for C_OUTLINE_IT, C_OUTLINE_LIST
|
#include "coutln.h" // for C_OUTLINE_IT, C_OUTLINE_LIST
|
||||||
#include "dawg_cache.h" // for DawgCache
|
#include "dawg_cache.h" // for DawgCache
|
||||||
@ -125,6 +122,34 @@ static const char *kOldVarsFile = "failed_vars.txt";
|
|||||||
/** Max string length of an int. */
|
/** Max string length of an int. */
|
||||||
const int kMaxIntSize = 22;
|
const int kMaxIntSize = 22;
|
||||||
|
|
||||||
|
#ifndef DISABLED_LEGACY_ENGINE
|
||||||
|
static const char kUnknownFontName[] = "UnknownFont";
|
||||||
|
|
||||||
|
static STRING_VAR(classify_font_name, kUnknownFontName,
|
||||||
|
"Default font name to be used in training");
|
||||||
|
|
||||||
|
// Finds the name of the training font and returns it in fontname, by cutting
|
||||||
|
// it out based on the expectation that the filename is of the form:
|
||||||
|
// /path/to/dir/[lang].[fontname].exp[num]
|
||||||
|
// The [lang], [fontname] and [num] fields should not have '.' characters.
|
||||||
|
// If the global parameter classify_font_name is set, its value is used instead.
|
||||||
|
static void ExtractFontName(const char* filename, std::string* fontname) {
|
||||||
|
*fontname = classify_font_name;
|
||||||
|
if (*fontname == kUnknownFontName) {
|
||||||
|
// filename is expected to be of the form [lang].[fontname].exp[num]
|
||||||
|
// The [lang], [fontname] and [num] fields should not have '.' characters.
|
||||||
|
const char *basename = strrchr(filename, '/');
|
||||||
|
const char *firstdot = strchr(basename ? basename : filename, '.');
|
||||||
|
const char *lastdot = strrchr(filename, '.');
|
||||||
|
if (firstdot != lastdot && firstdot != nullptr && lastdot != nullptr) {
|
||||||
|
++firstdot;
|
||||||
|
*fontname = firstdot;
|
||||||
|
fontname->resize(lastdot - firstdot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Add all available languages recursively.
|
/* Add all available languages recursively.
|
||||||
*/
|
*/
|
||||||
static void addAvailableLanguages(const std::string &datadir, const std::string &base,
|
static void addAvailableLanguages(const std::string &datadir, const std::string &base,
|
||||||
|
@ -15,8 +15,6 @@
|
|||||||
** limitations under the License.
|
** limitations under the License.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include "blobclass.h"
|
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
#include "classify.h"
|
#include "classify.h"
|
||||||
@ -26,35 +24,6 @@
|
|||||||
|
|
||||||
namespace tesseract {
|
namespace tesseract {
|
||||||
|
|
||||||
static const char kUnknownFontName[] = "UnknownFont";
|
|
||||||
|
|
||||||
static STRING_VAR(classify_font_name, kUnknownFontName, "Default font name to be used in training");
|
|
||||||
|
|
||||||
/**----------------------------------------------------------------------------
|
|
||||||
Public Code
|
|
||||||
----------------------------------------------------------------------------**/
|
|
||||||
|
|
||||||
// Finds the name of the training font and returns it in fontname, by cutting
|
|
||||||
// it out based on the expectation that the filename is of the form:
|
|
||||||
// /path/to/dir/[lang].[fontname].exp[num]
|
|
||||||
// The [lang], [fontname] and [num] fields should not have '.' characters.
|
|
||||||
// If the global parameter classify_font_name is set, its value is used instead.
|
|
||||||
void ExtractFontName(const char *filename, std::string *fontname) {
|
|
||||||
*fontname = classify_font_name;
|
|
||||||
if (*fontname == kUnknownFontName) {
|
|
||||||
// filename is expected to be of the form [lang].[fontname].exp[num]
|
|
||||||
// The [lang], [fontname] and [num] fields should not have '.' characters.
|
|
||||||
const char *basename = strrchr(filename, '/');
|
|
||||||
const char *firstdot = strchr(basename ? basename : filename, '.');
|
|
||||||
const char *lastdot = strrchr(filename, '.');
|
|
||||||
if (firstdot != lastdot && firstdot != nullptr && lastdot != nullptr) {
|
|
||||||
++firstdot;
|
|
||||||
*fontname = firstdot;
|
|
||||||
fontname->resize(lastdot - firstdot);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
// Extracts features from the given blob and saves them in the tr_file_data_
|
// Extracts features from the given blob and saves them in the tr_file_data_
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
** Filename: blobclass.h
|
|
||||||
** Purpose: Interface to high level classification and training.
|
|
||||||
** Author: Dan Johnson
|
|
||||||
**
|
|
||||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
|
||||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
** you may not use this file except in compliance with the License.
|
|
||||||
** You may obtain a copy of the License at
|
|
||||||
** http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
** Unless required by applicable law or agreed to in writing, software
|
|
||||||
** distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
** See the License for the specific language governing permissions and
|
|
||||||
** limitations under the License.
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
#ifndef BLOBCLASS_H
|
|
||||||
#define BLOBCLASS_H
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace tesseract {
|
|
||||||
// Finds the name of the training font and returns it in fontname, by cutting
|
|
||||||
// it out based on the expectation that the filename is of the form:
|
|
||||||
// /path/to/dir/[lang].[fontname].exp[num]
|
|
||||||
// The [lang], [fontname] and [num] fields should not have '.' characters.
|
|
||||||
// If the global parameter classify_font_name is set, its value is used instead.
|
|
||||||
void ExtractFontName(const char *filename, std::string *fontname);
|
|
||||||
|
|
||||||
} // namespace tesseract.
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
Reference in New Issue
Block a user