Skip to content

Commit 3e0cc39

Browse files
authored
Merge pull request #30 from drug007/master
Multi line title support added. Implemented by @drug007
2 parents 5deebd8 + 56b5baf commit 3e0cc39

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

source/ggplotd/ggplotd.d

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ alias TitleFunction = Title delegate(Title);
2222
struct Title
2323
{
2424
/// The actual title
25-
string title;
25+
string[] title;
2626
}
2727

2828
/**
@@ -34,6 +34,19 @@ GGPlotD().put( title( "My title" ) );
3434
--------------------
3535
*/
3636
TitleFunction title( string title )
37+
{
38+
return delegate(Title t) { t.title = [title]; return t; };
39+
}
40+
41+
/**
42+
Draw the multiline title
43+
44+
Examples:
45+
--------------------
46+
GGPlotD().put( title( ["My title line1", "line2", "line3"] ) );
47+
--------------------
48+
*/
49+
TitleFunction title( string[] title )
3750
{
3851
return delegate(Title t) { t.title = title; return t; };
3952
}
@@ -87,12 +100,16 @@ private auto drawTitle( in Title title, ref cairo.Surface surface,
87100
auto context = cairo.Context(surface);
88101
context.setFontSize(16.0);
89102
context.moveTo( width/2, margins.top/2 );
90-
auto extents = context.textExtents(title.title);
91-
92-
auto textSize = cairo.Point!double(0.5 * extents.width, 0.5 * extents.height);
93-
context.relMoveTo(-textSize.x, textSize.y);
103+
104+
auto f = context.fontExtents();
105+
foreach(t; title.title)
106+
{
107+
auto e = context.textExtents(t);
108+
context.relMoveTo( -e.width/2, 0 );
109+
context.showText(t);
110+
context.relMoveTo( -e.width/2, f.height );
111+
}
94112

95-
context.showText(title.title);
96113
return surface;
97114
}
98115

0 commit comments

Comments
 (0)