2 * Copyright © 2015-2019 Ebrahim Byagowi
4 * This is part of HarfBuzz, a text shaping library.
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
27 #ifdef HAVE_DIRECTWRITE
29 #include "hb-shaper-impl.hh"
33 #include "hb-directwrite.h"
35 #include "hb-ms-feature-ranges.hh"
38 * SECTION:hb-directwrite
39 * @title: hb-directwrite
40 * @short_description: DirectWrite integration
41 * @include: hb-directwrite.h
43 * Functions for using HarfBuzz with DirectWrite fonts.
46 /* Declare object creator for dynamic support of DWRITE */
47 typedef HRESULT (WINAPI *t_DWriteCreateFactory)(
48 DWRITE_FACTORY_TYPE factoryType,
55 * DirectWrite font stream helpers
58 // This is a font loader which provides only one font (unlike its original design).
59 // For a better implementation which was also source of this
60 // and DWriteFontFileStream, have a look at to NativeFontResourceDWrite.cpp in Mozilla
61 class DWriteFontFileLoader : public IDWriteFontFileLoader
64 IDWriteFontFileStream *mFontFileStream;
66 DWriteFontFileLoader (IDWriteFontFileStream *fontFileStream)
67 { mFontFileStream = fontFileStream; }
70 IFACEMETHOD (QueryInterface) (IID const& iid, OUT void** ppObject)
72 IFACEMETHOD_ (ULONG, AddRef) () { return 1; }
73 IFACEMETHOD_ (ULONG, Release) () { return 1; }
75 // IDWriteFontFileLoader methods
76 virtual HRESULT STDMETHODCALLTYPE
77 CreateStreamFromKey (void const* fontFileReferenceKey,
78 uint32_t fontFileReferenceKeySize,
79 OUT IDWriteFontFileStream** fontFileStream)
81 *fontFileStream = mFontFileStream;
85 virtual ~DWriteFontFileLoader() {}
88 class DWriteFontFileStream : public IDWriteFontFileStream
94 DWriteFontFileStream (uint8_t *aData, uint32_t aSize)
100 // IUnknown interface
101 IFACEMETHOD (QueryInterface) (IID const& iid, OUT void** ppObject)
103 IFACEMETHOD_ (ULONG, AddRef) () { return 1; }
104 IFACEMETHOD_ (ULONG, Release) () { return 1; }
106 // IDWriteFontFileStream methods
107 virtual HRESULT STDMETHODCALLTYPE
108 ReadFileFragment (void const** fragmentStart,
111 OUT void** fragmentContext)
113 // We are required to do bounds checking.
114 if (fileOffset + fragmentSize > mSize) return E_FAIL;
116 // truncate the 64 bit fileOffset to size_t sized index into mData
117 size_t index = static_cast<size_t> (fileOffset);
119 // We should be alive for the duration of this.
120 *fragmentStart = &mData[index];
121 *fragmentContext = nullptr;
125 virtual void STDMETHODCALLTYPE
126 ReleaseFileFragment (void* fragmentContext) {}
128 virtual HRESULT STDMETHODCALLTYPE
129 GetFileSize (OUT UINT64* fileSize)
135 virtual HRESULT STDMETHODCALLTYPE
136 GetLastWriteTime (OUT UINT64* lastWriteTime) { return E_NOTIMPL; }
138 virtual ~DWriteFontFileStream() {}
146 struct hb_directwrite_face_data_t
149 IDWriteFactory *dwriteFactory;
150 IDWriteFontFile *fontFile;
151 DWriteFontFileStream *fontFileStream;
152 DWriteFontFileLoader *fontFileLoader;
153 IDWriteFontFace *fontFace;
157 hb_directwrite_face_data_t *
158 _hb_directwrite_shaper_face_data_create (hb_face_t *face)
160 hb_directwrite_face_data_t *data = new hb_directwrite_face_data_t;
161 if (unlikely (!data))
166 DEBUG_MSG (DIRECTWRITE, nullptr, __VA_ARGS__); \
170 data->dwrite_dll = LoadLibrary (TEXT ("DWRITE"));
171 if (unlikely (!data->dwrite_dll))
172 FAIL ("Cannot find DWrite.DLL");
174 t_DWriteCreateFactory p_DWriteCreateFactory;
176 #if defined(__GNUC__)
177 #pragma GCC diagnostic push
178 #pragma GCC diagnostic ignored "-Wcast-function-type"
181 p_DWriteCreateFactory = (t_DWriteCreateFactory)
182 GetProcAddress (data->dwrite_dll, "DWriteCreateFactory");
184 #if defined(__GNUC__)
185 #pragma GCC diagnostic pop
188 if (unlikely (!p_DWriteCreateFactory))
189 FAIL ("Cannot find DWriteCreateFactory().");
193 // TODO: factory and fontFileLoader should be cached separately
194 IDWriteFactory* dwriteFactory;
195 hr = p_DWriteCreateFactory (DWRITE_FACTORY_TYPE_SHARED, __uuidof (IDWriteFactory),
196 (IUnknown**) &dwriteFactory);
198 if (unlikely (hr != S_OK))
199 FAIL ("Failed to run DWriteCreateFactory().");
201 hb_blob_t *blob = hb_face_reference_blob (face);
202 DWriteFontFileStream *fontFileStream;
203 fontFileStream = new DWriteFontFileStream ((uint8_t *) hb_blob_get_data (blob, nullptr),
204 hb_blob_get_length (blob));
206 DWriteFontFileLoader *fontFileLoader = new DWriteFontFileLoader (fontFileStream);
207 dwriteFactory->RegisterFontFileLoader (fontFileLoader);
209 IDWriteFontFile *fontFile;
210 uint64_t fontFileKey = 0;
211 hr = dwriteFactory->CreateCustomFontFileReference (&fontFileKey, sizeof (fontFileKey),
212 fontFileLoader, &fontFile);
215 FAIL ("Failed to load font file from data!");
218 DWRITE_FONT_FILE_TYPE fileType;
219 DWRITE_FONT_FACE_TYPE faceType;
220 uint32_t numberOfFaces;
221 hr = fontFile->Analyze (&isSupported, &fileType, &faceType, &numberOfFaces);
222 if (FAILED (hr) || !isSupported)
223 FAIL ("Font file is not supported.");
227 IDWriteFontFace *fontFace;
228 dwriteFactory->CreateFontFace (faceType, 1, &fontFile, 0,
229 DWRITE_FONT_SIMULATIONS_NONE, &fontFace);
231 data->dwriteFactory = dwriteFactory;
232 data->fontFile = fontFile;
233 data->fontFileStream = fontFileStream;
234 data->fontFileLoader = fontFileLoader;
235 data->fontFace = fontFace;
236 data->faceBlob = blob;
242 _hb_directwrite_shaper_face_data_destroy (hb_directwrite_face_data_t *data)
245 data->fontFace->Release ();
247 data->fontFile->Release ();
248 if (data->dwriteFactory)
250 if (data->fontFileLoader)
251 data->dwriteFactory->UnregisterFontFileLoader (data->fontFileLoader);
252 data->dwriteFactory->Release ();
254 delete data->fontFileLoader;
255 delete data->fontFileStream;
256 hb_blob_destroy (data->faceBlob);
257 if (data->dwrite_dll)
258 FreeLibrary (data->dwrite_dll);
267 struct hb_directwrite_font_data_t {};
269 hb_directwrite_font_data_t *
270 _hb_directwrite_shaper_font_data_create (hb_font_t *font)
272 return (hb_directwrite_font_data_t *) HB_SHAPER_DATA_SUCCEEDED;
276 _hb_directwrite_shaper_font_data_destroy (hb_directwrite_font_data_t *data)
281 // Most of TextAnalysis is originally written by Bas Schouten for Mozilla project
282 // but now is relicensed to MIT for HarfBuzz use
283 class TextAnalysis : public IDWriteTextAnalysisSource, public IDWriteTextAnalysisSink
287 IFACEMETHOD (QueryInterface) (IID const& iid, OUT void** ppObject)
289 IFACEMETHOD_ (ULONG, AddRef) () { return 1; }
290 IFACEMETHOD_ (ULONG, Release) () { return 1; }
292 // A single contiguous run of characters containing the same analysis
296 uint32_t mTextStart; // starting text position of this run
297 uint32_t mTextLength; // number of contiguous code units covered
298 uint32_t mGlyphStart; // starting glyph in the glyphs array
299 uint32_t mGlyphCount; // number of glyphs associated with this run
301 DWRITE_SCRIPT_ANALYSIS mScript;
305 bool ContainsTextPosition (uint32_t aTextPosition) const
307 return aTextPosition >= mTextStart &&
308 aTextPosition < mTextStart + mTextLength;
315 TextAnalysis (const wchar_t* text, uint32_t textLength,
316 const wchar_t* localeName, DWRITE_READING_DIRECTION readingDirection)
317 : mTextLength (textLength), mText (text), mLocaleName (localeName),
318 mReadingDirection (readingDirection), mCurrentRun (nullptr) {}
321 // delete runs, except mRunHead which is part of the TextAnalysis object
322 for (Run *run = mRunHead.nextRun; run;)
331 GenerateResults (IDWriteTextAnalyzer* textAnalyzer, Run **runHead)
333 // Analyzes the text using the script analyzer and returns
334 // the result as a series of runs.
338 // Initially start out with one result that covers the entire range.
339 // This result will be subdivided by the analysis processes.
340 mRunHead.mTextStart = 0;
341 mRunHead.mTextLength = mTextLength;
342 mRunHead.mBidiLevel =
343 (mReadingDirection == DWRITE_READING_DIRECTION_RIGHT_TO_LEFT);
344 mRunHead.nextRun = nullptr;
345 mCurrentRun = &mRunHead;
347 // Call each of the analyzers in sequence, recording their results.
348 if (SUCCEEDED (hr = textAnalyzer->AnalyzeScript (this, 0, mTextLength, this)))
349 *runHead = &mRunHead;
354 // IDWriteTextAnalysisSource implementation
357 GetTextAtPosition (uint32_t textPosition,
358 OUT wchar_t const** textString,
359 OUT uint32_t* textLength)
361 if (textPosition >= mTextLength)
363 // No text at this position, valid query though.
364 *textString = nullptr;
369 *textString = mText + textPosition;
370 *textLength = mTextLength - textPosition;
376 GetTextBeforePosition (uint32_t textPosition,
377 OUT wchar_t const** textString,
378 OUT uint32_t* textLength)
380 if (textPosition == 0 || textPosition > mTextLength)
382 // Either there is no text before here (== 0), or this
383 // is an invalid position. The query is considered valid though.
384 *textString = nullptr;
390 *textLength = textPosition;
395 IFACEMETHODIMP_ (DWRITE_READING_DIRECTION)
396 GetParagraphReadingDirection () { return mReadingDirection; }
398 IFACEMETHODIMP GetLocaleName (uint32_t textPosition, uint32_t* textLength,
399 wchar_t const** localeName)
403 GetNumberSubstitution (uint32_t textPosition,
404 OUT uint32_t* textLength,
405 OUT IDWriteNumberSubstitution** numberSubstitution)
407 // We do not support number substitution.
408 *numberSubstitution = nullptr;
409 *textLength = mTextLength - textPosition;
414 // IDWriteTextAnalysisSink implementation
417 SetScriptAnalysis (uint32_t textPosition, uint32_t textLength,
418 DWRITE_SCRIPT_ANALYSIS const* scriptAnalysis)
420 SetCurrentRun (textPosition);
421 SplitCurrentRun (textPosition);
422 while (textLength > 0)
424 Run *run = FetchNextRun (&textLength);
425 run->mScript = *scriptAnalysis;
432 SetLineBreakpoints (uint32_t textPosition,
434 const DWRITE_LINE_BREAKPOINT* lineBreakpoints)
437 IFACEMETHODIMP SetBidiLevel (uint32_t textPosition, uint32_t textLength,
438 uint8_t explicitLevel, uint8_t resolvedLevel)
442 SetNumberSubstitution (uint32_t textPosition, uint32_t textLength,
443 IDWriteNumberSubstitution* numberSubstitution)
447 Run *FetchNextRun (IN OUT uint32_t* textLength)
449 // Used by the sink setters, this returns a reference to the next run.
450 // Position and length are adjusted to now point after the current run
453 Run *origRun = mCurrentRun;
454 // Split the tail if needed (the length remaining is less than the
455 // current run's size).
456 if (*textLength < mCurrentRun->mTextLength)
457 SplitCurrentRun (mCurrentRun->mTextStart + *textLength);
459 // Just advance the current run.
460 mCurrentRun = mCurrentRun->nextRun;
461 *textLength -= origRun->mTextLength;
463 // Return a reference to the run that was just current.
467 void SetCurrentRun (uint32_t textPosition)
469 // Move the current run to the given position.
470 // Since the analyzers generally return results in a forward manner,
471 // this will usually just return early. If not, find the
472 // corresponding run for the text position.
474 if (mCurrentRun && mCurrentRun->ContainsTextPosition (textPosition))
477 for (Run *run = &mRunHead; run; run = run->nextRun)
478 if (run->ContainsTextPosition (textPosition))
483 assert (0); // We should always be able to find the text position in one of our runs
486 void SplitCurrentRun (uint32_t splitPosition)
490 assert (0); // SplitCurrentRun called without current run
491 // Shouldn't be calling this when no current run is set!
494 // Split the current run.
495 if (splitPosition <= mCurrentRun->mTextStart)
497 // No need to split, already the start of a run
498 // or before it. Usually the first.
501 Run *newRun = new Run;
503 *newRun = *mCurrentRun;
505 // Insert the new run in our linked list.
506 newRun->nextRun = mCurrentRun->nextRun;
507 mCurrentRun->nextRun = newRun;
509 // Adjust runs' text positions and lengths.
510 uint32_t splitPoint = splitPosition - mCurrentRun->mTextStart;
511 newRun->mTextStart += splitPoint;
512 newRun->mTextLength -= splitPoint;
513 mCurrentRun->mTextLength = splitPoint;
514 mCurrentRun = newRun;
519 // (weak references are fine here, since this class is a transient
520 // stack-based helper that doesn't need to copy data)
521 uint32_t mTextLength;
522 const wchar_t* mText;
523 const wchar_t* mLocaleName;
524 DWRITE_READING_DIRECTION mReadingDirection;
526 // Current processing state.
529 // Output is a list of runs starting here
538 _hb_directwrite_shape (hb_shape_plan_t *shape_plan,
541 const hb_feature_t *features,
542 unsigned int num_features)
544 hb_face_t *face = font->face;
545 const hb_directwrite_face_data_t *face_data = face->data.directwrite;
546 IDWriteFactory *dwriteFactory = face_data->dwriteFactory;
547 IDWriteFontFace *fontFace = face_data->fontFace;
549 IDWriteTextAnalyzer* analyzer;
550 dwriteFactory->CreateTextAnalyzer (&analyzer);
552 unsigned int scratch_size;
553 hb_buffer_t::scratch_buffer_t *scratch = buffer->get_scratch_buffer (&scratch_size);
554 #define ALLOCATE_ARRAY(Type, name, len) \
555 Type *name = (Type *) scratch; \
557 unsigned int _consumed = DIV_CEIL ((len) * sizeof (Type), sizeof (*scratch)); \
558 assert (_consumed <= scratch_size); \
559 scratch += _consumed; \
560 scratch_size -= _consumed; \
563 #define utf16_index() var1.u32
565 ALLOCATE_ARRAY (wchar_t, textString, buffer->len * 2);
567 unsigned int chars_len = 0;
568 for (unsigned int i = 0; i < buffer->len; i++)
570 hb_codepoint_t c = buffer->info[i].codepoint;
571 buffer->info[i].utf16_index () = chars_len;
572 if (likely (c <= 0xFFFFu))
573 textString[chars_len++] = c;
574 else if (unlikely (c > 0x10FFFFu))
575 textString[chars_len++] = 0xFFFDu;
578 textString[chars_len++] = 0xD800u + ((c - 0x10000u) >> 10);
579 textString[chars_len++] = 0xDC00u + ((c - 0x10000u) & ((1u << 10) - 1));
583 ALLOCATE_ARRAY (WORD, log_clusters, chars_len);
584 /* Need log_clusters to assign features. */
586 for (unsigned int i = 0; i < buffer->len; i++)
588 hb_codepoint_t c = buffer->info[i].codepoint;
589 unsigned int cluster = buffer->info[i].cluster;
590 log_clusters[chars_len++] = cluster;
591 if (hb_in_range (c, 0x10000u, 0x10FFFFu))
592 log_clusters[chars_len++] = cluster; /* Surrogates. */
595 DWRITE_READING_DIRECTION readingDirection;
596 readingDirection = buffer->props.direction ?
597 DWRITE_READING_DIRECTION_RIGHT_TO_LEFT :
598 DWRITE_READING_DIRECTION_LEFT_TO_RIGHT;
601 * There's an internal 16-bit limit on some things inside the analyzer,
602 * but we never attempt to shape a word longer than 64K characters
603 * in a single gfxShapedWord, so we cannot exceed that limit.
605 uint32_t textLength = chars_len;
607 TextAnalysis analysis (textString, textLength, nullptr, readingDirection);
608 TextAnalysis::Run *runHead;
610 hr = analysis.GenerateResults (analyzer, &runHead);
614 DEBUG_MSG (DIRECTWRITE, nullptr, __VA_ARGS__); \
619 FAIL ("Analyzer failed to generate results.");
621 uint32_t maxGlyphCount = 3 * textLength / 2 + 16;
623 bool isRightToLeft = HB_DIRECTION_IS_BACKWARD (buffer->props.direction);
625 const wchar_t localeName[20] = {0};
626 if (buffer->props.language)
627 mbstowcs ((wchar_t*) localeName,
628 hb_language_to_string (buffer->props.language), 20);
633 static_assert ((sizeof (DWRITE_TYPOGRAPHIC_FEATURES) == sizeof (hb_ms_features_t)), "");
634 static_assert ((sizeof (DWRITE_FONT_FEATURE) == sizeof (hb_ms_feature_t)), "");
635 hb_vector_t<hb_ms_features_t *> range_features;
636 hb_vector_t<uint32_t> range_char_counts;
639 hb_vector_t<hb_ms_feature_t> feature_records;
640 hb_vector_t<hb_ms_range_record_t> range_records;
641 if (hb_ms_setup_features (features, num_features, feature_records, range_records))
642 hb_ms_make_feature_ranges (feature_records,
651 uint16_t* clusterMap;
652 clusterMap = new uint16_t[textLength];
653 DWRITE_SHAPING_TEXT_PROPERTIES* textProperties;
654 textProperties = new DWRITE_SHAPING_TEXT_PROPERTIES[textLength];
657 uint16_t* glyphIndices = new uint16_t[maxGlyphCount];
658 DWRITE_SHAPING_GLYPH_PROPERTIES* glyphProperties;
659 glyphProperties = new DWRITE_SHAPING_GLYPH_PROPERTIES[maxGlyphCount];
661 hr = analyzer->GetGlyphs (textString,
669 (const DWRITE_TYPOGRAPHIC_FEATURES**) range_features.arrayZ,
670 range_char_counts.arrayZ,
671 range_features.length,
679 if (unlikely (hr == HRESULT_FROM_WIN32 (ERROR_INSUFFICIENT_BUFFER)))
681 delete [] glyphIndices;
682 delete [] glyphProperties;
686 goto retry_getglyphs;
689 FAIL ("Analyzer failed to get glyphs.");
691 float* glyphAdvances = new float[maxGlyphCount];
692 DWRITE_GLYPH_OFFSET* glyphOffsets = new DWRITE_GLYPH_OFFSET[maxGlyphCount];
694 /* The -2 in the following is to compensate for possible
695 * alignment needed after the WORD array. sizeof (WORD) == 2. */
696 unsigned int glyphs_size = (scratch_size * sizeof (int) - 2)
698 sizeof (DWRITE_SHAPING_GLYPH_PROPERTIES) +
700 sizeof (DWRITE_GLYPH_OFFSET) +
702 ALLOCATE_ARRAY (uint32_t, vis_clusters, glyphs_size);
704 #undef ALLOCATE_ARRAY
706 int fontEmSize = font->face->get_upem ();
707 if (fontEmSize < 0) fontEmSize = -fontEmSize;
709 if (fontEmSize < 0) fontEmSize = -fontEmSize;
710 double x_mult = (double) font->x_scale / fontEmSize;
711 double y_mult = (double) font->y_scale / fontEmSize;
713 hr = analyzer->GetGlyphPlacements (textString,
726 (const DWRITE_TYPOGRAPHIC_FEATURES**) range_features.arrayZ,
727 range_char_counts.arrayZ,
728 range_features.length,
733 FAIL ("Analyzer failed to get glyph placements.");
735 /* Ok, we've got everything we need, now compose output buffer,
736 * very, *very*, carefully! */
738 /* Calculate visual-clusters. That's what we ship. */
739 for (unsigned int i = 0; i < glyphCount; i++)
740 vis_clusters[i] = (uint32_t) -1;
741 for (unsigned int i = 0; i < buffer->len; i++)
744 &vis_clusters[log_clusters[buffer->info[i].utf16_index ()]];
745 *p = hb_min (*p, buffer->info[i].cluster);
747 for (unsigned int i = 1; i < glyphCount; i++)
748 if (vis_clusters[i] == (uint32_t) -1)
749 vis_clusters[i] = vis_clusters[i - 1];
753 if (unlikely (!buffer->ensure (glyphCount)))
754 FAIL ("Buffer in error");
758 /* Set glyph infos */
760 for (unsigned int i = 0; i < glyphCount; i++)
762 hb_glyph_info_t *info = &buffer->info[buffer->len++];
764 info->codepoint = glyphIndices[i];
765 info->cluster = vis_clusters[i];
767 /* The rest is crap. Let's store position info there for now. */
768 info->mask = glyphAdvances[i];
769 info->var1.i32 = glyphOffsets[i].advanceOffset;
770 info->var2.i32 = glyphOffsets[i].ascenderOffset;
773 /* Set glyph positions */
774 buffer->clear_positions ();
775 for (unsigned int i = 0; i < glyphCount; i++)
777 hb_glyph_info_t *info = &buffer->info[i];
778 hb_glyph_position_t *pos = &buffer->pos[i];
781 pos->x_advance = x_mult * (int32_t) info->mask;
782 pos->x_offset = x_mult * (isRightToLeft ? -info->var1.i32 : info->var1.i32);
783 pos->y_offset = y_mult * info->var2.i32;
786 if (isRightToLeft) hb_buffer_reverse (buffer);
788 buffer->clear_glyph_flags ();
789 buffer->unsafe_to_break ();
791 delete [] clusterMap;
792 delete [] glyphIndices;
793 delete [] textProperties;
794 delete [] glyphProperties;
795 delete [] glyphAdvances;
796 delete [] glyphOffsets;
802 struct _hb_directwrite_font_table_context {
803 IDWriteFontFace *face;
808 _hb_directwrite_table_data_release (void *data)
810 _hb_directwrite_font_table_context *context = (_hb_directwrite_font_table_context *) data;
811 context->face->ReleaseFontTable (context->table_context);
816 _hb_directwrite_reference_table (hb_face_t *face HB_UNUSED, hb_tag_t tag, void *user_data)
818 IDWriteFontFace *dw_face = ((IDWriteFontFace *) user_data);
823 if (!dw_face || FAILED (dw_face->TryGetFontTable (hb_uint32_swap (tag), &data,
824 &length, &table_context, &exists)))
827 if (!data || !exists || !length)
829 dw_face->ReleaseFontTable (table_context);
833 _hb_directwrite_font_table_context *context = (_hb_directwrite_font_table_context *) hb_malloc (sizeof (_hb_directwrite_font_table_context));
834 context->face = dw_face;
835 context->table_context = table_context;
837 return hb_blob_create ((const char *) data, length, HB_MEMORY_MODE_READONLY,
838 context, _hb_directwrite_table_data_release);
842 _hb_directwrite_font_release (void *data)
845 ((IDWriteFontFace *) data)->Release ();
849 * hb_directwrite_face_create:
850 * @font_face: a DirectWrite IDWriteFontFace object.
852 * Constructs a new face object from the specified DirectWrite IDWriteFontFace.
854 * Return value: #hb_face_t object corresponding to the given input
859 hb_directwrite_face_create (IDWriteFontFace *font_face)
862 font_face->AddRef ();
863 return hb_face_create_for_tables (_hb_directwrite_reference_table, font_face,
864 _hb_directwrite_font_release);
868 * hb_directwrite_face_get_font_face:
869 * @face: a #hb_face_t object
871 * Gets the DirectWrite IDWriteFontFace associated with @face.
873 * Return value: DirectWrite IDWriteFontFace object corresponding to the given input
878 hb_directwrite_face_get_font_face (hb_face_t *face)
880 return face->data.directwrite->fontFace;