Merge branch '#145_fix_x_bearing' into develop

This commit is contained in:
Kolan Sh 2017-12-30 16:40:43 +03:00
commit b75386a476
2 changed files with 9 additions and 23 deletions

View File

@ -219,7 +219,7 @@ namespace Gtk.CairoChart {
title_height = sz.height + (legend.position == Legend.Position.TOP ? title_vindent * 2 : title_vindent); title_height = sz.height + (legend.position == Legend.Position.TOP ? title_vindent * 2 : title_vindent);
cur_y_min += title_height; cur_y_min += title_height;
set_source_rgba(title.color); set_source_rgba(title.color);
context.move_to (width/2 - sz.width/2 - sz.x_bearing, sz.height + title_vindent); context.move_to (width/2 - sz.width/2, sz.height + title_vindent);
show_text(title); show_text(title);
} }
@ -380,7 +380,7 @@ namespace Gtk.CairoChart {
var y = legend_y0 + leg_height_sum + max_font_heights[heights_idx]; var y = legend_y0 + leg_height_sum + max_font_heights[heights_idx];
// series title // series title
context.move_to (x + legend_line_length - title_sz.x_bearing, y); context.move_to (x + legend_line_length, y);
set_source_rgba (s.title.color); set_source_rgba (s.title.color);
show_text(s.title); show_text(s.title);
@ -691,7 +691,7 @@ namespace Gtk.CairoChart {
protected virtual double compact_rec_x_pos (Series s, Float128 x, Text text) { protected virtual double compact_rec_x_pos (Series s, Float128 x, Text text) {
var sz = text.size(context); var sz = text.size(context);
return get_scr_x(s, x) - sz.width / 2.0 - sz.x_bearing return get_scr_x(s, x) - sz.width / 2.0
- sz.width * (x - (s.axis_x.zoom_min + s.axis_x.zoom_max) / 2.0) / (s.axis_x.zoom_max - s.axis_x.zoom_min); - sz.width * (x - (s.axis_x.zoom_min + s.axis_x.zoom_max) / 2.0) / (s.axis_x.zoom_max - s.axis_x.zoom_min);
} }
@ -943,7 +943,7 @@ namespace Gtk.CairoChart {
var text_sz = text_t.size(context); var text_sz = text_t.size(context);
switch (s.axis_y.position) { switch (s.axis_y.position) {
case Axis.Position.LOW: case Axis.Position.LOW:
context.move_to (cur_x_min + max_rec_width - text_sz.width + s.axis_y.font_indent - text_sz.x_bearing context.move_to (cur_x_min + max_rec_width - text_sz.width + s.axis_y.font_indent
+ (s.axis_y.title.text == "" ? 0 : sz.width + s.axis_y.font_indent), + (s.axis_y.title.text == "" ? 0 : sz.width + s.axis_y.font_indent),
compact_rec_y_pos (s, y, text_t)); compact_rec_y_pos (s, y, text_t));
show_text(text_t); show_text(text_t);
@ -959,7 +959,7 @@ namespace Gtk.CairoChart {
context.line_to (double.max (x, plot_area_x_min + (plot_area_x_max - plot_area_x_min) * s.place.zoom_x_high), scr_y); context.line_to (double.max (x, plot_area_x_min + (plot_area_x_max - plot_area_x_min) * s.place.zoom_x_high), scr_y);
break; break;
case Axis.Position.HIGH: case Axis.Position.HIGH:
context.move_to (cur_x_max - text_sz.width - s.axis_y.font_indent - text_sz.x_bearing context.move_to (cur_x_max - text_sz.width - s.axis_y.font_indent
- (s.axis_y.title.text == "" ? 0 : sz.width + s.axis_y.font_indent), - (s.axis_y.title.text == "" ? 0 : sz.width + s.axis_y.font_indent),
compact_rec_y_pos (s, y, text_t)); compact_rec_y_pos (s, y, text_t));
show_text(text_t); show_text(text_t);

View File

@ -6,9 +6,7 @@ namespace Gtk.CairoChart {
public Color color = Color(); public Color color = Color();
public Cairo.TextExtents get_extents (Cairo.Context context) { public Cairo.TextExtents get_extents (Cairo.Context context) {
context.select_font_face (style.family, context.select_font_face (style.family, style.slant, style.weight);
style.slant,
style.weight);
context.set_font_size (style.size); context.set_font_size (style.size);
Cairo.TextExtents extents; Cairo.TextExtents extents;
context.text_extents (text, out extents); context.text_extents (text, out extents);
@ -33,19 +31,9 @@ namespace Gtk.CairoChart {
} }
} }
public double get_x_bearing (Cairo.Context context) {
var extents = get_extents (context);
switch (style.orientation) {
case FontOrient.HORIZONTAL: return extents.x_bearing;
case FontOrient.VERTICAL: return extents.y_bearing;
default: return 0.0;
}
}
public struct Size { public struct Size {
double width; double width;
double height; double height;
double x_bearing;
} }
public Size size (Cairo.Context context) { public Size size (Cairo.Context context) {
@ -53,14 +41,12 @@ namespace Gtk.CairoChart {
var extents = get_extents (context); var extents = get_extents (context);
switch (style.orientation) { switch (style.orientation) {
case FontOrient.HORIZONTAL: case FontOrient.HORIZONTAL:
sz.width = extents.width; sz.width = extents.width + extents.x_bearing;
sz.height = extents.height; sz.height = extents.height;
sz.x_bearing = extents.x_bearing;
break; break;
case FontOrient.VERTICAL: case FontOrient.VERTICAL:
sz.width = extents.height; sz.width = extents.height; // + extents.x_bearing ?
sz.height = extents.width; sz.height = extents.width; // +- extents.y_bearing ?
sz.x_bearing = extents.y_bearing;
break; break;
} }
return sz; return sz;