PerspexTextRenderer.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // -----------------------------------------------------------------------
  2. // <copyright file="PerspexTextRenderer.cs" company="Steven Kirk">
  3. // Copyright 2013 MIT Licence. See licence.md for more information.
  4. // </copyright>
  5. // -----------------------------------------------------------------------
  6. namespace Perspex.Direct2D1.Media
  7. {
  8. using System;
  9. using SharpDX;
  10. using SharpDX.Direct2D1;
  11. using SharpDX.DirectWrite;
  12. internal class PerspexTextRenderer : TextRenderer
  13. {
  14. private DrawingContext context;
  15. private RenderTarget renderTarget;
  16. private Brush foreground;
  17. public PerspexTextRenderer(
  18. DrawingContext context,
  19. RenderTarget target,
  20. Brush foreground)
  21. {
  22. this.context = context;
  23. this.renderTarget = target;
  24. this.foreground = foreground;
  25. }
  26. public IDisposable Shadow
  27. {
  28. get;
  29. set;
  30. }
  31. public void Dispose()
  32. {
  33. }
  34. public Result DrawGlyphRun(
  35. object clientDrawingContext,
  36. float baselineOriginX,
  37. float baselineOriginY,
  38. MeasuringMode measuringMode,
  39. GlyphRun glyphRun,
  40. GlyphRunDescription glyphRunDescription,
  41. ComObject clientDrawingEffect)
  42. {
  43. var wrapper = clientDrawingEffect as BrushWrapper;
  44. // TODO: Work out how to get the size below rather than passing new Size().
  45. var brush = (wrapper == null) ?
  46. this.foreground :
  47. this.context.CreateBrush(wrapper.Brush, new Size()).PlatformBrush;
  48. this.renderTarget.DrawGlyphRun(
  49. new Vector2(baselineOriginX, baselineOriginY),
  50. glyphRun,
  51. brush,
  52. measuringMode);
  53. if (wrapper != null)
  54. {
  55. brush.Dispose();
  56. }
  57. return Result.Ok;
  58. }
  59. public Result DrawInlineObject(object clientDrawingContext, float originX, float originY, InlineObject inlineObject, bool isSideways, bool isRightToLeft, ComObject clientDrawingEffect)
  60. {
  61. throw new NotImplementedException();
  62. }
  63. public Result DrawStrikethrough(object clientDrawingContext, float baselineOriginX, float baselineOriginY, ref Strikethrough strikethrough, ComObject clientDrawingEffect)
  64. {
  65. throw new NotImplementedException();
  66. }
  67. public Result DrawUnderline(object clientDrawingContext, float baselineOriginX, float baselineOriginY, ref Underline underline, ComObject clientDrawingEffect)
  68. {
  69. throw new NotImplementedException();
  70. }
  71. public Matrix3x2 GetCurrentTransform(object clientDrawingContext)
  72. {
  73. return this.renderTarget.Transform;
  74. }
  75. public float GetPixelsPerDip(object clientDrawingContext)
  76. {
  77. return this.renderTarget.DotsPerInch.Width / 96;
  78. }
  79. public bool IsPixelSnappingDisabled(object clientDrawingContext)
  80. {
  81. return false;
  82. }
  83. }
  84. }