Skip to content

Commit dc06783

Browse files
committed
Fix bugs in locale and OT feature entry.
1 parent ced3341 commit dc06783

File tree

2 files changed

+51
-8
lines changed

2 files changed

+51
-8
lines changed

src/cpp/DWriteShapeInternal.cpp

+38-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ namespace DWriteShapeInternal
5858

5959
Font::~Font()
6060
{
61+
// Clear any previous features
62+
for (auto& it : features_)
63+
{
64+
if(it.features != nullptr)
65+
{
66+
delete[] it.features;
67+
}
68+
}
69+
features_.clear();
70+
6171
SafeRelease(&fontFaceReference_);
6272
SafeRelease(&fontFace_);
6373

@@ -111,7 +121,34 @@ namespace DWriteShapeInternal
111121
{
112122
fontRealized_ = false;
113123

114-
features_ = features;
124+
// Clear any previous features
125+
for (auto& it : features_)
126+
{
127+
if(it.features != nullptr)
128+
{
129+
delete[] it.features;
130+
}
131+
}
132+
features_.clear();
133+
134+
// Copy features from client
135+
for (auto& it : features)
136+
{
137+
DWRITE_TYPOGRAPHIC_FEATURES localFeatures;
138+
localFeatures.featureCount = it.featureCount;
139+
DWRITE_FONT_FEATURE* pLocalFeatures = new DWRITE_FONT_FEATURE[it.featureCount];
140+
141+
localFeatures.featureCount = it.featureCount;
142+
for(UINT32 i = 0; i < localFeatures.featureCount; i++ )
143+
{
144+
pLocalFeatures[i].nameTag = it.features[i].nameTag;
145+
pLocalFeatures[i].parameter = it.features[i].parameter;
146+
}
147+
localFeatures.features = pLocalFeatures;
148+
149+
features_.push_back(localFeatures);
150+
}
151+
115152
featureRangeLengths_ = featureRangeLengths;
116153

117154
return S_OK;

src/cpp/DWriteShapeLib.cpp

+13-7
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,17 @@ void Buffer_::SetLocale(const char* locale)
162162

163163
std::string str = reinterpret_cast<const char*>(locale);
164164
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
165-
std::wstring openTypeLocale = converter.from_bytes(str);
165+
std::wstring inputLocale = converter.from_bytes(str);
166166

167-
std::wstring windowsLocale;
168-
if (localeMap_->GetWindowsLocale(openTypeLocale, windowsLocale))
167+
std::wstring windowsLocale;
168+
if (localeMap_->GetWindowsLocale(inputLocale, windowsLocale))
169+
{
169170
locale_ = windowsLocale;
171+
}
172+
else
173+
{
174+
locale_ = inputLocale;
175+
}
170176
}
171177

172178
const char* Buffer_::GetLocale()
@@ -329,7 +335,7 @@ bool Font_::SetFeatures(uint32_t textLength, const std::vector<hb_feature_t>& f
329335

330336
// look though features and determine range boundries
331337
for (auto& it : features)
332-
{
338+
{
333339
if (it.start < featureRangeBounderies.size())
334340
{
335341
featureRangeBounderies[it.start] = true;
@@ -381,7 +387,7 @@ bool Font_::SetFeatures(uint32_t textLength, const std::vector<hb_feature_t>& f
381387
// allocate an array for DWRITE_FONT_FEATURE
382388
DWRITE_FONT_FEATURE* pLocalFeatures = new DWRITE_FONT_FEATURE[localFeatures.size()];
383389
for (int j = 0; j < localFeatures.size(); j++)
384-
{
390+
{
385391
pLocalFeatures[j].nameTag = localFeatures[j].nameTag;
386392
pLocalFeatures[j].parameter = localFeatures[j].parameter;
387393
}
@@ -394,15 +400,15 @@ bool Font_::SetFeatures(uint32_t textLength, const std::vector<hb_feature_t>& f
394400

395401
// Calculate featureRangeLengths
396402
if (i > 0)
397-
{
403+
{
398404
featureRangeLengths.push_back(featureRangeLength);
399405
featureRangeLength = 0;
400406
}
401407
}
402408

403409
featureRangeLength++;
404410
}
405-
411+
406412
// Final length
407413
featureRangeLengths.push_back(featureRangeLength);
408414
featureRangeLength = 0;

0 commit comments

Comments
 (0)