aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/GraphicObjects/TextRun.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/GraphicObjects/TextRun.cs')
-rw-r--r--src/GraphicObjects/TextRun.cs39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/GraphicObjects/TextRun.cs b/src/GraphicObjects/TextRun.cs
index a426bdee..bb308eb6 100644
--- a/src/GraphicObjects/TextRun.cs
+++ b/src/GraphicObjects/TextRun.cs
@@ -144,13 +144,11 @@ namespace Crow
set { base.Margin = value; }
}
- protected override Size measureRawSize()
- {
- Size size;
-
+ protected override int measureRawSize(LayoutingType lt)
+ {
if (lines == null)
lines = getLines;
-
+
using (ImageSurface img = new ImageSurface (Format.Argb32, 10, 10)) {
using (Context gr = new Context (img)) {
//Cairo.FontFace cf = gr.GetContextFontFace ();
@@ -158,30 +156,34 @@ namespace Crow
gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
gr.SetFontSize (Font.Size);
+
+ fe = gr.FontExtents;
te = new TextExtents();
+ if (lt == LayoutingType.Height){
+ int lc = lines.Count;
+ //ensure minimal height = text line height
+ if (lc == 0)
+ lc = 1;
+
+ return (int)(fe.Height * lc) + Margin * 2;
+ }
+
foreach (string s in lines) {
string l = s.Replace("\t", new String (' ', Interface.TabSize));
-#if _WIN32 || _WIN64
+ #if _WIN32 || _WIN64
TextExtents tmp = gr.TextExtents(str.ToUtf8());
-#elif __linux__
+ #elif __linux__
TextExtents tmp = gr.TextExtents (l);
-#endif
+ #endif
if (tmp.XAdvance > te.XAdvance)
te = tmp;
}
- fe = gr.FontExtents;
- int lc = lines.Count;
- //ensure minimal height = text line height
- if (lc == 0)
- lc = 1;
- size = new Size ((int)Math.Ceiling (te.XAdvance) + Margin * 2, (int)(fe.Height * lc) + Margin*2);
+ return (int)Math.Ceiling (te.XAdvance) + Margin * 2;
}
}
-
- return size;;
- }
+ }
protected override void onDraw (Context gr)
{
base.onDraw (gr);
@@ -193,7 +195,8 @@ namespace Crow
//gr.FontOptions.Antialias = Antialias.Subpixel;
//gr.FontOptions.HintMetrics = HintMetrics.On;
- rText = new Rectangle(measureRawSize());
+ rText = new Rectangle(new Size(
+ measureRawSize(LayoutingType.Width), measureRawSize(LayoutingType.Height)));
rText.Width -= 2 * Margin;
rText.Height -= 2 * Margin;