aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/GraphicObjects/Label.cs
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2016-02-17 00:53:59 +0100
committerjpbruyere <jp.bruyere@hotmail.com>2016-02-17 00:53:59 +0100
commita8a5562df0358b314197f3685fc7622ecfd307d0 (patch)
tree02cdd70b6b0f999dd2a2eab7bf8018da03ffdd9f /src/GraphicObjects/Label.cs
parent61d1d07d37a5cc9d6ae1c4fcc333ec8ae644aca3 (diff)
splitted measure with fault checking, changing default template sizing to 0, lots of bugs.
Diffstat (limited to 'src/GraphicObjects/Label.cs')
-rw-r--r--src/GraphicObjects/Label.cs31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/GraphicObjects/Label.cs b/src/GraphicObjects/Label.cs
index 4c7e7006..dd5b89e2 100644
--- a/src/GraphicObjects/Label.cs
+++ b/src/GraphicObjects/Label.cs
@@ -319,13 +319,11 @@ namespace Crow
set { base.Height = 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 ();
@@ -333,8 +331,19 @@ 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));
@@ -346,16 +355,9 @@ namespace Crow
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)
{
@@ -368,7 +370,8 @@ namespace Crow
//gr.FontOptions.Antialias = Antialias.Subpixel;
//gr.FontOptions.HintMetrics = HintMetrics.On;
- rText = new Rectangle(measureRawSize());
+ rText = new Rectangle(
+ measureRawSize(LayoutingType.Width), measureRawSize(LayoutingType.Height));
rText.Width -= 2 * Margin;
rText.Height -= 2 * Margin;