Moved the old Windows text code out of the way.

This commit is contained in:
Pietro Gagliardi 2018-03-11 21:04:38 -04:00
parent bffe311afe
commit e020ba465a
12 changed files with 142 additions and 146 deletions

View File

@ -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<void(uiDrawContext *c, uiDrawTextLayout *layout, double x, double y)> backgroundFunc;
extern void attrstrToIDWriteTextLayoutAttrs(uiDrawTextLayoutParams *p, IDWriteTextLayout *layout, std::vector<backgroundFunc> **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<uiDrawTextItalic, DWRITE_FONT_STYLE> dwriteItalics;
extern std::map<uiDrawTextStretch, DWRITE_FONT_STRETCH> dwriteStretches;
// drawtext.cpp
extern void fontdescFromIDWriteFont(IDWriteFont *font, uiDrawFontDescriptor *uidesc);
// opentype.cpp
extern IDWriteTypography *otfToDirectWrite(const uiOpenTypeFeatures *otf);

View File

@ -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);

View File

@ -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<void(uiDrawContext *c, uiDrawTextLayout *layout, double x, double y)> backgroundFunc;
extern void attrstrToIDWriteTextLayoutAttrs(uiDrawTextLayoutParams *p, IDWriteTextLayout *layout, std::vector<backgroundFunc> **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<uiDrawTextItalic, DWRITE_FONT_STYLE> dwriteItalics;
extern std::map<uiDrawTextStretch, DWRITE_FONT_STRETCH> dwriteStretches;

View File

@ -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);