[dwrite] Remove ifdefs without breaking execution on old Windows versions
This commit is contained in:
parent
6b861dbd8b
commit
f3f0ea980a
@ -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,106 +714,110 @@ retry_getglyphs:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HB_DIRECTWRITE_EXPERIMENTAL_JUSTIFICATION
|
|
||||||
|
|
||||||
DWRITE_JUSTIFICATION_OPPORTUNITY* justificationOpportunities =
|
|
||||||
(DWRITE_JUSTIFICATION_OPPORTUNITY*)
|
|
||||||
malloc (maxGlyphCount * sizeof (DWRITE_JUSTIFICATION_OPPORTUNITY));
|
|
||||||
hr = analyzer->GetJustificationOpportunities (fontFace, fontEmSize,
|
|
||||||
runHead->mScript, textLength, glyphCount, textString, clusterMap,
|
|
||||||
glyphProperties, justificationOpportunities);
|
|
||||||
|
|
||||||
if (FAILED (hr))
|
|
||||||
{
|
|
||||||
FAIL ("Analyzer failed to get justification opportunities.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: get lineWith from somewhere
|
// TODO: get lineWith from somewhere
|
||||||
float lineWidth = 60000;
|
float lineWidth = 0;
|
||||||
|
|
||||||
float* justifiedGlyphAdvances =
|
IDWriteTextAnalyzer1* analyzer1;
|
||||||
(float*) malloc (maxGlyphCount * sizeof (float));
|
analyzer->QueryInterface (&analyzer1);
|
||||||
DWRITE_GLYPH_OFFSET* justifiedGlyphOffsets = (DWRITE_GLYPH_OFFSET*)
|
|
||||||
malloc (glyphCount * sizeof (DWRITE_GLYPH_OFFSET));
|
|
||||||
hr = analyzer->JustifyGlyphAdvances (lineWidth, glyphCount, justificationOpportunities,
|
|
||||||
glyphAdvances, glyphOffsets, justifiedGlyphAdvances, justifiedGlyphOffsets);
|
|
||||||
|
|
||||||
if (FAILED (hr))
|
if (analyzer1 && lineWidth)
|
||||||
{
|
{
|
||||||
FAIL ("Analyzer failed to get justified glyph advances.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
DWRITE_SCRIPT_PROPERTIES scriptProperties;
|
DWRITE_JUSTIFICATION_OPPORTUNITY* justificationOpportunities =
|
||||||
hr = analyzer->GetScriptProperties (runHead->mScript, &scriptProperties);
|
(DWRITE_JUSTIFICATION_OPPORTUNITY*)
|
||||||
if (FAILED (hr))
|
malloc (maxGlyphCount * sizeof (DWRITE_JUSTIFICATION_OPPORTUNITY));
|
||||||
{
|
hr = analyzer1->GetJustificationOpportunities (fontFace, fontEmSize,
|
||||||
FAIL ("Analyzer failed to get script properties.");
|
runHead->mScript, textLength, glyphCount, textString, clusterMap,
|
||||||
return false;
|
glyphProperties, justificationOpportunities);
|
||||||
}
|
|
||||||
uint32_t justificationCharacter = scriptProperties.justificationCharacter;
|
|
||||||
|
|
||||||
// if a script justificationCharacter is not space, it can have GetJustifiedGlyphs
|
if (FAILED (hr))
|
||||||
if (justificationCharacter != 32)
|
{
|
||||||
{
|
FAIL ("Analyzer failed to get justification opportunities.");
|
||||||
retry_getjustifiedglyphs:
|
return false;
|
||||||
uint16_t* modifiedClusterMap = (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* justifiedGlyphAdvances =
|
||||||
DWRITE_GLYPH_OFFSET* modifiedGlyphOffsets = (DWRITE_GLYPH_OFFSET*)
|
(float*) malloc (maxGlyphCount * sizeof (float));
|
||||||
malloc (maxGlyphCount * sizeof (DWRITE_GLYPH_OFFSET));
|
DWRITE_GLYPH_OFFSET* justifiedGlyphOffsets = (DWRITE_GLYPH_OFFSET*)
|
||||||
uint32_t actualGlyphsCount;
|
malloc (glyphCount * sizeof (DWRITE_GLYPH_OFFSET));
|
||||||
hr = analyzer->GetJustifiedGlyphs (fontFace, fontEmSize, runHead->mScript,
|
hr = analyzer1->JustifyGlyphAdvances (lineWidth, glyphCount, justificationOpportunities,
|
||||||
|
glyphAdvances, glyphOffsets, justifiedGlyphAdvances, justifiedGlyphOffsets);
|
||||||
|
|
||||||
|
if (FAILED (hr))
|
||||||
|
{
|
||||||
|
FAIL("Analyzer failed to get justified glyph advances.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
DWRITE_SCRIPT_PROPERTIES scriptProperties;
|
||||||
|
hr = analyzer1->GetScriptProperties (runHead->mScript, &scriptProperties);
|
||||||
|
if (FAILED (hr))
|
||||||
|
{
|
||||||
|
FAIL("Analyzer failed to get script properties.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
uint32_t justificationCharacter = scriptProperties.justificationCharacter;
|
||||||
|
|
||||||
|
// if a script justificationCharacter is not space, it can have GetJustifiedGlyphs
|
||||||
|
if (justificationCharacter != 32)
|
||||||
|
{
|
||||||
|
retry_getjustifiedglyphs:
|
||||||
|
uint16_t* modifiedClusterMap = (uint16_t*) malloc (maxGlyphCount * sizeof(uint16_t));
|
||||||
|
uint16_t* modifiedGlyphIndices = (uint16_t*) malloc (maxGlyphCount * sizeof(uint16_t));
|
||||||
|
float* modifiedGlyphAdvances = (float*) malloc (maxGlyphCount * sizeof(float));
|
||||||
|
DWRITE_GLYPH_OFFSET* modifiedGlyphOffsets = (DWRITE_GLYPH_OFFSET*)
|
||||||
|
malloc (maxGlyphCount * sizeof (DWRITE_GLYPH_OFFSET));
|
||||||
|
uint32_t actualGlyphsCount;
|
||||||
|
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,
|
||||||
modifiedGlyphAdvances, modifiedGlyphOffsets);
|
modifiedGlyphAdvances, modifiedGlyphOffsets);
|
||||||
|
|
||||||
if (hr == HRESULT_FROM_WIN32 (ERROR_INSUFFICIENT_BUFFER))
|
if (hr == HRESULT_FROM_WIN32 (ERROR_INSUFFICIENT_BUFFER))
|
||||||
{
|
{
|
||||||
maxGlyphCount = actualGlyphsCount;
|
maxGlyphCount = actualGlyphsCount;
|
||||||
free (modifiedClusterMap);
|
free (modifiedClusterMap);
|
||||||
free (modifiedGlyphIndices);
|
free (modifiedGlyphIndices);
|
||||||
free (modifiedGlyphAdvances);
|
free (modifiedGlyphAdvances);
|
||||||
free (modifiedGlyphOffsets);
|
free (modifiedGlyphOffsets);
|
||||||
|
|
||||||
maxGlyphCount = actualGlyphsCount;
|
maxGlyphCount = actualGlyphsCount;
|
||||||
|
|
||||||
goto retry_getjustifiedglyphs;
|
goto retry_getjustifiedglyphs;
|
||||||
|
}
|
||||||
|
if (FAILED (hr))
|
||||||
|
{
|
||||||
|
FAIL ("Analyzer failed to get justified glyphs.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
free (clusterMap);
|
||||||
|
free (glyphIndices);
|
||||||
|
free (glyphAdvances);
|
||||||
|
free (glyphOffsets);
|
||||||
|
|
||||||
|
glyphCount = actualGlyphsCount;
|
||||||
|
clusterMap = modifiedClusterMap;
|
||||||
|
glyphIndices = modifiedGlyphIndices;
|
||||||
|
glyphAdvances = modifiedGlyphAdvances;
|
||||||
|
glyphOffsets = modifiedGlyphOffsets;
|
||||||
|
|
||||||
|
free (justifiedGlyphAdvances);
|
||||||
|
free (justifiedGlyphOffsets);
|
||||||
}
|
}
|
||||||
if (FAILED (hr))
|
else
|
||||||
{
|
{
|
||||||
FAIL ("Analyzer failed to get justified glyphs.");
|
free (glyphAdvances);
|
||||||
return false;
|
free (glyphOffsets);
|
||||||
|
|
||||||
|
glyphAdvances = justifiedGlyphAdvances;
|
||||||
|
glyphOffsets = justifiedGlyphOffsets;
|
||||||
}
|
}
|
||||||
|
|
||||||
free (clusterMap);
|
free (justificationOpportunities);
|
||||||
free (glyphIndices);
|
|
||||||
free (glyphAdvances);
|
|
||||||
free (glyphOffsets);
|
|
||||||
|
|
||||||
glyphCount = actualGlyphsCount;
|
|
||||||
clusterMap = modifiedClusterMap;
|
|
||||||
glyphIndices = modifiedGlyphIndices;
|
|
||||||
glyphAdvances = modifiedGlyphAdvances;
|
|
||||||
glyphOffsets = modifiedGlyphOffsets;
|
|
||||||
|
|
||||||
free(justifiedGlyphAdvances);
|
|
||||||
free(justifiedGlyphOffsets);
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
free(glyphAdvances);
|
|
||||||
free(glyphOffsets);
|
|
||||||
|
|
||||||
glyphAdvances = justifiedGlyphAdvances;
|
|
||||||
glyphOffsets = justifiedGlyphOffsets;
|
|
||||||
}
|
|
||||||
|
|
||||||
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! */
|
||||||
|
Loading…
Reference in New Issue
Block a user