tesseract v5.3.3.20231005
tesseract::FontInfo Struct Reference

#include <fontinfo.h>

Public Member Functions

 FontInfo ()
 
 ~FontInfo ()=default
 
bool operator== (const FontInfo &rhs) const
 
bool Serialize (FILE *fp) const
 
bool DeSerialize (TFile *fp)
 
void init_spacing (int unicharset_size)
 
void add_spacing (UNICHAR_ID uch_id, FontSpacingInfo *spacing_info)
 
const FontSpacingInfoget_spacing (UNICHAR_ID uch_id) const
 
bool get_spacing (UNICHAR_ID prev_uch_id, UNICHAR_ID uch_id, int *spacing) const
 
bool is_italic () const
 
bool is_bold () const
 
bool is_fixed_pitch () const
 
bool is_serif () const
 
bool is_fraktur () const
 

Public Attributes

char * name
 
uint32_t properties
 
int32_t universal_id
 
std::vector< FontSpacingInfo * > * spacing_vec
 

Detailed Description

Definition at line 64 of file fontinfo.h.

Constructor & Destructor Documentation

◆ FontInfo()

tesseract::FontInfo::FontInfo ( )
inline

Definition at line 65 of file fontinfo.h.

65: name(nullptr), properties(0), universal_id(0), spacing_vec(nullptr) {}
int32_t universal_id
Definition: fontinfo.h:140
std::vector< FontSpacingInfo * > * spacing_vec
Definition: fontinfo.h:142
uint32_t properties
Definition: fontinfo.h:135

◆ ~FontInfo()

tesseract::FontInfo::~FontInfo ( )
default

Member Function Documentation

◆ add_spacing()

void tesseract::FontInfo::add_spacing ( UNICHAR_ID  uch_id,
FontSpacingInfo spacing_info 
)
inline

Definition at line 85 of file fontinfo.h.

85 {
86 ASSERT_HOST(static_cast<size_t>(uch_id) < spacing_vec->size());
87 (*spacing_vec)[uch_id] = spacing_info;
88 }
#define ASSERT_HOST(x)
Definition: errcode.h:54

◆ DeSerialize()

bool tesseract::FontInfo::DeSerialize ( TFile fp)

Definition at line 37 of file fontinfo.cpp.

37 {
38 if (!read_info(fp, this)) {
39 return false;
40 }
41 if (!read_spacing_info(fp, this)) {
42 return false;
43 }
44 return true;
45}
bool read_info(TFile *f, FontInfo *fi)
Definition: fontinfo.cpp:143
bool read_spacing_info(TFile *f, FontInfo *fi)
Definition: fontinfo.cpp:163

◆ get_spacing() [1/2]

bool tesseract::FontInfo::get_spacing ( UNICHAR_ID  prev_uch_id,
UNICHAR_ID  uch_id,
int *  spacing 
) const
inline

Definition at line 98 of file fontinfo.h.

98 {
99 const FontSpacingInfo *prev_fsi = this->get_spacing(prev_uch_id);
100 const FontSpacingInfo *fsi = this->get_spacing(uch_id);
101 if (prev_fsi == nullptr || fsi == nullptr) {
102 return false;
103 }
104 size_t i = 0;
105 for (; i < prev_fsi->kerned_unichar_ids.size(); ++i) {
106 if (prev_fsi->kerned_unichar_ids[i] == uch_id) {
107 break;
108 }
109 }
110 if (i < prev_fsi->kerned_unichar_ids.size()) {
111 *spacing = prev_fsi->kerned_x_gaps[i];
112 } else {
113 *spacing = prev_fsi->x_gap_after + fsi->x_gap_before;
114 }
115 return true;
116 }
const FontSpacingInfo * get_spacing(UNICHAR_ID uch_id) const
Definition: fontinfo.h:91

◆ get_spacing() [2/2]

const FontSpacingInfo * tesseract::FontInfo::get_spacing ( UNICHAR_ID  uch_id) const
inline

Definition at line 91 of file fontinfo.h.

91 {
92 return (spacing_vec == nullptr || spacing_vec->size() <= static_cast<size_t>(uch_id)) ? nullptr
93 : (*spacing_vec)[uch_id];
94 }

◆ init_spacing()

void tesseract::FontInfo::init_spacing ( int  unicharset_size)
inline

Definition at line 79 of file fontinfo.h.

79 {
80 spacing_vec = new std::vector<FontSpacingInfo *>(unicharset_size);
81 }

◆ is_bold()

bool tesseract::FontInfo::is_bold ( ) const
inline

Definition at line 121 of file fontinfo.h.

121 {
122 return (properties & 2) != 0;
123 }

◆ is_fixed_pitch()

bool tesseract::FontInfo::is_fixed_pitch ( ) const
inline

Definition at line 124 of file fontinfo.h.

124 {
125 return (properties & 4) != 0;
126 }

◆ is_fraktur()

bool tesseract::FontInfo::is_fraktur ( ) const
inline

Definition at line 130 of file fontinfo.h.

130 {
131 return (properties & 16) != 0;
132 }

◆ is_italic()

bool tesseract::FontInfo::is_italic ( ) const
inline

Definition at line 118 of file fontinfo.h.

118 {
119 return properties & 1;
120 }

◆ is_serif()

bool tesseract::FontInfo::is_serif ( ) const
inline

Definition at line 127 of file fontinfo.h.

127 {
128 return (properties & 8) != 0;
129 }

◆ operator==()

bool tesseract::FontInfo::operator== ( const FontInfo rhs) const
inline

Definition at line 68 of file fontinfo.h.

68 {
69 return strcmp(name, rhs.name) == 0;
70 }

◆ Serialize()

bool tesseract::FontInfo::Serialize ( FILE *  fp) const

Definition at line 26 of file fontinfo.cpp.

26 {
27 if (!write_info(fp, *this)) {
28 return false;
29 }
30 if (!write_spacing_info(fp, *this)) {
31 return false;
32 }
33 return true;
34}
bool write_info(FILE *f, const FontInfo &fi)
Definition: fontinfo.cpp:157
bool write_spacing_info(FILE *f, const FontInfo &fi)
Definition: fontinfo.cpp:194

Member Data Documentation

◆ name

char* tesseract::FontInfo::name

Definition at line 134 of file fontinfo.h.

◆ properties

uint32_t tesseract::FontInfo::properties

Definition at line 135 of file fontinfo.h.

◆ spacing_vec

std::vector<FontSpacingInfo *>* tesseract::FontInfo::spacing_vec

Definition at line 142 of file fontinfo.h.

◆ universal_id

int32_t tesseract::FontInfo::universal_id

Definition at line 140 of file fontinfo.h.


The documentation for this struct was generated from the following files: