Browse Source

Added TextBlock.FontWeight.

Closes #31.
pull/39/head
Steven Kirk 12 years ago
parent
commit
53d804572d
  1. 5
      Cairo/Perspex.Cairo/CairoPlatform.cs
  2. 3
      Cairo/Perspex.Cairo/Media/FormattedTextImpl.cs
  3. 3
      Perspex.Controls/Presenters/TextPresenter.cs
  4. 12
      Perspex.Controls/TextBlock.cs
  5. 28
      Perspex.SceneGraph/Media/FontWeight.cs
  6. 11
      Perspex.SceneGraph/Media/FormattedText.cs
  7. 1
      Perspex.SceneGraph/Perspex.SceneGraph.csproj
  8. 3
      Perspex.SceneGraph/Platform/IPlatformRenderInterface.cs
  9. 5
      TestApplication/Program.cs
  10. 5
      Windows/Perspex.Direct2D1/Direct2D1Platform.cs
  11. 12
      Windows/Perspex.Direct2D1/Media/FormattedTextImpl.cs

5
Cairo/Perspex.Cairo/CairoPlatform.cs

@ -35,9 +35,10 @@ namespace Perspex.Cairo
string text,
string fontFamily,
double fontSize,
FontStyle fontStyle)
FontStyle fontStyle,
Perspex.Media.FontWeight fontWeight)
{
return new FormattedTextImpl(text, fontFamily, fontSize, fontStyle);
return new FormattedTextImpl(text, fontFamily, fontSize, fontStyle, fontWeight);
}
public IRenderer CreateRenderer(IPlatformHandle handle, double width, double height)

3
Cairo/Perspex.Cairo/Media/FormattedTextImpl.cs

@ -19,7 +19,8 @@ namespace Perspex.Cairo.Media
string text,
string fontFamily,
double fontSize,
FontStyle fontStyle)
FontStyle fontStyle,
FontWeight fontWeight)
{
var context = Locator.Current.GetService<Pango.Context>();
this.Layout = new Pango.Layout(context);

3
Perspex.Controls/Presenters/TextPresenter.cs

@ -178,7 +178,8 @@ namespace Perspex.Controls.Presenters
"X",
this.FontFamily,
this.FontSize,
this.FontStyle))
this.FontStyle,
this.FontWeight))
{
return formattedText.Measure();
}

12
Perspex.Controls/TextBlock.cs

@ -25,6 +25,9 @@ namespace Perspex.Controls
public static readonly PerspexProperty<FontStyle> FontStyleProperty =
PerspexProperty.Register<TextBlock, FontStyle>("FontStyle", inherits: true);
public static readonly PerspexProperty<FontWeight> FontWeightProperty =
PerspexProperty.Register<TextBlock, FontWeight>("FontWeight", inherits: true, defaultValue: FontWeight.Normal);
public static readonly PerspexProperty<Brush> ForegroundProperty =
PerspexProperty.Register<TextBlock, Brush>("Foreground", new SolidColorBrush(0xff000000), inherits: true);
@ -80,6 +83,12 @@ namespace Perspex.Controls
set { this.SetValue(FontStyleProperty, value); }
}
public FontWeight FontWeight
{
get { return this.GetValue(FontWeightProperty); }
set { this.SetValue(FontWeightProperty, value); }
}
public Brush Foreground
{
get { return this.GetValue(ForegroundProperty); }
@ -123,7 +132,8 @@ namespace Perspex.Controls
this.Text,
this.FontFamily,
this.FontSize,
this.FontStyle);
this.FontStyle,
this.FontWeight);
result.Constraint = this.constraint;
return result;
}

28
Perspex.SceneGraph/Media/FontWeight.cs

@ -0,0 +1,28 @@
// -----------------------------------------------------------------------
// <copyright file="FontWeight.cs" company="Steven Kirk">
// Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Media
{
public enum FontWeight
{
Thin = 100,
ExtraLight = 200,
UltraLight = 200,
Light = 300,
Normal = 400,
Regular = 400,
Medium = 500,
DemiBold = 600,
SemiBold = 600,
Bold = 700,
ExtraBold = 800,
UltraBold = 800,
Black = 900,
Heavy = 900,
ExtraBlack = 950,
UltraBlack = 950
}
}

11
Perspex.SceneGraph/Media/FormattedText.cs

@ -17,7 +17,8 @@ namespace Perspex.Media
string text,
string fontFamilyName,
double fontSize,
FontStyle fontStyle)
FontStyle fontStyle,
FontWeight fontWeight)
{
this.Text = text;
this.FontFamilyName = fontFamilyName;
@ -25,7 +26,13 @@ namespace Perspex.Media
this.FontStyle = fontStyle;
var platform = Locator.Current.GetService<IPlatformRenderInterface>();
this.PlatformImpl = platform.CreateFormattedText(text, fontFamilyName, fontSize, fontStyle);
this.PlatformImpl = platform.CreateFormattedText(
text,
fontFamilyName,
fontSize,
fontStyle,
fontWeight);
}
public Size Constraint

1
Perspex.SceneGraph/Perspex.SceneGraph.csproj

@ -50,6 +50,7 @@
<Compile Include="Media\Brushes.cs" />
<Compile Include="Media\Color.cs" />
<Compile Include="Media\Colors.cs" />
<Compile Include="Media\FontWeight.cs" />
<Compile Include="Media\FontStyle.cs" />
<Compile Include="Media\FormattedTextLine.cs" />
<Compile Include="Media\FormattedText.cs" />

3
Perspex.SceneGraph/Platform/IPlatformRenderInterface.cs

@ -16,7 +16,8 @@ namespace Perspex.Platform
string text,
string fontFamily,
double fontSize,
FontStyle fontStyle);
FontStyle fontStyle,
FontWeight fontWeight);
IStreamGeometryImpl CreateStreamGeometry();

5
TestApplication/Program.cs

@ -300,6 +300,11 @@ namespace TestApplication
Text = "Italic text.",
FontStyle = FontStyle.Italic,
},
new TextBlock
{
Text = "Bold text.",
FontWeight = FontWeight.Bold,
},
new TextBox
{
Text = "A non-wrapping text box. Lorem ipsum dolor sit amet.",

5
Windows/Perspex.Direct2D1/Direct2D1Platform.cs

@ -41,9 +41,10 @@ namespace Perspex.Direct2D1
string text,
string fontFamily,
double fontSize,
FontStyle fontStyle)
FontStyle fontStyle,
FontWeight fontWeight)
{
return new FormattedTextImpl(text, fontFamily, fontSize, fontStyle);
return new FormattedTextImpl(text, fontFamily, fontSize, fontStyle, fontWeight);
}
public IRenderer CreateRenderer(IPlatformHandle handle, double width, double height)

12
Windows/Perspex.Direct2D1/Media/FormattedTextImpl.cs

@ -20,14 +20,22 @@ namespace Perspex.Direct2D1.Media
string text,
string fontFamily,
double fontSize,
FontStyle fontStyle)
FontStyle fontStyle,
FontWeight fontWeight)
{
var factory = Locator.Current.GetService<DWrite.Factory>();
var format = new DWrite.TextFormat(
factory,
fontFamily,
(DWrite.FontWeight)fontWeight,
(DWrite.FontStyle)fontStyle,
(float)fontSize);
this.TextLayout = new DWrite.TextLayout(
factory,
text ?? string.Empty,
new DWrite.TextFormat(factory, fontFamily, DWrite.FontWeight.Normal, (DWrite.FontStyle)fontStyle, (float)fontSize),
format,
float.MaxValue,
float.MaxValue);
}

Loading…
Cancel
Save