void graph::close_graph() { get_map()->destroy_map(); close_resource(); close_font(); }
void Disp_FileNotFound() { /* 显示“文件未找到”消息(界面绘制) */ //MsgBoxPush(4); beg: font16 = open_font("\\\\fls0\\24PX.hzk"); select_font(font16); ClearArea(35, 45, 349, 141); print_chs_2(94, 71, 0,"文件未找到"); print_chs_2(94, 119, 0, "按"); locate_OS(8, 5); Print_OS(":[EXIT]", 0, 0); close_font(font16); while (1) { int key; GetKey(&key); switch (key) { case KEY_CTRL_EXIT: //MsgBoxPop(); return; break; } } }
u8 LCD_SetFont(unsigned int idx) { u8 old = LCD_GetFont(); if (old == idx) return old; if (idx == 0) { close_font(); cur_str.font_idx = 0; return 0; } else if (! open_font(FontNames[idx - 1])){ if (old == 0) close_font(); else open_font(FontNames[old - 1]); } else cur_str.font_idx = idx; return old; }
void exit_command (Widget w, XtPointer client_data, XtPointer call_data) { string font_name = client_data; close_font (font_name); if (true_gf_output_name != NULL) xrename (gf_output_name, true_gf_output_name); if (true_tfm_output_name != NULL) xrename (tfm_output_name, true_tfm_output_name); exit (0); }
u8 open_font(unsigned int idx) { char font[20]; close_font(); if (! idx) { cur_str.font.idx = 0; return 1; } sprintf(font, "media/%s.fon", FontNames[idx-1]); finit(&FontFAT, "media"); cur_str.font.fh = fopen2(&FontFAT, font, "rb"); if (! cur_str.font.fh) { printf("Couldn't open font file: %s\n", font); return 0; } setbuf(cur_str.font.fh, 0); if(fread(&cur_str.font.height, 1, 1, cur_str.font.fh) != 1) { printf("Failed to read height from font\n"); fclose(cur_str.font.fh); cur_str.font.fh = NULL; return 0; } cur_str.font.idx = idx; idx = 0; u8 *f = (u8 *)font; while(1) { if (fread(f, 4, 1, cur_str.font.fh) != 1) { printf("Failed to parse font range table\n"); fclose(cur_str.font.fh); cur_str.font.fh = NULL; return 0; } u16 start_c = f[0] | (f[1] << 8); u16 end_c = f[2] | (f[3] << 8); cur_str.font.range[idx++] = start_c; cur_str.font.range[idx++] = end_c; if (start_c == 0 && end_c == 0) break; } return 1; }
void Disp_About() { /* 显示关于信息(界面绘制) */ beg: font16 = open_font("\\\\fls0\\24PX.hzk"); select_font(font16); MsgBoxPush(5); ClearArea(35,45,349,166); locate_OS(3,2); Print_OS("iBooks Pro C",0,0); print_chs_2(38, 71, 0, "版本 "); locate_OS(7, 3); Print_OS("1.50", 0, 0); print_chs_2(38, 95, 0, "制作:清水视野工作室"); print_chs_2(38, 119, 0, "本程序依"); locate_OS(10, 5); Print_OS("GNU GPL v3",0,0); print_chs_2(38, 143, 0, "协议开放源代码。"); close_font(font16); while (1) { int key; GetKey(&key); switch (key) { case KEY_CTRL_EXIT: MsgBoxPop(); return;break; } } }
void Confirm_AllDivide(const char* fn) { /* 尝试全部分页(界面绘制) 参数说明: fn: 当前打开文件的文件名 */ beg: font16 = open_font("\\\\fls0\\24PX.hzk"); select_font(font16); ClearArea(35,45,349,166); print_chs_2(38,47,0,"尝试全部分页可能需要"); print_chs_2(38,71,0,"很长时间。"); print_chs_2(38,95,0,"确定继续?"); locate_OS(6,5); Print_OS("[F1]:",0,0);print_chs_2(181,119,0,"是"); locate_OS(6,6); Print_OS("[F6]:",0,0);print_chs_2(181,143,0,"否"); close_font(font16); while (1) { int key; GetKey(&key); switch (key) { case KEY_CTRL_F1: divide_page(fn,9999-cached,0); // 尝试分到 9999 页 return;break; case KEY_CTRL_F6: return;break; } } }
QEFont *select_font(QEditScreen *s, int style, int size) { QEFont *fc; int i, min_ts, min_index; min_ts = MAXINT; min_index = 0; for(i=0;i<FONT_CACHE_SIZE;i++) { fc = font_cache[i]; if (fc) { if (fc->style == style && fc->size == size) { fc->timestamp = font_cache_timestamp; goto the_end; } if (fc->timestamp < min_ts) { min_ts = fc->timestamp; min_index = i; } } else { min_ts = 0; min_index = i; } } /* not found : open new font */ if (font_cache[min_index]) close_font(s, font_cache[min_index]); fc = open_font(s, style, size); if (!fc) return NULL; fc->style = style; fc->size = size; fc->timestamp = font_cache_timestamp; font_cache[min_index] = fc; the_end: font_cache_timestamp++; return fc; }
void browse_main() { /* 文件浏览器主函数 */ char ncat[64], workdir[64] = "\\\\fls0"; // 当前目录 f_name *a=get_file_list("\\\\fls0\\*.*"); // 存储文件列表的二维数组 int pos=0,firstn=0; // 列表光标位置、列表下移的行数 unsigned int key; char subdir_fn[32]; // 供接收子目录文件名输入的缓冲区 FONTCHARACTER fname[64]; int handle = 0; DefineStatusAreaFlags(3, 0x01 | 0x02 | 0x100, 0, 0); beg: if (a) qsort(a, getn(a), sizeof(char *), cmp); font16 = open_font("\\\\fls0\\24PX.hzk"); select_font(font16); draw_browser(workdir,firstn,pos,a); // 绘制浏览器界面 close_font(font16); // 显示当前工作目录于状态栏 if (strcmp(workdir, "\\\\fls0") == 0) DefineStatusMessage("", 0, 0, 0); else { memset(ncat, 0, sizeof(ncat)); GetDisplayDirName(workdir, ncat); DefineStatusMessage(ncat, 0, 0, 0); } while (1) { GetKey(&key); switch (key) { case KEY_CTRL_UP: // 光标上移 if (a) { aa(&pos,&firstn,getn(a)); goto beg; } break; case KEY_CTRL_DOWN: // 光标下移 if (a) { bb(&pos,&firstn,getn(a)); goto beg; } break; case KEY_CTRL_F6: // 显示关于信息 Disp_About(); goto beg; break; case KEY_CTRL_F1: // 打开光标位置的文件 case KEY_CTRL_EXE: if (a) // 如果文件列表不为空 { if (strchr(a[pos+firstn].name,'[')) // 如果打开的是文件夹 { memset(ncat,0,sizeof(ncat)); //strcat(ncat,"\\\\fls0\\"); strcat(ncat, workdir); strcat(ncat, "\\"); strcat(ncat, ++a[pos+firstn].name); memset(workdir, 0, sizeof(workdir)); strcpy(workdir, ncat); strcat(ncat, "\\*.*"); // 解析出文件夹名称 a=get_file_list(ncat); // 浏览该文件夹 pos=0; firstn=0; // 列表初始化 goto beg; } else // 如果打开的是文本文件 { memset(ncat,0,sizeof(ncat)); strcpy(ncat,workdir); strcat(ncat,"\\"); strcat(ncat,a[pos+firstn].name); // 解析出文件名称 iRead_main(ncat); // 启动阅读器 goto beg; } } break; case KEY_CTRL_F2: // 根据输入的文件名打开文件 memset(subdir_fn, 0, sizeof(subdir_fn)); if (Subdir_Open(subdir_fn)) { memset(ncat, 0, sizeof(ncat)); strcpy(ncat, workdir); strcat(ncat, "\\"); strcat(ncat, subdir_fn); // 连接上输入的文件名字 strcat(ncat, ".txt"); char_to_font(ncat, fname); handle = Bfile_OpenFile_OS(fname,0); if (handle <= 0) // 如果文件未找到 { Disp_FileNotFound(); MsgBoxPop(); goto beg; break; } MsgBoxPop(); Bfile_CloseFile_OS(handle); // 重新绘制浏览器界面 font16 = open_font("\\\\fls0\\24PX.hzk"); select_font(font16); draw_browser(workdir, firstn, pos, a); close_font(font16); // 启动阅读器 iRead_main(ncat); } goto beg; break; case KEY_CTRL_EXIT: // 从文件夹返回根目录 if (strcmp(workdir,"\\\\fls0")!=0) // 如果当前在文件夹内 { memset(ncat,0,sizeof(ncat)); strncpy(ncat,workdir,strlen(workdir)-strlen(strrchr(workdir,'\\'))); memset(workdir,0,sizeof(workdir)); strcpy(workdir,ncat); strcat(ncat,"\\*.*"); // 解析出上一级目录的名称 a=get_file_list(ncat); // 浏览该文件夹 pos=0;firstn=0; // 初始化列表 goto beg; } break; } } }
void iRead_main(const char* filename) { /* 阅读界面主函数 参数说明: filename: 打开的文件名 (从文件浏览器得到) */ int key,handle; char* buf=(char*)malloc(461); FONTCHARACTER fname[64]; char tip[64], tmp[64]; page=0;cached=0; memset(bytes,0,sizeof(bytes)); memset(bookmark,0,sizeof(bookmark));bookmark[3]=0; Read_Config(filename,&cached); // 读取书签及分页配置 // 如果分的页数不满 500 的整数倍,补分页满 if (cached==0) divide_page(filename,500-cached,1); else if (cached%500!=0) divide_page(filename,500-cached%500,1); // 补至 500 的整数倍 totbytes=0; /* 设置状态栏显示文字 0x0001:显示电量 0x0100:显示文字 */ DefineStatusAreaFlags(3, 0x01 | 0x02 | 0x100, 0, 0); beg: font16=open_font("\\\\fls0\\24PX.hzk"); select_font(font16); Bdisp_AllClr_VRAM(); draw_pic(0,192,124,22,0,Menu_Read); draw_pic(126,192,61,22,0,Menu_Sub_Jump); // 若翻下一页时超出已缓存页面范围 if (cached<=page) { // 如果分的页数不满 500 的整数倍,补分页满 if (!divide_page(filename,1,0)) page=cached-1; else if (cached%500!=0) divide_page(filename,500-cached%500,0); close_font(font16); goto beg; } totbytes=bytes[page]; // 修正读取字节指针位置 char_to_font(filename,fname); handle=Bfile_OpenFile_OS(fname,0); // 打开文件 Bfile_ReadFile_OS(handle,buf,400,totbytes); Bfile_CloseFile_OS(handle); print_chs_page(0,24,totbytes,(unsigned char*)buf); // 绘制一页 close_font(font16); // 准备显示浏览进度 char fn_ptr[64]; memset(fn_ptr, 0, sizeof(fn_ptr)); GetDisplayFileName(filename, fn_ptr); memset(tip, 0, sizeof(tip)); memset(tmp, 0, sizeof(tmp)); strcat(tip, fn_ptr); strcat(tip, " "); itoa(page + 1, tmp, 10); strcat(tip, tmp); strcat(tip, "/"); memset(tmp, 0, sizeof(tmp)); itoa(cached, tmp, 10);strcat(tip, tmp); // 状态栏显示文件名及进度 DefineStatusMessage(tip, 0, 0, 0); while (1) { GetKey(&key); switch (key) { case KEY_CTRL_UP: // 跳到上一页 if (page>0) { --page; goto beg; } break; case KEY_CTRL_DOWN: // 跳到下一页 ++page; goto beg; break; case KEY_CTRL_EXIT: // 离开,返回文件浏览器 Save_Config(filename,cached+1); DefineStatusAreaFlags(3, 0x01 | 0x02 | 0x100, 0, 0); return;break; case KEY_CTRL_F2: // 打开存储书签对话框 Save_Bookmark(filename,page,cached+1); goto beg;break; case KEY_CTRL_F1: // 打开读取书签对话框 Read_Bookmark(filename,&page,&cached); goto beg;break; case KEY_CTRL_F3: // 打开跳页对话框 Page_Jump(filename); goto beg;break; } } }
int Subdir_Open(const char* fn) { /* 子目录文件名输入(界面绘制) 参数说明: fn: 接收从键盘输入文件名的缓冲区 */ FONTCHARACTER fname[64]; char keybuff[32]; // 接受文件名的字符缓冲区 int inspos = 0; memset(keybuff, 0, sizeof(keybuff)); MsgBoxPush(4); beg: font16 = open_font("\\\\fls0\\24PX.hzk"); select_font(font16); ClearArea(0, 192, 384, 216); draw_pic(0, 192, 61, 22, 0, Menu_Sub_Jump); ClearArea(35, 45, 349, 141); print_chs_2(38, 71, 0, "输入欲打开的文件名:"); locate_OS(3, 4); Print_OS("[ ].txt", 0, 0); locate_OS(4, 4); Print_OS(keybuff, 0, 0); close_font(font16); while (1) { int key; GetKey(&key); switch (key) { case KEY_CTRL_EXIT: MsgBoxPop(); return 0; break; case KEY_CTRL_DEL: if (inspos > 0) { keybuff[--inspos] = 0; // 最后一个字节置为 NULL,标识已删除 goto beg; } break; case KEY_CTRL_F1: case KEY_CTRL_EXE: strcpy(fn, keybuff); //MsgBoxPop(); return 1; break; default: if (key >= 0x30 && key <= 0x39 || key >= 0x41 && key <= 0x5A || key >= 0x61 && key <= 0x7A) // 输入数字 0~9 或英文字母 a-z、A-Z { if (inspos <= 8) { keybuff[inspos++] = key; // 最后一个字节添加输入 goto beg; } } } } }
void Page_Jump(const char* fn) { /* 跳页(界面绘制) 参数说明: fn: 当前打开文件的文件名 */ FONTCHARACTER fname[64]; char tip[64],tmp[64]; char keybuff[32]; // 接受页码的字符缓冲区 int inspos=0,target; memset(keybuff, 0, sizeof(keybuff)); MsgBoxPush(5); beg: font16 = open_font("\\\\fls0\\24PX.hzk"); select_font(font16); ClearArea(0,192,384,216); draw_pic(0,192,61,22,0,Menu_Sub_Jump); draw_pic(63,192,61,22,0,Menu_Jump); ClearArea(35,45,349,166); print_chs_2(38,47,0,"当前页/已缓存页数:"); locate_OS(3,3); memset(tmp,0,sizeof(tmp));memset(tip,0,sizeof(tip)); itoa(page+1,tmp,10);strcat(tip,tmp); strcat(tip,"/");memset(tmp,0,sizeof(tmp)); itoa(cached,tmp,10);strcat(tip,tmp); Print_OS(tip,0,0); print_chs_2(38,119,0,"输入目标页码:"); locate_OS(3,6); Print_OS("[ ]",0,0); locate_OS(4,6); Print_OS(keybuff,0,0); close_font(font16); while (1) { int key; GetKey(&key); switch (key) { case KEY_CTRL_EXIT: MsgBoxPop(); return;break; case KEY_CTRL_F2: Confirm_AllDivide(fn); // 尝试全部分页 goto beg;break; case KEY_CTRL_DEL: if (inspos>0) { keybuff[--inspos]=0; // 最后一个字节置为 NULL,标识已删除 goto beg; } break; case KEY_CTRL_F1: case KEY_CTRL_EXE: if (inspos==0) break; target=atoi(keybuff); if (target>cached) // 如果目标位置超出已缓存页面数,尝试分页 { if (!divide_page(fn, target-cached, 1)) page = cached - 1; // 若分页已达文件末尾,则将当前页面修正到最后一页 else page=target-1; // 否则修正当前页面为输入的目标位置 } else page=target-1; // 修正当前页面为输入的目标位置 MsgBoxPop(); return;break; default: if (key>=0x30&&key<=0x39) // 输入数字 0~9 { if (inspos<=3) { if (key==0x30&&inspos==0) break; // 尝试第一位输入 0 时跳出 keybuff[inspos++]=key; // 最后一个字节添加输入 goto beg; } } } } }
void Read_Bookmark(const char* fn,int* pages,int* n) { /* 读取书签(界面绘制) 参数说明: fn: 当前打开文件的文件名 pages: 接受当前所在页码的缓冲区 n: 接受已缓存页面数的缓冲区 */ int handle,_n=0,_page=*pages; int i,sel=0; FONTCHARACTER fname[64]; char tip[64],tmp[64]; MsgBoxPush(5); beg: font16 = open_font("\\\\fls0\\24PX.hzk"); select_font(font16); ClearArea(0,192,384,216); draw_pic(0,192,61,22,0,Menu_ReadB); ClearArea(35,49,349,166); print_chs_2(38,47,0,"读取书签"); close_font(font16); for (i=0;i<4;++i) { memset(tmp,0,sizeof(tmp));memset(tip,0,sizeof(tip)); strcat(tip,"["); itoa(i+1,tmp,10);strcat(tip,tmp); strcat(tip,"]"); if (bookmark[i]) { strcat(tip," Page "); memset(tmp,0,sizeof(tmp)); itoa(bookmark[i],tmp,10);strcat(tip,tmp); } else strcat(tip," Empty"); locate_OS(3,3+i); Print_OS(tip,0,0); } Bdisp_AreaReverseVRAM(35,72+sel*24,349,94+sel*24); while (1) { int key; GetKey(&key); switch (key) { case KEY_CTRL_UP: if (sel>0) --sel; goto beg;break; case KEY_CTRL_DOWN: if (sel<3) ++sel; goto beg;break; case KEY_CTRL_EXE: if (bookmark[sel]) { *pages=bookmark[sel]-1; // 读取书签 MsgBoxPop(); return; } else goto beg;break; case KEY_CTRL_F1: case KEY_CTRL_EXIT: *pages=_page; MsgBoxPop(); return;break; } } }
void Save_Bookmark(const char* fn,unsigned int pages,int n) { /* 存储书签(界面绘制) 参数说明: fn: 当前打开文件的文件名 pages: 当前所在页码 n: 已缓存页面数 */ int handle,size,i=0; int sel=0,flag; char tip[64],tmp[64]; MsgBoxPush(5); beg: flag=0; font16 = open_font("\\\\fls0\\24PX.hzk"); select_font(font16); ClearArea(0,192,384,216); draw_pic(0,192,124,22,0,Menu_PutB); ClearArea(35,49,349,166); print_chs_2(38,47,0,"存储书签"); close_font(font16); for (i=0;i<4;++i) { memset(tmp,0,sizeof(tmp));memset(tip,0,sizeof(tip)); strcat(tip,"["); itoa(i+1,tmp,10);strcat(tip,tmp); strcat(tip,"]"); if (bookmark[i]) { strcat(tip," Page "); memset(tmp,0,sizeof(tmp)); itoa(bookmark[i],tmp,10);strcat(tip,tmp); } else strcat(tip," Empty"); locate_OS(3,3+i); Print_OS(tip,0,0); } Bdisp_AreaReverseVRAM(35,72+sel*24,349,94+sel*24); while (1) { int key; GetKey(&key); switch (key) { case KEY_CTRL_UP: if (sel>0) --sel; goto beg;break; case KEY_CTRL_DOWN: if (sel<3) ++sel; goto beg;break; case KEY_CTRL_F1: case KEY_CTRL_EXE: bookmark[sel]=pages+1; // 存储书签 goto prg;break; case KEY_CTRL_F2: case KEY_CTRL_DEL: bookmark[sel]=0;flag=1;goto prg;break; // 删除书签 case KEY_CTRL_EXIT: MsgBoxPop(); return; } } prg: Save_Config(fn,n); if (flag) goto beg; MsgBoxPop(); }
void main (int argc, string argv[]) { int code; string font_name = read_command_line (argc, argv); bitmap_font_type f = get_bitmap_font (font_name, atou (dpi)); string font_basename = basename (font_name); /* Initializing the display might involve forking a process. We wouldn't want that process to get copies of open output files, since then when it exited, random stuff might get written to the end of the file. */ init_display (f); if (logging) log_file = xfopen (concat (font_basename, ".log"), "w"); if (strlen (BITMAP_FONT_COMMENT (f)) > 0) REPORT1 ("{%s}\n", BITMAP_FONT_COMMENT (f)); if (output_name == NULL) output_name = font_basename; bzr_start_output (output_name, f); /* The main loop: for each character, find the outline of the shape, then fit the splines to it. */ for (code = starting_char; code <= ending_char; code++) { pixel_outline_list_type pixels; spline_list_array_type splines; char_info_type *c = get_char (font_name, code); if (c == NULL) continue; REPORT1 ("[%u ", code); if (logging) { LOG ("\n\n\f"); print_char (log_file, *c); } x_start_char (*c); pixels = find_outline_pixels (*c); /* `find_outline_pixels' uses corners as the coordinates, instead of the pixel centers. So we have to increase the bounding box. */ CHAR_MIN_COL (*c)--; CHAR_MAX_COL (*c)++; CHAR_MIN_ROW (*c)--; CHAR_MAX_ROW (*c)++; REPORT ("|"); splines = fitted_splines (pixels); bzr_output_char (*c, splines); /* Flush output before displaying the character, in case the user is interested in looking at it and the online version simultaneously. */ flush_log_output (); x_output_char (*c, splines); REPORT ("]\n"); /* If the character was empty, it won't have a bitmap. */ if (BITMAP_BITS (CHAR_BITMAP (*c)) != NULL) free_bitmap (&CHAR_BITMAP (*c)); free_pixel_outline_list (&pixels); free_spline_list_array (&splines); } bzr_finish_output (); close_display (); close_font (font_name); exit (0); }