public static string GetFontFamilyName(this IDWriteTextLayout format, uint currentPosition = 0, DWRITE_TEXT_RANGE?range = null)
        {
            if (format == null)
            {
                throw new ArgumentNullException(nameof(format));
            }

            if (range == null)
            {
                return(call(IntPtr.Zero));
            }

            using (var mem = new ComMemory(range.Value))
            {
                return(call(mem.Pointer));
            }

            string call(IntPtr ptr)
            {
                format.GetFontFamilyNameLength(currentPosition, out var len, ptr).ThrowOnError();
                var s = new string('\0', (int)len);

                format.GetFontFamilyName(currentPosition, s, len + 1, ptr).ThrowOnError();
                return(s);
            }
        }
Beispiel #2
0
        public static void DrawTextLayout(this ID2D1RenderTarget context,
                                          D2D_POINT_2F origin,
                                          IDWriteTextLayout layout,
                                          ID2D1Brush defaultFillBrush    = null,
                                          D2D1_DRAW_TEXT_OPTIONS options = D2D1_DRAW_TEXT_OPTIONS.D2D1_DRAW_TEXT_OPTIONS_NONE)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (layout == null)
            {
                throw new ArgumentNullException(nameof(layout));
            }

            context.DrawTextLayout(origin, layout, defaultFillBrush, options);
        }
        public static DWRITE_TEXT_METRICS1 GetMetrics1(this IDWriteTextLayout layout)
        {
            if (layout == null)
            {
                throw new ArgumentNullException(nameof(layout));
            }

            DWRITE_TEXT_METRICS1 metrics1;

            if (layout is IDWriteTextLayout2 layout2)
            {
                layout2.GetMetrics(out metrics1).ThrowOnError();
            }
            else
            {
                layout.GetMetrics(out var metrics).ThrowOnError();
                metrics1.height = metrics.height;
                metrics1.heightIncludingTrailingWhitespace = metrics.height;
                metrics1.layoutHeight           = metrics.layoutHeight;
                metrics1.layoutWidth            = metrics.layoutWidth;
                metrics1.left                   = metrics.left;
                metrics1.lineCount              = metrics.lineCount;
                metrics1.maxBidiReorderingDepth = metrics.maxBidiReorderingDepth;
                metrics1.top   = metrics.top;
                metrics1.width = metrics.width;
                metrics1.widthIncludingTrailingWhitespace = metrics.widthIncludingTrailingWhitespace;
            }

            // sometimes, there's a bug where widthIncludingTrailingWhitespace is 0 while width is not...
            if (metrics1.widthIncludingTrailingWhitespace < metrics1.width)
            {
                metrics1.widthIncludingTrailingWhitespace = metrics1.width;
            }

            if (metrics1.heightIncludingTrailingWhitespace < metrics1.height)
            {
                metrics1.heightIncludingTrailingWhitespace = metrics1.height;
            }
            return(metrics1);
        }
        public static IComObject <IDWriteFontCollection> GetFontCollection(this IDWriteTextLayout format, uint currentPosition = 0, DWRITE_TEXT_RANGE?range = null)
        {
            if (format == null)
            {
                throw new ArgumentNullException(nameof(format));
            }

            if (range == null)
            {
                return(call(IntPtr.Zero));
            }

            using (var mem = new ComMemory(range.Value))
            {
                return(call(mem.Pointer));
            }

            ComObject <IDWriteFontCollection> call(IntPtr ptr)
            {
                format.GetFontCollection(currentPosition, out var coll, ptr).ThrowOnError();
                return(new ComObject <IDWriteFontCollection>(coll));
            }
        }
Beispiel #5
0
 internal DWriteTextLayout(IDWriteTextLayout handle)
 {
     this.handle = handle;
 }
Beispiel #6
0
 public static void DrawTextLayout(this IComObject <ID2D1RenderTarget> context,
                                   D2D_POINT_2F origin,
                                   IDWriteTextLayout layout,
                                   ID2D1Brush defaultFillBrush    = null,
                                   D2D1_DRAW_TEXT_OPTIONS options = D2D1_DRAW_TEXT_OPTIONS.D2D1_DRAW_TEXT_OPTIONS_NONE) => DrawTextLayout(context?.Object, origin, layout, defaultFillBrush, options);
 internal DWriteTextLayout(IDWriteTextLayout handle)
 {
     this.handle = handle;
 }
 /// <summary>
 /// Draws the formatted text described by the specified <see cref="IDWriteTextLayout"/> object.
 /// </summary>
 /// <param name="origin">The point, described in device-independent pixels, at which the upper-left corner of the text described by textLayout is drawn. </param>
 /// <param name="textLayout">The formatted text to draw. Any drawing effects that do not inherit from <see cref="ID2D1Resource" /> are ignored. If there are drawing effects that inherit from <see cref="ID2D1Resource"/> that are not brushes, this method fails and the render target is put in an error state.  </param>
 /// <param name="defaultForegroundBrush">The <see cref="ID2D1Brush"/> used to paint any text in textLayout that does not already have a brush associated with it as a drawing effect (specified by the <see cref="IDWriteTextLayout.SetDrawingEffect(IUnknown, TextRange)"/> method).</param>
 public void DrawTextLayout(Vector2 origin, IDWriteTextLayout textLayout, ID2D1Brush defaultForegroundBrush)
 {
     DrawTextLayout(origin, textLayout, defaultForegroundBrush, DrawTextOptions.None);
 }
        private void Release()
        {
            if (comObject != null)
            {
                Marshal.ReleaseComObject(comObject);
                comObject = null;

                setMaxWidth = null;
                setMaxHeight = null;
                getMaxWidth = null;
                getMaxHeight = null;
                draw = null;
            }
        }
        internal TextLayout(IntPtr objPtr)
        {
            Handle = objPtr;
            comObject =
                (IDWriteTextLayout) Marshal.GetObjectForIUnknown(objPtr);

            InitComMethods();
        }