[dwrite] Remove ifdefs without breaking execution on old Windows versions

This commit is contained in:
Ebrahim Byagowi 2016-06-23 16:41:37 +04:30
parent 6b861dbd8b
commit f3f0ea980a
1 changed files with 105 additions and 104 deletions

View File

@ -25,11 +25,7 @@
#define HB_SHAPER directwrite #define HB_SHAPER directwrite
#include "hb-shaper-impl-private.hh" #include "hb-shaper-impl-private.hh"
#ifndef HB_DIRECTWRITE_EXPERIMENTAL_JUSTIFICATION #include <DWrite_1.h>
#include <DWrite.h>
#else
#include <DWrite_1.h>
#endif
#include "hb-directwrite.h" #include "hb-directwrite.h"
@ -156,7 +152,6 @@ _hb_directwrite_shaper_face_data_create(hb_face_t *face)
(IUnknown**) &dwriteFactory (IUnknown**) &dwriteFactory
); );
HRESULT hr; HRESULT hr;
hb_blob_t* blob = hb_face_reference_blob (face); hb_blob_t* blob = hb_face_reference_blob (face);
IDWriteFontFileStream *fontFileStream = new DWriteFontFileStream ( IDWriteFontFileStream *fontFileStream = new DWriteFontFileStream (
@ -377,7 +372,8 @@ public:
IFACEMETHODIMP GetLocaleName(uint32_t textPosition, IFACEMETHODIMP GetLocaleName(uint32_t textPosition,
uint32_t* textLength, uint32_t* textLength,
wchar_t const** localeName) { wchar_t const** localeName)
{
return S_OK; return S_OK;
} }
@ -402,7 +398,8 @@ public:
{ {
SetCurrentRun(textPosition); SetCurrentRun(textPosition);
SplitCurrentRun(textPosition); SplitCurrentRun(textPosition);
while (textLength > 0) { while (textLength > 0)
{
Run *run = FetchNextRun(&textLength); Run *run = FetchNextRun(&textLength);
run->mScript = *scriptAnalysis; run->mScript = *scriptAnalysis;
} }
@ -435,10 +432,12 @@ protected:
Run *origRun = mCurrentRun; Run *origRun = mCurrentRun;
// Split the tail if needed (the length remaining is less than the // Split the tail if needed (the length remaining is less than the
// current run's size). // current run's size).
if (*textLength < mCurrentRun->mTextLength) { if (*textLength < mCurrentRun->mTextLength)
SplitCurrentRun(mCurrentRun->mTextStart + *textLength); {
SplitCurrentRun (mCurrentRun->mTextStart + *textLength);
} }
else { else
{
// Just advance the current run. // Just advance the current run.
mCurrentRun = mCurrentRun->nextRun; mCurrentRun = mCurrentRun->nextRun;
} }
@ -455,12 +454,14 @@ protected:
// this will usually just return early. If not, find the // this will usually just return early. If not, find the
// corresponding run for the text position. // corresponding run for the text position.
if (mCurrentRun && mCurrentRun->ContainsTextPosition(textPosition)) { if (mCurrentRun && mCurrentRun->ContainsTextPosition (textPosition))
{
return; return;
} }
for (Run *run = &mRunHead; run; run = run->nextRun) { for (Run *run = &mRunHead; run; run = run->nextRun) {
if (run->ContainsTextPosition(textPosition)) { if (run->ContainsTextPosition (textPosition))
{
mCurrentRun = run; mCurrentRun = run;
return; return;
} }
@ -471,13 +472,15 @@ protected:
void SplitCurrentRun(uint32_t splitPosition) void SplitCurrentRun(uint32_t splitPosition)
{ {
if (!mCurrentRun) { if (!mCurrentRun)
{
//NS_ASSERTION(false, "SplitCurrentRun called without current run."); //NS_ASSERTION(false, "SplitCurrentRun called without current run.");
// Shouldn't be calling this when no current run is set! // Shouldn't be calling this when no current run is set!
return; return;
} }
// Split the current run. // Split the current run.
if (splitPosition <= mCurrentRun->mTextStart) { if (splitPosition <= mCurrentRun->mTextStart)
{
// No need to split, already the start of a run // No need to split, already the start of a run
// or before it. Usually the first. // or before it. Usually the first.
return; return;
@ -514,9 +517,9 @@ protected:
Run mRunHead; Run mRunHead;
}; };
static inline uint16_t hb_uint16_swap(const uint16_t v) static inline uint16_t hb_uint16_swap (const uint16_t v)
{ return (v >> 8) | (v << 8); } { return (v >> 8) | (v << 8); }
static inline uint32_t hb_uint32_swap(const uint32_t v) static inline uint32_t hb_uint32_swap (const uint32_t v)
{ return (hb_uint16_swap(v) << 16) | hb_uint16_swap(v >> 16); } { return (hb_uint16_swap(v) << 16) | hb_uint16_swap(v >> 16); }
/* /*
@ -536,14 +539,8 @@ _hb_directwrite_shape(hb_shape_plan_t *shape_plan,
IDWriteFactory *dwriteFactory = face_data->dwriteFactory; IDWriteFactory *dwriteFactory = face_data->dwriteFactory;
IDWriteFontFace *fontFace = face_data->fontFace; IDWriteFontFace *fontFace = face_data->fontFace;
#ifndef HB_DIRECTWRITE_EXPERIMENTAL_JUSTIFICATION
IDWriteTextAnalyzer* analyzer; IDWriteTextAnalyzer* analyzer;
dwriteFactory->CreateTextAnalyzer(&analyzer); dwriteFactory->CreateTextAnalyzer(&analyzer);
#else
IDWriteTextAnalyzer* analyzer0;
dwriteFactory->CreateTextAnalyzer (&analyzer0);
IDWriteTextAnalyzer1* analyzer = (IDWriteTextAnalyzer1*) analyzer0;
#endif
unsigned int scratch_size; unsigned int scratch_size;
hb_buffer_t::scratch_buffer_t *scratch = buffer->get_scratch_buffer (&scratch_size); hb_buffer_t::scratch_buffer_t *scratch = buffer->get_scratch_buffer (&scratch_size);
@ -717,12 +714,19 @@ retry_getglyphs:
return false; return false;
} }
#ifdef HB_DIRECTWRITE_EXPERIMENTAL_JUSTIFICATION // TODO: get lineWith from somewhere
float lineWidth = 0;
IDWriteTextAnalyzer1* analyzer1;
analyzer->QueryInterface (&analyzer1);
if (analyzer1 && lineWidth)
{
DWRITE_JUSTIFICATION_OPPORTUNITY* justificationOpportunities = DWRITE_JUSTIFICATION_OPPORTUNITY* justificationOpportunities =
(DWRITE_JUSTIFICATION_OPPORTUNITY*) (DWRITE_JUSTIFICATION_OPPORTUNITY*)
malloc (maxGlyphCount * sizeof (DWRITE_JUSTIFICATION_OPPORTUNITY)); malloc (maxGlyphCount * sizeof (DWRITE_JUSTIFICATION_OPPORTUNITY));
hr = analyzer->GetJustificationOpportunities (fontFace, fontEmSize, hr = analyzer1->GetJustificationOpportunities (fontFace, fontEmSize,
runHead->mScript, textLength, glyphCount, textString, clusterMap, runHead->mScript, textLength, glyphCount, textString, clusterMap,
glyphProperties, justificationOpportunities); glyphProperties, justificationOpportunities);
@ -732,27 +736,24 @@ retry_getglyphs:
return false; return false;
} }
// TODO: get lineWith from somewhere
float lineWidth = 60000;
float* justifiedGlyphAdvances = float* justifiedGlyphAdvances =
(float*) malloc (maxGlyphCount * sizeof (float)); (float*) malloc (maxGlyphCount * sizeof (float));
DWRITE_GLYPH_OFFSET* justifiedGlyphOffsets = (DWRITE_GLYPH_OFFSET*) DWRITE_GLYPH_OFFSET* justifiedGlyphOffsets = (DWRITE_GLYPH_OFFSET*)
malloc (glyphCount * sizeof (DWRITE_GLYPH_OFFSET)); malloc (glyphCount * sizeof (DWRITE_GLYPH_OFFSET));
hr = analyzer->JustifyGlyphAdvances (lineWidth, glyphCount, justificationOpportunities, hr = analyzer1->JustifyGlyphAdvances (lineWidth, glyphCount, justificationOpportunities,
glyphAdvances, glyphOffsets, justifiedGlyphAdvances, justifiedGlyphOffsets); glyphAdvances, glyphOffsets, justifiedGlyphAdvances, justifiedGlyphOffsets);
if (FAILED (hr)) if (FAILED (hr))
{ {
FAIL ("Analyzer failed to get justified glyph advances."); FAIL("Analyzer failed to get justified glyph advances.");
return false; return false;
} }
DWRITE_SCRIPT_PROPERTIES scriptProperties; DWRITE_SCRIPT_PROPERTIES scriptProperties;
hr = analyzer->GetScriptProperties (runHead->mScript, &scriptProperties); hr = analyzer1->GetScriptProperties (runHead->mScript, &scriptProperties);
if (FAILED (hr)) if (FAILED (hr))
{ {
FAIL ("Analyzer failed to get script properties."); FAIL("Analyzer failed to get script properties.");
return false; return false;
} }
uint32_t justificationCharacter = scriptProperties.justificationCharacter; uint32_t justificationCharacter = scriptProperties.justificationCharacter;
@ -760,14 +761,14 @@ retry_getglyphs:
// if a script justificationCharacter is not space, it can have GetJustifiedGlyphs // if a script justificationCharacter is not space, it can have GetJustifiedGlyphs
if (justificationCharacter != 32) if (justificationCharacter != 32)
{ {
retry_getjustifiedglyphs: retry_getjustifiedglyphs:
uint16_t* modifiedClusterMap = (uint16_t*) malloc (maxGlyphCount * sizeof (uint16_t)); uint16_t* modifiedClusterMap = (uint16_t*) malloc (maxGlyphCount * sizeof(uint16_t));
uint16_t* modifiedGlyphIndices = (uint16_t*) malloc (maxGlyphCount * sizeof (uint16_t)); uint16_t* modifiedGlyphIndices = (uint16_t*) malloc (maxGlyphCount * sizeof(uint16_t));
float* modifiedGlyphAdvances = (float*) malloc (maxGlyphCount * sizeof (float)); float* modifiedGlyphAdvances = (float*) malloc (maxGlyphCount * sizeof(float));
DWRITE_GLYPH_OFFSET* modifiedGlyphOffsets = (DWRITE_GLYPH_OFFSET*) DWRITE_GLYPH_OFFSET* modifiedGlyphOffsets = (DWRITE_GLYPH_OFFSET*)
malloc (maxGlyphCount * sizeof (DWRITE_GLYPH_OFFSET)); malloc (maxGlyphCount * sizeof (DWRITE_GLYPH_OFFSET));
uint32_t actualGlyphsCount; uint32_t actualGlyphsCount;
hr = analyzer->GetJustifiedGlyphs (fontFace, fontEmSize, runHead->mScript, hr = analyzer1->GetJustifiedGlyphs (fontFace, fontEmSize, runHead->mScript,
textLength, glyphCount, maxGlyphCount, clusterMap, glyphIndices, textLength, glyphCount, maxGlyphCount, clusterMap, glyphIndices,
glyphAdvances, justifiedGlyphAdvances, justifiedGlyphOffsets, glyphAdvances, justifiedGlyphAdvances, justifiedGlyphOffsets,
glyphProperties, &actualGlyphsCount, modifiedClusterMap, modifiedGlyphIndices, glyphProperties, &actualGlyphsCount, modifiedClusterMap, modifiedGlyphIndices,
@ -802,21 +803,21 @@ retry_getjustifiedglyphs:
glyphAdvances = modifiedGlyphAdvances; glyphAdvances = modifiedGlyphAdvances;
glyphOffsets = modifiedGlyphOffsets; glyphOffsets = modifiedGlyphOffsets;
free(justifiedGlyphAdvances); free (justifiedGlyphAdvances);
free(justifiedGlyphOffsets); free (justifiedGlyphOffsets);
} }
else else
{ {
free(glyphAdvances); free (glyphAdvances);
free(glyphOffsets); free (glyphOffsets);
glyphAdvances = justifiedGlyphAdvances; glyphAdvances = justifiedGlyphAdvances;
glyphOffsets = justifiedGlyphOffsets; glyphOffsets = justifiedGlyphOffsets;
} }
free(justificationOpportunities); free (justificationOpportunities);
#endif }
/* Ok, we've got everything we need, now compose output buffer, /* Ok, we've got everything we need, now compose output buffer,
* very, *very*, carefully! */ * very, *very*, carefully! */