⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pgedit.cpp

📁 一OCR的相关资料。.希望对研究OCR的朋友有所帮助.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
  parent_menu->add_child (new SIMPLE_MENU_LEAF ("Quit", QUIT_CMD_EVENT));  parent_menu->add_child (new SIMPLE_MENU_LEAF ("Tidy Target",    TIDY_CMD_EVENT));  view_menu_item = new SIMPLE_MENU_LEAF ("View TARGET", VIEW_CMD_EVENT);  parent_menu->add_child (view_menu_item);  parent_menu->add_child (new TOGGLE_MENU_LEAF ("Show Image",    IMAGE_CMD_EVENT, FALSE));  parent_menu->add_child (new TOGGLE_MENU_LEAF ("ShowBlock Outlines",    BLOCKS_CMD_EVENT, FALSE));  parent_menu->add_child (new TOGGLE_MENU_LEAF ("Show Baselines",    BASELINES_CMD_EVENT, FALSE));  write_menu_item = new VARIABLE_MENU_LEAF ("Write File",    WRITE_CMD_EVENT,    imagebasename.string ());  parent_menu->add_child (write_menu_item);  parent_menu->add_child (new SIMPLE_MENU_LEAF ("Make SMD Image",    SMD_CMD_EVENT));  parent_menu->add_child (new VARIABLE_MENU_LEAF ("New Source File",    NEW_SOURCE_CMD_EVENT,    imagebasename.string ()));  parent_menu->add_child (new SIMPLE_MENU_LEAF ("Uniform Display",    UNIFORM_DISP_CMD_EVENT));  parent_menu->add_child (new SIMPLE_MENU_LEAF ("Refresh Display",    REFRESH_CMD_EVENT));                                 //Call driver program  extend_menu(modes_menu_item,              EXTENDED_MODES_BASE,              parent_menu,              EXTENDED_OTHER_BASE);  return root_menu_item;}/********************************************************************** *  debug_window_handle() * *  Return a FILE* for the debug window, creating it if necessary **********************************************************************/void debug_window_handle() {  //return handle  //      if      ( debug_winth == NULL )                                                                 //not opened yet  //      {  //    pgeditor_msg( "Creating debug window..." );  //  create_debug_window();  pgeditor_msg ("Creating debug window...Done");  //      }}/********************************************************************** *  display_bln_lines() * *  Display normalised baseline, x-height, ascender limit and descender limit **********************************************************************/void display_bln_lines(WINDOW window,                       COLOUR colour,                       float scale_factor,                       float y_offset,                       float minx,                       float maxx) {  line_color_index(window, colour);  line_type(window, SOLID);  move2d (window, minx, y_offset + scale_factor * DESC_HEIGHT);  draw2d (window, maxx, y_offset + scale_factor * DESC_HEIGHT);  move2d (window, minx, y_offset + scale_factor * BL_HEIGHT);  draw2d (window, maxx, y_offset + scale_factor * BL_HEIGHT);  move2d (window, minx, y_offset + scale_factor * X_HEIGHT);  draw2d (window, maxx, y_offset + scale_factor * X_HEIGHT);  move2d (window, minx, y_offset + scale_factor * ASC_HEIGHT);  draw2d (window, maxx, y_offset + scale_factor * ASC_HEIGHT);}/********************************************************************** *  do_new_source() * *  Change to another source file.  Automatically tidy page first * **********************************************************************/void do_new_source(            //serialise                   char *name  //file name                  ) {  FILE *infp;                    //input file  char msg_str[MAX_CHARS + 1];  STRING name_str(name);  char response_str[MAX_CHARS + 1];  char *token;                   //first response token  if (source_changed) {    response_str[0] = '\0';    command_window->prompt ("Source changes will be LOST.  Continue? (Y/N)",      response_str);    token = strtok (response_str, " ");    if (tolower (token[0]) != 'y')      return;  }                                 //if not file exists  if (!(infp = fopen (name, "r"))) {    sprintf (msg_str, "Cant open file " "%s" "", name);    command_window->msg (msg_str);    return;  }  fclose(infp);  sprintf (msg_str, "Reading file " "%s" "...", name);  command_window->msg (msg_str);  source_block_list->clear ();                                 //appends to SOURCE  pgeditor_read_file(name_str, source_block_list);  source_changed = FALSE;  command_window->msg ("Doing automatic Tidy Target...");  viewing_source = FALSE;        //Force viewing source  do_tidy_cmd();  command_window->msg ("Doing automatic Tidy Target...Done");}/********************************************************************** *  do_re_display() * *  Redisplay page **********************************************************************/void                                 //function to calldo_re_display (BOOL8 word_painter (BLOCK *, ROW *, WERD *)) {  BLOCK_IT block_it(current_block_list);  BLOCK *block;  int block_count = 1;  ROW_IT row_it;  ROW *row;  WERD_IT word_it;  WERD *word;  clear_view_surface(image_win);  if (display_image) {    show_sub_image (&page_image, 0, 0,      page_image.get_xsize (), page_image.get_ysize (),      image_win, 0, 0);  }  for (block_it.mark_cycle_pt ();  !block_it.cycled_list (); block_it.forward ()) {    block = block_it.data ();    row_it.set_to_list (block->row_list ());    for (row_it.mark_cycle_pt (); !row_it.cycled_list (); row_it.forward ()) {      row = row_it.data ();      word_it.set_to_list (row->word_list ());      for (word_it.mark_cycle_pt ();      !word_it.cycled_list (); word_it.forward ()) {        word = word_it.data ();        word_painter(block, row, word);      }      if (display_baselines)        row->plot_baseline (image_win, GREEN);    }    if (display_blocks)      block->plot (image_win, block_count++, RED);  }}/********************************************************************** *  do_tidy_cmd() * *  Tidy TARGET page **********************************************************************/const BOX do_tidy_cmd() {  //tidy  ICOORD shift_vector;  BOX tidy_box;                  //Just the tidy area  BOX source_box;                //source file area  source_box = block_list_bounding_box (source_block_list);  //find src area  if (!target_block_list.empty ()) {    tidy_box = block_list_compress (&target_block_list);    /* Shift tidied target above the source image area. */    shift_vector = ICOORD (0, source_box.top () + BLOCK_SPACING)      - tidy_box.botleft ();    block_list_move(&target_block_list, shift_vector);    tidy_box.move (shift_vector);  }  source_box += tidy_box;                                 //big enough for both  build_image_window(source_box);  do_view_cmd();  return tidy_box;}/********************************************************************** *  do_view_cmd() * *  View TARGET/View SOURCE command **********************************************************************/void do_view_cmd() {  viewing_source = !viewing_source;  clear_view_surface(image_win);  if (viewing_source) {    current_block_list = source_block_list;    current_image_changed = &source_changed;    other_block_list = &target_block_list;    other_image_changed = &target_changed;    do_re_display(&word_display);    command_window->replace_menu_text (view_menu_item, "View TARGET");    command_window->replace_menu_text (copy_menu_item, "Copy to TARGET");    write_menu_item->replace_value (imagebasename.string ());  }  else {    current_block_list = &target_block_list;    current_image_changed = &target_changed;    other_block_list = source_block_list;    other_image_changed = &source_changed;    do_re_display(&word_display);    command_window->replace_menu_text (view_menu_item, "View SOURCE");    command_window->replace_menu_text (copy_menu_item, "");    write_menu_item->replace_value ((imagebasename + ".bits.pg").string ());  }}/********************************************************************** *  do_write_file() * *  Serialise a block list to file * *  If writing image, tidy page and move to (0,0) first **********************************************************************/void do_write_file(            //serialise                   char *name  //file name                  ) {  FILE *infp;                    //input file  char msg_str[MAX_CHARS + 1];  char response_str[MAX_CHARS + 1];  char *token;                   //first response token  BOX enclosing_box;                                 //if file exists  if ((infp = fopen (name, "r")) != NULL) {    fclose(infp);    sprintf (msg_str, "Overwrite file " "%s" "? (Y/N)", name);    response_str[0] = '\0';    if (!command_window->prompt (msg_str, response_str))      return;    token = strtok (response_str, " ");    if (tolower (token[0]) != 'y')      return;                    // dont write  }  infp = fopen (name, "w");      //can we write to it?  if (infp == NULL) {    sprintf (msg_str, "Cant write to file " "%s" "", name);    command_window->msg (msg_str);    return;  }  fclose(infp);  if (!viewing_source && !target_block_list.empty ()) {                                 //Tidy & move to (0,0)    command_window->msg ("Automatic tidy...");    viewing_source = TRUE;       //Stay viewing target!    enclosing_box = do_tidy_cmd ();    block_list_move (&target_block_list, -enclosing_box.botleft ());    command_window->msg ("Writing file...");    pgeditor_write_file(name, &target_block_list);                                 //move back    block_list_move (&target_block_list,      enclosing_box.botleft ());  }  else {    command_window->msg ("Writing file...");    pgeditor_write_file(name, current_block_list);  }  command_window->msg ("Writing file...Done");  *current_image_changed = FALSE;}void smd_cmd() {  char response_str[MAX_CHARS + 1];  WINDOW display_window;         //temp  ICOORD tr, bl;  BOX page_box = block_list_bounding_box (current_block_list);  bl = ICOORD (0, 0);  tr = ICOORD (page_image.get_xsize () + 1, page_image.get_ysize () + 1);  page_box += BOX (bl, tr);  strcpy (response_str, imagebasename.string ());  strcpy (response_str + imagebasename.length (), ".smd.tif");  command_window->prompt ("SMD File Name?", response_str);  display_window = image_win;                                 // xmin  image_win = create_window (response_str, SMDWINDOW, 0, 0, (INT16) (page_box.width () * editor_smd_scale_factor), (INT16) (page_box.height () * editor_smd_scale_factor), 0.0,    page_box.width (),           // xmax    0.0,                         // ymin    page_box.height (),          // ymax    FALSE, FALSE, FALSE, FALSE); //down and up only  do_re_display(&word_display);  destroy_window(image_win);  //Dumps sbd file  image_win = display_window;}/********************************************************************** *  pgeditor_main() * *  Top level editor operation: *  Read events and send them to the appropriate command processor. * **********************************************************************/void pgeditor_main(BLOCK_LIST *blocks) {  GRAPHICS_EVENT event;  INT32 cmd_event = 0;  char new_value[MAX_CHARS + 1];  BOOL8 exit = FALSE;  source_block_list = blocks;  current_block_list = blocks;  if (current_block_list->empty ())    return;  command_window = new COMMAND_WINDOW ("WordEditorCmd", build_menu ());  build_image_window (block_list_bounding_box (source_block_list));  do_re_display(&word_display);  word_display_mode.turn_on_bit (DF_BOX);  while (!exit) {    overlap_picture_ops(TRUE);    await_event (0,              //all windows      TRUE,                      //wait for event      ANY_EVENT, &event);                                 //Command win event    if (event.fd == command_window->window ()) {      command_window->msg ("");  //Clear old message      command_window->event (event, &cmd_event, new_value);      exit = process_cmd_win_event (cmd_event, new_value);    }    else {      if (event.fd == image_win)        process_image_event(event);      else        pgeditor_show_point(&event);    }    current_word_quit.set_value (FALSE);    selection_quit.set_value (FALSE);                                 //replot all var wins    VARIABLES_WINDOW::plot_all();  }}/********************************************************************** * pgeditor_msg() * * Display a message - in the command window if there is one, or to stdout **********************************************************************/void pgeditor_msg(  //message display                  const char *msg) {  if (command_window == NO_WINDOW) {    tprintf(msg);    tprintf ("\n");  }  else    command_window->msg (msg);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -