diff --git a/windows/OLD_opentype.cpp b/windows/OLD_opentype.cpp deleted file mode 100644 index 235f0388..00000000 --- a/windows/OLD_opentype.cpp +++ /dev/null @@ -1,110 +0,0 @@ -// 11 may 2017 -#include "uipriv_windows.hpp" - -typedef std::map tagmap; - -struct uiOpenTypeFeatures { - tagmap *tags; -}; - -uiOpenTypeFeatures *uiNewOpenTypeFeatures(void) -{ - uiOpenTypeFeatures *otf; - - otf = uiNew(uiOpenTypeFeatures); - otf->tags = new tagmap; - return otf; -} - -void uiFreeOpenTypeFeatures(uiOpenTypeFeatures *otf) -{ - delete otf->tags; - uiFree(otf); -} - -uiOpenTypeFeatures *uiOpenTypeFeaturesClone(const uiOpenTypeFeatures *otf) -{ - uiOpenTypeFeatures *out; - - out = uiNew(uiOpenTypeFeatures); - out->tags = new tagmap; - *(out->tags) = *(otf->tags); - return out; -} - -#define mktag(a, b, c, d) ((uint32_t) DWRITE_MAKE_OPENTYPE_TAG(a, b, c, d)) - -void uiOpenTypeFeaturesAdd(uiOpenTypeFeatures *otf, char a, char b, char c, char d, uint32_t value) -{ - (*(otf->tags))[mktag(a, b, c, d)] = value; -} - -void uiOpenTypeFeaturesRemove(uiOpenTypeFeatures *otf, char a, char b, char c, char d) -{ - // this will just return 0 if nothing was removed (if I'm reading the help pages I've found correctly) - otf->tags->erase(mktag(a, b, c, d)); -} - -// TODO will the const wreck stuff up? -int uiOpenTypeFeaturesGet(const uiOpenTypeFeatures *otf, char a, char b, char c, char d, uint32_t *value) -{ - 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; -} - -void uiOpenTypeFeaturesForEach(const uiOpenTypeFeatures *otf, uiOpenTypeFeaturesForEachFunc f, void *data) -{ - tagmap::const_iterator iter, end; - - end = otf->tags->end(); - for (iter = otf->tags->begin(); iter != end; iter++) { - uint8_t a, b, c, d; - uiForEach ret; - - 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); - ret = (*f)(otf, (char) a, (char) b, (char) c, (char) d, - iter->second, data); - if (ret == uiForEachStop) - return; - } -} - -int uiOpenTypeFeaturesEqual(const uiOpenTypeFeatures *a, const uiOpenTypeFeatures *b) -{ - if (a == NULL && b == NULL) - return 1; - if (a == NULL || b == NULL) - return 0; - // TODO make sure this is correct - return *(a->tags) == *(b->tags); -} - -IDWriteTypography *otfToDirectWrite(const uiOpenTypeFeatures *otf) -{ - 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; -} diff --git a/windows/attrstr.hpp b/windows/attrstr.hpp new file mode 100644 index 00000000..0b1d9031 --- /dev/null +++ b/windows/attrstr.hpp @@ -0,0 +1,7 @@ +// 11 march 2018 +extern "C" { +#include "../common/attrstr.h" +} + +// opentype.cpp +extern IDWriteTypography *uiprivOpenTypeFeaturesToIDWriteTypography(const uiOpenTypeFeatures *otf); diff --git a/windows/OLD_graphemes.cpp b/windows/graphemes.cpp similarity index 93% rename from windows/OLD_graphemes.cpp rename to windows/graphemes.cpp index 256c3a07..63e4882f 100644 --- a/windows/OLD_graphemes.cpp +++ b/windows/graphemes.cpp @@ -1,16 +1,17 @@ // 25 may 2016 #include "uipriv_windows.hpp" +#include "attrstr.hpp" // We could use CharNextW() to generate grapheme cluster boundaries, but it doesn't handle surrogate pairs properly (see http://archives.miloush.net/michkap/archive/2008/12/16/9223301.html). // We could also use Uniscribe (see http://archives.miloush.net/michkap/archive/2005/01/14/352802.html, http://www.catch22.net/tuts/uniscribe-mysteries, http://www.catch22.net/tuts/keyboard-navigation, and https://maxradi.us/documents/uniscribe/), but its rules for buffer sizes is convoluted. // Let's just deal with the CharNextW() bug. -int graphemesTakesUTF16(void) +int uiprivGraphemesTakesUTF16(void) { return 1; } -struct graphemes *graphemes(void *s, size_t len) +struct graphemes *uiprivNewGraphemes(void *s, size_t len) { struct graphemes *g; WCHAR *str; diff --git a/windows/opentype.cpp b/windows/opentype.cpp new file mode 100644 index 00000000..0a96cdc4 --- /dev/null +++ b/windows/opentype.cpp @@ -0,0 +1,32 @@ +// 11 may 2017 +#include "uipriv_windows.hpp" +#include "attrstr.hpp" + +// TODO pull out my decision for empty uiOpenTypeFeatures, assuming that it isn't in another file or that I even made one + +static uiForEach addToTypography(const uiOpenTypeFeatures *otf, char a, char b, char c, char d, uint32_t value, void *data) +{ + IDWriteTypography *dt = (IDWriteTypography *) data; + DWRITE_FONT_FEATURE dff; + HRESULT hr; + + ZeroMemory(&dff, sizeof (DWRITE_FONT_FEATURE)); + dff.nameTag = /*(DWRITE_FONT_FEATURE_TAG)*/ DWRITE_MAKE_OPENTYPE_TAG(a, b, c, d); + dff.parameter = (UINT32) value; + hr = dt->AddFontFeature(dff); + if (hr != S_OK) + logHRESULT(L"error adding OpenType feature to IDWriteTypography", hr); + return uiForEachContinue; +} + +IDWriteTypography *uiprivOpenTypeFeaturesToIDWriteTypography(const uiOpenTypeFeatures *otf) +{ + IDWriteTypography *dt; + HRESULT hr; + + hr = dwfactory->CreateTypography(&dt); + if (hr != S_OK) + logHRESULT(L"error creating IDWriteTypography", hr); + uiOpenTypeFeaturesForEach(otf, addToTypography, dt); + return dt; +}