2017-05-11 09:27:34 -05:00
|
|
|
// 11 may 2017
|
|
|
|
#include "uipriv_windows.hpp"
|
|
|
|
|
2017-05-17 14:57:39 -05:00
|
|
|
typedef std::map<uint32_t, uint32_t> tagmap;
|
|
|
|
|
2017-05-11 09:27:34 -05:00
|
|
|
struct uiOpenTypeFeatures {
|
2017-05-17 14:57:39 -05:00
|
|
|
tagmap *tags;
|
2017-05-11 09:27:34 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
uiOpenTypeFeatures *uiNewOpenTypeFeatures(void)
|
|
|
|
{
|
|
|
|
uiOpenTypeFeatures *otf;
|
|
|
|
|
|
|
|
otf = uiNew(uiOpenTypeFeatures);
|
2017-05-17 14:57:39 -05:00
|
|
|
otf->tags = new tagmap;
|
2017-05-11 09:27:34 -05:00
|
|
|
return otf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiFreeOpenTypeFeatures(uiOpenTypeFeatures *otf)
|
|
|
|
{
|
2017-05-17 14:57:39 -05:00
|
|
|
delete otf->tags;
|
2017-05-11 09:27:34 -05:00
|
|
|
uiFree(otf);
|
|
|
|
}
|
|
|
|
|
2017-05-30 08:52:38 -05:00
|
|
|
uiOpenTypeFeatures *uiOpenTypeFeaturesClone(const uiOpenTypeFeatures *otf)
|
2017-05-11 09:27:34 -05:00
|
|
|
{
|
|
|
|
uiOpenTypeFeatures *out;
|
|
|
|
|
|
|
|
out = uiNew(uiOpenTypeFeatures);
|
2017-05-17 14:57:39 -05:00
|
|
|
out->tags = new tagmap;
|
|
|
|
*(out->tags) = *(otf->tags);
|
2017-05-11 09:27:34 -05:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2017-05-17 14:57:39 -05:00
|
|
|
#define mktag(a, b, c, d) ((uint32_t) DWRITE_MAKE_OPENTYPE_TAG(a, b, c, d))
|
|
|
|
|
2017-05-11 09:27:34 -05:00
|
|
|
void uiOpenTypeFeaturesAdd(uiOpenTypeFeatures *otf, char a, char b, char c, char d, uint32_t value)
|
|
|
|
{
|
2017-05-17 14:57:39 -05:00
|
|
|
(*(otf->tags))[mktag(a, b, c, d)] = value;
|
2017-05-11 09:27:34 -05:00
|
|
|
}
|
|
|
|
|
2017-05-17 14:57:39 -05:00
|
|
|
// TODO what should happen if a/b/c/d isn't defined?
|
|
|
|
// TODO what does std::map do if a/b/c/d isn't defined?
|
2017-05-11 09:27:34 -05:00
|
|
|
void uiOpenTypeFeaturesRemove(uiOpenTypeFeatures *otf, char a, char b, char c, char d)
|
|
|
|
{
|
2017-05-17 14:57:39 -05:00
|
|
|
otf->tags->erase(mktag(a, b, c, d));
|
2017-05-11 09:27:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int uiOpenTypeFeaturesGet(uiOpenTypeFeatures *otf, char a, char b, char c, char d, uint32_t *value)
|
|
|
|
{
|
2017-05-17 14:57:39 -05:00
|
|
|
tagmap::const_iterator iter;
|
|
|
|
|
|
|
|
iter = otf->tags->find(mktag(a, b, c, d));
|
|
|
|
if (iter == otf->tags->end())
|
|
|
|
return 0;
|
|
|
|
*value = iter->second;
|
|
|
|
return 1;
|
2017-05-11 09:27:34 -05:00
|
|
|
}
|
|
|
|
|
2017-05-30 13:00:58 -05:00
|
|
|
void uiOpenTypeFeaturesForEach(const uiOpenTypeFeatures *otf, uiOpenTypeFeaturesForEachFunc f, void *data)
|
2017-05-11 09:27:34 -05:00
|
|
|
{
|
2017-05-17 14:57:39 -05:00
|
|
|
tagmap::const_iterator iter, end;
|
|
|
|
|
|
|
|
end = otf->tags->end();
|
|
|
|
for (iter = otf->tags->begin(); iter != end; iter++) {
|
|
|
|
uint8_t a, b, c, d;
|
2017-06-06 11:47:07 -05:00
|
|
|
uiForEach ret;
|
2017-05-17 14:57:39 -05:00
|
|
|
|
|
|
|
a = (uint8_t) (iter->first & 0xFF);
|
|
|
|
b = (uint8_t) ((iter->first >> 8) & 0xFF);
|
|
|
|
c = (uint8_t) ((iter->first >> 16) & 0xFF);
|
|
|
|
d = (uint8_t) ((iter->first >> 24) & 0xFF);
|
2017-06-06 11:47:07 -05:00
|
|
|
ret = (*f)((char) a, (char) b, (char) c, (char) d,
|
2017-05-17 14:57:39 -05:00
|
|
|
iter->second, data);
|
2017-06-06 11:47:07 -05:00
|
|
|
if (ret == uiForEachStop)
|
|
|
|
return;
|
2017-05-17 14:57:39 -05:00
|
|
|
}
|
2017-05-11 09:27:34 -05:00
|
|
|
}
|
|
|
|
|
2017-05-30 08:52:38 -05:00
|
|
|
int uiOpenTypeFeaturesEqual(const uiOpenTypeFeatures *a, const uiOpenTypeFeatures *b)
|
2017-05-11 09:27:34 -05:00
|
|
|
{
|
2017-05-17 14:57:39 -05:00
|
|
|
// TODO make sure this is correct
|
|
|
|
return *(a->tags) == *(b->tags);
|
2017-05-11 09:27:34 -05:00
|
|
|
}
|
|
|
|
|
2017-05-30 15:57:25 -05:00
|
|
|
IDWriteTypography *otfToDirectWrite(const uiOpenTypeFeatures *otf)
|
2017-05-17 14:57:39 -05:00
|
|
|
{
|
|
|
|
IDWriteTypography *dt;
|
|
|
|
tagmap::const_iterator iter, end;
|
|
|
|
DWRITE_FONT_FEATURE dff;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = dwfactory->CreateTypography(&dt);
|
|
|
|
if (hr != S_OK)
|
|
|
|
logHRESULT(L"error creating IDWriteTypography", hr);
|
|
|
|
end = otf->tags->end();
|
|
|
|
for (iter = otf->tags->begin(); iter != end; iter++) {
|
|
|
|
ZeroMemory(&dff, sizeof (DWRITE_FONT_FEATURE));
|
|
|
|
dff.nameTag = (DWRITE_FONT_FEATURE_TAG) (iter->first);
|
|
|
|
dff.parameter = (UINT32) (iter->second);
|
|
|
|
hr = dt->AddFontFeature(dff);
|
|
|
|
if (hr != S_OK)
|
|
|
|
logHRESULT(L"error adding OpenType feature to IDWriteTypography", hr);
|
|
|
|
}
|
|
|
|
return dt;
|
|
|
|
}
|