@@ -259,11 +259,12 @@ bool Face_::Create(const char* fontData, unsigned int fontDataSize, unsigned int
259259//
260260
261261Font_::Font_ (Face_* pface) : pface_(pface)
262- {
262+ {
263263}
264264
265265Font_::~Font_ ()
266266{
267+ this ->ClearFeatures ();
267268}
268269
269270bool Font_::Create ()
@@ -321,8 +322,7 @@ bool Font_::SetVariations(const std::vector<hb_variation_t> &axisValues)
321322
322323bool Font_::SetFeatures (uint32_t textLength, const std::vector<hb_feature_t >& features)
323324{
324- std::vector<DWRITE_TYPOGRAPHIC_FEATURES> typographicFeatures;
325- std::vector<UINT32> featureRangeLengths;
325+ this ->ClearFeatures ();
326326
327327 if (textLength == 0 || features.size () == 0 )
328328 return true ;
@@ -396,12 +396,12 @@ bool Font_::SetFeatures(uint32_t textLength, const std::vector<hb_feature_t>& f
396396 typographicFeature.featureCount = static_cast <UINT32>(localFeatures.size ());
397397 typographicFeature.features = pLocalFeatures;
398398
399- typographicFeatures .push_back (typographicFeature);
399+ typographicFeatures_ .push_back (typographicFeature);
400400
401401 // Calculate featureRangeLengths
402402 if (i > 0 )
403403 {
404- featureRangeLengths .push_back (featureRangeLength);
404+ featureRangeLengths_ .push_back (featureRangeLength);
405405 featureRangeLength = 0 ;
406406 }
407407 }
@@ -410,16 +410,18 @@ bool Font_::SetFeatures(uint32_t textLength, const std::vector<hb_feature_t>& f
410410 }
411411
412412 // Final length
413- featureRangeLengths .push_back (featureRangeLength);
413+ featureRangeLengths_ .push_back (featureRangeLength);
414414 featureRangeLength = 0 ;
415415
416- assert (typographicFeatures .size () == featureRangeLengths .size ());
416+ assert (typographicFeatures_ .size () == featureRangeLengths_ .size ());
417417
418- // Set features in DWriteShape::Font object
419- HRESULT hr = pfont_-> SetFontFeatures (typographicFeatures, featureRangeLengths);
418+ return true ;
419+ }
420420
421+ void Font_::ClearFeatures ()
422+ {
421423 // Clean up
422- for (auto & it : typographicFeatures )
424+ for (auto & it : typographicFeatures_ )
423425 {
424426 if (it.features != nullptr )
425427 {
@@ -428,7 +430,8 @@ bool Font_::SetFeatures(uint32_t textLength, const std::vector<hb_feature_t>& f
428430 }
429431 }
430432
431- return hr == S_OK;
433+ typographicFeatures_.clear ();
434+ featureRangeLengths_.clear ();
432435}
433436
434437void Font_::GlyphToString (uint16_t glyphId, char * string, unsigned int size)
@@ -454,7 +457,7 @@ bool Font_::Shape(Buffer_* buffer)
454457 float fontEmSize = this ->GetFontEmSize ();
455458
456459 // Shape DWriteShape::Font
457- HRESULT hr = pfont_->Shape (text, buffer->Locale (), fontEmSize, output);
460+ HRESULT hr = pfont_->Shape (text, buffer->Locale (), fontEmSize, output, typographicFeatures_, featureRangeLengths_ );
458461
459462 buffer->SetOutput (output);
460463
0 commit comments