2018-01-08 23:33:13 +03:00
|
|
|
namespace CairoChart {
|
2017-08-28 14:47:31 +03:00
|
|
|
public class Text {
|
|
|
|
public string text = "";
|
2018-01-08 23:33:13 +03:00
|
|
|
public Font.Style style = Font.Style ();
|
2017-08-28 14:47:31 +03:00
|
|
|
public Color color = Color();
|
|
|
|
|
2018-01-15 12:05:21 +03:00
|
|
|
public virtual Cairo.TextExtents get_extents (Cairo.Context context) {
|
2017-12-30 09:16:28 +03:00
|
|
|
context.select_font_face (style.family, style.slant, style.weight);
|
2017-08-28 14:47:31 +03:00
|
|
|
context.set_font_size (style.size);
|
|
|
|
Cairo.TextExtents extents;
|
|
|
|
context.text_extents (text, out extents);
|
|
|
|
return extents;
|
|
|
|
}
|
|
|
|
|
2018-01-15 12:05:21 +03:00
|
|
|
public virtual double get_width (Cairo.Context context) {
|
2017-08-28 14:47:31 +03:00
|
|
|
var extents = get_extents (context);
|
2017-12-25 23:45:02 +03:00
|
|
|
switch (style.orientation) {
|
2018-01-08 23:33:13 +03:00
|
|
|
case Font.Orientation.HORIZONTAL: return extents.width;
|
|
|
|
case Font.Orientation.VERTICAL: return extents.height;
|
2017-12-25 23:45:02 +03:00
|
|
|
default: return 0.0;
|
|
|
|
}
|
2017-08-28 14:47:31 +03:00
|
|
|
}
|
|
|
|
|
2018-01-15 12:05:21 +03:00
|
|
|
public virtual double get_height (Cairo.Context context) {
|
2017-08-28 14:47:31 +03:00
|
|
|
var extents = get_extents (context);
|
2017-12-25 23:45:02 +03:00
|
|
|
switch (style.orientation) {
|
2018-01-08 23:33:13 +03:00
|
|
|
case Font.Orientation.HORIZONTAL: return extents.height;
|
|
|
|
case Font.Orientation.VERTICAL: return extents.width;
|
2017-12-25 23:45:02 +03:00
|
|
|
default: return 0.0;
|
|
|
|
}
|
2017-08-28 14:47:31 +03:00
|
|
|
}
|
|
|
|
|
2017-12-25 23:45:02 +03:00
|
|
|
public struct Size {
|
|
|
|
double width;
|
|
|
|
double height;
|
|
|
|
}
|
|
|
|
|
2018-01-15 12:05:21 +03:00
|
|
|
public virtual Size get_size (Cairo.Context context) {
|
2017-12-25 23:45:02 +03:00
|
|
|
var sz = Size();
|
|
|
|
var extents = get_extents (context);
|
|
|
|
switch (style.orientation) {
|
2018-01-08 23:33:13 +03:00
|
|
|
case Font.Orientation.HORIZONTAL:
|
2017-12-30 09:16:28 +03:00
|
|
|
sz.width = extents.width + extents.x_bearing;
|
2017-12-25 23:45:02 +03:00
|
|
|
sz.height = extents.height;
|
|
|
|
break;
|
2018-01-08 23:33:13 +03:00
|
|
|
case Font.Orientation.VERTICAL:
|
2017-12-30 09:16:28 +03:00
|
|
|
sz.width = extents.height; // + extents.x_bearing ?
|
|
|
|
sz.height = extents.width; // +- extents.y_bearing ?
|
2017-12-25 23:45:02 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return sz;
|
2017-08-28 14:47:31 +03:00
|
|
|
}
|
|
|
|
|
2018-01-15 12:05:21 +03:00
|
|
|
public virtual void show (Cairo.Context context) {
|
2018-01-10 11:02:47 +03:00
|
|
|
context.select_font_face(style.family,
|
|
|
|
style.slant,
|
|
|
|
style.weight);
|
|
|
|
context.set_font_size(style.size);
|
|
|
|
if (style.orientation == Font.Orientation.VERTICAL) {
|
2018-01-10 15:20:44 +03:00
|
|
|
context.rotate(- GLib.Math.PI / 2.0);
|
2018-01-10 11:02:47 +03:00
|
|
|
context.show_text(text);
|
2018-01-10 15:20:44 +03:00
|
|
|
context.rotate(GLib.Math.PI / 2.0);
|
2018-01-10 11:02:47 +03:00
|
|
|
} else {
|
|
|
|
context.show_text(text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-28 14:47:31 +03:00
|
|
|
public Text (string text = "",
|
2018-01-08 23:33:13 +03:00
|
|
|
Font.Style style = Font.Style(),
|
2017-08-28 14:47:31 +03:00
|
|
|
Color color = Color()) {
|
|
|
|
this.text = text;
|
|
|
|
this.style = style;
|
|
|
|
this.color = color;
|
|
|
|
}
|
|
|
|
|
2018-01-15 12:05:21 +03:00
|
|
|
public virtual Text copy () {
|
2017-08-28 18:16:48 +03:00
|
|
|
var text = new Text ();
|
|
|
|
text.text = this.text;
|
|
|
|
text.style = this.style;
|
|
|
|
text.color = this.color;
|
|
|
|
return text;
|
2017-08-28 14:47:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|