00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00019
00020
00021 #ifndef TESSERACT_CCSTRUCT_FONTINFO_H_
00022 #define TESSERACT_CCSTRUCT_FONTINFO_H_
00023
00024 #include "genericvector.h"
00025 #include "host.h"
00026 #include "unichar.h"
00027
00028 namespace tesseract {
00029
00030
00031 struct FontSpacingInfo {
00032 inT16 x_gap_before;
00033 inT16 x_gap_after;
00034 GenericVector<UNICHAR_ID> kerned_unichar_ids;
00035 GenericVector<inT16> kerned_x_gaps;
00036 };
00037
00038
00039
00040
00041
00042 struct FontInfo {
00043 FontInfo() : name(NULL), spacing_vec(NULL) {}
00044 ~FontInfo() {}
00045
00046 void init_spacing(int unicharset_size) {
00047 spacing_vec = new GenericVector<FontSpacingInfo *>();
00048 spacing_vec->init_to_size(unicharset_size, NULL);
00049 }
00050
00051
00052
00053 void add_spacing(UNICHAR_ID uch_id, FontSpacingInfo *spacing_info) {
00054 ASSERT_HOST(spacing_vec != NULL && spacing_vec->size() > uch_id);
00055 (*spacing_vec)[uch_id] = spacing_info;
00056 }
00057
00058
00059 const FontSpacingInfo *get_spacing(UNICHAR_ID uch_id) const {
00060 return (spacing_vec == NULL || spacing_vec->size() <= uch_id) ?
00061 NULL : (*spacing_vec)[uch_id];
00062 }
00063
00064
00065
00066 bool get_spacing(UNICHAR_ID prev_uch_id,
00067 UNICHAR_ID uch_id,
00068 int *spacing) const {
00069 const FontSpacingInfo *prev_fsi = this->get_spacing(prev_uch_id);
00070 const FontSpacingInfo *fsi = this->get_spacing(uch_id);
00071 if (prev_fsi == NULL || fsi == NULL) return false;
00072 int i = 0;
00073 for (; i < prev_fsi->kerned_unichar_ids.size(); ++i) {
00074 if (prev_fsi->kerned_unichar_ids[i] == uch_id) break;
00075 }
00076 if (i < prev_fsi->kerned_unichar_ids.size()) {
00077 *spacing = prev_fsi->kerned_x_gaps[i];
00078 } else {
00079 *spacing = prev_fsi->x_gap_after + fsi->x_gap_before;
00080 }
00081 return true;
00082 }
00083
00084 bool is_italic() const { return properties & 1; }
00085 bool is_bold() const { return (properties & 2) != 0; }
00086 bool is_fixed_pitch() const { return (properties & 4) != 0; }
00087 bool is_serif() const { return (properties & 8) != 0; }
00088 bool is_fraktur() const { return (properties & 16) != 0; }
00089
00090 char* name;
00091 uinT32 properties;
00092
00093
00094
00095
00096 inT32 universal_id;
00097
00098 GenericVector<FontSpacingInfo *> *spacing_vec;
00099 };
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 struct FontSet {
00111 int size;
00112 int* configs;
00113 };
00114
00115
00116 bool CompareFontInfo(const FontInfo& fi1, const FontInfo& fi2);
00117
00118 bool CompareFontSet(const FontSet& fs1, const FontSet& fs2);
00119
00120 void FontInfoDeleteCallback(FontInfo f);
00121 void FontSetDeleteCallback(FontSet fs);
00122
00123
00124 bool read_info(FILE* f, FontInfo* fi, bool swap);
00125 bool write_info(FILE* f, const FontInfo& fi);
00126 bool read_spacing_info(FILE *f, FontInfo* fi, bool swap);
00127 bool write_spacing_info(FILE* f, const FontInfo& fi);
00128 bool read_set(FILE* f, FontSet* fs, bool swap);
00129 bool write_set(FILE* f, const FontSet& fs);
00130
00131 }
00132
00133 #endif