Tesseract
3.02
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
fontinfo.h
Go to the documentation of this file.
1
2
// File: fontinfo.h
3
// Description: Font information classes abstracted from intproto.h/cpp.
4
// Author: rays@google.com (Ray Smith)
5
// Created: Tue May 17 17:08:01 PDT 2011
6
//
7
// (C) Copyright 2011, Google Inc.
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
//
19
20
21
#ifndef TESSERACT_CCSTRUCT_FONTINFO_H_
22
#define TESSERACT_CCSTRUCT_FONTINFO_H_
23
24
#include "
genericvector.h
"
25
#include "
host.h
"
26
#include "
unichar.h
"
27
28
namespace
tesseract
{
29
30
// Struct for information about spacing between characters in a particular font.
31
struct
FontSpacingInfo
{
32
inT16
x_gap_before
;
33
inT16
x_gap_after
;
34
GenericVector<UNICHAR_ID>
kerned_unichar_ids
;
35
GenericVector<inT16>
kerned_x_gaps
;
36
};
37
38
/*
39
* font_properties contains properties about boldness, italicness, fixed pitch,
40
* serif, fraktur
41
*/
42
struct
FontInfo
{
43
FontInfo
() :
name
(
NULL
),
spacing_vec
(
NULL
) {}
44
~FontInfo
() {}
45
// Reserves unicharset_size spots in spacing_vec.
46
void
init_spacing
(
int
unicharset_size) {
47
spacing_vec
=
new
GenericVector<FontSpacingInfo *>
();
48
spacing_vec
->
init_to_size
(unicharset_size,
NULL
);
49
}
50
// Adds the given pointer to FontSpacingInfo to spacing_vec member
51
// (FontInfo class takes ownership of the pointer).
52
// Note: init_spacing should be called before calling this function.
53
void
add_spacing
(
UNICHAR_ID
uch_id,
FontSpacingInfo
*spacing_info) {
54
ASSERT_HOST
(
spacing_vec
!=
NULL
&&
spacing_vec
->
size
() > uch_id);
55
(*spacing_vec)[uch_id] = spacing_info;
56
}
57
58
// Returns the pointer to FontSpacingInfo for the given UNICHAR_ID.
59
const
FontSpacingInfo
*
get_spacing
(
UNICHAR_ID
uch_id)
const
{
60
return
(
spacing_vec
==
NULL
||
spacing_vec
->
size
() <= uch_id) ?
61
NULL
: (*
spacing_vec
)[uch_id];
62
}
63
64
// Fills spacing with the value of the x gap expected between the two given
65
// UNICHAR_IDs. Returns true on success.
66
bool
get_spacing
(
UNICHAR_ID
prev_uch_id,
67
UNICHAR_ID
uch_id,
68
int
*spacing)
const
{
69
const
FontSpacingInfo
*prev_fsi = this->
get_spacing
(prev_uch_id);
70
const
FontSpacingInfo
*fsi = this->
get_spacing
(uch_id);
71
if
(prev_fsi ==
NULL
|| fsi ==
NULL
)
return
false
;
72
int
i = 0;
73
for
(; i < prev_fsi->
kerned_unichar_ids
.
size
(); ++i) {
74
if
(prev_fsi->
kerned_unichar_ids
[i] == uch_id)
break
;
75
}
76
if
(i < prev_fsi->kerned_unichar_ids.size()) {
77
*spacing = prev_fsi->
kerned_x_gaps
[i];
78
}
else
{
79
*spacing = prev_fsi->
x_gap_after
+ fsi->
x_gap_before
;
80
}
81
return
true
;
82
}
83
84
bool
is_italic
()
const
{
return
properties
& 1; }
85
bool
is_bold
()
const
{
return
(
properties
& 2) != 0; }
86
bool
is_fixed_pitch
()
const
{
return
(
properties
& 4) != 0; }
87
bool
is_serif
()
const
{
return
(
properties
& 8) != 0; }
88
bool
is_fraktur
()
const
{
return
(
properties
& 16) != 0; }
89
90
char
*
name
;
91
uinT32
properties
;
92
// The universal_id is a field reserved for the initialization process
93
// to assign a unique id number to all fonts loaded for the current
94
// combination of languages. This id will then be returned by
95
// ResultIterator::WordFontAttributes.
96
inT32
universal_id
;
97
// Horizontal spacing between characters (indexed by UNICHAR_ID).
98
GenericVector<FontSpacingInfo *>
*
spacing_vec
;
99
};
100
101
// Every class (character) owns a FontSet that represents all the fonts that can
102
// render this character.
103
// Since almost all the characters from the same script share the same set of
104
// fonts, the sets are shared over multiple classes (see
105
// Classify::fontset_table_). Thus, a class only store an id to a set.
106
// Because some fonts cannot render just one character of a set, there are a
107
// lot of FontSet that differ only by one font. Rather than storing directly
108
// the FontInfo in the FontSet structure, it's better to share FontInfos among
109
// FontSets (Classify::fontinfo_table_).
110
struct
FontSet
{
111
int
size
;
112
int
*
configs
;
// FontInfo ids
113
};
114
115
// Compare FontInfo structures.
116
bool
CompareFontInfo
(
const
FontInfo
& fi1,
const
FontInfo
& fi2);
117
// Compare FontSet structures.
118
bool
CompareFontSet
(
const
FontSet
& fs1,
const
FontSet
& fs2);
119
// Deletion callbacks for GenericVector.
120
void
FontInfoDeleteCallback
(
FontInfo
f
);
121
void
FontSetDeleteCallback
(
FontSet
fs);
122
123
// Callbacks used by UnicityTable to read/write FontInfo/FontSet structures.
124
bool
read_info
(FILE*
f
,
FontInfo
* fi,
bool
swap);
125
bool
write_info
(FILE*
f
,
const
FontInfo
& fi);
126
bool
read_spacing_info
(FILE *
f
,
FontInfo
* fi,
bool
swap);
127
bool
write_spacing_info
(FILE*
f
,
const
FontInfo
& fi);
128
bool
read_set
(FILE*
f
,
FontSet
* fs,
bool
swap);
129
bool
write_set
(FILE*
f
,
const
FontSet
& fs);
130
131
}
// namespace tesseract.
132
133
#endif
/* THIRD_PARTY_TESSERACT_CCSTRUCT_FONTINFO_H_ */
mnt
data
src
tesseract-ocr
ccstruct
fontinfo.h
Generated on Thu Nov 1 2012 20:19:44 for Tesseract by
1.8.1