From 1d4cca886d224182142589778f5c74299c8b19f7 Mon Sep 17 00:00:00 2001 From: Nelson Carrillo Date: Sat, 25 Jul 2015 23:39:17 -0400 Subject: [PATCH] Implemented text selection and temporarily worked around text scaling --- Cairo/Perspex.Cairo/Media/DrawingContext.cs | 8 ++++---- .../Perspex.Cairo/Media/FormattedTextImpl.cs | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Cairo/Perspex.Cairo/Media/DrawingContext.cs b/Cairo/Perspex.Cairo/Media/DrawingContext.cs index a0ddc58856..d5838ba962 100644 --- a/Cairo/Perspex.Cairo/Media/DrawingContext.cs +++ b/Cairo/Perspex.Cairo/Media/DrawingContext.cs @@ -51,7 +51,7 @@ namespace Perspex.Cairo.Media this.Drawable = drawable; this.context = Gdk.CairoHelper.Create(drawable); this.CurrentTransform = Matrix.Identity; - } + } public Matrix CurrentTransform { @@ -175,7 +175,7 @@ namespace Perspex.Cairo.Media /// /// The pen. /// The rectangle bounds. - public void DrawRectange(Pen pen, Rect rect) + public void DrawRectange(Pen pen, Rect rect, float cornerRadius) { this.SetPen(pen); this.context.Rectangle(rect.ToCairo()); @@ -192,7 +192,7 @@ namespace Perspex.Cairo.Media { var layout = ((FormattedTextImpl)text.PlatformImpl).Layout; this.SetBrush(foreground); - + this.context.MoveTo(origin.X, origin.Y); Pango.CairoHelper.ShowLayout(this.context, layout); } @@ -202,7 +202,7 @@ namespace Perspex.Cairo.Media /// /// The brush. /// The rectangle bounds. - public void FillRectange(Perspex.Media.Brush brush, Rect rect) + public void FillRectange(Perspex.Media.Brush brush, Rect rect, float cornerRadius) { this.SetBrush(brush); this.context.Rectangle(rect.ToCairo()); diff --git a/Cairo/Perspex.Cairo/Media/FormattedTextImpl.cs b/Cairo/Perspex.Cairo/Media/FormattedTextImpl.cs index 2925b2e741..b602f1abf3 100644 --- a/Cairo/Perspex.Cairo/Media/FormattedTextImpl.cs +++ b/Cairo/Perspex.Cairo/Media/FormattedTextImpl.cs @@ -29,11 +29,11 @@ namespace Perspex.Cairo.Media this.Layout.FontDescription = new Pango.FontDescription { Family = fontFamily, - Size = Pango.Units.FromDouble(fontSize), + Size = Pango.Units.FromDouble(fontSize * 0.73), Style = (Pango.Style)fontStyle, Weight = fontWeight.ToCairo() }; - + this.Layout.Alignment = textAlignment.ToCairo(); } @@ -92,8 +92,14 @@ namespace Perspex.Cairo.Media public IEnumerable HitTestTextRange(int index, int length, Point origin) { - // TODO: Implement. - return new Rect[0]; + var ranges = new List(); + + for (var i = 0; i < length; i++) + { + ranges.Add(this.HitTestTextPosition(index+i)); + } + + return ranges; } public Size Measure() @@ -102,11 +108,6 @@ namespace Perspex.Cairo.Media int height; this.Layout.GetPixelSize(out width, out height); - if (this.Layout.Alignment == Pango.Alignment.Right) - { - return new Size(width, height); - } - return new Size(width, height); }