* to override malloc/free, we will redefine new/delete so users
* won't need to do that by their own.
*/
-void* operator new (size_t size) { return malloc (size); }
-void* operator new [] (size_t size) { return malloc (size); }
-void operator delete (void* pointer) { free (pointer); }
+void* operator new (size_t size) { return malloc (size); }
+void* operator new [] (size_t size) { return malloc (size); }
+void operator delete (void* pointer) { free (pointer); }
void operator delete [] (void* pointer) { free (pointer); }
IDWriteFontFileStream *mFontFileStream;
public:
DWriteFontFileLoader (IDWriteFontFileStream *fontFileStream)
- {
- mFontFileStream = fontFileStream;
- }
+ { mFontFileStream = fontFileStream; }
// IUnknown interface
- IFACEMETHOD (QueryInterface) (IID const& iid, OUT void** ppObject) { return S_OK; }
- IFACEMETHOD_ (ULONG, AddRef) () { return 1; }
- IFACEMETHOD_ (ULONG, Release) () { return 1; }
+ IFACEMETHOD (QueryInterface) (IID const& iid, OUT void** ppObject)
+ { return S_OK; }
+ IFACEMETHOD_ (ULONG, AddRef) (void) { return 1; }
+ IFACEMETHOD_ (ULONG, Release) (void) { return 1; }
// IDWriteFontFileLoader methods
- virtual HRESULT STDMETHODCALLTYPE CreateStreamFromKey (void const* fontFileReferenceKey,
- uint32_t fontFileReferenceKeySize,
- OUT IDWriteFontFileStream** fontFileStream)
+ virtual HRESULT STDMETHODCALLTYPE
+ CreateStreamFromKey (void const* fontFileReferenceKey,
+ uint32_t fontFileReferenceKeySize,
+ OUT IDWriteFontFileStream** fontFileStream)
{
*fontFileStream = mFontFileStream;
return S_OK;
}
// IUnknown interface
- IFACEMETHOD (QueryInterface) (IID const& iid, OUT void** ppObject) { return S_OK; }
- IFACEMETHOD_ (ULONG, AddRef) () { return 1; }
- IFACEMETHOD_ (ULONG, Release) () { return 1; }
+ IFACEMETHOD (QueryInterface) (IID const& iid, OUT void** ppObject)
+ { return S_OK; }
+ IFACEMETHOD_ (ULONG, AddRef) (void) { return 1; }
+ IFACEMETHOD_ (ULONG, Release) (void) { return 1; }
// IDWriteFontFileStream methods
- virtual HRESULT STDMETHODCALLTYPE ReadFileFragment (void const** fragmentStart,
- UINT64 fileOffset,
- UINT64 fragmentSize,
- OUT void** fragmentContext)
+ virtual HRESULT STDMETHODCALLTYPE
+ ReadFileFragment (void const** fragmentStart,
+ UINT64 fileOffset,
+ UINT64 fragmentSize,
+ OUT void** fragmentContext)
{
// We are required to do bounds checking.
- if (fileOffset + fragmentSize > mSize)
- return E_FAIL;
+ if (fileOffset + fragmentSize > mSize) return E_FAIL;
// truncate the 64 bit fileOffset to size_t sized index into mData
size_t index = static_cast<size_t> (fileOffset);
return S_OK;
}
- virtual void STDMETHODCALLTYPE ReleaseFileFragment (void* fragmentContext) { }
+ virtual void STDMETHODCALLTYPE
+ ReleaseFileFragment (void* fragmentContext) {}
- virtual HRESULT STDMETHODCALLTYPE GetFileSize (OUT UINT64* fileSize)
+ virtual HRESULT STDMETHODCALLTYPE
+ GetFileSize (OUT UINT64* fileSize)
{
*fileSize = mSize;
return S_OK;
}
- virtual HRESULT STDMETHODCALLTYPE GetLastWriteTime (OUT UINT64* lastWriteTime)
- {
- return E_NOTIMPL;
- }
+ virtual HRESULT STDMETHODCALLTYPE
+ GetLastWriteTime (OUT UINT64* lastWriteTime) { return E_NOTIMPL; }
};
// TODO: factory and fontFileLoader should be cached separately
IDWriteFactory* dwriteFactory;
- DWriteCreateFactory (
- DWRITE_FACTORY_TYPE_SHARED,
- __uuidof (IDWriteFactory),
- (IUnknown**) &dwriteFactory
- );
+ DWriteCreateFactory (DWRITE_FACTORY_TYPE_SHARED, __uuidof (IDWriteFactory),
+ (IUnknown**) &dwriteFactory);
HRESULT hr;
hb_blob_t *blob = hb_face_reference_blob (face);
- DWriteFontFileStream *fontFileStream = new DWriteFontFileStream (
- (uint8_t *) hb_blob_get_data (blob, nullptr),
- hb_blob_get_length (blob));
+ DWriteFontFileStream *fontFileStream;
+ fontFileStream = new DWriteFontFileStream ((uint8_t *) hb_blob_get_data (blob, nullptr),
+ hb_blob_get_length (blob));
DWriteFontFileLoader *fontFileLoader = new DWriteFontFileLoader (fontFileStream);
dwriteFactory->RegisterFontFileLoader (fontFileLoader);
IDWriteFontFile *fontFile;
uint64_t fontFileKey = 0;
hr = dwriteFactory->CreateCustomFontFileReference (&fontFileKey, sizeof (fontFileKey),
- fontFileLoader, &fontFile);
+ fontFileLoader, &fontFile);
#define FAIL(...) \
HB_STMT_START { \
IDWriteFontFace *fontFace;
dwriteFactory->CreateFontFace (faceType, 1, &fontFile, 0,
- DWRITE_FONT_SIMULATIONS_NONE, &fontFace);
+ DWRITE_FONT_SIMULATIONS_NONE, &fontFace);
data->dwriteFactory = dwriteFactory;
data->fontFile = fontFile;
* shaper font data
*/
-struct hb_directwrite_font_data_t
-{
-};
+struct hb_directwrite_font_data_t {};
hb_directwrite_font_data_t *
_hb_directwrite_shaper_font_data_create (hb_font_t *font)
// Most of TextAnalysis is originally written by Bas Schouten for Mozilla project
// but now is relicensed to MIT for HarfBuzz use
-class TextAnalysis
- : public IDWriteTextAnalysisSource, public IDWriteTextAnalysisSink
+class TextAnalysis : public IDWriteTextAnalysisSource, public IDWriteTextAnalysisSink
{
public:
- IFACEMETHOD (QueryInterface) (IID const& iid, OUT void** ppObject) { return S_OK; }
- IFACEMETHOD_ (ULONG, AddRef) () { return 1; }
- IFACEMETHOD_ (ULONG, Release) () { return 1; }
+ IFACEMETHOD (QueryInterface) (IID const& iid, OUT void** ppObject)
+ { return S_OK; }
+ IFACEMETHOD_ (ULONG, AddRef) (void) { return 1; }
+ IFACEMETHOD_ (ULONG, Release) (void) { return 1; }
// A single contiguous run of characters containing the same analysis
// results.
};
public:
- TextAnalysis (const wchar_t* text,
- uint32_t textLength,
- const wchar_t* localeName,
- DWRITE_READING_DIRECTION readingDirection)
- : mText (text)
- , mTextLength (textLength)
- , mLocaleName (localeName)
- , mReadingDirection (readingDirection)
- , mCurrentRun (nullptr) { };
-
- ~TextAnalysis ()
+ TextAnalysis (const wchar_t* text, uint32_t textLength,
+ const wchar_t* localeName, DWRITE_READING_DIRECTION readingDirection)
+ : mText (text), mTextLength (textLength), mLocaleName (localeName),
+ mReadingDirection (readingDirection), mCurrentRun (nullptr) {}
+ ~TextAnalysis (void)
{
// delete runs, except mRunHead which is part of the TextAnalysis object
for (Run *run = mRunHead.nextRun; run;)
}
}
- STDMETHODIMP GenerateResults (IDWriteTextAnalyzer* textAnalyzer,
- Run **runHead)
+ STDMETHODIMP
+ GenerateResults (IDWriteTextAnalyzer* textAnalyzer, Run **runHead)
{
// Analyzes the text using the script analyzer and returns
// the result as a series of runs.
// IDWriteTextAnalysisSource implementation
- IFACEMETHODIMP GetTextAtPosition (uint32_t textPosition,
- OUT wchar_t const** textString,
- OUT uint32_t* textLength)
+ IFACEMETHODIMP
+ GetTextAtPosition (uint32_t textPosition,
+ OUT wchar_t const** textString,
+ OUT uint32_t* textLength)
{
if (textPosition >= mTextLength)
{
return S_OK;
}
- IFACEMETHODIMP GetTextBeforePosition (uint32_t textPosition,
- OUT wchar_t const** textString,
- OUT uint32_t* textLength)
+ IFACEMETHODIMP
+ GetTextBeforePosition (uint32_t textPosition,
+ OUT wchar_t const** textString,
+ OUT uint32_t* textLength)
{
if (textPosition == 0 || textPosition > mTextLength)
{
}
IFACEMETHODIMP_ (DWRITE_READING_DIRECTION)
- GetParagraphReadingDirection () { return mReadingDirection; }
+ GetParagraphReadingDirection (void) { return mReadingDirection; }
- IFACEMETHODIMP GetLocaleName (uint32_t textPosition,
- uint32_t* textLength,
- wchar_t const** localeName)
- {
- return S_OK;
- }
+ IFACEMETHODIMP GetLocaleName (uint32_t textPosition, uint32_t* textLength,
+ wchar_t const** localeName)
+ { return S_OK; }
IFACEMETHODIMP
- GetNumberSubstitution (uint32_t textPosition,
- OUT uint32_t* textLength,
- OUT IDWriteNumberSubstitution** numberSubstitution)
+ GetNumberSubstitution (uint32_t textPosition,
+ OUT uint32_t* textLength,
+ OUT IDWriteNumberSubstitution** numberSubstitution)
{
// We do not support number substitution.
*numberSubstitution = nullptr;
// IDWriteTextAnalysisSink implementation
IFACEMETHODIMP
- SetScriptAnalysis (uint32_t textPosition,
- uint32_t textLength,
- DWRITE_SCRIPT_ANALYSIS const* scriptAnalysis)
+ SetScriptAnalysis (uint32_t textPosition, uint32_t textLength,
+ DWRITE_SCRIPT_ANALYSIS const* scriptAnalysis)
{
SetCurrentRun (textPosition);
SplitCurrentRun (textPosition);
}
IFACEMETHODIMP
- SetLineBreakpoints (uint32_t textPosition,
- uint32_t textLength,
- const DWRITE_LINE_BREAKPOINT* lineBreakpoints) { return S_OK; }
+ SetLineBreakpoints (uint32_t textPosition,
+ uint32_t textLength,
+ const DWRITE_LINE_BREAKPOINT* lineBreakpoints)
+ { return S_OK; }
- IFACEMETHODIMP SetBidiLevel (uint32_t textPosition,
- uint32_t textLength,
- uint8_t explicitLevel,
- uint8_t resolvedLevel) { return S_OK; }
+ IFACEMETHODIMP SetBidiLevel (uint32_t textPosition, uint32_t textLength,
+ uint8_t explicitLevel, uint8_t resolvedLevel)
+ { return S_OK; }
IFACEMETHODIMP
- SetNumberSubstitution (uint32_t textPosition,
- uint32_t textLength,
- IDWriteNumberSubstitution* numberSubstitution) { return S_OK; }
+ SetNumberSubstitution (uint32_t textPosition, uint32_t textLength,
+ IDWriteNumberSubstitution* numberSubstitution)
+ { return S_OK; }
protected:
Run *FetchNextRun (IN OUT uint32_t* textLength)
static hb_bool_t
_hb_directwrite_shape_full (hb_shape_plan_t *shape_plan,
- hb_font_t *font,
- hb_buffer_t *buffer,
- const hb_feature_t *features,
- unsigned int num_features,
- float lineWidth)
+ hb_font_t *font,
+ hb_buffer_t *buffer,
+ const hb_feature_t *features,
+ unsigned int num_features,
+ float lineWidth)
{
hb_face_t *face = font->face;
const hb_directwrite_face_data_t *face_data = face->data.directwrite;
// TODO: Handle TEST_DISABLE_OPTIONAL_LIGATURES
- DWRITE_READING_DIRECTION readingDirection = buffer->props.direction ?
- DWRITE_READING_DIRECTION_RIGHT_TO_LEFT :
- DWRITE_READING_DIRECTION_LEFT_TO_RIGHT;
+ DWRITE_READING_DIRECTION readingDirection;
+ readingDirection = buffer->props.direction ?
+ DWRITE_READING_DIRECTION_RIGHT_TO_LEFT :
+ DWRITE_READING_DIRECTION_LEFT_TO_RIGHT;
/*
* There's an internal 16-bit limit on some things inside the analyzer,
const wchar_t localeName[20] = {0};
if (buffer->props.language != nullptr)
- {
mbstowcs ((wchar_t*) localeName,
- hb_language_to_string (buffer->props.language), 20);
- }
+ hb_language_to_string (buffer->props.language), 20);
// TODO: it does work but doesn't care about ranges
DWRITE_TYPOGRAPHIC_FEATURES typographic_features;
for (unsigned int i = 0; i < num_features; ++i)
{
typographic_features.features[i].nameTag = (DWRITE_FONT_FEATURE_TAG)
- hb_uint32_swap (features[i].tag);
+ hb_uint32_swap (features[i].tag);
typographic_features.features[i].parameter = features[i].value;
}
}
- const DWRITE_TYPOGRAPHIC_FEATURES* dwFeatures =
- (const DWRITE_TYPOGRAPHIC_FEATURES*) &typographic_features;
+ const DWRITE_TYPOGRAPHIC_FEATURES* dwFeatures;
+ dwFeatures = (const DWRITE_TYPOGRAPHIC_FEATURES*) &typographic_features;
const uint32_t featureRangeLengths[] = { textLength };
//
- uint16_t* clusterMap = new uint16_t[textLength];
- DWRITE_SHAPING_TEXT_PROPERTIES* textProperties =
- new DWRITE_SHAPING_TEXT_PROPERTIES[textLength];
+ uint16_t* clusterMap;
+ clusterMap = new uint16_t[textLength];
+ DWRITE_SHAPING_TEXT_PROPERTIES* textProperties;
+ textProperties = new DWRITE_SHAPING_TEXT_PROPERTIES[textLength];
retry_getglyphs:
uint16_t* glyphIndices = new uint16_t[maxGlyphCount];
- DWRITE_SHAPING_GLYPH_PROPERTIES* glyphProperties =
- new DWRITE_SHAPING_GLYPH_PROPERTIES[maxGlyphCount];
+ DWRITE_SHAPING_GLYPH_PROPERTIES* glyphProperties;
+ glyphProperties = new DWRITE_SHAPING_GLYPH_PROPERTIES[maxGlyphCount];
hr = analyzer->GetGlyphs (textString, textLength, fontFace, false,
- isRightToLeft, &runHead->mScript, localeName, nullptr, &dwFeatures,
- featureRangeLengths, 1, maxGlyphCount, clusterMap, textProperties, glyphIndices,
- glyphProperties, &glyphCount);
+ isRightToLeft, &runHead->mScript, localeName,
+ nullptr, &dwFeatures, featureRangeLengths, 1,
+ maxGlyphCount, clusterMap, textProperties,
+ glyphIndices, glyphProperties, &glyphCount);
if (unlikely (hr == HRESULT_FROM_WIN32 (ERROR_INSUFFICIENT_BUFFER)))
{
/* The -2 in the following is to compensate for possible
* alignment needed after the WORD array. sizeof (WORD) == 2. */
unsigned int glyphs_size = (scratch_size * sizeof (int) - 2)
- / (sizeof (WORD) +
- sizeof (DWRITE_SHAPING_GLYPH_PROPERTIES) +
- sizeof (int) +
- sizeof (DWRITE_GLYPH_OFFSET) +
- sizeof (uint32_t));
+ / (sizeof (WORD) +
+ sizeof (DWRITE_SHAPING_GLYPH_PROPERTIES) +
+ sizeof (int) +
+ sizeof (DWRITE_GLYPH_OFFSET) +
+ sizeof (uint32_t));
ALLOCATE_ARRAY (uint32_t, vis_clusters, glyphs_size);
#undef ALLOCATE_ARRAY
int fontEmSize = font->face->get_upem ();
- if (fontEmSize < 0)
- fontEmSize = -fontEmSize;
+ if (fontEmSize < 0) fontEmSize = -fontEmSize;
- if (fontEmSize < 0)
- fontEmSize = -fontEmSize;
+ if (fontEmSize < 0) fontEmSize = -fontEmSize;
double x_mult = (double) font->x_scale / fontEmSize;
double y_mult = (double) font->y_scale / fontEmSize;
- hr = analyzer->GetGlyphPlacements (textString,
- clusterMap, textProperties, textLength, glyphIndices,
- glyphProperties, glyphCount, fontFace, fontEmSize,
- false, isRightToLeft, &runHead->mScript, localeName,
- &dwFeatures, featureRangeLengths, 1,
- glyphAdvances, glyphOffsets);
+ hr = analyzer->GetGlyphPlacements (textString, clusterMap, textProperties,
+ textLength, glyphIndices, glyphProperties,
+ glyphCount, fontFace, fontEmSize,
+ false, isRightToLeft, &runHead->mScript, localeName,
+ &dwFeatures, featureRangeLengths, 1,
+ glyphAdvances, glyphOffsets);
if (FAILED (hr))
FAIL ("Analyzer failed to get glyph placements.");
if (analyzer1 && lineWidth)
{
-
DWRITE_JUSTIFICATION_OPPORTUNITY* justificationOpportunities =
new DWRITE_JUSTIFICATION_OPPORTUNITY[maxGlyphCount];
- hr = analyzer1->GetJustificationOpportunities (fontFace, fontEmSize,
- runHead->mScript, textLength, glyphCount, textString, clusterMap,
- glyphProperties, justificationOpportunities);
+ hr = analyzer1->GetJustificationOpportunities (fontFace, fontEmSize, runHead->mScript,
+ textLength, glyphCount, textString,
+ clusterMap, glyphProperties,
+ justificationOpportunities);
if (FAILED (hr))
FAIL ("Analyzer failed to get justification opportunities.");
float* justifiedGlyphAdvances = new float[maxGlyphCount];
DWRITE_GLYPH_OFFSET* justifiedGlyphOffsets = new DWRITE_GLYPH_OFFSET[glyphCount];
hr = analyzer1->JustifyGlyphAdvances (lineWidth, glyphCount, justificationOpportunities,
- glyphAdvances, glyphOffsets, justifiedGlyphAdvances, justifiedGlyphOffsets);
+ glyphAdvances, glyphOffsets, justifiedGlyphAdvances,
+ justifiedGlyphOffsets);
- if (FAILED (hr))
- FAIL ("Analyzer failed to get justified glyph advances.");
+ if (FAILED (hr)) FAIL ("Analyzer failed to get justify glyph advances.");
DWRITE_SCRIPT_PROPERTIES scriptProperties;
hr = analyzer1->GetScriptProperties (runHead->mScript, &scriptProperties);
- if (FAILED (hr))
- FAIL ("Analyzer failed to get script properties.");
+ if (FAILED (hr)) FAIL ("Analyzer failed to get script properties.");
uint32_t justificationCharacter = scriptProperties.justificationCharacter;
// if a script justificationCharacter is not space, it can have GetJustifiedGlyphs
retry_getjustifiedglyphs:
uint16_t* modifiedGlyphIndices = new uint16_t[maxGlyphCount];
float* modifiedGlyphAdvances = new float[maxGlyphCount];
- DWRITE_GLYPH_OFFSET* modifiedGlyphOffsets =
- new DWRITE_GLYPH_OFFSET[maxGlyphCount];
+ DWRITE_GLYPH_OFFSET* modifiedGlyphOffsets = new DWRITE_GLYPH_OFFSET[maxGlyphCount];
uint32_t actualGlyphsCount;
hr = analyzer1->GetJustifiedGlyphs (fontFace, fontEmSize, runHead->mScript,
- textLength, glyphCount, maxGlyphCount, clusterMap, glyphIndices,
- glyphAdvances, justifiedGlyphAdvances, justifiedGlyphOffsets,
- glyphProperties, &actualGlyphsCount, modifiedClusterMap, modifiedGlyphIndices,
- modifiedGlyphAdvances, modifiedGlyphOffsets);
+ textLength, glyphCount, maxGlyphCount,
+ clusterMap, glyphIndices, glyphAdvances,
+ justifiedGlyphAdvances, justifiedGlyphOffsets,
+ glyphProperties, &actualGlyphsCount,
+ modifiedClusterMap, modifiedGlyphIndices,
+ modifiedGlyphAdvances, modifiedGlyphOffsets);
if (hr == HRESULT_FROM_WIN32 (ERROR_INSUFFICIENT_BUFFER))
{
}
delete [] justificationOpportunities;
-
}
/* Ok, we've got everything we need, now compose output buffer,
/* TODO vertical */
pos->x_advance = x_mult * (int32_t) info->mask;
- pos->x_offset =
- x_mult * (isRightToLeft ? -info->var1.i32 : info->var1.i32);
+ pos->x_offset = x_mult * (isRightToLeft ? -info->var1.i32 : info->var1.i32);
pos->y_offset = y_mult * info->var2.i32;
}
- if (isRightToLeft)
- hb_buffer_reverse (buffer);
+ if (isRightToLeft) hb_buffer_reverse (buffer);
delete [] clusterMap;
delete [] glyphIndices;
hb_bool_t
_hb_directwrite_shape (hb_shape_plan_t *shape_plan,
- hb_font_t *font,
- hb_buffer_t *buffer,
- const hb_feature_t *features,
- unsigned int num_features)
+ hb_font_t *font,
+ hb_buffer_t *buffer,
+ const hb_feature_t *features,
+ unsigned int num_features)
{
return _hb_directwrite_shape_full (shape_plan, font, buffer,
- features, num_features, 0);
+ features, num_features, 0);
}
/*
hb_bool_t
hb_directwrite_shape_experimental_width (hb_font_t *font,
- hb_buffer_t *buffer,
- const hb_feature_t *features,
- unsigned int num_features,
- float width)
+ hb_buffer_t *buffer,
+ const hb_feature_t *features,
+ unsigned int num_features,
+ float width)
{
static const char *shapers = "directwrite";
- hb_shape_plan_t *shape_plan = hb_shape_plan_create_cached (font->face,
- &buffer->props, features, num_features, &shapers);
+ hb_shape_plan_t *shape_plan;
+ shape_plan = hb_shape_plan_create_cached (font->face, &buffer->props,
+ features, num_features, &shapers);
hb_bool_t res = _hb_directwrite_shape_full (shape_plan, font, buffer,
- features, num_features, width);
+ features, num_features, width);
buffer->unsafe_to_break_all ();