void directwriteAnalyzerTest(IDWriteFontFace *fontFace, WCHAR *string, int len, featurePreparer *features) { IDWriteTextAnalyzer *analyzer; analysisSourceSink *ss; const DWRITE_TYPOGRAPHIC_FEATURES **dwfeatures; UINT32 *dwfeatureRangeLengths; UINT32 dwfeatureRanges; std::vector<UINT16> glyphs; HRESULT hr; hr = dwfactory->CreateTextAnalyzer(&analyzer); if (hr != S_OK) die("error creating IDWriteTextAnalyzer", hr); ss = new analysisSourceSink(string, len); dwfeatures = NULL; dwfeatureRangeLengths = NULL; dwfeatureRanges = 0; if (features != NULL) { // TODO WTF IS THIS C++? or is this the DirectWrite devs failing? dwfeatures = (const DWRITE_TYPOGRAPHIC_FEATURES **) (features->dwFeatures); dwfeatureRangeLengths = features->dwFeatureRangeLengths; dwfeatureRanges = features->dwFeatureRanges; } hr = analyzer->AnalyzeScript(ss, 0, len, ss); if (hr != S_OK) die("error analyzing scripts for DirectWrite", hr); ss->processResults([&](DWRITE_SCRIPT_ANALYSIS scriptAnalysis, UINT32 start, UINT32 end) { UINT16 *clusterMap; DWRITE_SHAPING_TEXT_PROPERTIES *textProps; UINT16 *glyphIndices; DWRITE_SHAPING_GLYPH_PROPERTIES *glyphProps; UINT32 nGlyphs, nActualGlyphs; UINT32 i; clusterMap = new UINT16[end - start]; textProps = new DWRITE_SHAPING_TEXT_PROPERTIES[end - start]; nGlyphs = (3 * (end - start) / 2 + 16); for (;;) { glyphIndices = new UINT16[nGlyphs]; glyphProps = new DWRITE_SHAPING_GLYPH_PROPERTIES[nGlyphs]; ZeroMemory(clusterMap, (end - start) * sizeof (UINT16)); ZeroMemory(textProps, (end - start) * sizeof (DWRITE_SHAPING_TEXT_PROPERTIES)); ZeroMemory(glyphIndices, nGlyphs * sizeof (UINT16)); ZeroMemory(glyphProps, nGlyphs * sizeof (DWRITE_SHAPING_GLYPH_PROPERTIES)); hr = analyzer->GetGlyphs(string + start, end - start, fontFace, FALSE, FALSE, &scriptAnalysis, NULL, NULL, dwfeatures, dwfeatureRangeLengths, dwfeatureRanges, nGlyphs, clusterMap, textProps, glyphIndices, glyphProps, &nActualGlyphs); if (hr == S_OK) break; if (hr != HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)) die("error analyzing text with DirectWrite", hr); delete[] glyphProps; delete[] glyphIndices; nGlyphs *= 2; } for (i = 0; i < nActualGlyphs; i++) glyphs.push_back(glyphIndices[i]); delete[] glyphProps; delete[] glyphIndices; delete[] textProps; delete[] clusterMap; }); printGlyphs("DirectWrite IDWriteTextAnalyzer", glyphs); delete ss; analyzer->Release(); }