summaryrefslogtreecommitdiffstats
path: root/libass
diff options
context:
space:
mode:
Diffstat (limited to 'libass')
-rw-r--r--libass/Makefile.am2
-rw-r--r--libass/ass_directwrite.c (renamed from libass/ass_directwrite.cpp)429
-rw-r--r--libass/dwrite.h668
3 files changed, 910 insertions, 189 deletions
diff --git a/libass/Makefile.am b/libass/Makefile.am
index 4e266f1..2d7bc44 100644
--- a/libass/Makefile.am
+++ b/libass/Makefile.am
@@ -19,7 +19,7 @@ SRC_INTEL_RASTERIZER = x86/rasterizer.asm
SRC_RASTERIZER = ass_rasterizer.h ass_rasterizer.c ass_rasterizer_c.c
-SRC_DIRECTWRITE = ass_directwrite.cpp ass_directwrite.h
+SRC_DIRECTWRITE = ass_directwrite.c ass_directwrite.h dwrite.h
lib_LTLIBRARIES = libass.la
libass_la_SOURCES = ass.c ass_cache.c ass_font.c ass_fontselect.c ass_render.c \
diff --git a/libass/ass_directwrite.cpp b/libass/ass_directwrite.c
index 062aa31..483af50 100644
--- a/libass/ass_directwrite.cpp
+++ b/libass/ass_directwrite.c
@@ -15,15 +15,22 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#define COBJMACROS
#include "config.h"
-#include <dwrite.h>
+#include <initguid.h>
+#include <ole2.h>
+#include <shobjidl.h>
+
+#include "dwrite.h"
+
+DEFINE_GUID(IID_IDWriteFactory, 0xb859ee5a,0xd838,0x4b5b,0xa2,0xe8,0x1a,0xdc,0x7d,0x93,0xdb,0x48);
+DEFINE_GUID(IID_IDWritePixelSnapping, 0xeaf3a2da,0xecf4,0x4d24,0xb6,0x44,0xb3,0x4f,0x68,0x42,0x02,0x4b);
+DEFINE_GUID(IID_IDWriteTextRenderer, 0xef8a8135,0x5cc6,0x45fe,0x88,0x25,0xc5,0xa0,0x72,0x4e,0xb8,0x19);
-extern "C" {
#include "ass_directwrite.h"
#include "ass_utils.h"
-}
#define NAME_MAX_LENGTH 256
#define FALLBACK_DEFAULT_FONT L"Arial"
@@ -45,137 +52,173 @@ typedef struct {
* Custom text renderer class for logging the fonts used. It does not
* actually render anything or do anything apart from that.
*/
-class FallbackLogTextRenderer : public IDWriteTextRenderer {
-public:
- FallbackLogTextRenderer(IDWriteFactory *factory)
- : dw_factory(factory), ref_count(0)
- {}
-
- IFACEMETHOD(IsPixelSnappingDisabled)(
- _In_opt_ void* clientDrawingContext,
- _Out_ BOOL* isDisabled
- )
- {
- *isDisabled = true;
- return S_OK;
- }
- IFACEMETHOD(GetCurrentTransform)(
- _In_opt_ void* clientDrawingContext,
- _Out_ DWRITE_MATRIX* transform
- )
- {
- return E_NOTIMPL;
- }
+typedef struct FallbackLogTextRenderer {
+ IDWriteTextRenderer iface;
+ IDWriteTextRendererVtbl vtbl;
+ IDWriteFactory *dw_factory;
+ LONG ref_count;
+} FallbackLogTextRenderer;
+
+static HRESULT STDMETHODCALLTYPE FallbackLogTextRenderer_IsPixelSnappingDisabled(
+ IDWriteTextRenderer *This,
+ _In_opt_ void* clientDrawingContext,
+ _Out_ BOOL* isDisabled
+ )
+{
+ *isDisabled = true;
+ return S_OK;
+}
- IFACEMETHOD(GetPixelsPerDip)(
- _In_opt_ void* clientDrawingContext,
- _Out_ FLOAT* pixelsPerDip
- )
- {
- return E_NOTIMPL;
- }
+static HRESULT STDMETHODCALLTYPE FallbackLogTextRenderer_GetCurrentTransform(
+ IDWriteTextRenderer *This,
+ _In_opt_ void* clientDrawingContext,
+ _Out_ DWRITE_MATRIX* transform
+ )
+{
+ return E_NOTIMPL;
+}
- IFACEMETHOD(DrawGlyphRun)(
- _In_opt_ void* clientDrawingContext,
- FLOAT baselineOriginX,
- FLOAT baselineOriginY,
- DWRITE_MEASURING_MODE measuringMode,
- _In_ DWRITE_GLYPH_RUN const* glyphRun,
- _In_ DWRITE_GLYPH_RUN_DESCRIPTION const* glyphRunDescription,
- IUnknown* clientDrawingEffect
- )
- {
- HRESULT hr;
- IDWriteFontCollection *font_coll = NULL;
- IDWriteFont **font = static_cast<IDWriteFont **>(clientDrawingContext);
-
- hr = dw_factory->GetSystemFontCollection(&font_coll);
- if (FAILED(hr))
- return E_FAIL;
+static HRESULT STDMETHODCALLTYPE FallbackLogTextRenderer_GetPixelsPerDip(
+ IDWriteTextRenderer *This,
+ _In_opt_ void* clientDrawingContext,
+ _Out_ FLOAT* pixelsPerDip
+ )
+{
+ return E_NOTIMPL;
+}
- hr = font_coll->GetFontFromFontFace(glyphRun->fontFace, font);
- if (FAILED(hr))
- return E_FAIL;
+static HRESULT STDMETHODCALLTYPE FallbackLogTextRenderer_DrawGlyphRun(
+ IDWriteTextRenderer *This,
+ _In_opt_ void* clientDrawingContext,
+ FLOAT baselineOriginX,
+ FLOAT baselineOriginY,
+ DWRITE_MEASURING_MODE measuringMode,
+ _In_ DWRITE_GLYPH_RUN const* glyphRun,
+ _In_ DWRITE_GLYPH_RUN_DESCRIPTION const* glyphRunDescription,
+ IUnknown* clientDrawingEffect
+ )
+{
+ FallbackLogTextRenderer *this = (FallbackLogTextRenderer *)This;
+ HRESULT hr;
+ IDWriteFontCollection *font_coll = NULL;
+ IDWriteFont **font = (IDWriteFont **)clientDrawingContext;
- return S_OK;
- }
+ hr = IDWriteFactory_GetSystemFontCollection(this->dw_factory, &font_coll, FALSE);
+ if (FAILED(hr))
+ return E_FAIL;
- IFACEMETHOD(DrawUnderline)(
- _In_opt_ void* clientDrawingContext,
- FLOAT baselineOriginX,
- FLOAT baselineOriginY,
- _In_ DWRITE_UNDERLINE const* underline,
- IUnknown* clientDrawingEffect
- )
- {
- return S_OK;
- }
+ hr = IDWriteFontCollection_GetFontFromFontFace(font_coll, glyphRun->fontFace,
+ font);
+ if (FAILED(hr))
+ return E_FAIL;
- IFACEMETHOD(DrawStrikethrough)(
- _In_opt_ void* clientDrawingContext,
- FLOAT baselineOriginX,
- FLOAT baselineOriginY,
- _In_ DWRITE_STRIKETHROUGH const* strikethrough,
- IUnknown* clientDrawingEffect
- )
- {
- return S_OK;
- }
+ return S_OK;
+}
- IFACEMETHOD(DrawInlineObject)(
- _In_opt_ void* clientDrawingContext,
- FLOAT originX,
- FLOAT originY,
- IDWriteInlineObject* inlineObject,
- BOOL isSideways,
- BOOL isRightToLeft,
- IUnknown* clientDrawingEffect
- )
- {
- return S_OK;
- }
+static HRESULT STDMETHODCALLTYPE FallbackLogTextRenderer_DrawUnderline(
+ IDWriteTextRenderer *This,
+ _In_opt_ void* clientDrawingContext,
+ FLOAT baselineOriginX,
+ FLOAT baselineOriginY,
+ _In_ DWRITE_UNDERLINE const* underline,
+ IUnknown* clientDrawingEffect
+ )
+{
+ return S_OK;
+}
- // IUnknown methods
+static HRESULT STDMETHODCALLTYPE FallbackLogTextRenderer_DrawStrikethrough(
+ IDWriteTextRenderer *This,
+ _In_opt_ void* clientDrawingContext,
+ FLOAT baselineOriginX,
+ FLOAT baselineOriginY,
+ _In_ DWRITE_STRIKETHROUGH const* strikethrough,
+ IUnknown* clientDrawingEffect
+ )
+{
+ return S_OK;
+}
- IFACEMETHOD_(unsigned long, AddRef)()
- {
- return InterlockedIncrement(&ref_count);
- }
+static HRESULT STDMETHODCALLTYPE FallbackLogTextRenderer_DrawInlineObject(
+ IDWriteTextRenderer *This,
+ void *clientDrawingContext,
+ FLOAT originX,
+ FLOAT originY,
+ IDWriteInlineObject *inlineObject,
+ WINBOOL isSideways,
+ WINBOOL isRightToLeft,
+ IUnknown *clientDrawingEffect
+ )
+{
+ return S_OK;
+}
- IFACEMETHOD_(unsigned long, Release)()
- {
- unsigned long new_count = InterlockedDecrement(&ref_count);
- if (new_count == 0) {
- free(this);
- return 0;
- }
+// IUnknown methods
+
+static ULONG STDMETHODCALLTYPE FallbackLogTextRenderer_AddRef(
+ IDWriteTextRenderer *This
+ )
+{
+ FallbackLogTextRenderer *this = (FallbackLogTextRenderer *)This;
+ return InterlockedIncrement(&this->ref_count);
+}
- return new_count;
+static ULONG STDMETHODCALLTYPE FallbackLogTextRenderer_Release(
+ IDWriteTextRenderer *This
+ )
+{
+ FallbackLogTextRenderer *this = (FallbackLogTextRenderer *)This;
+ unsigned long new_count = InterlockedDecrement(&this->ref_count);
+ if (new_count == 0) {
+ free(this);
+ return 0;
}
- IFACEMETHOD(QueryInterface)(
- IID const& riid,
- void** ppvObject
- )
- {
- if (__uuidof(IDWriteTextRenderer) == riid
- || __uuidof(IDWritePixelSnapping) == riid
- || __uuidof(IUnknown) == riid) {
- *ppvObject = this;
- } else {
- *ppvObject = NULL;
- return E_FAIL;
- }
+ return new_count;
+}
- this->AddRef();
- return S_OK;
+static HRESULT STDMETHODCALLTYPE FallbackLogTextRenderer_QueryInterface(
+ IDWriteTextRenderer *This,
+ REFIID riid,
+ void **ppvObject
+ )
+{
+ if (IsEqualGUID(riid, &IID_IDWriteTextRenderer)
+ || IsEqualGUID(riid, &IID_IDWritePixelSnapping)
+ || IsEqualGUID(riid, &IID_IUnknown)) {
+ *ppvObject = This;
+ } else {
+ *ppvObject = NULL;
+ return E_FAIL;
}
-private:
- IDWriteFactory * const dw_factory;
- unsigned long ref_count;
-};
+ This->lpVtbl->AddRef(This);
+ return S_OK;
+}
+
+static void init_FallbackLogTextRenderer(FallbackLogTextRenderer *r,
+ IDWriteFactory *factory)
+{
+ *r = (FallbackLogTextRenderer){
+ .iface = {
+ .lpVtbl = &r->vtbl,
+ },
+ .vtbl = {
+ FallbackLogTextRenderer_QueryInterface,
+ FallbackLogTextRenderer_AddRef,
+ FallbackLogTextRenderer_Release,
+ FallbackLogTextRenderer_IsPixelSnappingDisabled,
+ FallbackLogTextRenderer_GetCurrentTransform,
+ FallbackLogTextRenderer_GetPixelsPerDip,
+ FallbackLogTextRenderer_DrawGlyphRun,
+ FallbackLogTextRenderer_DrawUnderline,
+ FallbackLogTextRenderer_DrawStrikethrough,
+ FallbackLogTextRenderer_DrawInlineObject,
+ },
+ .dw_factory = factory,
+ };
+}
/*
* This function is called whenever a font is used for the first
@@ -197,41 +240,41 @@ static bool init_font_private(FontPrivate *priv)
if (priv->stream != NULL)
return true;
- hr = font->CreateFontFace(&face);
+ hr = IDWriteFont_CreateFontFace(font, &face);
if (FAILED(hr) || !face)
return false;
/* DirectWrite only supports one file per face */
- hr = face->GetFiles(&n_files, &file);
+ hr = IDWriteFontFace_GetFiles(face, &n_files, &file);
if (FAILED(hr) || !file) {
- face->Release();
+ IDWriteFontFace_Release(face);
return false;
}
- hr = file->GetReferenceKey(&refKey, &keySize);
+ hr = IDWriteFontFile_GetReferenceKey(file, &refKey, &keySize);
if (FAILED(hr)) {
- file->Release();
- face->Release();
+ IDWriteFontFile_Release(file);
+ IDWriteFontFace_Release(face);
return false;
}
- hr = file->GetLoader(&loader);
+ hr = IDWriteFontFile_GetLoader(file, &loader);
if (FAILED(hr) || !loader) {
- file->Release();
- face->Release();
+ IDWriteFontFile_Release(file);
+ IDWriteFontFace_Release(face);
return false;
}
- hr = loader->CreateStreamFromKey(refKey, keySize, &stream);
+ hr = IDWriteFontFileLoader_CreateStreamFromKey(loader, refKey, keySize, &stream);
if (FAILED(hr) || !stream) {
- file->Release();
- face->Release();
+ IDWriteFontFile_Release(file);
+ IDWriteFontFace_Release(face);
return false;
}
priv->stream = stream;
- file->Release();
- face->Release();
+ IDWriteFontFile_Release(file);
+ IDWriteFontFace_Release(face);
return true;
}
@@ -256,21 +299,22 @@ static size_t get_data(void *data, unsigned char *buf, size_t offset,
if (buf == NULL) {
UINT64 fileSize;
- hr = priv->stream->GetFileSize(&fileSize);
+ hr = IDWriteFontFileStream_GetFileSize(priv->stream, &fileSize);
if (FAILED(hr))
return 0;
return fileSize;
}
- hr = priv->stream->ReadFileFragment(&fileBuf, offset, length, &fragContext);
+ hr = IDWriteFontFileStream_ReadFileFragment(priv->stream, &fileBuf, offset,
+ length, &fragContext);
if (FAILED(hr) || !fileBuf)
return 0;
memcpy(buf, fileBuf, length);
- priv->stream->ReleaseFileFragment(fragContext);
+ IDWriteFontFileStream_ReleaseFileFragment(priv->stream, fragContext);
return length;
}
@@ -288,7 +332,7 @@ static int check_glyph(void *data, uint32_t code)
if (code == 0)
return 1;
- priv->font->HasCharacter(code, &exists);
+ IDWriteFont_HasCharacter(priv->font, code, &exists);
if (FAILED(hr))
return 0;
@@ -301,7 +345,7 @@ static int check_glyph(void *data, uint32_t code)
static void destroy_provider(void *priv)
{
ProviderPrivate *provider_priv = (ProviderPrivate *)priv;
- provider_priv->factory->Release();
+ provider_priv->factory->lpVtbl->Release(provider_priv->factory);
FreeLibrary(provider_priv->directwrite_lib);
free(provider_priv);
}
@@ -315,9 +359,9 @@ static void destroy_font(void *data)
{
FontPrivate *priv = (FontPrivate *) data;
- priv->font->Release();
+ IDWriteFont_Release(priv->font);
if (priv->stream != NULL)
- priv->stream->Release();
+ IDWriteFontFileStream_Release(priv->stream);
free(priv);
}
@@ -342,9 +386,11 @@ static char *get_fallback(void *priv, ASS_FontProviderMetaData *meta,
IDWriteFactory *dw_factory = provider_priv->factory;
IDWriteTextFormat *text_format = NULL;
IDWriteTextLayout *text_layout = NULL;
- FallbackLogTextRenderer renderer(dw_factory);
+ FallbackLogTextRenderer renderer;
+
+ init_FallbackLogTextRenderer(&renderer, dw_factory);
- hr = dw_factory->CreateTextFormat(FALLBACK_DEFAULT_FONT, NULL,
+ hr = IDWriteFactory_CreateTextFormat(dw_factory, FALLBACK_DEFAULT_FONT, NULL,
DWRITE_FONT_WEIGHT_MEDIUM, DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL, 1.0f, L"", &text_format);
if (FAILED(hr)) {
@@ -357,53 +403,53 @@ static char *get_fallback(void *priv, ASS_FontProviderMetaData *meta,
// Create a text_layout, a high-level text rendering facility, using
// the given codepoint and dummy format.
- hr = dw_factory->CreateTextLayout(char_string, char_len, text_format,
+ hr = IDWriteFactory_CreateTextLayout(dw_factory, char_string, char_len, text_format,
0.0f, 0.0f, &text_layout);
if (FAILED(hr)) {
- text_format->Release();
+ IDWriteTextFormat_Release(text_format);
return NULL;
}
// Draw the layout with a dummy renderer, which logs the
// font used and stores it.
IDWriteFont *font = NULL;
- hr = text_layout->Draw(&font, &renderer, 0.0f, 0.0f);
+ hr = IDWriteTextLayout_Draw(text_layout, &font, &renderer.iface, 0.0f, 0.0f);
if (FAILED(hr) || font == NULL) {
- text_layout->Release();
- text_format->Release();
+ IDWriteTextLayout_Release(text_layout);
+ IDWriteTextFormat_Release(text_format);
return NULL;
}
// We're done with these now
- text_layout->Release();
- text_format->Release();
+ IDWriteTextLayout_Release(text_layout);
+ IDWriteTextFormat_Release(text_format);
// Now, just extract the first family name
BOOL exists = FALSE;
IDWriteLocalizedStrings *familyNames = NULL;
- hr = font->GetInformationalStrings(
+ hr = IDWriteFont_GetInformationalStrings(font,
DWRITE_INFORMATIONAL_STRING_WIN32_FAMILY_NAMES,
&familyNames, &exists);
if (FAILED(hr) || !exists) {
- font->Release();
+ IDWriteFont_Release(font);
return NULL;
}
wchar_t temp_name[NAME_MAX_LENGTH];
- hr = familyNames->GetString(0, temp_name, NAME_MAX_LENGTH);
+ hr = IDWriteLocalizedStrings_GetString(familyNames, 0, temp_name, NAME_MAX_LENGTH);
if (FAILED(hr)) {
- familyNames->Release();
- font->Release();
+ IDWriteLocalizedStrings_Release(familyNames);
+ IDWriteFont_Release(font);
return NULL;
}
temp_name[NAME_MAX_LENGTH-1] = 0;
// DirectWrite may not have found a valid fallback, so check that
// the selected font actually has the requested glyph.
- hr = font->HasCharacter(codepoint, &exists);
+ hr = IDWriteFont_HasCharacter(font, codepoint, &exists);
if (FAILED(hr) || !exists) {
- familyNames->Release();
- font->Release();
+ IDWriteLocalizedStrings_Release(familyNames);
+ IDWriteFont_Release(font);
return NULL;
}
@@ -411,8 +457,8 @@ static char *get_fallback(void *priv, ASS_FontProviderMetaData *meta,
char *family = (char *) malloc(size_needed);
WideCharToMultiByte(CP_UTF8, 0, temp_name, -1, family, size_needed, NULL, NULL);
- familyNames->Release();
- font->Release();
+ IDWriteLocalizedStrings_Release(familyNames);
+ IDWriteFont_Release(font);
return family;
}
@@ -446,15 +492,15 @@ static void scan_fonts(IDWriteFactory *factory,
IDWriteFont *font = NULL;
DWRITE_FONT_METRICS metrics;
DWRITE_FONT_STYLE style;
- ASS_FontProviderMetaData meta = ASS_FontProviderMetaData();
- hr = factory->GetSystemFontCollection(&fontCollection, FALSE);
+ ASS_FontProviderMetaData meta = {0};
+ hr = IDWriteFactory_GetSystemFontCollection(factory, &fontCollection, FALSE);
wchar_t temp_name[NAME_MAX_LENGTH];
int size_needed = 0;
if (FAILED(hr) || !fontCollection)
return;
- UINT32 familyCount = fontCollection->GetFontFamilyCount();
+ UINT32 familyCount = IDWriteFontCollection_GetFontFamilyCount(fontCollection);
for (UINT32 i = 0; i < familyCount; ++i) {
IDWriteFontFamily *fontFamily = NULL;
@@ -464,42 +510,43 @@ static void scan_fonts(IDWriteFactory *factory,
BOOL exists = FALSE;
char *psName = NULL;
- hr = fontCollection->GetFontFamily(i, &fontFamily);
+ hr = IDWriteFontCollection_GetFontFamily(fontCollection, i, &fontFamily);
if (FAILED(hr))
continue;
- UINT32 fontCount = fontFamily->GetFontCount();
+ UINT32 fontCount = IDWriteFontFamily_GetFontCount(fontFamily);
for (UINT32 j = 0; j < fontCount; ++j) {
- hr = fontFamily->GetFont(j, &font);
+ hr = IDWriteFontFamily_GetFont(fontFamily, j, &font);
if (FAILED(hr))
continue;
// Simulations for bold or oblique are sometimes synthesized by
// DirectWrite. We are only interested in physical fonts.
- if (font->GetSimulations() != 0) {
- font->Release();
+ if (IDWriteFont_GetSimulations(font) != 0) {
+ IDWriteFont_Release(font);
continue;
}
- meta.weight = font->GetWeight();
- meta.width = map_width(font->GetStretch());
- font->GetMetrics(&metrics);
- style = font->GetStyle();
+ meta.weight = IDWriteFont_GetWeight(font);
+ meta.width = map_width(IDWriteFont_GetStretch(font));
+ IDWriteFont_GetMetrics(font, &metrics);
+ style = IDWriteFont_GetStyle(font);
meta.slant = (style == DWRITE_FONT_STYLE_NORMAL) ? FONT_SLANT_NONE :
(style == DWRITE_FONT_STYLE_OBLIQUE)? FONT_SLANT_OBLIQUE :
(style == DWRITE_FONT_STYLE_ITALIC) ? FONT_SLANT_ITALIC : FONT_SLANT_NONE;
- hr = font->GetInformationalStrings(DWRITE_INFORMATIONAL_STRING_POSTSCRIPT_NAME, &psNames,&exists);
+ hr = IDWriteFont_GetInformationalStrings(font,
+ DWRITE_INFORMATIONAL_STRING_POSTSCRIPT_NAME, &psNames,&exists);
if (FAILED(hr)) {
- font->Release();
+ IDWriteFont_Release(font);
continue;
}
if (exists) {
- hr = psNames->GetString(0, temp_name, NAME_MAX_LENGTH);
+ hr = IDWriteLocalizedStrings_GetString(psNames, 0, temp_name, NAME_MAX_LENGTH);
if (FAILED(hr)) {
- psNames->Release();
- font->Release();
+ IDWriteLocalizedStrings_Release(psNames);
+ IDWriteFont_Release(font);
continue;
}
@@ -507,20 +554,23 @@ static void scan_fonts(IDWriteFactory *factory,
size_needed = WideCharToMultiByte(CP_UTF8, 0, temp_name, -1, NULL, 0,NULL, NULL);
psName = (char *) malloc(size_needed);
WideCharToMultiByte(CP_UTF8, 0, temp_name, -1, psName, size_needed, NULL, NULL);
- psNames->Release();
+ IDWriteLocalizedStrings_Release(psNames);
}
- hr = font->GetInformationalStrings(DWRITE_INFORMATIONAL_STRING_FULL_NAME, &fontNames,&exists);
+ hr = IDWriteFont_GetInformationalStrings(font,
+ DWRITE_INFORMATIONAL_STRING_FULL_NAME, &fontNames,&exists);
if (FAILED(hr)) {
- font->Release();
+ IDWriteFont_Release(font);
continue;
}
if (exists) {
- meta.n_fullname = fontNames->GetCount();
+ meta.n_fullname = IDWriteLocalizedStrings_GetCount(fontNames);
meta.fullnames = (char **) calloc(meta.n_fullname, sizeof(char *));
for (UINT32 k = 0; k < meta.n_fullname; ++k) {
- hr = fontNames->GetString(k, temp_name, NAME_MAX_LENGTH);
+ hr = IDWriteLocalizedStrings_GetString(fontNames, k,
+ temp_name,
+ NAME_MAX_LENGTH);
if (FAILED(hr)) {
continue;
}
@@ -531,21 +581,24 @@ static void scan_fonts(IDWriteFactory *factory,
WideCharToMultiByte(CP_UTF8, 0, temp_name, -1, mbName, size_needed, NULL, NULL);
meta.fullnames[k] = mbName;
}
- fontNames->Release();
+ IDWriteLocalizedStrings_Release(fontNames);
}
- hr = font->GetInformationalStrings(DWRITE_INFORMATIONAL_STRING_WIN32_FAMILY_NAMES, &familyNames, &exists);
+ hr = IDWriteFont_GetInformationalStrings(font,
+ DWRITE_INFORMATIONAL_STRING_WIN32_FAMILY_NAMES, &familyNames, &exists);
if (!exists)
- hr = fontFamily->GetFamilyNames(&familyNames);
+ hr = IDWriteFontFamily_GetFamilyNames(fontFamily, &familyNames);
if (FAILED(hr)) {
- font->Release();
+ IDWriteFont_Release(font);
continue;
}
- meta.n_family = familyNames->GetCount();
+ meta.n_family = IDWriteLocalizedStrings_GetCount(familyNames);
meta.families = (char **) calloc(meta.n_family, sizeof(char *));
for (UINT32 k = 0; k < meta.n_family; ++k) {
- hr = familyNames->GetString(k, temp_name, NAME_MAX_LENGTH);
+ hr = IDWriteLocalizedStrings_GetString(familyNames, k,
+ temp_name,
+ NAME_MAX_LENGTH);
if (FAILED(hr)) {
continue;
}
@@ -556,7 +609,7 @@ static void scan_fonts(IDWriteFactory *factory,
WideCharToMultiByte(CP_UTF8, 0, temp_name, -1, mbName, size_needed, NULL, NULL);
meta.families[k] = mbName;
}
- familyNames->Release();
+ IDWriteLocalizedStrings_Release(familyNames);
FontPrivate *font_priv = (FontPrivate *) calloc(1, sizeof(*font_priv));
font_priv->font = font;
@@ -620,7 +673,7 @@ ASS_FontProvider *ass_directwrite_add_provider(ASS_Library *lib,
goto cleanup;
hr = DWriteCreateFactoryPtr(DWRITE_FACTORY_TYPE_SHARED,
- __uuidof(IDWriteFactory),
+ &IID_IDWriteFactory,
(IUnknown **) (&dwFactory));
if (FAILED(hr) || !dwFactory) {
ass_msg(lib, MSGL_WARN, "Failed to initialize directwrite.");
@@ -645,7 +698,7 @@ cleanup:
free(priv);
if (dwFactory)
- dwFactory->Release();
+ dwFactory->lpVtbl->Release(dwFactory);
if (directwrite_lib)
FreeLibrary(directwrite_lib);
diff --git a/libass/dwrite.h b/libass/dwrite.h
new file mode 100644
index 0000000..c7bda0b
--- /dev/null
+++ b/libass/dwrite.h
@@ -0,0 +1,668 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+/**
+ * Stripped version. Only definitions needed by libass.
+ */
+#ifndef __INC_DWRITE__
+#define __INC_DWRITE__
+
+#define DWRITEAPI DECLSPEC_IMPORT
+
+#include <unknwn.h>
+
+typedef struct IDWriteFactory IDWriteFactory;
+typedef struct IDWriteFont IDWriteFont;
+typedef struct IDWriteFontCollection IDWriteFontCollection;
+typedef struct IDWriteFontFace IDWriteFontFace;
+typedef struct IDWriteFontFamily IDWriteFontFamily;
+typedef struct IDWriteFontList IDWriteFontList;
+typedef struct IDWriteFontFile IDWriteFontFile;
+typedef struct IDWriteFontFileLoader IDWriteFontFileLoader;
+typedef struct IDWriteFontFileStream IDWriteFontFileStream;
+typedef struct IDWriteInlineObject IDWriteInlineObject;
+typedef struct IDWriteLocalizedStrings IDWriteLocalizedStrings;
+typedef struct IDWritePixelSnapping IDWritePixelSnapping;
+typedef struct IDWriteTextFormat IDWriteTextFormat;
+typedef struct IDWriteTextLayout IDWriteTextLayout;
+typedef struct IDWriteTextRenderer IDWriteTextRenderer;
+
+#include <dcommon.h>
+
+typedef enum DWRITE_INFORMATIONAL_STRING_ID {
+ DWRITE_INFORMATIONAL_STRING_NONE = 0,
+ DWRITE_INFORMATIONAL_STRING_COPYRIGHT_NOTICE,
+ DWRITE_INFORMATIONAL_STRING_VERSION_STRINGS,
+ DWRITE_INFORMATIONAL_STRING_TRADEMARK,
+ DWRITE_INFORMATIONAL_STRING_MANUFACTURER,
+ DWRITE_INFORMATIONAL_STRING_DESIGNER,
+ DWRITE_INFORMATIONAL_STRING_DESIGNER_URL,
+ DWRITE_INFORMATIONAL_STRING_DESCRIPTION,
+ DWRITE_INFORMATIONAL_STRING_FONT_VENDOR_URL,
+ DWRITE_INFORMATIONAL_STRING_LICENSE_DESCRIPTION,
+ DWRITE_INFORMATIONAL_STRING_LICENSE_INFO_URL,
+ DWRITE_INFORMATIONAL_STRING_WIN32_FAMILY_NAMES,
+ DWRITE_INFORMATIONAL_STRING_WIN32_SUBFAMILY_NAMES,
+ DWRITE_INFORMATIONAL_STRING_PREFERRED_FAMILY_NAMES,
+ DWRITE_INFORMATIONAL_STRING_PREFERRED_SUBFAMILY_NAMES,
+ DWRITE_INFORMATIONAL_STRING_SAMPLE_TEXT,
+ DWRITE_INFORMATIONAL_STRING_FULL_NAME,
+ DWRITE_INFORMATIONAL_STRING_POSTSCRIPT_NAME,
+ DWRITE_INFORMATIONAL_STRING_POSTSCRIPT_CID_NAME
+} DWRITE_INFORMATIONAL_STRING_ID;
+
+typedef enum DWRITE_FACTORY_TYPE {
+ DWRITE_FACTORY_TYPE_SHARED = 0,
+ DWRITE_FACTORY_TYPE_ISOLATED
+} DWRITE_FACTORY_TYPE;
+
+
+typedef enum DWRITE_FONT_SIMULATIONS {
+ DWRITE_FONT_SIMULATIONS_NONE = 0x0000,
+ DWRITE_FONT_SIMULATIONS_BOLD = 0x0001,
+ DWRITE_FONT_SIMULATIONS_OBLIQUE = 0x0002
+} DWRITE_FONT_SIMULATIONS;
+
+typedef enum DWRITE_FONT_STRETCH {
+ DWRITE_FONT_STRETCH_UNDEFINED = 0,
+ DWRITE_FONT_STRETCH_ULTRA_CONDENSED = 1,
+ DWRITE_FONT_STRETCH_EXTRA_CONDENSED = 2,
+ DWRITE_FONT_STRETCH_CONDENSED = 3,
+ DWRITE_FONT_STRETCH_SEMI_CONDENSED = 4,
+ DWRITE_FONT_STRETCH_NORMAL = 5,
+ DWRITE_FONT_STRETCH_MEDIUM = 5,
+ DWRITE_FONT_STRETCH_SEMI_EXPANDED = 6,
+ DWRITE_FONT_STRETCH_EXPANDED = 7,
+ DWRITE_FONT_STRETCH_EXTRA_EXPANDED = 8,
+ DWRITE_FONT_STRETCH_ULTRA_EXPANDED = 9
+} DWRITE_FONT_STRETCH;
+
+typedef enum DWRITE_FONT_STYLE {
+ DWRITE_FONT_STYLE_NORMAL = 0,
+ DWRITE_FONT_STYLE_OBLIQUE,
+ DWRITE_FONT_STYLE_ITALIC
+} DWRITE_FONT_STYLE;
+
+typedef enum DWRITE_FONT_WEIGHT {
+ DWRITE_FONT_WEIGHT_MEDIUM = 500,
+ /* rest dropped */
+} DWRITE_FONT_WEIGHT;
+
+typedef struct DWRITE_FONT_METRICS {
+ UINT16 designUnitsPerEm;
+ UINT16 ascent;
+ UINT16 descent;
+ INT16 lineGap;
+ UINT16 capHeight;
+ UINT16 xHeight;
+ INT16 underlinePosition;
+ UINT16 underlineThickness;
+ INT16 strikethroughPosition;
+ UINT16 strikethroughThickness;
+} DWRITE_FONT_METRICS;
+
+typedef struct DWRITE_GLYPH_OFFSET DWRITE_GLYPH_OFFSET;
+
+typedef struct DWRITE_GLYPH_RUN {
+ IDWriteFontFace *fontFace;
+ FLOAT fontEmSize;
+ UINT32 glyphCount;
+ const UINT16 *glyphIndices;
+ const FLOAT *glyphAdvances;
+ const DWRITE_GLYPH_OFFSET *glyphOffsets;
+ WINBOOL isSideways;
+ UINT32 bidiLevel;
+} DWRITE_GLYPH_RUN;
+
+typedef struct DWRITE_GLYPH_RUN_DESCRIPTION DWRITE_GLYPH_RUN_DESCRIPTION;
+typedef struct DWRITE_HIT_TEST_METRICS DWRITE_HIT_TEST_METRICS;
+typedef struct DWRITE_LINE_METRICS DWRITE_LINE_METRICS;
+typedef struct DWRITE_MATRIX DWRITE_MATRIX;
+typedef struct DWRITE_STRIKETHROUGH DWRITE_STRIKETHROUGH;
+typedef struct DWRITE_TEXT_METRICS DWRITE_TEXT_METRICS;
+
+typedef struct DWRITE_TEXT_RANGE {
+ UINT32 startPosition;
+ UINT32 length;
+} DWRITE_TEXT_RANGE;
+
+typedef struct DWRITE_TRIMMING DWRITE_TRIMMING;
+typedef struct DWRITE_UNDERLINE DWRITE_UNDERLINE;
+
+#ifndef __MINGW_DEF_ARG_VAL
+#ifdef __cplusplus
+#define __MINGW_DEF_ARG_VAL(x) = x
+#else
+#define __MINGW_DEF_ARG_VAL(x)
+#endif
+#endif
+
+#undef INTERFACE
+#define INTERFACE IDWriteFactory
+DECLARE_INTERFACE_(IDWriteFactory,IUnknown)
+{
+ BEGIN_INTERFACE
+
+#ifndef __cplusplus
+ /* IUnknown methods */
+ STDMETHOD(QueryInterface)(THIS_ REFIID riid, void **ppvObject) PURE;
+ STDMETHOD_(ULONG, AddRef)(THIS) PURE;
+ STDMETHOD_(ULONG, Release)(THIS) PURE;
+#endif
+
+ /* IDWriteFactory methods */
+ STDMETHOD(GetSystemFontCollection)(THIS_
+ IDWriteFontCollection **fontCollection,
+ WINBOOL checkForUpdates __MINGW_DEF_ARG_VAL(FALSE)) PURE;
+
+ STDMETHOD(dummy1)(THIS);
+ STDMETHOD(dummy2)(THIS);
+ STDMETHOD(dummy3)(THIS);
+ STDMETHOD(dummy4)(THIS);
+ STDMETHOD(dummy5)(THIS);
+ STDMETHOD(dummy6)(THIS);
+ STDMETHOD(dummy7)(THIS);
+ STDMETHOD(dummy8)(THIS);
+ STDMETHOD(dummy9)(THIS);
+ STDMETHOD(dummy10)(THIS);
+ STDMETHOD(dummy11)(THIS);
+
+ STDMETHOD(CreateTextFormat)(THIS_
+ WCHAR const *fontFamilyName,
+ IDWriteFontCollection *fontCollection,
+ DWRITE_FONT_WEIGHT fontWeight,
+ DWRITE_FONT_STYLE fontStyle,
+ DWRITE_FONT_STRETCH fontStretch,
+ FLOAT fontSize,
+ WCHAR const *localeName,
+ IDWriteTextFormat **textFormat) PURE;
+
+ STDMETHOD(dummy12)(THIS);
+ STDMETHOD(dummy13)(THIS);
+
+ STDMETHOD(CreateTextLayout)(THIS_
+ WCHAR const *string,
+ UINT32 stringLength,
+ IDWriteTextFormat *textFormat,
+ FLOAT maxWidth,
+ FLOAT maxHeight,
+ IDWriteTextLayout **textLayout) PURE;
+
+ /* remainder dropped */
+ END_INTERFACE
+};
+#ifdef COBJMACROS
+#define IDWriteFactory_QueryInterface(This,riid,ppvObject) (This)->lpVtbl->QueryInterface(This,riid,ppvObject)
+#define IDWriteFactory_AddRef(This) (This)->lpVtbl->AddRef(This)
+#define IDWriteFactory_Release(This) (This)->lpVtbl->Release(This)
+#define IDWriteFactory_GetSystemFontCollection(This,fontCollection,checkForUpdates) (This)->lpVtbl->GetSystemFontCollection(This,fontCollection,checkForUpdates)
+#define IDWriteFactory_CreateTextFormat(This,fontFamilyName,fontCollection,fontWeight,fontStyle,fontStretch,fontSize,localeName,textFormat) (This)->lpVtbl->CreateTextFormat(This,fontFamilyName,fontCollection,fontWeight,fontStyle,fontStretch,fontSize,localeName,textFormat)
+#define IDWriteFactory_CreateTextLayout(This,string,stringLength,textFormat,maxWidth,maxHeight,textLayout) (This)->lpVtbl->CreateTextLayout(This,string,stringLength,textFormat,maxWidth,maxHeight,textLayout)
+#endif /*COBJMACROS*/
+
+#undef INTERFACE
+#define INTERFACE IDWriteFont
+DECLARE_INTERFACE_(IDWriteFont,IUnknown)
+{
+ BEGIN_INTERFACE
+
+#ifndef __cplusplus
+ /* IUnknown methods */
+ STDMETHOD(QueryInterface)(THIS_ REFIID riid, void **ppvObject) PURE;
+ STDMETHOD_(ULONG, AddRef)(THIS) PURE;
+ STDMETHOD_(ULONG, Release)(THIS) PURE;
+#endif
+
+ /* IDWriteFont methods */
+ STDMETHOD(GetFontFamily)(THIS_
+ IDWriteFontFamily **fontFamily) PURE;
+
+ STDMETHOD_(DWRITE_FONT_WEIGHT, GetWeight)(THIS) PURE;
+ STDMETHOD_(DWRITE_FONT_STRETCH, GetStretch)(THIS) PURE;
+ STDMETHOD_(DWRITE_FONT_STYLE, GetStyle)(THIS) PURE;
+ STDMETHOD_(WINBOOL, IsSymbolFont)(THIS) PURE;
+
+ STDMETHOD(GetFaceNames)(THIS_
+ IDWriteLocalizedStrings **names) PURE;
+
+ STDMETHOD(GetInformationalStrings)(THIS_
+ DWRITE_INFORMATIONAL_STRING_ID informationalStringID,
+ IDWriteLocalizedStrings **informationalStrings,
+ WINBOOL *exists) PURE;
+
+ STDMETHOD_(DWRITE_FONT_SIMULATIONS, GetSimulations)(THIS) PURE;
+
+ STDMETHOD_(void, GetMetrics)(THIS_
+ DWRITE_FONT_METRICS *fontMetrics) PURE;
+
+ STDMETHOD(HasCharacter)(THIS_
+ UINT32 unicodeValue,
+ WINBOOL *exists) PURE;
+
+ STDMETHOD(CreateFontFace)(THIS_
+ IDWriteFontFace **fontFace) PURE;
+
+ END_INTERFACE
+};
+#ifdef COBJMACROS
+#define IDWriteFont_QueryInterface(This,riid,ppvObject) (This)->lpVtbl->QueryInterface(This,riid,ppvObject)
+#define IDWriteFont_AddRef(This) (This)->lpVtbl->AddRef(This)
+#define IDWriteFont_Release(This) (This)->lpVtbl->Release(This)
+#define IDWriteFont_CreateFontFace(This,fontFace) (This)->lpVtbl->CreateFontFace(This,fontFace)
+#define IDWriteFont_GetFaceNames(This,names) (This)->lpVtbl->GetFaceNames(This,names)
+#define IDWriteFont_GetFontFamily(This,fontFamily) (This)->lpVtbl->GetFontFamily(This,fontFamily)
+#define IDWriteFont_GetInformationalStrings(This,informationalStringID,informationalStrings,exists) (This)->lpVtbl->GetInformationalStrings(This,informationalStringID,informationalStrings,exists)
+#define IDWriteFont_GetMetrics(This,fontMetrics) (This)->lpVtbl->GetMetrics(This,fontMetrics)
+#define IDWriteFont_GetSimulations(This) (This)->lpVtbl->GetSimulations(This)
+#define IDWriteFont_GetStretch(This) (This)->lpVtbl->GetStretch(This)
+#define IDWriteFont_GetStyle(This) (This)->lpVtbl->GetStyle(This)
+#define IDWriteFont_GetWeight(This) (This)->lpVtbl->GetWeight(This)
+#define IDWriteFont_HasCharacter(This,unicodeValue,exists) (This)->lpVtbl->HasCharacter(This,unicodeValue,exists)
+#define IDWriteFont_IsSymbolFont(This) (This)->lpVtbl->IsSymbolFont(This)
+#endif /*COBJMACROS*/
+
+#undef INTERFACE
+#define INTERFACE IDWriteFontCollection
+DECLARE_INTERFACE_(IDWriteFontCollection,IUnknown)
+{
+ BEGIN_INTERFACE
+
+#ifndef __cplusplus
+ /* IUnknown methods */
+ STDMETHOD(QueryInterface)(THIS_ REFIID riid, void **ppvObject) PURE;
+ STDMETHOD_(ULONG, AddRef)(THIS) PURE;
+ STDMETHOD_(ULONG, Release)(THIS) PURE;
+#endif
+
+ /* IDWriteFontCollection methods */
+ STDMETHOD_(UINT32, GetFontFamilyCount)(THIS) PURE;
+
+ STDMETHOD(GetFontFamily)(THIS_
+ UINT32 index,
+ IDWriteFontFamily **fontFamily) PURE;
+
+ STDMETHOD(FindFamilyName)(THIS_
+ WCHAR const *familyName,
+ UINT32 *index,
+ WINBOOL *exists) PURE;
+
+ STDMETHOD(GetFontFromFontFace)(THIS_
+ IDWriteFontFace* fontFace,
+ IDWriteFont **font) PURE;
+
+ END_INTERFACE
+};