Skip to content

Instantly share code, notes, and snippets.

@shoelzer
Created June 27, 2013 20:35
Show Gist options
  • Save shoelzer/5880151 to your computer and use it in GitHub Desktop.
Save shoelzer/5880151 to your computer and use it in GitHub Desktop.
A modification of TextRenderingApp from SharpDXSamples showing that `DrawTextOptions.NoSnap` behaves the same as `DrawTextOptions.None`.
// Copyright (c) 2010-2013 SharpDX - Alexandre Mutel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using SharpDX;
using SharpDX.Direct2D1;
using SharpDX.DirectWrite;
using SharpDX.Samples;
namespace TextRenderingApp
{
public class Program : Direct2D1DemoApp
{
private const string lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros. Donec viverra mi quis quam pulvinar at malesuada arcu rhoncus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In rutrum accumsan ultricies. Mauris vitae nisi at sem facilisis semper ac in est.";
private TextFormat textFormat;
private RectangleF layoutRect, layoutRect2;
private Brush brush;
protected override void Initialize(DemoConfiguration demoConfiguration)
{
base.Initialize(demoConfiguration);
RenderTarget2D.TextAntialiasMode = TextAntialiasMode.Cleartype;
this.textFormat = new TextFormat(FactoryDWrite, "Arial", 12);
this.layoutRect = new RectangleF(
RenderTarget2D.PixelSize.Width * 0.05f, RenderTarget2D.PixelSize.Height * 0.1f,
RenderTarget2D.PixelSize.Width * 0.4f, RenderTarget2D.PixelSize.Height * 0.4f);
this.layoutRect2 = this.layoutRect;
this.layoutRect2.Left = RenderTarget2D.PixelSize.Width / 2;
this.brush = new SolidColorBrush(RenderTarget2D, Color.White);
}
protected override void Draw(DemoTime time)
{
RenderTarget2D.Clear(null);
base.Draw(time);
RenderTarget2D.DrawText(lorem, this.textFormat, this.layoutRect, this.brush, DrawTextOptions.None);
RenderTarget2D.DrawText(lorem, this.textFormat, this.layoutRect2, this.brush, DrawTextOptions.NoSnap);
this.layoutRect.Top += 0.001f;
this.layoutRect2.Top += 0.001f;
}
[STAThread]
static void Main(string[] args)
{
Program program = new Program();
program.Run(new DemoConfiguration("SharpDX DirectWrite Text Rendering Demo"));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment