mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-04-05 05:30:43 +02:00
Dwrite: implement is_synthetic()
This commit is contained in:
parent
0321ac99a4
commit
d2f65a7306
3 changed files with 171 additions and 7 deletions
|
|
@ -245,8 +245,12 @@ _cairo_dwrite_load_truetype_table(void *scaled_font,
|
|||
unsigned long *length);
|
||||
|
||||
unsigned long
|
||||
_cairo_dwrite_ucs4_to_index(void *scaled_font,
|
||||
uint32_t ucs4);
|
||||
_cairo_dwrite_ucs4_to_index(void *scaled_font,
|
||||
uint32_t ucs4);
|
||||
|
||||
cairo_int_status_t
|
||||
static _cairo_dwrite_is_synthetic(void *scaled_font,
|
||||
cairo_bool_t *is_synthetic);
|
||||
|
||||
static cairo_bool_t
|
||||
_cairo_dwrite_has_color_glyphs(void *scaled_font);
|
||||
|
|
@ -259,7 +263,7 @@ const cairo_scaled_font_backend_t _cairo_dwrite_scaled_font_backend = {
|
|||
_cairo_dwrite_ucs4_to_index,
|
||||
_cairo_dwrite_load_truetype_table,
|
||||
NULL, /* index_to_ucs4 */
|
||||
NULL, /* is_synthetic */
|
||||
_cairo_dwrite_is_synthetic,
|
||||
NULL, /* index_to_glyph_name */
|
||||
NULL, /* load_type1_data */
|
||||
_cairo_dwrite_has_color_glyphs
|
||||
|
|
@ -1215,6 +1219,79 @@ _cairo_dwrite_load_truetype_table(void *scaled_font,
|
|||
return (cairo_int_status_t)CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static cairo_int_status_t
|
||||
_cairo_dwrite_is_synthetic(void *scaled_font,
|
||||
cairo_bool_t *is_synthetic)
|
||||
{
|
||||
cairo_dwrite_scaled_font_t *dwritesf = static_cast<cairo_dwrite_scaled_font_t*>(scaled_font);
|
||||
cairo_dwrite_font_face_t *face = reinterpret_cast<cairo_dwrite_font_face_t*>(dwritesf->base.font_face);
|
||||
HRESULT hr;
|
||||
cairo_int_status_t status;
|
||||
|
||||
if (face->dwriteface->GetSimulations() != DWRITE_FONT_SIMULATIONS_NONE) {
|
||||
*is_synthetic = FALSE;
|
||||
return CAIRO_INT_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
IDWriteFontFace5 *fontFace5 = NULL;
|
||||
if (!SUCCEEDED(face->dwriteface->QueryInterface(&fontFace5))) {
|
||||
/* If IDWriteFontFace5 is not available, assume this version of
|
||||
* DirectWrite does not support variations.
|
||||
*/
|
||||
*is_synthetic = FALSE;
|
||||
return CAIRO_INT_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (!fontFace5->HasVariations()) {
|
||||
*is_synthetic = FALSE;
|
||||
return CAIRO_INT_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
IDWriteFontResource *fontResource = NULL;
|
||||
hr = fontFace5->GetFontResource(&fontResource);
|
||||
if (!SUCCEEDED(hr))
|
||||
return _cairo_dwrite_error (hr, "GetFontResource failed");
|
||||
|
||||
UINT32 axis_count = fontResource->GetFontAxisCount();
|
||||
DWRITE_FONT_AXIS_VALUE *axis_defaults = new DWRITE_FONT_AXIS_VALUE[axis_count];
|
||||
DWRITE_FONT_AXIS_VALUE *axis_values = new DWRITE_FONT_AXIS_VALUE[axis_count];
|
||||
|
||||
hr = fontResource->GetDefaultFontAxisValues(axis_defaults, axis_count);
|
||||
if (!SUCCEEDED(hr)) {
|
||||
status = _cairo_dwrite_error (hr, "GetDefaultFontAxisValues failed");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
hr = fontFace5->GetFontAxisValues(axis_values, axis_count);
|
||||
if (!SUCCEEDED(hr)) {
|
||||
status = _cairo_dwrite_error (hr, "GetFontAxisValues failed");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* The DirectWrite documentation does not state if the tags of the returned
|
||||
* defaults and values arrays are in the same order. So assume they are not.
|
||||
*/
|
||||
*is_synthetic = FALSE;
|
||||
status = CAIRO_INT_STATUS_SUCCESS;
|
||||
for (UINT32 i = 0; i< axis_count; i++) {
|
||||
for (UINT32 j = 0; j < axis_count; j++) {
|
||||
if (axis_values[i].axisTag == axis_defaults[j].axisTag) {
|
||||
if (axis_values[i].value != axis_defaults[j].value) {
|
||||
*is_synthetic = TRUE;
|
||||
goto cleanup;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
delete[] axis_defaults;
|
||||
delete[] axis_values;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static cairo_bool_t
|
||||
_cairo_dwrite_has_color_glyphs(void *scaled_font)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -38,8 +38,8 @@
|
|||
#include <dwrite.h>
|
||||
#include <d2d1.h>
|
||||
|
||||
/* If either of the dwrite_2.h or d2d1_3.h headers required for color fonts
|
||||
* is not available, include our own version containing just the functions we need.
|
||||
/* If either of the dwrite_3.h or d2d1_3.h headers required for color fonts
|
||||
* are not available, include our own version containing just the functions we need.
|
||||
*/
|
||||
|
||||
#if HAVE_DWRITE_3_H
|
||||
|
|
|
|||
|
|
@ -2,8 +2,15 @@
|
|||
|
||||
/* Mingw-w64 dwrite_3.h is broken
|
||||
*
|
||||
* We only need the definitions of one function and its dependencies.
|
||||
* IDWriteFactory4::TranslateColorGlyphRun
|
||||
* We only need the definitions of the following functions and their dependencies.
|
||||
* IDWriteFactory4::TranslateColorGlyphRun()
|
||||
* IDWriteFontResource::GetDefaultFontAxisValues()
|
||||
* IDWriteFontResource::GetFontAxisCount()
|
||||
* IDWriteFontResource::HasVariations()
|
||||
* IDWriteFontFace5::GetFontAxisValueCount()
|
||||
* IDWriteFontFace5::GetFontAxisValues()
|
||||
* IDWriteFontFace5::HasVariations()
|
||||
* IDWriteFontFace5::GetFontResource()
|
||||
*
|
||||
* But we need to include all the prior functions in the same struct,
|
||||
* and parent structs, so that the functions are in the correct position
|
||||
|
|
@ -74,5 +81,85 @@ IDWriteFactory4 : public IDWriteFactory3
|
|||
};
|
||||
__CRT_UUID_DECL(IDWriteFactory4, 0x4b0b5bd3, 0x0797, 0x4549, 0x8a,0xc5, 0xfe,0x91,0x5c,0xc5,0x38,0x56)
|
||||
|
||||
typedef enum DWRITE_FONT_AXIS_TAG {
|
||||
DWRITE_FONT_AXIS_TAG_WEIGHT = 0x74686777,
|
||||
DWRITE_FONT_AXIS_TAG_WIDTH = 0x68746477,
|
||||
DWRITE_FONT_AXIS_TAG_SLANT = 0x746e6c73,
|
||||
DWRITE_FONT_AXIS_TAG_OPTICAL_SIZE = 0x7a73706f,
|
||||
DWRITE_FONT_AXIS_TAG_ITALIC = 0x6c617469
|
||||
} DWRITE_FONT_AXIS_TAG;
|
||||
|
||||
typedef struct DWRITE_FONT_AXIS_VALUE {
|
||||
DWRITE_FONT_AXIS_TAG axisTag;
|
||||
FLOAT value;
|
||||
} DWRITE_FONT_AXIS_VALUE;
|
||||
|
||||
DEFINE_GUID(IID_IDWriteFontResource, 0x1f803a76, 0x6871, 0x48e8, 0x98,0x7f, 0xb9,0x75,0x55,0x1c,0x50,0xf2);
|
||||
MIDL_INTERFACE("1f803a76-6871-48e8-987f-b975551c50f2")
|
||||
IDWriteFontResource : public IUnknown
|
||||
{
|
||||
virtual void STDMETHODCALLTYPE GetFontFile() = 0;
|
||||
virtual void STDMETHODCALLTYPE GetFontFaceIndex() = 0;
|
||||
virtual UINT32 STDMETHODCALLTYPE GetFontAxisCount() = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetDefaultFontAxisValues(
|
||||
const DWRITE_FONT_AXIS_VALUE *values,
|
||||
UINT32 num_values) = 0;
|
||||
virtual void STDMETHODCALLTYPE GetFontAxisRanges() = 0;
|
||||
virtual void STDMETHODCALLTYPE GetFontAxisAttributes() = 0;
|
||||
virtual void STDMETHODCALLTYPE GetAxisNames() = 0;
|
||||
virtual void STDMETHODCALLTYPE GetAxisValueNameCount() = 0;
|
||||
virtual void STDMETHODCALLTYPE GetAxisValueNames() = 0;
|
||||
virtual WINBOOL STDMETHODCALLTYPE HasVariations() = 0;
|
||||
virtual void STDMETHODCALLTYPE CreateFontFace() = 0;
|
||||
virtual void STDMETHODCALLTYPE CreateFontFaceReference() = 0;
|
||||
};
|
||||
__CRT_UUID_DECL(IDWriteFontResource, 0x1f803a76, 0x6871, 0x48e8, 0x98,0x7f, 0xb9,0x75,0x55,0x1c,0x50,0xf2)
|
||||
|
||||
DEFINE_GUID(IID_IDWriteFontFace3, 0xd37d7598, 0x09be, 0x4222, 0xa2,0x36, 0x20,0x81,0x34,0x1c,0xc1,0xf2);
|
||||
MIDL_INTERFACE("d37d7598-09be-4222-a236-2081341cc1f2")
|
||||
IDWriteFontFace3 : public IDWriteFontFace2
|
||||
{
|
||||
virtual void STDMETHODCALLTYPE GetFontFaceReference() = 0;
|
||||
virtual void STDMETHODCALLTYPE GetPanose() = 0;
|
||||
virtual void STDMETHODCALLTYPE GetWeight() = 0;
|
||||
virtual void STDMETHODCALLTYPE GetStretch() = 0;
|
||||
virtual void STDMETHODCALLTYPE GetStyle() = 0;
|
||||
virtual void STDMETHODCALLTYPE GetFamilyNames() = 0;
|
||||
virtual void STDMETHODCALLTYPE GetFaceNames() = 0;
|
||||
virtual void STDMETHODCALLTYPE GetInformationalStrings() = 0;
|
||||
virtual void STDMETHODCALLTYPE HasCharacter() = 0;
|
||||
virtual void STDMETHODCALLTYPE GetRecommendedRenderingMode() = 0;
|
||||
virtual void STDMETHODCALLTYPE IsCharacterLocal() = 0;
|
||||
virtual void STDMETHODCALLTYPE IsGlyphLocal() = 0;
|
||||
virtual void STDMETHODCALLTYPE AreCharactersLocal() = 0;
|
||||
virtual void STDMETHODCALLTYPE AreGlyphsLocal() = 0;
|
||||
};
|
||||
__CRT_UUID_DECL(IDWriteFontFace3, 0xd37d7598, 0x09be, 0x4222, 0xa2,0x36, 0x20,0x81,0x34,0x1c,0xc1,0xf2)
|
||||
|
||||
DEFINE_GUID(IID_IDWriteFontFace4, 0x27f2a904, 0x4eb8, 0x441d, 0x96,0x78, 0x05,0x63,0xf5,0x3e,0x3e,0x2f);
|
||||
MIDL_INTERFACE("27f2a904-4eb8-441d-9678-0563f53e3e2f")
|
||||
IDWriteFontFace4 : public IDWriteFontFace3
|
||||
{
|
||||
virtual void STDMETHODCALLTYPE GetGlyphImageFormats_() = 0;
|
||||
virtual void STDMETHODCALLTYPE GetGlyphImageFormats() = 0;
|
||||
virtual void STDMETHODCALLTYPE GetGlyphImageData() = 0;
|
||||
virtual void STDMETHODCALLTYPE ReleaseGlyphImageData() = 0;
|
||||
};
|
||||
__CRT_UUID_DECL(IDWriteFontFace4, 0x27f2a904, 0x4eb8, 0x441d, 0x96,0x78, 0x05,0x63,0xf5,0x3e,0x3e,0x2f)
|
||||
|
||||
DEFINE_GUID(IID_IDWriteFontFace5, 0x98eff3a5, 0xb667, 0x479a, 0xb1,0x45, 0xe2,0xfa,0x5b,0x9f,0xdc,0x29);
|
||||
MIDL_INTERFACE("98eff3a5-b667-479a-b145-e2fa5b9fdc29")
|
||||
IDWriteFontFace5 : public IDWriteFontFace4
|
||||
{
|
||||
virtual UINT32 STDMETHODCALLTYPE GetFontAxisValueCount() = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetFontAxisValues(
|
||||
DWRITE_FONT_AXIS_VALUE *values,
|
||||
UINT32 value_count) = 0;
|
||||
virtual WINBOOL STDMETHODCALLTYPE HasVariations() = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetFontResource(
|
||||
IDWriteFontResource **resource) = 0;
|
||||
virtual void STDMETHODCALLTYPE Equals() = 0;
|
||||
};
|
||||
__CRT_UUID_DECL(IDWriteFontFace5, 0x98eff3a5, 0xb667, 0x479a, 0xb1,0x45, 0xe2,0xfa,0x5b,0x9f,0xdc,0x29)
|
||||
|
||||
#endif /* DWRITE_EXTRA_H */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue