2017-08-28 14:47:31 +03:00
|
|
|
namespace Gtk.CairoChart {
|
|
|
|
[Compact]
|
|
|
|
public class Text {
|
|
|
|
public string text = "";
|
|
|
|
public FontStyle style = FontStyle ();
|
|
|
|
public Color color = Color();
|
|
|
|
|
2017-12-25 23:45:02 +03:00
|
|
|
public Cairo.TextExtents get_extents (Cairo.Context context) {
|
2017-08-28 14:47:31 +03:00
|
|
|
context.select_font_face (style.family,
|
|
|
|
style.slant,
|
|
|
|
style.weight);
|
|
|
|
context.set_font_size (style.size);
|
|
|
|
Cairo.TextExtents extents;
|
|
|
|
context.text_extents (text, out extents);
|
|
|
|
return extents;
|
|
|
|
}
|
|
|
|
|
|
|
|
public double get_width (Cairo.Context context) {
|
|
|
|
var extents = get_extents (context);
|
2017-12-25 23:45:02 +03:00
|
|
|
switch (style.orientation) {
|
|
|
|
case FontOrient.HORIZONTAL: return extents.width;
|
|
|
|
case FontOrient.VERTICAL: return extents.height;
|
|
|
|
default: return 0.0;
|
|
|
|
}
|
2017-08-28 14:47:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public double get_height (Cairo.Context context) {
|
|
|
|
var extents = get_extents (context);
|
2017-12-25 23:45:02 +03:00
|
|
|
switch (style.orientation) {
|
|
|
|
case FontOrient.HORIZONTAL: return extents.height;
|
|
|
|
case FontOrient.VERTICAL: return extents.width;
|
|
|
|
default: return 0.0;
|
|
|
|
}
|
2017-08-28 14:47:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public double get_x_bearing (Cairo.Context context) {
|
|
|
|
var extents = get_extents (context);
|
2017-12-25 23:45:02 +03:00
|
|
|
switch (style.orientation) {
|
|
|
|
case FontOrient.HORIZONTAL: return extents.x_bearing;
|
|
|
|
case FontOrient.VERTICAL: return extents.y_bearing;
|
|
|
|
default: return 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public struct Size {
|
|
|
|
double width;
|
|
|
|
double height;
|
|
|
|
double x_bearing;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Size size (Cairo.Context context) {
|
|
|
|
var sz = Size();
|
|
|
|
var extents = get_extents (context);
|
|
|
|
switch (style.orientation) {
|
|
|
|
case FontOrient.HORIZONTAL:
|
|
|
|
sz.width = extents.width;
|
|
|
|
sz.height = extents.height;
|
|
|
|
sz.x_bearing = extents.x_bearing;
|
|
|
|
break;
|
|
|
|
case FontOrient.VERTICAL:
|
|
|
|
sz.width = extents.height;
|
|
|
|
sz.height = extents.width;
|
|
|
|
sz.x_bearing = extents.y_bearing;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return sz;
|
2017-08-28 14:47:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public Text (string text = "",
|
|
|
|
FontStyle style = FontStyle(),
|
|
|
|
Color color = Color()) {
|
|
|
|
this.text = text;
|
|
|
|
this.style = style;
|
|
|
|
this.color = color;
|
|
|
|
}
|
|
|
|
|
2017-08-28 18:16:48 +03:00
|
|
|
public Text copy () {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|