integer copy_font (integer f) { int i; charinfo *ci , *co; integer k = new_font(); memcpy(font_tables[k],font_tables[f],sizeof(texfont)); set_font_cache_id(k,0); set_font_used(k,0); set_font_touched(k,0); font_tables[k]->_font_name = NULL; font_tables[k]->_font_filename = NULL; font_tables[k]->_font_fullname = NULL; font_tables[k]->_font_encodingname = NULL; font_tables[k]->_font_area = NULL; font_tables[k]->_font_cidregistry = NULL; font_tables[k]->_font_cidordering = NULL; font_tables[k]->_left_boundary = NULL; font_tables[k]->_right_boundary = NULL; set_font_name(k,xstrdup(font_name(f))); if (font_filename(f)!= NULL) set_font_filename(k,xstrdup(font_filename(f))); if (font_fullname(f)!= NULL) set_font_fullname(k,xstrdup(font_fullname(f))); if (font_encodingname(f)!= NULL) set_font_encodingname(k,xstrdup(font_encodingname(f))); if (font_area(f)!= NULL) set_font_area(k,xstrdup(font_area(f))); if (font_cidregistry(f)!= NULL) set_font_cidregistry(k,xstrdup(font_cidregistry(f))); if (font_cidordering(f)!= NULL) set_font_cidordering(k,xstrdup(font_cidordering(f))); i = sizeof(*param_base(f))*font_params(f); font_bytes += i; param_base(k) = xmalloc (i); memcpy(param_base(k),param_base(f), i); i = sizeof(charinfo)*(Charinfo_size(f)+1); font_bytes += i; font_tables[k]->charinfo = xmalloc(i); memset(font_tables[k]->charinfo,0,i); for(i=0;i<=Charinfo_size(k);i++) { ci = copy_charinfo(&font_tables[f]->charinfo[i]); font_tables[k]->charinfo[i] = *ci; } if (left_boundary(f)!= NULL ) { ci = copy_charinfo(left_boundary(f)); set_charinfo(k,left_boundarychar,ci); } if (right_boundary(f)!= NULL ) { ci = copy_charinfo(right_boundary(f)); set_charinfo(k,right_boundarychar,ci); } return k; }
void create_null_font (void) { int i = new_font(); assert(i==0); set_font_name(i,xstrdup("nullfont")); set_font_area(i,xstrdup("")); set_font_touched(i,1); }
void delete_font (integer f) { int i; charinfo *co; assert(f>0); if (font_tables[f]!=NULL) { set_font_name(f,NULL); set_font_filename(f,NULL); set_font_fullname(f,NULL); set_font_encodingname(f,NULL); set_font_area(f,NULL); set_font_cidregistry(f,NULL); set_font_cidordering(f,NULL); set_left_boundary(f,NULL); set_right_boundary(f,NULL); for(i=font_bc(f); i<=font_ec(f); i++) { if (char_exists(f,i)) { co = char_info(f,i); set_charinfo_name(co,NULL); set_charinfo_tounicode(co,NULL); set_charinfo_packets(co,NULL); set_charinfo_ligatures(co,NULL); set_charinfo_kerns(co,NULL); set_charinfo_extensible(co,0,0,0,0); } } /* free .notdef */ set_charinfo_name(font_tables[f]->charinfo+0,NULL); free(font_tables[f]->charinfo); destroy_sa_tree(font_tables[f]->characters); free(param_base(f)); free(font_tables[f]); font_tables[f] = NULL; if (font_id_maxval==f) { font_id_maxval--; } } }
int do_grid_numbers(void) { double g; char num_text[50]; int grid, vy, vx, hy = 0, hx = 0; int first, len, x, y, last_bottom, last_right; int rounded_grid, margin; if (PS.grid <= 0 || PS.grid_numbers <= 0) return 1; grid = PS.grid * PS.grid_numbers; /* round grid to multiple of 10 */ rounded_grid = 1; if (PS.w.proj != PROJECTION_LL) { sprintf(num_text, "%d", PS.grid); len = strlen(num_text); while (len-- && num_text[len] == '0') rounded_grid *= 10; if (rounded_grid == 10) rounded_grid = 1; } /* initialize */ set_font_name(PS.grid_font); set_font_size(PS.grid_fontsize); set_ps_color(&PS.grid_numbers_color); first = 1; /* horizontal grid numbers * these numbers only appear on the left edge of the first panel. * center the numbers on each grid line. * suppress number if it falls off the map or would overlay the previous * label */ margin = (int)(0.2 * (double)PS.grid_fontsize + 0.5); if (margin < 2) margin = 2; fprintf(PS.fp, "/mg %d def\n", margin); g = floor(PS.w.north / grid) * grid; last_bottom = (int)PS.map_top; first = 1; /* x = XCONV(PS.w.west); */ for (; g > PS.w.south; g -= grid) { /*y = YCONV(g); */ G_plot_where_xy(PS.w.west, g, &vx, &vy); x = (double)vx / 10.; y = (double)vy / 10.; if (y + PS.grid_fontsize > last_bottom) continue; if (y - PS.grid_fontsize < (int)PS.map_bot) continue; sprintf(num_text, "%s", format_northing(g, rounded_grid)); text_box_path(x, y, LEFT, CENTER, num_text, PS.grid_fontsize, 0); set_rgb_color(WHITE); fprintf(PS.fp, "F "); set_ps_color(&PS.grid_numbers_color); fprintf(PS.fp, "TIB\n"); last_bottom = y - PS.grid_fontsize; if (first) { first = 0; hy = y + (int)(0.5 * (double)PS.grid_fontsize + 0.5) + margin; hx = x + 0.7 * strlen(num_text) * PS.grid_fontsize + 2 * margin; } } /* vertical grid numbers * center the numbers on each grid line. * suppress number if it falls of the map or would overlay the previous * label */ g = floor(PS.w.west / grid) * grid; last_right = (int)PS.map_left; /* y = YCONV(PS.w.north); */ for (; g < PS.w.east; g += grid) { /* x = XCONV(g); */ G_plot_where_xy(g, PS.w.north, &vx, &vy); x = (double)vx / 10.; y = (double)vy / 10.; if (x - PS.grid_fontsize < last_right) continue; if (x + PS.grid_fontsize > (int)PS.map_right) continue; sprintf(num_text, "%s", format_easting(g, rounded_grid)); vy = y - 0.7 * strlen(num_text) * PS.grid_fontsize - 2 * margin; vx = x - (int)(0.5 * (double)PS.grid_fontsize + 0.5) - margin; if (vx < hx && vy < hy) continue; fprintf(PS.fp, "ZB (%s) PB 90 rotate\n", num_text); fprintf(PS.fp, "%d br sub bl add mg add\n", y); fprintf(PS.fp, "%d bt bb sub D2 add mg sub neg TR TB\n", x); set_rgb_color(WHITE); fprintf(PS.fp, "F "); set_ps_color(&PS.grid_numbers_color); fprintf(PS.fp, "TIB\n"); last_right = x + PS.grid_fontsize; } return 0; }