[PATCH] d2d1: Support text clipping with D2D1_DRAW_TEXT_OPTIONS_CLIP

Nikolay Sivov nsivov at codeweavers.com
Sat Apr 1 14:01:16 CDT 2017


Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
---
 dlls/d2d1/render_target.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/dlls/d2d1/render_target.c b/dlls/d2d1/render_target.c
index c773fdf51d..d45fcc5d5f 100644
--- a/dlls/d2d1/render_target.c
+++ b/dlls/d2d1/render_target.c
@@ -1002,12 +1002,33 @@ static void STDMETHODCALLTYPE d2d_d3d_render_target_DrawTextLayout(ID2D1RenderTa
     TRACE("iface %p, origin {%.8e, %.8e}, layout %p, brush %p, options %#x.\n",
             iface, origin.x, origin.y, layout, brush, options);
 
+    if (options & D2D1_DRAW_TEXT_OPTIONS_CLIP)
+    {
+        DWRITE_TEXT_METRICS layout_metrics;
+        D2D1_RECT_F clip_rect;
+
+        if (FAILED(hr = IDWriteTextLayout_GetMetrics(layout, &layout_metrics)))
+        {
+            FIXME("Failed to get layout metrics, hr %#x.\n", hr);
+            return;
+        }
+
+        clip_rect.left = origin.x + layout_metrics.left;
+        clip_rect.top = origin.y + layout_metrics.top;
+        clip_rect.right = clip_rect.left + layout_metrics.layoutWidth;
+        clip_rect.bottom = clip_rect.top + layout_metrics.layoutHeight;
+        ID2D1RenderTarget_PushAxisAlignedClip(iface, &clip_rect, D2D1_ANTIALIAS_MODE_ALIASED);
+    }
+
     ctx.brush = brush;
     ctx.options = options;
 
     if (FAILED(hr = IDWriteTextLayout_Draw(layout,
             &ctx, &render_target->IDWriteTextRenderer_iface, origin.x, origin.y)))
         FIXME("Failed to draw text layout, hr %#x.\n", hr);
+
+    if (options & D2D1_DRAW_TEXT_OPTIONS_CLIP)
+        ID2D1RenderTarget_PopAxisAlignedClip(iface);
 }
 
 static void d2d_rt_draw_glyph_run_outline(struct d2d_d3d_render_target *render_target,
@@ -1715,7 +1736,8 @@ static HRESULT STDMETHODCALLTYPE d2d_text_renderer_DrawGlyphRun(IDWriteTextRende
 
     if (desc)
         WARN("Ignoring glyph run description %p.\n", desc);
-    if (context->options & ~(D2D1_DRAW_TEXT_OPTIONS_NO_SNAP | D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT))
+    if (context->options & ~(D2D1_DRAW_TEXT_OPTIONS_NO_SNAP | D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT |
+            D2D1_DRAW_TEXT_OPTIONS_CLIP))
         FIXME("Ignoring options %#x.\n", context->options);
 
     brush = d2d_draw_get_text_brush(context, effect);
-- 
2.11.0




More information about the wine-patches mailing list