--- trunk/src/osm-gps-map-osd-classic.c 2009/09/08 10:24:11 100 +++ trunk/src/osm-gps-map-osd-classic.c 2009/09/08 19:08:37 102 @@ -736,6 +736,8 @@ return g_strdup_printf("%u km", dist/1000); } +#define OSD_SCALE_FONT_SIZE 12 + static void osd_render_scale(osm_gps_map_osd_t *osd) { @@ -752,56 +754,74 @@ /* determine the size of the scale width in meters */ float width = (OSD_SCALE_W-2) * m_per_pix; - printf("width = %f meters\n", width); - + printf("%d pixels is %f m\n", OSD_SCALE_W-2, width); + /* scale this to useful values */ int exp = logf(width)*M_LOG10E; int mant = width/pow(10,exp); - printf("mant = %d, exp = %d \n", mant, exp); - int width_metric = mant * pow(10,exp); char *dist_str = dist_str_metric(width_metric); width_metric /= m_per_pix; - printf("metric scale width = %d pixels: %s\n", width_metric, dist_str); - int font_size = 12; + /* and now the hard part: scale for useful imperial values :-( */ + /* try to convert to feet, 1ft == 0.3048 m */ + width /= 0.3048; + float imp_scale = 0.3048; + char *dist_imp_unit = "ft"; + + if(width >= 100) { + /* 1yd == 3 feet */ + width /= 3.0; + imp_scale *= 3.0; + dist_imp_unit = "yd"; + + if(width >= 1760.0) { + /* 1mi == 1760 yd */ + width /= 1760.0; + imp_scale *= 1760.0; + dist_imp_unit = "mi"; + } + } + + printf("this is %f %s\n", width, dist_imp_unit); + printf("this is %f pixels\n", width * imp_scale / m_per_pix); cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); - cairo_set_font_size (cr, font_size); + cairo_set_font_size (cr, OSD_SCALE_FONT_SIZE); cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0); cairo_text_extents_t extents; cairo_text_extents (cr, dist_str, &extents); cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); - cairo_move_to (cr, font_size/3, font_size); + cairo_move_to (cr, OSD_SCALE_FONT_SIZE/3, OSD_SCALE_FONT_SIZE); cairo_text_path (cr, dist_str); cairo_set_line_width (cr, 2); cairo_stroke (cr); cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); - cairo_move_to (cr, font_size/3, font_size); + cairo_move_to (cr, OSD_SCALE_FONT_SIZE/3, OSD_SCALE_FONT_SIZE); cairo_show_text (cr, dist_str); /* draw white line */ cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0); cairo_set_line_width (cr, 4); - cairo_move_to (cr, 2, 2*font_size/3); - cairo_rel_line_to (cr, 0, 2*font_size/3); + cairo_move_to (cr, 2, 2*OSD_SCALE_FONT_SIZE/3); + cairo_rel_line_to (cr, 0, 2*OSD_SCALE_FONT_SIZE/3); cairo_rel_line_to (cr, width_metric, 0); - cairo_rel_line_to (cr, 0, -2*font_size/3); + cairo_rel_line_to (cr, 0, -2*OSD_SCALE_FONT_SIZE/3); cairo_stroke(cr); /* draw black line */ cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0); cairo_set_line_width (cr, 2); - cairo_move_to (cr, 2, 2*font_size/3); - cairo_rel_line_to (cr, 0, 2*font_size/3); + cairo_move_to (cr, 2, 2*OSD_SCALE_FONT_SIZE/3); + cairo_rel_line_to (cr, 0, 2*OSD_SCALE_FONT_SIZE/3); cairo_rel_line_to (cr, width_metric, 0); - cairo_rel_line_to (cr, 0, -2*font_size/3); + cairo_rel_line_to (cr, 0, -2*OSD_SCALE_FONT_SIZE/3); cairo_stroke(cr); /* xyz */