56 uinT8 sorted = unichars_sorted_;
57 if (fwrite(&sorted,
sizeof(sorted), 1, fp) != 1)
66 if (fread(&sorted,
sizeof(sorted), 1, fp) != 1)
68 unichars_sorted_ = sorted != 0;
76 for (
int c = 0; c < unichars_.
size(); ++c) {
77 if (unichars_[c].unichar_id == unichar_id) {
80 for (
int f = 0;
f < font_list.
size(); ++
f) {
81 if (font_list[
f] == font_id)
90 unichars_sorted_ = unichars_.
size() <= 1;
95 for (
int c = 0; c < other.unichars_.
size(); ++c) {
96 for (
int f = 0;
f < other.unichars_[c].font_ids.
size(); ++
f) {
98 other.unichars_[c].font_ids[
f]);
101 unichars_sorted_ = unichars_.
size() <= 1;
106 for (
int c = 0; c < unichars_.
size(); ++c) {
107 if (unichars_[c].unichar_id == unichar_id) {
110 for (
int f = 0;
f < font_list.
size(); ++
f) {
111 if (font_list[
f] == font_id)
122 for (
int c = 0; c < unichars_.
size(); ++c) {
123 if (unichars_[c].unichar_id == unichar_id) {
132 for (
int c = 0; c < unichars_.
size(); ++c) {
134 for (
int f = 0;
f < font_list.
size(); ++
f) {
135 if (font_list[
f] == font_id)
144 for (
int c = 0; c < unichars_.
size(); ++c) {
145 int unichar_id = unichars_[c].unichar_id;
147 for (
int f = 0;
f < font_list.
size(); ++
f) {
159 if (unichars_.
size() != other->unichars_.
size())
return false;
160 if (!unichars_sorted_) SortUnichars();
161 if (!other->unichars_sorted_) other->SortUnichars();
162 for (
int c = 0; c < unichars_.
size(); ++c) {
163 if (unichars_[c].unichar_id != other->unichars_[c].unichar_id)
170 void Shape::SortUnichars() {
172 unichars_sorted_ =
true;
178 : unicharset_(&unicharset) {
183 if (!shape_table_.
Serialize(fp))
return false;
189 if (!shape_table_.
DeSerialize(swap, fp))
return false;
195 if (shape_id < 0 || shape_id >= shape_table_.
size())
196 return STRING(
"INVALID_UNICHAR_ID");
200 if (shape.
size() > 100) {
204 for (
int c = 0; c < shape.
size(); ++c) {
208 if (shape.
size() < 10) {
210 result +=
" fonts =";
211 int num_fonts = shape[c].font_ids.
size();
212 if (num_fonts > 10) {
214 result.
add_str_int(
" ... ", shape[c].font_ids[num_fonts - 1]);
216 for (
int f = 0;
f < num_fonts; ++
f) {
227 int max_unichars = 0;
228 int num_multi_shapes = 0;
229 int num_master_shapes = 0;
230 for (
int s = 0; s < shape_table_.
size(); ++s) {
236 if (shape_size > max_unichars)
237 max_unichars = shape_size;
240 result.
add_str_int(
"Number of shapes = ", num_master_shapes);
241 result.
add_str_int(
" max unichars = ", max_unichars);
242 result.
add_str_int(
" number with multiple unichars = ", num_multi_shapes);
250 int index = shape_table_.
size();
260 int index = shape_table_.
size();
268 delete shape_table_[shape_id];
269 shape_table_[shape_id] =
NULL;
270 shape_table_.
remove(shape_id);
276 Shape& shape = *shape_table_[shape_id];
282 Shape& shape = *shape_table_[shape_id];
291 for (
int s = 0; s < shape_table_.
size(); ++s) {
293 for (
int c = 0; c < shape.
size(); ++c) {
294 if (shape[c].unichar_id == unichar_id) {
297 for (
int f = 0;
f < shape[c].font_ids.
size(); ++
f) {
298 if (shape[c].font_ids[
f] == font_id)
309 int* unichar_id,
int* font_id)
const {
310 const UnicharAndFonts& unichar_and_fonts = (*shape_table_[shape_id])[0];
312 *font_id = unichar_and_fonts.
font_ids[0];
320 for (
int u_ind = 0; u_ind < shape.
size(); ++u_ind) {
321 for (
int f_ind = 0; f_ind < shape[u_ind].font_ids.
size(); ++f_ind) {
322 int c = shape[u_ind].unichar_id;
323 int f = shape[u_ind].font_ids[f_ind];
326 int master_id = master_shapes.
FindShape(c, f);
327 if (master_id >= 0 && shape.
size() > 1) {
331 shape_table_[shape_id]->AddShape(master);
349 for (
int s1 = 0; s1 < num_shapes; ++s1) {
359 int max_num_unichars = 0;
361 for (
int s = 0; s < num_shapes; ++s) {
362 if (
GetShape(s).size() > max_num_unichars)
365 return max_num_unichars;
372 for (
int s1 = start; s1 < end; ++s1) {
374 int unichar_id =
GetShape(s1)[0].unichar_id;
375 for (
int s2 = s1 + 1; s2 < end; ++s2) {
377 unichar_id ==
GetShape(s2)[0].unichar_id) {
399 for (
int c = 0; c < shape.
size(); ++c) {
400 font_count += shape[c].font_ids.
size();
410 Shape combined_shape(*shape_table_[master_id1]);
411 combined_shape.
AddShape(*shape_table_[master_id2]);
412 return combined_shape.
size();
420 shape_table_[master_id2]->set_destination_index(master_id1);
422 shape_table_[master_id1]->AddShape(*shape_table_[master_id2]);
428 int dest_id = shape_table_[shape_id]->destination_index();
429 if (dest_id == shape_id || dest_id < 0)
431 int master_id = shape_table_[dest_id]->destination_index();
432 if (master_id == dest_id || master_id < 0)
440 for (
int s = 0; s < other.shape_table_.
size(); ++s) {
441 if (other.shape_table_[s]->destination_index() < 0) {
450 for (
int s = 0; s < shape_table_.
size(); ++s) {
451 if (shape_table_[s]->destination_index() < 0)