MCPcopy Create free account
hub / github.com/creatale/node-dv / LoadXHeights

Method LoadXHeights

deps/tesseract/classify/mastertrainer.cpp:392–432  ·  view source on GitHub ↗

Loads the xheight font properties file into xheights_. Returns false on failure.

Source from the content-addressed store, hash-verified

390// Loads the xheight font properties file into xheights_.
391// Returns false on failure.
392bool MasterTrainer::LoadXHeights(const char* filename) {
393 tprintf("fontinfo table is of size %d\n", fontinfo_table_.size());
394 xheights_.init_to_size(fontinfo_table_.size(), -1);
395 if (filename == NULL) return true;
396 FILE *f = fopen(filename, "rb");
397 if (f == NULL) {
398 fprintf(stderr, "Failed to load font xheights from %s\n", filename);
399 return false;
400 }
401 tprintf("Reading x-heights from %s ...\n", filename);
402 FontInfo fontinfo;
403 fontinfo.properties = 0; // Not used to lookup in the table.
404 fontinfo.universal_id = 0;
405 char buffer[1024];
406 int xht;
407 int total_xheight = 0;
408 int xheight_count = 0;
409 while (!feof(f)) {
410 if (tfscanf(f, "%1023s %d\n", buffer, &xht) != 2)
411 continue;
412 buffer[1023] = '\0';
413 fontinfo.name = buffer;
414 if (!fontinfo_table_.contains(fontinfo)) continue;
415 int fontinfo_id = fontinfo_table_.get_index(fontinfo);
416 xheights_[fontinfo_id] = xht;
417 total_xheight += xht;
418 ++xheight_count;
419 }
420 if (xheight_count == 0) {
421 fprintf(stderr, "No valid xheights in %s!\n", filename);
422 fclose(f);
423 return false;
424 }
425 int mean_xheight = DivRounded(total_xheight, xheight_count);
426 for (int i = 0; i < fontinfo_table_.size(); ++i) {
427 if (xheights_[i] < 0)
428 xheights_[i] = mean_xheight;
429 }
430 fclose(f);
431 return true;
432} // LoadXHeights
433
434// Reads spacing stats from filename and adds them to fontinfo_table.
435bool MasterTrainer::AddSpacingInfo(const char *filename) {

Callers

nothing calls this directly

Calls 6

tfscanfFunction · 0.85
DivRoundedFunction · 0.85
init_to_sizeMethod · 0.80
get_indexMethod · 0.80
sizeMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected