dwrite: Implement IDWriteBitmapRenderTarget creation.
[wine/multimedia.git] / dlls / dwrite / gdiinterop.c
blobc3bcc889965b963dcfc12445aa3eb7908a00e53d
1 /*
2 * GDI Interop
4 * Copyright 2012 Nikolay Sivov for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
23 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "dwrite.h"
29 #include "dwrite_private.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(dwrite);
35 struct rendertarget {
36 IDWriteBitmapRenderTarget IDWriteBitmapRenderTarget_iface;
37 LONG ref;
39 HDC hdc;
42 static inline struct rendertarget *impl_from_IDWriteBitmapRenderTarget(IDWriteBitmapRenderTarget *iface)
44 return CONTAINING_RECORD(iface, struct rendertarget, IDWriteBitmapRenderTarget_iface);
47 static HRESULT WINAPI rendertarget_QueryInterface(IDWriteBitmapRenderTarget *iface, REFIID riid, void **obj)
49 struct rendertarget *This = impl_from_IDWriteBitmapRenderTarget(iface);
51 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
53 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDWriteBitmapRenderTarget))
55 *obj = iface;
56 IDWriteBitmapRenderTarget_AddRef(iface);
57 return S_OK;
60 *obj = NULL;
62 return E_NOINTERFACE;
65 static ULONG WINAPI rendertarget_AddRef(IDWriteBitmapRenderTarget *iface)
67 struct rendertarget *This = impl_from_IDWriteBitmapRenderTarget(iface);
68 ULONG ref = InterlockedIncrement(&This->ref);
69 TRACE("(%p)->(%d)\n", This, ref);
70 return ref;
73 static ULONG WINAPI rendertarget_Release(IDWriteBitmapRenderTarget *iface)
75 struct rendertarget *This = impl_from_IDWriteBitmapRenderTarget(iface);
76 ULONG ref = InterlockedDecrement(&This->ref);
78 TRACE("(%p)->(%d)\n", This, ref);
80 if (!ref)
82 DeleteDC(This->hdc);
83 heap_free(This);
86 return S_OK;
89 static HRESULT WINAPI rendertarget_DrawGlyphRun(IDWriteBitmapRenderTarget *iface,
90 FLOAT baselineOriginX, FLOAT baselineOriginY, DWRITE_MEASURING_MODE measuring_mode,
91 DWRITE_GLYPH_RUN const* glyph_run, IDWriteRenderingParams* params, COLORREF textColor,
92 RECT *blackbox_rect)
94 struct rendertarget *This = impl_from_IDWriteBitmapRenderTarget(iface);
95 FIXME("(%p)->(%f %f %d %p %p 0x%08x %p): stub\n", This, baselineOriginX, baselineOriginY,
96 measuring_mode, glyph_run, params, textColor, blackbox_rect);
97 return E_NOTIMPL;
100 static HDC WINAPI rendertarget_GetMemoryDC(IDWriteBitmapRenderTarget *iface)
102 struct rendertarget *This = impl_from_IDWriteBitmapRenderTarget(iface);
103 TRACE("(%p)\n", This);
104 return This->hdc;
107 static FLOAT WINAPI rendertarget_GetPixelsPerDip(IDWriteBitmapRenderTarget *iface)
109 struct rendertarget *This = impl_from_IDWriteBitmapRenderTarget(iface);
110 FIXME("(%p): stub\n", This);
111 return 1.0;
114 static HRESULT WINAPI rendertarget_SetPixelsPerDip(IDWriteBitmapRenderTarget *iface, FLOAT pixels_per_dip)
116 struct rendertarget *This = impl_from_IDWriteBitmapRenderTarget(iface);
117 FIXME("(%p)->(%f): stub\n", This, pixels_per_dip);
118 return E_NOTIMPL;
121 static HRESULT WINAPI rendertarget_GetCurrentTransform(IDWriteBitmapRenderTarget *iface, DWRITE_MATRIX *transform)
123 struct rendertarget *This = impl_from_IDWriteBitmapRenderTarget(iface);
124 FIXME("(%p)->(%p): stub\n", This, transform);
125 return E_NOTIMPL;
128 static HRESULT WINAPI rendertarget_SetCurrentTransform(IDWriteBitmapRenderTarget *iface, DWRITE_MATRIX const *transform)
130 struct rendertarget *This = impl_from_IDWriteBitmapRenderTarget(iface);
131 FIXME("(%p)->(%p): stub\n", This, transform);
132 return E_NOTIMPL;
135 static HRESULT WINAPI rendertarget_GetSize(IDWriteBitmapRenderTarget *iface, SIZE *size)
137 struct rendertarget *This = impl_from_IDWriteBitmapRenderTarget(iface);
138 FIXME("(%p)->(%p): stub\n", This, size);
139 return E_NOTIMPL;
142 static HRESULT WINAPI rendertarget_Resize(IDWriteBitmapRenderTarget *iface, UINT32 width, UINT32 height)
144 struct rendertarget *This = impl_from_IDWriteBitmapRenderTarget(iface);
145 FIXME("(%p)->(%u %u): stub\n", This, width, height);
146 return E_NOTIMPL;
149 static const IDWriteBitmapRenderTargetVtbl rendertargetvtbl = {
150 rendertarget_QueryInterface,
151 rendertarget_AddRef,
152 rendertarget_Release,
153 rendertarget_DrawGlyphRun,
154 rendertarget_GetMemoryDC,
155 rendertarget_GetPixelsPerDip,
156 rendertarget_SetPixelsPerDip,
157 rendertarget_GetCurrentTransform,
158 rendertarget_SetCurrentTransform,
159 rendertarget_GetSize,
160 rendertarget_Resize
163 static HRESULT create_rendertarget(HDC hdc, UINT32 width, UINT32 height, IDWriteBitmapRenderTarget **target)
165 char bmibuf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
166 BITMAPINFO *bmi = (BITMAPINFO*)bmibuf;
167 struct rendertarget *This;
168 HBITMAP dib;
170 *target = NULL;
172 This = heap_alloc(sizeof(struct rendertarget));
173 if (!This) return E_OUTOFMEMORY;
175 This->IDWriteBitmapRenderTarget_iface.lpVtbl = &rendertargetvtbl;
176 This->ref = 1;
178 This->hdc = CreateCompatibleDC(hdc);
180 memset(bmi, 0, sizeof(bmibuf));
181 bmi->bmiHeader.biSize = sizeof(bmi->bmiHeader);
182 bmi->bmiHeader.biHeight = height;
183 bmi->bmiHeader.biWidth = width;
184 bmi->bmiHeader.biBitCount = 32;
185 bmi->bmiHeader.biPlanes = 1;
186 bmi->bmiHeader.biCompression = BI_RGB;
188 dib = CreateDIBSection(This->hdc, bmi, DIB_RGB_COLORS, NULL, NULL, 0);
189 SelectObject(This->hdc, dib);
191 *target = &This->IDWriteBitmapRenderTarget_iface;
193 return S_OK;
196 static HRESULT WINAPI gdiinterop_QueryInterface(IDWriteGdiInterop *iface, REFIID riid, void **obj)
198 TRACE("(%s %p)\n", debugstr_guid(riid), obj);
200 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDWriteGdiInterop))
202 *obj = iface;
203 return S_OK;
206 *obj = NULL;
208 return E_NOINTERFACE;
211 static ULONG WINAPI gdiinterop_AddRef(IDWriteGdiInterop *iface)
213 return 2;
216 static ULONG WINAPI gdiinterop_Release(IDWriteGdiInterop *iface)
218 return 1;
221 static HRESULT WINAPI gdiinterop_CreateFontFromLOGFONT(IDWriteGdiInterop *iface,
222 LOGFONTW const *logfont, IDWriteFont **font)
224 TRACE("(%p %p)\n", logfont, font);
226 if (!logfont) return E_INVALIDARG;
228 return create_font_from_logfont(logfont, font);
231 static HRESULT WINAPI gdiinterop_ConvertFontToLOGFONT(IDWriteGdiInterop *iface,
232 IDWriteFont *font, LOGFONTW *logfont, BOOL *is_systemfont)
234 FIXME("(%p %p %p): stub\n", font, logfont, is_systemfont);
235 return E_NOTIMPL;
238 static HRESULT WINAPI gdiinterop_ConvertFontFaceToLOGFONT(IDWriteGdiInterop *iface,
239 IDWriteFontFace *font, LOGFONTW *logfont)
241 FIXME("(%p %p): stub\n", font, logfont);
242 return E_NOTIMPL;
245 static HRESULT WINAPI gdiinterop_CreateFontFaceFromHdc(IDWriteGdiInterop *iface,
246 HDC hdc, IDWriteFontFace **fontface)
248 FIXME("(%p %p): stub\n", hdc, fontface);
249 return E_NOTIMPL;
252 static HRESULT WINAPI gdiinterop_CreateBitmapRenderTarget(IDWriteGdiInterop *iface,
253 HDC hdc, UINT32 width, UINT32 height, IDWriteBitmapRenderTarget **target)
255 TRACE("(%p %u %u %p)\n", hdc, width, height, target);
256 return create_rendertarget(hdc, width, height, target);
259 static const struct IDWriteGdiInteropVtbl gdiinteropvtbl = {
260 gdiinterop_QueryInterface,
261 gdiinterop_AddRef,
262 gdiinterop_Release,
263 gdiinterop_CreateFontFromLOGFONT,
264 gdiinterop_ConvertFontToLOGFONT,
265 gdiinterop_ConvertFontFaceToLOGFONT,
266 gdiinterop_CreateFontFaceFromHdc,
267 gdiinterop_CreateBitmapRenderTarget
270 static IDWriteGdiInterop gdiinterop = { &gdiinteropvtbl };
272 HRESULT create_gdiinterop(IDWriteGdiInterop **ret)
274 *ret = &gdiinterop;
275 return S_OK;