diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2016-02-17 08:44:34 +0100 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2016-02-17 08:44:34 +0100 |
| commit | a8156b149f2e4a3c087bcb090db293d08116bd67 (patch) | |
| tree | 51dd4165422863f70c656de8e0bbfa7c079142bb /src/GraphicObjects/TextRun.cs | |
| parent | 3c1dbdbbc58d38d45276e3147c3717d19a69adf2 (diff) | |
| parent | bf27b88a6cbfcc65d7ed6360f9193d52f96b1598 (diff) | |
Merge branch 'DefTemplateSizing0'
Diffstat (limited to 'src/GraphicObjects/TextRun.cs')
| -rw-r--r-- | src/GraphicObjects/TextRun.cs | 39 |
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; |