From a5bbc83359f92fbbc86f219a8a8bcf7b9e2f7eb2 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 17 Mar 2018 15:49:00 -0400 Subject: [PATCH] Fixed build errors. Now to test. --- common/attrstr.h | 4 ++++ windows/attrstr.cpp | 1 + windows/drawtext.cpp | 28 ++++++++++++++-------------- windows/dwrite.cpp | 2 +- windows/fontbutton.cpp | 2 +- windows/fontdialog.cpp | 22 +++++++++++----------- windows/fontmatch.cpp | 6 +++--- windows/opentype.cpp | 3 ++- 8 files changed, 37 insertions(+), 31 deletions(-) diff --git a/common/attrstr.h b/common/attrstr.h index 643c8c3c..fb2346d1 100644 --- a/common/attrstr.h +++ b/common/attrstr.h @@ -5,7 +5,11 @@ #define uiprivAlloc(x, y) uiAlloc(x, y) #define uiprivRealloc(x, y, z) uiRealloc(x, y, z) #define uiprivFree(x) uiFree(x) +#ifndef _WIN32 #define uiprivStricmp(x, y) strcasecmp(x, y) +#else +#define uiprivStricmp(x, y) stricmp(x, y) +#endif // attribute.c extern uiAttribute *uiprivAttributeRetain(uiAttribute *a); diff --git a/windows/attrstr.cpp b/windows/attrstr.cpp index c39a259e..feaaa61e 100644 --- a/windows/attrstr.cpp +++ b/windows/attrstr.cpp @@ -210,6 +210,7 @@ public: }; // also needed by applyEffectsAttributes() below +// TODO provide all the fields of std::hash and std::equal_to? class applyEffectsHash { public: typedef combinedEffectsAttr *ceaptr; diff --git a/windows/drawtext.cpp b/windows/drawtext.cpp index c1de9b2e..56a7dfbb 100644 --- a/windows/drawtext.cpp +++ b/windows/drawtext.cpp @@ -59,7 +59,7 @@ uiDrawTextLayout *uiDrawNewTextLayout(uiDrawTextLayoutParams *p) logHRESULT(L"error applying text layout alignment", hr); hr = dwfactory->CreateTextLayout( - (const WCHAR *) attrstrUTF16(p->String), attrstrUTF16Len(p->String), + (const WCHAR *) uiprivAttributedStringUTF16String(p->String), uiprivAttributedStringUTF16Len(p->String), tl->format, // FLOAT is float, not double, so this should work... TODO FLT_MAX, FLT_MAX, @@ -84,11 +84,11 @@ uiDrawTextLayout *uiDrawNewTextLayout(uiDrawTextLayoutParams *p) if (hr != S_OK) logHRESULT(L"error setting IDWriteTextLayout max layout width", hr); - attrstrToIDWriteTextLayoutAttrs(p, tl->layout, &(tl->backgroundParams)); + uiprivAttributedStringApplyAttributesToDWriteTextLayout(p, tl->layout, &(tl->backgroundParams)); // and finally copy the UTF-8/UTF-16 index conversion tables - tl->u8tou16 = attrstrCopyUTF8ToUTF16(p->String, &(tl->nUTF8)); - tl->u16tou8 = attrstrCopyUTF16ToUTF8(p->String, &(tl->nUTF16)); + tl->u8tou16 = uiprivAttributedStringCopyUTF8ToUTF16Table(p->String, &(tl->nUTF8)); + tl->u16tou8 = uiprivAttributedStringCopyUTF16ToUTF8Table(p->String, &(tl->nUTF16)); return tl; } @@ -97,7 +97,7 @@ void uiDrawFreeTextLayout(uiDrawTextLayout *tl) { uiFree(tl->u16tou8); uiFree(tl->u8tou16); - for (auto p in *(tl->backgroundParams)) + for (auto p : *(tl->backgroundParams)) uiprivFree(p); delete tl->backgroundParams; tl->layout->Release(); @@ -147,7 +147,7 @@ drawingEffectsAttr::drawingEffectsAttr(void) this->hasUnderlineColor = false; } -virtual HRESULT STDMETHODCALLTYPE drawingEffectsAttr::QueryInterface(REFIID riid, void **ppvObject) +HRESULT STDMETHODCALLTYPE drawingEffectsAttr::QueryInterface(REFIID riid, void **ppvObject) { if (ppvObject == NULL) return E_POINTER; @@ -160,13 +160,13 @@ virtual HRESULT STDMETHODCALLTYPE drawingEffectsAttr::QueryInterface(REFIID riid return E_NOINTERFACE; } -virtual ULONG STDMETHODCALLTYPE drawingEffectsAttr::AddRef(void) +ULONG STDMETHODCALLTYPE drawingEffectsAttr::AddRef(void) { this->refcount++; return this->refcount; } -virtual ULONG STDMETHODCALLTYPE drawingEffectsAttr::Release(void) +ULONG STDMETHODCALLTYPE drawingEffectsAttr::Release(void) { this->refcount--; if (this->refcount == 0) { @@ -315,7 +315,7 @@ public: virtual HRESULT STDMETHODCALLTYPE DrawGlyphRun(void *clientDrawingContext, FLOAT baselineOriginX, FLOAT baselineOriginY, DWRITE_MEASURING_MODE measuringMode, const DWRITE_GLYPH_RUN *glyphRun, const DWRITE_GLYPH_RUN_DESCRIPTION *glyphRunDescription, IUnknown *clientDrawingEffect) { D2D1_POINT_2F baseline; - drawingEffecsAttr *dea = (drawingEffectAttrs *) clientDrawingEffect; + drawingEffectsAttr *dea = (drawingEffectsAttr *) clientDrawingEffect; ID2D1SolidColorBrush *brush; baseline.x = baselineOriginX; @@ -330,7 +330,7 @@ public: } if (brush == NULL) { brush = this->black; - brush->Retain(); + brush->AddRef(); } this->rt->DrawGlyphRun( baseline, @@ -387,17 +387,17 @@ public: } if (brush == NULL) { brush = this->black; - brush->Retain(); + brush->AddRef(); } rect.left = baselineOriginX; rect.top = baselineOriginY + underline->offset; rect.right = rect.left + underline->width; rect.bottom = rect.top + underline->thickness; switch (utype) { - case uiDrawUnderlineStyleSingle: + case uiUnderlineSingle: this->rt->FillRectangle(&rect, brush); break; - case uiDrawUnderlineStyleDouble: + case uiUnderlineDouble: // TODO do any of the matrix methods return errors? // TODO standardize double-underline shape across platforms? wavy underline shape? this->rt->GetTransform(&pixeltf); @@ -420,7 +420,7 @@ public: rect.bottom = rect.top + underline->thickness; this->rt->FillRectangle(&rect, brush); break; - case uiDrawUnderlineStyleSuggestion: + case uiUnderlineSuggestion: { // TODO get rid of the extra block // TODO properly clean resources on failure // TODO use fully qualified C overloads for all methods diff --git a/windows/dwrite.cpp b/windows/dwrite.cpp index 3aeedfdb..24a4aa3a 100644 --- a/windows/dwrite.cpp +++ b/windows/dwrite.cpp @@ -47,7 +47,7 @@ WCHAR *uiprivFontCollectionFamilyName(fontCollection *fc, IDWriteFontFamily *fam hr = family->GetFamilyNames(&names); if (hr != S_OK) logHRESULT(L"error getting names of font out", hr); - str = fontCollectionCorrectString(fc, names); + str = uiprivFontCollectionCorrectString(fc, names); names->Release(); return str; } diff --git a/windows/fontbutton.cpp b/windows/fontbutton.cpp index 4f1ef594..29de64b6 100644 --- a/windows/fontbutton.cpp +++ b/windows/fontbutton.cpp @@ -87,7 +87,7 @@ static void defaultOnChanged(uiFontButton *b, void *data) // do nothing } -void uiFontButtonFont(uiFontButton *b, uiDrawFontDescriptor *desc) +void uiFontButtonFont(uiFontButton *b, uiFontDescriptor *desc) { uiprivFontDescriptorFromIDWriteFont(b->params.font, desc); desc->Family = toUTF8(b->params.familyName); diff --git a/windows/fontdialog.cpp b/windows/fontdialog.cpp index 6a137de1..2d10a1ae 100644 --- a/windows/fontdialog.cpp +++ b/windows/fontdialog.cpp @@ -18,7 +18,7 @@ struct fontDialog { struct fontDialogParams *params; - fontCollection *fc; + struct fontCollection *fc; RECT sampleRect; HWND sampleBox; @@ -169,7 +169,7 @@ static WCHAR *fontStyleName(struct fontCollection *fc, IDWriteFont *font) hr = font->GetFaceNames(&str); if (hr != S_OK) logHRESULT(L"error getting font style name for font dialog", hr); - wstr = fontCollectionCorrectString(fc, str); + wstr = uiprivFontCollectionCorrectString(fc, str); str->Release(); return wstr; } @@ -365,7 +365,7 @@ static void fontDialogDrawSampleText(struct fontDialog *f, ID2D1RenderTarget *rt if (hr != S_OK) exists = FALSE; if (exists) { - sample = fontCollectionCorrectString(f->fc, sampleStrings); + sample = uiprivFontCollectionCorrectString(f->fc, sampleStrings); sampleStrings->Release(); } else sample = L"The quick brown fox jumps over the lazy dog."; @@ -474,13 +474,13 @@ static struct fontDialog *beginFontDialog(HWND hwnd, LPARAM lParam) f->styleCombobox = getDlgItem(f->hwnd, rcFontStyleCombobox); f->sizeCombobox = getDlgItem(f->hwnd, rcFontSizeCombobox); - f->fc = loadFontCollection(); + f->fc = uiprivLoadFontCollection(); nFamilies = f->fc->fonts->GetFontFamilyCount(); for (i = 0; i < nFamilies; i++) { hr = f->fc->fonts->GetFontFamily(i, &family); if (hr != S_OK) logHRESULT(L"error getting font family", hr); - wname = fontCollectionFamilyName(f->fc, family); + wname = uiprivFontCollectionFamilyName(f->fc, family); pos = cbAddString(f->familyCombobox, wname); uiFree(wname); cbSetItemData(f->familyCombobox, (WPARAM) pos, (LPARAM) family); @@ -503,7 +503,7 @@ static void endFontDialog(struct fontDialog *f, INT_PTR code) { wipeStylesBox(f); cbWipeAndReleaseData(f->familyCombobox); - fontCollectionFree(f->fc); + uiprivFontCollectionFree(f->fc); if (EndDialog(f->hwnd, code) == 0) logLastError(L"error ending font dialog"); uiFree(f); @@ -520,13 +520,13 @@ static INT_PTR tryFinishDialog(struct fontDialog *f, WPARAM wParam) } // OK - destroyFontDialogParams(f->params); + uiprivDestroyFontDialogParams(f->params); f->params->font = (IDWriteFont *) cbGetItemData(f->styleCombobox, f->curStyle); // we need to save font from being destroyed with the combobox f->params->font->AddRef(); f->params->size = f->curSize; family = (IDWriteFontFamily *) cbGetItemData(f->familyCombobox, f->curFamily); - f->params->familyName = fontCollectionFamilyName(f->fc, family); + f->params->familyName = uiprivFontCollectionFamilyName(f->fc, family); f->params->styleName = fontStyleName(f->fc, f->params->font); endFontDialog(f, 2); return TRUE; @@ -636,7 +636,7 @@ void uiprivLoadInitialFontDialogParams(struct fontDialogParams *params) // If Arial isn't found, we'll use Helvetica and then MS Sans Serif as fallbacks, and if not, we'll just grab the first font family in the collection. // We need the correct localized name for Regular (and possibly Arial too? let's say yes to be safe), so let's grab the strings from DirectWrite instead of hardcoding them. - fc = loadFontCollection(); + fc = uiprivLoadFontCollection(); family = tryFindFamily(fc->fonts, L"Arial"); if (family == NULL) { family = tryFindFamily(fc->fonts, L"Helvetica"); @@ -661,12 +661,12 @@ void uiprivLoadInitialFontDialogParams(struct fontDialogParams *params) params->font = font; params->size = 10; - params->familyName = fontCollectionFamilyName(fc, family); + params->familyName = uiprivFontCollectionFamilyName(fc, family); params->styleName = fontStyleName(fc, font); // don't release font; we still need it family->Release(); - fontCollectionFree(fc); + uiprivFontCollectionFree(fc); } void uiprivDestroyFontDialogParams(struct fontDialogParams *params) diff --git a/windows/fontmatch.cpp b/windows/fontmatch.cpp index 28b4c84a..73f29543 100644 --- a/windows/fontmatch.cpp +++ b/windows/fontmatch.cpp @@ -49,13 +49,13 @@ void uiprivFontDescriptorFromIDWriteFont(IDWriteFont *font, uiFontDescriptor *ui dwitalic = font->GetStyle(); // TODO reverse the above misalignment if it is corrected - uidesc->Weight = (uiDrawTextWeight) (font->GetWeight()); + uidesc->Weight = (uiTextWeight) (font->GetWeight()); dwstretch = font->GetStretch(); - for (uidesc->Italic = uiDrawTextItalicNormal; uidesc->Italic < uiDrawTextItalicItalic; uidesc->Italic++) + for (uidesc->Italic = uiTextItalicNormal; uidesc->Italic < uiTextItalicItalic; uidesc->Italic++) if (dwriteItalics[uidesc->Italic] == dwitalic) break; - for (uidesc->Stretch = uiDrawTextStretchUltraCondensed; uidesc->Stretch < uiDrawTextStretchUltraExpanded; uidesc->Stretch++) + for (uidesc->Stretch = uiTextStretchUltraCondensed; uidesc->Stretch < uiTextStretchUltraExpanded; uidesc->Stretch++) if (dwriteStretches[uidesc->Stretch] == dwstretch) break; } diff --git a/windows/opentype.cpp b/windows/opentype.cpp index 0a96cdc4..777f30d6 100644 --- a/windows/opentype.cpp +++ b/windows/opentype.cpp @@ -11,7 +11,8 @@ static uiForEach addToTypography(const uiOpenTypeFeatures *otf, char a, char b, HRESULT hr; ZeroMemory(&dff, sizeof (DWRITE_FONT_FEATURE)); - dff.nameTag = /*(DWRITE_FONT_FEATURE_TAG)*/ DWRITE_MAKE_OPENTYPE_TAG(a, b, c, d); + // yes, the cast here is necessary (the compiler will complain otherwise)... + 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)