Skip to content

Instantly share code, notes, and snippets.

@pulse-matt
Created December 4, 2013 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pulse-matt/7796669 to your computer and use it in GitHub Desktop.
Save pulse-matt/7796669 to your computer and use it in GitHub Desktop.
Sample program demonstrating https://github.com/sharpdx/SharpDX/issues/222
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SharpDXProblem1
{
class Program
{
static void Main(string[] args)
{
string fontName = "Arial";
string text = "A1a";
using (var factory = new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Shared))
{
using (var fontCollection = factory.GetSystemFontCollection(true))
{
int familyIndex;
fontCollection.FindFamilyName(fontName, out familyIndex);
using (var fontFamily = fontCollection.GetFontFamily(familyIndex))
{
var font = fontFamily.GetFont(0);
using (var textFormat = new SharpDX.DirectWrite.TextFormat(factory, fontName, font.Weight, font.Style, font.Stretch, 48.0f))
{
textFormat.WordWrapping = SharpDX.DirectWrite.WordWrapping.Wrap;
textFormat.TextAlignment = SharpDX.DirectWrite.TextAlignment.Leading;
textFormat.ReadingDirection = SharpDX.DirectWrite.ReadingDirection.LeftToRight;
textFormat.FlowDirection = SharpDX.DirectWrite.FlowDirection.TopToBottom;
textFormat.ParagraphAlignment = SharpDX.DirectWrite.ParagraphAlignment.Near;
using (var textLayout = new SharpDX.DirectWrite.TextLayout(factory, text, textFormat, float.MaxValue, float.MaxValue))
{
CustomTextRenderer textRenderer = new CustomTextRenderer();
textLayout.Draw(textRenderer, 0, 0);
}
}
}
}
}
}
}
public class CustomTextRenderer : SharpDX.DirectWrite.TextRenderer
{
#region TextRenderer Members
public SharpDX.Result DrawGlyphRun(object clientDrawingContext, float baselineOriginX, float baselineOriginY, SharpDX.Direct2D1.MeasuringMode measuringMode, SharpDX.DirectWrite.GlyphRun glyphRun, SharpDX.DirectWrite.GlyphRunDescription glyphRunDescription, SharpDX.ComObject clientDrawingEffect)
{
return new SharpDX.Result();
}
public SharpDX.Result DrawInlineObject(object clientDrawingContext, float originX, float originY, SharpDX.DirectWrite.InlineObject inlineObject, bool isSideways, bool isRightToLeft, SharpDX.ComObject clientDrawingEffect)
{
return new SharpDX.Result();
}
public SharpDX.Result DrawStrikethrough(object clientDrawingContext, float baselineOriginX, float baselineOriginY, ref SharpDX.DirectWrite.Strikethrough strikethrough, SharpDX.ComObject clientDrawingEffect)
{
return new SharpDX.Result();
}
public SharpDX.Result DrawUnderline(object clientDrawingContext, float baselineOriginX, float baselineOriginY, ref SharpDX.DirectWrite.Underline underline, SharpDX.ComObject clientDrawingEffect)
{
return new SharpDX.Result();
}
#endregion
#region PixelSnapping Members
public SharpDX.Matrix3x2 GetCurrentTransform(object clientDrawingContext)
{
return new SharpDX.Matrix3x2();
}
public float GetPixelsPerDip(object clientDrawingContext)
{
return 0;
}
public bool IsPixelSnappingDisabled(object clientDrawingContext)
{
return true;
}
#endregion
#region ICallbackable Members
public IDisposable Shadow
{
get
{
return null;
}
set
{
// throw new NotImplementedException();
}
}
#endregion
#region IDisposable Members
public void Dispose()
{
}
#endregion
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment