From e020ba465addecf8f19e490242e3290a34ff6219 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 11 Mar 2018 21:04:38 -0400 Subject: [PATCH] Moved the old Windows text code out of the way. --- ...old_drawtext.cpp => OLD__old_drawtext.cpp} | 0 windows/{attrstr.cpp => OLD_attrstr.cpp} | 0 windows/{drawtext.cpp => OLD_drawtext.cpp} | 0 windows/{dwrite.cpp => OLD_dwrite.cpp} | 0 .../{fontbutton.cpp => OLD_fontbutton.cpp} | 0 .../{fontdialog.cpp => OLD_fontdialog.cpp} | 0 windows/{graphemes.cpp => OLD_graphemes.cpp} | 0 windows/{opentype.cpp => OLD_opentype.cpp} | 0 windows/OLD_uipriv_attrstr.h | 142 ++++++++++++++++++ windows/_uipriv_migrate.hpp | 26 ---- windows/draw.hpp | 111 -------------- windows/uipriv_windows.hpp | 9 -- 12 files changed, 142 insertions(+), 146 deletions(-) rename windows/{_old_drawtext.cpp => OLD__old_drawtext.cpp} (100%) rename windows/{attrstr.cpp => OLD_attrstr.cpp} (100%) rename windows/{drawtext.cpp => OLD_drawtext.cpp} (100%) rename windows/{dwrite.cpp => OLD_dwrite.cpp} (100%) rename windows/{fontbutton.cpp => OLD_fontbutton.cpp} (100%) rename windows/{fontdialog.cpp => OLD_fontdialog.cpp} (100%) rename windows/{graphemes.cpp => OLD_graphemes.cpp} (100%) rename windows/{opentype.cpp => OLD_opentype.cpp} (100%) create mode 100644 windows/OLD_uipriv_attrstr.h diff --git a/windows/_old_drawtext.cpp b/windows/OLD__old_drawtext.cpp similarity index 100% rename from windows/_old_drawtext.cpp rename to windows/OLD__old_drawtext.cpp diff --git a/windows/attrstr.cpp b/windows/OLD_attrstr.cpp similarity index 100% rename from windows/attrstr.cpp rename to windows/OLD_attrstr.cpp diff --git a/windows/drawtext.cpp b/windows/OLD_drawtext.cpp similarity index 100% rename from windows/drawtext.cpp rename to windows/OLD_drawtext.cpp diff --git a/windows/dwrite.cpp b/windows/OLD_dwrite.cpp similarity index 100% rename from windows/dwrite.cpp rename to windows/OLD_dwrite.cpp diff --git a/windows/fontbutton.cpp b/windows/OLD_fontbutton.cpp similarity index 100% rename from windows/fontbutton.cpp rename to windows/OLD_fontbutton.cpp diff --git a/windows/fontdialog.cpp b/windows/OLD_fontdialog.cpp similarity index 100% rename from windows/fontdialog.cpp rename to windows/OLD_fontdialog.cpp diff --git a/windows/graphemes.cpp b/windows/OLD_graphemes.cpp similarity index 100% rename from windows/graphemes.cpp rename to windows/OLD_graphemes.cpp diff --git a/windows/opentype.cpp b/windows/OLD_opentype.cpp similarity index 100% rename from windows/opentype.cpp rename to windows/OLD_opentype.cpp diff --git a/windows/OLD_uipriv_attrstr.h b/windows/OLD_uipriv_attrstr.h new file mode 100644 index 00000000..1ef2b71f --- /dev/null +++ b/windows/OLD_uipriv_attrstr.h @@ -0,0 +1,142 @@ +// dwrite.cpp +extern IDWriteFactory *dwfactory; +extern HRESULT initDrawText(void); +extern void uninitDrawText(void); +struct fontCollection { + IDWriteFontCollection *fonts; + WCHAR userLocale[LOCALE_NAME_MAX_LENGTH]; + int userLocaleSuccess; +}; +extern fontCollection *loadFontCollection(void); +extern WCHAR *fontCollectionFamilyName(fontCollection *fc, IDWriteFontFamily *family); +extern void fontCollectionFree(fontCollection *fc); +extern WCHAR *fontCollectionCorrectString(fontCollection *fc, IDWriteLocalizedStrings *names); + +// fontdialog.cpp +struct fontDialogParams { + IDWriteFont *font; + double size; + WCHAR *familyName; + WCHAR *styleName; +}; +extern BOOL showFontDialog(HWND parent, struct fontDialogParams *params); +extern void loadInitialFontDialogParams(struct fontDialogParams *params); +extern void destroyFontDialogParams(struct fontDialogParams *params); +extern WCHAR *fontDialogParamsToString(struct fontDialogParams *params); + +// attrstr.cpp +typedef std::function backgroundFunc; +extern void attrstrToIDWriteTextLayoutAttrs(uiDrawTextLayoutParams *p, IDWriteTextLayout *layout, std::vector **backgroundFuncs); + +// drawtext.cpp +// TODO reconcile this with attrstr.cpp +class textDrawingEffect : public IUnknown { + ULONG refcount; +public: + bool hasColor; + double r; + double g; + double b; + double a; + + bool hasUnderline; + uiDrawUnderlineStyle u; + + bool hasUnderlineColor; + double ur; + double ug; + double ub; + double ua; + + textDrawingEffect() + { + this->refcount = 1; + this->hasColor = false; + this->hasUnderline = false; + this->hasUnderlineColor = false; + } + + // IUnknown + virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) + { + if (ppvObject == NULL) + return E_POINTER; + if (riid == IID_IUnknown) { + this->AddRef(); + *ppvObject = this; + return S_OK; + } + *ppvObject = NULL; + return E_NOINTERFACE; + } + + virtual ULONG STDMETHODCALLTYPE AddRef(void) + { + this->refcount++; + return this->refcount; + } + + virtual ULONG STDMETHODCALLTYPE Release(void) + { + this->refcount--; + if (this->refcount == 0) { + delete this; + return 0; + } + return this->refcount; + } + + // TODO deduplicate this with common/attrlist.c + bool same(textDrawingEffect *b) + { + static auto boolsDiffer = [](bool a, bool b) -> bool { + if (a && b) + return false; + if (!a && !b) + return false; + return true; + }; + + if (boolsDiffer(this->hasColor, b->hasColor)) + return false; + if (this->hasColor) { + // TODO use a closest match? + if (this->r != b->r) + return false; + if (this->g != b->g) + return false; + if (this->b != b->b) + return false; + if (this->a != b->a) + return false; + } + if (boolsDiffer(this->hasUnderline, b->hasUnderline)) + return false; + if (this->hasUnderline) + if (this->u != b->u) + return false; + if (boolsDiffer(this->hasUnderlineColor, b->hasUnderlineColor)) + return false; + if (this->hasUnderlineColor) { + // TODO use a closest match? + if (this->ur != b->ur) + return false; + if (this->ug != b->ug) + return false; + if (this->ub != b->ub) + return false; + if (this->ua != b->ua) + return false; + } + return true; + } +}; +// TODO these should not be exported +extern std::map dwriteItalics; +extern std::map dwriteStretches; + +// drawtext.cpp +extern void fontdescFromIDWriteFont(IDWriteFont *font, uiDrawFontDescriptor *uidesc); + +// opentype.cpp +extern IDWriteTypography *otfToDirectWrite(const uiOpenTypeFeatures *otf); diff --git a/windows/_uipriv_migrate.hpp b/windows/_uipriv_migrate.hpp index b9c365cc..96a67089 100644 --- a/windows/_uipriv_migrate.hpp +++ b/windows/_uipriv_migrate.hpp @@ -12,29 +12,3 @@ extern void uninitDraw(void); extern ID2D1HwndRenderTarget *makeHWNDRenderTarget(HWND hwnd); extern uiDrawContext *newContext(ID2D1RenderTarget *); extern void freeContext(uiDrawContext *); - -// dwrite.cpp -extern IDWriteFactory *dwfactory; -extern HRESULT initDrawText(void); -extern void uninitDrawText(void); -struct fontCollection { - IDWriteFontCollection *fonts; - WCHAR userLocale[LOCALE_NAME_MAX_LENGTH]; - int userLocaleSuccess; -}; -extern fontCollection *loadFontCollection(void); -extern WCHAR *fontCollectionFamilyName(fontCollection *fc, IDWriteFontFamily *family); -extern void fontCollectionFree(fontCollection *fc); -extern WCHAR *fontCollectionCorrectString(fontCollection *fc, IDWriteLocalizedStrings *names); - -// fontdialog.cpp -struct fontDialogParams { - IDWriteFont *font; - double size; - WCHAR *familyName; - WCHAR *styleName; -}; -extern BOOL showFontDialog(HWND parent, struct fontDialogParams *params); -extern void loadInitialFontDialogParams(struct fontDialogParams *params); -extern void destroyFontDialogParams(struct fontDialogParams *params); -extern WCHAR *fontDialogParamsToString(struct fontDialogParams *params); diff --git a/windows/draw.hpp b/windows/draw.hpp index 8cfbbf72..c271e4db 100644 --- a/windows/draw.hpp +++ b/windows/draw.hpp @@ -16,114 +16,3 @@ extern ID2D1PathGeometry *pathGeometry(uiDrawPath *p); // drawmatrix.cpp extern void m2d(uiDrawMatrix *m, D2D1_MATRIX_3X2_F *d); - -// attrstr.cpp -typedef std::function backgroundFunc; -extern void attrstrToIDWriteTextLayoutAttrs(uiDrawTextLayoutParams *p, IDWriteTextLayout *layout, std::vector **backgroundFuncs); - -// drawtext.cpp -// TODO reconcile this with attrstr.cpp -class textDrawingEffect : public IUnknown { - ULONG refcount; -public: - bool hasColor; - double r; - double g; - double b; - double a; - - bool hasUnderline; - uiDrawUnderlineStyle u; - - bool hasUnderlineColor; - double ur; - double ug; - double ub; - double ua; - - textDrawingEffect() - { - this->refcount = 1; - this->hasColor = false; - this->hasUnderline = false; - this->hasUnderlineColor = false; - } - - // IUnknown - virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) - { - if (ppvObject == NULL) - return E_POINTER; - if (riid == IID_IUnknown) { - this->AddRef(); - *ppvObject = this; - return S_OK; - } - *ppvObject = NULL; - return E_NOINTERFACE; - } - - virtual ULONG STDMETHODCALLTYPE AddRef(void) - { - this->refcount++; - return this->refcount; - } - - virtual ULONG STDMETHODCALLTYPE Release(void) - { - this->refcount--; - if (this->refcount == 0) { - delete this; - return 0; - } - return this->refcount; - } - - // TODO deduplicate this with common/attrlist.c - bool same(textDrawingEffect *b) - { - static auto boolsDiffer = [](bool a, bool b) -> bool { - if (a && b) - return false; - if (!a && !b) - return false; - return true; - }; - - if (boolsDiffer(this->hasColor, b->hasColor)) - return false; - if (this->hasColor) { - // TODO use a closest match? - if (this->r != b->r) - return false; - if (this->g != b->g) - return false; - if (this->b != b->b) - return false; - if (this->a != b->a) - return false; - } - if (boolsDiffer(this->hasUnderline, b->hasUnderline)) - return false; - if (this->hasUnderline) - if (this->u != b->u) - return false; - if (boolsDiffer(this->hasUnderlineColor, b->hasUnderlineColor)) - return false; - if (this->hasUnderlineColor) { - // TODO use a closest match? - if (this->ur != b->ur) - return false; - if (this->ug != b->ug) - return false; - if (this->ub != b->ub) - return false; - if (this->ua != b->ua) - return false; - } - return true; - } -}; -// TODO these should not be exported -extern std::map dwriteItalics; -extern std::map dwriteStretches; diff --git a/windows/uipriv_windows.hpp b/windows/uipriv_windows.hpp index 3f199cbc..3244b7b4 100644 --- a/windows/uipriv_windows.hpp +++ b/windows/uipriv_windows.hpp @@ -152,17 +152,8 @@ extern void getSizing(HWND hwnd, uiWindowsSizing *sizing, HFONT font); // TODO move into a dedicated file abibugs.cpp when we rewrite the drawing code extern D2D1_SIZE_F realGetSize(ID2D1RenderTarget *rt); - - - // TODO #include "_uipriv_migrate.hpp" // draw.cpp extern ID2D1DCRenderTarget *makeHDCRenderTarget(HDC dc, RECT *r); - -// drawtext.cpp -extern void fontdescFromIDWriteFont(IDWriteFont *font, uiDrawFontDescriptor *uidesc); - -// opentype.cpp -extern IDWriteTypography *otfToDirectWrite(const uiOpenTypeFeatures *otf);