From 74b16404603534162cc5bda3d66fa771a4162d33 Mon Sep 17 00:00:00 2001 From: ncarrillo Date: Mon, 20 Apr 2015 19:35:22 -0400 Subject: [PATCH] Implemented FontWeight for Cairo/Pango --- Cairo/Perspex.Cairo/CairoExtensions.cs | 23 +++++++++++++++++++ .../Perspex.Cairo/Media/FormattedTextImpl.cs | 1 + 2 files changed, 24 insertions(+) diff --git a/Cairo/Perspex.Cairo/CairoExtensions.cs b/Cairo/Perspex.Cairo/CairoExtensions.cs index 963d2fe980..3bbf4c04b6 100644 --- a/Cairo/Perspex.Cairo/CairoExtensions.cs +++ b/Cairo/Perspex.Cairo/CairoExtensions.cs @@ -33,5 +33,28 @@ namespace Perspex.Cairo Pango.Units.ToDouble(rect.Width), Pango.Units.ToDouble(rect.Height)); } + + public static Pango.Weight ToCairo(this Perspex.Media.FontWeight weight) + { + if (weight == Perspex.Media.FontWeight.Light) + return Pango.Weight.Light; + + if (weight == Perspex.Media.FontWeight.Normal || weight == Perspex.Media.FontWeight.Regular) + return Pango.Weight.Normal; + + if (weight == Perspex.Media.FontWeight.DemiBold || weight == Perspex.Media.FontWeight.Medium) + return Pango.Weight.Semibold; + + if (weight == Perspex.Media.FontWeight.Bold) + return Pango.Weight.Bold; + + if (weight == Perspex.Media.FontWeight.UltraBold || weight == Perspex.Media.FontWeight.ExtraBold) + return Pango.Weight.Ultrabold; + + if (weight == Perspex.Media.FontWeight.Black || weight == Perspex.Media.FontWeight.Heavy || weight == Perspex.Media.FontWeight.UltraBlack) + return Pango.Weight.Heavy; + + return Pango.Weight.Ultralight; + } } } \ No newline at end of file diff --git a/Cairo/Perspex.Cairo/Media/FormattedTextImpl.cs b/Cairo/Perspex.Cairo/Media/FormattedTextImpl.cs index e77617f098..a465c9ac71 100644 --- a/Cairo/Perspex.Cairo/Media/FormattedTextImpl.cs +++ b/Cairo/Perspex.Cairo/Media/FormattedTextImpl.cs @@ -30,6 +30,7 @@ namespace Perspex.Cairo.Media Family = fontFamily, Size = Pango.Units.FromDouble(fontSize), Style = (Pango.Style)fontStyle, + Weight = fontWeight.ToCairo() }; }