2008-03-14 14:12:30 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 Tony Wasserka
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2016-03-15 04:03:22 +01:00
|
|
|
#include "d3dx9_private.h"
|
2008-03-14 14:12:30 +01:00
|
|
|
|
2020-03-05 22:39:59 +01:00
|
|
|
#include "usp10.h"
|
|
|
|
|
2008-03-14 14:12:30 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
|
|
|
|
|
2020-02-27 13:01:39 +01:00
|
|
|
struct d3dx_glyph
|
|
|
|
{
|
|
|
|
unsigned int id;
|
|
|
|
RECT black_box;
|
|
|
|
POINT cell_inc;
|
|
|
|
IDirect3DTexture9 *texture;
|
|
|
|
|
|
|
|
struct wine_rb_entry entry;
|
|
|
|
};
|
|
|
|
|
2012-06-19 01:15:36 +02:00
|
|
|
struct d3dx_font
|
2008-03-14 14:12:30 +01:00
|
|
|
{
|
2011-01-27 00:28:41 +01:00
|
|
|
ID3DXFont ID3DXFont_iface;
|
|
|
|
LONG ref;
|
|
|
|
|
|
|
|
IDirect3DDevice9 *device;
|
|
|
|
D3DXFONT_DESCW desc;
|
2020-02-27 13:01:39 +01:00
|
|
|
TEXTMETRICW metrics;
|
2011-01-27 00:28:41 +01:00
|
|
|
|
|
|
|
HDC hdc;
|
|
|
|
HFONT hfont;
|
2020-02-27 13:01:39 +01:00
|
|
|
|
|
|
|
struct wine_rb_tree glyph_tree;
|
|
|
|
|
|
|
|
IDirect3DTexture9 **textures;
|
|
|
|
unsigned int texture_count, texture_pos;
|
|
|
|
|
|
|
|
unsigned int texture_size, glyph_size, glyphs_per_texture;
|
2012-06-19 01:15:36 +02:00
|
|
|
};
|
2011-01-27 00:28:41 +01:00
|
|
|
|
2020-02-27 13:01:39 +01:00
|
|
|
static int glyph_rb_compare(const void *key, const struct wine_rb_entry *entry)
|
|
|
|
{
|
|
|
|
struct d3dx_glyph *glyph = WINE_RB_ENTRY_VALUE(entry, struct d3dx_glyph, entry);
|
|
|
|
unsigned int id = (UINT_PTR)key;
|
|
|
|
|
|
|
|
return id - glyph->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void glyph_rb_free(struct wine_rb_entry *entry, void *context)
|
|
|
|
{
|
|
|
|
struct d3dx_glyph *glyph = WINE_RB_ENTRY_VALUE(entry, struct d3dx_glyph, entry);
|
|
|
|
|
|
|
|
heap_free(glyph);
|
|
|
|
}
|
|
|
|
|
2012-06-19 01:15:36 +02:00
|
|
|
static inline struct d3dx_font *impl_from_ID3DXFont(ID3DXFont *iface)
|
2011-01-27 00:28:41 +01:00
|
|
|
{
|
2012-06-19 01:15:36 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct d3dx_font, ID3DXFont_iface);
|
2011-01-27 00:28:41 +01:00
|
|
|
}
|
|
|
|
|
2012-04-10 22:06:22 +02:00
|
|
|
static HRESULT WINAPI ID3DXFontImpl_QueryInterface(ID3DXFont *iface, REFIID riid, void **out)
|
2011-01-27 00:28:41 +01:00
|
|
|
{
|
2012-04-10 22:06:22 +02:00
|
|
|
TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
|
2008-03-14 14:12:30 +01:00
|
|
|
|
2012-04-10 22:06:22 +02:00
|
|
|
if (IsEqualGUID(riid, &IID_ID3DXFont)
|
|
|
|
|| IsEqualGUID(riid, &IID_IUnknown))
|
|
|
|
{
|
2008-03-14 14:12:30 +01:00
|
|
|
IUnknown_AddRef(iface);
|
2012-04-10 22:06:22 +02:00
|
|
|
*out = iface;
|
2008-03-14 14:12:30 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
2012-04-10 22:06:22 +02:00
|
|
|
|
|
|
|
WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
|
|
|
|
|
|
|
|
*out = NULL;
|
2008-03-14 14:12:30 +01:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2011-01-27 00:28:41 +01:00
|
|
|
static ULONG WINAPI ID3DXFontImpl_AddRef(ID3DXFont *iface)
|
2008-03-14 14:12:30 +01:00
|
|
|
{
|
2020-02-27 13:01:39 +01:00
|
|
|
struct d3dx_font *font = impl_from_ID3DXFont(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&font->ref);
|
|
|
|
|
2012-06-19 01:15:36 +02:00
|
|
|
TRACE("%p increasing refcount to %u\n", iface, ref);
|
2008-03-14 14:12:30 +01:00
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
2011-01-27 00:28:41 +01:00
|
|
|
static ULONG WINAPI ID3DXFontImpl_Release(ID3DXFont *iface)
|
2008-03-14 14:12:30 +01:00
|
|
|
{
|
2020-02-27 13:01:39 +01:00
|
|
|
struct d3dx_font *font = impl_from_ID3DXFont(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&font->ref);
|
|
|
|
unsigned int i;
|
2010-04-02 08:54:54 +02:00
|
|
|
|
2012-06-19 01:15:36 +02:00
|
|
|
TRACE("%p decreasing refcount to %u\n", iface, ref);
|
2008-03-14 14:12:30 +01:00
|
|
|
|
2020-02-27 13:01:39 +01:00
|
|
|
if (!ref)
|
|
|
|
{
|
|
|
|
for (i = 0; i < font->texture_count; ++i)
|
|
|
|
IDirect3DTexture9_Release(font->textures[i]);
|
|
|
|
|
|
|
|
heap_free(font->textures);
|
|
|
|
|
|
|
|
wine_rb_destroy(&font->glyph_tree, glyph_rb_free, NULL);
|
|
|
|
|
|
|
|
DeleteObject(font->hfont);
|
|
|
|
DeleteDC(font->hdc);
|
|
|
|
IDirect3DDevice9_Release(font->device);
|
|
|
|
heap_free(font);
|
2008-03-14 14:12:30 +01:00
|
|
|
}
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
2012-06-19 01:15:36 +02:00
|
|
|
static HRESULT WINAPI ID3DXFontImpl_GetDevice(ID3DXFont *iface, IDirect3DDevice9 **device)
|
2008-03-14 14:12:30 +01:00
|
|
|
{
|
2020-02-27 13:01:39 +01:00
|
|
|
struct d3dx_font *font = impl_from_ID3DXFont(iface);
|
2010-04-02 08:54:54 +02:00
|
|
|
|
2012-06-19 01:15:36 +02:00
|
|
|
TRACE("iface %p, device %p\n", iface, device);
|
2009-06-05 13:15:44 +02:00
|
|
|
|
|
|
|
if( !device ) return D3DERR_INVALIDCALL;
|
2020-02-27 13:01:39 +01:00
|
|
|
*device = font->device;
|
|
|
|
IDirect3DDevice9_AddRef(font->device);
|
2009-06-05 13:15:44 +02:00
|
|
|
|
2008-03-14 14:12:30 +01:00
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-01-27 00:28:41 +01:00
|
|
|
static HRESULT WINAPI ID3DXFontImpl_GetDescA(ID3DXFont *iface, D3DXFONT_DESCA *desc)
|
2008-03-14 14:12:30 +01:00
|
|
|
{
|
2020-02-27 13:01:39 +01:00
|
|
|
struct d3dx_font *font = impl_from_ID3DXFont(iface);
|
2010-04-02 08:54:54 +02:00
|
|
|
|
2012-06-19 01:15:36 +02:00
|
|
|
TRACE("iface %p, desc %p\n", iface, desc);
|
2009-06-05 13:26:11 +02:00
|
|
|
|
|
|
|
if( !desc ) return D3DERR_INVALIDCALL;
|
2020-02-27 13:01:39 +01:00
|
|
|
memcpy(desc, &font->desc, FIELD_OFFSET(D3DXFONT_DESCA, FaceName));
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, font->desc.FaceName, -1, desc->FaceName, ARRAY_SIZE(desc->FaceName), NULL, NULL);
|
2009-06-05 13:26:11 +02:00
|
|
|
|
2008-03-14 14:12:30 +01:00
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-01-27 00:28:41 +01:00
|
|
|
static HRESULT WINAPI ID3DXFontImpl_GetDescW(ID3DXFont *iface, D3DXFONT_DESCW *desc)
|
2008-03-14 14:12:30 +01:00
|
|
|
{
|
2020-02-27 13:01:39 +01:00
|
|
|
struct d3dx_font *font = impl_from_ID3DXFont(iface);
|
2010-04-02 08:54:54 +02:00
|
|
|
|
2012-06-19 01:15:36 +02:00
|
|
|
TRACE("iface %p, desc %p\n", iface, desc);
|
2009-06-05 13:26:11 +02:00
|
|
|
|
|
|
|
if( !desc ) return D3DERR_INVALIDCALL;
|
2020-02-27 13:01:39 +01:00
|
|
|
*desc = font->desc;
|
2009-06-05 13:26:11 +02:00
|
|
|
|
2008-03-14 14:12:30 +01:00
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-01-27 00:28:41 +01:00
|
|
|
static BOOL WINAPI ID3DXFontImpl_GetTextMetricsA(ID3DXFont *iface, TEXTMETRICA *metrics)
|
2008-03-14 14:12:30 +01:00
|
|
|
{
|
2020-02-27 13:01:39 +01:00
|
|
|
struct d3dx_font *font = impl_from_ID3DXFont(iface);
|
2012-06-19 01:15:36 +02:00
|
|
|
TRACE("iface %p, metrics %p\n", iface, metrics);
|
2020-02-27 13:01:39 +01:00
|
|
|
return GetTextMetricsA(font->hdc, metrics);
|
2008-03-14 14:12:30 +01:00
|
|
|
}
|
|
|
|
|
2011-01-27 00:28:41 +01:00
|
|
|
static BOOL WINAPI ID3DXFontImpl_GetTextMetricsW(ID3DXFont *iface, TEXTMETRICW *metrics)
|
2008-03-14 14:12:30 +01:00
|
|
|
{
|
2020-02-27 13:01:39 +01:00
|
|
|
struct d3dx_font *font = impl_from_ID3DXFont(iface);
|
2012-06-19 01:15:36 +02:00
|
|
|
TRACE("iface %p, metrics %p\n", iface, metrics);
|
2020-02-27 13:01:39 +01:00
|
|
|
return GetTextMetricsW(font->hdc, metrics);
|
2008-03-14 14:12:30 +01:00
|
|
|
}
|
|
|
|
|
2011-01-27 00:28:41 +01:00
|
|
|
static HDC WINAPI ID3DXFontImpl_GetDC(ID3DXFont *iface)
|
2008-03-14 14:12:30 +01:00
|
|
|
{
|
2020-02-27 13:01:39 +01:00
|
|
|
struct d3dx_font *font = impl_from_ID3DXFont(iface);
|
2012-06-19 01:15:36 +02:00
|
|
|
TRACE("iface %p\n", iface);
|
2020-02-27 13:01:39 +01:00
|
|
|
return font->hdc;
|
2008-03-14 14:12:30 +01:00
|
|
|
}
|
|
|
|
|
2011-01-27 00:28:41 +01:00
|
|
|
static HRESULT WINAPI ID3DXFontImpl_GetGlyphData(ID3DXFont *iface, UINT glyph,
|
2020-02-27 13:01:40 +01:00
|
|
|
IDirect3DTexture9 **texture, RECT *black_box, POINT *cell_inc)
|
2008-03-14 14:12:30 +01:00
|
|
|
{
|
2020-02-27 13:01:40 +01:00
|
|
|
struct d3dx_font *font = impl_from_ID3DXFont(iface);
|
|
|
|
struct wine_rb_entry *entry;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("iface %p, glyph %#x, texture %p, black_box %p, cell_inc %p.\n",
|
|
|
|
iface, glyph, texture, black_box, cell_inc);
|
|
|
|
|
|
|
|
hr = ID3DXFont_PreloadGlyphs(iface, glyph, glyph);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
entry = wine_rb_get(&font->glyph_tree, ULongToPtr(glyph));
|
|
|
|
if (entry)
|
|
|
|
{
|
|
|
|
struct d3dx_glyph *current_glyph = WINE_RB_ENTRY_VALUE(entry, struct d3dx_glyph, entry);
|
|
|
|
|
|
|
|
if (cell_inc)
|
|
|
|
*cell_inc = current_glyph->cell_inc;
|
|
|
|
if (black_box)
|
|
|
|
*black_box = current_glyph->black_box;
|
|
|
|
if (texture)
|
|
|
|
{
|
|
|
|
*texture = current_glyph->texture;
|
|
|
|
if (*texture)
|
|
|
|
IDirect3DTexture9_AddRef(current_glyph->texture);
|
|
|
|
}
|
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return D3DXERR_INVALIDDATA;
|
2008-03-14 14:12:30 +01:00
|
|
|
}
|
|
|
|
|
2011-01-27 00:28:41 +01:00
|
|
|
static HRESULT WINAPI ID3DXFontImpl_PreloadCharacters(ID3DXFont *iface, UINT first, UINT last)
|
2008-03-14 14:12:30 +01:00
|
|
|
{
|
2020-02-27 13:01:41 +01:00
|
|
|
struct d3dx_font *font = impl_from_ID3DXFont(iface);
|
|
|
|
unsigned int i, count, start, end;
|
|
|
|
WORD *indices;
|
|
|
|
WCHAR *chars;
|
|
|
|
|
|
|
|
TRACE("iface %p, first %u, last %u.\n", iface, first, last);
|
|
|
|
|
|
|
|
if (last < first)
|
|
|
|
return D3D_OK;
|
|
|
|
|
|
|
|
count = last - first + 1;
|
|
|
|
indices = heap_alloc(count * sizeof(*indices));
|
|
|
|
if (!indices)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
chars = heap_alloc(count * sizeof(*chars));
|
|
|
|
if (!chars)
|
|
|
|
{
|
|
|
|
heap_free(indices);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
chars[i] = first + i;
|
|
|
|
|
|
|
|
GetGlyphIndicesW(font->hdc, chars, count, indices, 0);
|
|
|
|
|
|
|
|
start = end = indices[0];
|
|
|
|
for (i = 1; i < count; ++i)
|
|
|
|
{
|
|
|
|
if (indices[i] == end + 1)
|
|
|
|
{
|
|
|
|
end = indices[i];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ID3DXFont_PreloadGlyphs(iface, start, end);
|
|
|
|
start = end = indices[i];
|
|
|
|
}
|
|
|
|
ID3DXFont_PreloadGlyphs(iface, start, end);
|
|
|
|
|
|
|
|
heap_free(chars);
|
|
|
|
heap_free(indices);
|
|
|
|
|
|
|
|
return D3D_OK;
|
2008-03-14 14:12:30 +01:00
|
|
|
}
|
|
|
|
|
2020-02-27 13:01:39 +01:00
|
|
|
static uint32_t morton_decode(uint32_t x)
|
|
|
|
{
|
|
|
|
x &= 0x55555555;
|
|
|
|
x = (x ^ (x >> 1)) & 0x33333333;
|
|
|
|
x = (x ^ (x >> 2)) & 0x0f0f0f0f;
|
|
|
|
x = (x ^ (x >> 4)) & 0x00ff00ff;
|
|
|
|
x = (x ^ (x >> 8)) & 0x0000ffff;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The glyphs are stored in a grid. Cell sizes vary between different font
|
|
|
|
* sizes.
|
|
|
|
*
|
|
|
|
* The grid is filled in Morton order:
|
|
|
|
* 1 2 5 6 17 18 21 22
|
|
|
|
* 3 4 7 8 19 20 23 24
|
|
|
|
* 9 10 13 14 25 26 29 30
|
|
|
|
* 11 12 15 16 27 28 31 32
|
|
|
|
* 33 34 ...
|
|
|
|
* ...
|
|
|
|
*
|
|
|
|
* i.e. we try to fill one small square, then three equal-sized squares so
|
|
|
|
* that we get one big square, etc.
|
|
|
|
*
|
|
|
|
* The glyphs are positioned around their baseline, which is located at y
|
|
|
|
* position glyph_size * i + tmAscent. Concerning the x position, the glyphs
|
|
|
|
* are centered around glyph_size * (i + 0.5). */
|
2011-01-27 00:28:41 +01:00
|
|
|
static HRESULT WINAPI ID3DXFontImpl_PreloadGlyphs(ID3DXFont *iface, UINT first, UINT last)
|
2008-03-14 14:12:30 +01:00
|
|
|
{
|
2020-02-27 13:01:39 +01:00
|
|
|
static const MAT2 mat = { {0,1}, {0,0}, {0,0}, {0,1} };
|
|
|
|
struct d3dx_font *font = impl_from_ID3DXFont(iface);
|
|
|
|
IDirect3DTexture9 *current_texture = NULL;
|
|
|
|
unsigned int size, stride, glyph, x, y;
|
|
|
|
struct d3dx_glyph *current_glyph;
|
|
|
|
D3DLOCKED_RECT lockrect;
|
|
|
|
GLYPHMETRICS metrics;
|
|
|
|
BOOL mapped = FALSE;
|
|
|
|
DWORD *pixel_data;
|
|
|
|
BYTE *buffer;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("iface %p, first %u, last %u.\n", iface, first, last);
|
|
|
|
|
|
|
|
if (last < first)
|
|
|
|
return D3D_OK;
|
|
|
|
|
|
|
|
if (font->texture_count)
|
|
|
|
current_texture = font->textures[font->texture_count - 1];
|
|
|
|
|
|
|
|
for (glyph = first; glyph <= last; ++glyph)
|
|
|
|
{
|
|
|
|
if (wine_rb_get(&font->glyph_tree, ULongToPtr(glyph)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
current_glyph = heap_alloc(sizeof(*current_glyph));
|
|
|
|
if (!current_glyph)
|
|
|
|
{
|
|
|
|
if (mapped)
|
|
|
|
IDirect3DTexture9_UnlockRect(current_texture, 0);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
current_glyph->id = glyph;
|
|
|
|
current_glyph->texture = NULL;
|
|
|
|
wine_rb_put(&font->glyph_tree, ULongToPtr(current_glyph->id), ¤t_glyph->entry);
|
|
|
|
|
|
|
|
size = GetGlyphOutlineW(font->hdc, glyph, GGO_GLYPH_INDEX | GGO_GRAY8_BITMAP, &metrics, 0, NULL, &mat);
|
|
|
|
if (size == GDI_ERROR)
|
|
|
|
{
|
|
|
|
WARN("GetGlyphOutlineW failed.\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!size)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
buffer = heap_alloc(size);
|
|
|
|
if (!buffer)
|
|
|
|
{
|
|
|
|
if (mapped)
|
|
|
|
IDirect3DTexture9_UnlockRect(current_texture, 0);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
GetGlyphOutlineW(font->hdc, glyph, GGO_GLYPH_INDEX | GGO_GRAY8_BITMAP, &metrics, size, buffer, &mat);
|
|
|
|
|
|
|
|
if (font->texture_pos == font->glyphs_per_texture)
|
|
|
|
{
|
|
|
|
unsigned int new_texture_count = font->texture_count + 1;
|
|
|
|
IDirect3DTexture9 **new_textures;
|
|
|
|
|
|
|
|
if (mapped)
|
|
|
|
IDirect3DTexture9_UnlockRect(current_texture, 0);
|
|
|
|
mapped = FALSE;
|
|
|
|
new_textures = heap_realloc(font->textures, new_texture_count * sizeof(*new_textures));
|
|
|
|
if (!new_textures)
|
|
|
|
{
|
|
|
|
heap_free(buffer);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
font->textures = new_textures;
|
|
|
|
|
|
|
|
if (FAILED(hr = IDirect3DDevice9_CreateTexture(font->device, font->texture_size,
|
|
|
|
font->texture_size, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED,
|
|
|
|
&font->textures[font->texture_count], NULL)))
|
|
|
|
{
|
|
|
|
heap_free(buffer);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
current_texture = font->textures[font->texture_count++];
|
|
|
|
font->texture_pos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mapped)
|
|
|
|
{
|
|
|
|
if (FAILED(hr = IDirect3DTexture9_LockRect(current_texture, 0, &lockrect, NULL, 0)))
|
|
|
|
{
|
|
|
|
heap_free(buffer);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
mapped = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
x = morton_decode(font->texture_pos) * font->glyph_size;
|
|
|
|
y = morton_decode(font->texture_pos >> 1) * font->glyph_size;
|
|
|
|
|
|
|
|
current_glyph->black_box.left = x - metrics.gmptGlyphOrigin.x + font->glyph_size / 2
|
|
|
|
- metrics.gmBlackBoxX / 2;
|
|
|
|
current_glyph->black_box.top = y - metrics.gmptGlyphOrigin.y + font->metrics.tmAscent + 1;
|
|
|
|
current_glyph->black_box.right = current_glyph->black_box.left + metrics.gmBlackBoxX;
|
|
|
|
current_glyph->black_box.bottom = current_glyph->black_box.top + metrics.gmBlackBoxY;
|
|
|
|
current_glyph->cell_inc.x = metrics.gmptGlyphOrigin.x - 1;
|
|
|
|
current_glyph->cell_inc.y = font->metrics.tmAscent - metrics.gmptGlyphOrigin.y - 1;
|
|
|
|
current_glyph->texture = current_texture;
|
|
|
|
|
|
|
|
pixel_data = lockrect.pBits;
|
|
|
|
stride = (metrics.gmBlackBoxX + 3) & ~3;
|
|
|
|
for (y = 0; y < metrics.gmBlackBoxY; ++y)
|
|
|
|
for (x = 0; x < metrics.gmBlackBoxX; ++x)
|
|
|
|
pixel_data[(current_glyph->black_box.top + y) * lockrect.Pitch / 4
|
|
|
|
+ current_glyph->black_box.left + x] =
|
|
|
|
(buffer[y * stride + x] * 255 / 64 << 24) | 0x00ffffffu;
|
|
|
|
|
|
|
|
heap_free(buffer);
|
|
|
|
++font->texture_pos;
|
|
|
|
}
|
|
|
|
if (mapped)
|
|
|
|
IDirect3DTexture9_UnlockRect(current_texture, 0);
|
|
|
|
|
|
|
|
return D3D_OK;
|
2008-03-14 14:12:30 +01:00
|
|
|
}
|
|
|
|
|
2012-06-19 01:15:36 +02:00
|
|
|
static HRESULT WINAPI ID3DXFontImpl_PreloadTextA(ID3DXFont *iface, const char *string, INT count)
|
2008-03-14 14:12:30 +01:00
|
|
|
{
|
2020-03-03 09:38:27 +01:00
|
|
|
WCHAR *wstr;
|
|
|
|
HRESULT hr;
|
|
|
|
int countW;
|
|
|
|
|
|
|
|
TRACE("iface %p, string %s, count %d.\n", iface, debugstr_an(string, count), count);
|
|
|
|
|
|
|
|
if (!string && !count)
|
|
|
|
return D3D_OK;
|
|
|
|
|
|
|
|
if (!string)
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
countW = MultiByteToWideChar(CP_ACP, 0, string, count < 0 ? -1 : count, NULL, 0);
|
|
|
|
|
|
|
|
wstr = heap_alloc(countW * sizeof(*wstr));
|
|
|
|
if (!wstr)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, string, count < 0 ? -1 : count, wstr, countW);
|
|
|
|
|
|
|
|
hr = ID3DXFont_PreloadTextW(iface, wstr, count < 0 ? countW - 1 : countW);
|
|
|
|
|
|
|
|
heap_free(wstr);
|
|
|
|
|
|
|
|
return hr;
|
2008-03-14 14:12:30 +01:00
|
|
|
}
|
|
|
|
|
2012-06-19 01:15:36 +02:00
|
|
|
static HRESULT WINAPI ID3DXFontImpl_PreloadTextW(ID3DXFont *iface, const WCHAR *string, INT count)
|
2008-03-14 14:12:30 +01:00
|
|
|
{
|
2020-03-03 09:38:27 +01:00
|
|
|
struct d3dx_font *font = impl_from_ID3DXFont(iface);
|
|
|
|
WORD *indices;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
TRACE("iface %p, string %s, count %d.\n", iface, debugstr_wn(string, count), count);
|
|
|
|
|
|
|
|
if (!string && !count)
|
|
|
|
return D3D_OK;
|
|
|
|
|
|
|
|
if (!string)
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
if (count < 0)
|
|
|
|
count = lstrlenW(string);
|
|
|
|
|
|
|
|
indices = heap_alloc(count * sizeof(*indices));
|
|
|
|
if (!indices)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
GetGlyphIndicesW(font->hdc, string, count, indices, 0);
|
|
|
|
|
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
ID3DXFont_PreloadGlyphs(iface, indices[i], indices[i]);
|
|
|
|
|
|
|
|
heap_free(indices);
|
|
|
|
|
|
|
|
return D3D_OK;
|
2008-03-14 14:12:30 +01:00
|
|
|
}
|
|
|
|
|
2012-06-01 17:22:50 +02:00
|
|
|
static INT WINAPI ID3DXFontImpl_DrawTextA(ID3DXFont *iface, ID3DXSprite *sprite,
|
|
|
|
const char *string, INT count, RECT *rect, DWORD format, D3DCOLOR color)
|
2008-03-14 14:12:30 +01:00
|
|
|
{
|
2020-03-03 09:38:28 +01:00
|
|
|
int ret, countW;
|
|
|
|
WCHAR *wstr;
|
|
|
|
|
|
|
|
TRACE("iface %p, sprite %p, string %s, count %d, rect %s, format %#x, color 0x%08x.\n",
|
|
|
|
iface, sprite, debugstr_an(string, count), count, wine_dbgstr_rect(rect), format, color);
|
|
|
|
|
|
|
|
if (!string || !count)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
countW = MultiByteToWideChar(CP_ACP, 0, string, count < 0 ? -1 : count, NULL, 0);
|
|
|
|
|
|
|
|
if (!countW)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
wstr = heap_alloc_zero(countW * sizeof(*wstr));
|
|
|
|
if (!wstr)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, string, count < 0 ? -1 : count, wstr, countW);
|
|
|
|
|
|
|
|
ret = ID3DXFont_DrawTextW(iface, sprite, wstr, count < 0 ? countW - 1 : countW,
|
|
|
|
rect, format, color);
|
|
|
|
|
|
|
|
heap_free(wstr);
|
|
|
|
|
|
|
|
return ret;
|
2008-03-14 14:12:30 +01:00
|
|
|
}
|
|
|
|
|
2020-03-05 22:39:59 +01:00
|
|
|
static void word_break(HDC hdc, const WCHAR *str, unsigned int *str_len,
|
2020-03-10 11:21:38 +01:00
|
|
|
unsigned int chars_fit, unsigned int *chars_used, DWORD format, SIZE *size)
|
2020-03-05 22:39:59 +01:00
|
|
|
{
|
|
|
|
SCRIPT_LOGATTR *sla;
|
|
|
|
SCRIPT_ANALYSIS sa;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
*chars_used = 0;
|
|
|
|
|
|
|
|
sla = heap_alloc(*str_len * sizeof(*sla));
|
|
|
|
if (!sla)
|
|
|
|
return;
|
|
|
|
|
|
|
|
memset(&sa, 0, sizeof(sa));
|
|
|
|
sa.eScript = SCRIPT_UNDEFINED;
|
|
|
|
|
|
|
|
ScriptBreak(str, *str_len, &sa, sla);
|
|
|
|
|
|
|
|
/* Work back from the last character that did fit to a place where we can break */
|
|
|
|
i = chars_fit;
|
|
|
|
while (i > 0 && !sla[i].fSoftBreak) /* chars_fit < *str_len so this is valid */
|
|
|
|
--i;
|
|
|
|
|
|
|
|
/* If the there is no word that fits put in all characters that do fit */
|
2020-03-10 11:21:38 +01:00
|
|
|
if (!sla[i].fSoftBreak || (format & DT_SINGLELINE))
|
2020-03-05 22:39:59 +01:00
|
|
|
i = chars_fit;
|
|
|
|
|
|
|
|
*chars_used = i;
|
|
|
|
if (sla[i].fWhiteSpace)
|
|
|
|
++(*chars_used);
|
|
|
|
|
|
|
|
/* Remove extra spaces */
|
|
|
|
while (i > 0 && sla[i-1].fWhiteSpace)
|
|
|
|
--i;
|
|
|
|
*str_len = i;
|
|
|
|
|
|
|
|
/* Remeasure the string */
|
|
|
|
GetTextExtentExPointW(hdc, str, *str_len, 0, NULL, NULL, size);
|
|
|
|
heap_free(sla);
|
|
|
|
}
|
|
|
|
|
2020-04-01 20:27:12 +02:00
|
|
|
static const WCHAR *read_line(HDC hdc, const WCHAR *str, unsigned int *count,
|
2020-03-10 11:21:39 +01:00
|
|
|
WCHAR *dest, unsigned int *dest_len, int width, DWORD format, SIZE *size)
|
2020-03-05 22:39:57 +01:00
|
|
|
{
|
2020-04-01 20:27:12 +02:00
|
|
|
unsigned int orig_count = *count;
|
2020-03-05 22:39:57 +01:00
|
|
|
unsigned int i = 0;
|
2020-03-05 22:39:59 +01:00
|
|
|
int num_fit;
|
2020-03-05 22:39:57 +01:00
|
|
|
|
|
|
|
*dest_len = 0;
|
2020-03-10 11:21:38 +01:00
|
|
|
while (*count && (str[i] != '\n' || (format & DT_SINGLELINE)))
|
2020-03-05 22:39:57 +01:00
|
|
|
{
|
|
|
|
--(*count);
|
2020-03-10 11:21:38 +01:00
|
|
|
if (str[i] != '\r' && str[i] != '\n')
|
2020-03-05 22:39:57 +01:00
|
|
|
dest[(*dest_len)++] = str[i];
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
2020-03-05 22:39:59 +01:00
|
|
|
num_fit = 0;
|
2020-03-10 11:21:39 +01:00
|
|
|
GetTextExtentExPointW(hdc, dest, *dest_len, width, &num_fit, NULL, size);
|
2020-03-05 22:39:59 +01:00
|
|
|
|
2020-03-10 11:21:38 +01:00
|
|
|
if (num_fit < *dest_len)
|
2020-03-05 22:39:59 +01:00
|
|
|
{
|
2020-03-10 11:21:38 +01:00
|
|
|
if (format & DT_WORDBREAK)
|
|
|
|
{
|
|
|
|
unsigned int chars_used;
|
2020-03-05 22:39:59 +01:00
|
|
|
|
2020-03-10 11:21:39 +01:00
|
|
|
word_break(hdc, dest, dest_len, num_fit, &chars_used, format, size);
|
2020-03-10 11:21:38 +01:00
|
|
|
*count = orig_count - chars_used;
|
|
|
|
i = chars_used;
|
|
|
|
}
|
|
|
|
else if (format & DT_SINGLELINE)
|
|
|
|
{
|
|
|
|
*dest_len = num_fit;
|
|
|
|
*count = 0;
|
|
|
|
}
|
2020-03-05 22:39:59 +01:00
|
|
|
}
|
2020-03-05 22:39:57 +01:00
|
|
|
|
|
|
|
if (*count && str[i] == '\n')
|
|
|
|
{
|
|
|
|
--(*count);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*count)
|
|
|
|
return str + i;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-04-01 20:27:13 +02:00
|
|
|
static int compute_rect(struct d3dx_font *font, const WCHAR *string, unsigned int count,
|
|
|
|
WCHAR *line, RECT *rect, DWORD format)
|
|
|
|
{
|
|
|
|
int y, lh, width, top = rect->top;
|
|
|
|
int max_width = 0;
|
|
|
|
SIZE size;
|
|
|
|
|
|
|
|
y = rect->top;
|
|
|
|
lh = font->metrics.tmHeight;
|
|
|
|
width = rect->right - rect->left;
|
|
|
|
|
|
|
|
while (string)
|
|
|
|
{
|
|
|
|
unsigned int line_len;
|
|
|
|
|
|
|
|
string = read_line(font->hdc, string, &count, line, &line_len, width, format, &size);
|
|
|
|
|
|
|
|
if (size.cx > max_width)
|
|
|
|
max_width = size.cx;
|
|
|
|
|
|
|
|
y += lh;
|
|
|
|
if (!(format & DT_NOCLIP) && (y > rect->bottom))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-03-27 17:48:34 +01:00
|
|
|
if (format & DT_CENTER)
|
|
|
|
{
|
|
|
|
rect->left += (rect->right - rect->left - max_width) / 2;
|
|
|
|
rect->right = rect->left + max_width;
|
|
|
|
}
|
|
|
|
else if (format & DT_RIGHT)
|
|
|
|
{
|
|
|
|
rect->left = rect->right - max_width;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rect->right = rect->left + max_width;
|
|
|
|
}
|
|
|
|
|
2020-03-27 17:48:33 +01:00
|
|
|
if (format & DT_VCENTER)
|
|
|
|
{
|
|
|
|
rect->top += (rect->bottom - y) / 2;
|
|
|
|
rect->bottom = rect->top + y - top;
|
|
|
|
}
|
|
|
|
else if (format & DT_BOTTOM)
|
|
|
|
{
|
|
|
|
rect->top += rect->bottom - y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rect->bottom = y;
|
|
|
|
}
|
2020-04-01 20:27:13 +02:00
|
|
|
|
|
|
|
return rect->bottom - top;
|
|
|
|
}
|
|
|
|
|
2012-06-01 17:22:50 +02:00
|
|
|
static INT WINAPI ID3DXFontImpl_DrawTextW(ID3DXFont *iface, ID3DXSprite *sprite,
|
2020-04-01 20:27:12 +02:00
|
|
|
const WCHAR *string, INT in_count, RECT *rect, DWORD format, D3DCOLOR color)
|
2008-03-14 14:12:30 +01:00
|
|
|
{
|
2020-03-03 09:38:28 +01:00
|
|
|
struct d3dx_font *font = impl_from_ID3DXFont(iface);
|
2020-04-01 20:27:13 +02:00
|
|
|
int lh, x, y, width, top, ret = 0;
|
2020-03-03 09:38:28 +01:00
|
|
|
ID3DXSprite *target = sprite;
|
2020-04-01 20:27:12 +02:00
|
|
|
unsigned int count;
|
2020-04-01 20:27:13 +02:00
|
|
|
RECT r = {0};
|
2020-04-01 20:27:12 +02:00
|
|
|
WCHAR *line;
|
2020-03-10 11:21:39 +01:00
|
|
|
SIZE size;
|
2020-03-03 09:38:28 +01:00
|
|
|
|
2020-04-01 20:27:12 +02:00
|
|
|
TRACE("iface %p, sprite %p, string %s, in_count %d, rect %s, format %#x, color 0x%08x.\n",
|
|
|
|
iface, sprite, debugstr_wn(string, in_count), in_count, wine_dbgstr_rect(rect), format, color);
|
2020-03-03 09:38:28 +01:00
|
|
|
|
|
|
|
if (!string)
|
|
|
|
return 0;
|
|
|
|
|
2020-04-01 20:27:12 +02:00
|
|
|
count = in_count < 0 ? lstrlenW(string) : in_count;
|
2020-03-03 09:38:28 +01:00
|
|
|
|
|
|
|
if (!count)
|
|
|
|
return 0;
|
|
|
|
|
2020-03-05 22:39:58 +01:00
|
|
|
if (format & DT_CALCRECT)
|
|
|
|
format |= DT_NOCLIP;
|
|
|
|
|
2020-03-10 11:21:38 +01:00
|
|
|
if (format & DT_SINGLELINE)
|
|
|
|
format &= ~DT_WORDBREAK;
|
|
|
|
|
2020-03-05 22:39:57 +01:00
|
|
|
line = heap_alloc(count * sizeof(*line));
|
|
|
|
if (!line)
|
|
|
|
return 0;
|
|
|
|
|
2020-03-27 17:48:33 +01:00
|
|
|
if (!rect || format & (DT_CALCRECT | DT_VCENTER | DT_BOTTOM))
|
2020-04-01 20:27:13 +02:00
|
|
|
{
|
|
|
|
if (!rect)
|
|
|
|
{
|
|
|
|
rect = &r;
|
|
|
|
format |= DT_NOCLIP;
|
|
|
|
}
|
2020-03-27 17:48:33 +01:00
|
|
|
else if (!(format & DT_CALCRECT))
|
|
|
|
{
|
|
|
|
r = *rect;
|
|
|
|
rect = &r;
|
|
|
|
}
|
2020-04-01 20:27:13 +02:00
|
|
|
|
|
|
|
top = rect->top;
|
|
|
|
|
|
|
|
ret = compute_rect(font, string, count, line, rect, format);
|
|
|
|
|
|
|
|
if (format & DT_CALCRECT)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
top = rect->top;
|
|
|
|
}
|
|
|
|
|
|
|
|
y = rect->top;
|
|
|
|
lh = font->metrics.tmHeight;
|
|
|
|
width = rect->right - rect->left;
|
|
|
|
|
|
|
|
if (!sprite)
|
2020-03-03 09:38:28 +01:00
|
|
|
{
|
|
|
|
D3DXCreateSprite(font->device, &target);
|
|
|
|
ID3DXSprite_Begin(target, 0);
|
|
|
|
}
|
|
|
|
|
2020-03-05 22:39:57 +01:00
|
|
|
while (string)
|
2020-03-03 09:38:28 +01:00
|
|
|
{
|
2020-04-01 20:27:13 +02:00
|
|
|
unsigned int line_len, i;
|
|
|
|
GCP_RESULTSW results;
|
|
|
|
D3DXVECTOR3 pos;
|
2020-03-03 09:38:28 +01:00
|
|
|
|
2020-03-10 11:21:39 +01:00
|
|
|
string = read_line(font->hdc, string, &count, line, &line_len, width, format, &size);
|
2020-03-03 09:38:28 +01:00
|
|
|
|
2020-03-27 17:48:34 +01:00
|
|
|
if (format & DT_CENTER)
|
|
|
|
x = (rect->left + rect->right - size.cx) / 2;
|
|
|
|
else if (format & DT_RIGHT)
|
|
|
|
x = rect->right - size.cx;
|
|
|
|
else
|
|
|
|
x = rect->left;
|
|
|
|
|
2020-04-01 20:27:13 +02:00
|
|
|
memset(&results, 0, sizeof(results));
|
|
|
|
results.nGlyphs = line_len;
|
2020-03-03 09:38:28 +01:00
|
|
|
|
2020-04-01 20:27:13 +02:00
|
|
|
results.lpCaretPos = heap_alloc(line_len * sizeof(*results.lpCaretPos));
|
|
|
|
if (!results.lpCaretPos)
|
|
|
|
goto cleanup;
|
2020-03-03 09:38:28 +01:00
|
|
|
|
2020-04-01 20:27:13 +02:00
|
|
|
results.lpGlyphs = heap_alloc(line_len * sizeof(*results.lpGlyphs));
|
|
|
|
if (!results.lpGlyphs)
|
|
|
|
{
|
|
|
|
heap_free(results.lpCaretPos);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2020-03-03 09:38:28 +01:00
|
|
|
|
2020-04-01 20:27:13 +02:00
|
|
|
GetCharacterPlacementW(font->hdc, line, line_len, 0, &results, 0);
|
2020-03-03 09:38:28 +01:00
|
|
|
|
2020-04-01 20:27:13 +02:00
|
|
|
for (i = 0; i < results.nGlyphs; ++i)
|
|
|
|
{
|
|
|
|
IDirect3DTexture9 *texture;
|
|
|
|
POINT cell_inc;
|
|
|
|
RECT black_box;
|
2020-03-03 09:38:28 +01:00
|
|
|
|
2020-04-01 20:27:13 +02:00
|
|
|
ID3DXFont_GetGlyphData(iface, results.lpGlyphs[i], &texture, &black_box, &cell_inc);
|
2020-03-05 22:39:57 +01:00
|
|
|
|
2020-04-01 20:27:13 +02:00
|
|
|
if (!texture)
|
|
|
|
continue;
|
2020-03-05 22:39:57 +01:00
|
|
|
|
2020-04-01 20:27:13 +02:00
|
|
|
pos.x = cell_inc.x + x + results.lpCaretPos[i];
|
|
|
|
pos.y = cell_inc.y + y;
|
2020-03-05 22:39:57 +01:00
|
|
|
|
2020-04-01 20:27:13 +02:00
|
|
|
ID3DXSprite_Draw(target, texture, &black_box, NULL, &pos, color);
|
|
|
|
IDirect3DTexture9_Release(texture);
|
2020-03-10 11:21:39 +01:00
|
|
|
}
|
|
|
|
|
2020-04-01 20:27:13 +02:00
|
|
|
heap_free(results.lpCaretPos);
|
|
|
|
heap_free(results.lpGlyphs);
|
|
|
|
|
2020-03-05 22:39:57 +01:00
|
|
|
y += lh;
|
2020-04-01 20:27:13 +02:00
|
|
|
if (!(DT_NOCLIP & format) && (y > rect->bottom))
|
2020-03-05 22:39:58 +01:00
|
|
|
break;
|
2020-03-03 09:38:28 +01:00
|
|
|
}
|
|
|
|
|
2020-04-01 20:27:13 +02:00
|
|
|
ret = y - top;
|
2020-03-03 09:38:28 +01:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (target != sprite)
|
|
|
|
{
|
|
|
|
ID3DXSprite_End(target);
|
|
|
|
ID3DXSprite_Release(target);
|
|
|
|
}
|
|
|
|
|
2020-03-05 22:39:57 +01:00
|
|
|
heap_free(line);
|
|
|
|
|
2020-03-03 09:38:28 +01:00
|
|
|
return ret;
|
2008-03-14 14:12:30 +01:00
|
|
|
}
|
|
|
|
|
2011-01-27 00:28:41 +01:00
|
|
|
static HRESULT WINAPI ID3DXFontImpl_OnLostDevice(ID3DXFont *iface)
|
2008-03-14 14:12:30 +01:00
|
|
|
{
|
2012-06-19 01:15:36 +02:00
|
|
|
FIXME("iface %p stub!\n", iface);
|
2008-03-14 14:12:30 +01:00
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-01-27 00:28:41 +01:00
|
|
|
static HRESULT WINAPI ID3DXFontImpl_OnResetDevice(ID3DXFont *iface)
|
2008-03-14 14:12:30 +01:00
|
|
|
{
|
2012-06-19 01:15:36 +02:00
|
|
|
FIXME("iface %p stub\n", iface);
|
2008-03-14 14:12:30 +01:00
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const ID3DXFontVtbl D3DXFont_Vtbl =
|
|
|
|
{
|
|
|
|
/*** IUnknown methods ***/
|
|
|
|
ID3DXFontImpl_QueryInterface,
|
|
|
|
ID3DXFontImpl_AddRef,
|
|
|
|
ID3DXFontImpl_Release,
|
|
|
|
/*** ID3DXFont methods ***/
|
|
|
|
ID3DXFontImpl_GetDevice,
|
|
|
|
ID3DXFontImpl_GetDescA,
|
|
|
|
ID3DXFontImpl_GetDescW,
|
|
|
|
ID3DXFontImpl_GetTextMetricsA,
|
|
|
|
ID3DXFontImpl_GetTextMetricsW,
|
|
|
|
ID3DXFontImpl_GetDC,
|
|
|
|
ID3DXFontImpl_GetGlyphData,
|
|
|
|
ID3DXFontImpl_PreloadCharacters,
|
|
|
|
ID3DXFontImpl_PreloadGlyphs,
|
|
|
|
ID3DXFontImpl_PreloadTextA,
|
|
|
|
ID3DXFontImpl_PreloadTextW,
|
|
|
|
ID3DXFontImpl_DrawTextA,
|
|
|
|
ID3DXFontImpl_DrawTextW,
|
|
|
|
ID3DXFontImpl_OnLostDevice,
|
|
|
|
ID3DXFontImpl_OnResetDevice
|
|
|
|
};
|
|
|
|
|
2012-10-28 20:54:52 +01:00
|
|
|
HRESULT WINAPI D3DXCreateFontA(struct IDirect3DDevice9 *device, INT height, UINT width,
|
|
|
|
UINT weight, UINT miplevels, BOOL italic, DWORD charset, DWORD precision, DWORD quality,
|
|
|
|
DWORD pitchandfamily, const char *facename, struct ID3DXFont **font)
|
2008-03-14 14:12:30 +01:00
|
|
|
{
|
|
|
|
D3DXFONT_DESCA desc;
|
|
|
|
|
2009-06-05 13:06:25 +02:00
|
|
|
if( !device || !font ) return D3DERR_INVALIDCALL;
|
2008-03-14 14:12:30 +01:00
|
|
|
|
|
|
|
desc.Height=height;
|
|
|
|
desc.Width=width;
|
|
|
|
desc.Weight=weight;
|
|
|
|
desc.MipLevels=miplevels;
|
|
|
|
desc.Italic=italic;
|
|
|
|
desc.CharSet=charset;
|
|
|
|
desc.OutputPrecision=precision;
|
|
|
|
desc.Quality=quality;
|
|
|
|
desc.PitchAndFamily=pitchandfamily;
|
2009-06-05 13:06:25 +02:00
|
|
|
if(facename != NULL) lstrcpyA(desc.FaceName, facename);
|
|
|
|
else desc.FaceName[0] = '\0';
|
2008-03-14 14:12:30 +01:00
|
|
|
|
|
|
|
return D3DXCreateFontIndirectA(device, &desc, font);
|
|
|
|
}
|
|
|
|
|
2012-06-19 01:15:36 +02:00
|
|
|
HRESULT WINAPI D3DXCreateFontW(IDirect3DDevice9 *device, INT height, UINT width, UINT weight, UINT miplevels, BOOL italic, DWORD charset,
|
|
|
|
DWORD precision, DWORD quality, DWORD pitchandfamily, const WCHAR *facename, ID3DXFont **font)
|
2008-03-14 14:12:30 +01:00
|
|
|
{
|
|
|
|
D3DXFONT_DESCW desc;
|
|
|
|
|
2009-06-05 13:06:25 +02:00
|
|
|
if( !device || !font ) return D3DERR_INVALIDCALL;
|
2008-03-14 14:12:30 +01:00
|
|
|
|
|
|
|
desc.Height=height;
|
|
|
|
desc.Width=width;
|
|
|
|
desc.Weight=weight;
|
|
|
|
desc.MipLevels=miplevels;
|
|
|
|
desc.Italic=italic;
|
|
|
|
desc.CharSet=charset;
|
|
|
|
desc.OutputPrecision=precision;
|
|
|
|
desc.Quality=quality;
|
|
|
|
desc.PitchAndFamily=pitchandfamily;
|
2019-05-30 09:18:02 +02:00
|
|
|
if(facename != NULL) lstrcpyW(desc.FaceName, facename);
|
2009-06-05 13:06:25 +02:00
|
|
|
else desc.FaceName[0] = '\0';
|
2008-03-14 14:12:30 +01:00
|
|
|
|
|
|
|
return D3DXCreateFontIndirectW(device, &desc, font);
|
|
|
|
}
|
|
|
|
|
2008-07-26 19:20:33 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* D3DXCreateFontIndirectA (D3DX9_36.@)
|
|
|
|
*/
|
2012-06-19 01:15:36 +02:00
|
|
|
HRESULT WINAPI D3DXCreateFontIndirectA(IDirect3DDevice9 *device, const D3DXFONT_DESCA *desc, ID3DXFont **font)
|
2008-03-14 14:12:30 +01:00
|
|
|
{
|
|
|
|
D3DXFONT_DESCW widedesc;
|
|
|
|
|
2009-06-05 13:06:25 +02:00
|
|
|
if( !device || !desc || !font ) return D3DERR_INVALIDCALL;
|
2008-03-14 14:12:30 +01:00
|
|
|
|
|
|
|
/* Copy everything but the last structure member. This requires the
|
|
|
|
two D3DXFONT_DESC structures to be equal until the FaceName member */
|
|
|
|
memcpy(&widedesc, desc, FIELD_OFFSET(D3DXFONT_DESCA, FaceName));
|
2018-11-13 20:33:39 +01:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, desc->FaceName, -1, widedesc.FaceName, ARRAY_SIZE(widedesc.FaceName));
|
2008-03-14 14:12:30 +01:00
|
|
|
return D3DXCreateFontIndirectW(device, &widedesc, font);
|
|
|
|
}
|
|
|
|
|
2008-07-26 19:20:33 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* D3DXCreateFontIndirectW (D3DX9_36.@)
|
|
|
|
*/
|
2012-06-19 01:15:36 +02:00
|
|
|
HRESULT WINAPI D3DXCreateFontIndirectW(IDirect3DDevice9 *device, const D3DXFONT_DESCW *desc, ID3DXFont **font)
|
2008-03-14 14:12:30 +01:00
|
|
|
{
|
2009-06-05 13:06:25 +02:00
|
|
|
D3DDEVICE_CREATION_PARAMETERS cpars;
|
2012-06-19 01:15:36 +02:00
|
|
|
struct d3dx_font *object;
|
2020-02-27 13:01:39 +01:00
|
|
|
D3DDISPLAYMODE mode;
|
2009-06-05 13:06:25 +02:00
|
|
|
IDirect3D9 *d3d;
|
|
|
|
HRESULT hr;
|
2010-04-02 08:54:54 +02:00
|
|
|
|
2012-11-03 18:06:03 +01:00
|
|
|
TRACE("(%p, %p, %p)\n", device, desc, font);
|
2008-03-14 14:12:30 +01:00
|
|
|
|
2009-06-05 13:06:25 +02:00
|
|
|
if( !device || !desc || !font ) return D3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
/* the device MUST support D3DFMT_A8R8G8B8 */
|
|
|
|
IDirect3DDevice9_GetDirect3D(device, &d3d);
|
|
|
|
IDirect3DDevice9_GetCreationParameters(device, &cpars);
|
|
|
|
IDirect3DDevice9_GetDisplayMode(device, 0, &mode);
|
|
|
|
hr = IDirect3D9_CheckDeviceFormat(d3d, cpars.AdapterOrdinal, cpars.DeviceType, mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_A8R8G8B8);
|
2020-02-27 13:01:39 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2009-06-05 13:06:25 +02:00
|
|
|
IDirect3D9_Release(d3d);
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
IDirect3D9_Release(d3d);
|
2008-03-14 14:12:30 +01:00
|
|
|
|
2020-02-27 13:01:39 +01:00
|
|
|
object = heap_alloc_zero(sizeof(*object));
|
|
|
|
if (!object)
|
|
|
|
{
|
|
|
|
*font = NULL;
|
2008-03-14 14:12:30 +01:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2011-01-27 00:28:41 +01:00
|
|
|
object->ID3DXFont_iface.lpVtbl = &D3DXFont_Vtbl;
|
2020-02-27 13:01:39 +01:00
|
|
|
object->ref = 1;
|
|
|
|
object->device = device;
|
|
|
|
object->desc = *desc;
|
2008-03-14 14:12:30 +01:00
|
|
|
|
2009-06-05 13:45:12 +02:00
|
|
|
object->hdc = CreateCompatibleDC(NULL);
|
2020-02-27 13:01:39 +01:00
|
|
|
if (!object->hdc)
|
|
|
|
{
|
|
|
|
heap_free(object);
|
2009-06-05 13:45:12 +02:00
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
2009-06-05 13:57:23 +02:00
|
|
|
object->hfont = CreateFontW(desc->Height, desc->Width, 0, 0, desc->Weight, desc->Italic, FALSE, FALSE, desc->CharSet,
|
|
|
|
desc->OutputPrecision, CLIP_DEFAULT_PRECIS, desc->Quality, desc->PitchAndFamily, desc->FaceName);
|
2020-02-27 13:01:39 +01:00
|
|
|
if (!object->hfont)
|
|
|
|
{
|
2009-06-05 13:57:23 +02:00
|
|
|
DeleteDC(object->hdc);
|
2020-02-27 13:01:39 +01:00
|
|
|
heap_free(object);
|
2009-06-05 13:57:23 +02:00
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
SelectObject(object->hdc, object->hfont);
|
|
|
|
|
2020-02-27 13:01:39 +01:00
|
|
|
wine_rb_init(&object->glyph_tree, glyph_rb_compare);
|
|
|
|
|
|
|
|
if (!GetTextMetricsW(object->hdc, &object->metrics))
|
|
|
|
{
|
|
|
|
DeleteObject(object->hfont);
|
|
|
|
DeleteDC(object->hdc);
|
|
|
|
heap_free(object);
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
object->glyph_size = make_pow2(object->metrics.tmHeight);
|
|
|
|
|
|
|
|
object->texture_size = object->glyph_size;
|
|
|
|
if (object->glyph_size < 256)
|
|
|
|
object->texture_size = min(256, object->texture_size * 16);
|
|
|
|
|
|
|
|
object->glyphs_per_texture = object->texture_size * object->texture_size
|
|
|
|
/ (object->glyph_size * object->glyph_size);
|
|
|
|
object->texture_pos = object->glyphs_per_texture;
|
|
|
|
|
2009-06-05 13:15:44 +02:00
|
|
|
IDirect3DDevice9_AddRef(device);
|
2020-02-27 13:01:39 +01:00
|
|
|
*font = &object->ID3DXFont_iface;
|
2008-03-14 14:12:30 +01:00
|
|
|
|
|
|
|
return D3D_OK;
|
|
|
|
}
|