Skip to content

Commit d9eaf88

Browse files
author
bjn
committed
Useful code brought over from the skia branch
1 parent 3ac389e commit d9eaf88

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

lib/include/elements/support/canvas.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ namespace cycfi { namespace elements
168168
float ascent;
169169
float descent;
170170
float height;
171+
float leading;
171172
};
172173

173174
[[deprecated("Use fill_text(utf8, p) instead following artist API.")]]

lib/include/elements/support/color.hpp

+20
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,26 @@ namespace cycfi { namespace elements
100100
return r;
101101
}
102102

103+
constexpr color operator+(color const& a, color const& b)
104+
{
105+
return color(a.red + b.red, a.green + b.green, a.blue + b.blue, a.alpha + b.alpha*(1.0-a.alpha));
106+
}
107+
108+
constexpr color operator-(color const& a, color const& b)
109+
{
110+
return color(a.red - b.red, a.green - b.green, a.blue - b.blue, a.alpha + b.alpha*(1.0-a.alpha));
111+
}
112+
113+
constexpr color operator*(color const& a, float b)
114+
{
115+
return color(a.red * b, a.green * b, a.blue * b, a.alpha);
116+
}
117+
118+
constexpr color operator*(float a, color const& b)
119+
{
120+
return color(a * b.red, a * b.green, a * b.blue, b.alpha);
121+
}
122+
103123
////////////////////////////////////////////////////////////////////////////
104124
// Common colors
105125
////////////////////////////////////////////////////////////////////////////

lib/include/elements/support/rect.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ namespace cycfi { namespace elements
6565
constexpr bool is_valid(rect r);
6666
constexpr bool is_same_size(rect a, rect b);
6767
bool intersects(rect a, rect b);
68+
rect intersection(rect const& a, rect const& b);
6869

6970
constexpr point center_point(rect r);
7071
constexpr float area(rect r);

lib/src/support/canvas.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,13 @@ namespace cycfi { namespace elements
421421
{
422422
cairo_font_extents_t font_extents;
423423
cairo_scaled_font_extents(cairo_get_scaled_font(&_context), &font_extents);
424-
return font_extents;
424+
425+
return {
426+
/*ascent=*/ float(font_extents.ascent),
427+
/*descent=*/ float(font_extents.descent),
428+
/*height=*/ float(font_extents.height),
429+
/*leading=*/ float(font_extents.height-(font_extents.ascent+font_extents.descent))
430+
};
425431
}
426432

427433
void canvas::draw(pixmap const& pm, elements::rect src, elements::rect dest)

lib/src/support/rect.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ namespace cycfi { namespace elements
1818
return true;
1919
}
2020

21+
rect intersection(rect const& a, rect const& b)
22+
{
23+
return {
24+
std::max(a.left, b.left),
25+
std::max(a.top, b.top),
26+
std::min(a.right, b.right),
27+
std::min(a.bottom, b.bottom)
28+
};
29+
}
30+
2131
rect max(rect a, rect b)
2232
{
2333
return {

0 commit comments

Comments
 (0)